diff --git a/drivers/soc/apple/sleep-t6030.h b/drivers/soc/apple/sleep-t6030.h index 3e0ce1d3d2bc..b43da9938464 100644 --- a/drivers/soc/apple/sleep-t6030.h +++ b/drivers/soc/apple/sleep-t6030.h @@ -607,6 +607,23 @@ static const struct apple_sleep_words t6030_wake_mid_words = SLEEP_WORDS(t6030_p static const struct apple_sleep_words t6030_wake_late_words = SLEEP_WORDS(t6030_ps_wake_late); static const u32 t6030_i2c6_regs[] = { 0x38, 0x30, 0x2c }; +/* + * "mca-switch": the MCA audio clock muxes. The boot loader points mux i at NCO + * channel i (source 5 + i: aura's clk_set_mca_muxes(), from ADT + * /arm-io/mca-switch reg[2]); at source 0 the MCA clusters run from the 24 MHz + * reference and audio plays about 7 times too fast. A mux finishes a switch, + * clearing T6030_MCA_SWITCH_BUSY, only while the source it leaves runs. + */ +#define T6030_MCA_SWITCHES 4 +#define T6030_MCA_SWITCH_SRC GENMASK(27, 24) +#define T6030_MCA_SWITCH_BUSY BIT(30) +#define T6030_MCA_SWITCH_SRC_NCO0 5 +#define T6030_MCA_SWITCH_POLL_US 100 +#define T6030_NCO_COMPATIBLE "apple,t6030-nco" +#define T6030_NCO_CHANS 5 +#define T6030_NCO_STRIDE 0x4000 +#define T6030_NCO_CTRL_EN BIT(31) + struct t6030_ps_wake_sample { u32 before, saved, active, after; u32 us; @@ -625,7 +642,7 @@ static struct t6030_sleep { int gp_park_ret; void __iomem *ptd_read, *ptd_update, *ptd_ctrl; - void __iomem *pmp_mbox, *mtp_dart, *dart_sep, *i2c6, *mca_switch; + void __iomem *pmp_mbox, *mtp_dart, *dart_sep, *i2c6, *mca_switch, *nco; void __iomem *cpm[2]; void __iomem *slc_multicast[2]; void __iomem *qblk[T6030_QBLK_COUNT]; @@ -639,6 +656,9 @@ static struct t6030_sleep { u32 i2c6_regs_saved[ARRAY_SIZE(t6030_i2c6_regs)]; bool i2c6_ps_staged; bool i2c6_saved; + u32 mca_switch_saved[T6030_MCA_SWITCHES]; + bool mca_switch_saved_valid; + unsigned int mca_switch_stuck; u32 notify_saved[2]; bool notify_staged; @@ -1797,6 +1817,20 @@ static void __iomem *t6030_map_phandle(struct apple_sleep *s, const char *prop, return base; } +/* The NCO block, shared with its clock driver: mapped, not requested. */ +static void __iomem *t6030_map_nco(struct apple_sleep *s) +{ + struct device_node *np = of_find_compatible_node(NULL, NULL, T6030_NCO_COMPATIBLE); + void __iomem *base = NULL; + struct resource res; + + if (np && of_device_is_available(np) && !of_address_to_resource(np, 0, &res) && + resource_size(&res) >= (T6030_NCO_CHANS - 1) * T6030_NCO_STRIDE + 4) + base = t6030_ioremap(s->dev, &res); + of_node_put(np); + return base; +} + static void t6030_gp_map(struct apple_sleep *s) { struct device_node *host = of_parse_phandle(s->dev->of_node, "apple,pcie-host", 0); @@ -1873,8 +1907,6 @@ static void t6030_replay_pulse(struct device *dev, void __iomem *ps, u32 off, static void t6030_boot_replay(struct apple_sleep *s) { - unsigned int i; - /* DWI boot pulse */ writel(0x340, s->ps + T6030_PS_DWI); readl(s->ps + T6030_PS_DWI); @@ -1886,14 +1918,6 @@ static void t6030_boot_replay(struct apple_sleep *s) writel(0x1000000f, s->ps + T6030_PS_DWI); readl(s->ps + T6030_PS_DWI); - /* MCA audio-clock switches */ - if (t6030.mca_switch) { - for (i = 0; i < 4; i++) { - writel(0, t6030.mca_switch + 4 * i); - readl(t6030.mca_switch + 4 * i); - } - } - /* * ATC2_PCIE, then ATC1_PCIE. Built-in apple-sleep relies on drivers/Makefile * link order (drivers/soc/ before drivers/pmdomain/, drivers/spmi/, and @@ -2024,6 +2048,7 @@ static int t6030_sleep_map_regs(struct apple_sleep *s) t6030_gp_map(s); t6030.pmp_mbox = t6030_map_node_name(s, np, "pmp-mbox"); t6030.mca_switch = t6030_map_node_name(s, np, "mca-switch"); + t6030.nco = t6030_map_nco(s); t6030.dart_sep = t6030_map_phandle(s, "apple,sep-dart", 0); t6030.mtp_dart = t6030_map_phandle(s, "apple,mtp-dart", 0); t6030.i2c6 = t6030_map_phandle(s, "apple,i2c6", 0); @@ -2272,6 +2297,32 @@ static void t6030_sleep_undo_regs(struct apple_sleep *s) t6030.pcie_host_owned = false; } +/* + * Park MCA clock mux i on source 0 for the commit, the state every J516s wake + * was tested with. The NCO channel it leaves is stopped while audio is idle, + * so run that channel until the switch is done, then put its control back. + */ +static void t6030_mca_switch_park(unsigned int i) +{ + void __iomem *reg = t6030.mca_switch + 4 * i; + void __iomem *ctrl = NULL; + u32 v = readl(reg), src = FIELD_GET(T6030_MCA_SWITCH_SRC, v), nco = 0; + + t6030.mca_switch_saved[i] = v; + if (t6030.nco && src >= T6030_MCA_SWITCH_SRC_NCO0 && + src < T6030_MCA_SWITCH_SRC_NCO0 + T6030_NCO_CHANS) { + ctrl = t6030.nco + (src - T6030_MCA_SWITCH_SRC_NCO0) * T6030_NCO_STRIDE; + nco = readl(ctrl); + writel(nco | T6030_NCO_CTRL_EN, ctrl); + } + writel(0, reg); + if (readl_poll_timeout_atomic(reg, v, !(v & T6030_MCA_SWITCH_BUSY), 1, + T6030_MCA_SWITCH_POLL_US)) + t6030.mca_switch_stuck++; + if (ctrl) + writel(nco, ctrl); +} + static void t6030_sleep_after_ans(struct apple_sleep *s) { unsigned int i; @@ -2308,6 +2359,10 @@ static void t6030_sleep_after_ans(struct apple_sleep *s) } writel(T6030_LAST_I2C6, s->ps + T6030_PS_I2C6); readl(s->ps + T6030_PS_I2C6); + t6030.mca_switch_stuck = 0; + t6030.mca_switch_saved_valid = !!t6030.mca_switch; + for (i = 0; t6030.mca_switch && i < T6030_MCA_SWITCHES; i++) + t6030_mca_switch_park(i); t6030.notify_saved[0] = readl(s->spmi_a0 + SPMI_NOTIFY_ENABLE); t6030.notify_saved[1] = readl(s->spmi + SPMI_NOTIFY_ENABLE); t6030.notify_staged = true; @@ -3156,6 +3211,16 @@ static void t6030_sleep_wake(struct apple_sleep *s) } } } + /* Back to the boot loader's sources; each switch finishes when its NCO channel runs. */ + if (t6030.mca_switch_saved_valid) { + t6030.mca_switch_saved_valid = false; + for (i = 0; i < T6030_MCA_SWITCHES; i++) + writel(t6030.mca_switch_saved[i] & ~T6030_MCA_SWITCH_BUSY, + t6030.mca_switch + 4 * i); + if (t6030.mca_switch_stuck) + dev_warn(s->dev, "T6030: %u MCA clock mux(es) did not park for the commit\n", + t6030.mca_switch_stuck); + } t6030_ps_aon_back(s); t6030_ps_finish_display_off(s); if (t6030.gate_dispext1_staged) {