* [PATCH 0/3] iio: temperature: Add support for P3T1085
@ 2024-11-07 23:02 Frank Li
2024-11-07 23:02 ` [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor Frank Li
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Frank Li @ 2024-11-07 23:02 UTC (permalink / raw)
To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron,
Lars-Peter Clausen, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam
Cc: devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel,
Frank Li, Carlos Song, Clark Wang
Add basic function support for P3T1085 temperature sensor.
- Add binding doc trivial.yaml
- Add basic read temperature driver
- Update imx93-9x9-qsb.dts
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Carlos Song (1):
iio: temperature: Add support for P3T1085
Frank Li (2):
dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor
arm64: dts: imx93-9x9-qsb: add temp-sensor nxp,p3t1085
.../devicetree/bindings/trivial-devices.yaml | 2 +
arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts | 5 ++
drivers/iio/temperature/Kconfig | 1 +
drivers/iio/temperature/Makefile | 2 +
drivers/iio/temperature/p3t/Kconfig | 29 ++++++++
drivers/iio/temperature/p3t/Makefile | 5 ++
drivers/iio/temperature/p3t/p3t1085.h | 31 +++++++++
drivers/iio/temperature/p3t/p3t1085_core.c | 79 ++++++++++++++++++++++
drivers/iio/temperature/p3t/p3t1085_i2c.c | 68 +++++++++++++++++++
drivers/iio/temperature/p3t/p3t1085_i3c.c | 59 ++++++++++++++++
10 files changed, 281 insertions(+)
---
base-commit: 74741a050b79d31d8d2eeee12c77736596d0a6b2
change-id: 20241107-p3t1085-fbd8726cbc0e
Best regards,
---
Frank Li <Frank.Li@nxp.com>
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor 2024-11-07 23:02 [PATCH 0/3] iio: temperature: Add support for P3T1085 Frank Li @ 2024-11-07 23:02 ` Frank Li 2024-11-08 8:45 ` Marco Felsch 2024-11-07 23:02 ` [PATCH 2/3] iio: temperature: Add support for P3T1085 Frank Li ` (2 subsequent siblings) 3 siblings, 1 reply; 10+ messages in thread From: Frank Li @ 2024-11-07 23:02 UTC (permalink / raw) To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam Cc: devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel, Frank Li P3T1085UK is a temperature-to-digital converter with a -40 °C to +125 °C range. The device can be communicated by a controller via the 2-wire serial I3C (up to 12.5 MHz) and I2C (up to 3.4 MHz) interface. Add it to trivial-devices.yaml because only one 'reg' and 'interrupts' needs. Signed-off-by: Frank Li <Frank.Li@nxp.com> --- Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 6ecd6432b021b..361943b3d73bc 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -301,6 +301,8 @@ properties: - national,lm92 # Nuvoton Temperature Sensor - nuvoton,w83773g + # NXP I2C/I3C Temperature Sensor (-40 °C to +125 °C) + - nxp,p3t1085 # OKI ML86V7667 video decoder - oki,ml86v7667 # ON Semiconductor ADT7462 Temperature, Voltage Monitor and Fan Controller -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor 2024-11-07 23:02 ` [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor Frank Li @ 2024-11-08 8:45 ` Marco Felsch 2024-11-08 17:47 ` Conor Dooley 0 siblings, 1 reply; 10+ messages in thread From: Marco Felsch @ 2024-11-08 8:45 UTC (permalink / raw) To: Frank Li Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, devicetree, imx, linux-iio, linux-kernel, linux-arm-kernel On 24-11-07, Frank Li wrote: > P3T1085UK is a temperature-to-digital converter with a -40 °C to +125 °C > range. The device can be communicated by a controller via the 2-wire serial > I3C (up to 12.5 MHz) and I2C (up to 3.4 MHz) interface. > > Add it to trivial-devices.yaml because only one 'reg' and 'interrupts' > needs. > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml > index 6ecd6432b021b..361943b3d73bc 100644 > --- a/Documentation/devicetree/bindings/trivial-devices.yaml > +++ b/Documentation/devicetree/bindings/trivial-devices.yaml > @@ -301,6 +301,8 @@ properties: > - national,lm92 > # Nuvoton Temperature Sensor > - nuvoton,w83773g > + # NXP I2C/I3C Temperature Sensor (-40 °C to +125 °C) > + - nxp,p3t1085 The description of this binding says: "This is a list of trivial I2C and SPI devices ..." but you add a I2C and I3C device. Also I really like to see that you add a "power-supply" property which is most the time missing for such simple devices but always required. Regards, Marco > # OKI ML86V7667 video decoder > - oki,ml86v7667 > # ON Semiconductor ADT7462 Temperature, Voltage Monitor and Fan Controller > > -- > 2.34.1 > > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor 2024-11-08 8:45 ` Marco Felsch @ 2024-11-08 17:47 ` Conor Dooley 0 siblings, 0 replies; 10+ messages in thread From: Conor Dooley @ 2024-11-08 17:47 UTC (permalink / raw) To: Marco Felsch Cc: Frank Li, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, devicetree, imx, linux-iio, linux-kernel, linux-arm-kernel [-- Attachment #1: Type: text/plain, Size: 1513 bytes --] On Fri, Nov 08, 2024 at 09:45:47AM +0100, Marco Felsch wrote: > On 24-11-07, Frank Li wrote: > > P3T1085UK is a temperature-to-digital converter with a -40 °C to +125 °C > > range. The device can be communicated by a controller via the 2-wire serial > > I3C (up to 12.5 MHz) and I2C (up to 3.4 MHz) interface. > > > > Add it to trivial-devices.yaml because only one 'reg' and 'interrupts' > > needs. > > > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > --- > > Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml > > index 6ecd6432b021b..361943b3d73bc 100644 > > --- a/Documentation/devicetree/bindings/trivial-devices.yaml > > +++ b/Documentation/devicetree/bindings/trivial-devices.yaml > > @@ -301,6 +301,8 @@ properties: > > - national,lm92 > > # Nuvoton Temperature Sensor > > - nuvoton,w83773g > > + # NXP I2C/I3C Temperature Sensor (-40 °C to +125 °C) > > + - nxp,p3t1085 > > The description of this binding says: > > "This is a list of trivial I2C and SPI devices ..." > > but you add a I2C and I3C device. > > Also I really like to see that you add a "power-supply" property which > is most the time missing for such simple devices but always required. Aye, the done thing in iio land is to make the supplies required too. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] iio: temperature: Add support for P3T1085 2024-11-07 23:02 [PATCH 0/3] iio: temperature: Add support for P3T1085 Frank Li 2024-11-07 23:02 ` [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor Frank Li @ 2024-11-07 23:02 ` Frank Li 2024-11-08 8:41 ` Marco Felsch 2024-11-07 23:02 ` [PATCH 3/3] arm64: dts: imx93-9x9-qsb: add temp-sensor nxp,p3t1085 Frank Li 2024-11-08 15:28 ` [PATCH 0/3] iio: temperature: Add support for P3T1085 Jonathan Cameron 3 siblings, 1 reply; 10+ messages in thread From: Frank Li @ 2024-11-07 23:02 UTC (permalink / raw) To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam Cc: devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel, Frank Li, Carlos Song, Clark Wang From: Carlos Song <carlos.song@nxp.com> Add basic function support for P3T1085 temperature sensor. P3T1085UK is a temperature-to-digital converter with a -40 °C to +125 °C range. The device can be communicated by a controller via the 2-wire serial I3C (up to 12.5 MHz) and I2C (up to 3.4 MHz) interface. Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> Signed-off-by: Carlos Song <carlos.song@nxp.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> --- drivers/iio/temperature/Kconfig | 1 + drivers/iio/temperature/Makefile | 2 + drivers/iio/temperature/p3t/Kconfig | 29 +++++++++++ drivers/iio/temperature/p3t/Makefile | 5 ++ drivers/iio/temperature/p3t/p3t1085.h | 31 ++++++++++++ drivers/iio/temperature/p3t/p3t1085_core.c | 79 ++++++++++++++++++++++++++++++ drivers/iio/temperature/p3t/p3t1085_i2c.c | 68 +++++++++++++++++++++++++ drivers/iio/temperature/p3t/p3t1085_i3c.c | 59 ++++++++++++++++++++++ 8 files changed, 274 insertions(+) diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig index 1244d8e17d504..7cdd49279aba2 100644 --- a/drivers/iio/temperature/Kconfig +++ b/drivers/iio/temperature/Kconfig @@ -182,4 +182,5 @@ config MCP9600 This driver can also be built as a module. If so, the module will be called mcp9600. +source "drivers/iio/temperature/p3t/Kconfig" endmenu diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile index 07d6e65709f7f..d5e89c20d58b6 100644 --- a/drivers/iio/temperature/Makefile +++ b/drivers/iio/temperature/Makefile @@ -19,3 +19,5 @@ obj-$(CONFIG_TMP007) += tmp007.o obj-$(CONFIG_TMP117) += tmp117.o obj-$(CONFIG_TSYS01) += tsys01.o obj-$(CONFIG_TSYS02D) += tsys02d.o + +obj-y += p3t/ diff --git a/drivers/iio/temperature/p3t/Kconfig b/drivers/iio/temperature/p3t/Kconfig new file mode 100644 index 0000000000000..09e925024b66f --- /dev/null +++ b/drivers/iio/temperature/p3t/Kconfig @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config IIO_P3T1085 + tristate + depends on (I2C || I3C) + +config IIO_P3T1085_I2C + tristate "NXP P3T1085 temperature sensor I2C driver" + depends on I2C + select IIO_P3T1085 + select REGMAP_I2C + help + Say yes here to build support for NXP P3T1085 I2C temperature + sensor. + + To compile this driver as a module, choose M here: the module + will be called p3t1085_i2c + +config IIO_P3T1085_I3C + tristate "NXP P3T1085 temperature sensor I3C driver" + depends on I3C + select IIO_P3T1085 + select REGMAP_I3C + help + Say yes here to build support for NXP P3T1085 I3C temperature + sensor. + + To compile this driver as a module, choose M here: the module + will be called p3t1085_i3c diff --git a/drivers/iio/temperature/p3t/Makefile b/drivers/iio/temperature/p3t/Makefile new file mode 100644 index 0000000000000..21aaeb51e044d --- /dev/null +++ b/drivers/iio/temperature/p3t/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_IIO_P3T1085) += p3t1085_core.o +obj-$(CONFIG_IIO_P3T1085_I2C) += p3t1085_i2c.o +obj-$(CONFIG_IIO_P3T1085_I3C) += p3t1085_i3c.o diff --git a/drivers/iio/temperature/p3t/p3t1085.h b/drivers/iio/temperature/p3t/p3t1085.h new file mode 100644 index 0000000000000..b018a04e4aee4 --- /dev/null +++ b/drivers/iio/temperature/p3t/p3t1085.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * NXP P3T1085 Temperature Sensor Driver + * + * Copyright 2024 NXP + */ +#ifndef P3T1085_H +#define P3T1085_H + +#include <linux/device.h> +#include <linux/iio/iio.h> + +#define P3T1085_REG_TEMP 0x0 +#define P3T1085_REG_CFGR 0x1 +#define P3T1085_REG_HIGH_LIM 0x2 +#define P3T1085_REG_LOW_LIM 0x3 + +#define P3T1085_RESOLUTION_10UC 62500 + +enum p3t1085_hw_id { + P3T1085_ID, +}; + +struct p3t1085_data { + struct device *dev; + struct regmap *regmap; +}; + +int p3t1085_probe(struct device *dev, int irq, int hw_id, struct regmap *regmap); + +#endif /* P3T1085_H */ diff --git a/drivers/iio/temperature/p3t/p3t1085_core.c b/drivers/iio/temperature/p3t/p3t1085_core.c new file mode 100644 index 0000000000000..4b00e606a6d04 --- /dev/null +++ b/drivers/iio/temperature/p3t/p3t1085_core.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * NXP P3T1085 Temperature Sensor Driver + * + * Copyright 2024 NXP + */ +#include <linux/bitops.h> +#include <linux/err.h> +#include <linux/i2c.h> +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/kernel.h> +#include <linux/limits.h> +#include <linux/module.h> +#include <linux/regmap.h> +#include <linux/types.h> + +#include "p3t1085.h" + +static int p3t1085_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + struct p3t1085_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = regmap_read(data->regmap, P3T1085_REG_TEMP, val); + if (ret < 0) { + dev_err(data->dev, "failed to read temperature register\n"); + return ret; + } + *val = *val >> 4; + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec p3t1085_channels[] = { + { + .type = IIO_TEMP, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, +}; + +static const struct iio_info p3t1085_info = { + .read_raw = p3t1085_read_raw, +}; + +int p3t1085_probe(struct device *dev, int irq, int hw_id, struct regmap *regmap) +{ + struct p3t1085_data *data; + struct iio_dev *iio_dev; + + iio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!iio_dev) + return -ENOMEM; + + data = iio_priv(iio_dev); + data->dev = dev; + data->regmap = regmap; + + iio_dev->name = "p3t1085"; + iio_dev->modes = INDIO_DIRECT_MODE; + iio_dev->info = &p3t1085_info; + + iio_dev->channels = p3t1085_channels; + iio_dev->num_channels = ARRAY_SIZE(p3t1085_channels); + + return devm_iio_device_register(dev, iio_dev); +} +EXPORT_SYMBOL_NS(p3t1085_probe, IIO_P3T1085); + +MODULE_AUTHOR("Xiaoning Wang <xiaoning.wang@nxp.com>"); +MODULE_DESCRIPTION("NXP P3T1085 driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/iio/temperature/p3t/p3t1085_i2c.c b/drivers/iio/temperature/p3t/p3t1085_i2c.c new file mode 100644 index 0000000000000..20e5f7a68dd9e --- /dev/null +++ b/drivers/iio/temperature/p3t/p3t1085_i2c.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * NXP P3T1085 Temperature Sensor Driver + * + * Copyright 2024 NXP + */ + +#include <linux/i2c.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/regmap.h> +#include <linux/slab.h> + +#include "p3t1085.h" + +static const struct regmap_config p3t1085_i2c_regmap_config = { + .reg_bits = 8, + .val_bits = 16, +}; + +static int p3t1085_i2c_probe(struct i2c_client *client) +{ + const struct i2c_device_id *id; + struct regmap *regmap; + int ret; + + id = i2c_client_get_device_id(client); + if (!id) + return -EINVAL; + + regmap = devm_regmap_init_i2c(client, &p3t1085_i2c_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(&client->dev, PTR_ERR(regmap), + "Failed to register i2c regmap %ld\n", PTR_ERR(regmap)); + + ret = p3t1085_probe(&client->dev, client->irq, id->driver_data, regmap); + if (ret) + return dev_err_probe(&client->dev, ret, "Failed to probe\n"); + + return 0; +} + +static const struct of_device_id p3t1085_i2c_of_match[] = { + { .compatible = "nxp,p3t1085", }, + { } +}; +MODULE_DEVICE_TABLE(of, p3t1085_i2c_of_match); + +static const struct i2c_device_id p3t1085_i2c_id_table[] = { + { "p3t1085", P3T1085_ID }, + { } +}; +MODULE_DEVICE_TABLE(i2c, p3t1085_i2c_id_table); + +static struct i2c_driver p3t1085_driver = { + .driver = { + .name = "p3t1085_i2c", + .of_match_table = p3t1085_i2c_of_match, + }, + .probe = p3t1085_i2c_probe, + .id_table = p3t1085_i2c_id_table, +}; +module_i2c_driver(p3t1085_driver); + +MODULE_AUTHOR("Xiaoning Wang <xiaoning.wang@nxp.com>"); +MODULE_DESCRIPTION("NXP P3T1085 i2c driver"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_P3T1085); diff --git a/drivers/iio/temperature/p3t/p3t1085_i3c.c b/drivers/iio/temperature/p3t/p3t1085_i3c.c new file mode 100644 index 0000000000000..0007d79aa0a6d --- /dev/null +++ b/drivers/iio/temperature/p3t/p3t1085_i3c.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * NXP P3T1085 Temperature Sensor Driver + * + * Copyright 2024 NXP + */ +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/i3c/device.h> +#include <linux/i3c/master.h> +#include <linux/slab.h> +#include <linux/regmap.h> + +#include "p3t1085.h" + +static const struct i3c_device_id p3t1085_i3c_ids[] = { + I3C_DEVICE(0x011B, 0x1529, (void *)P3T1085_ID), + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(i3c, p3t1085_i3c_ids); + +static int p3t1085_i3c_probe(struct i3c_device *i3cdev) +{ + const struct regmap_config p3t1085_i3c_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + }; + int ret; + + const struct i3c_device_id *id = i3c_device_match_id(i3cdev, + p3t1085_i3c_ids); + struct regmap *regmap; + + regmap = devm_regmap_init_i3c(i3cdev, &p3t1085_i3c_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(&i3cdev->dev, PTR_ERR(regmap), + "Failed to register i3c regmap\n"); + + ret = p3t1085_probe(&i3cdev->dev, 0, (uintptr_t)id->data, regmap); + if (ret) + return dev_err_probe(&i3cdev->dev, ret, "Failed to probe\n"); + + return 0; +} + +static struct i3c_driver p3t1085_driver = { + .driver = { + .name = "p3t1085_i3c", + }, + .probe = p3t1085_i3c_probe, + .id_table = p3t1085_i3c_ids, +}; +module_i3c_driver(p3t1085_driver); + +MODULE_AUTHOR("Xiaoning Wang <xiaoning.wang@nxp.com>"); +MODULE_DESCRIPTION("NXP p3t1085 i3c driver"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(IIO_P3T1085); -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] iio: temperature: Add support for P3T1085 2024-11-07 23:02 ` [PATCH 2/3] iio: temperature: Add support for P3T1085 Frank Li @ 2024-11-08 8:41 ` Marco Felsch 0 siblings, 0 replies; 10+ messages in thread From: Marco Felsch @ 2024-11-08 8:41 UTC (permalink / raw) To: Frank Li Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, devicetree, imx, linux-iio, linux-kernel, Carlos Song, Clark Wang, linux-arm-kernel Hi Frank, thanks for the patch, please see my comments inline. On 24-11-07, Frank Li wrote: > From: Carlos Song <carlos.song@nxp.com> > > Add basic function support for P3T1085 temperature sensor. > > P3T1085UK is a temperature-to-digital converter with a -40 °C to +125 °C > range. The device can be communicated by a controller via the 2-wire serial > I3C (up to 12.5 MHz) and I2C (up to 3.4 MHz) interface. > > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > Signed-off-by: Carlos Song <carlos.song@nxp.com> > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/iio/temperature/Kconfig | 1 + > drivers/iio/temperature/Makefile | 2 + > drivers/iio/temperature/p3t/Kconfig | 29 +++++++++++ > drivers/iio/temperature/p3t/Makefile | 5 ++ > drivers/iio/temperature/p3t/p3t1085.h | 31 ++++++++++++ > drivers/iio/temperature/p3t/p3t1085_core.c | 79 ++++++++++++++++++++++++++++++ > drivers/iio/temperature/p3t/p3t1085_i2c.c | 68 +++++++++++++++++++++++++ > drivers/iio/temperature/p3t/p3t1085_i3c.c | 59 ++++++++++++++++++++++ > 8 files changed, 274 insertions(+) > > diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig > index 1244d8e17d504..7cdd49279aba2 100644 > --- a/drivers/iio/temperature/Kconfig > +++ b/drivers/iio/temperature/Kconfig > @@ -182,4 +182,5 @@ config MCP9600 > This driver can also be built as a module. If so, the module > will be called mcp9600. > > +source "drivers/iio/temperature/p3t/Kconfig" > endmenu > diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile > index 07d6e65709f7f..d5e89c20d58b6 100644 > --- a/drivers/iio/temperature/Makefile > +++ b/drivers/iio/temperature/Makefile > @@ -19,3 +19,5 @@ obj-$(CONFIG_TMP007) += tmp007.o > obj-$(CONFIG_TMP117) += tmp117.o > obj-$(CONFIG_TSYS01) += tsys01.o > obj-$(CONFIG_TSYS02D) += tsys02d.o > + > +obj-y += p3t/ > diff --git a/drivers/iio/temperature/p3t/Kconfig b/drivers/iio/temperature/p3t/Kconfig > new file mode 100644 > index 0000000000000..09e925024b66f > --- /dev/null > +++ b/drivers/iio/temperature/p3t/Kconfig > @@ -0,0 +1,29 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +config IIO_P3T1085 > + tristate > + depends on (I2C || I3C) > + > +config IIO_P3T1085_I2C > + tristate "NXP P3T1085 temperature sensor I2C driver" > + depends on I2C > + select IIO_P3T1085 > + select REGMAP_I2C > + help > + Say yes here to build support for NXP P3T1085 I2C temperature > + sensor. > + > + To compile this driver as a module, choose M here: the module > + will be called p3t1085_i2c > + > +config IIO_P3T1085_I3C > + tristate "NXP P3T1085 temperature sensor I3C driver" > + depends on I3C > + select IIO_P3T1085 > + select REGMAP_I3C > + help > + Say yes here to build support for NXP P3T1085 I3C temperature > + sensor. > + > + To compile this driver as a module, choose M here: the module > + will be called p3t1085_i3c > diff --git a/drivers/iio/temperature/p3t/Makefile b/drivers/iio/temperature/p3t/Makefile > new file mode 100644 > index 0000000000000..21aaeb51e044d > --- /dev/null > +++ b/drivers/iio/temperature/p3t/Makefile > @@ -0,0 +1,5 @@ > +# SPDX-License-Identifier: GPL-2.0-only > + > +obj-$(CONFIG_IIO_P3T1085) += p3t1085_core.o > +obj-$(CONFIG_IIO_P3T1085_I2C) += p3t1085_i2c.o > +obj-$(CONFIG_IIO_P3T1085_I3C) += p3t1085_i3c.o > diff --git a/drivers/iio/temperature/p3t/p3t1085.h b/drivers/iio/temperature/p3t/p3t1085.h > new file mode 100644 > index 0000000000000..b018a04e4aee4 > --- /dev/null > +++ b/drivers/iio/temperature/p3t/p3t1085.h > @@ -0,0 +1,31 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * NXP P3T1085 Temperature Sensor Driver > + * > + * Copyright 2024 NXP > + */ > +#ifndef P3T1085_H > +#define P3T1085_H > + > +#include <linux/device.h> > +#include <linux/iio/iio.h> > + > +#define P3T1085_REG_TEMP 0x0 This define can be moved into the core since the _i2c nor the _i3c is uses it. > +#define P3T1085_REG_CFGR 0x1 > +#define P3T1085_REG_HIGH_LIM 0x2 > +#define P3T1085_REG_LOW_LIM 0x3 > + > +#define P3T1085_RESOLUTION_10UC 62500 All three defines are not used, please remove it. > + > +enum p3t1085_hw_id { > + P3T1085_ID, > +}; Is this id really required? We should keep the driver simple for now and extend it on demand. > +struct p3t1085_data { > + struct device *dev; > + struct regmap *regmap; > +}; This belongs to the core.c > +int p3t1085_probe(struct device *dev, int irq, int hw_id, struct regmap *regmap); ^ ^ unsused params > + > +#endif /* P3T1085_H */ > diff --git a/drivers/iio/temperature/p3t/p3t1085_core.c b/drivers/iio/temperature/p3t/p3t1085_core.c > new file mode 100644 > index 0000000000000..4b00e606a6d04 > --- /dev/null > +++ b/drivers/iio/temperature/p3t/p3t1085_core.c > @@ -0,0 +1,79 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * NXP P3T1085 Temperature Sensor Driver > + * > + * Copyright 2024 NXP > + */ > +#include <linux/bitops.h> > +#include <linux/err.h> > +#include <linux/i2c.h> > +#include <linux/iio/iio.h> > +#include <linux/iio/sysfs.h> > +#include <linux/kernel.h> > +#include <linux/limits.h> > +#include <linux/module.h> > +#include <linux/regmap.h> > +#include <linux/types.h> > + > +#include "p3t1085.h" > + > +static int p3t1085_read_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *channel, int *val, > + int *val2, long mask) > +{ > + struct p3t1085_data *data = iio_priv(indio_dev); > + int ret; > + > + switch (mask) { > + case IIO_CHAN_INFO_RAW: > + ret = regmap_read(data->regmap, P3T1085_REG_TEMP, val); > + if (ret < 0) { > + dev_err(data->dev, "failed to read temperature register\n"); > + return ret; > + } > + *val = *val >> 4; > + return IIO_VAL_INT; > + > + default: > + return -EINVAL; > + } > +} > + > +static const struct iio_chan_spec p3t1085_channels[] = { > + { > + .type = IIO_TEMP, > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), > + }, > +}; > + > +static const struct iio_info p3t1085_info = { > + .read_raw = p3t1085_read_raw, > +}; > + > +int p3t1085_probe(struct device *dev, int irq, int hw_id, struct regmap *regmap) ^ ^ As written abvoe, both params are unused so can you please drop them? > +{ > + struct p3t1085_data *data; > + struct iio_dev *iio_dev; > + > + iio_dev = devm_iio_device_alloc(dev, sizeof(*data)); > + if (!iio_dev) > + return -ENOMEM; > + > + data = iio_priv(iio_dev); > + data->dev = dev; > + data->regmap = regmap; > + > + iio_dev->name = "p3t1085"; > + iio_dev->modes = INDIO_DIRECT_MODE; > + iio_dev->info = &p3t1085_info; > + > + iio_dev->channels = p3t1085_channels; > + iio_dev->num_channels = ARRAY_SIZE(p3t1085_channels); > + > + return devm_iio_device_register(dev, iio_dev); > +} > +EXPORT_SYMBOL_NS(p3t1085_probe, IIO_P3T1085); > + > +MODULE_AUTHOR("Xiaoning Wang <xiaoning.wang@nxp.com>"); > +MODULE_DESCRIPTION("NXP P3T1085 driver"); > +MODULE_LICENSE("GPL"); > diff --git a/drivers/iio/temperature/p3t/p3t1085_i2c.c b/drivers/iio/temperature/p3t/p3t1085_i2c.c > new file mode 100644 > index 0000000000000..20e5f7a68dd9e > --- /dev/null > +++ b/drivers/iio/temperature/p3t/p3t1085_i2c.c > @@ -0,0 +1,68 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * NXP P3T1085 Temperature Sensor Driver > + * > + * Copyright 2024 NXP > + */ > + > +#include <linux/i2c.h> > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/regmap.h> > +#include <linux/slab.h> > + > +#include "p3t1085.h" > + > +static const struct regmap_config p3t1085_i2c_regmap_config = { > + .reg_bits = 8, > + .val_bits = 16, > +}; > + > +static int p3t1085_i2c_probe(struct i2c_client *client) > +{ > + const struct i2c_device_id *id; > + struct regmap *regmap; > + int ret; > + > + id = i2c_client_get_device_id(client); > + if (!id) > + return -EINVAL; At the moment only one devices is supported therefore I would like drop passing the id to the p3t1085_probe function. > + regmap = devm_regmap_init_i2c(client, &p3t1085_i2c_regmap_config); > + if (IS_ERR(regmap)) > + return dev_err_probe(&client->dev, PTR_ERR(regmap), > + "Failed to register i2c regmap %ld\n", PTR_ERR(regmap)); > + > + ret = p3t1085_probe(&client->dev, client->irq, id->driver_data, regmap); > + if (ret) > + return dev_err_probe(&client->dev, ret, "Failed to probe\n"); > + > + return 0; > +} > + > +static const struct of_device_id p3t1085_i2c_of_match[] = { > + { .compatible = "nxp,p3t1085", }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, p3t1085_i2c_of_match); > + > +static const struct i2c_device_id p3t1085_i2c_id_table[] = { > + { "p3t1085", P3T1085_ID }, ^ This can be dropped > + { } > +}; > +MODULE_DEVICE_TABLE(i2c, p3t1085_i2c_id_table); > + > +static struct i2c_driver p3t1085_driver = { > + .driver = { > + .name = "p3t1085_i2c", > + .of_match_table = p3t1085_i2c_of_match, > + }, > + .probe = p3t1085_i2c_probe, > + .id_table = p3t1085_i2c_id_table, > +}; > +module_i2c_driver(p3t1085_driver); > + > +MODULE_AUTHOR("Xiaoning Wang <xiaoning.wang@nxp.com>"); > +MODULE_DESCRIPTION("NXP P3T1085 i2c driver"); > +MODULE_LICENSE("GPL"); > +MODULE_IMPORT_NS(IIO_P3T1085); > diff --git a/drivers/iio/temperature/p3t/p3t1085_i3c.c b/drivers/iio/temperature/p3t/p3t1085_i3c.c > new file mode 100644 > index 0000000000000..0007d79aa0a6d > --- /dev/null > +++ b/drivers/iio/temperature/p3t/p3t1085_i3c.c > @@ -0,0 +1,59 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * NXP P3T1085 Temperature Sensor Driver > + * > + * Copyright 2024 NXP > + */ > +#include <linux/kernel.h> > +#include <linux/mod_devicetable.h> > +#include <linux/module.h> > +#include <linux/i3c/device.h> > +#include <linux/i3c/master.h> > +#include <linux/slab.h> > +#include <linux/regmap.h> > + > +#include "p3t1085.h" > + > +static const struct i3c_device_id p3t1085_i3c_ids[] = { > + I3C_DEVICE(0x011B, 0x1529, (void *)P3T1085_ID), ^ here as well. > + { /* sentinel */ }, Nit: Can you please align your "sentinel" style. Either with or without the comment. Also the of_device_id is missing for the i3c case. > +}; > +MODULE_DEVICE_TABLE(i3c, p3t1085_i3c_ids); > + > +static int p3t1085_i3c_probe(struct i3c_device *i3cdev) > +{ > + const struct regmap_config p3t1085_i3c_regmap_config = { > + .reg_bits = 8, > + .val_bits = 16, > + }; Please align the style with the i2c module. > + int ret; > + > + const struct i3c_device_id *id = i3c_device_match_id(i3cdev, > + p3t1085_i3c_ids); Same here, we don't need to consider different ids yet. > + struct regmap *regmap; > + > + regmap = devm_regmap_init_i3c(i3cdev, &p3t1085_i3c_regmap_config); > + if (IS_ERR(regmap)) > + return dev_err_probe(&i3cdev->dev, PTR_ERR(regmap), > + "Failed to register i3c regmap\n"); > + > + ret = p3t1085_probe(&i3cdev->dev, 0, (uintptr_t)id->data, regmap); > + if (ret) > + return dev_err_probe(&i3cdev->dev, ret, "Failed to probe\n"); > + > + return 0; > +} > + > +static struct i3c_driver p3t1085_driver = { > + .driver = { > + .name = "p3t1085_i3c", > + }, > + .probe = p3t1085_i3c_probe, > + .id_table = p3t1085_i3c_ids, > +}; > +module_i3c_driver(p3t1085_driver); > + > +MODULE_AUTHOR("Xiaoning Wang <xiaoning.wang@nxp.com>"); > +MODULE_DESCRIPTION("NXP p3t1085 i3c driver"); > +MODULE_LICENSE("GPL"); > +MODULE_IMPORT_NS(IIO_P3T1085); > > -- > 2.34.1 > > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/3] arm64: dts: imx93-9x9-qsb: add temp-sensor nxp,p3t1085 2024-11-07 23:02 [PATCH 0/3] iio: temperature: Add support for P3T1085 Frank Li 2024-11-07 23:02 ` [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor Frank Li 2024-11-07 23:02 ` [PATCH 2/3] iio: temperature: Add support for P3T1085 Frank Li @ 2024-11-07 23:02 ` Frank Li 2024-11-08 15:28 ` [PATCH 0/3] iio: temperature: Add support for P3T1085 Jonathan Cameron 3 siblings, 0 replies; 10+ messages in thread From: Frank Li @ 2024-11-07 23:02 UTC (permalink / raw) To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam Cc: devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel, Frank Li Add temp-sensor nxp,p3t1085 for imx93-9x9-qsb boards. Signed-off-by: Frank Li <Frank.Li@nxp.com> --- arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts b/arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts index 20ec5b3c21f42..36f2995acbe29 100644 --- a/arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts +++ b/arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts @@ -221,6 +221,11 @@ wm8962: audio-codec@1a { >; }; + p3t1085: temperature-sensor@48 { + compatible = "nxp,p3t1085"; + reg = <0x48>; + }; + ptn5110: tcpc@50 { compatible = "nxp,ptn5110", "tcpci"; reg = <0x50>; -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] iio: temperature: Add support for P3T1085 2024-11-07 23:02 [PATCH 0/3] iio: temperature: Add support for P3T1085 Frank Li ` (2 preceding siblings ...) 2024-11-07 23:02 ` [PATCH 3/3] arm64: dts: imx93-9x9-qsb: add temp-sensor nxp,p3t1085 Frank Li @ 2024-11-08 15:28 ` Jonathan Cameron 2024-11-08 15:49 ` Guenter Roeck 3 siblings, 1 reply; 10+ messages in thread From: Jonathan Cameron @ 2024-11-08 15:28 UTC (permalink / raw) To: Frank Li Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel, Carlos Song, Clark Wang, Jean Delvare, Guenter Roeck, linux-hwmon On Thu, 07 Nov 2024 18:02:26 -0500 Frank Li <Frank.Li@nxp.com> wrote: > Add basic function support for P3T1085 temperature sensor. > - Add binding doc trivial.yaml > - Add basic read temperature driver Hi Frank, For a simple temperature sensor the usual question is why IIO rather than hwmon? Previous reasons have been: - Very high performmance / accuracy part (i.e. expensive) - Remote temperature so not typically hw monitoring. - Same silicon with a more complex sensor (typically humidity or similar). Any of those apply? Or some other reason? +CC hwmon maintainers and list. Jonathan > - Update imx93-9x9-qsb.dts > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > Carlos Song (1): > iio: temperature: Add support for P3T1085 > > Frank Li (2): > dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor > arm64: dts: imx93-9x9-qsb: add temp-sensor nxp,p3t1085 > > .../devicetree/bindings/trivial-devices.yaml | 2 + > arch/arm64/boot/dts/freescale/imx93-9x9-qsb.dts | 5 ++ > drivers/iio/temperature/Kconfig | 1 + > drivers/iio/temperature/Makefile | 2 + > drivers/iio/temperature/p3t/Kconfig | 29 ++++++++ > drivers/iio/temperature/p3t/Makefile | 5 ++ > drivers/iio/temperature/p3t/p3t1085.h | 31 +++++++++ > drivers/iio/temperature/p3t/p3t1085_core.c | 79 ++++++++++++++++++++++ > drivers/iio/temperature/p3t/p3t1085_i2c.c | 68 +++++++++++++++++++ > drivers/iio/temperature/p3t/p3t1085_i3c.c | 59 ++++++++++++++++ > 10 files changed, 281 insertions(+) > --- > base-commit: 74741a050b79d31d8d2eeee12c77736596d0a6b2 > change-id: 20241107-p3t1085-fbd8726cbc0e > > Best regards, > --- > Frank Li <Frank.Li@nxp.com> > > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] iio: temperature: Add support for P3T1085 2024-11-08 15:28 ` [PATCH 0/3] iio: temperature: Add support for P3T1085 Jonathan Cameron @ 2024-11-08 15:49 ` Guenter Roeck 2024-11-08 16:45 ` Frank Li 0 siblings, 1 reply; 10+ messages in thread From: Guenter Roeck @ 2024-11-08 15:49 UTC (permalink / raw) To: Jonathan Cameron, Frank Li Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel, Carlos Song, Clark Wang, Jean Delvare, linux-hwmon On 11/8/24 07:28, Jonathan Cameron wrote: > On Thu, 07 Nov 2024 18:02:26 -0500 > Frank Li <Frank.Li@nxp.com> wrote: > >> Add basic function support for P3T1085 temperature sensor. >> - Add binding doc trivial.yaml >> - Add basic read temperature driver > Hi Frank, > > For a simple temperature sensor the usual question is why IIO rather > than hwmon? > From looking into the datasheet, this is a chip which will be typically used for hardware monitoring. > Previous reasons have been: > - Very high performmance / accuracy part (i.e. expensive) 0.25 Hz ... 16 Hz sampling rate. No. > - Remote temperature so not typically hw monitoring. Local only. > - Same silicon with a more complex sensor (typically humidity or similar). > No. It looks like the I2C part of the chip is is compatible to TMP108, so another question would be why to implement a new driver in the first place. Guenter ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] iio: temperature: Add support for P3T1085 2024-11-08 15:49 ` Guenter Roeck @ 2024-11-08 16:45 ` Frank Li 0 siblings, 0 replies; 10+ messages in thread From: Frank Li @ 2024-11-08 16:45 UTC (permalink / raw) To: Guenter Roeck Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jonathan Cameron, Lars-Peter Clausen, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, devicetree, linux-kernel, linux-iio, imx, linux-arm-kernel, Carlos Song, Clark Wang, Jean Delvare, linux-hwmon On Fri, Nov 08, 2024 at 07:49:54AM -0800, Guenter Roeck wrote: > On 11/8/24 07:28, Jonathan Cameron wrote: > > On Thu, 07 Nov 2024 18:02:26 -0500 > > Frank Li <Frank.Li@nxp.com> wrote: > > > > > Add basic function support for P3T1085 temperature sensor. > > > - Add binding doc trivial.yaml > > > - Add basic read temperature driver > > Hi Frank, > > > > For a simple temperature sensor the usual question is why IIO rather > > than hwmon? > > > > From looking into the datasheet, this is a chip which will be typically > used for hardware monitoring. > > > Previous reasons have been: > > - Very high performmance / accuracy part (i.e. expensive) > > 0.25 Hz ... 16 Hz sampling rate. No. > > > - Remote temperature so not typically hw monitoring. > > Local only. > > > - Same silicon with a more complex sensor (typically humidity or similar). > > > No. > > It looks like the I2C part of the chip is is compatible to TMP108, so > another question would be why to implement a new driver in the first place. Thanks, let me check TMP108. Frank > > Guenter > > ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-11-08 17:48 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-11-07 23:02 [PATCH 0/3] iio: temperature: Add support for P3T1085 Frank Li 2024-11-07 23:02 ` [PATCH 1/3] dt-bindings: trivial-devices: Add NXP P3T1085UK I3C/I2C temperature sensor Frank Li 2024-11-08 8:45 ` Marco Felsch 2024-11-08 17:47 ` Conor Dooley 2024-11-07 23:02 ` [PATCH 2/3] iio: temperature: Add support for P3T1085 Frank Li 2024-11-08 8:41 ` Marco Felsch 2024-11-07 23:02 ` [PATCH 3/3] arm64: dts: imx93-9x9-qsb: add temp-sensor nxp,p3t1085 Frank Li 2024-11-08 15:28 ` [PATCH 0/3] iio: temperature: Add support for P3T1085 Jonathan Cameron 2024-11-08 15:49 ` Guenter Roeck 2024-11-08 16:45 ` Frank Li
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox