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
32 changes: 31 additions & 1 deletion Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ maintainers:

allOf:
- $ref: watchdog.yaml#
- if:
properties:
reg:
minItems: 2
required:
- reg
then:
required:
- reg-names

properties:
compatible:
Expand Down Expand Up @@ -42,7 +51,16 @@ properties:
- const: apple,wdt

reg:
maxItems: 1
minItems: 1
items:
- description: Watchdog timer registers
- description: Simple-reconfig routing register

reg-names:
minItems: 1
items:
- const: wdt
- const: reconfig

clocks:
maxItems: 1
Expand All @@ -69,5 +87,17 @@ examples:
clocks = <&clk>;
interrupts = <AIC_IRQ 123 IRQ_TYPE_LEVEL_HIGH>;
};
- |
#include <dt-bindings/interrupt-controller/apple-aic.h>
#include <dt-bindings/interrupt-controller/irq.h>

watchdog@8836c000 {
compatible = "apple,t6050-wdt", "apple,t8103-wdt";
reg = <0x8836c000 0x4000>,
<0x8833002c 0x4>;
reg-names = "wdt", "reconfig";
clocks = <&clk>;
interrupts = <AIC_IRQ 0 721 IRQ_TYPE_LEVEL_HIGH>;
};

...
4 changes: 3 additions & 1 deletion arch/arm64/boot/dts/apple/t6050-die0.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

wdt: watchdog@28836c000 {
compatible = "apple,t6050-wdt", "apple,t8103-wdt";
reg = <0x2 0x8836c000 0x0 0x4000>;
reg = <0x2 0x8836c000 0x0 0x4000>,
<0x2 0x8833002c 0x0 0x4>;
reg-names = "wdt", "reconfig";
clocks = <&clkref>;
interrupts = <AIC_IRQ 0 721 IRQ_TYPE_LEVEL_HIGH>;
};
Expand Down
35 changes: 29 additions & 6 deletions drivers/soc/apple/sleep-t6050.h
Original file line number Diff line number Diff line change
Expand Up @@ -3123,6 +3123,33 @@ static void t6050_clusters_down_first_report(struct apple_sleep *s)
r->early_seq[1], r->early_us[1], r->early_ret[2]);
}

static void t6050_sleep_commit_wdt(struct apple_sleep *s)
{
struct apple_sleep_region_state *r = s->region;

if (r && r->seq[T6050_SEQ_WDT].n) {
s->aon_wdt_saved = readl(s->wdt_aux + AON_WDT_SLEEP);
s->aon_wdt_marked = true;
}
t6050_seq(s, T6050_SEQ_WDT);
writel(0, s->wdt + WDT_WD0_CTL);
apple_sleep_set_wd2(s, T6050_WDT_COMMIT_SECS);
writel(0, s->wdt_aux + AON_AP_DEADLINE);
}

static void t6050_sleep_wake_wdt(struct apple_sleep *s)
{
writel(0, s->wdt + WDT_WD2_CTL);
writel(WDT_WD2_CTL_IRQ_STATUS, s->wdt + WDT_WD2_CTL);
(void)readl(s->wdt + WDT_WD2_CTL);
if (s->aon_wdt_marked) {
writel(s->aon_wdt_saved, s->wdt_aux + AON_WDT_SLEEP);
(void)readl(s->wdt_aux + AON_WDT_SLEEP);
s->aon_wdt_marked = false;
}
apple_sleep_set_wd2(s, WDT_SUSPEND_SECS);
}

