Message ID | 20250610-pf1550-v5-0-ed0d9e3aaac7@savoirfairelinux.com |
---|---|
Headers | show |
Series | add support for pf1550 PMIC MFD-based drivers | expand |
On Tue, Jun 10, 2025 at 03:47:31PM -0400, Samuel Kayode wrote: > Add regulator support for the pf1550 PMIC. > > Signed-off-by: Samuel Kayode <samuel.kayode@savoirfairelinux.com> > --- > v5: > - Address Mark's feedback: > - Add comments to clarify difference in interrupts > - Issue warn event for _LS(low side) interrupt > - Validate maximum ramp_delay > v4: > - Address Mark's feedback: > - Use C++ comments for SPDX license > - Add portions copyright to reflect my update > - Validate ramp_delay > - Report overcurrent and temperature events > - Use platform_get_irq > v3: > - Drop duplicate include > - Drop unnecessary includes > - Accept lower case regulator names from devicetree > - Use virqs mapped in core MFD driver > v2: > - Add driver for regulator > --- > drivers/regulator/Kconfig | 9 + > drivers/regulator/Makefile | 1 + > drivers/regulator/pf1550-regulator.c | 366 +++++++++++++++++++++++++++++++++++ > 3 files changed, 376 insertions(+) > > diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig > index 6d8988387da4599633ca9bde2698b9711e34a245..de455887f9aeeada5546e44b8dc9d7ed041618a6 100644 > --- a/drivers/regulator/Kconfig > +++ b/drivers/regulator/Kconfig > @@ -1049,6 +1049,15 @@ config REGULATOR_PV88090 > Say y here to support the voltage regulators and convertors > on PV88090 > > +config REGULATOR_PF1550 > + tristate "NXP PF1550 regulator" > + depends on MFD_PF1550 > + help > + Say y here to select this option to enable the regulators on > + the PF1550 PMICs. > + This driver controls the PF1550 regulators via I2C bus. > + The regulators include three bucks and three ldos. > + > config REGULATOR_PWM > tristate "PWM voltage regulator" > depends on PWM > diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile > index c0bc7a0f4e67098c50ac3cf887ae95f46b2eac44..891174b511fc0653bac662c71659498122e8441f 100644 > --- a/drivers/regulator/Makefile > +++ b/drivers/regulator/Makefile > @@ -125,6 +125,7 @@ obj-$(CONFIG_REGULATOR_QCOM_USB_VBUS) += qcom_usb_vbus-regulator.o > obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o > obj-$(CONFIG_REGULATOR_PCA9450) += pca9450-regulator.o > obj-$(CONFIG_REGULATOR_PF9453) += pf9453-regulator.o > +obj-$(CONFIG_REGULATOR_PF1550) += pf1550-regulator.o > obj-$(CONFIG_REGULATOR_PF8X00) += pf8x00-regulator.o > obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o > obj-$(CONFIG_REGULATOR_PV88060) += pv88060-regulator.o > diff --git a/drivers/regulator/pf1550-regulator.c b/drivers/regulator/pf1550-regulator.c > new file mode 100644 > index 0000000000000000000000000000000000000000..54fdf28643d8376d87faa5d2c5a562593ba0c063 > --- /dev/null > +++ b/drivers/regulator/pf1550-regulator.c > @@ -0,0 +1,366 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// pf1550.c - regulator driver for the PF1550 > +// > +// Copyright (C) 2016 Freescale Semiconductor, Inc. > +// Robin Gong <yibin.gong@freescale.com> > +// > +// Portions Copyright (c) 2025 Savoir-faire Linux Inc. > +// Samuel Kayode <samuel.kayode@savoirfairelinux.com> > +// > +// This driver is based on pfuze100-regulator.c > +// > + > +#include <linux/err.h> > +#include <linux/interrupt.h> > +#include <linux/mfd/pf1550.h> > +#include <linux/module.h> > +#include <linux/platform_device.h> > +#include <linux/regulator/driver.h> > +#include <linux/regulator/machine.h> > + > +#define PF1550_REGULATOR_IRQ_NR 11 > +#define PF1550_MAX_REGULATOR 7 > + > +struct pf1550_desc { > + struct regulator_desc desc; > + unsigned char stby_reg; > + unsigned char stby_mask; > +}; > + > +struct pf1550_regulator_info { > + struct device *dev; > + const struct pf1550_dev *pf1550; > + struct pf1550_desc regulator_descs[PF1550_MAX_REGULATOR]; > + struct regulator_dev *rdevs[PF1550_MAX_REGULATOR]; > +}; > + > +static const int pf1550_sw12_volts[] = { > + 1100000, 1200000, 1350000, 1500000, 1800000, 2500000, 3000000, 3300000, > +}; > + > +static const int pf1550_ldo13_volts[] = { > + 750000, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, > + 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, > + 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, > + 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000, > +}; > + > +static int pf1550_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) > +{ > + int id = rdev_get_id(rdev); > + unsigned int ramp_bits = 0; > + int ret; > + > + if (id > PF1550_VREFDDR) > + return -EACCES; > + > + if (ramp_delay < 0 || ramp_delay > 6250) > + return -EINVAL; > + > + ramp_delay = 6250 / ramp_delay; > + ramp_bits = ramp_delay >> 1; > + > + ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg + 4, 0x10, > + ramp_bits << 4); > + if (ret < 0) > + dev_err(&rdev->dev, "ramp failed, err %d\n", ret); > + > + return ret; > +} > + > +static const struct regulator_ops pf1550_sw1_ops = { > + .list_voltage = regulator_list_voltage_table, > + .set_voltage_sel = regulator_set_voltage_sel_regmap, > + .get_voltage_sel = regulator_get_voltage_sel_regmap, > + .set_voltage_time_sel = regulator_set_voltage_time_sel, > + .set_ramp_delay = pf1550_set_ramp_delay, > +}; > + > +static const struct regulator_ops pf1550_sw2_ops = { > + .list_voltage = regulator_list_voltage_linear, > + .set_voltage_sel = regulator_set_voltage_sel_regmap, > + .get_voltage_sel = regulator_get_voltage_sel_regmap, > + .set_voltage_time_sel = regulator_set_voltage_time_sel, > + .set_ramp_delay = pf1550_set_ramp_delay, > +}; > + > +static const struct regulator_ops pf1550_ldo1_ops = { > + .enable = regulator_enable_regmap, > + .disable = regulator_disable_regmap, > + .is_enabled = regulator_is_enabled_regmap, > + .list_voltage = regulator_list_voltage_table, > + .map_voltage = regulator_map_voltage_ascend, > + .set_voltage_sel = regulator_set_voltage_sel_regmap, > + .get_voltage_sel = regulator_get_voltage_sel_regmap, > +}; > + > +static const struct regulator_ops pf1550_ldo2_ops = { > + .enable = regulator_enable_regmap, > + .disable = regulator_disable_regmap, > + .is_enabled = regulator_is_enabled_regmap, > + .list_voltage = regulator_list_voltage_linear, > + .set_voltage_sel = regulator_set_voltage_sel_regmap, > + .get_voltage_sel = regulator_get_voltage_sel_regmap, > +}; > + > +static const struct regulator_ops pf1550_fixed_ops = { > + .enable = regulator_enable_regmap, > + .disable = regulator_disable_regmap, > + .is_enabled = regulator_is_enabled_regmap, > + .list_voltage = regulator_list_voltage_linear, > +}; > + > +#define PF_VREF(_chip, match, _name, voltage) { \ > + .desc = { \ > + .name = #_name, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = of_match_ptr("regulators"), \ > + .n_voltages = 1, \ > + .ops = &pf1550_fixed_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = _chip ## _ ## _name, \ > + .owner = THIS_MODULE, \ > + .min_uV = (voltage), \ > + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ > + .enable_mask = 0x1, \ > + }, \ > + .stby_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ > + .stby_mask = 0x2, \ > +} > + > +#define PF_SW1(_chip, match, _name, mask, voltages) { \ > + .desc = { \ > + .name = #_name, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = of_match_ptr("regulators"), \ > + .n_voltages = ARRAY_SIZE(voltages), \ > + .ops = &pf1550_sw1_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = _chip ## _ ## _name, \ > + .owner = THIS_MODULE, \ > + .volt_table = voltages, \ > + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ > + .vsel_mask = (mask), \ > + }, \ > + .stby_reg = _chip ## _PMIC_REG_ ## _name ## _STBY_VOLT, \ > + .stby_mask = (mask), \ > +} > + > +#define PF_SW3(_chip, match, _name, min, max, mask, step) { \ > + .desc = { \ > + .name = #_name, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = of_match_ptr("regulators"), \ > + .n_voltages = ((max) - (min)) / (step) + 1, \ > + .ops = &pf1550_sw2_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = _chip ## _ ## _name, \ > + .owner = THIS_MODULE, \ > + .min_uV = (min), \ > + .uV_step = (step), \ > + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ > + .vsel_mask = (mask), \ > + }, \ > + .stby_reg = _chip ## _PMIC_REG_ ## _name ## _STBY_VOLT, \ > + .stby_mask = (mask), \ > +} > + > +#define PF_LDO1(_chip, match, _name, mask, voltages) { \ > + .desc = { \ > + .name = #_name, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = of_match_ptr("regulators"), \ > + .n_voltages = ARRAY_SIZE(voltages), \ > + .ops = &pf1550_ldo1_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = _chip ## _ ## _name, \ > + .owner = THIS_MODULE, \ > + .volt_table = voltages, \ > + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ > + .vsel_mask = (mask), \ > + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ > + .enable_mask = 0x1, \ > + }, \ > + .stby_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ > + .stby_mask = 0x2, \ > +} > + > +#define PF_LDO2(_chip, match, _name, mask, min, max, step) { \ > + .desc = { \ > + .name = #_name, \ > + .of_match = of_match_ptr(match), \ > + .regulators_node = of_match_ptr("regulators"), \ > + .n_voltages = ((max) - (min)) / (step) + 1, \ > + .ops = &pf1550_ldo2_ops, \ > + .type = REGULATOR_VOLTAGE, \ > + .id = _chip ## _ ## _name, \ > + .owner = THIS_MODULE, \ > + .min_uV = (min), \ > + .uV_step = (step), \ > + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ > + .vsel_mask = (mask), \ > + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ > + .enable_mask = 0x1, \ > + }, \ > + .stby_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ > + .stby_mask = 0x2, \ > +} > + > +static struct pf1550_desc pf1550_regulators[] = { > + PF_SW3(PF1550, "sw1", SW1, 600000, 1387500, 0x3f, 12500), > + PF_SW3(PF1550, "sw2", SW2, 600000, 1387500, 0x3f, 12500), > + PF_SW3(PF1550, "sw3", SW3, 1800000, 3300000, 0xf, 100000), > + PF_VREF(PF1550, "vrefddr", VREFDDR, 1200000), > + PF_LDO1(PF1550, "ldo1", LDO1, 0x1f, pf1550_ldo13_volts), > + PF_LDO2(PF1550, "ldo2", LDO2, 0xf, 1800000, 3300000, 100000), > + PF_LDO1(PF1550, "ldo3", LDO3, 0x1f, pf1550_ldo13_volts), > +}; > + > +static irqreturn_t pf1550_regulator_irq_handler(int irq, void *data) > +{ > + struct pf1550_regulator_info *info = data; > + struct device *dev = info->dev; > + struct platform_device *pdev = to_platform_device(dev); > + int i, irq_type = -1; > + unsigned int event; > + > + for (i = 0; i < PF1550_REGULATOR_IRQ_NR; i++) > + if (irq == platform_get_irq(pdev, i)) > + irq_type = i; > + > + switch (irq_type) { > + /* The _LS interrupts indicate over-current event. The _HS interrupts > + * which are more accurate and can detect catastrophic faults, issue > + * an error event. The current limit FAULT interrupt is similar to the > + * _HS' > + */ > + case PF1550_PMIC_IRQ_SW1_LS: > + case PF1550_PMIC_IRQ_SW2_LS: > + case PF1550_PMIC_IRQ_SW3_LS: > + event = REGULATOR_EVENT_OVER_CURRENT_WARN; > + for (i = 0; i < PF1550_MAX_REGULATOR; i++) > + if (!strcmp(rdev_get_name(info->rdevs[i]), "SW3")) > + regulator_notifier_call_chain(info->rdevs[i], > + event, NULL); > + break; > + case PF1550_PMIC_IRQ_SW1_HS: > + case PF1550_PMIC_IRQ_SW2_HS: > + case PF1550_PMIC_IRQ_SW3_HS: > + event = REGULATOR_EVENT_OVER_CURRENT; > + for (i = 0; i < PF1550_MAX_REGULATOR; i++) > + if (!strcmp(rdev_get_name(info->rdevs[i]), "SW3")) > + regulator_notifier_call_chain(info->rdevs[i], > + event, NULL); > + break; > + case PF1550_PMIC_IRQ_LDO1_FAULT: > + case PF1550_PMIC_IRQ_LDO2_FAULT: > + case PF1550_PMIC_IRQ_LDO3_FAULT: > + event = REGULATOR_EVENT_OVER_CURRENT; > + for (i = 0; i < PF1550_MAX_REGULATOR; i++) > + if (!strcmp(rdev_get_name(info->rdevs[i]), "LDO3")) > + regulator_notifier_call_chain(info->rdevs[i], > + event, NULL); > + break; > + case PF1550_PMIC_IRQ_TEMP_110: > + case PF1550_PMIC_IRQ_TEMP_125: > + event = REGULATOR_EVENT_OVER_TEMP; > + for (i = 0; i < PF1550_MAX_REGULATOR; i++) > + regulator_notifier_call_chain(info->rdevs[i], > + event, NULL); > + break; > + default: > + dev_err(dev, "regulator interrupt: irq %d occurred\n", > + irq_type); > + } > + > + return IRQ_HANDLED; > +} > + > +static int pf1550_regulator_probe(struct platform_device *pdev) > +{ > + const struct pf1550_dev *pf1550 = dev_get_drvdata(pdev->dev.parent); > + struct pf1550_regulator_info *info; > + int i, irq = -1, ret = 0; > + struct regulator_config config = { }; > + > + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); > + if (!info) > + return -ENOMEM; > + > + config.regmap = dev_get_regmap(pf1550->dev, NULL); > + if (!config.regmap) > + return dev_err_probe(&pdev->dev, -ENODEV, > + "failed to get parent regmap\n"); > + > + config.dev = pf1550->dev; > + config.regmap = pf1550->regmap; > + info->dev = &pdev->dev; > + info->pf1550 = pf1550; > + > + memcpy(info->regulator_descs, pf1550_regulators, > + sizeof(info->regulator_descs)); > + > + for (i = 0; i < ARRAY_SIZE(pf1550_regulators); i++) { > + struct regulator_desc *desc; > + unsigned int val; > + > + desc = &info->regulator_descs[i].desc; > + > + if (desc->id == PF1550_SW2) { > + pf1550_read_otp(info->pf1550, 0x1f, &val); I suggest don't export pf1550_read_otp() function, you can add a field at top pf1550_dev like 'dvs_enb', here just check if (pf1550->dvs_enb). Frank > + /* OTP_SW2_DVS_ENB == 1? */ > + if ((val & 0x8)) { > + desc->volt_table = pf1550_sw12_volts; > + desc->n_voltages = ARRAY_SIZE(pf1550_sw12_volts); > + desc->ops = &pf1550_sw1_ops; > + } > + } > + > + info->rdevs[i] = devm_regulator_register(&pdev->dev, desc, > + &config); > + if (IS_ERR(info->rdevs[i])) > + return dev_err_probe(&pdev->dev, > + PTR_ERR(info->rdevs[i]), > + "failed to initialize regulator-%d\n", > + i); > + } > + > + platform_set_drvdata(pdev, info); > + > + for (i = 0; i < PF1550_REGULATOR_IRQ_NR; i++) { > + irq = platform_get_irq(pdev, i); > + if (irq < 0) > + return irq; > + > + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, > + pf1550_regulator_irq_handler, > + IRQF_NO_SUSPEND, > + "pf1550-regulator", info); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, > + "failed: irq request (IRQ: %d)\n", > + i); > + } > + > + return 0; > +} > + > +static const struct platform_device_id pf1550_regulator_id[] = { > + { "pf1550-regulator", 0 }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(platform, pf1550_regulator_id); > + > +static struct platform_driver pf1550_regulator_driver = { > + .driver = { > + .name = "pf1550-regulator", > + }, > + .probe = pf1550_regulator_probe, > + .id_table = pf1550_regulator_id, > +}; > +module_platform_driver(pf1550_regulator_driver); > + > +MODULE_DESCRIPTION("NXP PF1550 regulator driver"); > +MODULE_AUTHOR("Robin Gong <yibin.gong@freescale.com>"); > +MODULE_LICENSE("GPL"); > > -- > 2.49.0 >
On Tue, Jun 10, 2025 at 03:47:33PM -0400, Samuel Kayode wrote: > Add support for the battery charger for pf1550 PMIC. > > Signed-off-by: Samuel Kayode <samuel.kayode@savoirfairelinux.com> > --- > v5: > - Drop lock for battery and charger delayed_work > - More conservative locking in vbus delayed_work > - Apply lock when setting power supply type during register initialization > v4: > - Finish handling of some interrupts in threaded irq handler > - Use platform_get_irq > v3: > - Use struct power_supply_get_battery_info to get constant charge > voltage if specified > - Use virqs mapped in MFD driver > v2: > - Address feedback from Enric Balletbo Serra > --- > drivers/power/supply/Kconfig | 11 + > drivers/power/supply/Makefile | 1 + > drivers/power/supply/pf1550-charger.c | 645 ++++++++++++++++++++++++++++++++++ > 3 files changed, 657 insertions(+) > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > index 79ddb006e2dad6bf96b71ed570a37c006b5f9433..6d0c872edac1f45da314632e671af1aeda4c87b8 100644 > --- a/drivers/power/supply/Kconfig > +++ b/drivers/power/supply/Kconfig > @@ -471,6 +471,17 @@ config CHARGER_88PM860X > help > Say Y here to enable charger for Marvell 88PM860x chip. > > +config CHARGER_PF1550 > + tristate "NXP PF1550 battery charger driver" > + depends on MFD_PF1550 > + help > + Say Y to enable support for the NXP PF1550 battery charger. > + The device is a single cell Li-Ion/Li-Polymer battery charger for > + portable application. > + > + This driver can also be built as a module. If so, the module will be > + called pf1550-charger. > + > config BATTERY_RX51 > tristate "Nokia RX-51 (N900) battery driver" > depends on TWL4030_MADC > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > index 4f5f8e3507f80da02812f0d08c2d81ddff0a272f..7f68380099c59dab71b73120150612a23e16a745 100644 > --- a/drivers/power/supply/Makefile > +++ b/drivers/power/supply/Makefile > @@ -64,6 +64,7 @@ obj-$(CONFIG_CHARGER_RT9467) += rt9467-charger.o > obj-$(CONFIG_CHARGER_RT9471) += rt9471.o > obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o > obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o > +obj-$(CONFIG_CHARGER_PF1550) += pf1550-charger.o > obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o > obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_fg.o ab8500_btemp.o ab8500_chargalg.o > obj-$(CONFIG_CHARGER_CPCAP) += cpcap-charger.o > diff --git a/drivers/power/supply/pf1550-charger.c b/drivers/power/supply/pf1550-charger.c > new file mode 100644 > index 0000000000000000000000000000000000000000..04da5bd115657980c8eac462a9c33a42f6b94be7 > --- /dev/null > +++ b/drivers/power/supply/pf1550-charger.c > @@ -0,0 +1,645 @@ > +// SPDX-License-Identifier: GPL-2.0 > +// > +// pf1550_charger.c - charger driver for the PF1550 > +// > +// Copyright (C) 2016 Freescale Semiconductor, Inc. > +// Robin Gong <yibin.gong@freescale.com> > +// > +// Portions Copyright (c) 2025 Savoir-faire Linux Inc. > +// Samuel Kayode <samuel.kayode@savoirfairelinux.com> > +// > + > +#include <linux/interrupt.h> > +#include <linux/mfd/pf1550.h> > +#include <linux/module.h> > +#include <linux/platform_device.h> > +#include <linux/power_supply.h> > + > +#define PF1550_CHARGER_NAME "pf1550-charger" > +#define PF1550_DEFAULT_CONSTANT_VOLT 4200000 > +#define PF1550_DEFAULT_MIN_SYSTEM_VOLT 3500000 > +#define PF1550_DEFAULT_THERMAL_TEMP 75 > +#define PF1550_CHARGER_IRQ_NR 5 > + > +static const char *pf1550_charger_model = "PF1550"; > +static const char *pf1550_charger_manufacturer = "NXP"; > + > +struct pf1550_charger { > + struct device *dev; > + const struct pf1550_dev *pf1550; > + struct power_supply *charger; > + struct power_supply_desc psy_desc; > + struct delayed_work vbus_sense_work; > + struct delayed_work chg_sense_work; > + struct delayed_work bat_sense_work; > + struct mutex mutex; > + > + u32 constant_volt; > + u32 min_system_volt; > + u32 thermal_regulation_temp; > +}; > + ... > + > +static void pf1550_chg_vbus_work(struct work_struct *work) > +{ > + struct pf1550_charger *chg = container_of(to_delayed_work(work), > + struct pf1550_charger, > + vbus_sense_work); > + unsigned int data; > + bool psy_changed = false; > + > + if (!chg->charger) > + return; > + > + if (regmap_read(chg->pf1550->regmap, PF1550_CHARG_REG_VBUS_SNS, &data)) { > + dev_err(chg->dev, "Read VBUS_SNS error.\n"); > + return; > + } > + > + mutex_lock(&chg->mutex); > + > + if (data & PF1550_VBUS_UVLO) { > + chg->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY; > + psy_changed = true; > + dev_dbg(chg->dev, "VBUS detached.\n"); > + } > + if (data & PF1550_VBUS_IN2SYS) > + dev_dbg(chg->dev, "VBUS_IN2SYS_SNS.\n"); > + if (data & PF1550_VBUS_OVLO) > + dev_dbg(chg->dev, "VBUS_OVLO_SNS.\n"); > + if (data & PF1550_VBUS_VALID) { > + chg->psy_desc.type = POWER_SUPPLY_TYPE_MAINS; > + psy_changed = true; > + dev_dbg(chg->dev, "VBUS attached.\n"); > + } > + > + mutex_unlock(&chg->mutex); not sure why need lock here, you just update chg->psy_desc.type? > + > + if (psy_changed) > + power_supply_changed(chg->charger); > +} > + > +static irqreturn_t pf1550_charger_irq_handler(int irq, void *data) > +{ > + struct pf1550_charger *chg = data; > + struct device *dev = chg->dev; > + struct platform_device *pdev = to_platform_device(dev); > + int i, irq_type = -1; > + > + for (i = 0; i < PF1550_CHARGER_IRQ_NR; i++) > + if (irq == platform_get_irq(pdev, i)) > + irq_type = i; > + > + switch (irq_type) { > + case PF1550_CHARG_IRQ_BAT2SOCI: > + dev_info(dev, "BAT to SYS Overcurrent interrupt.\n"); > + break; > + case PF1550_CHARG_IRQ_BATI: > + schedule_delayed_work(&chg->bat_sense_work, > + msecs_to_jiffies(10)); > + break; > + case PF1550_CHARG_IRQ_CHGI: > + schedule_delayed_work(&chg->chg_sense_work, > + msecs_to_jiffies(10)); > + break; > + case PF1550_CHARG_IRQ_VBUSI: > + schedule_delayed_work(&chg->vbus_sense_work, > + msecs_to_jiffies(10)); > + break; > + case PF1550_CHARG_IRQ_THMI: > + dev_info(dev, "Thermal interrupt.\n"); > + break; > + default: > + dev_err(dev, "unknown interrupt occurred.\n"); > + } > + > + return IRQ_HANDLED; > +} > + ... > + > +static int pf1550_charger_probe(struct platform_device *pdev) > +{ > + struct pf1550_charger *chg; > + struct power_supply_config psy_cfg = {}; > + const struct pf1550_dev *pf1550 = dev_get_drvdata(pdev->dev.parent); maintain reverise christmas tree order look little big better. > + int i, irq, ret; > + > + chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); > + if (!chg) > + return -ENOMEM; > + > + chg->dev = &pdev->dev; > + chg->pf1550 = pf1550; > + > + if (!chg->pf1550->regmap) > + return dev_err_probe(&pdev->dev, -ENODEV, > + "failed to get regmap\n"); > + > + platform_set_drvdata(pdev, chg); > + > + mutex_init(&chg->mutex); > + > + INIT_DELAYED_WORK(&chg->vbus_sense_work, pf1550_chg_vbus_work); > + INIT_DELAYED_WORK(&chg->chg_sense_work, pf1550_chg_chg_work); > + INIT_DELAYED_WORK(&chg->bat_sense_work, pf1550_chg_bat_work); > + > + for (i = 0; i < PF1550_CHARGER_IRQ_NR; i++) { > + irq = platform_get_irq(pdev, i); > + if (irq < 0) > + return irq; > + > + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, > + pf1550_charger_irq_handler, > + IRQF_NO_SUSPEND, > + "pf1550-charger", chg); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, > + "failed irq request\n"); > + } > + > + psy_cfg.drv_data = chg; > + > + chg->psy_desc.name = PF1550_CHARGER_NAME; > + chg->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY; > + chg->psy_desc.get_property = pf1550_charger_get_property; > + chg->psy_desc.properties = pf1550_charger_props; > + chg->psy_desc.num_properties = ARRAY_SIZE(pf1550_charger_props); > + > + chg->charger = devm_power_supply_register(&pdev->dev, &chg->psy_desc, > + &psy_cfg); > + if (IS_ERR(chg->charger)) > + return dev_err_probe(&pdev->dev, PTR_ERR(chg->charger), > + "failed: power supply register\n"); > + > + pf1550_dt_parse_dev_info(chg); > + > + ret = pf1550_reg_init(chg); > + > + return ret; return pf1550_reg_init(chg); Frank > +} > + > +static void pf1550_charger_remove(struct platform_device *pdev) > +{ > + struct pf1550_charger *chg = platform_get_drvdata(pdev); > + > + cancel_delayed_work_sync(&chg->bat_sense_work); > + cancel_delayed_work_sync(&chg->chg_sense_work); > + cancel_delayed_work_sync(&chg->vbus_sense_work); > +} > + > +static const struct platform_device_id pf1550_charger_id[] = { > + { "pf1550-charger", 0 }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(platform, pf1550_charger_id); > + > +static struct platform_driver pf1550_charger_driver = { > + .driver = { > + .name = "pf1550-charger", > + }, > + .probe = pf1550_charger_probe, > + .remove = pf1550_charger_remove, > + .id_table = pf1550_charger_id, > +}; > +module_platform_driver(pf1550_charger_driver); > + > +MODULE_AUTHOR("Robin Gong <yibin.gong@freescale.com>"); > +MODULE_DESCRIPTION("PF1550 charger driver"); > +MODULE_LICENSE("GPL"); > > -- > 2.49.0 >
On Tue, Jun 10, 2025 at 03:47:31PM -0400, Samuel Kayode via B4 Relay wrote: > From: Samuel Kayode <samuel.kayode@savoirfairelinux.com> > > Add regulator support for the pf1550 PMIC. Reviewed-by: Mark Brown <broonie@kernel.org>
On Tue, Jun 10, 2025 at 05:11:31PM -0400, Frank Li wrote: > > +static void pf1550_chg_vbus_work(struct work_struct *work) > > +{ > > + struct pf1550_charger *chg = container_of(to_delayed_work(work), > > + struct pf1550_charger, > > + vbus_sense_work); > > + unsigned int data; > > + bool psy_changed = false; > > + > > + if (!chg->charger) > > + return; > > + > > + if (regmap_read(chg->pf1550->regmap, PF1550_CHARG_REG_VBUS_SNS, &data)) { > > + dev_err(chg->dev, "Read VBUS_SNS error.\n"); > > + return; > > + } > > + > > + mutex_lock(&chg->mutex); > > + > > + if (data & PF1550_VBUS_UVLO) { > > + chg->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY; > > + psy_changed = true; > > + dev_dbg(chg->dev, "VBUS detached.\n"); > > + } > > + if (data & PF1550_VBUS_IN2SYS) > > + dev_dbg(chg->dev, "VBUS_IN2SYS_SNS.\n"); > > + if (data & PF1550_VBUS_OVLO) > > + dev_dbg(chg->dev, "VBUS_OVLO_SNS.\n"); > > + if (data & PF1550_VBUS_VALID) { > > + chg->psy_desc.type = POWER_SUPPLY_TYPE_MAINS; > > + psy_changed = true; > > + dev_dbg(chg->dev, "VBUS attached.\n"); > > + } > > + > > + mutex_unlock(&chg->mutex); > > not sure why need lock here, you just update chg->psy_desc.type? > It prevents concurrent access in this delayed work and in pf1550_reg_init. However, it's unlikely that the probe is still active during the first execution of the delayed work. So, i also think this mutex can be removed. > > + > > + if (psy_changed) > > + power_supply_changed(chg->charger); > > +} > > + > > +static irqreturn_t pf1550_charger_irq_handler(int irq, void *data) > > +{ > > + struct pf1550_charger *chg = data; > > + struct device *dev = chg->dev; > > + struct platform_device *pdev = to_platform_device(dev); > > + int i, irq_type = -1; > > + > > + for (i = 0; i < PF1550_CHARGER_IRQ_NR; i++) > > + if (irq == platform_get_irq(pdev, i)) > > + irq_type = i; > > + > > + switch (irq_type) { > > + case PF1550_CHARG_IRQ_BAT2SOCI: > > + dev_info(dev, "BAT to SYS Overcurrent interrupt.\n"); > > + break; > > + case PF1550_CHARG_IRQ_BATI: > > + schedule_delayed_work(&chg->bat_sense_work, > > + msecs_to_jiffies(10)); > > + break; > > + case PF1550_CHARG_IRQ_CHGI: > > + schedule_delayed_work(&chg->chg_sense_work, > > + msecs_to_jiffies(10)); > > + break; > > + case PF1550_CHARG_IRQ_VBUSI: > > + schedule_delayed_work(&chg->vbus_sense_work, > > + msecs_to_jiffies(10)); > > + break; > > + case PF1550_CHARG_IRQ_THMI: > > + dev_info(dev, "Thermal interrupt.\n"); > > + break; > > + default: > > + dev_err(dev, "unknown interrupt occurred.\n"); > > + } > > + > > + return IRQ_HANDLED; > > +} > > + > > +static int pf1550_charger_probe(struct platform_device *pdev) > > + mutex_init(&chg->mutex); ... > > + > > + INIT_DELAYED_WORK(&chg->vbus_sense_work, pf1550_chg_vbus_work); > > + INIT_DELAYED_WORK(&chg->chg_sense_work, pf1550_chg_chg_work); > > + INIT_DELAYED_WORK(&chg->bat_sense_work, pf1550_chg_bat_work); ... > > + ret = pf1550_reg_init(chg); Thanks, Sam
This series adds support for pf1550 PMIC. It provides the core mfd driver and a set of three sub-drivers for the regulator, power supply and input subsystems. Patch 1 adds the DT binding document for the PMIC. Patches 2-5 adds the pertinent drivers. Last patch adds a MAINTAINERS entry for the drivers. Changes since v1: - DT bindings for all devices included - Add onkey driver - Add driver for the regulators - Ensure charger is activated as some variants have it off by default - Update mfd and charger driver per feedback from eballetbo@gmail.com - Add myself as maintainer for these drivers - Link to v1: https://lore.kernel.org/1523974819-8711-1-git-send-email-abel.vesa@nxp.com/ Changes since v2: - Rebase on recent mainline kernel v6.15 - Single yaml file containing dt bindings for all pf1550 devices - irq mapping done in MFD driver as suggested by Dmitry Torokhov - Drop unnecessary includes in drivers - Replace dev_err with dev_err_probe in probe method of drivers - Drop compatible string from drivers of the sub-devices - Remove dependency on OF from drivers of the sub-devices - onkey: move driver from input/keyboard into input/misc - onkey: remove dependency on OF - onkey: use onkey virqs instead of central irq - onkey: fix integer overflow for regmap_write when unmasking interrupts during pf1550_onkey_resume - charger: add support for monitored-battery which is used in setting a constant voltage for the charger. - Address other feedback from Dmitry Torokhov and Krzysztof Kozlowski - Link to v2: https://lore.kernel.org/cover.1747409892.git.samuel.kayode@savoirfairelinux.com/ Changes since v3: - Update manufacturer from Freescale to NXP in compatible, dt-binding and Kconfigs - Use C++ style comments for SPDX license in .c code - Add portions copyright to source code - irqs are defined as struct resource in mfd cell such that platform_get_irq is used in the sub-devices - Make struct pf1550_dev of type const in sub-device driver - irq variable dropped from sub-device driver struct - EXPORT_SYMBOL of global pf1550_read_otp function for use in regulator driver - Drop unneeded info in driver_data when defining device table id - regulator: validate ramp_delay - regulator: report overcurrent and over temperature events - onkey: drop unnecessary keycode variable - onkey: change wakeup variable to type bool - onkey: replace (error < 0) with error in if statement when possible - onkey: use pm_sleep_ptr when defining driver.pm - charger: finish handling of some interrupts in threaded irq handler - Link to v3: https://lore.kernel.org/20250527-pf1550-v3-0-45f69453cd51@savoirfairelinux.com/ Changes since v4: - Use top level interrupt to minimize number of registers checked on each interrupt - Fix bad offset for temperature interrupts of regulator irq chip - Address Krzysztof's comments for dt-binding - regulator: add comments to clarify difference in its interrupts - regulator: issue warn event for _LS interrupt and error event for _HS interrupt - regulator: validate maximum and minimum ramp_delay - charger: drop lock in battery and charger delayed_work - charger: more conservative locking for vbus delayed_work - charger: apply lock when setting power_supply type during register intialization - Link to v4: https://lore.kernel.org/r/20250603-pf1550-v4-0-bfdf51ee59cc@savoirfairelinux.com Signed-off-by: Samuel Kayode <samuel.kayode@savoirfairelinux.com> --- Samuel Kayode (6): dt-bindings: mfd: add pf1550 mfd: pf1550: add core mfd driver regulator: pf1550: add support for regulator input: pf1550: add onkey support power: supply: pf1550: add battery charger support MAINTAINERS: add an entry for pf1550 mfd driver .../devicetree/bindings/mfd/nxp,pf1550.yaml | 137 +++++ MAINTAINERS | 10 + drivers/input/misc/Kconfig | 11 + drivers/input/misc/Makefile | 1 + drivers/input/misc/pf1550-onkey.c | 183 ++++++ drivers/mfd/Kconfig | 14 + drivers/mfd/Makefile | 2 + drivers/mfd/pf1550.c | 335 +++++++++++ drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + drivers/power/supply/pf1550-charger.c | 645 +++++++++++++++++++++ drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/pf1550-regulator.c | 366 ++++++++++++ include/linux/mfd/pf1550.h | 259 +++++++++ 15 files changed, 1985 insertions(+) --- base-commit: 0a4b866d08c6adaea2f4592d31edac6deeb4dcbd change-id: 20250527-pf1550-d401f0d07b80 Best regards,