diff --git a/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml b/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml index 663c43b67f..e70bda177c 100644 --- a/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml +++ b/Documentation/devicetree/bindings/display/samsung/google,gs201-dsim.yaml @@ -14,14 +14,19 @@ description: pipeline. It takes pixel data from a DECON and drives up to four data lanes through a combined D-PHY/C-PHY, in video or command mode, with DSC slice packing and TE-based command scheduling. Panels are described - as child nodes. + as child nodes. The Tensor G4 (zumapro) has the same DSIM, at the same + register layout. allOf: - $ref: /schemas/display/dsi-controller.yaml# properties: compatible: - const: google,gs201-dsim + oneOf: + - const: google,gs201-dsim + - items: + - const: google,zumapro-dsim + - const: google,gs201-dsim reg: minItems: 1 diff --git a/Documentation/devicetree/bindings/gpio/maxim,max77779-pmic.yaml b/Documentation/devicetree/bindings/gpio/maxim,max77779-pmic.yaml new file mode 100644 index 0000000000..d6ea8eb63f --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/maxim,max77779-pmic.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/maxim,max77779-pmic.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim Integrated MAX77779 PMIC block (SGPIO) + +maintainers: + - W4HO <87742609+W4HO-ham@users.noreply.github.com> + +description: | + The MAX77779 interface PMIC is a set of I2C blocks on one chip: the + charger (maxim,max77779-charger), the fuel gauge (maxim,max77779-fg), the + Type-C port controller (maxim,max77779-tcpc) and the PMIC block, which + owns the chip's interrupt line and eight SGPIO pins with interrupt + support. This binding describes the PMIC block. + +properties: + compatible: + const: maxim,max77779-pmic + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: The chip's interrupt line (INTB), active low. + + "#gpio-cells": + const: 2 + + gpio-controller: true + + gpio-line-names: + minItems: 1 + maxItems: 8 + + "#interrupt-cells": + const: 2 + + interrupt-controller: true + +required: + - compatible + - reg + - "#gpio-cells" + - gpio-controller + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@66 { + compatible = "maxim,max77779-pmic"; + reg = <0x66>; + interrupt-parent = <&gpa8>; + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + }; diff --git a/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml b/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml index fbf2b14f69..a1d4603a57 100644 --- a/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml +++ b/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml @@ -26,6 +26,11 @@ properties: - st,st54l - const: nxp,nxp-nci-i2c + clocks: + maxItems: 1 + description: The controller's reference clock, or the SoC clock pad + that feeds it on the controller's request + enable-gpios: description: Output GPIO pin used for enabling/disabling the controller diff --git a/Documentation/devicetree/bindings/power/supply/maxim,max77779-charger.yaml b/Documentation/devicetree/bindings/power/supply/maxim,max77779-charger.yaml index 0842c0d00a..73fc0b349e 100644 --- a/Documentation/devicetree/bindings/power/supply/maxim,max77779-charger.yaml +++ b/Documentation/devicetree/bindings/power/supply/maxim,max77779-charger.yaml @@ -32,6 +32,25 @@ properties: description: The charger's interrupt, through the PMIC's interrupt controller. + otg-boost-supply: + description: An external boost that supplies VBUS to a device on the + USB port. For host mode the charger is put in standby and this + supply is enabled. + + chgin-otg-regulator: + type: object + $ref: /schemas/regulator/regulator.yaml# + unevaluatedProperties: false + description: VBUS out of the charger's input (CHGIN) for a device on + the USB port, the supply of the Type-C controller's vbus. Only the + Type-C controller turns it on, after it has seen VBUS at vSafe0V. + properties: + regulator-always-on: false + regulator-boot-on: false + +dependentRequired: + chgin-otg-regulator: [ otg-boost-supply ] + required: - compatible - reg @@ -47,6 +66,11 @@ examples: charger: charger@69 { compatible = "maxim,max77779-charger"; reg = <0x69>; + otg-boost-supply = <&otg_boost>; + + chgin-otg-regulator { + regulator-name = "chgin-otg"; + }; }; fuel-gauge@36 { diff --git a/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml b/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml index 2f273e9e5a..e9060543b9 100644 --- a/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/exynos-pmu.yaml @@ -63,6 +63,9 @@ properties: '#clock-cells': const: 1 + description: + On the Exynos SoCs, one clock per CLKOUT mux input. On google,zuma-pmu, + clock 0 is the NFC controller's reference clock pad. clock-names: description: diff --git a/MAINTAINERS b/MAINTAINERS index 4841af951f..294fc06121 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16200,6 +16200,13 @@ F: Documentation/devicetree/bindings/power/supply/maxim,max77779-fg.yaml F: drivers/power/supply/max77779_battery.c F: drivers/power/supply/max77779_charger.c +MAXIM MAX77779 PMIC SGPIO DRIVER +M: W4HO <87742609+W4HO-ham@users.noreply.github.com> +L: linux-gpio@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/gpio/maxim,max77779-pmic.yaml +F: drivers/gpio/gpio-max77779.c + MAXIM MAX77802 PMIC REGULATOR DEVICE DRIVER M: Javier Martinez Canillas L: linux-kernel@vger.kernel.org diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-reserved-memory.dtsi b/arch/arm64/boot/dts/exynos/google/zumapro-reserved-memory.dtsi index 66157671ca..c170f24228 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro-reserved-memory.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zumapro-reserved-memory.dtsi @@ -176,10 +176,17 @@ no-map; }; - /* Reserve only; the pstore consumer is not enabled yet. */ + /* + * Stock's ramoops region. zumapro's bootloader keeps it across + * a watchdog reset (it also writes its own log at the start of + * the console zone). + */ ramoops_reserved: ramoops@fd3ff000 { + compatible = "ramoops"; reg = <0x0 0xfd3ff000 0x00400000>; no-map; + console-size = <0x200000>; + pmsg-size = <0x200000>; }; /* Not in Google's list; kept reserved until shown unused. */ diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts index c8e150e529..2c3193fe4a 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts @@ -8,8 +8,11 @@ /dts-v1/; +#include #include #include +#include +#include #include "../exynos-pinctrl.h" #include "zumapro.dtsi" #include "zumapro-reserved-memory.dtsi" @@ -73,6 +76,68 @@ }; }; + /* + * The GPU's levels: the shader rates of the Pixel 9a's GPU DVFS table + * up to 890 MHz, each with its paired L2 rate through the ACPM "gpu" + * clock; gpu-thermal throttles them from 85 C. 940 MHz, the table's + * top, is left out until it has run on the 9a. + */ + gpu_opp: opp-table-gpu { + compatible = "operating-points-v2"; + + opp-150000000 { + opp-hz = /bits/ 64 <150000000>; + }; + + opp-302000000 { + opp-hz = /bits/ 64 <302000000>; + }; + + opp-337000000 { + opp-hz = /bits/ 64 <337000000>; + }; + + opp-376000000 { + opp-hz = /bits/ 64 <376000000>; + }; + + opp-419000000 { + opp-hz = /bits/ 64 <419000000>; + }; + + opp-467000000 { + opp-hz = /bits/ 64 <467000000>; + }; + + opp-521000000 { + opp-hz = /bits/ 64 <521000000>; + }; + + opp-580000000 { + opp-hz = /bits/ 64 <580000000>; + }; + + opp-649000000 { + opp-hz = /bits/ 64 <649000000>; + }; + + opp-723000000 { + opp-hz = /bits/ 64 <723000000>; + }; + + opp-807000000 { + opp-hz = /bits/ 64 <807000000>; + }; + + opp-850000000 { + opp-hz = /bits/ 64 <850000000>; + }; + + opp-890000000 { + opp-hz = /bits/ 64 <890000000>; + }; + }; + /* UFS VCC, switched by gpp0-1 as on stock. */ ufs_vcc: regulator-ufs-vcc { compatible = "regulator-fixed"; @@ -95,6 +160,15 @@ reg = <0x0 0xfac00000 0x009fc900>; no-map; }; + + /* DECON's scanout buffers, below 4 GiB for its 32-bit DMA. */ + display_pool: display-pool { + compatible = "shared-dma-pool"; + reusable; + size = <0x04000000>; + alignment = <0x0 0x00200000>; + alloc-ranges = <0x0 0x98000000 0x06000000>; + }; }; &acpm_ipc { @@ -135,6 +209,10 @@ status = "okay"; }; +&cmu_g3d { + status = "okay"; +}; + &cmu_hsi0 { status = "okay"; }; @@ -163,6 +241,52 @@ status = "okay"; }; +/* + * DECON0 scans out to DSIM0, so gs-decon can switch the link and the + * panel between 60 and 120 Hz. + */ +&decon0 { + memory-region = <&display_pool>, <&cont_splash_mem>; + memory-region-names = "pool", "boot-framebuffer"; + status = "okay"; + + port { + decon0_out: endpoint { + remote-endpoint = <&dsi0_in>; + }; + }; +}; + +&dsi0 { + status = "okay"; + + panel@0 { + compatible = "google,tg4c"; + reg = <0>; + }; + + port { + dsi0_in: endpoint { + remote-endpoint = <&decon0_out>; + }; + }; +}; + +/* + * The ST54L's chip enable (gpa0-1) powers the whole chip, NFC and its + * secure element; stock's eSE driver raises it at probe + * (ese_chip_enable-gpio in Google's GPL zuma-tegu-ese.dtsi). Nothing here + * drives the eSE, so hold it high. + */ +&gpa0 { + nfc-chip-enable-hog { + gpio-hog; + gpios = <1 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "nfc-chip-enable"; + }; +}; + /* The keys' banks and the touchscreen's raise their own interrupts. */ &gpa4 { interrupt-controller; @@ -182,14 +306,225 @@ ; }; +/* The NFC controller's interrupt (gpa7-5). */ +&gpa7 { + interrupt-controller; + #interrupt-cells = <2>; + interrupts = , + , + , + , + , + , + , + ; +}; + +/* The USB-C port controller's (gpa8-3) and the MAX77779's (gpa8-0) interrupts. */ +&gpa8 { + interrupt-controller; + #interrupt-cells = <2>; + interrupts = , + , + , + ; +}; + &gpn0 { interrupt-controller; #interrupt-cells = <2>; interrupts = ; }; +/* + * The GPU's core clock is ACPM's paired "gpu" clock, which sets the shader + * (G3D) and L2 (G3DL2) domains together; coregroup and stacks stay on + * CMU_G3D's gates. + */ +&gpu { + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_GPU>, + <&cmu_g3d CLK_GOUT_G3D_COREGROUP>, + <&cmu_g3d CLK_GOUT_G3D_STACKS>; + operating-points-v2 = <&gpu_opp>; + status = "okay"; +}; + +/* The torch: a TI LM3644 flash driver, both LED outputs on one white LED. */ +&hsi2c4 { + clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c4_bus>; + status = "okay"; + + led-controller@63 { + compatible = "ti,lm3644"; + reg = <0x63>; + enable-gpios = <&gpp24 1 GPIO_ACTIVE_HIGH>; + pinctrl-names = "default"; + pinctrl-0 = <&torch_enable>; + + led { + function = LED_FUNCTION_TORCH; + color = ; + led-sources = <1 2>; + /* A dim flashlight, far below the part's and the LED's limits. */ + led-max-microamp = <75000>; + }; + }; +}; + +/* + * The MAX77779's bus: its fuel gauge, its charger and its USB-C port + * controller. Bring-up, not for merge: the port is dual-role, sourcing VBUS + * from the charger's chgin-otg regulator over the RT9470's OTG boost (the + * charger in standby, then the boost, as Google's ext-otg-only use case), + * and its data role drives dwc3's role switch. + */ +&hsi2c6 { + clock-frequency = <950000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c6_bus>; + status = "okay"; + + usb_tcpc: tcpc@25 { + compatible = "maxim,max77779-tcpc"; + reg = <0x25>; + interrupt-parent = <&gpa8>; + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names = "default"; + pinctrl-0 = <&usb_pd_irq>; + vbus-supply = <&chgin_otg>; + + connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + self-powered; + op-sink-microwatt = <2600000>; + sink-pdos = ; + /* + * 5 V, 900 mA is stock's (zuma/max777x9-tcpc.dtsi: "Extboost + * can only do ~1A", set to 900 mA). Stock also sets + * PDO_FIXED_SUSPEND and PDO_FIXED_DUAL_ROLE; the 10-28 run + * advertised only these two flags, so they stay here as the + * record of that run. The mergeable board takes stock's set. + */ + source-pdos = ; + + port { + typec_hs: endpoint { + remote-endpoint = <&usb_hs>; + }; + }; + }; + }; + + charger@69 { + compatible = "maxim,max77779-charger"; + reg = <0x69>; + otg-boost-supply = <&otg_boost>; + + chgin_otg: chgin-otg-regulator { + regulator-name = "chgin-otg"; + }; + }; + + fuel_gauge: fuel-gauge@36 { + compatible = "maxim,max77779-fg"; + reg = <0x36>; + shunt-resistor-micro-ohms = <2000>; + }; + + /* + * The PMIC block: the chip's interrupt line (gpa8-0, stock's + * if_pmic_irq) and the SGPIOs that carry the RT9470's lines. + */ + max77779_pmic: pmic@66 { + compatible = "maxim,max77779-pmic"; + reg = <0x66>; + interrupt-parent = <&gpa8>; + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names = "default"; + pinctrl-0 = <&if_pmic_irq>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; +}; + +/* The RT9470, used only as the USB OTG boost (bring-up, not for merge). */ +&hsi2c10 { + clock-frequency = <400000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c10_bus>; + status = "okay"; + + otg_boost: regulator@5b { + compatible = "omamobile,tegu-rt9471-boost"; + reg = <0x5b>; + regulator-name = "otg-boost"; + /* stock's rt,intr_gpio (PLC_INT_L, pulled up) and rt,ceb_gpio */ + int-gpios = <&max77779_pmic 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + enable-gpios = <&max77779_pmic 7 GPIO_ACTIVE_LOW>; + }; +}; + +/* The haptics: a CS40L26 on the 9a's LRA, with Google's limits for it. */ +&hsi2c9 { + clock-frequency = <100000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c9_bus>; + status = "okay"; + + haptic-driver@43 { + compatible = "cirrus,cs40l26a"; + reg = <0x43>; + interrupt-parent = <&gpa6>; + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; + reset-gpios = <&gph2 3 GPIO_ACTIVE_LOW>; + pinctrl-names = "default"; + pinctrl-0 = <&haptic_reset>; + cirrus,boost-peak-microamp = <2500000>; + cirrus,boost-ctl-microvolt = <10000000>; + cirrus,lra-f0-hz = <162>; + cirrus,lra-redc-micro-ohms = <14100007>; + cirrus,vpbr-threshold-microvolt = <3008000>; + }; + + /* + * The ST54L NFC controller: plain NCI over I2C, nxp-nci's transport. + * Its "enable" line is the chip's RST_N; the PMU's clock pad gives it + * its reference clock. + */ + nfc@8 { + compatible = "st,st54l", "nxp,nxp-nci-i2c"; + reg = <0x08>; + clocks = <&pmu_system_controller 0>; + interrupt-parent = <&gpa7>; + interrupts = <5 IRQ_TYPE_LEVEL_HIGH>; + enable-gpios = <&gph1 6 GPIO_ACTIVE_HIGH>; + }; +}; + &pinctrl_alive { status = "okay"; + + usb_pd_irq: usb-pd-irq-pins { + samsung,pins = "gpa8-3"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + + if_pmic_irq: if-pmic-irq-pins { + samsung,pins = "gpa8-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; }; &pinctrl_custom_alive { @@ -202,6 +537,13 @@ &pinctrl_hsi1 { status = "okay"; + + haptic_reset: haptic-reset-pins { + samsung,pins = "gph2-3"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; }; &pinctrl_hsi2 { @@ -215,6 +557,20 @@ &pinctrl_peric0 { status = "okay"; + hsi2c4_bus: hsi2c4-bus-pins { + samsung,pins = "gpp8-0", "gpp8-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + + hsi2c6_bus: hsi2c6-bus-pins { + samsung,pins = "gpp12-0", "gpp12-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + touch_reset_held: touch-reset-held-pins { samsung,pins = "gpp1-1"; samsung,pin-function = ; @@ -224,6 +580,27 @@ &pinctrl_peric1 { status = "okay"; + + hsi2c10_bus: hsi2c10-bus-pins { + samsung,pins = "gpp20-0", "gpp20-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + + hsi2c9_bus: hsi2c9-bus-pins { + samsung,pins = "gpp19-4", "gpp19-5"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + + torch_enable: torch-enable-pins { + samsung,pins = "gpp24-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; }; &pmu_system_controller { @@ -294,11 +671,19 @@ <&cmu_hsi0 CLK_GOUT_HSI0_USB_SUSPEND>, <&cmu_hsi0 CLK_GOUT_HSI0_USB_SUBCTL>; clock-names = "bus_early", "ref", "suspend", "subctl"; - dr_mode = "peripheral"; + dr_mode = "otg"; maximum-speed = "high-speed"; snps,dis-u2-freeclk-exists-quirk; snps,usb2-gadget-lpm-disable; + usb-role-switch; + role-switch-default-mode = "peripheral"; status = "okay"; + + port { + usb_hs: endpoint { + remote-endpoint = <&typec_hs>; + }; + }; }; &usb_hsphy { @@ -321,6 +706,22 @@ status = "okay"; }; +&usi4 { + status = "okay"; +}; + +&usi6 { + status = "okay"; +}; + +&usi9 { + status = "okay"; +}; + +&usi10 { + status = "okay"; +}; + &watchdog_cl0 { status = "okay"; }; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi index 10b018b180..f8be1721dd 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi @@ -7,6 +7,7 @@ */ #include +#include #include #include @@ -104,6 +105,11 @@ compatible = "arm,cortex-a520"; reg = <0x000>; enable-method = "psci"; + capacity-dmips-mhz = <193>; + dynamic-power-coefficient = <70>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL0>; + operating-points-v2 = <&cpucl0_opp>; }; cpu1: cpu@100 { @@ -111,6 +117,11 @@ compatible = "arm,cortex-a520"; reg = <0x100>; enable-method = "psci"; + capacity-dmips-mhz = <193>; + dynamic-power-coefficient = <70>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL0>; + operating-points-v2 = <&cpucl0_opp>; }; cpu2: cpu@200 { @@ -118,6 +129,11 @@ compatible = "arm,cortex-a520"; reg = <0x200>; enable-method = "psci"; + capacity-dmips-mhz = <193>; + dynamic-power-coefficient = <70>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL0>; + operating-points-v2 = <&cpucl0_opp>; }; cpu3: cpu@300 { @@ -125,6 +141,11 @@ compatible = "arm,cortex-a520"; reg = <0x300>; enable-method = "psci"; + capacity-dmips-mhz = <193>; + dynamic-power-coefficient = <70>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL0>; + operating-points-v2 = <&cpucl0_opp>; }; cpu4: cpu@400 { @@ -132,6 +153,11 @@ compatible = "arm,cortex-a720"; reg = <0x400>; enable-method = "psci"; + capacity-dmips-mhz = <927>; + dynamic-power-coefficient = <513>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL1>; + operating-points-v2 = <&cpucl1_opp>; }; cpu5: cpu@500 { @@ -139,6 +165,11 @@ compatible = "arm,cortex-a720"; reg = <0x500>; enable-method = "psci"; + capacity-dmips-mhz = <927>; + dynamic-power-coefficient = <513>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL1>; + operating-points-v2 = <&cpucl1_opp>; }; cpu6: cpu@600 { @@ -146,6 +177,11 @@ compatible = "arm,cortex-a720"; reg = <0x600>; enable-method = "psci"; + capacity-dmips-mhz = <927>; + dynamic-power-coefficient = <513>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL1>; + operating-points-v2 = <&cpucl1_opp>; }; cpu7: cpu@700 { @@ -153,6 +189,11 @@ compatible = "arm,cortex-x4"; reg = <0x700>; enable-method = "psci"; + capacity-dmips-mhz = <1024>; + dynamic-power-coefficient = <757>; + #cooling-cells = <2>; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_CPUCL2>; + operating-points-v2 = <&cpucl2_opp>; }; }; @@ -214,6 +255,342 @@ mboxes = <&ap2apm_mailbox>; shmem = <&apm_sram>; status = "disabled"; + + acpm_tmu: thermal-sensor { + compatible = "google,zumapro-acpm-tmu"; + #thermal-sensor-cells = <1>; + }; + }; + }; + + /* + * CPU levels: the APM firmware's own DVFS levels, read on the Pixel 9a + * (the little cluster's 324 and 610 MHz are below stock's 820 MHz + * floor), up to the 9a's thermal headroom: the levels above each table's + * top, listed in it, are left out for that board. A board with more + * headroom can add them. The little cluster stops at 1950 MHz, Google's + * max-freq for it. + */ + cpucl0_opp: opp-table-cpucl0 { + compatible = "operating-points-v2"; + opp-shared; + + opp-324000000 { + opp-hz = /bits/ 64 <324000000>; + }; + + opp-610000000 { + opp-hz = /bits/ 64 <610000000>; + }; + + opp-820000000 { + opp-hz = /bits/ 64 <820000000>; + }; + + opp-955000000 { + opp-hz = /bits/ 64 <955000000>; + }; + + opp-1098000000 { + opp-hz = /bits/ 64 <1098000000>; + }; + + opp-1197000000 { + opp-hz = /bits/ 64 <1197000000>; + }; + + opp-1328000000 { + opp-hz = /bits/ 64 <1328000000>; + }; + + opp-1425000000 { + opp-hz = /bits/ 64 <1425000000>; + }; + + opp-1548000000 { + opp-hz = /bits/ 64 <1548000000>; + }; + + opp-1696000000 { + opp-hz = /bits/ 64 <1696000000>; + }; + + opp-1849000000 { + opp-hz = /bits/ 64 <1849000000>; + }; + + opp-1950000000 { + opp-hz = /bits/ 64 <1950000000>; + }; + + }; + + cpucl1_opp: opp-table-cpucl1 { + compatible = "operating-points-v2"; + opp-shared; + + opp-357000000 { + opp-hz = /bits/ 64 <357000000>; + }; + + opp-578000000 { + opp-hz = /bits/ 64 <578000000>; + }; + + opp-648000000 { + opp-hz = /bits/ 64 <648000000>; + }; + + opp-787000000 { + opp-hz = /bits/ 64 <787000000>; + }; + + opp-910000000 { + opp-hz = /bits/ 64 <910000000>; + }; + + opp-1065000000 { + opp-hz = /bits/ 64 <1065000000>; + }; + + opp-1221000000 { + opp-hz = /bits/ 64 <1221000000>; + }; + + opp-1328000000 { + opp-hz = /bits/ 64 <1328000000>; + }; + + opp-1418000000 { + opp-hz = /bits/ 64 <1418000000>; + }; + + opp-1549000000 { + opp-hz = /bits/ 64 <1549000000>; + }; + + opp-1795000000 { + opp-hz = /bits/ 64 <1795000000>; + }; + + opp-1945000000 { + opp-hz = /bits/ 64 <1945000000>; + }; + + opp-2130000000 { + opp-hz = /bits/ 64 <2130000000>; + }; + + opp-2245000000 { + opp-hz = /bits/ 64 <2245000000>; + }; + + opp-2367000000 { + opp-hz = /bits/ 64 <2367000000>; + }; + + /* 2450 and 2600 MHz stay off: above the cluster's thermal headroom. */ + }; + + cpucl2_opp: opp-table-cpucl2 { + compatible = "operating-points-v2"; + opp-shared; + + opp-700000000 { + opp-hz = /bits/ 64 <700000000>; + }; + + opp-1164000000 { + opp-hz = /bits/ 64 <1164000000>; + }; + + opp-1396000000 { + opp-hz = /bits/ 64 <1396000000>; + }; + + opp-1557000000 { + opp-hz = /bits/ 64 <1557000000>; + }; + + opp-1745000000 { + opp-hz = /bits/ 64 <1745000000>; + }; + + opp-1885000000 { + opp-hz = /bits/ 64 <1885000000>; + }; + + opp-1999000000 { + opp-hz = /bits/ 64 <1999000000>; + }; + + opp-2147000000 { + opp-hz = /bits/ 64 <2147000000>; + }; + + opp-2294000000 { + opp-hz = /bits/ 64 <2294000000>; + }; + + opp-2363000000 { + opp-hz = /bits/ 64 <2363000000>; + }; + + opp-2499000000 { + opp-hz = /bits/ 64 <2499000000>; + }; + + opp-2687000000 { + opp-hz = /bits/ 64 <2687000000>; + }; + + /* + * 2802, 2914, 2943, 2970, 3015 and 3105 MHz stay off: above the + * cluster's thermal headroom. + */ + }; + + thermal-zones { + big-thermal { + polling-delay-passive = <250>; + polling-delay = <1000>; + thermal-sensors = <&acpm_tmu 0>; + + trips { + big_alert: big-alert { + temperature = <80000>; + hysteresis = <5000>; + type = "passive"; + }; + + big_hot: big-hot { + temperature = <95000>; + hysteresis = <10000>; + type = "passive"; + }; + + big_crit: big-crit { + temperature = <105000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + cooling-maps { + map0 { + trip = <&big_alert>; + cooling-device = <&cpu7 0xffffffff 0xffffffff>; + }; + + map1 { + trip = <&big_hot>; + cooling-device = <&cpu7 11 0xffffffff>; + }; + }; + }; + + mid-thermal { + polling-delay-passive = <250>; + polling-delay = <1000>; + thermal-sensors = <&acpm_tmu 1>; + + trips { + mid_alert: mid-alert { + temperature = <80000>; + hysteresis = <5000>; + type = "passive"; + }; + + mid_hot: mid-hot { + temperature = <95000>; + hysteresis = <10000>; + type = "passive"; + }; + + mid_crit: mid-crit { + temperature = <105000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + cooling-maps { + map0 { + trip = <&mid_alert>; + cooling-device = <&cpu4 0xffffffff 0xffffffff>; + }; + + map1 { + trip = <&mid_hot>; + cooling-device = <&cpu4 14 0xffffffff>; + }; + }; + }; + + little-thermal { + polling-delay-passive = <250>; + polling-delay = <1000>; + thermal-sensors = <&acpm_tmu 2>; + + trips { + little_alert: little-alert { + temperature = <80000>; + hysteresis = <5000>; + type = "passive"; + }; + + little_hot: little-hot { + temperature = <95000>; + hysteresis = <10000>; + type = "passive"; + }; + + little_crit: little-crit { + temperature = <105000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + cooling-maps { + map0 { + trip = <&little_alert>; + cooling-device = <&cpu0 0xffffffff 0xffffffff>; + }; + + map1 { + trip = <&little_hot>; + cooling-device = <&cpu0 11 0xffffffff>; + }; + }; + }; + + gpu-thermal { + polling-delay-passive = <1000>; + polling-delay = <2000>; + thermal-sensors = <&acpm_tmu 3>; + + trips { + gpu_alert: gpu-alert { + temperature = <85000>; + hysteresis = <5000>; + type = "passive"; + }; + + gpu_crit: gpu-crit { + temperature = <105000>; + hysteresis = <2000>; + type = "critical"; + }; + }; + + /* panthor's devfreq cooling: step_wise walks the GPU down its OPPs. */ + cooling-maps { + map0 { + trip = <&gpu_alert>; + cooling-device = <&gpu 0xffffffff 0xffffffff>; + }; + }; }; }; @@ -598,6 +975,33 @@ }; }; + usi10: usi@10ca00c0 { + compatible = "google,zumapro-usi", "samsung,exynos850-usi"; + reg = <0x0 0x10ca00c0 0x20>; + clocks = <&cmu_peric1 CLK_GOUT_PERIC1_USI10_PCLK>, + <&cmu_peric1 CLK_GOUT_PERIC1_USI10_IPCLK>; + clock-names = "pclk", "ipclk"; + samsung,sysreg = <&sysreg_peric1 0x8>; + samsung,mode = ; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x10ca0000 0x0 0x10ca0000 0x1000>; + status = "disabled"; + + hsi2c10: i2c@10ca0000 { + compatible = "google,zumapro-hsi2c", + "samsung,exynosautov9-hsi2c"; + reg = <0x10ca0000 0xc0>; + interrupts = ; + clocks = <&cmu_peric1 CLK_GOUT_PERIC1_USI10_IPCLK>, + <&cmu_peric1 CLK_GOUT_PERIC1_USI10_PCLK>; + clock-names = "hsi2c", "hsi2c_pclk"; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + }; + cmu_hsi0: clock-controller@11000000 { compatible = "google,zumapro-cmu-hsi0"; reg = <0x0 0x11000000 0x8000>; @@ -938,6 +1342,7 @@ pmu_system_controller: system-controller@15460000 { compatible = "google,zumapro-pmu", "google,zuma-pmu"; reg = <0x0 0x15460000 0x10000>; + #clock-cells = <1>; status = "disabled"; reboot_mode: reboot-mode { @@ -1080,6 +1485,18 @@ }; }; + dsi0: dsi@19440000 { + compatible = "google,zumapro-dsim", "google,gs201-dsim"; + reg = <0x0 0x19440000 0x300>, + <0x0 0x19460100 0x700>, + <0x0 0x19460000 0x100>; + reg-names = "dsi", "dphy", "dphy-extra"; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + /* Scans out what the bootloader set up; no panel or clock control. */ decon0: display-controller@19470000 { compatible = "google,zumapro-decon"; @@ -1115,6 +1532,7 @@ <&cmu_g3d CLK_GOUT_G3D_COREGROUP>, <&cmu_g3d CLK_GOUT_G3D_STACKS>; clock-names = "core", "coregroup", "stacks"; + #cooling-cells = <2>; status = "disabled"; }; diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 819f1053eb..6d74a2045d 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1592,6 +1592,18 @@ config GPIO_MAX77650 GPIO driver for MAX77650/77651 PMIC from Maxim Semiconductor. These chips have a single pin that can be configured as GPIO. +config GPIO_MAX77779 + tristate "Maxim Integrated MAX77779 PMIC SGPIO support" + depends on I2C + select REGMAP_I2C + select GPIOLIB_IRQCHIP + help + GPIO driver for the SGPIO block of the MAX77779 interface PMIC from + Maxim Integrated (Google Pixel 9a). The eight pins can generate + interrupts; the board's charger side signals sit on them. + + Say M to build it as a module, called gpio-max77779. + config GPIO_MAX77759 tristate "Maxim Integrated MAX77759 GPIO support" depends on MFD_MAX77759 diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index ebd234ee7e..c9620ba353 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -113,6 +113,7 @@ obj-$(CONFIG_GPIO_MAX7360) += gpio-max7360.o obj-$(CONFIG_GPIO_MAX77620) += gpio-max77620.o obj-$(CONFIG_GPIO_MAX77650) += gpio-max77650.o obj-$(CONFIG_GPIO_MAX77759) += gpio-max77759.o +obj-$(CONFIG_GPIO_MAX77779) += gpio-max77779.o obj-$(CONFIG_GPIO_MB86S7X) += gpio-mb86s7x.o obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o obj-$(CONFIG_GPIO_MENZ127) += gpio-menz127.o diff --git a/drivers/gpio/gpio-max77779.c b/drivers/gpio/gpio-max77779.c new file mode 100644 index 0000000000..423513975a --- /dev/null +++ b/drivers/gpio/gpio-max77779.c @@ -0,0 +1,455 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// GPIO driver for the Maxim MAX77779 interface PMIC's SGPIO block +// +// The MAX77779 (Google Pixel 9a) is a set of I2C blocks on one chip: the +// charger, the fuel gauge, the Type-C port controller and, at 0x66, the +// PMIC block that owns the chip's interrupt line and eight SGPIO pins. The +// pins carry the board's charger side signals (the RT9470 boost's interrupt +// and enable, the wireless charger's lines). This driver binds to the PMIC +// block and exposes the SGPIOs as a GPIO chip with interrupts. The other +// interrupt sources the block gathers (the charger, the gauge, the port +// controller) have their own lines to the SoC on this board and stay masked +// here. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX77779_PMIC_ID 0x00 +#define MAX77779_PMIC_ID_VALUE 0x79 +#define MAX77779_PMIC_REVISION 0x01 +#define MAX77779_PMIC_OTP_REVISION 0x02 +#define MAX77779_PMIC_INTSRC_STS 0x22 /* write 1 to clear */ +#define MAX77779_PMIC_INTSRC_GPIO BIT(5) +#define MAX77779_PMIC_INTB_MASK 0x24 /* 1 = masked */ + +#define MAX77779_SGPIO_INT 0xe8 /* write 1 to clear */ +#define MAX77779_SGPIO_PU 0xe9 +#define MAX77779_SGPIO_PD 0xea +#define MAX77779_SGPIO_CNFG(n) (0xed + (n)) +#define MAX77779_SGPIO_CNFG_DATA BIT(0) +#define MAX77779_SGPIO_CNFG_VGPI_EN BIT(1) +#define MAX77779_SGPIO_CNFG_MODE GENMASK(3, 2) +#define MAX77779_SGPIO_MODE_INPUT 1 +#define MAX77779_SGPIO_MODE_OUTPUT 2 +#define MAX77779_SGPIO_CNFG_DBNC GENMASK(5, 4) +#define MAX77779_SGPIO_CNFG_IRQ GENMASK(7, 6) +#define MAX77779_SGPIO_IRQ_NONE 0 +#define MAX77779_SGPIO_IRQ_FALLING 1 +#define MAX77779_SGPIO_IRQ_RISING 2 +#define MAX77779_SGPIO_IRQ_BOTH 3 +#define MAX77779_VGPI_CNFG 0xfb + +#define MAX77779_N_SGPIO 8 + +struct max77779_gpio { + struct regmap *map; + struct gpio_chip gc; + struct mutex irq_lock; /* the irq bus: trigger and mask changes */ + u8 irq_trig[MAX77779_N_SGPIO]; + unsigned long irq_masked; + unsigned long irq_changed; +}; + +static const struct regmap_range max77779_pmic_volatile_ranges[] = { + regmap_reg_range(MAX77779_PMIC_ID, MAX77779_PMIC_OTP_REVISION), + regmap_reg_range(MAX77779_PMIC_INTSRC_STS, MAX77779_PMIC_INTSRC_STS), + regmap_reg_range(MAX77779_SGPIO_INT, MAX77779_SGPIO_INT), + /* CNFGx carries the pin's live level in DATA */ + regmap_reg_range(MAX77779_SGPIO_CNFG(0), MAX77779_SGPIO_CNFG(7)), +}; + +static const struct regmap_access_table max77779_pmic_volatile_table = { + .yes_ranges = max77779_pmic_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(max77779_pmic_volatile_ranges), +}; + +static const struct regmap_config max77779_pmic_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = MAX77779_VGPI_CNFG, + .volatile_table = &max77779_pmic_volatile_table, + .cache_type = REGCACHE_NONE, +}; + +static int max77779_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) +{ + struct max77779_gpio *chip = gpiochip_get_data(gc); + unsigned int cnfg; + int ret; + + ret = regmap_read(chip->map, MAX77779_SGPIO_CNFG(offset), &cnfg); + if (ret) + return ret; + + switch (FIELD_GET(MAX77779_SGPIO_CNFG_MODE, cnfg)) { + case MAX77779_SGPIO_MODE_INPUT: + return GPIO_LINE_DIRECTION_IN; + case MAX77779_SGPIO_MODE_OUTPUT: + return GPIO_LINE_DIRECTION_OUT; + default: + /* 0: the pin is off; 3: reserved */ + return -ENODEV; + } +} + +static int max77779_gpio_direction_input(struct gpio_chip *gc, unsigned int offset) +{ + struct max77779_gpio *chip = gpiochip_get_data(gc); + + return regmap_update_bits(chip->map, MAX77779_SGPIO_CNFG(offset), + MAX77779_SGPIO_CNFG_MODE, + FIELD_PREP(MAX77779_SGPIO_CNFG_MODE, + MAX77779_SGPIO_MODE_INPUT)); +} + +static int max77779_gpio_direction_output(struct gpio_chip *gc, + unsigned int offset, int value) +{ + struct max77779_gpio *chip = gpiochip_get_data(gc); + + return regmap_update_bits(chip->map, MAX77779_SGPIO_CNFG(offset), + MAX77779_SGPIO_CNFG_MODE | MAX77779_SGPIO_CNFG_DATA, + FIELD_PREP(MAX77779_SGPIO_CNFG_MODE, + MAX77779_SGPIO_MODE_OUTPUT) | + FIELD_PREP(MAX77779_SGPIO_CNFG_DATA, !!value)); +} + +static int max77779_gpio_get(struct gpio_chip *gc, unsigned int offset) +{ + struct max77779_gpio *chip = gpiochip_get_data(gc); + unsigned int cnfg; + int ret; + + ret = regmap_read(chip->map, MAX77779_SGPIO_CNFG(offset), &cnfg); + if (ret) + return ret; + + return !!(cnfg & MAX77779_SGPIO_CNFG_DATA); +} + +static int max77779_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) +{ + struct max77779_gpio *chip = gpiochip_get_data(gc); + + return regmap_update_bits(chip->map, MAX77779_SGPIO_CNFG(offset), + MAX77779_SGPIO_CNFG_DATA, + FIELD_PREP(MAX77779_SGPIO_CNFG_DATA, !!value)); +} + +static int max77779_gpio_set_config(struct gpio_chip *gc, unsigned int offset, + unsigned long config) +{ + struct max77779_gpio *chip = gpiochip_get_data(gc); + unsigned int pu = 0, pd = 0; + int ret; + + switch (pinconf_to_config_param(config)) { + case PIN_CONFIG_BIAS_PULL_UP: + pu = BIT(offset); + break; + case PIN_CONFIG_BIAS_PULL_DOWN: + pd = BIT(offset); + break; + case PIN_CONFIG_BIAS_DISABLE: + break; + default: + return -ENOTSUPP; + } + + ret = regmap_update_bits(chip->map, MAX77779_SGPIO_PU, BIT(offset), pu); + if (ret) + return ret; + + return regmap_update_bits(chip->map, MAX77779_SGPIO_PD, BIT(offset), pd); +} + +static void max77779_gpio_irq_mask(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct max77779_gpio *chip = gpiochip_get_data(gc); + irq_hw_number_t hwirq = irqd_to_hwirq(d); + + set_bit(hwirq, &chip->irq_masked); + set_bit(hwirq, &chip->irq_changed); + gpiochip_disable_irq(gc, hwirq); +} + +static void max77779_gpio_irq_unmask(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct max77779_gpio *chip = gpiochip_get_data(gc); + irq_hw_number_t hwirq = irqd_to_hwirq(d); + + gpiochip_enable_irq(gc, hwirq); + clear_bit(hwirq, &chip->irq_masked); + set_bit(hwirq, &chip->irq_changed); +} + +static int max77779_gpio_irq_set_type(struct irq_data *d, unsigned int type) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct max77779_gpio *chip = gpiochip_get_data(gc); + irq_hw_number_t hwirq = irqd_to_hwirq(d); + + /* + * The SGPIOs detect edges. A level request takes the edge into the + * level, and the handler re-checks the pin afterwards: while the level + * holds, the interrupt isn't cleared and fires again. + */ + switch (type) { + case IRQ_TYPE_EDGE_RISING: + case IRQ_TYPE_LEVEL_HIGH: + chip->irq_trig[hwirq] = MAX77779_SGPIO_IRQ_RISING; + break; + case IRQ_TYPE_EDGE_FALLING: + case IRQ_TYPE_LEVEL_LOW: + chip->irq_trig[hwirq] = MAX77779_SGPIO_IRQ_FALLING; + break; + case IRQ_TYPE_EDGE_BOTH: + chip->irq_trig[hwirq] = MAX77779_SGPIO_IRQ_BOTH; + break; + default: + return -EINVAL; + } + set_bit(hwirq, &chip->irq_changed); + + return 0; +} + +static void max77779_gpio_irq_bus_lock(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct max77779_gpio *chip = gpiochip_get_data(gc); + + mutex_lock(&chip->irq_lock); +} + +static void max77779_gpio_irq_bus_sync_unlock(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct max77779_gpio *chip = gpiochip_get_data(gc); + unsigned long changed = chip->irq_changed; + unsigned int offset; + int ret; + + for_each_set_bit(offset, &changed, MAX77779_N_SGPIO) { + u8 sel = test_bit(offset, &chip->irq_masked) ? + MAX77779_SGPIO_IRQ_NONE : chip->irq_trig[offset]; + + ret = regmap_update_bits(chip->map, MAX77779_SGPIO_CNFG(offset), + MAX77779_SGPIO_CNFG_IRQ, + FIELD_PREP(MAX77779_SGPIO_CNFG_IRQ, sel)); + if (ret) + dev_err(gc->parent, "SGPIO%u: can't set the trigger: %d\n", + offset, ret); + else + clear_bit(offset, &chip->irq_changed); + } + + mutex_unlock(&chip->irq_lock); +} + +static void max77779_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + + seq_puts(p, dev_name(gc->parent)); +} + +static const struct irq_chip max77779_gpio_irq_chip = { + .irq_mask = max77779_gpio_irq_mask, + .irq_unmask = max77779_gpio_irq_unmask, + .irq_set_type = max77779_gpio_irq_set_type, + .irq_bus_lock = max77779_gpio_irq_bus_lock, + .irq_bus_sync_unlock = max77779_gpio_irq_bus_sync_unlock, + .irq_print_chip = max77779_gpio_irq_print_chip, + .flags = IRQCHIP_IMMUTABLE, + GPIOCHIP_IRQ_RESOURCE_HELPERS, +}; + +/* A level-typed line is done only once the pin has left the active level */ +static bool max77779_gpio_level_done(struct max77779_gpio *chip, unsigned int offset) +{ + struct irq_data *d = irq_get_irq_data(irq_find_mapping(chip->gc.irq.domain, + offset)); + unsigned int cnfg, type; + int ret; + + type = d ? irqd_get_trigger_type(d) : IRQ_TYPE_NONE; + if (!(type & IRQ_TYPE_LEVEL_MASK)) + return true; + + ret = regmap_read(chip->map, MAX77779_SGPIO_CNFG(offset), &cnfg); + if (ret) + return true; + + if (type & IRQ_TYPE_LEVEL_LOW) + return cnfg & MAX77779_SGPIO_CNFG_DATA; + return !(cnfg & MAX77779_SGPIO_CNFG_DATA); +} + +static irqreturn_t max77779_gpio_irq_handler(int irq, void *data) +{ + struct max77779_gpio *chip = data; + struct gpio_chip *gc = &chip->gc; + bool handled = false; + unsigned int src, sts; + unsigned long pending; + unsigned int offset; + u8 done; + int ret; + + ret = regmap_read(chip->map, MAX77779_PMIC_INTSRC_STS, &src); + if (ret) { + dev_err_ratelimited(gc->parent, "can't read INTSRC_STS: %d\n", ret); + return IRQ_NONE; + } + + if (src & MAX77779_PMIC_INTSRC_GPIO) { + ret = regmap_read(chip->map, MAX77779_SGPIO_INT, &sts); + if (ret) { + dev_err_ratelimited(gc->parent, "can't read SGPIO_INT: %d\n", ret); + return IRQ_NONE; + } + + pending = sts; + done = 0; + for_each_set_bit(offset, &pending, MAX77779_N_SGPIO) { + handle_nested_irq(irq_find_mapping(gc->irq.domain, offset)); + if (max77779_gpio_level_done(chip, offset)) + done |= BIT(offset); + handled = true; + } + /* clear only what is done: a held level fires again */ + if (done) + regmap_write(chip->map, MAX77779_SGPIO_INT, done); + } + + /* the other sources are masked; acknowledge whatever is set */ + if (src) + regmap_write(chip->map, MAX77779_PMIC_INTSRC_STS, src); + + return IRQ_RETVAL(handled || src); +} + +static int max77779_gpio_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct max77779_gpio *chip; + struct gpio_irq_chip *girq; + unsigned int id, rev; + int ret; + + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->map = devm_regmap_init_i2c(client, &max77779_pmic_regmap_config); + if (IS_ERR(chip->map)) + return dev_err_probe(dev, PTR_ERR(chip->map), "can't init the regmap\n"); + + ret = regmap_read(chip->map, MAX77779_PMIC_ID, &id); + if (ret) + return dev_err_probe(dev, ret, "can't read the ID\n"); + if (id != MAX77779_PMIC_ID_VALUE) + return dev_err_probe(dev, -ENODEV, "ID 0x%02x is not a MAX77779\n", id); + ret = regmap_read(chip->map, MAX77779_PMIC_REVISION, &rev); + if (ret) + return dev_err_probe(dev, ret, "can't read the revision\n"); + dev_info(dev, "MAX77779 PMIC revision 0x%02x\n", rev); + + ret = devm_mutex_init(dev, &chip->irq_lock); + if (ret) + return ret; + + /* every pin's interrupt off, everything masked and acknowledged */ + chip->irq_masked = GENMASK(MAX77779_N_SGPIO - 1, 0); + chip->irq_changed = chip->irq_masked; + ret = regmap_write(chip->map, MAX77779_PMIC_INTB_MASK, 0xff); + if (ret) + return dev_err_probe(dev, ret, "can't mask the interrupts\n"); + regmap_write(chip->map, MAX77779_SGPIO_INT, 0xff); + regmap_write(chip->map, MAX77779_PMIC_INTSRC_STS, 0xff); + + chip->gc.base = -1; + chip->gc.label = dev_name(dev); + chip->gc.parent = dev; + chip->gc.owner = THIS_MODULE; + chip->gc.can_sleep = true; + chip->gc.ngpio = MAX77779_N_SGPIO; + chip->gc.get_direction = max77779_gpio_get_direction; + chip->gc.direction_input = max77779_gpio_direction_input; + chip->gc.direction_output = max77779_gpio_direction_output; + chip->gc.get = max77779_gpio_get; + chip->gc.set = max77779_gpio_set; + chip->gc.set_config = max77779_gpio_set_config; + + girq = &chip->gc.irq; + gpio_irq_chip_set_chip(girq, &max77779_gpio_irq_chip); + /* the parent interrupt is handled here */ + girq->parent_handler = NULL; + girq->num_parents = 0; + girq->parents = NULL; + girq->default_type = IRQ_TYPE_NONE; + girq->handler = handle_simple_irq; + girq->threaded = true; + + ret = devm_gpiochip_add_data(dev, &chip->gc, chip); + if (ret) + return dev_err_probe(dev, ret, "can't add the GPIO chip\n"); + + if (client->irq <= 0) { + dev_info(dev, "no interrupt line: the SGPIOs don't interrupt\n"); + return 0; + } + + ret = devm_request_threaded_irq(dev, client->irq, NULL, + max77779_gpio_irq_handler, + IRQF_ONESHOT, dev_name(dev), chip); + if (ret) + return dev_err_probe(dev, ret, "can't request the interrupt\n"); + + /* only the SGPIO source reaches the line; the rest have their own */ + ret = regmap_write(chip->map, MAX77779_PMIC_INTB_MASK, + (u8)~MAX77779_PMIC_INTSRC_GPIO); + if (ret) + return dev_err_probe(dev, ret, "can't unmask the SGPIO source\n"); + + return 0; +} + +static const struct of_device_id max77779_gpio_of_match[] = { + { .compatible = "maxim,max77779-pmic" }, + { } +}; +MODULE_DEVICE_TABLE(of, max77779_gpio_of_match); + +static const struct i2c_device_id max77779_gpio_i2c_id[] = { + { "max77779-pmic" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, max77779_gpio_i2c_id); + +static struct i2c_driver max77779_gpio_driver = { + .driver = { + .name = "max77779-pmic", + .of_match_table = max77779_gpio_of_match, + }, + .probe = max77779_gpio_probe, + .id_table = max77779_gpio_i2c_id, +}; +module_i2c_driver(max77779_gpio_driver); + +MODULE_AUTHOR("W4HO <87742609+W4HO-ham@users.noreply.github.com>"); +MODULE_DESCRIPTION("GPIO driver for the Maxim MAX77779 PMIC's SGPIOs"); +MODULE_LICENSE("GPL"); diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index 92ce096e9b..6d81a97784 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -277,6 +278,7 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) struct device *dev = &client->dev; struct nxp_nci_i2c_phy *phy; unsigned long irqflags; + struct clk *clk; int r; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { @@ -308,6 +310,11 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) return PTR_ERR(phy->gpiod_fw); } + /* a reference clock (or its pad's enable) the controller asks for */ + clk = devm_clk_get_optional_enabled(dev, NULL); + if (IS_ERR(clk)) + return dev_err_probe(dev, PTR_ERR(clk), "Failed to get the clock\n"); + r = nxp_nci_probe(phy, &client->dev, &i2c_phy_ops, NXP_NCI_I2C_MAX_PAYLOAD, &phy->ndev); if (r < 0) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index 1e63a06a74..4ed1cdd660 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -474,13 +474,14 @@ config CHARGER_MAX77779 tristate "Maxim MAX77779 battery charger" depends on I2C depends on OF + depends on REGULATOR select REGMAP_I2C help Say Y or M here to report the state of the charger in the Maxim MAX77779 power management IC, found in the Google Pixel 9a, and to let userspace stop and restart charging. The charger keeps its own (OTP) charge current and voltage; the driver only reads - them. + them. It also supplies VBUS to a device on the USB port. The module is named max77779_charger. diff --git a/drivers/power/supply/max77779_charger.c b/drivers/power/supply/max77779_charger.c index 8d41ddffee..6e30a6b531 100644 --- a/drivers/power/supply/max77779_charger.c +++ b/drivers/power/supply/max77779_charger.c @@ -1,13 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Maxim MAX77779 battery charger: status and charge inhibit. + * Maxim MAX77779 battery charger: status, charge inhibit and USB OTG VBUS. * * The charger runs under its own (OTP) defaults. This driver reports what * it is doing and can stop charging: inhibit-charge puts it in buck-only * mode, so the battery is no longer charged and USB powers the system, * though with the battery near full the battery still supplies part of the - * load. Nothing else is written; the interrupt registers (clear on read) - * are never read, and the state is polled. + * load. For host mode it supplies VBUS (its chgin-otg regulator). Only the + * mode is written; the interrupt registers (clear on read) are never read, + * and the state is polled. * * Register fields from Google's driver (google-modules/bms at 183509aff980: * max77779_charger.c, GPL, and max77779_v20240115_regs.h). @@ -21,6 +22,8 @@ #include #include #include +#include +#include #include #define MAX77779_CHG_INT_OK 0xb6 @@ -31,6 +34,7 @@ #define MAX77779_CHG_DTLS GENMASK(3, 0) #define MAX77779_CHG_CNFG_00 0xbc #define MAX77779_MODE GENMASK(3, 0) +#define MAX77779_MODE_OFF 0x0 #define MAX77779_MODE_BUCK 0x4 #define MAX77779_MODE_CHG_BUCK 0x5 #define MAX77779_CHG_CNFG_02 0xbe @@ -59,6 +63,9 @@ struct max77779_charger { unsigned int last; int behaviour; bool held; + /* the OTG boost that sources VBUS: optional, external */ + struct regulator *boost; + bool otg; }; static bool max77779_charger_readable(struct device *dev, unsigned int reg) @@ -167,12 +174,21 @@ static int max77779_charger_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_ONLINE: + /* While it sources VBUS, CHGIN carries our own boost: no input. */ + if (READ_ONCE(chg->otg)) { + val->intval = 0; + return 0; + } ret = regmap_read(chg->map, MAX77779_CHG_INT_OK, &v); if (ret) return ret; val->intval = !!(v & MAX77779_INPUT_OK); return 0; case POWER_SUPPLY_PROP_STATUS: + if (READ_ONCE(chg->otg)) { + val->intval = POWER_SUPPLY_STATUS_DISCHARGING; + return 0; + } return max77779_charger_status(chg, &val->intval); case POWER_SUPPLY_PROP_CHARGE_TYPE: return max77779_charger_charge_type(chg, &val->intval); @@ -224,6 +240,8 @@ static int max77779_charger_set_property(struct power_supply *psy, hold = val->intval == POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE; scoped_guard(mutex, &chg->lock) { + if (chg->otg) + return -EBUSY; if (hold != chg->held) { ret = max77779_charger_set_mode(chg, hold ? MAX77779_MODE_BUCK : @@ -266,6 +284,86 @@ static const struct power_supply_desc max77779_charger_desc = { BIT(POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE), }; +/* + * VBUS for a device on the USB-C port, from an external boost (the Pixel 9a's + * RT9470): the charger is put in standby first and then the boost is enabled, + * as Google's ext-otg-only use case does. The charger's own boost mode (0xa) + * is not used: nothing here has run it. + */ +static int max77779_charger_otg_enable(struct regulator_dev *rdev) +{ + struct max77779_charger *chg = rdev_get_drvdata(rdev); + unsigned int v; + int ret; + + if (!chg->boost) + return -EOPNOTSUPP; + + guard(mutex)(&chg->lock); + /* Something else already drives VBUS: don't boost into it. */ + ret = regmap_read(chg->map, MAX77779_CHG_INT_OK, &v); + if (ret) + return ret; + if (v & MAX77779_INPUT_OK) + return -EBUSY; + + ret = max77779_charger_set_mode(chg, MAX77779_MODE_OFF); + if (ret) + return ret; + + ret = regulator_enable(chg->boost); + if (ret) { + max77779_charger_set_mode(chg, chg->held ? MAX77779_MODE_BUCK : + MAX77779_MODE_CHG_BUCK); + return ret; + } + WRITE_ONCE(chg->otg, true); + + return 0; +} + +static int max77779_charger_otg_disable(struct regulator_dev *rdev) +{ + struct max77779_charger *chg = rdev_get_drvdata(rdev); + int ret; + + guard(mutex)(&chg->lock); + ret = regulator_disable(chg->boost); + if (ret) + return ret; + ret = max77779_charger_set_mode(chg, chg->held ? MAX77779_MODE_BUCK : + MAX77779_MODE_CHG_BUCK); + if (ret) + return ret; + WRITE_ONCE(chg->otg, false); + + return 0; +} + +static int max77779_charger_otg_is_enabled(struct regulator_dev *rdev) +{ + struct max77779_charger *chg = rdev_get_drvdata(rdev); + + guard(mutex)(&chg->lock); + return chg->otg; +} + +static const struct regulator_ops max77779_charger_otg_ops = { + .enable = max77779_charger_otg_enable, + .disable = max77779_charger_otg_disable, + .is_enabled = max77779_charger_otg_is_enabled, +}; + +static const struct regulator_desc max77779_charger_otg_desc = { + .name = "chgin-otg", + .of_match = "chgin-otg-regulator", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &max77779_charger_otg_ops, + .fixed_uV = 5000000, + .n_voltages = 1, +}; + /* Tell the gauge and userspace when the input or the charge state changes. */ static void max77779_charger_poll(struct work_struct *work) { @@ -292,7 +390,9 @@ static void max77779_charger_restore(void *data) { struct max77779_charger *chg = data; - if (chg->held) + if (chg->otg) + regulator_disable(chg->boost); + if (chg->held || chg->otg) max77779_charger_set_mode(chg, MAX77779_MODE_CHG_BUCK); } @@ -306,6 +406,8 @@ static void max77779_charger_cancel_poll(void *data) static int max77779_charger_probe(struct i2c_client *client) { struct power_supply_config cfg = {}; + struct regulator_config rcfg = {}; + struct regulator_dev *rdev; struct device *dev = &client->dev; struct max77779_charger *chg; unsigned int mode; @@ -345,7 +447,19 @@ static int max77779_charger_probe(struct i2c_client *client) dev_warn(dev, "found in mode %#x, not charging and buck\n", mode); } - /* Unwound in reverse: poll stopped, supply gone, then charging back. */ + chg->boost = devm_regulator_get_optional(dev, "otg-boost"); + if (IS_ERR(chg->boost)) { + if (PTR_ERR(chg->boost) != -ENODEV) + return dev_err_probe(dev, PTR_ERR(chg->boost), + "failed to get the OTG boost\n"); + chg->boost = NULL; + } + + /* + * Unwound in reverse: the VBUS regulator gone, poll stopped, supply + * gone, then the boost off and charging back, and only then the boost + * put. + */ ret = devm_add_action_or_reset(dev, max77779_charger_restore, chg); if (ret) return ret; @@ -361,6 +475,13 @@ static int max77779_charger_probe(struct i2c_client *client) if (ret) return ret; + rcfg.dev = dev; + rcfg.driver_data = chg; + rdev = devm_regulator_register(dev, &max77779_charger_otg_desc, &rcfg); + if (IS_ERR(rdev)) + return dev_err_probe(dev, PTR_ERR(rdev), + "failed to register the OTG regulator\n"); + queue_delayed_work(system_freezable_wq, &chg->poll, 0); return 0; } diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 6cda943820..d7bd2f5ca9 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1636,6 +1636,15 @@ config REGULATOR_SY8827N help This driver supports SY8827N single output regulator. +config REGULATOR_TEGU_RT9471_BOOST + tristate "Pixel 9a RT9470 USB OTG boost (bring-up)" + depends on I2C && OF + select REGMAP_I2C + help + Bring-up only, not for merge: the Pixel 9a's RT9470 charger used + only as the USB OTG boost, a regulator on its OTG_EN bit, for the + MAX77779 charger's chgin-otg regulator in USB host mode. + config REGULATOR_TPS51632 tristate "TI TPS51632 Power Regulator" depends on I2C diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index bdddb35323..02ff025de6 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -140,6 +140,7 @@ obj-$(CONFIG_REGULATOR_PV88060) += pv88060-regulator.o obj-$(CONFIG_REGULATOR_PV88080) += pv88080-regulator.o obj-$(CONFIG_REGULATOR_PV88090) += pv88090-regulator.o obj-$(CONFIG_REGULATOR_PWM) += pwm-regulator.o +obj-$(CONFIG_REGULATOR_TEGU_RT9471_BOOST) += tegu-rt9471-boost.o obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o obj-$(CONFIG_REGULATOR_PBIAS) += pbias-regulator.o obj-$(CONFIG_REGULATOR_RAA215300) += raa215300.o diff --git a/drivers/regulator/tegu-rt9471-boost.c b/drivers/regulator/tegu-rt9471-boost.c new file mode 100644 index 0000000000..567b398546 --- /dev/null +++ b/drivers/regulator/tegu-rt9471-boost.c @@ -0,0 +1,282 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Bring-up only, not for upstream: the Pixel 9a's RT9470 (run by Google's + * rt9471 driver) as an OTG boost only, a regulator on its OTG_EN bit + * (FUNCTION 0x02 bit 1), which the MAX77779 charger enables to give a USB-C + * device VBUS. Probe only reads (the device id, and the JEITA and watchdog + * settings it finds), except for a boost a previous boot left on, which it + * reports and turns off. Enabling turns off JEITA (0x0C bit 7; stock runs + * the RT9470 with it off, tegu's zumapro-buck-charge-rt9471.dtsi leaves + * en-jeita out), keeps the I2C watchdog at stock's 40 s (TOP 0x01 bits 1:0, + * wdt = <40>) and sets OTG_EN; disabling clears OTG_EN and puts JEITA and + * the watchdog back as probe found them. + * + * The watchdog is serviced as stock does it: the chip raises its WDT + * interrupt (IRQ3 bit 5) before the timer runs out and the handler kicks it + * (TOP bit 2). The interrupt line is the MAX77779 PMIC's SGPIO6, taken as a + * GPIO (int-gpios, so the pull-up stock sets on it comes with the request) + * and turned into an interrupt. Without the line, a kernel timer kicks the + * watchdog every 20 s instead, so a crash still ends the boost within 40 s + * either way. The chip enable (CEB, the PMIC's SGPIO7) is enable-gpios, + * asserted at probe. Shutdown turns the boost off. + * + * The charger part of the chip (charging, BC1.2, its other interrupts) is + * left alone. Registers from mainline rt9471.c and Google's GPL + * rt9471_charger.h and rt9471_charger.c (google-modules/bms at + * 183509aff980). + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RT9471_REG_OTGCFG 0x00 +#define RT9471_REG_TOP 0x01 +#define RT9471_WDT GENMASK(1, 0) +#define RT9471_WDT_40S 1 +#define RT9471_WDT_RST BIT(2) +#define RT9471_REG_FUNC 0x02 +#define RT9471_OTGEN BIT(1) +#define RT9471_REG_INFO 0x0b +#define RT9471_REG_JEITA 0x0c +#define RT9471_JEITA_EN BIT(7) +#define RT9471_DEVID GENMASK(6, 3) +#define RT9471_REG_IRQ3 0x23 /* write 1 to clear */ +#define RT9471_REG_MASK3 0x33 /* 1 = masked */ +#define RT9471_IRQ3_WDT BIT(5) /* interrupt 29 */ + +#define RT9471_KICK_MS 20000 /* half the 40 s watchdog */ + +static bool rt9471_boost_writeable(struct device *dev, unsigned int reg) +{ + return reg == RT9471_REG_FUNC || reg == RT9471_REG_TOP || + reg == RT9471_REG_JEITA || reg == RT9471_REG_IRQ3 || + reg == RT9471_REG_MASK3; +} + +static const struct regmap_config rt9471_boost_regmap = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0x33, + .writeable_reg = rt9471_boost_writeable, + .cache_type = REGCACHE_NONE, +}; + +struct rt9471_boost { + struct device *dev; + struct regmap *map; + struct gpio_desc *enable; + int irq; + struct delayed_work kick; + unsigned int jeita; /* JEITA_EN as probe found it */ + unsigned int wdt; /* the watchdog bits as probe found them */ + unsigned int mask3; /* MASK3 as probe found it */ +}; + +static int rt9471_boost_kick(struct rt9471_boost *b) +{ + return regmap_update_bits(b->map, RT9471_REG_TOP, RT9471_WDT_RST, RT9471_WDT_RST); +} + +static void rt9471_boost_kick_work(struct work_struct *work) +{ + struct rt9471_boost *b = container_of(to_delayed_work(work), + struct rt9471_boost, kick); + + if (rt9471_boost_kick(b)) + dev_err_ratelimited(b->dev, "cannot kick the watchdog\n"); + schedule_delayed_work(&b->kick, msecs_to_jiffies(RT9471_KICK_MS)); +} + +static irqreturn_t rt9471_boost_irq(int irq, void *data) +{ + struct rt9471_boost *b = data; + unsigned int irq3; + + if (regmap_read(b->map, RT9471_REG_IRQ3, &irq3)) + return IRQ_NONE; + if (!(irq3 & RT9471_IRQ3_WDT)) + return IRQ_NONE; + + rt9471_boost_kick(b); + regmap_write(b->map, RT9471_REG_IRQ3, RT9471_IRQ3_WDT); + return IRQ_HANDLED; +} + +static int rt9471_boost_enable(struct regulator_dev *rdev) +{ + struct rt9471_boost *b = rdev_get_drvdata(rdev); + int ret; + + ret = regmap_update_bits(b->map, RT9471_REG_JEITA, RT9471_JEITA_EN, 0) ?: + regmap_update_bits(b->map, RT9471_REG_TOP, RT9471_WDT, + FIELD_PREP(RT9471_WDT, RT9471_WDT_40S)) ?: + rt9471_boost_kick(b); + if (ret) + return ret; + + if (b->irq > 0) { + ret = regmap_write(b->map, RT9471_REG_IRQ3, RT9471_IRQ3_WDT) ?: + regmap_update_bits(b->map, RT9471_REG_MASK3, RT9471_IRQ3_WDT, 0); + if (ret) + return ret; + } else { + schedule_delayed_work(&b->kick, msecs_to_jiffies(RT9471_KICK_MS)); + } + + return regmap_update_bits(b->map, RT9471_REG_FUNC, RT9471_OTGEN, RT9471_OTGEN); +} + +static int rt9471_boost_off(struct rt9471_boost *b) +{ + cancel_delayed_work_sync(&b->kick); + return regmap_update_bits(b->map, RT9471_REG_FUNC, RT9471_OTGEN, 0) ?: + regmap_update_bits(b->map, RT9471_REG_MASK3, RT9471_IRQ3_WDT, + b->mask3 & RT9471_IRQ3_WDT) ?: + regmap_update_bits(b->map, RT9471_REG_JEITA, RT9471_JEITA_EN, b->jeita) ?: + regmap_update_bits(b->map, RT9471_REG_TOP, RT9471_WDT, b->wdt); +} + +static int rt9471_boost_disable(struct regulator_dev *rdev) +{ + return rt9471_boost_off(rdev_get_drvdata(rdev)); +} + +static const struct regulator_ops rt9471_boost_ops = { + .enable = rt9471_boost_enable, + .disable = rt9471_boost_disable, + .is_enabled = regulator_is_enabled_regmap, +}; + +static const struct regulator_desc rt9471_boost_desc = { + .name = "rt9471-otg-boost", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &rt9471_boost_ops, + .fixed_uV = 5000000, + .n_voltages = 1, + .enable_reg = RT9471_REG_FUNC, + .enable_mask = RT9471_OTGEN, + .enable_time = 5000, +}; + +static int rt9471_boost_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct regulator_config cfg = {}; + struct regulator_dev *rdev; + struct gpio_desc *int_gpio; + struct rt9471_boost *b; + struct regmap *map; + unsigned int info, func; + int ret; + + b = devm_kzalloc(dev, sizeof(*b), GFP_KERNEL); + if (!b) + return -ENOMEM; + b->dev = dev; + INIT_DELAYED_WORK(&b->kick, rt9471_boost_kick_work); + + /* CEB: asserted (low) keeps the chip on; stock drives it from the PMIC */ + b->enable = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH); + if (IS_ERR(b->enable)) + return dev_err_probe(dev, PTR_ERR(b->enable), "cannot get the enable line\n"); + + map = devm_regmap_init_i2c(client, &rt9471_boost_regmap); + if (IS_ERR(map)) + return PTR_ERR(map); + b->map = map; + + ret = regmap_read(map, RT9471_REG_INFO, &info); + if (ret) + return dev_err_probe(dev, ret, "no answer\n"); + /* RT9470 0x9, RT9470D 0xa, RT9471 0xd, RT9471D 0xe */ + switch (FIELD_GET(RT9471_DEVID, info)) { + case 0x9: case 0xa: case 0xd: case 0xe: + break; + default: + return dev_err_probe(dev, -ENODEV, "unknown id %#x\n", info); + } + dev_info(dev, "id %#lx\n", FIELD_GET(RT9471_DEVID, info)); + + ret = regmap_read(map, RT9471_REG_JEITA, &b->jeita) ?: + regmap_read(map, RT9471_REG_TOP, &b->wdt) ?: + regmap_read(map, RT9471_REG_MASK3, &b->mask3) ?: + regmap_read(map, RT9471_REG_FUNC, &func); + if (ret) + return dev_err_probe(dev, ret, "cannot read JEITA and the watchdog\n"); + b->jeita &= RT9471_JEITA_EN; + b->wdt &= RT9471_WDT; + dev_info(dev, "JEITA %s, watchdog %s (%#x)\n", + b->jeita ? "on" : "off", b->wdt ? "on" : "off", b->wdt); + + if (func & RT9471_OTGEN) { + dev_warn(dev, "the boost was left on (a reset in host mode?); turning it off\n"); + ret = regmap_update_bits(map, RT9471_REG_FUNC, RT9471_OTGEN, 0); + if (ret) + return dev_err_probe(dev, ret, "cannot turn the boost off\n"); + } + + /* the WDT interrupt: stock's PLC_INT_L on the PMIC's SGPIO6, pulled up */ + int_gpio = devm_gpiod_get_optional(dev, "int", GPIOD_IN); + if (IS_ERR(int_gpio)) + return dev_err_probe(dev, PTR_ERR(int_gpio), "cannot get the interrupt line\n"); + if (int_gpio) { + b->irq = gpiod_to_irq(int_gpio); + if (b->irq < 0) + return dev_err_probe(dev, b->irq, "the interrupt line has no interrupt\n"); + ret = devm_request_threaded_irq(dev, b->irq, NULL, rt9471_boost_irq, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + dev_name(dev), b); + if (ret) + return dev_err_probe(dev, ret, "cannot request the interrupt\n"); + dev_info(dev, "watchdog serviced from interrupt %d\n", b->irq); + } else { + dev_info(dev, "no interrupt line: a timer kicks the watchdog\n"); + } + + i2c_set_clientdata(client, b); + cfg.dev = dev; + cfg.regmap = map; + cfg.driver_data = b; + cfg.of_node = dev->of_node; + cfg.init_data = of_get_regulator_init_data(dev, dev->of_node, + &rt9471_boost_desc); + rdev = devm_regulator_register(dev, &rt9471_boost_desc, &cfg); + return PTR_ERR_OR_ZERO(rdev); +} + +static void rt9471_boost_shutdown(struct i2c_client *client) +{ + struct rt9471_boost *b = i2c_get_clientdata(client); + + if (rt9471_boost_off(b)) + dev_err(&client->dev, "cannot turn the boost off at shutdown\n"); +} + +static const struct of_device_id rt9471_boost_of_match[] = { + { .compatible = "omamobile,tegu-rt9471-boost" }, + { } +}; +MODULE_DEVICE_TABLE(of, rt9471_boost_of_match); + +static struct i2c_driver rt9471_boost_driver = { + .driver = { + .name = "tegu-rt9471-boost", + .of_match_table = rt9471_boost_of_match, + }, + .probe = rt9471_boost_probe, + .shutdown = rt9471_boost_shutdown, +}; +module_i2c_driver(rt9471_boost_driver); + +MODULE_DESCRIPTION("RT9471 OTG boost for the Pixel 9a's USB-C port"); +MODULE_LICENSE("GPL"); diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index e357744d4a..e70ceb9c20 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -7,7 +7,10 @@ #include #include +#include #include +#include +#include #include #include #include @@ -343,6 +346,8 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_CLUSTER1_NONCPU_INT_EN 0x1544 #define ZUMA_HSI0_STATUS 0x2a84 #define ZUMA_PHY_CTRL_UFS 0x3ec0 +#define ZUMA_NFC_CLK_PAD 0x3e84 +#define ZUMA_NFC_CLK_PAD_EXTPAD_EN BIT(16) static const struct regmap_range zuma_pmu_registers[] = { /* reboot mode */ @@ -360,6 +365,8 @@ static const struct regmap_range zuma_pmu_registers[] = { regmap_reg_range(ZUMA_PHY_CTRL_UFS, ZUMA_PHY_CTRL_UFS), /* a hint TF-A reads, not a status register: see zuma_pmu_regmap_init() */ regmap_reg_range(ZUMA_PMU_INFORM0, ZUMA_PMU_INFORM0), + /* the NFC controller's clock pad: see zuma_pmu_nfc_pad_ops */ + regmap_reg_range(ZUMA_NFC_CLK_PAD, ZUMA_NFC_CLK_PAD), }; static const struct regmap_range zuma_pmu_ro_registers[] = { @@ -386,6 +393,77 @@ static const struct regmap_access_table zuma_pmu_wr_table = { * INVALID_PARAMETERS) until the kernel allows C2 in PMU_INFORM0, as Google's * exynos-cpupm does once at init. */ +/* + * The NFC controller's reference clock pad (clock 0 of the PMU): with + * EXTPAD_EN set the PMU follows the controller's CLK_REQ line and feeds it + * the pad clock, as Google's st21nfc driver sets it (pmu_clk_pad 0x3e84, + * st,extpad_control_en). Without it the Pixel 9a's ST54L answers NCI but + * never finds a card. + */ +struct zuma_pmu_clk_pad { + struct clk_hw hw; + struct regmap *regmap; +}; + +static int zuma_pmu_nfc_pad_enable(struct clk_hw *hw) +{ + struct zuma_pmu_clk_pad *pad = container_of(hw, struct zuma_pmu_clk_pad, hw); + + return regmap_set_bits(pad->regmap, ZUMA_NFC_CLK_PAD, + ZUMA_NFC_CLK_PAD_EXTPAD_EN); +} + +static void zuma_pmu_nfc_pad_disable(struct clk_hw *hw) +{ + struct zuma_pmu_clk_pad *pad = container_of(hw, struct zuma_pmu_clk_pad, hw); + + regmap_clear_bits(pad->regmap, ZUMA_NFC_CLK_PAD, + ZUMA_NFC_CLK_PAD_EXTPAD_EN); +} + +static int zuma_pmu_nfc_pad_is_enabled(struct clk_hw *hw) +{ + struct zuma_pmu_clk_pad *pad = container_of(hw, struct zuma_pmu_clk_pad, hw); + + return regmap_test_bits(pad->regmap, ZUMA_NFC_CLK_PAD, + ZUMA_NFC_CLK_PAD_EXTPAD_EN); +} + +static const struct clk_ops zuma_pmu_nfc_pad_ops = { + .enable = zuma_pmu_nfc_pad_enable, + .disable = zuma_pmu_nfc_pad_disable, + .is_enabled = zuma_pmu_nfc_pad_is_enabled, +}; + +static int zuma_pmu_register_clks(struct device *dev, struct regmap *regmap) +{ + struct clk_init_data init = { + .name = "zuma_pmu_nfc_clk_pad", + .ops = &zuma_pmu_nfc_pad_ops, + }; + struct clk_hw_onecell_data *data; + struct zuma_pmu_clk_pad *pad; + int ret; + + if (!of_property_present(dev->of_node, "#clock-cells")) + return 0; + + pad = devm_kzalloc(dev, sizeof(*pad), GFP_KERNEL); + data = devm_kzalloc(dev, struct_size(data, hws, 1), GFP_KERNEL); + if (!pad || !data) + return -ENOMEM; + + pad->regmap = regmap; + pad->hw.init = &init; + ret = devm_clk_hw_register(dev, &pad->hw); + if (ret) + return ret; + + data->num = 1; + data->hws[0] = &pad->hw; + return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, data); +} + static void zuma_pmu_regmap_init(struct device *dev, struct regmap *regmap) { int ret; @@ -393,6 +471,10 @@ static void zuma_pmu_regmap_init(struct device *dev, struct regmap *regmap) ret = regmap_write(regmap, ZUMA_PMU_INFORM0, ZUMA_PMU_ALLOWED_C2); if (ret) dev_warn(dev, "failed to allow C2 in PMU_INFORM0: %d\n", ret); + + ret = zuma_pmu_register_clks(dev, regmap); + if (ret) + dev_warn(dev, "failed to register the PMU clocks: %d\n", ret); } /*