/*
* The commit window, each step at the DT schedule's time before the sleep timer: the MCC
* requests released, the storage link's PHY parked and its words down, the watchdogs, the
Expand Down Expand Up @@ -3175,10 +3202,7 @@ static void t6050_sleep_commit_regs(struct apple_sleep *s)
}
}
t6050_step(s, T6050_STEP_WDT);
t6050_seq(s, T6050_SEQ_WDT);
writel(0, s->wdt + WDT_WD0_CTL);
apple_sleep_set_wd2(s, T6050_WDT_COMMIT_SECS);
writel(0, s->wdt_aux + 8);
t6050_sleep_commit_wdt(s);
/* The memory floor's voter to 0, not read */
t6050_step(s, T6050_STEP_FLOOR);
s->region->floor_changed |= BIT(1);
Expand Down Expand Up @@ -3796,8 +3820,7 @@ static void t6050_sleep_wake_regs(struct apple_sleep *s)
r->gfx_aic[2] = readl(r->aic_gfx + 0x14);
}
/* The complexes' requests back, in macOS's early wake order */
writel(0, s->wdt + WDT_WD2_CTL);
apple_sleep_set_wd2(s, WDT_SUSPEND_SECS);
t6050_sleep_wake_wdt(s);
for (i = 0; i < 3; i++)
writel(r->cluster_saved[i], s->cluster + 4 * i);
writel(PWRGATE_ON, s->pwrgate);
Expand Down
131 changes: 131 additions & 0 deletions drivers/soc/apple/sleep-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,136 @@ static void apple_sleep_test_region_rejects_bad_inventory(struct kunit *test)
KUNIT_EXPECT_EQ(test, sleep_region_validate(&p), -EINVAL);
}

struct apple_sleep_test_wdt_saved {
struct device *dev;
void (*restore)(void *data);
void *data;
bool owned;
};

struct apple_sleep_test_wdt_ctx {
u32 *wdt_regs;
int calls;
u32 ctl_at_restore;
bool owned_at_restore;
};

struct apple_sleep_test_wdt_state {
struct device dev1;
struct device dev2;
u32 fake_wdt[16];
struct apple_sleep_test_wdt_saved saved;
};

static void apple_sleep_test_wdt_restore_global(void *data)
{
struct apple_sleep_test_wdt_saved *saved = data;
unsigned long flags;

spin_lock_irqsave(&apple_sleep_wdt_lock, flags);
apple_sleep_wdt_dev = saved->dev;
apple_sleep_wdt_restore = saved->restore;
apple_sleep_wdt_data = saved->data;
apple_sleep_wd2_owned = saved->owned;
spin_unlock_irqrestore(&apple_sleep_wdt_lock, flags);
}

static void apple_sleep_test_wdt_restore_cb(void *data)
{
struct apple_sleep_test_wdt_ctx *ctx = data;

ctx->calls++;
ctx->ctl_at_restore = ctx->wdt_regs[WDT_WD2_CTL / 4];
ctx->owned_at_restore = apple_sleep_wd2_owned;
}

static void apple_sleep_test_wdt_handoff(struct kunit *test)
{
struct resource t6050_sleep_wdt = DEFINE_RES_MEM(0x28836c000ULL, 0x4000);
struct resource t6050_dev_wdt = DEFINE_RES_MEM(0x28836c000ULL, 0x4000);
struct resource t8142_sleep_wdt = DEFINE_RES_MEM(0x23d2b0000ULL, 0x30);
struct resource t8142_dev_wdt = DEFINE_RES_MEM(0x23d2b0000ULL, 0x4000);
struct resource die1_wdt = DEFINE_RES_MEM(0x228836c000ULL, 0x4000);
struct apple_sleep_test_wdt_state *st;
struct apple_sleep_test_wdt_ctx ctx;
unsigned long flags;

st = kunit_kzalloc(test, sizeof(*st), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, st);

/* Isolate global handoff state so a probed apple_wdt on J714S/J716C is untouched. */
spin_lock_irqsave(&apple_sleep_wdt_lock, flags);
st->saved.dev = apple_sleep_wdt_dev;
st->saved.restore = apple_sleep_wdt_restore;
st->saved.data = apple_sleep_wdt_data;
st->saved.owned = apple_sleep_wd2_owned;
apple_sleep_wdt_dev = NULL;
apple_sleep_wdt_restore = NULL;
apple_sleep_wdt_data = NULL;
apple_sleep_wd2_owned = false;
spin_unlock_irqrestore(&apple_sleep_wdt_lock, flags);
KUNIT_ASSERT_EQ(test,
kunit_add_action_or_reset(test, apple_sleep_test_wdt_restore_global,
&st->saved), 0);

ctx = (struct apple_sleep_test_wdt_ctx){ .wdt_regs = st->fake_wdt };

/* Block matching compares resource start across differing map sizes. */
KUNIT_EXPECT_TRUE(test, apple_sleep_wdt_same_block(&t6050_sleep_wdt, &t6050_dev_wdt));
KUNIT_EXPECT_TRUE(test, apple_sleep_wdt_same_block(&t8142_sleep_wdt, &t8142_dev_wdt));
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_same_block(&t6050_sleep_wdt, &die1_wdt));
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_same_block(NULL, &t6050_dev_wdt));
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_same_block(&t6050_sleep_wdt, NULL));

