Skip to contentSkip to conversation

Add pinctrl support for MSM8952

PATCH Superseded Muzaffer Kadir 2 participants 5 messages Sep 4

Subsystems (6)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add pinctrl support for MSM8952

MSM8952 has pinctrl system that is similar to MSM8917 pinctrl, but it has some differences in some of the pins and their functions. This driver tested on General Mobile GM 5 Plus.

---
Changes in v3:
- Added missing functions and removed unnecessary functions
with Konrad Dybcio's suggestions.
- Because of the changes on functions, I changed dt-bindings too.
Dropped Krzysztof's Reviewed-By attribute because of the changes.
- Rebased and Tested on linux-next, next-20260902 tag.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reworded dt-bindings commit as Krzysztof suggested.
- Added depends and default to kconfig entry of pinctrl
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Muzaffer Kadir (2):
dt-bindings: pinctrl: qcom: Add MSM8952 pinctrl
pinctrl: qcom: Add MSM8952 tlmm pinctrl driver

 .../bindings/pinctrl/qcom,msm8952-pinctrl.yaml     |  146 +++
 drivers/pinctrl/qcom/Kconfig.msm                   |    8 +
 drivers/pinctrl/qcom/Makefile                      |    1 +
 drivers/pinctrl/qcom/pinctrl-msm8952.c             | 1194 ++++++++++++++++++++
 4 files changed, 1349 insertions(+)

---
base-commit: 32b6ef9a5d0eca44f9cd91f52f4faa89f145a0de
change-id: 20260816-msm8952-pinctrl-bc2bd4849261

Best regards,

Signature · 1 line
Muzaffer Kadir <[email protected]>
#1 lore raw

PATCH v3 1/2 dt-bindings: pinctrl: qcom: Add MSM8952 pinctrl

Add device tree bindings for the TLMM pin controller found on the Qualcomm MSM8952 platform.

