All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
To: Tomasz Figa <tomasz.figa@gmail.com>,
	Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, linux-gpio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Sylwester Nawrocki <snawrocki@kernel.org>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Chanho Park <chanho61.park@samsung.com>
Subject: [PATCH 02/24] pinctrl: samsung: accept GPIO bank nodes with a suffix
Date: Fri, 31 Dec 2021 17:19:08 +0100	[thread overview]
Message-ID: <20211231161930.256733-3-krzysztof.kozlowski@canonical.com> (raw)
In-Reply-To: <20211231161930.256733-1-krzysztof.kozlowski@canonical.com>

Existing dt-bindings expected that each GPIO/pin bank within pin
controller has its own node with name matching the bank (e.g. gpa0,
gpx2) and "gpio-controller" property.  The node name is then used for
matching between driver data and DTS.

Newly introduced dtschema expects to have nodes ending with "-gpio-bank"
suffix, so rewrite bank-devicetree matching to look for old and new
style of naming.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 57 ++++++++++++++++++-----
 1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index f2864a7869b3..561853df8ef7 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -1011,13 +1011,56 @@ static void samsung_banks_of_node_put(struct samsung_pinctrl_drv_data *d)
 		of_node_put(bank->of_node);
 }
 
+/*
+ * Iterate over all driver pin banks to find one matching the name of node,
+ * skipping optional "-gpio" node suffix. When found, assign node to the bank.
+ */
+static void samsung_banks_of_node_get(struct device *dev,
+				      struct samsung_pinctrl_drv_data *d,
+				      struct device_node *node)
+{
+	const char *suffix = "-gpio-bank";
+	struct samsung_pin_bank *bank;
+	struct device_node *child;
+	/* Pin bank names are up to 4 characters */
+	char node_name[20];
+	unsigned int i;
+	size_t len;
+
+	bank = d->pin_banks;
+	for (i = 0; i < d->nr_banks; ++i, ++bank) {
+		strscpy(node_name, bank->name, sizeof(node_name));
+		len = strlcat(node_name, suffix, sizeof(node_name));
+		if (len == sizeof(sizeof(node_name))) {
+			dev_err(dev, "Too long pin bank name '%s', ignoring\n",
+				bank->name);
+			continue;
+		}
+
+		for_each_child_of_node(node, child) {
+			if (!of_find_property(child, "gpio-controller", NULL))
+				continue;
+			if (of_node_name_eq(child, node_name))
+				break;
+			else if (of_node_name_eq(child, bank->name))
+				break;
+		}
+
+		if (child)
+			bank->of_node = child;
+		else
+			dev_warn(dev, "Missing node for bank %s - invalid DTB\n",
+				 bank->name);
+		/* child reference dropped in samsung_drop_banks_of_node() */
+	}
+}
+
 /* retrieve the soc specific data */
 static const struct samsung_pin_ctrl *
 samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
 			     struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
-	struct device_node *np;
 	const struct samsung_pin_bank_data *bdata;
 	const struct samsung_pin_ctrl *ctrl;
 	struct samsung_pin_bank *bank;
@@ -1081,17 +1124,7 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
 	 */
 	d->virt_base = virt_base[0];
 
-	for_each_child_of_node(node, np) {
-		if (!of_find_property(np, "gpio-controller", NULL))
-			continue;
-		bank = d->pin_banks;
-		for (i = 0; i < d->nr_banks; ++i, ++bank) {
-			if (of_node_name_eq(np, bank->name)) {
-				bank->of_node = np;
-				break;
-			}
-		}
-	}
+	samsung_banks_of_node_get(&pdev->dev, d, node);
 
 	d->pin_base = pin_base;
 	pin_base += d->nr_pins;
-- 
2.32.0


WARNING: multiple messages have this Message-ID (diff)
From: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
To: Tomasz Figa <tomasz.figa@gmail.com>,
	Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, linux-gpio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Sylwester Nawrocki <snawrocki@kernel.org>,
	Sam Protsenko <semen.protsenko@linaro.org>,
	Chanho Park <chanho61.park@samsung.com>