/* Invalid arguments and unmatched watchdogs. */
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(NULL, true,
apple_sleep_test_wdt_restore_cb,
&ctx), -EINVAL);
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev1, true, NULL, &ctx),
-EINVAL);
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev2, false,
apple_sleep_test_wdt_restore_cb,
&ctx), 0);
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_active(&st->dev2));

/* Matching watchdog claims the single slot; a second claiming it gets -EBUSY. */
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev1, true,
apple_sleep_test_wdt_restore_cb,
&ctx), 0);
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev2, true,
apple_sleep_test_wdt_restore_cb,
&ctx), -EBUSY);
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev2, false,
apple_sleep_test_wdt_restore_cb,
&ctx), 0);
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_active(&st->dev1));

/* Ownership applies only to the registered watchdog; .end orders CTL=0, restore, clear. */
spin_lock_irqsave(&apple_sleep_wdt_lock, flags);
apple_sleep_wd2_owned = true;
spin_unlock_irqrestore(&apple_sleep_wdt_lock, flags);
KUNIT_EXPECT_TRUE(test, apple_sleep_wdt_active(&st->dev1));
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_active(&st->dev2));

st->fake_wdt[WDT_WD2_CTL / 4] = 1;
apple_sleep_wdt_end((void __iomem __force *)st->fake_wdt);
KUNIT_EXPECT_EQ(test, ctx.calls, 1);
KUNIT_EXPECT_EQ(test, ctx.ctl_at_restore, 0u);
KUNIT_EXPECT_TRUE(test, ctx.owned_at_restore);
KUNIT_EXPECT_FALSE(test, apple_sleep_wdt_active(&st->dev1));

/* Unregistering a non-holder leaves the slot intact; unregistering the holder frees it. */
apple_sleep_wdt_unregister(&st->dev2);
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev2, true,
apple_sleep_test_wdt_restore_cb,
&ctx), -EBUSY);
apple_sleep_wdt_unregister(&st->dev1);
KUNIT_EXPECT_EQ(test, apple_sleep_wdt_register_matched(&st->dev2, true,
apple_sleep_test_wdt_restore_cb,
&ctx), 0);
apple_sleep_wdt_unregister(&st->dev2);
}

static struct kunit_case apple_sleep_test_cases[] = {
KUNIT_CASE(apple_sleep_test_layout),
KUNIT_CASE(apple_sleep_test_t6050),
Expand All @@ -377,6 +507,7 @@ static struct kunit_case apple_sleep_test_cases[] = {
KUNIT_CASE(apple_sleep_test_words),
KUNIT_CASE(apple_sleep_test_books),
KUNIT_CASE(apple_sleep_test_wake_names),
KUNIT_CASE(apple_sleep_test_wdt_handoff),
{}
};

Expand Down
Loading
Loading