diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9db955820e..e6f3dc686d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,6 +80,8 @@ jobs: ./tests/build-matrix.sh ./tests/mac-installer-dispatch.sh ./tests/limine-mkinitcpio-hook.sh + ./tests/linux-omarchy-source.sh + python tests/linux-omarchy-a16.py ./tests/voxtype-bin-install.sh ./tests/1password-polkit-owners.sh ./tests/superwhisper-bin-install.sh diff --git a/pkgbuilds/linux-omarchy-aarch64/2500-glymur-asus-zenbook-a16-local-hardware-fixes.patch b/pkgbuilds/linux-omarchy-aarch64/2500-glymur-asus-zenbook-a16-local-hardware-fixes.patch new file mode 100644 index 0000000000..94371bf6dc --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/2500-glymur-asus-zenbook-a16-local-hardware-fixes.patch @@ -0,0 +1,10557 @@ +Subject: [PATCH] arm64: retain A16 hardware fixes after the Surface Laptop 8 series + +Rebase the residual A16 changes onto the shared Linux 7.3-4 stack after +#1706. Keep the shared USB votes, LPASS Compander1 addresses, v8 eDP +calibration, LINK_RATE_SET refinements and USB4/DisplayPort lane ownership. +Retain A16 board/firmware policy and error recovery, adapting QMP resource +tracking and Type-C rollback to the shared USB4 state machine. Preserve +masked V2 altmode notifications when snapshotting events. Camera stays +disabled; native package builds and physical A16 acceptance are pending. + +diff --git a/Documentation/devicetree/bindings/embedded-controller/asus,zenbook-a16-ux3607oa-ec.yaml b/Documentation/devicetree/bindings/embedded-controller/asus,zenbook-a16-ux3607oa-ec.yaml +new file mode 100644 +index 0000000000000000000000000000000000000000..c0bfad5d21c09036009e8a2c348e25ec76b1f994 +--- /dev/null ++++ b/Documentation/devicetree/bindings/embedded-controller/asus,zenbook-a16-ux3607oa-ec.yaml +@@ -0,0 +1,64 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/embedded-controller/asus,zenbook-a16-ux3607oa-ec.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: ASUS Zenbook A16 (UX3607OA)-class Embedded Controller ++ ++maintainers: ++ - Konrad Dybcio ++ ++description: ++ The Qualcomm Snapdragon X2 series-based ASUS Zenbook A16 (and similar ++ machines) come with a custom EC firmware, loosely based on the ++ Qualcomm reference ("Hamoa CRD EC") implementation, with a lot of ++ customization. ++ ++properties: ++ compatible: ++ enum: ++ - asus,zenbook-a14-ux3407na-ec ++ - asus,zenbook-a16-ux3607oa-ec ++ ++ reg: ++ const: 0x76 ++ ++ interrupts: ++ maxItems: 1 ++ ++ "#thermal-sensor-cells": ++ const: 1 ++ ++ wakeup-source: true ++ ++required: ++ - compatible ++ - reg ++ - interrupts ++ - '#thermal-sensor-cells' ++ ++additionalProperties: false ++ ++examples: ++ - | ++ #include ++ i2c { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ embedded-controller@76 { ++ compatible = "asus,zenbook-a16-ux3607oa-ec"; ++ reg = <0x76>; ++ ++ interrupts-extended = <&tlmm 66 IRQ_TYPE_EDGE_FALLING>; ++ ++ pinctrl-0 = <&ec_int_n_default>; ++ pinctrl-names = "default"; ++ ++ #thermal-sensor-cells = <1>; ++ ++ wakeup-source; ++ }; ++ }; ++... +diff --git a/Documentation/devicetree/bindings/media/qcom,glymur-camss.yaml b/Documentation/devicetree/bindings/media/qcom,glymur-camss.yaml +new file mode 100644 +index 0000000000000000000000000000000000000000..a0b77edc212319fad69113f3d55ca24f184d4b23 +--- /dev/null ++++ b/Documentation/devicetree/bindings/media/qcom,glymur-camss.yaml +@@ -0,0 +1,300 @@ ++# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/media/qcom,glymur-camss.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Qualcomm Glymur Camera Subsystem (CAMSS) ++ ++maintainers: ++ - Nihal Kumar Gupta ++ ++description: ++ The CAMSS IP is a CSI decoder and ISP present on Qualcomm platforms. ++ ++properties: ++ compatible: ++ const: qcom,glymur-camss ++ ++ reg: ++ maxItems: 13 ++ ++ reg-names: ++ items: ++ - const: csid_wrapper ++ - const: csid0 ++ - const: csid1 ++ - const: csid2 ++ - const: csid_lite0 ++ - const: csid_lite1 ++ - const: csitpg0 ++ - const: csitpg1 ++ - const: csitpg2 ++ - const: vfe0 ++ - const: vfe1 ++ - const: vfe_lite0 ++ - const: vfe_lite1 ++ ++ clocks: ++ maxItems: 20 ++ ++ clock-names: ++ items: ++ - const: camnoc_nrt_axi ++ - const: camnoc_rt_axi ++ - const: core_ahb ++ - const: cpas_ahb ++ - const: cpas_fast_ahb ++ - const: cpas_vfe0 ++ - const: cpas_vfe1 ++ - const: cpas_vfe_lite ++ - const: csid ++ - const: csid_csiphy_rx ++ - const: gcc_axi_hf ++ - const: gcc_axi_sf ++ - const: vfe0 ++ - const: vfe0_fast_ahb ++ - const: vfe1 ++ - const: vfe1_fast_ahb ++ - const: vfe_lite ++ - const: vfe_lite_ahb ++ - const: vfe_lite_cphy_rx ++ - const: vfe_lite_csid ++ ++ interrupts: ++ maxItems: 9 ++ ++ interrupt-names: ++ items: ++ - const: csid0 ++ - const: csid1 ++ - const: csid2 ++ - const: csid_lite0 ++ - const: csid_lite1 ++ - const: vfe0 ++ - const: vfe1 ++ - const: vfe_lite0 ++ - const: vfe_lite1 ++ ++ interconnects: ++ maxItems: 4 ++ ++ interconnect-names: ++ items: ++ - const: ahb ++ - const: hf_mnoc ++ - const: sf_mnoc ++ - const: sf_icp_mnoc ++ ++ iommus: ++ items: ++ - description: S1 HLOS IFE and IFE_LITE non-protected ++ ++ power-domains: ++ items: ++ - description: IFE0 GDSC - Image Front End, Global Distributed Switch Controller. ++ - description: IFE1 GDSC - Image Front End, Global Distributed Switch Controller. ++ - description: Titan Top GDSC - Titan ISP Block, Global Distributed Switch Controller. ++ ++ power-domain-names: ++ items: ++ - const: ife0 ++ - const: ife1 ++ - const: top ++ ++ ports: ++ $ref: /schemas/graph.yaml#/properties/ports ++ ++ description: ++ CSI input ports. ++ ++ patternProperties: ++ "^port@[0-3]$": ++ $ref: /schemas/graph.yaml#/$defs/port-base ++ unevaluatedProperties: false ++ ++ description: ++ Input port for receiving CSI data. ++ ++ properties: ++ endpoint: ++ $ref: video-interfaces.yaml# ++ unevaluatedProperties: false ++ ++ properties: ++ data-lanes: ++ minItems: 1 ++ maxItems: 4 ++ ++required: ++ - compatible ++ - reg ++ - reg-names ++ - clocks ++ - clock-names ++ - interrupts ++ - interrupt-names ++ - interconnects ++ - interconnect-names ++ - iommus ++ - power-domains ++ - power-domain-names ++ - ports ++ ++additionalProperties: false ++ ++examples: ++ - | ++ #include ++ #include ++ #include ++ #include ++ #include ++ #include ++ ++ soc { ++ #address-cells = <2>; ++ #size-cells = <2>; ++ ++ camss: isp@acb6000 { ++ compatible = "qcom,glymur-camss"; ++ ++ reg = <0x0 0x0acb6000 0x0 0x1000>, ++ <0x0 0x0acb7000 0x0 0x2000>, ++ <0x0 0x0acb9000 0x0 0x2000>, ++ <0x0 0x0acbb000 0x0 0x2000>, ++ <0x0 0x0acc6000 0x0 0x1000>, ++ <0x0 0x0acca000 0x0 0x1000>, ++ <0x0 0x0acf6000 0x0 0x1000>, ++ <0x0 0x0acf7000 0x0 0x1000>, ++ <0x0 0x0acf8000 0x0 0x1000>, ++ <0x0 0x0ac62000 0x0 0xf000>, ++ <0x0 0x0ac71000 0x0 0xf000>, ++ <0x0 0x0acc7000 0x0 0x2000>, ++ <0x0 0x0accb000 0x0 0x2000>; ++ reg-names = "csid_wrapper", ++ "csid0", ++ "csid1", ++ "csid2", ++ "csid_lite0", ++ "csid_lite1", ++ "csitpg0", ++ "csitpg1", ++ "csitpg2", ++ "vfe0", ++ "vfe1", ++ "vfe_lite0", ++ "vfe_lite1"; ++ ++ clocks = <&camcc CAM_CC_CAMNOC_AXI_NRT_CLK>, ++ <&camcc CAM_CC_CAMNOC_AXI_RT_CLK>, ++ <&camcc CAM_CC_CORE_AHB_CLK>, ++ <&camcc CAM_CC_CPAS_AHB_CLK>, ++ <&camcc CAM_CC_CPAS_FAST_AHB_CLK>, ++ <&camcc CAM_CC_CPAS_IFE_0_CLK>, ++ <&camcc CAM_CC_CPAS_IFE_1_CLK>, ++ <&camcc CAM_CC_CPAS_IFE_LITE_CLK>, ++ <&camcc CAM_CC_CSID_CLK>, ++ <&camcc CAM_CC_CSID_CSIPHY_RX_CLK>, ++ <&gcc GCC_CAMERA_HF_AXI_CLK>, ++ <&gcc GCC_CAMERA_SF_AXI_CLK>, ++ <&camcc CAM_CC_IFE_0_CLK>, ++ <&camcc CAM_CC_IFE_0_FAST_AHB_CLK>, ++ <&camcc CAM_CC_IFE_1_CLK>, ++ <&camcc CAM_CC_IFE_1_FAST_AHB_CLK>, ++ <&camcc CAM_CC_IFE_LITE_CLK>, ++ <&camcc CAM_CC_IFE_LITE_AHB_CLK>, ++ <&camcc CAM_CC_IFE_LITE_CPHY_RX_CLK>, ++ <&camcc CAM_CC_IFE_LITE_CSID_CLK>; ++ clock-names = "camnoc_nrt_axi", ++ "camnoc_rt_axi", ++ "core_ahb", ++ "cpas_ahb", ++ "cpas_fast_ahb", ++ "cpas_vfe0", ++ "cpas_vfe1", ++ "cpas_vfe_lite", ++ "csid", ++ "csid_csiphy_rx", ++ "gcc_axi_hf", ++ "gcc_axi_sf", ++ "vfe0", ++ "vfe0_fast_ahb", ++ "vfe1", ++ "vfe1_fast_ahb", ++ "vfe_lite", ++ "vfe_lite_ahb", ++ "vfe_lite_cphy_rx", ++ "vfe_lite_csid"; ++ ++ interrupts = , ++ , ++ , ++ , ++ , ++ , ++ , ++ , ++ ; ++ interrupt-names = "csid0", ++ "csid1", ++ "csid2", ++ "csid_lite0", ++ "csid_lite1", ++ "vfe0", ++ "vfe1", ++ "vfe_lite0", ++ "vfe_lite1"; ++ ++ interconnects = <&hsc_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY ++ &config_noc SLAVE_CAMERA_CFG QCOM_ICC_TAG_ACTIVE_ONLY>, ++ <&mmss_noc MASTER_CAMNOC_HF QCOM_ICC_TAG_ALWAYS ++ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, ++ <&mmss_noc MASTER_CAMNOC_SF QCOM_ICC_TAG_ALWAYS ++ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, ++ <&mmss_noc MASTER_CAMNOC_ICP QCOM_ICC_TAG_ALWAYS ++ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>; ++ interconnect-names = "ahb", ++ "hf_mnoc", ++ "sf_mnoc", ++ "sf_icp_mnoc"; ++ ++ iommus = <&apps_smmu 0x800 0x20>; ++ ++ power-domains = <&camcc CAM_CC_IFE_0_GDSC>, ++ <&camcc CAM_CC_IFE_1_GDSC>, ++ <&camcc CAM_CC_TITAN_TOP_GDSC>; ++ power-domain-names = "ife0", ++ "ife1", ++ "top"; ++ ++ ports { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ port@0 { ++ reg = <0>; ++ camss_csiphy0_ep: endpoint { ++ data-lanes = <1 2 3 4>; ++ remote-endpoint = <&csiphy0_out>; ++ }; ++ }; ++ ++ port@1 { ++ reg = <1>; ++ camss_csiphy1_ep: endpoint { ++ data-lanes = <1 2 3 4>; ++ remote-endpoint = <&csiphy1_out>; ++ }; ++ }; ++ ++ port@3 { ++ reg = <3>; ++ camss_csiphy4_ep: endpoint { ++ data-lanes = <1 2 3 4>; ++ remote-endpoint = <&csiphy4_out>; ++ }; ++ }; ++ }; ++ }; ++ }; +diff --git a/Documentation/devicetree/bindings/phy/qcom,x1e80100-csi2-phy.yaml b/Documentation/devicetree/bindings/phy/qcom,x1e80100-csi2-phy.yaml +new file mode 100644 +index 0000000000000000000000000000000000000000..1f1e2a4993b2aff9a1519640bc4e04ca98fa4baa +--- /dev/null ++++ b/Documentation/devicetree/bindings/phy/qcom,x1e80100-csi2-phy.yaml +@@ -0,0 +1,213 @@ ++# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/phy/qcom,x1e80100-csi2-phy.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Qualcomm X1E80100 SoC CSI2 PHY ++ ++maintainers: ++ - Bryan O'Donoghue ++ ++description: ++ Qualcomm MIPI CSI2 C-PHY/D-PHY combination PHY. Connects MIPI CSI2 sensors ++ to Qualcomm's Camera CSI Decoder. The PHY supports both C-PHY and D-PHY ++ modes. ++ ++properties: ++ compatible: ++ oneOf: ++ - const: qcom,x1e80100-csi2-phy ++ - items: ++ - const: qcom,glymur-csi2-phy ++ - const: qcom,x1e80100-csi2-phy ++ ++ reg: ++ maxItems: 1 ++ ++ clocks: ++ maxItems: 3 ++ ++ clock-names: ++ items: ++ - const: core ++ - const: timer ++ - const: ahb ++ ++ interrupts: ++ maxItems: 1 ++ ++ operating-points-v2: true ++ ++ opp-table: ++ type: object ++ ++ power-domains: ++ items: ++ - description: Titan Top GDSC - Titan ISP Block, Global Distributed Switch Controller. ++ - description: MMCX voltage rail ++ - description: MXC or MXA voltage rail ++ ++ power-domain-names: ++ items: ++ - const: top ++ - const: mmcx ++ - const: mx ++ ++ vdda-0p9-supply: ++ description: Phandle to a 0.9V regulator supply to a PHY. ++ ++ vdda-1p2-supply: ++ description: Phandle to 1.2V regulator supply to a PHY. ++ ++ ports: ++ $ref: /schemas/graph.yaml#/properties/ports ++ ++ properties: ++ port@0: ++ $ref: /schemas/graph.yaml#/$defs/port-base ++ description: ++ Sensor input. Always present. A single sensor is described by a ++ single endpoint with one to four data lanes, numbered 1-4. The ++ clock lane is position 0. ++ ++ DPHY split mode, where two independent sensors share the PHY, is ++ described by two endpoints. endpoint@0 uses data lanes 1 or 1-2, ++ clock lane position 0; endpoint@1 uses data lane 3, clock lane ++ position 4. ++ ++ unevaluatedProperties: false ++ ++ patternProperties: ++ "^endpoint(@[01])?$": ++ $ref: /schemas/media/video-interfaces.yaml# ++ unevaluatedProperties: false ++ properties: ++ bus-type: ++ enum: ++ - 1 # MEDIA_BUS_TYPE_CSI2_CPHY ++ - 4 # MEDIA_BUS_TYPE_CSI2_DPHY ++ default: 4 ++ ++ data-lanes: ++ minItems: 1 ++ maxItems: 4 ++ items: ++ minimum: 1 ++ maximum: 4 ++ description: ++ Data lane positions following this endpoint's clock ++ lane. Positions are a per-port logical numbering, not ++ package pad or ball positions. ++ ++ required: ++ - data-lanes ++ - remote-endpoint ++ ++ allOf: ++ - if: ++ required: ++ - endpoint@1 ++ then: ++ properties: ++ endpoint@0: ++ properties: ++ data-lanes: ++ maxItems: 2 ++ items: ++ maximum: 2 ++ endpoint@1: ++ properties: ++ data-lanes: ++ items: ++ - const: 3 ++ required: ++ - endpoint@0 ++ ++ port@1: ++ $ref: /schemas/graph.yaml#/properties/port ++ description: Output to the CAMSS CSID controller. ++ ++ required: ++ - port@0 ++ - port@1 ++ ++required: ++ - compatible ++ - reg ++ - clocks ++ - clock-names ++ - interrupts ++ - operating-points-v2 ++ - power-domains ++ - power-domain-names ++ - vdda-0p9-supply ++ - vdda-1p2-supply ++ - ports ++ ++additionalProperties: false ++ ++examples: ++ - | ++ #include ++ #include ++ #include ++ #include ++ #include ++ ++ phy@ace4000 { ++ compatible = "qcom,x1e80100-csi2-phy"; ++ reg = <0x0ace4000 0x2000>; ++ ++ clocks = <&camcc CAM_CC_CSIPHY0_CLK>, ++ <&camcc CAM_CC_CSI0PHYTIMER_CLK>, ++ <&camcc CAM_CC_CORE_AHB_CLK>; ++ clock-names = "core", ++ "timer", ++ "ahb"; ++ ++ interrupts = ; ++ ++ operating-points-v2 = <&csiphy_opp_table>; ++ ++ power-domains = <&camcc CAM_CC_TITAN_TOP_GDSC>, ++ <&rpmhpd RPMHPD_MMCX>, ++ <&rpmhpd RPMHPD_MX>; ++ power-domain-names = "top", ++ "mmcx", ++ "mx"; ++ ++ vdda-0p9-supply = <&vreg_l2c_0p9>; ++ vdda-1p2-supply = <&vreg_l1c_1p2>; ++ ++ ports { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ port@0 { ++ reg = <0>; ++ csiphy0_in: endpoint { ++ bus-type = ; ++ data-lanes = <1 2 3 4>; ++ remote-endpoint = <&sensor_out>; ++ }; ++ }; ++ ++ port@1 { ++ reg = <1>; ++ csiphy0_out: endpoint { ++ remote-endpoint = <&csid_in>; ++ }; ++ }; ++ }; ++ ++ csiphy_opp_table: opp-table { ++ compatible = "operating-points-v2"; ++ ++ opp-300000000 { ++ opp-hz = /bits/ 64 <300000000>; ++ required-opps = <&rpmhpd_opp_low_svs_d1>, ++ <&rpmhpd_opp_low_svs_d1>; ++ }; ++ }; ++ }; +diff --git a/Documentation/devicetree/bindings/soundwire/qcom,soundwire.yaml b/Documentation/devicetree/bindings/soundwire/qcom,soundwire.yaml +index 8e6973fa229c9e9c667e9f9ae054e5fc0689e02c..fbeb4a4db1e5ae635b143cf15510db645db0c476 100644 +--- a/Documentation/devicetree/bindings/soundwire/qcom,soundwire.yaml ++++ b/Documentation/devicetree/bindings/soundwire/qcom,soundwire.yaml +@@ -72,6 +72,13 @@ properties: + + wakeup-source: true + ++ qcom,keep-runtime-active: ++ type: boolean ++ description: ++ Local Zenbook A16 test-only workaround that prevents controller runtime ++ autosuspend after probe. Does not repair detached slaves or establish ++ the detach cause. Userspace power/control can restore the auto policy. ++ + qcom,din-ports: + $ref: /schemas/types.yaml#/definitions/uint32 + description: count of data in ports +diff --git a/MAINTAINERS b/MAINTAINERS +index 3055f0eaf792cd917fde0e605fd369e896d4573f..f97cfb4d8384701a97bd5e06f30f36d42ff4c0ec 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -22562,6 +22562,16 @@ S: Maintained + F: Documentation/devicetree/bindings/media/qcom,*-iris.yaml + F: drivers/media/platform/qcom/iris/ + ++QUALCOMM MIPI CSI2 PHY DRIVER ++M: Bryan O'Donoghue ++L: linux-phy@lists.infradead.org ++L: linux-media@vger.kernel.org ++L: linux-arm-msm@vger.kernel.org ++S: Maintained ++F: Documentation/devicetree/bindings/phy/qcom,*-csi2-phy.yaml ++F: drivers/phy/qualcomm/phy-qcom-mipi-csi2*.c ++F: drivers/phy/qualcomm/phy-qcom-mipi-csi2*.h ++ + QUALCOMM NAND CONTROLLER DRIVER + M: Manivannan Sadhasivam + L: linux-mtd@lists.infradead.org +diff --git a/arch/arm64/boot/dts/qcom/glymur-asus-zenbook-a16-ux3607oa.dts b/arch/arm64/boot/dts/qcom/glymur-asus-zenbook-a16-ux3607oa.dts +index 939e1a927a7930651cf87cc8fb339515f5479a48..603ea9a9af44ab2409583afb6b19cf8dacee86bd 100644 +--- a/arch/arm64/boot/dts/qcom/glymur-asus-zenbook-a16-ux3607oa.dts ++++ b/arch/arm64/boot/dts/qcom/glymur-asus-zenbook-a16-ux3607oa.dts +@@ -23,6 +23,11 @@ + /delete-node/ &pmh0110_h_e0; + /delete-node/ &pmh0110_h0_thermal; + ++/* The A16 only populates the J and K USB repeaters. */ ++&smb2370_l_e2 { ++ status = "disabled"; ++}; ++ + / { + compatible = "asus,zenbook-a16-ux3607oa", "qcom,glymur"; + model = "ASUS Zenbook A16 (UX3607OA)"; +@@ -266,6 +271,16 @@ vreg_wcn_3p3: regulator-wcn-3p3 { + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + ++ /* ++ * GLYMUR-A16: qcom_wcn pwrseq asserts this rail for the power ++ * sequence and then releases it, so nothing holds a vote and ++ * regulator_init_complete() switches it off at t+30s ++ * (VREG_WCN_3P3: disabling), taking ath12k down ~60s later. ++ * The 7.1 tree only avoided this by reserving tlmm 94 so the ++ * regulator never probed and the firmware ON state persisted. ++ */ ++ regulator-always-on; ++ + gpio = <&tlmm 94 GPIO_ACTIVE_HIGH>; + enable-active-high; + +@@ -275,6 +290,82 @@ vreg_wcn_3p3: regulator-wcn-3p3 { + regulator-boot-on; + }; + ++ /* ++ * GLYMUR-A16: Wi-Fi is brought up with the qcom,wcn7850-pmu power ++ * sequencer (our verified-working 7.1 mechanism), not the generic ++ * pcie-m2-e-connector + pwrseq path, which never binds on 7.2-rc3. ++ */ ++ vreg_wcn_0p95: regulator-wcn-0p95 { ++ compatible = "regulator-fixed"; ++ ++ regulator-name = "VREG_WCN_0P95"; ++ regulator-min-microvolt = <950000>; ++ regulator-max-microvolt = <950000>; ++ ++ regulator-always-on; ++ ++ vin-supply = <&vreg_wcn_3p3>; ++ }; ++ ++ wcn7850-pmu { ++ compatible = "qcom,wcn7850-pmu"; ++ ++ vdd-supply = <&vreg_wcn_0p95>; ++ vddio-supply = <&vreg_l15b_e0>; ++ vddaon-supply = <&vreg_l15b_e0>; ++ vdddig-supply = <&vreg_l15b_e0>; ++ vddrfa1p2-supply = <&vreg_l15b_e0>; ++ vddrfa1p8-supply = <&vreg_l15b_e0>; ++ ++ wlan-enable-gpios = <&tlmm 117 GPIO_ACTIVE_HIGH>; ++ bt-enable-gpios = <&tlmm 116 GPIO_ACTIVE_HIGH>; ++ ++ pinctrl-0 = <&wcn_wlan_bt_en>; ++ pinctrl-names = "default"; ++ ++ regulators { ++ vreg_pmu_rfa_cmn: ldo0 { ++ regulator-name = "vreg_pmu_rfa_cmn"; ++ }; ++ ++ vreg_pmu_aon_0p59: ldo1 { ++ regulator-name = "vreg_pmu_aon_0p59"; ++ }; ++ ++ vreg_pmu_wlcx_0p8: ldo2 { ++ regulator-name = "vreg_pmu_wlcx_0p8"; ++ }; ++ ++ vreg_pmu_wlmx_0p85: ldo3 { ++ regulator-name = "vreg_pmu_wlmx_0p85"; ++ }; ++ ++ vreg_pmu_btcmx_0p85: ldo4 { ++ regulator-name = "vreg_pmu_btcmx_0p85"; ++ }; ++ ++ vreg_pmu_rfa_0p8: ldo5 { ++ regulator-name = "vreg_pmu_rfa_0p8"; ++ }; ++ ++ vreg_pmu_rfa_1p2: ldo6 { ++ regulator-name = "vreg_pmu_rfa_1p2"; ++ }; ++ ++ vreg_pmu_rfa_1p8: ldo7 { ++ regulator-name = "vreg_pmu_rfa_1p8"; ++ }; ++ ++ vreg_pmu_pcie_0p9: ldo8 { ++ regulator-name = "vreg_pmu_pcie_0p9"; ++ }; ++ ++ vreg_pmu_pcie_1p8: ldo9 { ++ regulator-name = "vreg_pmu_pcie_1p8"; ++ }; ++ }; ++ }; ++ + reserved-memory { + linux,cma { + compatible = "shared-dma-pool"; +@@ -331,44 +422,6 @@ platform { + }; + }; + +- wlan-connector { +- compatible = "pcie-m2-e-connector"; +- vpcie3v3-supply = <&vreg_wcn_3p3>; +- vpcie1v8-supply = <&vreg_l15b_e0>; +- +- w-disable1-gpios = <&tlmm 117 GPIO_ACTIVE_LOW>; +- w-disable2-gpios = <&tlmm 116 GPIO_ACTIVE_LOW>; +- +- pinctrl-0 = <&wcn_wlan_bt_en>; +- pinctrl-names = "default"; +- +- ports { +- #address-cells = <1>; +- #size-cells = <0>; +- +- port@0 { +- reg = <0>; +- #address-cells = <1>; +- #size-cells = <0>; +- +- m2_e_pcie_ep: endpoint@0 { +- reg = <0>; +- remote-endpoint = <&pcie4_port0_ep>; +- }; +- }; +- +- port@3 { +- reg = <3>; +- #address-cells = <1>; +- #size-cells = <0>; +- +- m2_e_uart_ep: endpoint@0 { +- reg = <0>; +- remote-endpoint = <&uart14_ep>; +- }; +- }; +- }; +- }; + }; + + &apps_rsc { +@@ -576,6 +629,14 @@ vreg_l2f_e1: ldo2 { + regulator-name = "vreg_l2f_e1"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <880000>; ++ ++ /* ++ * GLYMUR-A16: pin the eDP PHY supplies. qcom_edp_phy_exit() ++ * drops them on display power-down and the SoC is reset ++ * externally (no Linux fault). Reproduced 2/2 on the 7.1 tree ++ * as test73; merged1 regressed without it. ++ */ ++ regulator-always-on; + regulator-initial-mode = ; + }; + +@@ -583,16 +644,34 @@ vreg_l4f_e1: ldo4 { + regulator-name = "vreg_l4f_e1"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; ++ ++ /* ++ * GLYMUR-A16: pin the eDP PHY supplies. qcom_edp_phy_exit() ++ * drops them on display power-down and the SoC is reset ++ * externally (no Linux fault). Reproduced 2/2 on the 7.1 tree ++ * as test73; merged1 regressed without it. ++ */ ++ regulator-always-on; + regulator-initial-mode = ; + }; + }; + }; + + &gpu { ++ /* ++ * GLYMUR-A16: requires gpucc_glymur to NOT be blacklisted on the cmdline - ++ * gxclkctl-kaanapali runtime-resumes gpucc at probe, and without it the ++ * adreno SMMU times out and the whole msm component bind fails. ++ */ + status = "okay"; + }; + + &gmu { ++ /* ++ * GLYMUR-A16: requires gpucc_glymur to NOT be blacklisted on the cmdline - ++ * gxclkctl-kaanapali runtime-resumes gpucc at probe, and without it the ++ * adreno SMMU times out and the whole msm component bind fails. ++ */ + status = "okay"; + }; + +@@ -670,8 +749,19 @@ &i2c9 { + + status = "okay"; + +- /* EC subdevice @ 0x5b */ +- /* EC @ 0x76 */ ++ embedded-controller@76 { ++ compatible = "asus,zenbook-a16-ux3607oa-ec"; ++ reg = <0x76>; ++ ++ interrupts-extended = <&tlmm 66 IRQ_TYPE_EDGE_FALLING>; ++ ++ pinctrl-0 = <&ec_int_n_default>; ++ pinctrl-names = "default"; ++ ++ #thermal-sensor-cells = <1>; ++ ++ wakeup-source; ++ }; + }; + + &i2c10 { +@@ -737,7 +827,7 @@ &lpass_vamacro { + pinctrl-0 = <&dmic01_default>; + pinctrl-names = "default"; + +- qcom,dmic-sample-rate = <4800000>; ++ qcom,dmic-sample-rate = <2400000>; + }; + + &mdss { +@@ -825,10 +915,21 @@ &pcie4_phy { + &pcie4_port0 { + reset-gpios = <&tlmm 146 GPIO_ACTIVE_LOW>; + wake-gpios = <&tlmm 148 GPIO_ACTIVE_LOW>; +-}; + +-&pcie4_port0_ep { +- remote-endpoint = <&m2_e_pcie_ep>; ++ /* Match the currently booted QCC2072 power-sequencing topology. */ ++ wifi@0 { ++ compatible = "pci17cb,1112"; ++ reg = <0x10000 0 0 0 0>; ++ vddaon-supply = <&vreg_pmu_aon_0p59>; ++ vddwlcx-supply = <&vreg_pmu_wlcx_0p8>; ++ vddwlmx-supply = <&vreg_pmu_wlmx_0p85>; ++ vddrfacmn-supply = <&vreg_pmu_rfa_cmn>; ++ vddrfa0p8-supply = <&vreg_pmu_rfa_0p8>; ++ vddrfa1p2-supply = <&vreg_pmu_rfa_1p2>; ++ vddrfa1p8-supply = <&vreg_pmu_rfa_1p8>; ++ vddpcie0p9-supply = <&vreg_pmu_pcie_0p9>; ++ vddpcie1p8-supply = <&vreg_pmu_pcie_1p8>; ++ }; + }; + + &pcie5 { +@@ -861,7 +962,32 @@ nvme_reg_en: nvme-reg-en-state { + }; + + &pmk8850_rtc { +- qcom,uefi-rtc-info; ++ /* ++ * GLYMUR-A16: qcom,uefi-rtc-info deliberately REMOVED. ++ * ++ * rtc-pm8xxx treats that property as "the epoch offset lives in a UEFI ++ * variable, go read it", and returns -EPROBE_DEFER forever if efivars are ++ * unavailable. They are permanently unavailable on this firmware. ++ * ++ * EFI runtime services themselves DO come up ("Remapping and enabling EFI ++ * services." at boot). What this INSYDE firmware does not support is the ++ * *variable* subset: GetVariable returns EFI_UNSUPPORTED (status ++ * 0x8000000000000003, visible as "integrity: Couldn't get size: ++ * 0x8000000000000003" and "MODSIGN: Couldn't get UEFI db list"). So ++ * efivar_is_available() is false, fsopen("efivarfs") fails EOPNOTSUPP, and ++ * upstream's property can only ever defer here, never bind. This is not a ++ * kernel config gap -- CONFIG_EFIVAR_FS=y and efivarfs is registered in ++ * /proc/filesystems. ++ * ++ * Independent of efi=noruntime: verified 2026-07-30 by booting a variant with ++ * this property restored and that flag dropped. ++ * ++ * Without it the driver skips the UEFI lookup and binds. Two caveats remain: ++ * the RTC is read-only (RTC_SET_TIME returns ENODEV), and its counter is ++ * free-running rather than a wall clock -- so the epoch offset is supplied ++ * from userspace by glymur-rtc-restore instead. qcom,no-alarm below is ++ * upstream's, and means there is still no wake alarm for hibernate. ++ */ + qcom,no-alarm; + }; + +@@ -880,8 +1006,7 @@ &remoteproc_cdsp { + }; + + &remoteproc_soccp { +- firmware-name = "qcom/glymur/ASUSTeK/UX3607OA/soccp.mbn", +- "qcom/glymur/ASUSTeK/UX3607OA/soccp_dtb.mbn"; ++ /* Firmware-attached SOCCP: preserve the current DT's default names. */ + }; + + &smb2370_j_e2_eusb2_repeater { +@@ -897,6 +1022,9 @@ &smb2370_k_e2_eusb2_repeater { + &swr0 { + status = "okay"; + ++ /* Prevention trial only: keep the speaker bus out of runtime suspend. */ ++ qcom,keep-runtime-active; ++ + /* WSA8845, left woofer */ + left_woofer: speaker@0,0 { + compatible = "sdw20217020400"; +@@ -925,6 +1053,9 @@ left_tweeter: speaker@0,1 { + &swr3 { + status = "okay"; + ++ /* Prevention trial only: keep the speaker bus out of runtime suspend. */ ++ qcom,keep-runtime-active; ++ + /* WSA8845, right woofer */ + right_woofer: speaker@0,0 { + compatible = "sdw20217020400"; +@@ -1132,11 +1263,26 @@ wake-n-pins { + &uart14 { + status = "okay"; + +- port { +- uart14_ep: endpoint { +- remote-endpoint = <&m2_e_uart_ep>; +- }; ++ /* ++ * GLYMUR-A16: WCN7850 Bluetooth. Konrad's tree enables this UART and wires it ++ * into the pcie-m2-e-connector graph but declares no serdev child, so nothing ++ * probes a BT controller (bluetooth.service inactive, zero hci devices, no ++ * Bluetooth in rfkill). Supplies come from the qcom,wcn7850-pmu node we add for ++ * Wi-Fi, so these labels already resolve. Needs hci_uart + btqca. ++ */ ++ bluetooth { ++ compatible = "qcom,wcn7850-bt"; ++ max-speed = <3200000>; ++ ++ vddaon-supply = <&vreg_pmu_aon_0p59>; ++ vddwlcx-supply = <&vreg_pmu_wlcx_0p8>; ++ vddwlmx-supply = <&vreg_pmu_wlmx_0p85>; ++ vddrfacmn-supply = <&vreg_pmu_rfa_cmn>; ++ vddrfa0p8-supply = <&vreg_pmu_rfa_0p8>; ++ vddrfa1p2-supply = <&vreg_pmu_rfa_1p2>; ++ vddrfa1p8-supply = <&vreg_pmu_rfa_1p8>; + }; ++ + }; + + &uart21 { +@@ -1144,6 +1290,11 @@ &uart21 { + }; + + &usb_0 { ++ /* GLYMUR-A16: UCSI/Type-C only enumerates with the role switch gone ++ * and the controller pinned to host (our test68 finding). */ ++ /delete-property/ usb-role-switch; ++ dr_mode = "host"; ++ + status = "okay"; + }; + +@@ -1173,6 +1324,11 @@ &usb_0_qmpphy_out { + }; + + &usb_1 { ++ /* GLYMUR-A16: UCSI/Type-C only enumerates with the role switch gone ++ * and the controller pinned to host (our test68 finding). */ ++ /delete-property/ usb-role-switch; ++ dr_mode = "host"; ++ + status = "okay"; + }; + +@@ -1206,6 +1362,37 @@ &usb_2_qmpphy { + vdda-pll-supply = <&vreg_l4f_e1>; + refgen-supply = <&vreg_l4f_e1>; + ++ /* ++ * GLYMUR-A16: drop com_aux. gcc_usb3_tert_phy_com_aux_clk never leaves ++ * halt on this instance - phy@88e1000 has no DWC3 behind it (there is no ++ * tertiary USB controller), so the vote a USB half would normally cast is ++ * never made. qmp_combo_com_init() then fails -EBUSY after a 200us ++ * timeout, which kills AUX, EDID and every mode on the HDMI output. ++ * ++ * Legal because qmp_combo_clk_init() fetches the fixed list ++ * {aux, cfg_ahb, ref, com_aux} with devm_clk_bulk_get_optional(): a clock ++ * absent from the DT comes back NULL and clk_bulk_enable() skips it. ++ * cfg_ahb already proves this - it is missing from all three combo PHY ++ * nodes and nothing complains. ++ * ++ * Result: 0 clk-branch WARNs, EDID 0 -> 512 bytes, modes 0 -> 32, and the ++ * compositor no longer wedges in msm_dp_aux_transfer on hotplug. ++ * ++ * WORKAROUND, not the correct fix. The DT describes the PHY's clocks ++ * accurately; the driver is what enables com_aux unconditionally for an ++ * instance with no USB half. The real fix likely belongs in ++ * phy-qcom-qmp-combo.c or GCC. Do NOT present this upstream as ++ * "the DTS was wrong". ++ * ++ * Back-ported to source 2026-08-02; previously only in the compiled DTB. ++ */ ++ clocks = <&gcc GCC_USB3_TERT_PHY_AUX_CLK>, ++ <&tcsr TCSR_USB4_2_CLKREF_EN>, ++ <&gcc GCC_USB3_TERT_PHY_PIPE_CLK>; ++ clock-names = "aux", ++ "ref", ++ "usb3_pipe"; ++ + /delete-property/ mode-switch; + /delete-property/ orientation-switch; + +@@ -1267,3 +1454,807 @@ &usb_mp_qmpphy1 { + + status = "okay"; + }; ++ ++/* Compatibility only; built-in CPUCP versus polling needs a separate trial. */ ++&{/firmware/scmi} { ++ arm,no-completion-irq; ++}; ++ ++/* Local compatibility: retain the validated CPU/LLC cooling-map coverage. */ ++&{/thermal-zones/cpu-0-0-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_0_0_alert: cpu-0-0-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_0_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-0-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_0_1_alert: cpu-0-0-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_0_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-1-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_1_0_alert: cpu-0-1-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_1_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-1-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_1_1_alert: cpu-0-1-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_1_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-2-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_2_0_alert: cpu-0-2-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_2_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-2-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_2_1_alert: cpu-0-2-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_2_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-3-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_3_0_alert: cpu-0-3-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_3_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-3-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_3_1_alert: cpu-0-3-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_3_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-4-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_4_0_alert: cpu-0-4-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_4_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-4-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_4_1_alert: cpu-0-4-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_4_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-5-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_5_0_alert: cpu-0-5-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_5_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-0-5-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_0_5_1_alert: cpu-0-5-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_0_5_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-0-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_0_0_alert: cpu-1-0-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_0_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-0-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_0_1_alert: cpu-1-0-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_0_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-1-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_1_0_alert: cpu-1-1-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_1_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-1-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_1_1_alert: cpu-1-1-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_1_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-2-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_2_0_alert: cpu-1-2-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_2_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-2-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_2_1_alert: cpu-1-2-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_2_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-3-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_3_0_alert: cpu-1-3-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_3_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-3-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_3_1_alert: cpu-1-3-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_3_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-4-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_4_0_alert: cpu-1-4-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_4_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-4-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_4_1_alert: cpu-1-4-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_4_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-5-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_5_0_alert: cpu-1-5-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_5_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-1-5-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_1_5_1_alert: cpu-1-5-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_1_5_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-0-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_0_0_alert: cpu-2-0-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_0_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-0-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_0_1_alert: cpu-2-0-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_0_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-1-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_1_0_alert: cpu-2-1-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_1_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-1-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_1_1_alert: cpu-2-1-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_1_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-2-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_2_0_alert: cpu-2-2-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_2_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-2-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_2_1_alert: cpu-2-2-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_2_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-3-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_3_0_alert: cpu-2-3-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_3_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-3-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_3_1_alert: cpu-2-3-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_3_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-4-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_4_0_alert: cpu-2-4-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_4_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-4-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_4_1_alert: cpu-2-4-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_4_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-5-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_5_0_alert: cpu-2-5-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_5_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpu-2-5-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpu_2_5_1_alert: cpu-2-5-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpu_2_5_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpuillc-2-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpuillc_2_1_alert: cpuillc-2-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpuillc_2_1_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpullc-0-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpullc_0_0_alert: cpullc-0-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpullc_0_0_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpullc-0-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpullc_0_1_alert: cpullc-0-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpullc_0_1_alert>; ++ cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpullc-1-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpullc_1_0_alert: cpullc-1-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpullc_1_0_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpullc-1-1-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpullc_1_1_alert: cpullc-1-1-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpullc_1_1_alert>; ++ cooling-device = <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; ++ ++&{/thermal-zones/cpullc-2-0-thermal} { ++ polling-delay-passive = <100>; ++ ++ trips { ++ cpullc_2_0_alert: cpullc-2-0-alert { ++ temperature = <95000>; ++ hysteresis = <1000>; ++ type = "passive"; ++ }; ++ }; ++ ++ cooling-maps { ++ map0 { ++ trip = <&cpullc_2_0_alert>; ++ cooling-device = <&cpu12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; ++ }; ++ }; ++}; +diff --git a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi +index e27c697e317027bb9fb6623afc0926b451a9feaf..a081636155ff24a24079f2befd4ddd04c6ae23a8 100644 +--- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi ++++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi +@@ -1257,3 +1257,8 @@ &usb_mp_qmpphy1 { + + status = "okay"; + }; ++ ++&remoteproc_soccp { ++ firmware-name = "qcom/glymur/soccp.mbn", ++ "qcom/glymur/soccp_dtb.mbn"; ++}; +diff --git a/arch/arm64/boot/dts/qcom/glymur.dtsi b/arch/arm64/boot/dts/qcom/glymur.dtsi +index cecb9b7b4f186da903fe2eb9e7a446468796e518..cfe6963afd875f5858ad2ef2100c877105b33860 100644 +--- a/arch/arm64/boot/dts/qcom/glymur.dtsi ++++ b/arch/arm64/boot/dts/qcom/glymur.dtsi +@@ -4641,6 +4641,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, + usb-role-switch; + wakeup-source; + ++ dma-coherent; ++ + status = "disabled"; + + ports { +@@ -4730,6 +4732,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, + usb-role-switch; + wakeup-source; + ++ dma-coherent; ++ + status = "disabled"; + + ports { +@@ -4819,6 +4823,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, + usb-role-switch; + wakeup-source; + ++ dma-coherent; ++ + status = "disabled"; + + ports { +@@ -4909,6 +4915,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, + usb-role-switch; + wakeup-source; + ++ dma-coherent; ++ + status = "disabled"; + }; + +@@ -4993,6 +5001,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, + dr_mode = "host"; + wakeup-source; + ++ dma-coherent; ++ + status = "disabled"; + }; + +diff --git a/arch/arm64/configs/zenbook-a16-hibernation.config b/arch/arm64/configs/zenbook-a16-hibernation.config +new file mode 100644 +index 0000000000000000000000000000000000000000..88e6dca3cd0908ae23f162de7a365aabcddaaca1 +--- /dev/null ++++ b/arch/arm64/configs/zenbook-a16-hibernation.config +@@ -0,0 +1,4 @@ ++# SPDX-License-Identifier: GPL-2.0-only ++# Help: Enable kernel hibernation for a separately configured persistent target ++CONFIG_HIBERNATION=y ++# CONFIG_HIBERNATION_SNAPSHOT_DEV is not set +diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c +index 22b08ab05b829bef2452cacad9c25eb8a63cda19..ab79a499ec4760fd11c3a2ac4e8fe8d44dc6964d 100644 +--- a/drivers/bluetooth/btqca.c ++++ b/drivers/bluetooth/btqca.c +@@ -712,6 +712,16 @@ static int qca_check_bdaddr(struct hci_dev *hdev, const struct qca_fw_config *co + return 0; + } + ++/* The observed Cologne 1.0 identity uses a distinct firmware-name family. */ ++static bool qca_is_cln10(enum qca_btsoc_type soc_type, ++ struct qca_btsoc_version ver) ++{ ++ return soc_type == QCA_WCN7850 && ++ le32_to_cpu(ver.product_id) == 0x20 && ++ le32_to_cpu(ver.soc_id) == 0x40292100 && ++ le16_to_cpu(ver.rom_ver) == 0x0101; ++} ++ + static void qca_get_nvm_name_by_board(char *fwname, size_t max_size, + const char *stem, enum qca_btsoc_type soc_type, + struct qca_btsoc_version ver, u8 rom_ver, u16 bid) +@@ -719,6 +729,15 @@ static void qca_get_nvm_name_by_board(char *fwname, size_t max_size, + const char *variant; + const char *prefix; + ++ if (qca_is_cln10(soc_type, ver) && !strcmp(stem, "clnbtnv10")) { ++ if ((bid >> 8) > 1 || !(bid & 0xff)) ++ snprintf(fwname, max_size, "qca/%s.bin", stem); ++ else ++ snprintf(fwname, max_size, "qca/%s.b%0*x", stem, ++ bid >> 8 ? 4 : 2, bid); ++ return; ++ } ++ + /* Set the default value to variant and prefix */ + variant = ""; + prefix = "b"; +@@ -823,8 +842,12 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, + "qca/wcnhpbtfw%02x.tlv", rom_ver); + break; + case QCA_WCN7850: +- snprintf(config.fwname, sizeof(config.fwname), +- "qca/hmtbtfw%02x.tlv", rom_ver); ++ if (qca_is_cln10(soc_type, ver)) ++ snprintf(config.fwname, sizeof(config.fwname), ++ "qca/clnbtfw10.tlv"); ++ else ++ snprintf(config.fwname, sizeof(config.fwname), ++ "qca/hmtbtfw%02x.tlv", rom_ver); + break; + default: + snprintf(config.fwname, sizeof(config.fwname), +@@ -917,8 +940,12 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, + "wcnhpnv", soc_type, ver, rom_ver, boardid); + break; + case QCA_WCN7850: +- qca_get_nvm_name_by_board(config.fwname, sizeof(config.fwname), +- "hmtnv", soc_type, ver, rom_ver, boardid); ++ if (qca_is_cln10(soc_type, ver)) ++ qca_get_nvm_name_by_board(config.fwname, sizeof(config.fwname), ++ "clnbtnv10", soc_type, ver, 0, boardid); ++ else ++ qca_get_nvm_name_by_board(config.fwname, sizeof(config.fwname), ++ "hmtnv", soc_type, ver, rom_ver, boardid); + break; + default: + snprintf(config.fwname, sizeof(config.fwname), +diff --git a/drivers/dma/qcom/gpi.c b/drivers/dma/qcom/gpi.c +index c6bf91be2b645fb294cab448a313785978d2ec0a..7420a62b2b5f6110eab6098dc207379c367e91a2 100644 +--- a/drivers/dma/qcom/gpi.c ++++ b/drivers/dma/qcom/gpi.c +@@ -1209,6 +1209,13 @@ static void gpi_process_xfer_compl_event(struct gchan *gchan, + return; + } + ++ if (compl_event->code == MSM_GPI_TCE_EOB && ++ gchan->protocol == QCOM_GPI_I2C && ++ (gpi_desc->tre[gpi_desc->num_tre - 1].dword[3] & TRE_FLAGS_LINK)) { ++ dma_cookie_complete(&vd->tx); ++ goto gpi_free_desc; ++ } ++ + if (compl_event->code == MSM_GPI_TCE_UNEXP_ERR) { + dev_err(gpii->gpi_dev->dev, "Error in Transaction\n"); + result.result = DMA_TRANS_ABORTED; +@@ -2082,10 +2089,12 @@ static int gpi_create_i2c_tre(struct gchan *chan, struct gpi_desc *desc, + + tre->dword[3] = u32_encode_bits(TRE_TYPE_GO, TRE_FLAGS_TYPE); + +- if (i2c->multi_msg) ++ if (i2c->multi_msg) { ++ tre->dword[3] |= u32_encode_bits(1, TRE_FLAGS_IEOB); + tre->dword[3] |= u32_encode_bits(1, TRE_FLAGS_LINK); +- else ++ } else { + tre->dword[3] |= u32_encode_bits(1, TRE_FLAGS_CHAIN); ++ } + } + + if (i2c->op == I2C_READ || i2c->multi_msg == false) { +@@ -2343,7 +2352,7 @@ static int gpi_ch_init(struct gchan *gchan) + dev_err(gpii->gpi_dev->dev, "protocol did not match protocol %u != %u\n", + gpii->gchan[0].protocol, gpii->gchan[1].protocol); + ret = -EINVAL; +- goto exit_gpi_init; ++ goto error_free_ch_ring; + } + + /* allocate memory for event ring */ +@@ -2351,7 +2360,7 @@ static int gpi_ch_init(struct gchan *gchan) + ret = gpi_alloc_ring(&gpii->ev_ring, elements, + sizeof(union gpi_event), gpii); + if (ret) +- goto exit_gpi_init; ++ goto error_free_ch_ring; + + /* configure interrupts */ + write_lock_irq(&gpii->pm_lock); +@@ -2391,16 +2400,24 @@ static int gpi_ch_init(struct gchan *gchan) + error_start_chan: + for (i = i - 1; i >= 0; i--) { + gpi_stop_chan(&gpii->gchan[i]); +- gpi_send_cmd(gpii, gchan, GPI_CH_CMD_RESET); ++ gpi_send_cmd(gpii, &gpii->gchan[i], GPI_CH_CMD_RESET); + } + i = 2; + error_alloc_chan: + for (i = i - 1; i >= 0; i--) +- gpi_reset_chan(gchan, GPI_CH_CMD_DE_ALLOC); ++ gpi_reset_chan(&gpii->gchan[i], GPI_CH_CMD_DE_ALLOC); + error_alloc_ev_ring: + gpi_disable_interrupts(gpii); ++ gpi_free_ring(&gpii->ev_ring, gpii); ++ goto exit_gpi_init; + error_config_int: + gpi_free_ring(&gpii->ev_ring, gpii); ++error_free_ch_ring: ++ /* No hardware command has exposed this transfer ring. */ ++ gpi_free_ring(&gchan->ch_ring, gpii); ++ write_lock_irq(&gpii->pm_lock); ++ gchan->pm_state = DISABLE_STATE; ++ write_unlock_irq(&gpii->pm_lock); + exit_gpi_init: + return ret; + } +@@ -2438,6 +2455,7 @@ static void gpi_free_chan_resources(struct dma_chan *chan) + gpi_free_retired_rings(gchan); + vchan_free_chan_resources(&gchan->vc); + kfree(gchan->config); ++ gchan->config = NULL; + + write_lock_irq(&gpii->pm_lock); + gchan->pm_state = DISABLE_STATE; +diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c +index 3700e98697676d8e6f04f061f447391503f9abba..f9c28fbdb26dfbe1f2f534338c98cfafd1597cd8 100644 +--- a/drivers/firmware/efi/vars.c ++++ b/drivers/firmware/efi/vars.c +@@ -143,7 +143,7 @@ int efivar_lock(void) + { + if (down_interruptible(&efivars_lock)) + return -EINTR; +- if (!__efivars->ops) { ++ if (!__efivars || !__efivars->ops) { + up(&efivars_lock); + return -ENODEV; + } +@@ -159,7 +159,7 @@ int efivar_trylock(void) + { + if (down_trylock(&efivars_lock)) + return -EBUSY; +- if (!__efivars->ops) { ++ if (!__efivars || !__efivars->ops) { + up(&efivars_lock); + return -ENODEV; + } +diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c +index 93f478e49ebc65dde53341dfe7ccf7ae2dce368a..4d223411a1a399d1c9eb5b9ff6d765f471cd4488 100644 +--- a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c ++++ b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c +@@ -1184,17 +1184,19 @@ static void a6xx_gmu_set_initial_freq(struct msm_gpu *gpu, struct a6xx_gmu *gmu) + dev_pm_opp_put(gpu_opp); + } + +-static void a6xx_gmu_set_initial_bw(struct msm_gpu *gpu, struct a6xx_gmu *gmu) ++static int a6xx_gmu_set_initial_bw(struct msm_gpu *gpu, struct a6xx_gmu *gmu) + { + struct dev_pm_opp *gpu_opp; + unsigned long gpu_freq = gmu->gpu_freqs[gmu->current_perf_index]; ++ int ret; + + gpu_opp = dev_pm_opp_find_freq_exact(&gpu->pdev->dev, gpu_freq, true); + if (IS_ERR(gpu_opp)) +- return; ++ return PTR_ERR(gpu_opp); + +- dev_pm_opp_set_opp(&gpu->pdev->dev, gpu_opp); ++ ret = dev_pm_opp_set_opp(&gpu->pdev->dev, gpu_opp); + dev_pm_opp_put(gpu_opp); ++ return ret; + } + + static int a6xx_gmu_secure_init(struct a6xx_gpu *a6xx_gpu) +@@ -1276,7 +1278,7 @@ static int a6xx_gmu_gxpd_get(struct a6xx_gmu *gmu) + * anything but it will make sure that the refcounting is correct in + * case we need to bring down the GX after a GMU failure + */ +- return pm_runtime_get_sync(gmu->gxpd); ++ return pm_runtime_resume_and_get(gmu->gxpd); + } + + static int a6xx_gmu_gxpd_put(struct a6xx_gmu *gmu) +@@ -1319,9 +1321,13 @@ int a6xx_gmu_resume(struct a6xx_gpu *a6xx_gpu) + gmu->hung = false; + + /* Turn on the resources */ +- pm_runtime_get_sync(gmu->dev); ++ ret = pm_runtime_resume_and_get(gmu->dev); ++ if (ret < 0) ++ return ret; + +- a6xx_gmu_gxpd_get(gmu); ++ ret = a6xx_gmu_gxpd_get(gmu); ++ if (ret < 0) ++ goto gmu_put; + + /* Use a known rate to bring up the GMU */ + clk_set_rate(gmu->core_clk, 200000000); +@@ -1339,7 +1345,9 @@ int a6xx_gmu_resume(struct a6xx_gpu *a6xx_gpu) + a8xx_gpu_get_slice_info(gpu); + + /* Set the bus quota to a reasonable value for boot */ +- a6xx_gmu_set_initial_bw(gpu, gmu); ++ ret = a6xx_gmu_set_initial_bw(gpu, gmu); ++ if (ret) ++ goto disable_clk; + + /* Enable the GMU interrupt */ + gmu_write(gmu, REG_A6XX_GMU_AO_HOST_INTERRUPT_CLR, ~0); +@@ -1389,7 +1397,7 @@ int a6xx_gmu_resume(struct a6xx_gpu *a6xx_gpu) + clk_bulk_disable_unprepare(gmu->nr_clocks, gmu->clocks); + rpm_put: + a6xx_gmu_gxpd_put(gmu); +- ++gmu_put: + pm_runtime_put(gmu->dev); + + return ret; +@@ -1537,6 +1545,7 @@ static int a6xx_gmu_memory_alloc(struct a6xx_gmu *gmu, struct a6xx_gmu_bo *bo, + { + struct a6xx_gpu *a6xx_gpu = container_of(gmu, struct a6xx_gpu, gmu); + struct drm_device *dev = a6xx_gpu->base.base.dev; ++ struct drm_gem_object *obj; + uint32_t flags = MSM_BO_WC; + u64 range_start, range_end; + int ret; +@@ -1554,23 +1563,32 @@ static int a6xx_gmu_memory_alloc(struct a6xx_gmu *gmu, struct a6xx_gmu_bo *bo, + flags |= MSM_BO_MAP_PRIV; + } + +- bo->obj = msm_gem_new(dev, size, flags, NULL); +- if (IS_ERR(bo->obj)) +- return PTR_ERR(bo->obj); ++ obj = msm_gem_new(dev, size, flags, NULL); ++ if (IS_ERR(obj)) ++ return PTR_ERR(obj); + +- ret = msm_gem_get_and_pin_iova_range(bo->obj, gmu->vm, &bo->iova, ++ ret = msm_gem_get_and_pin_iova_range(obj, gmu->vm, &bo->iova, + range_start, range_end); +- if (ret) { +- drm_gem_object_put(bo->obj); +- return ret; ++ if (ret) ++ goto err_put; ++ ++ bo->virt = msm_gem_get_vaddr(obj); ++ if (IS_ERR(bo->virt)) { ++ ret = PTR_ERR(bo->virt); ++ msm_gem_unpin_iova(obj, gmu->vm); ++ goto err_put; + } + +- bo->virt = msm_gem_get_vaddr(bo->obj); ++ bo->obj = obj; + bo->size = size; + +- msm_gem_object_set_name(bo->obj, "%s", name); ++ msm_gem_object_set_name(obj, "%s", name); + + return 0; ++ ++err_put: ++ drm_gem_object_put(obj); ++ return ret; + } + + static int a6xx_gmu_memory_probe(struct drm_device *drm, struct a6xx_gmu *gmu) +@@ -1582,8 +1600,10 @@ static int a6xx_gmu_memory_probe(struct drm_device *drm, struct a6xx_gmu *gmu) + return PTR_ERR(mmu); + + gmu->vm = msm_gem_vm_create(drm, mmu, "gmu", 0x0, 0x80000000, true); +- if (IS_ERR(gmu->vm)) ++ if (IS_ERR(gmu->vm)) { ++ mmu->funcs->destroy(mmu); + return PTR_ERR(gmu->vm); ++ } + + return 0; + } +@@ -1622,12 +1642,17 @@ static int a6xx_gmu_rpmh_bw_votes_init(struct adreno_gpu *adreno_gpu, + if (IS_ERR(bcm_data[bcm_index])) + return PTR_ERR(bcm_data[bcm_index]); + +- if (!count) { ++ if (count < sizeof(*bcm_data[bcm_index])) { + dev_err(gmu->dev, "invalid BCM '%s' aux data size\n", + bcm->name); + return -EINVAL; + } + ++ if (!bcm->fixed && !le32_to_cpu(bcm_data[bcm_index]->unit)) { ++ dev_err(gmu->dev, "invalid BCM '%s' unit\n", bcm->name); ++ return -EINVAL; ++ } ++ + bcm_count++; + } + +@@ -1656,8 +1681,12 @@ static int a6xx_gmu_rpmh_bw_votes_init(struct adreno_gpu *adreno_gpu, + if (bcm->fixed) { + u32 perfmode = 0; + +- /* GMU on A6xx votes perfmode on all valid bandwidth */ +- if (!adreno_is_a7xx(adreno_gpu) || ++ /* ++ * GMU on A6xx votes perfmode on all valid ++ * bandwidth. A7xx and A8xx only vote perfmode ++ * above the perfmode_bw threshold. ++ */ ++ if (adreno_is_a6xx(adreno_gpu) || + (bcm->perfmode_bw && bw >= bcm->perfmode_bw)) + perfmode = bcm->perfmode; + +@@ -1707,70 +1736,88 @@ static unsigned int a6xx_gmu_get_arc_level(struct device *dev, + return val; + } + ++static const u16 *a6xx_gmu_rpmh_read_arc(const char *id, size_t *count) ++{ ++ const u16 *vals; ++ ++ vals = cmd_db_read_aux_data(id, count); ++ if (IS_ERR(vals)) ++ return vals; ++ ++ if (*count % sizeof(*vals)) ++ return ERR_PTR(-EINVAL); ++ ++ *count /= sizeof(*vals); ++ /* Exclude the trailing zero paddings if there are any */ ++ while (*count && !vals[*count - 1]) ++ (*count)--; ++ ++ if (!*count) ++ return ERR_PTR(-EINVAL); ++ ++ return vals; ++} ++ ++/* ++ * Find the first index in an arc level array whose level is greater than or ++ * equal to the target. If no level is high enough, either clamp to the ++ * highest available level (@clamp) or fail, dumping the list. ++ */ ++static int a6xx_gmu_rpmh_arc_index(struct device *dev, const u16 *arc, ++ size_t arc_count, unsigned int level, bool clamp) ++{ ++ int j; ++ ++ for (j = 0; j < arc_count; j++) { ++ if (arc[j] >= level) ++ return j; ++ } ++ ++ if (clamp) ++ return arc_count - 1; ++ ++ DRM_DEV_ERROR(dev, "Level %u not found in the RPMh list\n", level); ++ DRM_DEV_ERROR(dev, "Available levels:\n"); ++ for (j = 0; j < arc_count; j++) ++ DRM_DEV_ERROR(dev, " %u\n", arc[j]); ++ ++ return -EINVAL; ++} ++ + static int a6xx_gmu_rpmh_arc_votes_init(struct device *dev, u32 *votes, + unsigned long *freqs, int freqs_count, + const char *pri_id, const char *sec_id) + { +- int i, j; ++ int i; + const u16 *pri, *sec; + size_t pri_count, sec_count; + +- pri = cmd_db_read_aux_data(pri_id, &pri_count); ++ pri = a6xx_gmu_rpmh_read_arc(pri_id, &pri_count); + if (IS_ERR(pri)) + return PTR_ERR(pri); +- /* +- * The data comes back as an array of unsigned shorts so adjust the +- * count accordingly +- */ +- pri_count >>= 1; +- if (!pri_count) +- return -EINVAL; + +- sec = cmd_db_read_aux_data(sec_id, &sec_count); ++ sec = a6xx_gmu_rpmh_read_arc(sec_id, &sec_count); + if (IS_ERR(sec)) + return PTR_ERR(sec); + +- sec_count >>= 1; +- if (!sec_count) +- return -EINVAL; +- + /* Construct a vote for each frequency */ + for (i = 0; i < freqs_count; i++) { +- u8 pindex = 0, sindex = 0; + unsigned int level = a6xx_gmu_get_arc_level(dev, freqs[i]); ++ int pindex, sindex; + +- /* Get the primary index that matches the arc level */ +- for (j = 0; j < pri_count; j++) { +- if (pri[j] >= level) { +- pindex = j; +- break; +- } +- } +- +- if (j == pri_count) { +- DRM_DEV_ERROR(dev, +- "Level %u not found in the RPMh list\n", +- level); +- DRM_DEV_ERROR(dev, "Available levels:\n"); +- for (j = 0; j < pri_count; j++) +- DRM_DEV_ERROR(dev, " %u\n", pri[j]); +- +- return -EINVAL; +- } ++ pindex = a6xx_gmu_rpmh_arc_index(dev, pri, pri_count, level, false); ++ if (pindex < 0) ++ return pindex; + + /* +- * Look for a level in in the secondary list that matches. If +- * nothing fits, use the maximum non zero vote ++ * Look for a matching level in the secondary list; if nothing ++ * fits, clamp to the highest available vote. The secondary rail ++ * depends on the primary rail, so match it against the selected ++ * primary voltage (which is >= the requested level), not the ++ * requested level itself. + */ +- +- for (j = 0; j < sec_count; j++) { +- if (sec[j] >= level) { +- sindex = j; +- break; +- } else if (sec[j]) { +- sindex = j; +- } +- } ++ sindex = a6xx_gmu_rpmh_arc_index(dev, sec, sec_count, ++ pri[pindex], true); + + /* Construct the vote */ + votes[i] = ((pri[pindex] & 0xffff) << 16) | +@@ -1780,22 +1827,35 @@ static int a6xx_gmu_rpmh_arc_votes_init(struct device *dev, u32 *votes, + return 0; + } + ++#define GMU_BX_MASK GENMASK(25, 20) ++ + static int a6xx_gmu_rpmh_dep_votes_init(struct device *dev, u32 *votes, + unsigned long *freqs, int freqs_count) + { +- const u16 *mx; +- size_t count; ++ const u16 *mx, *gx = NULL, *gbx; ++ size_t count, gx_count = 0, gbx_count = 0; + +- mx = cmd_db_read_aux_data("mx.lvl", &count); ++ mx = a6xx_gmu_rpmh_read_arc("mx.lvl", &count); + if (IS_ERR(mx)) + return PTR_ERR(mx); ++ + /* +- * The data comes back as an array of unsigned shorts so adjust the +- * count accordingly ++ * Targets with a third memory rail (BX), in addition to GX and MX, ++ * expect a per-corner BX vote packed into the dependency vote. Detect ++ * such targets by the presence of the "gbx.lvl" RPMh resource. The BX ++ * corner is matched against the Gx rail level, so the "gfx.lvl" corners ++ * are needed as well. + */ +- count >>= 1; +- if (!count) +- return -EINVAL; ++ gbx = a6xx_gmu_rpmh_read_arc("gbx.lvl", &gbx_count); ++ if (IS_ERR(gbx)) { ++ if (PTR_ERR(gbx) != -ENODEV) ++ return PTR_ERR(gbx); ++ gbx = NULL; ++ } else { ++ gx = a6xx_gmu_rpmh_read_arc("gfx.lvl", &gx_count); ++ if (IS_ERR(gx)) ++ return PTR_ERR(gx); ++ } + + /* Fix the vote for zero frequency */ + votes[0] = 0xffffffff; +@@ -1803,29 +1863,32 @@ static int a6xx_gmu_rpmh_dep_votes_init(struct device *dev, u32 *votes, + /* Construct a vote for rest of the corners */ + for (int i = 1; i < freqs_count; i++) { + unsigned int level = a6xx_gmu_get_arc_level(dev, freqs[i]); +- u8 j, index = 0; ++ int index = a6xx_gmu_rpmh_arc_index(dev, mx, count, level, true); ++ int bx; + +- /* Get the primary index that matches the arc level */ +- for (j = 0; j < count; j++) { +- if (mx[j] >= level) { +- index = j; +- break; +- } +- } +- +- if (j == count) { +- DRM_DEV_ERROR(dev, +- "Mx Level %u not found in the RPMh list\n", +- level); +- DRM_DEV_ERROR(dev, "Available levels:\n"); +- for (j = 0; j < count; j++) +- DRM_DEV_ERROR(dev, " %u\n", mx[j]); +- +- return -EINVAL; +- } ++ if (index < 0) ++ return index; + + /* Construct the vote */ + votes[i] = (0x3fff << 14) | (index << 8) | (0xff); ++ ++ if (!gbx) ++ continue; ++ ++ index = a6xx_gmu_rpmh_arc_index(dev, gx, gx_count, level, false); ++ if (index < 0) ++ return index; ++ ++ /* ++ * Find the BX corner that satisfies that Gx level, falling ++ * back to the highest BX corner if none is high enough. ++ */ ++ bx = a6xx_gmu_rpmh_arc_index(dev, gbx, gbx_count, gx[index], true); ++ if (bx < 0) ++ return bx; ++ if (bx > FIELD_MAX(GMU_BX_MASK)) ++ return -ERANGE; ++ FIELD_MODIFY(GMU_BX_MASK, &votes[i], bx); + } + + return 0; +@@ -1860,16 +1923,23 @@ static int a6xx_gmu_rpmh_votes_init(struct a6xx_gmu *gmu) + ret = a6xx_gmu_rpmh_arc_votes_init(&gpu->pdev->dev, gmu->gx_arc_votes, + gmu->gpu_freqs, gmu->nr_gpu_freqs, "gfx.lvl", sec_id); + +- /* Build the CX votes */ +- ret |= a6xx_gmu_rpmh_arc_votes_init(gmu->dev, gmu->cx_arc_votes, +- gmu->gmu_freqs, gmu->nr_gmu_freqs, "cx.lvl", "mx.lvl"); ++ if (ret) ++ return ret; ++ ++ ret = a6xx_gmu_rpmh_dep_votes_init(&gpu->pdev->dev, gmu->dep_arc_votes, ++ gmu->gpu_freqs, gmu->nr_gpu_freqs); ++ if (ret) ++ return ret; + +- ret |= a6xx_gmu_rpmh_dep_votes_init(gmu->dev, gmu->dep_arc_votes, +- gmu->gpu_freqs, gmu->nr_gpu_freqs); ++ /* Build the CX votes */ ++ ret = a6xx_gmu_rpmh_arc_votes_init(gmu->dev, gmu->cx_arc_votes, ++ gmu->gmu_freqs, gmu->nr_gmu_freqs, "cx.lvl", "mx.lvl"); ++ if (ret) ++ return ret; + + /* Build the interconnect votes */ + if (info->bcms && gmu->nr_gpu_bws > 1) +- ret |= a6xx_gmu_rpmh_bw_votes_init(adreno_gpu, info, gmu); ++ ret = a6xx_gmu_rpmh_bw_votes_init(adreno_gpu, info, gmu); + + return ret; + } +@@ -1882,13 +1952,18 @@ static int a6xx_gmu_build_freq_table(struct device *dev, unsigned long *freqs, + int i, index = 0; + unsigned long freq = 1; + ++ if (count < 0) ++ return count; ++ if (!count) ++ return -EINVAL; ++ + /* + * The OPP table doesn't contain the "off" frequency level so we need to + * add 1 to the table size to account for it + */ + +- if (WARN(count + 1 > size, +- "The GMU frequency table is being truncated\n")) ++ if (WARN(count >= size, ++ "The GMU frequency table is being truncated\n")) + count = size - 1; + + /* Set the "off" frequency */ +@@ -1896,14 +1971,17 @@ static int a6xx_gmu_build_freq_table(struct device *dev, unsigned long *freqs, + + for (i = 0; i < count; i++) { + opp = dev_pm_opp_find_freq_ceil(dev, &freq); +- if (IS_ERR(opp)) +- break; ++ if (IS_ERR(opp)) { ++ if (PTR_ERR(opp) == -ERANGE) ++ break; ++ return PTR_ERR(opp); ++ } + + dev_pm_opp_put(opp); + freqs[index++] = freq++; + } + +- return index; ++ return index > 1 ? index : -EINVAL; + } + + static int a6xx_gmu_build_bw_table(struct device *dev, unsigned long *bandwidths, +@@ -1914,13 +1992,18 @@ static int a6xx_gmu_build_bw_table(struct device *dev, unsigned long *bandwidths + int i, index = 0; + unsigned int bandwidth = 1; + ++ if (count < 0) ++ return count; ++ if (!count) ++ return -EINVAL; ++ + /* + * The OPP table doesn't contain the "off" bandwidth level so we need to + * add 1 to the table size to account for it + */ + +- if (WARN(count + 1 > size, +- "The GMU bandwidth table is being truncated\n")) ++ if (WARN(count >= size, ++ "The GMU bandwidth table is being truncated\n")) + count = size - 1; + + /* Set the "off" bandwidth */ +@@ -1928,8 +2011,11 @@ static int a6xx_gmu_build_bw_table(struct device *dev, unsigned long *bandwidths + + for (i = 0; i < count; i++) { + opp = dev_pm_opp_find_bw_ceil(dev, &bandwidth, 0); +- if (IS_ERR(opp)) +- break; ++ if (IS_ERR(opp)) { ++ if (PTR_ERR(opp) == -ERANGE) ++ break; ++ return PTR_ERR(opp); ++ } + + dev_pm_opp_put(opp); + bandwidths[index++] = bandwidth++; +@@ -1957,15 +2043,21 @@ static int a6xx_gmu_pwrlevels_probe(struct a6xx_gmu *gmu) + return ret; + } + +- gmu->nr_gmu_freqs = a6xx_gmu_build_freq_table(gmu->dev, +- gmu->gmu_freqs, ARRAY_SIZE(gmu->gmu_freqs)); ++ ret = a6xx_gmu_build_freq_table(gmu->dev, ++ gmu->gmu_freqs, ARRAY_SIZE(gmu->gmu_freqs)); ++ if (ret < 0) ++ return ret; ++ gmu->nr_gmu_freqs = ret; + + /* + * The GMU also handles GPU frequency switching so build a list + * from the GPU OPP table + */ +- gmu->nr_gpu_freqs = a6xx_gmu_build_freq_table(&gpu->pdev->dev, +- gmu->gpu_freqs, ARRAY_SIZE(gmu->gpu_freqs)); ++ ret = a6xx_gmu_build_freq_table(&gpu->pdev->dev, ++ gmu->gpu_freqs, ARRAY_SIZE(gmu->gpu_freqs)); ++ if (ret < 0) ++ return ret; ++ gmu->nr_gpu_freqs = ret; + + gmu->current_perf_index = gmu->nr_gpu_freqs - 1; + +@@ -1973,9 +2065,13 @@ static int a6xx_gmu_pwrlevels_probe(struct a6xx_gmu *gmu) + * The GMU also handles GPU Interconnect Votes so build a list + * of DDR bandwidths from the GPU OPP table + */ +- if (info->bcms) +- gmu->nr_gpu_bws = a6xx_gmu_build_bw_table(&gpu->pdev->dev, +- gmu->gpu_bw_table, ARRAY_SIZE(gmu->gpu_bw_table)); ++ if (info->bcms) { ++ ret = a6xx_gmu_build_bw_table(&gpu->pdev->dev, ++ gmu->gpu_bw_table, ARRAY_SIZE(gmu->gpu_bw_table)); ++ if (ret < 0) ++ return ret; ++ gmu->nr_gpu_bws = ret; ++ } + + /* Build the list of RPMh votes that we'll send to the GMU */ + return a6xx_gmu_rpmh_votes_init(gmu); +@@ -2075,6 +2171,8 @@ static int a6xx_gmu_get_irq(struct a6xx_gmu *gmu, struct platform_device *pdev, + int irq, ret; + + irq = platform_get_irq_byname(pdev, name); ++ if (irq < 0) ++ return irq; + + ret = request_irq(irq, handler, IRQF_TRIGGER_HIGH | IRQF_NO_AUTOEN, name, gmu); + if (ret) { +@@ -2117,6 +2215,7 @@ static void a6xx_gmu_destroy(struct a6xx_gpu *a6xx_gpu) + { + struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; + struct a6xx_gmu *gmu = &a6xx_gpu->gmu; ++ int ret; + + mutex_lock(&gmu->lock); + if (!gmu->initialized) { +@@ -2128,7 +2227,10 @@ static void a6xx_gmu_destroy(struct a6xx_gpu *a6xx_gpu) + + mutex_unlock(&gmu->lock); + +- pm_runtime_force_suspend(gmu->dev); ++ /* force_suspend leaves runtime PM disabled unless it fails. */ ++ ret = pm_runtime_force_suspend(gmu->dev); ++ if (ret) ++ pm_runtime_disable(gmu->dev); + + /* + * Since cxpd is a virt device, the devlink with gmu-dev will be removed +@@ -2156,6 +2258,8 @@ static void a6xx_gmu_destroy(struct a6xx_gpu *a6xx_gpu) + free_irq(gmu->hfi_irq, gmu); + } + ++ devres_release_group(gmu->dev, gmu); ++ + /* Drop reference taken in of_find_device_by_node */ + put_device(gmu->dev); + } +@@ -2199,6 +2303,7 @@ static int a6xx_gmu_wrapper_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_n + struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; + struct msm_gpu *gpu = &adreno_gpu->base; + struct a6xx_gmu *gmu = &a6xx_gpu->gmu; ++ struct device_link *link; + resource_size_t start; + struct resource *res; + int ret; +@@ -2210,7 +2315,12 @@ static int a6xx_gmu_wrapper_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_n + + ret = of_dma_configure(gmu->dev, node, true); + if (ret) +- return ret; ++ goto err_put_device; ++ ++ if (!devres_open_group(gmu->dev, gmu, GFP_KERNEL)) { ++ ret = -ENOMEM; ++ goto err_put_device; ++ } + + pm_runtime_enable(gmu->dev); + +@@ -2228,7 +2338,7 @@ static int a6xx_gmu_wrapper_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_n + gmu->mmio = a6xx_gmu_get_mmio(pdev, &start); + if (IS_ERR(gmu->mmio)) { + ret = PTR_ERR(gmu->mmio); +- goto err_mmio; ++ goto err_clk; + } + + res = platform_get_resource_byname(gpu->pdev, IORESOURCE_MEM, "kgsl_3d0_reg_memory"); +@@ -2246,8 +2356,9 @@ static int a6xx_gmu_wrapper_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_n + goto err_mmio; + } + +- if (!device_link_add(gmu->dev, gmu->cxpd, +- DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS)) { ++ link = device_link_add(gmu->dev, gmu->cxpd, ++ DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); ++ if (!link) { + ret = -ENODEV; + goto detach_cxpd; + } +@@ -2260,13 +2371,17 @@ static int a6xx_gmu_wrapper_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_n + gmu->gxpd = dev_pm_domain_attach_by_name(gmu->dev, "gx"); + if (IS_ERR(gmu->gxpd)) { + ret = PTR_ERR(gmu->gxpd); +- goto err_mmio; ++ goto del_link; + } + ++ devres_close_group(gmu->dev, gmu); + gmu->initialized = true; + + return 0; + ++del_link: ++ device_link_del(link); ++ + detach_cxpd: + dev_pm_domain_detach(gmu->cxpd, false); + +@@ -2274,6 +2389,9 @@ static int a6xx_gmu_wrapper_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_n + iounmap(gmu->mmio); + + err_clk: ++ pm_runtime_disable(gmu->dev); ++ devres_release_group(gmu->dev, gmu); ++err_put_device: + /* Drop reference taken in of_find_device_by_node */ + put_device(gmu->dev); + +@@ -2298,7 +2416,12 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + + ret = of_dma_configure(gmu->dev, node, true); + if (ret) +- return ret; ++ goto err_put_device; ++ ++ if (!devres_open_group(gmu->dev, gmu, GFP_KERNEL)) { ++ ret = -ENOMEM; ++ goto err_put_device; ++ } + + /* Set GMU idle level */ + gmu->idle_level = (adreno_gpu->info->quirks & ADRENO_QUIRK_IFPC) ? +@@ -2309,11 +2432,11 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + /* Get the list of clocks */ + ret = a6xx_gmu_clocks_probe(gmu); + if (ret) +- goto err_put_device; ++ goto err_resources; + + ret = a6xx_gmu_memory_probe(adreno_gpu->base.dev, gmu); + if (ret) +- goto err_put_device; ++ goto err_resources; + + + /* A660 now requires handling "prealloc requests" in GMU firmware +@@ -2404,7 +2527,7 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + adreno_is_a7xx(adreno_gpu)) { + gmu->rscc = devm_platform_ioremap_resource_byname(pdev, "rscc"); + if (IS_ERR(gmu->rscc)) { +- ret = -ENODEV; ++ ret = PTR_ERR(gmu->rscc); + goto err_mmio; + } + } else if (adreno_is_a8xx(adreno_gpu)) { +@@ -2420,17 +2543,21 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + + /* Get the HFI and GMU interrupts */ + gmu->hfi_irq = a6xx_gmu_get_irq(gmu, pdev, "hfi", a6xx_hfi_irq); +- gmu->gmu_irq = a6xx_gmu_get_irq(gmu, pdev, "gmu", a6xx_gmu_irq); +- +- if (gmu->hfi_irq < 0 || gmu->gmu_irq < 0) { +- ret = -ENODEV; ++ if (gmu->hfi_irq < 0) { ++ ret = gmu->hfi_irq; + goto err_mmio; + } + ++ gmu->gmu_irq = a6xx_gmu_get_irq(gmu, pdev, "gmu", a6xx_gmu_irq); ++ if (gmu->gmu_irq < 0) { ++ ret = gmu->gmu_irq; ++ goto err_hfi_irq; ++ } ++ + gmu->cxpd = dev_pm_domain_attach_by_name(gmu->dev, "cx"); + if (IS_ERR(gmu->cxpd)) { + ret = PTR_ERR(gmu->cxpd); +- goto err_mmio; ++ goto err_gmu_irq; + } + + link = device_link_add(gmu->dev, gmu->cxpd, +@@ -2444,7 +2571,7 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + gmu->qmp = qmp_get(gmu->dev); + if (PTR_ERR_OR_ZERO(gmu->qmp) == -EPROBE_DEFER) { + ret = -EPROBE_DEFER; +- goto detach_gxpd; ++ goto del_link; + } + + init_completion(&gmu->pd_gate); +@@ -2458,7 +2585,9 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + gmu->gxpd = dev_pm_domain_attach_by_name(gmu->dev, "gx"); + + /* Get the power levels for the GMU and GPU */ +- a6xx_gmu_pwrlevels_probe(gmu); ++ ret = a6xx_gmu_pwrlevels_probe(gmu); ++ if (ret) ++ goto detach_gxpd; + + ret = a6xx_gmu_acd_probe(gmu); + if (ret) +@@ -2470,6 +2599,7 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + /* Initialize RPMh */ + a6xx_gmu_rpmh_init(gmu); + ++ devres_close_group(gmu->dev, gmu); + gmu->initialized = true; + + return 0; +@@ -2481,18 +2611,24 @@ static int a6xx_gmu_pdev_bind(struct a6xx_gpu *a6xx_gpu, struct device_node *nod + if (!IS_ERR_OR_NULL(gmu->qmp)) + qmp_put(gmu->qmp); + ++del_link: + device_link_del(link); + + detach_cxpd: + dev_pm_domain_detach(gmu->cxpd, false); + +-err_mmio: +- iounmap(gmu->mmio); ++err_gmu_irq: + free_irq(gmu->gmu_irq, gmu); ++err_hfi_irq: + free_irq(gmu->hfi_irq, gmu); ++err_mmio: ++ iounmap(gmu->mmio); + + err_memory: + a6xx_gmu_memory_free(gmu); ++err_resources: ++ pm_runtime_disable(gmu->dev); ++ devres_release_group(gmu->dev, gmu); + err_put_device: + /* Drop reference taken in of_find_device_by_node */ + put_device(gmu->dev); +diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.h b/drivers/gpu/drm/msm/adreno/adreno_gpu.h +index ea568dabb4c53a1e8e2e0bb60e233c932ddcfd49..fa733923f94eba3acd7650cf86d980f2e6ba3b73 100644 +--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.h ++++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.h +@@ -582,6 +582,11 @@ static inline int adreno_is_a750_family(struct adreno_gpu *gpu) + return gpu->info->family == ADRENO_7XX_GEN3; + } + ++static inline int adreno_is_a6xx(struct adreno_gpu *gpu) ++{ ++ return (gpu->info->family >= ADRENO_6XX_GEN1) && (gpu->info->family < ADRENO_7XX_GEN1); ++} ++ + static inline int adreno_is_a7xx(struct adreno_gpu *gpu) + { + /* Update with non-fake (i.e. non-A702) Gen 7 GPUs */ +diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c +index 3a1ee098c8a7917d7007f90d7d1e72fb72116156..de72dd059db26756ff318ef55ea63ee82a960dee 100644 +--- a/drivers/gpu/drm/msm/dp/dp_aux.c ++++ b/drivers/gpu/drm/msm/dp/dp_aux.c +@@ -274,16 +274,17 @@ static void msm_dp_aux_update_offset_and_segment(struct msm_dp_aux_private *aux, + * @input_msg: input message from DRM upstream APIs + * @send_seg: send the segment to sink + * +- * return: void ++ * Return: 0 on success or a negative error code. + * + * This helper function is used to fix EDID reads for non-compliant + * sinks that do not handle the i2c middle-of-transaction flag correctly. + */ +-static void msm_dp_aux_transfer_helper(struct msm_dp_aux_private *aux, +- struct drm_dp_aux_msg *input_msg, +- bool send_seg) ++static int msm_dp_aux_transfer_helper(struct msm_dp_aux_private *aux, ++ struct drm_dp_aux_msg *input_msg, ++ bool send_seg) + { + struct drm_dp_aux_msg helper_msg; ++ ssize_t ret; + u32 message_size = 0x10; + u32 edid_address = 0x50; + u32 segment_address = 0x30; +@@ -293,7 +294,7 @@ static void msm_dp_aux_transfer_helper(struct msm_dp_aux_private *aux, + (DP_AUX_I2C_READ & DP_AUX_NATIVE_READ); + + if (!i2c_mot || !i2c_read || (input_msg->size == 0)) +- return; ++ return 0; + + /* + * This workaround is specific to EDID reads, and the offset it tracks +@@ -309,7 +310,7 @@ static void msm_dp_aux_transfer_helper(struct msm_dp_aux_private *aux, + */ + if (input_msg->address != edid_address && + input_msg->address != segment_address) +- return; ++ return 0; + + /* + * Sending the segment value and EDID offset will be performed +@@ -338,7 +339,9 @@ static void msm_dp_aux_transfer_helper(struct msm_dp_aux_private *aux, + helper_msg.address = segment_address; + helper_msg.buffer = &aux->segment; + helper_msg.size = 1; +- msm_dp_aux_cmd_fifo_tx(aux, &helper_msg); ++ ret = msm_dp_aux_cmd_fifo_tx(aux, &helper_msg); ++ if (ret < 0) ++ return ret; + } + + /* +@@ -352,12 +355,16 @@ static void msm_dp_aux_transfer_helper(struct msm_dp_aux_private *aux, + helper_msg.address = input_msg->address; + helper_msg.buffer = &aux->offset; + helper_msg.size = 1; +- msm_dp_aux_cmd_fifo_tx(aux, &helper_msg); ++ ret = msm_dp_aux_cmd_fifo_tx(aux, &helper_msg); ++ if (ret < 0) ++ return ret; + + end: + aux->offset += message_size; + if (aux->offset == 0x80 || aux->offset == 0x100) + aux->segment = 0x0; /* reset segment at end of block */ ++ ++ return 0; + } + + /* +@@ -426,7 +433,9 @@ static ssize_t msm_dp_aux_transfer(struct drm_dp_aux *msm_dp_aux, + } + + msm_dp_aux_update_offset_and_segment(aux, msg); +- msm_dp_aux_transfer_helper(aux, msg, true); ++ ret = msm_dp_aux_transfer_helper(aux, msg, true); ++ if (ret < 0) ++ goto transfer_done; + + aux->read = msg->request & (DP_AUX_I2C_READ & DP_AUX_NATIVE_READ); + aux->cmd_busy = true; +@@ -440,6 +449,7 @@ static ssize_t msm_dp_aux_transfer(struct drm_dp_aux *msm_dp_aux, + } + + ret = msm_dp_aux_cmd_fifo_tx(aux, msg); ++transfer_done: + if (ret < 0) { + if (aux->native) { + aux->retry_cnt++; +diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c +index d294a02f89e5614b8b846bf4b67ac08d6129d45f..337e8da1051e53aaa102306219a5077a94e62e79 100644 +--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c ++++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c +@@ -183,6 +183,7 @@ struct msm_dp_ctrl_private { + bool core_clks_on; + bool link_clks_on; + bool stream_clks_on; ++ bool phy_powered_on; + }; + + static inline u32 msm_dp_read_ahb(const struct msm_dp_ctrl_private *ctrl, u32 offset) +@@ -228,8 +229,8 @@ static int msm_dp_aux_link_configure(struct drm_dp_aux *aux, + lane_count |= DP_LANE_COUNT_ENHANCED_FRAME_EN; + + err = drm_dp_dpcd_writeb(aux, DP_LANE_COUNT_SET, lane_count); +- if (err < 0) +- return err; ++ if (err != 1) ++ return err < 0 ? err : -EIO; + + if (link->use_rate_set) { + /* +@@ -256,7 +257,7 @@ static int msm_dp_aux_link_configure(struct drm_dp_aux *aux, + err = drm_dp_dpcd_writeb(aux, DP_LINK_BW_SET, bw_code); + } + +- return err; ++ return err == 1 ? 0 : (err < 0 ? err : -EIO); + } + + /* +@@ -1640,8 +1641,8 @@ static int msm_dp_ctrl_update_phy_vx_px(struct msm_dp_ctrl_private *ctrl, + return ret; + } + +-static bool msm_dp_ctrl_train_pattern_set(struct msm_dp_ctrl_private *ctrl, +- u8 pattern, enum drm_dp_phy dp_phy) ++static int msm_dp_ctrl_train_pattern_set(struct msm_dp_ctrl_private *ctrl, ++ u8 pattern, enum drm_dp_phy dp_phy) + { + u8 buf; + int reg; +@@ -1660,7 +1661,7 @@ static bool msm_dp_ctrl_train_pattern_set(struct msm_dp_ctrl_private *ctrl, + reg = DP_TRAINING_PATTERN_SET_PHY_REPEATER(dp_phy); + + ret = drm_dp_dpcd_writeb(ctrl->aux, reg, buf); +- return ret == 1; ++ return ret == 1 ? 0 : (ret < 0 ? ret : -EIO); + } + + static int msm_dp_ctrl_set_pattern_state_bit(struct msm_dp_ctrl_private *ctrl, +@@ -1706,8 +1707,10 @@ static int msm_dp_ctrl_link_train_1(struct msm_dp_ctrl_private *ctrl, + ret = msm_dp_ctrl_set_pattern_state_bit(ctrl, 1); + if (ret) + return ret; +- msm_dp_ctrl_train_pattern_set(ctrl, DP_TRAINING_PATTERN_1 | ++ ret = msm_dp_ctrl_train_pattern_set(ctrl, DP_TRAINING_PATTERN_1 | + DP_LINK_SCRAMBLING_DISABLE, dp_phy); ++ if (ret) ++ return ret; + + msm_dp_link_reset_phy_params_vx_px(ctrl->link); + ret = msm_dp_ctrl_update_phy_vx_px(ctrl, dp_phy); +@@ -1835,7 +1838,9 @@ static int msm_dp_ctrl_link_train_2(struct msm_dp_ctrl_private *ctrl, + if (ret) + return ret; + +- msm_dp_ctrl_train_pattern_set(ctrl, pattern, dp_phy); ++ ret = msm_dp_ctrl_train_pattern_set(ctrl, pattern, dp_phy); ++ if (ret) ++ return ret; + + for (tries = 0; tries <= maximum_retries; tries++) { + fsleep(delay_us); +@@ -2026,7 +2031,9 @@ static int msm_dp_ctrl_link_train(struct msm_dp_ctrl_private *ctrl, + link_info.use_rate_set = ctrl->link->link_params.use_rate_set; + link_info.capabilities = DP_LINK_CAP_ENHANCED_FRAMING; + +- msm_dp_aux_link_configure(ctrl->aux, dpcd, &link_info); ++ ret = msm_dp_aux_link_configure(ctrl->aux, dpcd, &link_info); ++ if (ret) ++ return ret; + + /* + * A compressed stream runs with forward error correction: tell the +@@ -2045,14 +2052,19 @@ static int msm_dp_ctrl_link_train(struct msm_dp_ctrl_private *ctrl, + encoding[0] |= DP_SPREAD_AMP_0_5; + + /* config DOWNSPREAD_CTRL and MAIN_LINK_CHANNEL_CODING_SET */ +- drm_dp_dpcd_write(ctrl->aux, DP_DOWNSPREAD_CTRL, encoding, 2); ++ ret = drm_dp_dpcd_write(ctrl->aux, DP_DOWNSPREAD_CTRL, encoding, 2); ++ if (ret != 2) ++ return ret < 0 ? ret : -EIO; + + if (drm_dp_alternate_scrambler_reset_cap(dpcd)) { + assr = DP_ALTERNATE_SCRAMBLER_RESET_ENABLE; +- drm_dp_dpcd_write(ctrl->aux, DP_EDP_CONFIGURATION_SET, +- &assr, 1); ++ ret = drm_dp_dpcd_write(ctrl->aux, DP_EDP_CONFIGURATION_SET, ++ &assr, 1); ++ if (ret != 1) ++ return ret < 0 ? ret : -EIO; + } + ++ ret = 0; + for (i = ctrl->link->lttpr_count - 1; i >= 0; i--) { + enum drm_dp_phy dp_phy = DP_PHY_LTTPR(i); + +@@ -2291,6 +2303,9 @@ static void msm_dp_ctrl_link_clk_disable(struct msm_dp_ctrl *msm_dp_ctrl) + + ctrl = container_of(msm_dp_ctrl, struct msm_dp_ctrl_private, msm_dp_ctrl); + ++ if (!ctrl->link_clks_on) ++ return; ++ + /* + * Restoring native framing can latch video/idle status. Mask it before + * stopping link clocks, while the ISR can still acknowledge it. +@@ -2326,6 +2341,20 @@ static void msm_dp_ctrl_link_clk_disable(struct msm_dp_ctrl *msm_dp_ctrl) + str_on_off(ctrl->core_clks_on)); + } + ++static int msm_dp_ctrl_phy_power_off(struct msm_dp_ctrl_private *ctrl) ++{ ++ int ret; ++ ++ if (!ctrl->phy_powered_on) ++ return 0; ++ ++ ret = phy_power_off(ctrl->phy); ++ if (!ret) ++ ctrl->phy_powered_on = false; ++ ++ return ret; ++} ++ + static int msm_dp_ctrl_enable_mainlink_clocks(struct msm_dp_ctrl_private *ctrl, + struct msm_dp_panel *panel) + { +@@ -2343,10 +2372,13 @@ static int msm_dp_ctrl_enable_mainlink_clocks(struct msm_dp_ctrl_private *ctrl, + ctrl->phy_opts.dp.link_rate * 100, ctrl->phy_opts.dp.lanes, ret); + return ret; + } +- ret = phy_power_on(phy); +- if (ret) { +- DRM_ERROR("Unable to power on phy. ret=%d\n", ret); +- return ret; ++ if (!ctrl->phy_powered_on) { ++ ret = phy_power_on(phy); ++ if (ret) { ++ DRM_ERROR("Unable to power on phy. ret=%d\n", ret); ++ return ret; ++ } ++ ctrl->phy_powered_on = true; + } + + dev_pm_opp_set_rate(ctrl->dev, ctrl->link->link_params.rate * 1000); +@@ -2372,7 +2404,7 @@ static int msm_dp_ctrl_enable_mainlink_clocks(struct msm_dp_ctrl_private *ctrl, + return 0; + + err_phy: +- phy_power_off(phy); ++ msm_dp_ctrl_phy_power_off(ctrl); + return ret; + } + +@@ -2519,12 +2551,13 @@ void msm_dp_ctrl_phy_exit(struct msm_dp_ctrl *msm_dp_ctrl) + static int msm_dp_ctrl_reinitialize_mainlink(struct msm_dp_ctrl_private *ctrl, + struct msm_dp_panel *panel) + { +- struct phy *phy = ctrl->phy; + int ret = 0; + + msm_dp_ctrl_mainlink_disable(ctrl); + ctrl->phy_opts.dp.lanes = ctrl->link->link_params.num_lanes; +- phy_configure(phy, &ctrl->phy_opts); ++ ret = phy_configure(ctrl->phy, &ctrl->phy_opts); ++ if (ret) ++ return ret; + + /* + * Disable and re-enable the mainlink clock since the +@@ -2533,7 +2566,9 @@ static int msm_dp_ctrl_reinitialize_mainlink(struct msm_dp_ctrl_private *ctrl, + */ + msm_dp_ctrl_link_clk_disable(&ctrl->msm_dp_ctrl); + +- phy_power_off(phy); ++ ret = msm_dp_ctrl_phy_power_off(ctrl); ++ if (ret) ++ return ret; + /* hw recommended delay before re-enabling clocks */ + msleep(20); + +@@ -2550,6 +2585,7 @@ static int msm_dp_ctrl_deinitialize_mainlink(struct msm_dp_ctrl_private *ctrl, + struct msm_dp_panel *panel) + { + struct phy *phy; ++ int ret; + + phy = ctrl->phy; + +@@ -2563,7 +2599,9 @@ static int msm_dp_ctrl_deinitialize_mainlink(struct msm_dp_ctrl_private *ctrl, + + msm_dp_ctrl_link_clk_disable(&ctrl->msm_dp_ctrl); + +- phy_power_off(phy); ++ ret = msm_dp_ctrl_phy_power_off(ctrl); ++ if (ret) ++ return ret; + + /* aux channel down, reinit phy */ + phy_exit(phy); +@@ -3004,13 +3042,17 @@ int msm_dp_ctrl_on_link(struct msm_dp_ctrl *msm_dp_ctrl, + rc = msm_dp_ctrl_reinitialize_mainlink(ctrl, panel); + if (rc) { + DRM_ERROR("Failed to reinitialize mainlink. rc=%d\n", rc); +- break; ++ msm_dp_ctrl_deinitialize_mainlink(ctrl, panel); ++ return rc; + } + } + + if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) + return rc; + ++ if (!link_train_max_retries) ++ rc = -ETIMEDOUT; ++ + if (rc == 0) { /* link train successfully */ + /* + * do not stop train pattern here +@@ -3248,10 +3290,9 @@ void msm_dp_ctrl_off_link(struct msm_dp_ctrl *msm_dp_ctrl, + struct msm_dp_panel *panel) + { + struct msm_dp_ctrl_private *ctrl; +- struct phy *phy; ++ int ret; + + ctrl = container_of(msm_dp_ctrl, struct msm_dp_ctrl_private, msm_dp_ctrl); +- phy = ctrl->phy; + + msm_dp_panel_disable_vsc_sdp(panel); + +@@ -3273,7 +3314,9 @@ void msm_dp_ctrl_off_link(struct msm_dp_ctrl *msm_dp_ctrl, + + msm_dp_ctrl_link_clk_disable(&ctrl->msm_dp_ctrl); + +- phy_power_off(phy); ++ ret = msm_dp_ctrl_phy_power_off(ctrl); ++ if (ret) ++ DRM_ERROR("Failed to power off DP PHY. ret=%d\n", ret); + } + + irqreturn_t msm_dp_ctrl_isr(struct msm_dp_ctrl *msm_dp_ctrl, +diff --git a/drivers/gpu/drm/msm/dp/dp_debug.c b/drivers/gpu/drm/msm/dp/dp_debug.c +index 5d5ebcb7bc8e3d00c0831a4b50513bf531490af3..4206619623cd6223fbb16ee5f3cdb07165fa0e8a 100644 +--- a/drivers/gpu/drm/msm/dp/dp_debug.c ++++ b/drivers/gpu/drm/msm/dp/dp_debug.c +@@ -236,6 +236,7 @@ int msm_dp_debug_init(struct device *dev, struct msm_dp_panel *panel, + + debug->link = link; + debug->panel = panel; ++ debug->connector = connector; + + debugfs_create_file("dp_debug", 0444, root, + debug, &msm_dp_debug_fops); +diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c +index fc5b2cc90ceae2f4bc9f3ec1924093626764c044..b8679e471cb48a9d8f6c41aff3dd92853f70a690 100644 +--- a/drivers/gpu/drm/msm/dp/dp_display.c ++++ b/drivers/gpu/drm/msm/dp/dp_display.c +@@ -511,6 +511,8 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp) + { + struct platform_device *pdev = dp->msm_dp_display.pdev; + ++ guard(mutex)(&dp->plugged_lock); ++ + dp->panel->video_test = false; + + msm_dp_aux_enable_xfers(dp->aux, false); +@@ -519,7 +521,6 @@ static int msm_dp_hpd_unplug_handle(struct msm_dp_display_private *dp) + dp->msm_dp_display.connector_type, + dp->link->sink_count); + +- guard(mutex)(&dp->plugged_lock); + if (!dp->plugged) + return 0; + +@@ -561,6 +562,8 @@ static int msm_dp_irq_hpd_handle(struct msm_dp_display_private *dp) + u32 sink_request; + int rc = 0; + ++ guard(mutex)(&dp->plugged_lock); ++ + /* irq_hpd can happen at either connected or disconnected state */ + drm_dbg_dp(dp->drm_dev, "Before, type=%d, sink_count=%d\n", + dp->msm_dp_display.connector_type, +@@ -959,6 +962,7 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp) + struct msm_dp *msm_dp_display = &dp->msm_dp_display; + int rc = 0; + bool force_link_train = false; ++ bool phy_deinit = false; + + drm_dbg_dp(dp->drm_dev, "sink_count=%d\n", dp->link->sink_count); + +@@ -983,6 +987,7 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp) + rc = msm_dp_display_host_phy_init(dp); + if (rc < 0) + return rc; ++ phy_deinit = rc; + force_link_train = true; + } + +@@ -990,7 +995,7 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp) + if (rc) { + DRM_ERROR("Failed link training (rc=%d)\n", rc); + // TODO: schedule drm_connector_set_link_status_property() +- return rc; ++ goto error; + } + + /* Autonomous USB4 training above already completed receiver training and +@@ -999,7 +1004,16 @@ static int msm_dp_display_prepare_link(struct msm_dp_display_private *dp) + if (msm_dp_aux_usb4_attached(dp->aux)) + return 0; + +- return msm_dp_ctrl_prepare_stream_on(dp->ctrl, dp->panel, force_link_train); ++ rc = msm_dp_ctrl_prepare_stream_on(dp->ctrl, dp->panel, force_link_train); ++ if (!rc) ++ return 0; ++ ++error: ++ if (!msm_dp_display->power_on) ++ msm_dp_ctrl_off_link(dp->ctrl, dp->panel); ++ if (phy_deinit) ++ msm_dp_display_host_phy_exit(dp); ++ return rc; + } + + static int msm_dp_display_enable(struct msm_dp_display_private *dp, +@@ -2028,7 +2042,7 @@ void msm_dp_display_atomic_enable(struct msm_dp *msm_dp_display, + rc = msm_dp_display_enable(dp, dp->panel); + if (rc) { + DRM_ERROR("DP display enable failed, rc=%d\n", rc); +- return; ++ goto error; + } + + rc = msm_dp_display_post_enable(msm_dp_display); +@@ -2038,6 +2052,14 @@ void msm_dp_display_atomic_enable(struct msm_dp *msm_dp_display, + } + + drm_dbg_dp(msm_dp_display->drm_dev, "type=%d Done\n", msm_dp_display->connector_type); ++ return; ++ ++error: ++ if (!msm_dp_display->power_on) { ++ msm_dp_ctrl_off_pixel_clk(dp->ctrl); ++ msm_dp_ctrl_off_link(dp->ctrl, dp->panel); ++ msm_dp_display_host_phy_exit(dp); ++ } + } + + void msm_dp_display_atomic_disable(struct msm_dp *dp) +diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c +index 0c2c356362518808d2ca3d54d3b5ae58c2498f28..06cc829916f42095530e9d43c71db840bc0048bf 100644 +--- a/drivers/gpu/drm/msm/msm_gpu.c ++++ b/drivers/gpu/drm/msm/msm_gpu.c +@@ -790,16 +790,23 @@ void msm_gpu_retire(struct msm_gpu *gpu) + } + + /* add bo's to gpu's ring, and kick gpu: */ +-void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit) ++int msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit) + { + struct msm_ringbuffer *ring = submit->ring; + unsigned long flags; ++ int ret; + + WARN_ON(!mutex_is_locked(&gpu->lock)); + +- pm_runtime_get_sync(&gpu->pdev->dev); ++ ret = pm_runtime_resume_and_get(&gpu->pdev->dev); ++ if (ret < 0) ++ return ret; + +- msm_gpu_hw_init(gpu); ++ ret = msm_gpu_hw_init(gpu); ++ if (ret) { ++ pm_runtime_put(&gpu->pdev->dev); ++ return ret; ++ } + + submit->seqno = submit->hw_fence->seqno; + +@@ -827,6 +834,7 @@ void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit) + + pm_runtime_put(&gpu->pdev->dev); + hangcheck_timer_reset(gpu); ++ return 0; + } + + /* +diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h +index d27d54bdb7a71b1f821f01e267e30bdf305a6c66..5c44a16ec6a055324c67d385ba2f438727a730bb 100644 +--- a/drivers/gpu/drm/msm/msm_gpu.h ++++ b/drivers/gpu/drm/msm/msm_gpu.h +@@ -743,7 +743,7 @@ void msm_devfreq_idle(struct msm_gpu *gpu); + int msm_gpu_hw_init(struct msm_gpu *gpu); + + void msm_gpu_retire(struct msm_gpu *gpu); +-void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit); ++int msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit); + + int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev, + struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs, +diff --git a/drivers/gpu/drm/msm/msm_ringbuffer.c b/drivers/gpu/drm/msm/msm_ringbuffer.c +index 38e1e6866301e539ec6d9c15b2c0776d81516169..835126530a24730da7175fcdab37efcb37aebcb8 100644 +--- a/drivers/gpu/drm/msm/msm_ringbuffer.c ++++ b/drivers/gpu/drm/msm/msm_ringbuffer.c +@@ -18,7 +18,7 @@ static struct dma_fence *msm_job_run(struct drm_sched_job *job) + struct msm_gpu *gpu = submit->gpu; + struct drm_device *dev = gpu->dev; + unsigned nr_cmds = submit->nr_cmds; +- int i; ++ int i, ret; + + msm_fence_init(submit->hw_fence, fctx); + +@@ -40,12 +40,15 @@ static struct dma_fence *msm_job_run(struct drm_sched_job *job) + if (submit->queue->ctx->closed) + submit->nr_cmds = 0; + +- msm_gpu_submit(gpu, submit); ++ ret = msm_gpu_submit(gpu, submit); + + submit->nr_cmds = nr_cmds; + + mutex_unlock(&gpu->lock); + ++ if (ret) ++ return ERR_PTR(ret); ++ + return dma_fence_get(submit->hw_fence); + } + +diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig +index d7b89508311ffc6cbe1ccd302a6e84dfa83bf6fe..14eb7e802bc86a06b7ec0688580886880026cb0e 100644 +--- a/drivers/i2c/busses/Kconfig ++++ b/drivers/i2c/busses/Kconfig +@@ -1050,6 +1050,7 @@ config I2C_PXA_SLAVE + config I2C_QCOM_CCI + tristate "Qualcomm Camera Control Interface" + depends on ARCH_QCOM || COMPILE_TEST ++ select PM_OPP + help + If you say yes to this option, support will be included for the + built-in camera control interface on the Qualcomm SoCs. +diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c +index a21fd931375daa03238c970366f7d0a49e1e85fb..4ccd15175915d346cd6330d1bd1f7f6bf6b2793f 100644 +--- a/drivers/i2c/busses/i2c-qcom-cci.c ++++ b/drivers/i2c/busses/i2c-qcom-cci.c +@@ -11,6 +11,7 @@ + #include + #include + #include ++#include + + #define CCI_HW_VERSION 0x0 + #define CCI_RESET_CMD 0x004 +@@ -82,6 +83,13 @@ enum { + I2C_MODE_STANDARD, + I2C_MODE_FAST, + I2C_MODE_FAST_PLUS, ++ NUM_I2C_MODES, ++}; ++ ++enum { ++ CCI_CLK_RATE_19_2MHZ, ++ CCI_CLK_RATE_37_5MHZ, ++ NUM_CCI_CLK_RATES, + }; + + enum cci_i2c_queue_t { +@@ -117,7 +125,8 @@ struct cci_data { + unsigned int num_masters; + struct i2c_adapter_quirks quirks; + u16 queue_size[NUM_QUEUES]; +- struct hw_params params[3]; ++ /* Highest I2C mode supported by this variant. */ ++ u8 max_mode; + }; + + struct cci { +@@ -127,6 +136,7 @@ struct cci { + const struct cci_data *data; + struct clk_bulk_data *clocks; + int nclocks; ++ struct clk *cci_clk; + struct cci_master master[NUM_MASTERS]; + }; + +@@ -225,7 +235,97 @@ static int cci_halt(struct cci *cci, u8 master_num) + return 0; + } + +-static void cci_init(struct cci *cci) ++static const unsigned long cci_clk_rates[NUM_CCI_CLK_RATES] = { ++ [CCI_CLK_RATE_19_2MHZ] = 19200000, ++ [CCI_CLK_RATE_37_5MHZ] = 37500000, ++}; ++ ++static int cci_clk_rate_idx(unsigned long rate) ++{ ++ int i; ++ ++ for (i = 0; i < NUM_CCI_CLK_RATES; i++) ++ if (cci_clk_rates[i] == rate) ++ return i; ++ ++ return -EINVAL; ++} ++ ++static const struct hw_params cci_hw_params[NUM_CCI_CLK_RATES][NUM_I2C_MODES] = { ++ [CCI_CLK_RATE_19_2MHZ][I2C_MODE_STANDARD] = { ++ .thigh = 78, ++ .tlow = 114, ++ .tsu_sto = 28, ++ .tsu_sta = 28, ++ .thd_dat = 10, ++ .thd_sta = 77, ++ .tbuf = 118, ++ .scl_stretch_en = 0, ++ .trdhld = 6, ++ .tsp = 1 ++ }, ++ [CCI_CLK_RATE_19_2MHZ][I2C_MODE_FAST] = { ++ .thigh = 20, ++ .tlow = 28, ++ .tsu_sto = 21, ++ .tsu_sta = 21, ++ .thd_dat = 13, ++ .thd_sta = 18, ++ .tbuf = 32, ++ .scl_stretch_en = 0, ++ .trdhld = 6, ++ .tsp = 3 ++ }, ++ [CCI_CLK_RATE_37_5MHZ][I2C_MODE_STANDARD] = { ++ .thigh = 201, ++ .tlow = 174, ++ .tsu_sto = 204, ++ .tsu_sta = 231, ++ .thd_dat = 22, ++ .thd_sta = 162, ++ .tbuf = 227, ++ .scl_stretch_en = 0, ++ .trdhld = 6, ++ .tsp = 3 ++ }, ++ [CCI_CLK_RATE_37_5MHZ][I2C_MODE_FAST] = { ++ .thigh = 38, ++ .tlow = 56, ++ .tsu_sto = 40, ++ .tsu_sta = 40, ++ .thd_dat = 22, ++ .thd_sta = 35, ++ .tbuf = 62, ++ .scl_stretch_en = 0, ++ .trdhld = 6, ++ .tsp = 3 ++ }, ++ [CCI_CLK_RATE_37_5MHZ][I2C_MODE_FAST_PLUS] = { ++ .thigh = 16, ++ .tlow = 22, ++ .tsu_sto = 17, ++ .tsu_sta = 18, ++ .thd_dat = 16, ++ .thd_sta = 15, ++ .tbuf = 24, ++ .scl_stretch_en = 0, ++ .trdhld = 3, ++ .tsp = 3 ++ }, ++}; ++ ++static const struct hw_params *cci_get_hw_params(struct cci *cci, int mode) ++{ ++ unsigned long rate = clk_get_rate(cci->cci_clk); ++ int ri = cci_clk_rate_idx(rate); ++ ++ if (ri >= 0 && mode <= cci->data->max_mode) ++ return &cci_hw_params[ri][mode]; ++ ++ return NULL; ++} ++ ++static int cci_init(struct cci *cci) + { + u32 val = CCI_IRQ_MASK_0_I2C_M0_RD_DONE | + CCI_IRQ_MASK_0_I2C_M0_Q0_REPORT | +@@ -249,7 +349,12 @@ static void cci_init(struct cci *cci) + if (!cci->master[i].cci) + continue; + +- hw = &cci->data->params[mode]; ++ hw = cci_get_hw_params(cci, mode); ++ if (!hw) { ++ dev_err(cci->dev, "no timing for mode %d at CCI clock %lu Hz\n", ++ mode, clk_get_rate(cci->cci_clk)); ++ return -EOPNOTSUPP; ++ } + + val = hw->thigh << 16 | hw->tlow; + writel(val, cci->base + CCI_I2C_Mm_SCL_CTL(i)); +@@ -266,6 +371,8 @@ static void cci_init(struct cci *cci) + val = hw->scl_stretch_en << 8 | hw->trdhld << 4 | hw->tsp; + writel(val, cci->base + CCI_I2C_Mm_MISC_CTL(i)); + } ++ ++ return 0; + } + + static int cci_reset(struct cci *cci) +@@ -283,9 +390,7 @@ static int cci_reset(struct cci *cci) + return -ETIMEDOUT; + } + +- cci_init(cci); +- +- return 0; ++ return cci_init(cci); + } + + static int cci_run_queue(struct cci *cci, u8 master, u8 queue) +@@ -471,6 +576,66 @@ static void cci_disable_clocks(struct cci *cci) + clk_bulk_disable_unprepare(cci->nclocks, cci->clocks); + } + ++/* ++ * The single CCI clock is shared by all masters, which may run in different ++ * modes. Pick the lowest rate that has a valid timing set for every active ++ * master's mode. ++ */ ++static int cci_get_required_rate(struct cci *cci, unsigned long *rate) ++{ ++ for (int ri = 0; ri < NUM_CCI_CLK_RATES; ri++) { ++ bool supported = true; ++ ++ for (int i = 0; i < cci->data->num_masters; i++) { ++ int mode = cci->master[i].mode; ++ ++ if (!cci->master[i].cci) ++ continue; ++ ++ if (mode > cci->data->max_mode || ++ !cci_hw_params[ri][mode].thigh) { ++ supported = false; ++ break; ++ } ++ } ++ ++ if (supported) { ++ *rate = cci_clk_rates[ri]; ++ return 0; ++ } ++ } ++ ++ return -EOPNOTSUPP; ++} ++ ++static int cci_set_core_rate(struct cci *cci) ++{ ++ struct device *dev = cci->dev; ++ unsigned long rate; ++ int ret; ++ ++ ret = cci_get_required_rate(cci, &rate); ++ if (ret) { ++ dev_err(dev, "no CCI clock rate satisfies all masters\n"); ++ return ret; ++ } ++ ++ ret = dev_pm_opp_set_rate(dev, rate); ++ if (ret) { ++ dev_err(dev, "CCI clock could not be set to %lu Hz\n", rate); ++ return ret; ++ } ++ ++ /* ++ * Sanity: The hw_params timings are only valid at the exact ++ * expected rate, verify what landed on the hardware. ++ */ ++ if (clk_get_rate(cci->cci_clk) != rate) ++ dev_warn(dev, "CCI clock is not at expected %lu Hz\n", rate); ++ ++ return 0; ++} ++ + static int __maybe_unused cci_suspend_runtime(struct device *dev) + { + struct cci *cci = dev_get_drvdata(dev); +@@ -495,8 +660,9 @@ static int __maybe_unused cci_resume_runtime(struct device *dev) + * the controller, with the interrupt mask set first so that the + * reset-done interrupt also arrives after a power collapse. + */ +- cci_init(cci); +- ret = cci_reset(cci); ++ ret = cci_init(cci); ++ if (!ret) ++ ret = cci_reset(cci); + if (ret) + cci_disable_clocks(cci); + +@@ -588,6 +754,24 @@ static int cci_probe(struct platform_device *pdev) + return dev_err_probe(dev, -EINVAL, "not enough clocks in DT\n"); + cci->nclocks = ret; + ++ cci->cci_clk = devm_clk_get(dev, "cci"); ++ if (IS_ERR(cci->cci_clk)) ++ return dev_err_probe(dev, PTR_ERR(cci->cci_clk), ++ "failed to get CCI clock\n"); ++ ++ ret = devm_pm_opp_set_clkname(dev, "cci"); ++ if (ret) ++ return dev_err_probe(dev, ret, "failed to set CCI OPP clk\n"); ++ ++ /* OPP table is optional */ ++ ret = devm_pm_opp_of_add_table(dev); ++ if (ret && ret != -ENODEV) ++ return dev_err_probe(dev, ret, "failed to add OPP table\n"); ++ ++ ret = cci_set_core_rate(cci); ++ if (ret) ++ return ret; ++ + ret = cci_enable_clocks(cci); + if (ret < 0) + return ret; +@@ -662,30 +846,7 @@ static const struct cci_data cci_v1_data = { + .max_write_len = 10, + .max_read_len = 12, + }, +- .params[I2C_MODE_STANDARD] = { +- .thigh = 78, +- .tlow = 114, +- .tsu_sto = 28, +- .tsu_sta = 28, +- .thd_dat = 10, +- .thd_sta = 77, +- .tbuf = 118, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 1 +- }, +- .params[I2C_MODE_FAST] = { +- .thigh = 20, +- .tlow = 28, +- .tsu_sto = 21, +- .tsu_sta = 21, +- .thd_dat = 13, +- .thd_sta = 18, +- .tbuf = 32, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 3 +- }, ++ .max_mode = I2C_MODE_FAST, + }; + + static const struct cci_data cci_v1_5_data = { +@@ -695,30 +856,7 @@ static const struct cci_data cci_v1_5_data = { + .max_write_len = 10, + .max_read_len = 12, + }, +- .params[I2C_MODE_STANDARD] = { +- .thigh = 78, +- .tlow = 114, +- .tsu_sto = 28, +- .tsu_sta = 28, +- .thd_dat = 10, +- .thd_sta = 77, +- .tbuf = 118, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 1 +- }, +- .params[I2C_MODE_FAST] = { +- .thigh = 20, +- .tlow = 28, +- .tsu_sto = 21, +- .tsu_sta = 21, +- .thd_dat = 13, +- .thd_sta = 18, +- .tbuf = 32, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 3 +- }, ++ .max_mode = I2C_MODE_FAST, + }; + + static const struct cci_data cci_v2_data = { +@@ -728,92 +866,12 @@ static const struct cci_data cci_v2_data = { + .max_write_len = 11, + .max_read_len = 12, + }, +- .params[I2C_MODE_STANDARD] = { +- .thigh = 201, +- .tlow = 174, +- .tsu_sto = 204, +- .tsu_sta = 231, +- .thd_dat = 22, +- .thd_sta = 162, +- .tbuf = 227, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 3 +- }, +- .params[I2C_MODE_FAST] = { +- .thigh = 38, +- .tlow = 56, +- .tsu_sto = 40, +- .tsu_sta = 40, +- .thd_dat = 22, +- .thd_sta = 35, +- .tbuf = 62, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 3 +- }, +- .params[I2C_MODE_FAST_PLUS] = { +- .thigh = 16, +- .tlow = 22, +- .tsu_sto = 17, +- .tsu_sta = 18, +- .thd_dat = 16, +- .thd_sta = 15, +- .tbuf = 24, +- .scl_stretch_en = 0, +- .trdhld = 3, +- .tsp = 3 +- }, +-}; +- +-static const struct cci_data cci_msm8953_data = { +- .num_masters = 2, +- .queue_size = { 64, 16 }, +- .quirks = { +- .max_write_len = 11, +- .max_read_len = 12, +- }, +- .params[I2C_MODE_STANDARD] = { +- .thigh = 78, +- .tlow = 114, +- .tsu_sto = 28, +- .tsu_sta = 28, +- .thd_dat = 10, +- .thd_sta = 77, +- .tbuf = 118, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 1 +- }, +- .params[I2C_MODE_FAST] = { +- .thigh = 20, +- .tlow = 28, +- .tsu_sto = 21, +- .tsu_sta = 21, +- .thd_dat = 13, +- .thd_sta = 18, +- .tbuf = 32, +- .scl_stretch_en = 0, +- .trdhld = 6, +- .tsp = 3 +- }, +- .params[I2C_MODE_FAST_PLUS] = { +- .thigh = 16, +- .tlow = 22, +- .tsu_sto = 17, +- .tsu_sta = 18, +- .thd_dat = 16, +- .thd_sta = 15, +- .tbuf = 19, +- .scl_stretch_en = 1, +- .trdhld = 3, +- .tsp = 3 +- }, ++ .max_mode = I2C_MODE_FAST_PLUS, + }; + + static const struct of_device_id cci_dt_match[] = { + { .compatible = "qcom,msm8226-cci", .data = &cci_v1_data}, +- { .compatible = "qcom,msm8953-cci", .data = &cci_msm8953_data}, ++ { .compatible = "qcom,msm8953-cci", .data = &cci_v2_data}, + { .compatible = "qcom,msm8974-cci", .data = &cci_v1_5_data}, + { .compatible = "qcom,msm8996-cci", .data = &cci_v2_data}, + +diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c +index c4c6202ff15a8c546c4aae28b31765a3546b7c76..864f0d9c5f4e684b0b4212bf880153f42880aca7 100644 +--- a/drivers/i2c/busses/i2c-qcom-geni.c ++++ b/drivers/i2c/busses/i2c-qcom-geni.c +@@ -346,7 +346,7 @@ static irqreturn_t geni_i2c_irq(int irq, void *dev) + if (!cur || + m_stat & (M_CMD_FAILURE_EN | M_CMD_ABORT_EN) || + dm_rx_st & (DM_I2C_CB_ERR)) { +- if (m_stat & M_GP_IRQ_1_EN) ++ if (cur && m_stat & M_GP_IRQ_1_EN) + geni_i2c_check_addr_data_nack(gi2c); + if (m_stat & M_GP_IRQ_3_EN) + geni_i2c_err(gi2c, BUS_PROTO); +@@ -635,16 +635,14 @@ static void geni_i2c_gpi_unmap(struct geni_i2c_dev *gi2c, struct i2c_msg *msg, + * geni_i2c_gpi_multi_desc_unmap() - Unmaps DMA buffers post multi message TX transfers + * @gi2c: I2C dev handle + * @msgs: Array of I2C messages +- * @peripheral: Pointer to gpi_i2c_config ++ * @msg_xfer_cnt: Completed transfers, or submitted transfers after DMA termination + */ + static void geni_i2c_gpi_multi_desc_unmap(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], +- struct gpi_i2c_config *peripheral) ++ u32 msg_xfer_cnt) + { +- u32 msg_xfer_cnt, wr_idx = 0; ++ u32 wr_idx = 0; + struct geni_i2c_gpi_multi_desc_xfer *tx_multi_xfer = &gi2c->i2c_multi_desc_config; + +- msg_xfer_cnt = gi2c->err ? tx_multi_xfer->msg_idx_cnt : tx_multi_xfer->irq_cnt; +- + /* Unmap the processed DMA buffers based on the received interrupt count */ + for (; tx_multi_xfer->unmap_msg_cnt < msg_xfer_cnt; tx_multi_xfer->unmap_msg_cnt++) { + wr_idx = tx_multi_xfer->unmap_msg_cnt; +@@ -652,12 +650,6 @@ static void geni_i2c_gpi_multi_desc_unmap(struct geni_i2c_dev *gi2c, struct i2c_ + tx_multi_xfer->dma_buf[wr_idx], + tx_multi_xfer->dma_addr[wr_idx], + NULL, 0); +- +- if (tx_multi_xfer->unmap_msg_cnt == gi2c->num_msgs - 1) { +- kfree(tx_multi_xfer->dma_buf); +- kfree(tx_multi_xfer->dma_addr); +- break; +- } + } + } + +@@ -665,7 +657,7 @@ static void geni_i2c_gpi_multi_desc_unmap(struct geni_i2c_dev *gi2c, struct i2c_ + * geni_i2c_gpi_multi_xfer_timeout_handler() - Handles multi message transfer timeout + * @dev: Pointer to the corresponding dev node + * @multi_xfer: Pointer to the geni_i2c_gpi_multi_desc_xfer +- * @transfer_timeout_msecs: Timeout value in milliseconds ++ * @transfer_timeout: Timeout value in jiffies + * @transfer_comp: Completion object of the transfer + * + * This function waits for the completion of each processed transfer messages +@@ -675,22 +667,16 @@ static void geni_i2c_gpi_multi_desc_unmap(struct geni_i2c_dev *gi2c, struct i2c_ + */ + static int geni_i2c_gpi_multi_xfer_timeout_handler(struct device *dev, + struct geni_i2c_gpi_multi_desc_xfer *multi_xfer, +- u32 transfer_timeout_msecs, ++ unsigned long transfer_timeout, + struct completion *transfer_comp) + { +- int i; +- u32 time_left; +- +- for (i = 0; i < multi_xfer->msg_idx_cnt - 1; i++) { +- reinit_completion(transfer_comp); ++ unsigned long time_left; + +- if (multi_xfer->msg_idx_cnt != multi_xfer->irq_cnt) { +- time_left = wait_for_completion_timeout(transfer_comp, +- transfer_timeout_msecs); +- if (!time_left) { +- dev_err(dev, "%s: Transfer timeout\n", __func__); +- return -ETIMEDOUT; +- } ++ while (READ_ONCE(multi_xfer->irq_cnt) < multi_xfer->msg_idx_cnt) { ++ time_left = wait_for_completion_timeout(transfer_comp, transfer_timeout); ++ if (!time_left) { ++ dev_err(dev, "%s: Transfer timeout\n", __func__); ++ return -ETIMEDOUT; + } + } + return 0; +@@ -792,9 +778,6 @@ static int geni_i2c_gpi(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], + desc->callback_result = i2c_gpi_cb_result; + desc->callback_param = gi2c; + +- if (!((msgs[msg_idx].flags & I2C_M_RD) && op == I2C_WRITE)) +- gi2c_gpi_xfer->msg_idx_cnt++; +- + cookie = dmaengine_submit(desc); + if (dma_submit_error(cookie)) { + dev_err(gi2c->se.dev, +@@ -803,6 +786,9 @@ static int geni_i2c_gpi(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], + goto err_config; + } + ++ if (!((msgs[msg_idx].flags & I2C_M_RD) && op == I2C_WRITE)) ++ gi2c_gpi_xfer->msg_idx_cnt++; ++ + if (gi2c->is_tx_multi_desc_xfer) { + gi2c_gpi_xfer->dma_buf[msg_idx] = dma_buf; + gi2c_gpi_xfer->dma_addr[msg_idx] = addr; +@@ -897,14 +883,21 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i + tx_multi_xfer->dma_addr = kzalloc_objs(dma_addr_t, num); + if (!tx_multi_xfer->dma_buf || !tx_multi_xfer->dma_addr) { + ret = -ENOMEM; +- goto err; ++ goto out_free; + } + } + ++ gi2c->err = 0; ++ reinit_completion(&gi2c->done); + for (i = 0; i < num; i++) { ++ tx_buf = NULL; ++ rx_buf = NULL; ++ tx_addr = 0; ++ rx_addr = 0; + gi2c->cur = &msgs[i]; + gi2c->err = 0; +- reinit_completion(&gi2c->done); ++ if (!gi2c->is_tx_multi_desc_xfer) ++ reinit_completion(&gi2c->done); + dev_dbg(gi2c->se.dev, "msg[%d].len:%d\n", i, gi2c->cur->len); + + peripheral.stretch = 0; +@@ -946,20 +939,26 @@ static int geni_i2c_gpi_xfer(struct geni_i2c_dev *gi2c, struct i2c_msg msgs[], i + if (!gi2c->is_tx_multi_desc_xfer) + geni_i2c_gpi_unmap(gi2c, &msgs[i], tx_buf, tx_addr, rx_buf, rx_addr); + else if (tx_multi_xfer->unmap_msg_cnt != tx_multi_xfer->irq_cnt) +- geni_i2c_gpi_multi_desc_unmap(gi2c, msgs, &peripheral); ++ geni_i2c_gpi_multi_desc_unmap(gi2c, msgs, ++ READ_ONCE(tx_multi_xfer->irq_cnt)); + } + +- return num; ++ ret = num; ++ goto out_free; + + err: + dev_err(gi2c->se.dev, "GPI transfer failed: %d\n", ret); + dmaengine_terminate_sync(gi2c->rx_c); + dmaengine_terminate_sync(gi2c->tx_c); + if (gi2c->is_tx_multi_desc_xfer) +- geni_i2c_gpi_multi_desc_unmap(gi2c, msgs, &peripheral); ++ geni_i2c_gpi_multi_desc_unmap(gi2c, msgs, tx_multi_xfer->msg_idx_cnt); + else + geni_i2c_gpi_unmap(gi2c, &msgs[i], tx_buf, tx_addr, rx_buf, rx_addr); + ++out_free: ++ kfree(tx_multi_xfer->dma_buf); ++ kfree(tx_multi_xfer->dma_addr); ++ + return ret; + } + +diff --git a/drivers/interconnect/qcom/icc-rpmh.c b/drivers/interconnect/qcom/icc-rpmh.c +index 3b445acefece7f1b3620ad921617694d2105e37f..b1346cdb349cf2d00459c3c78addb25478c533b2 100644 +--- a/drivers/interconnect/qcom/icc-rpmh.c ++++ b/drivers/interconnect/qcom/icc-rpmh.c +@@ -130,9 +130,7 @@ int qcom_icc_set(struct icc_node *src, struct icc_node *dst) + + qp = to_qcom_provider(node->provider); + +- qcom_icc_bcm_voter_commit(qp->voter); +- +- return 0; ++ return qcom_icc_bcm_voter_commit(qp->voter); + } + EXPORT_SYMBOL_GPL(qcom_icc_set); + +diff --git a/drivers/media/i2c/ov02c10.c b/drivers/media/i2c/ov02c10.c +index cf93d36032e14712209d50f4a8e223541c666e79..b36da75d7dfa258316b2197219ac9e67be859557 100644 +--- a/drivers/media/i2c/ov02c10.c ++++ b/drivers/media/i2c/ov02c10.c +@@ -18,8 +18,8 @@ + #define OV02C10_MCLK 19200000 + #define OV02C10_RGB_DEPTH 10 + +-#define OV02C10_REG_CHIP_ID CCI_REG16(0x300a) +-#define OV02C10_CHIP_ID 0x5602 ++#define OV02C10_REG_CHIP_ID CCI_REG24(0x300a) ++#define OV02C10_CHIP_ID 0x560243 + + #define OV02C10_REG_STREAM_CONTROL CCI_REG8(0x0100) + +diff --git a/drivers/media/platform/qcom/camss/Kconfig b/drivers/media/platform/qcom/camss/Kconfig +index 4eda48cb1adf049a7fb6cb59b9da3c0870fe57f4..b51745c942c9fd71a95d09993213bde4b7e877e2 100644 +--- a/drivers/media/platform/qcom/camss/Kconfig ++++ b/drivers/media/platform/qcom/camss/Kconfig +@@ -7,3 +7,5 @@ config VIDEO_QCOM_CAMSS + select VIDEO_V4L2_SUBDEV_API + select VIDEOBUF2_DMA_SG + select V4L2_FWNODE ++ select GENERIC_PHY ++ imply PHY_QCOM_MIPI_CSI2 +diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c +index 539ac4888b608b3cc789728365e7e8a39fc54e78..aaed7d0309dd67b78bcca638aba52e5605ce1db4 100644 +--- a/drivers/media/platform/qcom/camss/camss-csiphy.c ++++ b/drivers/media/platform/qcom/camss/camss-csiphy.c +@@ -13,6 +13,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include +@@ -131,10 +133,10 @@ static u8 csiphy_get_bpp(const struct csiphy_format_info *formats, + } + + /* +- * csiphy_set_clock_rates - Calculate and set clock rates on CSIPHY module ++ * csiphy_set_clock_rates_legacy - Calculate and set clock rates on CSIPHY module + * @csiphy: CSIPHY device + */ +-static int csiphy_set_clock_rates(struct csiphy_device *csiphy) ++static int csiphy_set_clock_rates_legacy(struct csiphy_device *csiphy) + { + struct device *dev = csiphy->camss->dev; + s64 link_freq; +@@ -200,7 +202,7 @@ static int csiphy_set_clock_rates(struct csiphy_device *csiphy) + * + * Return 0 on success or a negative error code otherwise + */ +-static int csiphy_set_power(struct v4l2_subdev *sd, int on) ++static int csiphy_set_power_legacy(struct v4l2_subdev *sd, int on) + { + struct csiphy_device *csiphy = v4l2_get_subdevdata(sd); + struct device *dev = csiphy->camss->dev; +@@ -219,7 +221,7 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on) + return ret; + } + +- ret = csiphy_set_clock_rates(csiphy); ++ ret = csiphy_set_clock_rates_legacy(csiphy); + if (ret < 0) { + regulator_bulk_disable(csiphy->num_supplies, + csiphy->supplies); +@@ -254,7 +256,7 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on) + } + + /* +- * csiphy_stream_on - Enable streaming on CSIPHY module ++ * csiphy_stream_on_legacy - Enable streaming on CSIPHY module + * @csiphy: CSIPHY device + * + * Helper function to enable streaming on CSIPHY module. +@@ -262,7 +264,7 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on) + * + * Return 0 on success or a negative error code otherwise + */ +-static int csiphy_stream_on(struct csiphy_device *csiphy) ++static int csiphy_stream_on_legacy(struct csiphy_device *csiphy) + { + struct csiphy_config *cfg = &csiphy->cfg; + s64 link_freq; +@@ -306,11 +308,98 @@ static int csiphy_stream_on(struct csiphy_device *csiphy) + * + * Helper function to disable streaming on CSIPHY module + */ +-static void csiphy_stream_off(struct csiphy_device *csiphy) ++static void csiphy_stream_off_legacy(struct csiphy_device *csiphy) + { + csiphy->res->hw_ops->lanes_disable(csiphy, &csiphy->cfg); + } + ++/* ++ * csiphy_stream_on - Enable streaming on CSIPHY module ++ * @csiphy: CSIPHY device ++ * ++ * Helper function to enable streaming on CSIPHY module. ++ * Main configuration of CSIPHY module is also done here. ++ * ++ * Return 0 on success or a negative error code otherwise ++ */ ++static int csiphy_stream_on(struct csiphy_device *csiphy) ++{ ++ u8 bpp = csiphy_get_bpp(csiphy->res->formats->formats, csiphy->res->formats->nformats, ++ csiphy->fmt[MSM_CSIPHY_PAD_SINK].code); ++ struct csiphy_lanes_cfg *lncfg = &csiphy->cfg.csi2->lane_cfg; ++ struct phy_configure_opts_mipi_dphy *dphy_cfg; ++ union phy_configure_opts dphy_opts = { 0 }; ++ struct device *dev = csiphy->camss->dev; ++ u8 num_lanes = lncfg->num_data; ++ s64 link_freq; ++ int ret; ++ ++ dphy_cfg = &dphy_opts.mipi_dphy; ++ ++ link_freq = camss_get_link_freq(&csiphy->subdev.entity, bpp, num_lanes); ++ ++ if (link_freq <= 0) { ++ dev_err(dev, ++ "Cannot get CSI2 transmitter's link frequency\n"); ++ return -EINVAL; ++ } ++ ++ ret = phy_mipi_dphy_get_default_config_for_hsclk(link_freq, num_lanes, ++ dphy_cfg); ++ if (ret < 0) { ++ dev_err(dev, "Invalid config for link frequency %lld\n", ++ link_freq); ++ return ret; ++ } ++ ++ ret = phy_set_mode(csiphy->phy, PHY_MODE_MIPI_DPHY); ++ if (ret) { ++ dev_err(dev, "Failed to set phy mode\n"); ++ return ret; ++ } ++ ++ ret = phy_configure(csiphy->phy, &dphy_opts); ++ if (ret) { ++ dev_err(dev, "failed to configure MIPI D-PHY\n"); ++ goto error; ++ } ++ ++ return phy_power_on(csiphy->phy); ++ ++error: ++ return ret; ++} ++ ++/* ++ * csiphy_stream_off - Disable streaming on CSIPHY module ++ * @csiphy: CSIPHY device ++ * ++ * Helper function to disable streaming on CSIPHY module ++ */ ++static void csiphy_stream_off(struct csiphy_device *csiphy) ++{ ++ phy_power_off(csiphy->phy); ++} ++ ++/* ++ * csiphy_set_stream - Enable/disable streaming on CSIPHY module ++ * @sd: CSIPHY V4L2 subdevice ++ * @enable: Requested streaming state ++ * ++ * Return 0 on success or a negative error code otherwise ++ */ ++static int csiphy_set_stream_legacy(struct v4l2_subdev *sd, int enable) ++{ ++ struct csiphy_device *csiphy = v4l2_get_subdevdata(sd); ++ int ret = 0; ++ ++ if (enable) ++ ret = csiphy_stream_on_legacy(csiphy); ++ else ++ csiphy_stream_off_legacy(csiphy); ++ ++ return ret; ++} + + /* + * csiphy_set_stream - Enable/disable streaming on CSIPHY module +@@ -572,16 +661,16 @@ csiphy_match_clock_name(const char *clock_name, const char *format, ...) + } + + /* +- * msm_csiphy_subdev_init - Initialize CSIPHY device structure and resources ++ * msm_csiphy_subdev_init_legacy - Initialize CSIPHY device structure and resources + * @csiphy: CSIPHY device + * @res: CSIPHY module resources table + * @id: CSIPHY module id + * + * Return 0 on success or a negative error code otherwise + */ +-int msm_csiphy_subdev_init(struct camss *camss, +- struct csiphy_device *csiphy, +- const struct camss_subdev_resources *res, u8 id) ++int msm_csiphy_subdev_init_legacy(struct camss *camss, ++ struct csiphy_device *csiphy, ++ const struct camss_subdev_resources *res, u8 id) + { + struct device *dev = camss->dev; + struct platform_device *pdev = to_platform_device(dev); +@@ -709,6 +798,54 @@ int msm_csiphy_subdev_init(struct camss *camss, + return ret; + } + ++/* ++ * msm_csiphy_subdev_init - Initialize CSIPHY device structure and resources ++ * @camss: CAMSS structure ++ * @port: DT port index ++ * ++ * Return 0 on success or absence of link, negative error code otherwise ++ */ ++int msm_csiphy_subdev_init(struct camss *camss, u8 port) ++{ ++ const struct camss_subdev_resources *res = &camss->res->csiphy_res[port]; ++ struct csiphy_device *csiphy = &camss->csiphy[port]; ++ struct device *dev = camss->dev; ++ struct device_node *ep, *remote; ++ int ret; ++ ++ ep = of_graph_get_endpoint_by_regs(dev->of_node, port, -1); ++ if (!ep) ++ return 0; ++ ++ remote = of_graph_get_remote_port_parent(ep); ++ of_node_put(ep); ++ if (!remote) ++ return 0; ++ ++ if (!of_device_is_available(remote)) { ++ of_node_put(remote); ++ return 0; ++ } ++ ++ csiphy->phy = devm_phy_get_by_of_node(dev, remote); ++ of_node_put(remote); ++ if (IS_ERR(csiphy->phy)) { ++ ret = PTR_ERR(csiphy->phy); ++ goto done; ++ } ++ ++ csiphy->camss = camss; ++ csiphy->id = res->csiphy.id; ++ csiphy->res = &res->csiphy; ++ ++ snprintf(csiphy->name, ARRAY_SIZE(csiphy->name), "csi%d", csiphy->id); ++ ++ return 0; ++ ++done: ++ return ret; ++} ++ + /* + * csiphy_link_setup - Setup CSIPHY connections + * @entity: Pointer to media entity structure +@@ -743,8 +880,12 @@ static int csiphy_link_setup(struct media_entity *entity, + return 0; + } + +-static const struct v4l2_subdev_core_ops csiphy_core_ops = { +- .s_power = csiphy_set_power, ++static const struct v4l2_subdev_core_ops csiphy_core_ops_legacy = { ++ .s_power = csiphy_set_power_legacy, ++}; ++ ++static const struct v4l2_subdev_video_ops csiphy_video_ops_legacy = { ++ .s_stream = csiphy_set_stream_legacy, + }; + + static const struct v4l2_subdev_video_ops csiphy_video_ops = { +@@ -758,8 +899,13 @@ static const struct v4l2_subdev_pad_ops csiphy_pad_ops = { + .set_fmt = csiphy_set_format, + }; + ++static const struct v4l2_subdev_ops csiphy_v4l2_ops_legacy = { ++ .core = &csiphy_core_ops_legacy, ++ .video = &csiphy_video_ops_legacy, ++ .pad = &csiphy_pad_ops, ++}; ++ + static const struct v4l2_subdev_ops csiphy_v4l2_ops = { +- .core = &csiphy_core_ops, + .video = &csiphy_video_ops, + .pad = &csiphy_pad_ops, + }; +@@ -785,10 +931,15 @@ int msm_csiphy_register_entity(struct csiphy_device *csiphy, + { + struct v4l2_subdev *sd = &csiphy->subdev; + struct media_pad *pads = csiphy->pads; +- struct device *dev = csiphy->camss->dev; ++ struct camss *camss = csiphy->camss; ++ struct device *dev = camss->dev; + int ret; + +- v4l2_subdev_init(sd, &csiphy_v4l2_ops); ++ if (camss->legacy_phy) ++ v4l2_subdev_init(sd, &csiphy_v4l2_ops_legacy); ++ else ++ v4l2_subdev_init(sd, &csiphy_v4l2_ops); ++ + sd->internal_ops = &csiphy_v4l2_internal_ops; + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + snprintf(sd->name, ARRAY_SIZE(sd->name), "%s%d", +@@ -816,9 +967,22 @@ int msm_csiphy_register_entity(struct csiphy_device *csiphy, + ret = v4l2_device_register_subdev(v4l2_dev, sd); + if (ret < 0) { + dev_err(dev, "Failed to register subdev: %d\n", ret); +- media_entity_cleanup(&sd->entity); ++ goto media_entity_err; ++ } ++ ++ if (!IS_ERR(csiphy->phy)) { ++ ret = phy_init(csiphy->phy); ++ if (ret) { ++ dev_err(dev, "%s init fail %d\n", csiphy->name, ret); ++ v4l2_device_unregister_subdev(sd); ++ goto media_entity_err; ++ } + } + ++ return 0; ++ ++media_entity_err: ++ media_entity_cleanup(&sd->entity); + return ret; + } + +@@ -828,6 +992,8 @@ int msm_csiphy_register_entity(struct csiphy_device *csiphy, + */ + void msm_csiphy_unregister_entity(struct csiphy_device *csiphy) + { ++ if (!IS_ERR(csiphy->phy)) ++ phy_exit(csiphy->phy); + v4l2_device_unregister_subdev(&csiphy->subdev); + media_entity_cleanup(&csiphy->subdev.entity); + } +diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/media/platform/qcom/camss/camss-csiphy.h +index 9dab9a8946deff69e97d3b94c64dc0471ef278a4..d0c9f9a068d6af9113114f1f4262f20ed160a7bc 100644 +--- a/drivers/media/platform/qcom/camss/camss-csiphy.h ++++ b/drivers/media/platform/qcom/camss/camss-csiphy.h +@@ -12,6 +12,7 @@ + + #include + #include ++#include + #include + #include + #include +@@ -20,6 +21,7 @@ + #define MSM_CSIPHY_PAD_SINK 0 + #define MSM_CSIPHY_PAD_SRC 1 + #define MSM_CSIPHY_PADS_NUM 2 ++#define MSM_CSIPHY_MAX_DATA_LANE 4 + + #define CSIPHY_GRP_ID 1 + +@@ -98,6 +100,7 @@ struct csiphy_device_regs { + + struct csiphy_device { + struct camss *camss; ++ struct phy *phy; + u8 id; + struct v4l2_subdev subdev; + struct media_pad pads[MSM_CSIPHY_PADS_NUM]; +@@ -105,6 +108,7 @@ struct csiphy_device { + void __iomem *base_clk_mux; + u32 irq; + char irq_name[30]; ++ char name[16]; + struct camss_clock *clock; + bool *rate_set; + int nclocks; +@@ -119,9 +123,11 @@ struct csiphy_device { + + struct camss_subdev_resources; + +-int msm_csiphy_subdev_init(struct camss *camss, +- struct csiphy_device *csiphy, +- const struct camss_subdev_resources *res, u8 id); ++int msm_csiphy_subdev_init_legacy(struct camss *camss, ++ struct csiphy_device *csiphy, ++ const struct camss_subdev_resources *res, u8 id); ++ ++int msm_csiphy_subdev_init(struct camss *camss, u8 port); + + int msm_csiphy_register_entity(struct csiphy_device *csiphy, + struct v4l2_device *v4l2_dev); +diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c +index 9fe3bc34495ea0cc96580e0fae96e57fb5d710ac..0e48e69ac05354d5894e49274e749f252ad99417 100644 +--- a/drivers/media/platform/qcom/camss/camss.c ++++ b/drivers/media/platform/qcom/camss/camss.c +@@ -4734,16 +4734,18 @@ static const struct parent_dev_ops vfe_parent_dev_ops = { + + /* + * camss_parse_endpoint_node - Parse port endpoint node +- * @dev: CAMSS device ++ * @camss: CAMSS device + * @ep: Device endpoint to be parsed + * @csd: Parsed data from port endpoint node + * + * Return 0 on success or a negative error code on failure + */ +-static int camss_parse_endpoint_node(struct device *dev, ++static int camss_parse_endpoint_node(struct camss *camss, + struct fwnode_handle *ep, +- struct camss_async_subdev *csd) ++ struct camss_async_subdev *csd, ++ u8 lane_base) + { ++ struct device *dev = camss->dev; + struct csiphy_lanes_cfg *lncfg = &csd->interface.csi2.lane_cfg; + struct v4l2_mbus_config_mipi_csi2 *mipi_csi2; + struct v4l2_fwnode_endpoint vep = { { 0 } }; +@@ -4761,6 +4763,11 @@ static int camss_parse_endpoint_node(struct device *dev, + } + csd->interface.csi2.is_cphy = vep.bus_type == V4L2_MBUS_CSI2_CPHY; + ++ if (vep.base.port >= camss->res->csiphy_num) { ++ dev_err(dev, "Invalid CSIPHY port %u\n", vep.base.port); ++ return -EINVAL; ++ } ++ + csd->interface.csiphy_id = vep.base.port; + + mipi_csi2 = &vep.bus.mipi_csi2; +@@ -4775,7 +4782,14 @@ static int camss_parse_endpoint_node(struct device *dev, + return -ENOMEM; + + for (i = 0; i < lncfg->num_data; i++) { +- lncfg->data[i].pos = mipi_csi2->data_lanes[i]; ++ u8 lane = mipi_csi2->data_lanes[i]; ++ ++ if (lane < lane_base || lane - lane_base >= MSM_CSIPHY_MAX_DATA_LANE) { ++ dev_err(dev, "invalid data-lane %u\n", lane); ++ return -EINVAL; ++ } ++ ++ lncfg->data[i].pos = mipi_csi2->data_lanes[i] - lane_base; + lncfg->data[i].pol = mipi_csi2->lane_polarities[i + 1]; + } + +@@ -4791,30 +4805,78 @@ static int camss_parse_endpoint_node(struct device *dev, + static int camss_parse_ports(struct camss *camss) + { + struct device *dev = camss->dev; +- struct fwnode_handle *fwnode = dev_fwnode(dev), *ep; ++ struct fwnode_handle *fwnode = dev_fwnode(dev); ++ u8 lane_base = camss->legacy_phy ? 0 : 1; + int ret; + +- fwnode_graph_for_each_endpoint(fwnode, ep) { ++ fwnode_graph_for_each_endpoint_scoped(fwnode, ep) { + struct camss_async_subdev *csd; + +- csd = v4l2_async_nf_add_fwnode_remote(&camss->notifier, ep, +- typeof(*csd)); +- if (IS_ERR(csd)) { +- ret = PTR_ERR(csd); +- goto err_cleanup; ++ if (!fwnode_device_is_available(ep)) ++ continue; ++ ++ if (camss->legacy_phy) { ++ csd = v4l2_async_nf_add_fwnode_remote(&camss->notifier, ep, ++ typeof(*csd)); ++ } else { ++ struct fwnode_handle *phy_out, *phy_node, *phy_in, *sensor_ep; ++ ++ phy_out = fwnode_graph_get_remote_endpoint(ep); ++ if (!phy_out) ++ continue; ++ ++ phy_node = fwnode_graph_get_port_parent(phy_out); ++ fwnode_handle_put(phy_out); ++ if (!phy_node) ++ continue; ++ ++ phy_in = fwnode_graph_get_endpoint_by_id(phy_node, 0, 0, 0); ++ fwnode_handle_put(phy_node); ++ if (!phy_in) ++ continue; ++ ++ sensor_ep = fwnode_graph_get_remote_endpoint(phy_in); ++ fwnode_handle_put(phy_in); ++ if (!sensor_ep) ++ continue; ++ ++ csd = v4l2_async_nf_add_fwnode(&camss->notifier, sensor_ep, ++ struct camss_async_subdev); ++ fwnode_handle_put(sensor_ep); + } + +- ret = camss_parse_endpoint_node(dev, ep, csd); ++ if (IS_ERR(csd)) ++ return PTR_ERR(csd); ++ ++ ret = camss_parse_endpoint_node(camss, ep, csd, lane_base); + if (ret < 0) +- goto err_cleanup; ++ return ret; + } + + return 0; ++} ++ ++static void camss_detect_legacy_phy(struct camss *camss) ++{ ++ struct device_node *remote; ++ struct device_node *ep; + +-err_cleanup: +- fwnode_handle_put(ep); ++ camss->legacy_phy = true; + +- return ret; ++ /* Find first remote-endpoint and determine if its a PHY */ ++ for_each_endpoint_of_node(camss->dev->of_node, ep) { ++ remote = of_graph_get_remote_port_parent(ep); ++ if (!remote) ++ continue; ++ ++ camss->legacy_phy = !of_node_name_eq(remote, "phy"); ++ of_node_put(remote); ++ of_node_put(ep); ++ break; ++ } ++ ++ dev_dbg(camss->dev, "legacy phy mode %s\n", ++ camss->legacy_phy ? "true" : "false"); + } + + /* +@@ -4830,14 +4892,21 @@ static int camss_init_subdevices(struct camss *camss) + unsigned int i; + int ret; + ++ camss_detect_legacy_phy(camss); ++ + for (i = 0; i < camss->res->csiphy_num; i++) { +- ret = msm_csiphy_subdev_init(camss, &camss->csiphy[i], +- &res->csiphy_res[i], +- res->csiphy_res[i].csiphy.id); ++ if (!camss->legacy_phy) { ++ ret = msm_csiphy_subdev_init(camss, i); ++ } else { ++ ret = msm_csiphy_subdev_init_legacy(camss, ++ &camss->csiphy[i], ++ &res->csiphy_res[i], ++ res->csiphy_res[i].csiphy.id); ++ } ++ + if (ret < 0) { +- dev_err(camss->dev, +- "Failed to init csiphy%d sub-device: %d\n", +- i, ret); ++ dev_err(camss->dev, "csiphy %d init fail\n", ++ res->csiphy_res[i].csiphy.id); + return ret; + } + } +@@ -4915,6 +4984,11 @@ inline void camss_link_err(struct camss *camss, + ret); + } + ++static inline bool csiphy_enabled(struct camss *camss, struct csiphy_device *c) ++{ ++ return camss->legacy_phy || c->phy; ++} ++ + /* + * camss_link_entities - Register subdev nodes and create links + * @camss: CAMSS device +@@ -4928,6 +5002,9 @@ static int camss_link_entities(struct camss *camss) + + for (i = 0; i < camss->res->csiphy_num; i++) { + for (j = 0; j < camss->res->csid_num; j++) { ++ if (!csiphy_enabled(camss, &camss->csiphy[i])) ++ continue; ++ + ret = media_create_pad_link(&camss->csiphy[i].subdev.entity, + MSM_CSIPHY_PAD_SRC, + &camss->csid[j].subdev.entity, +@@ -5054,6 +5131,9 @@ static int camss_register_entities(struct camss *camss) + int ret; + + for (i = 0; i < camss->res->csiphy_num; i++) { ++ if (!csiphy_enabled(camss, &camss->csiphy[i])) ++ continue; ++ + ret = msm_csiphy_register_entity(&camss->csiphy[i], + &camss->v4l2_dev); + if (ret < 0) { +@@ -5129,8 +5209,10 @@ static int camss_register_entities(struct camss *camss) + + i = camss->res->csiphy_num; + err_reg_csiphy: +- for (i--; i >= 0; i--) +- msm_csiphy_unregister_entity(&camss->csiphy[i]); ++ for (i--; i >= 0; i--) { ++ if (csiphy_enabled(camss, &camss->csiphy[i])) ++ msm_csiphy_unregister_entity(&camss->csiphy[i]); ++ } + + return ret; + } +@@ -5145,8 +5227,10 @@ static void camss_unregister_entities(struct camss *camss) + { + unsigned int i; + +- for (i = 0; i < camss->res->csiphy_num; i++) +- msm_csiphy_unregister_entity(&camss->csiphy[i]); ++ for (i = 0; i < camss->res->csiphy_num; i++) { ++ if (csiphy_enabled(camss, &camss->csiphy[i])) ++ msm_csiphy_unregister_entity(&camss->csiphy[i]); ++ } + + if (camss->tpg) { + for (i = 0; i < camss->res->tpg_num; i++) +@@ -5756,6 +5840,7 @@ static const struct of_device_id camss_dt_match[] = { + { .compatible = "qcom,sm8550-camss", .data = &sm8550_resources }, + { .compatible = "qcom,sm8650-camss", .data = &sm8650_resources }, + { .compatible = "qcom,x1e80100-camss", .data = &x1e80100_resources }, ++ { .compatible = "qcom,glymur-camss", .data = &x1e80100_resources }, + { } + }; + +diff --git a/drivers/media/platform/qcom/camss/camss.h b/drivers/media/platform/qcom/camss/camss.h +index 93d691c8ac63b2a47dbb234856b627d8911a1851..ba3d51d9c0bf8905fca8e996fb2a62ee254f1834 100644 +--- a/drivers/media/platform/qcom/camss/camss.h ++++ b/drivers/media/platform/qcom/camss/camss.h +@@ -138,6 +138,7 @@ struct camss { + struct device_link *genpd_link; + struct icc_path *icc_path[ICC_SM8250_COUNT]; + const struct camss_resources *res; ++ bool legacy_phy; + }; + + struct camss_camera_interface { +diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c +index 59745f938eb034f4eeb93933ec1f7cefa4603e68..4862097911ef5ed76b75d6807a5589d7422409b9 100644 +--- a/drivers/net/wireless/ath/ath12k/core.c ++++ b/drivers/net/wireless/ath/ath12k/core.c +@@ -850,8 +850,6 @@ static int ath12k_core_pdev_create(struct ath12k_base *ab) + goto err_dp_pdev_free; + } + +- ath12k_debugfs_pdev_create(ab); +- + return 0; + + err_dp_pdev_free: +diff --git a/drivers/net/wireless/ath/ath12k/debugfs.c b/drivers/net/wireless/ath/ath12k/debugfs.c +index d54995b7adb278fb4eb9b0a540b44f2502199220..1bbcc20b6fd0e99282fae307bd0b3cca295dd64f 100644 +--- a/drivers/net/wireless/ath/ath12k/debugfs.c ++++ b/drivers/net/wireless/ath/ath12k/debugfs.c +@@ -1222,15 +1222,6 @@ static const struct file_operations fops_device_dp_stats = { + .llseek = default_llseek, + }; + +-void ath12k_debugfs_pdev_create(struct ath12k_base *ab) +-{ +- debugfs_create_file("simulate_fw_crash", 0600, ab->debugfs_soc, ab, +- &fops_simulate_fw_crash); +- +- debugfs_create_file("device_dp_stats", 0400, ab->debugfs_soc, ab, +- &fops_device_dp_stats); +-} +- + void ath12k_debugfs_soc_create(struct ath12k_base *ab) + { + bool dput_needed; +@@ -1253,6 +1244,14 @@ void ath12k_debugfs_soc_create(struct ath12k_base *ab) + + ab->debugfs_soc = debugfs_create_dir(soc_name, debugfs_ath12k); + ++ if (!IS_ERR_OR_NULL(ab->debugfs_soc)) { ++ debugfs_create_file("simulate_fw_crash", 0600, ab->debugfs_soc, ab, ++ &fops_simulate_fw_crash); ++ ++ debugfs_create_file("device_dp_stats", 0400, ab->debugfs_soc, ab, ++ &fops_device_dp_stats); ++ } ++ + if (dput_needed) + dput(debugfs_ath12k); + } +diff --git a/drivers/net/wireless/ath/ath12k/debugfs.h b/drivers/net/wireless/ath/ath12k/debugfs.h +index f5dbca1b8d75114261beeb60ed00eb0c9163ca0e..f0002d41347dd8fa09ed5fdd85900ad86e63aa81 100644 +--- a/drivers/net/wireless/ath/ath12k/debugfs.h ++++ b/drivers/net/wireless/ath/ath12k/debugfs.h +@@ -14,7 +14,6 @@ void ath12k_debugfs_register(struct ath12k *ar); + void ath12k_debugfs_unregister(struct ath12k *ar); + void ath12k_debugfs_op_vif_add(struct ieee80211_hw *hw, + struct ieee80211_vif *vif); +-void ath12k_debugfs_pdev_create(struct ath12k_base *ab); + + static inline bool ath12k_debugfs_is_extd_rx_stats_enabled(struct ath12k *ar) + { +@@ -139,9 +138,6 @@ static inline void ath12k_debugfs_op_vif_add(struct ieee80211_hw *hw, + { + } + +-static inline void ath12k_debugfs_pdev_create(struct ath12k_base *ab) +-{ +-} + #endif /* CONFIG_ATH12K_DEBUGFS */ + + #endif /* _ATH12K_DEBUGFS_H_ */ +diff --git a/drivers/net/wireless/ath/ath12k/hw.h b/drivers/net/wireless/ath/ath12k/hw.h +index 011bb22e21c7b00711bdd2700f60477e8e4b4cb3..98a6634ff1e818f59f4a414420526b41861e01e4 100644 +--- a/drivers/net/wireless/ath/ath12k/hw.h ++++ b/drivers/net/wireless/ath/ath12k/hw.h +@@ -166,6 +166,7 @@ struct ath12k_hw_params { + u8 max_radios; + bool single_pdev_only:1; + u32 qmi_service_ins_id; ++ u32 qmi_max_chunk_size; + bool internal_sleep_clock:1; + + const struct ath12k_hw_ops *hw_ops; +diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c +index b609198b19ea794e443351a67603b715e77f8387..52fc7d65fe9722d25fc84c3ccad33afdbbd06b70 100644 +--- a/drivers/net/wireless/ath/ath12k/mac.c ++++ b/drivers/net/wireless/ath/ath12k/mac.c +@@ -14295,6 +14295,7 @@ static int ath12k_mac_setup_channels_rates(struct ath12k *ar, + sizeof(ath12k_6ghz_channels), GFP_KERNEL); + if (!channels) { + kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); ++ ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; + return -ENOMEM; + } + +@@ -14345,7 +14346,9 @@ static int ath12k_mac_setup_channels_rates(struct ath12k *ar, + GFP_KERNEL); + if (!channels) { + kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); ++ ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; + kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); ++ ar->mac.sbands[NL80211_BAND_6GHZ].channels = NULL; + return -ENOMEM; + } + +@@ -14385,7 +14388,7 @@ static int ath12k_mac_setup_channels_rates(struct ath12k *ar, + kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); + ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; + kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels); +- ar->mac.sbands[NL80211_BAND_2GHZ].channels = NULL; ++ ar->mac.sbands[NL80211_BAND_6GHZ].channels = NULL; + kfree(channels); + band->channels = NULL; + return ret; +@@ -15061,28 +15064,49 @@ static int ath12k_mac_hw_register(struct ath12k_hw *ah) + wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR); + + for_each_ar(ah, ar, i) { ++ struct ath12k_base *this_ab = ar->ab; ++ + /* Apply the regd received during initialization */ + ret = ath12k_regd_update(ar, true); + if (ret) { +- ath12k_err(ar->ab, "ath12k regd update failed: %d\n", ret); ++ ath12k_err(this_ab, "ath12k regd update failed: %d\n", ret); + goto err_unregister_hw; + } + +- if (ar->ab->hw_params->current_cc_support && ab->new_alpha2[0]) { ++ if (this_ab->hw_params->current_cc_support) { + struct wmi_set_current_country_arg current_cc = {}; ++ struct ieee80211_regdomain *default_regd; ++ bool same_cc = false; ++ ++ spin_lock_bh(&this_ab->base_lock); ++ memcpy(¤t_cc.alpha2, this_ab->new_alpha2, 2); ++ spin_unlock_bh(&this_ab->base_lock); ++ ++ if (!current_cc.alpha2[0]) ++ goto fw_stats_init; + +- memcpy(¤t_cc.alpha2, ab->new_alpha2, 2); +- memcpy(&ar->alpha2, ab->new_alpha2, 2); ++ memcpy(&ar->alpha2, current_cc.alpha2, 2); ++ ++ spin_lock_bh(&this_ab->base_lock); ++ default_regd = this_ab->default_regd[ar->pdev_idx]; ++ if (default_regd) ++ same_cc = !memcmp(default_regd->alpha2, ++ current_cc.alpha2, 2); ++ spin_unlock_bh(&this_ab->base_lock); ++ ++ if (same_cc) ++ goto fw_stats_init; + + reinit_completion(&ar->regd_update_completed); + + ret = ath12k_wmi_send_set_current_country_cmd(ar, ¤t_cc); + if (ret) +- ath12k_warn(ar->ab, ++ ath12k_warn(this_ab, + "failed set cc code for mac register: %d\n", + ret); + } + ++fw_stats_init: + ath12k_fw_stats_init(ar); + ath12k_debugfs_register(ar); + } +diff --git a/drivers/net/wireless/ath/ath12k/mhi.c b/drivers/net/wireless/ath/ath12k/mhi.c +index ee87f00bc5de9617019870e90258caf2bf3b19b9..bb5e77a8042f4d3fbcca76349fa31367111ccb0e 100644 +--- a/drivers/net/wireless/ath/ath12k/mhi.c ++++ b/drivers/net/wireless/ath/ath12k/mhi.c +@@ -271,6 +271,7 @@ int ath12k_mhi_register(struct ath12k_pci *ab_pci) + return 0; + + free_controller: ++ kfree(mhi_ctrl->irq); + mhi_free_controller(mhi_ctrl); + ab_pci->mhi_ctrl = NULL; + return ret; +diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c +index 8978edb44ceca051931f04cf51a032338859ea7d..14e0d133d2b57865072a27702ed8f2d38d1b35d7 100644 +--- a/drivers/net/wireless/ath/ath12k/pci.c ++++ b/drivers/net/wireless/ath/ath12k/pci.c +@@ -313,11 +313,24 @@ static void ath12k_pci_sw_reset(struct ath12k_base *ab, bool power_on) + ath12k_mhi_set_mhictrl_reset(ab); + } + +-static void ath12k_pci_free_ext_irq(struct ath12k_base *ab) ++static void ath12k_pci_free_ce_irq(struct ath12k_base *ab, int num_ce) ++{ ++ int i, irq_idx; ++ ++ for (i = 0; i < num_ce; i++) { ++ if (ath12k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) ++ continue; ++ ++ irq_idx = ATH12K_PCI_IRQ_CE0_OFFSET + i; ++ free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]); ++ } ++} ++ ++static void ath12k_pci_free_ext_irq(struct ath12k_base *ab, int num_ext_irq_grp) + { + int i, j; + +- for (i = 0; i < ATH12K_EXT_IRQ_GRP_NUM_MAX; i++) { ++ for (i = 0; i < num_ext_irq_grp; i++) { + struct ath12k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i]; + + for (j = 0; j < irq_grp->num_irq; j++) +@@ -330,16 +343,8 @@ static void ath12k_pci_free_ext_irq(struct ath12k_base *ab) + + static void ath12k_pci_free_irq(struct ath12k_base *ab) + { +- int i, irq_idx; +- +- for (i = 0; i < ab->hw_params->ce_count; i++) { +- if (ath12k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) +- continue; +- irq_idx = ATH12K_PCI_IRQ_CE0_OFFSET + i; +- free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]); +- } +- +- ath12k_pci_free_ext_irq(ab); ++ ath12k_pci_free_ce_irq(ab, ab->hw_params->ce_count); ++ ath12k_pci_free_ext_irq(ab, ATH12K_EXT_IRQ_GRP_NUM_MAX); + } + + static void ath12k_pci_ce_irq_enable(struct ath12k_base *ab, u16 ce_id) +@@ -504,9 +509,10 @@ static int ath12k_pci_ext_grp_napi_poll(struct napi_struct *napi, int budget) + + work_done = ath12k_dp_service_srng(dp, irq_grp, budget); + if (work_done < budget) { +- napi_complete_done(napi, work_done); +- for (i = 0; i < irq_grp->num_irq; i++) +- enable_irq(irq_grp->ab->irq_num[irq_grp->irqs[i]]); ++ if (napi_complete_done(napi, work_done)) { ++ for (i = 0; i < irq_grp->num_irq; i++) ++ enable_irq(irq_grp->ab->irq_num[irq_grp->irqs[i]]); ++ } + } + + if (work_done > budget) +@@ -595,8 +601,6 @@ static int ath12k_pci_ext_irq_config(struct ath12k_base *ab) + + irq = ath12k_pci_get_msi_irq(ab->dev, vector); + +- ab->irq_num[irq_idx] = irq; +- + ath12k_dbg(ab, ATH12K_DBG_PCI, + "irq:%d group:%d\n", irq, i); + +@@ -607,22 +611,24 @@ static int ath12k_pci_ext_irq_config(struct ath12k_base *ab) + if (ret) { + ath12k_err(ab, "failed request irq %d: %d\n", + vector, ret); +- goto fail_request; ++ ++ for (n = 0; n < j; n++) ++ free_irq(ab->irq_num[irq_grp->irqs[n]], irq_grp); ++ ++ netif_napi_del(&ab->ext_irq_grp[i].napi); ++ free_netdev(ab->ext_irq_grp[i].napi_ndev); ++ goto fail_allocate; + } ++ ++ ab->irq_num[irq_idx] = irq; + } + ath12k_pci_ext_grp_disable(irq_grp); + } + + return 0; + +-fail_request: +- /* i ->napi_ndev was properly allocated. Free it also */ +- i += 1; + fail_allocate: +- for (n = 0; n < i; n++) { +- irq_grp = &ab->ext_irq_grp[n]; +- free_netdev(irq_grp->napi_ndev); +- } ++ ath12k_pci_free_ext_irq(ab, i); + return ret; + } + +@@ -671,6 +677,8 @@ static int ath12k_pci_config_irq(struct ath12k_base *ab) + if (ret) { + ath12k_err(ab, "failed to request irq %d: %d\n", + irq_idx, ret); ++ ++ ath12k_pci_free_ce_irq(ab, i); + return ret; + } + +@@ -681,8 +689,10 @@ static int ath12k_pci_config_irq(struct ath12k_base *ab) + } + + ret = ath12k_pci_ext_irq_config(ab); +- if (ret) ++ if (ret) { ++ ath12k_pci_free_ce_irq(ab, ab->hw_params->ce_count); + return ret; ++ } + + return 0; + } +diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c +index 280e50a1f31d89e2bef94225b8bceeae6e0b1113..4eb1992bdc20958aff614a627050d3a5db7ab58c 100644 +--- a/drivers/net/wireless/ath/ath12k/qmi.c ++++ b/drivers/net/wireless/ath/ath12k/qmi.c +@@ -14,11 +14,12 @@ + #include + #include + #include ++#include ++#include + + #define SLEEP_CLOCK_SELECT_INTERNAL_BIT 0x02 + #define HOST_CSTATE_BIT 0x04 + #define PLATFORM_CAP_PCIE_GLOBAL_RESET 0x08 +-#define ATH12K_QMI_MAX_CHUNK_SIZE 2097152 + + static const struct qmi_elem_info wlfw_host_mlo_chip_info_s_v01_ei[] = { + { +@@ -2584,46 +2585,63 @@ static void ath12k_qmi_free_mlo_mem_chunk(struct ath12k_base *ab, + mlo_chunk->v.ioaddr = NULL; + } else if (mlo_chunk->v.addr) { + dma_free_coherent(ab->dev, +- mlo_chunk->size, +- mlo_chunk->v.addr, +- mlo_chunk->paddr); ++ mlo_chunk->total_size, ++ mlo_chunk->vaddr_unaligned, ++ mlo_chunk->paddr_unaligned); ++ mlo_chunk->vaddr_unaligned = NULL; + mlo_chunk->v.addr = NULL; + } + + mlo_chunk->paddr = 0; ++ mlo_chunk->paddr_unaligned = 0; + mlo_chunk->size = 0; +- if (fixed_mem) ++ mlo_chunk->total_size = 0; ++ ++ if (fixed_mem) { + chunk->v.ioaddr = NULL; +- else ++ } else { + chunk->v.addr = NULL; ++ chunk->vaddr_unaligned = NULL; ++ } + chunk->paddr = 0; ++ chunk->paddr_unaligned = 0; + chunk->size = 0; ++ chunk->total_size = 0; + } + + static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab) + { + struct ath12k_hw_group *ag = ab->ag; ++ struct target_mem_chunk *chunk; + int i, mlo_idx; + + for (i = 0, mlo_idx = 0; i < ab->qmi.mem_seg_count; i++) { +- if (ab->qmi.target_mem[i].type == MLO_GLOBAL_MEM_REGION_TYPE) { ++ chunk = &ab->qmi.target_mem[i]; ++ ++ if (chunk->type == MLO_GLOBAL_MEM_REGION_TYPE) { + ath12k_qmi_free_mlo_mem_chunk(ab, +- &ab->qmi.target_mem[i], ++ chunk, + mlo_idx++); + } else { + if (test_bit(ATH12K_FLAG_FIXED_MEM_REGION, &ab->dev_flags) && +- ab->qmi.target_mem[i].v.ioaddr) { +- iounmap(ab->qmi.target_mem[i].v.ioaddr); +- ab->qmi.target_mem[i].v.ioaddr = NULL; ++ chunk->v.ioaddr) { ++ iounmap(chunk->v.ioaddr); ++ chunk->v.ioaddr = NULL; + } else { +- if (!ab->qmi.target_mem[i].v.addr) ++ if (!chunk->v.addr) + continue; + dma_free_coherent(ab->dev, +- ab->qmi.target_mem[i].prev_size, +- ab->qmi.target_mem[i].v.addr, +- ab->qmi.target_mem[i].paddr); +- ab->qmi.target_mem[i].v.addr = NULL; ++ chunk->total_size, ++ chunk->vaddr_unaligned, ++ chunk->paddr_unaligned); ++ chunk->vaddr_unaligned = NULL; ++ chunk->v.addr = NULL; + } ++ ++ chunk->paddr = 0; ++ chunk->paddr_unaligned = 0; ++ chunk->size = 0; ++ chunk->total_size = 0; + } + } + +@@ -2636,6 +2654,13 @@ static void ath12k_qmi_free_target_mem_chunk(struct ath12k_base *ab) + static int ath12k_qmi_alloc_chunk(struct ath12k_base *ab, + struct target_mem_chunk *chunk) + { ++ dma_addr_t paddr; ++ size_t size; ++ void *vaddr; ++ ++ if (chunk->size > U32_MAX - (SZ_64K - PAGE_SIZE)) ++ return -EOVERFLOW; ++ + /* Firmware reloads in recovery/resume. + * In such cases, no need to allocate memory for FW again. + */ +@@ -2645,29 +2670,56 @@ static int ath12k_qmi_alloc_chunk(struct ath12k_base *ab, + goto this_chunk_done; + + /* cannot reuse the existing chunk */ +- dma_free_coherent(ab->dev, chunk->prev_size, +- chunk->v.addr, chunk->paddr); ++ dma_free_coherent(ab->dev, chunk->total_size, ++ chunk->vaddr_unaligned, chunk->paddr_unaligned); + chunk->v.addr = NULL; ++ chunk->vaddr_unaligned = NULL; ++ chunk->paddr_unaligned = 0; ++ chunk->total_size = 0; + } + +- chunk->v.addr = dma_alloc_coherent(ab->dev, +- chunk->size, +- &chunk->paddr, ++ /* ++ * Each unaligned chunk costs the firmware extra TLB entries when ++ * mapping it, and too many unaligned chunks exhaust the TLB and ++ * crash the firmware, so align the base to 64 KB. The DMA ++ * allocator only guarantees page alignment, but a natural ++ * allocation is often already 64 KB aligned. Try the exact size ++ * first and keep it when it happens to be aligned; only fall back ++ * to over-allocating and rounding up when it is not. ++ */ ++ size = chunk->size; ++ vaddr = dma_alloc_coherent(ab->dev, size, &paddr, ++ GFP_KERNEL | __GFP_NOWARN); ++ if (vaddr && !IS_ALIGNED(paddr, SZ_64K)) { ++ dma_free_coherent(ab->dev, size, vaddr, paddr); ++ ++ size = (size_t)chunk->size + SZ_64K - PAGE_SIZE; ++ vaddr = dma_alloc_coherent(ab->dev, size, &paddr, + GFP_KERNEL | __GFP_NOWARN); +- if (!chunk->v.addr) { +- if (chunk->size > ATH12K_QMI_MAX_CHUNK_SIZE) { ++ } ++ ++ if (!vaddr) { ++ if (chunk->size > ab->hw_params->qmi_max_chunk_size) { + ab->qmi.target_mem_delayed = true; + ath12k_warn(ab, +- "qmi dma allocation failed (%u B type %u), will try later with small size\n", +- chunk->size, ++ "qmi dma allocation failed (%zu B type %u), will try later with small size\n", ++ size, + chunk->type); + ath12k_qmi_free_target_mem_chunk(ab); + return -EAGAIN; + } +- ath12k_warn(ab, "memory allocation failure for %u size: %u\n", +- chunk->type, chunk->size); ++ ath12k_warn(ab, "memory allocation failure for %u size: %zu\n", ++ chunk->type, size); + return -ENOMEM; + } ++ ++ chunk->vaddr_unaligned = vaddr; ++ chunk->paddr_unaligned = paddr; ++ chunk->total_size = size; ++ ++ chunk->paddr = ALIGN(paddr, SZ_64K); ++ chunk->v.addr = (u8 *)vaddr + (chunk->paddr - paddr); ++ + chunk->prev_type = chunk->type; + chunk->prev_size = chunk->size; + this_chunk_done: +diff --git a/drivers/net/wireless/ath/ath12k/qmi.h b/drivers/net/wireless/ath/ath12k/qmi.h +index 6da10f3cb597c3533070bc8cf30b86af2e0f17a3..1b1c88906f1e94ad36e84cedc5ceebd1c6b6449a 100644 +--- a/drivers/net/wireless/ath/ath12k/qmi.h ++++ b/drivers/net/wireless/ath/ath12k/qmi.h +@@ -100,6 +100,10 @@ struct target_mem_chunk { + void __iomem *ioaddr; + void *addr; + } v; ++ ++ dma_addr_t paddr_unaligned; ++ void *vaddr_unaligned; ++ u32 total_size; + }; + + struct target_info { +diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c +index 7b86f324b2e682a631d6b11b90a524ebbbf9120e..126e006f6ca7135d56fc5624c5f662b71ac44b94 100644 +--- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c ++++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + + #include "../debug.h" + #include "../core.h" +@@ -369,6 +370,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { + .max_radios = 1, + .single_pdev_only = false, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9274, ++ .qmi_max_chunk_size = SZ_2M, + .internal_sleep_clock = false, + + .hw_ops = &qcn9274_ops, +@@ -461,6 +463,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { + .max_radios = 1, + .single_pdev_only = true, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_WCN7850, ++ .qmi_max_chunk_size = SZ_512K, + .internal_sleep_clock = true, + + .hw_ops = &wcn7850_ops, +@@ -553,6 +556,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { + .max_radios = 2, + .single_pdev_only = false, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_QCN9274, ++ .qmi_max_chunk_size = SZ_2M, + .internal_sleep_clock = false, + + .hw_ops = &qcn9274_ops, +@@ -643,6 +647,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { + .max_radios = 1, + .single_pdev_only = false, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ5332, ++ .qmi_max_chunk_size = SZ_2M, + .internal_sleep_clock = false, + + .hw_ops = &qcn9274_ops, +@@ -728,6 +733,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { + .max_radios = 1, + .single_pdev_only = true, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_WCN7850, ++ .qmi_max_chunk_size = SZ_512K, + .internal_sleep_clock = true, + + .hw_ops = &qcc2072_ops, +@@ -821,6 +827,7 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { + .max_radios = 1, + .single_pdev_only = false, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ5332, ++ .qmi_max_chunk_size = SZ_2M, + .internal_sleep_clock = false, + + .hw_ops = &qcn9274_ops, +diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c +index d5160af60e00d115131c548dbf17f55de2abffd6..097ad6befc8f18a94fc2687df6b4ce1c4fb5a2cd 100644 +--- a/drivers/net/wireless/ath/ath12k/wmi.c ++++ b/drivers/net/wireless/ath/ath12k/wmi.c +@@ -6975,6 +6975,14 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk + goto mem_free; + } + ++ /* ++ * Set the valid pdev_idx before validating so that, even when the ++ * event is dropped or falls back, the completion the caller in ++ * ath12k_mac_hw_register() may be waiting on is still signalled at ++ * the end and it does not time out. ++ */ ++ pdev_idx = reg_info->phy_id; ++ + ret = ath12k_reg_validate_reg_info(ab, reg_info); + if (ret == ATH12K_REG_STATUS_FALLBACK) { + ath12k_warn(ab, "failed to validate reg info %d\n", ret); +@@ -6991,7 +6999,6 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk + } + + /* free old reg_info if it exist */ +- pdev_idx = reg_info->phy_id; + if (ab->reg_info[pdev_idx]) { + ath12k_reg_reset_reg_info(ab->reg_info[pdev_idx]); + kfree(ab->reg_info[pdev_idx]); +@@ -7030,7 +7037,7 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk + + out: + /* In some error cases, even a valid pdev_idx might not be available */ +- if (pdev_idx != 255) ++ if (pdev_idx < ab->num_radios) + ar = ab->pdevs[pdev_idx].ar; + + /* During the boot-time update, 'ar' might not be allocated, +diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c +index b58a607b713f58ec32721e0ecb5c3154e64f3a73..b7189818dcb50bcc79b9f268c1ea982c3777849d 100644 +--- a/drivers/pci/controller/dwc/pcie-qcom.c ++++ b/drivers/pci/controller/dwc/pcie-qcom.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -73,6 +74,23 @@ + #define PARF_BDF_TO_SID_TABLE_N 0x2000 + #define PARF_BDF_TO_SID_CFG 0x2c00 + ++/* ++ * ECAM blocker range registers. The blocked range has a write pair ++ * (WR_BASE/WR_LIMIT) and a read pair (RD_BASE/RD_LIMIT); each address is ++ * split into a low (32-bit) and a HI (upper 32-bit) register. ++ */ ++#define PARF_BLOCK_SLV_AXI_WR_BASE 0x360 ++#define PARF_BLOCK_SLV_AXI_WR_BASE_HI 0x364 ++#define PARF_BLOCK_SLV_AXI_WR_LIMIT 0x368 ++#define PARF_BLOCK_SLV_AXI_WR_LIMIT_HI 0x36c ++#define PARF_BLOCK_SLV_AXI_RD_BASE 0x370 ++#define PARF_BLOCK_SLV_AXI_RD_BASE_HI 0x374 ++#define PARF_BLOCK_SLV_AXI_RD_LIMIT 0x378 ++#define PARF_BLOCK_SLV_AXI_RD_LIMIT_HI 0x37c ++ ++#define PARF_ECAM_BASE 0x380 ++#define PARF_ECAM_BASE_HI 0x384 ++ + /* ELBI registers */ + #define ELBI_SYS_CTRL 0x04 + #define ELBI_SYS_STTS 0x08 +@@ -90,6 +108,7 @@ + + /* PARF_SYS_CTRL register fields */ + #define MAC_PHY_POWERDOWN_IN_P2_D_MUX_EN BIT(29) ++#define ECAM_BLOCKER_EN BIT(26) + #define MST_WAKEUP_EN BIT(13) + #define SLV_WAKEUP_EN BIT(12) + #define MSTR_ACLK_CGC_DIS BIT(10) +@@ -308,6 +327,7 @@ struct qcom_pcie { + struct gpio_desc *reset; + int global_irq; + bool use_pm_opp; ++ struct mutex reset_lock; + }; + + #define to_qcom_pcie(x) dev_get_drvdata((x)->dev) +@@ -445,6 +465,25 @@ static void qcom_pcie_configure_dbi_atu_base(struct qcom_pcie *pcie) + } + } + ++static void qcom_pcie_init_ecam_blocker(struct qcom_pcie *pcie) ++{ ++ struct dw_pcie *pci = pcie->pci; ++ ++ /* ECAM base must match the DBI base address */ ++ writel(lower_32_bits(pci->dbi_phys_addr), pcie->parf + PARF_ECAM_BASE); ++ writel(upper_32_bits(pci->dbi_phys_addr), pcie->parf + PARF_ECAM_BASE_HI); ++ ++ writel(0, pcie->parf + PARF_BLOCK_SLV_AXI_WR_BASE); ++ writel(0, pcie->parf + PARF_BLOCK_SLV_AXI_WR_BASE_HI); ++ writel(U32_MAX, pcie->parf + PARF_BLOCK_SLV_AXI_WR_LIMIT); ++ writel(U32_MAX, pcie->parf + PARF_BLOCK_SLV_AXI_WR_LIMIT_HI); ++ ++ writel(0, pcie->parf + PARF_BLOCK_SLV_AXI_RD_BASE); ++ writel(0, pcie->parf + PARF_BLOCK_SLV_AXI_RD_BASE_HI); ++ writel(U32_MAX, pcie->parf + PARF_BLOCK_SLV_AXI_RD_LIMIT); ++ writel(U32_MAX, pcie->parf + PARF_BLOCK_SLV_AXI_RD_LIMIT_HI); ++} ++ + static void qcom_pcie_2_1_0_ltssm_enable(struct qcom_pcie *pcie) + { + struct dw_pcie *pci = pcie->pci; +@@ -990,6 +1029,8 @@ static int qcom_pcie_post_init_2_3_3(struct qcom_pcie *pcie) + + dw_pcie_dbi_ro_wr_dis(pci); + ++ qcom_pcie_init_ecam_blocker(pcie); ++ + return 0; + } + +@@ -1104,6 +1145,8 @@ static int qcom_pcie_post_init_2_7_0(struct qcom_pcie *pcie) + + qcom_pcie_set_slot_cap(pcie->pci); + ++ qcom_pcie_init_ecam_blocker(pcie); ++ + return 0; + } + +@@ -1322,6 +1365,8 @@ static int qcom_pcie_post_init_2_9_0(struct qcom_pcie *pcie) + for (i = 0; i < 256; i++) + writel(0, pcie->parf + PARF_BDF_TO_SID_TABLE_N + (4 * i)); + ++ qcom_pcie_init_ecam_blocker(pcie); ++ + return 0; + } + +@@ -1382,6 +1427,18 @@ static void qcom_pcie_configure_ports(struct qcom_pcie *pcie) + dw_pcie_program_t_power_on(pcie->pci, port->l1ss_t_power_on); + } + ++static void qcom_pcie_enable_ecam_blocker(struct qcom_pcie *pcie) ++{ ++ u32 sys_ctrl; ++ ++ sys_ctrl = readl(pcie->parf + PARF_SYS_CTRL); ++ sys_ctrl |= ECAM_BLOCKER_EN; ++ writel(sys_ctrl, pcie->parf + PARF_SYS_CTRL); ++ ++ /* Flush the write so the blocker is enabled before this function returns */ ++ readl(pcie->parf + PARF_SYS_CTRL); ++} ++ + static int qcom_pcie_host_init(struct dw_pcie_rp *pp) + { + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); +@@ -1775,6 +1832,8 @@ static int qcom_pcie_reset_root_port(struct pci_host_bridge *bridge, + u32 val; + int ret; + ++ guard(mutex)(&pcie->reset_lock); ++ + /* Wait for the pending transactions to be completed */ + ret = readl_relaxed_poll_timeout(pcie->parf + PARF_STATUS, val, + val & FLUSH_COMPLETED, 10, +@@ -1878,6 +1937,11 @@ static irqreturn_t qcom_pcie_global_irq_thread(int irq, void *data) + + if (test_and_clear_bit(INT_ALL_LINK_DOWN, &status)) { + dev_dbg(dev, "Received Link down event\n"); ++ ++ mutex_lock(&pcie->reset_lock); ++ qcom_pcie_enable_ecam_blocker(pcie); ++ mutex_unlock(&pcie->reset_lock); ++ + for_each_pci_bridge(port, pp->bridge->bus) { + if (pci_pcie_type(port) == PCI_EXP_TYPE_ROOT_PORT) + pci_host_handle_link_down(port); +@@ -1953,7 +2017,7 @@ static bool qcom_pcie_is_child_node(struct device *dev, + return false; + } + +-/* Parse PERST# from all nodes in depth first manner starting from @np */ ++/* Collect PERST# GPIOs from PCI bridge nodes depth-first, starting at @np */ + static int qcom_pcie_parse_perst(struct qcom_pcie *pcie, + struct qcom_pcie_port *port, + struct device_node *np) +@@ -2019,6 +2083,9 @@ static int qcom_pcie_parse_perst(struct qcom_pcie *pcie, + + parse_child_node: + for_each_available_child_of_node_scoped(np, child) { ++ if (!of_node_is_type(child, "pci")) ++ continue; ++ + ret = qcom_pcie_parse_perst(pcie, port, child); + if (ret) + return ret; +@@ -2204,6 +2271,10 @@ static int qcom_pcie_probe(struct platform_device *pdev) + + INIT_LIST_HEAD(&pcie->ports); + ++ ret = devm_mutex_init(dev, &pcie->reset_lock); ++ if (ret) ++ goto err_pm_runtime_put; ++ + pci->dev = dev; + pci->ops = &dw_pcie_ops; + pp = &pci->pp; +@@ -2340,7 +2411,11 @@ static int qcom_pcie_probe(struct platform_device *pdev) + static int qcom_pcie_suspend_noirq(struct device *dev) + { + struct qcom_pcie *pcie; +- int ret = 0; ++ int ret = 0, err; ++ const struct qcom_pcie_cfg *pcie_cfg = of_device_get_match_data(dev); ++ ++ if (pcie_cfg && pcie_cfg->firmware_managed) ++ return 0; + + pcie = dev_get_drvdata(dev); + if (!pcie) +@@ -2359,8 +2434,11 @@ static int qcom_pcie_suspend_noirq(struct device *dev) + if (ret) + dev_err(dev, "Failed to disable CPU-PCIe interconnect path: %d\n", ret); + +- if (pcie->use_pm_opp) +- dev_pm_opp_set_opp(pcie->pci->dev, NULL); ++ if (pcie->use_pm_opp) { ++ err = dev_pm_opp_set_opp(pcie->pci->dev, NULL); ++ if (err) ++ dev_err(dev, "Failed to release PCIe OPP: %d\n", err); ++ } + } else { + /* + * Set minimum bandwidth required to keep data path +@@ -2388,8 +2466,11 @@ static int qcom_pcie_suspend_noirq(struct device *dev) + dev_err(dev, "Failed to disable CPU-PCIe interconnect path: %d\n", + ret); + +- if (pcie->use_pm_opp) +- dev_pm_opp_set_opp(pcie->pci->dev, NULL); ++ if (pcie->use_pm_opp) { ++ err = dev_pm_opp_set_opp(pcie->pci->dev, NULL); ++ if (err) ++ dev_err(dev, "Failed to release PCIe OPP: %d\n", err); ++ } + } + } + return ret; +@@ -2399,6 +2480,10 @@ static int qcom_pcie_resume_noirq(struct device *dev) + { + struct qcom_pcie *pcie; + int ret; ++ const struct qcom_pcie_cfg *pcie_cfg = of_device_get_match_data(dev); ++ ++ if (pcie_cfg && pcie_cfg->firmware_managed) ++ return 0; + + pcie = dev_get_drvdata(dev); + if (!pcie) +diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c +index 049da856eb5f6a223a671da46826b1432f5c78ab..5912e670a1992f91cb4f499233ab2454bcc52f5a 100644 +--- a/drivers/pci/pci-driver.c ++++ b/drivers/pci/pci-driver.c +@@ -4,6 +4,7 @@ + * (C) Copyright 2007 Novell Inc. + */ + ++#include + #include + #include + #include +@@ -903,6 +904,14 @@ static int pci_pm_suspend_late(struct device *dev) + return pm_generic_suspend_late(dev); + } + ++/* ++ * GLYMUR DIAGNOSTIC (2026-07-30, not for upstream). See ++ * the project changelog. bit1 = skip pci_prepare_to_sleep (stay in D0), ++ * bit2 = skip the driver noirq callback, bit4 = skip pci_save_state (RISKY). ++ */ ++static int glymur_pci_skip; ++core_param(glymur_pci_skip, glymur_pci_skip, int, 0644); ++ + static int pci_pm_suspend_noirq(struct device *dev) + { + struct pci_dev *pci_dev = to_pci_dev(dev); +@@ -919,7 +928,7 @@ static int pci_pm_suspend_noirq(struct device *dev) + goto set_unknown; + } + +- if (pm->suspend_noirq) { ++ if (pm->suspend_noirq && !(glymur_pci_skip & 2)) { + pci_power_t prev = pci_dev->current_state; + int error; + +@@ -938,14 +947,16 @@ static int pci_pm_suspend_noirq(struct device *dev) + } + + if (!pci_dev->state_saved) { +- pci_save_state(pci_dev); ++ if (!(glymur_pci_skip & 4)) ++ pci_save_state(pci_dev); + + /* + * If the device is a bridge with a child in D0 below it, + * it needs to stay in D0, so check skip_bus_pm to avoid + * putting it into a low-power state in that case. + */ +- if (!pci_dev->skip_bus_pm && pci_power_manageable(pci_dev)) ++ if (!pci_dev->skip_bus_pm && pci_power_manageable(pci_dev) && ++ !(glymur_pci_skip & 1)) + pci_prepare_to_sleep(pci_dev); + } + +diff --git a/drivers/pci/pwrctrl/Kconfig b/drivers/pci/pwrctrl/Kconfig +index 9eec767cda86e229dea042ba765b03386f44ba98..b24b60d3c48203925870c5099925c2a2bce69573 100644 +--- a/drivers/pci/pwrctrl/Kconfig ++++ b/drivers/pci/pwrctrl/Kconfig +@@ -7,7 +7,7 @@ config PCI_PWRCTRL + tristate + + config PCI_PWRCTRL_PWRSEQ +- tristate ++ tristate "PCI Power Control driver for power sequenced devices" + select POWER_SEQUENCING + select PCI_PWRCTRL + +diff --git a/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c b/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +index c5ced87944b6ca3dc642692311ff504a650acec7..7a39c55c3ba71e9c1c355634f608bd82c6fdc7a6 100644 +--- a/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c ++++ b/drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +@@ -122,6 +122,11 @@ static const struct of_device_id pwrseq_pwrctrl_of_match[] = { + .compatible = "pci17cb,1107", + .data = &pwrseq_pwrctrl_qcom_wcn_pdata, + }, ++ { ++ /* ATH12K in QCC2072 package. */ ++ .compatible = "pci17cb,1112", ++ .data = &pwrseq_pwrctrl_qcom_wcn_pdata, ++ }, + { } + }; + MODULE_DEVICE_TABLE(of, pwrseq_pwrctrl_of_match); +diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c +index 21aaf2f76e53eb1c63f1ffd2217f767c2dab5c3a..597e6b234f5ef68999eb36586bfffe70dee1c288 100644 +--- a/drivers/phy/phy-core.c ++++ b/drivers/phy/phy-core.c +@@ -124,13 +124,13 @@ static struct phy *phy_find(struct device *dev, const char *con_id) + const char *dev_id = dev_name(dev); + struct phy_lookup *p, *pl = NULL; + +- mutex_lock(&phy_provider_mutex); ++ lockdep_assert_held(&phy_provider_mutex); ++ + list_for_each_entry(p, &phys, node) + if (!strcmp(p->dev_id, dev_id) && !strcmp(p->con_id, con_id)) { + pl = p; + break; + } +- mutex_unlock(&phy_provider_mutex); + + return pl ? pl->phy : ERR_PTR(-ENODEV); + } +@@ -606,12 +606,44 @@ int phy_validate(struct phy *phy, enum phy_mode mode, int submode, + } + EXPORT_SYMBOL_GPL(phy_validate); + ++/** ++ * _of_phy_get_with_args() - lookup and obtain a reference to a phy by of_phandle_args ++ * @args: of_phandle_args to the phy ++ * ++ * Returns: the phy from the provider's of_xlate, -ENODEV if disabled, ++ * -EPROBE_DEFER if the provider is not yet registered. ++ */ ++static struct phy *_of_phy_get_with_args(struct of_phandle_args *args) ++{ ++ struct phy *phy; ++ struct phy_provider *phy_provider; ++ ++ lockdep_assert_held(&phy_provider_mutex); ++ ++ phy_provider = of_phy_provider_lookup(args->np); ++ if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) ++ return ERR_PTR(-EPROBE_DEFER); ++ ++ if (!of_device_is_available(args->np)) { ++ dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); ++ phy = ERR_PTR(-ENODEV); ++ goto out_put_module; ++ } ++ ++ phy = phy_provider->of_xlate(phy_provider->dev, args); ++ ++out_put_module: ++ module_put(phy_provider->owner); ++ ++ return phy; ++} ++ + /** + * _of_phy_get() - lookup and obtain a reference to a phy by phandle + * @np: device_node for which to get the phy + * @index: the index of the phy + * +- * Returns the phy associated with the given phandle value, ++ * Returns: the phy associated with the given phandle value, + * after getting a refcount to it or -ENODEV if there is no such phy or + * -EPROBE_DEFER if there is a phandle to the phy, but the device is + * not yet loaded. This function uses of_xlate call back function provided +@@ -620,10 +652,11 @@ EXPORT_SYMBOL_GPL(phy_validate); + static struct phy *_of_phy_get(struct device_node *np, int index) + { + int ret; +- struct phy_provider *phy_provider; +- struct phy *phy = NULL; ++ struct phy *phy; + struct of_phandle_args args; + ++ lockdep_assert_held(&phy_provider_mutex); ++ + ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", + index, &args); + if (ret) +@@ -635,26 +668,8 @@ static struct phy *_of_phy_get(struct device_node *np, int index) + goto out_put_node; + } + +- mutex_lock(&phy_provider_mutex); +- phy_provider = of_phy_provider_lookup(args.np); +- if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { +- phy = ERR_PTR(-EPROBE_DEFER); +- goto out_unlock; +- } +- +- if (!of_device_is_available(args.np)) { +- dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); +- phy = ERR_PTR(-ENODEV); +- goto out_put_module; +- } +- +- phy = phy_provider->of_xlate(phy_provider->dev, &args); +- +-out_put_module: +- module_put(phy_provider->owner); ++ phy = _of_phy_get_with_args(&args); + +-out_unlock: +- mutex_unlock(&phy_provider_mutex); + out_put_node: + of_node_put(args.np); + +@@ -666,7 +681,7 @@ static struct phy *_of_phy_get(struct device_node *np, int index) + * @np: device_node for which to get the phy + * @con_id: name of the phy from device's point of view + * +- * Returns the phy driver, after getting a refcount to it; or ++ * Returns: the phy driver, after getting a refcount to it; or + * -ENODEV if there is no such phy. The caller is responsible for + * calling of_phy_put() to release that count. + */ +@@ -678,15 +693,21 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id) + if (con_id) + index = of_property_match_string(np, "phy-names", con_id); + ++ mutex_lock(&phy_provider_mutex); ++ + phy = _of_phy_get(np, index); + if (IS_ERR(phy)) +- return phy; ++ goto out_unlock; + +- if (!try_module_get(phy->ops->owner)) +- return ERR_PTR(-EPROBE_DEFER); ++ if (!try_module_get(phy->ops->owner)) { ++ phy = ERR_PTR(-EPROBE_DEFER); ++ goto out_unlock; ++ } + + get_device(&phy->dev); + ++out_unlock: ++ mutex_unlock(&phy_provider_mutex); + return phy; + } + EXPORT_SYMBOL_GPL(of_phy_get); +@@ -776,7 +797,7 @@ EXPORT_SYMBOL_GPL(of_phy_simple_xlate); + * @string: the phy name as given in the dt data or the name of the controller + * port for non-dt case + * +- * Returns the phy driver, after getting a refcount to it; or ++ * Returns: the phy driver, after getting a refcount to it; or + * -ENODEV if there is no such phy. The caller is responsible for + * calling phy_put() to release that count. + */ +@@ -786,6 +807,7 @@ struct phy *phy_get(struct device *dev, const char *string) + struct phy *phy; + struct device_link *link; + ++ mutex_lock(&phy_provider_mutex); + if (dev->of_node) { + if (string) + index = of_property_match_string(dev->of_node, "phy-names", +@@ -796,15 +818,18 @@ struct phy *phy_get(struct device *dev, const char *string) + } else { + if (string == NULL) { + dev_WARN(dev, "missing string\n"); +- return ERR_PTR(-EINVAL); ++ phy = ERR_PTR(-EINVAL); ++ goto out_unlock; + } + phy = phy_find(dev, string); + } + if (IS_ERR(phy)) +- return phy; ++ goto out_unlock; + +- if (!try_module_get(phy->ops->owner)) +- return ERR_PTR(-EPROBE_DEFER); ++ if (!try_module_get(phy->ops->owner)) { ++ phy = ERR_PTR(-EPROBE_DEFER); ++ goto out_unlock; ++ } + + get_device(&phy->dev); + +@@ -813,6 +838,8 @@ struct phy *phy_get(struct device *dev, const char *string) + dev_dbg(dev, "failed to create device link to %s\n", + dev_name(phy->dev.parent)); + ++out_unlock: ++ mutex_unlock(&phy_provider_mutex); + return phy; + } + EXPORT_SYMBOL_GPL(phy_get); +@@ -961,15 +988,17 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, + if (!ptr) + return ERR_PTR(-ENOMEM); + ++ mutex_lock(&phy_provider_mutex); + phy = _of_phy_get(np, index); + if (IS_ERR(phy)) { + devres_free(ptr); +- return phy; ++ goto out_unlock; + } + + if (!try_module_get(phy->ops->owner)) { + devres_free(ptr); +- return ERR_PTR(-EPROBE_DEFER); ++ phy = ERR_PTR(-EPROBE_DEFER); ++ goto out_unlock; + } + + get_device(&phy->dev); +@@ -982,10 +1011,77 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, + dev_dbg(dev, "failed to create device link to %s\n", + dev_name(phy->dev.parent)); + ++out_unlock: ++ mutex_unlock(&phy_provider_mutex); + return phy; + } + EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); + ++/** ++ * phy_get_by_of_node() - lookup and obtain a reference to a phy by device_node ++ * @np: node containing the phy ++ * ++ * Returns: the phy associated with the device node or ERR_PTR. ++ */ ++struct phy *phy_get_by_of_node(struct device_node *np) ++{ ++ struct of_phandle_args args = { .np = np, .args_count = 0 }; ++ struct phy *phy; ++ ++ mutex_lock(&phy_provider_mutex); ++ ++ phy = _of_phy_get_with_args(&args); ++ if (IS_ERR(phy)) ++ goto out_unlock; ++ ++ if (!try_module_get(phy->ops->owner)) { ++ phy = ERR_PTR(-EPROBE_DEFER); ++ goto out_unlock; ++ } ++ ++ get_device(&phy->dev); ++ ++out_unlock: ++ mutex_unlock(&phy_provider_mutex); ++ ++ return phy; ++} ++EXPORT_SYMBOL_GPL(phy_get_by_of_node); ++ ++/** ++ * devm_phy_get_by_of_node() - devm managed lookup and obtain phy reference by device node ++ * @dev: device requesting the PHY ++ * @np: device_node of the PHY provider ++ * ++ * Returns: phy associated with the device_node or ERR_PTR. devres manages ++ * releasing resources. ++ */ ++struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np) ++{ ++ struct phy **ptr, *phy; ++ struct device_link *link; ++ ++ ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL); ++ if (!ptr) ++ return ERR_PTR(-ENOMEM); ++ ++ phy = phy_get_by_of_node(np); ++ if (IS_ERR(phy)) { ++ devres_free(ptr); ++ return phy; ++ } ++ ++ *ptr = phy; ++ devres_add(dev, ptr); ++ link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS); ++ if (!link) ++ dev_dbg(dev, "failed to create device link to %s\n", ++ dev_name(phy->dev.parent)); ++ ++ return phy; ++} ++EXPORT_SYMBOL_GPL(devm_phy_get_by_of_node); ++ + /** + * phy_create() - create a new phy + * @dev: device that is creating the new phy +diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig +index d910a5d1a1ac3ad77599e72c3f4a3b2aebd02dbf..d802e63ad74ae9861a719531ea1cb744081b43f8 100644 +--- a/drivers/phy/qualcomm/Kconfig ++++ b/drivers/phy/qualcomm/Kconfig +@@ -28,6 +28,21 @@ config PHY_QCOM_EDP + Enable this driver to support the Qualcomm eDP PHY found in various + Qualcomm chipsets. + ++config PHY_QCOM_MIPI_CSI2 ++ tristate "Qualcomm MIPI CSI2 PHY driver" ++ depends on ARCH_QCOM || COMPILE_TEST ++ depends on OF ++ depends on PM ++ depends on PM_OPP ++ depends on COMMON_CLK ++ select GENERIC_PHY ++ select GENERIC_PHY_MIPI_DPHY ++ help ++ Enable this to support the MIPI CSI2 PHY driver found in various ++ Qualcomm chipsets. This PHY is used to connect MIPI CSI2 ++ camera sensors to the CSI Decoder in the Qualcomm Camera Subsystem ++ CAMSS. ++ + config PHY_QCOM_IPQ4019_USB + tristate "Qualcomm IPQ4019 USB PHY driver" + depends on OF && (ARCH_QCOM || COMPILE_TEST) +diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile +index 8bf887d58ee4a65687216dd91a6592da7941ace2..4b5e6640a6faa05715b96cc8e9512208340fb595 100644 +--- a/drivers/phy/qualcomm/Makefile ++++ b/drivers/phy/qualcomm/Makefile +@@ -6,6 +6,11 @@ obj-$(CONFIG_PHY_QCOM_IPQ4019_USB) += phy-qcom-ipq4019-usb.o + obj-$(CONFIG_PHY_QCOM_IPQ806X_SATA) += phy-qcom-ipq806x-sata.o + obj-$(CONFIG_PHY_QCOM_M31_USB) += phy-qcom-m31.o + obj-$(CONFIG_PHY_QCOM_M31_EUSB) += phy-qcom-m31-eusb2.o ++ ++phy-qcom-mipi-csi2-objs += phy-qcom-mipi-csi2-core.o \ ++ phy-qcom-mipi-csi2-3ph-dphy.o ++obj-$(CONFIG_PHY_QCOM_MIPI_CSI2) += phy-qcom-mipi-csi2.o ++ + obj-$(CONFIG_PHY_QCOM_PCIE2) += phy-qcom-pcie2.o + + obj-$(CONFIG_PHY_QCOM_QMP_COMBO) += phy-qcom-qmp-combo.o phy-qcom-qmp-usbc.o +diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c +new file mode 100644 +index 0000000000000000000000000000000000000000..966d79c98f9b21e1a235b8397c4c84b25d869427 +--- /dev/null ++++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c +@@ -0,0 +1,385 @@ ++// SPDX-License-Identifier: GPL-2.0 ++/* ++ * Qualcomm MSM Camera Subsystem - CSIPHY Module 3phase v1.0 ++ * ++ * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. ++ * Copyright (C) 2016-2026 Linaro Ltd. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "phy-qcom-mipi-csi2.h" ++ ++#define CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(offset, n) ((offset) + 0x4 * (n)) ++#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL0_PHY_SW_RESET BIT(0) ++#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL5_CLK_ENABLE BIT(7) ++#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B BIT(0) ++#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID BIT(1) ++#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL10_IRQ_CLEAR_CMD BIT(0) ++#define CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(offset, n) ((offset) + 0xb0 + 0x4 * (n)) ++ ++#define CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(n) ((0x200 * (n)) + 0x24) ++ ++/* ++ * 3 phase CSI has 19 common status regs with only 0-10 being used ++ * and 11-18 being reserved. ++ */ ++#define CSI_COMMON_STATUS_NUM 11 ++/* ++ * There are a number of common control registers ++ * The offset to clear the CSIPHY IRQ status starts @ 22 ++ * So to clear CSI_COMMON_STATUS0 this is CSI_COMMON_CONTROL22, STATUS1 is ++ * CONTROL23 and so on ++ */ ++#define CSI_CTRL_STATUS_INDEX 22 ++ ++/* ++ * There are 43 COMMON_CTRL registers with regs after # 33 being reserved ++ */ ++#define CSI_CTRL_MAX 33 ++ ++#define CSIPHY_DEFAULT_PARAMS 0 ++#define CSIPHY_SETTLE_CNT_LOWER_BYTE 2 ++#define CSIPHY_SKEW_CAL 7 ++ ++/* 4nm 2PH v 2.1.2 2p5Gbps 4 lane DPHY mode */ ++static const struct ++mipi_csi2phy_lane_regs lane_regs_x1e80100[] = { ++ /* Power up lanes 2ph mode */ ++ {.reg_addr = 0x101c, .reg_data = 0x7a, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x1018, .reg_data = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ ++ {.reg_addr = 0x0094, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x00a0, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0090, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0098, .reg_data = 0x08, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0094, .reg_data = 0x07, .delay_us = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0030, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0000, .reg_data = 0x8e, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0038, .reg_data = 0xfe, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x002c, .reg_data = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0034, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x001c, .reg_data = 0x0a, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0014, .reg_data = 0x60, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x003c, .reg_data = 0xb8, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0004, .reg_data = 0x0c, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0020, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0008, .reg_data = 0x10, .param_type = CSIPHY_SETTLE_CNT_LOWER_BYTE}, ++ {.reg_addr = 0x0010, .reg_data = 0x52, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0094, .reg_data = 0xd7, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x005c, .reg_data = 0x00, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0060, .reg_data = 0xbd, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0064, .reg_data = 0x7f, .param_type = CSIPHY_SKEW_CAL}, ++ ++ {.reg_addr = 0x0e94, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0ea0, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e90, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e98, .reg_data = 0x08, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e94, .reg_data = 0x07, .delay_us = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e30, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e28, .reg_data = 0x04, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e00, .reg_data = 0x80, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e0c, .reg_data = 0xff, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e38, .reg_data = 0x1f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e2c, .reg_data = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e34, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e1c, .reg_data = 0x0a, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e14, .reg_data = 0x60, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e3c, .reg_data = 0xb8, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e04, .reg_data = 0x0c, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e20, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0e08, .reg_data = 0x10, .param_type = CSIPHY_SETTLE_CNT_LOWER_BYTE}, ++ {.reg_addr = 0x0e10, .reg_data = 0x52, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ ++ {.reg_addr = 0x0494, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x04a0, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0490, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0498, .reg_data = 0x08, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0494, .reg_data = 0x07, .delay_us = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0430, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0400, .reg_data = 0x8e, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0438, .reg_data = 0xfe, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x042c, .reg_data = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0434, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x041c, .reg_data = 0x0a, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0414, .reg_data = 0x60, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x043c, .reg_data = 0xb8, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0404, .reg_data = 0x0c, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0420, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0408, .reg_data = 0x10, .param_type = CSIPHY_SETTLE_CNT_LOWER_BYTE}, ++ {.reg_addr = 0x0410, .reg_data = 0x52, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0494, .reg_data = 0xd7, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x045c, .reg_data = 0x00, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0460, .reg_data = 0xbd, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0464, .reg_data = 0x7f, .param_type = CSIPHY_SKEW_CAL}, ++ ++ {.reg_addr = 0x0894, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x08a0, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0890, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0898, .reg_data = 0x08, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0894, .reg_data = 0x07, .delay_us = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0830, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0800, .reg_data = 0x8e, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0838, .reg_data = 0xfe, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x082c, .reg_data = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0834, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x081c, .reg_data = 0x0a, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0814, .reg_data = 0x60, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x083c, .reg_data = 0xb8, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0804, .reg_data = 0x0c, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0820, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0808, .reg_data = 0x10, .param_type = CSIPHY_SETTLE_CNT_LOWER_BYTE}, ++ {.reg_addr = 0x0810, .reg_data = 0x52, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0894, .reg_data = 0xd7, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x085c, .reg_data = 0x00, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0860, .reg_data = 0xbd, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0864, .reg_data = 0x7f, .param_type = CSIPHY_SKEW_CAL}, ++ ++ {.reg_addr = 0x0c94, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0ca0, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c90, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c98, .reg_data = 0x08, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c94, .reg_data = 0x07, .delay_us = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c30, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c00, .reg_data = 0x8e, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c38, .reg_data = 0xfe, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c2c, .reg_data = 0x01, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c34, .reg_data = 0x0f, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c1c, .reg_data = 0x0a, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c14, .reg_data = 0x60, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c3c, .reg_data = 0xb8, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c04, .reg_data = 0x0c, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c20, .reg_data = 0x00, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c08, .reg_data = 0x10, .param_type = CSIPHY_SETTLE_CNT_LOWER_BYTE}, ++ {.reg_addr = 0x0c10, .reg_data = 0x52, .param_type = CSIPHY_DEFAULT_PARAMS}, ++ {.reg_addr = 0x0c94, .reg_data = 0xd7, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0c5c, .reg_data = 0x00, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0c60, .reg_data = 0xbd, .param_type = CSIPHY_SKEW_CAL}, ++ {.reg_addr = 0x0c64, .reg_data = 0x7f, .param_type = CSIPHY_SKEW_CAL}, ++}; ++ ++static inline const struct mipi_csi2phy_device_regs * ++csi2phy_dev_to_regs(struct mipi_csi2phy_device *csi2phy) ++{ ++ return &csi2phy->soc_cfg->reg_info; ++} ++ ++static void phy_qcom_mipi_csi2_hw_version_read(struct mipi_csi2phy_device *csi2phy) ++{ ++ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy); ++ u32 tmp; ++ ++ writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6)); ++ ++ tmp = readl_relaxed(csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 12)); ++ csi2phy->hw_version = tmp; ++ ++ tmp = readl_relaxed(csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 13)); ++ csi2phy->hw_version |= (tmp << 8) & 0xFF00; ++ ++ tmp = readl_relaxed(csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 14)); ++ csi2phy->hw_version |= (tmp << 16) & 0xFF0000; ++ ++ tmp = readl_relaxed(csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(regs->common_regs_offset, 15)); ++ csi2phy->hw_version |= (tmp << 24) & 0xFF000000; ++ ++ dev_dbg_once(csi2phy->dev, "CSIPHY 3PH HW Version = 0x%08x\n", csi2phy->hw_version); ++} ++ ++/* ++ * phy_qcom_mipi_csi2_reset - Perform software reset on CSIPHY module ++ * @phy_qcom_mipi_csi2: CSIPHY device ++ */ ++static void phy_qcom_mipi_csi2_reset(struct mipi_csi2phy_device *csi2phy) ++{ ++ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy); ++ ++ writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL0_PHY_SW_RESET, ++ csi2phy->base + CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0)); ++ usleep_range(5000, 8000); ++ writel(0x0, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0)); ++} ++ ++/* ++ * phy_qcom_mipi_csi2_settle_cnt_calc - Calculate settle count value ++ * ++ * Helper function to calculate settle count value. This is ++ * based on the CSI2 T_hs_settle parameter which in turn ++ * is calculated based on the CSI2 transmitter link frequency. ++ * ++ * Return settle count. ++ */ ++static u8 phy_qcom_mipi_csi2_settle_cnt_calc(s64 link_freq, u32 timer_clk_rate) ++{ ++ u32 t_hs_prepare_max_ps; ++ u32 timer_period_ps; ++ u32 t_hs_settle_ps; ++ u8 settle_cnt; ++ u32 ui_ps; ++ ++ ui_ps = div64_u64(PSEC_PER_SEC, link_freq); ++ ui_ps /= 2; ++ t_hs_prepare_max_ps = 85000 + 6 * ui_ps; ++ t_hs_settle_ps = t_hs_prepare_max_ps; ++ ++ timer_period_ps = div_u64(PSEC_PER_SEC, timer_clk_rate); ++ ++ if ((t_hs_settle_ps / timer_period_ps) < 6) ++ return 0; ++ ++ settle_cnt = t_hs_settle_ps / timer_period_ps - 6; ++ ++ return settle_cnt; ++} ++ ++static void ++phy_qcom_mipi_csi2_gen2_config_lanes(struct mipi_csi2phy_device *csi2phy, ++ u8 settle_cnt) ++{ ++ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy); ++ const struct mipi_csi2phy_lane_regs *r = regs->init_seq; ++ int i, array_size = regs->lane_array_size; ++ u32 val; ++ ++ for (i = 0; i < array_size; i++, r++) { ++ switch (r->param_type) { ++ case CSIPHY_SETTLE_CNT_LOWER_BYTE: ++ val = settle_cnt & 0xff; ++ break; ++ case CSIPHY_SKEW_CAL: ++ /* TODO: support application of skew from dt flag */ ++ continue; ++ default: ++ val = r->reg_data; ++ break; ++ } ++ writel(val, csi2phy->base + r->reg_addr); ++ if (r->delay_us) ++ udelay(r->delay_us); ++ } ++} ++ ++static int phy_qcom_mipi_csi2_lanes_enable(struct mipi_csi2phy_device *csi2phy, ++ struct mipi_csi2phy_stream_cfg *cfg) ++{ ++ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy); ++ struct mipi_csi2phy_lanes_cfg *lane_cfg = &cfg->lane_cfg; ++ u8 settle_cnt; ++ u8 val; ++ int i; ++ ++ if (cfg->link_freq <= 0) ++ return -EINVAL; ++ ++ settle_cnt = phy_qcom_mipi_csi2_settle_cnt_calc(cfg->link_freq, csi2phy->timer_clk_rate); ++ if (!settle_cnt) ++ return -ENODEV; ++ ++ /* ++ * CSI_COMMON_CTRL5 is a physical lane power-up bitmap: ++ * - Bits [0,2,4,6] → D-PHY data lanes(LN0, LN2, LN4, LN6) ++ * - Bits [1,3,5] → C-PHY trio lanes(LN1, LN3, LN5) ++ * - Bit [7] → D-PHY clock lane(LNCK) dedicated clock enable ++ */ ++ val = BIT(lane_cfg->clk.pos); ++ for (i = 0; i < cfg->num_data_lanes; i++) ++ val |= BIT(lane_cfg->data[i].pos * 2); ++ ++ writel(val, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 5)); ++ ++ /* Lane configuration for polarity @ CSIPHY-base + CTRL9 */ ++ for (i = 0; i < cfg->num_data_lanes; i++) { ++ if (lane_cfg->data[i].pol) { ++ u8 pos = lane_cfg->data[i].pos; ++ ++ writel(BIT(2), csi2phy->base + CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(pos * 2)); ++ } ++ } ++ ++ if (lane_cfg->clk.pol) ++ writel(BIT(2), csi2phy->base + CSIPHY_2PH_LN_CSI_2PHASE_CTRL9n(lane_cfg->clk.pos)); ++ ++ val = CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B; ++ writel(val, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6)); ++ ++ val = 0x02; ++ writel(val, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 7)); ++ ++ val = 0x00; ++ writel(val, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 0)); ++ ++ phy_qcom_mipi_csi2_gen2_config_lanes(csi2phy, settle_cnt); ++ ++ /* IRQ_MASK registers - disable all interrupts */ ++ for (i = CSI_COMMON_STATUS_NUM; i < CSI_CTRL_STATUS_INDEX; i++) { ++ writel(0, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, i)); ++ } ++ ++ return 0; ++} ++ ++static void ++phy_qcom_mipi_csi2_lanes_disable(struct mipi_csi2phy_device *csi2phy, ++ struct mipi_csi2phy_stream_cfg *cfg) ++{ ++ const struct mipi_csi2phy_device_regs *regs = csi2phy_dev_to_regs(csi2phy); ++ ++ writel(0, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 5)); ++ ++ writel(0, csi2phy->base + ++ CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(regs->common_regs_offset, 6)); ++} ++ ++static const struct mipi_csi2phy_hw_ops phy_qcom_mipi_csi2_ops_3ph_1_0 = { ++ .hw_version_read = phy_qcom_mipi_csi2_hw_version_read, ++ .reset = phy_qcom_mipi_csi2_reset, ++ .lanes_enable = phy_qcom_mipi_csi2_lanes_enable, ++ .lanes_disable = phy_qcom_mipi_csi2_lanes_disable, ++}; ++ ++static const char * const x1e_clks[] = { ++ "core", ++ "timer", ++ "ahb" ++}; ++ ++static const char * const x1e_supplies[] = { ++ "vdda-0p9", ++ "vdda-1p2" ++}; ++ ++static struct mipi_csi2_genpd x1e_genpds[] = { ++ { .name = "top", .scaled = false }, ++ { .name = "mmcx", .scaled = true }, ++ { .name = "mx", .scaled = true }, ++}; ++ ++const struct mipi_csi2phy_soc_cfg mipi_csi2_dphy_4nm_x1e = { ++ .ops = &phy_qcom_mipi_csi2_ops_3ph_1_0, ++ .reg_info = { ++ .init_seq = lane_regs_x1e80100, ++ .lane_array_size = ARRAY_SIZE(lane_regs_x1e80100), ++ .common_regs_offset = 0x1000, ++ }, ++ .supply_names = (const char **)x1e_supplies, ++ .num_supplies = ARRAY_SIZE(x1e_supplies), ++ .clk_names = (const char **)x1e_clks, ++ .num_clk = ARRAY_SIZE(x1e_clks), ++ .genpds = x1e_genpds, ++ .num_genpds = ARRAY_SIZE(x1e_genpds), ++}; +diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c +new file mode 100644 +index 0000000000000000000000000000000000000000..c0a4fa20eaf0c87f6c18b35e625f5ba1769c94e7 +--- /dev/null ++++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-core.c +@@ -0,0 +1,463 @@ ++// SPDX-License-Identifier: GPL-2.0 ++/* ++ * Copyright (c) 2026, Linaro Ltd. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "phy-qcom-mipi-csi2.h" ++ ++static int ++phy_qcom_mipi_csi2_set_clock_rates(struct mipi_csi2phy_device *csi2phy, ++ s64 link_freq) ++{ ++ struct device *dev = csi2phy->dev; ++ unsigned long opp_rate = link_freq / 4; ++ struct dev_pm_opp *opp; ++ long timer_rate; ++ int i, pstate; ++ int ret; ++ ++ opp = dev_pm_opp_find_freq_ceil(dev, &opp_rate); ++ if (IS_ERR(opp)) { ++ dev_err(csi2phy->dev, "Couldn't find ceiling for %lld Hz\n", ++ link_freq); ++ return PTR_ERR(opp); ++ } ++ ++ pstate = 0; ++ for (i = 0; i < csi2phy->pd_list->num_pds; i++) { ++ unsigned int perf; ++ ++ if (!csi2phy->soc_cfg->genpds[i].scaled) ++ continue; ++ ++ perf = dev_pm_opp_get_required_pstate(opp, pstate); ++ pstate += 1; ++ ++ ret = dev_pm_genpd_set_performance_state(csi2phy->pd_list->pd_devs[i], perf); ++ if (ret) { ++ dev_err(csi2phy->dev, "Couldn't set perf state %u\n", ++ perf); ++ dev_pm_opp_put(opp); ++ goto unset_pstate; ++ } ++ } ++ dev_pm_opp_put(opp); ++ ++ ret = dev_pm_opp_set_rate(dev, opp_rate); ++ if (ret) { ++ dev_err(csi2phy->dev, "dev_pm_opp_set_rate() fail\n"); ++ goto unset_opp_rate; ++ } ++ ++ timer_rate = clk_round_rate(csi2phy->timer_clk, link_freq / 4); ++ if (timer_rate <= 0) { ++ ret = -ENODEV; ++ goto unset_opp_rate; ++ } ++ ++ ret = clk_set_rate(csi2phy->timer_clk, timer_rate); ++ if (ret) ++ goto unset_opp_rate; ++ ++ csi2phy->timer_clk_rate = timer_rate; ++ ++ return 0; ++ ++unset_opp_rate: ++ dev_pm_opp_set_rate(dev, 0); ++ ++unset_pstate: ++ while (i--) { ++ if (!csi2phy->soc_cfg->genpds[i].scaled) ++ continue; ++ ++ dev_pm_genpd_set_performance_state(csi2phy->pd_list->pd_devs[i], 0); ++ } ++ ++ return ret; ++} ++ ++static int phy_qcom_mipi_csi2_configure(struct phy *phy, ++ union phy_configure_opts *opts) ++{ ++ struct mipi_csi2phy_device *csi2phy = phy_get_drvdata(phy); ++ struct phy_configure_opts_mipi_dphy *dphy_cfg = &opts->mipi_dphy; ++ struct mipi_csi2phy_stream_cfg *stream_cfg = &csi2phy->stream_cfg; ++ int ret; ++ ++ ret = phy_mipi_dphy_config_validate(dphy_cfg); ++ if (ret) ++ return ret; ++ ++ if (dphy_cfg->lanes < 1 || dphy_cfg->lanes > CSI2_MAX_DATA_LANES) ++ return -EINVAL; ++ ++ if (dphy_cfg->lanes != stream_cfg->num_data_lanes) ++ return -EINVAL; ++ ++ stream_cfg->link_freq = dphy_cfg->hs_clk_rate; ++ ++ return 0; ++} ++ ++static int phy_qcom_mipi_csi2_set_mode(struct phy *phy, ++ enum phy_mode mode, int submode) ++{ ++ struct mipi_csi2phy_device *csi2phy = phy_get_drvdata(phy); ++ ++ if (mode != PHY_MODE_MIPI_DPHY) ++ return -EOPNOTSUPP; ++ ++ csi2phy->phy_mode = mode; ++ return 0; ++} ++ ++static int phy_qcom_mipi_csi2_power_on(struct phy *phy) ++{ ++ struct mipi_csi2phy_device *csi2phy = phy_get_drvdata(phy); ++ const struct mipi_csi2phy_hw_ops *ops = csi2phy->soc_cfg->ops; ++ int i, ret; ++ ++ ret = regulator_bulk_enable(csi2phy->soc_cfg->num_supplies, ++ csi2phy->supplies); ++ if (ret) ++ return ret; ++ ++ ret = pm_runtime_resume_and_get(csi2phy->dev); ++ if (ret < 0) ++ goto disable_regulators; ++ ++ ret = phy_qcom_mipi_csi2_set_clock_rates(csi2phy, csi2phy->stream_cfg.link_freq); ++ if (ret) ++ goto poweroff_phy; ++ ++ ret = clk_bulk_prepare_enable(csi2phy->soc_cfg->num_clk, ++ csi2phy->clks); ++ if (ret) { ++ dev_err(csi2phy->dev, "failed to enable clocks, %d\n", ret); ++ goto unset_rate; ++ } ++ ++ ops->reset(csi2phy); ++ ++ ops->hw_version_read(csi2phy); ++ ++ ret = ops->lanes_enable(csi2phy, &csi2phy->stream_cfg); ++ if (ret) ++ goto unset_clocks; ++ ++ return 0; ++ ++unset_clocks: ++ clk_bulk_disable_unprepare(csi2phy->soc_cfg->num_clk, ++ csi2phy->clks); ++ ++unset_rate: ++ dev_pm_opp_set_rate(csi2phy->dev, 0); ++ ++ for (i = 0; i < csi2phy->pd_list->num_pds; i++) { ++ if (!csi2phy->soc_cfg->genpds[i].scaled) ++ continue; ++ ++ dev_pm_genpd_set_performance_state(csi2phy->pd_list->pd_devs[i], 0); ++ } ++ ++poweroff_phy: ++ pm_runtime_put_sync(csi2phy->dev); ++ ++disable_regulators: ++ regulator_bulk_disable(csi2phy->soc_cfg->num_supplies, ++ csi2phy->supplies); ++ ++ return ret; ++} ++ ++static int phy_qcom_mipi_csi2_power_off(struct phy *phy) ++{ ++ struct mipi_csi2phy_device *csi2phy = phy_get_drvdata(phy); ++ const struct mipi_csi2phy_hw_ops *ops = csi2phy->soc_cfg->ops; ++ int i; ++ ++ ops->lanes_disable(csi2phy, &csi2phy->stream_cfg); ++ ++ clk_bulk_disable_unprepare(csi2phy->soc_cfg->num_clk, ++ csi2phy->clks); ++ ++ dev_pm_opp_set_rate(csi2phy->dev, 0); ++ ++ for (i = 0; i < csi2phy->pd_list->num_pds; i++) { ++ if (!csi2phy->soc_cfg->genpds[i].scaled) ++ continue; ++ ++ dev_pm_genpd_set_performance_state(csi2phy->pd_list->pd_devs[i], 0); ++ } ++ ++ pm_runtime_put_sync(csi2phy->dev); ++ ++ regulator_bulk_disable(csi2phy->soc_cfg->num_supplies, ++ csi2phy->supplies); ++ ++ return 0; ++} ++ ++static const struct phy_ops phy_qcom_mipi_csi2_ops = { ++ .configure = phy_qcom_mipi_csi2_configure, ++ .set_mode = phy_qcom_mipi_csi2_set_mode, ++ .power_on = phy_qcom_mipi_csi2_power_on, ++ .power_off = phy_qcom_mipi_csi2_power_off, ++ .owner = THIS_MODULE, ++}; ++ ++static int phy_qcom_mipi_csi2_attach_pm_domains(struct mipi_csi2phy_device *csi2phy) ++{ ++ struct dev_pm_domain_attach_data pd_data = { 0 }; ++ const char **pd_names; ++ int i; ++ ++ pd_names = devm_kzalloc(csi2phy->dev, ++ sizeof(char *) * csi2phy->soc_cfg->num_genpds, ++ GFP_KERNEL); ++ if (!pd_names) ++ return -ENOMEM; ++ ++ for (i = 0; i < csi2phy->soc_cfg->num_genpds; i++) ++ pd_names[i] = csi2phy->soc_cfg->genpds[i].name; ++ ++ pd_data.pd_names = pd_names; ++ pd_data.num_pd_names = csi2phy->soc_cfg->num_genpds; ++ ++ return devm_pm_domain_attach_list(csi2phy->dev, &pd_data, ++ &csi2phy->pd_list); ++} ++ ++static int phy_qcom_mipi_csi2_parse_routing(struct mipi_csi2phy_device *csi2phy) ++{ ++ struct mipi_csi2phy_stream_cfg *stream_cfg = &csi2phy->stream_cfg; ++ u32 lane_polarities[CSI2_MAX_DATA_LANES + 1]; ++ u32 data_lanes[CSI2_MAX_DATA_LANES]; ++ struct device *dev = csi2phy->dev; ++ struct fwnode_handle *ep; ++ int num_polarities; ++ int num_data_lanes; ++ u32 bus_type; ++ int i, ret; ++ ++ ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 1, 0); ++ if (ep) { ++ fwnode_handle_put(ep); ++ dev_err(dev, "DPHY split mode is not supported\n"); ++ return -EOPNOTSUPP; ++ } ++ ++ ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0); ++ if (!ep) { ++ dev_err(dev, "Missing port@0\n"); ++ return -ENODEV; ++ } ++ ++ /* bus-type is optional, D-PHY is the default */ ++ bus_type = MEDIA_BUS_TYPE_CSI2_DPHY; ++ fwnode_property_read_u32(ep, "bus-type", &bus_type); ++ ++ if (bus_type != MEDIA_BUS_TYPE_CSI2_DPHY) { ++ ret = -EOPNOTSUPP; ++ dev_err(dev, "Unsupported bus-type %u\n", bus_type); ++ goto out_put; ++ } ++ ++ num_data_lanes = fwnode_property_count_u32(ep, "data-lanes"); ++ if (num_data_lanes < 1 || num_data_lanes > CSI2_MAX_DATA_LANES) { ++ ret = -EINVAL; ++ dev_err(dev, "Invalid data-lanes count: %d\n", num_data_lanes); ++ goto out_put; ++ } ++ stream_cfg->num_data_lanes = num_data_lanes; ++ ++ ret = fwnode_property_read_u32_array(ep, "data-lanes", data_lanes, ++ stream_cfg->num_data_lanes); ++ if (ret) { ++ dev_err(dev, "Failed to read data-lanes: %d\n", ret); ++ goto out_put; ++ } ++ ++ /* lane-polarities: optional, up to num_data_lanes + 1 entries */ ++ memset(lane_polarities, 0x00, sizeof(lane_polarities)); ++ num_polarities = fwnode_property_count_u32(ep, "lane-polarities"); ++ if (num_polarities > 0) { ++ if (num_polarities != stream_cfg->num_data_lanes + 1) { ++ ret = -EINVAL; ++ dev_err(dev, "clock+data-lane %d/polarities %d mismatch\n", ++ stream_cfg->num_data_lanes + 1, num_polarities); ++ goto out_put; ++ } ++ ++ ret = fwnode_property_read_u32_array(ep, "lane-polarities", lane_polarities, ++ num_polarities); ++ if (ret) { ++ dev_err(dev, "Failed to read lane-polarities: %d\n", ret); ++ goto out_put; ++ } ++ } ++ ++ csi2phy->stream_cfg.lane_cfg.clk.pos = CSI2_DEFAULT_CLK_LANE; ++ csi2phy->stream_cfg.lane_cfg.clk.pol = lane_polarities[0]; ++ ++ for (i = 0; i < csi2phy->stream_cfg.num_data_lanes; i++) { ++ if (data_lanes[i] < 1 || data_lanes[i] > CSI2_MAX_DATA_LANES) { ++ dev_err(dev, "Invalid lane %d\n", data_lanes[i]); ++ ret = -EINVAL; ++ goto out_put; ++ } ++ ++ /* Convert data-lanes = <1 2 3 4> to bit positions */ ++ csi2phy->stream_cfg.lane_cfg.data[i].pos = data_lanes[i] - 1; ++ csi2phy->stream_cfg.lane_cfg.data[i].pol = lane_polarities[i + 1]; ++ } ++ ++ ret = 0; ++ ++out_put: ++ fwnode_handle_put(ep); ++ ++ return ret; ++} ++ ++static int phy_qcom_mipi_csi2_probe(struct platform_device *pdev) ++{ ++ unsigned int i, num_clk, num_supplies; ++ struct mipi_csi2phy_device *csi2phy; ++ struct phy_provider *phy_provider; ++ struct device *dev = &pdev->dev; ++ struct phy *generic_phy; ++ int ret; ++ ++ csi2phy = devm_kzalloc(dev, sizeof(*csi2phy), GFP_KERNEL); ++ if (!csi2phy) ++ return -ENOMEM; ++ ++ csi2phy->dev = dev; ++ dev_set_drvdata(dev, csi2phy); ++ ++ csi2phy->soc_cfg = device_get_match_data(&pdev->dev); ++ ++ if (!csi2phy->soc_cfg) ++ return -EINVAL; ++ ++ num_clk = csi2phy->soc_cfg->num_clk; ++ ++ ret = phy_qcom_mipi_csi2_parse_routing(csi2phy); ++ if (ret) ++ return ret; ++ ++ ret = phy_qcom_mipi_csi2_attach_pm_domains(csi2phy); ++ if (ret < 0 || csi2phy->pd_list == NULL) { ++ if (ret == 0) ++ ret = -ENODEV; ++ return dev_err_probe(dev, ret, "Failed to attach power-domain list\n"); ++ } ++ ++ ret = devm_pm_runtime_enable(dev); ++ if (ret < 0) ++ return dev_err_probe(dev, ret, "Failed to enable pm runtime\n"); ++ ++ ret = devm_clk_bulk_get_all(dev, &csi2phy->clks); ++ if (ret < 0) ++ return dev_err_probe(dev, ret, "Failed to get clocks\n"); ++ ++ if (num_clk != ret) { ++ return dev_err_probe(dev, -ENODEV, "clock count %d expected %d\n", ++ ret, num_clk); ++ } ++ ++ for (i = 0; i < num_clk; i++) { ++ if (!csi2phy->clks[i].id) ++ return dev_err_probe(dev, -EINVAL, "Missing clock-names\n"); ++ ++ if (!strcmp(csi2phy->clks[i].id, "timer")) { ++ csi2phy->timer_clk = csi2phy->clks[i].clk; ++ break; ++ } ++ } ++ if (!csi2phy->timer_clk) ++ return dev_err_probe(dev, -ENODEV, "no timer clock\n"); ++ ++ ret = devm_pm_opp_set_clkname(dev, "core"); ++ if (ret) ++ return dev_err_probe(dev, ret, "Failed to set opp clkname\n"); ++ ++ ret = devm_pm_opp_of_add_table(dev); ++ if (ret) ++ return dev_err_probe(dev, ret, "invalid OPP table in device tree\n"); ++ ++ num_supplies = csi2phy->soc_cfg->num_supplies; ++ csi2phy->supplies = devm_kzalloc(dev, sizeof(*csi2phy->supplies) * num_supplies, ++ GFP_KERNEL); ++ if (!csi2phy->supplies) ++ return -ENOMEM; ++ ++ for (i = 0; i < num_supplies; i++) ++ csi2phy->supplies[i].supply = csi2phy->soc_cfg->supply_names[i]; ++ ++ ret = devm_regulator_bulk_get(dev, num_supplies, csi2phy->supplies); ++ if (ret) ++ return dev_err_probe(dev, ret, ++ "failed to get regulator supplies\n"); ++ ++ csi2phy->base = devm_platform_ioremap_resource(pdev, 0); ++ if (IS_ERR(csi2phy->base)) ++ return PTR_ERR(csi2phy->base); ++ ++ generic_phy = devm_phy_create(dev, NULL, &phy_qcom_mipi_csi2_ops); ++ if (IS_ERR(generic_phy)) { ++ ret = PTR_ERR(generic_phy); ++ return dev_err_probe(dev, ret, "failed to create phy\n"); ++ } ++ csi2phy->phy = generic_phy; ++ ++ phy_set_drvdata(generic_phy, csi2phy); ++ ++ phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); ++ if (!IS_ERR(phy_provider)) ++ dev_dbg(dev, "Registered MIPI CSI2 PHY device\n"); ++ ++ return PTR_ERR_OR_ZERO(phy_provider); ++} ++ ++static const struct of_device_id phy_qcom_mipi_csi2_of_match_table[] = { ++ { .compatible = "qcom,x1e80100-csi2-phy", .data = &mipi_csi2_dphy_4nm_x1e }, ++ { } ++}; ++MODULE_DEVICE_TABLE(of, phy_qcom_mipi_csi2_of_match_table); ++ ++static struct platform_driver phy_qcom_mipi_csi2_driver = { ++ .probe = phy_qcom_mipi_csi2_probe, ++ .driver = { ++ .name = "qcom-mipi-csi2-phy", ++ .of_match_table = phy_qcom_mipi_csi2_of_match_table, ++ }, ++}; ++ ++module_platform_driver(phy_qcom_mipi_csi2_driver); ++ ++MODULE_DESCRIPTION("Qualcomm MIPI CSI2 PHY driver"); ++MODULE_AUTHOR("Bryan O'Donoghue "); ++MODULE_LICENSE("GPL"); +diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h b/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h +new file mode 100644 +index 0000000000000000000000000000000000000000..7e55ae00737047f2d0384728a9c98780851eec05 +--- /dev/null ++++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2.h +@@ -0,0 +1,97 @@ ++/* SPDX-License-Identifier: GPL-2.0 */ ++/* ++ * ++ * Qualcomm MIPI CSI2 CPHY/DPHY driver ++ * ++ * Copyright (C) 2025 Linaro Ltd. ++ */ ++#ifndef __PHY_QCOM_MIPI_CSI2_H__ ++#define __PHY_QCOM_MIPI_CSI2_H__ ++ ++#include ++ ++#define CSI2_MAX_DATA_LANES 4 ++#define CSI2_DEFAULT_CLK_LANE 7 ++ ++struct mipi_csi2phy_lane { ++ u8 pos; ++ u8 pol; ++}; ++ ++struct mipi_csi2phy_lanes_cfg { ++ struct mipi_csi2phy_lane data[CSI2_MAX_DATA_LANES]; ++ struct mipi_csi2phy_lane clk; ++}; ++ ++struct mipi_csi2phy_stream_cfg { ++ s64 link_freq; ++ u8 num_data_lanes; ++ struct mipi_csi2phy_lanes_cfg lane_cfg; ++}; ++ ++struct mipi_csi2phy_device; ++ ++struct mipi_csi2phy_hw_ops { ++ void (*hw_version_read)(struct mipi_csi2phy_device *csi2phy_dev); ++ void (*reset)(struct mipi_csi2phy_device *csi2phy_dev); ++ int (*lanes_enable)(struct mipi_csi2phy_device *csi2phy_dev, ++ struct mipi_csi2phy_stream_cfg *cfg); ++ void (*lanes_disable)(struct mipi_csi2phy_device *csi2phy_dev, ++ struct mipi_csi2phy_stream_cfg *cfg); ++}; ++ ++struct mipi_csi2phy_lane_regs { ++ const s32 reg_addr; ++ const s32 reg_data; ++ const u32 delay_us; ++ const u32 param_type; ++}; ++ ++struct mipi_csi2phy_device_regs { ++ const struct mipi_csi2phy_lane_regs *init_seq; ++ const int lane_array_size; ++ const u32 common_regs_offset; ++}; ++ ++struct mipi_csi2_genpd { ++ const char *name; ++ bool scaled; ++}; ++ ++struct mipi_csi2phy_soc_cfg { ++ const struct mipi_csi2phy_hw_ops *ops; ++ const struct mipi_csi2phy_device_regs reg_info; ++ ++ const char ** const supply_names; ++ const unsigned int num_supplies; ++ ++ const char ** const clk_names; ++ const unsigned int num_clk; ++ ++ const struct mipi_csi2_genpd *genpds; ++ const unsigned int num_genpds; ++}; ++ ++struct mipi_csi2phy_device { ++ struct device *dev; ++ u8 phy_mode; ++ ++ struct phy *phy; ++ void __iomem *base; ++ ++ struct clk_bulk_data *clks; ++ struct clk *timer_clk; ++ u32 timer_clk_rate; ++ ++ struct regulator_bulk_data *supplies; ++ struct dev_pm_domain_list *pd_list; ++ ++ const struct mipi_csi2phy_soc_cfg *soc_cfg; ++ struct mipi_csi2phy_stream_cfg stream_cfg; ++ ++ u32 hw_version; ++}; ++ ++extern const struct mipi_csi2phy_soc_cfg mipi_csi2_dphy_4nm_x1e; ++ ++#endif /* __PHY_QCOM_MIPI_CSI2_H__ */ +diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c +index a57c594bf039e862d477462636c6f1d537ec247f..208db6c16c711e99a2fd354cb21602059d94cf69 100644 +--- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c ++++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c +@@ -2675,6 +2675,10 @@ struct qmp_combo { + + struct mutex phy_mutex; + int init_count; ++ unsigned long vregs_enabled; ++ bool clks_enabled; ++ bool pipe_clk_enabled; ++ bool reset_pending; + enum qmpphy_mode qmpphy_mode; + + struct phy *usb_phy; +@@ -4244,13 +4248,24 @@ static int qmp_v8_configure_dp_phy(struct qmp_combo *qmp) + return 0; + } + ++static bool qmp_combo_com_ready(struct qmp_combo *qmp) ++{ ++ return qmp->com_powered_on && qmp->clks_enabled && qmp->pipe_clk_enabled && ++ qmp->vregs_enabled == GENMASK(qmp->cfg->num_vregs - 1, 0); ++} ++ + static int qmp_combo_dp_configure(struct phy *phy, union phy_configure_opts *opts) + { + const struct phy_configure_opts_dp *dp_opts = &opts->dp; + struct qmp_combo *qmp = phy_get_drvdata(phy); + const struct qmp_phy_cfg *cfg = qmp->cfg; ++ int ret = 0; + + mutex_lock(&qmp->phy_mutex); ++ if (!qmp_combo_com_ready(qmp)) { ++ ret = -EIO; ++ goto out_unlock; ++ } + + memcpy(&qmp->dp_opts, dp_opts, sizeof(*dp_opts)); + if (qmp->dp_opts.set_voltages) { +@@ -4260,9 +4275,10 @@ static int qmp_combo_dp_configure(struct phy *phy, union phy_configure_opts *opt + qmp->dp_opts.set_voltages = 0; + } + ++out_unlock: + mutex_unlock(&qmp->phy_mutex); + +- return 0; ++ return ret; + } + + static int qmp_combo_dp_calibrate(struct phy *phy) +@@ -4272,15 +4288,22 @@ static int qmp_combo_dp_calibrate(struct phy *phy) + int ret = 0; + + mutex_lock(&qmp->phy_mutex); ++ if (!qmp_combo_com_ready(qmp)) { ++ ret = -EIO; ++ goto out_unlock; ++ } + + if (qmp->qmpphy_mode != QMPPHY_MODE_USB4 && cfg->calibrate_dp_phy) + ret = cfg->calibrate_dp_phy(qmp); + ++out_unlock: + mutex_unlock(&qmp->phy_mutex); + + return ret; + } + ++static int qmp_combo_com_exit(struct qmp_combo *qmp, bool force); ++ + static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) + { + const struct qmp_phy_cfg *cfg = qmp->cfg; +@@ -4289,7 +4312,7 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) + void __iomem *pcs = qmp->pcs; + void __iomem *com = qmp->com; + void __iomem *aon_toggle; +- int ret; ++ int ret, cleanup_ret, i; + u32 val, usb4_mode = USB4_MODE; + + if (!force && qmp->init_count++ && qmp->com_powered_on) +@@ -4312,33 +4335,38 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) + dp_reset_val &= ~SW_DPPHY_RESET_MUX; + } + +- ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs); +- if (ret) { +- dev_err(qmp->dev, "failed to enable regulators, err=%d\n", ret); +- goto err_decrement_count; ++ for (i = 0; i < cfg->num_vregs; i++) { ++ if (qmp->vregs_enabled & BIT(i)) ++ continue; ++ ret = regulator_enable(qmp->vregs[i].consumer); ++ if (ret) ++ goto error; ++ qmp->vregs_enabled |= BIT(i); + } + ++ /* A failed bulk reset may also fail its rollback. */ ++ qmp->reset_pending = true; + ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets); +- if (ret) { +- dev_err(qmp->dev, "reset assert failed\n"); +- goto err_disable_regulators; +- } ++ if (ret) ++ goto error; + + ret = reset_control_bulk_deassert(cfg->num_resets, qmp->resets); +- if (ret) { +- dev_err(qmp->dev, "reset deassert failed\n"); +- goto err_disable_regulators; +- } +- +- ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks); + if (ret) +- goto err_assert_reset; ++ goto error; + +- /* In DP-only mode, the pipe clk is still required for USB2 */ +- ret = clk_prepare_enable(qmp->pipe_clk); +- if (ret) { +- dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret); +- goto err_disable_clocks; ++ if (!qmp->clks_enabled) { ++ ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks); ++ if (ret) ++ goto error; ++ qmp->clks_enabled = true; ++ } ++ ++ /* In DP-only mode, the pipe clk is still required for USB2. */ ++ if (!qmp->pipe_clk_enabled) { ++ ret = clk_prepare_enable(qmp->pipe_clk); ++ if (ret) ++ goto error; ++ qmp->pipe_clk_enabled = true; + } + + qphy_setbits(com, QPHY_V3_DP_COM_POWER_DOWN_CTRL, SW_PWRDN); +@@ -4417,13 +4445,11 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) + qmp->com_powered_on = true; + return 0; + +-err_disable_clocks: +- clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); +-err_assert_reset: +- reset_control_bulk_assert(cfg->num_resets, qmp->resets); +-err_disable_regulators: +- regulator_bulk_disable(cfg->num_vregs, qmp->vregs); +-err_decrement_count: ++error: ++ qmp->com_powered_on = false; ++ cleanup_ret = qmp_combo_com_exit(qmp, true); ++ if (cleanup_ret) ++ dev_err(qmp->dev, "common init cleanup failed: %d\n", cleanup_ret); + if (!force) + qmp->init_count--; + +@@ -4433,21 +4459,45 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) + static int qmp_combo_com_exit(struct qmp_combo *qmp, bool force) + { + const struct qmp_phy_cfg *cfg = qmp->cfg; ++ int ret, i; + +- if (!force && --qmp->init_count) +- return 0; ++ if (!force) { ++ if (!qmp->init_count) ++ return -EINVAL; ++ if (qmp->init_count > 1) { ++ qmp->init_count--; ++ return 0; ++ } ++ } + +- if (!qmp->com_powered_on) +- return 0; + qmp->com_powered_on = false; ++ if (qmp->reset_pending) { ++ ret = reset_control_bulk_assert(cfg->num_resets, qmp->resets); ++ if (ret) ++ return ret; ++ qmp->reset_pending = false; ++ } + +- reset_control_bulk_assert(cfg->num_resets, qmp->resets); +- +- clk_disable_unprepare(qmp->pipe_clk); +- clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); ++ if (qmp->pipe_clk_enabled) { ++ clk_disable_unprepare(qmp->pipe_clk); ++ qmp->pipe_clk_enabled = false; ++ } ++ if (qmp->clks_enabled) { ++ clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); ++ qmp->clks_enabled = false; ++ } + +- regulator_bulk_disable(cfg->num_vregs, qmp->vregs); ++ for (i = cfg->num_vregs - 1; i >= 0; i--) { ++ if (!(qmp->vregs_enabled & BIT(i))) ++ continue; ++ ret = regulator_disable(qmp->vregs[i].consumer); ++ if (ret) ++ return ret; ++ qmp->vregs_enabled &= ~BIT(i); ++ } + ++ if (!force) ++ qmp->init_count--; + return 0; + } + +@@ -4475,16 +4525,24 @@ static int qmp_combo_dp_init(struct phy *phy) + static int qmp_combo_dp_exit(struct phy *phy) + { + struct qmp_combo *qmp = phy_get_drvdata(phy); ++ int ret; + + mutex_lock(&qmp->phy_mutex); ++ if (!qmp->dp_init_count || !qmp->init_count || qmp->dp_powered_on) { ++ ret = -EBUSY; ++ goto out_unlock; ++ } + +- qmp_combo_com_exit(qmp, false); ++ ret = qmp_combo_com_exit(qmp, false); ++ if (ret) ++ goto out_unlock; + + qmp->dp_init_count--; + ++out_unlock: + mutex_unlock(&qmp->phy_mutex); + +- return 0; ++ return ret; + } + + static int qmp_combo_dp_power_on(struct phy *phy) +@@ -4497,6 +4555,10 @@ static int qmp_combo_dp_power_on(struct phy *phy) + int ret = 0; + + mutex_lock(&qmp->phy_mutex); ++ if (!qmp_combo_com_ready(qmp)) { ++ ret = -EIO; ++ goto out_unlock; ++ } + + /* + * DisplayPort tunneling: while the PHY is in USB4 mode the lanes +@@ -4552,6 +4614,7 @@ static int qmp_combo_dp_power_on(struct phy *phy) + ret = cfg->configure_dp_phy(qmp); + if (ret) { + dev_err(qmp->dev, "DP PHY configuration failed: %d\n", ret); ++ writel(DP_PHY_PD_CTL_PSR_PWRDN, qmp->dp_dp_phy + QSERDES_DP_PHY_PD_CTL); + goto out_unlock; + } + +@@ -4569,10 +4632,10 @@ static int qmp_combo_dp_power_off(struct phy *phy) + mutex_lock(&qmp->phy_mutex); + + /* Assert DP PHY power down */ +- if (qmp->com_powered_on) ++ if (qmp_combo_com_ready(qmp)) + writel(DP_PHY_PD_CTL_PSR_PWRDN, qmp->dp_dp_phy + QSERDES_DP_PHY_PD_CTL); + +- if (qmp->qmpphy_mode == QMPPHY_MODE_USB4 && qmp->com_powered_on) ++ if (qmp->qmpphy_mode == QMPPHY_MODE_USB4 && qmp_combo_com_ready(qmp)) + qphy_clrbits(qmp->com, QPHY_V3_DP_COM_PHY_MODE_CTRL, + DP_TUNNELING_CLOCK_GEN_EN); + +@@ -4701,6 +4764,8 @@ static int qmp_v8_configure_usb4_phy(struct qmp_combo *qmp) + return qmp_v8_usb4_calibrate(qmp); + } + ++static int qmp_combo_usb_power_off(struct phy *phy); ++ + static int qmp_combo_usb_power_on(struct phy *phy) + { + struct qmp_combo *qmp = phy_get_drvdata(phy); +@@ -4721,6 +4786,9 @@ static int qmp_combo_usb_power_on(struct phy *phy) + unsigned int val; + int ret; + ++ if (!qmp_combo_com_ready(qmp)) ++ return -EIO; ++ + if (qmp->qmpphy_mode == QMPPHY_MODE_USB4 && cfg->configure_usb4_phy) + return cfg->configure_usb4_phy(qmp); + +@@ -4785,6 +4853,7 @@ static int qmp_combo_usb_power_on(struct phy *phy) + PHY_INIT_COMPLETE_TIMEOUT); + if (ret) { + dev_err(qmp->dev, "phy initialization timed-out\n"); ++ qmp_combo_usb_power_off(phy); + return ret; + } + +@@ -4803,6 +4872,9 @@ static int qmp_combo_usb_power_off(struct phy *phy) + if (qmp->usb4_init_count) + pcs = qmp->usb4_pcs; + ++ if (!qmp->clks_enabled || !qmp->pipe_clk_enabled) ++ return 0; ++ + /* PHY reset */ + qphy_setbits(pcs, cfg->regs[QPHY_SW_RESET], SW_RESET); + +@@ -4820,7 +4892,7 @@ static int qmp_combo_usb_power_off(struct phy *phy) + static int qmp_combo_usb_init(struct phy *phy) + { + struct qmp_combo *qmp = phy_get_drvdata(phy); +- int ret; ++ int ret, cleanup_ret; + + guard(mutex)(&qmp->phy_mutex); + +@@ -4837,7 +4909,11 @@ static int qmp_combo_usb_init(struct phy *phy) + + ret = qmp_combo_usb_power_on(phy); + if (ret) { +- qmp_combo_com_exit(qmp, false); ++ cleanup_ret = qmp_combo_com_exit(qmp, false); ++ if (cleanup_ret) { ++ qmp->init_count--; ++ dev_err(qmp->dev, "USB init cleanup failed: %d\n", cleanup_ret); ++ } + return ret; + } + +@@ -4877,25 +4953,32 @@ static int qmp_combo_usb_set_mode(struct phy *phy, enum phy_mode mode, int submo + { + struct qmp_combo *qmp = phy_get_drvdata(phy); + ++ mutex_lock(&qmp->phy_mutex); + qmp->phy_mode = mode; ++ mutex_unlock(&qmp->phy_mutex); + + return 0; + } + +-static int qmp_combo_reconfigure_phy(struct qmp_combo *qmp, enum qmpphy_mode new_mode) ++static int qmp_combo_apply_mode(struct qmp_combo *qmp, enum qmpphy_mode new_mode) + { + int ret; + + dev_dbg(qmp->dev, "qmp_combo_reconfigure_phy: switching from qmpphy mode %d to %d\n", + qmp->qmpphy_mode, new_mode); + +- if (qmp->usb_init_count || qmp->usb4_init_count) +- qmp_combo_usb_power_off(qmp->usb_phy); ++ if (qmp->usb_init_count || qmp->usb4_init_count) { ++ ret = qmp_combo_usb_power_off(qmp->usb_phy); ++ if (ret) ++ return ret; ++ } + + if (qmp->dp_init_count && qmp->com_powered_on) + writel(DP_PHY_PD_CTL_PSR_PWRDN, qmp->dp_dp_phy + QSERDES_DP_PHY_PD_CTL); + +- qmp_combo_com_exit(qmp, true); ++ ret = qmp_combo_com_exit(qmp, true); ++ if (ret) ++ return ret; + + qmp->qmpphy_mode = new_mode; + +@@ -4922,6 +5005,30 @@ static int qmp_combo_reconfigure_phy(struct qmp_combo *qmp, enum qmpphy_mode new + return 0; + } + ++static int qmp_combo_reconfigure_phy(struct qmp_combo *qmp, ++ enum typec_orientation orientation, ++ enum qmpphy_mode new_mode) ++{ ++ enum qmpphy_mode old_mode = qmp->qmpphy_mode; ++ enum typec_orientation old_orientation = qmp->orientation; ++ int ret, rollback_ret; ++ ++ qmp->orientation = orientation; ++ ret = qmp_combo_apply_mode(qmp, new_mode); ++ if (!ret) ++ return 0; ++ ++ qmp->orientation = old_orientation; ++ rollback_ret = qmp_combo_apply_mode(qmp, old_mode); ++ qmp->qmpphy_mode = old_mode; ++ if (rollback_ret) { ++ qmp->com_powered_on = false; ++ dev_err(qmp->dev, "Type-C rollback failed: %d (request: %d)\n", ++ rollback_ret, ret); ++ } ++ return ret; ++} ++ + static int qmp_combo_usb4_init(struct phy *phy) + { + struct qmp_combo *qmp = phy_get_drvdata(phy); +@@ -4953,7 +5060,7 @@ static int qmp_combo_usb4_init(struct phy *phy) + } + + /* USB4 mode takes precedence to USB3(+DP), force reconfigure the PHY */ +- ret = qmp_combo_reconfigure_phy(qmp, QMPPHY_MODE_USB4); ++ ret = qmp_combo_reconfigure_phy(qmp, qmp->orientation, QMPPHY_MODE_USB4); + if (ret) + goto err_restore; + +@@ -4971,9 +5078,13 @@ static int qmp_combo_usb4_init(struct phy *phy) + return 0; + + err_restore: +- qmp_combo_com_exit(qmp, false); ++ restore_ret = qmp_combo_com_exit(qmp, false); ++ if (restore_ret) { ++ qmp->init_count--; ++ dev_err(qmp->dev, "USB4 init cleanup failed: %d\n", restore_ret); ++ } + if (qmp->init_count) { +- restore_ret = qmp_combo_reconfigure_phy(qmp, old_mode); ++ restore_ret = qmp_combo_reconfigure_phy(qmp, qmp->orientation, old_mode); + if (restore_ret) + dev_err(qmp->dev, "failed to restore native PHY: %d\n", restore_ret); + } else { +@@ -5034,7 +5145,7 @@ static int qmp_combo_usb4_exit(struct phy *phy) + return 0; + } + +- ret = qmp_combo_reconfigure_phy(qmp, qmp->typec_mode); ++ ret = qmp_combo_reconfigure_phy(qmp, qmp->orientation, qmp->typec_mode); + if (ret) + dev_err(qmp->dev, "failed to restore Type-C mode %d: %d\n", + qmp->typec_mode, ret); +@@ -5173,9 +5284,11 @@ static int __maybe_unused qmp_combo_runtime_suspend(struct device *dev) + { + struct qmp_combo *qmp = dev_get_drvdata(dev); + ++ guard(mutex)(&qmp->phy_mutex); ++ + dev_vdbg(dev, "Suspending QMP phy, mode:%d\n", qmp->phy_mode); + +- if (!qmp->init_count) { ++ if (!qmp_combo_com_ready(qmp)) { + dev_vdbg(dev, "PHY not initialized, bailing out\n"); + return 0; + } +@@ -5193,7 +5306,9 @@ static int __maybe_unused qmp_combo_runtime_suspend(struct device *dev) + qmp_combo_enable_autonomous_mode(qmp); + + clk_disable_unprepare(qmp->pipe_clk); ++ qmp->pipe_clk_enabled = false; + clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); ++ qmp->clks_enabled = false; + + return 0; + } +@@ -5201,29 +5316,35 @@ static int __maybe_unused qmp_combo_runtime_suspend(struct device *dev) + static int __maybe_unused qmp_combo_runtime_resume(struct device *dev) + { + struct qmp_combo *qmp = dev_get_drvdata(dev); ++ bool new_clks = false; + int ret = 0; + +- dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->phy_mode); +- +- if (!qmp->init_count) { +- dev_vdbg(dev, "PHY not initialized, bailing out\n"); +- return 0; ++ mutex_lock(&qmp->phy_mutex); ++ if (!qmp->com_powered_on || !qmp->init_count || ++ qmp->vregs_enabled != GENMASK(qmp->cfg->num_vregs - 1, 0)) ++ goto out_unlock; ++ if (!qmp->clks_enabled) { ++ ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks); ++ if (ret) ++ goto out_unlock; ++ qmp->clks_enabled = true; ++ new_clks = true; + } +- +- ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks); +- if (ret) +- return ret; +- +- ret = clk_prepare_enable(qmp->pipe_clk); +- if (ret) { +- dev_err(dev, "pipe_clk enable failed, err=%d\n", ret); +- clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); +- return ret; ++ if (!qmp->pipe_clk_enabled) { ++ ret = clk_prepare_enable(qmp->pipe_clk); ++ if (ret) { ++ if (new_clks) { ++ clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks); ++ qmp->clks_enabled = false; ++ } ++ goto out_unlock; ++ } ++ qmp->pipe_clk_enabled = true; + } +- + qmp_combo_disable_autonomous_mode(qmp); +- +- return 0; ++out_unlock: ++ mutex_unlock(&qmp->phy_mutex); ++ return ret; + } + + /* +@@ -5571,23 +5692,34 @@ static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) + { + struct qmp_combo *qmp = typec_switch_get_drvdata(sw); ++ int ret; + ++ ret = pm_runtime_resume_and_get(qmp->dev); ++ if (ret < 0) ++ return ret; ++ ++ mutex_lock(&qmp->phy_mutex); ++ ret = 0; + if (qmp->qmpphy_mode == QMPPHY_MODE_USB4) { +- /* QMPPHY has no orientation handling in USB4 mode, don't cache the setting */ + qmp->orientation = TYPEC_ORIENTATION_NONE; +- return 0; ++ goto out_unlock; ++ } ++ if (orientation == TYPEC_ORIENTATION_NONE || ++ (orientation == qmp->orientation && qmp_combo_com_ready(qmp))) ++ goto out_unlock; ++ if (qmp->dp_powered_on) { ++ ret = -EBUSY; ++ goto out_unlock; + } +- +- if (orientation == qmp->orientation || orientation == TYPEC_ORIENTATION_NONE) +- return 0; +- +- guard(mutex)(&qmp->phy_mutex); +- qmp->orientation = orientation; +- + if (qmp->init_count) +- return qmp_combo_reconfigure_phy(qmp, qmp->qmpphy_mode); ++ ret = qmp_combo_reconfigure_phy(qmp, orientation, qmp->qmpphy_mode); ++ else ++ qmp->orientation = orientation; + +- return 0; ++out_unlock: ++ mutex_unlock(&qmp->phy_mutex); ++ pm_runtime_put(qmp->dev); ++ return ret; + } + + static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) +@@ -5595,8 +5727,14 @@ static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_s + struct qmp_combo *qmp = typec_mux_get_drvdata(mux); + enum qmpphy_mode new_mode; + unsigned int svid; ++ int ret; + +- guard(mutex)(&qmp->phy_mutex); ++ ret = pm_runtime_resume_and_get(qmp->dev); ++ if (ret < 0) ++ return ret; ++ ++ mutex_lock(&qmp->phy_mutex); ++ ret = 0; + + if (state->alt) + svid = state->alt->svid; +@@ -5609,7 +5747,7 @@ static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_s + * lacking USB4 support. + */ + if (svid == USB_TYPEC_TBT_SID || (!state->alt && state->mode == TYPEC_MODE_USB4)) +- return 0; ++ goto out_unlock; + + if (svid == USB_TYPEC_DP_SID) { + switch (state->mode) { +@@ -5648,25 +5786,30 @@ static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_s + if (qmp->usb4_init_count) { + qmp->typec_mode = new_mode; + qmp->typec_mode_pending = true; +- return 0; ++ goto out_unlock; + } + qmp->typec_mode_pending = false; + +- if (new_mode == qmp->qmpphy_mode && qmp->com_powered_on) { ++ if (new_mode == qmp->qmpphy_mode && qmp_combo_com_ready(qmp)) { + dev_dbg(qmp->dev, "typec_mux_set: same qmpphy mode, bail out\n"); +- return 0; ++ goto out_unlock; + } + + if (qmp->qmpphy_mode != QMPPHY_MODE_USB3_ONLY && qmp->dp_powered_on) { + dev_dbg(qmp->dev, "typec_mux_set: DP PHY is still in use, delaying switch\n"); +- return 0; ++ goto out_unlock; + } + + /* The mux still receives Type-C events, even if all PHYs are uninitialized */ + if (!qmp->init_count) +- return 0; ++ goto out_unlock; ++ ++ ret = qmp_combo_reconfigure_phy(qmp, qmp->orientation, new_mode); + +- return qmp_combo_reconfigure_phy(qmp, new_mode); ++out_unlock: ++ mutex_unlock(&qmp->phy_mutex); ++ pm_runtime_put(qmp->dev); ++ return ret; + } + + static void qmp_combo_typec_switch_unregister(void *data) +@@ -6067,12 +6210,8 @@ static int qmp_combo_probe(struct platform_device *pdev) + + qmp->qmpphy_mode = QMPPHY_MODE_USB3DP; + +- if (of_property_present(dev->of_node, "mode-switch") || +- of_property_present(dev->of_node, "orientation-switch")) { +- ret = qmp_combo_typec_register(qmp); +- if (ret) +- goto err_node_put; +- } else { ++ if (!of_property_present(dev->of_node, "mode-switch") && ++ !of_property_present(dev->of_node, "orientation-switch")) { + enum typec_orientation dp_orientation = TYPEC_ORIENTATION_NONE; + enum typec_orientation usb3_orientation = TYPEC_ORIENTATION_NONE; + +@@ -6171,6 +6310,13 @@ static int qmp_combo_probe(struct platform_device *pdev) + goto err_pm_put; + } + ++ if (of_property_present(dev->of_node, "mode-switch") || ++ of_property_present(dev->of_node, "orientation-switch")) { ++ ret = qmp_combo_typec_register(qmp); ++ if (ret) ++ goto err_pm_put; ++ } ++ + of_node_put(usb_np); + of_node_put(dp_np); + +diff --git a/drivers/platform/arm64/Kconfig b/drivers/platform/arm64/Kconfig +index 7d882af9e612d21ea6ad000b5f47e5b697a61d7c..9a4c143d25ea5178989632693d03d2bbcd6ded32 100644 +--- a/drivers/platform/arm64/Kconfig ++++ b/drivers/platform/arm64/Kconfig +@@ -50,6 +50,20 @@ config EC_ACER_ASPIRE1 + laptop where this information is not properly exposed via the + standard ACPI devices. + ++config EC_ASUS_GLYMUR ++ tristate "ASUS Zenbook A16 (Qualcomm) Embedded Controller driver" ++ depends on ARCH_QCOM || COMPILE_TEST ++ depends on I2C ++ depends on HWMON ++ depends on INPUT ++ depends on PM ++ depends on THERMAL || THERMAL=n ++ help ++ Say M or Y here to enable the EC driver for the Qualcomm Snapdragon- ++ based ASUS Zenbook A16 (UX3607OA) and similar machines. It provides ++ temperature sensors readout, fan monitoring, and EC event ++ reporting. ++ + config EC_HUAWEI_GAOKUN + tristate "Huawei Matebook E Go Embedded Controller driver" + depends on ARCH_QCOM || COMPILE_TEST +diff --git a/drivers/platform/arm64/Makefile b/drivers/platform/arm64/Makefile +index 848bb289e24b6c20448610a526195e11ffab3398..ed841758fc3ea462a9f1cc13aa8293ac4e606e9e 100644 +--- a/drivers/platform/arm64/Makefile ++++ b/drivers/platform/arm64/Makefile +@@ -7,6 +7,7 @@ + + obj-$(CONFIG_DELL_ARM64_HOTKEYS) += dell-arm64-hotkeys.o + obj-$(CONFIG_EC_ACER_ASPIRE1) += acer-aspire1-ec.o ++obj-$(CONFIG_EC_ASUS_GLYMUR) += asus-glymur-ec.o + obj-$(CONFIG_EC_HUAWEI_GAOKUN) += huawei-gaokun-ec.o + obj-$(CONFIG_EC_LENOVO_YOGA_C630) += lenovo-yoga-c630.o + obj-$(CONFIG_EC_LENOVO_THINKPAD_T14S) += lenovo-thinkpad-t14s.o +diff --git a/drivers/platform/arm64/asus-glymur-ec.c b/drivers/platform/arm64/asus-glymur-ec.c +new file mode 100644 +index 0000000000000000000000000000000000000000..889752f71c221f117b49e1673df13c96539ef066 +--- /dev/null ++++ b/drivers/platform/arm64/asus-glymur-ec.c +@@ -0,0 +1,600 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* ++ * The EC firmware on the ASUS Zenbook A16 looks to be derived from the ++ * 'Qualcomm Hamoa EC' reference base with many major modifications. Some of ++ * the original interface is reused, albeit many of its core invariants (such ++ * as the capabilities bitmap) are absent. ++ * ++ * It presents itself as two I2C devices: ++ * [0x5b] is the custom ASUS interface ++ * [0x76] is the Hamoa EC-derived interface ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++/* Qualcomm-derived registers (main device @ 0x76) */ ++#define ASUS_QCOM_EC_EVENT_CMD 0x05 ++ #define ASUS_QCOM_EC_EVENT_NONE 0x00 ++ #define ASUS_QCOM_EC_EVENT_INVALID 0xff ++ ++#define ASUS_QCOM_EC_SUBCMD_FULL_VER 0x0f ++#define ASUS_QCOM_EC_FULL_VER_LEN 7 ++ ++/* This "read RAM" command isn't actually part of the Qualcomm standard */ ++#define ASUS_QCOM_EC_RECM_OFFS 0x52 ++#define ASUS_QCOM_EC_RECM_FRAME_LEN 5 ++ ++#define ASUS_QCOM_EC_RAM_FAN_CPU 0x0602 ++#define ASUS_QCOM_EC_RAM_AC_STATUS 0x0609 ++#define ASUS_QCOM_EC_RAM_FAN_GPU 0x0624 ++ ++#define ASUS_QCOM_EC_MODERN_STANDBY_CMD 0x23 ++#define ASUS_QCOM_EC_MODERN_STANDBY_ENTER 0x07 ++#define ASUS_QCOM_EC_MODERN_STANDBY_EXIT 0x08 ++ ++#define ASUS_QCOM_EC_FAN_PROFILE_CMD 0x24 ++ ++/* ASUS-specific registers (secondary device @ 0x5b) */ ++#define ASUS_EC_SUBDEV_ADDR 0x5b ++ ++#define ASUS_EC_REQ_REG 0x10 ++#define ASUS_EC_RESP_REG 0x11 ++ ++#define ASUS_EC_PAGE_MAILBOX 0xc4 ++ #define ASUS_EC_MBOX_REG_CMD 0x30 ++ #define ASUS_EC_MBOX_REG_SUBCMD 0x31 ++ #define ASUS_EC_MBOX_REG_DATA 0x32 ++ ++#define ASUS_EC_MBOX_CMD_MISC 0x02 ++ #define ASUS_EC_MBOX_SUBCMD_MISC_ENABLE 0x83 ++ ++#define ASUS_EC_PAGE_TEMPERATURE 0xc6 ++ #define ASUS_EC_TEMP_REG_CPU 0xa6 ++ #define ASUS_EC_TEMP_REG_SOC 0x2a ++ #define ASUS_EC_TEMP_MAX 0x7f ++ ++enum asus_ec_event { ++ ASUS_EC_EVT_CHARGE_STATE = 0x1c, ++ ASUS_EC_EVT_AC_STATE = 0x1d, ++ ASUS_EC_EVT_CRIT_TRIP = 0x1e, ++ ASUS_EC_EVT_THERMISTOR = 0x4f, ++ ASUS_EC_EVT_HOTKEY = 0xda, ++ ASUS_EC_EVT_FAN_STATUS = 0xdb, ++ ASUS_EC_EVT_THERMAL_TRIP = 0xe0, ++ ASUS_EC_EVT_CHARGE_COMMIT = 0xe4, ++}; ++ ++/* Opt-in firmware profile IDs from UX3607OA BIOS 312 IC10._DSM. */ ++static int fan_profile = -1; ++module_param(fan_profile, int, 0444); ++MODULE_PARM_DESC(fan_profile, "A16 EC fan profile ID 0..3; -1 leaves firmware policy unchanged"); ++ ++struct asus_ec { ++ struct i2c_client *client; ++ struct i2c_client *subdev_client; ++ /* Serializes all EC access across both I2C devices */ ++ struct mutex lock; ++ struct device *hwmon_dev; ++}; ++ ++static int asus_qcom_ec_write(struct asus_ec *ec, u8 offset, ++ const u8 *buf, u8 len) ++{ ++ int ret; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ ret = i2c_smbus_write_i2c_block_data(ec->client, offset, len, buf); ++ if (ret < 0) { ++ dev_dbg(&ec->client->dev, ++ "Main device write off %#x len %u failed: %d\n", ++ offset, len, ret); ++ } ++ ++ return ret; ++} ++ ++static int asus_qcom_ec_read(struct asus_ec *ec, u8 offset, u8 *buf, u8 len) ++{ ++ int ret; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ ret = i2c_smbus_read_i2c_block_data(ec->client, offset, len, buf); ++ if (ret < 0) ++ return ret; ++ if (ret < len) { ++ dev_err(&ec->client->dev, ++ "Short read off %#x: got %d of %u bytes\n", ++ offset, ret, len); ++ return -EIO; ++ } ++ ++ return 0; ++} ++ ++static int asus_qcom_ec_read_ram(struct asus_ec *ec, u16 addr, u8 count, u16 *out) ++{ ++ u8 frame[ASUS_QCOM_EC_RECM_FRAME_LEN] = { 0, 0, count, 0, 0 }; ++ u8 resp[ASUS_QCOM_EC_RECM_FRAME_LEN] = { }; ++ int ret; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ if (count != 1 && count != 2) ++ return -EINVAL; ++ ++ put_unaligned_be16(addr, frame); ++ ++ ret = asus_qcom_ec_write(ec, ASUS_QCOM_EC_RECM_OFFS, frame, ++ ASUS_QCOM_EC_RECM_FRAME_LEN); ++ if (ret < 0) ++ return ret; ++ ++ ret = asus_qcom_ec_read(ec, ASUS_QCOM_EC_RECM_OFFS, resp, ++ ASUS_QCOM_EC_RECM_FRAME_LEN); ++ if (ret < 0) ++ return ret; ++ ++ *out = (count == 2) ? get_unaligned_le16(resp) : resp[0]; ++ ++ return 0; ++} ++ ++static int asus_ec_readb(struct asus_ec *ec, u8 page, u8 reg, u8 *out) ++{ ++ u8 sel[2] = { page, reg }; ++ int ret; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ ret = i2c_smbus_write_i2c_block_data(ec->subdev_client, ASUS_EC_REQ_REG, ++ sizeof(sel), sel); ++ if (ret < 0) ++ return ret; ++ ++ ret = i2c_smbus_read_byte_data(ec->subdev_client, ASUS_EC_RESP_REG); ++ if (ret < 0) ++ return ret; ++ ++ *out = ret; ++ ++ return 0; ++} ++ ++static int asus_ec_writeb(struct asus_ec *ec, u8 page, u8 reg, u8 data) ++{ ++ u8 sel[2] = { page, reg }; ++ int ret; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ ret = i2c_smbus_write_i2c_block_data(ec->subdev_client, ASUS_EC_REQ_REG, ++ sizeof(sel), sel); ++ if (ret < 0) ++ return ret; ++ ++ return i2c_smbus_write_byte_data(ec->subdev_client, ++ ASUS_EC_RESP_REG, data); ++} ++ ++static int asus_ec_wait_mailbox(struct asus_ec *ec) ++{ ++ int ret, tries; ++ u8 status; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ for (tries = 5; tries > 0; tries--) { ++ ret = asus_ec_readb(ec, ASUS_EC_PAGE_MAILBOX, ++ ASUS_EC_MBOX_REG_CMD, &status); ++ if (ret < 0) ++ return ret; ++ if (!status) ++ return 0; ++ usleep_range(5000, 6000); ++ } ++ ++ return -ETIMEDOUT; ++} ++ ++static int asus_ec_mailbox_cmd(struct asus_ec *ec, u8 cmd, u8 sub, u8 data) ++{ ++ int ret; ++ ++ lockdep_assert_held(&ec->lock); ++ ++ ret = asus_ec_wait_mailbox(ec); ++ if (ret < 0) ++ return ret == -ETIMEDOUT ? -EBUSY : ret; ++ ++ ret = asus_ec_writeb(ec, ASUS_EC_PAGE_MAILBOX, ASUS_EC_MBOX_REG_SUBCMD, sub); ++ if (ret < 0) ++ return ret; ++ ++ ret = asus_ec_writeb(ec, ASUS_EC_PAGE_MAILBOX, ASUS_EC_MBOX_REG_DATA, data); ++ if (ret < 0) ++ return ret; ++ ++ ret = asus_ec_writeb(ec, ASUS_EC_PAGE_MAILBOX, ASUS_EC_MBOX_REG_CMD, cmd); ++ if (ret < 0) ++ return ret; ++ ++ return asus_ec_wait_mailbox(ec); ++} ++ ++static int asus_ec_enable_writes(struct asus_ec *ec) ++{ ++ guard(mutex)(&ec->lock); ++ ++ return asus_ec_mailbox_cmd(ec, ASUS_EC_MBOX_CMD_MISC, ++ ASUS_EC_MBOX_SUBCMD_MISC_ENABLE, 1); ++} ++ ++static int asus_ec_apply_fan_profile(struct asus_ec *ec) ++{ ++ struct device *dev = &ec->client->dev; ++ int ret; ++ ++ if (fan_profile == -1) ++ return 0; ++ if (fan_profile < 0 || fan_profile > 3) ++ return -EINVAL; ++ if (!of_device_is_compatible(dev->of_node, "asus,zenbook-a16-ux3607oa-ec")) ++ return -EOPNOTSUPP; ++ ++ guard(mutex)(&ec->lock); ++ ++ /* BIOS 312 uses AttribByte at offset 0x24, not a block/PWM command. */ ++ ret = i2c_smbus_write_byte_data(ec->client, ++ ASUS_QCOM_EC_FAN_PROFILE_CMD, fan_profile); ++ if (ret < 0) ++ return ret; ++ ++ dev_info(dev, "Requested EC fan profile %d\n", fan_profile); ++ return 0; ++} ++ ++static int asus_ec_read_version(struct asus_ec *ec, u8 *major, u8 *minor, u8 *patch) ++{ ++ u8 resp[ASUS_QCOM_EC_FULL_VER_LEN + 1]; ++ int ret; ++ ++ guard(mutex)(&ec->lock); ++ ++ ret = asus_qcom_ec_read(ec, ASUS_QCOM_EC_SUBCMD_FULL_VER, ++ resp, sizeof(resp)); ++ if (ret < 0) ++ return ret; ++ if (resp[0] < ASUS_QCOM_EC_FULL_VER_LEN) ++ return -EIO; ++ ++ *major = resp[3]; ++ *minor = resp[2]; ++ *patch = resp[1]; ++ ++ return 0; ++} ++ ++static int asus_ec_get_temp(struct asus_ec *ec, u8 reg, long *millideg) ++{ ++ u8 raw; ++ int ret; ++ ++ guard(mutex)(&ec->lock); ++ ++ ret = asus_ec_readb(ec, ASUS_EC_PAGE_TEMPERATURE, reg, &raw); ++ if (ret < 0) ++ return ret; ++ if (raw > ASUS_EC_TEMP_MAX) ++ return -ENODATA; ++ ++ *millideg = raw * MILLIDEGREE_PER_DEGREE; ++ ++ return 0; ++} ++ ++static int asus_ec_get_fan_rpm(struct asus_ec *ec, u16 base, long *rpm) ++{ ++ u16 val; ++ int ret; ++ ++ guard(mutex)(&ec->lock); ++ ++ ret = asus_qcom_ec_read_ram(ec, base, 2, &val); ++ if (ret < 0) ++ return ret; ++ ++ *rpm = val; ++ ++ return 0; ++} ++ ++static irqreturn_t asus_ec_irq(int irq, void *data) ++{ ++ struct asus_ec *ec = data; ++ struct device *dev = &ec->client->dev; ++ int code; ++ ++ scoped_guard(mutex, &ec->lock) ++ code = i2c_smbus_read_byte_data(ec->client, ASUS_QCOM_EC_EVENT_CMD); ++ ++ if (code < 0) { ++ dev_err_ratelimited(dev, "Failed to read EC event: %d\n", code); ++ return IRQ_HANDLED; ++ } ++ if (code == ASUS_QCOM_EC_EVENT_NONE || ++ code == ASUS_QCOM_EC_EVENT_INVALID) ++ return IRQ_HANDLED; ++ ++ switch (code) { ++ case ASUS_EC_EVT_HOTKEY: ++ /* Present in DSDT, don't know what triggers it */ ++ dev_dbg_ratelimited(dev, "EC hotkey event\n"); ++ break; ++ ++ case ASUS_EC_EVT_FAN_STATUS: ++ dev_dbg_ratelimited(dev, "Fan status changed\n"); ++ break; ++ ++ /* Maybe the temperature of the EC itself? */ ++ case ASUS_EC_EVT_THERMAL_TRIP: ++ case ASUS_EC_EVT_CRIT_TRIP: ++ /* ASUS_EC_TEMP_SOC climbing above 91 *C or falling below 92 *C */ ++ case ASUS_EC_EVT_THERMISTOR: ++ dev_dbg_ratelimited(dev, "Thermal event %#x\n", code); ++ break; ++ ++ case ASUS_EC_EVT_AC_STATE: { ++ u16 ac = 0; ++ int ret; ++ ++ /* TODO: ping SoCCP over the pmic_glink OEM-specific interface */ ++ scoped_guard(mutex, &ec->lock) ++ ret = asus_qcom_ec_read_ram(ec, ASUS_QCOM_EC_RAM_AC_STATUS, 1, &ac); ++ if (ret < 0) { ++ dev_warn_ratelimited(dev, ++ "Failed to read AC status: %d\n", ++ ret); ++ } else { ++ dev_dbg_ratelimited(dev, "AC event: 0x%x\n", ac); ++ } ++ break; ++ } ++ case ASUS_EC_EVT_CHARGE_STATE: ++ case ASUS_EC_EVT_CHARGE_COMMIT: ++ break; ++ ++ default: ++ dev_info_ratelimited(dev, "unknown EC event: %#x\n", code); ++ break; ++ } ++ ++ return IRQ_HANDLED; ++} ++ ++enum asus_ec_temp_channel { ++ /* External sensor? */ ++ ASUS_EC_TEMP_CPU, ++ /* Likely SoC-internal temp data communicated over a side channel */ ++ ASUS_EC_TEMP_SOC, ++ ASUS_EC_TEMP_COUNT, ++}; ++ ++static umode_t asus_ec_hwmon_is_visible(const void *data, ++ enum hwmon_sensor_types type, ++ u32 attr, int channel) ++{ ++ switch (type) { ++ case hwmon_fan: ++ case hwmon_temp: ++ return 0444; ++ default: ++ return 0; ++ } ++} ++ ++static int asus_ec_hwmon_read(struct device *dev, ++ enum hwmon_sensor_types type, ++ u32 attr, int channel, long *val) ++{ ++ struct asus_ec *ec = dev_get_drvdata(dev); ++ ++ switch (type) { ++ case hwmon_temp: ++ switch (channel) { ++ case ASUS_EC_TEMP_CPU: ++ return asus_ec_get_temp(ec, ASUS_EC_TEMP_REG_CPU, val); ++ case ASUS_EC_TEMP_SOC: ++ return asus_ec_get_temp(ec, ASUS_EC_TEMP_REG_SOC, val); ++ default: ++ return -EINVAL; ++ } ++ case hwmon_fan: ++ switch (channel) { ++ case 0: ++ return asus_ec_get_fan_rpm(ec, ASUS_QCOM_EC_RAM_FAN_CPU, val); ++ case 1: ++ return asus_ec_get_fan_rpm(ec, ASUS_QCOM_EC_RAM_FAN_GPU, val); ++ default: ++ return -EINVAL; ++ } ++ default: ++ return -EINVAL; ++ } ++} ++ ++static int asus_ec_hwmon_read_string(struct device *dev, ++ enum hwmon_sensor_types type, ++ u32 attr, int channel, const char **str) ++{ ++ if (type != hwmon_temp || channel >= ASUS_EC_TEMP_COUNT) ++ return -EINVAL; ++ ++ switch (channel) { ++ case ASUS_EC_TEMP_CPU: ++ *str = "CPU"; ++ break; ++ case ASUS_EC_TEMP_SOC: ++ *str = "SoC"; ++ break; ++ } ++ ++ return 0; ++} ++ ++static const struct hwmon_channel_info * const asus_ec_hwmon_info[] = { ++ HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ), ++ HWMON_CHANNEL_INFO(temp, ++ HWMON_T_INPUT | HWMON_T_LABEL, ++ HWMON_T_INPUT | HWMON_T_LABEL), ++ HWMON_CHANNEL_INFO(fan, ++ HWMON_F_INPUT, ++ HWMON_F_INPUT), ++ NULL ++}; ++ ++static const struct hwmon_ops asus_ec_hwmon_ops = { ++ .is_visible = asus_ec_hwmon_is_visible, ++ .read = asus_ec_hwmon_read, ++ .read_string = asus_ec_hwmon_read_string, ++}; ++ ++static const struct hwmon_chip_info asus_ec_hwmon_chip_info = { ++ .ops = &asus_ec_hwmon_ops, ++ .info = asus_ec_hwmon_info, ++}; ++ ++static int asus_glymur_ec_probe(struct i2c_client *client) ++{ ++ struct device *dev = &client->dev; ++ u8 major, minor, patch; ++ struct asus_ec *ec; ++ int ret; ++ ++ ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); ++ if (!ec) ++ return -ENOMEM; ++ ++ ec->client = client; ++ i2c_set_clientdata(client, ec); ++ ++ ret = devm_mutex_init(dev, &ec->lock); ++ if (ret) ++ return ret; ++ ++ ec->subdev_client = devm_i2c_new_dummy_device(dev, client->adapter, ++ ASUS_EC_SUBDEV_ADDR); ++ if (IS_ERR(ec->subdev_client)) { ++ return dev_err_probe(dev, PTR_ERR(ec->subdev_client), ++ "Failed to register 0x5b EC device\n"); ++ } ++ ++ ret = asus_ec_enable_writes(ec); ++ if (ret < 0) ++ return dev_err_probe(dev, ret, "Failed to enable EC direct access: %d\n", ret); ++ ++ ret = asus_ec_read_version(ec, &major, &minor, &patch); ++ if (ret < 0) ++ return dev_err_probe(dev, ret, "Failed to read EC version: %d\n", ret); ++ ++ dev_dbg(dev, "ASUS Zenbook EC version %u.%u.%u\n", major, minor, patch); ++ ++ ret = asus_ec_apply_fan_profile(ec); ++ if (ret < 0) ++ dev_warn(dev, "EC fan profile request failed: %d\n", ret); ++ ++ ret = devm_request_threaded_irq(dev, client->irq, NULL, asus_ec_irq, ++ IRQF_ONESHOT, dev_name(dev), ec); ++ if (ret) ++ return dev_err_probe(dev, ret, "Failed to request IRQ\n"); ++ ++ ec->hwmon_dev = devm_hwmon_device_register_with_info(dev, ++ "asus_glymur_ec", ++ ec, ++ &asus_ec_hwmon_chip_info, ++ NULL); ++ if (IS_ERR(ec->hwmon_dev)) { ++ return dev_err_probe(dev, PTR_ERR(ec->hwmon_dev), ++ "Failed to register hwmon\n"); ++ } ++ ++ return 0; ++} ++ ++static int asus_glymur_ec_modern_standby(struct asus_ec *ec, u8 val) ++{ ++ guard(mutex)(&ec->lock); ++ ++ return i2c_smbus_write_byte_data(ec->client, ++ ASUS_QCOM_EC_MODERN_STANDBY_CMD, val); ++} ++ ++static int asus_glymur_ec_suspend(struct device *dev) ++{ ++ return asus_glymur_ec_modern_standby(dev_get_drvdata(dev), ++ ASUS_QCOM_EC_MODERN_STANDBY_ENTER); ++} ++ ++static int asus_glymur_ec_resume(struct device *dev) ++{ ++ struct asus_ec *ec = dev_get_drvdata(dev); ++ int ret; ++ ++ ret = asus_glymur_ec_modern_standby(ec, ASUS_QCOM_EC_MODERN_STANDBY_EXIT); ++ if (ret < 0) ++ return ret; ++ ++ ret = asus_ec_apply_fan_profile(ec); ++ if (ret < 0) ++ dev_warn(dev, "EC fan profile request failed after resume: %d\n", ret); ++ ++ return 0; ++} ++ ++static DEFINE_SIMPLE_DEV_PM_OPS(asus_glymur_ec_pm_ops, ++ asus_glymur_ec_suspend, ++ asus_glymur_ec_resume); ++ ++static const struct of_device_id asus_glymur_ec_of_match[] = { ++ { .compatible = "asus,zenbook-a14-ux3407na-ec" }, ++ { .compatible = "asus,zenbook-a16-ux3607oa-ec" }, ++ {} ++}; ++MODULE_DEVICE_TABLE(of, asus_glymur_ec_of_match); ++ ++static const struct i2c_device_id asus_glymur_ec_id[] = { ++ { "asus-glymur-ec" }, ++ {} ++}; ++MODULE_DEVICE_TABLE(i2c, asus_glymur_ec_id); ++ ++static struct i2c_driver asus_glymur_ec_driver = { ++ .driver = { ++ .name = "asus-glymur-ec", ++ .of_match_table = asus_glymur_ec_of_match, ++ .pm = pm_sleep_ptr(&asus_glymur_ec_pm_ops), ++ }, ++ .probe = asus_glymur_ec_probe, ++ .id_table = asus_glymur_ec_id, ++}; ++module_i2c_driver(asus_glymur_ec_driver); ++ ++MODULE_DESCRIPTION("ASUS Zenbook A16 (Qualcomm) Embedded Controller driver"); ++MODULE_LICENSE("GPL"); +diff --git a/drivers/regulator/qcom-rpmh-regulator.c b/drivers/regulator/qcom-rpmh-regulator.c +index 25c14de3cd8b5e77b48f168d1afa0f3ad7ab9d5e..a967b41358329b4ac468cd302e8e7e61b0daa163 100644 +--- a/drivers/regulator/qcom-rpmh-regulator.c ++++ b/drivers/regulator/qcom-rpmh-regulator.c +@@ -1663,6 +1663,9 @@ static const struct rpmh_vreg_init_data pmh0104_vreg_data[] = { + RPMH_VREG("smps2", SMPS, 2, &pmic5_ftsmps530, "vdd-s2"), + RPMH_VREG("smps3", SMPS, 3, &pmic5_ftsmps530, "vdd-s3"), + RPMH_VREG("smps4", SMPS, 4, &pmic5_ftsmps530, "vdd-s4"), ++ RPMH_VREG("ldo3", LDO, 3, &pmic5_nldo530, "vdd-l3"), ++ RPMH_VREG("ldo4", LDO, 4, &pmic5_nldo530, "vdd-l4"), ++ RPMH_VREG("ldo7", LDO, 7, &pmic5_pldo530_mvp150, "vdd-l7"), + {} + }; + +diff --git a/drivers/remoteproc/qcom_q6v5.c b/drivers/remoteproc/qcom_q6v5.c +index fe148b4b3775fc98f3ea86fed60a6eb495bb5a0a..71b79ab827e636a0b1a97c55d70366a2c76b7764 100644 +--- a/drivers/remoteproc/qcom_q6v5.c ++++ b/drivers/remoteproc/qcom_q6v5.c +@@ -372,9 +372,11 @@ int qcom_q6v5_init(struct qcom_q6v5 *q6v5, struct platform_device *pdev, + } + + q6v5->path = devm_of_icc_get(&pdev->dev, NULL); +- if (IS_ERR(q6v5->path)) ++ if (IS_ERR(q6v5->path)) { ++ qmp_put(q6v5->qmp); + return dev_err_probe(&pdev->dev, PTR_ERR(q6v5->path), + "failed to acquire interconnect path\n"); ++ } + + return 0; + } +diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c +index 61e1038328e839ecfeae7f61a813d162dcf52c2b..1e6d6608bce39a1bc97f8a7ea1c8417dd338b552 100644 +--- a/drivers/remoteproc/qcom_sysmon.c ++++ b/drivers/remoteproc/qcom_sysmon.c +@@ -739,7 +739,7 @@ bool qcom_sysmon_shutdown_irq_state(struct qcom_sysmon *sysmon) + bool shutdown_state; + int ret; + +- if (!sysmon) ++ if (!sysmon || sysmon->shutdown_irq < 0) + return false; + + ret = irq_get_irqchip_state(sysmon->shutdown_irq, +diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c +index e624f848c22b5799d23107518bbfd01b2e93d150..3d2f644957c13cd8ab6e1e1b2fdcefc8c5a204a8 100644 +--- a/drivers/rtc/rtc-pm8xxx.c ++++ b/drivers/rtc/rtc-pm8xxx.c +@@ -587,6 +587,7 @@ static int pm8xxx_rtc_probe_offset(struct pm8xxx_rtc *rtc_dd) + + dev_warn(rtc_dd->dev, "efivars not available\n"); + rtc_dd->use_uefi = false; ++ return 0; + } + + return pm8xxx_rtc_read_uefi_offset(rtc_dd); +diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c +index 3042261578aad8dcb45e8803fd2ffb249aeace26..84fd0c82c0c4dbad468acbdd6713086334d5f49c 100644 +--- a/drivers/soc/qcom/pmic_glink.c ++++ b/drivers/soc/qcom/pmic_glink.c +@@ -250,7 +250,8 @@ static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev) + guard(mutex)(&__pmic_glink_lock); + pg = __pmic_glink; + if (!pg) +- return dev_err_probe(&rpdev->dev, -ENODEV, "no pmic_glink device to attach to\n"); ++ return dev_err_probe(&rpdev->dev, -EPROBE_DEFER, ++ "no pmic_glink device to attach to\n"); + + dev_set_drvdata(&rpdev->dev, pg); + pg->pdr_available = rpdev->id.driver_data; +diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c +index a9568b941ebce74e103c6335e23ed1785048ff0f..0450ffc8b25beb38612a03e526f12ea5da9e54be 100644 +--- a/drivers/soc/qcom/pmic_glink_altmode.c ++++ b/drivers/soc/qcom/pmic_glink_altmode.c +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -105,15 +106,25 @@ struct pmic_glink_altmode; + + #define work_to_altmode_port(w) container_of((w), struct pmic_glink_altmode_port, work) + ++struct pmic_glink_altmode_state { ++ bool legacy; ++ enum typec_orientation orientation; ++ u16 svid; ++ struct usbc_sc8280x_tbt_data tbt_data; ++ u8 dp_data; ++ u8 mode; ++ u8 hpd_state; ++ u8 hpd_irq; ++ u8 mux_ctrl; ++}; ++ + struct pmic_glink_altmode_port { + struct pmic_glink_altmode *altmode; + unsigned int index; + + struct typec_switch *typec_switch; + struct typec_mux *typec_mux; +- struct typec_mux_state state; + struct typec_retimer *typec_retimer; +- struct typec_retimer_state retimer_state; + struct typec_altmode dp_alt; + struct typec_altmode tbt_alt; + +@@ -121,14 +132,9 @@ struct pmic_glink_altmode_port { + + struct auxiliary_device *bridge; + +- enum typec_orientation orientation; +- u16 svid; +- struct usbc_sc8280x_tbt_data tbt_data; +- u8 dp_data; +- u8 mode; +- u8 hpd_state; +- u8 hpd_irq; +- u8 mux_ctrl; ++ spinlock_t state_lock; ++ struct pmic_glink_altmode_state pending; ++ unsigned long generation; + }; + + #define work_to_altmode(w) container_of((w), struct pmic_glink_altmode, enable_work) +@@ -183,11 +189,13 @@ static int pmic_glink_altmode_request(struct pmic_glink_altmode *altmode, u32 cm + return 0; + } + +-static void pmic_glink_altmode_enable_dp(struct pmic_glink_altmode *altmode, ++static int pmic_glink_altmode_enable_dp(struct pmic_glink_altmode *altmode, + struct pmic_glink_altmode_port *port, + u8 mode, bool hpd_state, + bool hpd_irq) + { ++ struct typec_mux_state mux_state = {}; ++ struct typec_retimer_state retimer_state = {}; + struct typec_displayport_data dp_data = {}; + int ret; + +@@ -198,27 +206,33 @@ static void pmic_glink_altmode_enable_dp(struct pmic_glink_altmode *altmode, + dp_data.status |= DP_STATUS_IRQ_HPD; + dp_data.conf = DP_CONF_SET_PIN_ASSIGN(mode); + +- port->state.alt = &port->dp_alt; +- port->state.data = &dp_data; +- port->state.mode = TYPEC_MODAL_STATE(mode); ++ mux_state.alt = &port->dp_alt; ++ mux_state.data = &dp_data; ++ mux_state.mode = TYPEC_MODAL_STATE(mode); + +- ret = typec_mux_set(port->typec_mux, &port->state); +- if (ret) ++ ret = typec_mux_set(port->typec_mux, &mux_state); ++ if (ret) { + dev_err(altmode->dev, "failed to switch mux to DP: %d\n", ret); ++ return ret; ++ } + +- port->retimer_state.alt = &port->dp_alt; +- port->retimer_state.data = &dp_data; +- port->retimer_state.mode = TYPEC_MODAL_STATE(mode); ++ retimer_state.alt = &port->dp_alt; ++ retimer_state.data = &dp_data; ++ retimer_state.mode = TYPEC_MODAL_STATE(mode); + +- ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); ++ ret = typec_retimer_set(port->typec_retimer, &retimer_state); + if (ret) + dev_err(altmode->dev, "failed to setup retimer to DP: %d\n", ret); ++ ++ return ret; + } + +-static void pmic_glink_altmode_enable_tbt(struct pmic_glink_altmode *altmode, +- struct pmic_glink_altmode_port *port) ++static int pmic_glink_altmode_enable_tbt(struct pmic_glink_altmode *altmode, ++ struct pmic_glink_altmode_port *port, ++ const struct usbc_sc8280x_tbt_data *tbt, u8 mode) + { +- struct usbc_sc8280x_tbt_data *tbt = &port->tbt_data; ++ struct typec_mux_state mux_state = {}; ++ struct typec_retimer_state retimer_state = {}; + struct typec_thunderbolt_data tbt_data = {}; + u32 cable_speed, cable_flags = 0; + int ret; +@@ -236,7 +250,7 @@ static void pmic_glink_altmode_enable_tbt(struct pmic_glink_altmode *altmode, + break; + default: + dev_err(altmode->dev, "Invalid TBT3 cable type: %u\n", tbt->cable_type); +- return; ++ return -EINVAL; + } + + /* Device Discover Mode VDO */ +@@ -252,7 +266,7 @@ static void pmic_glink_altmode_enable_tbt(struct pmic_glink_altmode *altmode, + cable_speed = TBT_CABLE_10_AND_20GBPS; + } else { + dev_err(altmode->dev, "Invalid TBT3 cable speed: %u\n", tbt->usb_speed); +- return; ++ return -EINVAL; + } + tbt_data.cable_mode |= TBT_SET_CABLE_SPEED(cable_speed); + +@@ -270,27 +284,33 @@ static void pmic_glink_altmode_enable_tbt(struct pmic_glink_altmode *altmode, + tbt_data.enter_vdo |= TBT_SET_CABLE_ROUNDED(tbt->rounded_cable); + } + +- port->state.alt = &port->tbt_alt; +- port->state.data = &tbt_data; +- port->state.mode = TYPEC_MODAL_STATE(port->mode); ++ mux_state.alt = &port->tbt_alt; ++ mux_state.data = &tbt_data; ++ mux_state.mode = TYPEC_MODAL_STATE(mode); + +- ret = typec_mux_set(port->typec_mux, &port->state); +- if (ret) ++ ret = typec_mux_set(port->typec_mux, &mux_state); ++ if (ret) { + dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); ++ return ret; ++ } + +- port->retimer_state.alt = &port->tbt_alt; +- port->retimer_state.data = &tbt_data; +- port->retimer_state.mode = TYPEC_MODAL_STATE(port->mode); ++ retimer_state.alt = &port->tbt_alt; ++ retimer_state.data = &tbt_data; ++ retimer_state.mode = TYPEC_MODAL_STATE(mode); + +- ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); ++ ret = typec_retimer_set(port->typec_retimer, &retimer_state); + if (ret) + dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); ++ ++ return ret; + } + +-static void pmic_glink_altmode_enable_usb4(struct pmic_glink_altmode *altmode, +- struct pmic_glink_altmode_port *port) ++static int pmic_glink_altmode_enable_usb4(struct pmic_glink_altmode *altmode, ++ struct pmic_glink_altmode_port *port, ++ const struct usbc_sc8280x_tbt_data *tbt) + { +- struct usbc_sc8280x_tbt_data *tbt = &port->tbt_data; ++ struct typec_mux_state mux_state = {}; ++ struct typec_retimer_state retimer_state = {}; + struct enter_usb_data data = {}; + int ret; + +@@ -302,122 +322,147 @@ static void pmic_glink_altmode_enable_usb4(struct pmic_glink_altmode *altmode, + data.eudo |= FIELD_PREP(EUDO_CABLE_SPEED_MASK, EUDO_CABLE_SPEED_USB4_GEN3); + } else { + dev_err(altmode->dev, "Invalid USB4 cable speed: %u\n", tbt->usb_speed); +- return; ++ return -EINVAL; + } + + if (tbt->cable_type > EUDO_CABLE_TYPE_OPTICAL) { + dev_err(altmode->dev, "Invalid USB4 cable type: %u\n", tbt->cable_type); +- return; ++ return -EINVAL; + } + + data.eudo |= FIELD_PREP(EUDO_CABLE_TYPE_MASK, tbt->cable_type); + +- port->state.alt = NULL; +- port->state.data = &data; +- port->state.mode = TYPEC_MODE_USB4; ++ mux_state.alt = NULL; ++ mux_state.data = &data; ++ mux_state.mode = TYPEC_MODE_USB4; + +- ret = typec_mux_set(port->typec_mux, &port->state); +- if (ret) ++ ret = typec_mux_set(port->typec_mux, &mux_state); ++ if (ret) { + dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); ++ return ret; ++ } + +- port->retimer_state.alt = NULL; +- port->retimer_state.data = &data; +- port->retimer_state.mode = TYPEC_MODE_USB4; ++ retimer_state.alt = NULL; ++ retimer_state.data = &data; ++ retimer_state.mode = TYPEC_MODE_USB4; + +- ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); ++ ret = typec_retimer_set(port->typec_retimer, &retimer_state); + if (ret) + dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); ++ ++ return ret; + } + +-static void pmic_glink_altmode_enable_usb(struct pmic_glink_altmode *altmode, ++static int pmic_glink_altmode_enable_usb(struct pmic_glink_altmode *altmode, + struct pmic_glink_altmode_port *port) + { ++ struct typec_mux_state mux_state = {}; ++ struct typec_retimer_state retimer_state = {}; + int ret; + +- port->state.alt = NULL; +- port->state.data = NULL; +- port->state.mode = TYPEC_STATE_USB; ++ mux_state.alt = NULL; ++ mux_state.data = NULL; ++ mux_state.mode = TYPEC_STATE_USB; + +- ret = typec_mux_set(port->typec_mux, &port->state); +- if (ret) ++ ret = typec_mux_set(port->typec_mux, &mux_state); ++ if (ret) { + dev_err(altmode->dev, "failed to switch mux to USB: %d\n", ret); ++ return ret; ++ } + +- port->retimer_state.alt = NULL; +- port->retimer_state.data = NULL; +- port->retimer_state.mode = TYPEC_STATE_USB; ++ retimer_state.alt = NULL; ++ retimer_state.data = NULL; ++ retimer_state.mode = TYPEC_STATE_USB; + +- ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); ++ ret = typec_retimer_set(port->typec_retimer, &retimer_state); + if (ret) + dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); ++ ++ return ret; + } + +-static void pmic_glink_altmode_safe(struct pmic_glink_altmode *altmode, ++static int pmic_glink_altmode_safe(struct pmic_glink_altmode *altmode, + struct pmic_glink_altmode_port *port) + { ++ struct typec_mux_state mux_state = {}; ++ struct typec_retimer_state retimer_state = {}; + int ret; + +- port->state.alt = NULL; +- port->state.data = NULL; +- port->state.mode = TYPEC_STATE_SAFE; ++ mux_state.alt = NULL; ++ mux_state.data = NULL; ++ mux_state.mode = TYPEC_STATE_SAFE; + +- ret = typec_mux_set(port->typec_mux, &port->state); +- if (ret) ++ ret = typec_mux_set(port->typec_mux, &mux_state); ++ if (ret) { + dev_err(altmode->dev, "failed to switch mux to safe mode: %d\n", ret); ++ return ret; ++ } + +- port->retimer_state.alt = NULL; +- port->retimer_state.data = NULL; +- port->retimer_state.mode = TYPEC_STATE_SAFE; ++ retimer_state.alt = NULL; ++ retimer_state.data = NULL; ++ retimer_state.mode = TYPEC_STATE_SAFE; + +- ret = typec_retimer_set(port->typec_retimer, &port->retimer_state); ++ ret = typec_retimer_set(port->typec_retimer, &retimer_state); + if (ret) + dev_err(altmode->dev, "failed to setup retimer to USB: %d\n", ret); ++ ++ return ret; + } + + static void pmic_glink_altmode_worker(struct work_struct *work) + { + struct pmic_glink_altmode_port *alt_port = work_to_altmode_port(work); + struct pmic_glink_altmode *altmode = alt_port->altmode; +- enum drm_connector_status conn_status; ++ struct pmic_glink_altmode_state state; ++ enum drm_connector_status conn_status = connector_status_disconnected; ++ unsigned long flags, generation; ++ bool stale; ++ int ret; + +- typec_switch_set(alt_port->typec_switch, alt_port->orientation); ++ spin_lock_irqsave(&alt_port->state_lock, flags); ++ state = alt_port->pending; ++ generation = alt_port->generation; ++ spin_unlock_irqrestore(&alt_port->state_lock, flags); + +- /* +- * MUX_CTRL_STATE_DP4LN/USB3_DP may only be set if SVID=DP, but we need +- * to special-case the SVID=DP && mux_ctrl=NO_CONN case to deliver a +- * HPD notification +- */ +- if (alt_port->svid == USB_TYPEC_DP_SID) { +- if (alt_port->mux_ctrl == MUX_CTRL_STATE_NO_CONN) { +- pmic_glink_altmode_safe(altmode, alt_port); +- } else { +- pmic_glink_altmode_enable_dp(altmode, alt_port, +- alt_port->mode, +- alt_port->hpd_state, +- alt_port->hpd_irq); +- } ++ ret = typec_switch_set(alt_port->typec_switch, state.orientation); ++ if (ret) ++ goto acknowledge; + +- if (alt_port->hpd_state) +- conn_status = connector_status_connected; ++ if (state.svid == USB_TYPEC_DP_SID) { ++ if (state.mux_ctrl == MUX_CTRL_STATE_NO_CONN) ++ ret = pmic_glink_altmode_safe(altmode, alt_port); + else +- conn_status = connector_status_disconnected; +- +- drm_aux_hpd_bridge_notify(&alt_port->bridge->dev, conn_status); +- } else if (alt_port->mux_ctrl == MUX_CTRL_STATE_TUNNELING) { +- if (alt_port->svid == USB_TYPEC_TBT_SID) +- pmic_glink_altmode_enable_tbt(altmode, alt_port); ++ ret = pmic_glink_altmode_enable_dp(altmode, alt_port, ++ state.mode, state.hpd_state, state.hpd_irq); ++ if (!ret && (state.legacy || state.mux_ctrl != MUX_CTRL_STATE_NO_CONN) && ++ state.hpd_state) ++ conn_status = connector_status_connected; ++ } else if (state.mux_ctrl == MUX_CTRL_STATE_TUNNELING) { ++ if (state.svid == USB_TYPEC_TBT_SID) ++ ret = pmic_glink_altmode_enable_tbt(altmode, alt_port, ++ &state.tbt_data, state.mode); + else +- pmic_glink_altmode_enable_usb4(altmode, alt_port); +- } else if (alt_port->mux_ctrl == MUX_CTRL_STATE_USB3_ONLY) { +- pmic_glink_altmode_enable_usb(altmode, alt_port); +- } else if (alt_port->mux_ctrl == MUX_CTRL_STATE_NO_CONN) { +- pmic_glink_altmode_safe(altmode, alt_port); ++ ret = pmic_glink_altmode_enable_usb4(altmode, alt_port, ++ &state.tbt_data); ++ } else if (state.mux_ctrl == MUX_CTRL_STATE_USB3_ONLY) { ++ ret = pmic_glink_altmode_enable_usb(altmode, alt_port); + } else { +- dev_err(altmode->dev, "Got unknown mux_ctrl: %u on port %u, forcing safe mode\n", +- alt_port->mux_ctrl, alt_port->index); +- pmic_glink_altmode_safe(altmode, alt_port); ++ ret = pmic_glink_altmode_safe(altmode, alt_port); + } + ++acknowledge: ++ /* A failed local configuration must still release the firmware event. */ + pmic_glink_altmode_request(altmode, ALTMODE_PAN_ACK, alt_port->index); ++ spin_lock_irqsave(&alt_port->state_lock, flags); ++ stale = generation != alt_port->generation; ++ spin_unlock_irqrestore(&alt_port->state_lock, flags); ++ if (ret || stale) ++ conn_status = connector_status_disconnected; ++ if (ret) ++ dev_err(altmode->dev, "port %u configuration failed: %d\n", alt_port->index, ret); ++ ++ /* Notifications schedule another work item; HPD may sleep. */ ++ drm_aux_hpd_bridge_notify(&alt_port->bridge->dev, conn_status); + } + + static enum typec_orientation pmic_glink_altmode_orientation(unsigned int orientation) +@@ -440,6 +485,7 @@ static enum typec_orientation pmic_glink_altmode_orientation(unsigned int orient + static void pmic_glink_altmode_sc8180xp_notify(struct pmic_glink_altmode *altmode, + const void *data, size_t len) + { ++ unsigned long flags; + struct pmic_glink_altmode_port *alt_port; + const struct usbc_sc8180x_notify *msg; + u32 notification; +@@ -473,11 +519,15 @@ static void pmic_glink_altmode_sc8180xp_notify(struct pmic_glink_altmode *altmod + } + + alt_port = &altmode->ports[port]; +- alt_port->orientation = pmic_glink_altmode_orientation(orientation); +- alt_port->svid = svid; +- alt_port->mode = mode; +- alt_port->hpd_state = hpd_state; +- alt_port->hpd_irq = hpd_irq; ++ spin_lock_irqsave(&alt_port->state_lock, flags); ++ alt_port->pending = (struct pmic_glink_altmode_state){ .legacy = true }; ++ alt_port->pending.orientation = pmic_glink_altmode_orientation(orientation); ++ alt_port->pending.svid = svid; ++ alt_port->pending.mode = mode; ++ alt_port->pending.hpd_state = hpd_state; ++ alt_port->pending.hpd_irq = hpd_irq; ++ alt_port->generation++; ++ spin_unlock_irqrestore(&alt_port->state_lock, flags); + schedule_work(&alt_port->work); + } + +@@ -488,6 +538,7 @@ static void pmic_glink_altmode_sc8180xp_notify(struct pmic_glink_altmode *altmod + static void pmic_glink_altmode_sc8280xp_notify(struct pmic_glink_altmode *altmode, + u16 svid, const void *data, size_t len) + { ++ unsigned long flags; + struct pmic_glink_altmode_port *alt_port; + const struct usbc_sc8280x_tbt_data *tbt; + const struct usbc_sc8280x_dp_data *dp; +@@ -527,23 +578,27 @@ static void pmic_glink_altmode_sc8280xp_notify(struct pmic_glink_altmode *altmod + } + + alt_port = &altmode->ports[port]; +- alt_port->orientation = pmic_glink_altmode_orientation(orientation); +- alt_port->svid = svid; +- alt_port->mux_ctrl = mux_ctrl; ++ spin_lock_irqsave(&alt_port->state_lock, flags); ++ alt_port->pending = (struct pmic_glink_altmode_state){}; ++ alt_port->pending.orientation = pmic_glink_altmode_orientation(orientation); ++ alt_port->pending.svid = svid; ++ alt_port->pending.mux_ctrl = mux_ctrl; + + if (svid == USB_TYPEC_DP_SID) { + dp = ¬ify->extended_data.dp; + +- alt_port->mode = dp->pin_assignment - DPAM_HPD_A; +- alt_port->hpd_state = dp->hpd_state; +- alt_port->hpd_irq = dp->hpd_irq; +- } else if (alt_port->mux_ctrl == MUX_CTRL_STATE_TUNNELING) { ++ alt_port->pending.mode = dp->pin_assignment - DPAM_HPD_A; ++ alt_port->pending.hpd_state = dp->hpd_state; ++ alt_port->pending.hpd_irq = dp->hpd_irq; ++ } else if (alt_port->pending.mux_ctrl == MUX_CTRL_STATE_TUNNELING) { + /* Valid for both USB4 and TBT3 */ + tbt = ¬ify->extended_data.tbt; + +- alt_port->tbt_data = *tbt; ++ alt_port->pending.tbt_data = *tbt; + } + ++ alt_port->generation++; ++ spin_unlock_irqrestore(&alt_port->state_lock, flags); + schedule_work(&alt_port->work); + } + +@@ -662,6 +717,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev, + alt_port = &altmode->ports[port]; + alt_port->altmode = altmode; + alt_port->index = port; ++ spin_lock_init(&alt_port->state_lock); + INIT_WORK(&alt_port->work, pmic_glink_altmode_worker); + + alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode)); +diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h +index e3cf1beff8038827e45334efddceb69a3bf2cf32..9899edc0f00922696cdbe5bc81a540ef5f6f583b 100644 +--- a/drivers/soc/qcom/rpmh-internal.h ++++ b/drivers/soc/qcom/rpmh-internal.h +@@ -8,6 +8,8 @@ + #define __RPM_INTERNAL_H__ + + #include ++#include ++#include + #include + #include + +@@ -60,6 +62,9 @@ struct tcs_group { + * @completion: triggered when request is done + * @dev: the device making the request + * @needs_free: check to free dynamically allocated request object ++ * @refs: caller and completion references for an allocated request ++ * @done: completion storage owned by an allocated request ++ * @batch: owner of a request within an active batch + */ + struct rpmh_request { + struct tcs_request msg; +@@ -67,6 +72,9 @@ struct rpmh_request { + struct completion *completion; + const struct device *dev; + bool needs_free; ++ refcount_t refs; ++ struct completion done; ++ struct batch_cache_req *batch; + }; + + /** +diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c +index f881af35ecfc51d4dbcc7d2d3c32eea854210d5e..bc9b965cb033358777263d0e69d44d940f87f960 100644 +--- a/drivers/soc/qcom/rpmh-rsc.c ++++ b/drivers/soc/qcom/rpmh-rsc.c +@@ -333,14 +333,15 @@ static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv, + } + + /** +- * get_req_from_tcs() - Get a stashed request that was xfering on the given TCS. ++ * take_req_from_tcs() - Take the request that was xfering on the given TCS. + * @drv: The RSC controller. + * @tcs_id: The global ID of this TCS. + * + * For ACTIVE_ONLY transfers we want to call back into the client when the + * transfer finishes. To do this we need the "request" that the client + * originally provided us. This function grabs the request that we stashed +- * when we started the transfer. ++ * when we started the transfer and clears the slot before the completion ++ * callback can free the request. + * + * This only makes sense for ACTIVE_ONLY transfers since those are the only + * ones we track sending (the only ones we enable interrupts for and the only +@@ -348,16 +349,20 @@ static struct tcs_group *get_tcs_for_msg(struct rsc_drv *drv, + * + * Return: The stashed request. + */ +-static const struct tcs_request *get_req_from_tcs(struct rsc_drv *drv, +- int tcs_id) ++static const struct tcs_request *take_req_from_tcs(struct rsc_drv *drv, ++ int tcs_id) + { ++ const struct tcs_request *req; + struct tcs_group *tcs; + int i; + + for (i = 0; i < TCS_TYPE_NR; i++) { + tcs = &drv->tcs[i]; +- if (tcs->mask & BIT(tcs_id)) +- return tcs->req[tcs_id - tcs->offset]; ++ if (tcs->mask & BIT(tcs_id)) { ++ req = tcs->req[tcs_id - tcs->offset]; ++ tcs->req[tcs_id - tcs->offset] = NULL; ++ return req; ++ } + } + + return NULL; +@@ -448,7 +453,7 @@ static irqreturn_t tcs_tx_done(int irq, void *p) + irq_status = readl_relaxed(drv->tcs_base + drv->regs[RSC_DRV_IRQ_STATUS]); + + for_each_set_bit(i, &irq_status, BITS_PER_TYPE(u32)) { +- req = get_req_from_tcs(drv, i); ++ req = take_req_from_tcs(drv, i); + if (WARN_ON(!req)) + goto skip; + +@@ -635,7 +640,7 @@ static int claim_tcs_for_req(struct rsc_drv *drv, struct tcs_group *tcs, + * - This is only used for "ACTIVE_ONLY" since the limitations of this + * function don't make sense for sleep/wake cases. + * - To do the transfer, we will grab a whole TCS for ourselves--we don't +- * try to share. If there are none available we'll wait indefinitely ++ * try to share. If there are none available we'll wait up to 10 seconds + * for a free one. + * - This function will not wait for the commands to be finished, only for + * data to be programmed into the RPMh. See rpmh_tx_done() which will +@@ -646,12 +651,13 @@ static int claim_tcs_for_req(struct rsc_drv *drv, struct tcs_group *tcs, + * the interrupt handler to run. If the interrupts is set to run on the + * active CPU this can never happen if interrupts are disabled. + * +- * Return: 0 on success, -EINVAL on error. ++ * Return: 0 on success, negative error code on failure. + */ + int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg) + { + struct tcs_group *tcs; + int tcs_id; ++ long time_left; + + might_sleep(); + +@@ -661,10 +667,16 @@ int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg) + + spin_lock_irq(&drv->lock); + +- /* Wait forever for a free tcs. It better be there eventually! */ +- wait_event_lock_irq(drv->tcs_wait, +- (tcs_id = claim_tcs_for_req(drv, tcs, msg)) >= 0, +- drv->lock); ++ /* A missing acknowledgment must not block every subsequent voter. */ ++ time_left = wait_event_lock_irq_timeout(drv->tcs_wait, ++ (tcs_id = claim_tcs_for_req(drv, tcs, msg)) >= 0, ++ drv->lock, msecs_to_jiffies(10000)); ++ if (!time_left) { ++ spin_unlock_irq(&drv->lock); ++ dev_err(drv->dev, "TCS unavailable for RPMh address %#x\n", ++ msg->cmds[0].addr); ++ return -ETIMEDOUT; ++ } + + tcs->req[tcs_id - tcs->offset] = msg; + set_bit(tcs_id, drv->tcs_in_use); +diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c +index f881c4c757ec8302b09eabf2f18bc79941a6f2c5..96391f408a6cd6997d45314a6fc920062cb83ba4 100644 +--- a/drivers/soc/qcom/rpmh.c ++++ b/drivers/soc/qcom/rpmh.c +@@ -59,12 +59,14 @@ struct cache_req { + * struct batch_cache_req - An entry in our batch catch + * + * @list: linked list obj ++ * @refs: caller and pending completion references + * @count: number of messages + * @rpm_msgs: the messages + */ + + struct batch_cache_req { + struct list_head list; ++ refcount_t refs; + int count; + struct rpmh_request rpm_msgs[]; + }; +@@ -82,6 +84,7 @@ void rpmh_tx_done(const struct tcs_request *msg) + msg); + struct completion *compl = rpm_msg->completion; + bool free = rpm_msg->needs_free; ++ struct batch_cache_req *batch = rpm_msg->batch; + + if (!compl) + goto exit; +@@ -90,8 +93,12 @@ void rpmh_tx_done(const struct tcs_request *msg) + complete(compl); + + exit: +- if (free) ++ if (batch) { ++ if (refcount_dec_and_test(&batch->refs)) ++ kfree(batch); ++ } else if (free && refcount_dec_and_test(&rpm_msg->refs)) { + kfree(rpm_msg); ++ } + } + + static struct cache_req *__find_req(struct rpmh_ctrlr *ctrlr, u32 addr) +@@ -213,6 +220,46 @@ static int __fill_rpmh_msg(struct rpmh_request *req, enum rpmh_state state, + return 0; + } + ++static int rpmh_write_sync(const struct device *dev, enum rpmh_state state, ++ const struct tcs_cmd *cmd, u32 n, bool is_read, ++ u32 *value) ++{ ++ struct rpmh_request *req; ++ int ret; ++ ++ req = kzalloc_obj(*req, GFP_ATOMIC); ++ if (!req) ++ return -ENOMEM; ++ ++ ret = __fill_rpmh_msg(req, state, cmd, n, is_read); ++ if (ret) { ++ kfree(req); ++ return ret; ++ } ++ ++ req->dev = dev; ++ req->needs_free = true; ++ req->msg.wait_for_compl = true; ++ init_completion(&req->done); ++ req->completion = &req->done; ++ /* One reference for the caller, one for the eventual acknowledgment. */ ++ refcount_set(&req->refs, 2); ++ ++ ret = __rpmh_write(dev, state, req); ++ if (ret) { ++ /* An unsuccessful send has no completion callback. */ ++ refcount_dec(&req->refs); ++ } else if (!wait_for_completion_timeout(&req->done, RPMH_TIMEOUT_MS)) { ++ ret = -ETIMEDOUT; ++ } else if (value) { ++ *value = req->cmd[0].data; ++ } ++ ++ if (refcount_dec_and_test(&req->refs)) ++ kfree(req); ++ return ret; ++} ++ + /** + * rpmh_read: Read a resource value + * +@@ -228,22 +275,11 @@ static int __fill_rpmh_msg(struct rpmh_request *req, enum rpmh_state state, + */ + int rpmh_read(const struct device *dev, struct tcs_cmd *cmd) + { +- DECLARE_COMPLETION_ONSTACK(compl); +- DEFINE_RPMH_MSG_ONSTACK(dev, RPMH_ACTIVE_ONLY_STATE, &compl, rpm_msg); +- int ret; +- +- ret = __fill_rpmh_msg(&rpm_msg, RPMH_ACTIVE_ONLY_STATE, cmd, 1, true); +- if (ret) +- return ret; +- +- ret = __rpmh_write(dev, RPMH_ACTIVE_ONLY_STATE, &rpm_msg); +- if (ret) +- return ret; +- +- ret = wait_for_completion_timeout(&compl, RPMH_TIMEOUT_MS); +- cmd[0].data = rpm_msg.cmd[0].data; ++ if (!cmd) ++ return -EINVAL; + +- return (ret > 0) ? 0 : -ETIMEDOUT; ++ return rpmh_write_sync(dev, RPMH_ACTIVE_ONLY_STATE, cmd, 1, true, ++ &cmd[0].data); + } + EXPORT_SYMBOL_GPL(rpmh_read); + +@@ -268,6 +304,7 @@ int rpmh_write_async(const struct device *dev, enum rpmh_state state, + if (!rpm_msg) + return -ENOMEM; + rpm_msg->needs_free = true; ++ refcount_set(&rpm_msg->refs, 1); + + ret = __fill_rpmh_msg(rpm_msg, state, cmd, n, false); + if (ret) { +@@ -275,7 +312,10 @@ int rpmh_write_async(const struct device *dev, enum rpmh_state state, + return ret; + } + +- return __rpmh_write(dev, state, rpm_msg); ++ ret = __rpmh_write(dev, state, rpm_msg); ++ if (ret) ++ kfree(rpm_msg); ++ return ret; + } + EXPORT_SYMBOL_GPL(rpmh_write_async); + +@@ -292,21 +332,11 @@ EXPORT_SYMBOL_GPL(rpmh_write_async); + int rpmh_write(const struct device *dev, enum rpmh_state state, + const struct tcs_cmd *cmd, u32 n) + { +- DECLARE_COMPLETION_ONSTACK(compl); +- DEFINE_RPMH_MSG_ONSTACK(dev, state, &compl, rpm_msg); + int ret; + +- ret = __fill_rpmh_msg(&rpm_msg, state, cmd, n, false); +- if (ret) +- return ret; +- +- ret = __rpmh_write(dev, state, &rpm_msg); +- if (ret) +- return ret; +- +- ret = wait_for_completion_timeout(&compl, RPMH_TIMEOUT_MS); +- WARN_ON(!ret); +- return (ret > 0) ? 0 : -ETIMEDOUT; ++ ret = rpmh_write_sync(dev, state, cmd, n, false, NULL); ++ WARN_ON(ret == -ETIMEDOUT); ++ return ret; + } + EXPORT_SYMBOL_GPL(rpmh_write); + +@@ -334,7 +364,7 @@ static int flush_batch(struct rpmh_ctrlr *ctrlr) + ret = rpmh_rsc_write_ctrl_data(ctrlr_to_drv(ctrlr), + &rpm_msg->msg); + if (ret) +- break; ++ return ret; + } + } + +@@ -391,7 +421,11 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state, + rpm_msgs = req->rpm_msgs; + + for (i = 0; i < count; i++) { +- __fill_rpmh_msg(rpm_msgs + i, state, cmd, n[i], false); ++ ret = __fill_rpmh_msg(rpm_msgs + i, state, cmd, n[i], false); ++ if (ret) { ++ kfree(ptr); ++ return ret; ++ } + cmd += n[i]; + } + +@@ -400,13 +434,17 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state, + return 0; + } + ++ refcount_set(&req->refs, 1); + for (i = 0; i < count; i++) { + struct completion *compl = &compls[i]; + + init_completion(compl); + rpm_msgs[i].completion = compl; ++ rpm_msgs[i].batch = req; ++ refcount_inc(&req->refs); + ret = rpmh_rsc_send_data(ctrlr_to_drv(ctrlr), &rpm_msgs[i].msg); + if (ret) { ++ refcount_dec(&req->refs); + pr_err("Error(%d) sending RPMH message addr=%#x\n", + ret, rpm_msgs[i].msg.cmds[0].addr); + break; +@@ -417,11 +455,7 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state, + while (i--) { + time_left = wait_for_completion_timeout(&compls[i], time_left); + if (!time_left) { +- /* +- * Better hope they never finish because they'll signal +- * the completion that we're going to free once +- * we've returned from this function. +- */ ++ /* Pending acknowledgments retain the batch after timeout. */ + WARN_ON(1); + ret = -ETIMEDOUT; + goto exit; +@@ -429,7 +463,8 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state, + } + + exit: +- kfree(ptr); ++ if (refcount_dec_and_test(&req->refs)) ++ kfree(ptr); + + return ret; + } +diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c +index a3316efdf8ac27d5f25f39c2738a3fea351e3516..980ad8aa8ee9ddaf185add31c6d9f24f96943a87 100644 +--- a/drivers/soundwire/amd_manager.c ++++ b/drivers/soundwire/amd_manager.c +@@ -1196,7 +1196,7 @@ static int amd_sdw_clock_stop(struct amd_sdw_manager *amd_manager) + + static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager) + { +- int ret; ++ int ret = 0; + u32 val; + + if (amd_manager->clk_stopped) { +@@ -1206,6 +1206,11 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager) + ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL, val, + (val & AMD_SDW_CLK_RESUME_DONE), ACP_DELAY_US, + AMD_SDW_TIMEOUT); ++ if (ret) { ++ dev_err(amd_manager->dev, "SDW%x clock stop exit failed: %d\n", ++ amd_manager->instance, ret); ++ return ret; ++ } + if (val & AMD_SDW_CLK_RESUME_DONE) { + writel(0, amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL); + ret = sdw_bus_exit_clk_stop(&amd_manager->bus); +@@ -1215,10 +1220,8 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager) + amd_manager->clk_stopped = false; + } + } +- if (amd_manager->clk_stopped) { +- dev_err(amd_manager->dev, "SDW%x clock stop exit failed\n", amd_manager->instance); +- return 0; +- } ++ if (ret < 0) ++ return ret; + dev_dbg(amd_manager->dev, "SDW%x clock stop exit successful\n", amd_manager->instance); + return 0; + } +diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c +index 12087cbd87b7bcd77d61fec98503188750104efe..17f38c891b80835e9f04a0461c52fc08cf1332b3 100644 +--- a/drivers/soundwire/bus.c ++++ b/drivers/soundwire/bus.c +@@ -1188,6 +1188,7 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus) + bool simple_clk_stop = true; + struct sdw_slave *slave; + bool is_slave = false; ++ int first_error = 0; + int ret; + + /* +@@ -1208,8 +1209,11 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus) + + ret = sdw_slave_clk_stop_callback(slave, SDW_CLK_STOP_MODE0, + SDW_CLK_PRE_DEPREPARE); +- if (ret < 0) ++ if (ret < 0) { + dev_warn(&slave->dev, "clock stop pre-deprepare cb failed:%d\n", ret); ++ if (!first_error) ++ first_error = ret; ++ } + + /* Only de-prepare a Slave device if needed */ + if (!slave->prop.simple_clk_stop_capable) { +@@ -1218,8 +1222,11 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus) + ret = sdw_slave_clk_stop_prepare(slave, SDW_CLK_STOP_MODE0, + false); + +- if (ret < 0) ++ if (ret < 0) { + dev_warn(&slave->dev, "clock stop deprepare failed:%d\n", ret); ++ if (!first_error) ++ first_error = ret; ++ } + } + } + +@@ -1233,8 +1240,11 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus) + */ + if (!simple_clk_stop) { + ret = sdw_bus_wait_for_clk_prep_deprep(bus, SDW_BROADCAST_DEV_NUM, false); +- if (ret < 0) ++ if (ret < 0) { + dev_warn(bus->dev, "clock stop deprepare wait failed:%d\n", ret); ++ if (!first_error) ++ first_error = ret; ++ } + } + + list_for_each_entry(slave, &bus->slaves, node) { +@@ -1247,11 +1257,14 @@ int sdw_bus_exit_clk_stop(struct sdw_bus *bus) + + ret = sdw_slave_clk_stop_callback(slave, SDW_CLK_STOP_MODE0, + SDW_CLK_POST_DEPREPARE); +- if (ret < 0) ++ if (ret < 0) { + dev_warn(&slave->dev, "clock stop post-deprepare cb failed:%d\n", ret); ++ if (!first_error) ++ first_error = ret; ++ } + } + +- return 0; ++ return first_error; + } + EXPORT_SYMBOL(sdw_bus_exit_clk_stop); + +diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c +index 55678a30cd4a1eeea7439ee403d236f0f74eb109..907213fda255e0611e30f18a49e130f27c63c588 100644 +--- a/drivers/soundwire/qcom.c ++++ b/drivers/soundwire/qcom.c +@@ -1,6 +1,8 @@ + // SPDX-License-Identifier: GPL-2.0 + // Copyright (c) 2019, Linaro Limited + ++#include ++#include + #include + #include + #include +@@ -18,6 +20,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include "bus.h" +@@ -131,7 +135,7 @@ + ((reg) | ((id) << 16) | ((dev) << 20) | ((data) << 24)) + + #define MAX_FREQ_NUM 1 +-#define TIMEOUT_MS 100 ++#define TIMEOUT_MS 500 + #define QCOM_SWRM_MAX_RD_LEN 0x1 + #define DEFAULT_CLK_FREQ 9600000 + #define SWR_INVALID_PARAM 0xFF +@@ -199,6 +203,14 @@ struct qcom_swrm_ctrl { + struct completion enumeration; + /* Port alloc/free lock */ + struct mutex port_lock; ++ /* Serialize recovery with PCM startup/shutdown. */ ++ struct mutex recovery_lock; ++ struct work_struct recovery_work; ++ atomic_t recovery_pending; ++ wait_queue_head_t slaves_wait; ++ unsigned int active_streams; ++ bool recovery_failed; ++ bool recovery_ready; + struct clk *hclk; + int irq; + unsigned int version; +@@ -221,8 +233,14 @@ struct qcom_swrm_ctrl { + u32 slave_status; + u32 wr_fifo_depth; + bool clock_stop_not_supported; ++ /* Per-Slave SCP_ADDRPAGE1/2 shadow; -1 = unknown. */ ++ s16 page1_cache[SDW_MAX_DEVICES + 1]; ++ s16 page2_cache[SDW_MAX_DEVICES + 1]; + }; + ++/* Controller recovery must not overlap another controller's probe. */ ++static DEFINE_MUTEX(qcom_swrm_probe_recovery_lock); ++ + struct qcom_swrm_data { + u32 default_cols; + u32 default_rows; +@@ -578,25 +596,6 @@ static int qcom_swrm_cmd_fifo_rd_cmd(struct qcom_swrm_ctrl *ctrl, + return SDW_CMD_IGNORED; + } + +-static int qcom_swrm_get_alert_slave_dev_num(struct qcom_swrm_ctrl *ctrl) +-{ +- u32 val, status; +- int dev_num; +- +- ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &val); +- +- for (dev_num = 1; dev_num <= SDW_MAX_DEVICES; dev_num++) { +- status = (val >> (dev_num * SWRM_MCP_SLV_STATUS_SZ)); +- +- if ((status & SWRM_MCP_SLV_STATUS_MASK) == SDW_SLAVE_ALERT) { +- ctrl->status[dev_num] = status & SWRM_MCP_SLV_STATUS_MASK; +- return dev_num; +- } +- } +- +- return -EINVAL; +-} +- + static void qcom_swrm_get_device_status(struct qcom_swrm_ctrl *ctrl) + { + u32 val; +@@ -614,6 +613,29 @@ static void qcom_swrm_get_device_status(struct qcom_swrm_ctrl *ctrl) + } + } + ++static int qcom_swrm_get_alert_slave_dev_num(struct qcom_swrm_ctrl *ctrl) ++{ ++ int dev_num, alert_dev = -EINVAL; ++ ++ /* ++ * In multi-slave topologies (such as Woofer + Tweeter WSA8845 smart ++ * amplifiers sharing a single SoundWire bus), decoding SWRM_MCP_SLV_STATUS ++ * across all devices is mandatory before handing status to SoundWire core. ++ * If only the alerting dev_num slot is written to ctrl->status, sibling ++ * slaves remain unpopulated (SDW_SLAVE_UNATTACHED) in the status array, ++ * causing sdw_handle_slave_status() to falsely demote them to UNATTACHED ++ * and permanently mute that channel. ++ */ ++ qcom_swrm_get_device_status(ctrl); ++ ++ for (dev_num = 1; dev_num <= SDW_MAX_DEVICES; dev_num++) { ++ if (ctrl->status[dev_num] == SDW_SLAVE_ALERT && alert_dev < 0) ++ alert_dev = dev_num; ++ } ++ ++ return alert_dev; ++} ++ + static void qcom_swrm_set_slave_dev_num(struct sdw_bus *bus, + struct sdw_slave *slave, int devnum) + { +@@ -630,6 +652,10 @@ static void qcom_swrm_set_slave_dev_num(struct sdw_bus *bus, + mutex_lock(&bus->bus_lock); + set_bit(devnum, bus->assigned); + mutex_unlock(&bus->bus_lock); ++ ++ /* Re-attach resets SCP_ADDRPAGE1/2 to defaults; invalidate. */ ++ ctrl->page1_cache[devnum] = -1; ++ ctrl->page2_cache[devnum] = -1; + } + } + +@@ -639,7 +665,7 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus) + struct sdw_slave *slave, *_s; + struct sdw_slave_id id; + u32 val1, val2; +- bool found; ++ bool found, enumerated = false; + u64 addr; + int i; + char *buf1 = (char *)&val1, *buf2 = (char *)&val2; +@@ -657,6 +683,7 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus) + + if (!val1 && !val2) + break; ++ enumerated = true; + + addr = buf2[1] | (buf2[0] << 8) | (buf1[3] << 16) | + ((u64)buf1[2] << 24) | ((u64)buf1[1] << 32) | +@@ -680,10 +707,12 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus) + if (!found) { + qcom_swrm_set_slave_dev_num(bus, NULL, i); + sdw_slave_add(bus, &id, NULL); ++ found = true; + } + } + +- complete(&ctrl->enumeration); ++ if (enumerated) ++ complete(&ctrl->enumeration); + return 0; + } + +@@ -712,6 +741,111 @@ static irqreturn_t qcom_swrm_wake_irq_handler(int irq, void *dev_id) + return IRQ_HANDLED; + } + ++static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl); ++static void qcom_swrm_reprobe_unattached_slaves(struct qcom_swrm_ctrl *ctrl); ++ ++static bool qcom_swrm_all_slaves_online(struct qcom_swrm_ctrl *ctrl) ++{ ++ struct sdw_slave *slave; ++ bool online; ++ ++ mutex_lock(&ctrl->bus.bus_lock); ++ online = !list_empty(&ctrl->bus.slaves); ++ list_for_each_entry(slave, &ctrl->bus.slaves, node) { ++ if (!slave->dev_num || slave->status != SDW_SLAVE_ATTACHED) { ++ online = false; ++ break; ++ } ++ } ++ mutex_unlock(&ctrl->bus.bus_lock); ++ ++ return online; ++} ++ ++static void qcom_swrm_recover_work(struct work_struct *work) ++{ ++ struct qcom_swrm_ctrl *ctrl = ++ container_of(work, struct qcom_swrm_ctrl, recovery_work); ++ unsigned long time_left; ++ int generation, ret; ++ bool attached; ++ ++ mutex_lock(&qcom_swrm_probe_recovery_lock); ++ mutex_lock(&ctrl->recovery_lock); ++ if (!READ_ONCE(ctrl->recovery_ready) || ctrl->active_streams) ++ goto unlock; ++ ++ generation = atomic_read(&ctrl->recovery_pending); ++ if (!generation) ++ goto unlock; ++ ctrl->recovery_failed = false; ++ ++ /* The fault was reported by a threaded IRQ; let it finish first. */ ++ synchronize_irq(ctrl->irq); ++ ++ ret = pm_runtime_resume_and_get(ctrl->dev); ++ if (ret < 0) { ++ dev_err_ratelimited(ctrl->dev, ++ "deferred clash recovery: runtime resume failed: %d\n", ++ ret); ++ if (atomic_cmpxchg(&ctrl->recovery_pending, generation, 0) == generation) ++ ctrl->recovery_failed = true; ++ goto unlock; ++ } ++ ++ /* A reset during an open stream drops its port routing. */ ++ reinit_completion(&ctrl->enumeration); ++ ret = ctrl->reg_write(ctrl, SWRM_COMP_SW_RESET, 0x01); ++ if (ret) ++ goto recovery_failed; ++ usleep_range(2000, 2050); ++ ret = qcom_swrm_init(ctrl); ++ if (ret) ++ goto recovery_failed; ++ time_left = wait_for_completion_timeout(&ctrl->enumeration, ++ msecs_to_jiffies(TIMEOUT_MS)); ++ if (!time_left) ++ dev_warn(ctrl->dev, "deferred clash recovery: enumeration timeout\n"); ++ synchronize_irq(ctrl->irq); ++ ++ qcom_swrm_get_device_status(ctrl); ++ qcom_swrm_enumerate(&ctrl->bus); ++ sdw_handle_slave_status(&ctrl->bus, ctrl->status); ++ attached = qcom_swrm_all_slaves_online(ctrl); ++ if (!attached) { ++ qcom_swrm_reprobe_unattached_slaves(ctrl); ++ /* Reprobe can release reset before the attach IRQ is handled. */ ++ attached = wait_event_timeout(ctrl->slaves_wait, ++ qcom_swrm_all_slaves_online(ctrl), ++ msecs_to_jiffies(TIMEOUT_MS)) > 0; ++ } ++ ++recovery_failed: ++ if (ret) { ++ dev_err(ctrl->dev, "deferred clash recovery: initialization failed: %d\n", ret); ++ attached = false; ++ } ++ if (atomic_cmpxchg(&ctrl->recovery_pending, generation, 0) == generation) ++ ctrl->recovery_failed = !attached; ++ ++ if (attached) { ++ dev_info(ctrl->dev, "deferred clash recovery: slaves attached\n"); ++ } else { ++ /* Keep the clash masked; a failed attempt must not loop on startup. */ ++ ctrl->intr_mask &= ~SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; ++ ctrl->reg_write(ctrl, ++ ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], ++ ctrl->intr_mask); ++ dev_err(ctrl->dev, "deferred clash recovery: slaves still missing\n"); ++ } ++ ++ pm_runtime_mark_last_busy(ctrl->dev); ++ pm_runtime_put_autosuspend(ctrl->dev); ++unlock: ++ mutex_unlock(&ctrl->recovery_lock); ++ mutex_unlock(&qcom_swrm_probe_recovery_lock); ++} ++ + static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) + { + struct qcom_swrm_ctrl *ctrl = dev_id; +@@ -739,6 +873,7 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) + "no slave alert found.spurious interrupt\n"); + } else { + sdw_handle_slave_status(&ctrl->bus, ctrl->status); ++ wake_up_all(&ctrl->slaves_wait); + } + + break; +@@ -750,35 +885,42 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) + dev_dbg(ctrl->dev, "Slave status not changed %x\n", + slave_status); + } else { ++ ctrl->slave_status = slave_status; + qcom_swrm_get_device_status(ctrl); + qcom_swrm_enumerate(&ctrl->bus); + sdw_handle_slave_status(&ctrl->bus, ctrl->status); ++ wake_up_all(&ctrl->slaves_wait); + } + break; + case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET: + dev_err_ratelimited(ctrl->dev, +- "%s: SWR bus clsh detected\n", ++ "%s: SWR bus clash detected\n", + __func__); + ctrl->intr_mask &= ~SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; + ctrl->reg_write(ctrl, + ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], + ctrl->intr_mask); ++ atomic_inc(&ctrl->recovery_pending); ++ if (READ_ONCE(ctrl->recovery_ready)) ++ schedule_work(&ctrl->recovery_work); + break; + case SWRM_INTERRUPT_STATUS_RD_FIFO_OVERFLOW: + ctrl->reg_read(ctrl, + ctrl->reg_layout[SWRM_REG_CMD_FIFO_STATUS], + &value); + dev_err_ratelimited(ctrl->dev, +- "%s: SWR read FIFO overflow fifo status 0x%x\n", ++ "%s: SWR read FIFO overflow fifo status 0x%x, flushing fifo\n", + __func__, value); ++ ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CMD, 0x1); + break; + case SWRM_INTERRUPT_STATUS_RD_FIFO_UNDERFLOW: + ctrl->reg_read(ctrl, + ctrl->reg_layout[SWRM_REG_CMD_FIFO_STATUS], + &value); + dev_err_ratelimited(ctrl->dev, +- "%s: SWR read FIFO underflow fifo status 0x%x\n", ++ "%s: SWR read FIFO underflow fifo status 0x%x, flushing fifo\n", + __func__, value); ++ ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CMD, 0x1); + break; + case SWRM_INTERRUPT_STATUS_WR_CMD_FIFO_OVERFLOW: + ctrl->reg_read(ctrl, +@@ -856,16 +998,19 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) + return ret; + } + +-static bool swrm_wait_for_frame_gen_enabled(struct qcom_swrm_ctrl *ctrl) ++static int swrm_wait_for_frame_gen_enabled(struct qcom_swrm_ctrl *ctrl) + { + int retry = SWRM_LINK_STATUS_RETRY_CNT; +- int comp_sts; ++ u32 comp_sts; ++ int ret; + + do { +- ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_FRAME_GEN_ENABLED], +- &comp_sts); ++ ret = ctrl->reg_read(ctrl, ctrl->reg_layout[SWRM_REG_FRAME_GEN_ENABLED], ++ &comp_sts); ++ if (ret) ++ return ret; + if (comp_sts & SWRM_FRM_GEN_ENABLED) +- return true; ++ return 0; + + usleep_range(500, 510); + } while (retry--); +@@ -873,81 +1018,123 @@ static bool swrm_wait_for_frame_gen_enabled(struct qcom_swrm_ctrl *ctrl) + dev_err(ctrl->dev, "%s: link status not %s\n", __func__, + comp_sts & SWRM_FRM_GEN_ENABLED ? "connected" : "disconnected"); + +- return false; ++ return -ETIMEDOUT; + } + + static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl) + { + u32 val; ++ int ret; + + /* Clear Rows and Cols */ + val = FIELD_PREP(SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_BMSK, ctrl->rows_index); + val |= FIELD_PREP(SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_BMSK, ctrl->cols_index); + +- reset_control_reset(ctrl->audio_cgcr); ++ ret = reset_control_reset(ctrl->audio_cgcr); ++ if (ret) ++ return ret; + +- ctrl->reg_write(ctrl, SWRM_MCP_FRAME_CTRL_BANK_ADDR(0), val); ++ ret = ctrl->reg_write(ctrl, SWRM_MCP_FRAME_CTRL_BANK_ADDR(0), val); ++ if (ret) ++ return ret; + + /* Enable Auto enumeration */ +- ctrl->reg_write(ctrl, SWRM_ENUMERATOR_CFG_ADDR, 1); ++ ret = ctrl->reg_write(ctrl, SWRM_ENUMERATOR_CFG_ADDR, 1); ++ if (ret) ++ return ret; + + ctrl->intr_mask = SWRM_INTERRUPT_STATUS_RMSK; + /* Mask soundwire interrupts */ +- if (ctrl->version < SWRM_VERSION_2_0_0) +- ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_MASK_ADDR], ++ if (ctrl->version < SWRM_VERSION_2_0_0) { ++ ret = ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_MASK_ADDR], + SWRM_INTERRUPT_STATUS_RMSK); ++ if (ret) ++ return ret; ++ } + + /* Configure No pings */ +- ctrl->reg_read(ctrl, SWRM_MCP_CFG_ADDR, &val); ++ ret = ctrl->reg_read(ctrl, SWRM_MCP_CFG_ADDR, &val); ++ if (ret) ++ return ret; + u32p_replace_bits(&val, SWRM_DEF_CMD_NO_PINGS, SWRM_MCP_CFG_MAX_NUM_OF_CMD_NO_PINGS_BMSK); +- ctrl->reg_write(ctrl, SWRM_MCP_CFG_ADDR, val); ++ ret = ctrl->reg_write(ctrl, SWRM_MCP_CFG_ADDR, val); ++ if (ret) ++ return ret; + + if (ctrl->version == SWRM_VERSION_1_7_0) { +- ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); +- ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, ++ ret = ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); ++ if (ret) ++ return ret; ++ ret = ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, + SWRM_MCP_BUS_CLK_START << SWRM_EE_CPU); ++ if (ret) ++ return ret; + } else if (ctrl->version >= SWRM_VERSION_2_0_0) { +- ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); +- ctrl->reg_write(ctrl, SWRM_V2_0_CLK_CTRL, ++ ret = ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); ++ if (ret) ++ return ret; ++ ret = ctrl->reg_write(ctrl, SWRM_V2_0_CLK_CTRL, + SWRM_V2_0_CLK_CTRL_CLK_START); ++ if (ret) ++ return ret; + } else { +- ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, SWRM_MCP_BUS_CLK_START); ++ ret = ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, SWRM_MCP_BUS_CLK_START); ++ if (ret) ++ return ret; + } + + /* Configure number of retries of a read/write cmd */ + if (ctrl->version >= SWRM_VERSION_1_5_1) { +- ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CFG_ADDR, ++ ret = ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CFG_ADDR, + SWRM_RD_WR_CMD_RETRIES | + SWRM_CONTINUE_EXEC_ON_CMD_IGNORE); ++ if (ret) ++ return ret; + } else { +- ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CFG_ADDR, ++ ret = ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CFG_ADDR, + SWRM_RD_WR_CMD_RETRIES); ++ if (ret) ++ return ret; + } + + /* COMP Enable */ +- ctrl->reg_write(ctrl, SWRM_COMP_CFG_ADDR, SWRM_COMP_CFG_ENABLE_MSK); ++ ret = ctrl->reg_write(ctrl, SWRM_COMP_CFG_ADDR, SWRM_COMP_CFG_ENABLE_MSK); ++ if (ret) ++ return ret; + + /* Set IRQ to PULSE */ +- ctrl->reg_write(ctrl, SWRM_COMP_CFG_ADDR, ++ ret = ctrl->reg_write(ctrl, SWRM_COMP_CFG_ADDR, + SWRM_COMP_CFG_IRQ_LEVEL_OR_PULSE_MSK); ++ if (ret) ++ return ret; + +- ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR], ++ ret = ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR], + 0xFFFFFFFF); ++ if (ret) ++ return ret; + + /* enable CPU IRQs */ + if (ctrl->mmio) { +- ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], ++ ret = ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], + SWRM_INTERRUPT_STATUS_RMSK); ++ if (ret) ++ return ret; + } + + /* Set IRQ to PULSE */ +- ctrl->reg_write(ctrl, SWRM_COMP_CFG_ADDR, ++ ret = ctrl->reg_write(ctrl, SWRM_COMP_CFG_ADDR, + SWRM_COMP_CFG_IRQ_LEVEL_OR_PULSE_MSK | + SWRM_COMP_CFG_ENABLE_MSK); ++ if (ret) ++ return ret; + +- swrm_wait_for_frame_gen_enabled(ctrl); ++ ret = swrm_wait_for_frame_gen_enabled(ctrl); ++ if (ret) ++ return ret; + ctrl->slave_status = 0; +- ctrl->reg_read(ctrl, SWRM_COMP_PARAMS, &val); ++ ret = ctrl->reg_read(ctrl, SWRM_COMP_PARAMS, &val); ++ if (ret) ++ return ret; + + if (ctrl->version >= SWRM_VERSION_3_1_0) + ctrl->wr_fifo_depth = FIELD_GET(SWRM_V3_COMP_PARAMS_WR_FIFO_DEPTH, val); +@@ -976,17 +1163,25 @@ static enum sdw_command_response qcom_swrm_xfer_msg(struct sdw_bus *bus, + int ret, i, len; + + if (msg->page) { +- ret = qcom_swrm_cmd_fifo_wr_cmd(ctrl, msg->addr_page1, +- msg->dev_num, +- SDW_SCP_ADDRPAGE1); +- if (ret) +- return ret; ++ if (ctrl->page1_cache[msg->dev_num] != msg->addr_page1) { ++ ret = qcom_swrm_cmd_fifo_wr_cmd(ctrl, msg->addr_page1, ++ msg->dev_num, ++ SDW_SCP_ADDRPAGE1); ++ if (ret) ++ return ret; + +- ret = qcom_swrm_cmd_fifo_wr_cmd(ctrl, msg->addr_page2, +- msg->dev_num, +- SDW_SCP_ADDRPAGE2); +- if (ret) +- return ret; ++ ctrl->page1_cache[msg->dev_num] = msg->addr_page1; ++ } ++ ++ if (ctrl->page2_cache[msg->dev_num] != msg->addr_page2) { ++ ret = qcom_swrm_cmd_fifo_wr_cmd(ctrl, msg->addr_page2, ++ msg->dev_num, ++ SDW_SCP_ADDRPAGE2); ++ if (ret) ++ return ret; ++ ++ ctrl->page2_cache[msg->dev_num] = msg->addr_page2; ++ } + } + + if (msg->flags == SDW_MSG_FLAG_READ) { +@@ -1351,29 +1546,75 @@ static int qcom_swrm_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) + { + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev); ++ bool recovery_retried = false; + int ret; + ++retry: ++ if (atomic_read(&ctrl->recovery_pending)) { ++ /* Startup can be called while another controller still probes. */ ++ if (!mutex_trylock(&qcom_swrm_probe_recovery_lock)) ++ return -EAGAIN; ++ mutex_unlock(&qcom_swrm_probe_recovery_lock); ++ schedule_work(&ctrl->recovery_work); ++ flush_work(&ctrl->recovery_work); ++ } ++ ++ mutex_lock(&ctrl->recovery_lock); ++ if (ctrl->recovery_failed && qcom_swrm_all_slaves_online(ctrl)) ++ ctrl->recovery_failed = false; ++ if (atomic_read(&ctrl->recovery_pending) || ctrl->recovery_failed) { ++ ret = -EIO; ++ goto unlock; ++ } ++ + ret = pm_runtime_get_sync(ctrl->dev); + if (ret < 0 && ret != -EACCES) { + dev_err_ratelimited(ctrl->dev, + "pm_runtime_get_sync failed in %s, ret %d\n", + __func__, ret); + pm_runtime_put_noidle(ctrl->dev); +- return ret; ++ goto unlock; + } + +- return 0; ++ /* Resume can queue clash recovery after the pre-resume check. */ ++ synchronize_irq(ctrl->irq); ++ if (atomic_read(&ctrl->recovery_pending)) { ++ pm_runtime_mark_last_busy(ctrl->dev); ++ pm_runtime_put_autosuspend(ctrl->dev); ++ mutex_unlock(&ctrl->recovery_lock); ++ ++ /* The worker needs recovery_lock; wait only after releasing it. */ ++ if (recovery_retried) ++ return -EIO; ++ recovery_retried = true; ++ goto retry; ++ } ++ ++ ctrl->active_streams++; ++ ret = 0; ++unlock: ++ mutex_unlock(&ctrl->recovery_lock); ++ return ret; + } + + static void qcom_swrm_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) + { + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev); ++ bool recover; + ++ mutex_lock(&ctrl->recovery_lock); + swrm_wait_for_wr_fifo_done(ctrl); + pm_runtime_mark_last_busy(ctrl->dev); + pm_runtime_put_autosuspend(ctrl->dev); +- ++ if (ctrl->active_streams) ++ ctrl->active_streams--; ++ recover = !ctrl->active_streams && ++ atomic_read(&ctrl->recovery_pending); ++ mutex_unlock(&ctrl->recovery_lock); ++ ++ if (recover) ++ schedule_work(&ctrl->recovery_work); + } + + static const struct snd_soc_dai_ops qcom_swrm_pdm_dai_ops = { +@@ -1547,6 +1788,51 @@ static int swrm_reg_show(struct seq_file *s_file, void *data) + DEFINE_SHOW_ATTRIBUTE(swrm_reg); + #endif + ++static void qcom_swrm_log_boot_slaves(struct qcom_swrm_ctrl *ctrl) ++{ ++ struct sdw_slave *slave; ++ ++ mutex_lock(&ctrl->bus.bus_lock); ++ list_for_each_entry(slave, &ctrl->bus.slaves, node) { ++ dev_info(ctrl->dev, "boot slave %s: dev_num %u status %u\n", ++ dev_name(&slave->dev), slave->dev_num, slave->status); ++ } ++ mutex_unlock(&ctrl->bus.bus_lock); ++} ++ ++/* ++ * A slave stuck at dev_num 0 has virtually always failed to attach because ++ * its own driver returned -EPROBE_DEFER (e.g. its reset-gpios resolve ++ * through a GPIO chip gated behind a slow-booting co-processor) -- it never ++ * got far enough to release the codec's physical reset, so no amount of ++ * bus-level rescanning here can help; only re-running the slave's own ++ * .probe() can. Linux normally does that automatically on any unrelated ++ * successful probe elsewhere (driver_bound() -> driver_deferred_probe_ ++ * trigger()), but that can take an unbounded, highly variable amount of ++ * time late in boot when little else is left to probe (measured 2026-08-17: ++ * over 15s on one boot, sub-millisecond on another, with no correlation to ++ * how close the actual dependency was to being ready). Ask directly instead ++ * of waiting for a coincidental trigger from elsewhere. ++ */ ++static void qcom_swrm_reprobe_unattached_slaves(struct qcom_swrm_ctrl *ctrl) ++{ ++ struct sdw_slave *slave; ++ ++ list_for_each_entry(slave, &ctrl->bus.slaves, node) { ++ int ret; ++ ++ if (slave->dev_num) ++ continue; ++ ret = device_reprobe(&slave->dev); ++ if (of_machine_is_compatible("asus,zenbook-a16-ux3607oa")) ++ dev_info(&slave->dev, ++ "enumeration reprobe returned %d (dev_num %u, status %u)\n", ++ ret, slave->dev_num, slave->status); ++ if (ret) ++ dev_dbg(&slave->dev, "reprobe still not ready (%d)\n", ret); ++ } ++} ++ + static int qcom_swrm_probe(struct platform_device *pdev) + { + struct device *dev = &pdev->dev; +@@ -1554,12 +1840,17 @@ static int qcom_swrm_probe(struct platform_device *pdev) + struct sdw_bus_params *params; + struct qcom_swrm_ctrl *ctrl; + const struct qcom_swrm_data *data; ++ struct sdw_slave *slave; + int ret; + u32 val; + + ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); + if (!ctrl) + return -ENOMEM; ++ guard(mutex)(&qcom_swrm_probe_recovery_lock); ++ ++ memset(ctrl->page1_cache, 0xff, sizeof(ctrl->page1_cache)); ++ memset(ctrl->page2_cache, 0xff, sizeof(ctrl->page2_cache)); + + data = of_device_get_match_data(dev); + ctrl->max_reg = data->max_reg; +@@ -1605,11 +1896,17 @@ static int qcom_swrm_probe(struct platform_device *pdev) + goto err_init; + } + +- clk_prepare_enable(ctrl->hclk); ++ ret = clk_prepare_enable(ctrl->hclk); ++ if (ret) ++ goto err_init; + + ctrl->dev = dev; + dev_set_drvdata(&pdev->dev, ctrl); + mutex_init(&ctrl->port_lock); ++ mutex_init(&ctrl->recovery_lock); ++ INIT_WORK(&ctrl->recovery_work, qcom_swrm_recover_work); ++ atomic_set(&ctrl->recovery_pending, 0); ++ init_waitqueue_head(&ctrl->slaves_wait); + init_completion(&ctrl->broadcast); + init_completion(&ctrl->enumeration); + +@@ -1660,7 +1957,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) + "swr_wake_irq", ctrl); + if (ret) { + dev_err(dev, "Failed to request soundwire wake irq\n"); +- goto err_init; ++ goto err_clk; + } + } + +@@ -1678,9 +1975,34 @@ static int qcom_swrm_probe(struct platform_device *pdev) + goto err_clk; + } + +- qcom_swrm_init(ctrl); +- wait_for_completion_timeout(&ctrl->enumeration, +- msecs_to_jiffies(TIMEOUT_MS)); ++ ret = qcom_swrm_init(ctrl); ++ if (ret) ++ goto err_master_add; ++ if (!wait_event_timeout(ctrl->slaves_wait, ++ qcom_swrm_all_slaves_online(ctrl), ++ msecs_to_jiffies(TIMEOUT_MS))) { ++ qcom_swrm_log_boot_slaves(ctrl); ++ /* ++ * A deferred codec probe may still need to release reset. ++ * device_attach() leaves already bound codecs intact; resetting ++ * the controller or rebinding them here can race attachment. ++ */ ++ list_for_each_entry(slave, &ctrl->bus.slaves, node) { ++ ret = device_attach(&slave->dev); ++ dev_info(dev, "boot attach %s returned %d\n", ++ dev_name(&slave->dev), ret); ++ } ++ if (!wait_event_timeout(ctrl->slaves_wait, ++ qcom_swrm_all_slaves_online(ctrl), ++ msecs_to_jiffies(TIMEOUT_MS))) { ++ qcom_swrm_log_boot_slaves(ctrl); ++ dev_err(dev, "boot enumeration failed: slaves still missing\n"); ++ ret = -ETIMEDOUT; ++ goto err_master_add; ++ } ++ } ++ qcom_swrm_log_boot_slaves(ctrl); ++ dev_info(dev, "boot enumeration complete: all slaves attached\n"); + ret = qcom_swrm_register_dais(ctrl); + if (ret) + goto err_master_add; +@@ -1694,16 +2016,29 @@ static int qcom_swrm_probe(struct platform_device *pdev) + pm_runtime_mark_last_busy(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); ++ /* Test-only prevention workaround; userspace can restore power/control. */ ++ if (of_machine_is_compatible("asus,zenbook-a16-ux3607oa") && ++ of_property_read_bool(dev->of_node, "qcom,keep-runtime-active")) { ++ pm_runtime_forbid(dev); ++ dev_info(dev, "runtime autosuspend disabled for audio prevention trial\n"); ++ } ++ WRITE_ONCE(ctrl->recovery_ready, true); ++ if (atomic_read(&ctrl->recovery_pending)) ++ schedule_work(&ctrl->recovery_work); + + #ifdef CONFIG_DEBUG_FS + ctrl->debugfs = debugfs_create_dir("qualcomm-sdw", ctrl->bus.debugfs); +- debugfs_create_file("qualcomm-registers", 0400, ctrl->debugfs, ctrl, +- &swrm_reg_fops); ++ /* A full register dump caused bus and codec faults on this board. */ ++ if (!of_machine_is_compatible("asus,zenbook-a16-ux3607oa")) ++ debugfs_create_file("qualcomm-registers", 0400, ctrl->debugfs, ++ ctrl, &swrm_reg_fops); + #endif + + return 0; + + err_master_add: ++ /* Stop status callbacks before removing their slave devices. */ ++ disable_irq(ctrl->irq); + sdw_bus_master_delete(&ctrl->bus); + err_clk: + clk_disable_unprepare(ctrl->hclk); +@@ -1715,6 +2050,9 @@ static void qcom_swrm_remove(struct platform_device *pdev) + { + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(&pdev->dev); + ++ WRITE_ONCE(ctrl->recovery_ready, false); ++ disable_irq(ctrl->irq); ++ cancel_work_sync(&ctrl->recovery_work); + sdw_bus_master_delete(&ctrl->bus); + clk_disable_unprepare(ctrl->hclk); + } +@@ -1722,71 +2060,112 @@ static void qcom_swrm_remove(struct platform_device *pdev) + static int __maybe_unused swrm_runtime_resume(struct device *dev) + { + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); ++ bool wake_irq_disabled = false; + int ret; + ++ ret = clk_prepare_enable(ctrl->hclk); ++ if (ret) ++ return ret; ++ + if (ctrl->wake_irq > 0) { +- if (!irqd_irq_disabled(irq_get_irq_data(ctrl->wake_irq))) ++ if (!irqd_irq_disabled(irq_get_irq_data(ctrl->wake_irq))) { + disable_irq_nosync(ctrl->wake_irq); ++ wake_irq_disabled = true; ++ } + } + +- clk_prepare_enable(ctrl->hclk); +- + if (ctrl->clock_stop_not_supported) { + reinit_completion(&ctrl->enumeration); +- ctrl->reg_write(ctrl, SWRM_COMP_SW_RESET, 0x01); ++ ret = ctrl->reg_write(ctrl, SWRM_COMP_SW_RESET, 0x01); ++ if (ret) ++ goto err_clk; + usleep_range(100, 105); + +- qcom_swrm_init(ctrl); ++ ret = qcom_swrm_init(ctrl); ++ if (ret) ++ goto err_clk; + + usleep_range(100, 105); +- if (!swrm_wait_for_frame_gen_enabled(ctrl)) +- dev_err(ctrl->dev, "link failed to connect\n"); ++ ret = swrm_wait_for_frame_gen_enabled(ctrl); ++ if (ret) ++ goto err_clk; + + /* wait for hw enumeration to complete */ +- wait_for_completion_timeout(&ctrl->enumeration, +- msecs_to_jiffies(TIMEOUT_MS)); ++ if (!wait_for_completion_timeout(&ctrl->enumeration, ++ msecs_to_jiffies(TIMEOUT_MS))) { ++ ret = -ETIMEDOUT; ++ goto err_clk; ++ } + qcom_swrm_get_device_status(ctrl); + sdw_handle_slave_status(&ctrl->bus, ctrl->status); + } else { +- reset_control_reset(ctrl->audio_cgcr); ++ ret = reset_control_reset(ctrl->audio_cgcr); ++ if (ret) ++ goto err_clk; + + if (ctrl->version == SWRM_VERSION_1_7_0) { +- ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); +- ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, ++ ret = ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); ++ if (ret) ++ goto err_clk; ++ ret = ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, + SWRM_MCP_BUS_CLK_START << SWRM_EE_CPU); ++ if (ret) ++ goto err_clk; + } else if (ctrl->version >= SWRM_VERSION_2_0_0) { +- ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); +- ctrl->reg_write(ctrl, SWRM_V2_0_CLK_CTRL, ++ ret = ctrl->reg_write(ctrl, SWRM_LINK_MANAGER_EE, SWRM_EE_CPU); ++ if (ret) ++ goto err_clk; ++ ret = ctrl->reg_write(ctrl, SWRM_V2_0_CLK_CTRL, + SWRM_V2_0_CLK_CTRL_CLK_START); ++ if (ret) ++ goto err_clk; + } else { +- ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, SWRM_MCP_BUS_CLK_START); ++ ret = ctrl->reg_write(ctrl, SWRM_MCP_BUS_CTRL, SWRM_MCP_BUS_CLK_START); ++ if (ret) ++ goto err_clk; + } +- ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR], ++ ret = ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR], + SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET); ++ if (ret) ++ goto err_clk; + + ctrl->intr_mask |= SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; +- if (ctrl->version < SWRM_VERSION_2_0_0) +- ctrl->reg_write(ctrl, ++ if (ctrl->version < SWRM_VERSION_2_0_0) { ++ ret = ctrl->reg_write(ctrl, + ctrl->reg_layout[SWRM_REG_INTERRUPT_MASK_ADDR], + ctrl->intr_mask); +- ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], ++ if (ret) ++ goto err_clk; ++ } ++ ret = ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], + ctrl->intr_mask); ++ if (ret) ++ goto err_clk; + + usleep_range(100, 105); +- if (!swrm_wait_for_frame_gen_enabled(ctrl)) +- dev_err(ctrl->dev, "link failed to connect\n"); ++ ret = swrm_wait_for_frame_gen_enabled(ctrl); ++ if (ret) ++ goto err_clk; + + ret = sdw_bus_exit_clk_stop(&ctrl->bus); + if (ret < 0) +- dev_err(ctrl->dev, "bus failed to exit clock stop %d\n", ret); ++ goto err_clk; + } + + return 0; ++ ++err_clk: ++ dev_err(dev, "runtime resume failed: %d\n", ret); ++ clk_disable_unprepare(ctrl->hclk); ++ if (wake_irq_disabled) ++ enable_irq(ctrl->wake_irq); ++ return ret; + } + + static int __maybe_unused swrm_runtime_suspend(struct device *dev) + { + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); ++ u32 intr_mask = ctrl->intr_mask; + int ret; + + swrm_wait_for_wr_fifo_done(ctrl); +@@ -1803,13 +2182,13 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev) + ret = sdw_bus_prep_clk_stop(&ctrl->bus); + if (ret < 0 && ret != -ENODATA) { + dev_err(dev, "prepare clock stop failed %d", ret); +- return ret; ++ goto restore_intr_mask; + } + + ret = sdw_bus_clk_stop(&ctrl->bus); + if (ret < 0 && ret != -ENODATA) { + dev_err(dev, "bus clock stop failed %d", ret); +- return ret; ++ goto restore_intr_mask; + } + } + +@@ -1823,6 +2202,18 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev) + } + + return 0; ++ ++restore_intr_mask: ++ /* Preserve the IRQ policy when runtime PM rejects the suspend. */ ++ if (!atomic_read(&ctrl->recovery_pending)) ++ ctrl->intr_mask |= intr_mask & SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET; ++ if (ctrl->version < SWRM_VERSION_2_0_0) ++ ctrl->reg_write(ctrl, ++ ctrl->reg_layout[SWRM_REG_INTERRUPT_MASK_ADDR], ++ ctrl->intr_mask); ++ ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], ++ ctrl->intr_mask); ++ return ret; + } + + static const struct dev_pm_ops swrm_dev_pm_ops = { +@@ -1848,6 +2239,14 @@ static struct platform_driver qcom_swrm_driver = { + .name = "qcom-soundwire", + .of_match_table = qcom_swrm_of_match, + .pm = &swrm_dev_pm_ops, ++ /* ++ * NOT PROBE_PREFER_ASYNCHRONOUS: tried 2026-08-17, caused ++ * "swrm_wait_for_rd_fifo_avail err read underflow" on the ++ * second controller when both probed concurrently -- real ++ * register-level contention between the two instances on ++ * this platform, not just a timing coincidence. Serial ++ * (default) probing is required here. ++ */ + } + }; + module_platform_driver(qcom_swrm_driver); +diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c +index 0636986d9b755d062a26f754818c5d47c5865577..02f839716c34e31b1bd6c585799a9c09dc3f56d2 100644 +--- a/drivers/usb/core/message.c ++++ b/drivers/usb/core/message.c +@@ -1249,7 +1249,8 @@ int usb_get_status(struct usb_device *dev, int recip, int type, int target, + ret = 0; + break; + default: +- ret = -EIO; ++ if (ret >= 0) ++ ret = -EIO; + } + + kfree(status); +diff --git a/drivers/usb/typec/mux/ps883x.c b/drivers/usb/typec/mux/ps883x.c +index 64e0a61b776a183971403525780d150402a668a0..8607cc8f398c027af49fe8d0cf2d6904cf8544e2 100644 +--- a/drivers/usb/typec/mux/ps883x.c ++++ b/drivers/usb/typec/mux/ps883x.c +@@ -279,21 +279,23 @@ static int ps883x_sw_set(struct typec_switch_dev *sw, + guard(mutex)(&retimer->lock); + + if (retimer->orientation != orientation) { +- retimer->orientation = orientation; +- + /* + * Orientation notifications usually come prior to mode switch + * events. If the retimer is already in reset, we still want to + * cache the new orientation value for the subsequent ps883x_set(). + */ +- if (retimer->in_reset) ++ if (retimer->in_reset) { ++ retimer->orientation = orientation; + return 0; ++ } + + ret = regmap_assign_bits(retimer->regmap, REG_USB_PORT_CONN_STATUS_0, + CONN_STATUS_0_ORIENTATION_REVERSED, + orientation == TYPEC_ORIENTATION_REVERSE); + if (ret) + dev_err(&retimer->client->dev, "failed to set orientation: %d\n", ret); ++ else ++ retimer->orientation = orientation; + } + + return ret; +diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h +index 3a2ace2cadff03a55abde838aeb7bbd9a7521358..c480d6cb42c500a295eef3bdf42fbc6d36f54bf8 100644 +--- a/include/linux/phy/phy.h ++++ b/include/linux/phy/phy.h +@@ -286,6 +286,8 @@ struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np, + const char *con_id); + struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, + int index); ++struct phy *phy_get_by_of_node(struct device_node *np); ++struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np); + void of_phy_put(struct phy *phy); + void phy_put(struct device *dev, struct phy *phy); + void devm_phy_put(struct device *dev, struct phy *phy); +@@ -495,6 +497,17 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev, + return ERR_PTR(-ENOSYS); + } + ++static inline struct phy *phy_get_by_of_node(struct device_node *np) ++{ ++ return ERR_PTR(-ENOSYS); ++} ++ ++static inline struct phy *devm_phy_get_by_of_node(struct device *dev, ++ struct device_node *np) ++{ ++ return ERR_PTR(-ENOSYS); ++} ++ + static inline void of_phy_put(struct phy *phy) + { + } +diff --git a/include/linux/property.h b/include/linux/property.h +index 907c790a3f013fc8282f26e510817949f80941d7..9143fe4f5c05179e595ba875aafbcb006a740824 100644 +--- a/include/linux/property.h ++++ b/include/linux/property.h +@@ -547,6 +547,11 @@ unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode, + for (child = fwnode_graph_get_next_endpoint(fwnode, NULL); child; \ + child = fwnode_graph_get_next_endpoint(fwnode, child)) + ++#define fwnode_graph_for_each_endpoint_scoped(fwnode, child) \ ++ for (struct fwnode_handle *child __free(fwnode_handle) = \ ++ fwnode_graph_get_next_endpoint(fwnode, NULL); \ ++ child; child = fwnode_graph_get_next_endpoint(fwnode, child)) ++ + int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, + struct fwnode_endpoint *endpoint); + +diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c +index 01f18bb370477e6aba2ea298754fbd5a5168a049..329acf3e4b72189630dfc37c77ee3d3db47082a8 100644 +--- a/security/keys/trusted-keys/trusted_tpm2.c ++++ b/security/keys/trusted-keys/trusted_tpm2.c +@@ -4,6 +4,7 @@ + * Copyright (C) 2014 Intel Corporation + */ + ++#include + #include + #include + #include +diff --git a/sound/soc/codecs/lpass-rx-macro.c b/sound/soc/codecs/lpass-rx-macro.c +index 30c7a0a70aebf0cccc472f480bb5e7b39a73402c..c41eb8de61609888b5242aac1d975bdfee262988 100644 +--- a/sound/soc/codecs/lpass-rx-macro.c ++++ b/sound/soc/codecs/lpass-rx-macro.c +@@ -3732,8 +3732,8 @@ static int rx_macro_register_mclk_output(struct rx_macro *rx) + struct device *dev = rx->dev; + const char *parent_clk_name = NULL; + const char *clk_name = "lpass-rx-mclk"; ++ struct clk_init_data init = {}; + struct clk_hw *hw; +- struct clk_init_data init; + int ret; + + if (rx->npl) +diff --git a/sound/soc/codecs/lpass-tx-macro.c b/sound/soc/codecs/lpass-tx-macro.c +index 6f362b196f47e7a762453bd6d68ef33fc044345e..6deaaabe43afa435ebb3ee563ecaf5b0502ae7d0 100644 +--- a/sound/soc/codecs/lpass-tx-macro.c ++++ b/sound/soc/codecs/lpass-tx-macro.c +@@ -2210,8 +2210,8 @@ static int tx_macro_register_mclk_output(struct tx_macro *tx) + struct device *dev = tx->dev; + const char *parent_clk_name = NULL; + const char *clk_name = "lpass-tx-mclk"; ++ struct clk_init_data init = {}; + struct clk_hw *hw; +- struct clk_init_data init; + int ret; + + if (tx->npl) +diff --git a/sound/soc/codecs/lpass-va-macro.c b/sound/soc/codecs/lpass-va-macro.c +index f0797715ab5457b89039edf0d81e9c18a7bab78f..03d6434a4a126c798c9534f88364b1d31f3097ad 100644 +--- a/sound/soc/codecs/lpass-va-macro.c ++++ b/sound/soc/codecs/lpass-va-macro.c +@@ -1414,7 +1414,7 @@ static int va_macro_register_fsgen_output(struct va_macro *va) + struct device_node *np = dev->of_node; + const char *parent_clk_name; + const char *clk_name = "fsgen"; +- struct clk_init_data init; ++ struct clk_init_data init = {}; + int ret; + + if (va->has_npl_clk) +diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c +index 3c63043207a9e7a6b172251ac7847046cdaf83f2..899c8bee4645fcb5beac951450d06fe26d8008e7 100644 +--- a/sound/soc/codecs/lpass-wsa-macro.c ++++ b/sound/soc/codecs/lpass-wsa-macro.c +@@ -2649,10 +2649,10 @@ static const struct clk_ops swclk_gate_ops = { + + static int wsa_macro_register_mclk_output(struct wsa_macro *wsa) + { ++ struct clk_init_data init = {}; + struct device *dev = wsa->dev; + const char *parent_clk_name; + struct clk_hw *hw; +- struct clk_init_data init; + int ret; + + if (wsa->npl) +diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c +index eb138ab4e922662a35e029de96e81d1021e83391..ff9d6eef403662cdc769fd3950663edc0a591d1a 100644 +--- a/sound/soc/codecs/wsa884x.c ++++ b/sound/soc/codecs/wsa884x.c +@@ -2313,6 +2313,11 @@ static void wsa884x_cancel_pa_health_work(void *data) + cancel_delayed_work_sync(&wsa884x->pa_health_work); + } + ++static void wsa884x_pm_runtime_disable(void *data) ++{ ++ pm_runtime_disable(data); ++} ++ + static int wsa884x_probe(struct sdw_slave *pdev, + const struct sdw_device_id *id) + { +@@ -2407,6 +2412,19 @@ static int wsa884x_probe(struct sdw_slave *pdev, + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + ++ /* ++ * Every other resource acquired above is devm-managed and unwound on ++ * detach. This one was not, so a forced device_reprobe() (see ++ * drivers/soundwire/qcom.c: qcom_swrm_reprobe_unattached_slaves()) ++ * calls pm_runtime_enable() a second time on a device that was never ++ * balanced by pm_runtime_disable() on the first detach, producing ++ * "Unbalanced pm_runtime_enable!" and a codec left in a broken ++ * runtime-PM state -- silent on that channel from then on. ++ */ ++ ret = devm_add_action_or_reset(dev, wsa884x_pm_runtime_disable, dev); ++ if (ret) ++ return ret; ++ + return devm_snd_soc_register_component(dev, + &wsa884x_component_drv, + wsa884x_dais, +diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c +index cce0ad31ff0c036e0cadd113e3a3e88b6344e02f..884722b2ed9272c3a97457a6ebcc3bd33b0ba3df 100644 +--- a/sound/soc/qcom/qdsp6/audioreach.c ++++ b/sound/soc/qcom/qdsp6/audioreach.c +@@ -590,10 +590,11 @@ void *audioreach_alloc_graph_pkt(struct q6apm *apm, + } + EXPORT_SYMBOL_GPL(audioreach_alloc_graph_pkt); + +-int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, +- struct gpr_ibasic_rsp_result_t *result, struct mutex *cmd_lock, +- gpr_port_t *port, wait_queue_head_t *cmd_wait, +- const struct gpr_pkt *pkt, uint32_t rsp_opcode) ++int audioreach_send_cmd_sync_timeout(struct device *dev, gpr_device_t *gdev, ++ struct gpr_ibasic_rsp_result_t *result, struct mutex *cmd_lock, ++ gpr_port_t *port, wait_queue_head_t *cmd_wait, ++ const struct gpr_pkt *pkt, uint32_t rsp_opcode, ++ unsigned long timeout, bool quiet) + { + + const struct gpr_hdr *hdr = &pkt->hdr; +@@ -615,15 +616,17 @@ int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, + + if (rsp_opcode) + rc = wait_event_timeout(*cmd_wait, (result->opcode == hdr->opcode) || +- (result->opcode == rsp_opcode), 5 * HZ); ++ (result->opcode == rsp_opcode), timeout); + else +- rc = wait_event_timeout(*cmd_wait, (result->opcode == hdr->opcode), 5 * HZ); ++ rc = wait_event_timeout(*cmd_wait, (result->opcode == hdr->opcode), timeout); + + if (!rc) { +- dev_err(dev, "CMD timeout for [%x] opcode\n", hdr->opcode); ++ if (!quiet) ++ dev_err(dev, "CMD timeout for [%x] opcode\n", hdr->opcode); + rc = -ETIMEDOUT; + } else if (result->status > 0) { +- dev_err(dev, "DSP returned error[%x] %x\n", hdr->opcode, result->status); ++ if (!quiet) ++ dev_err(dev, "DSP returned error[%x] %x\n", hdr->opcode, result->status); + rc = -EINVAL; + } else { + /* DSP successfully finished the command */ +@@ -634,6 +637,17 @@ int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, + mutex_unlock(cmd_lock); + return rc; + } ++EXPORT_SYMBOL_GPL(audioreach_send_cmd_sync_timeout); ++ ++int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, ++ struct gpr_ibasic_rsp_result_t *result, struct mutex *cmd_lock, ++ gpr_port_t *port, wait_queue_head_t *cmd_wait, ++ const struct gpr_pkt *pkt, uint32_t rsp_opcode) ++{ ++ return audioreach_send_cmd_sync_timeout(dev, gdev, result, cmd_lock, ++ port, cmd_wait, pkt, rsp_opcode, ++ 5 * HZ, false); ++} + EXPORT_SYMBOL_GPL(audioreach_send_cmd_sync); + + int audioreach_graph_send_cmd_sync(struct q6apm_graph *graph, const struct gpr_pkt *pkt, +diff --git a/sound/soc/qcom/qdsp6/audioreach.h b/sound/soc/qcom/qdsp6/audioreach.h +index 35541b2d8c99840563ec63a5bb584568b87a3135..b3e5c8c185db82c95ca6173abdfee59c32568fe4 100644 +--- a/sound/soc/qcom/qdsp6/audioreach.h ++++ b/sound/soc/qcom/qdsp6/audioreach.h +@@ -1020,6 +1020,10 @@ int audioreach_tplg_init(struct snd_soc_component *component); + + /* Module specific */ + void audioreach_graph_free_buf(struct q6apm_graph *graph); ++int audioreach_send_cmd_sync_timeout(struct device *dev, gpr_device_t *gdev, struct gpr_ibasic_rsp_result_t *result, ++ struct mutex *cmd_lock, gpr_port_t *port, wait_queue_head_t *cmd_wait, ++ const struct gpr_pkt *pkt, uint32_t rsp_opcode, ++ unsigned long timeout, bool quiet); + int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev, struct gpr_ibasic_rsp_result_t *result, + struct mutex *cmd_lock, gpr_port_t *port, wait_queue_head_t *cmd_wait, + const struct gpr_pkt *pkt, uint32_t rsp_opcode); +diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c +index f167b9dae3fa140989f7f3a39d62c028d37ec66a..282b3b450da39f5052b87908014397a976f42d37 100644 +--- a/sound/soc/qcom/qdsp6/q6apm.c ++++ b/sound/soc/qcom/qdsp6/q6apm.c +@@ -29,13 +29,21 @@ struct apm_graph_mgmt_cmd { + + static struct q6apm *g_apm; + +-int q6apm_send_cmd_sync(struct q6apm *apm, const struct gpr_pkt *pkt, +- uint32_t rsp_opcode) ++int q6apm_send_cmd_sync_timeout(struct q6apm *apm, const struct gpr_pkt *pkt, ++ uint32_t rsp_opcode, unsigned long timeout, bool quiet) + { + gpr_device_t *gdev = apm->gdev; + +- return audioreach_send_cmd_sync(&gdev->dev, gdev, &apm->result, &apm->lock, +- NULL, &apm->wait, pkt, rsp_opcode); ++ return audioreach_send_cmd_sync_timeout(&gdev->dev, gdev, &apm->result, &apm->lock, ++ NULL, &apm->wait, pkt, rsp_opcode, ++ timeout, quiet); ++} ++EXPORT_SYMBOL_GPL(q6apm_send_cmd_sync_timeout); ++ ++int q6apm_send_cmd_sync(struct q6apm *apm, const struct gpr_pkt *pkt, ++ uint32_t rsp_opcode) ++{ ++ return q6apm_send_cmd_sync_timeout(apm, pkt, rsp_opcode, 5 * HZ, false); + } + + static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, uint32_t graph_id) +@@ -142,12 +150,33 @@ static void q6apm_put_audioreach_graph(struct kref *ref) + + static int q6apm_get_apm_state(struct q6apm *apm) + { +- struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(0, +- APM_CMD_GET_SPF_STATE, 0); +- if (IS_ERR(pkt)) +- return PTR_ERR(pkt); ++ int ret, retries = 50; ++ ++ /* ++ * During boot the APM service may take a short time after GPR registration ++ * before responding to GET_SPF_STATE. Instead of a single 5-second blocking ++ * wait on an unhandled initial packet, poll with short timeouts (100ms) so ++ * we unblock as soon as the DSP APM service is ready. ++ */ ++ while (retries--) { ++ struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(0, ++ APM_CMD_GET_SPF_STATE, 0); ++ if (IS_ERR(pkt)) ++ return PTR_ERR(pkt); ++ ++ ret = q6apm_send_cmd_sync_timeout(apm, pkt, APM_CMD_RSP_GET_SPF_STATE, ++ msecs_to_jiffies(100), true); ++ if (!ret && apm->state) { ++ dev_info(apm->dev, "APM service ready (state: 0x%x)\n", apm->state); ++ return apm->state; ++ } ++ ++ if (ret != -ETIMEDOUT) ++ break; ++ } + +- q6apm_send_cmd_sync(apm, pkt, APM_CMD_RSP_GET_SPF_STATE); ++ if (!apm->state) ++ dev_err(apm->dev, "APM service did not become ready (state: 0x%x)\n", apm->state); + + return apm->state; + } +diff --git a/sound/soc/qcom/qdsp6/q6apm.h b/sound/soc/qcom/qdsp6/q6apm.h +index 5cb51ca491dc4fac7d910c3e26ea36d9831de1ca..3fdaa9ce3b4ed06f1258d6ec296f3fdb83d1025f 100644 +--- a/sound/soc/qcom/qdsp6/q6apm.h ++++ b/sound/soc/qcom/qdsp6/q6apm.h +@@ -147,6 +147,8 @@ int q6apm_alloc_fragments(struct q6apm_graph *graph, + int q6apm_free_fragments(struct q6apm_graph *graph, unsigned int dir); + int q6apm_unmap_memory_fixed_region(struct device *dev, unsigned int graph_id); + /* Helpers */ ++int q6apm_send_cmd_sync_timeout(struct q6apm *apm, const struct gpr_pkt *pkt, ++ uint32_t rsp_opcode, unsigned long timeout, bool quiet); + int q6apm_send_cmd_sync(struct q6apm *apm, const struct gpr_pkt *pkt, + uint32_t rsp_opcode); + diff --git a/pkgbuilds/linux-omarchy-aarch64/2501-soundwire-qcom-allow-deferred-codecs-at-boot.patch b/pkgbuilds/linux-omarchy-aarch64/2501-soundwire-qcom-allow-deferred-codecs-at-boot.patch new file mode 100644 index 0000000000..299407f83f --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/2501-soundwire-qcom-allow-deferred-codecs-at-boot.patch @@ -0,0 +1,34 @@ +Subject: [PATCH] soundwire: qcom: keep the bus for deferred codec probes + +A controller probe running on the deferred-probe worker can wait for codecs +whose GPIO/reset suppliers are queued behind that same probe. The fatal +boot timeout deletes the codecs before their suppliers can bind. + +Keep the initialized bus registered so deferred probing can finish. Only +report complete enumeration when all slaves are online. Hardware init and +DAI registration failures still use the existing cleanup paths. + +On the A16, the failing trace deletes both buses before the reset providers +bind. With this change the same deferred-reset condition occurs, both +controller probes finish, and all four codecs bind and produce audio. + +--- a/drivers/soundwire/qcom.c ++++ b/drivers/soundwire/qcom.c +@@ -1996,13 +1996,13 @@ + qcom_swrm_all_slaves_online(ctrl), + msecs_to_jiffies(TIMEOUT_MS))) { + qcom_swrm_log_boot_slaves(ctrl); +- dev_err(dev, "boot enumeration failed: slaves still missing\n"); +- ret = -ETIMEDOUT; +- goto err_master_add; ++ /* Reset suppliers may be queued behind this probe on the same worker. */ ++ dev_info(dev, "boot enumeration pending: allowing deferred codec probes\n"); + } + } + qcom_swrm_log_boot_slaves(ctrl); +- dev_info(dev, "boot enumeration complete: all slaves attached\n"); ++ if (qcom_swrm_all_slaves_online(ctrl)) ++ dev_info(dev, "boot enumeration complete: all slaves attached\n"); + ret = qcom_swrm_register_dais(ctrl); + if (ret) + goto err_master_add; diff --git a/pkgbuilds/linux-omarchy-aarch64/2503-power-supply-uevent-eagain.patch b/pkgbuilds/linux-omarchy-aarch64/2503-power-supply-uevent-eagain.patch new file mode 100644 index 0000000000..084155a5f7 --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/2503-power-supply-uevent-eagain.patch @@ -0,0 +1,28 @@ +Subject: [PATCH] power: supply: keep uevents when a property is temporarily unavailable + +The Qualcomm battery manager returns -EAGAIN while its firmware service +is starting. Aborting the entire power-supply event drops the device name, +type and any other available properties, and makes initramfs udev trigger +report a failure for each supply. + +Treat temporary unavailability like other missing properties when +building the event. Keep -EAGAIN for direct property reads and thermal +consumers, and keep propagating transport and allocation failures. + +--- +--- a/drivers/power/supply/power_supply_sysfs.c ++++ b/drivers/power/supply/power_supply_sysfs.c +@@ -539,10 +539,11 @@ + dev_attr = &pwr_attr->dev_attr; + + ret = power_supply_format_property((struct device *)dev, true, dev_attr, prop_buf); +- if (ret == -ENODEV || ret == -ENODATA || ret == -EINVAL) { ++ if (ret == -ENODEV || ret == -ENODATA || ret == -EINVAL || ret == -EAGAIN) { + /* + * When a battery is absent, we expect -ENODEV. Don't abort; +- * send the uevent with at least the PRESENT=0 property ++ * send the uevent with at least the PRESENT=0 property. Also allow ++ * properties which are temporarily unavailable during initialization. + */ + return 0; + } diff --git a/pkgbuilds/linux-omarchy-aarch64/A16-README.md b/pkgbuilds/linux-omarchy-aarch64/A16-README.md new file mode 100644 index 0000000000..2439f7d551 --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/A16-README.md @@ -0,0 +1,21 @@ +# A16 additions to the shared ARM kernel + +This contribution targets `omacom/omarchy-pkgs@a8de4a65`, after the Surface Laptop 8 merge (#1706), and advances `pkgrel=4` to `5`. The package version is **7.3-5**; the kernel release is **7.3.0-5-omarchy**. All 357 shared patches, signatures, checksums and `config.aarch64` are retained. The shared Type-C/USB4 configuration and existing kernel/headers package names stay in place. The separate `omarchy-a16-support` recipe is outside this contribution. + +- **2500:** residual A16 hardware fixes after the complete shared series. The shared LPASS Compander1 addresses, Glymur USB votes, v8 eDP calibration and `LINK_RATE_SET` fixes are no longer duplicated. A16 board power/firmware policy, EC, audio, display recovery, Wi-Fi, camera prerequisites and error handling remain. Camera nodes stay disabled. +- **2501:** deferred SoundWire codecs, renumbered from 2301 with unchanged contents. The bus remains registered while reset suppliers finish probing. +- **2503:** temporary `-EAGAIN` battery properties are omitted from uevents, renumbered from 2303 with unchanged contents. Direct reads and other errors keep their behavior. + +The original A16 block-mq patch remains omitted because Linux 7.3 includes it. Shared patch 2302 is a different LPASS regcache change and is retained. + +The QMP merge retains shared USB4 ownership, deferred native-mode requests, DP lane selection, runtime-PM guard and calibration. A16 clock/regulator/reset tracking, failed-transition rollback and powered-off access checks are adapted to that state machine. DP retains the shared FEC/USB4 paths and A16 transfer/error cleanup. Altmode retains masked V2 notifications, synchronized snapshots and firmware acknowledgments, including invalid cable errors. + +`a16-source.json` pins the baseline, complete patched source-tree hash and local patch digests. `prepare()` checks source regressions, provenance, configuration and the actual kernel release. `check()` requires the Image, module symbol table and A16 DTB with its two SoundWire runtime-active properties. The unchanged `a16.config` remains an overlay on the shared config. + +The package provides `omarchy-a16-dsp-abi=1`, installs its per-release marker, and records the actual kernel release, configuration and source provenance. The SoCCP early-boot/shared-memory bridge contract is retained. The ABI marker is an interface contract; it does not establish physical A16 acceptance. + +See [A16-VALIDATION.md](A16-VALIDATION.md) for current checks and remaining gates. Earlier native package, UKI and physical results belong to **7.2.8-24-omarchy**. Camera and sleep remain outside the validated A16 scope. Other ARM boards require fresh regression coverage. + +## Corresponding source publication + +The split build emits `linux-omarchy-aarch64-source` alongside kernel and headers. It includes every declared archive, patch, config, regression helper and signature, public keys, the actual recipe, final `BUILD_CONFIG`, `KERNEL_RELEASE` and `SHA256SUMS`. Publish and retain all three matching outputs through the existing artifact/signing pipeline. `README.source` describes offline preparation; `.BUILDINFO` records native build dependencies. Source reconstruction does not guarantee identical binaries across toolchains. No OEM firmware is included. diff --git a/pkgbuilds/linux-omarchy-aarch64/A16-VALIDATION.md b/pkgbuilds/linux-omarchy-aarch64/A16-VALIDATION.md new file mode 100644 index 0000000000..e58c3dab96 --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/A16-VALIDATION.md @@ -0,0 +1,47 @@ +# Linux 7.3-5 A16 rebase validation + +Baseline: `omacom/omarchy-pkgs@a8de4a65abd6bf0bfd90fa515d2f160ca280c973`, including the Surface Laptop 8 merge (#1706) at `488cd623d066eab6ad3cf07774a84d1596b697b9`. +Previous PR head: `026ad947ce51dadccc25f4dde5ba7db31a5f584f`. +Candidate: package `7.3-5`, kernel `7.3.0-5-omarchy`. +Patched source tree: `035c9c08d096b1762f937a942ce9d3c17f2e392e`. + +Checks ran on 27 October 2026 in an isolated Arch Linux ARM container on an AArch64 Debian VM, using GCC 16.1.1, binutils 2.46.0 and GNU Make 4.4.1. These are native source/object checks; the full kernel/headers/source package build and physical A16 acceptance remain pending. + +| Check | Actual result | +| --- | --- | +| Source archive SHA-256 and BLAKE2 | Match the unchanged shared recipe | +| Linux archive OpenPGP signature | Good signature from the pinned Greg Kroah-Hartman key `647F28654894E3BD457199BE38DBBDC86092693E` | +| Shared detached patch signatures | All 76 verify using the supplied public keys | +| Shared stack preservation | All 357 shared patches, input order, checksums, signatures and `config.aarch64` are unchanged | +| Recipe integrity | 443 declared inputs; aligned SHA-256/BLAKE2 arrays and local input checksums pass | +| Patch application | All 360 patches apply to the signed 7.3 archive with zero fuzz and no rejects; offsets allowed | +| Distributed-source replay | Real `makepkg --verifysource` and `makepkg --nobuild --nodeps` pass from the staged corresponding-source package; its complete patched source tree matches the recorded hash | +| Configuration/release | Every unchanged A16 overlay setting survives native `olddefconfig`; actual recipe release check passes for `7.3.0-5-omarchy` | +| Device trees | Both A16 and Surface Laptop 8 DTBs compile; decompiled A16 DTB has exactly two `qcom,keep-runtime-active` properties | +| Native compilation | All 54 changed C files plus block-mq/mq-deadline, shared eDP, adjacent DP panel/link, dwc3-qcom and the shared USB4 host compile: 61 AArch64 ELF objects with no compiler warnings/errors in the final checks | +| Compiled regressions | Battery missing-property/EAGAIN, valid-property, transport and allocation failures pass; actual merged QMP cleanup/rollback code passes reset/regulator retry, reference-count, forced cleanup, failed USB/USB4 initialization and Type-C rollback success/failure cases under mocks | +| Source contracts | Deferred SoundWire bus/DAI error handling, upstream block-mq initialization, DSP early-boot/shared-memory bridge and board policy checks pass | +| Packaging regressions | Source inputs, aliases, external download cache, public keys and tamper detection pass; kernel fixture installs ABI provider/marker, actual release, config, provenance and DTBs | +| Corresponding-source staging | Real recipe/inputs/config/release stage successfully; all 449 manifest entries verify | +| Repository checks | Package metadata and pinned-source tests pass | + +## Overlap resolution + +A three-way comparison used the previous 222-patch shared baseline, the previous A16 source changes and the new 357-patch shared baseline. Sixteen files overlap; five require manual resolution. The A16 patches move from 2300/2301/2303 to 2500/2501/2503. SoundWire and battery patch contents are unchanged. + +The LPASS Compander1 addresses, Glymur USB votes, v8 eDP calibration and `LINK_RATE_SET` fixes are supplied by the shared series. The newer eDP driver remains byte-for-byte identical to the shared baseline. The remaining QMP merge keeps shared USB4 precedence, DP lane selection, deferred native-mode requests, calibration and the runtime-PM guard while adapting the prior A16 resource tracking and rollback checks. Display merges preserve shared FEC/USB4 paths and A16 transfer/error cleanup. Altmode stores the masked V2 mux value in its synchronized snapshot and returns invalid cable errors to the acknowledging worker. + +The first native object pass caught four invalid-cable exits inherited from the shared void helpers after merging them into A16 error-returning helpers. They now return `-EINVAL`. A later caller audit also found that failed USB/USB4 initialization could retain a tentative PHY reference when reset cleanup failed. Both failure callers now release that reference while keeping failed resources tracked. A compiled regression fails on the earlier candidate and passes with the corrected callers. The final native object checks and compiled regressions pass after these corrections. + +Native `olddefconfig` regenerates compiler/tool capability and BTF-related settings for the installed tools. All A16 overlay settings survive; the shared config input is unchanged. This does not establish the full Arch BTF/module build. `makepkg --nodeps` was used only for source preparation, not to claim a completed package build. Source-package staging and kernel-package fixtures do not substitute for real split-package archives. + +## Required before promotion + +- Build all three split packages with the complete supported native Arch aarch64 build dependencies; run full `build()`/`check()`, module/symbol checks and packaged-header module compilation. +- Retain the matching corresponding-source package and verify its final release artifacts through the normal publishing pipeline. +- Boot both UKIs on a physical A16; verify release/ABI markers, both early DSPs before root mount, firmware selection and absence of early modprobe or battery uevent failures. +- Recheck audio playback/microphones, deferred codec reset/recovery, internal display, external outputs/hotplug and failed-link/power transitions. +- Recheck charger/battery transitions, Wi-Fi, Bluetooth calls/audio, keyboard, touchscreen, USB and storage; reassess PMIC supplier-link and codec warnings. +- Run shared-kernel regressions on the other ARM boards, including Surface Laptop 8 after these driver merges. + +Earlier A16 hardware acceptance remains historical evidence for **7.2.8-24** only. The previous 7.3-4 checks remain source/cross-compilation evidence. Camera and sleep receive no new acceptance claim. No OEM firmware, external-SSD UAS quirk or `omarchy-a16-support` recipe is added here. diff --git a/pkgbuilds/linux-omarchy-aarch64/PKGBUILD b/pkgbuilds/linux-omarchy-aarch64/PKGBUILD index 4194b4f82f..4346d8d207 100644 --- a/pkgbuilds/linux-omarchy-aarch64/PKGBUILD +++ b/pkgbuilds/linux-omarchy-aarch64/PKGBUILD @@ -4,11 +4,11 @@ # The aarch64 build of linux-omarchy. It has a recipe of its own, in a folder # of its own, and that folder's name is its pkgbase so the build and publish # tooling can tell its files from the x86_64 recipe's. The packages it makes -# are linux-omarchy and linux-omarchy-headers, the names x86_64 has. +# are linux-omarchy and linux-omarchy-headers, plus a corresponding-source package. pkgbase=linux-omarchy-aarch64 _kernel=linux-omarchy pkgver=7.3 -pkgrel=4 +pkgrel=5 pkgdesc='Omarchy Linux for aarch64 (BORE CPU scheduler, ADIOS I/O scheduler)' url='https://omarchy.org' arch=( @@ -20,6 +20,7 @@ makedepends=( binutils cpio gettext + git glibc libelf libgcc @@ -414,8 +415,14 @@ source=( 2432-usb-core-hub-don-t-enable-U1-on-a-link-tunnelled-ove.patch 2433-arm64-dts-qcom-surface-laptop8-Describe-the-USB4-hos.patch 2434-arm64-dts-qcom-surface-laptop8-Disable-the-Wi-Fi-har.patch + # A16 residuals follow the shared Surface Laptop 8 series. + 2500-glymur-asus-zenbook-a16-local-hardware-fixes.patch + 2501-soundwire-qcom-allow-deferred-codecs-at-boot.patch + 2503-power-supply-uevent-eagain.patch + a16.config + a16-regression.py ) -source_aarch64=(config.aarch64) +source_aarch64=(config.aarch64 a16-source.json README.source) validpgpkeys=( ABAF11C65A2970B130ABE3C479BE3E4300411886 # Linus Torvalds 647F28654894E3BD457199BE38DBBDC86092693E # Greg Kroah-Hartman @@ -855,8 +862,15 @@ sha256sums=('87363c24f10e06321eb362765521094e94471f6bff8bce2d6b3e40f39f004953' '006ae8d2fb77f11c43ceb036b9c6a5d81b74de2cc7d779cfbdb3553e42469f18' '0e84a6ce2050897f6d3b1b8571af9ca5747da44063ff43ea5bced048be4255dd' '179d20fc514250c21dff26162835214be28549883ea3df71f1f102d88a1d52cf' - '273003520e40df721b9cfec8c9ee53fa04398c3459075267fc9a2358216ca888') -sha256sums_aarch64=('ea12355d4ace5c0d3b96560df53a486fbf5321404cd086f00fa7e179fe2e5d53') + '273003520e40df721b9cfec8c9ee53fa04398c3459075267fc9a2358216ca888' + 'e3fbd4e5d252fedebc29214664243490af439e742870bcebb07190e26f9c0825' + '768bc9688b9cae6c6e4fdfd5425ae18a4ac5febc659988e88af521b5d963e461' + '96760536815e8b44de166ed40c82cf5b9227a3bdbcfd850d639a913339b66d77' + '581c849a9807a8cb5ac3553cc369ea354b6e1ba8d904836b2cae66c70b5a10a6' + '828e117a398e37311061ba756e91274b7dad3e13576e11a32ec4165800f335a3') +sha256sums_aarch64=('ea12355d4ace5c0d3b96560df53a486fbf5321404cd086f00fa7e179fe2e5d53' + 'ab94a4de5595b5ea244cb7a795ce345f347306332f7efb3c7361c24cb84121b7' + 'da29b052cd347fb831a5a917ea75d6106e018cad66797fad84db43cc3ef5b647') b2sums=('b7fb8c74de664fdd0cd7b42afff2720bda5c4bdb2ffffa80a745c5fecd029c6fe739a3ecbdaa5c5e27194a8acb9bf861271e7bafe6eb475bb3ccd6862e4caf60' 'SKIP' '60eac409f1ba50fe319f6b3aa5b0af81bc7ce5628ca41c1af346a6d5ef0fc9c577527742d1f70ece7e07ea410fcd112b32d64f0a05af5b532f27b62e5e7d837a' @@ -1291,8 +1305,15 @@ b2sums=('b7fb8c74de664fdd0cd7b42afff2720bda5c4bdb2ffffa80a745c5fecd029c6fe739a3e 'f6f13748a9f28b6a2d7773bf86b64d5e411212e7f8cb3507ad2defe1ab52b322c2e285ef562241c2f7bf18f5f3d477091ee9d7f9dc5ba509803e6a6ae2c81f4d' '15dfb20255c180621752cf10311a0af75321a7dbe82bea588f9acf6bb38d5173c240670e109ff80967e6b8c21d2c70ce7b91e0850340b50a163b1fa952e50049' '36813989f04c9878d6fefad7e6481e497b81e22be7065e4f9599b8bb0085713e70d9a0e9ebf48f127477e976c8c8d6f7c5cc59f36ffe0c516c21111d0f5edc06' - '237d5d62022e361c12aa999e67bd4beddb18181a9339dc573988ae66e09f9c431bfb028febd468379126fd1fd6595066cc2a3fb331cdea7ee08b87926f25e9f1') -b2sums_aarch64=('d1b5a6f7bfa18a9d68efde8ab18d7790edd7fb0dd2b1183004d0b2c9b0d63b92c7765baa9a00ac4ad6fa43763902517fb1a2afaaaaf31758793c0312b71b6933') + '237d5d62022e361c12aa999e67bd4beddb18181a9339dc573988ae66e09f9c431bfb028febd468379126fd1fd6595066cc2a3fb331cdea7ee08b87926f25e9f1' + '20f63353876a90ba714ae4f940aa12b8d9dd4c28f4c9e72736956c4e458d6b8a00024cb776ea3128a7bbd633ba1c30e0483acea8e01b726ee93817517a54d993' + '0ef0ed8845d54dee7646310398ecdc88a2f8bdb2cbf87c62b3d85c7d19e90243fd769fd9f71528e101f8023b258c62a1644d744f1cf6ef18bb6b3062ebd63d13' + '507c6dac4ffc74194facf4d63cf3653f59d91156e7cde5dfdecb5915a09ef234077f7562e3315b4fa92ae57be768be5e0b951140a5f0707b23eed74636b147fc' + '6959e1d25df78b552a3bffd854409102c7708824c70bc9db35867ca80a32000ddd707d07b1ac2cbebeb836379ac425edc398b587b96a0ca9fb32fc025c54b19d' + '03df71c7c990e44c924debf613e7def9bf5ecf4f80fd69791f5c11452a74413f7e045d483ebfe19099791cc41066523f39b613d7539e920a25a8596e71f9eb39') +b2sums_aarch64=('d1b5a6f7bfa18a9d68efde8ab18d7790edd7fb0dd2b1183004d0b2c9b0d63b92c7765baa9a00ac4ad6fa43763902517fb1a2afaaaaf31758793c0312b71b6933' + 'e7a322db9a92a32c5638a6fe920d0a078e0a8e6f59431ab1636eaf221f3c836f1598342dbee344e12555a4c08d46793e0e372d4e7ae3098e295422ba6eb4d896' + '9cc7ff336747c691d894ac43a8fee813bd98aca8acc7f0e64d45d73db09bc74547f9374e539cbee66505c1d862eeead55ba4f4ecfbbd62c9ad2097aa339381ed') # https://www.kernel.org/pub/linux/kernel/v7.x/sha256sums.asc @@ -1303,13 +1324,9 @@ export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EP prepare() { cd $_srcname - echo "Setting version..." - echo "-$pkgrel" > localversion.10-pkgrel - echo "${_kernel#linux}" > localversion.20-pkgname - if [[ -n ${_rcpatch:-} ]]; then echo "Applying patch $_rcpatch..." - patch -Np1 --fuzz=0 < "../$_rcpatch" + patch -Np1 --fuzz=0 --no-backup-if-mismatch < "../$_rcpatch" fi local src @@ -1319,15 +1336,35 @@ prepare() { src="${src%.zst}" [[ $src = *.patch ]] || continue echo "Applying patch $src..." - patch -Np1 --fuzz=0 < "../$src" + patch -Np1 --fuzz=0 --no-backup-if-mismatch < "../$src" done + python ../a16-regression.py . || return 1 + + # Verify source provenance before adding generated version/config files. + git init -q + git add --force -A + local expected_tree actual_tree + expected_tree=$(python -c 'import json; print(json.load(open("../a16-source.json"))["source_tree"])') + actual_tree=$(git write-tree) + if [[ $actual_tree != "$expected_tree" ]]; then + printf 'A16 source provenance mismatch: expected %s, got %s\n' "$expected_tree" "$actual_tree" >&2 + return 1 + fi + + echo "Setting version..." + echo "-$pkgrel" > localversion.10-pkgrel + echo "${_kernel#linux}" > localversion.20-pkgname + echo "Setting config..." cp ../config.$CARCH .config + scripts/kconfig/merge_config.sh -m .config ../a16.config make olddefconfig + _check_a16_config .config || return 1 diff -u ../config.$CARCH .config || : make -s kernelrelease > version + _check_kernel_release || return 1 echo "Prepared $_kernel version $( "$modulesdir/omarchy-a16-dsp-abi" + install -Dm644 version "$pkgdir/usr/share/doc/$_kernel/kernel-release" + install -Dm644 ../a16-source.json "$pkgdir/usr/share/doc/$_kernel/a16-source.json" + install -Dm644 .config "$pkgdir/usr/share/doc/$_kernel/config" echo "Installing device trees..." # The Windows-on-ARM laptops, whose UKIs carry a device tree for the machine. @@ -1510,9 +1552,34 @@ _package-headers() { ln -sr "$builddir" "$pkgdir/usr/src/$_kernel" } +_package-aarch64-source() { + pkgdesc='Complete corresponding sources and build recipe for linux-omarchy aarch64' + depends=() + optdepends=() + local destination="$pkgdir/usr/src/$pkgbase" src path + install -dm755 "$destination" + install -m644 "$startdir/PKGBUILD" "$destination/PKGBUILD" + for src in "${source[@]}" "${source_aarch64[@]}"; do + src=${src%%::*} + src=${src##*/} + path="$srcdir/$src" + [[ -f $path ]] || path="${SRCDEST:-$startdir}/$src" + install -m644 "$path" "$destination/$src" + done + if [[ -d $startdir/keys/pgp ]]; then + cp -a "$startdir/keys" "$destination/keys" + fi + install -m644 "$srcdir/$_srcname/.config" "$destination/BUILD_CONFIG" + install -m644 "$srcdir/$_srcname/version" "$destination/KERNEL_RELEASE" + cd "$destination" + # Make the offline input set independently checkable after downloading. + find . -type f ! -name SHA256SUMS -print0 | sort -z | xargs -0 sha256sum > SHA256SUMS +} + pkgname=( "$_kernel" "$_kernel-headers" + "$pkgbase-source" ) for _p in "${pkgname[@]}"; do eval "package_$_p() { @@ -1522,3 +1589,33 @@ for _p in "${pkgname[@]}"; do done # vim:set ts=8 sts=2 sw=2 et: + +check() { + cd $_srcname + _check_kernel_release || return 1 + [[ -s arch/arm64/boot/Image && -s Module.symvers ]] || return 1 + local board=arch/arm64/boot/dts/qcom/glymur-asus-zenbook-a16-ux3607oa.dtb + [[ -s $board ]] || return 1 + [[ $(scripts/dtc/dtc -I dtb -O dts "$board" 2>/dev/null | grep -c 'qcom,keep-runtime-active;') == 2 ]] || return 1 + _check_a16_config .config || return 1 +} + +_check_a16_config() { + python - ../a16.config "$1" <<'PYCONFIG' +from pathlib import Path +import sys +expected = {line for line in Path(sys.argv[1]).read_text().splitlines() + if line.startswith('CONFIG_') or line.startswith('# CONFIG_')} +actual = set(Path(sys.argv[2]).read_text().splitlines()) +missing = expected - actual +if missing: + raise SystemExit('Missing A16 kernel configuration: ' + ', '.join(sorted(missing))) +PYCONFIG +} + +_check_kernel_release() { + # A base release such as pkgver=7.3 reports kernelversion=7.3.0. + local upstream_version + upstream_version=$(make -s kernelversion) + [[ $(cmd_flags)" in late + assert "RQF_SCHED_TAGS" in late and "RQF_RESV" in late + assert "rq->rq_flags |= RQF_USE_SCHED" in late + assert "e->type->ops.prepare_request(rq)" in late + assert "RQF_USE_SCHED" not in function(blk, "blk_mq_limit_depth") + + pas = read("drivers/remoteproc/qcom_q6v5_pas.c") + soccp = re.search(r"glymur_soccp_resource = \{(.*?)\n\};", pas, re.S).group(1) + assert ".early_boot = true" in soccp and ".needs_tzmem = true" in soccp + board = read("arch/arm64/boot/dts/qcom/glymur-asus-zenbook-a16-ux3607oa.dts") + assert board.count("qcom,keep-runtime-active;") == 2 + + # Compile the actual patched uevent helper, with only its environment mocked. + helper = function(read("drivers/power/supply/power_supply_sysfs.c"), "add_prop_uevent") + harness = r''' +#include +#include +#include +#include +struct device { int unused; }; +struct kobj_uevent_env { int unused; }; +struct device_attribute { int unused; }; +enum power_supply_property { PROP_TEST }; +struct power_supply_attr { struct device_attribute dev_attr; const char *prop_name; }; +static struct power_supply_attr power_supply_attrs[] = {{{0}, "STATUS"}}; +static int property_result, event_result, event_calls; +static int power_supply_format_property(struct device *dev, bool uevent, + struct device_attribute *attr, char *buf) { + (void)dev; (void)uevent; (void)attr; + if (property_result >= 0) strcpy(buf, "Charging\n"); + return property_result; +} +static int add_uevent_var(struct kobj_uevent_env *env, const char *fmt, + const char *name, const char *value) { + (void)env; (void)fmt; (void)name; + assert(strcmp(value, "Charging") == 0); + event_calls++; + return event_result; +} +''' + cases = r''' +int main(void) { + char buf[64]; struct device dev = {0}; struct kobj_uevent_env env = {0}; + int missing[] = {-ENODEV, -ENODATA, -EINVAL, -EAGAIN}; + for (unsigned i = 0; i < sizeof(missing)/sizeof(missing[0]); i++) { + property_result = missing[i]; event_calls = 0; + assert(add_prop_uevent(&dev, &env, PROP_TEST, buf) == 0); + assert(event_calls == 0); + } + int errors[] = {-EIO, -ENOMEM, -ETIMEDOUT}; + for (unsigned i = 0; i < sizeof(errors)/sizeof(errors[0]); i++) { + property_result = errors[i]; event_calls = 0; + assert(add_prop_uevent(&dev, &env, PROP_TEST, buf) == errors[i]); + assert(event_calls == 0); + } + property_result = 9; event_result = 0; event_calls = 0; + assert(add_prop_uevent(&dev, &env, PROP_TEST, buf) == 0); + assert(event_calls == 1); + event_result = -ENOMEM; + assert(add_prop_uevent(&dev, &env, PROP_TEST, buf) == -ENOMEM); + return 0; +} +''' + with tempfile.TemporaryDirectory(prefix="a16-regression-") as tmp: + source = Path(tmp) / "battery.c" + binary = Path(tmp) / "battery" + source.write_text(harness + helper + cases) + subprocess.run(shlex.split(os.environ.get("HOSTCC", "cc")) + + ["-std=c11", "-Wall", "-Wextra", "-Werror", str(source), "-o", str(binary)], check=True) + subprocess.run([str(binary)], check=True) + print("PASS: deferred SoundWire, upstream block-mq, DSP/DT contracts and compiled battery uevent regression") + + + # Exercise the merged QMP cleanup and rollback code with failing resources. + qmp = read("drivers/phy/qualcomm/phy-qcom-qmp-combo.c") + helper = function(qmp, "qmp_combo_com_exit") + rollback = function(qmp, "qmp_combo_reconfigure_phy") + harness = r''' +#include +#include +#include +#define BIT(n) (1UL << (n)) +#define dev_err(...) ((void)0) +#define dev_err_probe(dev, error, ...) (error) +#define WARN_ON(condition) ((void)(condition)) +#define guard(kind) mock_guard +enum typec_orientation { NORMAL, REVERSE }; +enum qmpphy_mode { NATIVE, USB4 }; +#define QMPPHY_MODE_USB4 USB4 +struct regulator { int index; }; +struct regulator_bulk_data { struct regulator *consumer; }; +struct qmp_phy_cfg { int num_vregs, num_resets; bool configure_usb4_phy; }; +struct qmp_combo { + const struct qmp_phy_cfg *cfg; + struct regulator_bulk_data *vregs; + int init_count, num_clks, resets, pipe_clk, clks, phy_mutex; + unsigned int usb_init_count, usb4_init_count, usb4_rx_eq; + int p2rr2p_pipe_clk; + unsigned long vregs_enabled; + bool com_powered_on, reset_pending, pipe_clk_enabled, clks_enabled; + enum typec_orientation orientation; + enum qmpphy_mode qmpphy_mode; + struct phy *usb_phy; +}; +static int reset_error, regulator_error = -1, pipe_disables, clock_disables; +static int reset_control_bulk_assert(int n, int resets) { + (void)n; (void)resets; return reset_error; +} +static void clk_disable_unprepare(int c) { (void)c; pipe_disables++; } +static void clk_bulk_disable_unprepare(int n, int c) { + (void)n; (void)c; clock_disables++; +} +static int regulator_disable(struct regulator *r) { + return r->index == regulator_error ? -EIO : 0; +} +struct phy { struct qmp_combo *qmp; }; +static void mock_guard(int *lock) { (void)lock; } +static struct qmp_combo *phy_get_drvdata(struct phy *phy) { return phy->qmp; } +static int clk_prepare_enable(int clock) { (void)clock; return 0; } +static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) { + assert(!force); qmp->init_count++; return 0; +} +static int qmp_combo_usb_power_on(struct phy *phy) { (void)phy; return -EIO; } +static int apply_calls, apply_error, rollback_error; +static int qmp_combo_apply_mode(struct qmp_combo *qmp, enum qmpphy_mode mode) { + apply_calls++; + qmp->qmpphy_mode = mode; + if (apply_calls == 2) { + assert(qmp->orientation == NORMAL); + assert(mode == NATIVE); + return rollback_error; + } + assert(qmp->orientation == REVERSE); + return apply_error; +} +''' + cases = r''' +int main(void) { + struct qmp_phy_cfg cfg = { .num_vregs = 2 }; + struct regulator regs[] = {{0}, {1}}; + struct regulator_bulk_data bulk[] = {{®s[0]}, {®s[1]}}; + struct qmp_combo q = { + .cfg = &cfg, .vregs = bulk, .init_count = 1, .vregs_enabled = 3, + .com_powered_on = true, .reset_pending = true, + .pipe_clk_enabled = true, .clks_enabled = true + }; + reset_error = -ETIMEDOUT; + assert(qmp_combo_com_exit(&q, false) == -ETIMEDOUT); + assert(q.init_count == 1 && q.reset_pending && q.vregs_enabled == 3); + assert(!pipe_disables && !clock_disables); + reset_error = 0; regulator_error = 0; + assert(qmp_combo_com_exit(&q, false) == -EIO); + assert(q.init_count == 1 && q.vregs_enabled == 1 && !q.com_powered_on); + assert(pipe_disables == 1 && clock_disables == 1); + regulator_error = -1; + assert(qmp_combo_com_exit(&q, false) == 0); + assert(q.init_count == 0 && q.vregs_enabled == 0); + assert(pipe_disables == 1 && clock_disables == 1); + assert(qmp_combo_com_exit(&q, false) == -EINVAL); + q.init_count = 2; + assert(qmp_combo_com_exit(&q, false) == 0 && q.init_count == 1); + assert(qmp_combo_com_exit(&q, true) == 0 && q.init_count == 1); + apply_error = -EIO; rollback_error = 0; + assert(qmp_combo_reconfigure_phy(&q, REVERSE, USB4) == -EIO); + assert(apply_calls == 2 && q.orientation == NORMAL && q.qmpphy_mode == NATIVE); + apply_calls = 0; rollback_error = -ETIMEDOUT; q.com_powered_on = true; + assert(qmp_combo_reconfigure_phy(&q, REVERSE, USB4) == -EIO); + assert(!q.com_powered_on && q.orientation == NORMAL && q.qmpphy_mode == NATIVE); + apply_calls = 0; apply_error = 0; + assert(qmp_combo_reconfigure_phy(&q, REVERSE, USB4) == 0); + assert(apply_calls == 1 && q.orientation == REVERSE && q.qmpphy_mode == USB4); + struct qmp_combo failed = { + .cfg = &cfg, .vregs = bulk, .reset_pending = true, + .orientation = REVERSE, .p2rr2p_pipe_clk = 1 + }; + struct phy phy = { .qmp = &failed }; + reset_error = -ETIMEDOUT; + assert(qmp_combo_usb_init(&phy) == -EIO); + assert(failed.init_count == 0 && failed.usb_init_count == 0); + apply_calls = 0; + assert(qmp_combo_usb4_init(&phy) == -EIO); + assert(failed.init_count == 0 && failed.usb4_init_count == 0); + return 0; +} +''' + with tempfile.TemporaryDirectory(prefix="a16-qmp-regression-") as tmp: + source = Path(tmp) / "qmp.c" + binary = Path(tmp) / "qmp" + source.write_text(harness + helper + rollback + + function(qmp, "qmp_combo_usb_init") + + function(qmp, "qmp_combo_usb4_init") + cases) + subprocess.run(shlex.split(os.environ.get("HOSTCC", "cc")) + + ["-std=c11", "-Wall", "-Wextra", "-Werror", str(source), "-o", str(binary)], check=True) + subprocess.run([str(binary)], check=True) + print("PASS: compiled QMP reset/regulator failure retries, reference counts, failed USB/USB4 init and Type-C rollback") + + +if __name__ == "__main__": + check(Path(sys.argv[1])) diff --git a/pkgbuilds/linux-omarchy-aarch64/a16-source.json b/pkgbuilds/linux-omarchy-aarch64/a16-source.json new file mode 100644 index 0000000000..16ee703c2b --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/a16-source.json @@ -0,0 +1,42 @@ +{ + "status": "Linux 7.3-5 rebase after Surface Laptop 8 #1706; signed-source replay, native AArch64 object/DTB checks and packaging regressions pass. Full native split-package build and physical A16 acceptance remain pending.", + "kernel_version": "7.3", + "package_revision": 5, + "a16_dsp_abi": 1, + "source_tree": "035c9c08d096b1762f937a942ce9d3c17f2e392e", + "upstream_package_commit": "a8de4a65abd6bf0bfd90fa515d2f160ca280c973", + "upstream_kernel_recipe": "https://github.com/omacom/omarchy-pkgs/tree/a8de4a65abd6bf0bfd90fa515d2f160ca280c973/pkgbuilds/linux-omarchy-aarch64", + "upstream_kernel_sha256": "87363c24f10e06321eb362765521094e94471f6bff8bce2d6b3e40f39f004953", + "board_reference": "https://github.com/FixItFoundry/zenbook-a16-linux/tree/a35b01128b2a45532fd72a2c5dd3caccdfe4ac57/kernel/arch-7.2.10", + "original_contribution_commit": "4c4570e1e1e0a9f75d9522fd67095030c0513dbb", + "patch_review": { + "2500": "Rebased after all 357 shared patches, including #1706. Shared LPASS addresses, USB votes, eDP calibration and LINK_RATE_SET refinements are not duplicated. QMP resource tracking/Type-C rollback, DP error cleanup and synchronized altmode snapshots retain shared USB4 ownership, FEC paths and masked V2 mux values. Invalid cable guards return -EINVAL to the acknowledging worker. Failed USB/USB4 initialization drops its tentative reference even if reset cleanup fails; resource ownership remains tracked for recovery.", + "2501": "Renumbered from 2301; deferred SoundWire codec behavior retained unchanged.", + "2302": "Original A16 block-mq fix remains dropped because Linux 7.3 includes it. Shared patch 2302 is the Surface LPASS regcache change and is retained.", + "2503": "Renumbered from 2303; temporary -EAGAIN battery property handling retained unchanged.", + "shared": "All 357 shared patches, signatures, checksums and config.aarch64 are retained, including TYPEC=y and USB4_QCOM=m from #1706." + }, + "local_patch_sha256": { + "2500-glymur-asus-zenbook-a16-local-hardware-fixes.patch": "e3fbd4e5d252fedebc29214664243490af439e742870bcebb07190e26f9c0825", + "2501-soundwire-qcom-allow-deferred-codecs-at-boot.patch": "768bc9688b9cae6c6e4fdfd5425ae18a4ac5febc659988e88af521b5d963e461", + "2503-power-supply-uevent-eagain.patch": "96760536815e8b44de166ed40c82cf5b9227a3bdbcfd850d639a913339b66d77" + }, + "prior_hardware_acceptance": { + "release": "7.2.8-24-omarchy", + "source_tree": "d05c4879b3789c74e2a73684683b15deb0be258b", + "scope": "Previously reported native build, source replay, both UKIs, early DSPs, audio, keyboard, touchscreen, charger transitions and Bluetooth calls/audio. These results do not validate Linux 7.3-5." + }, + "hardware_required": [ + "Boot both UKIs on A16; verify kernel-release/ABI markers and both early DSPs before root mount", + "Audio playback and microphones; deferred codec reset and recovery", + "Internal display, HDMI/USB-C output, hotplug, failed-link recovery and power transitions", + "Battery/charger transitions and initramfs uevents", + "Wi-Fi and Bluetooth calls/audio, keyboard, touchscreen, USB and storage", + "Native kernel/modules/headers/source package build, packaged-header module compilation and distributed-source replay", + "Other ARM-board regression coverage before shared promotion" + ], + "excluded_acceptance": "Camera and suspend remain disabled in the prior bring-up scope; this rebase supplies no hardware acceptance for them. No OEM firmware or omarchy-a16-support recipe is included.", + "shared_patch_count": 357, + "total_patch_count": 360, + "kernel_release": "7.3.0-5-omarchy" +} diff --git a/pkgbuilds/linux-omarchy-aarch64/a16.config b/pkgbuilds/linux-omarchy-aarch64/a16.config new file mode 100644 index 0000000000..39b6964765 --- /dev/null +++ b/pkgbuilds/linux-omarchy-aarch64/a16.config @@ -0,0 +1,31 @@ +# A16 hardware additions to Omarchy's shared aarch64 kernel config. +CONFIG_PINCTRL_GLYMUR=y +CONFIG_CLK_GLYMUR_GCC=y +CONFIG_CLK_GLYMUR_TCSRCC=y +CONFIG_CLK_GLYMUR_DISPCC=m +CONFIG_CLK_GLYMUR_GPUCC=m +CONFIG_CLK_GLYMUR_CAMCC=m +CONFIG_CLK_GLYMUR_EVACC=m +CONFIG_INTERCONNECT_QCOM_GLYMUR=y +CONFIG_HID_ASUS=m +CONFIG_EC_ASUS_GLYMUR=m +CONFIG_PHY_QCOM_QMP_PCIE_MULTIPHY=m +CONFIG_PHY_QCOM_MIPI_CSI2=m +# SoCCP shared-memory protection requires the bridge backend. +# CONFIG_QCOM_TZMEM_MODE_GENERIC is not set +CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE=y +CONFIG_QCOM_Q6V5_PAS=m +CONFIG_PCI_PWRCTRL_PWRSEQ=y +CONFIG_POWER_SEQUENCING_QCOM_WCN=y +CONFIG_FW_LOADER_COMPRESS_ZSTD=y +CONFIG_SQUASHFS_ZSTD=y +CONFIG_ATH12K_DEBUGFS=y +CONFIG_ATH12K_TRACING=y +# The shared kernel keeps its PHY and USB platform drivers modular. +CONFIG_PHY_QCOM_QMP_PCIE=m +CONFIG_PHY_QCOM_QMP_COMBO=m +CONFIG_PHY_QCOM_QMP_USB=m +CONFIG_PHY_QCOM_M31_EUSB=m +CONFIG_PHY_QCOM_EUSB2_REPEATER=m +CONFIG_USB_DWC3_QCOM=m +CONFIG_RPMSG_QCOM_GLINK_SMEM=m diff --git a/tests/linux-omarchy-a16.py b/tests/linux-omarchy-a16.py new file mode 100644 index 0000000000..f4e48da2e1 --- /dev/null +++ b/tests/linux-omarchy-a16.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""Check recipe integrity and the release/ABI contract without downloading Linux.""" +import hashlib +import json +from pathlib import Path +import subprocess + +recipe = Path(__file__).resolve().parents[1] / 'pkgbuilds/linux-omarchy-aarch64' +keys = ['source', 'source_aarch64', 'sha256sums', 'sha256sums_aarch64', + 'b2sums', 'b2sums_aarch64', 'pkgname'] +command = 'CARCH=aarch64; source "$1"; ' +for key in keys: + command += 'printf "%s\\0" "${' + key + '[@]}"; printf "\\1"; ' +command += 'printf "%s\\0" "$pkgver" "$pkgrel"' +parts = subprocess.check_output(['bash', '-c', command, 'bash', str(recipe / 'PKGBUILD')]).split(b'\1') +arrays = {key: [v.decode() for v in part.split(b'\0') if v] for key, part in zip(keys, parts)} +version, revision = [v.decode() for v in parts[-1].split(b'\0') if v] +manifest = json.loads((recipe / 'a16-source.json').read_text()) +assert manifest['kernel_version'] == version +assert manifest['package_revision'] == int(revision) +upstream_version = version + '.0' if version.count('.') == 1 else version +assert manifest['kernel_release'] == f'{upstream_version}-{revision}-omarchy' +assert manifest['a16_dsp_abi'] == 1 +assert len(manifest['source_tree']) == 40 +assert arrays['pkgname'] == ['linux-omarchy', 'linux-omarchy-headers', 'linux-omarchy-aarch64-source'] +count = 0 +for suffix in ['', '_aarch64']: + sources = arrays['source' + suffix] + for key, algorithm in [('sha256sums', hashlib.sha256), ('b2sums', hashlib.blake2b)]: + sums = arrays[key + suffix] + assert len(sources) == len(sums), (key, suffix, len(sources), len(sums)) + for source, expected in zip(sources, sums): + if source.startswith('https://'): + continue + if expected == 'SKIP': + assert source.endswith('.sig'), source + continue + assert algorithm((recipe / source).read_bytes()).hexdigest() == expected, source + count += len(sources) +patches = [p for p in arrays['source'] if p.endswith('.patch')] +assert len(patches) == manifest['total_patch_count'] == manifest['shared_patch_count'] + 3 +assert not any(p.startswith('2502-') for p in patches) +assert len({p.split('-', 1)[0] for p in patches}) == len(patches) +assert '2302-ASoC-codecs-lpass-wsa-macro-switch-cache-to-REGCACHE.patch' in patches +assert '2434-arm64-dts-qcom-surface-laptop8-Disable-the-Wi-Fi-har.patch' in patches +assert all(p.startswith(('2500-', '2501-', '2503-')) for p in manifest['local_patch_sha256']) +assert '2300-glymur-asus-zenbook-a16-board-support.patch' not in patches +assert '2210-arm64-dts-qcom-hamoa-glymur-Disable-the-crypto-engine.patch' in patches +for patch, expected in manifest['local_patch_sha256'].items(): + assert patch in patches + assert hashlib.sha256((recipe / patch).read_bytes()).hexdigest() == expected +print(f'PASS: {count} declared inputs, aligned checksums, {len(patches)} patches and matching source/release/ABI metadata') diff --git a/tests/linux-omarchy-source.sh b/tests/linux-omarchy-source.sh new file mode 100755 index 0000000000..ac4c28b5ca --- /dev/null +++ b/tests/linux-omarchy-source.sh @@ -0,0 +1,67 @@ +#!/bin/bash +set -euo pipefail +ROOT=$(realpath "${BASH_SOURCE[0]%/*}/..") +CARCH=aarch64 +source "$ROOT/pkgbuilds/linux-omarchy-aarch64/PKGBUILD" +[[ " ${pkgname[*]} " == *" linux-omarchy-aarch64-source "* ]] +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT +startdir=$scratch/recipe +srcdir=$scratch/inputs +pkgdir=$scratch/package +mkdir -p "$startdir" "$srcdir/$_srcname" "$pkgdir" +cp "$ROOT/pkgbuilds/linux-omarchy-aarch64/PKGBUILD" "$startdir/PKGBUILD" +source=(linux.tar.xz public.patch offline.patch::https://example.invalid/patch) +source_aarch64=(config.aarch64) +for input in "${source[@]}" "${source_aarch64[@]}"; do + input=${input%%::*} + echo "$input" > "$srcdir/$input" +done +SRCDEST=$scratch/downloads +mkdir -p "$SRCDEST" "$startdir/keys/pgp" +mv "$srcdir/linux.tar.xz" "$SRCDEST/linux.tar.xz" +echo public-key > "$startdir/keys/pgp/key.asc" +echo config > "$srcdir/$_srcname/.config" +echo release > "$srcdir/$_srcname/version" +echo private > "$srcdir/vendor-firmware.exe" +_package-aarch64-source +cd "$pkgdir/usr/src/$pkgbase" +sha256sum -c SHA256SUMS +[[ -f linux.tar.xz && -f PKGBUILD && -f BUILD_CONFIG && -f KERNEL_RELEASE ]] +[[ -f offline.patch && -f public.patch && -f keys/pgp/key.asc ]] +[[ ! -e vendor-firmware.exe ]] +echo tampered >> offline.patch +if sha256sum -c SHA256SUMS >/dev/null 2>&1; then + echo 'FAIL: source manifest accepted a modified input' + exit 1 +fi +echo 'PASS: complete declared source inputs and recipe are packaged; unrelated vendor files are excluded' + +# Exercise the real kernel package function with a fixture module installer. +# Its ABI marker/release/config paths are consumed by the separate support package. +source "$ROOT/pkgbuilds/linux-omarchy-aarch64/PKGBUILD" +pkgdir=$scratch/kernel-package +srcdir=$scratch/inputs +cd "$srcdir" +mkdir -p "$_srcname/arch/arm64/boot/dts/qcom" +python -c 'import json,sys; print(json.load(open(sys.argv[1]))["kernel_release"])' "$ROOT/pkgbuilds/linux-omarchy-aarch64/a16-source.json" > "$_srcname/version" +echo image > "$_srcname/arch/arm64/boot/Image" +for dtb in glymur-asus-zenbook-a16-ux3607oa x1-fixture hamoa-fixture sc8280xp-fixture; do + echo dtb > "$_srcname/arch/arm64/boot/dts/qcom/$dtb.dtb" +done +cp "$ROOT/pkgbuilds/linux-omarchy-aarch64/a16-source.json" a16-source.json +make() { + local modulesdir="$pkgdir/usr/lib/modules/$(