---
 .../bindings/pinctrl/qcom,msm8952-pinctrl.yaml     | 146 +++++++++++++++++++++
 1 file changed, 146 insertions(+)
Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml new file +146 -0
new file mode 100644
index 000000000000..cbd4a995ac63
@@ -0,0 +1,146 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/qcom,msm8952-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm MSM8952 TLMM pin controller
+
+maintainers:
+  - Muzaffer Kadir <[email protected]>
+
+description:
+  Top Level Mode Multiplexer pin controller in Qualcomm MSM8952 SoC.
+
+properties:
+  compatible:
+    const: qcom,msm8952-pinctrl
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  gpio-reserved-ranges:
+    minItems: 1
+    maxItems: 61
+
+  gpio-line-names:
+    maxItems: 134
+
+patternProperties:
+  "-state$":
+    oneOf:
+      - $ref: "#/$defs/qcom-msm8952-tlmm-state"
+      - patternProperties:
+          "-pins$":
+            $ref: "#/$defs/qcom-msm8952-tlmm-state"
+        additionalProperties: false
+
+$defs:
+  qcom-msm8952-tlmm-state:
+    type: object
+    description:
+      Pinctrl node's client devices use subnodes for desired pin configuration.
+      Client device subnodes use below standard properties.
+    $ref: qcom,tlmm-common.yaml#/$defs/qcom-tlmm-state
+    unevaluatedProperties: false
+
+    properties:
+      pins:
+        description:
+          List of gpio pins affected by the properties specified in this
+          subnode.
+        items:
+          oneOf:
+            - pattern: "^gpio([0-9]|[1-9][0-9]|1[0-2][0-9]|13[0-4])$"
+            - enum: [ qdsd_clk, qdsd_cmd, qdsd_data0, qdsd_data1, qdsd_data2,
+                      qdsd_data3, sdc1_clk, sdc1_cmd, sdc1_data, sdc1_rclk,
+                      sdc2_clk, sdc2_cmd, sdc2_data ]
+        minItems: 1
+        maxItems: 36
+
+      function:
+        description:
+          Specify the alternative function to be configured for the specified
+          pins.
+
+        enum: [ gpio, blsp_uart1, blsp_spi1, adsp_ext, blsp_i2c1, prng_rosc, qdss_cti_trig_out_b0,
+                qdss_cti_trig_out_a1, blsp_spi2, blsp_uart2, ldo_update, qdss_tracedata_b,
+                pbs1, pwr_modem_enabled_b, blsp_i2c3, gcc_gp2_clk_b, atest_combodac_to_gpio_native,
+                ldo_en, blsp_i2c2, gcc_gp1_clk_b, atest_gpsadc_dtest0_native, blsp_spi3,
+                blsp_uart3, sec_mi2s, pbs0, gcc_gp3_clk_b, blsp_spi4, blsp_uart4, pbs2,
+                pwr_nav_enabled_b, pwr_crypto_enabled_b, blsp_i2c4, blsp_spi5, blsp_uart5,
+                qdss_traceclk_a, atest_bbrx1, qdss_tracectl_b, qdss_cti_trig_in_b0, blsp_i2c6,
+                qdss_traceclk_b, atest_wlan0, m_voc, qdss_cti_trig_in_a0, atest_bbrx0, blsp_i2c5,
+                qdss_tracectl_a, atest_gpsadc_dtest1_native, qdss_tracedata_a, blsp_spi6,
+                blsp_uart6, atest_wlan1, mdp_vsync, pri_mi2s_mclk_a, sec_mi2s_mclk_a,
+                cam_mclk, cci_i2c, pwr_modem_enabled_a, cci_timer0, cci_timer1, pwr_nav_enabled_a,
+                pwr_crypto_enabled_a, cci_async, sd_write, qdss_cti_trig_out_a0, gcc_gp1_clk_a,
+                gcc_gp2_clk_a, gcc_gp3_clk_a, blsp6_spi, qdss_cti_trig_in_b1, uim_batt,
+                qdss_cti_trig_out_b1, uim1_data, uim1_clk, uim1_reset, uim1_present, uim2_data,
+                uim2_clk, uim2_reset, uim2_present, uim3_data, usb_fs, uim3_clk, uim3_reset,
+                uim3_present, atest_char3, dbg_out, bimc_dte0, sec_mi2s_mclk_b, pri_mi2s,
+                atest_char1, ebi_cdc, atest_char0, cdc_pdm0, pri_mi2s_mclk_b, lpass_slimbus,
+                lpass_slimbus0, lpass_slimbus1, wcss_bt, atest_char2, ebi_ch0, wcss_wlan2,
+                wcss_wlan1, wcss_wlan0, wcss_wlan, wcss_fm, ext_lpass, gcc_tlmm, dmic0_clk,
+                dmic0_data, qdss_cti_trig_in_a1, blsp_spi7, blsp_uart7, pri_mi2s_ws, wsa_io,
+                blsp_i2c7, blsp_spi8, blsp_uart8, blsp_i2c8, gcc_plltest, nav_pps_in_a,
+                pa_indicator, nav_pps_in_b, nav_pps, modem_tsync, nav_tsync, ssbi_wtr1,
+                gsm1_tx, gsm0_tx, atest_char, atest_tsens, bimc_dte1,
+                gp_mn, gp_pdm_0a, gp_pdm_0b, gp_pdm_1a, gp_pdm_1b,
+                gp_pdm_2a, gp_pdm_2b, gp0_clk, gp1_clk]
+
+    required:
+      - pins
+
+allOf:
+  - $ref: /schemas/pinctrl/qcom,tlmm-common.yaml#
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    msmgpio: pinctrl@1000000 {
+        compatible = "qcom,msm8952-pinctrl";
+        reg = <0x01000000 0x300000>;
+        interrupts = <GIC_SPI 208 IRQ_TYPE_LEVEL_HIGH>;
+        gpio-controller;
+        gpio-ranges = <&msmgpio 0 0 134>;
+        #gpio-cells = <2>;
+        interrupt-controller;
+        #interrupt-cells = <2>;
+
+        blsp1-uart2-sleep-state {
+            pins = "gpio4", "gpio5";
+            function = "gpio";
+
+            drive-strength = <2>;
+            bias-pull-down;
+        };
+
+        spi1-default-state {
+            spi-pins {
+                pins = "gpio0", "gpio1", "gpio3";
+                function = "blsp_spi1";
+
+                drive-strength = <12>;
+                bias-disable;
+            };
+
+            cs-pins {
+                pins = "gpio2";
+                function = "blsp_spi1";
+
+                drive-strength = <2>;
+                bias-disable;
+            };
+        };
+    };
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: pinctrl: qcom: Add MSM8952 pinctrl

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Inconsistent GPIO pin count constraints and off-by-one error in pins regex. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Inconsistent GPIO pin count constraints and off-by-one error in pins regex. --

