diff --git a/Documentation/devicetree/bindings/iio/imu/apple,s5l8960x-oscar.yaml b/Documentation/devicetree/bindings/iio/imu/apple,s5l8960x-oscar.yaml index 8da0958950f6af..eff1d4cec1e93f 100644 --- a/Documentation/devicetree/bindings/iio/imu/apple,s5l8960x-oscar.yaml +++ b/Documentation/devicetree/bindings/iio/imu/apple,s5l8960x-oscar.yaml @@ -34,6 +34,11 @@ properties: sensors-supply: description: Sensor supply (Apple's sensor_power). + clk32-supply: + description: + PMIC 32 kHz clock output the M7 runs from, where the PMIC does not have + it on already (Apple's oscar1_clock, on the iPad mini 3). + reset-gpios: maxItems: 1 diff --git a/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml b/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml index 5db8a1d3511240..c99d6d61c237ee 100644 --- a/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml @@ -33,6 +33,7 @@ properties: - apple,antigua-touch-core-regulator - apple,august-touch-analog-regulator - apple,chestnut-touch-hv-regulator + - apple,d2089-oscar-clk32-regulator - apple,d2089-oscar-core-regulator - apple,d2089-oscar-io-regulator - apple,d2089-oscar-sensors-regulator diff --git a/arch/arm64/boot/dts/apple/s5l8960x-mini3.dtsi b/arch/arm64/boot/dts/apple/s5l8960x-mini3.dtsi index 4e397b3d7d7ad3..e23723c3a2bf9f 100644 --- a/arch/arm64/boot/dts/apple/s5l8960x-mini3.dtsi +++ b/arch/arm64/boot/dts/apple/s5l8960x-mini3.dtsi @@ -12,3 +12,23 @@ * to no differentiation between these 2 for now. */ #include "s5l8960x-mini2.dtsi" + +/* + * Apple's device tree gives the mini 3's M7 (not the mini 2's) a clock + * function, oscar1_clock = , which iOS applies to + * the PMIC's first 32 kHz clock output register (0x400, 0x79 off, 0x49 on) + * before it boots the M7. This PMIC leaves it off; the M7 firmware halts with + * "PMU 32kclk is not working" until it is on. + */ +&{/soc/i2c@20a110000/pmic@3c} { + oscar_clk32: regulator-oscar-clk32 { + compatible = "apple,d2089-oscar-clk32-regulator"; + regulator-name = "oscar-clk32"; + }; +}; + +&serial4 { + motion-coprocessor { + clk32-supply = <&oscar_clk32>; + }; +}; diff --git a/drivers/iio/imu/apple-oscar.c b/drivers/iio/imu/apple-oscar.c index 69c5fa36bbc49e..c2493f5965f164 100644 --- a/drivers/iio/imu/apple-oscar.c +++ b/drivers/iio/imu/apple-oscar.c @@ -155,8 +155,10 @@ struct oscar { struct serdev_device *serdev; struct device *dev; struct regulator *core, *io, *sensors; + /* PMIC 32 kHz clock output, on boards whose PMIC leaves it off */ + struct regulator *clk32; struct gpio_desc *reset; - bool core_on, io_on, sensors_on; + bool core_on, io_on, sensors_on, clk32_on; const struct oscar_variant *variant; const char *fw_name; @@ -836,6 +838,9 @@ static void oscar_power_off(struct oscar *o) regulator_disable(o->io); if (o->core_on) regulator_disable(o->core); + if (o->clk32_on) + regulator_disable(o->clk32); + o->clk32_on = false; o->sensors_on = false; o->io_on = false; o->core_on = false; @@ -977,6 +982,18 @@ static int oscar_boot(struct oscar *o, const u8 *image, size_t size) memset(o->line, 0, sizeof(o->line)); spin_unlock_irqrestore(&o->lock, flags); + /* + * The M7 firmware checks its 32 kHz clock at start and halts with + * "PMU 32kclk is not working" without it. Where the PMIC leaves that + * output off (the iPad mini 3), it has to be on before the M7 boots; + * the order against the supplies is not known from iOS, and untested. + */ + if (o->clk32) { + ret = regulator_enable(o->clk32); + if (ret) + goto fail; + o->clk32_on = true; + } ret = regulator_enable(o->core); if (ret) goto fail; @@ -1146,6 +1163,12 @@ static int oscar_probe(struct serdev_device *serdev) o->sensors = devm_regulator_get(dev, "sensors"); if (IS_ERR(o->sensors)) return dev_err_probe(dev, PTR_ERR(o->sensors), "sensors supply\n"); + o->clk32 = devm_regulator_get_optional(dev, "clk32"); + if (IS_ERR(o->clk32)) { + if (PTR_ERR(o->clk32) != -ENODEV) + return dev_err_probe(dev, PTR_ERR(o->clk32), "clk32 supply\n"); + o->clk32 = NULL; + } o->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(o->reset)) return dev_err_probe(dev, PTR_ERR(o->reset), "reset GPIO\n"); diff --git a/drivers/regulator/apple-pmic-touch-regulator.c b/drivers/regulator/apple-pmic-touch-regulator.c index 2b71e2b38ff6e2..523358d40f2b69 100644 --- a/drivers/regulator/apple-pmic-touch-regulator.c +++ b/drivers/regulator/apple-pmic-touch-regulator.c @@ -96,6 +96,28 @@ static const struct regulator_desc apple_d2089_oscar_io = { .disable_val = 0, }; +/* + * The 32 kHz clock output the M7 runs from on the iPad mini 3: Apple's device + * tree gives that board (not the mini 2) function-oscar1_clock = . iOS 12.5.8's 'GPIc' function applies (mask 0xfb, value + * 0x49 on or 0x79 off) to a PMIC register that its index 0 selects. That + * index-to-register mapping was not found in iOS; register 0x400 (0x79 at + * boot, next to 0x401 at 0x49) was inferred from a register dump and + * confirmed on an iPad mini 3: with it at 0x49 the M7 boots, without it the + * firmware halts with "PMU 32kclk is not working". A clock provider would be + * the usual form for a PMIC clock output; this follows the other M7 switches. + */ +static const struct regulator_desc apple_d2089_oscar_clk32 = { + .name = "d2089-oscar-clk32", + .ops = &apple_pmic_touch_regulator_ops, + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .enable_reg = 0x400, + .enable_mask = 0xfb, + .enable_val = 0x49, + .disable_val = 0x79, +}; + static const struct regulator_desc apple_d2089_oscar_sensors = { .name = "d2089-oscar-sensors", .ops = &apple_pmic_touch_regulator_ops, @@ -392,6 +414,10 @@ static const struct of_device_id apple_pmic_touch_regulator_of_match[] = { .compatible = "apple,d2089-touch-core-regulator", .data = &apple_d2089_touch_core, }, + { + .compatible = "apple,d2089-oscar-clk32-regulator", + .data = &apple_d2089_oscar_clk32, + }, { .compatible = "apple,d2089-oscar-core-regulator", .data = &apple_d2089_oscar_core,