diff mbox series

[v1,3/3] drivers: pinctrl-single: add request api

Message ID 20200429163446.15390-4-rayagonda.kokatanur@broadcom.com
State New
Delegated to: Tom Rini
Headers show
Series extend pinctrl-single driver with APIs | expand

Commit Message

Rayagonda Kokatanur April 29, 2020, 4:34 p.m. UTC
Add pinctrl_ops->request api to configure pctrl
pad register in gpio mode.

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

Comments

Simon Glass April 29, 2020, 6:04 p.m. UTC | #1
Hi Rayagonda,

+Stephen Warren

On Wed, 29 Apr 2020 at 10:36, Rayagonda Kokatanur
<rayagonda.kokatanur@broadcom.com> wrote:
>
> Add pinctrl_ops->request api to configure pctrl
> pad register in gpio mode.
>
> Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> ---
>  drivers/pinctrl/pinctrl-single.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)

This should use the Kconfig also (and needs a test)

Regards,
Simon
Rayagonda Kokatanur April 30, 2020, 11:03 a.m. UTC | #2
Hi Simon,

On Wed, Apr 29, 2020 at 11:34 PM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Rayagonda,
>
> +Stephen Warren
>
> On Wed, 29 Apr 2020 at 10:36, Rayagonda Kokatanur
> <rayagonda.kokatanur@broadcom.com> wrote:
> >
> > Add pinctrl_ops->request api to configure pctrl
> > pad register in gpio mode.
> >
> > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> > ---
> >  drivers/pinctrl/pinctrl-single.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
>
> This should use the Kconfig also (and needs a test)

Please elaborate "need a test".
Do you mean a testing procedure as part of the commit message ?

I feel we don't need the Kconfig option, looking at Linux pinctrl-single driver.
Please let me know.

>
> Regards,
> Simon
Simon Glass May 8, 2020, 1:36 a.m. UTC | #3
Hi Rayagonda,

On Thu, 30 Apr 2020 at 05:03, Rayagonda Kokatanur
<rayagonda.kokatanur@broadcom.com> wrote:
>
> Hi Simon,
>
> On Wed, Apr 29, 2020 at 11:34 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Rayagonda,
> >
> > +Stephen Warren
> >
> > On Wed, 29 Apr 2020 at 10:36, Rayagonda Kokatanur
> > <rayagonda.kokatanur@broadcom.com> wrote:
> > >
> > > Add pinctrl_ops->request api to configure pctrl
> > > pad register in gpio mode.
> > >
> > > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
> > > ---
> > >  drivers/pinctrl/pinctrl-single.c | 29 +++++++++++++++++++++++++++++
> > >  1 file changed, 29 insertions(+)
> >
> > This should use the Kconfig also (and needs a test)
>
> Please elaborate "need a test".
> Do you mean a testing procedure as part of the commit message ?

No I mean U-Boot has automated tests. So when we add code we need to
add tests for that code. See test/dm/rtc.c for an example. You can run
them with:

   make qcheck

or a single one with:



>
> I feel we don't need the Kconfig option, looking at Linux pinctrl-single driver.
> Please let me know.

OK we can go without one. It is easy to add later if needed.

Regards,
Simon
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index fe79a218ee..2cdba1d338 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -130,6 +130,34 @@  static int single_configure_pins(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_configure_bits(struct udevice *dev,
 				 const struct single_fdt_bits_cfg *pins,
 				 int size)
@@ -288,6 +316,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[] = {