commit ef5e44784233c9aad2c47ecf25b2914eec5fa936
Author: Muzaffer Kadir <[email protected]>

dt-bindings: pinctrl: qcom: Add MSM8952 pinctrl

This commit adds device tree bindings for the TLMM pin controller found on the Qualcomm MSM8952 platform.

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml new file +0 -0
new file mode 100644

[ ... ]

Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml line 27

Quoted 13 lines
Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml new file +13 -0
+properties:
+  compatible:
+    const: qcom,msm8952-pinctrl
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  gpio-reserved-ranges:
+    minItems: 1
+    maxItems: 61

[Severity: Low]
Should maxItems for gpio-reserved-ranges be 67 instead of 61?

The MSM8952 has 134 pins, meaning there can be up to 67 reserved ranges. The limit of 61 appears to be a leftover from a 122-pin part like the MSM8916. This restricts the maximum number of items incorrectly and rejects valid device trees that need to reserve more ranges up to the correct max of 67.

Quoted 3 lines
Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml new file +3 -0
+
+  gpio-line-names:
+    maxItems: 134

[ ... ]

Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml line 57

Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/qcom,msm8952-pinctrl.yaml new file +8 -0
+    properties:
+      pins:
+        description:
+          List of gpio pins affected by the properties specified in this
+          subnode.
+        items:
+          oneOf:
+            - pattern: "^gpio([0-9]|[1-9][0-9]|1[0-2][0-9]|13[0-4])$"

[Severity: Low]
Does this regex incorrectly allow "gpio134" to pass DT validation?

The regex matches up to 13[0-4], which includes "gpio134" (the 135th GPIO). However, the gpio-line-names property above is correctly restricted to 134 items (indices 0 to 133).

Since the maximum valid GPIO index is 133, a device tree author specifying "gpio134" in a configuration node will pass validation but fail at runtime.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v3 2/2 pinctrl: qcom: Add MSM8952 tlmm pinctrl driver

In reply to Muzaffer Kadir

MSM8952 has same pin count and similar pinctrl
functions mostly with msm8917, but some functions use different pins.

---
 drivers/pinctrl/qcom/Kconfig.msm       |    8 +
 drivers/pinctrl/qcom/Makefile          |    1 +
 drivers/pinctrl/qcom/pinctrl-msm8952.c | 1194 ++++++++++++++++++++++++++++++++
 3 files changed, 1203 insertions(+)
drivers/pinctrl/qcom/Kconfig.msm +8 -0
index 42875457b5fc..04673b4a0db6 100644
@@ -232,6 +232,14 @@ config PINCTRL_MSM8917
 	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
 	  Qualcomm TLMM block found on the Qualcomm MSM8917, MSM8937 platform.
 
+config PINCTRL_MSM8952
+	tristate "Qualcomm 8952 pin controller driver"
+	depends on ARM64 || COMPILE_TEST
+	default ARCH_QCOM
+	help
+	  This is the pinctrl, pinmux, pinconf and gpiolib driver for the
+	  Qualcomm TLMM block found on the Qualcomm MSM8952 platform.
+
 config PINCTRL_MSM8953
 	tristate "Qualcomm 8953 pin controller driver"
 	depends on ARM64 || COMPILE_TEST
drivers/pinctrl/qcom/Makefile +1 -0
index 987a79f9d4c4..50d32456e429 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_PINCTRL_MSM8X74)	+= pinctrl-msm8x74.o
 obj-$(CONFIG_PINCTRL_MSM8909)	+= pinctrl-msm8909.o
 obj-$(CONFIG_PINCTRL_MSM8916)	+= pinctrl-msm8916.o
 obj-$(CONFIG_PINCTRL_MSM8917)	+= pinctrl-msm8917.o
+obj-$(CONFIG_PINCTRL_MSM8952)	+= pinctrl-msm8952.o
 obj-$(CONFIG_PINCTRL_MSM8953)	+= pinctrl-msm8953.o
 obj-$(CONFIG_PINCTRL_MSM8976)	+= pinctrl-msm8976.o
 obj-$(CONFIG_PINCTRL_MSM8994)   += pinctrl-msm8994.o
drivers/pinctrl/qcom/pinctrl-msm8952.c new file +1194 -0

1,194 lines not on this page · raw message

Signature · 1 line
2.54.0
#4 lore raw

