[PATCH 08/11] pinctrl: single: add get_pins_count operation
Dario Binacchi
dariobin at libero.it
Sat Jan 23 19:27:08 CET 2021
It returns the number of selectable pins.
Signed-off-by: Dario Binacchi <dariobin at libero.it>
---
drivers/pinctrl/pinctrl-single.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index eb69e53096..21a3bbaaa7 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -28,10 +28,14 @@ struct single_pdata {
/**
* struct single_priv - private data
+ * @bits_per_pin: number of bits per pin
+ * @npins: number of selectable pins
* @read: function to read from a configuration register
* @write: function to write to a configuration register
*/
struct single_priv {
+ unsigned int bits_per_pin;
+ unsigned int npins;
unsigned int (*read)(fdt_addr_t reg);
void (*write)(unsigned int val, fdt_addr_t reg);
};
@@ -203,10 +207,27 @@ static int single_set_state(struct udevice *dev,
return len;
}
+static int single_get_pins_count(struct udevice *dev)
+{
+ struct single_priv *priv = dev_get_priv(dev);
+
+ return priv->npins;
+}
+
static int single_probe(struct udevice *dev)
{
struct single_pdata *pdata = dev_get_plat(dev);
struct single_priv *priv = dev_get_priv(dev);
+ u32 size;
+
+ size = pdata->offset + pdata->width / BITS_PER_BYTE;
+ priv->npins = size / (pdata->width / BITS_PER_BYTE);
+ if (pdata->bits_per_mux) {
+ priv->bits_per_pin = fls(pdata->mask);
+ priv->npins *= (pdata->width / priv->bits_per_pin);
+ }
+
+ dev_dbg(dev, "%d pins\n", priv->npins);
switch (pdata->width) {
case 8:
@@ -264,6 +285,7 @@ static int single_of_to_plat(struct udevice *dev)
}
const struct pinctrl_ops single_pinctrl_ops = {
+ .get_pins_count = single_get_pins_count,
.set_state = single_set_state,
};
--
2.17.1
More information about the U-Boot
mailing list