diff --git a/Documentation/devicetree/bindings/arm/qcom.yaml b/Documentation/devicetree/bindings/arm/qcom.yaml index ff8a35df78..b0400d5a17 100644 --- a/Documentation/devicetree/bindings/arm/qcom.yaml +++ b/Documentation/devicetree/bindings/arm/qcom.yaml @@ -1168,6 +1168,7 @@ properties: - items: - enum: + - oneplus,dodge - qcom,sm8750-mtp - qcom,sm8750-qrd - const: qcom,sm8750 diff --git a/Documentation/devicetree/bindings/display/msm/gmu.yaml b/Documentation/devicetree/bindings/display/msm/gmu.yaml index 9e459f12ce..1f9307e174 100644 --- a/Documentation/devicetree/bindings/display/msm/gmu.yaml +++ b/Documentation/devicetree/bindings/display/msm/gmu.yaml @@ -335,7 +335,9 @@ allOf: properties: compatible: contains: - const: qcom,adreno-gmu-840.1 + enum: + - qcom,adreno-gmu-830.1 + - qcom,adreno-gmu-840.1 then: properties: reg: diff --git a/Documentation/devicetree/bindings/display/msm/gpu.yaml b/Documentation/devicetree/bindings/display/msm/gpu.yaml index e5efe2d35d..bfa0f89520 100644 --- a/Documentation/devicetree/bindings/display/msm/gpu.yaml +++ b/Documentation/devicetree/bindings/display/msm/gpu.yaml @@ -451,6 +451,7 @@ allOf: - qcom,adreno-43050c01 - qcom,adreno-43051401 - qcom,adreno-44010000 + - qcom,adreno-44050000 - qcom,adreno-44050a01 - qcom,adreno-44070001 diff --git a/Documentation/devicetree/bindings/display/panel/oneplus,dodge-panel.yaml b/Documentation/devicetree/bindings/display/panel/oneplus,dodge-panel.yaml new file mode 100644 index 0000000000..abfdc5718e --- /dev/null +++ b/Documentation/devicetree/bindings/display/panel/oneplus,dodge-panel.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/panel/oneplus,dodge-panel.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: OnePlus 13 (dodge) DSC panel + +maintainers: + - Martin Lund + +description: + DSC panel used on the OnePlus 13 (dodge), driven by + drivers/gpu/drm/panel/panel-aa569-p-3-a0019-dsc.c. + +allOf: + - $ref: panel-common.yaml# + +properties: + compatible: + const: oneplus,dodge-panel + + reg: + maxItems: 1 + + vddio-supply: true + vci-supply: true + vdd-supply: true + reset-gpios: true + port: true + +required: + - compatible + - reg + - reset-gpios + +unevaluatedProperties: false + +... diff --git a/Documentation/devicetree/bindings/input/touchscreen/synaptics,tcm-spi-hbp.yaml b/Documentation/devicetree/bindings/input/touchscreen/synaptics,tcm-spi-hbp.yaml new file mode 100644 index 0000000000..2f146578c3 --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/synaptics,tcm-spi-hbp.yaml @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/synaptics,tcm-spi-hbp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Synaptics TouchComm SPI HBP touchscreen (S3910 and similar) + +maintainers: + - Martin Lund + +description: | + Synaptics touchscreen controllers that use the TouchComm host-based + protocol over SPI. Bound by drivers/input/touchscreen/syna_tcm2_spi.c + as compatible "synaptics,tcm-spi-hbp" (OnePlus 13 S3910). + + Panel size and TX/RX counts stay as vendor properties because the + carried Synaptics driver reads them via of_property_read_u32_array + rather than touchscreen_parse_properties(). Reset/AVDD/IRQ similarly + use the driver's own GPIO helpers. + +allOf: + - $ref: touchscreen.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: synaptics,tcm-spi-hbp + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: true + + synaptics,irq-gpio: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: ATTN GPIO (duplicates interrupts for the vendor driver) + maxItems: 1 + + synaptics,reset-gpio: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: Reset GPIO + maxItems: 1 + + synaptics,avdd-gpio: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: AVDD enable GPIO + maxItems: 1 + + synaptics,panel-coords: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Panel max X and Y coordinates in firmware units + minItems: 2 + maxItems: 2 + + synaptics,tx-rx-num: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: TX and RX channel counts + minItems: 2 + maxItems: 2 + +required: + - compatible + - reg + - interrupts + +unevaluatedProperties: false + +... diff --git a/Documentation/devicetree/bindings/net/bluetooth/qcom,wcn7850-bt.yaml b/Documentation/devicetree/bindings/net/bluetooth/qcom,wcn7850-bt.yaml index 8108ef83e9..696f09a6bd 100644 --- a/Documentation/devicetree/bindings/net/bluetooth/qcom,wcn7850-bt.yaml +++ b/Documentation/devicetree/bindings/net/bluetooth/qcom,wcn7850-bt.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/net/bluetooth/qcom,wcn7850-bt.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Qualcomm WCN7850 Bluetooth +title: Qualcomm WCN7850/WCN7860 Bluetooth maintainers: - Bartosz Golaszewski @@ -15,6 +15,7 @@ properties: compatible: enum: - qcom,wcn7850-bt + - qcom,wcn7860-bt enable-gpios: maxItems: 1 diff --git a/Documentation/devicetree/bindings/net/qcom,ipa.yaml b/Documentation/devicetree/bindings/net/qcom,ipa.yaml index 68ec76fe44..898505c62b 100644 --- a/Documentation/devicetree/bindings/net/qcom,ipa.yaml +++ b/Documentation/devicetree/bindings/net/qcom,ipa.yaml @@ -44,6 +44,7 @@ properties: compatible: oneOf: - enum: + - qcom,eliza-ipa - qcom,milos-ipa - qcom,msm8998-ipa - qcom,sc7180-ipa @@ -54,6 +55,7 @@ properties: - qcom,sm6350-ipa - qcom,sm8350-ipa - qcom,sm8550-ipa + - qcom,sm8750-ipa - items: - enum: - qcom,qcm2290-ipa diff --git a/Documentation/devicetree/bindings/sound/awinic,aw882308.yaml b/Documentation/devicetree/bindings/sound/awinic,aw882308.yaml new file mode 100644 index 0000000000..89ccad8c97 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/awinic,aw882308.yaml @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/awinic,aw882308.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Awinic AW882308 Smart Audio Amplifier + +maintainers: + - Martin Lund + +description: + The Awinic AW882308 (chip id 0x2308) is an I2C controlled, I2S/TDM + input mono smart audio amplifier with an integrated boost converter, + used for the speakers and earpiece of the OnePlus 13. + +properties: + compatible: + const: awinic,aw882308 + + reg: + maxItems: 1 + + '#sound-dai-cells': + const: 0 + + reset-gpios: + maxItems: 1 + + sound-name-prefix: true + +required: + - compatible + - reg + - '#sound-dai-cells' + +allOf: + - $ref: dai-common.yaml# + +unevaluatedProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + audio-codec@34 { + compatible = "awinic,aw882308"; + reg = <0x34>; + reset-gpios = <&tlmm 2 GPIO_ACTIVE_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Left"; + }; + }; diff --git a/arch/arm64/boot/dts/qcom/Makefile b/arch/arm64/boot/dts/qcom/Makefile index 1c86e7e98f..9559330a25 100644 --- a/arch/arm64/boot/dts/qcom/Makefile +++ b/arch/arm64/boot/dts/qcom/Makefile @@ -407,6 +407,7 @@ dtb-$(CONFIG_ARCH_QCOM) += sm8650-hdk.dtb dtb-$(CONFIG_ARCH_QCOM) += sm8650-mtp.dtb dtb-$(CONFIG_ARCH_QCOM) += sm8650-qrd.dtb dtb-$(CONFIG_ARCH_QCOM) += sm8750-mtp.dtb +dtb-$(CONFIG_ARCH_QCOM) += sm8750-oneplus-dodge.dtb dtb-$(CONFIG_ARCH_QCOM) += sm8750-qrd.dtb dtb-$(CONFIG_ARCH_QCOM) += talos-evk.dtb diff --git a/arch/arm64/boot/dts/qcom/sm8750-oneplus-dodge.dts b/arch/arm64/boot/dts/qcom/sm8750-oneplus-dodge.dts new file mode 100644 index 0000000000..2917b753c7 --- /dev/null +++ b/arch/arm64/boot/dts/qcom/sm8750-oneplus-dodge.dts @@ -0,0 +1,1543 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2025 index986. All rights reserved. + */ + +/dts-v1/; + +#include +#include +#include +#include +#include "sm8750.dtsi" +#include "pm8010.dtsi" +#include "pm8550.dtsi" +#define PMK8550VE_SID 8 +#include "pm8550ve.dtsi" +#include "pmih0108.dtsi" +#include "pmk8550.dtsi" +#include "pmr735d_a.dtsi" +#include "sm8750-pmics.dtsi" + +/delete-node/ &{/reserved-memory}; + +/ { + model = "OnePlus 13"; + compatible = "oneplus,dodge", "qcom,sm8750"; + chassis-type = "handset"; + + sound { + compatible = "qcom,sm8750-sndcard", "qcom,sm8450-sndcard"; + model = "OnePlus-dodge"; + + pinctrl-0 = <&i2s1_active>; + pinctrl-names = "default"; + + /* Mic bias wiring as on stock; AMIC2 is the USB-C headset mic. */ + audio-routing = "AMIC1", "MIC BIAS1", + "AMIC2", "MIC BIAS2", + "AMIC3", "MIC BIAS4", + "AMIC4", "MIC BIAS3", + "AMIC5", "MIC BIAS1", + "IN1_HPHL", "HPHL_OUT", + "IN2_HPHR", "HPHR_OUT", + "TX SWR_INPUT0", "ADC1_OUTPUT", + "TX SWR_INPUT1", "ADC2_OUTPUT", + "TX SWR_INPUT2", "ADC3_OUTPUT", + "TX SWR_INPUT3", "ADC4_OUTPUT"; + + wcd-playback-dai-link { + link-name = "WCD Playback"; + + cpu { + sound-dai = <&q6apmbedai RX_CODEC_DMA_RX_0>; + }; + + codec { + sound-dai = <&wcd939x 0>, <&swr1 0>, <&lpass_rxmacro 0>; + }; + + platform { + sound-dai = <&q6apm>; + }; + }; + + wcd-capture-dai-link { + link-name = "WCD Capture"; + + cpu { + sound-dai = <&q6apmbedai TX_CODEC_DMA_TX_3>; + }; + + codec { + sound-dai = <&wcd939x 1>, <&swr2 0>, <&lpass_txmacro 0>; + }; + + platform { + sound-dai = <&q6apm>; + }; + }; + + speaker-dai-link { + link-name = "Speaker Playback"; + + cpu { + sound-dai = <&q6apmbedai SECONDARY_MI2S_RX>; + }; + + codec { + sound-dai = <&speaker_left>, <&speaker_right>; + }; + + platform { + sound-dai = <&q6apm>; + }; + }; + }; + + wcd939x: audio-codec { + compatible = "qcom,wcd9395-codec", "qcom,wcd9390-codec"; + + pinctrl-0 = <&wcd_default>; + pinctrl-names = "default"; + + /* Stock runs all four mic biases at 2.7 V. */ + qcom,micbias1-microvolt = <2700000>; + qcom,micbias2-microvolt = <2700000>; + qcom,micbias3-microvolt = <2700000>; + qcom,micbias4-microvolt = <2700000>; + qcom,mbhc-buttons-vthreshold-microvolt = <75000 150000 237000 500000 500000 500000 500000 500000>; + qcom,mbhc-headset-vthreshold-microvolt = <1700000>; + qcom,mbhc-headphone-vthreshold-microvolt = <50000>; + qcom,rx-device = <&wcd_rx>; + qcom,tx-device = <&wcd_tx>; + + reset-gpios = <&tlmm 101 GPIO_ACTIVE_LOW>; + + vdd-buck-supply = <&vreg_l15b_1p8>; + vdd-rxtx-supply = <&vreg_l15b_1p8>; + vdd-io-supply = <&vreg_l15b_1p8>; + vdd-mic-bias-supply = <&vreg_bob1>; + + #sound-dai-cells = <1>; + + /* No 3.5 mm jack: the headset is analog audio over USB-C. */ + mode-switch; + orientation-switch; + + port { + wcd_codec_headset_in: endpoint { + remote-endpoint = <&wcd_usbss_headset_out>; + }; + }; + }; + + aliases { + serial0 = &uart7; + }; + + + chosen { + #address-cells = <2>; + #size-cells = <2>; + ranges; + }; + + pmic-glink { + compatible = "qcom,sm8750-pmic-glink", + "qcom,sm8550-pmic-glink", + "qcom,pmic-glink"; + #address-cells = <1>; + #size-cells = <0>; + orientation-gpios = <&tlmm 61 GPIO_ACTIVE_HIGH>; // qrd value + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + pmic_glink_hs_in: endpoint { + remote-endpoint = <&usb_dwc3_hs>; + }; + }; + + port@1 { + reg = <1>; + pmic_glink_ss_in: endpoint { + remote-endpoint = <&usb_dp_qmpphy_out>; + }; + }; + + port@2 { + reg = <2>; + pmic_glink_sbu: endpoint { + remote-endpoint = <&wcd_usbss_sbu_mux>; + }; + }; + }; + }; + }; + + bat: battery { + compatible = "simple-battery"; + voltage-min-design-microvolt = <6300000>; + }; + + clocks { + xo_board: xo-board { + compatible = "fixed-clock"; + clock-frequency = <76800000>; + #clock-cells = <0>; + }; + + sleep_clk: sleep-clk { + compatible = "fixed-clock"; + clock-frequency = <32000>; + #clock-cells = <0>; + }; + + bi_tcxo_div2: bi-tcxo-div2-clk { + compatible = "fixed-factor-clock"; + #clock-cells = <0>; + + clocks = <&rpmhcc RPMH_CXO_CLK>; + clock-mult = <1>; + clock-div = <2>; + }; + + bi_tcxo_ao_div2: bi-tcxo-ao-div2-clk { + compatible = "fixed-factor-clock"; + #clock-cells = <0>; + + clocks = <&rpmhcc RPMH_CXO_CLK_A>; + clock-mult = <1>; + clock-div = <2>; + }; + }; + + reserved_memory: reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + hyp_mem: hyp-region@80000000 { + no-map; + reg = <0x00 0x80000000 0x00 0xe00000>; + }; + + cpusys_vm_mem: cpusys-vm-region@80e00000 { + no-map; + reg = <0x00 0x80e00000 0x00 0x400000>; + }; + + cpucp_mem: cpucp@81200000 { + no-map; + reg = <0x00 0x81200000 0x00 0x200000>; + }; + + bl_dtlog_mem: xbl-dtlog@81a00000 { + no-map; + reg = <0x00 0x81a00000 0x00 0x40000>; + }; + + aop_image_mem: aop-image@81c00000 { + no-map; + reg = <0x00 0x81c00000 0x00 0x60000>; + }; + + aop_cmd_db_mem: aop-cmd-db@81c60000 { + compatible = "qcom,cmd-db"; + no-map; + reg = <0x00 0x81c60000 0x00 0x20000>; + }; + + aop_tme_uefi_merged_mem: aop-tme-uefi-merged@81c80000 { + no-map; + reg = <0x00 0x81c80000 0x00 0x74000>; + }; + + smem_region@81d00000 { + compatible = "qcom,smem"; + reg = <0x00 0x81d00000 0x00 0x200000>; + hwlocks = <&tcsr_mutex 3>; + no-map; + }; + + pdp_ns_shared_mem: pdp-ns-shared@81f00000 { + no-map; + reg = <0x00 0x81f00000 0x00 0x100000>; + }; + + cpucp_scandump_mem: cpucp-scandump@82000000 { + no-map; + reg = <0x00 0x82000000 0x00 0x380000>; + }; + + adsp_mhi_mem: adsp-mhi@82380000 { + no-map; + reg = <0x00 0x82380000 0x00 0x20000>; + }; + + soccp_sdi_mem: soccp-sdi@823a0000 { + no-map; + reg = <0x00 0x823a0000 0x00 0x40000>; + }; + + pmic_minii_dump_mem: pmic-minii-dump@823e0000 { + no-map; + reg = <0x00 0x823e0000 0x00 0x80000>; + }; + + pvmfw_mem: pvmfw@824a0000 { + no-map; + reg = <0x00 0x824a0000 0x00 0x100000>; + }; + + global_sync_mem: global-sync@82600000 { + no-map; + reg = <0x00 0x82600000 0x00 0x100000>; + }; + + tz_stat_mem: tz-stat@82700000 { + no-map; + reg = <0x00 0x82700000 0x00 0x100000>; + }; + + qdss_mem: qdss@82800000 { + compatible = "shared-dma-pool"; + reg = <0x00 0x82800000 0x00 0x2000000>; + no-map; + }; + + dsm_partition_1_mem: dsm-partition-1@84a00000 { + no-map; + reg = <0x00 0x84a00000 0x00 0x4900000>; + }; + + dsm_partition_2_mem: dsm-partition-2@89300000 { + no-map; + reg = <0x00 0x89300000 0x00 0xa80000>; + }; + + mpss_mem: mpss@8ba00000 { + no-map; + reg = <0x00 0x8ba00000 0x00 0xf600000>; + }; + + q6_mpss_dtb_mem: q6-mpss-dtb@9b000000 { + no-map; + reg = <0x00 0x9b000000 0x00 0x80000>; + }; + + ipa_fw_mem: ipa-fw@9b080000 { + no-map; + reg = <0x00 0x9b080000 0x00 0x10000>; + }; + + ipa_gsi_mem: ipa-gsi@9b090000 { + no-map; + reg = <0x00 0x9b090000 0x00 0xa000>; + }; + + gpu_micro_code_mem: gpu-micro-code@9b09a000 { + no-map; + reg = <0x00 0x9b09a000 0x00 0x2000>; + }; + + spss_region_region@9b0a0000 { + no-map; + reg = <0x00 0x9b0a0000 0x00 0x1e0000>; + }; + + /* First part of the "SPU secure shared memory" region */ + spu_tz_shared_mem: spu-tz-shared@9b280000 { + no-map; + reg = <0x00 0x9b280000 0x00 0x40000>; + }; + + /* Second part of the "SPU secure shared memory" region */ + spu_modem_shared_mem: spu-modem-shared@9b2c0000 { + no-map; + reg = <0x00 0x9b2c0000 0x00 0x40000>; + }; + + camera_mem: camera@9b300000 { + no-map; + reg = <0x00 0x9b300000 0x00 0x800000>; + }; + + camera_2_mem: camera-2@9bb00000 { + no-map; + reg = <0x00 0x9bb00000 0x00 0x800000>; + }; + + video_mem: video@9c300000 { + no-map; + reg = <0x00 0x9c300000 0x00 0x800000>; + }; + + cvp_mem: cvp@9cb00000 { + no-map; + reg = <0x00 0x9cb00000 0x00 0x700000>; + }; + + cdsp_mem: cdsp@9d200000 { + no-map; + reg = <0x00 0x9d200000 0x00 0x1900000>; + }; + + q6_cdsp_dtb_mem: q6-cdsp-dtb@9eb00000 { + no-map; + reg = <0x00 0x9eb00000 0x00 0x80000>; + }; + + soccp_mem: soccp@9ec00000 { + no-map; + reg = <0x00 0x9ec00000 0x00 0x180000>; + }; + + q6_adsp_dtb_mem: q6-adsp-dtb@9ed80000 { + no-map; + reg = <0x00 0x9ed80000 0x00 0x80000>; + }; + + adspslpi_mem: adspslpi@9ee00000 { + no-map; + reg = <0x00 0x9ee00000 0x00 0x5a80000>; + }; + + xbl_ramdump_mem: xbl-ramdump@b8000000 { + no-map; + reg = <0x00 0xb8000000 0x00 0x1c0000>; + }; + + hwfence_shbuf: hwfence-shbuf@d4e23000 { + no-map; + reg = <0x00 0xd4e23000 0x00 0x2dd000>; + }; + + /* + * Stock allocates a 4 MiB rmtfs buffer (client-id 1) at boot. Upstream + * needs a fixed carve-out; this is the same place SM8650 uses, just + * below tz_merged, and it is plain System RAM on stock and here. + */ + rmtfs_mem: rmtfs@d7c00000 { + compatible = "qcom,rmtfs-mem"; + reg = <0x00 0xd7c00000 0x00 0x400000>; + no-map; + + qcom,client-id = <1>; + qcom,vmid = ; + }; + + /* Merged tz_reserved, xbl_sc, and qtee regions */ + tz_merged_mem: tz-merged@d8000000 { + no-map; + reg = <0x00 0xd8000000 0x00 0x600000>; + }; + + trust_ui_vm_mem: trust-ui-vm@f3800000 { + compatible = "shared-dma-pool"; + reg = <0x00 0xf3800000 0x00 0x4400000>; + no-map; + }; + + oem_vm_mem: oem-vm@f7c00000 { + compatible = "shared-dma-pool"; + reg = <0x00 0xf7c00000 0x00 0x4c00000>; + no-map; + }; + + llcc_lpi_mem: llcc-lpi@ff800000 { + no-map; + reg = <0x00 0xff800000 0x00 0x800000>; + }; + + device_info_mem: memory@a4f00000 { + no-map; + reg = <0x00 0xa4f00000 0x00 0x8000>; + label = "dump_device_info_mem"; + }; + }; + + gpio-keys { + compatible = "gpio-keys"; + + pinctrl-0 = <&volume_down_n>; + pinctrl-names = "default"; + + key-volume-down { + label = "Volume Down"; + linux,code = ; + gpios = <&pm8550_gpios 6 GPIO_ACTIVE_LOW>; + debounce-interval = <15>; + linux,can-disable; + wakeup-source; + }; + }; + + vph_pwr: vph-pwr-regulator { + compatible = "regulator-fixed"; + + regulator-name = "vph_pwr"; + regulator-min-microvolt = <3700000>; + regulator-max-microvolt = <3700000>; + + regulator-always-on; + regulator-boot-on; + }; + + wcn7850-pmu { + compatible = "qcom,wcn7850-pmu"; + + pinctrl-names = "default"; + pinctrl-0 = <&wlan_en>, <&bt_default>; + + wlan-enable-gpios = <&tlmm 16 GPIO_ACTIVE_HIGH>; + bt-enable-gpios = <&pm8550ve_f_gpios 3 GPIO_ACTIVE_HIGH>; + + vdd-supply = <&vreg_s5f_0p85>; + vddio-supply = <&vreg_l3f_1p8>; + vddio1p2-supply = <&vreg_l2f_1p2>; + vddaon-supply = <&vreg_s4d_0p85>; + vdddig-supply = <&vreg_s1d_0p97>; + vddrfa1p2-supply = <&vreg_s7i_1p2>; + vddrfa1p8-supply = <&vreg_s3g_1p8>; + + status = "okay"; + + clocks = <&rpmhcc RPMH_RF_CLK1>; + + 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"; + }; + }; + }; +}; + +&apps_rsc { + regulators-0 { + compatible = "qcom,pm8550-rpmh-regulators"; + + vdd-bob1-supply = <&vph_pwr>; + vdd-bob2-supply = <&vph_pwr>; + vdd-l1-l4-l10-supply = <&vreg_s3g_1p8>; + vdd-l2-l13-l14-supply = <&vreg_bob1>; + vdd-l3-supply = <&vreg_s7i_1p2>; + vdd-l5-l16-supply = <&vreg_bob1>; + vdd-l6-l7-supply = <&vreg_bob1>; + vdd-l8-l9-supply = <&vreg_bob1>; + vdd-l11-supply = <&vreg_s7i_1p2>; + vdd-l12-supply = <&vreg_s3g_1p8>; + vdd-l15-supply = <&vreg_s3g_1p8>; + vdd-l17-supply = <&vreg_bob2>; + + qcom,pmic-id = "b"; + + vreg_bob1: bob1 { + regulator-name = "vreg_bob1"; + regulator-min-microvolt = <3008000>; + regulator-max-microvolt = <3960000>; + regulator-initial-mode = ; + }; + + vreg_bob2: bob2 { + regulator-name = "vreg_bob2"; + regulator-min-microvolt = <2704000>; + regulator-max-microvolt = <3008000>; + regulator-initial-mode = ; + }; + + vreg_l1b_1p8: ldo1 { + regulator-name = "vreg_l1b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l2b_3p0: ldo2 { + regulator-name = "vreg_l2b_3p0"; + regulator-min-microvolt = <3008000>; + regulator-max-microvolt = <3048000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l4b_1p8: ldo4 { + regulator-name = "vreg_l4b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l5b_3p1: ldo5 { + regulator-name = "vreg_l5b_3p1"; + regulator-min-microvolt = <3100000>; + regulator-max-microvolt = <3148000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l6b_1p8: ldo6 { + regulator-name = "vreg_l6b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <3008000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l7b_1p8: ldo7 { + regulator-name = "vreg_l7b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <3008000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l8b_1p8: ldo8 { + regulator-name = "vreg_l8b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <3008000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l9b_2p9: ldo9 { + regulator-name = "vreg_l9b_2p9"; + regulator-min-microvolt = <2960000>; + regulator-max-microvolt = <3008000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l10b_1p8: ldo10 { + regulator-name = "vreg_l10b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l11b_1p0: ldo11 { + regulator-name = "vreg_l11b_1p0"; + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <1100000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l12b_1p8: ldo12 { + regulator-name = "vreg_l12b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l13b_3p0: ldo13 { + regulator-name = "vreg_l13b_3p0"; + regulator-min-microvolt = <3000000>; + regulator-max-microvolt = <3000000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l14b_3p2: ldo14 { + regulator-name = "vreg_l14b_3p2"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l15b_1p8: ldo15 { + regulator-name = "vreg_l15b_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l16b_2p8: ldo16 { + regulator-name = "vreg_l16b_2p8"; + regulator-min-microvolt = <3000000>; + regulator-max-microvolt = <3200000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l17b_2p5: ldo17 { + regulator-name = "vreg_l17b_2p5"; + regulator-min-microvolt = <2504000>; + regulator-max-microvolt = <2504000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + }; + + regulators-1 { + compatible = "qcom,pm8550ve-rpmh-regulators"; + + vdd-l1-supply = <&vreg_s7i_1p2>; + vdd-l2-supply = <&vreg_s1d_0p97>; + vdd-l3-supply = <&vreg_s1d_0p97>; + vdd-s1-supply = <&vph_pwr>; + vdd-s3-supply = <&vph_pwr>; + vdd-s4-supply = <&vph_pwr>; + + qcom,pmic-id = "d"; + + vreg_s1d_0p97: smps1 { + regulator-name = "vreg_s1d_0p97"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <1100000>; + regulator-initial-mode = ; + }; + + vreg_s3d_1p2: smps3 { + regulator-name = "vreg_s3d_1p2"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1300000>; + regulator-initial-mode = ; + }; + + vreg_s4d_0p85: smps4 { + regulator-name = "vreg_s4d_0p85"; + regulator-min-microvolt = <852000>; + regulator-max-microvolt = <1036000>; + regulator-initial-mode = ; + }; + + vreg_l1d_1p2: ldo1 { + regulator-name = "vreg_l1d_1p2"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l2d_0p88: ldo2 { + regulator-name = "vreg_l2d_0p88"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <912000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l3d_0p88: ldo3 { + regulator-name = "vreg_l3d_0p88"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <920000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + }; + + regulators-2 { + compatible = "qcom,pm8550ve-rpmh-regulators"; + + vdd-l1-supply = <&vreg_s1d_0p97>; + vdd-l2-supply = <&vreg_s7i_1p2>; + vdd-l3-supply = <&vreg_s3g_1p8>; + vdd-s5-supply = <&vph_pwr>; + + qcom,pmic-id = "f"; + + vreg_s5f_0p85: smps5 { + regulator-name = "vreg_s5f_0p85"; + regulator-min-microvolt = <852000>; + regulator-max-microvolt = <1000000>; + regulator-initial-mode = ; + }; + + vreg_l1f_0p88: ldo1 { + regulator-name = "vreg_l1f_0p88"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <920000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l2f_1p2: ldo2 { + regulator-name = "vreg_l2f_1p2"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l3f_1p8: ldo3 { + regulator-name = "vreg_l3f_1p8"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + }; + + regulators-3 { + compatible = "qcom,pm8550ve-rpmh-regulators"; + + vdd-l1-supply = <&vreg_s1d_0p97>; + vdd-l2-supply = <&vreg_s3g_1p8>; + vdd-l3-supply = <&vreg_s7i_1p2>; + vdd-s1-supply = <&vph_pwr>; + vdd-s3-supply = <&vph_pwr>; + + qcom,pmic-id = "g"; + + vreg_s1g_0p5: smps1 { + regulator-name = "vreg_s1g_0p5"; + regulator-min-microvolt = <300000>; + regulator-max-microvolt = <700000>; + regulator-initial-mode = ; + }; + + vreg_s3g_1p8: smps3 { + regulator-name = "vreg_s3g_1p8"; + regulator-min-microvolt = <1856000>; + regulator-max-microvolt = <2000000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_s4g_0p75: smps4 { + regulator-name = "vreg_s4g_0p75"; + regulator-min-microvolt = <300000>; + regulator-max-microvolt = <900000>; + regulator-initial-mode = ; + }; + + vreg_l1g_0p91: ldo1 { + regulator-name = "vreg_l1g_0p91"; + regulator-min-microvolt = <912000>; + regulator-max-microvolt = <936000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l2g_1p8: ldo2 { + regulator-name = "vreg_l2g_1p8"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1860000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l3g_1p2: ldo3 { + regulator-name = "vreg_l3g_1p2"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1256000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + }; + + regulators-4 { + compatible = "qcom,pm8550ve-rpmh-regulators"; + + vdd-l1-supply = <&vreg_s7i_1p2>; + vdd-l2-supply = <&vreg_s7i_1p2>; + vdd-l3-supply = <&vreg_s1d_0p97>; + vdd-s7-supply = <&vph_pwr>; + vdd-s8-supply = <&vph_pwr>; + + qcom,pmic-id = "i"; + + vreg_s7i_1p2: smps7 { + regulator-name = "vreg_s7i_1p2"; + regulator-min-microvolt = <1224000>; + regulator-max-microvolt = <1340000>; + regulator-initial-mode = ; + }; + + vreg_s8i_0p9: smps8 { + regulator-name = "vreg_s8i_0p9"; + regulator-min-microvolt = <900000>; + regulator-max-microvolt = <972000>; + regulator-initial-mode = ; + }; + + vreg_l1i_1p2: ldo1 { + regulator-name = "vreg_l1i_1p2"; + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <1200000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l2i_1p2: ldo2 { + regulator-name = "vreg_l2i_1p2"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l3i_0p88: ldo3 { + regulator-name = "vreg_l3i_0p88"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <912000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + }; + + regulators-5 { + compatible = "qcom,pm8550vs-rpmh-regulators"; + + vdd-l1-supply = <&vreg_s1d_0p97>; + vdd-l2-supply = <&vreg_s7i_1p2>; + vdd-s2-supply = <&vph_pwr>; + vdd-s3-supply = <&vph_pwr>; + + qcom,pmic-id = "j"; + + vreg_s2j_1p1: smps2 { + regulator-name = "vreg_s2j_1p1"; + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <1100000>; + regulator-initial-mode = ; + }; + + vreg_s3j_1p1: smps3 { + regulator-name = "vreg_s3j_1p1"; + regulator-min-microvolt = <1000000>; + regulator-max-microvolt = <1100000>; + regulator-initial-mode = ; + }; + + + vreg_l1j_0p91: ldo1 { + regulator-name = "vreg_l1j_0p91"; + regulator-min-microvolt = <880000>; + regulator-max-microvolt = <920000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + + vreg_l2j_1p2: ldo2 { + regulator-name = "vreg_l2j_1p2"; + regulator-min-microvolt = <1200000>; + regulator-max-microvolt = <1200000>; + regulator-initial-mode = ; + regulator-allow-set-load; + regulator-allowed-modes = ; + }; + }; +}; + +&ipa { + firmware-name = "qcom/sm8750/OnePlus/ipa_fws.mbn"; + memory-region = <&ipa_fw_mem>; + + status = "okay"; +}; + +&pm8550_flash { + status = "okay"; + led-0 { + function = LED_FUNCTION_FLASH; + color = ; + led-sources = <1>, <4>; + led-max-microamp = <500000>; + flash-max-microamp = <2000000>; + flash-max-timeout-us = <1280000>; + function-enumerator = <0>; + }; +}; + + +&pm8550_gpios { + volume_down_n: volume-down-n-state { + pins = "gpio6"; + function = "normal"; + bias-pull-up; + input-enable; + power-source = <1>; + }; +}; + +&pon_pwrkey { + status = "okay"; +}; + +&pon_resin { + linux,code = ; + + status = "okay"; +}; + +&pcie0 { + wake-gpios = <&tlmm 104 GPIO_ACTIVE_HIGH>; + perst-gpios = <&tlmm 102 GPIO_ACTIVE_LOW>; + + pinctrl-0 = <&pcie0_default_state>; + pinctrl-names = "default"; + + status = "okay"; +}; + +&pcie0_phy { + vdda-phy-supply = <&vreg_l1f_0p88>; + vdda-pll-supply = <&vreg_l3g_1p2>; + + status = "okay"; +}; + +&pcieport0 { + wifi@0 { + compatible = "pci17cb,1107"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + + vddrfacmn-supply = <&vreg_pmu_rfa_cmn>; + vddaon-supply = <&vreg_pmu_aon_0p59>; + vddwlcx-supply = <&vreg_pmu_wlcx_0p8>; + vddwlmx-supply = <&vreg_pmu_wlmx_0p85>; + 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>; + }; +}; + +&pmih0108_eusb2_repeater { + status = "okay"; + + vdd18-supply = <&vreg_l15b_1p8>; + vdd3-supply = <&vreg_l5b_3p1>; +}; + +&qupv3_1 { + status = "okay"; +}; + +&qupv3_2 { + status = "okay"; +}; + +&i2c_master_hub_0 { + status = "okay"; +}; + +&i2c_hub_9 { + /* Empty: oplus,dhall-ak09970 dropped (no in-tree driver; + * oplus vendor prefix is not in vendor-prefixes.yaml). + * Re-enable with a binding + driver when that lands. + */ +}; + +&spi4 { + status = "okay"; + synaptics_tcm_hbp@0 { + compatible = "synaptics,tcm-spi-hbp"; + reg = <0>; + spi-max-frequency = <19000000>; + interrupt-parent = <&tlmm>; + interrupts = <162 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <&vreg_l4b_1p8>; + synaptics,irq-gpio = <&tlmm 162 GPIO_ACTIVE_LOW>; + synaptics,reset-gpio = <&tlmm 161 GPIO_ACTIVE_LOW>; + synaptics,avdd-gpio = <&pm8550vs_j_gpios 3 GPIO_ACTIVE_LOW>; + pinctrl-names = "ts_spi_active", "ts_spi_suspend"; + pinctrl-0 = <&ts_int_active &ts_reset_active>; + pinctrl-1 = <&ts_int_suspend &ts_reset_suspend>; + /* Properties read by syna_tcm2 / syna_tcm2_spi */ + synaptics,panel-coords = <20224 44480>; + synaptics,tx-rx-num = <17 38>; + }; +}; + + +&gpi_dma1 { + status = "okay"; +}; + +&gpi_dma2 { + status = "okay"; +}; + +&remoteproc_adsp { + firmware-name = "qcom/sm8750/OnePlus/adsp.mbn", + "qcom/sm8750/OnePlus/adsp_dtb.mbn"; + + status = "okay"; +}; + +/* + * Probing the modem hands its memory to the modem VM. Firmware names, + * carve-outs and power handling are in place on this phone; keep the + * risk in mind if either status is flipped back to disabled. + */ +&remoteproc_cdsp { + firmware-name = "qcom/sm8750/OnePlus/cdsp.mbn", + "qcom/sm8750/OnePlus/cdsp_dtb.mbn"; + status = "okay"; +}; + +&remoteproc_mpss { + firmware-name = "qcom/sm8750/OnePlus/modem.mbn", + "qcom/sm8750/OnePlus/modem_dtb.mbn"; + status = "okay"; +}; + +&gpu { + status = "okay"; +}; + +&gpu_zap_shader { + firmware-name = "qcom/sm8750/OnePlus/gen80000_zap.mbn"; +}; + +&i2c3 { + status = "okay"; + + /* WCD939x USB-C analog switch; stock has no reset line for it. */ + wcd_usbss: typec-mux@e { + compatible = "qcom,wcd9395-usbss", "qcom,wcd9390-usbss"; + reg = <0xe>; + + vdd-supply = <&vreg_l15b_1p8>; + + mode-switch; + orientation-switch; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + wcd_usbss_sbu_mux: endpoint { + remote-endpoint = <&pmic_glink_sbu>; + }; + }; + + port@1 { + reg = <1>; + + wcd_usbss_headset_out: endpoint { + remote-endpoint = <&wcd_codec_headset_in>; + }; + }; + }; + }; +}; + +&swr1 { + status = "okay"; + + /* WCD939x RX */ + wcd_rx: codec@0,4 { + compatible = "sdw20217010e00"; + reg = <0 4>; + qcom,rx-port-mapping = <1 2 3 4 5 9>; + }; +}; + +&swr2 { + status = "okay"; + + /* WCD939x TX */ + wcd_tx: codec@0,3 { + compatible = "sdw20217010e00"; + reg = <0 3>; + qcom,tx-port-mapping = <2 2 3 4>; + }; +}; + +&tlmm { + /* reserved for secure world */ + gpio-reserved-ranges = <36 4>, <74 1>; + + wcd_default: wcd-reset-n-active-state { + pins = "gpio101"; + function = "gpio"; + drive-strength = <16>; + bias-disable; + output-low; + }; + + /* Secondary MI2S to the speaker amplifiers; data1 is their input. */ + i2s1_active: i2s1-active-state { + sck-pins { + pins = "gpio121"; + function = "i2s1_sck"; + drive-strength = <4>; + bias-disable; + }; + + data0-pins { + pins = "gpio122"; + function = "i2s1_data0"; + drive-strength = <4>; + bias-disable; + }; + + ws-pins { + pins = "gpio123"; + function = "i2s1_ws"; + drive-strength = <4>; + bias-disable; + }; + + data1-pins { + pins = "gpio124"; + function = "i2s1_data1"; + drive-strength = <4>; + bias-disable; + }; + }; + + ts_reset_active: ts_reset_active-state { + pins = "gpio161"; + function = "gpio"; + bias-disable; + output-low; + drive-strength = <8>; + }; + + ts_int_active: ts_int_active-state { + pins = "gpio162"; + function = "gpio"; + bias-pull-up; + drive-strength = <8>; + }; + + ts_reset_suspend: ts_reset_suspend-state { + pins = "gpio161"; + function = "gpio"; + bias-pull-down; + drive-strength = <2>; + }; + + ts_int_suspend: ts_int_suspend-state { + pins = "gpio162"; + function = "gpio"; + bias-pull-down; + drive-strength = <2>; + }; + + + bt_default: bt-default-state { + sw-ctrl-pins { + pins = "gpio18"; + function = "gpio"; + bias-pull-down; + }; + }; + + disp0_reset_n_active: disp0-reset-n-active-state { + pins = "gpio98"; + function = "gpio"; + drive-strength = <8>; + bias-disable; + }; + + disp0_reset_n_suspend: disp0-reset-n-suspend-state { + pins = "gpio98"; + function = "gpio"; + drive-strength = <2>; + bias-pull-down; + }; + + mdp_vsync_active: mdp-vsync-active-state { + pins = "gpio86"; + function = "mdp_vsync"; + drive-strength = <2>; + bias-pull-down; + }; + + mdp_vsync_suspend: mdp-vsync-suspend-state { + pins = "gpio86"; + function = "mdp_vsync"; + drive-strength = <2>; + bias-pull-down; + }; + + wlan_en: wlan-en-state { + pins = "gpio16"; + function = "gpio"; + drive-strength = <8>; + bias-pull-down; + }; +}; + +&uart14 { + status = "okay"; + + bluetooth { + compatible = "qcom,wcn7860-bt"; + + vddrfacmn-supply = <&vreg_pmu_rfa_cmn>; + vddaon-supply = <&vreg_pmu_aon_0p59>; + vddwlcx-supply = <&vreg_pmu_wlcx_0p8>; + vddwlmx-supply = <&vreg_pmu_wlmx_0p85>; + vddrfa0p8-supply = <&vreg_pmu_rfa_0p8>; + vddrfa1p2-supply = <&vreg_pmu_rfa_1p2>; + vddrfa1p8-supply = <&vreg_pmu_rfa_1p8>; + + max-speed = <3200000>; + }; +}; + +&uart7 { + status = "okay"; +}; + +&ufs_mem_phy { + vdda-phy-supply = <&vreg_l1j_0p91>; + vdda-pll-supply = <&vreg_l3g_1p2>; + + status = "okay"; +}; + +&ufs_mem_hc { + reset-gpios = <&tlmm 215 GPIO_ACTIVE_LOW>; + + vcc-supply = <&vreg_l17b_2p5>; + vcc-max-microamp = <1300000>; + vccq-supply = <&vreg_l1d_1p2>; + vccq-max-microamp = <1200000>; + + status = "okay"; +}; + +&pm8010_n { + status = "disabled"; +}; + +&usb { + status = "okay"; + dr_mode = "otg"; + usb-role-switch; +}; + +&usb_dwc3_hs { + remote-endpoint = <&pmic_glink_hs_in>; +}; + +&usb_hsphy { + vdd-supply = <&vreg_l2d_0p88>; + vdda12-supply = <&vreg_l3g_1p2>; + + phys = <&pmih0108_eusb2_repeater>; + + status = "okay"; +}; + +&usb_dp_qmpphy { + vdda-phy-supply = <&vreg_l3g_1p2>; + vdda-pll-supply = <&vreg_l2d_0p88>; + + status = "okay"; +}; + +&usb_dp_qmpphy_out { + remote-endpoint = <&pmic_glink_ss_in>; +}; + +&mdss { + status = "okay"; +}; + +// Disabled for now until upstream DP merged +&mdss_dp0 { + status = "disabled"; +}; + +&mdss_dp0_out { + data-lanes = <0 1>; +}; + +&mdss_dsi0 { + vdda-supply = <&vreg_l3g_1p2>; + + status = "okay"; + + panel@0 { + compatible = "oneplus,dodge-panel"; + reg = <0>; + + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&disp0_reset_n_active>, <&mdp_vsync_active>; + pinctrl-1 = <&disp0_reset_n_suspend>, <&mdp_vsync_suspend>; + + vddio-supply = <&vreg_l12b_1p8>; + vci-supply = <&vreg_l13b_3p0>; + vdd-supply = <&vreg_l11b_1p0>; + + reset-gpios = <&tlmm 98 GPIO_ACTIVE_LOW>; + + port { + panel0_in: endpoint { + remote-endpoint = <&mdss_dsi0_out>; + }; + }; + }; +}; + +&mdss_dsi0_out { + remote-endpoint = <&panel0_in>; + data-lanes = <0 1 2 3>; +}; + +&mdss_dsi0_phy { + vdds-supply = <&vreg_l3i_0p88>; + + status = "okay"; +}; + +/* + * The two speaker amplifiers (Awinic, product id 0x2308). Their I2S input + * is Secondary MI2S data1. + */ +&i2c_hub_4 { + status = "okay"; + + speaker_left: audio-codec@34 { + compatible = "awinic,aw882308"; + reg = <0x34>; + reset-gpios = <&tlmm 2 GPIO_ACTIVE_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Left"; + }; + + speaker_right: audio-codec@35 { + compatible = "awinic,aw882308"; + reg = <0x35>; + reset-gpios = <&tlmm 164 GPIO_ACTIVE_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Right"; + }; +}; + +&i2c_hub_3 { + status = "okay"; + bq28z610: fuel-gauge@55 { + compatible = "ti,bq27541"; + reg = <0x55>; + monitored-battery = <&bat>; + }; +}; + +&reserved_memory { + adsp_rpc_remote_heap_mem: adsp-rpc-remote-heap { + compatible = "shared-dma-pool"; + alloc-ranges = <0x0 0x00000000 0x0 0xffffffff>; + alignment = <0x0 0x400000>; + size = <0x0 0xc00000>; + reusable; + }; +}; diff --git a/arch/arm64/boot/dts/qcom/sm8750.dtsi b/arch/arm64/boot/dts/qcom/sm8750.dtsi index dd738d13df..beb0a20e48 100644 --- a/arch/arm64/boot/dts/qcom/sm8750.dtsi +++ b/arch/arm64/boot/dts/qcom/sm8750.dtsi @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -2180,6 +2182,52 @@ #hwlock-cells = <1>; }; + ipa: ipa@3f40000 { + compatible = "qcom,sm8750-ipa"; + + iommus = <&apps_smmu 0x4a0 0x0>, + <&apps_smmu 0x4a2 0x0>; + reg = <0 0x3f40000 0 0x10000>, + <0 0x3f50000 0 0x5000>, + <0 0x3e04000 0 0xfc000>; + reg-names = "ipa-reg", + "ipa-shared", + "gsi"; + + interrupts-extended = <&intc GIC_SPI 655 IRQ_TYPE_EDGE_RISING>, + <&intc GIC_SPI 432 IRQ_TYPE_LEVEL_HIGH>, + <&ipa_smp2p_in 0 IRQ_TYPE_EDGE_RISING>, + <&ipa_smp2p_in 1 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "ipa", + "gsi", + "ipa-clock-query", + "ipa-setup-ready"; + + clocks = <&rpmhcc RPMH_IPA_CLK>; + clock-names = "core"; + + interconnects = <&aggre2_noc MASTER_IPA QCOM_ICC_TAG_ALWAYS + &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>, + <&gem_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY + &cnoc_main SLAVE_IPA_CFG QCOM_ICC_TAG_ACTIVE_ONLY>; + interconnect-names = "memory", + "config"; + + qcom,qmp = <&aoss_qmp>; + + qcom,smem-states = <&ipa_smp2p_out 0>, + <&ipa_smp2p_out 1>; + qcom,smem-state-names = "ipa-clock-enabled-valid", + "ipa-clock-enabled"; + + qcom,gsi-loader = "self"; + memory-region = <&ipa_fw_mem>; + + sram = <&ipa_modem_tables>; + + status = "disabled"; + }; + remoteproc_mpss: remoteproc@4080000 { compatible = "qcom,sm8750-mpss-pas"; reg = <0x0 0x04080000 0x0 0x10000>; @@ -3512,6 +3560,216 @@ #power-domain-cells = <1>; }; + gpu: gpu@3d00000 { + compatible = "qcom,adreno-44050000", "qcom,adreno"; + reg = <0x0 0x03d00000 0x0 0x60000>, + <0x0 0x03d9e000 0x0 0x2000>, + <0x0 0x03d61000 0x0 0x800>; + reg-names = "kgsl_3d0_reg_memory", + "cx_mem", + "cx_dbgc"; + + interrupts = ; + + iommus = <&adreno_smmu 0 0x0>, + <&adreno_smmu 1 0x0>; + + operating-points-v2 = <&gpu_opp_table>; + + qcom,gmu = <&gmu>; + #cooling-cells = <2>; + + interconnects = <&gem_noc MASTER_GFX3D QCOM_ICC_TAG_ALWAYS + &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>; + interconnect-names = "gfx-mem"; + + status = "disabled"; + + gpu_zap_shader: zap-shader { + memory-region = <&gpu_micro_code_mem>; + }; + + gpu_opp_table: opp-table { + compatible = "operating-points-v2-adreno", + "operating-points-v2"; + + opp-1100000000 { + opp-hz = /bits/ 64 <1100000000>; + opp-level = ; + opp-peak-kBps = <20832031>; + qcom,opp-acd-level = <0x882a5ffd>; + }; + + opp-1050000000 { + opp-hz = /bits/ 64 <1050000000>; + opp-level = ; + opp-peak-kBps = <20832031>; + qcom,opp-acd-level = <0x882a5ffd>; + }; + + opp-967000000 { + opp-hz = /bits/ 64 <967000000>; + opp-level = ; + opp-peak-kBps = <12449218>; + qcom,opp-acd-level = <0x882b5ffd>; + }; + + opp-900000000 { + opp-hz = /bits/ 64 <900000000>; + opp-level = ; + opp-peak-kBps = <12449218>; + qcom,opp-acd-level = <0x882b5ffd>; + }; + + opp-832000000 { + opp-hz = /bits/ 64 <832000000>; + opp-level = ; + opp-peak-kBps = <12449218>; + qcom,opp-acd-level = <0x882b5ffd>; + }; + + opp-734000000 { + opp-hz = /bits/ 64 <734000000>; + opp-level = ; + opp-peak-kBps = <8171875>; + qcom,opp-acd-level = <0xa82b5ffd>; + }; + + opp-660000000 { + opp-hz = /bits/ 64 <660000000>; + opp-level = ; + opp-peak-kBps = <8171875>; + qcom,opp-acd-level = <0x882d5ffd>; + }; + + opp-607000000 { + opp-hz = /bits/ 64 <607000000>; + opp-level = ; + opp-peak-kBps = <6074218>; + qcom,opp-acd-level = <0xa82e5ffd>; + }; + + opp-525000000 { + opp-hz = /bits/ 64 <525000000>; + opp-level = ; + opp-peak-kBps = <6074218>; + qcom,opp-acd-level = <0xc0285ffd>; + }; + + opp-443000000 { + opp-hz = /bits/ 64 <443000000>; + opp-level = ; + opp-peak-kBps = <6074218>; + qcom,opp-acd-level = <0xe02d5ffd>; + }; + + opp-389000000 { + opp-hz = /bits/ 64 <389000000>; + opp-level = ; + opp-peak-kBps = <5285156>; + qcom,opp-acd-level = <0xe02f5ffd>; + }; + + opp-342000000 { + opp-hz = /bits/ 64 <342000000>; + opp-level = ; + opp-peak-kBps = <5285156>; + }; + + opp-222000000 { + opp-hz = /bits/ 64 <222000000>; + opp-level = ; + opp-peak-kBps = <2136718>; + }; + + opp-160000000 { + opp-hz = /bits/ 64 <160000000>; + opp-level = ; + opp-peak-kBps = <2136718>; + }; + }; + }; + + gmu: gmu@3d37000 { + compatible = "qcom,adreno-gmu-830.1", "qcom,adreno-gmu"; + + reg = <0x0 0x03d37000 0x0 0x68000>; + reg-names = "gmu"; + + interrupts = , + ; + interrupt-names = "hfi", "gmu"; + + clocks = <&gpucc GPU_CC_AHB_CLK>, + <&gpucc GPU_CC_CX_GMU_CLK>, + <&gpucc GPU_CC_CXO_CLK>, + <&gcc GCC_GPU_GEMNOC_GFX_CLK>, + <&gpucc GPU_CC_HUB_CX_INT_CLK>; + clock-names = "ahb", + "gmu", + "cxo", + "memnoc", + "hub"; + + power-domains = <&gpucc GPU_CC_CX_GDSC>, + <&gxclkctl GX_CLKCTL_GX_GDSC>; + power-domain-names = "cx", + "gx"; + + iommus = <&adreno_smmu 5 0x0>; + + qcom,qmp = <&aoss_qmp>; + + operating-points-v2 = <&gmu_opp_table>; + + gmu_opp_table: opp-table { + compatible = "operating-points-v2"; + + opp-500000000 { + opp-hz = /bits/ 64 <500000000>; + opp-level = ; + }; + + opp-650000000 { + opp-hz = /bits/ 64 <650000000>; + opp-level = ; + }; + + opp-687500000 { + opp-hz = /bits/ 64 <687500000>; + opp-level = ; + }; + }; + }; + + gxclkctl: clock-controller@3d64000 { + compatible = "qcom,sm8750-gxclkctl"; + reg = <0x0 0x03d64000 0x0 0x6000>; + + power-domains = <&rpmhpd RPMHPD_GFX>, + <&rpmhpd RPMHPD_GMXC>, + <&gpucc GPU_CC_CX_GDSC>; + + #power-domain-cells = <1>; + }; + + gpucc: clock-controller@3d90000 { + compatible = "qcom,sm8750-gpucc"; + reg = <0x0 0x03d90000 0x0 0x9800>; + + clocks = <&bi_tcxo_div2>, + <&gcc GCC_GPU_GPLL0_CLK_SRC>, + <&gcc GCC_GPU_GPLL0_DIV_CLK_SRC>; + + power-domains = <&rpmhpd RPMHPD_MX>, + <&rpmhpd RPMHPD_CX>; + required-opps = <&rpmhpd_opp_low_svs>, + <&rpmhpd_opp_low_svs>; + #clock-cells = <1>; + #reset-cells = <1>; + #power-domain-cells = <1>; + }; + pdc: interrupt-controller@b220000 { compatible = "qcom,sm8750-pdc", "qcom,pdc"; reg = <0x0 0x0b220000 0x0 0x10000>, <0x0 0x164400f0 0x0 0x64>; @@ -5283,6 +5541,58 @@ }; }; + adreno_smmu: iommu@3da0000 { + compatible = "qcom,sm8750-smmu-500", "qcom,adreno-smmu", + "qcom,smmu-500", "arm,mmu-500"; + reg = <0x0 0x03da0000 0x0 0x40000>; + #iommu-cells = <2>; + #global-interrupts = <1>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + clocks = <&gpucc GPU_CC_HLOS1_VOTE_GPU_SMMU_CLK>; + clock-names = "hlos"; + power-domains = <&gpucc GPU_CC_CX_GDSC>; + dma-coherent; + }; + + sram@14680000 { + compatible = "qcom,sm8750-imem", "syscon", "simple-mfd"; + reg = <0 0x14680000 0 0x2c000>; + + #address-cells = <1>; + #size-cells = <1>; + + ranges = <0 0 0x14680000 0x2c000>; + + ipa_modem_tables: modem-tables@3000 { + reg = <0x3000 0x2000>; + }; + }; + apps_smmu: iommu@15000000 { compatible = "qcom,sm8750-smmu-500", "qcom,smmu-500", "arm,mmu-500"; reg = <0x0 0x15000000 0x0 0x100000>; diff --git a/arch/arm64/configs/sm8750.config b/arch/arm64/configs/sm8750.config new file mode 100644 index 0000000000..14d7d35812 --- /dev/null +++ b/arch/arm64/configs/sm8750.config @@ -0,0 +1,41 @@ +# Minimal additive fragment for OnePlus 13 (dodge) / SM8750. +# Applied on top of arch/arm64/configs/defconfig with: +# scripts/kconfig/merge_config.sh -m arch/arm64/configs/defconfig \ +# arch/arm64/configs/sm8750.config +# Only options this board needs beyond defconfig. No =n lines. + +# SoC pinctrl (not in defconfig) +CONFIG_PINCTRL_SM8750=y + +# Display panel + touch +CONFIG_DRM_PANEL_ONEPLUS_DODGE=m +CONFIG_TOUCHSCREEN_SYNA_TCM2=m + +# Speaker amplifiers (bring-up driver; no default in Kconfig) +CONFIG_SND_SOC_AW882308=m + +# Fuel gauge I2C front-end used by the dodge DT +CONFIG_BATTERY_BQ27XXX_I2C=y + +# Early-boot builtins needed before modules can load: UFS root, USB +# gadget (configfs), and the splash simple-framebuffer. DRM=y so +# SIMPLEDRM and the QMP combo PHY can be built-in (both depend on DRM). +CONFIG_DRM=y +CONFIG_DRM_SIMPLEDRM=y +CONFIG_SYSFB_SIMPLEFB=y +CONFIG_SCSI_UFS_QCOM=y +CONFIG_PHY_QCOM_QMP=y +CONFIG_PHY_QCOM_QMP_UFS=y +CONFIG_PHY_QCOM_QMP_COMBO=y +CONFIG_PHY_QCOM_M31_EUSB=y +CONFIG_PHY_QCOM_EUSB2_REPEATER=y +CONFIG_USB_CONFIGFS=y +CONFIG_TYPEC=y +CONFIG_SM_TCSRCC_8750=y + +# GPU/display providers that must be present before deferred_probe_timeout. +# SM_GPUCC_8750 also builds gxclkctl-kaanapali (same Makefile). The Adreno +# SMMU and GPU clock and power from GPUCC; without it built in they time +# out before modules load, msm bind fails, and the panel never attaches. +# DISPCC stays =m (loaded with the display stack). +CONFIG_SM_GPUCC_8750=y diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c index 22b08ab05b..d861375ad0 100644 --- a/drivers/bluetooth/btqca.c +++ b/drivers/bluetooth/btqca.c @@ -826,6 +826,11 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, snprintf(config.fwname, sizeof(config.fwname), "qca/hmtbtfw%02x.tlv", rom_ver); break; + case QCA_WCN7860: + config.type = ELF_TYPE_PATCH; + snprintf(config.fwname, sizeof(config.fwname), + "qca/gngbtfw%02x.mbn", rom_ver); + break; default: snprintf(config.fwname, sizeof(config.fwname), "qca/rampatch_%08x.bin", soc_ver); @@ -859,7 +864,8 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, /* Give the controller some time to get ready to receive the NVM */ msleep(10); - if (soc_type == QCA_QCA2066 || soc_type == QCA_WCN7850) + if (soc_type == QCA_QCA2066 || soc_type == QCA_WCN7850 || + soc_type == QCA_WCN7860) qca_read_fw_board_id(hdev, &boardid); /* Download NVM configuration */ @@ -920,6 +926,10 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, qca_get_nvm_name_by_board(config.fwname, sizeof(config.fwname), "hmtnv", soc_type, ver, rom_ver, boardid); break; + case QCA_WCN7860: + qca_get_nvm_name_by_board(config.fwname, sizeof(config.fwname), + "gngbtnv", soc_type, ver, rom_ver, boardid); + break; default: snprintf(config.fwname, sizeof(config.fwname), "qca/nvm_%08x.bin", soc_ver); @@ -946,6 +956,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: err = qca_disable_soc_logging(hdev); if (err < 0) return err; @@ -983,6 +994,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: /* get fw build info */ err = qca_read_fw_build_info(hdev); if (err < 0) diff --git a/drivers/bluetooth/btqca.h b/drivers/bluetooth/btqca.h index 8f3c1b1c77..3fe18739e5 100644 --- a/drivers/bluetooth/btqca.h +++ b/drivers/bluetooth/btqca.h @@ -158,6 +158,7 @@ enum qca_btsoc_type { QCA_WCN6750, QCA_WCN6855, QCA_WCN7850, + QCA_WCN7860, }; #if IS_ENABLED(CONFIG_BT_QCA) diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index 7089e9b639..e553c47384 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1383,6 +1383,7 @@ static int qca_set_baudrate(struct hci_dev *hdev, uint8_t baudrate) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: usleep_range(1000, 10000); break; @@ -1401,6 +1402,43 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed) hci_uart_set_baudrate(hu, speed); } +/* + * WCN7860 also runs a peripheral (UWB) core behind the same UART. Its + * baud rate is set with a vendor packet before the BT core switches to + * the operating speed; without it the speed change does not take. + * Sequence from the ROCKNIX SM8750 (AYN Odin 3) port. + */ +static int qca_peri_set_baudrate(struct hci_uart *hu, unsigned int speed) +{ + struct qca_data *qca = hu->priv; + struct sk_buff *skb; + u8 cmd[] = { 0x31, 0x00, 0xf1, 0xff, 0x02, 0x02, 0x00 }; + + if (!hu->serdev) + return -ENODEV; + + cmd[6] = qca_get_baudrate_value(speed); + + if (send_hci_ibs_cmd(HCI_IBS_WAKE_IND, hu) < 0) + return -EIO; + /* send_hci_ibs_cmd only queues; kick the UART so WAKE_IND goes out. */ + hci_uart_tx_wakeup(hu); + + usleep_range(10000, 11000); + + skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); + if (!skb) + return -ENOMEM; + + skb_put_data(skb, cmd, sizeof(cmd)); + skb_queue_tail(&qca->txq, skb); + hci_uart_tx_wakeup(hu); + + msleep(100); + + return 0; +} + static int qca_send_power_pulse(struct hci_uart *hu, bool on) { int timeout = CMD_TRANS_TIMEOUT; @@ -1470,6 +1508,7 @@ static int qca_check_speeds(struct hci_uart *hu) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: if (!qca_get_speed(hu, QCA_INIT_SPEED) && !qca_get_speed(hu, QCA_OPER_SPEED)) return -EINVAL; @@ -1513,6 +1552,7 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: hci_uart_set_flow_control(hu, true); break; @@ -1548,6 +1588,7 @@ static int qca_set_speed(struct hci_uart *hu, enum qca_speed_type speed_type) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: hci_uart_set_flow_control(hu, false); break; @@ -1864,6 +1905,7 @@ static int qca_power_on(struct hci_dev *hdev) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: ret = qca_regulator_init(hu); break; @@ -1963,6 +2005,10 @@ static int qca_setup(struct hci_uart *hu) soc_name = "wcn7850"; break; + case QCA_WCN7860: + soc_name = "wcn7860"; + break; + default: soc_name = "ROME/QCA6390"; } @@ -1986,6 +2032,7 @@ static int qca_setup(struct hci_uart *hu) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: if (qcadev && qcadev->bdaddr_property_broken) hci_set_quirk(hdev, HCI_QUIRK_BDADDR_PROPERTY_BROKEN); @@ -2000,6 +2047,12 @@ static int qca_setup(struct hci_uart *hu) qca_set_speed(hu, QCA_INIT_SPEED); } + if (soc_type == QCA_WCN7860) { + ret = qca_peri_set_baudrate(hu, qca_get_speed(hu, QCA_OPER_SPEED)); + if (ret) + goto out; + } + /* Setup user speed if needed */ speed = qca_get_speed(hu, QCA_OPER_SPEED); if (speed) { @@ -2019,6 +2072,7 @@ static int qca_setup(struct hci_uart *hu) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: break; default: @@ -2219,6 +2273,20 @@ static const struct qca_device_data qca_soc_data_wcn7850 __maybe_unused = { QCA_CAP_HFP_HW_OFFLOAD, }; +static const struct qca_device_data qca_soc_data_wcn7860 __maybe_unused = { + .soc_type = QCA_WCN7860, + .vregs = (struct qca_vreg []) { + { "vddio", 5000 }, + { "vddaon", 26000 }, + { "vdddig", 126000 }, + { "vddrfa0p8", 102000 }, + { "vddrfa1p2", 257000 }, + { "vddrfa1p9", 302000 }, + }, + .num_vregs = 6, + .capabilities = QCA_CAP_WIDEBAND_SPEECH | QCA_CAP_VALID_LE_STATES, +}; + static void qca_power_off(struct hci_uart *hu) { struct qca_serdev *qcadev; @@ -2435,6 +2503,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: qcadev->bt_power = devm_kzalloc(&serdev->dev, sizeof(struct qca_power), GFP_KERNEL); @@ -2454,6 +2523,7 @@ static int qca_serdev_probe(struct serdev_device *serdev) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: if (!device_property_present(&serdev->dev, "enable-gpios")) { /* * Backward compatibility with old DT sources. If the @@ -2504,7 +2574,8 @@ static int qca_serdev_probe(struct serdev_device *serdev) if (IS_ERR(qcadev->sw_ctrl) && (data->soc_type == QCA_WCN6750 || data->soc_type == QCA_WCN6855 || - data->soc_type == QCA_WCN7850)) { + data->soc_type == QCA_WCN7850 || + data->soc_type == QCA_WCN7860)) { dev_err(&serdev->dev, "failed to acquire SW_CTRL gpio\n"); return PTR_ERR(qcadev->sw_ctrl); } @@ -2589,6 +2660,7 @@ static void qca_serdev_remove(struct serdev_device *serdev) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: + case QCA_WCN7860: if (power->vregs_on) qca_power_off(&qcadev->serdev_hu); break; @@ -2791,6 +2863,7 @@ static const struct of_device_id qca_bluetooth_of_match[] = { { .compatible = "qcom,wcn6750-bt", .data = &qca_soc_data_wcn6750}, { .compatible = "qcom,wcn6855-bt", .data = &qca_soc_data_wcn6855}, { .compatible = "qcom,wcn7850-bt", .data = &qca_soc_data_wcn7850}, + { .compatible = "qcom,wcn7860-bt", .data = &qca_soc_data_wcn7860}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, qca_bluetooth_of_match); diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c index 19c84913cf..2b1e0053b6 100644 --- a/drivers/bus/mhi/host/boot.c +++ b/drivers/bus/mhi/host/boot.c @@ -598,6 +598,28 @@ void mhi_fw_load_handler(struct mhi_controller *mhi_cntrl) } dev_info(dev, "Wait for device to enter SBL or Mission mode\n"); + /* + * Opt-in for controllers that lose the EE event (ath12k WCN7860): + * continue from BHI_EXECENV when the register already shows SBL, + * AMSS/WFW or FP. Only read the register when access is valid. + */ + if (mhi_cntrl->ee_reg_continue && + MHI_REG_ACCESS_VALID(mhi_cntrl->pm_state)) { + enum mhi_ee_type exec = mhi_get_exec_env(mhi_cntrl); + enum dev_st_transition st = DEV_ST_TRANSITION_MAX; + + if (exec == MHI_EE_SBL) + st = DEV_ST_TRANSITION_SBL; + else if (exec == MHI_EE_AMSS || exec == MHI_EE_WFW) + st = DEV_ST_TRANSITION_MISSION_MODE; + else if (exec == MHI_EE_FP) + st = DEV_ST_TRANSITION_FP; + + if (st != DEV_ST_TRANSITION_MAX) { + dev_dbg(dev, "EE 0x%x already set, continuing\n", exec); + mhi_queue_state_transition(mhi_cntrl, st); + } + } return; error_ready_state: diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c index ced83fbb1a..f7d1ed0b90 100644 --- a/drivers/bus/mhi/host/pm.c +++ b/drivers/bus/mhi/host/pm.c @@ -813,6 +813,9 @@ void mhi_pm_st_worker(struct work_struct *work) mhi_fw_load_handler(mhi_cntrl); break; case DEV_ST_TRANSITION_SBL: + /* The register path and the EE event can both queue this. */ + if (mhi_cntrl->ee_reg_continue && mhi_cntrl->ee == MHI_EE_SBL) + break; write_lock_irq(&mhi_cntrl->pm_lock); mhi_cntrl->ee = MHI_EE_SBL; write_unlock_irq(&mhi_cntrl->pm_lock); @@ -824,10 +827,36 @@ void mhi_pm_st_worker(struct work_struct *work) mhi_create_devices(mhi_cntrl); if (mhi_cntrl->fbc_download) mhi_download_amss_image(mhi_cntrl); + /* + * Opt-in for controllers that lose the EE event + * (ath12k WCN7860): poll BHI_EXECENV for up to 2 s + * (20 x 100 ms). Do not treat FP as mission mode. + */ + if (mhi_cntrl->ee_reg_continue) { + int n; + + for (n = 0; n < 20; n++) { + u32 exec = MHI_EE_MAX; + + if (!mhi_read_reg(mhi_cntrl, mhi_cntrl->bhi, + BHI_EXECENV, &exec)) + dev_dbg(&mhi_cntrl->mhi_dev->dev, + "post-AMSS %d ee=0x%x\n", n, exec); + if (exec == MHI_EE_AMSS || exec == MHI_EE_WFW) { + mhi_queue_state_transition(mhi_cntrl, + DEV_ST_TRANSITION_MISSION_MODE); + break; + } + msleep(100); + } + } mhi_uevent_notify(mhi_cntrl, mhi_cntrl->ee); break; case DEV_ST_TRANSITION_MISSION_MODE: + if (mhi_cntrl->ee_reg_continue && + MHI_IN_MISSION_MODE(mhi_cntrl->ee)) + break; mhi_pm_mission_mode_transition(mhi_cntrl); break; case DEV_ST_TRANSITION_FP: diff --git a/drivers/gpu/drm/msm/adreno/a6xx_catalog.c b/drivers/gpu/drm/msm/adreno/a6xx_catalog.c index 90a0c7ffb3..11c5336998 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_catalog.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_catalog.c @@ -2088,6 +2088,273 @@ static const struct adreno_reglist_pipe a810_dyn_pwrup_reglist_regs[] = { }; DECLARE_ADRENO_REGLIST_PIPE_LIST(a810_dyn_pwrup_reglist); +static const struct adreno_reglist_pipe a830_nonctxt_regs[] = { + { REG_A8XX_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, + { REG_A8XX_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A6XX_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, + /* Disable BR throttling */ + { REG_A8XX_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, + /* Configure GBIF GX registers */ + { REG_A8XX_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, + { REG_A8XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, + /* Enable full concurrent resolve and unresolves */ + { REG_A7XX_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, + { REG_A8XX_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) }, + /* Configure number of outstanding transactions to 32 */ + { REG_A8XX_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, + /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ + { REG_A8XX_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, + { REG_A8XX_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, + { REG_A8XX_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, + { REG_A8XX_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, + { REG_A8XX_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, + { REG_A8XX_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, + /* Enable contribution of all shader stages to SP perfcounters */ + { REG_A6XX_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, + /* + * BIT(26): Limit the number of wave-slots for Eviction buffer to 1 per ALU GRP + * BIT(30): Disable LPAC auto-promotion + */ + { REG_A7XX_SP_CHICKEN_BITS_1, BIT(26) | BIT(30), BIT(PIPE_NONE) }, + /* + * BIT(22): Disable PS out of order retire + * BIT(23): Enable half wave mode and MM instruction src&dst is half precision + */ + { REG_A7XX_SP_CHICKEN_BITS_2, BIT(22) | BIT(23), BIT(PIPE_NONE) }, + { REG_A7XX_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) }, + { REG_A7XX_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 0x00000080, BIT(PIPE_NONE) }, + { REG_A6XX_TPL1_DBG_ECO_CNTL, 0x10000000, BIT(PIPE_NONE) }, + /* Enable cubemap small miplevel optimization settings */ + /* BIT(26): Disable final clamp for bicubic filtering */ + { REG_A6XX_TPL1_DBG_ECO_CNTL1, 0x04000724, BIT(PIPE_NONE) }, + /* Disable tag bank id hashing */ + { REG_A6XX_UCHE_MODE_CNTL, 0x00080000, BIT(PIPE_NONE) }, + { REG_A8XX_UCHE_CCHE_MODE_CNTL, 0x00001000, BIT(PIPE_NONE) }, + /* Limit gmem number of ways for GMEM requests in each set */ + { REG_A8XX_UCHE_CCHE_CACHE_WAYS, 0x00000800, BIT(PIPE_NONE) }, + /* Disable write slow pointer in data phase queue */ + { REG_A8XX_UCHE_HW_DBG_CNTL, BIT(8), BIT(PIPE_NONE) }, + /* Configure UCHE to CCU switchthreshold timeout cycles */ + { REG_A8XX_UCHE_VARB_IDLE_TIMEOUT, 0x00000020, BIT(PIPE_NONE) }, + { REG_A7XX_VFD_DBG_ECO_CNTL, 0x00008000, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_VFD_CB_BV_THRESHOLD, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_VFD_CB_BR_THRESHOLD, 0x00600060, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_VFD_CB_BUSY_REQ_CNT, 0x00200020, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_VFD_CB_LP_REQ_CNT, 0x00100020, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, + /* Disable redundant tile data optimization */ + { REG_A8XX_VSC_KMD_DBG_ECO_CNTL, BIT(11), BIT(PIPE_NONE) }, + { }, +}; + +static const u32 a830_protect_regs[] = { + A6XX_PROTECT_RDONLY(0x00000, 0x03a3), + A6XX_PROTECT_RDONLY(0x003b4, 0x008b), + A6XX_PROTECT_NORDWR(0x00440, 0x001f), + A6XX_PROTECT_RDONLY(0x00580, 0x005f), + A6XX_PROTECT_NORDWR(0x005e0, 0x011f), + A6XX_PROTECT_RDONLY(0x0074a, 0x0005), + A6XX_PROTECT_RDONLY(0x00759, 0x0026), + A6XX_PROTECT_RDONLY(0x00789, 0x0000), + A6XX_PROTECT_RDONLY(0x0078c, 0x0013), + A6XX_PROTECT_NORDWR(0x00800, 0x0029), + A6XX_PROTECT_NORDWR(0x00837, 0x00af), + A6XX_PROTECT_RDONLY(0x008e7, 0x00c9), + A6XX_PROTECT_NORDWR(0x008ec, 0x00c3), + A6XX_PROTECT_NORDWR(0x009b1, 0x0250), + A6XX_PROTECT_RDONLY(0x00ce0, 0x0001), + A6XX_PROTECT_RDONLY(0x00df0, 0x0000), + A6XX_PROTECT_NORDWR(0x00df1, 0x0000), + A6XX_PROTECT_NORDWR(0x00e01, 0x0000), + A6XX_PROTECT_NORDWR(0x00e03, 0x1fff), + A6XX_PROTECT_NORDWR(0x03c00, 0x00c5), + A6XX_PROTECT_RDONLY(0x03cc6, 0x1fff), + A6XX_PROTECT_NORDWR(0x08600, 0x01ff), + A6XX_PROTECT_NORDWR(0x08e00, 0x00ff), + A6XX_PROTECT_RDONLY(0x08f00, 0x0000), + A6XX_PROTECT_NORDWR(0x08f01, 0x01be), + A6XX_PROTECT_NORDWR(0x09600, 0x01ff), + A6XX_PROTECT_RDONLY(0x0981a, 0x02e5), + A6XX_PROTECT_NORDWR(0x09e00, 0x01ff), + A6XX_PROTECT_NORDWR(0x0a600, 0x01ff), + A6XX_PROTECT_NORDWR(0x0ae00, 0x0000), + A6XX_PROTECT_NORDWR(0x0ae02, 0x0004), + A6XX_PROTECT_NORDWR(0x0ae08, 0x0006), + A6XX_PROTECT_NORDWR(0x0ae10, 0x036f), + A6XX_PROTECT_NORDWR(0x0b600, 0x1fff), + A6XX_PROTECT_NORDWR(0x0dc00, 0x1fff), + A6XX_PROTECT_RDONLY(0x0fc00, 0x1fff), + A6XX_PROTECT_NORDWR(0x18400, 0x003f), + A6XX_PROTECT_RDONLY(0x18440, 0x013f), + A6XX_PROTECT_NORDWR(0x18580, 0x1fff), + A6XX_PROTECT_NORDWR(0x1b400, 0x1fff), + A6XX_PROTECT_NORDWR(0x1f400, 0x0477), + A6XX_PROTECT_RDONLY(0x1f878, 0x0787), + A6XX_PROTECT_NORDWR(0x1f930, 0x0329), + A6XX_PROTECT_NORDWR(0x20000, 0x1fff), + A6XX_PROTECT_NORDWR(0x27800, 0x007f), + A6XX_PROTECT_RDONLY(0x27880, 0x0381), + A6XX_PROTECT_NORDWR(0x27882, 0x0001), + A6XX_PROTECT_NORDWR(0x27c02, 0x0000), +}; +DECLARE_ADRENO_PROTECT(a830_protect, 15); + +static const uint32_t a830_pwrup_reglist_regs[] = { + REG_A6XX_UCHE_MODE_CNTL, + REG_A8XX_UCHE_VARB_IDLE_TIMEOUT, + REG_A8XX_UCHE_GBIF_GX_CONFIG, + REG_A8XX_UCHE_CACHE_WAYS, + REG_A8XX_UCHE_CCHE_MODE_CNTL, + REG_A8XX_UCHE_CCHE_CACHE_WAYS, + REG_A8XX_UCHE_CCHE_GC_GMEM_RANGE_MIN, + REG_A8XX_UCHE_CCHE_GC_GMEM_RANGE_MIN + 1, + REG_A8XX_UCHE_CCHE_LPAC_GMEM_RANGE_MIN, + REG_A8XX_UCHE_CCHE_LPAC_GMEM_RANGE_MIN + 1, + REG_A8XX_UCHE_CCHE_TRAP_BASE, + REG_A8XX_UCHE_CCHE_TRAP_BASE + 1, + REG_A8XX_UCHE_CCHE_WRITE_THRU_BASE, + REG_A8XX_UCHE_CCHE_WRITE_THRU_BASE + 1, + REG_A8XX_UCHE_HW_DBG_CNTL, + REG_A8XX_UCHE_WRITE_THRU_BASE, + REG_A8XX_UCHE_WRITE_THRU_BASE + 1, + REG_A8XX_UCHE_TRAP_BASE, + REG_A8XX_UCHE_TRAP_BASE + 1, + REG_A8XX_UCHE_CLIENT_PF, + REG_A8XX_VSC_KMD_DBG_ECO_CNTL, + REG_A8XX_RB_CMP_NC_MODE_CNTL, + REG_A7XX_SP_HLSQ_TIMEOUT_THRESHOLD_DP, + REG_A8XX_SP_HLSQ_GC_GMEM_RANGE_MIN, + REG_A8XX_SP_HLSQ_GC_GMEM_RANGE_MIN + 1, + REG_A7XX_SP_READ_SEL, + REG_A6XX_TPL1_NC_MODE_CNTL, + REG_A6XX_TPL1_DBG_ECO_CNTL, + REG_A6XX_TPL1_DBG_ECO_CNTL1, + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(1), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(2), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(3), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(4), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(5), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(6), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(7), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(8), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(9), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(10), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(11), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(12), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(13), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(14), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(15), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(16), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(17), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(18), + REG_A8XX_TPL1_BICUBIC_WEIGHTS_TABLE(19), +}; +DECLARE_ADRENO_REGLIST_LIST(a830_pwrup_reglist); + +static const u32 a830_ifpc_reglist_regs[] = { + REG_A8XX_RBBM_NC_MODE_CNTL, + REG_A8XX_RBBM_SLICE_INTERFACE_HANG_INT_CNTL, + REG_A8XX_RBBM_SLICE_NC_MODE_CNTL, + REG_A6XX_SP_NC_MODE_CNTL, + REG_A8XX_SP_HLSQ_LPAC_GMEM_RANGE_MIN, + REG_A8XX_SP_HLSQ_LPAC_GMEM_RANGE_MIN + 1, + REG_A7XX_SP_CHICKEN_BITS_1, + REG_A7XX_SP_CHICKEN_BITS_2, + REG_A7XX_SP_CHICKEN_BITS_3, + REG_A6XX_SP_PERFCTR_SHADER_MASK, + REG_A8XX_CP_PROTECT_GLOBAL(0), + REG_A8XX_CP_PROTECT_GLOBAL(1), + REG_A8XX_CP_PROTECT_GLOBAL(2), + REG_A8XX_CP_PROTECT_GLOBAL(3), + REG_A8XX_CP_PROTECT_GLOBAL(4), + REG_A8XX_CP_PROTECT_GLOBAL(5), + REG_A8XX_CP_PROTECT_GLOBAL(6), + REG_A8XX_CP_PROTECT_GLOBAL(7), + REG_A8XX_CP_PROTECT_GLOBAL(8), + REG_A8XX_CP_PROTECT_GLOBAL(9), + REG_A8XX_CP_PROTECT_GLOBAL(10), + REG_A8XX_CP_PROTECT_GLOBAL(11), + REG_A8XX_CP_PROTECT_GLOBAL(12), + REG_A8XX_CP_PROTECT_GLOBAL(13), + REG_A8XX_CP_PROTECT_GLOBAL(14), + REG_A8XX_CP_PROTECT_GLOBAL(15), + REG_A8XX_CP_PROTECT_GLOBAL(16), + REG_A8XX_CP_PROTECT_GLOBAL(17), + REG_A8XX_CP_PROTECT_GLOBAL(18), + REG_A8XX_CP_PROTECT_GLOBAL(19), + REG_A8XX_CP_PROTECT_GLOBAL(20), + REG_A8XX_CP_PROTECT_GLOBAL(21), + REG_A8XX_CP_PROTECT_GLOBAL(22), + REG_A8XX_CP_PROTECT_GLOBAL(23), + REG_A8XX_CP_PROTECT_GLOBAL(24), + REG_A8XX_CP_PROTECT_GLOBAL(25), + REG_A8XX_CP_PROTECT_GLOBAL(26), + REG_A8XX_CP_PROTECT_GLOBAL(27), + REG_A8XX_CP_PROTECT_GLOBAL(28), + REG_A8XX_CP_PROTECT_GLOBAL(29), + REG_A8XX_CP_PROTECT_GLOBAL(30), + REG_A8XX_CP_PROTECT_GLOBAL(31), + REG_A8XX_CP_PROTECT_GLOBAL(32), + REG_A8XX_CP_PROTECT_GLOBAL(33), + REG_A8XX_CP_PROTECT_GLOBAL(34), + REG_A8XX_CP_PROTECT_GLOBAL(35), + REG_A8XX_CP_PROTECT_GLOBAL(36), + REG_A8XX_CP_PROTECT_GLOBAL(37), + REG_A8XX_CP_PROTECT_GLOBAL(38), + REG_A8XX_CP_PROTECT_GLOBAL(39), + REG_A8XX_CP_PROTECT_GLOBAL(40), + REG_A8XX_CP_PROTECT_GLOBAL(41), + REG_A8XX_CP_PROTECT_GLOBAL(42), + REG_A8XX_CP_PROTECT_GLOBAL(43), + REG_A8XX_CP_PROTECT_GLOBAL(44), + REG_A8XX_CP_PROTECT_GLOBAL(45), + REG_A8XX_CP_PROTECT_GLOBAL(46), + REG_A8XX_CP_PROTECT_GLOBAL(47), + REG_A8XX_CP_PROTECT_GLOBAL(63), + REG_A8XX_CP_INTERRUPT_STATUS_MASK_GLOBAL, +}; +DECLARE_ADRENO_REGLIST_LIST(a830_ifpc_reglist); + +static const struct adreno_reglist_pipe a830_dyn_pwrup_reglist_regs[] = { + { REG_A8XX_CP_HW_FAULT_STATUS_MASK_PIPE, 0, BIT(PIPE_BR) | + BIT(PIPE_BV) | BIT(PIPE_LPAC) | BIT(PIPE_AQE0) | + BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, + { REG_A8XX_CP_INTERRUPT_STATUS_MASK_PIPE, 0, BIT(PIPE_BR) | + BIT(PIPE_BV) | BIT(PIPE_LPAC) | BIT(PIPE_AQE0) | + BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, + { REG_A8XX_CP_PROTECT_CNTL_PIPE, 0, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, + { REG_A8XX_CP_PROTECT_PIPE(15), 0, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, + { REG_A8XX_GRAS_TSEFE_DBG_ECO_CNTL, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_GRAS_NC_MODE_CNTL, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_GRAS_DBG_ECO_CNTL, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A7XX_RB_CCU_CNTL, 0, BIT(PIPE_BR) }, + { REG_A8XX_RB_CCU_NC_MODE_CNTL, 0, BIT(PIPE_BR) }, + { REG_A8XX_RB_CMP_NC_MODE_CNTL, 0, BIT(PIPE_BR) }, + { REG_A8XX_RB_RESOLVE_PREFETCH_CNTL, 0, BIT(PIPE_BR) }, + { REG_A8XX_RB_CMP_DBG_ECO_CNTL, 0, BIT(PIPE_BR) }, + { REG_A8XX_RB_GC_GMEM_PROTECT, 0, BIT(PIPE_BR) }, + { REG_A6XX_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE_ENABLE, 0, BIT(PIPE_BR) }, + { REG_A8XX_VPC_FLATSHADE_MODE_CNTL, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_PC_CHICKEN_BITS_1, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_PC_CHICKEN_BITS_2, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_PC_CHICKEN_BITS_3, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_PC_CHICKEN_BITS_4, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A6XX_PC_AUTO_VERTEX_STRIDE, 0, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_VIS_STREAM_CNTL, 0, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0, BIT(PIPE_BR) | BIT(PIPE_BV) }, + { REG_A8XX_VFD_CB_BV_THRESHOLD, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_VFD_CB_BR_THRESHOLD, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_VFD_CB_BUSY_REQ_CNT, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A8XX_VFD_CB_LP_REQ_CNT, 0, BIT(PIPE_BV) | BIT(PIPE_BR) }, + { REG_A7XX_VFD_DBG_ECO_CNTL, 0, BIT(PIPE_BR) | BIT(PIPE_BV) }, +}; +DECLARE_ADRENO_REGLIST_PIPE_LIST(a830_dyn_pwrup_reglist); + static const struct adreno_reglist_pipe a840_nonctxt_regs[] = { { REG_A8XX_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, { REG_A8XX_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, @@ -2439,6 +2706,43 @@ static const struct adreno_info a8xx_gpus[] = { { 357, 2 }, { 284, 3 }, ), + }, { + .chip_ids = ADRENO_CHIP_IDS(0x44050000), + .family = ADRENO_8XX_GEN1, + .fw = { + [ADRENO_FW_SQE] = "gen80000_sqe.fw", + [ADRENO_FW_GMU] = "gen80000_gmu.bin", + [ADRENO_FW_AQE] = "gen80000_aqe.fw", + }, + .gmem = 12 * SZ_1M, + .inactive_period = DRM_MSM_INACTIVE_PERIOD, + .quirks = ADRENO_QUIRK_HAS_CACHED_COHERENT | + ADRENO_QUIRK_HAS_HW_APRIV | + ADRENO_QUIRK_PREEMPTION | + ADRENO_QUIRK_IFPC, + .funcs = &a8xx_gpu_funcs, + .a6xx = &(const struct a6xx_info) { + .protect = &a830_protect, + .nonctxt_reglist = a830_nonctxt_regs, + .pwrup_reglist = &a830_pwrup_reglist, + .dyn_pwrup_reglist = &a830_dyn_pwrup_reglist, + .ifpc_reglist = &a830_ifpc_reglist, + .gbif_cx = a840_gbif, + .max_slices = 3, + .gmu_chipid = 0x8000100, + .bcms = (const struct a6xx_bcm[]) { + { .name = "SH0", .buswidth = 16 }, + { .name = "MC0", .buswidth = 4 }, + { + .name = "ACV", + .fixed = true, + .perfmode = BIT(2), + .perfmode_bw = 8171875, + }, + { /* sentinel */ }, + }, + }, + .preempt_record_size = 13536 * SZ_1K, }, { .chip_ids = ADRENO_CHIP_IDS(0x44050a01), .family = ADRENO_8XX_GEN2, diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.h b/drivers/gpu/drm/msm/adreno/adreno_gpu.h index 114a40f79e..c096e171ff 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.h +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.h @@ -602,6 +602,11 @@ static inline int adreno_is_x285(struct adreno_gpu *gpu) return gpu->info->chip_ids[0] == 0x44070001; } +static inline int adreno_is_a830(struct adreno_gpu *gpu) +{ + return gpu->info->chip_ids[0] == 0x44050000; +} + static inline int adreno_is_a840(struct adreno_gpu *gpu) { return gpu->info->chip_ids[0] == 0x44050a01; diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c index b292dfd266..c147ba1889 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_host.c +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c @@ -852,7 +852,17 @@ static void dsi_ctrl_enable(struct msm_dsi_host *msm_host, } else { /* Do not swap RGB colors */ data = DSI_CMD_CFG0_RGB_SWAP(SWAP_RGB); - data |= DSI_CMD_CFG0_DST_FORMAT(dsi_get_cmd_fmt(mipi_fmt)); + /* + * With DSC and an RGB101010 panel (the AA569 on the OnePlus 13) + * the RGB101010 command DST format makes the first DCS command + * time out (cmd dma tx -110), while RGB888, which older kernels + * programmed here, works. Keep RGB888 with DSC until the cause + * is understood. + */ + if (msm_host->dsc && mipi_fmt == MIPI_DSI_FMT_RGB101010) + data |= DSI_CMD_CFG0_DST_FORMAT(CMD_DST_FORMAT_RGB888); + else + data |= DSI_CMD_CFG0_DST_FORMAT(dsi_get_cmd_fmt(mipi_fmt)); dsi_write(msm_host, REG_DSI_CMD_CFG0, data); data = DSI_CMD_CFG1_WR_MEM_START(MIPI_DCS_WRITE_MEMORY_START) | diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c index 9087c4b290..79f8e40b7d 100644 --- a/drivers/gpu/drm/msm/msm_mdss.c +++ b/drivers/gpu/drm/msm/msm_mdss.c @@ -26,6 +26,12 @@ struct msm_mdss_data { u32 reg_bus_bw; + /* + * Physical address of the display (mdp_hf) QTB500 TBU of the apps + * SMMU, or 0. If set, it is read once on every MDSS enable, before + * any display master issues a memory fetch. See msm_mdss_qtb_sync(). + */ + phys_addr_t hf_qtb_base; }; struct msm_mdss { @@ -43,6 +49,7 @@ struct msm_mdss { u32 reg_bus_bw; struct icc_path *mdp_path[2]; u32 num_mdp_paths; + void __iomem *hf_qtb; struct icc_path *reg_bus_path; }; @@ -228,6 +235,21 @@ static void msm_mdss_6x_setup_ubwc(struct msm_mdss *msm_mdss) (((minor) & 0xfff) << 16) | \ ((step) & 0xffff)) +/* + * On SM8750 the first DSI command-mode DMA fetches after a warm reset can + * wedge in the display QTB500 (the apps SMMU TBU in front of MDSS): the DSI + * engine and xin7 stay busy forever, with no SMMU fault and no DSI error, + * after two small fetches have completed. A single CPU read of the QTB's + * SWID_LOW register (offset 0, what the downstream qtb500 code uses as its + * write_sync) before the first fetch avoids it. Do that read here, after the + * MDSS clocks and interconnect votes are up. + */ +static void msm_mdss_qtb_sync(struct msm_mdss *msm_mdss) +{ + if (msm_mdss->hf_qtb) + readl(msm_mdss->hf_qtb); +} + static int msm_mdss_enable(struct msm_mdss *msm_mdss) { int ret, i; @@ -258,6 +280,8 @@ static int msm_mdss_enable(struct msm_mdss *msm_mdss) return ret; } + msm_mdss_qtb_sync(msm_mdss); + /* * Register access requires MDSS_MDP_CLK, which is not enabled by the * mdss on mdp5 hardware. Skip it for now. @@ -393,6 +417,14 @@ static struct msm_mdss *msm_mdss_init(struct platform_device *pdev, bool is_mdp5 dev_dbg(&pdev->dev, "mapped mdss address space @%p\n", msm_mdss->mmio); + if (mdss_data->hf_qtb_base) { + /* Not a resource of this device: the TBU belongs to the apps SMMU */ + msm_mdss->hf_qtb = devm_ioremap(&pdev->dev, mdss_data->hf_qtb_base, + SZ_4K); + if (!msm_mdss->hf_qtb) + dev_warn(&pdev->dev, "cannot map the display QTB\n"); + } + ret = msm_mdss_parse_data_bus_icc_path(&pdev->dev, msm_mdss); if (ret) return ERR_PTR(ret); @@ -512,6 +544,11 @@ static const struct msm_mdss_data data_57k = { .reg_bus_bw = 57000, }; +static const struct msm_mdss_data sm8750_data = { + .reg_bus_bw = 57000, + .hf_qtb_base = 0x017d0000, /* mdp_hf_qtb, stock DT apps-smmu */ +}; + static const struct msm_mdss_data data_74k = { .reg_bus_bw = 74000, }; @@ -553,7 +590,7 @@ static const struct of_device_id mdss_dt_match[] = { { .compatible = "qcom,sm8450-mdss", .data = &data_74k }, { .compatible = "qcom,sm8550-mdss", .data = &data_57k }, { .compatible = "qcom,sm8650-mdss", .data = &data_57k }, - { .compatible = "qcom,sm8750-mdss", .data = &data_57k }, + { .compatible = "qcom,sm8750-mdss", .data = &sm8750_data }, /* TODO: x1e8: Add reg_bus_bw with real value */ { .compatible = "qcom,x1e80100-mdss", .data = &data_153k6 }, {} diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig index 5d667d0148..34ddc78d6c 100644 --- a/drivers/gpu/drm/panel/Kconfig +++ b/drivers/gpu/drm/panel/Kconfig @@ -1442,4 +1442,15 @@ config DRM_PANEL_XINPENG_XPP055C272 Say Y here if you want to enable support for the Xinpeng XPP055C272 controller for 720x1280 LCD panels with MIPI/RGB/SPI system interfaces. + +config DRM_PANEL_ONEPLUS_DODGE + tristate "OnePlus dodge panel driver" + depends on OF + depends on DRM_MIPI_DSI + depends on BACKLIGHT_CLASS_DEVICE + select DRM_DISPLAY_DSC_HELPER + select DRM_DISPLAY_HELPER + help + Say Y here if you want to enable support for the OnePlus screen + endmenu diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile index cbf10d7d4d..6d4547cb0e 100644 --- a/drivers/gpu/drm/panel/Makefile +++ b/drivers/gpu/drm/panel/Makefile @@ -139,3 +139,4 @@ obj-$(CONFIG_DRM_PANEL_VISIONOX_VTDR6130) += panel-visionox-vtdr6130.o obj-$(CONFIG_DRM_PANEL_VISIONOX_R66451) += panel-visionox-r66451.o obj-$(CONFIG_DRM_PANEL_WIDECHIPS_WS2401) += panel-widechips-ws2401.o obj-$(CONFIG_DRM_PANEL_XINPENG_XPP055C272) += panel-xinpeng-xpp055c272.o +obj-$(CONFIG_DRM_PANEL_ONEPLUS_DODGE) += panel-aa569-p-3-a0019-dsc.o diff --git a/drivers/gpu/drm/panel/panel-aa569-p-3-a0019-dsc.c b/drivers/gpu/drm/panel/panel-aa569-p-3-a0019-dsc.c new file mode 100644 index 0000000000..c1eb231482 --- /dev/null +++ b/drivers/gpu/drm/panel/panel-aa569-p-3-a0019-dsc.c @@ -0,0 +1,504 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree: +// Copyright (c) 2013, The Linux Foundation. All rights reserved. + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +struct panel_aa569_p_3_a0019_dsc { + struct drm_panel panel; + struct mipi_dsi_device *dsi; + struct drm_dsc_config dsc; + struct gpio_desc *reset_gpio; + struct regulator_bulk_data *supplies; +}; + +static const struct regulator_bulk_data panel_aa569_supplies[] = { + { .supply = "vddio" }, + { .supply = "vci" }, + { .supply = "vdd" }, +}; + +static inline +struct panel_aa569_p_3_a0019_dsc *to_panel_aa569_p_3_a0019_dsc(struct drm_panel *panel) +{ + return container_of(panel, struct panel_aa569_p_3_a0019_dsc, panel); +} + +static void panel_aa569_p_3_a0019_dsc_reset(struct panel_aa569_p_3_a0019_dsc *ctx) +{ + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + msleep(10); + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + msleep(5); + gpiod_set_value_cansleep(ctx->reset_gpio, 0); + msleep(30); + +} + +static int panel_aa569_p_3_a0019_dsc_on(struct panel_aa569_p_3_a0019_dsc *ctx) +{ + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; + + ctx->dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x07); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8a, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x31); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd0, 0x80); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x08); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xbe, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x08); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd2, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd3, 0x0f); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd4, 0x40); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf5, 0x55); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf6, 0x18); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x21); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa4, 0x18); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x1f); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8f, + 0x03, 0x08, 0x50, 0x0e, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x0e, 0x00, 0x00, 0x08, + 0x02, 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x9e, 0x77); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x14); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x80, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x17); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa0, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x13); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf9, 0x5c); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x85, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x1c); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xe2, + 0x0a, 0x0a, 0x0a, 0x1a, 0x1a, 0x1a, 0x1a, + 0x1a, 0x0a, 0x0a, 0x0a, 0x04, 0x27, 0x12, + 0x23, 0x09, 0x46, 0x45); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfb, 0x08); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x09); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8e, + 0x10, 0x82, 0x00, 0x00, 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x88, 0xc0, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x14); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x82, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x07); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x91, 0x03); + // Changes from downstream kernel + //mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8a, 0x00); + //mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8b, 0xa0, 0x21); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x81, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, + 0x00, 0xab, 0x21, 0x00, 0x0c, 0x60, 0x05, + 0xa0, 0x00, 0x16, 0x02, 0xd0, 0x02, 0xd0, + 0x01, 0x55, 0x01, 0xe2, 0x00, 0x0a, 0x01, + 0x4d, 0x00, 0x3c, 0x00, 0x0d, 0x04, 0xf4, + 0x13, 0xa3, 0x08, 0x00, 0x0c, 0x00, 0x07, + 0x10, 0x20, 0x00, 0x06, 0x0f, 0x0f, 0x33, + 0x0e, 0x1c, 0x2a, 0x38, 0x46, 0x54, 0x62, + 0x69, 0x70, 0x77, 0x79, 0x7b, 0x7d, 0x7e, + 0x00, 0x82, 0x11, 0x40, 0x19, 0xc0, 0x22, + 0x3e, 0x32, 0x7c, 0x3a, 0xba, 0x3a, 0xf8, + 0x3b, 0x38, 0x3b, 0x38, 0x3b, 0x76, 0x4b, + 0x76, 0x4b, 0x74, 0x4b, 0x74, 0x5b, 0xb4, + 0x73, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x5e, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x60, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x61, 0x0d); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x6d, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x35, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x53, 0x20); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x60, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x2d); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x83, 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf2, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb0, 0x01, 0x80, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x84, 0x01, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x1e); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x98, 0x99, 0xaa, 0x99); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x99, + 0x88, 0x00, 0x00, 0x88, 0x00, 0x00, 0x88, + 0x00, 0x00, 0x08, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa3, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x1e); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x81, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x22); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd8, + 0x01, 0x0c, 0x11, 0x10, 0x32, 0x19, 0x19); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdc, + 0x84, 0x94, 0xbb, 0x00, 0x20, 0xc4, 0xa1, + 0xcc, 0x10); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdd, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xde, 0xf1); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdf, 0x80); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xe0, + 0x02, 0x00, 0x5f, 0x21, 0x00, 0x28); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x2d); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xed, 0x05, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x97, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x98, 0x03); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x99, 0x0b); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x9a, 0x17); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa0, 0x00, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa1, 0x02, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa4, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa5, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa6, 0x08); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa7, 0x11); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xad, 0x00, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xae, 0x02, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x08); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x98, 0x66); + mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx); + mipi_dsi_msleep(&dsi_ctx, 120); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x4f); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x80, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x53); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0x01); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x63); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf9, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfa, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x53); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x49); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd9, 0x03); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xda, 0x1e); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdb, 0xfc); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdf, 0x06); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x5a); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x81, 0x07, 0x1a, 0x04); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8a, 0xf6, 0x17, 0x12); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x8f, 0x12, 0x3a, 0x33); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa5, 0x09, 0x1a, 0x08); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb3, 0x30, 0x38, 0x31); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xc9, 0x08, 0x0d, 0x06); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xca, 0x03, 0x06, 0x03); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd7, 0x2f, 0x34, 0x2d); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x5b); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x81, 0x05, 0x09, 0x03); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x83, 0x02, 0x0c, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x93, 0x00, 0x01, 0x07); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x94, 0x05, 0x06, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa5, 0x09, 0x0c, 0x04); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa7, 0xfd, 0x0f, 0x04); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb7, 0x02, 0x07, 0x07); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb8, 0x05, 0x07, 0x06); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xc9, 0x05, 0x07, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xca, 0x00, 0x00, 0x00); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xcb, 0x02, 0x09, 0xff); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdb, 0x00, 0x04, 0x06); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xdc, 0x00, 0x06, 0x04); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x5c); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x81, 0x00, 0x03, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x83, 0x01, 0x08, 0x05); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x93, 0xff, 0x01, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x94, 0xff, 0x06, 0x04); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa5, 0x01, 0x03, 0x02); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb7, 0xff, 0x01, 0x06); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb8, 0xff, 0x06, 0x03); + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_set_display_on_multi(&dsi_ctx); + + return dsi_ctx.accum_err; +} + +static int panel_aa569_p_3_a0019_dsc_off(struct panel_aa569_p_3_a0019_dsc *ctx) +{ + struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi }; + + ctx->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xff, 0x5a, 0xa5, 0x00); + mipi_dsi_dcs_set_display_off_multi(&dsi_ctx); + mipi_dsi_msleep(&dsi_ctx, 20); + mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx); + mipi_dsi_msleep(&dsi_ctx, 120); + + return dsi_ctx.accum_err; +} + +static int panel_aa569_p_3_a0019_dsc_prepare(struct drm_panel *panel) +{ + struct panel_aa569_p_3_a0019_dsc *ctx = to_panel_aa569_p_3_a0019_dsc(panel); + struct device *dev = &ctx->dsi->dev; + struct drm_dsc_picture_parameter_set pps; + int ret; + + ret = regulator_bulk_enable(ARRAY_SIZE(panel_aa569_supplies), + ctx->supplies); + if (ret < 0) + return ret; + + panel_aa569_p_3_a0019_dsc_reset(ctx); + + ret = panel_aa569_p_3_a0019_dsc_on(ctx); + if (ret < 0) { + dev_err(dev, "Failed to initialize panel: %d\n", ret); + goto err_poweroff; + } + + drm_dsc_pps_payload_pack(&pps, &ctx->dsc); + + ret = mipi_dsi_picture_parameter_set(ctx->dsi, &pps); + if (ret < 0) { + dev_err(panel->dev, "failed to transmit PPS: %d\n", ret); + goto err_poweroff; + } + + ret = mipi_dsi_compression_mode(ctx->dsi, true); + if (ret < 0) { + dev_err(dev, "failed to enable compression mode: %d\n", ret); + goto err_poweroff; + } + + msleep(28); /* TODO: Is this panel-dependent? */ + + return 0; + +err_poweroff: + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + regulator_bulk_disable(ARRAY_SIZE(panel_aa569_supplies), ctx->supplies); + return ret; +} + +static int panel_aa569_p_3_a0019_dsc_unprepare(struct drm_panel *panel) +{ + struct panel_aa569_p_3_a0019_dsc *ctx = to_panel_aa569_p_3_a0019_dsc(panel); + struct device *dev = &ctx->dsi->dev; + int ret; + + ret = panel_aa569_p_3_a0019_dsc_off(ctx); + if (ret < 0) + dev_err(dev, "Failed to un-initialize panel: %d\n", ret); + + gpiod_set_value_cansleep(ctx->reset_gpio, 1); + regulator_bulk_disable(ARRAY_SIZE(panel_aa569_supplies), ctx->supplies); + + return 0; +} + +static const struct drm_display_mode panel_aa569_p_3_a0019_dsc_mode = { + .clock = (1440 + 64 + 8 + 50) * (3168 + 16 + 4 + 12) * 120 / 1000, + .hdisplay = 1440, + .hsync_start = 1440 + 64, + .hsync_end = 1440 + 64 + 8, + .htotal = 1440 + 64 + 8 + 50, + .vdisplay = 3168, + .vsync_start = 3168 + 16, + .vsync_end = 3168 + 16 + 4, + .vtotal = 3168 + 16 + 4 + 12, + .width_mm = 71, + .height_mm = 158, + .type = DRM_MODE_TYPE_DRIVER, +}; + +static int panel_aa569_p_3_a0019_dsc_get_modes(struct drm_panel *panel, + struct drm_connector *connector) +{ + return drm_connector_helper_get_modes_fixed(connector, &panel_aa569_p_3_a0019_dsc_mode); +} + +static const struct drm_panel_funcs panel_aa569_p_3_a0019_dsc_panel_funcs = { + .prepare = panel_aa569_p_3_a0019_dsc_prepare, + .unprepare = panel_aa569_p_3_a0019_dsc_unprepare, + .get_modes = panel_aa569_p_3_a0019_dsc_get_modes, +}; + +static int panel_aa569_p_3_a0019_dsc_bl_update_status(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + struct panel_aa569_p_3_a0019_dsc *ctx = mipi_dsi_get_drvdata(dsi); + u16 brightness = backlight_get_brightness(bl); + int ret; + + if (!ctx->panel.prepared) + return 0; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness); + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return ret; +} + + +static int panel_aa569_p_3_a0019_dsc_bl_get_brightness(struct backlight_device *bl) +{ + struct mipi_dsi_device *dsi = bl_get_data(bl); + struct panel_aa569_p_3_a0019_dsc *ctx = mipi_dsi_get_drvdata(dsi); + u16 brightness; + int ret; + + if (!ctx->panel.prepared) + return 0; + + dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; + + ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness); + + dsi->mode_flags |= MIPI_DSI_MODE_LPM; + + return ret < 0 ? ret : brightness; +} + +static const struct backlight_ops panel_aa569_p_3_a0019_dsc_bl_ops = { + .update_status = panel_aa569_p_3_a0019_dsc_bl_update_status, + .get_brightness = panel_aa569_p_3_a0019_dsc_bl_get_brightness, +}; + +static struct backlight_device * +panel_aa569_p_3_a0019_dsc_create_backlight(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + const struct backlight_properties props = { + .type = BACKLIGHT_RAW, + .brightness = 2047, + .max_brightness = 3502, // 15% cut to prevent burn in ( original value 4095 ) + }; + + return devm_backlight_device_register(dev, dev_name(dev), dev, dsi, + &panel_aa569_p_3_a0019_dsc_bl_ops, &props); +} + +static int panel_aa569_p_3_a0019_dsc_probe(struct mipi_dsi_device *dsi) +{ + struct device *dev = &dsi->dev; + struct panel_aa569_p_3_a0019_dsc *ctx; + int ret; + + ctx = devm_drm_panel_alloc(dev, struct panel_aa569_p_3_a0019_dsc, panel, + &panel_aa569_p_3_a0019_dsc_panel_funcs, + DRM_MODE_CONNECTOR_DSI); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); + + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(ctx->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), + "Failed to get reset-gpios\n"); + + ret = devm_regulator_bulk_get_const(dev, + ARRAY_SIZE(panel_aa569_supplies), + panel_aa569_supplies, + &ctx->supplies); + if (ret) + return dev_err_probe(dev, ret, "Failed to get regulators\n"); + + ctx->dsi = dsi; + mipi_dsi_set_drvdata(dsi, ctx); + + dsi->lanes = 4; + dsi->format = MIPI_DSI_FMT_RGB101010; + /* + * Stock drives this panel in DSC command mode + * (qcom,mdss-dsi-panel-type = "dsi_cmd_mode") with TE on mdp_vsync. + */ + dsi->mode_flags = MIPI_DSI_MODE_NO_EOT_PACKET | + MIPI_DSI_CLOCK_NON_CONTINUOUS; + + ctx->panel.prepare_prev_first = true; + + ctx->panel.backlight = panel_aa569_p_3_a0019_dsc_create_backlight(dsi); + if (IS_ERR(ctx->panel.backlight)) + return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight), + "Failed to create backlight\n"); + + + drm_panel_add(&ctx->panel); + + /* This panel only supports DSC; unconditionally enable it */ + dsi->dsc = &ctx->dsc; + + ctx->dsc.dsc_version_major = 1; + ctx->dsc.dsc_version_minor = 2; + + ctx->dsc.slice_height = 22; + ctx->dsc.slice_width = 720; + /* One slice per packet: the 7.3 default (no ALL_SLICES_IN_PKT). */ + ctx->dsc.slice_count = 2; + ctx->dsc.convert_rgb = true; + ctx->dsc.bits_per_component = 10; + ctx->dsc.bits_per_pixel = 8 << 4; /* 4 fractional bits */ + ctx->dsc.block_pred_enable = true; + + + ret = mipi_dsi_attach(dsi); + if (ret < 0) { + drm_panel_remove(&ctx->panel); + return dev_err_probe(dev, ret, "Failed to attach to DSI host\n"); + } + + return 0; +} + + +static void panel_aa569_p_3_a0019_dsc_remove(struct mipi_dsi_device *dsi) +{ + struct panel_aa569_p_3_a0019_dsc *ctx = mipi_dsi_get_drvdata(dsi); + int ret; + + ret = mipi_dsi_detach(dsi); + if (ret < 0) + dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret); + + drm_panel_remove(&ctx->panel); +} + +static const struct of_device_id panel_aa569_p_3_a0019_dsc_of_match[] = { + { .compatible = "oneplus,dodge-panel" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, panel_aa569_p_3_a0019_dsc_of_match); + +static struct mipi_dsi_driver panel_aa569_p_3_a0019_dsc_driver = { + .probe = panel_aa569_p_3_a0019_dsc_probe, + .remove = panel_aa569_p_3_a0019_dsc_remove, + .driver = { + .name = "panel-panel-aa569-p-3-a0019-dsc", + .of_match_table = panel_aa569_p_3_a0019_dsc_of_match, + }, +}; +module_mipi_dsi_driver(panel_aa569_p_3_a0019_dsc_driver); + +MODULE_DESCRIPTION("DRM driver for AA569 P 3 A0019 dsc cmd mode panel"); +MODULE_LICENSE("GPL"); diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 87f635e73c..9699d4bd0d 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1462,4 +1462,16 @@ config TOUCHSCREEN_HIMAX_HX83112B To compile this driver as a module, choose M here: the module will be called himax_hx83112b. +config TOUCHSCREEN_SYNA_TCM2 + tristate "Synaptics TCM touchscreen over SPI" + depends on SPI + help + Say Y here if you have a Synaptics TCM touchscreen on SPI, + such as the S3910 (compatible "synaptics,tcm-spi-hbp"). + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called synaptics_tcm2. + endif diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 6da5860c62..bf825cef40 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -122,3 +122,6 @@ obj-$(CONFIG_TOUCHSCREEN_IQS5XX) += iqs5xx.o obj-$(CONFIG_TOUCHSCREEN_IQS7211) += iqs7211.o obj-$(CONFIG_TOUCHSCREEN_ZINITIX) += zinitix.o obj-$(CONFIG_TOUCHSCREEN_HIMAX_HX83112B) += himax_hx83112b.o +# syna_tcm2.c cannot be both the member and the module name. +obj-$(CONFIG_TOUCHSCREEN_SYNA_TCM2) += synaptics_tcm2.o +synaptics_tcm2-y := syna_tcm2.o syna_tcm2_spi.o diff --git a/drivers/input/touchscreen/syna_tcm2.c b/drivers/input/touchscreen/syna_tcm2.c new file mode 100644 index 0000000000..c47f67ddea --- /dev/null +++ b/drivers/input/touchscreen/syna_tcm2.c @@ -0,0 +1,2448 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Synaptics TouchCom touchscreen driver + * + * Copyright (C) 2017-2020 Synaptics Incorporated. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS + * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, + * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS. + * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION + * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED + * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES + * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' + * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. + * DOLLARS. + */ + +#include "syna_tcm2.h" +#include +#include + +static DECLARE_WAIT_QUEUE_HEAD(state_waiter); + +extern struct platform_device *syna_spi_device; + +static void syna_dev_free_input_events(struct syna_tcm *tcm) +{ + struct input_dev *input_dev = tcm->input_dev; + unsigned int idx; + if (input_dev == NULL) + return; + syna_pal_mutex_lock(&tcm->tp_event_mutex); + for (idx = 0; idx < MAX_NUM_OBJECTS; idx++) { + input_mt_slot(input_dev, idx); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + } + input_report_key(input_dev, BTN_TOUCH, 0); + input_report_key(input_dev, BTN_TOOL_FINGER, 0); + input_sync(input_dev); + syna_pal_mutex_unlock(&tcm->tp_event_mutex); + +} + +static void syna_dev_report_input_events(struct syna_tcm *tcm) +{ + unsigned int idx; + unsigned int x; + unsigned int y; + int wx; + int wy; + unsigned int status; + unsigned int touch_count; + struct input_dev *input_dev = tcm->input_dev; + unsigned int max_objects = tcm->tcm_dev->max_objects; + struct tcm_objects_data_blob *object_data; + if (input_dev == NULL) + return; + syna_pal_mutex_lock(&tcm->tp_event_mutex); + object_data = &tcm->tp_data.object_data[0]; + + if (tcm->pwr_state == LOW_PWR) + goto exit; + touch_count = 0; + if (max_objects > MAX_NUM_OBJECTS) + max_objects = MAX_NUM_OBJECTS; + for (idx = 0; idx < max_objects; idx++) { + if (tcm->prev_obj_status[idx] == LIFT && + object_data[idx].status == LIFT) + status = NOP; + else + status = object_data[idx].status; + + switch (status) { + case LIFT: + input_mt_slot(input_dev, idx); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); + break; + case FINGER: + case GLOVED_OBJECT: + x = object_data[idx].x_pos; + y = object_data[idx].y_pos; + wx = object_data[idx].x_width; + wy = object_data[idx].y_width; + input_mt_slot(input_dev, idx); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1); + input_report_key(input_dev, BTN_TOUCH, 1); + input_report_key(input_dev, BTN_TOOL_FINGER, 1); + if (tcm->dts_max_x && tcm->dts_max_y && + tcm->firmware_max_x && tcm->firmware_max_y) { + input_report_abs(input_dev, ABS_MT_POSITION_X, x * tcm->dts_max_x / tcm->firmware_max_x); + input_report_abs(input_dev, ABS_MT_POSITION_Y, y * tcm->dts_max_y / tcm->firmware_max_y); + } else { + input_report_abs(input_dev, ABS_MT_POSITION_X, x); + input_report_abs(input_dev, ABS_MT_POSITION_Y, y); + } + input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, MAX(wx, wy)); + input_report_abs(input_dev, ABS_MT_TOUCH_MINOR, MIN(wx, wy)); + touch_count++; + break; + default: + break; + } + tcm->prev_obj_status[idx] = object_data[idx].status; + } + if (touch_count == 0) { + input_report_key(input_dev, BTN_TOUCH, 0); + input_report_key(input_dev, BTN_TOOL_FINGER, 0); + } + input_sync(input_dev); +exit: + syna_pal_mutex_unlock(&tcm->tp_event_mutex); +} + +static int syna_dev_create_input_device(struct syna_tcm *tcm) +{ + int retval = 0; + struct tcm_dev *tcm_dev = tcm->tcm_dev; + struct input_dev *input_dev = NULL; + input_dev = input_allocate_device(); + if (input_dev == NULL) + return -ENODEV; + input_dev->name = TOUCH_INPUT_NAME; + input_dev->phys = TOUCH_INPUT_PHYS_PATH; + input_dev->id.product = SYNAPTICS_TCM_DRIVER_ID; + input_dev->id.version = SYNAPTICS_TCM_DRIVER_VERSION; + input_dev->dev.parent = tcm->pdev->dev.parent; + input_set_drvdata(input_dev, tcm); + set_bit(EV_SYN, input_dev->evbit); + set_bit(EV_KEY, input_dev->evbit); + set_bit(EV_ABS, input_dev->evbit); + set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit); + set_bit(ABS_MT_POSITION_X, input_dev->absbit); + set_bit(ABS_MT_POSITION_Y, input_dev->absbit); + set_bit(ABS_MT_TOOL_TYPE, input_dev->absbit); + set_bit(BTN_TOUCH, input_dev->keybit); + set_bit(BTN_TOOL_FINGER, input_dev->keybit); +#ifdef INPUT_PROP_DIRECT + set_bit(INPUT_PROP_DIRECT, input_dev->propbit); +#endif + set_bit(KEY_SLEEP, input_dev->keybit); + input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, tcm_dev->max_x, 0, 0); + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, tcm_dev->max_y, 0, 0); + input_mt_init_slots(input_dev, tcm_dev->max_objects, INPUT_MT_DIRECT); + input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); + input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0); + input_set_abs_params(input_dev, ABS_PROFILE, 0, 1, 0, 0); + tcm->input_dev_params.max_x = tcm_dev->max_x; + tcm->input_dev_params.max_y = tcm_dev->max_y; + tcm->input_dev_params.max_objects = tcm_dev->max_objects; + + retval = input_register_device(input_dev); + if (retval < 0) { + input_free_device(input_dev); + input_dev = NULL; + return retval; + } + + tcm->input_dev = input_dev; + + return 0; +} + +static void syna_dev_release_input_device(struct syna_tcm *tcm) +{ + if (!tcm->input_dev) + return; + input_unregister_device(tcm->input_dev); + tcm->input_dev = NULL; +} + +static int syna_dev_set_up_input_device(struct syna_tcm *tcm) +{ + int retval = 0; + if (IS_NOT_APP_FW_MODE(tcm->tcm_dev->dev_mode)) + return 0; + syna_dev_free_input_events(tcm); + syna_pal_mutex_lock(&tcm->tp_event_mutex); + if (tcm->input_dev != NULL) + syna_dev_release_input_device(tcm); + retval = syna_dev_create_input_device(tcm); + if (retval < 0) + goto exit; + +exit: + syna_pal_mutex_unlock(&tcm->tp_event_mutex); + return retval; +} + +int syna_tcm_get_touch_data(const unsigned char *report, + unsigned int report_size, unsigned int offset, + unsigned int bits, unsigned int *data) +{ + unsigned char mask; + unsigned char byte_data; + unsigned int output_data; + unsigned int bit_offset; + unsigned int byte_offset; + unsigned int data_bits; + unsigned int available_bits; + unsigned int remaining_bits; + + if (bits == 0 || bits > 32 || !report) + return _EINVAL; + + if (offset + bits > report_size * 8) { + *data = 0; + return 0; + } + + output_data = 0; + remaining_bits = bits; + + bit_offset = offset % 8; + byte_offset = offset / 8; + + while (remaining_bits) { + byte_data = report[byte_offset]; + byte_data >>= bit_offset; + + available_bits = 8 - bit_offset; + data_bits = MIN(available_bits, remaining_bits); + mask = 0xff >> (8 - data_bits); + + byte_data &= mask; + + output_data |= byte_data << (bits - remaining_bits); + + bit_offset = 0; + byte_offset += 1; + remaining_bits -= data_bits; + } + + *data = output_data; + + return 0; +} + +int syna_tcm_get_event_data(struct tcm_dev *tcm_dev, + unsigned char *code, struct tcm_buffer *data) +{ + int retval = 0; + + if (!tcm_dev || !code) + return _EINVAL; + + retval = tcm_dev->read_message(tcm_dev, + code); + if (retval < 0) + return retval; + + if (!data) + goto exit; + + if (*code >= REPORT_IDENTIFY && *code != STATUS_INVALID) { + if (tcm_dev->report_buf.data_length == 0) + goto exit; + + syna_tcm_buf_lock(&tcm_dev->report_buf); + + retval = syna_tcm_buf_copy(data, &tcm_dev->report_buf); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_dev->report_buf); + goto exit; + } + + syna_tcm_buf_unlock(&tcm_dev->report_buf); + } + + if (*code > STATUS_IDLE && *code <= STATUS_ERROR) { + if (tcm_dev->resp_buf.data_length == 0) + goto exit; + + syna_tcm_buf_lock(&tcm_dev->resp_buf); + + retval = syna_tcm_buf_copy(data, &tcm_dev->resp_buf); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + goto exit; + } + + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + } + +exit: + return retval; +} + +static int syna_tcm_get_gesture_data(const unsigned char *report, + unsigned int report_size, unsigned int offset, + unsigned int bits, struct tcm_gesture_data_blob *gesture_data, + unsigned int gesture_id) +{ + int retval; + unsigned int idx; + unsigned int data; + unsigned int size; + unsigned int data_end; + + if (!report) + return _EINVAL; + + if (offset + bits > report_size * 8) + return 0; + + data_end = offset + bits; + + size = (sizeof(gesture_data->data) / sizeof(unsigned char)); + + idx = 0; + while (offset < data_end && idx < size) { + retval = syna_tcm_get_touch_data(report, report_size, offset, 16, &data); + if (retval < 0) + return retval; + gesture_data->data[idx++] = (unsigned char)(data & 0xff); + gesture_data->data[idx++] = (unsigned char)((data >> 8) & 0xff); + offset += 16; + } + + return 0; +} + +int syna_tcm_parse_touch_report(struct tcm_dev *tcm_dev, + unsigned char *report, unsigned int report_size, + struct tcm_touch_data_blob *touch_data) +{ + int retval; + bool active_only; + bool num_of_active_objects; + unsigned char code; + unsigned int size; + unsigned int idx; + unsigned int obj; + unsigned int next; + unsigned int data; + unsigned int bits; + unsigned int offset; + unsigned int objects; + unsigned int active_objects; + unsigned int config_size; + unsigned char *config_data; + struct tcm_objects_data_blob *object_data; + unsigned int end_of_foreach = 0; + + if (!tcm_dev || !report || report_size <= 0 || !touch_data || tcm_dev->max_objects == 0) + return _EINVAL; + + object_data = touch_data->object_data; + + if (!object_data) + return _EINVAL; + + config_data = tcm_dev->touch_config.buf; + config_size = tcm_dev->touch_config.data_length; + + if (!config_data || config_size == 0) + return _EINVAL; + + size = sizeof(touch_data->object_data); + memset(touch_data->object_data, 0x00, size); + + num_of_active_objects = false; + + idx = 0; + offset = 0; + objects = 0; + active_objects = 0; + active_only = false; + obj = 0; + next = 0; + + while (idx < config_size) { + code = config_data[idx++]; + switch (code) { + case TOUCH_REPORT_END: + goto exit; + case TOUCH_REPORT_FOREACH_ACTIVE_OBJECT: + obj = 0; + next = idx; + active_only = true; + break; + case TOUCH_REPORT_FOREACH_OBJECT: + obj = 0; + next = idx; + active_only = false; + break; + case TOUCH_REPORT_FOREACH_END: + end_of_foreach = idx; + if (active_only) { + if (num_of_active_objects) { + objects++; + obj++; + if (obj >= MAX_NUM_OBJECTS) + goto exit; + if (objects < active_objects) + idx = next; + } else if (offset < report_size * 8) { + obj++; + if (obj >= MAX_NUM_OBJECTS) + goto exit; + idx = next; + } + } else { + obj++; + if (obj < tcm_dev->max_objects && + obj < MAX_NUM_OBJECTS) + idx = next; + } + break; + case TOUCH_REPORT_PAD_TO_NEXT_BYTE: + offset = syna_pal_ceil_div(offset, 8) * 8; + break; + case TOUCH_REPORT_TIMESTAMP: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->timestamp = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_INDEX: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + obj = data; + if (obj >= MAX_NUM_OBJECTS) + return _EINVAL; + touch_data->obji = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_CLASSIFICATION: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].status = (unsigned char)data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_X_POSITION: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].x_pos = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_Y_POSITION: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].y_pos = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_Z: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].z = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_X_WIDTH: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].x_width = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_Y_WIDTH: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].y_width = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_TX_POSITION_TIXELS: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].tx_pos = data; + offset += bits; + break; + case TOUCH_REPORT_OBJECT_N_RX_POSITION_TIXELS: + if (obj >= MAX_NUM_OBJECTS || idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + object_data[obj].rx_pos = data; + offset += bits; + break; + case TOUCH_REPORT_NUM_OF_ACTIVE_OBJECTS: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + active_objects = data; + num_of_active_objects = true; + touch_data->num_of_active_objects = data; + offset += bits; + if (touch_data->num_of_active_objects == 0) { + if (end_of_foreach == 0) + return 0; + + idx = end_of_foreach; + } + break; + case TOUCH_REPORT_0D_BUTTONS_STATE: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->buttons_state = data; + offset += bits; + break; + case TOUCH_REPORT_GESTURE_ID: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, + report_size, offset, bits, &data); + touch_data->gesture_id = data; + offset += bits; + if (retval < 0) + return retval; + break; + case TOUCH_REPORT_GESTURE_DATA: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_gesture_data(report, + report_size, + offset, bits, + &touch_data->gesture_data, + touch_data->gesture_id); + offset += bits; + if (retval < 0) + return retval; + break; + case TOUCH_REPORT_FRAME_RATE: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->frame_rate = data; + offset += bits; + break; + case TOUCH_REPORT_FORCE_MEASUREMENT: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->force_data = data; + offset += bits; + break; + case TOUCH_REPORT_POWER_IM: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->power_im = data; + offset += bits; + break; + case TOUCH_REPORT_CID_IM: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->cid_im = data; + offset += bits; + break; + case TOUCH_REPORT_RAIL_IM: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->rail_im = data; + offset += bits; + break; + case TOUCH_REPORT_CID_VARIANCE_IM: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->cid_variance_im = data; + offset += bits; + break; + case TOUCH_REPORT_NSM_FREQUENCY_INDEX: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->nsm_frequency = data; + offset += bits; + break; + case TOUCH_REPORT_NSM_STATE: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->nsm_state = data; + offset += bits; + break; + case TOUCH_REPORT_SENSING_MODE: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + retval = syna_tcm_get_touch_data(report, report_size, + offset, bits, &data); + if (retval < 0) + return retval; + touch_data->sensing_mode = data; + offset += bits; + break; + default: + if (idx >= config_size) + return _EINVAL; + bits = config_data[idx++]; + offset += bits; + break; + } + } + +exit: + return 0; +} + +static irqreturn_t syna_dev_isr(int irq, void *data) +{ + int retval; + unsigned char code = 0; + struct syna_tcm *tcm = data; + struct syna_hw_attn_data *attn = &tcm->hw_if->bdata_attn; + + if (unlikely(gpio_get_value(attn->irq_gpio) != attn->irq_on_state)) + goto exit; + + tcm->isr_pid = current->pid; + + retval = syna_tcm_get_event_data(tcm->tcm_dev, + &code, + &tcm->event_data); + if (retval < 0) + goto exit; + + if (code == REPORT_TOUCH) { + retval = syna_tcm_parse_touch_report(tcm->tcm_dev, + tcm->event_data.buf, + tcm->event_data.data_length, + &tcm->tp_data); + if (retval < 0) + goto exit; + syna_dev_report_input_events(tcm); + } + +exit: + return IRQ_HANDLED; +} + +static int syna_dev_request_irq(struct syna_tcm *tcm) +{ + int retval; + struct syna_hw_attn_data *attn = &tcm->hw_if->bdata_attn; + + if (attn->irq_gpio < 0) { + retval = -EINVAL; + goto exit; + } + + attn->irq_id = gpio_to_irq(attn->irq_gpio); + retval = request_threaded_irq(attn->irq_id, + NULL, + syna_dev_isr, + attn->irq_flags | IRQF_ONESHOT, + PLATFORM_DRIVER_NAME, + tcm); + if (retval < 0) + goto exit; + + attn->irq_enabled = true; + tcm->bus_ready = true; + +exit: + return retval; +} + +static void syna_dev_release_irq(struct syna_tcm *tcm) +{ + struct syna_hw_attn_data *attn = &tcm->hw_if->bdata_attn; + + if (attn->irq_id <= 0) + return; + + if (tcm->hw_if->ops_enable_irq) + tcm->hw_if->ops_enable_irq(tcm->hw_if, false); + + free_irq(attn->irq_id, tcm); + + attn->irq_id = 0; + attn->irq_enabled = false; +} + +int syna_tcm_preserve_touch_report_config(struct tcm_dev *tcm_dev) +{ + int retval = 0; + unsigned char resp_code; + unsigned int size = 0; + + if (!tcm_dev || IS_NOT_APP_FW_MODE(tcm_dev->dev_mode)) + return _EINVAL; + + retval = tcm_dev->write_message(tcm_dev, + CMD_GET_TOUCH_REPORT_CONFIG, + NULL, + 0, + &resp_code, + tcm_dev->msg_data.default_resp_reading); + if (retval < 0) + goto exit; + + syna_tcm_buf_lock(&tcm_dev->resp_buf); + + size = tcm_dev->resp_buf.data_length; + retval = syna_tcm_buf_alloc(&tcm_dev->touch_config, + size); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + goto exit; + } + + syna_tcm_buf_lock(&tcm_dev->touch_config); + + retval = syna_pal_mem_cpy(tcm_dev->touch_config.buf, + tcm_dev->touch_config.buf_size, + tcm_dev->resp_buf.buf, + tcm_dev->resp_buf.buf_size, + size); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_dev->touch_config); + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + goto exit; + } + + tcm_dev->touch_config.data_length = size; + + syna_tcm_buf_unlock(&tcm_dev->touch_config); + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + +exit: + return retval; +} + +int syna_tcm_get_app_info(struct tcm_dev *tcm_dev, + struct tcm_application_info *app_info) +{ + int retval = 0; + unsigned char resp_code; + unsigned int app_status; + unsigned int resp_data_len = 0; + unsigned int copy_size; + struct tcm_application_info *info; + + if (!tcm_dev) + return _EINVAL; + + if (IS_NOT_APP_FW_MODE(tcm_dev->dev_mode)) + return _EINVAL; + + retval = tcm_dev->write_message(tcm_dev, + CMD_GET_APPLICATION_INFO, + NULL, + 0, + &resp_code, + tcm_dev->msg_data.default_resp_reading); + if (retval < 0) + goto exit; + + resp_data_len = tcm_dev->resp_buf.data_length; + copy_size = MIN(sizeof(tcm_dev->app_info), resp_data_len); + + info = &tcm_dev->app_info; + + retval = syna_pal_mem_cpy((unsigned char *)info, + sizeof(struct tcm_application_info), + tcm_dev->resp_buf.buf, + tcm_dev->resp_buf.buf_size, + copy_size); + if (retval < 0) + goto exit; + + if (app_info == NULL) + goto show_info; + + retval = syna_pal_mem_cpy((unsigned char *)app_info, + sizeof(struct tcm_application_info), + tcm_dev->resp_buf.buf, + tcm_dev->resp_buf.buf_size, + copy_size); + if (retval < 0) + goto exit; + +show_info: + app_status = syna_pal_le2_to_uint(tcm_dev->app_info.status); + + if (app_status == APP_STATUS_BAD_APP_CONFIG) { + retval = _ENODEV; + goto exit; + } else if (app_status != APP_STATUS_OK) { + retval = _ENODEV; + goto exit; + } + + tcm_dev->max_objects = syna_pal_le2_to_uint(info->max_objects); + if (tcm_dev->max_objects > MAX_NUM_OBJECTS) { + pr_warn("syna_tcm2: clamping max_objects %u to %u\n", + tcm_dev->max_objects, MAX_NUM_OBJECTS); + tcm_dev->max_objects = MAX_NUM_OBJECTS; + } + tcm_dev->max_x = syna_pal_le2_to_uint(info->max_x); + tcm_dev->max_y = syna_pal_le2_to_uint(info->max_y); + + tcm_dev->cols = syna_pal_le2_to_uint(info->num_of_image_cols); + tcm_dev->rows = syna_pal_le2_to_uint(info->num_of_image_rows); + syna_pal_mem_cpy((unsigned char *)tcm_dev->config_id, + MAX_SIZE_CONFIG_ID, + info->customer_config_id, + MAX_SIZE_CONFIG_ID, + MAX_SIZE_CONFIG_ID); + +exit: + return retval; +} + +static int syna_dev_set_up_app_fw(struct syna_tcm *tcm) +{ + int retval = 0; + struct tcm_dev *tcm_dev = tcm->tcm_dev; + + if (IS_NOT_APP_FW_MODE(tcm_dev->dev_mode)) + return -EINVAL; + + retval = syna_tcm_get_app_info(tcm_dev, &tcm_dev->app_info); + if (retval < 0) + return -EIO; + if (tcm->dts_max_x && tcm->dts_max_y) { + if (!tcm_dev->max_x || !tcm_dev->max_y) + return -EINVAL; + tcm->firmware_max_x = tcm_dev->max_x; + tcm->firmware_max_y = tcm_dev->max_y; + tcm_dev->max_x = tcm->dts_max_x; + tcm_dev->max_y = tcm->dts_max_y; + } + retval = syna_tcm_preserve_touch_report_config(tcm_dev); + if (retval < 0) + return -EIO; + + return retval; +} + +int syna_tcm_sleep(struct tcm_dev *tcm_dev, bool en) +{ + int retval = 0; + unsigned char resp_code; + unsigned char command; + + if (!tcm_dev) + return _EINVAL; + + command = (en) ? CMD_ENTER_DEEP_SLEEP : CMD_EXIT_DEEP_SLEEP; + + retval = tcm_dev->write_message(tcm_dev, + command, + NULL, + 0, + &resp_code, + tcm_dev->msg_data.default_resp_reading); + if (retval < 0) + goto exit; + + tcm_dev->is_sleep = en; + retval = 0; +exit: + return retval; +} + +static int syna_dev_enter_normal_sensing(struct syna_tcm *tcm) +{ + int retval = 0; + + if (!tcm) + return -EINVAL; + + retval = syna_tcm_sleep(tcm->tcm_dev, false); + if (retval < 0) + return retval; + + return 0; +} + +static int syna_dev_resume(struct device *dev) +{ + struct syna_tcm *tcm = dev_get_drvdata(dev); + queue_work(tcm->speedup_resume_wq, &tcm->speed_up_work); + return 0; +} + +static void syna_speedup_resume(struct work_struct *work) +{ + struct syna_tcm *tcm = container_of(work, struct syna_tcm, + speed_up_work); + int retval; + struct syna_hw_interface *hw_if = tcm->hw_if; + bool irq_enabled = true; + + if (tcm->pwr_state == PWR_ON) { + tcm->sub_pwr_state = SUB_PWR_RESUME_DONE; + return; + } + mutex_lock(&tcm->mutex); + + if (IS_REMOVE == tcm->driver_current_state) { + mutex_unlock(&tcm->mutex); + return; + }; + + tcm->sub_pwr_state = SUB_PWR_RESUMING; + + irq_enabled = (!hw_if->bdata_attn.irq_enabled); + + if (irq_enabled && (hw_if->ops_enable_irq)) + hw_if->ops_enable_irq(hw_if, true); + + retval = syna_dev_enter_normal_sensing(tcm); + if (retval < 0) + goto exit; + + tcm->pwr_state = PWR_ON; + + retval = syna_dev_set_up_app_fw(tcm); + if (retval < 0) + goto exit; + + retval = 0; + +exit: + tcm->sub_pwr_state = SUB_PWR_RESUME_DONE; + tcm->slept_in_early_suspend = false; + + mutex_unlock(&tcm->mutex); +} + +static int syna_dev_suspend(struct device *dev) +{ + struct syna_tcm *tcm = dev_get_drvdata(dev); + struct syna_hw_interface *hw_if = tcm->hw_if; + struct touchpanel_event event_data; + bool irq_disabled = true; + + if (tcm->pwr_state != PWR_ON) + return 0; + mutex_lock(&tcm->mutex); + + if (IS_REMOVE == tcm->driver_current_state) { + mutex_unlock(&tcm->mutex); + return -EINVAL; + }; + + tcm->sub_pwr_state = SUB_PWR_SUSPENDING; + syna_dev_free_input_events(tcm); + tcm->pwr_state = PWR_OFF; + memset(&event_data, 0, sizeof(struct touchpanel_event)); + irq_disabled = (!tcm->lpwg_enabled); + + if (irq_disabled && (hw_if->ops_enable_irq)) + hw_if->ops_enable_irq(hw_if, false); + + tcm->sub_pwr_state = SUB_PWR_SUSPEND_DONE; + mutex_unlock(&tcm->mutex); + + return 0; +} + +static int syna_dev_disconnect(struct syna_tcm *tcm) +{ + struct syna_hw_interface *hw_if = tcm->hw_if; + int ret = 0; + + if (tcm->is_connected == false) + return 0; + + if (hw_if->bdata_attn.irq_id) + syna_dev_release_irq(tcm); + + if (hw_if->bdata_rst.reset_gpio >= 0) { + ret = gpio_direction_output(hw_if->bdata_rst.reset_gpio, 0); + if (ret) + return -EINVAL; + } + + syna_dev_release_input_device(tcm); + + tcm->input_dev_params.max_x = 0; + tcm->input_dev_params.max_y = 0; + tcm->input_dev_params.max_objects = 0; + + if (hw_if->ops_power_on) + hw_if->ops_power_on(hw_if, false); + + tcm->pwr_state = PWR_OFF; + tcm->is_connected = false; + + return 0; +} + +static int syna_tcm_v1_read(struct tcm_dev *tcm_dev, unsigned int rd_length, + unsigned char *buf, unsigned int buf_size, bool extra_crc) +{ + int retval; + unsigned int max_rd_size; + int retry; + + if (!tcm_dev || IS_ERR_OR_NULL(buf) || rd_length > buf_size) + return _EINVAL; + + if (rd_length == 0) + return 0; + + max_rd_size = tcm_dev->max_rd_size; + + if (max_rd_size != 0 && rd_length > max_rd_size) { + return _EINVAL; + } + + for (retry = 0; retry < 10; retry++) { + retval = syna_tcm_read(tcm_dev, + buf, + rd_length); + if (retval < 0) + goto exit; + + if (buf[0] == TCM_V1_MESSAGE_MARKER) + break; + + retval = _EIO; + usleep_range(RD_RETRY_US_MIN, RD_RETRY_US_MAX); + } + +exit: + return retval; +} + +static int syna_tcm_v1_continued_read(struct tcm_dev *tcm_dev, + unsigned int length) +{ + int retval = 0; + unsigned char code; + unsigned int idx; + unsigned int offset; + unsigned int chunks; + unsigned int chunk_space; + unsigned int xfer_length; + unsigned int total_length; + unsigned int remaining_length; + struct tcm_message_data_blob *tcm_msg = NULL; + bool last = false; + + if (!tcm_dev) + return _EINVAL; + + tcm_msg = &tcm_dev->msg_data; + + if (length == 0 || tcm_msg->payload_length == 0) + return 0; + + if ((length & 0xffff) == 0xffff) + return _EINVAL; + + total_length = MESSAGE_HEADER_SIZE + tcm_msg->payload_length + 1; + remaining_length = length + 1; + + if (tcm_msg->has_crc) { + total_length += TCM_MSG_CRC_LENGTH; + remaining_length += TCM_MSG_CRC_LENGTH; + } + if (tcm_msg->has_extra_rc) { + total_length += TCM_EXTRA_RC_LENGTH; + remaining_length += TCM_EXTRA_RC_LENGTH; + } + if (tcm_msg->has_crc || tcm_msg->has_extra_rc) { + total_length += 1; + remaining_length += 1; + } + + syna_tcm_buf_lock(&tcm_msg->in); + + retval = syna_tcm_buf_realloc(&tcm_msg->in, total_length + 1); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + return retval; + } + + if (tcm_dev->max_rd_size == 0) + chunk_space = remaining_length; + else + chunk_space = tcm_dev->max_rd_size - 2; + + chunks = syna_pal_ceil_div(remaining_length, chunk_space); + chunks = chunks == 0 ? 1 : chunks; + + offset = MESSAGE_HEADER_SIZE + (tcm_msg->payload_length - length); + + syna_tcm_buf_lock(&tcm_msg->temp); + + for (idx = 0; idx < chunks; idx++) { + if (remaining_length > chunk_space) + xfer_length = chunk_space; + else + xfer_length = remaining_length; + + last = ((idx + 1) == chunks); + + if (xfer_length == 1) { + tcm_msg->in.buf[offset] = TCM_V1_MESSAGE_PADDING; + offset += xfer_length; + remaining_length -= xfer_length; + continue; + } + + retval = syna_tcm_buf_alloc(&tcm_msg->temp, xfer_length + 2); + if (retval < 0) + goto exit; + + retval = syna_tcm_v1_read(tcm_dev, + xfer_length + 2, + tcm_msg->temp.buf, + tcm_msg->temp.buf_size, + (tcm_msg->has_crc) && last); + if (retval < 0) + goto exit; + + tcm_msg->temp.data_length = xfer_length + 2; + + code = tcm_msg->temp.buf[1]; + + if (code != STATUS_CONTINUED_READ) { + retval = _EIO; + goto exit; + } + + retval = syna_pal_mem_cpy(&tcm_msg->in.buf[offset], + tcm_msg->in.buf_size - offset, + &tcm_msg->temp.buf[2], + tcm_msg->temp.buf_size - 2, + xfer_length); + if (retval < 0) + goto exit; + + offset += xfer_length; + remaining_length -= xfer_length; + } + +exit: + syna_tcm_buf_unlock(&tcm_msg->temp); + syna_tcm_buf_unlock(&tcm_msg->in); + + return retval; +} + +static int syna_tcm_v1_parse_idinfo(struct tcm_dev *tcm_dev, + unsigned char *data, unsigned int size, unsigned int data_len) +{ + int retval; + unsigned int build_id = 0; + struct tcm_identification_info *id_info; + + if (!tcm_dev || !data || data_len == 0) + return _EINVAL; + + id_info = &tcm_dev->id_info; + + retval = syna_pal_mem_cpy((unsigned char *)id_info, + sizeof(struct tcm_identification_info), + data, + size, + MIN(sizeof(*id_info), data_len)); + if (retval < 0) + return retval; + + build_id = syna_pal_le4_to_uint(id_info->build_id); + + if (tcm_dev->packrat_number != build_id) + tcm_dev->packrat_number = build_id; + + tcm_dev->dev_mode = id_info->mode; + + return 0; +} + +static void syna_tcm_v1_dispatch_response(struct tcm_dev *tcm_dev) +{ + int retval; + struct tcm_message_data_blob *tcm_msg = NULL; + struct completion *cmd_completion = NULL; + + if (!tcm_dev) + return; + + tcm_msg = &tcm_dev->msg_data; + cmd_completion = &tcm_msg->cmd_completion; + + tcm_msg->response_code = tcm_msg->status_report_code; + + if (ATOMIC_GET(tcm_msg->command_status) != CMD_STATE_BUSY) + return; + + if (tcm_msg->payload_length == 0) { + tcm_dev->resp_buf.data_length = tcm_msg->payload_length; + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_IDLE); + goto exit; + } + + syna_tcm_buf_lock(&tcm_dev->resp_buf); + + retval = syna_tcm_buf_alloc(&tcm_dev->resp_buf, tcm_msg->payload_length); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + goto exit; + } + + syna_tcm_buf_lock(&tcm_msg->in); + + retval = syna_pal_mem_cpy(tcm_dev->resp_buf.buf, + tcm_dev->resp_buf.buf_size, + &tcm_msg->in.buf[MESSAGE_HEADER_SIZE], + tcm_msg->in.buf_size - MESSAGE_HEADER_SIZE, + tcm_msg->payload_length); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + goto exit; + } + + tcm_dev->resp_buf.data_length = tcm_msg->payload_length; + + syna_tcm_buf_unlock(&tcm_msg->in); + syna_tcm_buf_unlock(&tcm_dev->resp_buf); + + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_IDLE); + +exit: + syna_pal_completion_complete(cmd_completion); +} + +static void syna_tcm_v1_dispatch_report(struct tcm_dev *tcm_dev) +{ + int retval; + struct tcm_message_data_blob *tcm_msg = NULL; + struct completion *cmd_completion = NULL; + + if (!tcm_dev) + return; + + tcm_msg = &tcm_dev->msg_data; + cmd_completion = &tcm_msg->cmd_completion; + + tcm_msg->report_code = tcm_msg->status_report_code; + + if (tcm_msg->payload_length == 0) { + tcm_dev->report_buf.data_length = 0; + goto exit; + } + + syna_tcm_buf_lock(&tcm_dev->report_buf); + + retval = syna_tcm_buf_alloc(&tcm_dev->report_buf, + tcm_msg->payload_length); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_dev->report_buf); + goto exit; + } + + syna_tcm_buf_lock(&tcm_msg->in); + + retval = syna_pal_mem_cpy(tcm_dev->report_buf.buf, + tcm_dev->report_buf.buf_size, + &tcm_msg->in.buf[MESSAGE_HEADER_SIZE], + tcm_msg->in.buf_size - MESSAGE_HEADER_SIZE, + tcm_msg->payload_length); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + syna_tcm_buf_unlock(&tcm_dev->report_buf); + goto exit; + } + + tcm_dev->report_buf.data_length = tcm_msg->payload_length; + + syna_tcm_buf_unlock(&tcm_msg->in); + syna_tcm_buf_unlock(&tcm_dev->report_buf); + + if (tcm_msg->report_code == REPORT_IDENTIFY) { + tcm_dev->is_sleep = false; + syna_tcm_buf_lock(&tcm_msg->in); + + retval = syna_tcm_v1_parse_idinfo(tcm_dev, + &tcm_msg->in.buf[MESSAGE_HEADER_SIZE], + tcm_msg->in.buf_size - MESSAGE_HEADER_SIZE, + tcm_msg->payload_length); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + return; + } + + syna_tcm_buf_unlock(&tcm_msg->in); + + if (tcm_dev->dev_mode == 0x0b) { + tcm_dev->firmware_mode_count++; + if (!tcm_dev->upload_flag && tcm_dev->firmware_mode_count >= FIRMWARE_MODE_BL_MAX) { + tcm_dev->upload_flag = 1; + } + } + if (ATOMIC_GET(tcm_msg->command_status) == CMD_STATE_BUSY) { + switch (tcm_msg->command) { + case CMD_RESET: + tcm_msg->response_code = STATUS_OK; + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_IDLE); + syna_pal_completion_complete(cmd_completion); + goto exit; + case CMD_REBOOT_TO_ROM_BOOTLOADER: + case CMD_RUN_BOOTLOADER_FIRMWARE: + case CMD_RUN_APPLICATION_FIRMWARE: + case CMD_ENTER_PRODUCTION_TEST_MODE: + case CMD_ROMBOOT_RUN_BOOTLOADER_FIRMWARE: + tcm_msg->response_code = STATUS_OK; + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_IDLE); + syna_pal_completion_complete(cmd_completion); + goto exit; + default: + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_ERROR); + syna_pal_completion_complete(cmd_completion); + goto exit; + } + } + } + +exit: + return; +} + +static void syna_tcm_v1_update_crc(struct tcm_dev *tcm_dev) +{ + struct tcm_message_data_blob *tcm_msg = NULL; + int offset; + + if (!tcm_dev) + return; + + tcm_msg = &tcm_dev->msg_data; + + if (!tcm_msg->has_crc || tcm_msg->payload_length == 0) + return; + + syna_tcm_buf_lock(&tcm_msg->in); + + offset = MESSAGE_HEADER_SIZE + tcm_msg->payload_length; + /* Need buf[offset+1] and buf[offset+2] for the CRC word. */ + if (tcm_msg->in.buf_size <= offset + 2) + goto unlock; + + if (tcm_msg->has_crc) { + tcm_msg->crc_bytes = (unsigned short)syna_pal_le2_to_uint(&tcm_msg->in.buf[offset + 1]); + + if (tcm_msg->has_extra_rc) { + offset += TCM_MSG_CRC_LENGTH; + if (tcm_msg->in.buf_size > offset + 1) + tcm_msg->rc_byte = tcm_msg->in.buf[offset + 1]; + } + } + +unlock: + syna_tcm_buf_unlock(&tcm_msg->in); +} + +static int syna_tcm_v1_read_message(struct tcm_dev *tcm_dev, + unsigned char *status_report_code) +{ + int retval = 0; + struct tcm_v1_message_header *header; + struct tcm_message_data_blob *tcm_msg = NULL; + struct mutex *rw_mutex = NULL; + struct completion *cmd_completion = NULL; + unsigned int len = 0; + bool do_predict = false; + unsigned int tmp_len; + + if (!tcm_dev) + return _EINVAL; + + tcm_msg = &tcm_dev->msg_data; + rw_mutex = &tcm_msg->rw_mutex; + cmd_completion = &tcm_msg->cmd_completion; + + do_predict = (ATOMIC_GET(tcm_msg->command_status) == CMD_STATE_IDLE); + + if (status_report_code) + *status_report_code = STATUS_INVALID; + + syna_pal_mutex_lock(rw_mutex); + + syna_tcm_buf_lock(&tcm_msg->in); + + len = MESSAGE_HEADER_SIZE; + + if (tcm_msg->predict_reads && do_predict) { + if (tcm_msg->predict_length > 0) { + len += tcm_msg->predict_length; + if (tcm_msg->has_crc) + len += TCM_MSG_CRC_LENGTH; + if (tcm_msg->has_extra_rc) + len += TCM_EXTRA_RC_LENGTH; + len += 1; + } + } + + if (len > tcm_msg->in.buf_size) { + retval = syna_tcm_buf_alloc(&tcm_msg->in, len); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + + tcm_msg->status_report_code = STATUS_INVALID; + tcm_msg->payload_length = 0; + goto exit; + } + } + + retval = syna_tcm_v1_read(tcm_dev, + len, + tcm_msg->in.buf, + tcm_msg->in.buf_size, + false); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + + tcm_msg->status_report_code = STATUS_INVALID; + tcm_msg->payload_length = 0; + goto exit; + } + + header = (struct tcm_v1_message_header *)tcm_msg->in.buf; + + tcm_msg->status_report_code = header->code; + + tcm_msg->payload_length = syna_pal_le2_to_uint(header->length); + + syna_tcm_buf_unlock(&tcm_msg->in); + + if (tcm_msg->payload_length == 0) + goto do_dispatch; + + tmp_len = len - MESSAGE_HEADER_SIZE; + if (len > MESSAGE_HEADER_SIZE) + len = (tcm_msg->payload_length > tmp_len) ? + (tcm_msg->payload_length - tmp_len) : 0; + else + len = tcm_msg->payload_length; + + retval = syna_tcm_v1_continued_read(tcm_dev, len); + if (retval < 0) + goto exit; + +do_dispatch: + syna_tcm_buf_lock(&tcm_msg->in); + + tcm_msg->in.buf[0] = TCM_V1_MESSAGE_MARKER; + tcm_msg->in.buf[1] = tcm_msg->status_report_code; + tcm_msg->in.buf[2] = (unsigned char)tcm_msg->payload_length; + tcm_msg->in.buf[3] = (unsigned char)(tcm_msg->payload_length >> 8); + + syna_tcm_buf_unlock(&tcm_msg->in); + + syna_tcm_v1_update_crc(tcm_dev); + + syna_tcm_buf_lock(&tcm_dev->external_buf); + if (tcm_msg->payload_length > 0) { + retval = syna_tcm_buf_alloc(&tcm_dev->external_buf, + tcm_msg->payload_length); + if (retval >= 0) { + retval = syna_pal_mem_cpy(&tcm_dev->external_buf.buf[0], + tcm_msg->payload_length, + &tcm_msg->in.buf[MESSAGE_HEADER_SIZE], + tcm_msg->in.buf_size - MESSAGE_HEADER_SIZE, + tcm_msg->payload_length); + } + } + tcm_dev->external_buf.data_length = tcm_msg->payload_length; + syna_tcm_buf_unlock(&tcm_dev->external_buf); + + if (tcm_msg->status_report_code <= STATUS_ERROR || + tcm_msg->status_report_code == STATUS_INVALID) { + switch (tcm_msg->status_report_code) { + case STATUS_CONTINUED_READ: + retval = _EIO; + goto exit; + case STATUS_IDLE: + retval = 0; + goto exit; + default: + break; + } + } + + if (tcm_msg->status_report_code >= REPORT_IDENTIFY) + syna_tcm_v1_dispatch_report(tcm_dev); + else + syna_tcm_v1_dispatch_response(tcm_dev); + + if (status_report_code) + *status_report_code = tcm_msg->status_report_code; + + if (tcm_msg->predict_reads && do_predict) { + if (tcm_dev->max_rd_size < MESSAGE_HEADER_SIZE) + tcm_msg->predict_length = tcm_msg->payload_length; + else + tcm_msg->predict_length = MIN(tcm_msg->payload_length, + tcm_dev->max_rd_size - MESSAGE_HEADER_SIZE - 1); + + if (tcm_msg->status_report_code < REPORT_IDENTIFY) + tcm_msg->predict_length = 0; + } + + retval = 0; + +exit: + if (retval < 0) { + if (ATOMIC_GET(tcm_msg->command_status) == CMD_STATE_BUSY) { + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_ERROR); + complete(cmd_completion); + } + } + + syna_pal_mutex_unlock(rw_mutex); + + return retval; +} + +static int syna_tcm_v1_write(struct tcm_dev *tcm_dev, unsigned char command, + unsigned char *payload, unsigned int payload_len, + bool extra_crc, unsigned short crc) +{ + int retval = 0; + struct tcm_message_data_blob *tcm_msg = NULL; + int size, buf_size; + unsigned char crc16[TCM_MSG_CRC_LENGTH] = { 0 }; + + if (!tcm_dev) + return _EINVAL; + + tcm_msg = &tcm_dev->msg_data; + + syna_tcm_buf_lock(&tcm_msg->out); + + buf_size = payload_len + 3; + if (extra_crc) { + crc16[0] = (unsigned char) crc & 0xff; + crc16[1] = (unsigned char) (crc >> 8); + + buf_size += sizeof(crc16); + } + + retval = syna_tcm_buf_alloc(&tcm_msg->out, buf_size); + if (retval < 0) + goto exit; + + if (command != CMD_CONTINUE_WRITE) { + size = payload_len + 3; + + tcm_msg->out.buf[0] = command; + tcm_msg->out.buf[1] = (unsigned char)payload_len; + tcm_msg->out.buf[2] = (unsigned char)(payload_len >> 8); + + if (payload_len > 0) { + retval = syna_pal_mem_cpy(&tcm_msg->out.buf[3], + tcm_msg->out.buf_size - 3, + payload, + payload_len, + payload_len); + if (retval < 0) + goto exit; + } + } else { + size = payload_len + 1; + + tcm_msg->out.buf[0] = CMD_CONTINUE_WRITE; + + retval = syna_pal_mem_cpy(&tcm_msg->out.buf[1], + tcm_msg->out.buf_size - 1, + payload, + payload_len, + payload_len); + if (retval < 0) + goto exit; + } + + if (extra_crc) { + retval = syna_pal_mem_cpy(&tcm_msg->out.buf[size], + tcm_msg->out.buf_size - size, + crc16, + sizeof(crc16), + sizeof(crc16) + ); + if (retval < 0) + goto exit; + + size += sizeof(crc16); + } + + retval = syna_tcm_write(tcm_dev, + tcm_msg->out.buf, + size + ); + if (retval < 0) + goto exit; + +exit: + syna_tcm_buf_unlock(&tcm_msg->out); + + return retval; +} + +static int syna_tcm_v1_write_message(struct tcm_dev *tcm_dev, + unsigned char command, unsigned char *payload, + unsigned int payload_len, unsigned char *resp_code, + unsigned int delay_ms_resp) +{ + int retval = 0; + unsigned int idx; + unsigned int chunks = 0; + unsigned int chunk_space; + unsigned int xfer_length; + unsigned int remaining_length; + int timeout = 0; + int polling_ms = 0; + struct tcm_message_data_blob *tcm_msg = NULL; + struct mutex *cmd_mutex = NULL; + struct mutex *rw_mutex = NULL; + struct completion *cmd_completion = NULL; + bool has_irq_ctrl = false; + bool in_polling = false; + bool last = false; + unsigned char tmp; + unsigned short crc16 = 0xFFFF; + + if (!tcm_dev) + return _EINVAL; + + tcm_msg = &tcm_dev->msg_data; + cmd_mutex = &tcm_msg->cmd_mutex; + rw_mutex = &tcm_msg->rw_mutex; + cmd_completion = &tcm_msg->cmd_completion; + + if (resp_code) + *resp_code = STATUS_INVALID; + + in_polling = (delay_ms_resp != RESP_IN_ATTN); + + has_irq_ctrl = (bool)(tcm_dev->hw_if->ops_enable_irq != NULL); + has_irq_ctrl &= tcm_dev->hw_if->bdata_attn.irq_enabled; + + if (has_irq_ctrl && in_polling && tcm_dev->hw_if->ops_enable_irq) + tcm_dev->hw_if->ops_enable_irq(tcm_dev->hw_if, false); + + syna_pal_mutex_lock(cmd_mutex); + + syna_pal_mutex_lock(rw_mutex); + + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_BUSY); + + reinit_completion(cmd_completion); + + tcm_msg->command = command; + + remaining_length = payload_len; + + if (tcm_msg->has_crc) { + crc16 = syna_tcm_crc16(&command, 1, crc16); + tmp = (unsigned char)payload_len & 0xff; + crc16 = syna_tcm_crc16(&tmp, 1, crc16); + tmp = (unsigned char)(payload_len >> 8) & 0xff; + crc16 = syna_tcm_crc16(&tmp, 1, crc16); + if (payload_len > 0) + crc16 = syna_tcm_crc16(payload, payload_len, crc16); + } + + if (tcm_dev->max_wr_size == 0) + chunk_space = remaining_length; + else + chunk_space = tcm_dev->max_wr_size - 1; + + if (chunk_space) + chunks = syna_pal_ceil_div(remaining_length, chunk_space); + + chunks = chunks == 0 ? 1 : chunks; + + for (idx = 0; idx < chunks; idx++) { + if (remaining_length > chunk_space) + xfer_length = chunk_space; + else + xfer_length = remaining_length; + + last = ((idx + 1) == chunks); + + if (idx == 0) { + retval = syna_tcm_v1_write(tcm_dev, + tcm_msg->command, + &payload[0], + xfer_length, + (tcm_msg->has_crc) && last, + crc16); + } else { + retval = syna_tcm_v1_write(tcm_dev, + CMD_CONTINUE_WRITE, + &payload[idx * chunk_space], + xfer_length, + (tcm_msg->has_crc) && last, + crc16); + } + + if (retval < 0) { + syna_pal_mutex_unlock(rw_mutex); + goto exit; + } + + remaining_length -= xfer_length; + + if (chunks > 1) + usleep_range(WR_DELAY_US_MIN, WR_DELAY_US_MAX); + } + + syna_pal_mutex_unlock(rw_mutex); + + timeout = 0; + if (!in_polling) + polling_ms = CMD_RESPONSE_TIMEOUT_MS; + else + polling_ms = delay_ms_resp; + + do { + retval = syna_pal_completion_wait_for(cmd_completion, + polling_ms); + + if (ATOMIC_GET(tcm_msg->command_status) == CMD_STATE_IDLE) + goto check_response; + if (in_polling) { + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_BUSY); + + retval = syna_tcm_v1_read_message(tcm_dev, NULL); + if (retval < 0) + reinit_completion(cmd_completion); + } + + timeout += polling_ms; + + } while (timeout < CMD_RESPONSE_TIMEOUT_MS); + +check_response: + if (ATOMIC_GET(tcm_msg->command_status) != CMD_STATE_IDLE) { + if (timeout >= CMD_RESPONSE_TIMEOUT_MS) { + retval = _ETIMEDOUT; + goto exit; + } else { + retval = _EIO; + goto exit; + } + } + + if (resp_code) + *resp_code = tcm_msg->status_report_code; + + if (tcm_msg->response_code != STATUS_OK) { + retval = _EIO; + } else { + retval = 0; + } + +exit: + tcm_msg->command = CMD_NONE; + + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_IDLE); + + syna_pal_mutex_unlock(cmd_mutex); + + if (has_irq_ctrl && in_polling && tcm_dev->hw_if->ops_enable_irq) { + msleep(POLLING_ENABLE_IRQ_DELAY_MS); + tcm_dev->hw_if->ops_enable_irq(tcm_dev->hw_if, true); + } + + return retval; +} + +static void syna_tcm_v1_set_ops(struct tcm_dev *tcm_dev) +{ + if (!tcm_dev) + return; + + tcm_dev->read_message = syna_tcm_v1_read_message; + tcm_dev->write_message = syna_tcm_v1_write_message; + + tcm_dev->msg_data.predict_length = 0; + + tcm_dev->protocol = TOUCHCOMM_V1; +} + +static int syna_tcm_v1_set_max_rw_size(struct tcm_dev *tcm_dev) +{ + unsigned int wr_size = 0; + struct tcm_identification_info *id_info; + + if (!tcm_dev) { + return _EINVAL; + } + + id_info = &tcm_dev->id_info; + + wr_size = syna_pal_le2_to_uint(id_info->max_write_size); + + if (wr_size == 0) { + return 0; + } + + if (wr_size != tcm_dev->max_wr_size) { + if (tcm_dev->max_wr_size == 0) + tcm_dev->max_wr_size = wr_size; + else + tcm_dev->max_wr_size = MIN(wr_size, tcm_dev->max_wr_size); + } + + return 0; +} + +static int syna_tcm_v1_detect(struct tcm_dev *tcm_dev, unsigned char *data, + unsigned int size) +{ + int retval; + struct tcm_v1_message_header *header; + struct tcm_message_data_blob *tcm_msg = NULL; + unsigned int payload_length = 0; + unsigned char resp_code = 0; + unsigned short default_crc = 0x5a5a; + unsigned short default_rc = 0x5a; + + if (!tcm_dev || !data || size != MESSAGE_HEADER_SIZE) + return _EINVAL; + + tcm_msg = &tcm_dev->msg_data; + + header = (struct tcm_v1_message_header *)data; + + if (header->marker != TCM_V1_MESSAGE_MARKER) + return _ENODEV; + + tcm_msg->has_crc = true; + tcm_dev->msg_data.crc_bytes = default_crc; + tcm_msg->has_extra_rc = true; + tcm_dev->msg_data.rc_byte = default_rc; + + if (header->code == REPORT_IDENTIFY) { + payload_length = syna_pal_le2_to_uint(header->length); + tcm_msg->payload_length = payload_length; + + retval = syna_tcm_v1_continued_read(tcm_dev, + payload_length); + if (retval < 0) + return retval; + } else { + retval = syna_tcm_v1_write_message(tcm_dev, + CMD_IDENTIFY, + NULL, + 0, + &resp_code, + RESP_IN_POLLING); + if (retval < 0) { + retval = syna_tcm_v1_write_message(tcm_dev, + CMD_RESET, + NULL, + 0, + &resp_code, + RESET_DELAY_MS); + if (retval < 0) + return retval; + } + + payload_length = tcm_msg->payload_length; + } + + + if (tcm_dev->dev_mode == MODE_UNKNOWN) { + syna_tcm_buf_lock(&tcm_msg->in); + + retval = syna_tcm_v1_parse_idinfo(tcm_dev, + &tcm_msg->in.buf[MESSAGE_HEADER_SIZE], + tcm_msg->in.buf_size - MESSAGE_HEADER_SIZE, + payload_length); + if (retval < 0) { + syna_tcm_buf_unlock(&tcm_msg->in); + return retval; + } + + syna_tcm_buf_unlock(&tcm_msg->in); + } + + retval = syna_tcm_v1_set_max_rw_size(tcm_dev); + if (retval < 0) + return retval; + + syna_tcm_v1_update_crc(tcm_dev); + if (tcm_dev->msg_data.crc_bytes == default_crc) + tcm_msg->has_crc = false; + if (tcm_dev->msg_data.rc_byte == default_rc) + tcm_msg->has_extra_rc = false; + + syna_tcm_v1_set_ops(tcm_dev); + + return retval; +} + +static int syna_tcm_detect_protocol(struct tcm_dev *tcm_dev, + unsigned char *data, unsigned int data_len) +{ + int retval; + + if (!tcm_dev) + return _EINVAL; + + retval = syna_tcm_v1_detect(tcm_dev, data, data_len); + + return retval; +} + +int syna_tcm_detect_device(struct tcm_dev *tcm_dev) +{ + int retval = 0; + unsigned char data[4] = { 0 }; + + if (!tcm_dev) + return _EINVAL; + + tcm_dev->dev_mode = MODE_UNKNOWN; + + data[0] = 0x07; + retval = syna_tcm_write(tcm_dev, &data[0], 1); + if (retval < 0) + return _EIO; + + retval = syna_tcm_read(tcm_dev, + data, (unsigned int)sizeof(data)); + if (retval < 0) + return _EIO; + + retval = syna_tcm_detect_protocol(tcm_dev, + data, (unsigned int)sizeof(data)); + if (retval < 0) + return retval; + + if (!tcm_dev->write_message || !tcm_dev->read_message) + return _ENODEV; + + retval = tcm_dev->dev_mode; + return retval; +} + +static int syna_dev_connect(struct syna_tcm *tcm) +{ + int retval; + struct syna_hw_interface *hw_if = tcm->hw_if; + struct syna_hw_bus_data *bus = &hw_if->bdata_io; + struct tcm_dev *tcm_dev = tcm->tcm_dev; + + if (!tcm_dev) + return -EINVAL; + + if (tcm->is_connected) + return 0; + + if (hw_if->ops_power_on) { + retval = hw_if->ops_power_on(hw_if, true); + if (retval < 0) + return -ENODEV; + } + + if (hw_if->ops_hw_reset) + hw_if->ops_hw_reset(hw_if); + + retval = syna_tcm_detect_device(tcm->tcm_dev); + if (retval < 0) + goto err_detect_dev; + + switch (retval) { + case MODE_APPLICATION_FIRMWARE: + retval = syna_dev_set_up_app_fw(tcm); + if (retval >= 0) { + retval = syna_dev_set_up_input_device(tcm); + if (retval < 0) + goto err_setup_input_dev; + } + + break; + default: + break; + } + + retval = syna_dev_request_irq(tcm); + if (retval < 0) + goto err_request_irq; + + tcm->pwr_state = PWR_ON; + tcm->is_connected = true; + tcm->bus_ready = true; + + if (tcm->tcm_dev->max_wr_size != bus->wr_chunk_size) + bus->wr_chunk_size = tcm->tcm_dev->max_wr_size; + if (tcm->tcm_dev->max_rd_size != bus->rd_chunk_size) + bus->rd_chunk_size = tcm->tcm_dev->max_rd_size; + + return 0; + +err_request_irq: + syna_dev_release_input_device(tcm); + +err_setup_input_dev: +err_detect_dev: + if (hw_if->ops_power_on) + hw_if->ops_power_on(hw_if, false); + + return retval; +} + +static int init_chip_dts(struct device *dev, void *chip_data) +{ + int rc = 0; + struct device_node *np; + struct syna_tcm *tcm = (struct syna_tcm *)chip_data; + int tx_rx_num[2], panel_coords[2]; + np = dev->of_node; + + rc = of_property_read_u32_array(np, "synaptics,tx-rx-num", tx_rx_num, 2); + + if (rc) { + tcm->tx_num = TX_NUM; + tcm->rx_num = RX_NUM; + + } else { + tcm->tx_num = tx_rx_num[0]; + tcm->rx_num = tx_rx_num[1]; + } + + + rc = of_property_read_u32_array(np, "synaptics,panel-coords", panel_coords, 2); + + if (rc) { + tcm->dts_max_x = 0; + tcm->dts_max_y = 0; + + } else { + tcm->dts_max_x = panel_coords[0]; + tcm->dts_max_y = panel_coords[1]; + } + + return 0; +} + +static int syna_tcm_init_message_wrap(struct tcm_message_data_blob *tcm_msg, + unsigned int resp_reading) +{ + syna_tcm_buf_init(&tcm_msg->in); + syna_tcm_buf_init(&tcm_msg->out); + syna_tcm_buf_init(&tcm_msg->temp); + + init_completion(&tcm_msg->cmd_completion); + mutex_init(&tcm_msg->cmd_mutex); + mutex_init(&tcm_msg->rw_mutex); + + ATOMIC_SET(tcm_msg->command_status, CMD_STATE_IDLE); + tcm_msg->command = CMD_NONE; + tcm_msg->status_report_code = STATUS_IDLE; + tcm_msg->payload_length = 0; + tcm_msg->response_code = 0; + tcm_msg->report_code = 0; + tcm_msg->seq_toggle = 0; + + syna_tcm_buf_lock(&tcm_msg->in); + + if (syna_tcm_buf_alloc(&tcm_msg->in, MESSAGE_HEADER_SIZE) < 0) { + tcm_msg->in.buf_size = 0; + tcm_msg->in.data_length = 0; + syna_tcm_buf_unlock(&tcm_msg->in); + return _EINVAL; + } + tcm_msg->in.buf_size = MESSAGE_HEADER_SIZE; + + syna_tcm_buf_unlock(&tcm_msg->in); + + tcm_msg->default_resp_reading = resp_reading; + + tcm_msg->predict_reads = false; + tcm_msg->predict_length = 0; + tcm_msg->has_crc = false; + tcm_msg->crc_bytes = 0; + tcm_msg->has_extra_rc = false; + tcm_msg->rc_byte = 0; + + return 0; +} + +int syna_tcm_allocate_device(struct tcm_dev **ptcm_dev_ptr, + struct syna_hw_interface *hw_if, unsigned int resp_reading) +{ + int retval = 0; + struct tcm_dev *tcm_dev = NULL; + + if (!hw_if || (!hw_if->ops_read_data || !hw_if->ops_write_data)) + return _EINVAL; + + *ptcm_dev_ptr = NULL; + + tcm_dev = (struct tcm_dev *)syna_pal_mem_alloc( + 1, + sizeof(struct tcm_dev)); + if (!tcm_dev) + return _ENOMEM; + + tcm_dev->hw_if = hw_if; + + tcm_dev->max_rd_size = hw_if->bdata_io.rd_chunk_size; + tcm_dev->max_wr_size = hw_if->bdata_io.wr_chunk_size; + + tcm_dev->write_message = NULL; + tcm_dev->read_message = NULL; + + tcm_dev->dev_mode = MODE_UNKNOWN; + + syna_tcm_buf_init(&tcm_dev->report_buf); + syna_tcm_buf_init(&tcm_dev->resp_buf); + syna_tcm_buf_init(&tcm_dev->external_buf); + syna_tcm_buf_init(&tcm_dev->touch_config); + + retval = syna_tcm_init_message_wrap(&tcm_dev->msg_data, resp_reading); + if (retval < 0) + goto err_init_message_wrap; + + *ptcm_dev_ptr = tcm_dev; + + return 0; + +err_init_message_wrap: + syna_tcm_buf_release(&tcm_dev->touch_config); + syna_tcm_buf_release(&tcm_dev->external_buf); + syna_tcm_buf_release(&tcm_dev->report_buf); + syna_tcm_buf_release(&tcm_dev->resp_buf); + + tcm_dev->hw_if = NULL; + + kfree(tcm_dev); + + return retval; +} + +int syna_tcm_enable_predict_reading(struct tcm_dev *tcm_dev, bool en) +{ + if (!tcm_dev) + return _EINVAL; + + tcm_dev->msg_data.predict_reads = en; + tcm_dev->msg_data.predict_length = 0; + + return 0; +} + +static int syna_dev_probe(struct platform_device *pdev) +{ + int retval; + struct syna_tcm *tcm = NULL; + struct tcm_dev *tcm_dev = NULL; + struct syna_hw_interface *hw_if = NULL; + struct device *syna_spi_pdev; + + hw_if = pdev->dev.platform_data; + if (!hw_if) + return -EINVAL; + + tcm = syna_pal_mem_alloc(1, sizeof(struct syna_tcm)); + if (!tcm) + return -ENOMEM; + + retval = syna_tcm_allocate_device(&tcm_dev, hw_if, RESP_IN_POLLING); + if (retval < 0 || !tcm_dev) + goto err_allocate_cdev; + + tcm->tcm_dev = tcm_dev; + tcm->pdev = pdev; + tcm->hw_if = hw_if; + + syna_spi_pdev = syna_spi_device->dev.parent; + + retval = init_chip_dts(syna_spi_pdev, tcm); + + if (retval < 0) + goto err_manufacture_info; + + syna_tcm_buf_init(&tcm->event_data); + + mutex_init(&tcm->tp_event_mutex); + + mutex_init(&tcm->mutex); + init_completion(&tcm->fw_complete); + + tcm->is_connected = false; + tcm->pwr_state = PWR_OFF; + + tcm->dev_connect = syna_dev_connect; + tcm->dev_disconnect = syna_dev_disconnect; + tcm->dev_set_up_app_fw = syna_dev_set_up_app_fw; + tcm->dev_resume = syna_dev_resume; + tcm->dev_suspend = syna_dev_suspend; + + tcm->wait_for_ioctl_operation = 0; + tcm->waiting_frame = 0; + tcm->use_short_frame_waiting = 0; + tcm->primary_timestamp_enabled = 1; + + platform_set_drvdata(pdev, tcm); + + device_init_wakeup(&pdev->dev, 1); + init_completion(&tcm->report_complete); + + retval = tcm->dev_connect(tcm); + if (retval < 0) { + mutex_destroy(&tcm->mutex); + goto err_connect; + } + + tcm->speedup_resume_wq = create_singlethread_workqueue("sp_resume0"); + INIT_WORK(&tcm->speed_up_work, syna_speedup_resume); + + syna_tcm_enable_predict_reading(tcm->tcm_dev, true); + + tcm->probe_done = 1; + + return 0; + tcm->dev_disconnect(tcm); +err_manufacture_info: +err_connect: + syna_tcm_buf_release(&tcm->event_data); + mutex_destroy(&tcm->mutex); +err_allocate_cdev: + kfree(tcm); + + return retval; +} + +static void syna_tcm_del_message_wrap(struct tcm_message_data_blob *tcm_msg) +{ + syna_tcm_buf_release(&tcm_msg->temp); + syna_tcm_buf_release(&tcm_msg->out); + syna_tcm_buf_release(&tcm_msg->in); +} + +void syna_tcm_remove_device(struct tcm_dev *tcm_dev) +{ + if (!tcm_dev) + return; + + syna_tcm_del_message_wrap(&tcm_dev->msg_data); + + syna_tcm_buf_release(&tcm_dev->touch_config); + syna_tcm_buf_release(&tcm_dev->external_buf); + syna_tcm_buf_release(&tcm_dev->report_buf); + syna_tcm_buf_release(&tcm_dev->resp_buf); + + tcm_dev->hw_if = NULL; + + kfree(tcm_dev); +} + +static void syna_dev_remove(struct platform_device *pdev) +{ + struct syna_tcm *tcm = platform_get_drvdata(pdev); + msleep(25); + tcm->driver_current_state = IS_REMOVE; + mutex_lock(&tcm->mutex); + tcm->dev_disconnect(tcm); + mutex_unlock(&tcm->mutex); + syna_tcm_buf_release(&tcm->event_data); + syna_tcm_remove_device(tcm->tcm_dev); + kfree(tcm); +} + +static void syna_dev_shutdown(struct platform_device *pdev) +{ + syna_dev_remove(pdev); +} + +static int syna_spi_suspend(struct device *dev) +{ + struct syna_tcm *tcm = dev_get_drvdata(dev); + struct syna_hw_attn_data *attn; + if (!tcm || !tcm->hw_if) { + return 0; + } + attn = &tcm->hw_if->bdata_attn; + if (attn->irq_id == 0) + return 0; + tcm->bus_ready = false; + if (tcm->hw_if->ops_enable_irq) + tcm->hw_if->ops_enable_irq(tcm->hw_if, false); + return 0; +} + +static int syna_spi_resume(struct device *dev) +{ + struct syna_tcm *tcm = dev_get_drvdata(dev); + struct syna_hw_attn_data *attn; + + if (!tcm || !tcm->hw_if) { + return 0; + } + attn = &tcm->hw_if->bdata_attn; + if (attn->irq_id == 0) + return 0; + if (tcm->hw_if->ops_enable_irq) + tcm->hw_if->ops_enable_irq(tcm->hw_if, true); + tcm->bus_ready = true; + return 0; +} + +static const struct dev_pm_ops syna_dev_pm_ops = { + .suspend = syna_spi_suspend, + .resume = syna_spi_resume, +}; + +static struct platform_driver syna_dev_driver = { + .driver = { + .name = PLATFORM_DRIVER_NAME, + .owner = THIS_MODULE, + .pm = &syna_dev_pm_ops, + }, + .probe = syna_dev_probe, + .remove = syna_dev_remove, + .shutdown = syna_dev_shutdown, +}; + +static int __init syna_dev_module_init(void) +{ + int retval; + retval = syna_hw_interface_init(); + if (retval < 0) + return retval; + return platform_driver_register(&syna_dev_driver); +} + +static void __exit syna_dev_module_exit(void) +{ + platform_driver_unregister(&syna_dev_driver); + syna_hw_interface_exit(); +} + +module_init(syna_dev_module_init); +module_exit(syna_dev_module_exit); + +MODULE_AUTHOR("Synaptics, Inc."); +MODULE_DESCRIPTION("Synaptics TCM Touch Driver"); +MODULE_LICENSE("GPL v2"); + diff --git a/drivers/input/touchscreen/syna_tcm2.h b/drivers/input/touchscreen/syna_tcm2.h new file mode 100644 index 0000000000..fd28b27351 --- /dev/null +++ b/drivers/input/touchscreen/syna_tcm2.h @@ -0,0 +1,1228 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Synaptics TouchCom touchscreen driver + * + * Copyright (C) 2017-2020 Synaptics Incorporated. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS + * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, + * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS. + * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION + * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED + * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES + * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' + * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. + * DOLLARS. + */ + +#ifndef _SYNAPTICS_TCM2_DRIVER_H_ +#define _SYNAPTICS_TCM2_DRIVER_H_ + +#define REMOVE_OPLUS_FUNCTION 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define _EIO (-EIO) +#define _ENOMEM (-ENOMEM) +#define _EINVAL (-EINVAL) +#define _ENODEV (-ENODEV) +#define _ETIMEDOUT (-ETIMEDOUT) + +#define GET_BIT(var, pos) \ + (((var) & (1 << (pos))) >> (pos)) + +#define ATOMIC_SET(atomic, value) \ + atomic_set(&atomic, value) + +#define ATOMIC_GET(atomic) \ + atomic_read(&atomic) + +#define PLATFORM_DRIVER_NAME "synaptics_tcm_hbp" + +#define TOUCH_INPUT_NAME "touchpanel" +#define TOUCH_INPUT_PHYS_PATH "synaptics_tcm/touch_input" + +#define CHAR_DEVICE_NAME "tcm_hbp" +#define CHAR_DEVICE_MODE (0x0600) + +#define SIG_DISPLAY_ON 44 +#define SIG_DISPLAY_OFF 45 +#define SIG_FINGER_DOWN 46 + +#undef MAX_DEVICE_VERSION_LENGTH +#define MAX_DEVICE_VERSION_LENGTH 256 + +#define SYNAPTICS_TCM_DRIVER_ID (1 << 0) +#define SYNAPTICS_TCM_DRIVER_VERSION 1 +#define SYNAPTICS_TCM_DRIVER_SUBVER "4.0" + +#define ABS_TOUCH_COST_TIME_KERNEL 0x21 +#define ABS_TOUCH_COST_TIME_ALGO 0x22 +#define ABS_TOUCH_COST_TIME_DAEMON 0x23 +#define MAX_TOUCH_COST_TIME (1000 * 1000) + +#define TX_NUM 17 +#define RX_NUM 38 + +#define IRQ_COST_TIME_OVER_5MS 5000 +#define IRQ_COST_TIME_OVER_10MS 10000 +#define IRQ_COST_TIME_OVER_20MS 20000 +#define IRQ_COST_TIME_OVER_50MS 50000 + +#define FW_UPDATE_COMPLETE_TIMEOUT msecs_to_jiffies(40*1000) + +#define GESTURE_MODE_SWITCH_RETRY_TIMES 5 +#define MAX_HEALTH_REPORT_LEN 50 + +#define HAS_SYSFS_INTERFACE +#define HAS_REFLASH_FEATURE +#define HAS_ROMBOOT_REFLASH_FEATURE +#define HAS_TESTING_FEATURE + +#define TYPE_B_PROTOCOL + +#define RESET_ON_RESUME + +#define REPORT_TOUCH_WIDTH +#define RESUME_EARLY_UNBLANK + +#define REPORT_TYPES (256) +#define EFP_ENABLE (1) +#define EFP_DISABLE (0) + +#define TCM_CONNECT_IN_PROBE + +#define DTAP_DETECT 0x01 +#define SWIPE_DETECT 0x02 +#define TRIANGLE_DETECT 0x03 +#define CIRCLE_DETECT 0x04 +#define VEE_DETECT 0x05 +#define HEART_DETECT 0x07 +#define UNICODE_DETECT 0x08 +#define STAP_DETECT 0x10 +#define M_UNICODE 0x6d +#define S_UNICODE 0x73 +#define W_UNICODE 0x77 + +#define REPORT_TIMEOUT_MS 1000 + +#define TOUCH_HOLD_DOWN 0x80 +#define TOUCH_HOLD_UP 0x81 +#define FINGERPRINT_ERR_REPORT 0x84 + +#define TOUCH_BIT_CHECK 0x3FF + +#define TCM_V1_MESSAGE_MARKER 0xa5 +#define TCM_V1_MESSAGE_PADDING 0x5a + +#define IS_APP_FW_MODE(mode) \ + (mode == MODE_APPLICATION_FIRMWARE) + +#define IS_NOT_APP_FW_MODE(mode) \ + (!IS_APP_FW_MODE(mode)) + +#define IS_BOOTLOADER_MODE(mode) \ + ((mode == MODE_BOOTLOADER) || \ + (mode == MODE_TDDI_BOOTLOADER) || \ + (mode == MODE_TDDI_HDL_BOOTLOADER) || \ + (mode == MODE_MULTICHIP_TDDI_BOOTLOADER)) + +#define IS_ROM_BOOTLOADER_MODE(mode) \ + (mode == MODE_ROMBOOTLOADER) + +#define MAX_NUM_OBJECTS (10) + +#define MAX_SIZE_GESTURE_DATA (8) + +#define MAX_SIZE_CONFIG_ID (16) + +#define MAX_SIZE_GRIP_INFO (4) + +#define RD_RETRY_US_MIN (5000) +#define RD_RETRY_US_MAX (10000) + +#define WR_DELAY_US_MIN (500) +#define WR_DELAY_US_MAX (1000) + +#define TAT_DELAY_US_MIN (100) +#define TAT_DELAY_US_MAX (200) + +#define TCM_MSG_CRC_LENGTH (2) +#define TCM_EXTRA_RC_LENGTH (1) + +#define RECORD_POINTS_COUNT 5 + +#define FIRMWARE_MODE_BL_MAX (2) +#define FWUPDATE_BL_MAX (3) + +#define MESSAGE_HEADER_SIZE (4) + +#define CMD_RESPONSE_TIMEOUT_MS (3000) +#define CMD_RESPONSE_POLLING_DELAY_MS (20) + +#define RESET_DELAY_MS (200) + +#define POLLING_ENABLE_IRQ_DELAY_MS 5 + +#define RESP_IN_ATTN (0) +#define RESP_IN_POLLING (CMD_RESPONSE_POLLING_DELAY_MS) + +#define RD_CHUNK_SIZE (0) +#define WR_CHUNK_SIZE (1024) + +typedef enum tp_dev { + TP_OFILM, + TP_BIEL, + TP_TRULY, + TP_BOE, + TP_G2Y, + TP_TPK, + TP_JDI, + TP_TIANMA, + TP_SAMSUNG, + TP_DSJM, + TP_BOE_B8, + TP_INNOLUX, + TP_HIMAX_DPT, + TP_AUO, + TP_DEPUTE, + TP_HUAXING, + TP_HLT, + TP_DJN, + TP_VXN, + TP_UNKNOWN, +} tp_dev; + +enum tcm_app_status { + APP_STATUS_OK = 0x00, + APP_STATUS_BOOTING = 0x01, + APP_STATUS_UPDATING = 0x02, + APP_STATUS_BAD_APP_CONFIG = 0xff, +}; + +enum tcm_firmware_protocol { + TOUCHCOMM_NONE = 0, + TOUCHCOMM_V1 = 1, + TOUCHCOMM_V2 = 2, +}; + +enum tcm_report_type { + REPORT_IDENTIFY = 0x10, + REPORT_TOUCH = 0x11, + REPORT_DELTA = 0x12, + REPORT_RAW = 0x13, + REPORT_DEBUG = 0x14, + REPORT_HBP_ACTIVE_FRAME = 0x23, + REPORT_LOG = 0x9f, + REPORT_POWER_STATE_INFO = 0xFE, +}; + +enum tcm_firmware_mode { + MODE_UNKNOWN = 0x00, + MODE_APPLICATION_FIRMWARE = 0x01, + MODE_HOSTDOWNLOAD_FIRMWARE = 0x02, + MODE_ROMBOOTLOADER = 0x04, + MODE_BOOTLOADER = 0x0b, + MODE_TDDI_BOOTLOADER = 0x0c, + MODE_TDDI_HDL_BOOTLOADER = 0x0d, + MODE_PRODUCTIONTEST_FIRMWARE = 0x0e, + MODE_MULTICHIP_TDDI_BOOTLOADER = 0xab, +}; + +enum tcm_status_code { + STATUS_IDLE = 0x00, + STATUS_OK = 0x01, + STATUS_CONTINUED_READ = 0x03, + STATUS_NO_REPORT_AVAILABLE = 0x04, + STATUS_ACK = 0x07, + STATUS_RETRY_REQUESTED = 0x08, + STATUS_CMD_FAILED = 0x09, + STATUS_RECEIVE_BUFFER_OVERFLOW = 0x0c, + STATUS_PREVIOUS_COMMAND_PENDING = 0x0d, + STATUS_NOT_IMPLEMENTED = 0x0e, + STATUS_ERROR = 0x0f, + STATUS_PACKET_CORRUPTED = 0xfe, + STATUS_INVALID = 0xff, +}; + +enum tcm_command { + CMD_NONE = 0x00, + CMD_CONTINUE_WRITE = 0x01, + CMD_IDENTIFY = 0x02, + CMD_RESET = 0x04, + CMD_ENABLE_REPORT = 0x05, + CMD_DISABLE_REPORT = 0x06, + CMD_TCM2_ACK = 0x07, + CMD_TCM2_RETRY = 0x08, + CMD_TCM2_SET_MAX_READ_LENGTH = 0x09, + CMD_TCM2_GET_REPORT = 0x0a, + CMD_GET_BOOT_INFO = 0x10, + CMD_ERASE_FLASH = 0x11, + CMD_WRITE_FLASH = 0x12, + CMD_READ_FLASH = 0x13, + CMD_RUN_APPLICATION_FIRMWARE = 0x14, + CMD_SPI_MASTER_WRITE_THEN_READ = 0x15, + CMD_REBOOT_TO_ROM_BOOTLOADER = 0x16, + CMD_RUN_BOOTLOADER_FIRMWARE = 0x1f, + CMD_GET_APPLICATION_INFO = 0x20, + CMD_GET_STATIC_CONFIG = 0x21, + CMD_SET_STATIC_CONFIG = 0x22, + CMD_GET_DYNAMIC_CONFIG = 0x23, + CMD_SET_DYNAMIC_CONFIG = 0x24, + CMD_GET_TOUCH_REPORT_CONFIG = 0x25, + CMD_SET_TOUCH_REPORT_CONFIG = 0x26, + CMD_REZERO = 0x27, + CMD_COMMIT_CONFIG = 0x28, + CMD_DESCRIBE_DYNAMIC_CONFIG = 0x29, + CMD_PRODUCTION_TEST = 0x2a, + CMD_SET_CONFIG_ID = 0x2b, + CMD_ENTER_DEEP_SLEEP = 0x2c, + CMD_EXIT_DEEP_SLEEP = 0x2d, + CMD_GET_TOUCH_INFO = 0x2e, + CMD_GET_DATA_LOCATION = 0x2f, + CMD_DOWNLOAD_CONFIG = 0x30, + CMD_ENTER_PRODUCTION_TEST_MODE = 0x31, + CMD_GET_FEATURES = 0x32, + CMD_GET_ROMBOOT_INFO = 0x40, + CMD_WRITE_PROGRAM_RAM = 0x41, + CMD_ROMBOOT_RUN_BOOTLOADER_FIRMWARE = 0x42, + CMD_SPI_MASTER_WRITE_THEN_READ_EXTENDED = 0x43, + CMD_ENTER_IO_BRIDGE_MODE = 0x44, + CMD_ROMBOOT_DOWNLOAD = 0x45, +}; + +enum dynamic_config_id { + DC_UNKNOWN_1 = 0x00, + DC_NO_DOZE, + DC_DISABLE_NOISE_MITIGATION_1, + DC_INHIBIT_FREQUENCY_SHIFT, + DC_REQUESTED_FREQUENCY, + DC_DISABLE_HSYNC_1, + DC_REZERO_ON_EXIT_DEEP_SLEEP_1, + DC_CHARGER_CONNECTED, + DC_NO_BASELINE_RELAXATION, + DC_IN_WAKEUP_GESTURE_MODE, + DC_STIMULUS_FINGERS, + DC_GRIP_SUPPRESSION_ENABLED, + DC_ENABLE_THICK_GLOVE_1, + DC_ENABLE_GLOVE_1, + DC_PS_STATUS = 0xC1, + DC_DISABLE_ESD = 0xC2, + DC_FREQUENCE_HOPPING = 0xD2, + DC_TOUCH_HOLD = 0xD4, + DC_ERROR_PRIORITY = 0xD5, + DC_NOISE_LENGTH = 0xD6, + DC_GRIP_CONDTION_ZONE = 0xD8, + DC_GRIP_SPECIAL_ZONE_X = 0xD9, + DC_GRIP_SPECIAL_ZONE_Y = 0xDA, + DC_GRIP_SPECIAL_ZONE_L = 0xDB, + DC_GRIP_ROATE_TO_HORIZONTAL_LEVEL = 0xDC, + DC_DARK_ZONE_ENABLE = 0xDD, + DC_GRIP_ENABLED = 0xDE, + DC_GRIP_DARK_ZONE_X = 0xDF, + DC_GRIP_DARK_ZONE_Y = 0xE0, + DC_GRIP_ABS_DARK_X = 0xE1, + DC_GRIP_ABS_DARK_Y = 0xE2, + DC_GRIP_ABS_DARK_U = 0xE3, + DC_GRIP_ABS_DARK_V = 0xE4, + DC_GRIP_ABS_DARK_SEL = 0xE5, + DC_SET_REPORT_FRE = 0xE6, + DC_GESTURE_MASK = 0xFE, + DC_LOW_TEMP_ENABLE = 0xFD, +}; + +enum bus_connection { + BUS_TYPE_NONE, + BUS_TYPE_I2C, + BUS_TYPE_SPI, + BUS_TYPE_I3C, +}; + +enum gesture_classification { + GESTURE_ID_NONE = 0, + GESTURE_ID_DOUBLE_TAP = 1, + GESTURE_ID_SWIPE = 2, + GESTURE_ID_ACTIVE_SINGLE_TAP = 0x10, + GESTURE_ID_ACTIVE_TAP_AND_HOLD = 0x80, +}; + +enum object_classification { + LIFT = 0, + FINGER = 1, + GLOVED_OBJECT = 2, + STYLUS = 3, + ERASER = 4, + SMALL_OBJECT = 5, + PALM = 6, + EDGE_TOUCHED = 8, + HOVER_OBJECT = 9, + NOP = -1, +}; + +enum touch_report_code { + TOUCH_REPORT_END = 0x00, + TOUCH_REPORT_FOREACH_ACTIVE_OBJECT = 0x01, + TOUCH_REPORT_FOREACH_OBJECT = 0x02, + TOUCH_REPORT_FOREACH_END = 0x03, + TOUCH_REPORT_PAD_TO_NEXT_BYTE = 0x04, + TOUCH_REPORT_TIMESTAMP = 0x05, + TOUCH_REPORT_OBJECT_N_INDEX = 0x06, + TOUCH_REPORT_OBJECT_N_CLASSIFICATION = 0x07, + TOUCH_REPORT_OBJECT_N_X_POSITION = 0x08, + TOUCH_REPORT_OBJECT_N_Y_POSITION = 0x09, + TOUCH_REPORT_OBJECT_N_Z = 0x0a, + TOUCH_REPORT_OBJECT_N_X_WIDTH = 0x0b, + TOUCH_REPORT_OBJECT_N_Y_WIDTH = 0x0c, + TOUCH_REPORT_OBJECT_N_TX_POSITION_TIXELS = 0x0d, + TOUCH_REPORT_OBJECT_N_RX_POSITION_TIXELS = 0x0e, + TOUCH_REPORT_0D_BUTTONS_STATE = 0x0f, + TOUCH_REPORT_GESTURE_ID = 0x10, + TOUCH_REPORT_FRAME_RATE = 0x11, + TOUCH_REPORT_POWER_IM = 0x12, + TOUCH_REPORT_CID_IM = 0x13, + TOUCH_REPORT_RAIL_IM = 0x14, + TOUCH_REPORT_CID_VARIANCE_IM = 0x15, + TOUCH_REPORT_NSM_FREQUENCY_INDEX = 0x16, + TOUCH_REPORT_NSM_STATE = 0x17, + TOUCH_REPORT_NUM_OF_ACTIVE_OBJECTS = 0x18, + TOUCH_REPORT_CPU_CYCLES_USED_SINCE_LAST_FRAME = 0x19, + TOUCH_REPORT_FACE_DETECT = 0x1a, + TOUCH_REPORT_GESTURE_DATA = 0x1b, + TOUCH_REPORT_FORCE_MEASUREMENT = 0x1c, + TOUCH_REPORT_FINGERPRINT_AREA_MEET = 0x1d, + TOUCH_REPORT_SENSING_MODE = 0x1e, + TOUCH_REPORT_KNOB_DATA = 0x24, + TOUCH_REPORT_CUSTOM_GESTURE_INFO = 0xC6, + TOUCH_REPORT_CUSTOM_GESTURE_COORDINATE = 0xC7, + TOUCH_REPORT_CUSTOM_GRIP_INFO = 0xCB, +}; + +enum power_state { + PWR_OFF = 0, + PWR_ON, + LOW_PWR, + PWR_UNKNOWN, +}; + +enum sub_power_state { + SUB_NONE = 0, + SUB_PWR_RESUMING, + SUB_PWR_RESUME_DONE, + SUB_PWR_EARLY_SUSPENDING, + SUB_PWR_SUSPENDING, + SUB_PWR_SUSPEND_DONE, +}; + +enum tcm_command_status { + CMD_STATE_IDLE = 0, + CMD_STATE_BUSY = 1, + CMD_STATE_ERROR = -1, +}; + +enum driver_state { + IS_PROBE = 0, + IS_SHUTDOWN, + IS_REMOVE, +}; + +enum power_supply { + PSU_REGULATOR = 0, + PSU_GPIO, +}; + +struct tcm_buffer { + unsigned char *buf; + unsigned int buf_size; + unsigned int data_length; + struct mutex buf_mutex; + unsigned char ref_cnt; +}; + +typedef enum { + TP_RATE_START, + TP_RATE_CALC, + TP_RATE_CLEAR, +} tp_rate; + +struct Coordinate { + int x; + int y; +}; + +struct swipes_record { + int count; + struct Coordinate start_points[RECORD_POINTS_COUNT]; + struct Coordinate end_points[RECORD_POINTS_COUNT]; +}; + +struct points_record { + int count; + struct Coordinate points[RECORD_POINTS_COUNT]; +}; + +static inline unsigned int le2_to_uint(const unsigned char *src) +{ + return (unsigned int)src[0] + + (unsigned int)src[1] * 0x100; +} + +static inline unsigned int le4_to_uint(const unsigned char *src) +{ + return (unsigned int)src[0] + + (unsigned int)src[1] * 0x100 + + (unsigned int)src[2] * 0x10000 + + (unsigned int)src[3] * 0x1000000; +} + +struct touchpanel_event { + int touchpanel_id; + int x; + int y; + int fid; + char type; + int touch_state; + int area_rate; +}; + +struct tcm_v1_message_header { + union { + struct { + unsigned char marker; + unsigned char code; + unsigned char length[2]; + }; + unsigned char data[MESSAGE_HEADER_SIZE]; + }; +}; + +struct tcm_application_info { + unsigned char version[2]; + unsigned char status[2]; + unsigned char static_config_size[2]; + unsigned char dynamic_config_size[2]; + unsigned char app_config_start_write_block[2]; + unsigned char app_config_size[2]; + unsigned char max_touch_report_config_size[2]; + unsigned char max_touch_report_payload_size[2]; + unsigned char customer_config_id[MAX_SIZE_CONFIG_ID]; + unsigned char max_x[2]; + unsigned char max_y[2]; + unsigned char max_objects[2]; + unsigned char num_of_buttons[2]; + unsigned char num_of_image_rows[2]; + unsigned char num_of_image_cols[2]; + unsigned char has_hybrid_data[2]; + unsigned char num_of_force_elecs[2]; +}; + +struct tcm_identification_info { + unsigned char version; + unsigned char mode; + unsigned char part_number[16]; + unsigned char build_id[4]; + unsigned char max_write_size[2]; + unsigned char max_read_size[2]; + unsigned char reserved[6]; +}; + +struct tcm_gesture_data_blob { + union { + struct { + unsigned char tap_x[2]; + unsigned char tap_y[2]; + }; + struct { + unsigned char swipe_x[2]; + unsigned char swipe_y[2]; + unsigned char swipe_direction[2]; + }; + unsigned char data[MAX_SIZE_GESTURE_DATA]; + }; +}; + +struct tcm_grip_info_blob { + unsigned char data[MAX_SIZE_GRIP_INFO]; +}; + +struct tcm_objects_data_blob { + unsigned char status; + unsigned int x_pos; + unsigned int y_pos; + unsigned int x_width; + unsigned int y_width; + unsigned int z; + unsigned int tx_pos; + unsigned int rx_pos; + unsigned int custom_data[5]; + struct tcm_grip_info_blob grip_info; +}; + +struct tcm_touch_data_blob { + unsigned int obji; + unsigned int num_of_active_objects; + struct tcm_objects_data_blob object_data[MAX_NUM_OBJECTS]; + unsigned int gesture_id; + struct tcm_gesture_data_blob gesture_data; + unsigned int timestamp; + unsigned int buttons_state; + unsigned int frame_rate; + unsigned int force_data; + unsigned int power_im; + unsigned int cid_im; + unsigned int rail_im; + unsigned int cid_variance_im; + unsigned int nsm_frequency; + unsigned int nsm_state; + unsigned int sensing_mode; +}; + +struct tcm_message_data_blob { + atomic_t command_status; + unsigned char command; + unsigned char status_report_code; + unsigned int payload_length; + unsigned char response_code; + unsigned char report_code; + unsigned char seq_toggle; + unsigned int default_resp_reading; + struct completion cmd_completion; + struct tcm_buffer in; + struct tcm_buffer out; + struct tcm_buffer temp; + struct mutex cmd_mutex; + struct mutex rw_mutex; + bool predict_reads; + unsigned int predict_length; + bool has_crc; + unsigned short crc_bytes; + bool has_extra_rc; + unsigned char rc_byte; +}; + +struct syna_hw_bus_data { + unsigned char type; + unsigned int rd_chunk_size; + unsigned int wr_chunk_size; + unsigned int frequency_hz; + unsigned int i2c_addr; + unsigned int spi_mode; + unsigned int spi_byte_delay_us; + unsigned int spi_block_delay_us; + struct mutex io_mutex; + int switch_gpio; + int switch_state; + struct pinctrl *pinctrl; + struct pinctrl_state *pin_spi_mode_active; + struct pinctrl_state *pin_spi_mode_suspend; + struct pinctrl_state *pin_cs_high; + struct pinctrl_state *pin_cs_low; +}; + +struct syna_hw_attn_data { + int irq_gpio; + int irq_on_state; + unsigned long irq_flags; + int irq_id; + bool irq_enabled; + struct mutex irq_en_mutex; +}; + +struct syna_hw_rst_data { + int reset_gpio; + int reset_on_state; + unsigned int reset_delay_ms; + unsigned int reset_active_ms; + struct mutex reset_en_mutex; +}; + +struct syna_hw_pwr_data { + int psu; + int vdd_gpio; + int avdd_gpio; + int power_on_state; + unsigned int power_on_delay_ms; + unsigned int vdd; + unsigned int vled; + unsigned int vio; + unsigned int vddtx; + const char *vdd_reg_name; + void *vdd_reg_dev; + const char *avdd_reg_name; + void *avdd_reg_dev; +}; + +struct syna_hw_interface { + void *pdev; + struct syna_hw_bus_data bdata_io; + struct syna_hw_attn_data bdata_attn; + struct syna_hw_rst_data bdata_rst; + struct syna_hw_pwr_data bdata_pwr; + int (*ops_power_on)(struct syna_hw_interface *hw_if, bool en); + void (*ops_hw_reset)(struct syna_hw_interface *hw_if); + int (*ops_bus_setup)(struct syna_hw_interface *hw_if, struct syna_hw_bus_data *config); + int (*ops_read_data)(struct syna_hw_interface *hw_if, unsigned char *rd_data, unsigned int rd_len); + int (*ops_write_data)(struct syna_hw_interface *hw_if, unsigned char *wr_data, unsigned int wr_len); + int (*ops_enable_irq)(struct syna_hw_interface *hw_if, bool en); + int (*ops_wait_irq)(struct syna_hw_interface *hw_if, unsigned int timeout_ms); + +}; + +int syna_hw_interface_init(void); +void syna_hw_interface_exit(void); + +struct tcm_boot_info { + unsigned char version; + unsigned char status; + unsigned char asic_id[2]; + unsigned char write_block_size_words; + unsigned char erase_page_size_words[2]; + unsigned char max_write_payload_size[2]; + unsigned char last_reset_reason; + unsigned char pc_at_time_of_last_reset[2]; + unsigned char boot_config_start_block[2]; + unsigned char boot_config_size_blocks[2]; + unsigned char display_config_start_block[4]; + unsigned char display_config_length_blocks[2]; + unsigned char backup_display_config_start_block[4]; + unsigned char backup_display_config_length_blocks[2]; + unsigned char custom_otp_start_block[2]; + unsigned char custom_otp_length_blocks[2]; +}; + +struct tcm_dev { + unsigned char protocol; + unsigned char dev_mode; + unsigned int packrat_number; + unsigned int max_x; + unsigned int max_y; + unsigned int max_objects; + unsigned int rows; + unsigned int cols; + unsigned char config_id[MAX_SIZE_CONFIG_ID]; + unsigned int max_wr_size; + unsigned int max_rd_size; + bool bypass_max_wr_rd_setup; + bool is_sleep; + struct syna_hw_interface *hw_if; + unsigned int firmware_mode_count; + unsigned int upload_flag; + unsigned int error_state_count; + struct tcm_identification_info id_info; + struct tcm_application_info app_info; + struct tcm_boot_info boot_info; + struct tcm_buffer report_buf; + struct tcm_buffer resp_buf; + struct tcm_buffer external_buf; + struct tcm_buffer touch_config; + struct tcm_message_data_blob msg_data; + atomic_t firmware_flashing; + int (*read_message)(struct tcm_dev *tcm_dev, + unsigned char *status_report_code); + int (*write_message)(struct tcm_dev *tcm_dev, + unsigned char command, unsigned char *payload, + unsigned int payload_length, unsigned char *resp_code, + unsigned int delay_ms_resp); +}; + +struct syna_tcm { + + int tp_index; + struct tcm_dev *tcm_dev; + struct completion report_complete; + struct platform_device *pdev; + struct tcm_touch_data_blob tp_data; + struct mutex tp_event_mutex; + struct mutex extif_mutex; + struct mutex mutex; + unsigned char prev_obj_status[MAX_NUM_OBJECTS]; + struct tcm_buffer event_data; + struct syna_hw_interface *hw_if; + pid_t isr_pid; + bool irq_wake; + int irq_cost_time; + struct cdev char_dev; + dev_t char_dev_num; + int char_dev_ref_count; + struct class *device_class; + struct device *device; + struct kobject *sysfs_dir; + struct proc_dir_entry *prEntry_tp; + struct proc_dir_entry *prEntry_debug_tp; + struct input_dev *input_dev; + struct input_params { + unsigned int max_x; + unsigned int max_y; + unsigned int max_objects; + } input_dev_params; + int tx_num; + int rx_num; + int dts_max_x; + int dts_max_y; + unsigned int firmware_max_x; + unsigned int firmware_max_y; + char *fw_name_fae; + char algo_version[MAX_DEVICE_VERSION_LENGTH]; + int firmware_update_type; + struct completion fw_complete; + struct delayed_work reflash_work; + struct workqueue_struct *reflash_workqueue; + pid_t proc_pid; + struct task_struct *proc_task; + int probe_done; + int pwr_state; + int sub_pwr_state; + bool slept_in_early_suspend; + bool lpwg_enabled; + bool is_attn_redirecting; + unsigned char fb_ready; + bool is_connected; + bool hbp_enabled; + int daemon_state; + int primary_timestamp_enabled; + int driver_current_state; + unsigned int waiting_frame; + unsigned int wait_for_ioctl_operation; + unsigned int use_short_frame_waiting; + bool snr_read_support; + bool freq_hop_simulate_support; + unsigned short gesture_type; + unsigned short touch_and_hold; + bool fp_active; + int aging_test; + int aging_mode; + void *chip_data; + bool in_test_process; + unsigned int fifo_remaining_frame; + struct list_head frame_fifo_queue; + wait_queue_head_t wait_frame; + unsigned char report_to_queue[REPORT_TYPES]; + struct work_struct speed_up_work; + struct workqueue_struct *speedup_resume_wq; + bool bus_ready; + wait_queue_head_t wait; + int (*dev_connect)(struct syna_tcm *tcm); + int (*dev_disconnect)(struct syna_tcm *tcm); + int (*dev_set_up_app_fw)(struct syna_tcm *tcm); + int (*dev_resume)(struct device *dev); + int (*dev_suspend)(struct device *dev); +}; + +int syna_dev_disable_hbp_mode(struct syna_tcm *tcm); +void syna_dev_update_lpwg_status(struct syna_tcm *tcm); +void syna_send_signal(struct syna_tcm *tcm, int signal_num); +int syna_dev_enable_lowpwr_gesture(struct syna_tcm *tcm, bool en); +int syna_tcm_get_touch_data(const unsigned char *report, + unsigned int report_size, unsigned int offset, + unsigned int bits, unsigned int *data); +int syna_tcm_preserve_touch_report_config(struct tcm_dev *tcm_dev); +int syna_tcm_parse_touch_report(struct tcm_dev *tcm_dev, + unsigned char *report, unsigned int report_size, + struct tcm_touch_data_blob *touch_data); +void syna_tcm_remove_device(struct tcm_dev *tcm_dev); +int syna_tcm_enable_predict_reading(struct tcm_dev *tcm_dev, bool en); +int syna_tcm_allocate_device(struct tcm_dev **ptcm_dev_ptr, + struct syna_hw_interface *hw_if, unsigned int resp_reading); +int syna_tcm_switch_fw_mode(struct tcm_dev *tcm_dev, + unsigned char mode, unsigned int fw_switch_delay); +int syna_tcm_set_dynamic_config(struct tcm_dev *tcm_dev, + unsigned char id, unsigned short value, + unsigned int delay_ms_resp); +int syna_tcm_detect_device(struct tcm_dev *tcm_dev); +int syna_tcm_reset(struct tcm_dev *tcm_dev); +int syna_tcm_sleep(struct tcm_dev *tcm_dev, bool en); +int syna_tcm_get_event_data(struct tcm_dev *tcm_dev, + unsigned char *code, + struct tcm_buffer *report); +int syna_tcm_get_app_info(struct tcm_dev *tcm_dev, + struct tcm_application_info *app_info); + +int syna_cdev_create_sysfs(struct syna_tcm *ptcm, + struct platform_device *pdev); + +void syna_cdev_remove_sysfs(struct syna_tcm *ptcm); + +void syna_cdev_redirect_attn(struct syna_tcm *ptcm); + +static inline void syna_pal_mutex_lock(struct mutex *ptr) +{ + mutex_lock(ptr); +} + +static inline void syna_pal_mutex_unlock(struct mutex *ptr) +{ + mutex_unlock(ptr); +} + +static inline int syna_pal_mem_cpy(void *dest, unsigned int dest_size, const void *src, unsigned int src_size, unsigned int num) +{ + if (dest == NULL || src == NULL) + return -1; + + if (num > dest_size || num > src_size) + return -1; + + memcpy(dest, src, num); + + return 0; +} + +static inline void *syna_pal_mem_alloc(unsigned int num, unsigned int size) +{ + if ((int)(num * size) <= 0) + return NULL; + + return kcalloc(num, size, GFP_KERNEL); +} + +static inline int secure_memcpy(unsigned char *dest, unsigned int dest_size, + const unsigned char *src, unsigned int src_size, + unsigned int count) +{ + if (dest == NULL || src == NULL) + return -EINVAL; + + if (count > dest_size || count > src_size) { + pr_err("%s: src_size = %d, dest_size = %d, count = %d\n", + __func__, src_size, dest_size, count); + return -EINVAL; + } + + memcpy((void *)dest, (const void *)src, count); + + return 0; +} + +static inline unsigned short syna_tcm_crc16(unsigned char *p, + unsigned int len, unsigned short val) +{ + unsigned short r = val; + static unsigned short crc16_table[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, + 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, + 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, + 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 + }; + + if (len == 0) + return r; + + while (len--) + r = (r << 8) ^ crc16_table[(r >> 8) ^ *p++]; + + return r; +} + +static inline int syna_tcm_buf_realloc(struct tcm_buffer *pbuf, + unsigned int size) +{ + int retval; + unsigned char *temp_src; + unsigned int temp_size = 0; + + if (!pbuf) + return -1; + + if (size > pbuf->buf_size) { + temp_src = pbuf->buf; + temp_size = pbuf->buf_size; + + pbuf->buf = syna_pal_mem_alloc(size, sizeof(unsigned char)); + if (!(pbuf->buf)) { + kfree(temp_src); + pbuf->buf_size = 0; + return -1; + } + + retval = syna_pal_mem_cpy(pbuf->buf, + size, + temp_src, + temp_size, + temp_size); + if (retval < 0) { + kfree(temp_src); + kfree(pbuf->buf); + pbuf->buf_size = 0; + return retval; + } + + kfree(temp_src); + pbuf->buf_size = size; + } + + return 0; +} + +static inline int syna_tcm_buf_alloc(struct tcm_buffer *pbuf, + unsigned int size) +{ + if (!pbuf) + return -1; + + if (size > pbuf->buf_size) { + if (pbuf->buf) + kfree(pbuf->buf); + + pbuf->buf = syna_pal_mem_alloc(size, sizeof(unsigned char)); + if (!(pbuf->buf)) { + pbuf->buf_size = 0; + pbuf->data_length = 0; + return -1; + } + pbuf->buf_size = size; + } + + memset(pbuf->buf, 0x00, pbuf->buf_size); + pbuf->data_length = 0; + + return 0; +} + +static inline int syna_tcm_buf_copy(struct tcm_buffer *dest, + struct tcm_buffer *src) +{ + int retval = 0; + + if (dest->buf_size < src->data_length) { + retval = syna_tcm_buf_alloc(dest, src->data_length + 1); + if (retval < 0) + return retval; + } + + retval = syna_pal_mem_cpy(dest->buf, + dest->buf_size, + src->buf, + src->buf_size, + src->data_length); + if (retval < 0) + return retval; + + dest->data_length = src->data_length; + + return retval; +} + +static inline void syna_tcm_buf_lock(struct tcm_buffer *pbuf) +{ + syna_pal_mutex_lock(&pbuf->buf_mutex); + pbuf->ref_cnt++; +} + +static inline void syna_tcm_buf_unlock(struct tcm_buffer *pbuf) +{ + pbuf->ref_cnt--; + syna_pal_mutex_unlock(&pbuf->buf_mutex); +} + +static inline unsigned int syna_pal_le2_to_uint(const unsigned char *src) +{ + return (unsigned int)src[0] + (unsigned int)src[1] * 0x100; +} + +static inline int syna_pal_completion_wait_for(struct completion *ptr, unsigned int timeout_ms) +{ + int retval; + + retval = wait_for_completion_timeout(ptr, msecs_to_jiffies(timeout_ms)); + if (retval == 0) + return -1; + + return 0; +} + +static inline void syna_tcm_buf_release(struct tcm_buffer *pbuf) +{ + kfree(pbuf->buf); + pbuf->buf_size = 0; + pbuf->data_length = 0; + pbuf->ref_cnt = 0; +} + +static inline void syna_tcm_buf_init(struct tcm_buffer *pbuf) +{ + pbuf->buf_size = 0; + pbuf->data_length = 0; + pbuf->ref_cnt = 0; + pbuf->buf = NULL; + mutex_init(&pbuf->buf_mutex); +} + +static inline int syna_tcm_read(struct tcm_dev *tcm_dev, + unsigned char *rd_data, unsigned int rd_len) +{ + struct syna_hw_interface *hw_if; + + if (!tcm_dev) + return _EINVAL; + + hw_if = tcm_dev->hw_if; + if (!hw_if->ops_read_data) + return _ENODEV; + + return hw_if->ops_read_data(hw_if, rd_data, rd_len); +} + +static inline int syna_tcm_write(struct tcm_dev *tcm_dev, + unsigned char *wr_data, unsigned int wr_len) +{ + struct syna_hw_interface *hw_if; + + if (!tcm_dev) + return _EINVAL; + + hw_if = tcm_dev->hw_if; + if (!hw_if->ops_write_data) + return _ENODEV; + + return hw_if->ops_write_data(hw_if, wr_data, wr_len); +} + +static inline unsigned int syna_pal_ceil_div(unsigned int dividend, unsigned int divisor) +{ + return (dividend + divisor - 1) / divisor; +} + +static inline void syna_pal_completion_complete(struct completion *ptr) +{ + complete(ptr); +} + +static inline unsigned int syna_pal_le4_to_uint(const unsigned char *src) +{ + return (unsigned int)src[0] + (unsigned int)src[1] * 0x100 + (unsigned int)src[2] * 0x10000 + (unsigned int)src[3] * 0x1000000; +} + +void syna_cdev_update_report_queue(struct syna_tcm *tcm, + unsigned char code, struct tcm_buffer *pevent_data); +void syna_cdev_update_power_state_report_queue(struct syna_tcm *tcm, bool wakeup); + + + + +#define INIT_BUFFER(buffer, is_clone) \ + mutex_init(&buffer.buf_mutex); \ + +#define LOCK_BUFFER(buffer) \ + mutex_lock(&buffer.buf_mutex) + +#define UNLOCK_BUFFER(buffer) \ + mutex_unlock(&buffer.buf_mutex) + +#define RELEASE_BUFFER(buffer) \ + do { \ + if (buffer.clone == false) { \ + kfree(buffer.buf); \ + buffer.buf_size = 0; \ + buffer.data_length = 0; \ + } \ + } while (0) + +struct syna_tcm_report { + unsigned char id; + struct tcm_buffer buffer; +}; + +static inline int syna_tcm_alloc_mem(struct tcm_buffer *buffer, + unsigned int size) +{ + if (size > buffer->buf_size) { + if (buffer->buf != NULL) { + kfree(buffer->buf); + } + buffer->buf = kzalloc(size, GFP_KERNEL); + + if (!(buffer->buf)) { + buffer->buf_size = 0; + buffer->data_length = 0; + return -ENOMEM; + } + buffer->buf_size = size; + } + + memset(buffer->buf, 0, buffer->buf_size); + buffer->data_length = 0; + + return 0; +} + +static inline int tp_memcpy(void *dest, unsigned int dest_size, + void *src, unsigned int src_size, + unsigned int count) +{ + if (dest == NULL || src == NULL) { + return -EINVAL; + } + + if (count > dest_size || count > src_size) { + return -EINVAL; + } + + memcpy(dest, src, count); + + return 0; +} + +#endif /* end of _SYNAPTICS_TCM2_DRIVER_H_ */ + diff --git a/drivers/input/touchscreen/syna_tcm2_spi.c b/drivers/input/touchscreen/syna_tcm2_spi.c new file mode 100644 index 0000000000..4e3508b50c --- /dev/null +++ b/drivers/input/touchscreen/syna_tcm2_spi.c @@ -0,0 +1,707 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Synaptics TouchCom touchscreen driver + * + * Copyright (C) 2017-2020 Synaptics Incorporated. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS + * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, + * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS. + * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION + * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED + * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES + * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' + * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. + * DOLLARS. + */ + +#include +#include "syna_tcm2.h" +#include + +/* + * is gone. The driver still uses legacy GPIO numbers, + * so look the line up through gpiod and hand back its number. The + * descriptor is released again so the later gpio_request() succeeds. + */ +static int syna_of_get_named_gpio(struct device_node *np, const char *prop, + int index) +{ + char con_id[48]; + struct gpio_desc *desc; + size_t n = strlen(prop); + int gpio; + + if (n > 5 && !strcmp(prop + n - 5, "-gpio")) + n -= 5; + if (n >= sizeof(con_id)) + return -EINVAL; + memcpy(con_id, prop, n); + con_id[n] = '\0'; + + desc = fwnode_gpiod_get_index(of_fwnode_handle(np), con_id, index, + GPIOD_ASIS, "syna_tcm2"); + if (IS_ERR(desc)) + return PTR_ERR(desc); + gpio = desc_to_gpio(desc); + gpiod_put(desc); + return gpio; +} + +#define SPI_MODULE_NAME "synaptics_tcm_spi" + +static unsigned char *rx_buf; +static unsigned char *tx_buf; + +static unsigned int buf_size; + +static struct spi_transfer *xfer; + +struct platform_device *syna_spi_device; + +static struct device *syna_request_managed_device(void) +{ + if (!syna_spi_device) + return NULL; + + return syna_spi_device->dev.parent; +} + +static void syna_spi_hw_reset(struct syna_hw_interface *hw_if) +{ + struct syna_hw_rst_data *rst = &hw_if->bdata_rst; + + if (rst->reset_gpio >= 0) { + syna_pal_mutex_lock(&rst->reset_en_mutex); + gpio_set_value(rst->reset_gpio, rst->reset_on_state); + msleep(rst->reset_active_ms); + gpio_set_value(rst->reset_gpio, !rst->reset_on_state); + msleep(rst->reset_delay_ms); + syna_pal_mutex_unlock(&rst->reset_en_mutex); + } +} + +static int syna_spi_request_gpio(int gpio, bool config, int dir, int state, char *label) +{ + int retval; + + struct device *dev = syna_request_managed_device(); + + if (!dev) + return -ENODEV; + + if (gpio < 0) + return -EINVAL; + + if (config) { + retval = snprintf(label, 16, "tcm_gpio_%d\n", gpio); + if (retval < 0) + return retval; + + retval = gpio_request(gpio, label); + if (retval < 0) + return retval; + + if (dir == 0) + retval = gpio_direction_input(gpio); + else + retval = gpio_direction_output(gpio, state); + + if (retval < 0) + return retval; + } else { + gpio_free(gpio); + } + + return 0; +} + +static void syna_spi_release_gpio(struct syna_hw_interface *hw_if) +{ + struct syna_hw_attn_data *attn = &hw_if->bdata_attn; + struct syna_hw_rst_data *rst = &hw_if->bdata_rst; + + if (rst->reset_gpio >= 0) + syna_spi_request_gpio(rst->reset_gpio, false, 0, 0, NULL); + if (attn->irq_gpio >= 0) + syna_spi_request_gpio(attn->irq_gpio, false, 0, 0, NULL); +} + +static int syna_spi_active_pinctrl(struct syna_hw_interface *hw_if) +{ + int retval = 0; + struct syna_hw_bus_data *bus = &hw_if->bdata_io; + + if (bus->pin_spi_mode_active != NULL) { + retval = pinctrl_select_state(bus->pinctrl, bus->pin_spi_mode_active); + if (retval < 0) + goto err_active_pinctrl; + } + +err_active_pinctrl: + return retval; +} + +static int syna_spi_config_gpio(struct syna_hw_interface *hw_if) +{ + int retval; + static char str_irq_gpio[32] = {0}; + static char str_rst_gpio[32] = {0}; + struct syna_hw_attn_data *attn = &hw_if->bdata_attn; + struct syna_hw_rst_data *rst = &hw_if->bdata_rst; + + if (attn->irq_gpio >= 0) { + retval = syna_spi_request_gpio(attn->irq_gpio, true, 0, 0, str_irq_gpio); + if (retval < 0) + goto err_set_gpio_irq; + } + + if (rst->reset_gpio >= 0) { + retval = syna_spi_request_gpio(rst->reset_gpio, true, 1, !rst->reset_on_state, str_rst_gpio); + if (retval < 0) + goto err_set_gpio_reset; + } + + return 0; + +err_set_gpio_reset: + if (attn->irq_gpio >= 0) + syna_spi_request_gpio(attn->irq_gpio, false, 0, 0, NULL); +err_set_gpio_irq: + return retval; +} + +static int syna_spi_enable_pwr_gpio(struct syna_hw_interface *hw_if, bool en) +{ + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + int state = (en) ? pwr->power_on_state : !pwr->power_on_state; + int ret = 0; + + if (pwr->avdd_gpio >= 0) { + ret = gpio_direction_output(pwr->avdd_gpio, state); + if (ret) + return ret; + } + + if (pwr->vdd_gpio >= 0) { + ret = gpio_direction_output(pwr->vdd_gpio, state); + if (ret) + return ret; + } + + return ret; +} + +static int syna_spi_enable_regulator(struct syna_hw_interface *hw_if, bool en) +{ + int retval; + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + struct regulator *vdd_reg = pwr->vdd_reg_dev; + + if (!en) { + retval = 0; + goto disable_pwr_reg; + } + + if (vdd_reg) { + retval = regulator_enable(vdd_reg); + if (retval < 0) + goto exit; + } + + return 0; + +disable_pwr_reg: + if (vdd_reg) + regulator_disable(vdd_reg); + +exit: + return retval; +} + +static int syna_spi_power_on(struct syna_hw_interface *hw_if, bool en) +{ + int retval; + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + + retval = syna_spi_enable_pwr_gpio(hw_if, en); + if (retval < 0) + return retval; + + retval = syna_spi_enable_regulator(hw_if, en); + if (retval < 0) + return retval; + + msleep(pwr->power_on_delay_ms); + + return 0; +} + +static int syna_spi_get_regulator(struct syna_hw_interface *hw_if, bool get) +{ + int retval; + struct device *dev = syna_spi_device->dev.parent; + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + + if (!get) { + retval = 0; + goto regulator_put; + } + + pwr->vdd_reg_dev = regulator_get(dev, "vdd"); + if (IS_ERR((struct regulator *)pwr->vdd_reg_dev)) { + retval = PTR_ERR((struct regulator *)pwr->vdd_reg_dev); + goto exit; + } else { + if (regulator_count_voltages(pwr->vdd_reg_dev) > 0) { + retval = regulator_set_voltage(pwr->vdd_reg_dev, 1800000, 1800000); + if (retval) + goto exit; + + retval = regulator_set_load(pwr->vdd_reg_dev, 200000); + if (retval < 0) + goto exit; + } + } + + return 0; + +regulator_put: + if (pwr->vdd_reg_dev) { + regulator_put(pwr->vdd_reg_dev); + pwr->vdd_reg_dev = NULL; + } +exit: + return retval; +} + +static int syna_spi_config_psu(struct syna_hw_interface *hw_if) +{ + int retval; + static char str_avdd_gpio[32] = {0}; + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + + if (pwr->psu == PSU_GPIO) { + if (pwr->avdd_gpio >= 0) { + retval = syna_spi_request_gpio(pwr->avdd_gpio, true, 1, !pwr->power_on_state, str_avdd_gpio); + if (retval < 0) { + syna_spi_request_gpio(pwr->vdd_gpio, false, 0, 0, NULL); + return retval; + } + } + } else { + retval = syna_spi_get_regulator(hw_if, true); + if (retval < 0) + return retval; + } + + return 0; +} + +static int syna_spi_release_psu(struct syna_hw_interface *hw_if) +{ + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + + if (pwr->psu == PSU_GPIO) { + syna_spi_request_gpio(pwr->avdd_gpio, false, 0, 0, NULL); + } else { + syna_spi_get_regulator(hw_if, false); + } + + return 0; +} + +static int syna_spi_enable_irq(struct syna_hw_interface *hw_if, bool en) +{ + int retval = 0; + struct syna_hw_attn_data *attn = &hw_if->bdata_attn; + + if (attn->irq_id == 0) + return 0; + + syna_pal_mutex_lock(&attn->irq_en_mutex); + + if (en) { + if (attn->irq_enabled) { + retval = 0; + goto exit; + } + + enable_irq(attn->irq_id); + attn->irq_enabled = true; + } else { + if (!attn->irq_enabled) { + retval = 0; + goto exit; + } + + disable_irq_nosync(attn->irq_id); + attn->irq_enabled = false; + } + +exit: + syna_pal_mutex_unlock(&attn->irq_en_mutex); + + return retval; +} + +static int syna_spi_parse_dt(struct syna_hw_interface *hw_if, struct device *dev) +{ + struct property *prop; + struct device_node *np = dev->of_node; + struct syna_hw_attn_data *attn = &hw_if->bdata_attn; + struct syna_hw_pwr_data *pwr = &hw_if->bdata_pwr; + struct syna_hw_rst_data *rst = &hw_if->bdata_rst; + struct syna_hw_bus_data *bus = &hw_if->bdata_io; + + prop = of_find_property(np, "synaptics,irq-gpio", NULL); + if (prop && prop->length) { + attn->irq_gpio = syna_of_get_named_gpio(np, "synaptics,irq-gpio", 0); + } else { + attn->irq_gpio = -1; + } + + attn->irq_on_state = 0; + pwr->psu = (int)PSU_REGULATOR; + + prop = of_find_property(np, "synaptics,avdd-gpio", NULL); + if (prop && prop->length) { + pwr->avdd_gpio = syna_of_get_named_gpio(np, "synaptics,avdd-gpio", 0); + } else { + pwr->avdd_gpio = -1; + } + + pwr->power_on_state = 1; + pwr->power_on_delay_ms = 200; + + prop = of_find_property(np, "synaptics,reset-gpio", NULL); + if (prop && prop->length) { + rst->reset_gpio = syna_of_get_named_gpio(np, "synaptics,reset-gpio", 0); + } else { + rst->reset_gpio = -1; + } + + rst->reset_on_state = 0; + rst->reset_active_ms = 10; + rst->reset_delay_ms = 80; + + bus->spi_byte_delay_us = 0; + bus->spi_block_delay_us = 0; + bus->spi_mode = 0; + bus->switch_gpio = -1; + bus->switch_state = 1; + + bus->pinctrl = devm_pinctrl_get(dev); + + if (!IS_ERR_OR_NULL(bus->pinctrl)) { + bus->pin_spi_mode_active = pinctrl_lookup_state(bus->pinctrl, "ts_spi_active"); + if (IS_ERR_OR_NULL(bus->pin_spi_mode_active)) { + bus->pin_spi_mode_active = NULL; + } + + bus->pin_spi_mode_suspend = pinctrl_lookup_state(bus->pinctrl, "ts_spi_suspend"); + if (IS_ERR_OR_NULL(bus->pin_spi_mode_suspend)) { + bus->pin_spi_mode_suspend = NULL; + } + } + + return 0; +} + +static int syna_spi_alloc_mem(unsigned int count, unsigned int size) +{ + static unsigned int xfer_count; + + if (count > xfer_count) { + kfree(xfer); + xfer = syna_pal_mem_alloc(count, sizeof(*xfer)); + if (!xfer) { + xfer_count = 0; + return -ENOMEM; + } + xfer_count = count; + } else { + memset(xfer, 0, count * sizeof(*xfer)); + } + + if (size > buf_size) { + if (rx_buf) { + kfree(rx_buf); + rx_buf = NULL; + } + if (tx_buf) { + kfree(tx_buf); + tx_buf = NULL; + } + + rx_buf = syna_pal_mem_alloc(size, sizeof(unsigned char)); + if (!rx_buf) { + buf_size = 0; + return -ENOMEM; + } + tx_buf = syna_pal_mem_alloc(size, sizeof(unsigned char)); + if (!tx_buf) { + buf_size = 0; + return -ENOMEM; + } + + buf_size = size; + } + + return 0; +} + +static int syna_spi_read(struct syna_hw_interface *hw_if, unsigned char *rd_data, unsigned int rd_len) +{ + int retval; + unsigned int idx; + struct spi_message msg; + struct spi_device *spi = hw_if->pdev; + struct syna_hw_bus_data *bus = &hw_if->bdata_io; + + if (!spi) + return -ENXIO; + + syna_pal_mutex_lock(&bus->io_mutex); + + spi_message_init(&msg); + + if (bus->spi_byte_delay_us == 0) + retval = syna_spi_alloc_mem(1, rd_len); + else + retval = syna_spi_alloc_mem(rd_len, rd_len); + if (retval < 0) + goto exit; + + if (bus->spi_byte_delay_us == 0) { + memset(tx_buf, 0xff, rd_len); + xfer[0].len = rd_len; + xfer[0].tx_buf = tx_buf; + xfer[0].rx_buf = rx_buf; + spi_message_add_tail(&xfer[0], &msg); + } else { + tx_buf[0] = 0xff; + for (idx = 0; idx < rd_len; idx++) { + xfer[idx].len = 1; + xfer[idx].tx_buf = tx_buf; + xfer[idx].rx_buf = &rx_buf[idx]; + spi_message_add_tail(&xfer[idx], &msg); + } + } + + retval = spi_sync(spi, &msg); + if (retval != 0) + goto exit; + retval = syna_pal_mem_cpy(rd_data, rd_len, rx_buf, rd_len, rd_len); + if (retval < 0) + goto exit; + + retval = rd_len; + +exit: + syna_pal_mutex_unlock(&bus->io_mutex); + + return retval; +} + +static int syna_spi_write(struct syna_hw_interface *hw_if, unsigned char *wr_data, unsigned int wr_len) +{ + int retval; + unsigned int idx; + struct spi_message msg; + struct spi_device *spi = hw_if->pdev; + struct syna_hw_bus_data *bus = &hw_if->bdata_io; + + if (!spi) + return -ENXIO; + + syna_pal_mutex_lock(&bus->io_mutex); + + spi_message_init(&msg); + + if (bus->spi_byte_delay_us == 0) + retval = syna_spi_alloc_mem(1, wr_len); + else + retval = syna_spi_alloc_mem(wr_len, wr_len); + if (retval < 0) + goto exit; + + retval = syna_pal_mem_cpy(tx_buf, wr_len, wr_data, wr_len, wr_len); + if (retval < 0) + goto exit; + + if (bus->spi_byte_delay_us == 0) { + xfer[0].len = wr_len; + xfer[0].tx_buf = tx_buf; + spi_message_add_tail(&xfer[0], &msg); + } else { + for (idx = 0; idx < wr_len; idx++) { + xfer[idx].len = 1; + xfer[idx].tx_buf = &tx_buf[idx]; + spi_message_add_tail(&xfer[idx], &msg); + } + } + + retval = spi_sync(spi, &msg); + if (retval != 0) + goto exit; + + retval = wr_len; + +exit: + syna_pal_mutex_unlock(&bus->io_mutex); + + return retval; +} + +static struct syna_hw_interface syna_spi_hw_if = { + .bdata_io = { + .type = BUS_TYPE_SPI, + .rd_chunk_size = RD_CHUNK_SIZE, + .wr_chunk_size = WR_CHUNK_SIZE, + }, + .bdata_attn = { + .irq_enabled = false, + .irq_on_state = 0, + }, + .bdata_rst = { + .reset_on_state = 0, + .reset_delay_ms = 80, + .reset_active_ms = 10, + }, + .bdata_pwr = { + .power_on_state = 1, + .power_on_delay_ms = 200, + }, + .ops_power_on = syna_spi_power_on, + .ops_hw_reset = syna_spi_hw_reset, + .ops_read_data = syna_spi_read, + .ops_write_data = syna_spi_write, + .ops_enable_irq = syna_spi_enable_irq, +}; + +static int syna_spi_probe(struct spi_device *spi) +{ + int retval; + struct syna_hw_attn_data *attn = &syna_spi_hw_if.bdata_attn; + struct syna_hw_bus_data *bus = &syna_spi_hw_if.bdata_io; + struct syna_hw_rst_data *rst = &syna_spi_hw_if.bdata_rst; + + syna_spi_device = platform_device_alloc(PLATFORM_DRIVER_NAME, 0); + if (!syna_spi_device) + return _ENODEV; + + syna_spi_parse_dt(&syna_spi_hw_if, &spi->dev); + + mutex_init((struct mutex *)&attn->irq_en_mutex); + mutex_init((struct mutex *)&bus->io_mutex); + mutex_init((struct mutex *)&rst->reset_en_mutex); + + spi->mode = SPI_MODE_0; + + syna_spi_hw_if.pdev = spi; + + syna_spi_device->dev.parent = &spi->dev; + syna_spi_device->dev.platform_data = &syna_spi_hw_if; + + spi->bits_per_word = 8; + + retval = spi_setup(spi); + if (retval < 0) + return retval; + + retval = syna_spi_config_psu(&syna_spi_hw_if); + if (retval < 0) + return retval; + + retval = syna_spi_config_gpio(&syna_spi_hw_if); + if (retval < 0) + return retval; + + retval = syna_spi_active_pinctrl(&syna_spi_hw_if); + if (retval < 0) + return retval; + + retval = platform_device_add(syna_spi_device); + if (retval < 0) + return retval; + + return 0; +} + +static void syna_spi_remove(struct spi_device *spi) +{ + syna_spi_release_gpio(&syna_spi_hw_if); + syna_spi_release_psu(&syna_spi_hw_if); + syna_spi_device->dev.platform_data = NULL; + platform_device_unregister(syna_spi_device); +} +static const struct spi_device_id syna_spi_id_table[] = { + {SPI_MODULE_NAME, 0}, + {}, +}; +MODULE_DEVICE_TABLE(spi, syna_spi_id_table); + +static const struct of_device_id syna_spi_of_match_table[] = { + { + .compatible = "synaptics,tcm-spi-hbp", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, syna_spi_of_match_table); + + +static struct spi_driver syna_spi_driver = { + .driver = { + .name = SPI_MODULE_NAME, + .owner = THIS_MODULE, + .of_match_table = syna_spi_of_match_table, + }, + .probe = syna_spi_probe, + .remove = syna_spi_remove, + .id_table = syna_spi_id_table, +}; + +int syna_hw_interface_init(void) +{ + return spi_register_driver(&syna_spi_driver); +} + +void syna_hw_interface_exit(void) +{ + if (rx_buf) { + kfree(rx_buf); + rx_buf = NULL; + } + + if (tx_buf) { + kfree(tx_buf); + tx_buf = NULL; + } + + if (xfer) { + kfree(xfer); + xfer = NULL; + } + + spi_unregister_driver(&syna_spi_driver); +} + +MODULE_AUTHOR("Synaptics, Inc."); +MODULE_DESCRIPTION("Synaptics TouchCom SPI Bus Module"); +MODULE_LICENSE("GPL v2"); + diff --git a/drivers/net/ipa/data/ipa_data-v4.5.c b/drivers/net/ipa/data/ipa_data-v4.5.c index 730d8c43a4..353fe40645 100644 --- a/drivers/net/ipa/data/ipa_data-v4.5.c +++ b/drivers/net/ipa/data/ipa_data-v4.5.c @@ -419,6 +419,7 @@ static const struct ipa_mem_data ipa_mem_data = { .imem_addr = 0x14688000, .imem_size = 0x00003000, .smem_size = 0x00009000, + .fnr_idx_cnt = 0, }; /* Interconnect rates are in 1000 byte/second units */ diff --git a/drivers/net/ipa/data/ipa_data-v4.7.c b/drivers/net/ipa/data/ipa_data-v4.7.c index 5e1d9049c6..44d071698d 100644 --- a/drivers/net/ipa/data/ipa_data-v4.7.c +++ b/drivers/net/ipa/data/ipa_data-v4.7.c @@ -361,6 +361,7 @@ static const struct ipa_mem_data ipa_mem_data = { .imem_addr = 0x146a8000, .imem_size = 0x00002000, .smem_size = 0x00009000, + .fnr_idx_cnt = 0, }; /* Interconnect rates are in 1000 byte/second units */ diff --git a/drivers/net/ipa/data/ipa_data-v4.9.c b/drivers/net/ipa/data/ipa_data-v4.9.c index da472a2a2e..1c710e94a4 100644 --- a/drivers/net/ipa/data/ipa_data-v4.9.c +++ b/drivers/net/ipa/data/ipa_data-v4.9.c @@ -417,6 +417,7 @@ static const struct ipa_mem_data ipa_mem_data = { .imem_addr = 0x146bd000, .imem_size = 0x00002000, .smem_size = 0x00009000, + .fnr_idx_cnt = 0, }; /* Interconnect rates are in 1000 byte/second units */ diff --git a/drivers/net/ipa/data/ipa_data-v5.0.c b/drivers/net/ipa/data/ipa_data-v5.0.c index bc5722e4b0..77558d1258 100644 --- a/drivers/net/ipa/data/ipa_data-v5.0.c +++ b/drivers/net/ipa/data/ipa_data-v5.0.c @@ -443,6 +443,7 @@ static const struct ipa_mem_data ipa_mem_data = { .imem_addr = 0x14688000, .imem_size = 0x00003000, .smem_size = 0x00009000, + .fnr_idx_cnt = 0, }; /* Interconnect rates are in 1000 byte/second units */ diff --git a/drivers/net/ipa/data/ipa_data-v5.5.c b/drivers/net/ipa/data/ipa_data-v5.5.c index 741ae21d9d..2b2f42d720 100644 --- a/drivers/net/ipa/data/ipa_data-v5.5.c +++ b/drivers/net/ipa/data/ipa_data-v5.5.c @@ -61,6 +61,20 @@ static const struct ipa_qsb_data ipa_qsb_data[] = { }, }; +/* QSB configuration for Eliza / SM8750 (IPA v5.5). */ +static const struct ipa_qsb_data ipa_qsb_data_eliza[] = { + [IPA_QSB_MASTER_DDR] = { + .max_writes = 12, + .max_reads = 0, /* Unlimited */ + .max_reads_beats = 0, + }, + [IPA_QSB_MASTER_PCIE] = { + .max_writes = 8, + .max_reads = 0, /* Unlimited */ + .max_reads_beats = 0, + }, +}; + /* Endpoint configuration data for an SoC having IPA v5.5 */ static const struct ipa_gsi_endpoint_data ipa_gsi_endpoint_data[] = { [IPA_ENDPOINT_AP_COMMAND_TX] = { @@ -182,6 +196,126 @@ static const struct ipa_gsi_endpoint_data ipa_gsi_endpoint_data[] = { }, }; +static const struct ipa_gsi_endpoint_data ipa_gsi_endpoint_data_eliza[] = { + [IPA_ENDPOINT_AP_COMMAND_TX] = { + .ee_id = GSI_EE_AP, + .channel_id = 12, + .endpoint_id = 14, + .toward_ipa = true, + .channel = { + .tre_count = 256, + .event_count = 256, + .tlv_count = 20, + }, + .endpoint = { + .config = { + .resource_group = IPA_RSRC_GROUP_SRC_UL, + .dma_mode = true, + .dma_endpoint = IPA_ENDPOINT_AP_LAN_RX, + .tx = { + .seq_type = IPA_SEQ_DMA, + }, + }, + }, + }, + [IPA_ENDPOINT_AP_LAN_RX] = { + .ee_id = GSI_EE_AP, + .channel_id = 14, + .endpoint_id = 17, + .toward_ipa = false, + .channel = { + .tre_count = 256, + .event_count = 256, + .tlv_count = 9, + }, + .endpoint = { + .config = { + .resource_group = IPA_RSRC_GROUP_DST_UL, + .aggregation = true, + .status_enable = true, + .rx = { + .buffer_size = 8192, + .pad_align = ilog2(sizeof(u32)), + .aggr_time_limit = 500, + }, + }, + }, + }, + [IPA_ENDPOINT_AP_MODEM_TX] = { + .ee_id = GSI_EE_AP, + .channel_id = 11, + .endpoint_id = 2, + .toward_ipa = true, + .channel = { + .tre_count = 512, + .event_count = 512, + .tlv_count = 25, + }, + .endpoint = { + .filter_support = true, + .config = { + .resource_group = IPA_RSRC_GROUP_SRC_UL, + .checksum = true, + .qmap = true, + .status_enable = true, + .tx = { + .seq_type = IPA_SEQ_2_PASS_SKIP_LAST_UC, + .status_endpoint = + IPA_ENDPOINT_MODEM_AP_RX, + }, + }, + }, + }, + [IPA_ENDPOINT_AP_MODEM_RX] = { + .ee_id = GSI_EE_AP, + .channel_id = 1, + .endpoint_id = 24, + .toward_ipa = false, + .channel = { + .tre_count = 256, + .event_count = 256, + .tlv_count = 9, + }, + .endpoint = { + .config = { + .resource_group = IPA_RSRC_GROUP_DST_DL, + .checksum = true, + .qmap = true, + .aggregation = true, + .rx = { + .buffer_size = 8192, + .aggr_time_limit = 500, + .aggr_close_eof = true, + }, + }, + }, + }, + [IPA_ENDPOINT_MODEM_AP_TX] = { + .ee_id = GSI_EE_MODEM, + .channel_id = 0, + .endpoint_id = 12, + .toward_ipa = true, + .endpoint = { + .filter_support = true, + }, + }, + [IPA_ENDPOINT_MODEM_AP_RX] = { + .ee_id = GSI_EE_MODEM, + .channel_id = 7, + .endpoint_id = 22, + .toward_ipa = false, + }, + [IPA_ENDPOINT_MODEM_DL_NLO_TX] = { + .ee_id = GSI_EE_MODEM, + .channel_id = 2, + .endpoint_id = 15, + .toward_ipa = true, + .endpoint = { + .filter_support = true, + }, + }, +}; + /* Source resource configuration data for an SoC having IPA v5.5 */ static const struct ipa_resource ipa_resource_src[] = { [IPA_RESOURCE_TYPE_SRC_PKT_CONTEXTS] = { @@ -288,6 +422,148 @@ static const struct ipa_resource_data ipa_resource_data = { .resource_dst = ipa_resource_dst, }; +/* IPA-resident memory region data for the Eliza SoC */ +static const struct ipa_mem ipa_mem_local_data_eliza[] = { + { + .id = IPA_MEM_UC_EVENT_RING, + .offset = 0x0000, + .size = 0x1000, + .canary_count = 0, + }, + { + .id = IPA_MEM_UC_SHARED, + .offset = 0x1000, + .size = 0x0080, + .canary_count = 0, + }, + { + .id = IPA_MEM_UC_INFO, + .offset = 0x1080, + .size = 0x0200, + .canary_count = 0, + }, + { + .id = IPA_MEM_V4_FILTER_HASHED, + .offset = 0x1288, + .size = 0x0078, + .canary_count = 2, + }, + { + .id = IPA_MEM_V4_FILTER, + .offset = 0x1308, + .size = 0x0078, + .canary_count = 2, + }, + { + .id = IPA_MEM_V6_FILTER_HASHED, + .offset = 0x1388, + .size = 0x0078, + .canary_count = 2, + }, + { + .id = IPA_MEM_V6_FILTER, + .offset = 0x1408, + .size = 0x0078, + .canary_count = 2, + }, + { + .id = IPA_MEM_V4_ROUTE_HASHED, + .offset = 0x1488, + .size = 0x0098, + .canary_count = 2, + }, + { + .id = IPA_MEM_V4_ROUTE, + .offset = 0x1528, + .size = 0x0098, + .canary_count = 2, + }, + { + .id = IPA_MEM_V6_ROUTE_HASHED, + .offset = 0x15c8, + .size = 0x0098, + .canary_count = 2, + }, + { + .id = IPA_MEM_V6_ROUTE, + .offset = 0x1668, + .size = 0x0098, + .canary_count = 2, + }, + { + .id = IPA_MEM_MODEM_HEADER, + .offset = 0x1708, + .size = 0x0240, + .canary_count = 2, + }, + { + .id = IPA_MEM_AP_HEADER, + .offset = 0x1948, + .size = 0x01e0, + .canary_count = 0, + }, + { + .id = IPA_MEM_MODEM_PROC_CTX, + .offset = 0x1b40, + .size = 0x0b20, + .canary_count = 2, + }, + { + .id = IPA_MEM_AP_PROC_CTX, + .offset = 0x2660, + .size = 0x0200, + .canary_count = 0, + }, + { + .id = IPA_MEM_STATS_QUOTA_MODEM, + .offset = 0x2868, + .size = 0x0060, + .canary_count = 2, + }, + { + .id = IPA_MEM_STATS_QUOTA_AP, + .offset = 0x28c8, + .size = 0x0048, + .canary_count = 0, + }, + { + .id = IPA_MEM_STATS_TETHERING, + .offset = 0x2910, + .size = 0x03c0, + .canary_count = 0, + }, + { + .id = IPA_MEM_STATS_FILTER_ROUTE, + .offset = 0x2cd0, + .size = 0x0c40, + .canary_count = 2, + }, + { + .id = IPA_MEM_STATS_DROP, + .offset = 0x3910, + .size = 0x0020, + .canary_count = 0, + }, + { + .id = IPA_MEM_MODEM, + .offset = 0x3938, + .size = 0x0d48, + .canary_count = 2, + }, + { + .id = IPA_MEM_NAT_TABLE, + .offset = 0x4680, + .size = 0x0900, + .canary_count = 0, + }, + { + .id = IPA_MEM_PDN_CONFIG, + .offset = 0x4f88, + .size = 0x0050, + .canary_count = 2, + }, +}; + /* IPA-resident memory region data for an SoC having IPA v5.5 */ static const struct ipa_mem ipa_mem_local_data[] = { { @@ -442,6 +718,14 @@ static const struct ipa_mem ipa_mem_local_data[] = { }, }; +/* Memory configuration data for the Eliza SoC */ +static const struct ipa_mem_data ipa_mem_data_eliza = { + .local_count = ARRAY_SIZE(ipa_mem_local_data_eliza), + .local = ipa_mem_local_data_eliza, + .smem_size = 0x0000b000, + .fnr_idx_cnt = 68, +}; + /* Memory configuration data for an SoC having IPA v5.5 */ static const struct ipa_mem_data ipa_mem_data = { .local_count = ARRAY_SIZE(ipa_mem_local_data), @@ -449,6 +733,7 @@ static const struct ipa_mem_data ipa_mem_data = { .imem_addr = 0x14688000, .imem_size = 0x00002000, .smem_size = 0x0000b000, + .fnr_idx_cnt = 0, }; /* Interconnect rates are in 1000 byte/second units */ @@ -485,3 +770,16 @@ const struct ipa_data ipa_data_v5_5 = { .mem_data = &ipa_mem_data, .power_data = &ipa_power_data, }; + +/* Configuration data for the Eliza SoC (IPA v5.5). */ +const struct ipa_data ipa_data_v5_5_eliza = { + .version = IPA_VERSION_5_5, + .qsb_count = ARRAY_SIZE(ipa_qsb_data_eliza), + .qsb_data = ipa_qsb_data_eliza, + .modem_route_count = 11, + .endpoint_count = ARRAY_SIZE(ipa_gsi_endpoint_data_eliza), + .endpoint_data = ipa_gsi_endpoint_data_eliza, + .resource_data = &ipa_resource_data, + .mem_data = &ipa_mem_data_eliza, + .power_data = &ipa_power_data, +}; diff --git a/drivers/net/ipa/ipa.h b/drivers/net/ipa/ipa.h index 7ef10a4ff3..d2ceaea316 100644 --- a/drivers/net/ipa/ipa.h +++ b/drivers/net/ipa/ipa.h @@ -69,6 +69,7 @@ struct ipa_smp2p; * @modem_state: State of modem (stopped, running) * @modem_netdev: Network device structure used for modem * @qmi: QMI information + * @fnr_idx_cnt: Number of FnR counters */ struct ipa { struct gsi gsi; @@ -129,6 +130,8 @@ struct ipa { atomic_t modem_state; /* enum ipa_modem_state */ struct net_device *modem_netdev; struct ipa_qmi qmi; + + u8 fnr_idx_cnt; }; /** diff --git a/drivers/net/ipa/ipa_data.h b/drivers/net/ipa/ipa_data.h index 3eb9dc2ce3..da01fc84ed 100644 --- a/drivers/net/ipa/ipa_data.h +++ b/drivers/net/ipa/ipa_data.h @@ -181,6 +181,7 @@ struct ipa_resource_data { * @imem_addr: physical address of IPA region within IMEM * @imem_size: size in bytes of IPA IMEM region * @smem_size: size in bytes of the IPA SMEM region + * @fnr_idx_cnt: Number of FnR counters */ struct ipa_mem_data { u32 local_count; @@ -193,6 +194,8 @@ struct ipa_mem_data { u32 imem_size; /* DEPRECATED */ u32 smem_size; + + u8 fnr_idx_cnt; }; /** @@ -255,5 +258,6 @@ extern const struct ipa_data ipa_data_v4_11; extern const struct ipa_data ipa_data_v5_0; extern const struct ipa_data ipa_data_v5_2; extern const struct ipa_data ipa_data_v5_5; +extern const struct ipa_data ipa_data_v5_5_eliza; #endif /* _IPA_DATA_H_ */ diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index 14ac2d2faf..db2b951bbc 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -640,6 +640,14 @@ static int ipa_firmware_load(struct device *dev) } static const struct of_device_id ipa_match[] = { + { + .compatible = "qcom,eliza-ipa", + .data = &ipa_data_v5_5_eliza, + }, + { + .compatible = "qcom,sm8750-ipa", + .data = &ipa_data_v5_5_eliza, + }, { .compatible = "qcom,msm8998-ipa", .data = &ipa_data_v3_1, diff --git a/drivers/net/ipa/ipa_mem.c b/drivers/net/ipa/ipa_mem.c index 078d32a18d..fb04f953bf 100644 --- a/drivers/net/ipa/ipa_mem.c +++ b/drivers/net/ipa/ipa_mem.c @@ -631,6 +631,8 @@ int ipa_mem_init(struct ipa *ipa, struct platform_device *pdev, ipa->mem_count = mem_data->local_count; ipa->mem = mem_data->local; + ipa->fnr_idx_cnt = mem_data->fnr_idx_cnt; + /* Check the route and filter table memory regions */ if (!ipa_table_mem_valid(ipa, false)) return -EINVAL; diff --git a/drivers/net/ipa/ipa_qmi.c b/drivers/net/ipa/ipa_qmi.c index d771f3a71f..a5a5572c9c 100644 --- a/drivers/net/ipa/ipa_qmi.c +++ b/drivers/net/ipa/ipa_qmi.c @@ -74,6 +74,8 @@ #define IPA_MODEM_SERVICE_INS_ID 2 #define IPA_MODEM_SVC_VERS 1 +#define IPA_MODEM_FNR_IDX_START 128 + #define QMI_INIT_DRIVER_TIMEOUT 60000 /* A minute in milliseconds */ /* Send an INIT_COMPLETE indication message to the modem */ @@ -394,6 +396,22 @@ init_modem_driver_req(struct ipa_qmi *ipa_qmi) } } + if (ipa->version >= IPA_VERSION_4_5 && ipa->fnr_idx_cnt) { + mem = ipa_mem_find(ipa, IPA_MEM_STATS_FILTER_ROUTE); + if (mem && mem->size) { + req.hw_stats_filter_info_valid = 1; + req.hw_stats_filter_info.start_addr = + ipa->mem_offset + mem->offset; + req.hw_stats_filter_info.size = + ipa->fnr_idx_cnt * 16; + req.hw_stats_filter_info.start_index = + IPA_MODEM_FNR_IDX_START; + req.hw_stats_filter_info.end_index = + IPA_MODEM_FNR_IDX_START + + ipa->fnr_idx_cnt - 1; + } + } + return &req; } diff --git a/drivers/net/ipa/ipa_qmi_msg.c b/drivers/net/ipa/ipa_qmi_msg.c index 51dc13a577..160c0d2076 100644 --- a/drivers/net/ipa/ipa_qmi_msg.c +++ b/drivers/net/ipa/ipa_qmi_msg.c @@ -250,6 +250,43 @@ const struct qmi_elem_info ipa_mem_range_ei[] = { }, }; +/* QMI message structure definition for struct ipa_stats_filter */ +const struct qmi_elem_info ipa_stats_filter_ei[] = { + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = + sizeof_field(struct ipa_stats_filter, start_addr), + .offset = offsetof(struct ipa_stats_filter, + start_addr), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = + sizeof_field(struct ipa_stats_filter, size), + .offset = offsetof(struct ipa_stats_filter, size), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = + sizeof_field(struct ipa_stats_filter, start_index), + .offset = offsetof(struct ipa_stats_filter, + start_index), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = + sizeof_field(struct ipa_stats_filter, end_index), + .offset = offsetof(struct ipa_stats_filter, end_index), + }, + { + .data_type = QMI_EOTI, + }, +}; + /* QMI message structure definition for struct ipa_init_modem_driver_req */ const struct qmi_elem_info ipa_init_modem_driver_req_ei[] = { { @@ -640,6 +677,27 @@ const struct qmi_elem_info ipa_init_modem_driver_req_ei[] = { .offset = offsetof(struct ipa_init_modem_driver_req, hw_stats_drop_size), }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = + sizeof_field(struct ipa_init_modem_driver_req, + hw_stats_filter_info_valid), + .tlv_type = 0x23, + .offset = offsetof(struct ipa_init_modem_driver_req, + hw_stats_filter_info_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = + sizeof_field(struct ipa_init_modem_driver_req, + hw_stats_filter_info), + .tlv_type = 0x23, + .offset = offsetof(struct ipa_init_modem_driver_req, + hw_stats_filter_info), + .ei_array = ipa_stats_filter_ei, + }, { .data_type = QMI_EOTI, }, diff --git a/drivers/net/ipa/ipa_qmi_msg.h b/drivers/net/ipa/ipa_qmi_msg.h index 644b8c2710..3a2205c213 100644 --- a/drivers/net/ipa/ipa_qmi_msg.h +++ b/drivers/net/ipa/ipa_qmi_msg.h @@ -27,7 +27,7 @@ */ #define IPA_QMI_INDICATION_REGISTER_REQ_SZ 20 /* -> server handle */ #define IPA_QMI_INDICATION_REGISTER_RSP_SZ 7 /* <- server handle */ -#define IPA_QMI_INIT_DRIVER_REQ_SZ 162 /* client handle -> */ +#define IPA_QMI_INIT_DRIVER_REQ_SZ 186 /* client handle -> */ #define IPA_QMI_INIT_DRIVER_RSP_SZ 25 /* client handle <- */ #define IPA_QMI_INIT_COMPLETE_IND_SZ 7 /* <- server handle */ #define IPA_QMI_DRIVER_INIT_COMPLETE_REQ_SZ 4 /* -> server handle */ @@ -119,6 +119,13 @@ struct ipa_mem_range { u32 size; }; +struct ipa_stats_filter { + u32 start_addr; + u32 size; + u8 start_index; + u8 end_index; +}; + /* The message for the IPA_QMI_INIT_DRIVER request contains information * from the AP that affects modem initialization. */ @@ -216,6 +223,11 @@ struct ipa_init_modem_driver_req { u32 hw_stats_drop_base_addr; u8 hw_stats_drop_size_valid; u32 hw_stats_drop_size; + + /* Hardware filter statistics information. (IPA v4.5 and above) + */ + u8 hw_stats_filter_info_valid; + struct ipa_stats_filter hw_stats_filter_info; }; /* The response to a IPA_QMI_INIT_DRIVER request begins with a standard @@ -256,6 +268,7 @@ extern const struct qmi_elem_info ipa_init_complete_ind_ei[]; extern const struct qmi_elem_info ipa_mem_bounds_ei[]; extern const struct qmi_elem_info ipa_mem_array_ei[]; extern const struct qmi_elem_info ipa_mem_range_ei[]; +extern const struct qmi_elem_info ipa_stats_filter_ei[]; extern const struct qmi_elem_info ipa_init_modem_driver_req_ei[]; extern const struct qmi_elem_info ipa_init_modem_driver_rsp_ei[]; diff --git a/drivers/net/wireless/ath/ath12k/core.c b/drivers/net/wireless/ath/ath12k/core.c index 262a204530..4f03c6c718 100644 --- a/drivers/net/wireless/ath/ath12k/core.c +++ b/drivers/net/wireless/ath/ath12k/core.c @@ -1666,6 +1666,8 @@ static void ath12k_core_reset(struct work_struct *work) if (!(test_bit(ATH12K_FLAG_QMI_FW_READY_COMPLETE, &ab->dev_flags))) { ath12k_warn(ab, "ignore reset dev flags 0x%lx\n", ab->dev_flags); + if (ab->id.device == ATH12K_PCI_DEVICE_ID_WCN7860) + ath12k_coredump_collect(ab); return; } diff --git a/drivers/net/wireless/ath/ath12k/core.h b/drivers/net/wireless/ath/ath12k/core.h index a98fc6e069..47f420549f 100644 --- a/drivers/net/wireless/ath/ath12k/core.h +++ b/drivers/net/wireless/ath/ath12k/core.h @@ -159,8 +159,12 @@ enum ath12k_hw_rev { ATH12K_HW_IPQ5332_HW10, ATH12K_HW_QCC2072_HW10, ATH12K_HW_IPQ5424_HW10, + ATH12K_HW_WCN7860_HW20, }; +/* WCN7860 (peach); its QMI and DMA setup differ from the other chips */ +#define ATH12K_PCI_DEVICE_ID_WCN7860 0x110e + #define ATH12K_IRQ_NUM_MAX 57 #define ATH12K_EXT_IRQ_NUM_MAX 16 #define ATH12K_MAX_TCL_RING_NUM 3 diff --git a/drivers/net/wireless/ath/ath12k/mhi.c b/drivers/net/wireless/ath/ath12k/mhi.c index ee87f00bc5..3d262505c9 100644 --- a/drivers/net/wireless/ath/ath12k/mhi.c +++ b/drivers/net/wireless/ath/ath12k/mhi.c @@ -155,6 +155,7 @@ static void ath12k_mhi_op_status_cb(struct mhi_controller *mhi_cntrl, break; } + ath12k_dbg(ab, ATH12K_DBG_BOOT, "firmware entered RDDM\n"); if (!(test_bit(ATH12K_FLAG_UNREGISTERING, &ab->dev_flags))) { set_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags); set_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags); @@ -261,6 +262,9 @@ int ath12k_mhi_register(struct ath12k_pci *ab_pci) mhi_ctrl->status_cb = ath12k_mhi_op_status_cb; mhi_ctrl->read_reg = ath12k_mhi_op_read_reg; mhi_ctrl->write_reg = ath12k_mhi_op_write_reg; + /* WCN7860 loses the EE event; continue from BHI_EXECENV instead. */ + if (ab->id.device == ATH12K_PCI_DEVICE_ID_WCN7860) + mhi_ctrl->ee_reg_continue = true; ret = mhi_register_controller(mhi_ctrl, ab->hw_params->mhi_config); if (ret) { diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c index 6441927b53..715239112c 100644 --- a/drivers/net/wireless/ath/ath12k/pci.c +++ b/drivers/net/wireless/ath/ath12k/pci.c @@ -21,6 +21,7 @@ #define ATH12K_PCI_BAR_NUM 0 #define ATH12K_PCI_DMA_MASK 36 +#define ATH12K_PCI_DMA_MASK_WCN7860 28 #define ATH12K_PCI_IRQ_CE0_OFFSET 3 @@ -860,9 +861,19 @@ static int ath12k_pci_claim(struct ath12k_pci *ab_pci, struct pci_dev *pdev) goto disable_device; } - ab_pci->dma_mask = DMA_BIT_MASK(ATH12K_PCI_DMA_MASK); + /* WCN7860 firmware fails when its memory is allocated near the + * top of the 32-bit DMA space (0xfe400000 and up); the vendor + * driver keeps it low. Limit both masks to 256 MiB for it. + */ + if (device_id == ATH12K_PCI_DEVICE_ID_WCN7860) + ab_pci->dma_mask = DMA_BIT_MASK(ATH12K_PCI_DMA_MASK_WCN7860); + else + ab_pci->dma_mask = DMA_BIT_MASK(ATH12K_PCI_DMA_MASK); dma_set_mask(&pdev->dev, ab_pci->dma_mask); - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); + if (device_id == ATH12K_PCI_DEVICE_ID_WCN7860) + dma_set_coherent_mask(&pdev->dev, ab_pci->dma_mask); + else + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); pci_set_master(pdev); diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c index 280e50a1f3..ea667b686a 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.c +++ b/drivers/net/wireless/ath/ath12k/qmi.c @@ -11,6 +11,7 @@ #include "debug.h" #include #include +#include #include #include #include @@ -1660,6 +1661,59 @@ static const struct qmi_elem_info qmi_wlanfw_m3_info_resp_msg_v01_ei[] = { }, }; +static const struct qmi_elem_info qmi_wlanfw_tme_lite_info_req_msg_v01_ei[] = { + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof(enum qmi_wlanfw_tme_lite_file_type_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x01, + .offset = offsetof(struct qmi_wlanfw_tme_lite_info_req_msg_v01, + tme_file), + }, + { + .data_type = QMI_UNSIGNED_8_BYTE, + .elem_len = 1, + .elem_size = sizeof(u64), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_wlanfw_tme_lite_info_req_msg_v01, + addr), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x03, + .offset = offsetof(struct qmi_wlanfw_tme_lite_info_req_msg_v01, + size), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info qmi_wlanfw_tme_lite_info_resp_msg_v01_ei[] = { + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct qmi_response_type_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_wlanfw_tme_lite_info_resp_msg_v01, + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + static const struct qmi_elem_info qmi_wlanfw_aux_uc_info_req_msg_v01_ei[] = { { .data_type = QMI_UNSIGNED_8_BYTE, @@ -2058,6 +2112,13 @@ static const struct qmi_elem_info qmi_wlanfw_fw_ready_ind_msg_v01_ei[] = { }, }; +static const struct qmi_elem_info qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei[] = { + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + }, +}; + static const struct qmi_elem_info qmi_wlanfw_wlan_ini_req_msg_v01_ei[] = { { .data_type = QMI_OPT_FLAG, @@ -2254,6 +2315,8 @@ int ath12k_qmi_host_cap_send(struct ath12k_base *ab) req.bdf_support_valid = 1; req.bdf_support = 1; + /* Peach downloads phy_ucode20.elf as its M3. Advertise it. + */ if (ab->hw_params->fw.m3_loader == ath12k_m3_fw_loader_driver) { req.m3_support_valid = 1; req.m3_support = 1; @@ -3101,6 +3164,7 @@ int ath12k_qmi_load_bdf_qmi(struct ath12k_base *ab, else type = ATH12K_QMI_BDF_TYPE_BIN; + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi board data len %zu type %d\n", bd.len, type); break; case ATH12K_QMI_BDF_TYPE_REGDB: ret = ath12k_core_fetch_regdb(ab, &bd); @@ -3190,6 +3254,48 @@ static void ath12k_qmi_m3_free(struct ath12k_base *ab) m3_mem->size = 0; } +static int ath12k_qmi_load_mem_file(struct ath12k_base *ab, + struct m3_mem_region *mem, + const char *filename) +{ + const struct firmware *fw; + int ret; + + fw = ath12k_core_firmware_request(ab, filename); + if (IS_ERR(fw)) { + ret = PTR_ERR(fw); + ath12k_err(ab, "failed to load %s: %d\n", filename, ret); + return ret; + } + + if (mem->vaddr && mem->total_size < fw->size) { + dma_free_coherent(ab->dev, mem->total_size, mem->vaddr, + mem->paddr); + mem->vaddr = NULL; + mem->total_size = 0; + mem->size = 0; + } + + if (!mem->vaddr) { + mem->vaddr = dma_alloc_coherent(ab->dev, fw->size, &mem->paddr, + GFP_KERNEL); + if (!mem->vaddr) { + ath12k_err(ab, "failed to allocate %zu bytes for %s\n", + fw->size, filename); + release_firmware(fw); + return -ENOMEM; + } + mem->total_size = fw->size; + } + + memcpy(mem->vaddr, fw->data, fw->size); + mem->size = fw->size; + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi loaded %s size %zu addr %pad\n", + filename, fw->size, &mem->paddr); + release_firmware(fw); + return 0; +} + static int ath12k_qmi_m3_load(struct ath12k_base *ab) { struct m3_mem_region *m3_mem = &ab->qmi.m3_mem; @@ -3264,7 +3370,11 @@ int ath12k_qmi_wlanfw_m3_info_send(struct ath12k_base *ab) int ret = 0; if (ab->hw_params->fw.m3_loader == ath12k_m3_fw_loader_driver) { - ret = ath12k_qmi_m3_load(ab); + if (ab->id.device == ATH12K_PCI_DEVICE_ID_WCN7860) + ret = ath12k_qmi_load_mem_file(ab, &ab->qmi.m3_mem, + "phy_ucode20.elf"); + else + ret = ath12k_qmi_m3_load(ab); if (ret) { ath12k_err(ab, "failed to load m3 firmware: %d\n", ret); return ret; @@ -3430,6 +3540,204 @@ int ath12k_qmi_wlanfw_aux_uc_info_send(struct ath12k_base *ab) return ret; } +static const struct qmi_elem_info qmi_wlanfw_qdss_cfg_req_msg_v01_ei[] = { + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + total_size_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + total_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + seg_id_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + seg_id), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + data_valid), + }, + { + .data_type = QMI_DATA_LEN, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + data_len), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = QMI_WLANFW_MAX_DATA_SIZE_V01, + .elem_size = sizeof(u8), + .array_type = VAR_LEN_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + data), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + end_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01, + end), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info qmi_wlanfw_qdss_cfg_resp_msg_v01_ei[] = { + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct qmi_response_type_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_wlanfw_qdss_trace_config_download_resp_msg_v01, + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +/* Stock sends this after PHY ucode. A missing file is not fatal there. */ +static int ath12k_qmi_qdss_cfg_send(struct ath12k_base *ab) +{ + struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01 *req; + struct qmi_wlanfw_qdss_trace_config_download_resp_msg_v01 resp = {}; + const struct firmware *fw; + const u8 *tmp; + struct qmi_txn txn; + u32 remaining; + int ret; + + if (ab->id.device != ATH12K_PCI_DEVICE_ID_WCN7860) + return 0; + + fw = ath12k_core_firmware_request(ab, "qdss_trace_config_v2.cfg"); + if (IS_ERR(fw)) { + ath12k_warn(ab, "qmi qdss config missing: %ld\n", PTR_ERR(fw)); + return 0; + } + + req = kzalloc(sizeof(*req), GFP_KERNEL); + if (!req) { + release_firmware(fw); + return -ENOMEM; + } + + tmp = fw->data; + remaining = fw->size; + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi qdss config len %zu\n", fw->size); + + while (remaining) { + req->total_size_valid = 1; + req->total_size = remaining; + req->seg_id_valid = 1; + req->data_valid = 1; + req->end_valid = 1; + req->end = 0; + + if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) + req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01; + else { + req->data_len = remaining; + req->end = 1; + } + + memcpy(req->data, tmp, req->data_len); + + ret = qmi_txn_init(&ab->qmi.handle, &txn, + qmi_wlanfw_qdss_cfg_resp_msg_v01_ei, &resp); + if (ret < 0) + goto out; + + ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, + QMI_WLANFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_V01, + QMI_WLANFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_MSG_V01_MAX_LEN, + qmi_wlanfw_qdss_cfg_req_msg_v01_ei, req); + if (ret < 0) { + qmi_txn_cancel(&txn); + ath12k_warn(ab, "qmi failed to send qdss config, err = %d\n", + ret); + goto out; + } + + ret = qmi_txn_wait(&txn, + msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS)); + if (ret < 0) { + ath12k_warn(ab, "qmi qdss config request timed out: %d\n", + ret); + goto out; + } + + if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { + ath12k_warn(ab, "qmi qdss config failed, result: %d, err: %d\n", + resp.resp.result, resp.resp.error); + ret = -EINVAL; + goto out; + } + + remaining -= req->data_len; + tmp += req->data_len; + req->seg_id++; + } + + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi qdss config sent\n"); + ret = 0; +out: + kfree(req); + release_firmware(fw); + return ret; +} + static int ath12k_qmi_wlanfw_mode_send(struct ath12k_base *ab, enum ath12k_qmi_firmware_mode mode) { @@ -3789,6 +4097,84 @@ int ath12k_qmi_event_mem_request(struct ath12k_qmi *qmi) return ret; } +/* Peach needs the TME-Lite ELF in DMA memory, then its physical + * address over QMI, after target capabilities and before board data. + * Stock cnss does this in cnss_fw_mem_ready_hdlr. The OnePlus 13s + * mainline port (pagani) ties a missing send to the set-mode timeout. + */ +static int ath12k_qmi_tme_lite_info_send(struct ath12k_base *ab) +{ + struct qmi_wlanfw_tme_lite_info_req_msg_v01 req = {}; + struct qmi_wlanfw_tme_lite_info_resp_msg_v01 resp = {}; + const struct firmware *fw; + struct qmi_txn txn; + dma_addr_t paddr; + void *vaddr; + int ret; + + if (ab->id.device != ATH12K_PCI_DEVICE_ID_WCN7860) + return 0; + + fw = ath12k_core_firmware_request(ab, "tmel_peach_20.elf"); + if (IS_ERR(fw)) { + ret = PTR_ERR(fw); + ath12k_err(ab, "failed to load tmel_peach_20.elf: %d\n", ret); + return ret; + } + + vaddr = dma_alloc_coherent(ab->dev, fw->size, &paddr, GFP_KERNEL); + if (!vaddr) { + ret = -ENOMEM; + goto release_fw; + } + memcpy(vaddr, fw->data, fw->size); + + req.tme_file = WLANFW_TME_LITE_PATCH_FILE_V01; + req.addr = paddr; + req.size = fw->size; + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi tme-lite addr %pad size %zu\n", + &paddr, fw->size); + + ret = qmi_txn_init(&ab->qmi.handle, &txn, + qmi_wlanfw_tme_lite_info_resp_msg_v01_ei, &resp); + if (ret < 0) + goto free_dma; + + ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, + QMI_WLANFW_TME_LITE_INFO_REQ_V01, + QMI_WLANFW_TME_LITE_INFO_REQ_MSG_V01_MAX_MSG_LEN, + qmi_wlanfw_tme_lite_info_req_msg_v01_ei, &req); + if (ret < 0) { + qmi_txn_cancel(&txn); + ath12k_warn(ab, "qmi failed to send TME-Lite info request: %d\n", + ret); + goto free_dma; + } + + ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH12K_QMI_WLANFW_TIMEOUT_MS)); + if (ret < 0) { + ath12k_warn(ab, "qmi failed TME-Lite info request: %d\n", ret); + goto free_dma; + } + + if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { + ath12k_warn(ab, "qmi TME-Lite info request failed, result: %d err: %d\n", + resp.resp.result, resp.resp.error); + ret = -EINVAL; + goto free_dma; + } + + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi tme-lite info sent, %zu bytes\n", + fw->size); + ret = 0; + +free_dma: + dma_free_coherent(ab->dev, fw->size, vaddr, paddr); +release_fw: + release_firmware(fw); + return ret; +} + /* clang stack usage explodes if this is inlined */ static noinline_for_stack int ath12k_qmi_event_load_bdf(struct ath12k_qmi *qmi) @@ -3803,10 +4189,18 @@ int ath12k_qmi_event_load_bdf(struct ath12k_qmi *qmi) return ret; } + ret = ath12k_qmi_tme_lite_info_send(ab); + if (ret < 0) + ath12k_warn(ab, "qmi tme-lite info send failed: %d\n", ret); + ret = ath12k_qmi_load_bdf_qmi(ab, ATH12K_QMI_BDF_TYPE_REGDB); if (ret < 0) { ath12k_warn(ab, "qmi failed to load regdb file:%d\n", ret); - return ret; + /* WCN7860 has no upstream regdb in board-2.bin. Keep going + * so the stock board.bin is still sent. + */ + if (ab->id.device != ATH12K_PCI_DEVICE_ID_WCN7860) + return ret; } ret = ath12k_qmi_load_bdf_qmi(ab, ATH12K_QMI_BDF_TYPE_ELF); @@ -3835,7 +4229,11 @@ int ath12k_qmi_event_load_bdf(struct ath12k_qmi *qmi) } } - return ret; + ret = ath12k_qmi_qdss_cfg_send(ab); + if (ret < 0) + ath12k_warn(ab, "qmi qdss config send failed: %d\n", ret); + + return 0; } static void ath12k_qmi_msg_mem_request_cb(struct qmi_handle *qmi_hdl, @@ -3907,6 +4305,19 @@ static void ath12k_qmi_msg_fw_ready_cb(struct qmi_handle *qmi_hdl, ath12k_qmi_driver_event_post(qmi, ATH12K_QMI_EVENT_FW_READY, NULL); } +static void ath12k_qmi_msg_cold_boot_cal_done_cb(struct qmi_handle *qmi_hdl, + struct sockaddr_qrtr *sq, + struct qmi_txn *txn, + const void *decoded) +{ + struct ath12k_qmi *qmi = container_of(qmi_hdl, struct ath12k_qmi, handle); + struct ath12k_base *ab = qmi->ab; + + if (ab->id.device == ATH12K_PCI_DEVICE_ID_WCN7860) + ab->qmi.cal_done = 1; + ath12k_dbg(ab, ATH12K_DBG_QMI, "qmi cold boot calibration done\n"); +} + static const struct qmi_msg_handler ath12k_qmi_msg_handlers[] = { { .type = QMI_INDICATION, @@ -3929,6 +4340,13 @@ static const struct qmi_msg_handler ath12k_qmi_msg_handlers[] = { .decoded_size = sizeof(struct qmi_wlanfw_fw_ready_ind_msg_v01), .fn = ath12k_qmi_msg_fw_ready_cb, }, + { + .type = QMI_INDICATION, + .msg_id = QMI_WLFW_COLD_BOOT_CAL_DONE_IND_V01, + .ei = qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei, + .decoded_size = sizeof(struct qmi_wlanfw_cold_boot_cal_done_ind_msg_v01), + .fn = ath12k_qmi_msg_cold_boot_cal_done_cb, + }, /* end of list */ {}, diff --git a/drivers/net/wireless/ath/ath12k/qmi.h b/drivers/net/wireless/ath/ath12k/qmi.h index 6da10f3cb5..5571556761 100644 --- a/drivers/net/wireless/ath/ath12k/qmi.h +++ b/drivers/net/wireless/ath/ath12k/qmi.h @@ -30,6 +30,7 @@ #define QMI_WLFW_REQUEST_MEM_IND_V01 0x0035 #define QMI_WLFW_FW_MEM_READY_IND_V01 0x0037 #define QMI_WLFW_FW_READY_IND_V01 0x0038 +#define QMI_WLFW_COLD_BOOT_CAL_DONE_IND_V01 0x003E #define QMI_WLANFW_MAX_DATA_SIZE_V01 6144 @@ -374,6 +375,10 @@ struct qmi_wlanfw_fw_ready_ind_msg_v01 { char placeholder; }; +struct qmi_wlanfw_cold_boot_cal_done_ind_msg_v01 { + char placeholder; +}; + #define QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN 0 #define QMI_WLANFW_CAP_REQ_V01 0x0024 @@ -526,6 +531,51 @@ struct qmi_wlanfw_m3_info_resp_msg_v01 { struct qmi_response_type_v01 resp; }; +#define QMI_WLANFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_V01 0x0044 +#define QMI_WLANFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_MSG_V01_MAX_LEN 6167 +#define QMI_WLANFW_QDSS_TRACE_CONFIG_DOWNLOAD_RESP_MSG_V01_MAX_LEN 7 +struct qmi_wlanfw_qdss_trace_config_download_req_msg_v01 { + u8 total_size_valid; + u32 total_size; + u8 seg_id_valid; + u32 seg_id; + u8 data_valid; + u32 data_len; + u8 data[QMI_WLANFW_MAX_DATA_SIZE_V01]; + u8 end_valid; + u8 end; +}; + +struct qmi_wlanfw_qdss_trace_config_download_resp_msg_v01 { + struct qmi_response_type_v01 resp; +}; + +/* WCN7860 (peach) needs this before board data. Stock cnss sends + * tmel_peach_20.elf here. Without it the secured PHY init faults and the + * later WLAN mode request times out. + */ +#define QMI_WLANFW_TME_LITE_INFO_REQ_MSG_V01_MAX_MSG_LEN 25 +#define QMI_WLANFW_TME_LITE_INFO_RESP_MSG_V01_MAX_MSG_LEN 7 +#define QMI_WLANFW_TME_LITE_INFO_REQ_V01 0x005B +#define QMI_WLANFW_TME_LITE_INFO_RESP_V01 0x005B + +enum qmi_wlanfw_tme_lite_file_type_v01 { + WLANFW_TME_LITE_PATCH_FILE_V01 = 0, + WLANFW_TME_LITE_OEM_FUSE_FILE_V01 = 1, + WLANFW_TME_LITE_RPR_FILE_V01 = 2, + WLANFW_TME_LITE_DPR_FILE_V01 = 3, +}; + +struct qmi_wlanfw_tme_lite_info_req_msg_v01 { + enum qmi_wlanfw_tme_lite_file_type_v01 tme_file; + u64 addr; + u32 size; +}; + +struct qmi_wlanfw_tme_lite_info_resp_msg_v01 { + struct qmi_response_type_v01 resp; +}; + #define QMI_WLANFW_AUX_UC_INFO_REQ_MSG_V01_MAX_MSG_LEN 18 #define QMI_WLANFW_AUX_UC_INFO_REQ_V01 0x005A diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal.c b/drivers/net/wireless/ath/ath12k/wifi7/hal.c index a0a1902fb4..7175383cee 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal.c @@ -57,6 +57,14 @@ static const struct ath12k_hw_version_map ath12k_wifi7_hw_ver_map[] = { .hal_params = &ath12k_hw_hal_params_ipq5332, .hw_regs = &ipq5424_regs, }, + /* WCN7860 (peach) has the QCC2072 UMAC: same regs and descriptors */ + [ATH12K_HW_WCN7860_HW20] = { + .hal_ops = &hal_qcc2072_ops, + .hal_desc_sz = sizeof(struct hal_rx_desc_qcc2072), + .tcl_to_wbm_rbm_map = ath12k_hal_tcl_to_wbm_rbm_map_wcn7850, + .hal_params = &ath12k_hw_hal_params_wcn7850, + .hw_regs = &qcc2072_regs, + }, }; int ath12k_wifi7_hal_init(struct ath12k_base *ab) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index 7b86f324b2..095a0bc1ed 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -806,6 +806,104 @@ static const struct ath12k_hw_params ath12k_wifi7_hw_params[] = { .max_client_dbs_sbs = 128, }, + .host_alloc_ml_id = false, + }, { + .name = "wcn7860 hw2.0", + .hw_rev = ATH12K_HW_WCN7860_HW20, + + .fw = { + .dir = "WCN7860/hw2.0", + .board_size = 256 * 1024, + .cal_offset = 256 * 1024, + .m3_loader = ath12k_m3_fw_loader_driver, + .download_aux_ucode = true, + }, + + .max_radios = 1, + .single_pdev_only = true, + .qmi_service_ins_id = ATH12K_QMI_WLFW_SERVICE_INS_ID_V01_WCN7850, + .internal_sleep_clock = true, + + .hw_ops = &qcc2072_ops, + .ring_mask = &ath12k_wifi7_hw_ring_mask_wcn7850, + + .host_ce_config = ath12k_wifi7_host_ce_config_wcn7850, + .ce_count = 9, + .target_ce_config = ath12k_wifi7_target_ce_config_wlan_wcn7850, + .target_ce_count = 9, + .svc_to_ce_map = + ath12k_wifi7_target_service_to_ce_map_wlan_wcn7850, + .svc_to_ce_map_len = 14, + + .rxdma1_enable = false, + .num_rxdma_per_pdev = 2, + .num_rxdma_dst_ring = 1, + .rx_mac_buf_ring = true, + .vdev_start_delay = true, + + .interface_modes = BIT(NL80211_IFTYPE_STATION) | + BIT(NL80211_IFTYPE_AP) | + BIT(NL80211_IFTYPE_P2P_DEVICE) | + BIT(NL80211_IFTYPE_P2P_CLIENT) | + BIT(NL80211_IFTYPE_P2P_GO), + .supports_monitor = true, + .supports_cong_ctrl_max_msdus = false, + + .idle_ps = true, + .download_calib = false, + .supports_suspend = true, + .tcl_ring_retry = false, + .reoq_lut_support = false, + .supports_shadow_regs = true, + + .num_tcl_banks = 7, + .max_tx_ring = 3, + + .mhi_config = &ath12k_wifi7_mhi_config_wcn7850, + + .wmi_init = ath12k_wifi7_wmi_init_wcn7850, + + /* Not QDSS_CFG_MISS: with it peach starts initializing at + * once, rejects aux and qdss with err 90 (incompatible + * state) and asserts in the aux MAC wakeup. Stock cnss2 sets + * it only when the qdss file is missing. 0x50. + */ + .qmi_cnss_feature_bitmap = BIT(CNSS_PCIE_PERST_NO_PULL_V01) | + BIT(CNSS_AUX_UC_SUPPORT_V01), + + .rfkill_pin = 0, + .rfkill_cfg = 0, + .rfkill_on_level = 0, + + .rddm_size = 0x780000, + + .def_num_link = 2, + .max_mlo_peer = 32, + + .otp_board_id_register = 0, + + .supports_sta_ps = true, + + .acpi_guid = &wcn7850_uuid, + .supports_dynamic_smps_6ghz = false, + + .iova_mask = 0, + + .supports_aspm = true, + + .ce_ie_addr = NULL, + .ce_remap = NULL, + .bdf_addr_offset = 0, + + .current_cc_support = true, + + .dp_primary_link_only = false, + .client = { + .max_client_single = 512, + .max_client_dbs = 128, + .max_client_dbs_sbs = 128, + }, + .host_alloc_ml_id = false, }, { diff --git a/drivers/net/wireless/ath/ath12k/wifi7/pci.c b/drivers/net/wireless/ath/ath12k/wifi7/pci.c index 6c96b52dec..0c0625c48f 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/pci.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/pci.c @@ -20,6 +20,7 @@ #define QCN9274_DEVICE_ID 0x1109 #define WCN7850_DEVICE_ID 0x1107 #define QCC2072_DEVICE_ID 0x1112 +#define WCN7860_DEVICE_ID ATH12K_PCI_DEVICE_ID_WCN7860 #define ATH12K_PCI_W7_SOC_HW_VERSION_1 1 #define ATH12K_PCI_W7_SOC_HW_VERSION_2 2 @@ -35,6 +36,7 @@ static const struct pci_device_id ath12k_wifi7_pci_id_table[] = { { PCI_VDEVICE(QCOM, QCN9274_DEVICE_ID) }, { PCI_VDEVICE(QCOM, WCN7850_DEVICE_ID) }, { PCI_VDEVICE(QCOM, QCC2072_DEVICE_ID) }, + { PCI_VDEVICE(QCOM, WCN7860_DEVICE_ID) }, {} }; @@ -165,6 +167,19 @@ static int ath12k_wifi7_pci_probe(struct pci_dev *pdev, /* there is only one version till now */ ab->hw_rev = ATH12K_HW_QCC2072_HW10; break; + case WCN7860_DEVICE_ID: + /* + * WCN7860 (peach) reports SOC hw version 2 like WCN7850, but + * its UMAC, window register and RX descriptors are QCC2072's. + */ + ab->id.bdf_search = ATH12K_BDF_SEARCH_BUS_AND_BOARD; + ab_pci->msi_config = &ath12k_wifi7_msi_config[0]; + ab->static_window_map = false; + ab_pci->pci_ops = &ath12k_wifi7_pci_ops_wcn7850; + ab_pci->window_reg_addr = WINDOW_REG_ADDRESS_QCC2072; + ab->target_mem_mode = ATH12K_QMI_MEMORY_MODE_DEFAULT; + ab->hw_rev = ATH12K_HW_WCN7860_HW20; + break; default: dev_err(&pdev->dev, "Unknown Wi-Fi 7 PCI device found: 0x%x\n", pci_dev->device); diff --git a/drivers/net/wireless/ath/ath12k/wmi.c b/drivers/net/wireless/ath/ath12k/wmi.c index d5160af60e..7081540994 100644 --- a/drivers/net/wireless/ath/ath12k/wmi.c +++ b/drivers/net/wireless/ath/ath12k/wmi.c @@ -6987,6 +6987,8 @@ static int ath12k_reg_chan_list_event(struct ath12k_base *ab, struct sk_buff *sk * not going to create new regd for it */ ret = ATH12K_REG_STATUS_VALID; + if (reg_info->phy_id < ab->num_radios) + pdev_idx = reg_info->phy_id; goto mem_free; } diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index b58a607b71..eafb571200 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -1143,37 +1143,50 @@ static void qcom_pcie_deinit_2_7_0(struct qcom_pcie *pcie) static int qcom_pcie_config_sid_1_9_0(struct qcom_pcie *pcie) { - /* iommu map structure */ - struct { - u32 bdf; - u32 phandle; - u32 smmu_sid; - u32 smmu_sid_len; - } *map; + /* + * iommu-map entries are , where the IOMMU + * specifier has #iommu-cells cells (1 or 2). Only the first specifier + * cell (the SID) is used here. + */ void __iomem *bdf_to_sid_base = pcie->parf + PARF_BDF_TO_SID_TABLE_N; struct device *dev = pcie->pci->dev; u8 qcom_pcie_crc8_table[CRC8_TABLE_SIZE]; - int i, nr_map, size = 0; + struct device_node *iommu_np; + u32 iommu_cells = 1; + int i, nr_map, stride, size = 0; u32 smmu_sid_base; + u32 *map; u32 val; of_get_property(dev->of_node, "iommu-map", &size); if (!size) return 0; - /* Enable BDF to SID translation by disabling bypass mode (default) */ - val = readl(pcie->parf + PARF_BDF_TO_SID_CFG); - val &= ~BDF_TO_SID_BYPASS; - writel(val, pcie->parf + PARF_BDF_TO_SID_CFG); - map = kzalloc(size, GFP_KERNEL); if (!map) return -ENOMEM; - of_property_read_u32_array(dev->of_node, "iommu-map", (u32 *)map, + of_property_read_u32_array(dev->of_node, "iommu-map", map, size / sizeof(u32)); - nr_map = size / (sizeof(*map)); + iommu_np = of_find_node_by_phandle(map[1]); + if (iommu_np) { + of_property_read_u32(iommu_np, "#iommu-cells", &iommu_cells); + of_node_put(iommu_np); + } + stride = 3 + iommu_cells; + if ((size / sizeof(u32)) % stride) { + dev_err(dev, "iommu-map: bad length %d for %u iommu cells\n", + size, iommu_cells); + kfree(map); + return -EINVAL; + } + nr_map = size / sizeof(u32) / stride; + + /* Enable BDF to SID translation by disabling bypass mode (default) */ + val = readl(pcie->parf + PARF_BDF_TO_SID_CFG); + val &= ~BDF_TO_SID_BYPASS; + writel(val, pcie->parf + PARF_BDF_TO_SID_CFG); crc8_populate_msb(qcom_pcie_crc8_table, QCOM_PCIE_CRC8_POLYNOMIAL); @@ -1181,11 +1194,13 @@ static int qcom_pcie_config_sid_1_9_0(struct qcom_pcie *pcie) memset_io(bdf_to_sid_base, 0, CRC8_TABLE_SIZE * sizeof(u32)); /* Extract the SMMU SID base from the first entry of iommu-map */ - smmu_sid_base = map[0].smmu_sid; + smmu_sid_base = map[2]; /* Look for an available entry to hold the mapping */ for (i = 0; i < nr_map; i++) { - __be16 bdf_be = cpu_to_be16(map[i].bdf); + u32 bdf = map[i * stride]; + u32 sid = map[i * stride + 2]; + __be16 bdf_be = cpu_to_be16(bdf); u32 val; u8 hash; @@ -1208,7 +1223,7 @@ static int qcom_pcie_config_sid_1_9_0(struct qcom_pcie *pcie) } /* BDF [31:16] | SID [15:8] | NEXT [7:0] */ - val = map[i].bdf << 16 | (map[i].smmu_sid - smmu_sid_base) << 8 | 0; + val = bdf << 16 | (sid - smmu_sid_base) << 8 | 0; writel(val, bdf_to_sid_base + hash * sizeof(u32)); } diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 8616bacd86..1bf93a3f46 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -379,6 +379,8 @@ struct mhi_controller_config { * @fbc_download: MHI host needs to do complete image transfer (optional) * @wake_set: Device wakeup set flag * @no_m3: Device doesn't support M3 state + * @ee_reg_continue: Continue SBL/AMSS from BHI_EXECENV when the EE event is lost + * (optional; set by controllers such as ath12k WCN7860) * @irq_flags: irq flags passed to request_irq (optional) * @mru: the default MRU for the MHI device * @@ -465,6 +467,7 @@ struct mhi_controller { bool fbc_download; bool wake_set; bool no_m3; + bool ee_reg_continue; unsigned long irq_flags; u32 mru; }; diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8e251e1d84..8303a1b7b1 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -664,6 +664,15 @@ config SND_SOC_AW8738 SND_SOC_SIMPLE_AMPLIFIER, but additionally allows setting the operation mode using the Awinic-specific one-wire pulse control. +config SND_SOC_AW882308 + tristate "Awinic 0x2308 speaker amplifier (bring-up)" + depends on I2C + select REGMAP_I2C + help + Bring-up driver for the Awinic smart amplifiers with product id + 0x2308, as on the OnePlus 13. No speaker protection: the volume + control keeps an attenuation floor. + config SND_SOC_AW88395_LIB select CRC8 tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 3d122ace75..389b506ae1 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -49,6 +49,7 @@ snd-soc-audio-iio-aux-y := audio-iio-aux.o snd-soc-aw8738-y := aw8738.o snd-soc-aw87390-y := aw87390.o snd-soc-aw88081-y := aw88081.o +snd-soc-aw882308-y := aw882308.o snd-soc-aw88395-lib-y := aw88395/aw88395_lib.o \ aw88395/aw88395_device.o snd-soc-aw88395-y := aw88395/aw88395.o @@ -494,6 +495,7 @@ obj-$(CONFIG_SND_SOC_AUDIO_IIO_AUX) += snd-soc-audio-iio-aux.o obj-$(CONFIG_SND_SOC_AW8738) += snd-soc-aw8738.o obj-$(CONFIG_SND_SOC_AW87390) += snd-soc-aw87390.o obj-$(CONFIG_SND_SOC_AW88081) += snd-soc-aw88081.o +obj-$(CONFIG_SND_SOC_AW882308) += snd-soc-aw882308.o obj-$(CONFIG_SND_SOC_AW88395_LIB) += snd-soc-aw88395-lib.o obj-$(CONFIG_SND_SOC_AW88395) +=snd-soc-aw88395.o obj-$(CONFIG_SND_SOC_AW88166) +=snd-soc-aw88166.o diff --git a/sound/soc/codecs/aw882308.c b/sound/soc/codecs/aw882308.c new file mode 100644 index 0000000000..b0c4d910ba --- /dev/null +++ b/sound/soc/codecs/aw882308.c @@ -0,0 +1,515 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Bring-up driver for the Awinic smart amplifiers with product id 0x2308 + * that drive the OnePlus 13 (dodge) speakers. + * + * Register layout per the GPL-2.0 aw882xx driver OnePlus publishes for this + * phone (aw882xx_pid_2308_reg.h). This driver does no speaker protection: + * it applies an optional register table from firmware, runs the amplifier + * from register defaults otherwise, and caps the volume. + * + * Described in DT as "awinic,aw882308" (provisional) with reset-gpios and + * sound-name-prefix. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define AW_ID 0x00 /* write 0x55aa: soft reset */ +#define AW_SYSST 0x01 +#define AW_SYSINT 0x02 +#define AW_SYSINTM 0x03 +#define AW_SYSCTRL 0x04 +#define AW_SYSCTRL2 0x05 +#define AW_I2SCTRL1 0x06 +#define AW_REG_MAX 0x80 + +#define AW_CHIP_ID 0x2308 +#define AW_SOFT_RESET 0x55aa + +#define SYSST_PLLS BIT(0) +#define SYSST_CLKS BIT(4) +#define SYSST_SWS BIT(8) +#define SYSST_BSTS BIT(9) + +#define SYSCTRL_PWDN BIT(0) +#define SYSCTRL_AMPPD BIT(1) +#define SYSCTRL_HMUTE BIT(8) +#define SYSCTRL_I2STXEN BIT(13) +#define SYSCTRL_ULS_HMUTE BIT(15) + +#define SYSCTRL2_VOL GENMASK(9, 0) /* attenuation, ~0.094 dB/step */ +#define AW_MUTE_VOL 1023 + +#define I2SCTRL1_CHSEL GENMASK(11, 10) /* 1 left, 2 right, 3 mono */ +#define I2SCTRL1_I2SMD GENMASK(9, 8) +#define I2SCTRL1_I2SFS GENMASK(7, 6) /* 0 16b, 1 20b, 2 24b, 3 32b */ +#define I2SCTRL1_I2SBCK GENMASK(5, 4) /* 0 32fs, 1 48fs, 2 64fs */ +#define I2SCTRL1_I2SSR GENMASK(3, 0) /* 8 = 48 kHz */ + +/* Attenuation floor: 0 would be full scale. 320 steps is about -30 dB. */ +static unsigned int min_atten = 320; +module_param(min_atten, uint, 0444); +MODULE_PARM_DESC(min_atten, "Lowest attenuation the volume control allows (0..1023)"); + +static bool use_fw = true; +module_param(use_fw, bool, 0444); +MODULE_PARM_DESC(use_fw, "Apply aw882308-.bin register table if present"); + +struct aw882308 { + struct device *dev; + struct regmap *regmap; + struct gpio_desc *reset; + unsigned int atten; /* user attenuation, >= min_atten */ + unsigned int chsel; + unsigned int profile; /* table loaded: 0 Speaker, 1 Receiver */ + unsigned int want; /* profile for the next start */ + bool running; +}; + +static const struct regmap_config aw882308_regmap = { + .reg_bits = 8, + .val_bits = 16, + .max_register = AW_REG_MAX - 1, + .cache_type = REGCACHE_NONE, + .val_format_endian = REGMAP_ENDIAN_BIG, +}; + +static int aw882308_wait_sysst(struct aw882308 *aw, unsigned int want) +{ + unsigned int st = 0; + int i; + + for (i = 0; i < 50; i++) { + regmap_read(aw->regmap, AW_SYSST, &st); + if ((st & want) == want) + return 0; + usleep_range(2000, 2100); + } + dev_err(aw->dev, "SYSST 0x%04x, wanted 0x%04x\n", st, want); + return -ETIMEDOUT; +} + +static int aw882308_apply_fw(struct aw882308 *aw, unsigned int profile); + +static void aw882308_set_vol(struct aw882308 *aw, unsigned int v) +{ + regmap_update_bits(aw->regmap, AW_SYSCTRL2, SYSCTRL2_VOL, v); +} + +static void aw882308_stop(struct aw882308 *aw) +{ + aw882308_set_vol(aw, AW_MUTE_VOL); + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_ULS_HMUTE | SYSCTRL_HMUTE, + SYSCTRL_ULS_HMUTE | SYSCTRL_HMUTE); + usleep_range(5000, 5100); + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_I2STXEN, 0); + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_AMPPD, SYSCTRL_AMPPD); + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_PWDN, SYSCTRL_PWDN); + aw->running = false; +} + +static int aw882308_start(struct aw882308 *aw) +{ + unsigned int st, ctrl, ngcheck; + int ret; + + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_PWDN, 0); + usleep_range(2000, 2100); + ret = aw882308_wait_sysst(aw, SYSST_PLLS | SYSST_CLKS); + if (ret) + goto fail; + + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_AMPPD, 0); + usleep_range(1000, 1100); + /* Boost finished, clocks stable, PLL locked. */ + ngcheck = SYSST_BSTS | SYSST_CLKS | SYSST_PLLS; + ret = aw882308_wait_sysst(aw, ngcheck); + if (ret) + goto fail; + + regmap_write(aw->regmap, AW_SYSINT, 0xffff); /* read-clear status */ + regmap_read(aw->regmap, AW_SYSINT, &st); + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_ULS_HMUTE, 0); + aw882308_set_vol(aw, AW_MUTE_VOL); + regmap_update_bits(aw->regmap, AW_SYSCTRL, SYSCTRL_HMUTE, 0); + aw882308_set_vol(aw, aw->atten); + aw->running = true; + + regmap_read(aw->regmap, AW_SYSST, &st); + regmap_read(aw->regmap, AW_SYSCTRL, &ctrl); + dev_dbg(aw->dev, "running: SYSST 0x%04x SYSCTRL 0x%04x atten %u\n", + st, ctrl, aw->atten); + return 0; +fail: + regmap_read(aw->regmap, AW_SYSCTRL, &ctrl); + dev_err(aw->dev, "start failed, SYSCTRL 0x%04x\n", ctrl); + aw882308_stop(aw); + return ret; +} + +static int aw882308_mute(struct snd_soc_dai *dai, int mute, int stream) +{ + struct aw882308 *aw = snd_soc_component_get_drvdata(dai->component); + + if (stream != SNDRV_PCM_STREAM_PLAYBACK) + return 0; + if (mute) { + if (aw->running) + aw882308_stop(aw); + return 0; + } + if (aw->running) + return 0; + return aw882308_start(aw); +} + +static int aw882308_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct aw882308 *aw = snd_soc_component_get_drvdata(dai->component); + unsigned int width = params_physical_width(params); + unsigned int fs, bck, val; + + /* + * A profile picked while playing takes effect here, powered down and + * before the I2S setup below, which the table would otherwise undo. + */ + if (!aw->running && aw->want != aw->profile) { + if (aw882308_apply_fw(aw, aw->want)) + aw->want = aw->profile; + else + aw->profile = aw->want; + aw882308_stop(aw); + } + + if (params_rate(params) != 48000) { + dev_err(aw->dev, "only 48 kHz for now, got %u\n", params_rate(params)); + return -EINVAL; + } + switch (params_width(params)) { + case 16: + fs = 0; + break; + case 24: + fs = 2; + break; + case 32: + fs = 3; + break; + default: + return -EINVAL; + } + switch (width * params_channels(params)) { + case 32: + bck = 0; + break; + case 48: + bck = 1; + break; + case 64: + bck = 2; + break; + default: + dev_err(aw->dev, "unsupported frame of %u bits\n", + width * params_channels(params)); + return -EINVAL; + } + val = FIELD_PREP(I2SCTRL1_CHSEL, aw->chsel) | + FIELD_PREP(I2SCTRL1_I2SMD, 0) | + FIELD_PREP(I2SCTRL1_I2SFS, fs) | + FIELD_PREP(I2SCTRL1_I2SBCK, bck) | + FIELD_PREP(I2SCTRL1_I2SSR, 8); + regmap_update_bits(aw->regmap, AW_I2SCTRL1, + I2SCTRL1_CHSEL | I2SCTRL1_I2SMD | I2SCTRL1_I2SFS | + I2SCTRL1_I2SBCK | I2SCTRL1_I2SSR, val); + regmap_read(aw->regmap, AW_I2SCTRL1, &val); + dev_dbg(aw->dev, "I2SCTRL1 0x%04x\n", val); + return 0; +} + +static int aw882308_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) +{ + if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_I2S) + return -EINVAL; + if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC) + return -EINVAL; + return 0; +} + +static const struct snd_soc_dai_ops aw882308_dai_ops = { + .hw_params = aw882308_hw_params, + .set_fmt = aw882308_set_fmt, + .mute_stream = aw882308_mute, + .no_capture_mute = 1, + /* + * The amps lock their PLL to BCLK. AudioReach starts the back-end + * graph, and so BCLK, in the CPU DAI trigger, after prepare, so + * unmute (and start) from trigger, once the CPU DAI has run. + */ + .mute_unmute_on_trigger = 1, +}; + +static struct snd_soc_dai_driver aw882308_dai = { + .name = "aw882308-aif", + .playback = { + .stream_name = "Speaker Playback", + .channels_min = 1, + .channels_max = 2, + .rates = SNDRV_PCM_RATE_48000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | + SNDRV_PCM_FMTBIT_S32_LE, + }, + .ops = &aw882308_dai_ops, +}; + +/* The control is a gain: 0 is the quietest allowed, max is min_atten. */ +static int aw882308_vol_info(struct snd_kcontrol *kc, struct snd_ctl_elem_info *ui) +{ + ui->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + ui->count = 1; + ui->value.integer.min = 0; + ui->value.integer.max = AW_MUTE_VOL - min_atten; + return 0; +} + +static int aw882308_vol_get(struct snd_kcontrol *kc, struct snd_ctl_elem_value *uc) +{ + struct snd_soc_component *c = snd_kcontrol_chip(kc); + struct aw882308 *aw = snd_soc_component_get_drvdata(c); + + uc->value.integer.value[0] = AW_MUTE_VOL - aw->atten; + return 0; +} + +static int aw882308_vol_put(struct snd_kcontrol *kc, struct snd_ctl_elem_value *uc) +{ + struct snd_soc_component *c = snd_kcontrol_chip(kc); + struct aw882308 *aw = snd_soc_component_get_drvdata(c); + long v = uc->value.integer.value[0]; + + if (v < 0 || v > AW_MUTE_VOL - min_atten) + return -EINVAL; + if (aw->atten == AW_MUTE_VOL - v) + return 0; + aw->atten = AW_MUTE_VOL - v; + if (aw->running) + aw882308_set_vol(aw, aw->atten); + return 1; +} + +/* + * Stock profiles: 0 (Speaker) for music, 10 (Receiver) when the top + * speaker is the earpiece. Each has its own table, loaded only while the + * amplifier is powered down, in hw_params: a change takes effect when the + * next stream is set up. The volume floor applies to both. + */ +static const char * const aw882308_profiles[] = { "Speaker", "Receiver" }; +static SOC_ENUM_SINGLE_EXT_DECL(aw882308_profile_enum, aw882308_profiles); + +static int aw882308_profile_get(struct snd_kcontrol *kc, struct snd_ctl_elem_value *uc) +{ + struct snd_soc_component *c = snd_kcontrol_chip(kc); + struct aw882308 *aw = snd_soc_component_get_drvdata(c); + + uc->value.enumerated.item[0] = aw->want; + return 0; +} + +static int aw882308_profile_put(struct snd_kcontrol *kc, struct snd_ctl_elem_value *uc) +{ + struct snd_soc_component *c = snd_kcontrol_chip(kc); + struct aw882308 *aw = snd_soc_component_get_drvdata(c); + unsigned int p = uc->value.enumerated.item[0]; + + if (p >= ARRAY_SIZE(aw882308_profiles)) + return -EINVAL; + if (p == aw->want) + return 0; + aw->want = p; + return 1; +} + +static const struct snd_kcontrol_new aw882308_controls[] = { + SOC_ENUM_EXT("Amp Profile", aw882308_profile_enum, + aw882308_profile_get, aw882308_profile_put), + { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Amp Volume", + .info = aw882308_vol_info, + .get = aw882308_vol_get, + .put = aw882308_vol_put, + }, +}; + +static const struct snd_soc_dapm_widget aw882308_widgets[] = { + SND_SOC_DAPM_OUTPUT("SPK"), +}; + +static const struct snd_soc_dapm_route aw882308_routes[] = { + { "SPK", NULL, "Speaker Playback" }, +}; + +static const struct snd_soc_component_driver aw882308_component = { + .controls = aw882308_controls, + .num_controls = ARRAY_SIZE(aw882308_controls), + .dapm_widgets = aw882308_widgets, + .num_dapm_widgets = ARRAY_SIZE(aw882308_widgets), + .dapm_routes = aw882308_routes, + .num_dapm_routes = ARRAY_SIZE(aw882308_routes), +}; + +/* + * Optional register tables, firmware "aw882308-.bin" (Speaker) + * and "aw882308--receiver.bin": little-endian u16 (reg, value) + * pairs, e.g. made from the phone's own ACF by tools/aw-acf-regs.py. + * Never shipped in the repo. + */ +static int aw882308_apply_fw(struct aw882308 *aw, unsigned int profile) +{ + struct i2c_client *i2c = to_i2c_client(aw->dev); + const struct firmware *fw; + char name[40]; + unsigned int cur; + size_t i; + int n = 0; + + snprintf(name, sizeof(name), "aw882308-%02x%s.bin", i2c->addr, + profile ? "-receiver" : ""); + if (firmware_request_nowarn(&fw, name, aw->dev)) { + dev_info(aw->dev, "no %s, register table unchanged\n", name); + return -ENOENT; + } + for (i = 0; i + 4 <= fw->size; i += 4) { + unsigned int reg = get_unaligned_le16(fw->data + i); + unsigned int val = get_unaligned_le16(fw->data + i + 2); + + if (reg >= AW_REG_MAX || reg == AW_ID || reg == AW_SYSST || + reg == AW_SYSINT) + continue; + if (reg == AW_SYSINTM) + val = 0xffff; + if (reg == AW_SYSCTRL) { + /* Stay powered down and muted; no I/V feedback. */ + val |= SYSCTRL_PWDN | SYSCTRL_AMPPD | SYSCTRL_HMUTE | + SYSCTRL_ULS_HMUTE; + val &= ~SYSCTRL_I2STXEN; + } + if (reg == AW_SYSCTRL2) + val = (val & ~SYSCTRL2_VOL) | AW_MUTE_VOL; + if (reg == AW_I2SCTRL1) + aw->chsel = FIELD_GET(I2SCTRL1_CHSEL, val); + regmap_write(aw->regmap, reg, val); + n++; + } + release_firmware(fw); + regmap_read(aw->regmap, AW_SYSCTRL, &cur); + dev_info(aw->dev, "applied %d registers from %s, SYSCTRL 0x%04x chsel %u\n", + n, name, cur, aw->chsel); + return 0; +} + +static int aw882308_probe(struct i2c_client *i2c) +{ + struct device *dev = &i2c->dev; + struct aw882308 *aw; + unsigned int id = 0; + int ret; + + aw = devm_kzalloc(dev, sizeof(*aw), GFP_KERNEL); + if (!aw) + return -ENOMEM; + aw->dev = dev; + aw->atten = AW_MUTE_VOL; + /* Stock: 0x34 plays the left channel, 0x35 the right. */ + aw->chsel = (i2c->addr & 1) ? 2 : 1; + i2c_set_clientdata(i2c, aw); + + aw->regmap = devm_regmap_init_i2c(i2c, &aw882308_regmap); + if (IS_ERR(aw->regmap)) + return PTR_ERR(aw->regmap); + + /* Active-low reset: request asserted, then release. */ + aw->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(aw->reset)) + return dev_err_probe(dev, PTR_ERR(aw->reset), "reset gpio\n"); + if (aw->reset) { + usleep_range(1000, 1100); + gpiod_set_value_cansleep(aw->reset, 0); + usleep_range(2000, 2100); + } else { + dev_warn(dev, "no reset gpio\n"); + } + + ret = regmap_read(aw->regmap, AW_ID, &id); + if (ret) + return dev_err_probe(dev, ret, "no answer on I2C\n"); + if (id != AW_CHIP_ID) + return dev_err_probe(dev, -ENODEV, "chip id 0x%04x\n", id); + + regmap_write(aw->regmap, AW_ID, AW_SOFT_RESET); + usleep_range(2000, 2100); + if (use_fw) + aw882308_apply_fw(aw, 0); + aw882308_stop(aw); + + /* + * min_atten is a module parameter; keep it inside the volume field + * so the control range cannot underflow. + */ + min_atten = min(min_atten, AW_MUTE_VOL); + + /* Start quiet: attenuation 700 of 1023, or min_atten if higher. */ + aw->atten = max(min_atten, 700u); + dev_info(dev, "chip 0x%04x, chsel %u, atten floor %u\n", id, aw->chsel, + min_atten); + + return devm_snd_soc_register_component(dev, &aw882308_component, + &aw882308_dai, 1); +} + +static void aw882308_remove(struct i2c_client *i2c) +{ + struct aw882308 *aw = i2c_get_clientdata(i2c); + + aw882308_stop(aw); +} + +static const struct i2c_device_id aw882308_id[] = { + { "aw882308" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, aw882308_id); + +static const struct of_device_id aw882308_of_match[] = { + { .compatible = "awinic,aw882308" }, + { } +}; +MODULE_DEVICE_TABLE(of, aw882308_of_match); + +static struct i2c_driver aw882308_driver = { + .driver = { + .name = "aw882308", + .of_match_table = aw882308_of_match, + }, + .probe = aw882308_probe, + .remove = aw882308_remove, + .id_table = aw882308_id, +}; + +module_i2c_driver(aw882308_driver); + + + +MODULE_DESCRIPTION("Awinic 0x2308 speaker amplifier (bring-up)"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/qcom/sc8280xp.c b/sound/soc/qcom/sc8280xp.c index 4d48e1012c..ceb67e09df 100644 --- a/sound/soc/qcom/sc8280xp.c +++ b/sound/soc/qcom/sc8280xp.c @@ -193,6 +193,12 @@ static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd) snd_soc_limit_volume(card, "SpkrLeft PA Volume", 17); snd_soc_limit_volume(card, "SpkrRight PA Volume", 17); break; + case PRIMARY_MI2S_RX ... QUATERNARY_MI2S_TX: + case QUINARY_MI2S_RX ... QUINARY_MI2S_TX: + /* Format comes from .codec_dai_fmt on the board's priv_data. + * No headset behind an MI2S amplifier link. + */ + return 0; case DISPLAY_PORT_RX_0: /* DISPLAY_PORT dai ids are not contiguous */ dp_pcm_id = 0; @@ -556,6 +562,9 @@ static const struct qcom_snd_soc_common sm8750_priv_data = { .dapm_widgets = sc8280xp_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(sc8280xp_dapm_widgets), .wcd_jack = true, + .codec_dai_fmt = SND_SOC_DAIFMT_BC_FC | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_I2S, }; static const struct of_device_id snd_sc8280xp_dt_match[] = {