2022-10-30 18:01:27

by Angel Iglesias

[permalink] [raw]
Subject: [RFC PATCH 0/2] i2c: core: Introduce i2c_client_get_device_id helper

Hello,

I don't want to step anyone's work here, so I'm sending this RFC to the
devs involved in the original discussion. I read on Uwe Kleine-König's
patchset submission thread the necessity for an i2c helper to aid with the
migration to the new i2c_driver .probe_new callback. Following the
suggestions made there, I wrote this small patchset implementing the
suggested helper function and ported the bmp280 IIO i2c probe to the new
probe using that helper.

Thanks for your time!
Angel

Original discussion thread for additional context:
https://lore.kernel.org/all/[email protected]/

Angel Iglesias (2):
i2c: core: Introduce i2c_client_get_device_id helper function
iio: pressure: bmp280: convert to i2c's .probe_new()

drivers/i2c/i2c-core-base.c | 15 +++++++++++++++
drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
include/linux/i2c.h | 1 +
3 files changed, 20 insertions(+), 4 deletions(-)


base-commit: c32793afc6976e170f6ab11ca3750fe94fb3454d
--
2.38.1



2022-10-30 18:01:57

by Angel Iglesias

[permalink] [raw]
Subject: [RFC PATCH 2/2] iio: pressure: bmp280: convert to i2c's .probe_new()

Use i2c_client_get_device_id() to get the i2c_device_id* parameter in the
.new_probe() callback.

Signed-off-by: Angel Iglesias <[email protected]>
---
drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c
index 0c27211f3ea0..20073b09b3e3 100644
--- a/drivers/iio/pressure/bmp280-i2c.c
+++ b/drivers/iio/pressure/bmp280-i2c.c
@@ -5,11 +5,11 @@

#include "bmp280.h"

-static int bmp280_i2c_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+static int bmp280_i2c_probe(struct i2c_client *client)
{
- struct regmap *regmap;
+ const struct i2c_device_id *id = i2c_client_get_device_id(client);
const struct regmap_config *regmap_config;
+ struct regmap *regmap;

switch (id->driver_data) {
case BMP180_CHIP_ID:
@@ -65,7 +65,7 @@ static struct i2c_driver bmp280_i2c_driver = {
.of_match_table = bmp280_of_i2c_match,
.pm = pm_ptr(&bmp280_dev_pm_ops),
},
- .probe = bmp280_i2c_probe,
+ .probe_new = bmp280_i2c_probe,
.id_table = bmp280_i2c_id,
};
module_i2c_driver(bmp280_i2c_driver);
--
2.38.1


2022-11-01 16:03:03

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] i2c: core: Introduce i2c_client_get_device_id helper

On Sun, Oct 30, 2022 at 06:51:06PM +0100, Angel Iglesias wrote:
> Hello,
>
> I don't want to step anyone's work here, so I'm sending this RFC to the
> devs involved in the original discussion. I read on Uwe Kleine-K?nig's
> patchset submission thread the necessity for an i2c helper to aid with the
> migration to the new i2c_driver .probe_new callback. Following the
> suggestions made there, I wrote this small patchset implementing the
> suggested helper function and ported the bmp280 IIO i2c probe to the new
> probe using that helper.

For the entire series (please drop RFC in the next version)
Reviewed-by: Andy Shevchenko <[email protected]>

> Thanks for your time!
> Angel
>
> Original discussion thread for additional context:
> https://lore.kernel.org/all/[email protected]/
>
> Angel Iglesias (2):
> i2c: core: Introduce i2c_client_get_device_id helper function
> iio: pressure: bmp280: convert to i2c's .probe_new()
>
> drivers/i2c/i2c-core-base.c | 15 +++++++++++++++
> drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
> include/linux/i2c.h | 1 +
> 3 files changed, 20 insertions(+), 4 deletions(-)
>
>
> base-commit: c32793afc6976e170f6ab11ca3750fe94fb3454d
> --
> 2.38.1
>

--
With Best Regards,
Andy Shevchenko



2022-11-01 21:59:33

by Uwe Kleine-König

[permalink] [raw]
Subject: Re: [RFC PATCH 2/2] iio: pressure: bmp280: convert to i2c's .probe_new()

Hello,

