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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ properties:
maxItems: 1
description: SEP's, PMP0's, SIO's and the DCP's DART, stopped in the sleep's last steps.

apple,entry-off-domains:
$ref: /schemas/types.yaml#/definitions/phandle-array
minItems: 1
maxItems: 4
items:
maxItems: 1
description: |
PMGR power domains the boot loader can leave on with no user while the
sleep's last phase waits for their power gates (the video encoders'
system domains). Each one found on is lowered at the entry and must go
off, or the sleep is refused.

apple,radio-pcie:
$ref: /schemas/types.yaml#/definitions/phandle
description: |
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/boot/dts/apple/t6050-j716c-sleep.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<&aop_spmi0>;
/* SEP's, PMP0's, SIO's and the DCP's DART, stopped in the sleep's last steps */
apple,sleep-darts = <&sep_dart>, <&pmp0_dart>, <&sio_dart>, <&dcp_dart>;
/* The encoders' system domains: lowered at the entry when left on with no user */
apple,entry-off-domains = <&ps_venc0_sys>, <&ps_venc1_sys>;
/* The N1's host: its link is shut down for the sleep and brought back after it */
apple,radio-pcie = <&pcie0>;
apple,pinctrl = <&pinctrl_ap>;
Expand Down
145 changes: 109 additions & 36 deletions drivers/soc/apple/sleep-t6050.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ enum {
T6050_REGIONS,
};

/* The most power words apple,entry-off-domains may name */
#define T6050_ENTRY_OFF_MAX 4

#define T6050_W(r, off) SLEEP_REGION_WORD(r, off)
#include "sleep-t6050-tables.h"
#undef T6050_W
Expand Down Expand Up @@ -106,9 +109,15 @@ struct apple_sleep_region_state {
u32 late_saved[17], state4_saved[16], pmc154_lowered;
/* AUSS and the routers' CIO_AUSS words the entry lowered, and each as it read before */
u32 auss_lowered, auss_timeouts, auss_saved[5];
/* VENC0_SYS as it read before the entry lowered it, if it did */
u32 venc0_saved;
bool venc0_lowered;
/*
* The power words the entry lowers when it finds them on (the DT's
* apple,entry-off-domains, else VENC0_SYS where the SoC asks for it), their names, which
* ones the entry lowered, and each as it read before.
*/
u32 entry_off[T6050_ENTRY_OFF_MAX], entry_off_saved[T6050_ENTRY_OFF_MAX];
const char *entry_off_name[T6050_ENTRY_OFF_MAX];
unsigned int nentry_off;
u32 entry_off_lowered;
/* The idle words the last refusal switched off and on again: their blocks' registers are at reset */
u32 refusal_cycled;
/* Type-C ports, by port index, whose always-on USB word the last entry left on. */
Expand Down Expand Up @@ -1098,6 +1107,8 @@ static unsigned int t6050_ops_run(struct apple_sleep *s, const struct t6050_ops
return timeouts;
}

static int t6050_entry_off_get(struct apple_sleep *s);

/* The shared PHY's blocks, then every sequence the DT gives */
static int t6050_sleep_map_ops(struct apple_sleep *s)
{
Expand All @@ -1120,7 +1131,8 @@ static int t6050_sleep_map_ops(struct apple_sleep *s)
t6050_ops_get(s, "apple,radio-dart-wake", &r->dart_wake) ?:
t6050_ops_get(s, "apple,radio-phy-wake", &r->phy_wake) ?:
t6050_ops_get(s, "apple,phy-park", &r->phy_park) ?:
t6050_ops_get(s, "apple,phy-down", &r->phy_down);
t6050_ops_get(s, "apple,phy-down", &r->phy_down) ?:
t6050_entry_off_get(s);
}

static void t6050_seq(struct apple_sleep *s, unsigned int seq)
Expand Down Expand Up @@ -1692,7 +1704,7 @@ static int t6050_sleep_begin(struct apple_sleep *s)
r->committed = false;
r->early_done = false;
r->early_dropped = false;
r->venc0_lowered = false;
r->entry_off_lowered = 0;
r->wake_status_valid = false;
r->wake_status_fresh = false;
r->spmi_src_valid = false;
Expand Down Expand Up @@ -2285,48 +2297,108 @@ static void t6050_auss_restore(struct apple_sleep *s)
}

