[U-Boot] [PATCH 2/3] pinctrl: pinctrl-single: Add request api

Vladimir Olovyannikov vladimir.olovyannikov at broadcom.com
Fri Nov 22 22:44:42 UTC 2019


From: Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com>

Add pinctrl_ops->request api to configure pctrl pad register
to configure in gpio mode.

Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com>
Signed-off-by: Vladimir Olovyannikov <vladimir.olovyannikov at broadcom.com>
---
 drivers/pinctrl/pinctrl-single.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 6c6a33e4c5..2dcc131513 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -136,6 +136,35 @@ static int single_configure_bits(struct udevice *dev,
 	}
 	return 0;
 }
+
+static int single_request(struct udevice *dev, int pin, int flags)
+{
+	struct single_pdata *pdata = dev->platdata;
+	struct single_gpiofunc_range *frange = NULL;
+	struct list_head *pos, *tmp;
+	int mux_bytes = 0;
+	u32 data;
+
+	if (!pdata->mask)
+		return -ENOTSUPP;
+
+	list_for_each_safe(pos, tmp, &pdata->gpiofuncs) {
+		frange = list_entry(pos, struct single_gpiofunc_range, node);
+		if ((pin >= frange->offset + frange->npins) ||
+		    pin < frange->offset)
+			continue;
+
+		mux_bytes = pdata->width / BITS_PER_BYTE;
+		data = pdata->read(pdata->base + pin * mux_bytes);
+		data &= ~pdata->mask;
+		data |= frange->gpiofunc;
+		pdata->write(data, pdata->base + pin * mux_bytes);
+		break;
+	}
+
+	return 0;
+}
+
 static int single_set_state(struct udevice *dev,
 			    struct udevice *config)
 {
@@ -235,6 +264,7 @@ static int single_ofdata_to_platdata(struct udevice *dev)
 
 const struct pinctrl_ops single_pinctrl_ops = {
 	.set_state = single_set_state,
+	.request = single_request,
 };
 
 static const struct udevice_id single_pinctrl_match[] = {
-- 
2.17.1



More information about the U-Boot mailing list