diff mbox series

[RFC/RFT] iio: imu: lsm6dsx: Use i2c_get_match_data()

Message ID 20230812083204.55346-1-biju.das.jz@bp.renesas.com (mailing list archive)
State Changes Requested
Headers show
Series [RFC/RFT] iio: imu: lsm6dsx: Use i2c_get_match_data() | expand

Commit Message

Biju Das Aug. 12, 2023, 8:32 a.m. UTC
Replace device_get_match_data() and id lookup for retrieving match data
by i2c_get_match_data() by converting enum->pointer for data in the
match table.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c | 126 ++++++++++++--------
 1 file changed, 74 insertions(+), 52 deletions(-)

Comments

Geert Uytterhoeven Aug. 14, 2023, 12:31 p.m. UTC | #1
Hi Biju,

On Sat, Aug 12, 2023 at 10:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> Replace device_get_match_data() and id lookup for retrieving match data
> by i2c_get_match_data() by converting enum->pointer for data in the
> match table.
>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Thanks for your patch!

> index 911444ec57c0..a2def435c9c2 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> @@ -16,6 +16,30 @@
>
>  #include "st_lsm6dsx.h"
>
> +static const int lsm6ds3 = ST_LSM6DS3_ID;
> +static const int lsm6ds3h = ST_LSM6DS3H_ID;

As these are single values, not structures with multiple members,
I see not much value in adding all these variables, which increases
kernel size...