/*
* VENC0_SYS, the first video encoder's system word. On the J716c it reads 0x0f0003ff (on, no
* automatic state) at the commit, with no Linux user, while every other media word of the GPU
* die is off or under automatic power; and the entry's last phase waits for its power gate.
* It is lowered at the entry, after AUSS, and polled off: one that does not go off refuses the
* sleep. A refusal puts it back as it read before; after a sleep the snapshot's replay raises
* it again.
* Power words the boot loader can leave on with no Linux user, while the entry's last phase
* waits for their power gates: the video encoders' system words, which the loader raises to
* program the encoder DARTs' filters and leaves up. On the J716c VENC0_SYS reads 0x0f0003ff
* (on, no automatic state) before the entry, and VENC1_SYS too since the loader programs the
* second encoder's filter, while every other media word of the GPU die is off or under
* automatic power. Each one that reads on with no automatic mode is lowered at the entry, after
* AUSS, and polled off: one that does not go off refuses the sleep. A refusal puts back the
* saved target of each one lowered; after a sleep the snapshot's replay raises them again. A
* word that reads off (Linux already powered it down) or is under automatic power (its owner's)
* is left alone.
*
* The DT names them (apple,entry-off-domains). A DT without the property gets VENC0_SYS where
* the SoC asks for it (lower_venc0), as before.
*/
#define T6050_VENC0_SYS SLEEP_REGION_WORD(T6050_PS_MEDIA, 0x1c0)

static int t6050_venc0_lower(struct apple_sleep *s)
static int t6050_entry_off_get(struct apple_sleep *s)
{
struct apple_sleep_region_state *r = s->region;
struct device_node *np = s->dev->of_node;
int n, i, word;

r->nentry_off = 0;
if (!of_property_present(np, "apple,entry-off-domains")) {
if (s->soc->lower_venc0) {
r->entry_off[0] = T6050_VENC0_SYS;
r->entry_off_name[0] = "VENC0_SYS";
r->nentry_off = 1;
}
return 0;
}
/* Present: one to T6050_ENTRY_OFF_MAX whole phandles, each a power word here */
n = of_count_phandle_with_args(np, "apple,entry-off-domains", NULL);
if (n < 1 || n > T6050_ENTRY_OFF_MAX ||
of_property_count_u32_elems(np, "apple,entry-off-domains") != n)
return dev_err_probe(s->dev, -EINVAL, "invalid apple,entry-off-domains\n");
for (i = 0; i < n; i++) {
struct device_node *pd __free(device_node) =
of_parse_phandle(np, "apple,entry-off-domains", i);
const char *name;

word = pd ? sleep_region_domain_offset(s, pd) : -EINVAL;
if (word < 0)
return dev_err_probe(s->dev, -EINVAL,
"apple,entry-off-domains[%d]: not a power word\n", i);
if (of_property_read_string(pd, "label", &name))
name = pd->name;
r->entry_off[i] = word;
r->entry_off_name[i] = devm_kstrdup(s->dev, name, GFP_KERNEL);
if (!r->entry_off_name[i])
return -ENOMEM;
}
r->nentry_off = n;
return 0;
}

