linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] pinctrl: qcom: add multi TLMM region option parameter
@ 2025-06-24  9:06 Yuanjie Yang
  2025-07-03 21:45 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Yuanjie Yang @ 2025-06-24  9:06 UTC (permalink / raw)
  To: andersson, linus.walleij, linux-arm-msm, linux-gpio, linux-kernel
  Cc: kernel, quic_tingweiz, quic_yuanjiey

Add support for selecting multiple TLMM regions using the
tlmm-test tool.
The current implementation only selects the TLMM Node region
0, which can lead to incorrect region selection.

QCS 615 TLMM Node dts reg:
	tlmm: pinctrl@3100000 {
		compatible = "qcom,qcs615-tlmm";
		reg = <0x0 0x03100000 0x0 0x300000>,
		      <0x0 0x03500000 0x0 0x300000>,
		      <0x0 0x03d00000 0x0 0x300000>;
		reg-names = "east",
			    "west",
			    "south";

QCS615 gpio57 is in the south region with an offset of 0x39000,
and its address is 0x3d39000. However, the default region selection
is region 0 (east region), resulting in a wrong calculated address
of 0x3139000.

Add a tlmm option parameter named tlmm_reg_name to select the region.
If the user does not input the parameter, the default region is 0.

Signed-off-by: Yuanjie Yang <quic_yuanjiey@quicinc.com>
---
Changes in v2:
- when input name can't match reg name, set error code
- Link to v1: https://lore.kernel.org/all/20250624065121.4000885-1-quic_yuanjiey@quicinc.com/

---
 drivers/pinctrl/qcom/tlmm-test.c | 47 +++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/qcom/tlmm-test.c b/drivers/pinctrl/qcom/tlmm-test.c
index 7b99e89e0f67..7d7fff538755 100644
--- a/drivers/pinctrl/qcom/tlmm-test.c
+++ b/drivers/pinctrl/qcom/tlmm-test.c
@@ -16,6 +16,7 @@
 #include <linux/of_irq.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
+#include <linux/slab.h>
 
 /*
  * This TLMM test module serves the purpose of validating that the TLMM driver
@@ -38,7 +39,10 @@
 #define TLMM_REG_SIZE		0x1000
 
 static int tlmm_test_gpio = -1;
+static char *tlmm_reg_name = "default_region";
+
 module_param_named(gpio, tlmm_test_gpio, int, 0600);
+module_param_named(name, tlmm_reg_name, charp, 0600);
 
 static struct {
 	void __iomem *base;
@@ -570,6 +574,47 @@ static const struct of_device_id tlmm_of_match[] = {
 	{}
 };
 
+static int tlmm_reg_base(struct device_node *tlmm, struct resource *res)
+{
+	const char **reg_names;
+	int count;
+	int ret;
+	int i;
+
+	count = of_property_count_strings(tlmm, "reg-names");
+	if (count <= 0) {
+		pr_err("failed to find tlmm reg name\n");
+		return count;
+	}
+
+	reg_names = kcalloc(count, sizeof(char *), GFP_KERNEL);
+	if (!reg_names)
+		return -ENOMEM;
+
+	ret = of_property_read_string_array(tlmm, "reg-names", reg_names, count);
+	if (ret != count) {
+		kfree(reg_names);
+		return -EINVAL;
+	}
+
+	if (!strcmp(tlmm_reg_name, "default_region")) {
+		ret = of_address_to_resource(tlmm, 0, res);
+	} else {
+		for (i = 0; i < count; i++) {
+			if (!strcmp(reg_names[i], tlmm_reg_name)) {
+				ret = of_address_to_resource(tlmm, i, res);
+				break;
+			}
+		}
+		if (i == count)
+			ret = -EINVAL;
+	}
+
+	kfree(reg_names);
+
+	return ret;
+}
+
 static int tlmm_test_init_suite(struct kunit_suite *suite)
 {
 	struct of_phandle_args args = {};
@@ -588,7 +633,7 @@ static int tlmm_test_init_suite(struct kunit_suite *suite)
 		return -EINVAL;
 	}
 
-	ret = of_address_to_resource(tlmm, 0, &res);
+	ret = tlmm_reg_base(tlmm, &res);
 	if (ret < 0)
 		return ret;
 

base-commit: 5d4809e25903ab8e74034c1f23c787fd26d52934
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] pinctrl: qcom: add multi TLMM region option parameter
  2025-06-24  9:06 [PATCH v2] pinctrl: qcom: add multi TLMM region option parameter Yuanjie Yang
@ 2025-07-03 21:45 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2025-07-03 21:45 UTC (permalink / raw)
  To: Yuanjie Yang
  Cc: andersson, linux-arm-msm, linux-gpio, linux-kernel, kernel,
	quic_tingweiz

On Tue, Jun 24, 2025 at 11:06 AM Yuanjie Yang <quic_yuanjiey@quicinc.com> wrote:

> Add support for selecting multiple TLMM regions using the
> tlmm-test tool.
> The current implementation only selects the TLMM Node region
> 0, which can lead to incorrect region selection.
>
> QCS 615 TLMM Node dts reg:
>         tlmm: pinctrl@3100000 {
>                 compatible = "qcom,qcs615-tlmm";
>                 reg = <0x0 0x03100000 0x0 0x300000>,
>                       <0x0 0x03500000 0x0 0x300000>,
>                       <0x0 0x03d00000 0x0 0x300000>;
>                 reg-names = "east",
>                             "west",
>                             "south";
>
> QCS615 gpio57 is in the south region with an offset of 0x39000,
> and its address is 0x3d39000. However, the default region selection
> is region 0 (east region), resulting in a wrong calculated address
> of 0x3139000.
>
> Add a tlmm option parameter named tlmm_reg_name to select the region.
> If the user does not input the parameter, the default region is 0.
>
> Signed-off-by: Yuanjie Yang <quic_yuanjiey@quicinc.com>

I don't understand the test tool but it looks reasonable to me
so patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-03 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24  9:06 [PATCH v2] pinctrl: qcom: add multi TLMM region option parameter Yuanjie Yang
2025-07-03 21:45 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).