[U-Boot,2/3] pinctrl: pinctrl-single: Add request api
diff mbox series

Message ID 20191122224443.29497-3-vladimir.olovyannikov@broadcom.com
State New
Delegated to: Tom Rini
Headers show
Series
  • Extend pinctrl-single driver with APIs
Related show

Commit Message

Vladimir Olovyannikov Nov. 22, 2019, 10:44 p.m. UTC
From: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>

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

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

Patch
diff mbox series

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[] = {