On Sun, Oct 30, 2022 at 06:53:11PM +0100, Angel Iglesias wrote:
> Use i2c_client_get_device_id() to get the i2c_device_id* parameter in the
> .new_probe() callback.
>
> Signed-off-by: Angel Iglesias <[email protected]>
> ---
> drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c
> index 0c27211f3ea0..20073b09b3e3 100644
> --- a/drivers/iio/pressure/bmp280-i2c.c
> +++ b/drivers/iio/pressure/bmp280-i2c.c
> @@ -5,11 +5,11 @@
>
> #include "bmp280.h"
>
> -static int bmp280_i2c_probe(struct i2c_client *client,
> - const struct i2c_device_id *id)
> +static int bmp280_i2c_probe(struct i2c_client *client)
> {
> - struct regmap *regmap;
> + const struct i2c_device_id *id = i2c_client_get_device_id(client);
> const struct regmap_config *regmap_config;
> + struct regmap *regmap;
>
> switch (id->driver_data) {
> case BMP180_CHIP_ID:

What is the motivation for moving regmap? I thought reverse christmas
tree is only a thing in network code? I would have left the regmap
declaration where it is.

> @@ -65,7 +65,7 @@ static struct i2c_driver bmp280_i2c_driver = {
> .of_match_table = bmp280_of_i2c_match,
> .pm = pm_ptr(&bmp280_dev_pm_ops),
> },
> - .probe = bmp280_i2c_probe,
> + .probe_new = bmp280_i2c_probe,
> .id_table = bmp280_i2c_id,
> };
> module_i2c_driver(bmp280_i2c_driver);

Best regards
Uwe

--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |


Attachments:
(No filename) (1.65 kB)
signature.asc (499.00 B)
Download all attachments

2022-11-02 00:36:21

by Angel Iglesias

[permalink] [raw]
Subject: Re: [RFC PATCH 2/2] iio: pressure: bmp280: convert to i2c's .probe_new()

On Tue, 2022-11-01 at 22:52 +0100, Uwe Kleine-König wrote:
> Hello,
>
> On Sun, Oct 30, 2022 at 06:53:11PM +0100, Angel Iglesias wrote:
> > Use i2c_client_get_device_id() to get the i2c_device_id* parameter in the
> > .new_probe() callback.
> >
> > Signed-off-by: Angel Iglesias <[email protected]>
> > ---
> >  drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/iio/pressure/bmp280-i2c.c
> > b/drivers/iio/pressure/bmp280-i2c.c
> > index 0c27211f3ea0..20073b09b3e3 100644
> > --- a/drivers/iio/pressure/bmp280-i2c.c
> > +++ b/drivers/iio/pressure/bmp280-i2c.c
> > @@ -5,11 +5,11 @@
> >  
> >  #include "bmp280.h"
> >  
> > -static int bmp280_i2c_probe(struct i2c_client *client,
> > -                           const struct i2c_device_id *id)
> > +static int bmp280_i2c_probe(struct i2c_client *client)
> >  {
> > -       struct regmap *regmap;
> > +       const struct i2c_device_id *id = i2c_client_get_device_id(client);
> >         const struct regmap_config *regmap_config;
> > +       struct regmap *regmap;
> >  
> >         switch (id->driver_data) {
> >         case BMP180_CHIP_ID:
>
> What is the motivation for moving regmap? I thought reverse christmas
> tree is only a thing in network code? I would have left the regmap
> declaration where it is.

Long story short, I worked previously on a small refactor of this driver to add
support for a new family of sensors. During the different iterations of the
patchset, one thing that was agreed was unifying the driver coding style to
reverse xmas tree. For some extra context, here's the thread:
https://lore.kernel.org/all/20220814145249.701f1261@jic23-huawei/

> > @@ -65,7 +65,7 @@ static struct i2c_driver bmp280_i2c_driver = {
> >                 .of_match_table = bmp280_of_i2c_match,
> >                 .pm = pm_ptr(&bmp280_dev_pm_ops),
> >         },
> > -       .probe          = bmp280_i2c_probe,
> > +       .probe_new      = bmp280_i2c_probe,
> >         .id_table       = bmp280_i2c_id,
> >  };
> >  module_i2c_driver(bmp280_i2c_driver);
>
> Best regards
> Uwe
>
Kind regards
Angel

2022-11-05 15:43:42

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] i2c: core: Introduce i2c_client_get_device_id helper

On Tue, 1 Nov 2022 16:58:13 +0200
Andy Shevchenko <[email protected]> wrote:

> On Sun, Oct 30, 2022 at 06:51:06PM +0100, Angel Iglesias wrote:
> > Hello,
> >
> > I don't want to step anyone's work here, so I'm sending this RFC to the
> > devs involved in the original discussion. I read on Uwe Kleine-König's
> > patchset submission thread the necessity for an i2c helper to aid with the
> > migration to the new i2c_driver .probe_new callback. Following the
> > suggestions made there, I wrote this small patchset implementing the
> > suggested helper function and ported the bmp280 IIO i2c probe to the new
> > probe using that helper.
>
> For the entire series (please drop RFC in the next version)
> Reviewed-by: Andy Shevchenko <[email protected]>

I'm happy to pick up the next version but a question on 'route' in to the kernel.

I can do an immutable branch with just the new function call in it if
that is useful given I assume this is applicable across a bunch of subsystems?

Jonathan

>
> > Thanks for your time!
> > Angel
> >
> > Original discussion thread for additional context:
> > https://lore.kernel.org/all/[email protected]/
> >
> > Angel Iglesias (2):
> > i2c: core: Introduce i2c_client_get_device_id helper function
> > iio: pressure: bmp280: convert to i2c's .probe_new()
> >
> > drivers/i2c/i2c-core-base.c | 15 +++++++++++++++
> > drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
> > include/linux/i2c.h | 1 +
> > 3 files changed, 20 insertions(+), 4 deletions(-)
> >
> >
> > base-commit: c32793afc6976e170f6ab11ca3750fe94fb3454d
> > --
> > 2.38.1
> >
>


2022-11-05 16:01:03

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [RFC PATCH 2/2] iio: pressure: bmp280: convert to i2c's .probe_new()

On Wed, 02 Nov 2022 01:16:44 +0100
Angel Iglesias <[email protected]> wrote:

> On Tue, 2022-11-01 at 22:52 +0100, Uwe Kleine-König wrote:
> > Hello,
> >
> > On Sun, Oct 30, 2022 at 06:53:11PM +0100, Angel Iglesias wrote:
> > > Use i2c_client_get_device_id() to get the i2c_device_id* parameter in the
> > > .new_probe() callback.
> > >
> > > Signed-off-by: Angel Iglesias <[email protected]>
> > > ---
> > >  drivers/iio/pressure/bmp280-i2c.c | 8 ++++----
> > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/iio/pressure/bmp280-i2c.c
> > > b/drivers/iio/pressure/bmp280-i2c.c
> > > index 0c27211f3ea0..20073b09b3e3 100644
> > > --- a/drivers/iio/pressure/bmp280-i2c.c
> > > +++ b/drivers/iio/pressure/bmp280-i2c.c
> > > @@ -5,11 +5,11 @@
> > >  
> > >  #include "bmp280.h"
> > >  
> > > -static int bmp280_i2c_probe(struct i2c_client *client,
> > > -                           const struct i2c_device_id *id)
> > > +static int bmp280_i2c_probe(struct i2c_client *client)
> > >  {
> > > -       struct regmap *regmap;
> > > +       const struct i2c_device_id *id = i2c_client_get_device_id(client);
> > >         const struct regmap_config *regmap_config;
> > > +       struct regmap *regmap;
> > >  
> > >         switch (id->driver_data) {
> > >         case BMP180_CHIP_ID:
> >
> > What is the motivation for moving regmap? I thought reverse christmas
> > tree is only a thing in network code? I would have left the regmap
> > declaration where it is.
>
> Long story short, I worked previously on a small refactor of this driver to add
> support for a new family of sensors. During the different iterations of the
> patchset, one thing that was agreed was unifying the driver coding style to
> reverse xmas tree. For some extra context, here's the thread:
> https://lore.kernel.org/all/20220814145249.701f1261@jic23-huawei/

Not something I feel strongly enough about either way, but has benefit of
consistency. However, it's an unrelated change in this patch, so drop it
to avoid the noise in a patch where you have more significant changes.

Jonathan

>
> > > @@ -65,7 +65,7 @@ static struct i2c_driver bmp280_i2c_driver = {
> > >                 .of_match_table = bmp280_of_i2c_match,
> > >                 .pm = pm_ptr(&bmp280_dev_pm_ops),
> > >         },
> > > -       .probe          = bmp280_i2c_probe,
> > > +       .probe_new      = bmp280_i2c_probe,
> > >         .id_table       = bmp280_i2c_id,
> > >  };
> > >  module_i2c_driver(bmp280_i2c_driver);
> >
> > Best regards
> > Uwe
> >
> Kind regards
> Angel


2022-11-05 21:36:57

by Wolfram Sang

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] i2c: core: Introduce i2c_client_get_device_id helper


> I can do an immutable branch with just the new function call in it if
> that is useful given I assume this is applicable across a bunch of subsystems?

I'd think I should provide the immutable branch with the new I2C API
call. Feels a bit more logical. Will that work for you as well?


Attachments:
(No filename) (296.00 B)
signature.asc (849.00 B)
Download all attachments

2022-11-06 12:40:01

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [RFC PATCH 0/2] i2c: core: Introduce i2c_client_get_device_id helper

On Sat, 5 Nov 2022 22:29:29 +0100
Wolfram Sang <[email protected]> wrote:

> > I can do an immutable branch with just the new function call in it if
> > that is useful given I assume this is applicable across a bunch of subsystems?
>
> I'd think I should provide the immutable branch with the new I2C API
> call. Feels a bit more logical. Will that work for you as well?
>

Absolutely. That's even better - I didn't want to assign you work to do :)

Jonathan