[PATCH v1 1/3] drivers: pinctrl-single: handle different register width

Rayagonda Kokatanur rayagonda.kokatanur at broadcom.com
Tue May 26 20:57:01 CEST 2020


Hi Simon,

On Mon, May 25, 2020 at 7:45 AM Simon Glass <sjg at chromium.org> wrote:
>
> Hi Rayagonda,
>
> On Sun, 24 May 2020 at 04:46, Rayagonda Kokatanur
> <rayagonda.kokatanur at broadcom.com> wrote:
> >
> > Hi Simon,
> >
> > On Fri, May 8, 2020 at 7:07 AM Simon Glass <sjg at chromium.org> wrote:
> > >
> > > Hi Rayagonda,
> > >
> > > On Thu, 30 Apr 2020 at 04:06, Rayagonda Kokatanur
> > > <rayagonda.kokatanur at broadcom.com> wrote:
> > > >
> > > > On Wed, Apr 29, 2020 at 11:34 PM Simon Glass <sjg at chromium.org> wrote:
> > > > >
> > > > > Hi Rayagonda,
> > > > >
> > > > > +Stephen Warren
> > > > >
> > > > > On Wed, 29 Apr 2020 at 10:35, Rayagonda Kokatanur
> > > > > <rayagonda.kokatanur at broadcom.com> wrote:
> > > > > >
> > > > > > Add support to use different register read/write api's
> > > > > > based on register width.
> > > > > >
> > > > > > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com>
> > > > > > ---
> > > > > >  drivers/pinctrl/pinctrl-single.c | 98 ++++++++++++++++++++++++--------
> > > > > >  1 file changed, 74 insertions(+), 24 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> > > > > > index 738f5bd636..aed113b083 100644
> > > > > > --- a/drivers/pinctrl/pinctrl-single.c
> > > > > > +++ b/drivers/pinctrl/pinctrl-single.c
> > > > > > @@ -10,12 +10,24 @@
> > > > > >  #include <linux/libfdt.h>
> > > > > >  #include <asm/io.h>
> > > > > >
> > > > > > +/**
> > > > > > + * struct single_pdata - pinctrl device instance
> > > > > > + * @base       first configuration register
> > > > > > + * @offset     index of last configuration register
> > > > > > + * @mask       configuration-value mask bits
> > > > > > + * @width      configuration register bit width
> > > > > > + * @bits_per_mux
> > > > > > + * @read       register read function to use
> > > > > > + * @write      register write function to use
> > > > > > + */
> > > > > >  struct single_pdata {
> > > > > >         fdt_addr_t base;        /* first configuration register */
> > > > > >         int offset;             /* index of last configuration register */
> > > > > >         u32 mask;               /* configuration-value mask bits */
> > > > > >         int width;              /* configuration register bit width */
> > > > > >         bool bits_per_mux;
> > > > > > +       u32 (*read)(phys_addr_t reg);
> > > > > > +       void (*write)(u32 val, phys_addr_t reg);
> > > > >
> > > > > Can't we just have a read & write function with a switch statement?
> > > > > Why do we need function pointers?
> > > >
> > > > I referred to the linux pinctrl-single.c and kept code similar to linux.
> > > > Please let me know.
> > >
> > > See the regmap discussion here which is related:
> > >
> > > http://patchwork.ozlabs.org/project/uboot/patch/20191105114700.24989-3-jjhiblot@ti.com/
> > >
> > > Should this driver use regmap, then?
> >
> > I think using a function pointer is a better approach, we can check
> > for errors in one place ie invalid register width.
> > Right now it's been done in single_probe() function.
> > Please let me know.
>
> What sort of errors?

What I mean is, right now read/write function pointres are getting
initialized in single_probe() based on pdata->width.
If pdata->width is invalid, its erroring out there only.

So if we use a single read and write function with switch statement
then checking pdata->width should be part of this switch statement.
This means every call to read/write should check for failure. Hence I
am thinking function pointer is a better approach.

Please let me know.

Best regards,
Rayagonda

>
> I'm sorry but I prefer the switch() for U-Boot. We have different
> constraints from Linux. After all, our file is 200 lines and in Linux
> this is 2k lines.
>
> Regards,
> Simon


More information about the U-Boot mailing list