Skip to content
Merged
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
74 changes: 51 additions & 23 deletions drivers/soc/apple/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct aura_s2r_mailbox {
/* PS word */
#define PS_AUTO_ENABLE BIT(28)
#define PS_UNLATCH BIT(12)
#define PS_BUSY BIT(11)
#define PS_DEV_DISABLE BIT(10)
#define PS_FLAGS GENMASK(9, 8)
#define PS_ACTUAL GENMASK(7, 4)
Expand Down Expand Up @@ -3036,7 +3037,7 @@ static u32 sleep_ps_lower_start(struct apple_sleep *s, u32 offset)
u32 val = readl(reg);

if (val & PS_AUTO_ENABLE) {
val &= ~(PS_AUTO_ENABLE | PS_FLAGS);
val &= ~(PS_AUTO_ENABLE | PS_FLAGS | PS_BUSY);
writel(val, reg);
}

Expand All @@ -3045,12 +3046,33 @@ static u32 sleep_ps_lower_start(struct apple_sleep *s, u32 offset)

static void sleep_ps_lower_finish(struct apple_sleep *s, u32 offset, u32 val)
{
writel((val & ~PS_TARGET) | PS_FLAGS, sleep_power_reg(s, offset));
writel((val & ~(PS_TARGET | PS_BUSY)) | PS_FLAGS, sleep_power_reg(s, offset));
}

/* A domain the hardware idled under AUTO_ENABLE comes back once that's cleared. */
static bool sleep_ps_wait_on(struct apple_sleep *s, u32 offset, u32 val)
{
u32 target = FIELD_GET(PS_TARGET, val);

if (!target)
return false;

return !readl_poll_timeout_atomic(sleep_power_reg(s, offset), val,
FIELD_GET(PS_ACTUAL, val) == target, 1,
PS_OFF_TIMEOUT_US);
}

static void sleep_ps_lower(struct apple_sleep *s, u32 offset)
{
sleep_ps_lower_finish(s, offset, sleep_ps_lower_start(s, offset));
void __iomem *reg = sleep_power_reg(s, offset);
u32 val = readl(reg);

if (val & PS_AUTO_ENABLE) {
val &= ~(PS_AUTO_ENABLE | PS_FLAGS | PS_BUSY);
writel(val, reg);
sleep_ps_wait_on(s, offset, val);
}
sleep_ps_lower_finish(s, offset, val);
}

/*
Expand Down Expand Up @@ -3085,16 +3107,6 @@ static int sleep_ps_raise(struct apple_sleep *s, u32 offset)
return ret;
}

/* A domain the hardware idled under AUTO_ENABLE comes back once that's cleared. */
static bool sleep_ps_wait_on(struct apple_sleep *s, u32 offset, u32 val)
{
if (!FIELD_GET(PS_TARGET, val))
return false;

return !readl_poll_timeout_atomic(sleep_power_reg(s, offset), val, FIELD_GET(PS_ACTUAL, val), 1,
PS_OFF_TIMEOUT_US);
}

static int sleep_ps_wait_off(struct apple_sleep *s, u32 offset)
{
u32 val;
Expand Down Expand Up @@ -3222,7 +3234,6 @@ EXPORT_SYMBOL_GPL(apple_sleep_domain_is_down);
* target 4 and 0, released with the domain off, then raised again, its DARTs' state kept. The
* caller has cleared the run bit, and starts the firmware after.
*/
#define PS_BUSY BIT(11)
#define PS_RESET BIT(31)
#define PS_ENGINE_RESET_4 0x8f000244
#define PS_ENGINE_RESET_0 0x80000000
Expand Down Expand Up @@ -4579,34 +4590,51 @@ static void apple_sleep_lower_apcie_gen4(struct apple_sleep *s)
static void apple_sleep_lower_apcie(struct apple_sleep *s)
{
const struct apple_sleep_domains *d = &s->soc->ps;
u32 val;
u32 st_val, gp_val, phy_val;
bool st_on, gp_on, phy_on;

if (s->soc->apcie_gen4) {
apple_sleep_lower_apcie_gen4(s);
return;
}
sleep_apcie_port_stop_once(s);

/*
* Clear AUTO_ENABLE and wait for full power on apcie_sys_st,
* apcie_sys_gp, and apcie_phy_sw before touching port, PHY, clkgen,
* or AXI registers. Under hardware auto-PM an idle domain reads
* PS_ACTUAL=0 (skipping PHY/clkgen teardown) or can auto-gate
* mid-MMIO, and lowering directly from an auto-gated state can
* latch BUSY.
*/
st_val = sleep_ps_lower_start(s, d->apcie_sys_st);
st_on = sleep_ps_wait_on(s, d->apcie_sys_st, st_val);
gp_val = sleep_ps_lower_start(s, d->apcie_sys_gp);
gp_on = sleep_ps_wait_on(s, d->apcie_sys_gp, gp_val);
phy_val = sleep_ps_lower_start(s, d->apcie_phy_sw);
phy_on = sleep_ps_wait_on(s, d->apcie_phy_sw, phy_val);

if (phy_on)
sleep_apcie_port_stop_once(s);
/* The PHY's registers need both domains on. */
if (s->apcie_phy && sleep_ps_on(s, d->apcie_phy_sw) && sleep_ps_on(s, d->apcie_sys_st))
if (s->apcie_phy && phy_on && st_on)
sleep_apcie_phy_off(s);
sleep_ps_lower(s, d->apcie_phy_sw);
sleep_ps_lower_finish(s, d->apcie_phy_sw, phy_val);

if (s->apcie_clkgen && sleep_ps_on(s, d->apcie_sys_st))
if (s->apcie_clkgen && st_on)
sleep_apcie_clk_off(s);
sleep_ps_lower(s, d->apcie_sys_st);
sleep_ps_lower_finish(s, d->apcie_sys_st, st_val);
sleep_ps_lower(s, d->apcie_st);

/*
* The AXI enables are the block's link into the fabric. macOS reads the domain on
* before clearing them: powered off with them set, SoC NI 1 latches a PCIe receive
* link error once the block's last domain goes off.
*/
val = sleep_ps_lower_start(s, d->apcie_sys_gp);
if (s->apcie_axi && sleep_ps_wait_on(s, d->apcie_sys_gp, val)) {
if (s->apcie_axi && gp_on) {
writel(readl(s->apcie_axi + APCIE_AXI_EN0) & ~BIT(0), s->apcie_axi + APCIE_AXI_EN0);
writel(readl(s->apcie_axi + APCIE_AXI_EN1) & ~BIT(0), s->apcie_axi + APCIE_AXI_EN1);
}
sleep_ps_lower_finish(s, d->apcie_sys_gp, val);
sleep_ps_lower_finish(s, d->apcie_sys_gp, gp_val);

sleep_ps_lower(s, d->apcie_gp);
sleep_ps_lower(s, d->ans);
Expand Down
Loading