Message ID | 20241108-p3t1085-v2-3-6a8990a59efd@nxp.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | iio: temperature: Add support for P3T1085 | expand |
On 11/8/24 14:26, Frank Li wrote: > Add support for I3C device in the tmp108 driver to handle the P3T1085 > sensor. Register the I3C device driver to enable I3C functionality for the > sensor. > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/hwmon/tmp108.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c > index bfbea6349a95f..83d6847cb542c 100644 > --- a/drivers/hwmon/tmp108.c > +++ b/drivers/hwmon/tmp108.c > @@ -13,6 +13,8 @@ > #include <linux/mutex.h> > #include <linux/of.h> > #include <linux/i2c.h> > +#include <linux/i3c/device.h> > +#include <linux/i3c/master.h> > #include <linux/init.h> > #include <linux/jiffies.h> > #include <linux/regmap.h> > @@ -442,6 +444,35 @@ static struct i2c_driver tmp108_driver = { > > module_i2c_driver(tmp108_driver); > > +#ifdef CONFIG_REGMAP_I3C REGMAP_I3C needs to be selected in Kconfig. Maybe with "select REGMAP_I3C if I3C" or similar, but we'll also need to cover situations where I2C=y and I3C=n. That means that an additional "depends on I3C || I3C=n" may be necessary. In summary, config SENSORS_TMP108 tristate "Texas Instruments TMP108 and P3T1085" <-- depends on I2C select REGMAP_I2C depends on depends on I3C || I3C=n <-- select REGMAP_I3C if I3C <-- help If you say yes here you get support for Texas Instruments TMP108 and compatible sensor chips. <-- This driver can also be built as a module. If so, the module will be called tmp108. Thanks, Guenter > +static const struct i3c_device_id p3t1085_i3c_ids[] = { > + I3C_DEVICE(0x011b, 0x1529, NULL), > + {}, > +}; > +MODULE_DEVICE_TABLE(i3c, p3t1085_i3c_ids); > + > +static int p3t1085_i3c_probe(struct i3c_device *i3cdev) > +{ > + struct regmap *regmap; > + > + regmap = devm_regmap_init_i3c(i3cdev, &tmp108_regmap_config); > + if (IS_ERR(regmap)) > + return dev_err_probe(&i3cdev->dev, PTR_ERR(regmap), > + "Failed to register i3c regmap\n"); > + > + return tmp108_common_probe(&i3cdev->dev, regmap, "p3t1085_i3c"); > +} > + > +static struct i3c_driver p3t1085_driver = { > + .driver = { > + .name = "p3t1085_i3c", > + }, > + .probe = p3t1085_i3c_probe, > + .id_table = p3t1085_i3c_ids, > +}; > +module_i3c_driver(p3t1085_driver); > +#endif > + > MODULE_AUTHOR("John Muir <john@jmuir.com>"); > MODULE_DESCRIPTION("Texas Instruments TMP108 temperature sensor driver"); > MODULE_LICENSE("GPL"); >
On Fri, 08 Nov 2024 17:26:57 -0500 Frank Li <Frank.Li@nxp.com> wrote: > Add support for I3C device in the tmp108 driver to handle the P3T1085 > sensor. Register the I3C device driver to enable I3C functionality for the > sensor. > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/hwmon/tmp108.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c > index bfbea6349a95f..83d6847cb542c 100644 > --- a/drivers/hwmon/tmp108.c > +++ b/drivers/hwmon/tmp108.c > @@ -13,6 +13,8 @@ > #include <linux/mutex.h> > #include <linux/of.h> > #include <linux/i2c.h> > +#include <linux/i3c/device.h> > +#include <linux/i3c/master.h> Seems odd you need master.h in a device driver. I'll guess that's because you should be using i3cdev_to_device() and not looking in the i3c_device structure at all. > #include <linux/init.h> > #include <linux/jiffies.h> > #include <linux/regmap.h> > @@ -442,6 +444,35 @@ static struct i2c_driver tmp108_driver = { > > module_i2c_driver(tmp108_driver); > > +#ifdef CONFIG_REGMAP_I3C > +static const struct i3c_device_id p3t1085_i3c_ids[] = { > + I3C_DEVICE(0x011b, 0x1529, NULL), > + {}, Trivial, but no trailing comma needed here as nothing can come after this terminator entry. That is also consistent with existing similar tables in this driver. > +}; > +MODULE_DEVICE_TABLE(i3c, p3t1085_i3c_ids); > + > +static int p3t1085_i3c_probe(struct i3c_device *i3cdev) > +{ > + struct regmap *regmap; > + > + regmap = devm_regmap_init_i3c(i3cdev, &tmp108_regmap_config); > + if (IS_ERR(regmap)) > + return dev_err_probe(&i3cdev->dev, PTR_ERR(regmap), > + "Failed to register i3c regmap\n"); > + > + return tmp108_common_probe(&i3cdev->dev, regmap, "p3t1085_i3c"); > +} > + > +static struct i3c_driver p3t1085_driver = { > + .driver = { > + .name = "p3t1085_i3c", > + }, > + .probe = p3t1085_i3c_probe, > + .id_table = p3t1085_i3c_ids, > +}; > +module_i3c_driver(p3t1085_driver); > +#endif > + > MODULE_AUTHOR("John Muir <john@jmuir.com>"); > MODULE_DESCRIPTION("Texas Instruments TMP108 temperature sensor driver"); > MODULE_LICENSE("GPL"); >
On 11/9/24 05:16, Jonathan Cameron wrote: > On Fri, 08 Nov 2024 17:26:57 -0500 > Frank Li <Frank.Li@nxp.com> wrote: > >> Add support for I3C device in the tmp108 driver to handle the P3T1085 >> sensor. Register the I3C device driver to enable I3C functionality for the >> sensor. >> >> Signed-off-by: Frank Li <Frank.Li@nxp.com> >> --- >> drivers/hwmon/tmp108.c | 31 +++++++++++++++++++++++++++++++ >> 1 file changed, 31 insertions(+) >> >> diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c >> index bfbea6349a95f..83d6847cb542c 100644 >> --- a/drivers/hwmon/tmp108.c >> +++ b/drivers/hwmon/tmp108.c >> @@ -13,6 +13,8 @@ >> #include <linux/mutex.h> >> #include <linux/of.h> >> #include <linux/i2c.h> >> +#include <linux/i3c/device.h> >> +#include <linux/i3c/master.h> > > Seems odd you need master.h in a device driver. > I'll guess that's because you should be using i3cdev_to_device() I assume you mean i3cdev_to_dev() ? Good point, but there are not many examples to draw from. The one existing iio driver (st_lsm6dsx) doesn't use it either. I'll send a patch shortly to fix that to prevent others from making the same mistake. Thanks, Guenter
On Sat, 9 Nov 2024 06:53:28 -0800 Guenter Roeck <linux@roeck-us.net> wrote: > On 11/9/24 05:16, Jonathan Cameron wrote: > > On Fri, 08 Nov 2024 17:26:57 -0500 > > Frank Li <Frank.Li@nxp.com> wrote: > > > >> Add support for I3C device in the tmp108 driver to handle the P3T1085 > >> sensor. Register the I3C device driver to enable I3C functionality for the > >> sensor. > >> > >> Signed-off-by: Frank Li <Frank.Li@nxp.com> > >> --- > >> drivers/hwmon/tmp108.c | 31 +++++++++++++++++++++++++++++++ > >> 1 file changed, 31 insertions(+) > >> > >> diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c > >> index bfbea6349a95f..83d6847cb542c 100644 > >> --- a/drivers/hwmon/tmp108.c > >> +++ b/drivers/hwmon/tmp108.c > >> @@ -13,6 +13,8 @@ > >> #include <linux/mutex.h> > >> #include <linux/of.h> > >> #include <linux/i2c.h> > >> +#include <linux/i3c/device.h> > >> +#include <linux/i3c/master.h> > > > > Seems odd you need master.h in a device driver. > > I'll guess that's because you should be using i3cdev_to_device() > > I assume you mean i3cdev_to_dev() ? > Indeed! :( > Good point, but there are not many examples to draw from. The one > existing iio driver (st_lsm6dsx) doesn't use it either. I'll send > a patch shortly to fix that to prevent others from making the same > mistake. Excellent. > > Thanks, > Guenter >
On 11/9/24 07:15, Jonathan Cameron wrote: > On Sat, 9 Nov 2024 06:53:28 -0800 > Guenter Roeck <linux@roeck-us.net> wrote: > >> On 11/9/24 05:16, Jonathan Cameron wrote: >>> On Fri, 08 Nov 2024 17:26:57 -0500 >>> Frank Li <Frank.Li@nxp.com> wrote: >>> >>>> Add support for I3C device in the tmp108 driver to handle the P3T1085 >>>> sensor. Register the I3C device driver to enable I3C functionality for the >>>> sensor. >>>> >>>> Signed-off-by: Frank Li <Frank.Li@nxp.com> >>>> --- >>>> drivers/hwmon/tmp108.c | 31 +++++++++++++++++++++++++++++++ >>>> 1 file changed, 31 insertions(+) >>>> >>>> diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c >>>> index bfbea6349a95f..83d6847cb542c 100644 >>>> --- a/drivers/hwmon/tmp108.c >>>> +++ b/drivers/hwmon/tmp108.c >>>> @@ -13,6 +13,8 @@ >>>> #include <linux/mutex.h> >>>> #include <linux/of.h> >>>> #include <linux/i2c.h> >>>> +#include <linux/i3c/device.h> >>>> +#include <linux/i3c/master.h> >>> >>> Seems odd you need master.h in a device driver. >>> I'll guess that's because you should be using i3cdev_to_device() >> >> I assume you mean i3cdev_to_dev() ? >> > Indeed! :( > >> Good point, but there are not many examples to draw from. The one >> existing iio driver (st_lsm6dsx) doesn't use it either. I'll send >> a patch shortly to fix that to prevent others from making the same >> mistake. > Excellent. In this context, are you by any chance aware of an USB<->I3C adapter wit decent price point ? With more I3C devices becoming available, I'd like to be able to test at least some of the code with real hardware. For I2C I use the Devantech USB-ISS adapter, but I have not yet found anything comparable for I3C, at least nothing that is affordable. Thanks, Guenter
diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c index bfbea6349a95f..83d6847cb542c 100644 --- a/drivers/hwmon/tmp108.c +++ b/drivers/hwmon/tmp108.c @@ -13,6 +13,8 @@ #include <linux/mutex.h> #include <linux/of.h> #include <linux/i2c.h> +#include <linux/i3c/device.h> +#include <linux/i3c/master.h> #include <linux/init.h> #include <linux/jiffies.h> #include <linux/regmap.h> @@ -442,6 +444,35 @@ static struct i2c_driver tmp108_driver = { module_i2c_driver(tmp108_driver); +#ifdef CONFIG_REGMAP_I3C +static const struct i3c_device_id p3t1085_i3c_ids[] = { + I3C_DEVICE(0x011b, 0x1529, NULL), + {}, +}; +MODULE_DEVICE_TABLE(i3c, p3t1085_i3c_ids); + +static int p3t1085_i3c_probe(struct i3c_device *i3cdev) +{ + struct regmap *regmap; + + regmap = devm_regmap_init_i3c(i3cdev, &tmp108_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(&i3cdev->dev, PTR_ERR(regmap), + "Failed to register i3c regmap\n"); + + return tmp108_common_probe(&i3cdev->dev, regmap, "p3t1085_i3c"); +} + +static struct i3c_driver p3t1085_driver = { + .driver = { + .name = "p3t1085_i3c", + }, + .probe = p3t1085_i3c_probe, + .id_table = p3t1085_i3c_ids, +}; +module_i3c_driver(p3t1085_driver); +#endif + MODULE_AUTHOR("John Muir <john@jmuir.com>"); MODULE_DESCRIPTION("Texas Instruments TMP108 temperature sensor driver"); MODULE_LICENSE("GPL");
Add support for I3C device in the tmp108 driver to handle the P3T1085 sensor. Register the I3C device driver to enable I3C functionality for the sensor. Signed-off-by: Frank Li <Frank.Li@nxp.com> --- drivers/hwmon/tmp108.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)