linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Wolfram Sang <wsa@kernel.org>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	"linux-renesas-soc@vger.kernel.org" 
	<linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH] i2c: Add i2c_get_match_data()
Date: Mon, 22 May 2023 14:42:48 +0200	[thread overview]
Message-ID: <CAMuHMdXBoazJtsZ89zv1_xG9CtJ+hnasZLrW_13xtoVKANN+cg@mail.gmail.com> (raw)
In-Reply-To: <OS0PR01MB5922DAE12A85AC045B6222DB86439@OS0PR01MB5922.jpnprd01.prod.outlook.com>

Hi Biju,

On Mon, May 22, 2023 at 2:38 PM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > -----Original Message-----
> > From: Geert Uytterhoeven <geert@linux-m68k.org>
> > Sent: Monday, May 22, 2023 12:29 PM
> > To: Biju Das <biju.das.jz@bp.renesas.com>
> > Cc: Wolfram Sang <wsa@kernel.org>; linux-i2c@vger.kernel.org; Alessandro
> > Zummo <a.zummo@towertech.it>; Alexandre Belloni
> > <alexandre.belloni@bootlin.com>; Prabhakar Mahadev Lad
> > <prabhakar.mahadev-lad.rj@bp.renesas.com>; linux-renesas-
> > soc@vger.kernel.org
> > Subject: Re: [PATCH] i2c: Add i2c_get_match_data()
> >
> > Hi Biju,
> >
> > On Mon, May 22, 2023 at 12:42 PM Biju Das <biju.das.jz@bp.renesas.com>
> > wrote:
> > > Add i2c_get_match_data() similar to of_device_get_match_data(), so
> > > that we can optimize the driver code that uses both I2C and DT-based
> > > matching.
> > >
> > > Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> >
> > Thanks for your patch!
> >
> > > --- a/drivers/i2c/i2c-core-base.c
> > > +++ b/drivers/i2c/i2c-core-base.c
> > > @@ -99,8 +99,8 @@ const char *i2c_freq_mode_string(u32 bus_freq_hz)  }
> > > EXPORT_SYMBOL_GPL(i2c_freq_mode_string);
> > >
> > > -const struct i2c_device_id *i2c_match_id(const struct i2c_device_id
> > *id,
> > > -                                               const struct
> > i2c_client *client)
> > > +static const struct i2c_device_id *i2c_match_device_id(const struct
> > i2c_device_id *id,
> > > +                                                      const struct
> > > +i2c_client *client)
> > >  {
> > >         if (!(id && client))
> > >                 return NULL;
> > > @@ -110,10 +110,30 @@ const struct i2c_device_id *i2c_match_id(const
> > struct i2c_device_id *id,
> > >                         return id;
> > >                 id++;
> > >         }
> > > +
> > >         return NULL;
> > >  }
> > > +
> > > +const struct i2c_device_id *i2c_match_id(const struct i2c_device_id
> > *id,
> > > +                                        const struct i2c_client
> > > +*client) {
> > > +       return i2c_match_device_id(id, client); }
> > >  EXPORT_SYMBOL_GPL(i2c_match_id);
> >
> > Is there any reason why you're adding a new intermediate?
>
> The same code is shared between below function.
> As discussed below, it is not required.
>
> >
> > >
> > > +const void *i2c_get_match_data(const struct i2c_device_id *id,
> > > +                              const struct i2c_client *client)
> >
> > I think this should take the id table from the i2c_driver, as pointed to
> > by client->dev.driver, instead of from an explicitly passed parameter.
>
> You mean const void *i2c_get_match_data(const struct i2c_client *client)??
>
> struct i2c_driver       *driver = client->dev.driver;

also needs to_i2c_driver()

>
> And then call
>
> match = i2c_match_id(driver->id_table, client)??

Exactly.

> > > +{
> > > +       const struct i2c_device_id *match;
> > > +
> > > +       match = i2c_match_device_id(id, client);
> > > +       if (!match)
> > > +               return NULL;
> > > +
> > > +       return (const void *)match->driver_data;
> >
> > One can discuss about the returned type: personally, I won't mind "const
> > void *" for consistency with other subsystems (e.g. DT), but as
> > i2c_device_id.driver_data has type "kernel_ulong_t", other people might
> > prefer the latter.
>
> The advantage of void*, is upper layer don't need casting.

Depending on what the driver wants...
Some drivers want integers, other want pointers...

> eg: with kernel_ulong_t as return parameter:
>
> isl1208->config = (struct isl1208_config *)i2c_get_match_data;

I know ;-)
For the isl1208 case, "void *" simplifies the driver...

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2023-05-22 12:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 10:41 [PATCH] i2c: Add i2c_get_match_data() Biju Das
2023-05-22 11:28 ` Geert Uytterhoeven
2023-05-22 12:38   ` Biju Das
2023-05-22 12:42     ` Geert Uytterhoeven [this message]
2023-06-01 15:44       ` Biju Das

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMuHMdXBoazJtsZ89zv1_xG9CtJ+hnasZLrW_13xtoVKANN+cg@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).