Subject: [PATCH 02/24] pinctrl: samsung: accept GPIO bank nodes with a suffix
Date: Fri, 31 Dec 2021 17:19:08 +0100	[thread overview]
Message-ID: <20211231161930.256733-3-krzysztof.kozlowski@canonical.com> (raw)
In-Reply-To: <20211231161930.256733-1-krzysztof.kozlowski@canonical.com>

Existing dt-bindings expected that each GPIO/pin bank within pin
controller has its own node with name matching the bank (e.g. gpa0,
gpx2) and "gpio-controller" property.  The node name is then used for
matching between driver data and DTS.

Newly introduced dtschema expects to have nodes ending with "-gpio-bank"
suffix, so rewrite bank-devicetree matching to look for old and new
style of naming.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 57 ++++++++++++++++++-----
 1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index f2864a7869b3..561853df8ef7 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -1011,13 +1011,56 @@ static void samsung_banks_of_node_put(struct samsung_pinctrl_drv_data *d)
 		of_node_put(bank->of_node);
 }
 
+/*
+ * Iterate over all driver pin banks to find one matching the name of node,
+ * skipping optional "-gpio" node suffix. When found, assign node to the bank.
+ */
+static void samsung_banks_of_node_get(struct device *dev,
+				      struct samsung_pinctrl_drv_data *d,
+				      struct device_node *node)
+{
+	const char *suffix = "-gpio-bank";
+	struct samsung_pin_bank *bank;
+	struct device_node *child;
+	/* Pin bank names are up to 4 characters */
+	char node_name[20];
+	unsigned int i;
+	size_t len;
+
+	bank = d->pin_banks;
+	for (i = 0; i < d->nr_banks; ++i, ++bank) {
+		strscpy(node_name, bank->name, sizeof(node_name));
+		len = strlcat(node_name, suffix, sizeof(node_name));
+		if (len == sizeof(sizeof(node_name))) {
+			dev_err(dev, "Too long pin bank name '%s', ignoring\n",
+				bank->name);
+			continue;
+		}
+
+		for_each_child_of_node(node, child) {
+			if (!of_find_property(child, "gpio-controller", NULL))
+				continue;
+			if (of_node_name_eq(child, node_name))
+				break;
+			else if (of_node_name_eq(child, bank->name))
+				break;
+		}
+
+		if (child)
+			bank->of_node = child;
+		else
+			dev_warn(dev, "Missing node for bank %s - invalid DTB\n",
+				 bank->name);
+		/* child reference dropped in samsung_drop_banks_of_node() */
+	}
+}
+
 /* retrieve the soc specific data */
 static const struct samsung_pin_ctrl *
 samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
 			     struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
-	struct device_node *np;
 	const struct samsung_pin_bank_data *bdata;
 	const struct samsung_pin_ctrl *ctrl;
 	struct samsung_pin_bank *bank;
