RE: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors
> -Original Message- > From: Lars-Peter Clausen > Sent: Monday, March 22, 2021 6:22 PM > To: Raviteja Narayanam ; robh...@kernel.org; > ji...@kernel.org > Cc: Michal Simek ; pme...@pmeerw.net; linux- > i...@vger.kernel.org; devicet...@vger.kernel.org; linux- > ker...@vger.kernel.org; git ; Shubhrajyoti Datta > > Subject: Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors > > On 3/22/21 1:11 PM, Raviteja Narayanam wrote: > > > >> -Original Message- > >> From: Lars-Peter Clausen > >> Sent: Monday, March 22, 2021 5:22 PM > >> To: Raviteja Narayanam ; robh...@kernel.org; > >> ji...@kernel.org > >> Cc: Michal Simek ; pme...@pmeerw.net; linux- > >> i...@vger.kernel.org; devicet...@vger.kernel.org; linux- > >> ker...@vger.kernel.org; git ; Shubhrajyoti Datta > >> > >> Subject: Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power > >> monitors > >> > >> On 3/22/21 12:43 PM, Lars-Peter Clausen wrote: > >>> On 3/22/21 11:50 AM, Raviteja Narayanam wrote: > >>>> This driver supports software buffer mode and raw reads of ina260 > >>>> iio channels. > >>>> > >>>> In software buffer mode, a kthread will capture the active > >>>> scan_elements periodically using a delay. This can produce a stream > >>>> of up to 3 channels plus a 64 bits timestamp based on the > scan_elements. > >>>> > >>>> Signed-off-by: Raviteja Narayanam > >>>> Signed-off-by: Shubhrajyoti Datta > >>> Hi, > >>> > >>> Thanks for that patch, it looks really good. > >>> > >>> Looking at the datasheet the part seems to be very similar to the > >>> ina226 from a software interface point of view. Looks like the > >>> current and calibration register are missing and the scales are a bit > different. > >>> > >>> We already have a driver for the ina226 (adc-ina2xx) and it looks > >>> like your driver is also inspired by it. Have you considered adding > >>> support for the ina260 to the existing driver? This will reduce the > >>> amount of duplicated code. > >> To add to that this driver has some nice new features and bug fixes > >> that are not in the ina2xx driver, like debug register access. But > >> the ina2xx has also seen a fair amount of improvements since this driver > was branched off of it. > >> It would be nice to get the best of both in a single driver. > > Thanks for the review Lars. > > Yes, using ina2xx driver was the first preference but after this > > discussion (https://www.spinics.net/lists/devicetree/msg354475.html ), > we have started a new driver as ina260 was considered to be sufficiently > different from ina2xx. > > Can you elaborate where you see the significant difference? When I look at > the code the drivers are >90% identical. > > I believe pretty much all we need to support the ina260 in the existing driver > is to add a new iio_chan_spec and ina2xx_config for it. And then some minor > tweaks to other parts of the driver, e.g. to make calibration optional. I > believe this can be done in ~50 lines of code without making the structure of > the driver more cluttered. We will take a look at it again and get back to you. > > > > > Regards, > > Raviteja N > > > >>> - Lars > >>> > >>>> --- > >>>> MAINTAINERS | 8 + > >>>> drivers/iio/adc/Kconfig | 12 + > >>>> drivers/iio/adc/Makefile | 1 + > >>>> drivers/iio/adc/ina260-adc.c | 556 > >>>> +++ > >>>> 4 files changed, 577 insertions(+) > >>>> create mode 100644 drivers/iio/adc/ina260-adc.c > >>>> > >>>> diff --git a/MAINTAINERS b/MAINTAINERS index > >>>> aa84121c5611..768a4b148035 100644 > >>>> --- a/MAINTAINERS > >>>> +++ b/MAINTAINERS > >>>> @@ -8760,6 +8760,14 @@ F: Documentation/hwmon/ina2xx.rst > >>>> F: drivers/hwmon/ina2xx.c > >>>> F: include/linux/platform_data/ina2xx.h > >>>> +INA260 POWER MONITOR DRIVER > >>>> +M: Raviteja Narayanam > >>>> +R: Shubhrajyoti Datta > >>>> +R: Michal Simek > >>>> +S: Maintained > >>>> +F: Documentation/devicetree/bindings/iio/adc/ti,ina260.yaml > >>>> +
Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors
On 3/22/21 1:11 PM, Raviteja Narayanam wrote: -Original Message- From: Lars-Peter Clausen Sent: Monday, March 22, 2021 5:22 PM To: Raviteja Narayanam ; robh...@kernel.org; ji...@kernel.org Cc: Michal Simek ; pme...@pmeerw.net; linux- i...@vger.kernel.org; devicet...@vger.kernel.org; linux- ker...@vger.kernel.org; git ; Shubhrajyoti Datta Subject: Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors On 3/22/21 12:43 PM, Lars-Peter Clausen wrote: On 3/22/21 11:50 AM, Raviteja Narayanam wrote: This driver supports software buffer mode and raw reads of ina260 iio channels. In software buffer mode, a kthread will capture the active scan_elements periodically using a delay. This can produce a stream of up to 3 channels plus a 64 bits timestamp based on the scan_elements. Signed-off-by: Raviteja Narayanam Signed-off-by: Shubhrajyoti Datta Hi, Thanks for that patch, it looks really good. Looking at the datasheet the part seems to be very similar to the ina226 from a software interface point of view. Looks like the current and calibration register are missing and the scales are a bit different. We already have a driver for the ina226 (adc-ina2xx) and it looks like your driver is also inspired by it. Have you considered adding support for the ina260 to the existing driver? This will reduce the amount of duplicated code. To add to that this driver has some nice new features and bug fixes that are not in the ina2xx driver, like debug register access. But the ina2xx has also seen a fair amount of improvements since this driver was branched off of it. It would be nice to get the best of both in a single driver. Thanks for the review Lars. Yes, using ina2xx driver was the first preference but after this discussion (https://www.spinics.net/lists/devicetree/msg354475.html ), we have started a new driver as ina260 was considered to be sufficiently different from ina2xx. Can you elaborate where you see the significant difference? When I look at the code the drivers are >90% identical. I believe pretty much all we need to support the ina260 in the existing driver is to add a new iio_chan_spec and ina2xx_config for it. And then some minor tweaks to other parts of the driver, e.g. to make calibration optional. I believe this can be done in ~50 lines of code without making the structure of the driver more cluttered. Regards, Raviteja N - Lars --- MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ina260-adc.c | 556 +++ 4 files changed, 577 insertions(+) create mode 100644 drivers/iio/adc/ina260-adc.c diff --git a/MAINTAINERS b/MAINTAINERS index aa84121c5611..768a4b148035 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8760,6 +8760,14 @@ F: Documentation/hwmon/ina2xx.rst F: drivers/hwmon/ina2xx.c F: include/linux/platform_data/ina2xx.h +INA260 POWER MONITOR DRIVER +M: Raviteja Narayanam +R: Shubhrajyoti Datta +R: Michal Simek +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/ti,ina260.yaml +F: drivers/iio/adc/ina260-adc.c + INDUSTRY PACK SUBSYSTEM (IPACK) M: Samuel Iglesias Gonsalvez M: Jens Taprogge diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index bf7d22fa4be2..f6f8fd6bd113 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -497,6 +497,18 @@ config INA2XX_ADC Say yes here to build support for TI INA2xx family of Power Monitors. This driver is mutually exclusive with the HWMON version. +config INA260_ADC + tristate "Texas Instruments INA260 Power Monitors IIO driver" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say yes here to build support for TI INA260 power monitor. + This driver can also be built as a module. It supports software buffer + mode and raw reads of ina260 iio channels. Up to 4 channels +are + supported including timestamp. + config INGENIC_ADC tristate "Ingenic JZ47xx SoCs ADC driver" depends on MIPS || COMPILE_TEST diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 5fca90ada0ec..a3bbcad64a41 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_HX711) += hx711.o obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o +obj-$(CONFIG_INA260_ADC) += ina260-adc.o obj-$(CONFIG_INGENIC_ADC) += ingenic-adc.o obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o diff --git a/drivers/iio/adc/ina260-adc.c b/drivers/iio/adc/ina260-adc.c new file mode 100644 index ..7f74aa94fd31 --- /dev/null +++ b/drivers/iio/adc/ina260-adc.c @@ -0,0 +1,556 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * INA260 power moni
RE: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors
> -Original Message- > From: Lars-Peter Clausen > Sent: Monday, March 22, 2021 5:22 PM > To: Raviteja Narayanam ; robh...@kernel.org; > ji...@kernel.org > Cc: Michal Simek ; pme...@pmeerw.net; linux- > i...@vger.kernel.org; devicet...@vger.kernel.org; linux- > ker...@vger.kernel.org; git ; Shubhrajyoti Datta > > Subject: Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors > > On 3/22/21 12:43 PM, Lars-Peter Clausen wrote: > > On 3/22/21 11:50 AM, Raviteja Narayanam wrote: > >> This driver supports software buffer mode and raw reads of ina260 iio > >> channels. > >> > >> In software buffer mode, a kthread will capture the active > >> scan_elements periodically using a delay. This can produce a stream > >> of up to 3 channels plus a 64 bits timestamp based on the scan_elements. > >> > >> Signed-off-by: Raviteja Narayanam > >> Signed-off-by: Shubhrajyoti Datta > > > > Hi, > > > > Thanks for that patch, it looks really good. > > > > Looking at the datasheet the part seems to be very similar to the > > ina226 from a software interface point of view. Looks like the current > > and calibration register are missing and the scales are a bit different. > > > > We already have a driver for the ina226 (adc-ina2xx) and it looks like > > your driver is also inspired by it. Have you considered adding support > > for the ina260 to the existing driver? This will reduce the amount of > > duplicated code. > > To add to that this driver has some nice new features and bug fixes that are > not in the ina2xx driver, like debug register access. But the ina2xx has also > seen a fair amount of improvements since this driver was branched off of it. > It would be nice to get the best of both in a single driver. Thanks for the review Lars. Yes, using ina2xx driver was the first preference but after this discussion (https://www.spinics.net/lists/devicetree/msg354475.html ), we have started a new driver as ina260 was considered to be sufficiently different from ina2xx. Regards, Raviteja N > > > > > - Lars > > > >> --- > >> MAINTAINERS | 8 + > >> drivers/iio/adc/Kconfig | 12 + > >> drivers/iio/adc/Makefile | 1 + > >> drivers/iio/adc/ina260-adc.c | 556 > >> +++ > >> 4 files changed, 577 insertions(+) > >> create mode 100644 drivers/iio/adc/ina260-adc.c > >> > >> diff --git a/MAINTAINERS b/MAINTAINERS index > >> aa84121c5611..768a4b148035 100644 > >> --- a/MAINTAINERS > >> +++ b/MAINTAINERS > >> @@ -8760,6 +8760,14 @@ F: Documentation/hwmon/ina2xx.rst > >> F: drivers/hwmon/ina2xx.c > >> F: include/linux/platform_data/ina2xx.h > >> +INA260 POWER MONITOR DRIVER > >> +M: Raviteja Narayanam > >> +R: Shubhrajyoti Datta > >> +R: Michal Simek > >> +S: Maintained > >> +F: Documentation/devicetree/bindings/iio/adc/ti,ina260.yaml > >> +F: drivers/iio/adc/ina260-adc.c > >> + > >> INDUSTRY PACK SUBSYSTEM (IPACK) > >> M: Samuel Iglesias Gonsalvez > >> M: Jens Taprogge diff --git > >> a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index > >> bf7d22fa4be2..f6f8fd6bd113 100644 > >> --- a/drivers/iio/adc/Kconfig > >> +++ b/drivers/iio/adc/Kconfig > >> @@ -497,6 +497,18 @@ config INA2XX_ADC > >> Say yes here to build support for TI INA2xx family of Power > >> Monitors. > >> This driver is mutually exclusive with the HWMON version. > >> +config INA260_ADC > >> + tristate "Texas Instruments INA260 Power Monitors IIO driver" > >> + depends on I2C > >> + select REGMAP_I2C > >> + select IIO_BUFFER > >> + select IIO_KFIFO_BUF > >> + help > >> + Say yes here to build support for TI INA260 power monitor. > >> + This driver can also be built as a module. It supports > >> software buffer > >> + mode and raw reads of ina260 iio channels. Up to 4 channels > >> +are > >> + supported including timestamp. > >> + > >> config INGENIC_ADC > >> tristate "Ingenic JZ47xx SoCs ADC driver" > >> depends on MIPS || COMPILE_TEST diff --git > >> a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index > >> 5fca90ada0ec..a3bbcad64a41 100644 > >> --- a/drivers/iio/adc/Makefile > >> +++ b/drivers/
Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors
On 3/22/21 12:43 PM, Lars-Peter Clausen wrote: On 3/22/21 11:50 AM, Raviteja Narayanam wrote: This driver supports software buffer mode and raw reads of ina260 iio channels. In software buffer mode, a kthread will capture the active scan_elements periodically using a delay. This can produce a stream of up to 3 channels plus a 64 bits timestamp based on the scan_elements. Signed-off-by: Raviteja Narayanam Signed-off-by: Shubhrajyoti Datta Hi, Thanks for that patch, it looks really good. Looking at the datasheet the part seems to be very similar to the ina226 from a software interface point of view. Looks like the current and calibration register are missing and the scales are a bit different. We already have a driver for the ina226 (adc-ina2xx) and it looks like your driver is also inspired by it. Have you considered adding support for the ina260 to the existing driver? This will reduce the amount of duplicated code. To add to that this driver has some nice new features and bug fixes that are not in the ina2xx driver, like debug register access. But the ina2xx has also seen a fair amount of improvements since this driver was branched off of it. It would be nice to get the best of both in a single driver. - Lars --- MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ina260-adc.c | 556 +++ 4 files changed, 577 insertions(+) create mode 100644 drivers/iio/adc/ina260-adc.c diff --git a/MAINTAINERS b/MAINTAINERS index aa84121c5611..768a4b148035 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8760,6 +8760,14 @@ F: Documentation/hwmon/ina2xx.rst F: drivers/hwmon/ina2xx.c F: include/linux/platform_data/ina2xx.h +INA260 POWER MONITOR DRIVER +M: Raviteja Narayanam +R: Shubhrajyoti Datta +R: Michal Simek +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/ti,ina260.yaml +F: drivers/iio/adc/ina260-adc.c + INDUSTRY PACK SUBSYSTEM (IPACK) M: Samuel Iglesias Gonsalvez M: Jens Taprogge diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index bf7d22fa4be2..f6f8fd6bd113 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -497,6 +497,18 @@ config INA2XX_ADC Say yes here to build support for TI INA2xx family of Power Monitors. This driver is mutually exclusive with the HWMON version. +config INA260_ADC + tristate "Texas Instruments INA260 Power Monitors IIO driver" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say yes here to build support for TI INA260 power monitor. + This driver can also be built as a module. It supports software buffer + mode and raw reads of ina260 iio channels. Up to 4 channels are + supported including timestamp. + config INGENIC_ADC tristate "Ingenic JZ47xx SoCs ADC driver" depends on MIPS || COMPILE_TEST diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 5fca90ada0ec..a3bbcad64a41 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_HX711) += hx711.o obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o +obj-$(CONFIG_INA260_ADC) += ina260-adc.o obj-$(CONFIG_INGENIC_ADC) += ingenic-adc.o obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o diff --git a/drivers/iio/adc/ina260-adc.c b/drivers/iio/adc/ina260-adc.c new file mode 100644 index ..7f74aa94fd31 --- /dev/null +++ b/drivers/iio/adc/ina260-adc.c @@ -0,0 +1,556 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * INA260 power monitor driver + * Based on drivers/iio/adc/ina2xx-adc.c + * + * Copyright (C) 2021 Xilinx, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* INA260 registers definition */ +#define INA260_CONFIG 0x00 +#define INA260_CURRENT 0x01 +#define INA260_VOLTAGE 0x02 +#define INA260_POWER 0x03 +#define INA260_MASK_ENABLE 0x06 +#define INA260_ALERT_LIMIT 0x07 +#define INA260_MANF_ID 0xFE +#define INA260_DIE_ID 0xFF + +#define INA260_CONFIG_DEFAULT 0x6327 + +#define INA260_CURRENT_LSB 1250 +#define INA260_VOLTAGE_LSB 1250 +#define INA260_POWER_LSB 10 + +/* Bits */ +#define INA260_CVRF BIT(3) + +#define INA260_MODE_MASK GENMASK(2, 0) +#define INA260_VOLT_MASK GENMASK(8, 6) +#define INA260_SHIFT_VOLT(val) ((val) << 6) +#define INA260_CURR_MASK GENMASK(5, 3) +#define INA260_SHIFT_CURR(val) ((val) << 3) +#define INA260_AVG_MASK GENMASK(11, 9) +#define INA260_SHIFT_AVG(val) ((val) << 9) + +#define SAMPLING_PERIOD(x) ({ \ + typeof(x) _x = (x); \ + (_x->config->volt_conv_time \ + + _x->config->curr_conv_time)
Re: [PATCH 2/2] iio: adc: Add support for TI INA260 power monitors
On 3/22/21 11:50 AM, Raviteja Narayanam wrote: This driver supports software buffer mode and raw reads of ina260 iio channels. In software buffer mode, a kthread will capture the active scan_elements periodically using a delay. This can produce a stream of up to 3 channels plus a 64 bits timestamp based on the scan_elements. Signed-off-by: Raviteja Narayanam Signed-off-by: Shubhrajyoti Datta Hi, Thanks for that patch, it looks really good. Looking at the datasheet the part seems to be very similar to the ina226 from a software interface point of view. Looks like the current and calibration register are missing and the scales are a bit different. We already have a driver for the ina226 (adc-ina2xx) and it looks like your driver is also inspired by it. Have you considered adding support for the ina260 to the existing driver? This will reduce the amount of duplicated code. - Lars --- MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ina260-adc.c | 556 +++ 4 files changed, 577 insertions(+) create mode 100644 drivers/iio/adc/ina260-adc.c diff --git a/MAINTAINERS b/MAINTAINERS index aa84121c5611..768a4b148035 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8760,6 +8760,14 @@ F: Documentation/hwmon/ina2xx.rst F:drivers/hwmon/ina2xx.c F:include/linux/platform_data/ina2xx.h +INA260 POWER MONITOR DRIVER +M: Raviteja Narayanam +R: Shubhrajyoti Datta +R: Michal Simek +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/ti,ina260.yaml +F: drivers/iio/adc/ina260-adc.c + INDUSTRY PACK SUBSYSTEM (IPACK) M:Samuel Iglesias Gonsalvez M:Jens Taprogge diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index bf7d22fa4be2..f6f8fd6bd113 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -497,6 +497,18 @@ config INA2XX_ADC Say yes here to build support for TI INA2xx family of Power Monitors. This driver is mutually exclusive with the HWMON version. +config INA260_ADC + tristate "Texas Instruments INA260 Power Monitors IIO driver" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say yes here to build support for TI INA260 power monitor. + This driver can also be built as a module. It supports software buffer + mode and raw reads of ina260 iio channels. Up to 4 channels are + supported including timestamp. + config INGENIC_ADC tristate "Ingenic JZ47xx SoCs ADC driver" depends on MIPS || COMPILE_TEST diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 5fca90ada0ec..a3bbcad64a41 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_HX711) += hx711.o obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o +obj-$(CONFIG_INA260_ADC) += ina260-adc.o obj-$(CONFIG_INGENIC_ADC) += ingenic-adc.o obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o diff --git a/drivers/iio/adc/ina260-adc.c b/drivers/iio/adc/ina260-adc.c new file mode 100644 index ..7f74aa94fd31 --- /dev/null +++ b/drivers/iio/adc/ina260-adc.c @@ -0,0 +1,556 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * INA260 power monitor driver + * Based on drivers/iio/adc/ina2xx-adc.c + * + * Copyright (C) 2021 Xilinx, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* INA260 registers definition */ +#define INA260_CONFIG 0x00 +#define INA260_CURRENT 0x01 +#define INA260_VOLTAGE 0x02 +#define INA260_POWER 0x03 +#define INA260_MASK_ENABLE 0x06 +#define INA260_ALERT_LIMIT 0x07 +#define INA260_MANF_ID 0xFE +#define INA260_DIE_ID 0xFF + +#define INA260_CONFIG_DEFAULT 0x6327 + +#define INA260_CURRENT_LSB 1250 +#define INA260_VOLTAGE_LSB 1250 +#define INA260_POWER_LSB 10 + +/* Bits */ +#define INA260_CVRFBIT(3) + +#define INA260_MODE_MASK GENMASK(2, 0) +#define INA260_VOLT_MASK GENMASK(8, 6) +#define INA260_SHIFT_VOLT(val) ((val) << 6) +#define INA260_CURR_MASK GENMASK(5, 3) +#define INA260_SHIFT_CURR(val) ((val) << 3) +#define INA260_AVG_MASKGENMASK(11, 9) +#define INA260_SHIFT_AVG(val) ((val) << 9) + +#define SAMPLING_PERIOD(x) ({ \ + typeof(x) _x = (x); \ + (_x->config->volt_conv_time \ + + _x->config->curr_conv_time) \ + * _x->config->avgs; }) + +static bool ina260_is_writeable_reg(struct device *dev, unsigned int reg) +{ + return (reg == INA260_CONFIG) || (reg == INA260_MASK_ENABLE) || + (reg == INA260_ALERT_LIMIT); +} + +static bool ina26
[PATCH 2/2] iio: adc: Add support for TI INA260 power monitors
This driver supports software buffer mode and raw reads of ina260 iio channels. In software buffer mode, a kthread will capture the active scan_elements periodically using a delay. This can produce a stream of up to 3 channels plus a 64 bits timestamp based on the scan_elements. Signed-off-by: Raviteja Narayanam Signed-off-by: Shubhrajyoti Datta --- MAINTAINERS | 8 + drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ina260-adc.c | 556 +++ 4 files changed, 577 insertions(+) create mode 100644 drivers/iio/adc/ina260-adc.c diff --git a/MAINTAINERS b/MAINTAINERS index aa84121c5611..768a4b148035 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8760,6 +8760,14 @@ F: Documentation/hwmon/ina2xx.rst F: drivers/hwmon/ina2xx.c F: include/linux/platform_data/ina2xx.h +INA260 POWER MONITOR DRIVER +M: Raviteja Narayanam +R: Shubhrajyoti Datta +R: Michal Simek +S: Maintained +F: Documentation/devicetree/bindings/iio/adc/ti,ina260.yaml +F: drivers/iio/adc/ina260-adc.c + INDUSTRY PACK SUBSYSTEM (IPACK) M: Samuel Iglesias Gonsalvez M: Jens Taprogge diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index bf7d22fa4be2..f6f8fd6bd113 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -497,6 +497,18 @@ config INA2XX_ADC Say yes here to build support for TI INA2xx family of Power Monitors. This driver is mutually exclusive with the HWMON version. +config INA260_ADC + tristate "Texas Instruments INA260 Power Monitors IIO driver" + depends on I2C + select REGMAP_I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say yes here to build support for TI INA260 power monitor. + This driver can also be built as a module. It supports software buffer + mode and raw reads of ina260 iio channels. Up to 4 channels are + supported including timestamp. + config INGENIC_ADC tristate "Ingenic JZ47xx SoCs ADC driver" depends on MIPS || COMPILE_TEST diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 5fca90ada0ec..a3bbcad64a41 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_HI8435) += hi8435.o obj-$(CONFIG_HX711) += hx711.o obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o +obj-$(CONFIG_INA260_ADC) += ina260-adc.o obj-$(CONFIG_INGENIC_ADC) += ingenic-adc.o obj-$(CONFIG_INTEL_MRFLD_ADC) += intel_mrfld_adc.o obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o diff --git a/drivers/iio/adc/ina260-adc.c b/drivers/iio/adc/ina260-adc.c new file mode 100644 index ..7f74aa94fd31 --- /dev/null +++ b/drivers/iio/adc/ina260-adc.c @@ -0,0 +1,556 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * INA260 power monitor driver + * Based on drivers/iio/adc/ina2xx-adc.c + * + * Copyright (C) 2021 Xilinx, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* INA260 registers definition */ +#define INA260_CONFIG 0x00 +#define INA260_CURRENT 0x01 +#define INA260_VOLTAGE 0x02 +#define INA260_POWER 0x03 +#define INA260_MASK_ENABLE 0x06 +#define INA260_ALERT_LIMIT 0x07 +#define INA260_MANF_ID 0xFE +#define INA260_DIE_ID 0xFF + +#define INA260_CONFIG_DEFAULT 0x6327 + +#define INA260_CURRENT_LSB 1250 +#define INA260_VOLTAGE_LSB 1250 +#define INA260_POWER_LSB 10 + +/* Bits */ +#define INA260_CVRFBIT(3) + +#define INA260_MODE_MASK GENMASK(2, 0) +#define INA260_VOLT_MASK GENMASK(8, 6) +#define INA260_SHIFT_VOLT(val) ((val) << 6) +#define INA260_CURR_MASK GENMASK(5, 3) +#define INA260_SHIFT_CURR(val) ((val) << 3) +#define INA260_AVG_MASKGENMASK(11, 9) +#define INA260_SHIFT_AVG(val) ((val) << 9) + +#define SAMPLING_PERIOD(x) ({ \ + typeof(x) _x = (x); \ + (_x->config->volt_conv_time \ + + _x->config->curr_conv_time) \ + * _x->config->avgs; }) + +static bool ina260_is_writeable_reg(struct device *dev, unsigned int reg) +{ + return (reg == INA260_CONFIG) || (reg == INA260_MASK_ENABLE) || + (reg == INA260_ALERT_LIMIT); +} + +static bool ina260_is_volatile_reg(struct device *dev, unsigned int reg) +{ + return (reg != INA260_CONFIG); +} + +static inline bool is_signed_reg(unsigned int reg) +{ + return (reg == INA260_CURRENT); +} + +static const struct regmap_config ina260_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .max_register = 8, + .writeable_reg = ina260_is_writeable_reg, + .volatile_reg = ina260_is_volatile_reg, +}; + +enum ina260_ids {ina260 = 0}; + +/** + * struct ina260_config - For configurable parameters + * @config_default: Default configuration + *