Re: [PATCH v3 2/2] pinctrl: qcom: Add MSM8952 tlmm pinctrl driver

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] The _groups arrays for qdss_tracedata_b and atest_combodac_to_gpio_native list several GPIO pins that do not actually include these functions in their corresponding PINGROUP macro definitions.

Pre-existing issues:
- [High] Use-After-Free on pin function memory during driver unbind due to devres LIFO ordering. --

commit e99bbcf6f4490c02c597eff9b2155619cf4f3564
Author: Muzaffer Kadir <[email protected]>

pinctrl: qcom: Add MSM8952 tlmm pinctrl driver

This commit adds the pinctrl, pinmux, pinconf, and gpiolib driver for the Qualcomm TLMM block found on the MSM8952 platform. It defines the available pins, their functions, and the pingroups for the SoC.

Quoted 4 lines
drivers/pinctrl/qcom/pinctrl-msm8952.c new file +0 -0
new file mode 100644

[ ... ]

Quoted 5 lines
drivers/pinctrl/qcom/pinctrl-msm8952.c new file +5 -0
+static const char *const qdss_tracedata_b_groups[] = {
+	"gpio8",  "gpio9",  "gpio12", "gpio13", "gpio23", "gpio42",
+	"gpio43", "gpio44", "gpio45", "gpio46", "gpio47", "gpio66",
+	"gpio86", "gpio87", "gpio88", "gpio92",
+};

[ ... ]

Quoted 5 lines
drivers/pinctrl/qcom/pinctrl-msm8952.c new file +5 -0
+static const char *const atest_combodac_to_gpio_native_groups[] = {
+	"gpio4",  "gpio12", "gpio13", "gpio20", "gpio21", "gpio28",  "gpio29",
+	"gpio30", "gpio39", "gpio40", "gpio41", "gpio42", "gpio43",  "gpio44",
+	"gpio45", "gpio46", "gpio47", "gpio48", "gpio67", "gpio115",
+};

[ ... ]

Quoted 1 line

+static const struct msm_pingroup msm8952_groups[] = {

[ ... ]

drivers/pinctrl/qcom/pinctrl-msm8952.c

Quoted 2 lines
drivers/pinctrl/qcom/pinctrl-msm8952.c new file +2 -0
+	PINGROUP(8, blsp_spi3, blsp_uart3, sec_mi2s, pbs0, NA, NA, NA, NA, NA,
+		 NA, NA, NA),

[Severity: Medium]
Will attempting to mux qdss_tracedata_b or atest_combodac_to_gpio_native on some of these advertised pins fail at runtime?

The qdss_tracedata_b_groups array claims that qdss_tracedata_b can be muxed on gpio8, gpio9, gpio12, and gpio13. Similarly, atest_combodac_to_gpio_native_groups claims gpio12, gpio13, etc., support it. However, looking at the hardware group definitions in msm8952_groups (such as for gpio8), these functions appear to be missing.

If a device tree configuration requests these mux mappings, will it cause msm_pinmux_set_mux to return -EINVAL because the requested function isn't actually in the pin's function list?

[ ... ]

drivers/pinctrl/qcom/pinctrl-msm8952.c line 1165

Quoted 4 lines
drivers/pinctrl/qcom/pinctrl-msm8952.c new file +4 -0
+static int msm8952_pinctrl_probe(struct platform_device *pdev)
+{
+	return msm_pinctrl_probe(pdev, &msm8952_pinctrl);
+}

[Severity: High]
This is a pre-existing issue, but does calling msm_pinctrl_probe expose a use-after-free regression during driver unbind?

Looking at msm_pinctrl_probe in drivers/pinctrl/qcom/pinctrl-msm.c:

msm_pinctrl_probe() {
    ...
    ret = devm_pinctrl_register_and_init(&pdev->dev, &pctrl->desc,
                                         pctrl, &pctrl->pctrl);
    ...
    for (i = 0; i < soc_data->nfunctions; i++) {
        func = &soc_data->functions[i];
        ret = pinmux_generic_add_pinfunction(pctrl->pctrl, func, NULL);
    ...
}

Because devm_kzalloc is used inside pinmux_generic_add_pinfunction, and it is called after the pinctrl device is registered with devm, the devres LIFO ordering means this memory will be freed before the pinctrl unregister action runs.

If the device is unbound, and a user concurrently reads the debugfs pinmux-functions file, could pinmux_generic_get_function_name dereference the freed memory while the radix tree still holds pointers to it?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2