Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions drivers/mfd/macsmc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,31 @@ static void macsmc_port_reasons_test(struct kunit *test)
KUNIT_EXPECT_FALSE(test, apple_smc_port_reasons_only(&ctx->smc, BIT_ULL(43)));
}

/*
* The SMC's first message may come as soon as its endpoint is started: the
* state the probe sets up before the RTKit is enough to take it.
*/
static void macsmc_early_message_test(struct kunit *test)
{
struct macsmc_test_context *ctx = test->priv;
struct resource sram = DEFINE_RES_MEM(0x10000, SMC_SHMEM_SIZE);
struct apple_smc *smc;

smc = kunit_kzalloc(test, sizeof(*smc), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, smc);
apple_smc_init_state(smc);
smc->sram = &sram;
smc->sram_base = (void __iomem *)ctx->shmem;

KUNIT_EXPECT_EQ(test, smc->boot_stage, APPLE_SMC_BOOTING);
KUNIT_EXPECT_FALSE(test, completion_done(&smc->init_done));

KUNIT_EXPECT_TRUE(test, apple_smc_rtkit_recv_early(smc, SMC_ENDPOINT, sram.start));
KUNIT_EXPECT_EQ(test, smc->boot_stage, APPLE_SMC_INITIALIZED);
KUNIT_EXPECT_TRUE(test, completion_done(&smc->init_done));
KUNIT_EXPECT_PTR_EQ(test, smc->shmem.iomem, smc->sram_base);
}

static struct device *macsmc_test_attach_dev(struct kunit *test,
struct macsmc_test_context *ctx)
{
Expand Down Expand Up @@ -535,6 +560,7 @@ static struct kunit_case macsmc_parser_cases[] = {
KUNIT_CASE(macsmc_lid_wake_test),
KUNIT_CASE(macsmc_wake_reason_test),
KUNIT_CASE(macsmc_port_reasons_test),
KUNIT_CASE(macsmc_early_message_test),
KUNIT_CASE(macsmc_wktp_probe_test),
KUNIT_CASE(macsmc_wktp_full_wake_test),
KUNIT_CASE(macsmc_wktp_dark_wake_test),
Expand Down
22 changes: 15 additions & 7 deletions drivers/mfd/macsmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,20 @@ static const struct apple_smc_wake_reason apple_smc_j714s_wake_reasons[] = {
{ 43, "USB2_plug" }, { 44, "USB2_wake" }, { 45, "aupo" }, { 48, "rtc" }, { }
};

/*
* The state the RTKit callbacks use. A message can arrive as soon as the
* RTKit is initialised, so this is set up before that.
*/
static void apple_smc_init_state(struct apple_smc *smc)
{
mutex_init(&smc->mutex);
spin_lock_init(&smc->lock);
init_completion(&smc->init_done);
init_completion(&smc->cmd_done);
BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
smc->boot_stage = APPLE_SMC_BOOTING;
}

/* A board's own numbering, from its device tree (apple,wake-reasons and their names) */
static const struct apple_smc_wake_reason *apple_smc_dt_wake_reasons(struct device *dev)
{
Expand Down Expand Up @@ -721,8 +735,7 @@ static int apple_smc_probe(struct platform_device *pdev)
smc->sleep_pmvc_set = !of_property_read_u32(dev->of_node, "apple,sleep-pmvc",
&smc->sleep_pmvc);

mutex_init(&smc->mutex);
spin_lock_init(&smc->lock);
apple_smc_init_state(smc);
smc->dev = &pdev->dev;
smc->saved_enabled = apple_t6050_sleep_described() &&
of_device_is_compatible(dev->of_node, "apple,t6050-smc");
Expand All @@ -744,7 +757,6 @@ static int apple_smc_probe(struct platform_device *pdev)
if (IS_ERR(smc->rtk))
return dev_err_probe(dev, PTR_ERR(smc->rtk), "Failed to initialize RTKit");

smc->boot_stage = APPLE_SMC_BOOTING;
ret = apple_rtkit_wake(smc->rtk);
if (ret)
return dev_err_probe(dev, ret, "Failed to wake up SMC");
Expand All @@ -757,9 +769,6 @@ static int apple_smc_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "Failed to start SMC endpoint");

init_completion(&smc->init_done);
init_completion(&smc->cmd_done);

ret = apple_rtkit_send_message(smc->rtk, SMC_ENDPOINT,
FIELD_PREP(SMC_MSG, SMC_MSG_INITIALIZE), NULL, false);
if (ret)
Expand All @@ -776,7 +785,6 @@ static int apple_smc_probe(struct platform_device *pdev)
}

dev_set_drvdata(&pdev->dev, smc);
BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);

ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
if (ret >= 0 && ret != sizeof(count)) {
Expand Down
Loading