mfd: rn5t618: Extend ADC support
Subsystems (2)
v3 cover mfd: rn5t618: Extend ADC support
Add iio map to make voltage_now related channels accessible to power driver.
Changes in v3:
- use scale functions
- add acks
Changes in v2:
- use iio_map instead of devicetree to allow mapping which does not block future extension by devicetree.
*** BLURB HERE ***
Andreas Kemnade (2):
iio: adc: rn5t618: Add iio map
power: supply: rn5t618: Add voltage_now property
drivers/iio/adc/rn5t618-adc.c | 23 +++++++++++++++++ drivers/power/supply/Kconfig | 2 ++ drivers/power/supply/rn5t618_power.c | 38 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+)
Signature · 1 line
2.30.2
PATCH v3 1/2 iio: adc: rn5t618: Add iio map
Add iio map to allow power driver to read out values as a consumer. This approach does not block later addition of devicetree support which would be helpful if there is an in-kernel consumer for AIN0/1.
---
Changes in v3:
- none
Changes in v2:
- provide consumer mapping via iio_map instead of devicetree
drivers/iio/adc/rn5t618-adc.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/iio/adc/rn5t618-adc.c +23 -0
@@ -16,6 +16,8 @@#include <linux/completion.h> #include <linux/regmap.h> #include <linux/iio/iio.h> +#include <linux/iio/driver.h> +#include <linux/iio/machine.h> #include <linux/slab.h> #define RN5T618_ADC_CONVERSION_TIMEOUT (msecs_to_jiffies(500))
@@ -189,6 +191,19 @@ static const struct iio_chan_spec rn5t618_adc_iio_channels[] = { RN5T618_ADC_CHANNEL(AIN0, IIO_VOLTAGE, "AIN0") }; +static struct iio_map rn5t618_maps[] = { +IIO_MAP ("VADP" ,"rn5t618-power" ,"vadp" ), +IIO_MAP ("VUSB" ,"rn5t618-power" ,"vusb" ), + {/* sentinel */ } +}; + +static void unregister_map (void *data) +{ +struct iio_dev *iio_dev = (struct iio_dev *) data; + +iio_map_array_unregister (iio_dev); +} +static int rn5t618_adc_probe (struct platform_device *pdev) {int ret;
@@ -239,6 +254,14 @@ static int rn5t618_adc_probe(struct platform_device *pdev)return ret; } + ret =iio_map_array_register (iio_dev, rn5t618_maps); +if (ret <0 ) +return ret; + + ret =devm_add_action_or_reset (adc->dev, unregister_map, iio_dev); +if (ret <0 ) +return ret; +return devm_iio_device_register (adc->dev, iio_dev); }
Signature · 1 line
2.30.2
PATCH v3 2/2 power: supply: rn5t618: Add voltage_now property
In reply to Andreas KemnadeRead voltage_now via IIO and provide the property.
---
Changes in v3:
- use scaled reading function
Changes in v2:
- different error handling needed for iio_map usage
- fix dependencies in Kconfig
drivers/power/supply/Kconfig | 2 ++ drivers/power/supply/rn5t618_power.c | 38 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
drivers/power/supply/Kconfig +2 -0
@@ -790,6 +790,8 @@ config CHARGER_WILCO config RN5T618_POWER tristate "RN5T618 charger/fuel gauge support" depends on MFD_RN5T618 + depends on RN5T618_ADC + depends on IIO help Say Y here to have support for RN5T618 PMIC family fuel gauge and charger. This driver can also be built as a module. If so, the module will be
drivers/power/supply/rn5t618_power.c +38 -0
@@ -9,10 +9,12 @@#include <linux/device.h> #include <linux/bitops.h> #include <linux/errno.h> +#include <linux/iio/consumer.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/mfd/rn5t618.h> +#include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/power_supply.h> #include <linux/regmap.h>
@@ -64,6 +66,8 @@ struct rn5t618_power_info {struct power_supply *battery;struct power_supply *usb;struct power_supply *adp; +struct iio_channel *channel_vusb; +struct iio_channel *channel_vadp;int irq; };
@@ -77,6 +81,7 @@ static enum power_supply_usb_type rn5t618_usb_types[] = {static enum power_supply_property rn5t618_usb_props[] = {/* input current limit is not very accurate */ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT , +POWER_SUPPLY_PROP_VOLTAGE_NOW ,POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_USB_TYPE ,POWER_SUPPLY_PROP_ONLINE ,
@@ -85,6 +90,7 @@ static enum power_supply_property rn5t618_usb_props[] = {static enum power_supply_property rn5t618_adp_props[] = {/* input current limit is not very accurate */ POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT , +POWER_SUPPLY_PROP_VOLTAGE_NOW ,POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_ONLINE , };
@@ -463,6 +469,15 @@ static int rn5t618_adp_get_property(struct power_supply *psy,return ret; val->intval =FROM_CUR_REG (regval); +break ; +case POWER_SUPPLY_PROP_VOLTAGE_NOW : +if (!info->channel_vadp) +return -ENODATA ; + + ret =iio_read_channel_processed_scale (info->channel_vadp, &val->intval,1000 ); +if (ret <0 ) +return ret; +break ;default :return -EINVAL ;
@@ -588,6 +603,15 @@ static int rn5t618_usb_get_property(struct power_supply *psy, val->intval =FROM_CUR_REG (regval); } +break ; +case POWER_SUPPLY_PROP_VOLTAGE_NOW : +if (!info->channel_vusb) +return -ENODATA ; + + ret =iio_read_channel_processed_scale (info->channel_vusb, &val->intval,1000 ); +if (ret <0 ) +return ret; +break ;default :return -EINVAL ;
@@ -711,6 +735,20 @@ static int rn5t618_power_probe(struct platform_device *pdev)platform_set_drvdata (pdev, info); + info->channel_vusb =devm_iio_channel_get (&pdev->dev,"vusb" ); +if (IS_ERR (info->channel_vusb)) { +if (PTR_ERR (info->channel_vusb) == -ENODEV ) +return -EPROBE_DEFER ; +return PTR_ERR (info->channel_vusb); + } + + info->channel_vadp =devm_iio_channel_get (&pdev->dev,"vadp" ); +if (IS_ERR (info->channel_vadp)) { +if (PTR_ERR (info->channel_vadp) == -ENODEV ) +return -EPROBE_DEFER ; +return PTR_ERR (info->channel_vadp); + } + ret =regmap_read (info->rn5t618->regmap,RN5T618_CONTROL , &v);if (ret)return ret;
Signature · 1 line
2.30.2
Quoted 7 lines · Andreas Kemnade
Add iio map to make
voltage_nowrelated channels accessible to power driver.Changes in v3:
- use scale functions
- add acks
Quoted 6 lines
Changes in v2:
- useiio_mapinstead of devicetree to allow mapping which does not block future extension by devicetree.*** BLURB HERE ***
Doh!
Quoted 8 lines
Andreas Kemnade (2):
iio: adc: rn5t618: Add iio map
power: supply: rn5t618: Addvoltage_nowpropertydrivers/iio/adc/rn5t618-adc.c | 23 +++++++++++++++++ drivers/power/supply/Kconfig | 2 ++ drivers/power/supply/rn5t618_power.c | 38 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+)
Not sure I get this.
Firstly, the cover-letter is marked as MFD, but no MFD changes occur. Secondly, I am only in receipt of the 0th patch which seems odd. IMHO patch sets should be sent threaded and all parties should see discussion on all patches regardless of whether they maintain them or not, since the overall conversation is often useful/relevant to all.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog
Jonathan Cameron
maintainerQuoted 22 lines · On Tue, 13 Jul 2021 09:27:27 +0100 Lee Jones <[email protected]> wrote:
Quoted 7 lines · Andreas Kemnade
Add iio map to make
voltage_nowrelated channels accessible to power driver.Changes in v3:
- use scale functions
- add acksQuoted 6 lines
Changes in v2:
- useiio_mapinstead of devicetree to allow mapping which does not block future extension by devicetree.*** BLURB HERE ***
Doh!
Quoted 4 lines
Andreas Kemnade (2):
iio: adc: rn5t618: Add iio map
power: supply: rn5t618: Addvoltage_nowproperty
Quoted 8 lines
Quoted 4 lines
drivers/iio/adc/rn5t618-adc.c | 23 +++++++++++++++++ drivers/power/supply/Kconfig | 2 ++ drivers/power/supply/rn5t618_power.c | 38 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+)Not sure I get this.
Firstly, the cover-letter is marked as MFD, but no MFD changes occur.
So this is a bit of a fun corner case. The series 'used' to include an mfd change that made that labelling relevant. Then that went away as I suggested that we could do it in a simpler fashion.
Under the circumstances the series needed a rename!
Quoted 5 lines
Secondly, I am only in receipt of the 0th patch which seems odd. IMHO patch sets should be sent threaded and all parties should see discussion on all patches regardless of whether they maintain them or not, since the overall conversation is often useful/relevant to all.
Absolutely agree for small series like this.
Anyhow, as far as I'm concerned this is now in the hands of the power supply maintainers anyway so ignoring it ;)
Jonathan
Hi,
Quoted 10 lines · Andreas Kemnade
Add iio map to make
voltage_nowrelated channels accessible to power driver.Changes in v3:
- use scale functions
- add acksChanges in v2:
- useiio_mapinstead of devicetree to allow mapping which does not block future extension by devicetree.
Thanks, queued.
-- Sebastian
Quoted 1 line
*** BLURB HERE ***
:)
Quoted 12 lines
Andreas Kemnade (2):
iio: adc: rn5t618: Add iio map
power: supply: rn5t618: Addvoltage_nowpropertydrivers/iio/adc/rn5t618-adc.c | 23 +++++++++++++++++ drivers/power/supply/Kconfig | 2 ++ drivers/power/supply/rn5t618_power.c | 38 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+)Signature · 1 line
2.30.2