* [PATCH v4 0/8] Add support for mp2733 battery charger
@ 2022-10-24 13:27 Saravanan Sekar
2022-10-24 13:27 ` [PATCH v4 1/8] iio: adc: mp2629: fix wrong comparison of channel Saravanan Sekar
` (7 more replies)
0 siblings, 8 replies; 19+ messages in thread
From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw)
To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars,
andy.shevchenko
Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar
changes in v4:
- fixed attributes groups review comments in v3
- added new bug fix patches v4-0007 and v4-0008
changes in v3:
- fixed dt_binding_check error
- fixed spelling usb->USB
changes in v2:
- fixed spelling
- revert back probe to probe_new in mfd driver
I do not see a cover letter, but FWIW,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
for all patches except DT binding
Note, some of the comments regarding spelling were given, I believe
you are going to address them in v3.
add support for mp2733 Battery charger control driver for Monolithic
Power System's MP2733 chipset
Saravanan Sekar (8):
iio: adc: mp2629: fix wrong comparison of channel
mfd: mp2629: Add support for mps mp2733 battery charger
iio: adc: mp2629: restrict input voltage mask for mp2629
power: supply: Add support for mp2733 battery charger
power: supply: mp2629: Add USB fast charge settings
power: supply: fix failed to get iio channel by device name
iio: adc: mp2629: fix potential array out of bound access
power: supply: fix wrong interpretation of register value
.../ABI/testing/sysfs-class-power-mp2629 | 16 ++
drivers/iio/adc/mp2629_adc.c | 8 +-
drivers/mfd/mp2629.c | 7 +-
drivers/power/supply/mp2629_charger.c | 229 +++++++++++++++---
include/linux/mfd/mp2629.h | 6 +
5 files changed, 228 insertions(+), 38 deletions(-)
--
2.32.0
^ permalink raw reply [flat|nested] 19+ messages in thread* [PATCH v4 1/8] iio: adc: mp2629: fix wrong comparison of channel 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 2/8] mfd: mp2629: Add support for mps mp2733 battery charger Saravanan Sekar ` (6 subsequent siblings) 7 siblings, 0 replies; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar Input voltage channel enum is compared against iio address instead of the channel. Fixes: 7abd9fb64682 ("iio: adc: mp2629: Add support for mp2629 ADC driver") Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> --- drivers/iio/adc/mp2629_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/mp2629_adc.c b/drivers/iio/adc/mp2629_adc.c index 30a31f185d08..f7af9af1665d 100644 --- a/drivers/iio/adc/mp2629_adc.c +++ b/drivers/iio/adc/mp2629_adc.c @@ -74,7 +74,7 @@ static int mp2629_read_raw(struct iio_dev *indio_dev, if (ret) return ret; - if (chan->address == MP2629_INPUT_VOLT) + if (chan->channel == MP2629_INPUT_VOLT) rval &= GENMASK(6, 0); *val = rval; return IIO_VAL_INT; -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v4 2/8] mfd: mp2629: Add support for mps mp2733 battery charger 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 1/8] iio: adc: mp2629: fix wrong comparison of channel Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 3/8] iio: adc: mp2629: restrict input voltage mask for mp2629 Saravanan Sekar ` (5 subsequent siblings) 7 siblings, 0 replies; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar mp2733 is updated version of mp2629 battery charge management device for single-cell Li-ion or Li-polymer battery. Additionally supports USB fast-charge and higher range of input voltage. Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> --- drivers/mfd/mp2629.c | 5 ++++- include/linux/mfd/mp2629.h | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/mp2629.c b/drivers/mfd/mp2629.c index 16840ec5fd1c..f59c97e70f83 100644 --- a/drivers/mfd/mp2629.c +++ b/drivers/mfd/mp2629.c @@ -13,6 +13,7 @@ #include <linux/mfd/mp2629.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/regmap.h> #include <linux/slab.h> @@ -43,6 +44,7 @@ static int mp2629_probe(struct i2c_client *client) return -ENOMEM; ddata->dev = &client->dev; + ddata->chip_id = (uintptr_t)device_get_match_data(&client->dev); i2c_set_clientdata(client, ddata); ddata->regmap = devm_regmap_init_i2c(client, &mp2629_regmap_config); @@ -60,7 +62,8 @@ static int mp2629_probe(struct i2c_client *client) } static const struct of_device_id mp2629_of_match[] = { - { .compatible = "mps,mp2629"}, + { .compatible = "mps,mp2629", .data = (void *)CHIP_ID_MP2629 }, + { .compatible = "mps,mp2733", .data = (void *)CHIP_ID_MP2733 }, { } }; MODULE_DEVICE_TABLE(of, mp2629_of_match); diff --git a/include/linux/mfd/mp2629.h b/include/linux/mfd/mp2629.h index 89b706900b57..ee0e65720c75 100644 --- a/include/linux/mfd/mp2629.h +++ b/include/linux/mfd/mp2629.h @@ -9,9 +9,15 @@ #include <linux/device.h> #include <linux/regmap.h> +enum mp2xx_chip_id { + CHIP_ID_MP2629, + CHIP_ID_MP2733, +}; + struct mp2629_data { struct device *dev; struct regmap *regmap; + enum mp2xx_chip_id chip_id; }; enum mp2629_adc_chan { -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v4 3/8] iio: adc: mp2629: restrict input voltage mask for mp2629 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 1/8] iio: adc: mp2629: fix wrong comparison of channel Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 2/8] mfd: mp2629: Add support for mps mp2733 battery charger Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 4/8] power: supply: Add support for mp2733 battery charger Saravanan Sekar ` (4 subsequent siblings) 7 siblings, 0 replies; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar Add support for mp2733 which is updated version of mp2629 with a higher range of input voltage. Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> --- drivers/iio/adc/mp2629_adc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/mp2629_adc.c b/drivers/iio/adc/mp2629_adc.c index f7af9af1665d..0f297072b8aa 100644 --- a/drivers/iio/adc/mp2629_adc.c +++ b/drivers/iio/adc/mp2629_adc.c @@ -65,6 +65,7 @@ static int mp2629_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct mp2629_adc *info = iio_priv(indio_dev); + struct mp2629_data *ddata = dev_get_drvdata(info->dev); unsigned int rval; int ret; @@ -74,8 +75,10 @@ static int mp2629_read_raw(struct iio_dev *indio_dev, if (ret) return ret; - if (chan->channel == MP2629_INPUT_VOLT) + if (chan->channel == MP2629_INPUT_VOLT && + ddata->chip_id == CHIP_ID_MP2629) rval &= GENMASK(6, 0); + *val = rval; return IIO_VAL_INT; -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v4 4/8] power: supply: Add support for mp2733 battery charger 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar ` (2 preceding siblings ...) 2022-10-24 13:27 ` [PATCH v4 3/8] iio: adc: mp2629: restrict input voltage mask for mp2629 Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-28 14:06 ` Sebastian Reichel 2022-10-24 13:27 ` [PATCH v4 5/8] power: supply: mp2629: Add USB fast charge settings Saravanan Sekar ` (3 subsequent siblings) 7 siblings, 1 reply; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar mp2733 is updated version of mp2629 battery charge management which supports USB fast-charge and higher range of input voltage. Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> --- drivers/power/supply/mp2629_charger.c | 223 ++++++++++++++++++++++---- 1 file changed, 192 insertions(+), 31 deletions(-) diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c index bf9c27b463a8..9e4111aace4b 100644 --- a/drivers/power/supply/mp2629_charger.c +++ b/drivers/power/supply/mp2629_charger.c @@ -30,12 +30,15 @@ #define MP2629_REG_INTERRUPT 0x0b #define MP2629_REG_STATUS 0x0c #define MP2629_REG_FAULT 0x0d +#define MP2629_REG_FAST_CHARGE 0x17 #define MP2629_MASK_INPUT_TYPE GENMASK(7, 5) #define MP2629_MASK_CHARGE_TYPE GENMASK(4, 3) #define MP2629_MASK_CHARGE_CTRL GENMASK(5, 4) #define MP2629_MASK_WDOG_CTRL GENMASK(5, 4) #define MP2629_MASK_IMPEDANCE GENMASK(7, 4) +#define MP2733_MASK_FAST_CHARGE GENMASK(2, 1) +#define MP2733_MASK_FAST_CHARGE_RESET BIT(0) #define MP2629_INPUTSOURCE_CHANGE GENMASK(7, 5) #define MP2629_CHARGING_CHANGE GENMASK(4, 3) @@ -62,6 +65,17 @@ enum mp2629_source_type { MP2629_SOURCE_TYPE_OTG = 7, }; +enum mp2733_source_type { + MP2733_SOURCE_TYPE_NO_INPUT, + MP2733_SOURCE_TYPE_NON_STD, + MP2733_SOURCE_TYPE_APPLE_1p0, + MP2733_SOURCE_TYPE_APPLE_2p1, + MP2733_SOURCE_TYPE_APPLE_2p4, + MP2733_SOURCE_TYPE_SDP, + MP2733_SOURCE_TYPE_CDP, + MP2733_SOURCE_TYPE_DCP, +}; + enum mp2629_field { INPUT_ILIM, INPUT_VLIM, @@ -72,11 +86,30 @@ enum mp2629_field { MP2629_MAX_FIELD }; +struct mp2629_prop { + int reg; + int mask; + int min; + int max; + int step; + int shift; +}; + +struct mp2xx_chip_info { + const struct reg_field *rfields; + struct mp2629_prop *chip_props; + bool has_impedance; + bool has_fast_charge; + + int (*mp2xx_get_usb_type)(unsigned int rval); +}; + struct mp2629_charger { struct device *dev; int status; int fault; + const struct mp2xx_chip_info *chip_info; struct regmap *regmap; struct regmap_field *regmap_fields[MP2629_MAX_FIELD]; struct mutex lock; @@ -85,15 +118,6 @@ struct mp2629_charger { struct iio_channel *iiochan[MP2629_ADC_CHAN_END]; }; -struct mp2629_prop { - int reg; - int mask; - int min; - int max; - int step; - int shift; -}; - static enum power_supply_usb_type mp2629_usb_types[] = { POWER_SUPPLY_USB_TYPE_SDP, POWER_SUPPLY_USB_TYPE_DCP, @@ -126,7 +150,25 @@ static enum power_supply_property mp2629_charger_bat_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, }; -static struct mp2629_prop props[] = { +static struct mp2629_prop mp2733_chip_props[] = { + MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000), + MP2629_PROPS(INPUT_VLIM, 3800000, 15200000, 100000), + MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000), + MP2629_PROPS(CHARGE_VLIM, 3400000, 4670000, 10000), + MP2629_PROPS(PRECHARGE, 120000, 720000, 40000), + MP2629_PROPS(TERM_CURRENT, 80000, 680000, 40000), +}; + +static const struct reg_field mp2733_reg_fields[] = { + [INPUT_ILIM] = REG_FIELD(MP2629_REG_INPUT_ILIM, 0, 5), + [INPUT_VLIM] = REG_FIELD(MP2629_REG_INPUT_VLIM, 0, 6), + [CHARGE_ILIM] = REG_FIELD(MP2629_REG_CHARGE_ILIM, 0, 6), + [CHARGE_VLIM] = REG_FIELD(MP2629_REG_CHARGE_VLIM, 1, 7), + [PRECHARGE] = REG_FIELD(MP2629_REG_PRECHARGE, 4, 7), + [TERM_CURRENT] = REG_FIELD(MP2629_REG_TERM_CURRENT, 0, 3), +}; + +static struct mp2629_prop mp2629_chip_props[] = { MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000), MP2629_PROPS(INPUT_VLIM, 3800000, 5300000, 100000), MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000), @@ -174,6 +216,7 @@ static int mp2629_get_prop(struct mp2629_charger *charger, { int ret; unsigned int rval; + struct mp2629_prop *props = charger->chip_info->chip_props; ret = regmap_field_read(charger->regmap_fields[fld], &rval); if (ret) @@ -189,6 +232,7 @@ static int mp2629_set_prop(struct mp2629_charger *charger, const union power_supply_propval *val) { unsigned int rval; + struct mp2629_prop *props = charger->chip_info->chip_props; if (val->intval < props[fld].min || val->intval > props[fld].max) return -EINVAL; @@ -311,6 +355,16 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, default: val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; } + + if (charger->chip_info->has_fast_charge) { + ret = regmap_read(charger->regmap, + MP2629_REG_FAST_CHARGE, &rval); + if (ret) + break; + + if (rval & BIT(6)) + val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; + } break; default: @@ -344,6 +398,40 @@ static int mp2629_charger_battery_set_prop(struct power_supply *psy, } } +static int mp2733_get_usb_type(unsigned int rval) +{ + switch (rval) { + case MP2733_SOURCE_TYPE_APPLE_1p0: + case MP2733_SOURCE_TYPE_APPLE_2p1: + case MP2733_SOURCE_TYPE_APPLE_2p4: + return POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID; + case MP2733_SOURCE_TYPE_SDP: + return POWER_SUPPLY_USB_TYPE_SDP; + case MP2733_SOURCE_TYPE_CDP: + return POWER_SUPPLY_USB_TYPE_CDP; + case MP2733_SOURCE_TYPE_DCP: + return POWER_SUPPLY_USB_TYPE_DCP; + default: + return POWER_SUPPLY_USB_TYPE_UNKNOWN; + } +} + +static int mp2629_get_usb_type(unsigned int rval) +{ + switch (rval) { + case MP2629_SOURCE_TYPE_SDP: + return POWER_SUPPLY_USB_TYPE_SDP; + case MP2629_SOURCE_TYPE_CDP: + return POWER_SUPPLY_USB_TYPE_CDP; + case MP2629_SOURCE_TYPE_DCP: + return POWER_SUPPLY_USB_TYPE_DCP; + case MP2629_SOURCE_TYPE_OTG: + return POWER_SUPPLY_USB_TYPE_PD_DRP; + default: + return POWER_SUPPLY_USB_TYPE_UNKNOWN; + } +} + static int mp2629_charger_usb_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -367,23 +455,7 @@ static int mp2629_charger_usb_get_prop(struct power_supply *psy, break; rval = (rval & MP2629_MASK_INPUT_TYPE) >> 5; - switch (rval) { - case MP2629_SOURCE_TYPE_SDP: - val->intval = POWER_SUPPLY_USB_TYPE_SDP; - break; - case MP2629_SOURCE_TYPE_CDP: - val->intval = POWER_SUPPLY_USB_TYPE_CDP; - break; - case MP2629_SOURCE_TYPE_DCP: - val->intval = POWER_SUPPLY_USB_TYPE_DCP; - break; - case MP2629_SOURCE_TYPE_OTG: - val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP; - break; - default: - val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; - break; - } + val->intval = charger->chip_info->mp2xx_get_usb_type(rval); break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: @@ -550,11 +622,72 @@ static ssize_t batt_impedance_compensation_store(struct device *dev, static DEVICE_ATTR_RW(batt_impedance_compensation); -static struct attribute *mp2629_charger_sysfs_attrs[] = { +static struct attribute *mp2xx_batt_imp_sysfs_attrs[] = { + &dev_attr_batt_impedance_compensation.attr, + NULL +}; +ATTRIBUTE_GROUPS(mp2xx_batt_imp_sysfs); + +static ssize_t usb_fast_charge_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct mp2629_charger *charger = dev_get_drvdata(dev->parent); + unsigned int rval; + int ret; + + ret = regmap_read(charger->regmap, MP2629_REG_INTERRUPT, &rval); + if (ret) + return ret; + + return sysfs_emit(buf, "USB DP %u:DM %u\n", !!(rval & BIT(2)), + !!(rval & BIT(1))); +} + +static ssize_t usb_fast_charge_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct mp2629_charger *charger = dev_get_drvdata(dev->parent); + unsigned int val; + int ret; + + ret = kstrtouint(buf, 10, &val); + if (ret) + return ret; + + if (val > 3) + return -ERANGE; + + ret = regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, + MP2733_MASK_FAST_CHARGE, val << 1); + if (ret) + return ret; + + ret = regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, + MP2733_MASK_FAST_CHARGE_RESET, + MP2733_MASK_FAST_CHARGE_RESET); + if (ret) + return ret; + + return count; +} + +static DEVICE_ATTR_RW(usb_fast_charge); + +static struct attribute *mp2xx_fast_charge_sysfs_attrs[] = { + &dev_attr_usb_fast_charge.attr, + NULL +}; +ATTRIBUTE_GROUPS(mp2xx_fast_charge_sysfs); + +static struct attribute *mp2xx_all_sysfs_attrs[] = { + &dev_attr_usb_fast_charge.attr, &dev_attr_batt_impedance_compensation.attr, NULL }; -ATTRIBUTE_GROUPS(mp2629_charger_sysfs); +ATTRIBUTE_GROUPS(mp2xx_all_sysfs); static void mp2629_charger_disable(void *data) { @@ -564,6 +697,23 @@ static void mp2629_charger_disable(void *data) MP2629_MASK_CHARGE_CTRL, 0); } +static const struct mp2xx_chip_info mp2xx_chip_info_tbl[] = { + [CHIP_ID_MP2629] = { + .rfields = mp2629_reg_fields, + .chip_props = mp2629_chip_props, + .has_impedance = 1, + + .mp2xx_get_usb_type = mp2629_get_usb_type, + }, + [CHIP_ID_MP2733] = { + .rfields = mp2733_reg_fields, + .chip_props = mp2733_chip_props, + .has_fast_charge = 1, + + .mp2xx_get_usb_type = mp2733_get_usb_type, + }, +}; + static int mp2629_charger_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -578,6 +728,7 @@ static int mp2629_charger_probe(struct platform_device *pdev) charger->regmap = ddata->regmap; charger->dev = dev; + charger->chip_info = &mp2xx_chip_info_tbl[ddata->chip_id]; platform_set_drvdata(pdev, charger); irq = platform_get_irq(to_platform_device(dev->parent), 0); @@ -586,7 +737,8 @@ static int mp2629_charger_probe(struct platform_device *pdev) for (i = 0; i < MP2629_MAX_FIELD; i++) { charger->regmap_fields[i] = devm_regmap_field_alloc(dev, - charger->regmap, mp2629_reg_fields[i]); + charger->regmap, + charger->chip_info->rfields[i]); if (IS_ERR(charger->regmap_fields[i])) { dev_err(dev, "regmap field alloc fail %d\n", i); return PTR_ERR(charger->regmap_fields[i]); @@ -613,7 +765,16 @@ static int mp2629_charger_probe(struct platform_device *pdev) } psy_cfg.drv_data = charger; - psy_cfg.attr_grp = mp2629_charger_sysfs_groups; + + if (charger->chip_info->has_impedance && + charger->chip_info->has_fast_charge) { + psy_cfg.attr_grp = mp2xx_all_sysfs_groups; + } else if (charger->chip_info->has_impedance) { + psy_cfg.attr_grp = mp2xx_batt_imp_sysfs_groups; + } else if (charger->chip_info->has_fast_charge) { + psy_cfg.attr_grp = mp2xx_fast_charge_sysfs_groups; + } + charger->battery = devm_power_supply_register(dev, &mp2629_battery_desc, &psy_cfg); if (IS_ERR(charger->battery)) { -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v4 4/8] power: supply: Add support for mp2733 battery charger 2022-10-24 13:27 ` [PATCH v4 4/8] power: supply: Add support for mp2733 battery charger Saravanan Sekar @ 2022-10-28 14:06 ` Sebastian Reichel 0 siblings, 0 replies; 19+ messages in thread From: Sebastian Reichel @ 2022-10-28 14:06 UTC (permalink / raw) To: Saravanan Sekar Cc: lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko, linux-pm, devicetree, linux-iio [-- Attachment #1: Type: text/plain, Size: 11634 bytes --] Hi, On Mon, Oct 24, 2022 at 03:27:53PM +0200, Saravanan Sekar wrote: > mp2733 is updated version of mp2629 battery charge management > which supports USB fast-charge and higher range of input voltage. > > Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > --- Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> -- Sebastian > drivers/power/supply/mp2629_charger.c | 223 ++++++++++++++++++++++---- > 1 file changed, 192 insertions(+), 31 deletions(-) > > diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c > index bf9c27b463a8..9e4111aace4b 100644 > --- a/drivers/power/supply/mp2629_charger.c > +++ b/drivers/power/supply/mp2629_charger.c > @@ -30,12 +30,15 @@ > #define MP2629_REG_INTERRUPT 0x0b > #define MP2629_REG_STATUS 0x0c > #define MP2629_REG_FAULT 0x0d > +#define MP2629_REG_FAST_CHARGE 0x17 > > #define MP2629_MASK_INPUT_TYPE GENMASK(7, 5) > #define MP2629_MASK_CHARGE_TYPE GENMASK(4, 3) > #define MP2629_MASK_CHARGE_CTRL GENMASK(5, 4) > #define MP2629_MASK_WDOG_CTRL GENMASK(5, 4) > #define MP2629_MASK_IMPEDANCE GENMASK(7, 4) > +#define MP2733_MASK_FAST_CHARGE GENMASK(2, 1) > +#define MP2733_MASK_FAST_CHARGE_RESET BIT(0) > > #define MP2629_INPUTSOURCE_CHANGE GENMASK(7, 5) > #define MP2629_CHARGING_CHANGE GENMASK(4, 3) > @@ -62,6 +65,17 @@ enum mp2629_source_type { > MP2629_SOURCE_TYPE_OTG = 7, > }; > > +enum mp2733_source_type { > + MP2733_SOURCE_TYPE_NO_INPUT, > + MP2733_SOURCE_TYPE_NON_STD, > + MP2733_SOURCE_TYPE_APPLE_1p0, > + MP2733_SOURCE_TYPE_APPLE_2p1, > + MP2733_SOURCE_TYPE_APPLE_2p4, > + MP2733_SOURCE_TYPE_SDP, > + MP2733_SOURCE_TYPE_CDP, > + MP2733_SOURCE_TYPE_DCP, > +}; > + > enum mp2629_field { > INPUT_ILIM, > INPUT_VLIM, > @@ -72,11 +86,30 @@ enum mp2629_field { > MP2629_MAX_FIELD > }; > > +struct mp2629_prop { > + int reg; > + int mask; > + int min; > + int max; > + int step; > + int shift; > +}; > + > +struct mp2xx_chip_info { > + const struct reg_field *rfields; > + struct mp2629_prop *chip_props; > + bool has_impedance; > + bool has_fast_charge; > + > + int (*mp2xx_get_usb_type)(unsigned int rval); > +}; > + > struct mp2629_charger { > struct device *dev; > int status; > int fault; > > + const struct mp2xx_chip_info *chip_info; > struct regmap *regmap; > struct regmap_field *regmap_fields[MP2629_MAX_FIELD]; > struct mutex lock; > @@ -85,15 +118,6 @@ struct mp2629_charger { > struct iio_channel *iiochan[MP2629_ADC_CHAN_END]; > }; > > -struct mp2629_prop { > - int reg; > - int mask; > - int min; > - int max; > - int step; > - int shift; > -}; > - > static enum power_supply_usb_type mp2629_usb_types[] = { > POWER_SUPPLY_USB_TYPE_SDP, > POWER_SUPPLY_USB_TYPE_DCP, > @@ -126,7 +150,25 @@ static enum power_supply_property mp2629_charger_bat_props[] = { > POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, > }; > > -static struct mp2629_prop props[] = { > +static struct mp2629_prop mp2733_chip_props[] = { > + MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000), > + MP2629_PROPS(INPUT_VLIM, 3800000, 15200000, 100000), > + MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000), > + MP2629_PROPS(CHARGE_VLIM, 3400000, 4670000, 10000), > + MP2629_PROPS(PRECHARGE, 120000, 720000, 40000), > + MP2629_PROPS(TERM_CURRENT, 80000, 680000, 40000), > +}; > + > +static const struct reg_field mp2733_reg_fields[] = { > + [INPUT_ILIM] = REG_FIELD(MP2629_REG_INPUT_ILIM, 0, 5), > + [INPUT_VLIM] = REG_FIELD(MP2629_REG_INPUT_VLIM, 0, 6), > + [CHARGE_ILIM] = REG_FIELD(MP2629_REG_CHARGE_ILIM, 0, 6), > + [CHARGE_VLIM] = REG_FIELD(MP2629_REG_CHARGE_VLIM, 1, 7), > + [PRECHARGE] = REG_FIELD(MP2629_REG_PRECHARGE, 4, 7), > + [TERM_CURRENT] = REG_FIELD(MP2629_REG_TERM_CURRENT, 0, 3), > +}; > + > +static struct mp2629_prop mp2629_chip_props[] = { > MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000), > MP2629_PROPS(INPUT_VLIM, 3800000, 5300000, 100000), > MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000), > @@ -174,6 +216,7 @@ static int mp2629_get_prop(struct mp2629_charger *charger, > { > int ret; > unsigned int rval; > + struct mp2629_prop *props = charger->chip_info->chip_props; > > ret = regmap_field_read(charger->regmap_fields[fld], &rval); > if (ret) > @@ -189,6 +232,7 @@ static int mp2629_set_prop(struct mp2629_charger *charger, > const union power_supply_propval *val) > { > unsigned int rval; > + struct mp2629_prop *props = charger->chip_info->chip_props; > > if (val->intval < props[fld].min || val->intval > props[fld].max) > return -EINVAL; > @@ -311,6 +355,16 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, > default: > val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; > } > + > + if (charger->chip_info->has_fast_charge) { > + ret = regmap_read(charger->regmap, > + MP2629_REG_FAST_CHARGE, &rval); > + if (ret) > + break; > + > + if (rval & BIT(6)) > + val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; > + } > break; > > default: > @@ -344,6 +398,40 @@ static int mp2629_charger_battery_set_prop(struct power_supply *psy, > } > } > > +static int mp2733_get_usb_type(unsigned int rval) > +{ > + switch (rval) { > + case MP2733_SOURCE_TYPE_APPLE_1p0: > + case MP2733_SOURCE_TYPE_APPLE_2p1: > + case MP2733_SOURCE_TYPE_APPLE_2p4: > + return POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID; > + case MP2733_SOURCE_TYPE_SDP: > + return POWER_SUPPLY_USB_TYPE_SDP; > + case MP2733_SOURCE_TYPE_CDP: > + return POWER_SUPPLY_USB_TYPE_CDP; > + case MP2733_SOURCE_TYPE_DCP: > + return POWER_SUPPLY_USB_TYPE_DCP; > + default: > + return POWER_SUPPLY_USB_TYPE_UNKNOWN; > + } > +} > + > +static int mp2629_get_usb_type(unsigned int rval) > +{ > + switch (rval) { > + case MP2629_SOURCE_TYPE_SDP: > + return POWER_SUPPLY_USB_TYPE_SDP; > + case MP2629_SOURCE_TYPE_CDP: > + return POWER_SUPPLY_USB_TYPE_CDP; > + case MP2629_SOURCE_TYPE_DCP: > + return POWER_SUPPLY_USB_TYPE_DCP; > + case MP2629_SOURCE_TYPE_OTG: > + return POWER_SUPPLY_USB_TYPE_PD_DRP; > + default: > + return POWER_SUPPLY_USB_TYPE_UNKNOWN; > + } > +} > + > static int mp2629_charger_usb_get_prop(struct power_supply *psy, > enum power_supply_property psp, > union power_supply_propval *val) > @@ -367,23 +455,7 @@ static int mp2629_charger_usb_get_prop(struct power_supply *psy, > break; > > rval = (rval & MP2629_MASK_INPUT_TYPE) >> 5; > - switch (rval) { > - case MP2629_SOURCE_TYPE_SDP: > - val->intval = POWER_SUPPLY_USB_TYPE_SDP; > - break; > - case MP2629_SOURCE_TYPE_CDP: > - val->intval = POWER_SUPPLY_USB_TYPE_CDP; > - break; > - case MP2629_SOURCE_TYPE_DCP: > - val->intval = POWER_SUPPLY_USB_TYPE_DCP; > - break; > - case MP2629_SOURCE_TYPE_OTG: > - val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP; > - break; > - default: > - val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; > - break; > - } > + val->intval = charger->chip_info->mp2xx_get_usb_type(rval); > break; > > case POWER_SUPPLY_PROP_VOLTAGE_NOW: > @@ -550,11 +622,72 @@ static ssize_t batt_impedance_compensation_store(struct device *dev, > > static DEVICE_ATTR_RW(batt_impedance_compensation); > > -static struct attribute *mp2629_charger_sysfs_attrs[] = { > +static struct attribute *mp2xx_batt_imp_sysfs_attrs[] = { > + &dev_attr_batt_impedance_compensation.attr, > + NULL > +}; > +ATTRIBUTE_GROUPS(mp2xx_batt_imp_sysfs); > + > +static ssize_t usb_fast_charge_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + struct mp2629_charger *charger = dev_get_drvdata(dev->parent); > + unsigned int rval; > + int ret; > + > + ret = regmap_read(charger->regmap, MP2629_REG_INTERRUPT, &rval); > + if (ret) > + return ret; > + > + return sysfs_emit(buf, "USB DP %u:DM %u\n", !!(rval & BIT(2)), > + !!(rval & BIT(1))); > +} > + > +static ssize_t usb_fast_charge_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, > + size_t count) > +{ > + struct mp2629_charger *charger = dev_get_drvdata(dev->parent); > + unsigned int val; > + int ret; > + > + ret = kstrtouint(buf, 10, &val); > + if (ret) > + return ret; > + > + if (val > 3) > + return -ERANGE; > + > + ret = regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, > + MP2733_MASK_FAST_CHARGE, val << 1); > + if (ret) > + return ret; > + > + ret = regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, > + MP2733_MASK_FAST_CHARGE_RESET, > + MP2733_MASK_FAST_CHARGE_RESET); > + if (ret) > + return ret; > + > + return count; > +} > + > +static DEVICE_ATTR_RW(usb_fast_charge); > + > +static struct attribute *mp2xx_fast_charge_sysfs_attrs[] = { > + &dev_attr_usb_fast_charge.attr, > + NULL > +}; > +ATTRIBUTE_GROUPS(mp2xx_fast_charge_sysfs); > + > +static struct attribute *mp2xx_all_sysfs_attrs[] = { > + &dev_attr_usb_fast_charge.attr, > &dev_attr_batt_impedance_compensation.attr, > NULL > }; > -ATTRIBUTE_GROUPS(mp2629_charger_sysfs); > +ATTRIBUTE_GROUPS(mp2xx_all_sysfs); > > static void mp2629_charger_disable(void *data) > { > @@ -564,6 +697,23 @@ static void mp2629_charger_disable(void *data) > MP2629_MASK_CHARGE_CTRL, 0); > } > > +static const struct mp2xx_chip_info mp2xx_chip_info_tbl[] = { > + [CHIP_ID_MP2629] = { > + .rfields = mp2629_reg_fields, > + .chip_props = mp2629_chip_props, > + .has_impedance = 1, > + > + .mp2xx_get_usb_type = mp2629_get_usb_type, > + }, > + [CHIP_ID_MP2733] = { > + .rfields = mp2733_reg_fields, > + .chip_props = mp2733_chip_props, > + .has_fast_charge = 1, > + > + .mp2xx_get_usb_type = mp2733_get_usb_type, > + }, > +}; > + > static int mp2629_charger_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -578,6 +728,7 @@ static int mp2629_charger_probe(struct platform_device *pdev) > > charger->regmap = ddata->regmap; > charger->dev = dev; > + charger->chip_info = &mp2xx_chip_info_tbl[ddata->chip_id]; > platform_set_drvdata(pdev, charger); > > irq = platform_get_irq(to_platform_device(dev->parent), 0); > @@ -586,7 +737,8 @@ static int mp2629_charger_probe(struct platform_device *pdev) > > for (i = 0; i < MP2629_MAX_FIELD; i++) { > charger->regmap_fields[i] = devm_regmap_field_alloc(dev, > - charger->regmap, mp2629_reg_fields[i]); > + charger->regmap, > + charger->chip_info->rfields[i]); > if (IS_ERR(charger->regmap_fields[i])) { > dev_err(dev, "regmap field alloc fail %d\n", i); > return PTR_ERR(charger->regmap_fields[i]); > @@ -613,7 +765,16 @@ static int mp2629_charger_probe(struct platform_device *pdev) > } > > psy_cfg.drv_data = charger; > - psy_cfg.attr_grp = mp2629_charger_sysfs_groups; > + > + if (charger->chip_info->has_impedance && > + charger->chip_info->has_fast_charge) { > + psy_cfg.attr_grp = mp2xx_all_sysfs_groups; > + } else if (charger->chip_info->has_impedance) { > + psy_cfg.attr_grp = mp2xx_batt_imp_sysfs_groups; > + } else if (charger->chip_info->has_fast_charge) { > + psy_cfg.attr_grp = mp2xx_fast_charge_sysfs_groups; > + } > + > charger->battery = devm_power_supply_register(dev, > &mp2629_battery_desc, &psy_cfg); > if (IS_ERR(charger->battery)) { > -- > 2.32.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 5/8] power: supply: mp2629: Add USB fast charge settings 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar ` (3 preceding siblings ...) 2022-10-24 13:27 ` [PATCH v4 4/8] power: supply: Add support for mp2733 battery charger Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-28 14:07 ` Sebastian Reichel 2022-10-24 13:27 ` [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name Saravanan Sekar ` (2 subsequent siblings) 7 siblings, 1 reply; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar Allows the user to change the USB device fast charge setting to advertise host on enumeration helps to accelerate the charging cycle. Altering this value resets USB existing connection. Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> --- .../ABI/testing/sysfs-class-power-mp2629 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-power-mp2629 b/Documentation/ABI/testing/sysfs-class-power-mp2629 index 914d67caac0d..b386d02cb010 100644 --- a/Documentation/ABI/testing/sysfs-class-power-mp2629 +++ b/Documentation/ABI/testing/sysfs-class-power-mp2629 @@ -1,3 +1,19 @@ +What: /sys/class/power_supply/mp2629_battery/usb_fast_charge +Date: June 2022 +KernelVersion: 5.20 +Description: + Represents a USB device fast charge settings.Altering this + value resets USB existing connection + USB DP:DM[0:0] 0.6V : Hi-Z + USB DP:DM[0:1] 3.3V : 0.6V + USB DP:DM[1:0] 0.6V : 0.6V + USB DP:DM[1:1] 0.6V : 3.3V + + Access: Read, Write + + Valid values: Represented in bit DP & DM setting. Valid + range is [0, 3]. + What: /sys/class/power_supply/mp2629_battery/batt_impedance_compen Date: April 2020 KernelVersion: 5.7 -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v4 5/8] power: supply: mp2629: Add USB fast charge settings 2022-10-24 13:27 ` [PATCH v4 5/8] power: supply: mp2629: Add USB fast charge settings Saravanan Sekar @ 2022-10-28 14:07 ` Sebastian Reichel 0 siblings, 0 replies; 19+ messages in thread From: Sebastian Reichel @ 2022-10-28 14:07 UTC (permalink / raw) To: Saravanan Sekar Cc: lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko, linux-pm, devicetree, linux-iio [-- Attachment #1: Type: text/plain, Size: 1565 bytes --] Hi, On Mon, Oct 24, 2022 at 03:27:54PM +0200, Saravanan Sekar wrote: > Allows the user to change the USB device fast charge setting to advertise > host on enumeration helps to accelerate the charging cycle. Altering this > value resets USB existing connection. > > Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > --- Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> -- Sebastian > .../ABI/testing/sysfs-class-power-mp2629 | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-class-power-mp2629 b/Documentation/ABI/testing/sysfs-class-power-mp2629 > index 914d67caac0d..b386d02cb010 100644 > --- a/Documentation/ABI/testing/sysfs-class-power-mp2629 > +++ b/Documentation/ABI/testing/sysfs-class-power-mp2629 > @@ -1,3 +1,19 @@ > +What: /sys/class/power_supply/mp2629_battery/usb_fast_charge > +Date: June 2022 > +KernelVersion: 5.20 > +Description: > + Represents a USB device fast charge settings.Altering this > + value resets USB existing connection > + USB DP:DM[0:0] 0.6V : Hi-Z > + USB DP:DM[0:1] 3.3V : 0.6V > + USB DP:DM[1:0] 0.6V : 0.6V > + USB DP:DM[1:1] 0.6V : 3.3V > + > + Access: Read, Write > + > + Valid values: Represented in bit DP & DM setting. Valid > + range is [0, 3]. > + > What: /sys/class/power_supply/mp2629_battery/batt_impedance_compen > Date: April 2020 > KernelVersion: 5.7 > -- > 2.32.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar ` (4 preceding siblings ...) 2022-10-24 13:27 ` [PATCH v4 5/8] power: supply: mp2629: Add USB fast charge settings Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-24 13:49 ` Andy Shevchenko 2022-10-24 13:27 ` [PATCH v4 7/8] iio: adc: mp2629: fix potential array out of bound access Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 8/8] power: supply: fix wrong interpretation of register value Saravanan Sekar 7 siblings, 1 reply; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar The mfd cell devices name populated on sysfs entry is dynamically derived from an auto instance which introduced a regression. As a result mpc2629_charger driver failed to get adc channel because of iio consumer name mismatch with the sysfs. /sys/class/i2c-adapter/i2c-1/mp2629_adc.0.auto/ /sys/class/i2c-adapter/i2c-1/mp2629_charger.1.auto/ Fixes: 466a62d7642f(mfd: core: Make a best effort attempt to match devices) Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> --- drivers/mfd/mp2629.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mfd/mp2629.c b/drivers/mfd/mp2629.c index f59c97e70f83..57db0f5009b9 100644 --- a/drivers/mfd/mp2629.c +++ b/drivers/mfd/mp2629.c @@ -53,7 +53,7 @@ static int mp2629_probe(struct i2c_client *client) return PTR_ERR(ddata->regmap); } - ret = devm_mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, mp2629_cell, + ret = devm_mfd_add_devices(ddata->dev, PLATFORM_DEVID_NONE, mp2629_cell, ARRAY_SIZE(mp2629_cell), NULL, 0, NULL); if (ret) dev_err(ddata->dev, "Failed to register sub-devices %d\n", ret); -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name 2022-10-24 13:27 ` [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name Saravanan Sekar @ 2022-10-24 13:49 ` Andy Shevchenko 2022-10-24 14:02 ` saravanan sekar 0 siblings, 1 reply; 19+ messages in thread From: Andy Shevchenko @ 2022-10-24 13:49 UTC (permalink / raw) To: Saravanan Sekar Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: > > The mfd cell devices name populated on sysfs entry is dynamically derived > from an auto instance which introduced a regression. As a result > mpc2629_charger driver failed to get adc channel because of iio consumer > name mismatch with the sysfs. > > /sys/class/i2c-adapter/i2c-1/mp2629_adc.0.auto/ > /sys/class/i2c-adapter/i2c-1/mp2629_charger.1.auto/ > > Fixes: 466a62d7642f(mfd: core: Make a best effort attempt to match devices) Wrong Fixes tag format, moreover the fixes should be grouped at the beginning of the series, so it will be visible and splittable based on this property. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name 2022-10-24 13:49 ` Andy Shevchenko @ 2022-10-24 14:02 ` saravanan sekar 2022-10-28 14:05 ` Sebastian Reichel 0 siblings, 1 reply; 19+ messages in thread From: saravanan sekar @ 2022-10-24 14:02 UTC (permalink / raw) To: Andy Shevchenko Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On 24/10/22 15:49, Andy Shevchenko wrote: > On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: >> >> The mfd cell devices name populated on sysfs entry is dynamically derived >> from an auto instance which introduced a regression. As a result >> mpc2629_charger driver failed to get adc channel because of iio consumer >> name mismatch with the sysfs. >> >> /sys/class/i2c-adapter/i2c-1/mp2629_adc.0.auto/ >> /sys/class/i2c-adapter/i2c-1/mp2629_charger.1.auto/ >> >> Fixes: 466a62d7642f(mfd: core: Make a best effort attempt to match devices) > > Wrong Fixes tag format, moreover the fixes should be grouped at the > beginning of the series, so it will be visible and splittable based on > this property. Thanks for quick review Andy, I will correct fixes tag format and group all the fixes beginning of series in v5. Thanks, Saravanan ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name 2022-10-24 14:02 ` saravanan sekar @ 2022-10-28 14:05 ` Sebastian Reichel 0 siblings, 0 replies; 19+ messages in thread From: Sebastian Reichel @ 2022-10-28 14:05 UTC (permalink / raw) To: saravanan sekar Cc: Andy Shevchenko, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio [-- Attachment #1: Type: text/plain, Size: 1132 bytes --] Hi, On Mon, Oct 24, 2022 at 04:02:21PM +0200, saravanan sekar wrote: > On 24/10/22 15:49, Andy Shevchenko wrote: > > On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: > > > > > > The mfd cell devices name populated on sysfs entry is dynamically derived > > > from an auto instance which introduced a regression. As a result > > > mpc2629_charger driver failed to get adc channel because of iio consumer > > > name mismatch with the sysfs. > > > > > > /sys/class/i2c-adapter/i2c-1/mp2629_adc.0.auto/ > > > /sys/class/i2c-adapter/i2c-1/mp2629_charger.1.auto/ > > > > > > Fixes: 466a62d7642f(mfd: core: Make a best effort attempt to match devices) > > > > Wrong Fixes tag format, moreover the fixes should be grouped at the > > beginning of the series, so it will be visible and splittable based on > > this property. > > Thanks for quick review Andy, I will correct fixes tag format and group all > the fixes beginning of series in v5. > > Thanks, > Saravanan Also the patch subject has incorrect prefix. It should be "mfd:" instead of "power: supply:". -- Sebastian [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH v4 7/8] iio: adc: mp2629: fix potential array out of bound access 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar ` (5 preceding siblings ...) 2022-10-24 13:27 ` [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 8/8] power: supply: fix wrong interpretation of register value Saravanan Sekar 7 siblings, 0 replies; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar Add sentinel at end of maps to avoid potential array out of bound access in iio core. Fixes: 7abd9fb6468 ("iio: adc: mp2629: Add support for mp2629 ADC driver") Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> --- drivers/iio/adc/mp2629_adc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/mp2629_adc.c b/drivers/iio/adc/mp2629_adc.c index 0f297072b8aa..18290e176e1e 100644 --- a/drivers/iio/adc/mp2629_adc.c +++ b/drivers/iio/adc/mp2629_adc.c @@ -57,7 +57,8 @@ static struct iio_map mp2629_adc_maps[] = { MP2629_MAP(SYSTEM_VOLT, "system-volt"), MP2629_MAP(INPUT_VOLT, "input-volt"), MP2629_MAP(BATT_CURRENT, "batt-current"), - MP2629_MAP(INPUT_CURRENT, "input-current") + MP2629_MAP(INPUT_CURRENT, "input-current"), + { } }; static int mp2629_read_raw(struct iio_dev *indio_dev, -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH v4 8/8] power: supply: fix wrong interpretation of register value 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar ` (6 preceding siblings ...) 2022-10-24 13:27 ` [PATCH v4 7/8] iio: adc: mp2629: fix potential array out of bound access Saravanan Sekar @ 2022-10-24 13:27 ` Saravanan Sekar 2022-10-24 13:50 ` Andy Shevchenko 7 siblings, 1 reply; 19+ messages in thread From: Saravanan Sekar @ 2022-10-24 13:27 UTC (permalink / raw) To: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, andy.shevchenko Cc: linux-pm, devicetree, linux-iio, Saravanan Sekar fix wrong interpretation of bitwise as hex Signed-off-by: Saravanan Sekar <sravanhome@gmail.com> --- drivers/power/supply/mp2629_charger.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/mp2629_charger.c b/drivers/power/supply/mp2629_charger.c index 9e4111aace4b..2ff3729afc48 100644 --- a/drivers/power/supply/mp2629_charger.c +++ b/drivers/power/supply/mp2629_charger.c @@ -328,10 +328,10 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, val->intval = POWER_SUPPLY_STATUS_DISCHARGING; break; case 0x01: - case 0x10: + case 0x02: val->intval = POWER_SUPPLY_STATUS_CHARGING; break; - case 0x11: + case 0x03: val->intval = POWER_SUPPLY_STATUS_FULL; } break; @@ -349,7 +349,7 @@ static int mp2629_charger_battery_get_prop(struct power_supply *psy, case 0x01: val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; break; - case 0x10: + case 0x02: val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; break; default: -- 2.32.0 ^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH v4 8/8] power: supply: fix wrong interpretation of register value 2022-10-24 13:27 ` [PATCH v4 8/8] power: supply: fix wrong interpretation of register value Saravanan Sekar @ 2022-10-24 13:50 ` Andy Shevchenko 2022-10-24 13:50 ` Andy Shevchenko 0 siblings, 1 reply; 19+ messages in thread From: Andy Shevchenko @ 2022-10-24 13:50 UTC (permalink / raw) To: Saravanan Sekar Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: > > fix wrong interpretation of bitwise as hex Respect English grammar and punctuation. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v4 8/8] power: supply: fix wrong interpretation of register value 2022-10-24 13:50 ` Andy Shevchenko @ 2022-10-24 13:50 ` Andy Shevchenko 2022-10-24 14:07 ` saravanan sekar 0 siblings, 1 reply; 19+ messages in thread From: Andy Shevchenko @ 2022-10-24 13:50 UTC (permalink / raw) To: Saravanan Sekar Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On Mon, Oct 24, 2022 at 4:50 PM Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: > > > > fix wrong interpretation of bitwise as hex Maybe you can replace 0x with 0b instead? -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v4 8/8] power: supply: fix wrong interpretation of register value 2022-10-24 13:50 ` Andy Shevchenko @ 2022-10-24 14:07 ` saravanan sekar 2022-10-24 14:18 ` Andy Shevchenko 0 siblings, 1 reply; 19+ messages in thread From: saravanan sekar @ 2022-10-24 14:07 UTC (permalink / raw) To: Andy Shevchenko Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On 24/10/22 15:50, Andy Shevchenko wrote: > On Mon, Oct 24, 2022 at 4:50 PM Andy Shevchenko > <andy.shevchenko@gmail.com> wrote: >> On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: >>> >>> fix wrong interpretation of bitwise as hex > > Maybe you can replace 0x with 0b instead? > Ok, I consider to changes as "fix the register value interpretation as 0x instead of 0b" does it fits !! Thanks, Saravanan ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v4 8/8] power: supply: fix wrong interpretation of register value 2022-10-24 14:07 ` saravanan sekar @ 2022-10-24 14:18 ` Andy Shevchenko 2022-10-24 14:37 ` saravanan sekar 0 siblings, 1 reply; 19+ messages in thread From: Andy Shevchenko @ 2022-10-24 14:18 UTC (permalink / raw) To: saravanan sekar Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On Mon, Oct 24, 2022 at 5:07 PM saravanan sekar <sravanhome@gmail.com> wrote: > > On 24/10/22 15:50, Andy Shevchenko wrote: > > On Mon, Oct 24, 2022 at 4:50 PM Andy Shevchenko > > <andy.shevchenko@gmail.com> wrote: > >> On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: > >>> > >>> fix wrong interpretation of bitwise as hex > > > > Maybe you can replace 0x with 0b instead? > > > > Ok, I consider to changes as "fix the register value interpretation as > 0x instead of 0b" does it fits !! No, it doesn't because there is no evidence of 0b in use. I suggested to use 0b in the code (as the part of your change) instead of switching to hex. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH v4 8/8] power: supply: fix wrong interpretation of register value 2022-10-24 14:18 ` Andy Shevchenko @ 2022-10-24 14:37 ` saravanan sekar 0 siblings, 0 replies; 19+ messages in thread From: saravanan sekar @ 2022-10-24 14:37 UTC (permalink / raw) To: Andy Shevchenko Cc: sre, lee.jones, robh+dt, krzysztof.kozlowski+dt, jic23, lars, linux-pm, devicetree, linux-iio On 24/10/22 16:18, Andy Shevchenko wrote: > On Mon, Oct 24, 2022 at 5:07 PM saravanan sekar <sravanhome@gmail.com> wrote: >> >> On 24/10/22 15:50, Andy Shevchenko wrote: >>> On Mon, Oct 24, 2022 at 4:50 PM Andy Shevchenko >>> <andy.shevchenko@gmail.com> wrote: >>>> On Mon, Oct 24, 2022 at 4:28 PM Saravanan Sekar <sravanhome@gmail.com> wrote: >>>>> >>>>> fix wrong interpretation of bitwise as hex >>> >>> Maybe you can replace 0x with 0b instead? >>> >> >> Ok, I consider to changes as "fix the register value interpretation as >> 0x instead of 0b" does it fits !! > > No, it doesn't because there is no evidence of 0b in use. I suggested > to use 0b in the code (as the part of your change) instead of > switching to hex. > Ok, I guess re-phrase of commit message shall solve the conflict. I feel use of 0x in code is fine. I will edit the commit message as "fix the switch case to match the register values" Thanks, Saravanan ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2022-10-28 14:07 UTC | newest] Thread overview: 19+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-10-24 13:27 [PATCH v4 0/8] Add support for mp2733 battery charger Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 1/8] iio: adc: mp2629: fix wrong comparison of channel Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 2/8] mfd: mp2629: Add support for mps mp2733 battery charger Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 3/8] iio: adc: mp2629: restrict input voltage mask for mp2629 Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 4/8] power: supply: Add support for mp2733 battery charger Saravanan Sekar 2022-10-28 14:06 ` Sebastian Reichel 2022-10-24 13:27 ` [PATCH v4 5/8] power: supply: mp2629: Add USB fast charge settings Saravanan Sekar 2022-10-28 14:07 ` Sebastian Reichel 2022-10-24 13:27 ` [PATCH v4 6/8] power: supply: fix failed to get iio channel by device name Saravanan Sekar 2022-10-24 13:49 ` Andy Shevchenko 2022-10-24 14:02 ` saravanan sekar 2022-10-28 14:05 ` Sebastian Reichel 2022-10-24 13:27 ` [PATCH v4 7/8] iio: adc: mp2629: fix potential array out of bound access Saravanan Sekar 2022-10-24 13:27 ` [PATCH v4 8/8] power: supply: fix wrong interpretation of register value Saravanan Sekar 2022-10-24 13:50 ` Andy Shevchenko 2022-10-24 13:50 ` Andy Shevchenko 2022-10-24 14:07 ` saravanan sekar 2022-10-24 14:18 ` Andy Shevchenko 2022-10-24 14:37 ` saravanan sekar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).