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 @@ -100,6 +100,13 @@ properties:
The DCP and the external DCPs, which must be off before a commit, in that
order.

apple,nco:
$ref: /schemas/types.yaml#/definitions/phandle
description:
The NCO clock block feeding the audio clock muxes. Its channels are kept
running across the commit and restored on wake, so the muxes can switch
back to them.

required:
- compatible
- reg
Expand Down Expand Up @@ -140,8 +147,9 @@ allOf:
properties:
reg:
minItems: 21
maxItems: 21
maxItems: 22
reg-names:
minItems: 21
items:
- const: ps
- const: pwrgate
Expand All @@ -164,6 +172,7 @@ allOf:
- const: apcie-phy
- const: apcie-phy-ip
- const: apcie-port0
- const: clk-mux
- if:
properties:
compatible:
Expand Down
7 changes: 5 additions & 2 deletions arch/arm64/boot/dts/apple/t8122.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,18 @@
<0x5 0x9e088000 0x0 0x3000>,
<0x5 0x9e000000 0x0 0x10000>,
<0x5 0x9e040000 0x0 0x10000>,
<0x5 0x94008000 0x0 0x5000>;
<0x5 0x94008000 0x0 0x5000>,
<0x2 0xd0040000 0x0 0x1000>;
reg-names = "ps", "pwrgate", "cpu-start", "cllt",
"cluster", "commit", "wdt", "spmi",
"spmi-hpm", "wake", "ps-aon",
"mcc-a", "mcc-b", "mcc-c", "mcc-d",
"apcie-axi", "apcie-rc", "apcie-clkgen",
"apcie-phy", "apcie-phy-ip", "apcie-port0";
"apcie-phy", "apcie-phy-ip", "apcie-port0",
"clk-mux";
apple,wake-enable = <155>;
apple,display-coprocessors = <&dcp>;
apple,nco = <&nco>;
apple,pinctrl = <&pinctrl_ap>;
status = "disabled";
};
Expand Down
186 changes: 186 additions & 0 deletions drivers/soc/apple/sleep-t8122.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,39 @@
#define T8122_CLLT_CTL 0x0
#define T8122_CLLT_LAST 0x24

/*
* The PMGR clock-mux block ("clk-mux") and the NCO block (apple,nco).
* Deep sleep resets the NCO channels and parks the four MCA audio clock
* muxes (+0xd8..+0xe4, selecting NCO0..3) back to source 0 (24 MHz
* bypass), so audio after a wake runs at 93,750 Hz (24 MHz / 256) unless
* both are restored. The NCOs must run before the commit (as on T8103)
* and be restored before the muxes are switched back on wake, or a mux
* switch never completes (BUSY, bit 30, stays set).
*/
#define T8122_CLK_MUX_ENABLE BIT(31)
#define T8122_CLK_MUX_BUSY BIT(30)
#define T8122_CLK_MUX_SEL_MASK (T8122_CLK_MUX_ENABLE | GENMASK(27, 24))
#define T8122_CLK_MUX_TIMEOUT_US 192000

#define T8122_NCO_CHANS 4 /* NCO0..3: one per audio mux */
#define T8122_NCO_REGSIZE 20
#define T8122_NCO_STRIDE 0x4000
#define T8122_NCO_REG_CTRL 0x00
#define T8122_NCO_REG_DIV 0x04
#define T8122_NCO_REG_INC1 0x08
#define T8122_NCO_REG_INC2 0x0c
#define T8122_NCO_REG_ACCINIT 0x10
#define T8122_NCO_CTRL_EN BIT(31)

/*
* Without "clk-mux" or apple,nco on the sleep node (loaders that predate
* them), the NCO block is the node matching this compatible, and the
* clock-mux block is the PMGR page T8122 places this far below it.
*/
#define T8122_NCO_COMPATIBLE "apple,t8122-nco"
#define T8122_CLK_MUX_BELOW_NCO 0x4000
#define T8122_CLK_MUX_SIZE 0x1000

#define T8122_SYS_HID4 sys_reg(3, 0, 15, 4, 0)
#define T8122_SYS_EHID4 sys_reg(3, 0, 15, 4, 1)
#define T8122_HID4_DISABLE_DC_MVA BIT_ULL(11)
Expand Down Expand Up @@ -104,7 +137,18 @@ static const struct apple_sleep_word t8122_stray[] = {
{ "spi2", 0x2a8 }, { "qspi", 0x2c8 }, { "sio_cpu", 0x210 }, { "apcie_phy_sw", 0x4a0 },
};

