diff --git a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml index 7859baca69..cae6c53cc1 100644 --- a/Documentation/devicetree/bindings/media/google,gs201-csis.yaml +++ b/Documentation/devicetree/bindings/media/google,gs201-csis.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/media/google,gs201-csis.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 CSIS camera receiver link and CSIS WDMA +title: Google gs201 and zumapro CSIS camera receiver link and CSIS WDMA maintainers: - Derek Ross @@ -13,48 +13,36 @@ description: The camera block of Google's gs201 SoC has eight MIPI CSI-2 receiver links (CSIS) and a DMA block whose CSIS WDMA contexts write a link's frames to memory. One node describes one link and the WDMA context it feeds. + zumapro (Tensor G4) has the same receiver link in its ISP front end, with + twelve link contexts; its DMA path is different and not described here. properties: compatible: - const: google,gs201-csis + enum: + - google,gs201-csis + - google,zumapro-csis reg: - minItems: 3 - items: - - description: the CSIS link registers - - description: the CSIS DMA block's common page (shared by all links) - - description: the CSIS WDMA context (links may share one; they then - stream one at a time) - - description: the EBUF control (shared by all links), bypassed on the - way to the WDMA + minItems: 1 + maxItems: 4 reg-names: - minItems: 3 - items: - - const: link - - const: dma - - const: wdma - - const: ebuf + minItems: 1 + maxItems: 4 interrupts: - items: - - description: link interrupt - - description: WDMA context interrupt + minItems: 1 + maxItems: 2 interrupt-names: - items: - - const: link - - const: wdma + minItems: 1 + maxItems: 2 clocks: - items: - - description: the camera block's DVFS domain - - description: the bus (INT) DVFS domain + maxItems: 2 clock-names: - items: - - const: cam - - const: int + maxItems: 2 phys: maxItems: 1 @@ -62,8 +50,8 @@ properties: google,csis-link: $ref: /schemas/types.yaml#/definitions/uint32 - maximum: 7 - description: Index of the CSIS link. + maximum: 11 + description: Index of the CSIS link (0-7 on gs201). google,wdma-context: $ref: /schemas/types.yaml#/definitions/uint32 @@ -82,6 +70,13 @@ properties: description: WDMA input slot the link is routed to; defaults to the context index. + google,image-loch: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 6 + description: + zumapro only. The CSIS core's image logical channel the link writes + its frames through; defaults to 0. + google,lrte-packet-delimiters: type: boolean description: @@ -132,10 +127,88 @@ required: - interrupt-names - phys - google,csis-link - - google,wdma-context - - google,csis-sysreg - port +allOf: + - if: + properties: + compatible: + const: google,gs201-csis + then: + properties: + reg: + minItems: 3 + items: + - description: the CSIS link registers + - description: the CSIS DMA block's common page (shared by all links) + - description: the CSIS WDMA context (links may share one; they + then stream one at a time) + - description: the EBUF control (shared by all links), bypassed on + the way to the WDMA + reg-names: + minItems: 3 + items: + - const: link + - const: dma + - const: wdma + - const: ebuf + interrupts: + items: + - description: link interrupt + - description: WDMA context interrupt + interrupt-names: + items: + - const: link + - const: wdma + clocks: + items: + - description: the camera block's DVFS domain + - description: the bus (INT) DVFS domain + clock-names: + items: + - const: cam + - const: int + google,csis-link: + maximum: 7 + google,image-loch: false + required: + - google,wdma-context + - google,csis-sysreg + else: + properties: + reg: + minItems: 1 + items: + - description: the CSIS link registers + - description: the ISP front end's CSIS core page, shared by all + links; without it the link runs without DMA + reg-names: + minItems: 1 + items: + - const: link + - const: core + interrupts: + minItems: 1 + items: + - description: link interrupt + - description: CSIS core interrupt, shared by all links + interrupt-names: + minItems: 1 + items: + - const: link + - const: core + clocks: + items: + - description: the INT DVFS domain, the ISP front end clock's rail + - description: the ISP front end's NOC clock + clock-names: + items: + - const: int + - const: fe + google,wdma-context: false + google,csis-sysreg: false + google,ebuf: false + additionalProperties: false examples: diff --git a/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml b/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml index 3325351f95..031f08548d 100644 --- a/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml +++ b/Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml @@ -13,7 +13,8 @@ description: Samsung Bayer CMOS sensors with a MIPI CSI-2 C-PHY or D-PHY output, controlled over I2C - the S5KGN1 (ISOCELL GN1, 50 MP, dual-pixel phase detection), the S5K3J1 (10.5 MP, dual-pixel phase detection) and the - S5KGM5 (ISOCELL GM5, 48 MP). Their initialisation and readout modes are + S5KGM5 (ISOCELL GM5, 48 MP), and the S5KGN8 (model 0x08e8, the Pixel 9a + main camera). Their initialisation and readout modes are loaded from a data file named by firmware-name. allOf: @@ -21,7 +22,9 @@ allOf: - if: properties: compatible: - const: samsung,s5kgn1 + enum: + - samsung,s5kgn1 + - samsung,s5kgn8 then: required: - vaux-supply @@ -29,6 +32,19 @@ allOf: else: properties: vaux-supply: false + - if: + properties: + compatible: + const: samsung,s5kgn8 + then: + required: + - vaux2-supply + - vdig-supply + properties: + vsw-supply: false + else: + properties: + vaux2-supply: false - if: properties: compatible: @@ -52,6 +68,7 @@ properties: - samsung,s5k3j1 - samsung,s5kgm5 - samsung,s5kgn1 + - samsung,s5kgn8 reg: maxItems: 1 @@ -71,6 +88,11 @@ properties: The module's auxiliary supply (2.9 V on the Pixel 7 Pro, shared with its focus actuator), switched on right after the interface supply. + vaux2-supply: + description: + A second auxiliary supply (2.9 V on the Pixel 9a, shared with the + module's focus actuator and EEPROM), switched on after vaux-supply. + vsw-supply: description: A switched module supply, on before the core supplies (S5KGN1) or diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml b/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml index 43d08cf600..5452de0770 100644 --- a/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml +++ b/Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml @@ -4,22 +4,25 @@ $id: http://devicetree.org/schemas/media/i2c/sony,imx386.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Sony IMX386 image sensor +title: Sony IMX386 and IMX712 image sensors maintainers: - Derek Ross description: Sony IMX386 12 MP Bayer CMOS sensor with a MIPI CSI-2 D-PHY output, - controlled over I2C. Its initialisation and readout modes are loaded from - a data file named by firmware-name. + controlled over I2C, and the IMX712 (the Pixel 9a's ultrawide and front + cameras), which has the same register map. Their initialisation and + readout modes are loaded from a data file named by firmware-name. allOf: - $ref: /schemas/media/video-interface-devices.yaml# properties: compatible: - const: sony,imx386 + enum: + - sony,imx386 + - sony,imx712 reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml b/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml index 38b4b835d1..e37d2c54d4 100644 --- a/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml +++ b/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml @@ -35,6 +35,31 @@ properties: wakeup-source: true + gpio: + type: object + description: + The PMIC's six general purpose pins. On the Pixel 9a one switches + the main camera's digital supply. + + properties: + compatible: + const: samsung,s2mpg14-gpio + + gpio-controller: true + + '#gpio-cells': + const: 2 + + gpio-line-names: + maxItems: 6 + + required: + - compatible + - gpio-controller + - '#gpio-cells' + + additionalProperties: false + regulators: type: object $ref: /schemas/regulator/samsung,s2mpg14-regulator.yaml @@ -60,6 +85,12 @@ examples: google,vgpio2ap-sysreg = <&sysreg_vgpio2ap>; wakeup-source; + gpio { + compatible = "samsung,s2mpg14-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + regulators { ldo4m { regulator-name = "touch-avdd"; diff --git a/Documentation/devicetree/bindings/mfd/samsung,s2mpg15-pmic.yaml b/Documentation/devicetree/bindings/mfd/samsung,s2mpg15-pmic.yaml index 90d7e84423..3f4a1902ac 100644 --- a/Documentation/devicetree/bindings/mfd/samsung,s2mpg15-pmic.yaml +++ b/Documentation/devicetree/bindings/mfd/samsung,s2mpg15-pmic.yaml @@ -13,12 +13,38 @@ description: | S2MPG15 is the sub PMIC paired with Google's Tensor G4 and is reached through ACPM. Its LDOs supply the AoC sensors, the GNSS receiver, the camera sensors and the fingerprint sensor. - Interrupt, meter, GPIO and RTC functions are not described here. + Interrupt, meter and RTC functions are not described here. properties: compatible: const: samsung,s2mpg15-pmic + gpio: + type: object + description: + The PMIC's ten general purpose pins. On the Pixel 9a they enable + the camera buck-boost, the camera PMIC and the cameras' 1.35 V + supply. + + properties: + compatible: + const: samsung,s2mpg15-gpio + + gpio-controller: true + + '#gpio-cells': + const: 2 + + gpio-line-names: + maxItems: 10 + + required: + - compatible + - gpio-controller + - '#gpio-cells' + + additionalProperties: false + regulators: type: object $ref: /schemas/regulator/samsung,s2mpg15-regulator.yaml @@ -34,6 +60,12 @@ examples: pmic-2 { compatible = "samsung,s2mpg15-pmic"; + gpio { + compatible = "samsung,s2mpg15-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + regulators { ldo5s { regulator-name = "sensor-3v3"; diff --git a/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml b/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml index 9e50ca4c6f..28a20e5b56 100644 --- a/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml +++ b/Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/phy/google,gs201-mipi-dcphy-rx.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 MIPI DC-PHY receiver +title: Google gs201 and zumapro MIPI DC-PHY receiver maintainers: - Derek Ross @@ -17,11 +17,15 @@ description: one PMU isolation control. The PHY cell selects the link. Each slave receives D-PHY or C-PHY (up to three trios on links 0 and 1, two on the others); the consumer selects the mode at run time, from its endpoint's - bus type. + bus type. zumapro (Tensor G4) has nine slaves for twelve CSIS links, the + clock lane first on each, and one reset bit per slave; the PHY cell is + the CSIS link. properties: compatible: - const: google,gs201-mipi-dcphy-rx + enum: + - google,gs201-mipi-dcphy-rx + - google,zumapro-mipi-dcphy-rx reg: maxItems: 1 @@ -42,7 +46,7 @@ properties: items: - items: - description: the camera block's system registers - - description: offset of the per-slave reset register (bit = link) + - description: offset of the per-slave reset register (bit = slave) description: The register that holds each DC-PHY slave in reset (bit clear) or releases it (bit set). diff --git a/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml b/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml index 6b5892fe9d..2c71c1ca7f 100644 --- a/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml @@ -35,6 +35,7 @@ properties: - google,zuma-ufs-sysreg - google,zumapro-apm-sysreg - google,zumapro-hsi0-sysreg + - google,zumapro-ispfe-sysreg - google,zumapro-peric0-sysreg - google,zumapro-peric1-sysreg - google,zumapro-ufs-sysreg diff --git a/MAINTAINERS b/MAINTAINERS index d5c748f6f6..4bd0d5da0d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11155,6 +11155,20 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git F: drivers/firmware/google/ F: include/linux/coreboot.h +GOOGLE GS201 AND ZUMAPRO CAMERA RECEIVER (CSIS) AND MIPI DC-PHY +M: Derek Ross +R: W4HO <87742609+W4HO-ham@users.noreply.github.com> +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/google,gs201-csis.yaml +F: Documentation/devicetree/bindings/media/i2c/samsung,s5kgn1.yaml +F: Documentation/devicetree/bindings/media/i2c/sony,imx386.yaml +F: Documentation/devicetree/bindings/phy/google,gs201-mipi-dcphy-rx.yaml +F: drivers/media/i2c/imx386.c +F: drivers/media/i2c/s5kgn1.c +F: drivers/media/platform/samsung/gs201-csis/ +F: drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c + GOOGLE TENSOR SoC SUPPORT M: Peter Griffin R: André Draszik diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts index f66e006084..1466f2c3fa 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "../exynos-pinctrl.h" #include "zumapro.dtsi" @@ -138,6 +139,25 @@ }; }; + /* The cameras' 1.35 V (stock's PP1350_CAM), on the sub-PMIC's GPIO 2. */ + cam_1v35: regulator-cam-1v35 { + compatible = "regulator-fixed"; + regulator-name = "pp1350-cam"; + regulator-min-microvolt = <1350000>; + regulator-max-microvolt = <1350000>; + gpio = <&pmic_sub_gpio 2 GPIO_ACTIVE_HIGH>; + enable-active-high; + startup-delay-us = <2000>; + }; + + /* The main camera's digital supply: a switch on the main PMIC's GPIO 0. */ + cam_main_vdig: regulator-cam-main-vdig { + compatible = "regulator-fixed"; + regulator-name = "cam-main-vdig"; + gpio = <&pmic_main_gpio 0 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; + /* UFS VCC, switched by gpp0-1 as on stock. */ ufs_vcc: regulator-ufs-vcc { compatible = "regulator-fixed"; @@ -174,9 +194,15 @@ &acpm_ipc { status = "okay"; - pmic-1 { + pmic_main: pmic-1 { compatible = "samsung,s2mpg14-pmic"; + pmic_main_gpio: gpio { + compatible = "samsung,s2mpg14-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + regulators { touch_avdd: ldo4m { regulator-name = "touch-avdd"; @@ -196,9 +222,20 @@ }; }; - pmic-2 { + /* + * The sub-PMIC. Its GPIO 0 selects the camera PMIC, GPIO 1 enables + * the camera buck-boost and GPIO 2 the cameras' 1.35 V, as in stock's + * board description; all ten pins are outputs, low, at hand-off. + */ + pmic_sub: pmic-2 { compatible = "samsung,s2mpg15-pmic"; + pmic_sub_gpio: gpio { + compatible = "samsung,s2mpg15-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + regulators { sensor_3v3: ldo5s { regulator-name = "sensor-3v3"; @@ -207,6 +244,11 @@ sensor_1v8: ldo7s { regulator-name = "sensor-1v8"; }; + + /* the camera sensors' shared 1.8 V (stock's S2MPG15 LDO12) */ + cam_1v8: ldo12s { + regulator-name = "cam-1v8"; + }; }; }; }; @@ -283,6 +325,51 @@ status = "okay"; }; +/* The main camera's receiver: three C-PHY trios on DC-PHY slave 0. */ +&csis0 { + /* without them the link decodes frame starts and nothing else */ + google,lrte-packet-delimiters; + status = "okay"; + + port { + csis0_in: endpoint { + remote-endpoint = <&cam_main_out>; + bus-type = ; + data-lanes = <1 2 3>; + }; + }; +}; + +/* The ultrawide's receiver: four D-PHY lanes on slave 1. */ +&csis1 { + status = "okay"; + + port { + csis1_in: endpoint { + remote-endpoint = <&cam_uw_out>; + data-lanes = <1 2 3 4>; + }; + }; +}; + +/* The front camera's receiver. */ +&csis6 { + status = "okay"; + + port { + csis6_in: endpoint { + remote-endpoint = <&cam_front_out>; + data-lanes = <1 2 3 4>; + }; + }; +}; + +/* The receive settings are a data file taken from the owner's own phone. */ +&csis_dcphy { + firmware-name = "omamobile/camera/zumapro-dcphy.bin"; + status = "okay"; +}; + /* * DECON0 scans out to DSIM0, so gs-decon can switch the link and the * panel between 60 and 120 Hz. @@ -433,7 +520,95 @@ }; }; -/* The torch: a TI LM3644 flash driver, both LED outputs on one white LED. */ +/* + * The ultrawide, a Sony IMX712 (stock's sensor-leshen-uw), powered in stock's + * order: PP3200_CAM_BB, PP1350, LDO12S, LDO3, LDO6, reset, master clock. + * Master clock: CMU_TOP CIS_CLK0 from OSCCLK (24.576 MHz; stock asks for + * 24 MHz), out on gpp3-0. + */ +&hsi2c2 { + clock-frequency = <400000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c2_bus>; + status = "okay"; + + cam_uw: camera@1a { + compatible = "sony,imx712"; + reg = <0x1a>; + clocks = <&cmu_top CLK_DOUT_CIS_CLK0>; + assigned-clocks = <&cmu_top CLK_MOUT_CIS_CLK0>, + <&cmu_top CLK_DOUT_CIS_CLK0>; + assigned-clock-parents = <&oscclk>, <0>; + assigned-clock-rates = <0>, <24576000>; + pinctrl-names = "default"; + pinctrl-0 = <&cam_uw_mclk>; + /* high runs the sensor */ + reset-gpios = <&gpp4 2 GPIO_ACTIVE_LOW>; + vbb-supply = <&cam_bb>; + vbuck-supply = <&cam_1v35>; + vif-supply = <&cam_1v8>; + vdig-supply = <&cam_ldo6>; + vana-supply = <&cam_ldo3>; + firmware-name = "omamobile/camera/imx712-uw.bin"; + orientation = <1>; /* back */ + + port { + cam_uw_out: endpoint { + remote-endpoint = <&csis1_in>; + data-lanes = <1 2 3 4>; + link-frequencies = /bits/ 64 <552960000 479232000>; + }; + }; + }; +}; + +/* + * The front camera, a second IMX712 (stock's sensor-leshen), powered in + * stock's order: PP3200_CAM_BB, PP1350, LDO12S, LDO2, LDO7, reset, master + * clock (CMU_TOP CIS_CLK1 from OSCCLK, out on gpp5-0). This bus has no + * external pull-ups; stock turns the internal ones on. + */ +&hsi2c3 { + clock-frequency = <400000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c3_bus>; + status = "okay"; + + cam_front: camera@1a { + compatible = "sony,imx712"; + reg = <0x1a>; + clocks = <&cmu_top CLK_DOUT_CIS_CLK1>; + assigned-clocks = <&cmu_top CLK_MOUT_CIS_CLK1>, + <&cmu_top CLK_DOUT_CIS_CLK1>; + assigned-clock-parents = <&oscclk>, <0>; + assigned-clock-rates = <0>, <24576000>; + pinctrl-names = "default"; + pinctrl-0 = <&cam_front_mclk>; + /* high runs the sensor */ + reset-gpios = <&gpp6 2 GPIO_ACTIVE_LOW>; + vbb-supply = <&cam_bb>; + vbuck-supply = <&cam_1v35>; + vif-supply = <&cam_1v8>; + vdig-supply = <&cam_ldo7>; + vana-supply = <&cam_ldo2>; + /* the same sensor and modes as the ultrawide */ + firmware-name = "omamobile/camera/imx712-uw.bin"; + orientation = <0>; /* front */ + + port { + cam_front_out: endpoint { + remote-endpoint = <&csis6_in>; + data-lanes = <1 2 3 4>; + link-frequencies = /bits/ 64 <552960000 479232000>; + }; + }; + }; +}; + +/* + * The torch (a TI LM3644 flash driver, both LED outputs on one white LED) + * and the cameras' power chips. + */ &hsi2c4 { clock-frequency = <100000>; pinctrl-names = "default"; @@ -455,6 +630,123 @@ led-max-microamp = <75000>; }; }; + + /* + * The camera PMIC: an SLG51002 behind the camera buck-boost, whose + * LDOs feed the three camera sensors. Voltages as stock's board + * description; every LDO stays off until a sensor is powered. + */ + cam_pmic: pmic@75 { + compatible = "dlg,slg51002"; + reg = <0x75>; + dlg,cs-gpios = <&pmic_sub_gpio 0 GPIO_ACTIVE_HIGH>; + vin1-2-supply = <&cam_bb>; + vin3-supply = <&cam_bb>; + vin4-supply = <&cam_bb>; + vin5-supply = <&cam_bb>; + + regulators { + cam_ldo1: ldo1 { + regulator-name = "cam-ldo1"; + regulator-min-microvolt = <2250000>; + regulator-max-microvolt = <2250000>; + }; + + cam_ldo2: ldo2 { + regulator-name = "cam-ldo2"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + }; + + cam_ldo3: ldo3 { + regulator-name = "cam-ldo3"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + }; + + cam_ldo4: ldo4 { + regulator-name = "cam-ldo4"; + regulator-min-microvolt = <2900000>; + regulator-max-microvolt = <2900000>; + }; + + cam_ldo5: ldo5 { + regulator-name = "cam-ldo5"; + regulator-min-microvolt = <2900000>; + regulator-max-microvolt = <2900000>; + }; + + cam_ldo6: ldo6 { + regulator-name = "cam-ldo6"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + }; + + cam_ldo7: ldo7 { + regulator-name = "cam-ldo7"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + }; + }; + }; + + /* The camera buck-boost (stock's PP3200_CAM_BB), an RT6160. */ + cam_bb: regulator@77 { + compatible = "richtek,rt6160"; + reg = <0x77>; + enable-gpios = <&pmic_sub_gpio 1 GPIO_ACTIVE_HIGH>; + regulator-name = "pp3200-cam-bb"; + regulator-min-microvolt = <3200000>; + regulator-max-microvolt = <3200000>; + regulator-enable-ramp-delay = <2000>; + }; +}; + +/* + * The main camera, a Samsung GN8 (stock's sensor-barghest), on three C-PHY + * trios, powered in stock's order: PP3200_CAM_BB, PP1350, LDO12S, LDO5, + * LDO4, LDO1, the digital supply, reset, master clock. Master clock: + * CMU_TOP CIS_CLK3 from OSCCLK (24.576 MHz; stock asks for 26 MHz), out on + * gpp9-0. Bus pins pulled up internally, as stock. + */ +&hsi2c5 { + clock-frequency = <400000>; + pinctrl-names = "default"; + pinctrl-0 = <&hsi2c5_bus>; + status = "okay"; + + cam_main: camera@56 { + compatible = "samsung,s5kgn8"; + reg = <0x56>; + clocks = <&cmu_top CLK_DOUT_CIS_CLK3>; + assigned-clocks = <&cmu_top CLK_MOUT_CIS_CLK3>, + <&cmu_top CLK_DOUT_CIS_CLK3>; + assigned-clock-parents = <&oscclk>, <0>; + assigned-clock-rates = <0>, <24576000>; + pinctrl-names = "default"; + pinctrl-0 = <&cam_main_mclk>; + reset-gpios = <&gpp10 2 GPIO_ACTIVE_LOW>; + vbb-supply = <&cam_bb>; + vbuck-supply = <&cam_1v35>; + vio-supply = <&cam_1v8>; + vaux-supply = <&cam_ldo5>; + vaux2-supply = <&cam_ldo4>; + vana-supply = <&cam_ldo1>; + vdig-supply = <&cam_main_vdig>; + firmware-name = "omamobile/camera/s5kgn8-main.bin"; + /* its lines burst at over 2 GB/s; 550 MB/s lines land cleanly */ + samsung,max-line-throughput = <500>; + orientation = <1>; /* back */ + + port { + cam_main_out: endpoint { + remote-endpoint = <&csis0_in>; + bus-type = ; + data-lanes = <1 2 3>; + link-frequencies = /bits/ 64 <1370112000>; + }; + }; + }; }; /* @@ -590,6 +882,41 @@ &pinctrl_peric0 { status = "okay"; + cam_front_mclk: cam-front-mclk-pins { + samsung,pins = "gpp5-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <1>; + }; + + cam_main_mclk: cam-main-mclk-pins { + samsung,pins = "gpp9-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <1>; + }; + + cam_uw_mclk: cam-uw-mclk-pins { + samsung,pins = "gpp3-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <1>; + }; + + hsi2c2_bus: hsi2c2-bus-pins { + samsung,pins = "gpp4-0", "gpp4-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + + hsi2c3_bus: hsi2c3-bus-pins { + samsung,pins = "gpp6-0", "gpp6-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = <0>; + }; + hsi2c4_bus: hsi2c4-bus-pins { samsung,pins = "gpp8-0", "gpp8-1"; samsung,pin-function = ; @@ -597,6 +924,13 @@ samsung,pin-drv = <0>; }; + hsi2c5_bus: hsi2c5-bus-pins { + samsung,pins = "gpp10-0", "gpp10-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 = ; @@ -668,6 +1002,10 @@ status = "okay"; }; +&sysreg_ispfe { + status = "okay"; +}; + &sysreg_peric0 { status = "okay"; }; @@ -747,6 +1085,10 @@ status = "okay"; }; +&usi2 { + status = "okay"; +}; + /* * Hold the touchscreen in reset before the USI's probe switches it to SPI; * the touch driver releases it. @@ -757,6 +1099,10 @@ status = "okay"; }; +&usi3 { + status = "okay"; +}; + &usi4 { status = "okay"; }; @@ -765,6 +1111,10 @@ status = "okay"; }; +&usi5 { + status = "okay"; +}; + &usi6 { status = "okay"; }; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi index be17249e58..e401f3c0dd 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi @@ -1645,6 +1645,86 @@ status = "disabled"; }; + /* + * The ISP front end: its camera receiver links, their MIPI + * DC-PHY slaves and the CSIS core that writes frames to memory + * through logical channels. The bootloader leaves the block + * powered and its CMU_ISPFE gates on; there's no power domain + * or CMU_ISPFE driver yet. + */ + sysreg_ispfe: syscon@1c020000 { + compatible = "google,zumapro-ispfe-sysreg", "syscon"; + reg = <0x0 0x1c020000 0x10000>; + status = "disabled"; + }; + + /* + * Link n's registers are at 0x1c040000 + n * 0x10000 and its + * interrupt is SPI 467 + n; all links share the CSIS core and + * its interrupt. Only the links the Pixel 9a's cameras use are + * described. + */ + csis0: csis@1c040000 { + compatible = "google,zumapro-csis"; + reg = <0x0 0x1c040000 0x1000>, <0x0 0x1c320000 0x2000>; + reg-names = "link", "core"; + interrupts = , + ; + interrupt-names = "link", "core"; + /* INT DVFS (the ISP-FE NOC clock's rail), then the clock */ + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_INT>, + <&cmu_top CLK_DOUT_ISPFE_NOC>; + clock-names = "int", "fe"; + phys = <&csis_dcphy 0>; + google,csis-link = <0>; + status = "disabled"; + }; + + csis1: csis@1c050000 { + compatible = "google,zumapro-csis"; + reg = <0x0 0x1c050000 0x1000>, <0x0 0x1c320000 0x2000>; + reg-names = "link", "core"; + interrupts = , + ; + interrupt-names = "link", "core"; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_INT>, + <&cmu_top CLK_DOUT_ISPFE_NOC>; + clock-names = "int", "fe"; + phys = <&csis_dcphy 1>; + google,csis-link = <1>; + status = "disabled"; + }; + + /* Four D-PHY lanes on slave 5 with slave 6's clock lane. */ + csis6: csis@1c0a0000 { + compatible = "google,zumapro-csis"; + reg = <0x0 0x1c0a0000 0x1000>, <0x0 0x1c320000 0x2000>; + reg-names = "link", "core"; + interrupts = , + ; + interrupt-names = "link", "core"; + clocks = <&acpm_ipc ZUMAPRO_CLK_ACPM_DVFS_INT>, + <&cmu_top CLK_DOUT_ISPFE_NOC>; + clock-names = "int", "fe"; + phys = <&csis_dcphy 6>; + google,csis-link = <6>; + status = "disabled"; + }; + + /* + * The DC-PHY slaves (bias at +0x1000), their resets in the + * ISP-FE sysreg at 0x500 (bit n for slave n), and their PMU + * isolation at 0x3ebc as on gs201. + */ + csis_dcphy: phy@1c100000 { + compatible = "google,zumapro-mipi-dcphy-rx"; + reg = <0x0 0x1c100000 0x4000>; + #phy-cells = <1>; + samsung,pmu-syscon = <&pmu_system_controller 0x3ebc>; + google,reset-sysreg = <&sysreg_ispfe 0x500>; + status = "disabled"; + }; + /* The bootloader leaves G3D powered; there's no power domain yet. */ cmu_g3d: clock-controller@1ee00000 { compatible = "google,zumapro-cmu-g3d"; diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 819f1053eb..09df4a84e8 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1651,12 +1651,13 @@ config GPIO_RC5T583 of RC5T583 device through standard GPIO library. config GPIO_S2MPG13 - tristate "Samsung S2MPG13 PMIC GPIO support" + tristate "Samsung S2MPG13, S2MPG14 and S2MPG15 PMIC GPIO support" depends on MFD_SEC_ACPM help - Support for the eight GPIOs of the Samsung S2MPG13 sub-PMIC paired - with Google's gs201 SoC, reached through the ACPM firmware. On the - Pixel 7 boards they switch the camera supplies. + Support for the GPIOs of the Samsung S2MPG13 sub-PMIC paired with + Google's gs201 SoC and of the S2MPG14 and S2MPG15 PMICs paired with + the Tensor G4, reached through the ACPM firmware. On the Pixel 7 + and Pixel 9a boards they switch the camera supplies. This driver can also be built as a module. If so, the module will be called gpio-s2mpg13. diff --git a/drivers/gpio/gpio-s2mpg13.c b/drivers/gpio/gpio-s2mpg13.c index 368eb98da7..919d21d701 100644 --- a/drivers/gpio/gpio-s2mpg13.c +++ b/drivers/gpio/gpio-s2mpg13.c @@ -8,29 +8,62 @@ * level and an output enable bit; the input levels of all pins are in one * status register. On the Pixel 7 boards they switch the camera supplies. * - * The register layout is from Google's GPL s2mpg13 register header and its - * s2mpg1x GPIO driver. Only the output level and output enable bits are - * ever changed; the pin mode, pulls and drive strength stay as the - * bootloader left them. + * The Tensor G4's PMICs have the same pin control registers at other + * offsets: six pins on the S2MPG14 main PMIC and ten on the S2MPG15 + * sub-PMIC, whose input levels take two status registers. On the Pixel 9a + * they switch the camera power. + * + * The register layouts are from Google's GPL s2mpg13, s2mpg14 and s2mpg15 + * register headers and its s2mpg1x GPIO driver. Only the output level + * and output enable bits are ever changed; the pin mode, pulls and drive + * strength stay as the bootloader left them. */ #include #include #include #include +#include +#include #include #include #include #include +/* Where a chip keeps its SET and status registers; the SET bits are common. */ +struct s2mpg1x_gpio_data { + unsigned int set_base; + unsigned int status; /* lines 0-7; the next register for 8 and up */ + unsigned int ngpio; +}; + +static const struct s2mpg1x_gpio_data s2mpg13_data = { + .set_base = S2MPG13_GPIO_0_SET, + .status = S2MPG13_GPIO_STATUS, + .ngpio = S2MPG13_GPIO_NUM, +}; + +static const struct s2mpg1x_gpio_data s2mpg14_data = { + .set_base = S2MPG14_GPIO_0_SET, + .status = S2MPG14_GPIO_STATUS, + .ngpio = S2MPG14_GPIO_NUM, +}; + +static const struct s2mpg1x_gpio_data s2mpg15_data = { + .set_base = S2MPG15_GPIO_0_SET, + .status = S2MPG15_GPIO_STATUS1, + .ngpio = S2MPG15_GPIO_NUM, +}; + struct s2mpg13_gpio { struct gpio_chip gc; struct regmap *regmap; + const struct s2mpg1x_gpio_data *data; }; -static unsigned int s2mpg13_gpio_set_reg(unsigned int offset) +static unsigned int s2mpg13_gpio_set_reg(struct s2mpg13_gpio *chip, unsigned int offset) { - return S2MPG13_GPIO_0_SET + offset; + return chip->data->set_base + offset; } static int s2mpg13_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) @@ -39,7 +72,7 @@ static int s2mpg13_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) unsigned int val; int ret; - ret = regmap_read(chip->regmap, s2mpg13_gpio_set_reg(offset), &val); + ret = regmap_read(chip->regmap, s2mpg13_gpio_set_reg(chip, offset), &val); if (ret) return ret; @@ -53,7 +86,7 @@ static int s2mpg13_gpio_get(struct gpio_chip *gc, unsigned int offset) unsigned int val; int ret; - ret = regmap_read(chip->regmap, s2mpg13_gpio_set_reg(offset), &val); + ret = regmap_read(chip->regmap, s2mpg13_gpio_set_reg(chip, offset), &val); if (ret) return ret; @@ -61,18 +94,18 @@ static int s2mpg13_gpio_get(struct gpio_chip *gc, unsigned int offset) if (val & S2MPG13_GPIO_SET_OUT_EN) return !!(val & S2MPG13_GPIO_SET_OUT); - ret = regmap_read(chip->regmap, S2MPG13_GPIO_STATUS, &val); + ret = regmap_read(chip->regmap, chip->data->status + offset / 8, &val); if (ret) return ret; - return !!(val & BIT(offset)); + return !!(val & BIT(offset % 8)); } static int s2mpg13_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) { struct s2mpg13_gpio *chip = gpiochip_get_data(gc); - return regmap_update_bits(chip->regmap, s2mpg13_gpio_set_reg(offset), + return regmap_update_bits(chip->regmap, s2mpg13_gpio_set_reg(chip, offset), S2MPG13_GPIO_SET_OUT, value ? S2MPG13_GPIO_SET_OUT : 0); } @@ -81,7 +114,7 @@ static int s2mpg13_gpio_direction_input(struct gpio_chip *gc, unsigned int offse { struct s2mpg13_gpio *chip = gpiochip_get_data(gc); - return regmap_update_bits(chip->regmap, s2mpg13_gpio_set_reg(offset), + return regmap_update_bits(chip->regmap, s2mpg13_gpio_set_reg(chip, offset), S2MPG13_GPIO_SET_OUT_EN, 0); } @@ -91,7 +124,7 @@ static int s2mpg13_gpio_direction_output(struct gpio_chip *gc, struct s2mpg13_gpio *chip = gpiochip_get_data(gc); /* Level and output enable in one read-modify-write, so no glitch. */ - return regmap_update_bits(chip->regmap, s2mpg13_gpio_set_reg(offset), + return regmap_update_bits(chip->regmap, s2mpg13_gpio_set_reg(chip, offset), S2MPG13_GPIO_SET_OUT | S2MPG13_GPIO_SET_OUT_EN, (value ? S2MPG13_GPIO_SET_OUT : 0) | S2MPG13_GPIO_SET_OUT_EN); @@ -109,6 +142,10 @@ static int s2mpg13_gpio_probe(struct platform_device *pdev) if (!chip) return -ENOMEM; + chip->data = device_get_match_data(dev); + if (!chip->data) + chip->data = (const struct s2mpg1x_gpio_data *) + platform_get_device_id(pdev)->driver_data; chip->regmap = dev_get_regmap(dev->parent, "gpio"); if (!chip->regmap) return dev_err_probe(dev, -ENODEV, "no GPIO regmap\n"); @@ -117,7 +154,7 @@ static int s2mpg13_gpio_probe(struct platform_device *pdev) chip->gc.parent = dev; chip->gc.owner = THIS_MODULE; chip->gc.base = -1; - chip->gc.ngpio = S2MPG13_GPIO_NUM; + chip->gc.ngpio = chip->data->ngpio; chip->gc.can_sleep = true; chip->gc.get_direction = s2mpg13_gpio_get_direction; chip->gc.direction_input = s2mpg13_gpio_direction_input; @@ -129,13 +166,17 @@ static int s2mpg13_gpio_probe(struct platform_device *pdev) } static const struct of_device_id s2mpg13_gpio_of_match[] = { - { .compatible = "samsung,s2mpg13-gpio" }, + { .compatible = "samsung,s2mpg13-gpio", .data = &s2mpg13_data }, + { .compatible = "samsung,s2mpg14-gpio", .data = &s2mpg14_data }, + { .compatible = "samsung,s2mpg15-gpio", .data = &s2mpg15_data }, { } }; MODULE_DEVICE_TABLE(of, s2mpg13_gpio_of_match); static const struct platform_device_id s2mpg13_gpio_id[] = { - { "s2mpg13-gpio" }, + { "s2mpg13-gpio", (kernel_ulong_t)&s2mpg13_data }, + { "s2mpg14-gpio", (kernel_ulong_t)&s2mpg14_data }, + { "s2mpg15-gpio", (kernel_ulong_t)&s2mpg15_data }, { } }; MODULE_DEVICE_TABLE(platform, s2mpg13_gpio_id); @@ -150,5 +191,5 @@ static struct platform_driver s2mpg13_gpio_driver = { }; module_platform_driver(s2mpg13_gpio_driver); -MODULE_DESCRIPTION("Samsung S2MPG13 PMIC GPIO driver"); +MODULE_DESCRIPTION("Samsung S2MPG13, S2MPG14 and S2MPG15 PMIC GPIO driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/i2c/imx386.c b/drivers/media/i2c/imx386.c index 28ef2934f4..c82b51addf 100644 --- a/drivers/media/i2c/imx386.c +++ b/drivers/media/i2c/imx386.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ #define IMX386_REG_FRAME_COUNT CCI_REG8(0x0005) #define IMX386_REG_CHIP_ID CCI_REG16(0x0016) #define IMX386_CHIP_ID 0x0386 +#define IMX712_CHIP_ID 0x0712 #define IMX386_REG_EXPOSURE CCI_REG16(0x0202) #define IMX386_REG_ANALOG_GAIN CCI_REG16(0x0204) /* per colour channel: Gr, R, B, Gb (CCS) */ @@ -152,6 +154,7 @@ struct imx386 { struct clk *mclk; struct gpio_desc *reset; + u16 chip_id; /* IMX386 (Pixel 7 Pro) or IMX712 (Pixel 9a), from the compatible */ struct regulator *supplies[IMX386_NUM_SUPPLIES]; u32 delays_us[3]; /* after the last supply, after MCLK, after reset */ u32 max_line_mbps; /* receiver's line throughput, MB/s; 0: none */ @@ -297,7 +300,7 @@ static int imx386_load_data(struct imx386 *s) h = (const void *)s->fw->data; if (le32_to_cpu(h->magic) != IMX386_FW_MAGIC || le16_to_cpu(h->version) != IMX386_FW_VERSION || - le16_to_cpu(h->chip_id) != IMX386_CHIP_ID) + le16_to_cpu(h->chip_id) != s->chip_id) goto bad; s->num_modes = le16_to_cpu(h->num_modes); @@ -897,10 +900,10 @@ static int imx386_identify(struct imx386 *s) if (ret) return dev_err_probe(s->dev, ret, "chip ID read failed\n"); - if (id != IMX386_CHIP_ID) + if (id != s->chip_id) return dev_err_probe(s->dev, -ENODEV, "chip ID 0x%04llx, expected 0x%04x\n", - id, IMX386_CHIP_ID); + id, s->chip_id); dev_info(s->dev, "model 0x%04llx\n", id); @@ -919,6 +922,7 @@ static int imx386_probe(struct i2c_client *client) return -ENOMEM; s->dev = dev; + s->chip_id = (uintptr_t)device_get_match_data(dev) ?: IMX386_CHIP_ID; v4l2_i2c_subdev_init(&s->sd, client, &imx386_subdev_ops); s->sd.internal_ops = &imx386_internal_ops; @@ -1042,7 +1046,9 @@ static DEFINE_RUNTIME_DEV_PM_OPS(imx386_pm_ops, imx386_power_off, imx386_power_on, NULL); static const struct of_device_id imx386_of_match[] = { - { .compatible = "sony,imx386" }, + { .compatible = "sony,imx386", .data = (void *)IMX386_CHIP_ID }, + /* Pixel 9a ultrawide: same CCS-style register map, own init and modes in its data file */ + { .compatible = "sony,imx712", .data = (void *)IMX712_CHIP_ID }, { } }; MODULE_DEVICE_TABLE(of, imx386_of_match); @@ -1058,5 +1064,5 @@ static struct i2c_driver imx386_driver = { }; module_i2c_driver(imx386_driver); -MODULE_DESCRIPTION("Sony IMX386 sensor driver"); +MODULE_DESCRIPTION("Sony IMX386 and IMX712 sensor driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/i2c/s5kgn1.c b/drivers/media/i2c/s5kgn1.c index e7e6bb5aac..3ef2c22768 100644 --- a/drivers/media/i2c/s5kgn1.c +++ b/drivers/media/i2c/s5kgn1.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Samsung S5KGN1, S5K3J1 and S5KGM5 image sensor driver + * Samsung S5KGN1, S5K3J1, S5KGM5 and S5KGN8 image sensor driver * * The S5KGN1 (ISOCELL GN1) is a 50 MP Samsung Bayer sensor with dual-pixel * phase detection and a MIPI CSI-2 C-PHY or D-PHY output; the S5K3J1 a @@ -246,6 +246,43 @@ static const struct s5kgn1_variant s5kgm5_variant = { .crop_x_div = 1, }; +/* + * GN8, the Pixel 9a main camera, in stock's power-up order + * (rear_main_camera_power_seq in Google's GPL zuma-tegu-camera.dtsi): + * pp3200_bb, pp1350, s2mpg15_ldo12 (I/O), slg51002 ldo5 (2.9 V), ldo4 + * (2.9 V), ldo1 (2.25 V, analog), the digital supply's enable, reset + * released, the clock; 1 ms after each, 10 ms after the clock. Its soft reset goes through the + * direct page (0xfcfc = 0x4000, 0x6010 = 1), 10 ms, and nothing enables a + * clock after it; standard registers in the direct page. Horizontal + * addresses count pixels, one per column (80..8142 for a 2x2-binned 4000). + * + * ldo5 and ldo4 are the actuator's and OIS's supplies (that sequence names + * them AVDD and AF_VM; the sensor's own are ldo1, VDDA, and vdig), but the + * module's sequence powers them before the sensor, so both stay required + * here. The driver has one supply delay (after delay_supply), so + * stock's 1 ms between ldo5, ldo4, ldo1 and vdig is left out unless the + * driver grows a per-supply step. + */ +static const char * const s5kgn8_supplies[] = { + "vbb", "vbuck", "vio", "vaux", "vaux2", "vana", "vdig", +}; + +static const struct s5kgn1_variant s5kgn8_variant = { + .name = "S5KGN8", + .model = "s5kgn8", + .chip_id = 0x08e8, + .supplies = s5kgn8_supplies, + .num_supplies = ARRAY_SIZE(s5kgn8_supplies), + .optional = BIT(0) | BIT(1), + .delay_supply = 2, /* 1 ms after vio */ + .delays_us = { 1000, 1000, 1000, 10000 }, + .reset_before_clock = true, /* reset, 1 ms, clock, 10 ms */ + .direct_page = true, + .clock_enable = false, + .soft_reset_us = 10000, + .crop_x_div = 1, +}; + static const u32 s5kgn1_mbus_codes[] = { MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10, @@ -1346,6 +1383,7 @@ static const struct of_device_id s5kgn1_of_match[] = { { .compatible = "samsung,s5k3j1", .data = &s5k3j1_variant }, { .compatible = "samsung,s5kgm5", .data = &s5kgm5_variant }, { .compatible = "samsung,s5kgn1", .data = &s5kgn1_variant }, + { .compatible = "samsung,s5kgn8", .data = &s5kgn8_variant }, { } }; MODULE_DEVICE_TABLE(of, s5kgn1_of_match); @@ -1361,5 +1399,5 @@ static struct i2c_driver s5kgn1_driver = { }; module_i2c_driver(s5kgn1_driver); -MODULE_DESCRIPTION("Samsung S5KGN1, S5K3J1 and S5KGM5 sensor driver"); +MODULE_DESCRIPTION("Samsung S5KGN1, S5K3J1, S5KGM5 and S5KGN8 sensor driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c index f342302c0c..8250319020 100644 --- a/drivers/media/platform/samsung/gs201-csis/gs201-csis.c +++ b/drivers/media/platform/samsung/gs201-csis/gs201-csis.c @@ -58,6 +58,7 @@ #include #include "gs201-csis-regs.h" +#include "zumapro-csis-core.h" #define CSIS_DRIVER_NAME "gs201-csis" @@ -76,6 +77,30 @@ #define CSIS_MIN_LANE_RATE 80000000ULL #define CSIS_MAX_LANE_RATE 6500000000ULL +/* + * zumapro (Tensor G4) has the same CSI-2 link (version 0x08010000 against + * gs201's 0x05040000, same layout) but a different DMA path: the ISP front + * end's CSIS core, whose image logical channel (LoCH) takes a link's data + * type on one virtual channel and writes it to memory through its Bayer + * WDMA (zumapro-csis-core.h). Without the core's registers in the device + * tree the link runs alone (as link_only), counting frames. + */ +struct gs201_csis_soc { + bool wdma; /* gs201's CSIS WDMA, routing and CSIS sysreg */ + unsigned int num_links; + u32 cmn_ctrl_extra; /* CMN_CTRL bits the SoC's camera software sets */ + unsigned int pixel_mode; /* the link channel's, unless overridden */ + unsigned int dma_bits; + /* + * DBG_OPTION_SUITE bit 23: gs201's camera software sets it, and the link + * then hands out unpacked 16-bit words, which gs201's WDMA expects. + * zumapro's clears it: its CSIS core unpacks the packed CSI-2 stream. + */ + bool dbg_bit23; + /* PHY_CMN_CTRL lane enables: gs201 sets them; zumapro never writes it */ + bool phy_cmn_ctrl; +}; + struct gs201_csis_format { u32 code; u32 fourcc; @@ -116,6 +141,9 @@ struct gs201_csis_stats { u32 dropped; u32 missed_fe; u32 link_irqs; + u32 core_irqs; /* zumapro: core interrupts this link handled */ + u32 core_last_agg; + u32 core_last_proc; u32 wdma_started_at; /* the link frame end the WDMA started at */ u32 wdma_restarts; /* wdma_recover restarts */ u32 wdma_lines; /* line ends since the channel's last frame start */ @@ -132,6 +160,16 @@ struct gs201_csis_stats { }; struct gs201_csis { + const struct gs201_csis_soc *soc; + void __iomem *core; /* zumapro: the CSIS core page, or NULL */ + unsigned int loch; /* zumapro: the image LoCH this link writes through */ + void *sq_buf; /* zumapro: the LoCH's status queue */ + dma_addr_t sq_dma; + struct clk *fe_clk; /* zumapro: the ISP front end's NOC clock */ + unsigned long fe_rate_old; + void *scratch; /* zumapro: frames with no buffer go here */ + dma_addr_t scratch_dma; + size_t scratch_size; struct device *dev; void __iomem *link; void __iomem *dma; @@ -304,9 +342,40 @@ MODULE_PARM_DESC(wdma_line_irq, "Count WDMA line ends per channel (bring-up; man * stock uses quad, 2), to try how a C-PHY link hands its lines to the * WDMA. */ -static unsigned int pixel_mode = CSIS_ISPCFG_PIXEL_MODE_QUAD; -module_param(pixel_mode, uint, 0644); -MODULE_PARM_DESC(pixel_mode, "Link channel pixel mode, 0-3 (bring-up; default 2, quad)"); +/* zumapro bring-up: the CSIS core's memory format and the link's parallel mode */ +static int zp_mem_fmt = -1; +module_param(zp_mem_fmt, int, 0644); +MODULE_PARM_DESC(zp_mem_fmt, "zumapro Bayer WDMA memory format (bring-up; default RAW10 packed 4, 2 RAW16)"); + +/* + * zumapro: ABL leaves the front end's NOC clock at a sixth of SHARED3 + * (111 MHz); the main camera's C-PHY link (18.8 Gbps) then overruns the + * front end (link ERR_DESKEW_OVER, short frames). While a link streams, the + * INT DVFS domain (the clock's rail) goes up first, then the clock. + */ +static unsigned int fe_khz = 331776; +module_param(fe_khz, uint, 0644); +MODULE_PARM_DESC(fe_khz, "zumapro ISP-FE NOC clock in kHz while streaming (0: leave it)"); + +static unsigned int fe_int_khz = 533000; +module_param(fe_int_khz, uint, 0644); +MODULE_PARM_DESC(fe_int_khz, "zumapro INT DVFS rate in kHz while streaming, before the ISP-FE clock (0: leave it)"); + +static int cmn_ctrl_extra = -1; +module_param(cmn_ctrl_extra, int, 0644); +MODULE_PARM_DESC(cmn_ctrl_extra, "Extra link CMN_CTRL bits (bring-up; default the SoC's)"); + +static int zp_dt = -1; +module_param(zp_dt, int, 0644); +MODULE_PARM_DESC(zp_dt, "zumapro LoCH data type code (bring-up; default from the CSI-2 data type)"); + +static int parallel_mode = -1; +module_param(parallel_mode, int, 0644); +MODULE_PARM_DESC(parallel_mode, "Link channel parallel mode, ISP_CONFIG bits 15:14 (bring-up; default left 0)"); + +static int pixel_mode = -1; +module_param(pixel_mode, int, 0644); +MODULE_PARM_DESC(pixel_mode, "Link channel pixel mode, 0-3 (bring-up; default the SoC's: gs201 2, quad; zumapro 3)"); /* * Bring-up: start the WDMA channel only at the link's Nth frame end after @@ -568,8 +637,11 @@ static void gs201_csis_link_start(struct gs201_csis *csis, CSIS_ISPCFG_VC); } - link_write(csis, CSIS_DBG_OPTION_SUITE, - link_read(csis, CSIS_DBG_OPTION_SUITE) | CSIS_DBG_OPTION_BIT23); + if (csis->soc->dbg_bit23) + link_write(csis, CSIS_DBG_OPTION_SUITE, + link_read(csis, CSIS_DBG_OPTION_SUITE) | CSIS_DBG_OPTION_BIT23); + else + link_write(csis, CSIS_DBG_OPTION_SUITE, 0); link_write(csis, CSIS_INT_SRC0, ~0u); link_write(csis, CSIS_INT_SRC1, ~0u); @@ -585,7 +657,9 @@ static void gs201_csis_link_start(struct gs201_csis *csis, link_write(csis, CSIS_ISP_CONFIG_CH(ch), cfg_keep[ch] | FIELD_PREP(CSIS_ISPCFG_DATAFORMAT, dt) | - FIELD_PREP(CSIS_ISPCFG_PIXEL_MODE, pixel_mode & 3) | + FIELD_PREP(CSIS_ISPCFG_PIXEL_MODE, + (pixel_mode >= 0 ? pixel_mode : csis->soc->pixel_mode) & 3) | + (parallel_mode >= 0 ? FIELD_PREP(GENMASK(15, 14), parallel_mode & 3) : 0) | FIELD_PREP(CSIS_ISPCFG_VC, vc)); link_write(csis, CSIS_ISP_RESOL_CH(ch), !used ? 0 : FIELD_PREP(CSIS_ISP_RESOL_V, mf->height) | @@ -601,7 +675,8 @@ static void gs201_csis_link_start(struct gs201_csis *csis, csis->lrte_epd ? CSIS_LRTE_EPD_EN | CSIS_LRTE_SPACERS_RESET : CSIS_LRTE_DEFAULT); link_write(csis, CSIS_UPD_SDW, CSIS_UPD_SDW_ALL); - link_write(csis, CSIS_PHY_CMN_CTRL, CSIS_PHY_CMN_CTRL_ENABLE); + if (csis->soc->phy_cmn_ctrl) + link_write(csis, CSIS_PHY_CMN_CTRL, CSIS_PHY_CMN_CTRL_ENABLE); link_write(csis, CSIS_INT_MSK0, int0_mask & CSIS_INT0_ERRORS); link_write(csis, CSIS_INT_MSK1, CSIS_INT1_FRAME_START | @@ -611,16 +686,175 @@ static void gs201_csis_link_start(struct gs201_csis *csis, FIELD_PREP(CSIS_CMN_CTRL_LANE_NUMBER, lanes - 1) | FIELD_PREP(CSIS_CMN_CTRL_INTERLEAVE, 3) | FIELD_PREP(CSIS_CMN_CTRL_F13, 2) | + (cmn_ctrl_extra >= 0 ? cmn_ctrl_extra : csis->soc->cmn_ctrl_extra) | (csis->cphy ? CSIS_CMN_CTRL_CPHY : 0)); } +/* ----------------------------------------------------------------------------- + * Hardware: the zumapro CSIS core's image LoCH + */ + +static inline u32 core_read(struct gs201_csis *csis, u32 reg) +{ + return readl(csis->core + reg); +} + +static inline void core_write(struct gs201_csis *csis, u32 reg, u32 val) +{ + writel(val, csis->core + reg); +} + +static inline u32 img_read(struct gs201_csis *csis, u32 reg) +{ + return core_read(csis, ZP_IMG(csis->loch, reg)); +} + +static inline void img_write(struct gs201_csis *csis, u32 reg, u32 val) +{ + core_write(csis, ZP_IMG(csis->loch, reg), val); +} + +static u32 zp_core_dt(u8 data_type) +{ + switch (data_type) { + case MIPI_CSI2_DT_RAW8: + return ZP_DT_RAW8; + case MIPI_CSI2_DT_RAW12: + return ZP_DT_RAW12; + case MIPI_CSI2_DT_RAW14: + return ZP_DT_RAW14; + default: + return ZP_DT_RAW10; + } +} + +static void zp_core_set_addr(struct gs201_csis *csis, dma_addr_t addr) +{ + /* one batch slot; the configuration takes effect at the next frame */ + img_write(csis, ZP_IMG_BATCH_ADDR_LSB(0), + lower_32_bits(addr) & ZP_IMG_ADDR_LSB_MASK); + img_write(csis, ZP_IMG_BATCH_ADDR_MSB(0), + upper_32_bits(addr) & ZP_IMG_ADDR_MSB_MASK); + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 1); +} + +/* The LoCH takes the link's channel 0 (VC 0) data type, as the HAL routes it. */ +static void zp_core_route(struct gs201_csis *csis) +{ + u32 val; + + /* a LoCH a previous stream left running or in error starts clean */ + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 0); + img_write(csis, ZP_IMG_WDMA_CONTEXT_ENABLE, 0); + /* + * A stream that stopped cleanly leaves the LoCH bound to its link + * (EN_STATUS active), and a disabled LoCH ignores the abort, so the + * next stream on another link got no interrupt at all. Abort it + * enabled, with its DMA off. + */ + if (img_read(csis, ZP_IMG_LOCH_EN_STATUS) & ZP_IMG_LOCH_EN_STATUS_ACTIVE) + core_write(csis, ZP_LOCH_EN_SET, BIT(csis->loch)); + core_write(csis, ZP_LOCH_ABORT, BIT(csis->loch)); + if (readl_poll_timeout(csis->core + ZP_IMG(csis->loch, ZP_IMG_ABORT_DONE_ISR), + val, val & ZP_IMG_ABORT_DONE, 100, 20000)) + dev_dbg(csis->dev, "LoCH %u: no abort-done at start\n", csis->loch); + core_write(csis, ZP_LOCH_EN_CLR, BIT(csis->loch)); + img_write(csis, ZP_IMG_ABORT_DONE_ISR, val); + img_write(csis, ZP_IMG_PROC_ISR, img_read(csis, ZP_IMG_PROC_ISR)); + img_write(csis, ZP_IMG_ERR_ISR, img_read(csis, ZP_IMG_ERR_ISR)); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); + + core_write(csis, ZP_FRAME_ID_CLR, BIT(csis->loch)); + img_write(csis, ZP_IMG_AUTO_REC_SYNC_INTV0, 0); + img_write(csis, ZP_IMG_AUTO_REC_SYNC_INTV1, 0); + img_write(csis, ZP_IMG_BATCH_INT_MSK_SOF, 1); + img_write(csis, ZP_IMG_BATCH_INT_MSK_EOF, 1); + img_write(csis, ZP_IMG_BATCH_INT_MSK_DMA_DONE, 1); + img_write(csis, ZP_IMG_BATCH_INT_MSK_FRAME_DONE, 1); + img_write(csis, ZP_IMG_CTL, + FIELD_PREP(ZP_IMG_CTL_LINK, csis->link_id) | + FIELD_PREP(ZP_IMG_CTL_LINK_CH, 0) | + FIELD_PREP(ZP_IMG_CTL_DT, zp_dt >= 0 ? zp_dt : + zp_core_dt(csis->fmt->data_type))); + img_write(csis, ZP_IMG_BATCH_CTL, 0); + img_write(csis, ZP_IMG_ISP_RESOL, + FIELD_PREP(ZP_IMG_ISP_RESOL_H, csis->pix.height) | + FIELD_PREP(ZP_IMG_ISP_RESOL_W, csis->pix.width)); + img_write(csis, ZP_IMG_PROC_IER, ZP_IMG_PROC_SOF | ZP_IMG_PROC_EOF | + ZP_IMG_PROC_SHADOW_UPDATE | ZP_IMG_PROC_DMA_DONE); +} + +static void zp_core_unroute(struct gs201_csis *csis) +{ + core_write(csis, ZP_LOCH_EN_CLR, BIT(csis->loch)); + img_write(csis, ZP_IMG_CTL, 0); +} + +static void zp_core_wdma_start(struct gs201_csis *csis) +{ + u32 fmt = zp_mem_fmt >= 0 ? zp_mem_fmt : + csis->fmt->bpp == 8 ? ZP_MEM_FMT_8BIT : ZP_MEM_FMT_RAW10_PACKED; + + img_write(csis, ZP_IMG_BAYER_MEM_FORMAT, fmt); + img_write(csis, ZP_IMG_BAYER_STRIDE, csis->pix.bytesperline); + img_write(csis, ZP_IMG_BAYER_CROP_EN, 0); + img_write(csis, ZP_IMG_BAYER_ENABLE, BIT(0)); + img_write(csis, ZP_IMG_SQ_CONFIG_ID_LSB, 0); + img_write(csis, ZP_IMG_SQ_CONFIG_ID_MSB, 0); + img_write(csis, ZP_IMG_SQ_BASE_ADDR_LSB, lower_32_bits(csis->sq_dma)); + img_write(csis, ZP_IMG_SQ_BASE_ADDR_MSB, upper_32_bits(csis->sq_dma)); + + img_write(csis, ZP_IMG_PROC_ISR, img_read(csis, ZP_IMG_PROC_ISR)); + img_write(csis, ZP_IMG_ERR_ISR, img_read(csis, ZP_IMG_ERR_ISR)); + img_write(csis, ZP_IMG_WDMA_CONFIG_MISS, 1); + img_write(csis, ZP_IMG_PROC_IMR, ZP_IMG_PROC_SOF | ZP_IMG_PROC_EOF | + ZP_IMG_PROC_DMA_DONE | ZP_IMG_PROC_FRAME_DONE); + img_write(csis, ZP_IMG_ERR_IMR, ZP_IMG_ERRORS); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); + core_write(csis, ZP_LOCH_INT_IMR, + core_read(csis, ZP_LOCH_INT_IMR) | BIT(csis->loch)); + + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 1); + img_write(csis, ZP_IMG_WDMA_CONTEXT_ENABLE, 1); + core_write(csis, ZP_LOCH_EN_SET, BIT(csis->loch)); + + dev_info(csis->dev, "LoCH %u on: link %u, CTL 0x%08x RESOL 0x%08x, %u bytes a line, format %u, slot 0 0x%x:%08x; LOCH_EN 0x%08x\n", + csis->loch, csis->link_id, img_read(csis, ZP_IMG_CTL), + img_read(csis, ZP_IMG_ISP_RESOL), csis->pix.bytesperline, fmt, + img_read(csis, ZP_IMG_BATCH_ADDR_MSB(0)), + img_read(csis, ZP_IMG_BATCH_ADDR_LSB(0)), + core_read(csis, ZP_LOCH_EN)); +} + +static void zp_core_wdma_stop(struct gs201_csis *csis) +{ + u32 val; + + img_write(csis, ZP_IMG_WDMA_CONFIG_ENABLE, 0); + img_write(csis, ZP_IMG_WDMA_CONTEXT_ENABLE, 0); + core_write(csis, ZP_LOCH_EN_CLR, BIT(csis->loch)); + core_write(csis, ZP_LOCH_ABORT, BIT(csis->loch)); + if (readl_poll_timeout(csis->core + ZP_IMG(csis->loch, ZP_IMG_ABORT_DONE_ISR), + val, val & ZP_IMG_ABORT_DONE, 100, 50000)) + dev_dbg(csis->dev, "LoCH %u: no abort-done\n", csis->loch); + img_write(csis, ZP_IMG_ABORT_DONE_ISR, val); + core_write(csis, ZP_LOCH_INT_IMR, + core_read(csis, ZP_LOCH_INT_IMR) & ~BIT(csis->loch)); + img_write(csis, ZP_IMG_PROC_IMR, 0); + img_write(csis, ZP_IMG_ERR_IMR, 0); + img_write(csis, ZP_IMG_PROC_ISR, img_read(csis, ZP_IMG_PROC_ISR)); + img_write(csis, ZP_IMG_ERR_ISR, img_read(csis, ZP_IMG_ERR_ISR)); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); +} + static void gs201_csis_link_stop(struct gs201_csis *csis) { link_write(csis, CSIS_INT_MSK0, 0); link_write(csis, CSIS_INT_MSK1, 0); link_write(csis, CSIS_CMN_CTRL, link_read(csis, CSIS_CMN_CTRL) & ~CSIS_CMN_CTRL_CSI_EN); - link_write(csis, CSIS_PHY_CMN_CTRL, 0); + if (csis->soc->phy_cmn_ctrl) + link_write(csis, CSIS_PHY_CMN_CTRL, 0); } /* ----------------------------------------------------------------------------- @@ -865,7 +1099,9 @@ static void gs201_csis_next_buffer(struct gs201_csis *csis) struct gs201_csis_buffer, list); if (csis->next) { list_del(&csis->next->list); - if (csis->dma_on) + if (csis->dma_on && csis->core) + zp_core_set_addr(csis, csis->next->addr); + else if (csis->dma_on) gs201_csis_wdma_set_addr(csis, csis->next->addr); } } @@ -998,6 +1234,107 @@ static irqreturn_t gs201_csis_wdma_irq(int irq, void *data) return IRQ_HANDLED; } +/* + * zumapro: the CSIS core's interrupt is shared by every LoCH. Start of frame + * latched the slot address: that buffer becomes active and the next is + * programmed; DMA done completes it. + */ +static irqreturn_t zp_core_irq(int irq, void *data) +{ + struct gs201_csis *csis = data; + struct gs201_csis_buffer *done = NULL, *failed = NULL; + u32 agg, proc, err; + + if (READ_ONCE(gs201_csis_owner) != csis) + return IRQ_NONE; + + agg = core_read(csis, ZP_LOCH_INT_ISR); + csis->stats.core_last_agg = agg; + if (!(agg & BIT(csis->loch))) + return IRQ_NONE; + proc = img_read(csis, ZP_IMG_PROC_ISR); + csis->stats.core_irqs++; + csis->stats.core_last_proc = proc; + err = img_read(csis, ZP_IMG_ERR_ISR) & ZP_IMG_ERRORS; + img_write(csis, ZP_IMG_PROC_ISR, proc); + if (err) + img_write(csis, ZP_IMG_ERR_ISR, err); + core_write(csis, ZP_LOCH_INT_ISR, BIT(csis->loch)); + + spin_lock(&csis->slock); + csis->stats.wdma_fs[0] += !!(proc & ZP_IMG_PROC_SOF); + csis->stats.wdma_fe[0] += !!(proc & ZP_IMG_PROC_EOF); + csis->stats.wdma_le[0] += !!(proc & ZP_IMG_PROC_FRAME_DONE); + if (err) { + unsigned long be = err; + unsigned int bit; + + csis->stats.wdma_errors++; + csis->stats.last_wdma_err = err; + for_each_set_bit(bit, &be, 32) + csis->stats.wdma_bits[bit]++; + if (!csis->wdma_err_logged) { + csis->wdma_err_logged = true; + dev_warn(csis->dev, "LoCH %u error 0x%04x (proc 0x%02x): CTL 0x%08x RESOL 0x%08x STRIDE %u, slot 0 0x%x:%08x, activity 0x%08x, WDMA debug 0x%08x, AXI response errors 0x%08x, config miss 0x%x\n", + csis->loch, err, proc, img_read(csis, ZP_IMG_CTL), + img_read(csis, ZP_IMG_ISP_RESOL), + img_read(csis, ZP_IMG_BAYER_STRIDE), + img_read(csis, ZP_IMG_BATCH_ADDR_MSB(0)), + img_read(csis, ZP_IMG_BATCH_ADDR_LSB(0)), + img_read(csis, ZP_IMG_ACTIVITY_STATUS), + img_read(csis, ZP_IMG_WDMA_DBG_INFO), + img_read(csis, ZP_IMG_AXI_RESP_ERR_STATUS), + img_read(csis, ZP_IMG_WDMA_CONFIG_MISS)); + } + } + + /* + * Each frame start latches the slot programmed before it, so the slot + * is reprogrammed only here, never mid-frame (a configuration written + * during a frame is a "late config" and stops the LoCH): the next + * queued buffer, or the scratch buffer. + */ + if (proc & ZP_IMG_PROC_SOF) { + if (csis->active) { + failed = csis->active; + csis->active = NULL; + csis->stats.missed_fe++; + } + csis->active = csis->next; + csis->next = NULL; + if (!list_empty(&csis->pending)) { + gs201_csis_next_buffer(csis); + } else { + zp_core_set_addr(csis, csis->scratch_dma); + csis->stats.dropped++; + } + } + + if ((proc & ZP_IMG_PROC_DMA_DONE) && csis->active) { + done = csis->active; + csis->active = NULL; + csis->stats.wdma_done++; + } + spin_unlock(&csis->slock); + + if (failed) { + failed->vb.vb2_buf.timestamp = ktime_get_ns(); + failed->vb.sequence = csis->sequence++; + failed->vb.field = V4L2_FIELD_NONE; + vb2_buffer_done(&failed->vb.vb2_buf, keep_failed ? + VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR); + } + if (done) { + done->vb.vb2_buf.timestamp = ktime_get_ns(); + done->vb.sequence = csis->sequence++; + done->vb.field = V4L2_FIELD_NONE; + vb2_buffer_done(&done->vb.vb2_buf, err && !keep_failed ? + VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); + } + + return IRQ_HANDLED; +} + /* ----------------------------------------------------------------------------- * Streaming */ @@ -1087,7 +1424,7 @@ static int gs201_csis_enable_streams(struct v4l2_subdev *sd, if (lanes < 0) return lanes; - { + if (csis->sysreg) { unsigned int sel = 0, rst = 0; regmap_read(csis->sysreg, CSIS_SYSREG_LINK_SEL, &sel); @@ -1113,7 +1450,7 @@ static int gs201_csis_enable_streams(struct v4l2_subdev *sd, goto err_dvfs; gs201_csis_link_start(csis, mf, f, lanes); - if (csis->dma_on && wdma_after_link) + if (csis->dma_on && wdma_after_link && !csis->core) gs201_csis_wdma_start(csis); ret = v4l2_subdev_enable_streams(csis->source.sd, @@ -1122,7 +1459,7 @@ static int gs201_csis_enable_streams(struct v4l2_subdev *sd, goto err_link; /* Bring-up: what each part looks like right after the start. */ - { + if (csis->sysreg) { unsigned int sel = 0, rst = 0; regmap_read(csis->sysreg, CSIS_SYSREG_LINK_SEL, &sel); @@ -1165,7 +1502,7 @@ static int gs201_csis_disable_streams(struct v4l2_subdev *sd, v4l2_subdev_disable_streams(csis->source.sd, csis->source.pad->index, BIT(0)); - if (link_sel_bits) + if (link_sel_bits && csis->sysreg) regmap_write(csis->sysreg, CSIS_SYSREG_LINK_SEL, csis->link_sel_saved); gs201_csis_link_stop(csis); phy_power_off(csis->phy); @@ -1546,7 +1883,9 @@ static void gs201_csis_buf_queue(struct vb2_buffer *vb) spin_lock_irqsave(&csis->slock, flags); list_add_tail(&buf->list, &csis->pending); - if (!csis->next && vb2_start_streaming_called(vb->vb2_queue)) + /* zumapro programs the slot at frame start only */ + if (!csis->next && vb2_start_streaming_called(vb->vb2_queue) && + !csis->core) gs201_csis_next_buffer(csis); spin_unlock_irqrestore(&csis->slock, flags); } @@ -1588,14 +1927,32 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) csis->sequence = 0; memset(&csis->stats, 0, sizeof(csis->stats)); csis->wdma_err_logged = false; - csis->dma_on = !link_only; + csis->dma_on = !link_only && (csis->soc->wdma || csis->core); spin_lock_irqsave(&csis->slock, flags); if (!csis->next) gs201_csis_next_buffer(csis); spin_unlock_irqrestore(&csis->slock, flags); - if (csis->dma_on) { + if (csis->dma_on && csis->core) { + gs201_csis_dvfs_vote(csis, csis->int_clk, "INT", fe_int_khz, + &csis->int_rate_old); + gs201_csis_dvfs_vote(csis, csis->fe_clk, "ISP-FE", fe_khz, + &csis->fe_rate_old); + csis->scratch_size = csis->pix.sizeimage; + csis->scratch = dma_alloc_coherent(csis->dev, csis->scratch_size, + &csis->scratch_dma, GFP_KERNEL); + if (!csis->scratch) { + gs201_csis_dvfs_restore(csis->fe_clk, &csis->fe_rate_old); + gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); + ret = -ENOMEM; + goto err_pipeline; + } + if (!csis->next) + zp_core_set_addr(csis, csis->scratch_dma); + zp_core_route(csis); + zp_core_wdma_start(csis); + } else if (csis->dma_on) { ret = gs201_csis_route(csis); if (ret) goto err_pipeline; @@ -1612,7 +1969,15 @@ static int gs201_csis_start_streaming(struct vb2_queue *vq, unsigned int count) return 0; err_wdma: - if (csis->dma_on) { + if (csis->dma_on && csis->core) { + zp_core_wdma_stop(csis); + zp_core_unroute(csis); + dma_free_coherent(csis->dev, csis->scratch_size, csis->scratch, + csis->scratch_dma); + csis->scratch = NULL; + gs201_csis_dvfs_restore(csis->fe_clk, &csis->fe_rate_old); + gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); + } else if (csis->dma_on) { gs201_csis_wdma_stop(csis); gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); gs201_csis_unroute(csis); @@ -1656,7 +2021,21 @@ static void gs201_csis_stop_streaming(struct vb2_queue *vq) csis->wdma_arm = 0; spin_unlock_irqrestore(&csis->slock, flags); v4l2_subdev_disable_streams(&csis->sd, CSIS_PAD_SOURCE, BIT(0)); - if (csis->dma_on) { + if (csis->dma_on && csis->core) { + dev_info(csis->dev, "LoCH %u at stop: frame %u, done frame %u, activity 0x%08x, WDMA debug 0x%08x, AXI response errors 0x%08x\n", + csis->loch, img_read(csis, ZP_IMG_FRAME_ID), + img_read(csis, ZP_IMG_DONE_FRAME_ID), + img_read(csis, ZP_IMG_ACTIVITY_STATUS), + img_read(csis, ZP_IMG_WDMA_DBG_INFO), + img_read(csis, ZP_IMG_AXI_RESP_ERR_STATUS)); + zp_core_wdma_stop(csis); + zp_core_unroute(csis); + dma_free_coherent(csis->dev, csis->scratch_size, csis->scratch, + csis->scratch_dma); + csis->scratch = NULL; + gs201_csis_dvfs_restore(csis->fe_clk, &csis->fe_rate_old); + gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); + } else if (csis->dma_on) { gs201_csis_wdma_stop(csis); gs201_csis_dvfs_restore(csis->int_clk, &csis->int_rate_old); gs201_csis_unroute(csis); @@ -1671,7 +2050,7 @@ static void gs201_csis_stop_streaming(struct vb2_queue *vq) csis->stats.wdma_done, csis->stats.wdma_errors, csis->stats.last_wdma_err, csis->stats.dropped, csis->stats.missed_fe); - if (csis->dma_on) + if (csis->dma_on && csis->dma) dev_info(csis->dev, "WDMA debug at stop: frames 0x%08x, lines/data 0x%08x\n", readl(csis->dma + CSIS_DMA_CMN_DBG_VCNT(csis->ctx_id)), readl(csis->dma + CSIS_DMA_CMN_DBG_HDCNT(csis->ctx_id))); @@ -1715,6 +2094,8 @@ static int gs201_csis_stats_show(struct seq_file *s, void *unused) seq_printf(s, "wdma_done %u\nwdma_errors %u\nlast_wdma_err 0x%08x\ndropped %u\nmissed_fe %u\nlink_irqs %u\n", st.wdma_done, st.wdma_errors, st.last_wdma_err, st.dropped, st.missed_fe, st.link_irqs); + seq_printf(s, "core_irqs %u\ncore_last_agg 0x%08x\ncore_last_proc 0x%08x\n", + st.core_irqs, st.core_last_agg, st.core_last_proc); gs201_csis_print_bits(s, NULL, "int0", st.int0_bits, 32); gs201_csis_print_bits(s, NULL, "int1", st.int1_bits, 8); gs201_csis_print_bits(s, NULL, "wdma", st.wdma_bits, 32); @@ -1758,10 +2139,10 @@ static int gs201_csis_regs_show(struct seq_file *s, void *unused) for (i = 0; i < ARRAY_SIZE(link_regs); i++) seq_printf(s, "link 0x%03x = 0x%08x\n", link_regs[i], link_read(csis, link_regs[i])); - for (i = 0; i < ARRAY_SIZE(wdma_regs); i++) + for (i = 0; csis->wdma && i < ARRAY_SIZE(wdma_regs); i++) seq_printf(s, "wdma 0x%03x = 0x%08x\n", wdma_regs[i], wdma_read(csis, wdma_regs[i])); - for (i = 0; i < ARRAY_SIZE(ch_regs); i++) { + for (i = 0; csis->wdma && i < ARRAY_SIZE(ch_regs); i++) { u32 r = CSIS_WDMA_CH(csis->wdma_ch, ch_regs[i]); seq_printf(s, "wdma 0x%03x = 0x%08x\n", r, wdma_read(csis, r)); @@ -1806,7 +2187,7 @@ static int gs201_csis_scan_show(struct seq_file *s, void *unused) seq_printf(s, "link%u+0x%03x = 0x%08x\n", csis->link_id, off, link_read(csis, off)); - for (i = 0; i < ARRAY_SIZE(sysreg_regs); i++) { + for (i = 0; csis->sysreg && i < ARRAY_SIZE(sysreg_regs); i++) { if (regmap_read(csis->sysreg, sysreg_regs[i], &val)) continue; seq_printf(s, "sysreg+0x%03x = 0x%08x\n", sysreg_regs[i], val); @@ -2060,10 +2441,31 @@ static int gs201_csis_probe(struct platform_device *pdev) INIT_LIST_HEAD(&csis->pending); platform_set_drvdata(pdev, csis); + csis->soc = of_device_get_match_data(dev); + if (!csis->soc) + return -ENODEV; + csis->link = devm_platform_ioremap_resource_byname(pdev, "link"); if (IS_ERR(csis->link)) return PTR_ERR(csis->link); + if (!csis->soc->wdma) { + /* zumapro: the CSIS core page, optional (without it, link only) */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (res) { + csis->core = devm_ioremap(dev, res->start, resource_size(res)); + if (!csis->core) + return -ENOMEM; + } + device_property_read_u32(dev, "google,image-loch", &csis->loch); + csis->fe_clk = devm_clk_get_optional(dev, "fe"); + if (IS_ERR(csis->fe_clk)) + return dev_err_probe(dev, PTR_ERR(csis->fe_clk), "ISP-FE clock\n"); + if (csis->loch > 6) + return dev_err_probe(dev, -EINVAL, "bad google,image-loch\n"); + goto no_wdma; + } + /* The DMA common page is shared by all instances: map, don't claim. */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); if (!res) @@ -2088,6 +2490,7 @@ static int gs201_csis_probe(struct platform_device *pdev) return -ENOMEM; } +no_wdma: csis->cam_clk = devm_clk_get_optional(dev, "cam"); if (IS_ERR(csis->cam_clk)) return dev_err_probe(dev, PTR_ERR(csis->cam_clk), "CAM clock\n"); @@ -2096,10 +2499,10 @@ static int gs201_csis_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(csis->int_clk), "INT clock\n"); ret = device_property_read_u32(dev, "google,csis-link", &csis->link_id); - if (ret || csis->link_id > 7) + if (ret || csis->link_id >= csis->soc->num_links) return dev_err_probe(dev, -EINVAL, "bad google,csis-link\n"); ret = device_property_read_u32(dev, "google,wdma-context", &csis->ctx_id); - if (ret || csis->ctx_id > 3) + if (csis->soc->wdma && (ret || csis->ctx_id > 3)) return dev_err_probe(dev, -EINVAL, "bad google,wdma-context\n"); csis->ebuf = csis->ctx_id; @@ -2110,10 +2513,13 @@ static int gs201_csis_probe(struct platform_device *pdev) csis->lrte_epd = device_property_read_bool(dev, "google,lrte-packet-delimiters"); - csis->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node, - "google,csis-sysreg"); - if (IS_ERR(csis->sysreg)) - return dev_err_probe(dev, PTR_ERR(csis->sysreg), "no CSIS sysreg\n"); + if (csis->soc->wdma) { + csis->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node, + "google,csis-sysreg"); + if (IS_ERR(csis->sysreg)) + return dev_err_probe(dev, PTR_ERR(csis->sysreg), + "no CSIS sysreg\n"); + } csis->phy = devm_phy_get(dev, NULL); if (IS_ERR(csis->phy)) @@ -2123,10 +2529,29 @@ static int gs201_csis_probe(struct platform_device *pdev) if (ret && ret != -ENODEV) return dev_err_probe(dev, ret, "memory region\n"); - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(CSIS_WDMA_ADDR_BITS)); + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(csis->soc->dma_bits)); if (ret) goto err_mem; + if (csis->core) { + /* the LoCH writes a status record per frame: give it a page */ + csis->sq_buf = dmam_alloc_coherent(dev, PAGE_SIZE, &csis->sq_dma, + GFP_KERNEL); + if (!csis->sq_buf) { + ret = -ENOMEM; + goto err_mem; + } + irq = platform_get_irq_byname(pdev, "core"); + if (irq < 0) { + ret = irq; + goto err_mem; + } + ret = devm_request_irq(dev, irq, zp_core_irq, IRQF_SHARED, + dev_name(dev), csis); + if (ret) + goto err_mem; + } + irq = platform_get_irq_byname(pdev, "link"); if (irq < 0) { ret = irq; @@ -2137,15 +2562,17 @@ static int gs201_csis_probe(struct platform_device *pdev) if (ret) goto err_mem; - irq = platform_get_irq_byname(pdev, "wdma"); - if (irq < 0) { - ret = irq; - goto err_mem; + if (csis->soc->wdma) { + irq = platform_get_irq_byname(pdev, "wdma"); + if (irq < 0) { + ret = irq; + goto err_mem; + } + ret = devm_request_irq(dev, irq, gs201_csis_wdma_irq, IRQF_SHARED, + dev_name(dev), csis); + if (ret) + goto err_mem; } - ret = devm_request_irq(dev, irq, gs201_csis_wdma_irq, IRQF_SHARED, - dev_name(dev), csis); - if (ret) - goto err_mem; csis->fmt = &gs201_csis_formats[0]; csis->pix.width = CSIS_DEF_WIDTH; @@ -2194,8 +2621,27 @@ static void gs201_csis_remove(struct platform_device *pdev) of_reserved_mem_device_release(&pdev->dev); } +static const struct gs201_csis_soc gs201_csis_gs201 = { + .wdma = true, + .num_links = 8, + .pixel_mode = CSIS_ISPCFG_PIXEL_MODE_QUAD, + .dma_bits = CSIS_WDMA_ADDR_BITS, + .dbg_bit23 = true, + .phy_cmn_ctrl = true, +}; + +/* Links 0-11 have contexts and interrupts; stock wires sensors to 0-8. */ +static const struct gs201_csis_soc gs201_csis_zumapro = { + .num_links = 12, + /* the zumapro HAL's CMN_CTRL bits 15:12 are 5, gs201's 4 */ + .cmn_ctrl_extra = ZP_LINK_CMN_CTRL_F12, + .pixel_mode = ZP_LINK_PIXEL_MODE, + .dma_bits = ZP_ADDR_BITS, +}; + static const struct of_device_id gs201_csis_of_match[] = { - { .compatible = "google,gs201-csis" }, + { .compatible = "google,gs201-csis", .data = &gs201_csis_gs201 }, + { .compatible = "google,zumapro-csis", .data = &gs201_csis_zumapro }, { } }; MODULE_DEVICE_TABLE(of, gs201_csis_of_match); diff --git a/drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h b/drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h new file mode 100644 index 0000000000..6dec060d2b --- /dev/null +++ b/drivers/media/platform/samsung/gs201-csis/zumapro-csis-core.h @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * zumapro (Tensor G4) CSIS core: the image logical channel (LoCH) path that + * writes a CSI-2 link's frames to memory. Offsets are from the ISP front + * end's CSIS core page (isp-fe 0x1c300000 + 0x20000). Names follow the + * Pixel 9a camera HAL's register table; the fields come from the HAL's own + * value packers. The interrupt registers (image processing, error, abort + * done, the aggregate, and LoCH 1 at 0x20824) are also in Google's GPL + * zuma-isp-event-info.dtsi, and their bits in + * dt-bindings/lwis/platform/zuma/isp_fe.h. + */ +#ifndef ZUMAPRO_CSIS_CORE_H +#define ZUMAPRO_CSIS_CORE_H + +#include + +/* common page */ +#define ZP_LOCH_INT_ISR 0x008c /* bit n = LoCH n */ +#define ZP_LOCH_INT_IMR 0x0094 /* 1 passes the LoCH's interrupt */ +#define ZP_LOCH_EN 0x009c +#define ZP_LOCH_EN_SET 0x00a0 +#define ZP_LOCH_EN_CLR 0x00a4 +#define ZP_LOCH_ABORT 0x00ac +#define ZP_FRAME_ID_CLR 0x00b0 + +/* image LoCH n (0-6) */ +#define ZP_IMG(n, r) (0x0400 + 0x400 * (n) + (r)) +#define ZP_IMG_ABORT_DONE_ISR 0x004 +#define ZP_IMG_ABORT_DONE BIT(0) +#define ZP_IMG_WDMA_CONTEXT_ENABLE 0x018 +#define ZP_IMG_WDMA_CONFIG_ENABLE 0x01c +#define ZP_IMG_WDMA_CONFIG_MISS 0x020 +#define ZP_IMG_PROC_ISR 0x024 +#define ZP_IMG_PROC_IER 0x02c +#define ZP_IMG_PROC_IMR 0x030 +#define ZP_IMG_PROC_SOF BIT(0) +#define ZP_IMG_PROC_EOF BIT(1) +#define ZP_IMG_PROC_SHADOW_UPDATE BIT(3) +#define ZP_IMG_PROC_DMA_DONE BIT(4) +#define ZP_IMG_PROC_FRAME_DONE BIT(5) +#define ZP_IMG_ERR_ISR 0x038 +#define ZP_IMG_ERR_IMR 0x044 +#define ZP_IMG_ERRORS GENMASK(13, 0) +#define ZP_IMG_BATCH_INT_MSK_SOF 0x060 +#define ZP_IMG_BATCH_INT_MSK_EOF 0x064 +#define ZP_IMG_BATCH_INT_MSK_DMA_DONE 0x06c +#define ZP_IMG_BATCH_INT_MSK_FRAME_DONE 0x070 +#define ZP_IMG_ISP_RESOL 0x074 +#define ZP_IMG_ISP_RESOL_W GENMASK(15, 0) +#define ZP_IMG_ISP_RESOL_H GENMASK(31, 16) +#define ZP_IMG_AUTO_REC_SYNC_INTV0 0x078 +#define ZP_IMG_AUTO_REC_SYNC_INTV1 0x07c +#define ZP_IMG_BATCH_CTL 0x088 +#define ZP_IMG_CTL 0x08c +#define ZP_IMG_CTL_DT GENMASK(11, 8) +#define ZP_IMG_CTL_LINK_CH GENMASK(15, 12) +#define ZP_IMG_CTL_LINK GENMASK(27, 24) +#define ZP_IMG_FRAME_ID 0x09c +#define ZP_IMG_LOCH_EN_STATUS 0x0a8 /* the link in the low bits */ +#define ZP_IMG_LOCH_EN_STATUS_ACTIVE BIT(8) +#define ZP_IMG_SQ_CONFIG_ID_LSB 0x108 +#define ZP_IMG_SQ_CONFIG_ID_MSB 0x10c +#define ZP_IMG_SQ_BASE_ADDR_LSB 0x110 +#define ZP_IMG_SQ_BASE_ADDR_MSB 0x114 +#define ZP_IMG_BAYER_ENABLE 0x140 +#define ZP_IMG_BAYER_CROP_EN 0x144 +#define ZP_IMG_BAYER_MEM_FORMAT 0x150 +#define ZP_IMG_BAYER_STRIDE 0x154 +#define ZP_IMG_BATCH_ADDR_LSB(i) (0x1c0 + 8 * (i)) +#define ZP_IMG_BATCH_ADDR_MSB(i) (0x1c4 + 8 * (i)) +#define ZP_IMG_ADDR_LSB_MASK GENMASK(31, 5) +#define ZP_IMG_ADDR_MSB_MASK GENMASK(3, 0) +#define ZP_IMG_WDMA_DBG_INFO 0x2d0 +#define ZP_IMG_AXI_RESP_ERR_STATUS 0x2d4 +#define ZP_IMG_ACTIVITY_STATUS 0x2e4 +#define ZP_IMG_DONE_FRAME_ID 0x2f0 + +/* ZP_IMG_CTL_DT, from the CSI-2 data type */ +#define ZP_DT_RAW8 0 +#define ZP_DT_RAW10 2 +#define ZP_DT_RAW12 4 +#define ZP_DT_RAW14 6 + +/* ZP_IMG_BAYER_MEM_FORMAT */ +#define ZP_MEM_FMT_8BIT 0 +#define ZP_MEM_FMT_RAW16 2 +#define ZP_MEM_FMT_RAW10_PACKED 4 /* as on the CSI-2 bus: 4 pixels in 5 bytes */ +#define ZP_MEM_FMT_RAW12_PACKED 5 + +#define ZP_ADDR_BITS 36 + +/* the link's CMN_CTRL bits 15:12, as the zumapro HAL writes them */ +#define ZP_LINK_CMN_CTRL_F12 BIT(12) +#define ZP_LINK_PIXEL_MODE 3 + +#endif diff --git a/drivers/mfd/sec-acpm.c b/drivers/mfd/sec-acpm.c index c644530c44..262c9257d0 100644 --- a/drivers/mfd/sec-acpm.c +++ b/drivers/mfd/sec-acpm.c @@ -677,6 +677,35 @@ static const struct regmap_config s2mpg14_regmap_config_rtc = { .cache_type = REGCACHE_NONE, }; +/* GPIO block: masks, status and the SET registers; INT1-2 (clear on read) stay out. */ +static const struct regmap_range s2mpg14_gpio_rd_registers[] = { + regmap_reg_range(S2MPG14_GPIO_INT1M, S2MPG14_GPIO_5_SET), +}; + +static const struct regmap_range s2mpg14_gpio_wr_registers[] = { + regmap_reg_range(S2MPG14_GPIO_0_SET, S2MPG14_GPIO_5_SET), +}; + +static const struct regmap_access_table s2mpg14_gpio_rd_table = { + .yes_ranges = s2mpg14_gpio_rd_registers, + .n_yes_ranges = ARRAY_SIZE(s2mpg14_gpio_rd_registers), +}; + +static const struct regmap_access_table s2mpg14_gpio_wr_table = { + .yes_ranges = s2mpg14_gpio_wr_registers, + .n_yes_ranges = ARRAY_SIZE(s2mpg14_gpio_wr_registers), +}; + +static const struct regmap_config s2mpg14_regmap_config_gpio = { + .name = "gpio", + .reg_bits = ACPM_ADDR_BITS, + .val_bits = 8, + .max_register = S2MPG14_GPIO_5_SET, + .wr_table = &s2mpg14_gpio_wr_table, + .rd_table = &s2mpg14_gpio_rd_table, + .cache_type = REGCACHE_NONE, +}; + /* The sub-PMIC's revision and the LDO controls its consumers use. */ static const struct regmap_range s2mpg15_common_registers[] = { regmap_reg_range(S2MPG15_COMMON_CHIPID, S2MPG15_COMMON_CHIPID), @@ -719,6 +748,35 @@ static const struct regmap_access_table s2mpg15_pmic_table = { .n_yes_ranges = ARRAY_SIZE(s2mpg15_pmic_registers), }; +/* GPIO block: masks, status and the SET registers; INT1-3 (clear on read) stay out. */ +static const struct regmap_range s2mpg15_gpio_rd_registers[] = { + regmap_reg_range(S2MPG15_GPIO_INT1M, S2MPG15_GPIO_9_SET), +}; + +static const struct regmap_range s2mpg15_gpio_wr_registers[] = { + regmap_reg_range(S2MPG15_GPIO_0_SET, S2MPG15_GPIO_9_SET), +}; + +static const struct regmap_access_table s2mpg15_gpio_rd_table = { + .yes_ranges = s2mpg15_gpio_rd_registers, + .n_yes_ranges = ARRAY_SIZE(s2mpg15_gpio_rd_registers), +}; + +static const struct regmap_access_table s2mpg15_gpio_wr_table = { + .yes_ranges = s2mpg15_gpio_wr_registers, + .n_yes_ranges = ARRAY_SIZE(s2mpg15_gpio_wr_registers), +}; + +static const struct regmap_config s2mpg15_regmap_config_gpio = { + .name = "gpio", + .reg_bits = ACPM_ADDR_BITS, + .val_bits = 8, + .max_register = S2MPG15_GPIO_9_SET, + .wr_table = &s2mpg15_gpio_wr_table, + .rd_table = &s2mpg15_gpio_rd_table, + .cache_type = REGCACHE_NONE, +}; + static const struct regmap_config s2mpg15_regmap_config_pmic = { .name = "pmic", .reg_bits = ACPM_ADDR_BITS, @@ -970,6 +1028,7 @@ static const struct sec_pmic_acpm_platform_data s2mpg14_data = { .regmap_cfg_common = &s2mpg14_regmap_config_common, .regmap_cfg_pmic = &s2mpg14_regmap_config_pmic, .regmap_cfg_rtc = &s2mpg14_regmap_config_rtc, + .regmap_cfg_gpio = &s2mpg14_regmap_config_gpio, .irq_optional = true, }; @@ -979,6 +1038,7 @@ static const struct sec_pmic_acpm_platform_data s2mpg15_data = { .speedy_channel = 1, .regmap_cfg_common = &s2mpg15_regmap_config_common, .regmap_cfg_pmic = &s2mpg15_regmap_config_pmic, + .regmap_cfg_gpio = &s2mpg15_regmap_config_gpio, .no_irq = true, }; diff --git a/drivers/mfd/sec-common.c b/drivers/mfd/sec-common.c index 6a40169c4f..934775eba4 100644 --- a/drivers/mfd/sec-common.c +++ b/drivers/mfd/sec-common.c @@ -79,10 +79,11 @@ static const struct resource s2mpg14_rtc_resources[] = { DEFINE_RES_IRQ_NAMED(S2MPG14_IRQ_RTCA0, "alarm"), }; -/* The qualified LDOs and the RTC with its alarm; no GPIO or protection writes. */ +/* The qualified LDOs, the RTC with its alarm and the GPIOs; no protection writes. */ static const struct mfd_cell s2mpg14_devs[] = { MFD_CELL_NAME("s2mpg14-regulator"), MFD_CELL_RES("s2mpg14-rtc", s2mpg14_rtc_resources), + MFD_CELL_OF("s2mpg14-gpio", NULL, NULL, 0, 0, "samsung,s2mpg14-gpio"), }; /* @@ -92,11 +93,13 @@ static const struct mfd_cell s2mpg14_devs[] = { static const struct mfd_cell s2mpg14_devs_no_irq[] = { MFD_CELL_NAME("s2mpg14-regulator"), MFD_CELL_NAME("s2mpg14-rtc"), + MFD_CELL_OF("s2mpg14-gpio", NULL, NULL, 0, 0, "samsung,s2mpg14-gpio"), }; -/* The sub-PMIC's LDOs; no interrupt, meter, GPIO or RTC. */ +/* The sub-PMIC's LDOs and GPIOs; no interrupt, meter or RTC. */ static const struct mfd_cell s2mpg15_devs[] = { MFD_CELL_NAME("s2mpg15-regulator"), + MFD_CELL_OF("s2mpg15-gpio", NULL, NULL, 0, 0, "samsung,s2mpg15-gpio"), }; static const struct resource s2mps11_rtc_resources[] = { diff --git a/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c b/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c index 06b8bd15c5..ed3dacc7f9 100644 --- a/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c +++ b/drivers/phy/samsung/phy-gs201-mipi-dcphy-rx.c @@ -37,6 +37,15 @@ * data in the Omarchy Mobile project), named by the firmware-name property and * loaded when a link first powers on. Without the file no link powers on. * + * zumapro (Tensor G4) has nine slaves for twelve CSIS links, all with the + * clock lane first and up to four data lanes (three C-PHY trios) after it; + * three are a clock lane only, which links 4, 6 and 9 enable next to their + * own in four-lane D-PHY mode. The shared bias block, the PMU isolation word + * and the data file are as on gs201; the reset bits are one per slave (the + * layout from the camera HAL's register table and Google's GPL zuma DT). + * Only the four-lane links are described; the two-lane and single-trio + * splits (links 3, 5, 7, 8, 10, 11) and link 9 are not. + * * C-PHY (Google's GPL code leaves it unimplemented): a consumer selects it * with phy_set_mode_ext(PHY_MODE_MIPI_DPHY, PHY_TYPE_CPHY), and the lanes * of phy_configure() are then trios and hs_clk_rate the symbol rate. Each @@ -78,7 +87,7 @@ #include -#define DCPHY_NUM_LINKS 8 +#define DCPHY_MAX_LINKS 12 #define DCPHY_BIAS_BASE 0x1000 #define DCPHY_M_BIAS_CON0 0x00 @@ -176,6 +185,8 @@ struct gs201_dcphy_link { unsigned int max_lanes; bool data_first; /* odd two-lane links: data, data, clock */ bool can_pair; /* even two-lane link: takes the next one's lanes */ + u32 partner_clk; /* zumapro: a clock-only slave enabled with this one */ + u32 reset_bits; /* the slaves' reset bits */ bool cphy; /* selected by the consumer with phy_set_mode_ext() */ u32 settle; /* TIME_CON0 settle count as last powered on */ unsigned int lanes; /* data lanes, or trios in C-PHY mode */ @@ -197,21 +208,52 @@ struct gs201_dcphy { const char *fw_name; bool loaded; struct gs201_dcphy_settings settings[DCPHY_NUM_MODES]; - struct gs201_dcphy_link links[DCPHY_NUM_LINKS]; + unsigned int num_links; + struct gs201_dcphy_link links[DCPHY_MAX_LINKS]; struct dentry *debugfs; }; -/* Offset of each link's lane block and its layout (Google's GPL DT) */ -static const struct { +/* Offset of each link's lane block and its layout */ +struct gs201_dcphy_layout { u32 offset; - unsigned int max_lanes; + unsigned int max_lanes; /* 0: not described */ bool data_first; bool can_pair; -} gs201_dcphy_layout[DCPHY_NUM_LINKS] = { - { 0x1300, 4, false, false }, { 0x1b00, 4, false, false }, - { 0x2300, 2, false, true }, { 0x2600, 2, true, false }, - { 0x2b00, 2, false, true }, { 0x2e00, 2, true, false }, - { 0x3300, 2, false, true }, { 0x3600, 2, true, false }, + u32 partner_clk; + u32 reset_bits; +}; + +struct gs201_dcphy_soc { + const struct gs201_dcphy_layout *layout; + unsigned int num_links; +}; + +/* gs201 (Google's GPL DT) */ +static const struct gs201_dcphy_layout gs201_dcphy_layout[] = { + { 0x1300, 4, false, false, 0, BIT(0) }, { 0x1b00, 4, false, false, 0, BIT(1) }, + { 0x2300, 2, false, true, 0, BIT(2) }, { 0x2600, 2, true, false, 0, BIT(3) }, + { 0x2b00, 2, false, true, 0, BIT(4) }, { 0x2e00, 2, true, false, 0, BIT(5) }, + { 0x3300, 2, false, true, 0, BIT(6) }, { 0x3600, 2, true, false, 0, BIT(7) }, +}; + +static const struct gs201_dcphy_soc gs201_dcphy_gs201 = { + .layout = gs201_dcphy_layout, + .num_links = ARRAY_SIZE(gs201_dcphy_layout), +}; + +/* zumapro: link n's clock lane, and the clock-only partner of links 4 and 6 */ +static const struct gs201_dcphy_layout zumapro_dcphy_layout[] = { + [0] = { 0x1200, 4, false, false, 0, BIT(0) }, + [1] = { 0x1700, 4, false, false, 0, BIT(1) }, + [2] = { 0x2200, 4, false, false, 0, BIT(2) }, + [4] = { 0x2700, 4, false, false, 0x2c00, BIT(3) | BIT(4) }, + [6] = { 0x3100, 4, false, false, 0x3600, BIT(5) | BIT(6) }, + [11] = { }, +}; + +static const struct gs201_dcphy_soc gs201_dcphy_zumapro = { + .layout = zumapro_dcphy_layout, + .num_links = ARRAY_SIZE(zumapro_dcphy_layout), }; #define DCPHY_PAIR_LANES 4 @@ -225,8 +267,9 @@ static unsigned int gs201_dcphy_nr_lanes(struct gs201_dcphy_link *link) /* Reset bits of the slaves the link uses */ static u32 gs201_dcphy_reset_mask(struct gs201_dcphy_link *link) { - return link->paired ? BIT(link->index) | BIT(link->index + 1) : - BIT(link->index); + return link->paired ? link->reset_bits | + link->dcphy->links[link->index + 1].reset_bits : + link->reset_bits; } static int gs201_dcphy_reset(struct gs201_dcphy_link *link, bool release) @@ -278,6 +321,8 @@ static void gs201_dcphy_lanes_off(struct gs201_dcphy_link *link) unsigned int i; writel(0, gs201_dcphy_clk_lane(link) + DCPHY_GNR_CON0); + if (link->partner_clk) + writel(0, link->dcphy->base + link->partner_clk + DCPHY_GNR_CON0); for (i = 0; i < gs201_dcphy_nr_lanes(link); i++) writel(0, gs201_dcphy_data_lane(link, i) + DCPHY_GNR_CON0); } @@ -511,9 +556,14 @@ static int gs201_dcphy_lanes_on(struct gs201_dcphy_link *link) gs201_dcphy_run_block(set, cols, DCPHY_BLOCK_BIAS, dcphy->base + DCPHY_BIAS_BASE); - if (!link->cphy) + if (!link->cphy) { gs201_dcphy_run_block(set, cols, DCPHY_BLOCK_CLOCK, gs201_dcphy_clk_lane(link)); + /* zumapro four-lane D-PHY: the partner's clock enable, as the link's */ + if (link->partner_clk && link->lanes > 2) + writel(readl(gs201_dcphy_clk_lane(link) + DCPHY_GNR_CON0), + dcphy->base + link->partner_clk + DCPHY_GNR_CON0); + } for (i = 0; i < link->lanes; i++) gs201_dcphy_run_block(set, cols, DCPHY_BLOCK_LANE, gs201_dcphy_data_lane(link, i)); @@ -728,7 +778,7 @@ static int gs201_dcphy_regs_show(struct seq_file *s, void *unused) seq_printf(s, " %08x", readl(dcphy->base + DCPHY_BIAS_BASE + off)); seq_putc(s, '\n'); - for (i = 0; i < DCPHY_NUM_LINKS; i++) { + for (i = 0; i < dcphy->num_links; i++) { struct gs201_dcphy_link *link = &dcphy->links[i]; if (!link->powered) @@ -752,7 +802,8 @@ static struct phy *gs201_dcphy_xlate(struct device *dev, { struct gs201_dcphy *dcphy = dev_get_drvdata(dev); - if (args->args[0] >= DCPHY_NUM_LINKS) + if (args->args[0] >= dcphy->num_links || + !dcphy->links[args->args[0]].phy) return ERR_PTR(-ENODEV); return dcphy->links[args->args[0]].phy; @@ -762,10 +813,15 @@ static int gs201_dcphy_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct phy_provider *provider; + const struct gs201_dcphy_soc *soc; struct gs201_dcphy *dcphy; unsigned int i; int ret; + soc = of_device_get_match_data(dev); + if (!soc || soc->num_links > DCPHY_MAX_LINKS) + return -ENODEV; + dcphy = devm_kzalloc(dev, sizeof(*dcphy), GFP_KERNEL); if (!dcphy) return -ENOMEM; @@ -802,15 +858,20 @@ static int gs201_dcphy_probe(struct platform_device *pdev) /* The settings file; without it, no link powers on (says so then). */ of_property_read_string(dev->of_node, "firmware-name", &dcphy->fw_name); - for (i = 0; i < DCPHY_NUM_LINKS; i++) { + dcphy->num_links = soc->num_links; + for (i = 0; i < dcphy->num_links; i++) { struct gs201_dcphy_link *link = &dcphy->links[i]; link->dcphy = dcphy; link->index = i; - link->offset = gs201_dcphy_layout[i].offset; - link->max_lanes = gs201_dcphy_layout[i].max_lanes; - link->data_first = gs201_dcphy_layout[i].data_first; - link->can_pair = gs201_dcphy_layout[i].can_pair; + link->offset = soc->layout[i].offset; + link->max_lanes = soc->layout[i].max_lanes; + link->data_first = soc->layout[i].data_first; + link->can_pair = soc->layout[i].can_pair; + link->partner_clk = soc->layout[i].partner_clk; + link->reset_bits = soc->layout[i].reset_bits; + if (!link->max_lanes) + continue; link->phy = devm_phy_create(dev, NULL, &gs201_dcphy_ops); if (IS_ERR(link->phy)) @@ -837,7 +898,8 @@ static void gs201_dcphy_remove(struct platform_device *pdev) } static const struct of_device_id gs201_dcphy_of_match[] = { - { .compatible = "google,gs201-mipi-dcphy-rx" }, + { .compatible = "google,gs201-mipi-dcphy-rx", .data = &gs201_dcphy_gs201 }, + { .compatible = "google,zumapro-mipi-dcphy-rx", .data = &gs201_dcphy_zumapro }, { } }; MODULE_DEVICE_TABLE(of, gs201_dcphy_of_match); diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index 9ee77754d0..de3664bb02 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -343,6 +343,7 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_CLUSTER1_NONCPU_INT_EN 0x1544 #define ZUMA_HSI0_STATUS 0x2a84 #define ZUMA_PAD_CTRL_NFC_CLK 0x3e84 +#define ZUMA_PHY_CTRL_CSIS 0x3ebc #define ZUMA_PHY_CTRL_UFS 0x3ec0 static const struct regmap_range zuma_pmu_registers[] = { @@ -358,6 +359,7 @@ static const struct regmap_range zuma_pmu_registers[] = { regmap_reg_range(ZUMA_HSI0_STATUS, ZUMA_HSI0_STATUS), /* PHY isolation */ regmap_reg_range(GS101_PHY_CTRL_USB20, GS101_PHY_CTRL_USB20), + regmap_reg_range(ZUMA_PHY_CTRL_CSIS, ZUMA_PHY_CTRL_CSIS), 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), diff --git a/include/linux/mfd/samsung/s2mpg14.h b/include/linux/mfd/samsung/s2mpg14.h index d2fcdebb3d..466ea50d40 100644 --- a/include/linux/mfd/samsung/s2mpg14.h +++ b/include/linux/mfd/samsung/s2mpg14.h @@ -42,4 +42,17 @@ */ #define S2MPG14_VGPIO2AP_INTC0_IPEND 0x290 +/* GPIO registers (access type 0x0c): INT1-2 clear on read, then masks, status, SET */ +enum s2mpg14_gpio_reg { + S2MPG14_GPIO_INT1, + S2MPG14_GPIO_INT2, + S2MPG14_GPIO_INT1M, + S2MPG14_GPIO_INT2M, + S2MPG14_GPIO_STATUS, + S2MPG14_GPIO_0_SET, + S2MPG14_GPIO_5_SET = S2MPG14_GPIO_0_SET + 5, +}; + +#define S2MPG14_GPIO_NUM 6 + #endif /* __LINUX_MFD_S2MPG14_H */ diff --git a/include/linux/mfd/samsung/s2mpg15.h b/include/linux/mfd/samsung/s2mpg15.h index de66ce7f91..7315cbb6bc 100644 --- a/include/linux/mfd/samsung/s2mpg15.h +++ b/include/linux/mfd/samsung/s2mpg15.h @@ -15,4 +15,20 @@ #define S2MPG15_PMIC_L12S_CTRL 0x3a #define S2MPG15_PMIC_L15S_CTRL 0x3d +/* GPIO registers (access type 0x0c): INT1-3 clear on read, then masks, status, SET */ +enum s2mpg15_gpio_reg { + S2MPG15_GPIO_INT1, + S2MPG15_GPIO_INT2, + S2MPG15_GPIO_INT3, + S2MPG15_GPIO_INT1M, + S2MPG15_GPIO_INT2M, + S2MPG15_GPIO_INT3M, + S2MPG15_GPIO_STATUS1, + S2MPG15_GPIO_STATUS2, + S2MPG15_GPIO_0_SET, + S2MPG15_GPIO_9_SET = S2MPG15_GPIO_0_SET + 9, +}; + +#define S2MPG15_GPIO_NUM 10 + #endif /* __LINUX_MFD_S2MPG15_H */