static int t6050_entry_off_lower(struct apple_sleep *s)
{
struct apple_sleep_region_state *r = s->region;
unsigned int i;
int ret;

r->venc0_lowered = false;
if (!s->soc->lower_venc0 || !t6050_late_word_on(s, T6050_VENC0_SYS))
return 0;
r->venc0_saved = readl(sleep_region_reg(s, T6050_VENC0_SYS));
sleep_ps_lower(s, T6050_VENC0_SYS);
r->venc0_lowered = true;
ret = sleep_ps_wait_off(s, T6050_VENC0_SYS);
if (ret) {
dev_warn(s->dev, "entry: VENC0_SYS %#x -> %#x, not off: refusing the sleep\n",
r->venc0_saved, readl(sleep_region_reg(s, T6050_VENC0_SYS)));
return ret;
r->entry_off_lowered = 0;
for (i = 0; i < r->nentry_off; i++) {
u32 word = r->entry_off[i];

if (!t6050_late_word_on(s, word) ||
(readl(sleep_region_reg(s, word)) & PS_AUTO_ENABLE))
continue;
r->entry_off_saved[i] = readl(sleep_region_reg(s, word));
sleep_ps_lower(s, word);
r->entry_off_lowered |= BIT(i);
ret = sleep_ps_wait_off(s, word);
if (ret) {
dev_warn(s->dev, "entry: %s %#x -> %#x, not off: refusing the sleep\n",
r->entry_off_name[i], r->entry_off_saved[i],
readl(sleep_region_reg(s, word)));
return ret;
}
dev_info(s->dev, "entry: %s %#x -> %#x\n", r->entry_off_name[i],
r->entry_off_saved[i], readl(sleep_region_reg(s, word)));
}
dev_info(s->dev, "entry: VENC0_SYS %#x -> %#x\n", r->venc0_saved,
readl(sleep_region_reg(s, T6050_VENC0_SYS)));
return 0;
}

/* After a refusal: VENC0_SYS as it read before the entry lowered it */
static void t6050_venc0_restore(struct apple_sleep *s)
/* After a refusal: each word the entry lowered, as it read before */
static void t6050_entry_off_restore(struct apple_sleep *s)
{
struct apple_sleep_region_state *r = s->region;
unsigned int i;

if (!r->venc0_lowered)
return;
if (sleep_ps_restore(sleep_region_reg(s, T6050_VENC0_SYS), r->venc0_saved))
dev_warn(s->dev, "refusal: VENC0_SYS not back: reads %#x, was %#x\n",
readl(sleep_region_reg(s, T6050_VENC0_SYS)), r->venc0_saved);
r->venc0_lowered = false;
for (i = r->nentry_off; i-- > 0;) {
u32 word = r->entry_off[i];

if (!(r->entry_off_lowered & BIT(i)))
continue;
if (sleep_ps_restore(sleep_region_reg(s, word), r->entry_off_saved[i]))
dev_warn(s->dev, "refusal: %s not back: reads %#x, was %#x\n",
r->entry_off_name[i], readl(sleep_region_reg(s, word)),
r->entry_off_saved[i]);
}
r->entry_off_lowered = 0;
}

/*
Expand All @@ -2343,7 +2415,7 @@ static int t6050_sleep_entry_lower(struct apple_sleep *s)
for (i = 0; i < T6050_LATE_ENTRY_END; i++)
t6050_late_lower(s, i);
t6050_auss_lower(s);
ret = t6050_venc0_lower(s);
ret = t6050_entry_off_lower(s);
if (ret)
return ret;
for (i = 0; i < ARRAY_SIZE(t6050_state4); i++) {
Expand Down Expand Up @@ -3403,7 +3475,7 @@ static void t6050_sleep_refusal_raise(struct apple_sleep *s)
}
}
r->state4_set = 0;
t6050_venc0_restore(s);
t6050_entry_off_restore(s);
/* AUSS and its children: between the caps and the idle words, as the entry had them */
t6050_auss_restore(s);
for (i = ARRAY_SIZE(t6050_late_off); i-- > 0;) {
Expand Down Expand Up @@ -4097,7 +4169,8 @@ static const struct apple_sleep_ops t6050_j716c_sleep_ops = {

/*
* The J716c (M5 Max): the J714s's entry and wake over the Max inventory. The Max's own power
* words (the second encoder, AMCC16-31) are in no list the entry lowers: saved at the entry
* words (the second encoder, AMCC16-31) are in no list the entry lowers, except the second
* encoder's system word where the DT names it (apple,entry-off-domains): saved at the entry
* and put back at the wake if they dropped. No PMP runs on this board.
*/
static const struct apple_sleep_soc t6050_j716c_sleep_soc = {
Expand Down
Loading