static const u32 t8122_audio_muxes[] = {
0xd8, 0xdc, 0xe0, 0xe4,
};

static struct {
u32 clk_mux_saved[ARRAY_SIZE(t8122_audio_muxes)];
u32 nco_saved[T8122_NCO_CHANS][4];
u8 nco_forced;
u8 nco_chans;
u8 clk_mux_commit_timeouts;
u8 clk_mux_wake_timeouts;
void __iomem *nco;
void __iomem *hpm_notify;
void __iomem *mcc[4];
void __iomem *apcie_axi;
Expand Down Expand Up @@ -536,6 +580,42 @@ static void t8122_clean_state_poc(struct apple_sleep *s)
dsb(sy);
}

/*
* The NCO block: the sleep node's apple,nco phandle, else the node matching
* T8122_NCO_COMPATIBLE. Channels come from its size; @out gets its range.
*/
static void __iomem *t8122_map_nco(struct apple_sleep *s, struct resource *out)
{
struct device_node *np = of_parse_phandle(s->dev->of_node, "apple,nco", 0);
struct resource res;
void __iomem *base;
int ret;

if (!np) {
np = of_find_compatible_node(NULL, NULL, T8122_NCO_COMPATIBLE);
if (np && !of_device_is_available(np)) {
of_node_put(np);
np = NULL;
}
if (np)
dev_info(s->dev, "no apple,nco: using %pOF\n", np);
}
if (!np)
return NULL;
ret = of_address_to_resource(np, 0, &res);
of_node_put(np);
if (ret || resource_size(&res) < T8122_NCO_REGSIZE)
return NULL;
*out = res;
t8122.nco_chans = min_t(resource_size_t, T8122_NCO_CHANS,
(resource_size(&res) - T8122_NCO_REGSIZE) / T8122_NCO_STRIDE + 1);
/* Shared with the NCO clock driver: mapped, not requested. */
base = ioremap_np(res.start, resource_size(&res));
if (base && devm_add_action_or_reset(s->dev, apple_sleep_iounmap, (void __force *)base))
return NULL;
return base;
}

static void __iomem *t8122_map(struct apple_sleep *s, const char *name, struct resource *out)
{
struct device_node *np = s->dev->of_node;
Expand Down Expand Up @@ -577,6 +657,8 @@ static int t8122_sleep_map_regs(struct apple_sleep *s)
unsigned int i;
bool pcore;
u64 hid4_orig;
struct resource nco_res;
resource_size_t mux_start;
int ret;

s->ps = t8122_map(s, "ps", &s->ps_res);
Expand All @@ -600,6 +682,27 @@ static int t8122_sleep_map_regs(struct apple_sleep *s)
s->ps_aon = NULL;
}

t8122.nco = t8122_map_nco(s, &nco_res);
if (!t8122.nco)
dev_warn(s->dev, "no NCO block: audio NCO state will not be kept across sleep\n");

s->clk_mux = t8122_map(s, "clk-mux", NULL);
if (IS_ERR(s->clk_mux) && t8122.nco &&
nco_res.start >= T8122_CLK_MUX_BELOW_NCO) {
mux_start = nco_res.start - T8122_CLK_MUX_BELOW_NCO;
/* Shared with the PMGR: mapped, not requested; never unmapped, as t8122_map(). */
s->clk_mux = ioremap_np(mux_start, T8122_CLK_MUX_SIZE);
if (s->clk_mux)
dev_info(s->dev, "no clk-mux registers: using %pa, below the NCO block\n",
&mux_start);
else
s->clk_mux = IOMEM_ERR_PTR(-ENOMEM);
}
if (IS_ERR(s->clk_mux)) {
dev_warn(s->dev, "no clk-mux registers: audio clock muxes will not be restored\n");
s->clk_mux = NULL;
}

ret = apple_sleep_read_wake_sources(s);
if (ret)
return ret;
Expand Down Expand Up @@ -917,6 +1020,39 @@ static void t8122_sleep_commit_regs(struct apple_sleep *s)
u64 hid4_orig;