@@ -1081,17 +1124,7 @@ samsung_pinctrl_get_soc_data(struct samsung_pinctrl_drv_data *d,
 	 */
 	d->virt_base = virt_base[0];
 
-	for_each_child_of_node(node, np) {
-		if (!of_find_property(np, "gpio-controller", NULL))
-			continue;
-		bank = d->pin_banks;
-		for (i = 0; i < d->nr_banks; ++i, ++bank) {
-			if (of_node_name_eq(np, bank->name)) {
-				bank->of_node = np;
-				break;
-			}
-		}
-	}
+	samsung_banks_of_node_get(&pdev->dev, d, node);
 
 	d->pin_base = pin_base;
 	pin_base += d->nr_pins;
-- 
2.32.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-12-31 16:20 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-31 16:19 [PATCH 00/24] pinctrl: dt-bindings: samsung: convert to dtschema Krzysztof Kozlowski
2021-12-31 16:19 ` Krzysztof Kozlowski
2021-12-31 16:19 ` [PATCH 01/24] pinctrl: samsung: drop pin banks references on error paths Krzysztof Kozlowski
2021-12-31 16:19   ` Krzysztof Kozlowski
2022-01-03 14:49   ` Sam Protsenko
2022-01-03 14:49     ` Sam Protsenko
2022-01-05 20:24     ` Krzysztof Kozlowski
2022-01-05 20:24       ` Krzysztof Kozlowski
2021-12-31 16:19 ` Krzysztof Kozlowski [this message]
2021-12-31 16:19   ` [PATCH 02/24] pinctrl: samsung: accept GPIO bank nodes with a suffix Krzysztof Kozlowski
2022-01-03 18:43   ` Sam Protsenko
2022-01-03 18:43     ` Sam Protsenko
2022-01-05 20:31     ` Krzysztof Kozlowski
2022-01-05 20:31       ` Krzysztof Kozlowski
2021-12-31 16:19 ` [PATCH 03/24] ARM: dts: exynos: drop unused pinctrl defines in Exynos3250 Krzysztof Kozlowski
2021-12-31 16:19   ` Krzysztof Kozlowski
2022-01-06 18:20   ` Alim Akhtar
2022-01-06 18:20     ` Alim Akhtar
2021-12-31 16:19 ` [PATCH 04/24] ARM: dts: exynos: simplify PMIC DVS pin configuration in Odroid XU Krzysztof Kozlowski
2021-12-31 16:19   ` Krzysztof Kozlowski
2021-12-31 16:19 ` [PATCH 05/24] ARM: dts: exynos: override pins by label in Peach Pit Krzysztof Kozlowski
2021-12-31 16:19   ` Krzysztof Kozlowski
2022-01-06 18:42   ` Alim Akhtar
2022-01-06 18:42     ` Alim Akhtar
2021-12-31 16:19 ` [PATCH 06/24] ARM: dts: exynos: simplify PMIC DVS pin configuration " Krzysztof Kozlowski
2021-12-31 16:19   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 07/24] ARM: dts: exynos: override pins by label in Peach Pi Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2022-01-06 18:44   ` Alim Akhtar
2022-01-06 18:44     ` Alim Akhtar
2021-12-31 16:21 ` [PATCH 08/24] ARM: dts: exynos: simplify PMIC DVS pin configuration " Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2022-01-06 18:47   ` Alim Akhtar
2022-01-06 18:47     ` Alim Akhtar
2022-01-07  7:34     ` Krzysztof Kozlowski
2022-01-07  7:34       ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 09/24] ARM: dts: s3c64xx: drop unneeded pinctrl wake-up interrupt mapping Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 10/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos3250 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 11/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos4210 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 12/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos4412 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 13/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos5250 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 14/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos5260 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 15/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos5410 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:21 ` [PATCH 16/24] ARM: dts: exynos: align pinctrl with dtschema in Exynos542x/5800 Krzysztof Kozlowski
2021-12-31 16:21   ` Krzysztof Kozlowski
2021-12-31 16:22 ` [PATCH 17/24] arm64: dts: exynos: align pinctrl with dtschema in Exynos5433 Krzysztof Kozlowski
2021-12-31 16:22   ` Krzysztof Kozlowski
2021-12-31 16:23 ` [PATCH 18/24] arm64: dts: exynos: align pinctrl with dtschema in Exynos7 Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2021-12-31 16:23 ` [PATCH 19/24] arm64: dts: exynos: align pinctrl with dtschema in Exynos850 Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2022-01-03 14:45   ` Sam Protsenko
2022-01-03 14:45     ` Sam Protsenko
2021-12-31 16:23 ` [PATCH 20/24] arm64: dts: exynos: align pinctrl with dtschema in ExynosAutov9 Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2021-12-31 16:23 ` [PATCH 21/24] ARM: dts: s3c24xx: align pinctrl with dtschema Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2021-12-31 16:23 ` [PATCH 22/24] ARM: dts: s3c64xx: " Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2021-12-31 16:23 ` [PATCH 23/24] ARM: dts: s5pv210: " Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2021-12-31 16:23 ` [PATCH 24/24] dt-bindings: pinctrl: samsung: convert to dtschema Krzysztof Kozlowski
2021-12-31 16:23   ` Krzysztof Kozlowski
2022-01-03 21:19   ` Sam Protsenko
2022-01-03 21:19     ` Sam Protsenko
2022-01-10 20:43   ` Rob Herring
2022-01-10 20:43     ` Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211231161930.256733-3-krzysztof.kozlowski@canonical.com \
    --to=krzysztof.kozlowski@canonical.com \
    --cc=chanho61.park@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robh+dt@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=semen.protsenko@linaro.org \
    --cc=snawrocki@kernel.org \
    --cc=tomasz.figa@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.