> @@ -23,12 +47,10 @@ static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
>
>  static int st_lsm6dsx_i2c_probe(struct i2c_client *client)
>  {
> -       int hw_id;
> +       const int *hw_id;
>         struct regmap *regmap;
>
> -       hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
> -       if (!hw_id)
> -               hw_id = i2c_client_get_device_id(client)->driver_data;
> +       hw_id = i2c_get_match_data(client);
>         if (!hw_id)
>                 return -EINVAL;

So just

    -        hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
    -       if (!hw_id)
    -               hw_id = i2c_client_get_device_id(client)->driver_data;
    +        hw_id = (kernel_ulong_t)i2c_get_match_data(client);

and be done with it?

Gr{oetje,eeting}s,

                        Geert
Biju Das Aug. 14, 2023, 12:59 p.m. UTC | #2
Hi Geert,

Thanks for the feedback.

> Subject: Re: [PATCH RFC/RFT] iio: imu: lsm6dsx: Use i2c_get_match_data()
> 
> Hi Biju,
> 
> On Sat, Aug 12, 2023 at 10:32 AM Biju Das <biju.das.jz@bp.renesas.com>
> wrote:
> > Replace device_get_match_data() and id lookup for retrieving match
> > data by i2c_get_match_data() by converting enum->pointer for data in
> > the match table.
> >
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> 
> Thanks for your patch!
> 
> > index 911444ec57c0..a2def435c9c2 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> > @@ -16,6 +16,30 @@
> >
> >  #include "st_lsm6dsx.h"
> >
> > +static const int lsm6ds3 = ST_LSM6DS3_ID; static const int lsm6ds3h =
> > +ST_LSM6DS3H_ID;
> 
> As these are single values, not structures with multiple members, I see
> not much value in adding all these variables, which increases kernel
> size...

OK.

> 
> > @@ -23,12 +47,10 @@ static const struct regmap_config
> > st_lsm6dsx_i2c_regmap_config = {
> >
> >  static int st_lsm6dsx_i2c_probe(struct i2c_client *client)  {
> > -       int hw_id;
> > +       const int *hw_id;
> >         struct regmap *regmap;
> >
> > -       hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
> > -       if (!hw_id)
> > -               hw_id = i2c_client_get_device_id(client)->driver_data;
> > +       hw_id = i2c_get_match_data(client);
> >         if (!hw_id)
> >                 return -EINVAL;
> 
> So just
> 
>     -        hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
>     -       if (!hw_id)
>     -               hw_id = i2c_client_get_device_id(client)->driver_data;
>     +        hw_id = (kernel_ulong_t)i2c_get_match_data(client);
> 
> and be done with it?

Agreed for this case. This will fit here.

There is a discussion related to extending device_match_data() to
buses [1]
[1] https://lore.kernel.org/all/20230807204505.5f3f245e@jic23-huawei/

Some maintainer's want legacy enums in ID table and pointer in OF table. There won't be uniform data across OF/ACPI/ID tables.

So i2c_get_match_data() and device_match_data() will fail in those cases.

Once case is here [1]
[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/iio/magnetometer/ak8975.c?h=next-20230809#n936

Here name = id->name; which is making it not backward compatible.

By looking at the data in OF/I2C table (pointer vs enum) in the table, it needs to return NULL to make it backward compatible.

Cheers,
Biju
Andy Shevchenko Aug. 15, 2023, 7:16 a.m. UTC | #3
On Sat, Aug 12, 2023 at 09:32:04AM +0100, Biju Das wrote:
> Replace device_get_match_data() and id lookup for retrieving match data
> by i2c_get_match_data() by converting enum->pointer for data in the
> match table.

...

> +static const int lsm6ds3 = ST_LSM6DS3_ID;
> +static const int lsm6ds3h = ST_LSM6DS3H_ID;
> +static const int lsm6dsl = ST_LSM6DSL_ID;
> +static const int lsm6dsm = ST_LSM6DSM_ID;
> +static const int ism330dlc = ST_ISM330DLC_ID;
> +static const int lsm6dso = ST_LSM6DSO_ID;
> +static const int asm330lhh = ST_ASM330LHH_ID;
> +static const int lsm6dsox = ST_LSM6DSOX_ID;
> +static const int lsm6dsr = ST_LSM6DSR_ID;
> +static const int lsm6ds3tr_c = ST_LSM6DS3TRC_ID;
> +static const int ism330dhcx = ST_ISM330DHCX_ID;
> +static const int lsm9ds1_imu = ST_LSM9DS1_ID;
> +static const int lsm6ds0 = ST_LSM6DS0_ID;
> +static const int lsm6dsrx = ST_LSM6DSRX_ID;
> +static const int lsm6dst = ST_LSM6DST_ID;
> +static const int lsm6dsop = ST_LSM6DSOP_ID;
> +static const int asm330lhhx = ST_ASM330LHHX_ID;
> +static const int lsm6dstx = ST_LSM6DSTX_ID;
> +static const int lsm6dsv = ST_LSM6DSV_ID;
> +static const int lsm6dsv16x = ST_LSM6DSV16X_ID;
> +static const int lsm6dso16is = ST_LSM6DSO16IS_ID;
> +static const int ism330is = ST_ISM330IS_ID;
> +static const int asm330lhb = ST_ASM330LHB_ID;

I think it would be better to have a data type for this

struct st_lsm6dsx_id {
	int id;
};

...

>  	{
>  		.compatible = "st,lsm6ds3",
> -		.data = (void *)ST_LSM6DS3_ID,
> +		.data = &lsm6ds3,
>  	},

And these can be folded at least by one line each (if you want to be
in 80 limit).
Jonathan Cameron Aug. 28, 2023, 1:30 p.m. UTC | #4
On Sat, 12 Aug 2023 09:32:04 +0100
Biju Das <biju.das.jz@bp.renesas.com> wrote:

> Replace device_get_match_data() and id lookup for retrieving match data
> by i2c_get_match_data() by converting enum->pointer for data in the
> match table.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>

Hi Biju

So, there is an issue in this driver that I've been wanting fixed for a while
that is related to the fact we only pass through an enum and then map it
to the relevant structure internally. This driver doesn't handle fall back compatibles
and adds a look up that we shouldn't need.

Assuming we don't have incompatible parts with the same WhoAmI value
(it has happened in past *sigh)
What should be happening here is:
1) The match tables contain pointers to appropriate entries of st_lsm6dsx_sensor_settings[]
2) We then assume that that info isn't available and try matching whoami against all devices
   possibly with a short cut for the value matching what is expected.
   If it is the one we expect. Good.
   If it is a different whoami but we know about it. Good - maybe print some info as that's
   probably some outdated firmware..
   If we have no idea print a message and muddle on with the data provided by the id table
   as that's probably a fallback compatible case where the whoami is different but the chip
   is fully compatible.

Key to this is that we should just point into st_lsm6dsx_sensor_settings but that needs some
mess probably via externs pointers with definitions in the header, but set in the core file,
to avoid having to make that huge structure directly visible.

Not a nice one to solve and I'm open to other suggestions on how to tidy this up.

Jonathan


> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c | 126 ++++++++++++--------
>  1 file changed, 74 insertions(+), 52 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> index 911444ec57c0..a2def435c9c2 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
> @@ -16,6 +16,30 @@
>  
>  #include "st_lsm6dsx.h"
>  
> +static const int lsm6ds3 = ST_LSM6DS3_ID;
> +static const int lsm6ds3h = ST_LSM6DS3H_ID;
> +static const int lsm6dsl = ST_LSM6DSL_ID;
> +static const int lsm6dsm = ST_LSM6DSM_ID;
> +static const int ism330dlc = ST_ISM330DLC_ID;
> +static const int lsm6dso = ST_LSM6DSO_ID;
> +static const int asm330lhh = ST_ASM330LHH_ID;
> +static const int lsm6dsox = ST_LSM6DSOX_ID;
> +static const int lsm6dsr = ST_LSM6DSR_ID;
> +static const int lsm6ds3tr_c = ST_LSM6DS3TRC_ID;
> +static const int ism330dhcx = ST_ISM330DHCX_ID;
> +static const int lsm9ds1_imu = ST_LSM9DS1_ID;
> +static const int lsm6ds0 = ST_LSM6DS0_ID;
> +static const int lsm6dsrx = ST_LSM6DSRX_ID;
> +static const int lsm6dst = ST_LSM6DST_ID;
> +static const int lsm6dsop = ST_LSM6DSOP_ID;
> +static const int asm330lhhx = ST_ASM330LHHX_ID;
> +static const int lsm6dstx = ST_LSM6DSTX_ID;
> +static const int lsm6dsv = ST_LSM6DSV_ID;
> +static const int lsm6dsv16x = ST_LSM6DSV16X_ID;
> +static const int lsm6dso16is = ST_LSM6DSO16IS_ID;
> +static const int ism330is = ST_ISM330IS_ID;
> +static const int asm330lhb = ST_ASM330LHB_ID;
> +
>  static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
>  	.reg_bits = 8,
>  	.val_bits = 8,
> @@ -23,12 +47,10 @@ static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
>  
>  static int st_lsm6dsx_i2c_probe(struct i2c_client *client)
>  {
> -	int hw_id;
> +	const int *hw_id;
>  	struct regmap *regmap;
>  
> -	hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
> -	if (!hw_id)
> -		hw_id = i2c_client_get_device_id(client)->driver_data;
> +	hw_id = i2c_get_match_data(client);
>  	if (!hw_id)
>  		return -EINVAL;
>  
> @@ -38,136 +60,136 @@ static int st_lsm6dsx_i2c_probe(struct i2c_client *client)
>  		return PTR_ERR(regmap);
>  	}
>  
> -	return st_lsm6dsx_probe(&client->dev, client->irq, hw_id, regmap);
> +	return st_lsm6dsx_probe(&client->dev, client->irq, *hw_id, regmap);
>  }
>  
>  static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
>  	{
>  		.compatible = "st,lsm6ds3",
> -		.data = (void *)ST_LSM6DS3_ID,
> +		.data = &lsm6ds3,
>  	},
>  	{
>  		.compatible = "st,lsm6ds3h",
> -		.data = (void *)ST_LSM6DS3H_ID,
> +		.data = &lsm6ds3h,
>  	},
>  	{
>  		.compatible = "st,lsm6dsl",
> -		.data = (void *)ST_LSM6DSL_ID,
> +		.data = &lsm6dsl,
>  	},
>  	{
>  		.compatible = "st,lsm6dsm",
> -		.data = (void *)ST_LSM6DSM_ID,
> +		.data = &lsm6dsm,
>  	},
>  	{
>  		.compatible = "st,ism330dlc",
> -		.data = (void *)ST_ISM330DLC_ID,
> +		.data = &ism330dlc,
>  	},
>  	{
>  		.compatible = "st,lsm6dso",
> -		.data = (void *)ST_LSM6DSO_ID,
> +		.data = &lsm6dso,
>  	},
>  	{
>  		.compatible = "st,asm330lhh",
> -		.data = (void *)ST_ASM330LHH_ID,
> +		.data = &asm330lhh,
>  	},
>  	{
>  		.compatible = "st,lsm6dsox",
> -		.data = (void *)ST_LSM6DSOX_ID,
> +		.data = &lsm6dsox,
>  	},
>  	{
>  		.compatible = "st,lsm6dsr",
> -		.data = (void *)ST_LSM6DSR_ID,
> +		.data = &lsm6dsr,
>  	},
>  	{
>  		.compatible = "st,lsm6ds3tr-c",
> -		.data = (void *)ST_LSM6DS3TRC_ID,
> +		.data = &lsm6ds3tr_c,
>  	},
>  	{
>  		.compatible = "st,ism330dhcx",
> -		.data = (void *)ST_ISM330DHCX_ID,
> +		.data = &ism330dhcx,
>  	},
>  	{
>  		.compatible = "st,lsm9ds1-imu",
> -		.data = (void *)ST_LSM9DS1_ID,
> +		.data = &lsm9ds1_imu,
>  	},
>  	{
>  		.compatible = "st,lsm6ds0",
> -		.data = (void *)ST_LSM6DS0_ID,
> +		.data = &lsm6ds0,
>  	},
>  	{
>  		.compatible = "st,lsm6dsrx",
> -		.data = (void *)ST_LSM6DSRX_ID,
> +		.data = &lsm6dsrx,
>  	},
>  	{
>  		.compatible = "st,lsm6dst",
> -		.data = (void *)ST_LSM6DST_ID,
> +		.data = &lsm6dst,
>  	},
>  	{
>  		.compatible = "st,lsm6dsop",
> -		.data = (void *)ST_LSM6DSOP_ID,
> +		.data = &lsm6dsop,
>  	},
>  	{
>  		.compatible = "st,asm330lhhx",
> -		.data = (void *)ST_ASM330LHHX_ID,
> +		.data = &asm330lhhx,
>  	},
>  	{
>  		.compatible = "st,lsm6dstx",
> -		.data = (void *)ST_LSM6DSTX_ID,
> +		.data = &lsm6dstx,
>  	},
>  	{
>  		.compatible = "st,lsm6dsv",
> -		.data = (void *)ST_LSM6DSV_ID,
> +		.data = &lsm6dsv,
>  	},
>  	{
>  		.compatible = "st,lsm6dsv16x",
> -		.data = (void *)ST_LSM6DSV16X_ID,
> +		.data = &lsm6dsv16x,
>  	},
>  	{
>  		.compatible = "st,lsm6dso16is",
> -		.data = (void *)ST_LSM6DSO16IS_ID,
> +		.data = &lsm6dso16is,
>  	},
>  	{
>  		.compatible = "st,ism330is",
> -		.data = (void *)ST_ISM330IS_ID,
> +		.data = &ism330is,
>  	},
>  	{
>  		.compatible = "st,asm330lhb",
> -		.data = (void *)ST_ASM330LHB_ID,
> +		.data = &asm330lhb,
>  	},
>  	{},
>  };
>  MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
>  
>  static const struct acpi_device_id st_lsm6dsx_i2c_acpi_match[] = {
> -	{ "SMO8B30", ST_LSM6DS3TRC_ID, },
> +	{ "SMO8B30", (kernel_ulong_t)&lsm6ds3tr_c, },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(acpi, st_lsm6dsx_i2c_acpi_match);
>  
>  static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
> -	{ ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
> -	{ ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
> -	{ ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
> -	{ ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
> -	{ ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
> -	{ ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
> -	{ ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
> -	{ ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
> -	{ ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
> -	{ ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
> -	{ ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
> -	{ ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
> -	{ ST_LSM6DS0_DEV_NAME, ST_LSM6DS0_ID },
> -	{ ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
> -	{ ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
> -	{ ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
> -	{ ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID },
> -	{ ST_LSM6DSTX_DEV_NAME, ST_LSM6DSTX_ID },
> -	{ ST_LSM6DSV_DEV_NAME, ST_LSM6DSV_ID },
> -	{ ST_LSM6DSV16X_DEV_NAME, ST_LSM6DSV16X_ID },
> -	{ ST_LSM6DSO16IS_DEV_NAME, ST_LSM6DSO16IS_ID },
> -	{ ST_ISM330IS_DEV_NAME, ST_ISM330IS_ID },
> -	{ ST_ASM330LHB_DEV_NAME, ST_ASM330LHB_ID },
> +	{ ST_LSM6DS3_DEV_NAME, (kernel_ulong_t)&lsm6ds3 },
> +	{ ST_LSM6DS3H_DEV_NAME, (kernel_ulong_t)&lsm6ds3h },
> +	{ ST_LSM6DSL_DEV_NAME, (kernel_ulong_t)&lsm6dsl },
> +	{ ST_LSM6DSM_DEV_NAME, (kernel_ulong_t)&lsm6dsm },
> +	{ ST_ISM330DLC_DEV_NAME, (kernel_ulong_t)&ism330dlc },
> +	{ ST_LSM6DSO_DEV_NAME, (kernel_ulong_t)&lsm6dso },
> +	{ ST_ASM330LHH_DEV_NAME, (kernel_ulong_t)&asm330lhh },
> +	{ ST_LSM6DSOX_DEV_NAME, (kernel_ulong_t)&lsm6dsox },
> +	{ ST_LSM6DSR_DEV_NAME, (kernel_ulong_t)&lsm6dsr },
> +	{ ST_LSM6DS3TRC_DEV_NAME, (kernel_ulong_t)&lsm6ds3tr_c },
> +	{ ST_ISM330DHCX_DEV_NAME, (kernel_ulong_t)&ism330dhcx },
> +	{ ST_LSM9DS1_DEV_NAME, (kernel_ulong_t)&lsm9ds1_imu },
> +	{ ST_LSM6DS0_DEV_NAME, (kernel_ulong_t)&lsm6ds0 },
> +	{ ST_LSM6DSRX_DEV_NAME, (kernel_ulong_t)&lsm6dsrx },
> +	{ ST_LSM6DST_DEV_NAME, (kernel_ulong_t)&lsm6dst },
> +	{ ST_LSM6DSOP_DEV_NAME, (kernel_ulong_t)&lsm6dsop },
> +	{ ST_ASM330LHHX_DEV_NAME, (kernel_ulong_t)&asm330lhhx },
> +	{ ST_LSM6DSTX_DEV_NAME, (kernel_ulong_t)&lsm6dstx },
> +	{ ST_LSM6DSV_DEV_NAME, (kernel_ulong_t)&lsm6dsv },
> +	{ ST_LSM6DSV16X_DEV_NAME, (kernel_ulong_t)&lsm6dsv16x },
> +	{ ST_LSM6DSO16IS_DEV_NAME, (kernel_ulong_t)&lsm6dso16is },
> +	{ ST_ISM330IS_DEV_NAME, (kernel_ulong_t)&ism330is },
> +	{ ST_ASM330LHB_DEV_NAME, (kernel_ulong_t)&asm330lhb },
>  	{},
>  };
>  MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
diff mbox series

Patch

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
index 911444ec57c0..a2def435c9c2 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
@@ -16,6 +16,30 @@ 
 
 #include "st_lsm6dsx.h"
 
+static const int lsm6ds3 = ST_LSM6DS3_ID;
+static const int lsm6ds3h = ST_LSM6DS3H_ID;
+static const int lsm6dsl = ST_LSM6DSL_ID;
+static const int lsm6dsm = ST_LSM6DSM_ID;
+static const int ism330dlc = ST_ISM330DLC_ID;
+static const int lsm6dso = ST_LSM6DSO_ID;
+static const int asm330lhh = ST_ASM330LHH_ID;
+static const int lsm6dsox = ST_LSM6DSOX_ID;
+static const int lsm6dsr = ST_LSM6DSR_ID;
+static const int lsm6ds3tr_c = ST_LSM6DS3TRC_ID;
+static const int ism330dhcx = ST_ISM330DHCX_ID;
+static const int lsm9ds1_imu = ST_LSM9DS1_ID;
+static const int lsm6ds0 = ST_LSM6DS0_ID;
+static const int lsm6dsrx = ST_LSM6DSRX_ID;
+static const int lsm6dst = ST_LSM6DST_ID;
+static const int lsm6dsop = ST_LSM6DSOP_ID;
+static const int asm330lhhx = ST_ASM330LHHX_ID;
+static const int lsm6dstx = ST_LSM6DSTX_ID;
+static const int lsm6dsv = ST_LSM6DSV_ID;
+static const int lsm6dsv16x = ST_LSM6DSV16X_ID;
+static const int lsm6dso16is = ST_LSM6DSO16IS_ID;
+static const int ism330is = ST_ISM330IS_ID;
+static const int asm330lhb = ST_ASM330LHB_ID;
+
 static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
 	.reg_bits = 8,
 	.val_bits = 8,
@@ -23,12 +47,10 @@  static const struct regmap_config st_lsm6dsx_i2c_regmap_config = {
 
 static int st_lsm6dsx_i2c_probe(struct i2c_client *client)
 {
-	int hw_id;
+	const int *hw_id;
 	struct regmap *regmap;
 
-	hw_id = (kernel_ulong_t)device_get_match_data(&client->dev);
-	if (!hw_id)
-		hw_id = i2c_client_get_device_id(client)->driver_data;
+	hw_id = i2c_get_match_data(client);
 	if (!hw_id)
 		return -EINVAL;
 
@@ -38,136 +60,136 @@  static int st_lsm6dsx_i2c_probe(struct i2c_client *client)
 		return PTR_ERR(regmap);
 	}
 
-	return st_lsm6dsx_probe(&client->dev, client->irq, hw_id, regmap);
+	return st_lsm6dsx_probe(&client->dev, client->irq, *hw_id, regmap);
 }
 
 static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
 	{
 		.compatible = "st,lsm6ds3",
-		.data = (void *)ST_LSM6DS3_ID,
+		.data = &lsm6ds3,
 	},
 	{
 		.compatible = "st,lsm6ds3h",
-		.data = (void *)ST_LSM6DS3H_ID,
+		.data = &lsm6ds3h,
 	},
 	{
 		.compatible = "st,lsm6dsl",
-		.data = (void *)ST_LSM6DSL_ID,
+		.data = &lsm6dsl,
 	},
 	{
 		.compatible = "st,lsm6dsm",
-		.data = (void *)ST_LSM6DSM_ID,
+		.data = &lsm6dsm,
 	},
 	{
 		.compatible = "st,ism330dlc",
-		.data = (void *)ST_ISM330DLC_ID,
+		.data = &ism330dlc,
 	},
 	{
 		.compatible = "st,lsm6dso",
-		.data = (void *)ST_LSM6DSO_ID,
+		.data = &lsm6dso,
 	},
 	{
 		.compatible = "st,asm330lhh",
-		.data = (void *)ST_ASM330LHH_ID,
+		.data = &asm330lhh,
 	},
 	{
 		.compatible = "st,lsm6dsox",
-		.data = (void *)ST_LSM6DSOX_ID,
+		.data = &lsm6dsox,
 	},
 	{
 		.compatible = "st,lsm6dsr",
-		.data = (void *)ST_LSM6DSR_ID,
+		.data = &lsm6dsr,
 	},
 	{
 		.compatible = "st,lsm6ds3tr-c",
-		.data = (void *)ST_LSM6DS3TRC_ID,
+		.data = &lsm6ds3tr_c,
 	},
 	{
 		.compatible = "st,ism330dhcx",
-		.data = (void *)ST_ISM330DHCX_ID,
+		.data = &ism330dhcx,
 	},
 	{
 		.compatible = "st,lsm9ds1-imu",
-		.data = (void *)ST_LSM9DS1_ID,
+		.data = &lsm9ds1_imu,
 	},
 	{
 		.compatible = "st,lsm6ds0",
-		.data = (void *)ST_LSM6DS0_ID,
+		.data = &lsm6ds0,
 	},
 	{
 		.compatible = "st,lsm6dsrx",
-		.data = (void *)ST_LSM6DSRX_ID,
+		.data = &lsm6dsrx,
 	},
 	{
 		.compatible = "st,lsm6dst",
-		.data = (void *)ST_LSM6DST_ID,
+		.data = &lsm6dst,
 	},
 	{
 		.compatible = "st,lsm6dsop",
-		.data = (void *)ST_LSM6DSOP_ID,
+		.data = &lsm6dsop,
 	},
 	{
 		.compatible = "st,asm330lhhx",
-		.data = (void *)ST_ASM330LHHX_ID,
+		.data = &asm330lhhx,
 	},
 	{
 		.compatible = "st,lsm6dstx",
-		.data = (void *)ST_LSM6DSTX_ID,
+		.data = &lsm6dstx,
 	},
 	{
 		.compatible = "st,lsm6dsv",
-		.data = (void *)ST_LSM6DSV_ID,
+		.data = &lsm6dsv,
 	},
 	{
 		.compatible = "st,lsm6dsv16x",
-		.data = (void *)ST_LSM6DSV16X_ID,
+		.data = &lsm6dsv16x,
 	},
 	{
 		.compatible = "st,lsm6dso16is",
-		.data = (void *)ST_LSM6DSO16IS_ID,
+		.data = &lsm6dso16is,
 	},
 	{
 		.compatible = "st,ism330is",
-		.data = (void *)ST_ISM330IS_ID,
+		.data = &ism330is,
 	},
 	{
 		.compatible = "st,asm330lhb",
-		.data = (void *)ST_ASM330LHB_ID,
+		.data = &asm330lhb,
 	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
 
 static const struct acpi_device_id st_lsm6dsx_i2c_acpi_match[] = {
-	{ "SMO8B30", ST_LSM6DS3TRC_ID, },
+	{ "SMO8B30", (kernel_ulong_t)&lsm6ds3tr_c, },
 	{}
 };
 MODULE_DEVICE_TABLE(acpi, st_lsm6dsx_i2c_acpi_match);
 
 static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
-	{ ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
-	{ ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID },
-	{ ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID },
-	{ ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
-	{ ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID },
-	{ ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID },
-	{ ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID },
-	{ ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID },
-	{ ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID },
-	{ ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID },
-	{ ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID },
-	{ ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID },
-	{ ST_LSM6DS0_DEV_NAME, ST_LSM6DS0_ID },
-	{ ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID },
-	{ ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID },
-	{ ST_LSM6DSOP_DEV_NAME, ST_LSM6DSOP_ID },
-	{ ST_ASM330LHHX_DEV_NAME, ST_ASM330LHHX_ID },
-	{ ST_LSM6DSTX_DEV_NAME, ST_LSM6DSTX_ID },
-	{ ST_LSM6DSV_DEV_NAME, ST_LSM6DSV_ID },
-	{ ST_LSM6DSV16X_DEV_NAME, ST_LSM6DSV16X_ID },
-	{ ST_LSM6DSO16IS_DEV_NAME, ST_LSM6DSO16IS_ID },
-	{ ST_ISM330IS_DEV_NAME, ST_ISM330IS_ID },
-	{ ST_ASM330LHB_DEV_NAME, ST_ASM330LHB_ID },
+	{ ST_LSM6DS3_DEV_NAME, (kernel_ulong_t)&lsm6ds3 },
+	{ ST_LSM6DS3H_DEV_NAME, (kernel_ulong_t)&lsm6ds3h },
+	{ ST_LSM6DSL_DEV_NAME, (kernel_ulong_t)&lsm6dsl },
+	{ ST_LSM6DSM_DEV_NAME, (kernel_ulong_t)&lsm6dsm },
+	{ ST_ISM330DLC_DEV_NAME, (kernel_ulong_t)&ism330dlc },
+	{ ST_LSM6DSO_DEV_NAME, (kernel_ulong_t)&lsm6dso },
+	{ ST_ASM330LHH_DEV_NAME, (kernel_ulong_t)&asm330lhh },
+	{ ST_LSM6DSOX_DEV_NAME, (kernel_ulong_t)&lsm6dsox },
+	{ ST_LSM6DSR_DEV_NAME, (kernel_ulong_t)&lsm6dsr },
+	{ ST_LSM6DS3TRC_DEV_NAME, (kernel_ulong_t)&lsm6ds3tr_c },
+	{ ST_ISM330DHCX_DEV_NAME, (kernel_ulong_t)&ism330dhcx },
+	{ ST_LSM9DS1_DEV_NAME, (kernel_ulong_t)&lsm9ds1_imu },
+	{ ST_LSM6DS0_DEV_NAME, (kernel_ulong_t)&lsm6ds0 },
+	{ ST_LSM6DSRX_DEV_NAME, (kernel_ulong_t)&lsm6dsrx },
+	{ ST_LSM6DST_DEV_NAME, (kernel_ulong_t)&lsm6dst },
+	{ ST_LSM6DSOP_DEV_NAME, (kernel_ulong_t)&lsm6dsop },
+	{ ST_ASM330LHHX_DEV_NAME, (kernel_ulong_t)&asm330lhhx },
+	{ ST_LSM6DSTX_DEV_NAME, (kernel_ulong_t)&lsm6dstx },
+	{ ST_LSM6DSV_DEV_NAME, (kernel_ulong_t)&lsm6dsv },
+	{ ST_LSM6DSV16X_DEV_NAME, (kernel_ulong_t)&lsm6dsv16x },
+	{ ST_LSM6DSO16IS_DEV_NAME, (kernel_ulong_t)&lsm6dso16is },
+	{ ST_ISM330IS_DEV_NAME, (kernel_ulong_t)&ism330is },
+	{ ST_ASM330LHB_DEV_NAME, (kernel_ulong_t)&asm330lhb },
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);