sleep_ps_save(s);
t8122.nco_forced = 0;
if (t8122.nco) {
unsigned int i;

for (i = 0; i < t8122.nco_chans; i++) {
void __iomem *ch = t8122.nco + i * T8122_NCO_STRIDE;
u32 ctrl = readl(ch + T8122_NCO_REG_CTRL);

t8122.nco_saved[i][0] = ctrl;
t8122.nco_saved[i][1] = readl(ch + T8122_NCO_REG_DIV);
t8122.nco_saved[i][2] = readl(ch + T8122_NCO_REG_INC1);
t8122.nco_saved[i][3] = readl(ch + T8122_NCO_REG_INC2);
if (!(ctrl & T8122_NCO_CTRL_EN)) {
writel(BIT(31), ch + T8122_NCO_REG_ACCINIT);
writel(ctrl | T8122_NCO_CTRL_EN, ch + T8122_NCO_REG_CTRL);
readl(ch + T8122_NCO_REG_CTRL);
t8122.nco_forced |= BIT(i);
}
}
}
if (s->clk_mux) {
unsigned int i;

for (i = 0; i < ARRAY_SIZE(t8122_audio_muxes); i++) {
void __iomem *reg = s->clk_mux + t8122_audio_muxes[i];
u32 val;

if (readl_poll_timeout_atomic(reg, val, !(val & T8122_CLK_MUX_BUSY),
1, T8122_CLK_MUX_TIMEOUT_US))
t8122.clk_mux_commit_timeouts++;
t8122.clk_mux_saved[i] = val & ~T8122_CLK_MUX_BUSY;
}
}
t8122_sleep_atc_off(s);
writel(0, s->wdt + WDT_WD0_CTL);

Expand Down Expand Up @@ -1148,6 +1284,56 @@ static void t8122_sleep_wake(struct apple_sleep *s)
sleep_ps_raise(s, T8122_PS_GPIO);
s->pins_lost = s->pins_saved_valid;

if (t8122.nco) {
unsigned int i;

for (i = 0; i < t8122.nco_chans; i++) {
void __iomem *ch = t8122.nco + i * T8122_NCO_STRIDE;
u32 ctrl = t8122.nco_saved[i][0];

writel(ctrl & ~T8122_NCO_CTRL_EN, ch + T8122_NCO_REG_CTRL);
writel(t8122.nco_saved[i][1], ch + T8122_NCO_REG_DIV);
writel(t8122.nco_saved[i][2], ch + T8122_NCO_REG_INC1);
writel(t8122.nco_saved[i][3], ch + T8122_NCO_REG_INC2);
writel(BIT(31), ch + T8122_NCO_REG_ACCINIT);
writel(ctrl | T8122_NCO_CTRL_EN, ch + T8122_NCO_REG_CTRL);
readl(ch + T8122_NCO_REG_CTRL);
}
}

if (s->clk_mux) {
unsigned int i;

for (i = 0; i < ARRAY_SIZE(t8122_audio_muxes); i++) {
void __iomem *reg = s->clk_mux + t8122_audio_muxes[i];
u32 saved = t8122.clk_mux_saved[i];

if (!(saved & T8122_CLK_MUX_ENABLE))
continue;
if (!((readl(reg) ^ saved) & T8122_CLK_MUX_SEL_MASK))
continue;
writel(saved & ~T8122_CLK_MUX_BUSY, reg);
if (readl_poll_timeout_atomic(reg, val, !(val & T8122_CLK_MUX_BUSY),
1, T8122_CLK_MUX_TIMEOUT_US))
t8122.clk_mux_wake_timeouts++;
}
}

if (t8122.nco && t8122.nco_forced) {
unsigned int i;

for (i = 0; i < t8122.nco_chans; i++) {
void __iomem *ch = t8122.nco + i * T8122_NCO_STRIDE;

if (!(t8122.nco_forced & BIT(i)))
continue;
writel(t8122.nco_saved[i][0] & ~T8122_NCO_CTRL_EN,
ch + T8122_NCO_REG_CTRL);
readl(ch + T8122_NCO_REG_CTRL);
}
t8122.nco_forced = 0;
}

if (t8122.apcie_axi) {
if (!t8122_raise_apcie(s) && t8122.apcie_port0 && t8122.apcie_phy)
t8122_port0_wake(s);
Expand Down
Loading