mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [PATCH 6/8] pinctrl: stm32: fix up st,package into stm32mp nodes
Date: Mon, 30 Mar 2020 16:39:13 +0200	[thread overview]
Message-ID: <20200330143915.663705-6-ahmad@a3f.at> (raw)
In-Reply-To: <20200330143915.663705-1-ahmad@a3f.at>

Since Linux v5.1, the pinctrl driver can use the st,package property
if provided to validate whether the ball to be configured exists
on the package. Have barebox supply this property.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 arch/arm/dts/stm32mp151.dtsi    | 16 ++++++++
 drivers/pinctrl/pinctrl-stm32.c | 67 +++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/arch/arm/dts/stm32mp151.dtsi b/arch/arm/dts/stm32mp151.dtsi
index 8f8249dbc479..2a70a747e76e 100644
--- a/arch/arm/dts/stm32mp151.dtsi
+++ b/arch/arm/dts/stm32mp151.dtsi
@@ -37,4 +37,20 @@
 
 &bsec {
 	barebox,provide-mac-address = <&ethernet0 0x39>;
+
+	soc_package: soc-package@43 {
+		reg = <0x43 1>;
+		bits = <3 3>;
+		read-only;
+	};
+};
+
+&pinctrl {
+	nvmem-cells = <&soc_package>;
+	nvmem-cell-names = "soc-package";
+};
+
+&pinctrl_z {
+	nvmem-cells = <&soc_package>;
+	nvmem-cell-names = "soc-package";
 };
diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
index cdaed510c564..e760ce875774 100644
--- a/drivers/pinctrl/pinctrl-stm32.c
+++ b/drivers/pinctrl/pinctrl-stm32.c
@@ -16,11 +16,25 @@
 #include <malloc.h>
 #include <linux/clk.h>
 #include <soc/stm32/gpio.h>
+#include <dt-bindings/pinctrl/stm32-pinfunc.h>
+#include <linux/nvmem-consumer.h>
 
 #define STM32_PIN_NO(x) ((x) << 8)
 #define STM32_GET_PIN_NO(x) ((x) >> 8)
 #define STM32_GET_PIN_FUNC(x) ((x) & 0xff)
 
+/*
+ * - 100: LBGA448  (FFI) => AA = LFBGA 18x18mm 448 balls p. 0.8mm
+ * - 011: LBGA354  (LCI) => AB = LFBGA 16x16mm 359 balls p. 0.8mm
+ * - 010: TFBGA361 (FFC) => AC = TFBGA 12x12mm 361 balls p. 0.5mm
+ * - 001: TFBGA257 (LCC) => AD = TFBGA 10x10mm 257 balls p. 0.5mm
+ * - others: Reserved
+ */
+#define PKG_AA_LBGA448	4
+#define PKG_AB_LBGA354	3
+#define PKG_AC_TFBGA361	2
+#define PKG_AD_TFBGA257	1
+
 struct stm32_gpio_bank {
 	void __iomem *base;
 	struct gpio_chip chip;
@@ -369,6 +383,57 @@ static int stm32_gpiochip_add(struct stm32_gpio_bank *bank,
 	return gpiochip_add(&bank->chip);
 }
 
+static int fixup_pinctrl(struct device_node *root, const char *compat, u32 pkg)
+{
+	struct device_node *np = of_find_compatible_node(root, NULL, compat);
+	if (!np)
+		return -ENODEV;
+
+	return of_property_write_u32(np, "st,package", pkg);
+}
+
+static u8 stm32_package_xlate(u8 pkg)
+{
+	switch (pkg) {
+	case PKG_AA_LBGA448:
+		return STM32MP_PKG_AA;
+	case PKG_AB_LBGA354:
+		return STM32MP_PKG_AB;
+	case PKG_AC_TFBGA361:
+		return STM32MP_PKG_AC;
+	case PKG_AD_TFBGA257:
+		return STM32MP_PKG_AD;
+	default:
+		return 0;
+	}
+}
+
+static int stm32_fixup_package(struct device_node *root, void *_dev)
+{
+	struct device_d *dev = _dev;
+	u8 *cell, pkg, pkg_raw;
+	int ret;
+
+	cell = nvmem_cell_get_and_read(dev->device_node, "soc-package", 1);
+	if (IS_ERR(cell))
+		return 0;
+
+	pkg_raw = *cell;
+	free(cell);
+
+	pkg = stm32_package_xlate(pkg_raw);
+	if (!pkg) {
+		dev_dbg(dev, "Unknown package: %01x\n", pkg_raw);
+		return 0;
+	}
+
+	ret = fixup_pinctrl(root, "st,stm32mp157-pinctrl", pkg);
+	if (ret)
+		return ret;
+
+	return fixup_pinctrl(root, "st,stm32mp157-z-pinctrl", pkg);
+}
+
 static struct pinctrl_ops stm32_pinctrl_ops = {
 	.set_state = stm32_pinctrl_set_state,
 };
@@ -419,6 +484,8 @@ static int stm32_pinctrl_probe(struct device_d *dev)
 		}
 	}
 
+	of_register_fixup(stm32_fixup_package, dev);
+
 	dev_dbg(dev, "pinctrl/gpio driver registered\n");
 
 	return 0;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-03-30 14:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 14:39 [PATCH 1/8] ARM: stm32mp: init: don't cast signed error to unsigned Ahmad Fatoum
2020-03-30 14:39 ` [PATCH 2/8] ARM: stm32mp: init: detect Revision Z and 800 MHz profiles Ahmad Fatoum
2020-03-30 14:39 ` [PATCH 3/8] ARM: stm32mp: init: fix up CPU device tree nodes Ahmad Fatoum
2020-03-30 14:39 ` [PATCH 4/8] nvmem: bsec: allow reads at unaligned offsets Ahmad Fatoum
2020-03-30 14:39 ` [PATCH 5/8] nvmem: bsec: remove wrongly named bsec_field type Ahmad Fatoum
2020-05-08 12:53   ` Sascha Hauer
2020-03-30 14:39 ` Ahmad Fatoum [this message]
2020-03-31  5:45   ` [PATCH 6/8] pinctrl: stm32: fix up st,package into stm32mp nodes Sascha Hauer
2020-03-31  5:50     ` Ahmad Fatoum
2020-03-31  6:55       ` Sascha Hauer
2020-03-31  7:03         ` Ahmad Fatoum
2020-04-15  9:38     ` Ahmad Fatoum
2020-05-08  6:43       ` Ahmad Fatoum
2020-03-30 14:39 ` [PATCH 7/8] ARM: stm32mp: init: don't query package type Ahmad Fatoum
2020-03-30 14:39 ` [PATCH 8/8] ARM: stm32mp: add support for STM32MP157-EV1 board Ahmad Fatoum

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=20200330143915.663705-6-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox