[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211116062328.1949151-18-colin.foster@in-advantage.com>
Date: Mon, 15 Nov 2021 22:23:22 -0800
From: Colin Foster <colin.foster@...advantage.com>
To: linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-gpio@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Vladimir Oltean <vladimir.oltean@....com>,
Claudiu Manoil <claudiu.manoil@....com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
UNGLinuxDriver@...rochip.com, Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Ioana Ciornei <ioana.ciornei@....com>,
Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
Lars Povlsen <lars.povlsen@...rochip.com>,
Steen Hegelund <Steen.Hegelund@...rochip.com>,
Linus Walleij <linus.walleij@...aro.org>,
Philipp Zabel <p.zabel@...gutronix.de>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: [RFC PATCH v4 net-next 17/23] pinctrl: microchip-sgpio: expose microchip_sgpio_core_probe interface
Allow external drivers to hook into microchip_sgpio with custom regmaps. In
the case where the sgpio is part of an external chip like a VSC7512
controlled over SPI, a pre-existing SPI regmap can be used.
Signed-off-by: Colin Foster <colin.foster@...advantage.com>
---
drivers/pinctrl/pinctrl-microchip-sgpio.c | 46 ++++++++++++++---------
include/soc/mscc/ocelot.h | 11 ++++++
2 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
index 10736ef5c6ca..2ddee50707d0 100644
--- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
+++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
@@ -835,22 +835,15 @@ static struct sgpio_properties
return NULL;
}
-static int microchip_sgpio_probe(struct platform_device *pdev)
+int microchip_sgpio_core_probe(struct device *dev, struct device_node *node,
+ struct regmap *regmap, u32 offset)
{
int div_clock = 0, ret, port, i, nbanks;
- struct device *dev = &pdev->dev;
- struct device_node *node = dev_of_node(dev);
struct fwnode_handle *child, *fwnode;
struct reset_control *reset;
struct sgpio_priv *priv;
struct clk *clk;
- u32 __iomem *regs;
u32 val;
- struct regmap_config regmap_config = {
- .reg_bits = 32,
- .val_bits = 32,
- .reg_stride = 4,
- };
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -878,18 +871,14 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
return -EINVAL;
}
- regs = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(regs))
- return PTR_ERR(regs);
-
- priv->regs = devm_regmap_init_mmio(dev, regs, ®map_config);
- if (IS_ERR(priv->regs))
- return PTR_ERR(priv->regs);
-
+ priv->regs = regmap;
priv->regs_offset = 0;
priv->properties = microchip_sgpio_match_from_node(node);
priv->in.is_input = true;
+ if (!priv->properties)
+ return dev_err_probe(dev, -EINVAL, "No property match found\n");
+
/* Get rest of device properties */
ret = microchip_sgpio_get_ports(priv);
if (ret)
@@ -926,6 +915,29 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
return 0;
}
+EXPORT_SYMBOL(microchip_sgpio_core_probe);
+
+static int microchip_sgpio_probe(struct platform_device *pdev)
+{
+ struct regmap_config regmap_config = {0};
+ struct device *dev = &pdev->dev;
+ struct regmap *regmap;
+ u32 __iomem *regs;
+
+ regmap_config.reg_bits = 32;
+ regmap_config.val_bits = 32;
+ regmap_config.reg_stride = 4;
+
+ regs = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(regs))
+ return PTR_ERR(regs);
+
+ regmap = devm_regmap_init_mmio(dev, regs, ®map_config);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
+ return microchip_sgpio_core_probe(dev, dev->of_node, regmap, 0);
+}
static struct platform_driver microchip_sgpio_pinctrl_driver = {
.driver = {
diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h
index 14acfe82d0a4..8c27f8f79fff 100644
--- a/include/soc/mscc/ocelot.h
+++ b/include/soc/mscc/ocelot.h
@@ -930,4 +930,15 @@ int ocelot_pinctrl_core_probe(struct device *dev,
}
#endif
+#if IS_ENABLED(CONFIG_PINCTRL_MICROCHIP_SGPIO)
+int microchip_sgpio_core_probe(struct device *dev, struct device_node *node,
+ struct regmap *regmap, u32 offset);
+#else
+int microchip_sgpio_core_probe(struct device *dev, struct device_node *node,
+ struct regmap *regmap, u32 offset)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
#endif
--
2.25.1
Powered by blists - more mailing lists