Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: Use container_of_const() when all types are

Merge series from Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>:

Use container_of_const(), which is preferred over container_of(), when
the argument 'ptr' and returned pointer are already const, for better
code safety and readability.

Some drivers already have const everywhere, so container_of_const can be
directly used. In few other drivers, the final pointer can be constified
that way.

+2168 -35
+161
Documentation/devicetree/bindings/mfd/nxp,pf1550.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mfd/nxp,pf1550.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NXP PF1550 Power Management IC 8 + 9 + maintainers: 10 + - Samuel Kayode <samuel.kayode@savoirfairelinux.com> 11 + 12 + description: 13 + PF1550 PMIC provides battery charging and power supply for low power IoT and 14 + wearable applications. This device consists of an i2c controlled MFD that 15 + includes regulators, battery charging and an onkey/power button. 16 + 17 + $ref: /schemas/power/supply/power-supply.yaml 18 + 19 + properties: 20 + compatible: 21 + const: nxp,pf1550 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + wakeup-source: true 30 + 31 + regulators: 32 + type: object 33 + additionalProperties: false 34 + 35 + patternProperties: 36 + "^(ldo[1-3]|sw[1-3]|vrefddr)$": 37 + type: object 38 + $ref: /schemas/regulator/regulator.yaml 39 + description: 40 + regulator configuration for ldo1-3, buck converters(sw1-3) 41 + and DDR termination reference voltage (vrefddr) 42 + unevaluatedProperties: false 43 + 44 + monitored-battery: 45 + description: | 46 + A phandle to a monitored battery node that contains a valid value 47 + for: 48 + constant-charge-voltage-max-microvolt. 49 + 50 + nxp,thermal-regulation-celsius: 51 + description: 52 + Temperature threshold for thermal regulation of charger in celsius. 53 + enum: [ 80, 95, 110, 125 ] 54 + 55 + nxp,min-system-microvolt: 56 + description: 57 + System specific lower limit voltage. 58 + enum: [ 3500000, 3700000, 4300000 ] 59 + 60 + nxp,disable-key-power: 61 + type: boolean 62 + description: 63 + Disable power-down using a long key-press. The onkey driver will remove 64 + support for the KEY_POWER key press when triggered using a long press of 65 + the onkey. 66 + 67 + required: 68 + - compatible 69 + - reg 70 + - interrupts 71 + 72 + unevaluatedProperties: false 73 + 74 + examples: 75 + - | 76 + #include <dt-bindings/interrupt-controller/irq.h> 77 + #include <dt-bindings/input/linux-event-codes.h> 78 + 79 + battery: battery-cell { 80 + compatible = "simple-battery"; 81 + constant-charge-voltage-max-microvolt = <4400000>; 82 + }; 83 + 84 + i2c { 85 + #address-cells = <1>; 86 + #size-cells = <0>; 87 + 88 + pmic@8 { 89 + compatible = "nxp,pf1550"; 90 + reg = <0x8>; 91 + 92 + interrupt-parent = <&gpio1>; 93 + interrupts = <2 IRQ_TYPE_LEVEL_LOW>; 94 + wakeup-source; 95 + monitored-battery = <&battery>; 96 + nxp,min-system-microvolt = <4300000>; 97 + nxp,thermal-regulation-celsius = <80>; 98 + 99 + regulators { 100 + sw1_reg: sw1 { 101 + regulator-name = "sw1"; 102 + regulator-min-microvolt = <600000>; 103 + regulator-max-microvolt = <1387500>; 104 + regulator-always-on; 105 + regulator-ramp-delay = <6250>; 106 + 107 + regulator-state-mem { 108 + regulator-on-in-suspend; 109 + regulator-suspend-min-microvolt = <1270000>; 110 + }; 111 + }; 112 + 113 + sw2_reg: sw2 { 114 + regulator-name = "sw2"; 115 + regulator-min-microvolt = <600000>; 116 + regulator-max-microvolt = <1387500>; 117 + regulator-always-on; 118 + 119 + regulator-state-mem { 120 + regulator-on-in-suspend; 121 + }; 122 + }; 123 + 124 + sw3_reg: sw3 { 125 + regulator-name = "sw3"; 126 + regulator-min-microvolt = <1800000>; 127 + regulator-max-microvolt = <3300000>; 128 + regulator-always-on; 129 + 130 + regulator-state-mem { 131 + regulator-on-in-suspend; 132 + }; 133 + }; 134 + 135 + vldo1_reg: ldo1 { 136 + regulator-name = "ldo1"; 137 + regulator-min-microvolt = <750000>; 138 + regulator-max-microvolt = <3300000>; 139 + regulator-always-on; 140 + 141 + regulator-state-mem { 142 + regulator-off-in-suspend; 143 + }; 144 + }; 145 + 146 + vldo2_reg: ldo2 { 147 + regulator-name = "ldo2"; 148 + regulator-min-microvolt = <1800000>; 149 + regulator-max-microvolt = <3300000>; 150 + regulator-always-on; 151 + }; 152 + 153 + vldo3_reg: ldo3 { 154 + regulator-name = "ldo3"; 155 + regulator-min-microvolt = <750000>; 156 + regulator-max-microvolt = <3300000>; 157 + regulator-always-on; 158 + }; 159 + }; 160 + }; 161 + };
+11
MAINTAINERS
··· 18636 18636 F: Documentation/devicetree/bindings/regulator/nxp,pf5300.yaml 18637 18637 F: drivers/regulator/pf530x-regulator.c 18638 18638 18639 + NXP PF1550 PMIC MFD DRIVER 18640 + M: Samuel Kayode <samuel.kayode@savoirfairelinux.com> 18641 + L: imx@lists.linux.dev 18642 + S: Maintained 18643 + F: Documentation/devicetree/bindings/mfd/nxp,pf1550.yaml 18644 + F: drivers/input/misc/pf1550-onkey.c 18645 + F: drivers/mfd/pf1550.c 18646 + F: drivers/power/supply/pf1550-charger.c 18647 + F: drivers/regulator/pf1550-regulator.c 18648 + F: include/linux/mfd/pfd1550.h 18649 + 18639 18650 NXP PF8100/PF8121A/PF8200 PMIC REGULATOR DEVICE DRIVER 18640 18651 M: Jagan Teki <jagan@amarulasolutions.com> 18641 18652 S: Maintained
+11
drivers/input/misc/Kconfig
··· 190 190 To compile this driver as a module, choose M here: the 191 191 module will be called pcspkr. 192 192 193 + config INPUT_PF1550_ONKEY 194 + tristate "NXP PF1550 Onkey support" 195 + depends on MFD_PF1550 196 + help 197 + Say Y here if you want support for PF1550 PMIC. Onkey can trigger 198 + release and 1s(push hold), 2s, 3s, 4s, 8s interrupt for long press 199 + detect. 200 + 201 + To compile this driver as a module, choose M here. The module will be 202 + called pf1550-onkey. 203 + 193 204 config INPUT_PM8941_PWRKEY 194 205 tristate "Qualcomm PM8941 power key support" 195 206 depends on MFD_SPMI_PMIC
+1
drivers/input/misc/Makefile
··· 63 63 obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o 64 64 obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o 65 65 obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o 66 + obj-$(CONFIG_INPUT_PF1550_ONKEY) += pf1550-onkey.o 66 67 obj-$(CONFIG_INPUT_PM8941_PWRKEY) += pm8941-pwrkey.o 67 68 obj-$(CONFIG_INPUT_PM8XXX_VIBRATOR) += pm8xxx-vibrator.o 68 69 obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += pmic8xxx-pwrkey.o
+197
drivers/input/misc/pf1550-onkey.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Driver for the PF1550 ONKEY 4 + * Copyright (C) 2016 Freescale Semiconductor, Inc. All Rights Reserved. 5 + * 6 + * Portions Copyright (c) 2025 Savoir-faire Linux Inc. 7 + * Samuel Kayode <samuel.kayode@savoirfairelinux.com> 8 + */ 9 + 10 + #include <linux/err.h> 11 + #include <linux/input.h> 12 + #include <linux/interrupt.h> 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/mfd/pf1550.h> 16 + #include <linux/platform_device.h> 17 + 18 + #define PF1550_ONKEY_IRQ_NR 6 19 + 20 + struct onkey_drv_data { 21 + struct device *dev; 22 + const struct pf1550_ddata *pf1550; 23 + bool wakeup; 24 + struct input_dev *input; 25 + }; 26 + 27 + static irqreturn_t pf1550_onkey_irq_handler(int irq, void *data) 28 + { 29 + struct onkey_drv_data *onkey = data; 30 + struct platform_device *pdev = to_platform_device(onkey->dev); 31 + int i, state, irq_type = -1; 32 + 33 + for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) 34 + if (irq == platform_get_irq(pdev, i)) 35 + irq_type = i; 36 + 37 + switch (irq_type) { 38 + case PF1550_ONKEY_IRQ_PUSHI: 39 + state = 0; 40 + break; 41 + case PF1550_ONKEY_IRQ_1SI: 42 + case PF1550_ONKEY_IRQ_2SI: 43 + case PF1550_ONKEY_IRQ_3SI: 44 + case PF1550_ONKEY_IRQ_4SI: 45 + case PF1550_ONKEY_IRQ_8SI: 46 + state = 1; 47 + break; 48 + default: 49 + dev_err(onkey->dev, "onkey interrupt: irq %d occurred\n", 50 + irq_type); 51 + return IRQ_HANDLED; 52 + } 53 + 54 + input_event(onkey->input, EV_KEY, KEY_POWER, state); 55 + input_sync(onkey->input); 56 + 57 + return IRQ_HANDLED; 58 + } 59 + 60 + static int pf1550_onkey_probe(struct platform_device *pdev) 61 + { 62 + struct onkey_drv_data *onkey; 63 + struct input_dev *input; 64 + bool key_power = false; 65 + int i, irq, error; 66 + 67 + onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL); 68 + if (!onkey) 69 + return -ENOMEM; 70 + 71 + onkey->dev = &pdev->dev; 72 + 73 + onkey->pf1550 = dev_get_drvdata(pdev->dev.parent); 74 + if (!onkey->pf1550->regmap) 75 + return dev_err_probe(&pdev->dev, -ENODEV, 76 + "failed to get regmap\n"); 77 + 78 + onkey->wakeup = device_property_read_bool(pdev->dev.parent, 79 + "wakeup-source"); 80 + 81 + if (device_property_read_bool(pdev->dev.parent, 82 + "nxp,disable-key-power")) { 83 + error = regmap_clear_bits(onkey->pf1550->regmap, 84 + PF1550_PMIC_REG_PWRCTRL1, 85 + PF1550_ONKEY_RST_EN); 86 + if (error) 87 + return dev_err_probe(&pdev->dev, error, 88 + "failed: disable turn system off"); 89 + } else { 90 + key_power = true; 91 + } 92 + 93 + input = devm_input_allocate_device(&pdev->dev); 94 + if (!input) 95 + return dev_err_probe(&pdev->dev, -ENOMEM, 96 + "failed to allocate the input device\n"); 97 + 98 + input->name = pdev->name; 99 + input->phys = "pf1550-onkey/input0"; 100 + input->id.bustype = BUS_HOST; 101 + 102 + if (key_power) 103 + input_set_capability(input, EV_KEY, KEY_POWER); 104 + 105 + onkey->input = input; 106 + platform_set_drvdata(pdev, onkey); 107 + 108 + for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) { 109 + irq = platform_get_irq(pdev, i); 110 + if (irq < 0) 111 + return irq; 112 + 113 + error = devm_request_threaded_irq(&pdev->dev, irq, NULL, 114 + pf1550_onkey_irq_handler, 115 + IRQF_NO_SUSPEND, 116 + "pf1550-onkey", onkey); 117 + if (error) 118 + return dev_err_probe(&pdev->dev, error, 119 + "failed: irq request (IRQ: %d)\n", 120 + i); 121 + } 122 + 123 + error = input_register_device(input); 124 + if (error) 125 + return dev_err_probe(&pdev->dev, error, 126 + "failed to register input device\n"); 127 + 128 + device_init_wakeup(&pdev->dev, onkey->wakeup); 129 + 130 + return 0; 131 + } 132 + 133 + static int pf1550_onkey_suspend(struct device *dev) 134 + { 135 + struct platform_device *pdev = to_platform_device(dev); 136 + struct onkey_drv_data *onkey = platform_get_drvdata(pdev); 137 + int i, irq; 138 + 139 + if (!device_may_wakeup(&pdev->dev)) 140 + regmap_write(onkey->pf1550->regmap, 141 + PF1550_PMIC_REG_ONKEY_INT_MASK0, 142 + ONKEY_IRQ_PUSHI | ONKEY_IRQ_1SI | ONKEY_IRQ_2SI | 143 + ONKEY_IRQ_3SI | ONKEY_IRQ_4SI | ONKEY_IRQ_8SI); 144 + else 145 + for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) { 146 + irq = platform_get_irq(pdev, i); 147 + if (irq > 0) 148 + enable_irq_wake(irq); 149 + } 150 + 151 + return 0; 152 + } 153 + 154 + static int pf1550_onkey_resume(struct device *dev) 155 + { 156 + struct platform_device *pdev = to_platform_device(dev); 157 + struct onkey_drv_data *onkey = platform_get_drvdata(pdev); 158 + int i, irq; 159 + 160 + if (!device_may_wakeup(&pdev->dev)) 161 + regmap_write(onkey->pf1550->regmap, 162 + PF1550_PMIC_REG_ONKEY_INT_MASK0, 163 + ~((u8)(ONKEY_IRQ_PUSHI | ONKEY_IRQ_1SI | 164 + ONKEY_IRQ_2SI | ONKEY_IRQ_3SI | ONKEY_IRQ_4SI | 165 + ONKEY_IRQ_8SI))); 166 + else 167 + for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) { 168 + irq = platform_get_irq(pdev, i); 169 + if (irq > 0) 170 + disable_irq_wake(irq); 171 + } 172 + 173 + return 0; 174 + } 175 + 176 + static SIMPLE_DEV_PM_OPS(pf1550_onkey_pm_ops, pf1550_onkey_suspend, 177 + pf1550_onkey_resume); 178 + 179 + static const struct platform_device_id pf1550_onkey_id[] = { 180 + { "pf1550-onkey", }, 181 + { /* sentinel */ } 182 + }; 183 + MODULE_DEVICE_TABLE(platform, pf1550_onkey_id); 184 + 185 + static struct platform_driver pf1550_onkey_driver = { 186 + .driver = { 187 + .name = "pf1550-onkey", 188 + .pm = pm_sleep_ptr(&pf1550_onkey_pm_ops), 189 + }, 190 + .probe = pf1550_onkey_probe, 191 + .id_table = pf1550_onkey_id, 192 + }; 193 + module_platform_driver(pf1550_onkey_driver); 194 + 195 + MODULE_AUTHOR("Freescale Semiconductor"); 196 + MODULE_DESCRIPTION("PF1550 onkey Driver"); 197 + MODULE_LICENSE("GPL");
+16
drivers/mfd/Kconfig
··· 605 605 i.MX25 processors. They consist of a conversion queue for general 606 606 purpose ADC and a queue for Touchscreens. 607 607 608 + config MFD_PF1550 609 + tristate "NXP PF1550 PMIC Support" 610 + depends on I2C=y && OF 611 + select MFD_CORE 612 + select REGMAP_I2C 613 + select REGMAP_IRQ 614 + help 615 + Say yes here to add support for NXP PF1550. This is a companion Power 616 + Management IC with regulators, onkey, and charger control on chip. 617 + This driver provides common support for accessing the device; 618 + additional drivers must be enabled in order to use the functionality 619 + of the device. 620 + 621 + This driver can also be built as a module and if so will be called 622 + pf1550. 623 + 608 624 config MFD_HI6421_PMIC 609 625 tristate "HiSilicon Hi6421 PMU/Codec IC" 610 626 depends on OF
+2
drivers/mfd/Makefile
··· 122 122 obj-$(CONFIG_MFD_MC13XXX_SPI) += mc13xxx-spi.o 123 123 obj-$(CONFIG_MFD_MC13XXX_I2C) += mc13xxx-i2c.o 124 124 125 + obj-$(CONFIG_MFD_PF1550) += pf1550.o 126 + 125 127 obj-$(CONFIG_MFD_NCT6694) += nct6694.o 126 128 127 129 obj-$(CONFIG_MFD_CORE) += mfd-core.o
+367
drivers/mfd/pf1550.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Core driver for the PF1550 4 + * 5 + * Copyright (C) 2016 Freescale Semiconductor, Inc. 6 + * Robin Gong <yibin.gong@freescale.com> 7 + * 8 + * Portions Copyright (c) 2025 Savoir-faire Linux Inc. 9 + * Samuel Kayode <samuel.kayode@savoirfairelinux.com> 10 + */ 11 + 12 + #include <linux/err.h> 13 + #include <linux/i2c.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/mfd/core.h> 16 + #include <linux/mfd/pf1550.h> 17 + #include <linux/module.h> 18 + #include <linux/of.h> 19 + #include <linux/regmap.h> 20 + 21 + static const struct regmap_config pf1550_regmap_config = { 22 + .reg_bits = 8, 23 + .val_bits = 8, 24 + .max_register = PF1550_PMIC_REG_END, 25 + }; 26 + 27 + static const struct regmap_irq pf1550_irqs[] = { 28 + REGMAP_IRQ_REG(PF1550_IRQ_CHG, 0, IRQ_CHG), 29 + REGMAP_IRQ_REG(PF1550_IRQ_REGULATOR, 0, IRQ_REGULATOR), 30 + REGMAP_IRQ_REG(PF1550_IRQ_ONKEY, 0, IRQ_ONKEY), 31 + }; 32 + 33 + static const struct regmap_irq_chip pf1550_irq_chip = { 34 + .name = "pf1550", 35 + .status_base = PF1550_PMIC_REG_INT_CATEGORY, 36 + .init_ack_masked = 1, 37 + .num_regs = 1, 38 + .irqs = pf1550_irqs, 39 + .num_irqs = ARRAY_SIZE(pf1550_irqs), 40 + }; 41 + 42 + static const struct regmap_irq pf1550_regulator_irqs[] = { 43 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_SW1_LS, 0, PMIC_IRQ_SW1_LS), 44 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_SW2_LS, 0, PMIC_IRQ_SW2_LS), 45 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_SW3_LS, 0, PMIC_IRQ_SW3_LS), 46 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_SW1_HS, 3, PMIC_IRQ_SW1_HS), 47 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_SW2_HS, 3, PMIC_IRQ_SW2_HS), 48 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_SW3_HS, 3, PMIC_IRQ_SW3_HS), 49 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_LDO1_FAULT, 16, PMIC_IRQ_LDO1_FAULT), 50 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_LDO2_FAULT, 16, PMIC_IRQ_LDO2_FAULT), 51 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_LDO3_FAULT, 16, PMIC_IRQ_LDO3_FAULT), 52 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_TEMP_110, 24, PMIC_IRQ_TEMP_110), 53 + REGMAP_IRQ_REG(PF1550_PMIC_IRQ_TEMP_125, 24, PMIC_IRQ_TEMP_125), 54 + }; 55 + 56 + static const struct regmap_irq_chip pf1550_regulator_irq_chip = { 57 + .name = "pf1550-regulator", 58 + .status_base = PF1550_PMIC_REG_SW_INT_STAT0, 59 + .ack_base = PF1550_PMIC_REG_SW_INT_STAT0, 60 + .mask_base = PF1550_PMIC_REG_SW_INT_MASK0, 61 + .use_ack = 1, 62 + .init_ack_masked = 1, 63 + .num_regs = 25, 64 + .irqs = pf1550_regulator_irqs, 65 + .num_irqs = ARRAY_SIZE(pf1550_regulator_irqs), 66 + }; 67 + 68 + static const struct resource regulator_resources[] = { 69 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_SW1_LS), 70 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_SW2_LS), 71 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_SW3_LS), 72 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_SW1_HS), 73 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_SW2_HS), 74 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_SW3_HS), 75 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_LDO1_FAULT), 76 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_LDO2_FAULT), 77 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_LDO3_FAULT), 78 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_TEMP_110), 79 + DEFINE_RES_IRQ(PF1550_PMIC_IRQ_TEMP_125), 80 + }; 81 + 82 + static const struct regmap_irq pf1550_onkey_irqs[] = { 83 + REGMAP_IRQ_REG(PF1550_ONKEY_IRQ_PUSHI, 0, ONKEY_IRQ_PUSHI), 84 + REGMAP_IRQ_REG(PF1550_ONKEY_IRQ_1SI, 0, ONKEY_IRQ_1SI), 85 + REGMAP_IRQ_REG(PF1550_ONKEY_IRQ_2SI, 0, ONKEY_IRQ_2SI), 86 + REGMAP_IRQ_REG(PF1550_ONKEY_IRQ_3SI, 0, ONKEY_IRQ_3SI), 87 + REGMAP_IRQ_REG(PF1550_ONKEY_IRQ_4SI, 0, ONKEY_IRQ_4SI), 88 + REGMAP_IRQ_REG(PF1550_ONKEY_IRQ_8SI, 0, ONKEY_IRQ_8SI), 89 + }; 90 + 91 + static const struct regmap_irq_chip pf1550_onkey_irq_chip = { 92 + .name = "pf1550-onkey", 93 + .status_base = PF1550_PMIC_REG_ONKEY_INT_STAT0, 94 + .ack_base = PF1550_PMIC_REG_ONKEY_INT_STAT0, 95 + .mask_base = PF1550_PMIC_REG_ONKEY_INT_MASK0, 96 + .use_ack = 1, 97 + .init_ack_masked = 1, 98 + .num_regs = 1, 99 + .irqs = pf1550_onkey_irqs, 100 + .num_irqs = ARRAY_SIZE(pf1550_onkey_irqs), 101 + }; 102 + 103 + static const struct resource onkey_resources[] = { 104 + DEFINE_RES_IRQ(PF1550_ONKEY_IRQ_PUSHI), 105 + DEFINE_RES_IRQ(PF1550_ONKEY_IRQ_1SI), 106 + DEFINE_RES_IRQ(PF1550_ONKEY_IRQ_2SI), 107 + DEFINE_RES_IRQ(PF1550_ONKEY_IRQ_3SI), 108 + DEFINE_RES_IRQ(PF1550_ONKEY_IRQ_4SI), 109 + DEFINE_RES_IRQ(PF1550_ONKEY_IRQ_8SI), 110 + }; 111 + 112 + static const struct regmap_irq pf1550_charger_irqs[] = { 113 + REGMAP_IRQ_REG(PF1550_CHARG_IRQ_BAT2SOCI, 0, CHARG_IRQ_BAT2SOCI), 114 + REGMAP_IRQ_REG(PF1550_CHARG_IRQ_BATI, 0, CHARG_IRQ_BATI), 115 + REGMAP_IRQ_REG(PF1550_CHARG_IRQ_CHGI, 0, CHARG_IRQ_CHGI), 116 + REGMAP_IRQ_REG(PF1550_CHARG_IRQ_VBUSI, 0, CHARG_IRQ_VBUSI), 117 + REGMAP_IRQ_REG(PF1550_CHARG_IRQ_THMI, 0, CHARG_IRQ_THMI), 118 + }; 119 + 120 + static const struct regmap_irq_chip pf1550_charger_irq_chip = { 121 + .name = "pf1550-charger", 122 + .status_base = PF1550_CHARG_REG_CHG_INT, 123 + .ack_base = PF1550_CHARG_REG_CHG_INT, 124 + .mask_base = PF1550_CHARG_REG_CHG_INT_MASK, 125 + .use_ack = 1, 126 + .init_ack_masked = 1, 127 + .num_regs = 1, 128 + .irqs = pf1550_charger_irqs, 129 + .num_irqs = ARRAY_SIZE(pf1550_charger_irqs), 130 + }; 131 + 132 + static const struct resource charger_resources[] = { 133 + DEFINE_RES_IRQ(PF1550_CHARG_IRQ_BAT2SOCI), 134 + DEFINE_RES_IRQ(PF1550_CHARG_IRQ_BATI), 135 + DEFINE_RES_IRQ(PF1550_CHARG_IRQ_CHGI), 136 + DEFINE_RES_IRQ(PF1550_CHARG_IRQ_VBUSI), 137 + DEFINE_RES_IRQ(PF1550_CHARG_IRQ_THMI), 138 + }; 139 + 140 + static const struct mfd_cell pf1550_regulator_cell = { 141 + .name = "pf1550-regulator", 142 + .num_resources = ARRAY_SIZE(regulator_resources), 143 + .resources = regulator_resources, 144 + }; 145 + 146 + static const struct mfd_cell pf1550_onkey_cell = { 147 + .name = "pf1550-onkey", 148 + .num_resources = ARRAY_SIZE(onkey_resources), 149 + .resources = onkey_resources, 150 + }; 151 + 152 + static const struct mfd_cell pf1550_charger_cell = { 153 + .name = "pf1550-charger", 154 + .num_resources = ARRAY_SIZE(charger_resources), 155 + .resources = charger_resources, 156 + }; 157 + 158 + /* 159 + * The PF1550 is shipped in variants of A0, A1,...A9. Each variant defines a 160 + * configuration of the PMIC in a One-Time Programmable (OTP) memory. 161 + * This memory is accessed indirectly by writing valid keys to specific 162 + * registers of the PMIC. To read the OTP memory after writing the valid keys, 163 + * the OTP register address to be read is written to pf1550 register 0xc4 and 164 + * its value read from pf1550 register 0xc5. 165 + */ 166 + static int pf1550_read_otp(const struct pf1550_ddata *pf1550, unsigned int index, 167 + unsigned int *val) 168 + { 169 + int ret = 0; 170 + 171 + ret = regmap_write(pf1550->regmap, PF1550_PMIC_REG_KEY, PF1550_OTP_PMIC_KEY); 172 + if (ret) 173 + goto read_err; 174 + 175 + ret = regmap_write(pf1550->regmap, PF1550_CHARG_REG_CHGR_KEY2, PF1550_OTP_CHGR_KEY); 176 + if (ret) 177 + goto read_err; 178 + 179 + ret = regmap_write(pf1550->regmap, PF1550_TEST_REG_KEY3, PF1550_OTP_TEST_KEY); 180 + if (ret) 181 + goto read_err; 182 + 183 + ret = regmap_write(pf1550->regmap, PF1550_TEST_REG_FMRADDR, index); 184 + if (ret) 185 + goto read_err; 186 + 187 + ret = regmap_read(pf1550->regmap, PF1550_TEST_REG_FMRDATA, val); 188 + if (ret) 189 + goto read_err; 190 + 191 + return 0; 192 + 193 + read_err: 194 + return dev_err_probe(pf1550->dev, ret, "OTP reg %x not found!\n", index); 195 + } 196 + 197 + static int pf1550_i2c_probe(struct i2c_client *i2c) 198 + { 199 + const struct mfd_cell *regulator = &pf1550_regulator_cell; 200 + const struct mfd_cell *charger = &pf1550_charger_cell; 201 + const struct mfd_cell *onkey = &pf1550_onkey_cell; 202 + unsigned int reg_data = 0, otp_data = 0; 203 + struct pf1550_ddata *pf1550; 204 + struct irq_domain *domain; 205 + int irq, ret = 0; 206 + 207 + pf1550 = devm_kzalloc(&i2c->dev, sizeof(*pf1550), GFP_KERNEL); 208 + if (!pf1550) 209 + return -ENOMEM; 210 + 211 + i2c_set_clientdata(i2c, pf1550); 212 + pf1550->dev = &i2c->dev; 213 + pf1550->irq = i2c->irq; 214 + 215 + pf1550->regmap = devm_regmap_init_i2c(i2c, &pf1550_regmap_config); 216 + if (IS_ERR(pf1550->regmap)) 217 + return dev_err_probe(pf1550->dev, PTR_ERR(pf1550->regmap), 218 + "failed to allocate register map\n"); 219 + 220 + ret = regmap_read(pf1550->regmap, PF1550_PMIC_REG_DEVICE_ID, &reg_data); 221 + if (ret < 0) 222 + return dev_err_probe(pf1550->dev, ret, "cannot read chip ID\n"); 223 + if (reg_data != PF1550_DEVICE_ID) 224 + return dev_err_probe(pf1550->dev, -ENODEV, "invalid device ID: 0x%02x\n", reg_data); 225 + 226 + /* Regulator DVS for SW2 */ 227 + ret = pf1550_read_otp(pf1550, PF1550_OTP_SW2_SW3, &otp_data); 228 + if (ret) 229 + return ret; 230 + 231 + /* When clear, DVS should be enabled */ 232 + if (!(otp_data & OTP_SW2_DVS_ENB)) 233 + pf1550->dvs2_enable = true; 234 + 235 + /* Regulator DVS for SW1 */ 236 + ret = pf1550_read_otp(pf1550, PF1550_OTP_SW1_SW2, &otp_data); 237 + if (ret) 238 + return ret; 239 + 240 + if (!(otp_data & OTP_SW1_DVS_ENB)) 241 + pf1550->dvs1_enable = true; 242 + 243 + /* Add top level interrupts */ 244 + ret = devm_regmap_add_irq_chip(pf1550->dev, pf1550->regmap, pf1550->irq, 245 + IRQF_ONESHOT | IRQF_SHARED | 246 + IRQF_TRIGGER_FALLING, 247 + 0, &pf1550_irq_chip, 248 + &pf1550->irq_data); 249 + if (ret) 250 + return ret; 251 + 252 + /* Add regulator */ 253 + irq = regmap_irq_get_virq(pf1550->irq_data, PF1550_IRQ_REGULATOR); 254 + if (irq < 0) 255 + return dev_err_probe(pf1550->dev, irq, 256 + "Failed to get parent vIRQ(%d) for chip %s\n", 257 + PF1550_IRQ_REGULATOR, pf1550_irq_chip.name); 258 + 259 + ret = devm_regmap_add_irq_chip(pf1550->dev, pf1550->regmap, irq, 260 + IRQF_ONESHOT | IRQF_SHARED | 261 + IRQF_TRIGGER_FALLING, 0, 262 + &pf1550_regulator_irq_chip, 263 + &pf1550->irq_data_regulator); 264 + if (ret) 265 + return dev_err_probe(pf1550->dev, ret, "Failed to add %s IRQ chip\n", 266 + pf1550_regulator_irq_chip.name); 267 + 268 + domain = regmap_irq_get_domain(pf1550->irq_data_regulator); 269 + 270 + ret = devm_mfd_add_devices(pf1550->dev, PLATFORM_DEVID_NONE, regulator, 1, NULL, 0, domain); 271 + if (ret) 272 + return ret; 273 + 274 + /* Add onkey */ 275 + irq = regmap_irq_get_virq(pf1550->irq_data, PF1550_IRQ_ONKEY); 276 + if (irq < 0) 277 + return dev_err_probe(pf1550->dev, irq, 278 + "Failed to get parent vIRQ(%d) for chip %s\n", 279 + PF1550_IRQ_ONKEY, pf1550_irq_chip.name); 280 + 281 + ret = devm_regmap_add_irq_chip(pf1550->dev, pf1550->regmap, irq, 282 + IRQF_ONESHOT | IRQF_SHARED | 283 + IRQF_TRIGGER_FALLING, 0, 284 + &pf1550_onkey_irq_chip, 285 + &pf1550->irq_data_onkey); 286 + if (ret) 287 + return dev_err_probe(pf1550->dev, ret, "Failed to add %s IRQ chip\n", 288 + pf1550_onkey_irq_chip.name); 289 + 290 + domain = regmap_irq_get_domain(pf1550->irq_data_onkey); 291 + 292 + ret = devm_mfd_add_devices(pf1550->dev, PLATFORM_DEVID_NONE, onkey, 1, NULL, 0, domain); 293 + if (ret) 294 + return ret; 295 + 296 + /* Add battery charger */ 297 + irq = regmap_irq_get_virq(pf1550->irq_data, PF1550_IRQ_CHG); 298 + if (irq < 0) 299 + return dev_err_probe(pf1550->dev, irq, 300 + "Failed to get parent vIRQ(%d) for chip %s\n", 301 + PF1550_IRQ_CHG, pf1550_irq_chip.name); 302 + 303 + ret = devm_regmap_add_irq_chip(pf1550->dev, pf1550->regmap, irq, 304 + IRQF_ONESHOT | IRQF_SHARED | 305 + IRQF_TRIGGER_FALLING, 0, 306 + &pf1550_charger_irq_chip, 307 + &pf1550->irq_data_charger); 308 + if (ret) 309 + return dev_err_probe(pf1550->dev, ret, "Failed to add %s IRQ chip\n", 310 + pf1550_charger_irq_chip.name); 311 + 312 + domain = regmap_irq_get_domain(pf1550->irq_data_charger); 313 + 314 + return devm_mfd_add_devices(pf1550->dev, PLATFORM_DEVID_NONE, charger, 1, NULL, 0, domain); 315 + } 316 + 317 + static int pf1550_suspend(struct device *dev) 318 + { 319 + struct pf1550_ddata *pf1550 = dev_get_drvdata(dev); 320 + 321 + if (device_may_wakeup(dev)) { 322 + enable_irq_wake(pf1550->irq); 323 + disable_irq(pf1550->irq); 324 + } 325 + 326 + return 0; 327 + } 328 + 329 + static int pf1550_resume(struct device *dev) 330 + { 331 + struct pf1550_ddata *pf1550 = dev_get_drvdata(dev); 332 + 333 + if (device_may_wakeup(dev)) { 334 + disable_irq_wake(pf1550->irq); 335 + enable_irq(pf1550->irq); 336 + } 337 + 338 + return 0; 339 + } 340 + static DEFINE_SIMPLE_DEV_PM_OPS(pf1550_pm, pf1550_suspend, pf1550_resume); 341 + 342 + static const struct i2c_device_id pf1550_i2c_id[] = { 343 + { "pf1550" }, 344 + { /* sentinel */ } 345 + }; 346 + MODULE_DEVICE_TABLE(i2c, pf1550_i2c_id); 347 + 348 + static const struct of_device_id pf1550_dt_match[] = { 349 + { .compatible = "nxp,pf1550" }, 350 + { /* sentinel */ } 351 + }; 352 + MODULE_DEVICE_TABLE(of, pf1550_dt_match); 353 + 354 + static struct i2c_driver pf1550_i2c_driver = { 355 + .driver = { 356 + .name = "pf1550", 357 + .pm = pm_sleep_ptr(&pf1550_pm), 358 + .of_match_table = pf1550_dt_match, 359 + }, 360 + .probe = pf1550_i2c_probe, 361 + .id_table = pf1550_i2c_id, 362 + }; 363 + module_i2c_driver(pf1550_i2c_driver); 364 + 365 + MODULE_DESCRIPTION("NXP PF1550 core driver"); 366 + MODULE_AUTHOR("Robin Gong <yibin.gong@freescale.com>"); 367 + MODULE_LICENSE("GPL");
+11
drivers/power/supply/Kconfig
··· 486 486 help 487 487 Say Y here to enable charger for Marvell 88PM860x chip. 488 488 489 + config CHARGER_PF1550 490 + tristate "NXP PF1550 battery charger driver" 491 + depends on MFD_PF1550 492 + help 493 + Say Y to enable support for the NXP PF1550 battery charger. 494 + The device is a single cell Li-Ion/Li-Polymer battery charger for 495 + portable application. 496 + 497 + This driver can also be built as a module. If so, the module will be 498 + called pf1550-charger. 499 + 489 500 config BATTERY_RX51 490 501 tristate "Nokia RX-51 (N900) battery driver" 491 502 depends on TWL4030_MADC
+1
drivers/power/supply/Makefile
··· 66 66 obj-$(CONFIG_CHARGER_RT9471) += rt9471.o 67 67 obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o 68 68 obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o 69 + obj-$(CONFIG_CHARGER_PF1550) += pf1550-charger.o 69 70 obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o 70 71 obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_fg.o ab8500_btemp.o ab8500_chargalg.o 71 72 obj-$(CONFIG_CHARGER_CPCAP) += cpcap-charger.o
+641
drivers/power/supply/pf1550-charger.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * charger driver for the PF1550 4 + * 5 + * Copyright (C) 2016 Freescale Semiconductor, Inc. 6 + * Robin Gong <yibin.gong@freescale.com> 7 + * 8 + * Portions Copyright (c) 2025 Savoir-faire Linux Inc. 9 + * Samuel Kayode <samuel.kayode@savoirfairelinux.com> 10 + */ 11 + 12 + #include <linux/devm-helpers.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/mfd/pf1550.h> 15 + #include <linux/module.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/power_supply.h> 18 + 19 + #define PF1550_DEFAULT_CONSTANT_VOLT 4200000 20 + #define PF1550_DEFAULT_MIN_SYSTEM_VOLT 3500000 21 + #define PF1550_DEFAULT_THERMAL_TEMP 95 22 + #define PF1550_CHARGER_IRQ_NR 5 23 + 24 + struct pf1550_charger { 25 + struct device *dev; 26 + const struct pf1550_ddata *pf1550; 27 + struct power_supply *charger; 28 + struct power_supply *battery; 29 + struct delayed_work vbus_sense_work; 30 + struct delayed_work chg_sense_work; 31 + struct delayed_work bat_sense_work; 32 + int virqs[PF1550_CHARGER_IRQ_NR]; 33 + 34 + u32 constant_volt; 35 + u32 min_system_volt; 36 + u32 thermal_regulation_temp; 37 + }; 38 + 39 + static int pf1550_get_charger_state(struct regmap *regmap, int *val) 40 + { 41 + unsigned int data; 42 + int ret; 43 + 44 + ret = regmap_read(regmap, PF1550_CHARG_REG_CHG_SNS, &data); 45 + if (ret < 0) 46 + return ret; 47 + 48 + data &= PF1550_CHG_SNS_MASK; 49 + 50 + switch (data) { 51 + case PF1550_CHG_PRECHARGE: 52 + case PF1550_CHG_CONSTANT_CURRENT: 53 + case PF1550_CHG_CONSTANT_VOL: 54 + case PF1550_CHG_EOC: 55 + *val = POWER_SUPPLY_STATUS_CHARGING; 56 + break; 57 + case PF1550_CHG_DONE: 58 + *val = POWER_SUPPLY_STATUS_FULL; 59 + break; 60 + case PF1550_CHG_TIMER_FAULT: 61 + case PF1550_CHG_SUSPEND: 62 + *val = POWER_SUPPLY_STATUS_NOT_CHARGING; 63 + break; 64 + case PF1550_CHG_OFF_INV: 65 + case PF1550_CHG_OFF_TEMP: 66 + case PF1550_CHG_LINEAR_ONLY: 67 + *val = POWER_SUPPLY_STATUS_DISCHARGING; 68 + break; 69 + default: 70 + *val = POWER_SUPPLY_STATUS_UNKNOWN; 71 + } 72 + 73 + return 0; 74 + } 75 + 76 + static int pf1550_get_charge_type(struct regmap *regmap, int *val) 77 + { 78 + unsigned int data; 79 + int ret; 80 + 81 + ret = regmap_read(regmap, PF1550_CHARG_REG_CHG_SNS, &data); 82 + if (ret < 0) 83 + return ret; 84 + 85 + data &= PF1550_CHG_SNS_MASK; 86 + 87 + switch (data) { 88 + case PF1550_CHG_SNS_MASK: 89 + *val = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; 90 + break; 91 + case PF1550_CHG_CONSTANT_CURRENT: 92 + case PF1550_CHG_CONSTANT_VOL: 93 + case PF1550_CHG_EOC: 94 + *val = POWER_SUPPLY_CHARGE_TYPE_FAST; 95 + break; 96 + case PF1550_CHG_DONE: 97 + case PF1550_CHG_TIMER_FAULT: 98 + case PF1550_CHG_SUSPEND: 99 + case PF1550_CHG_OFF_INV: 100 + case PF1550_CHG_BAT_OVER: 101 + case PF1550_CHG_OFF_TEMP: 102 + case PF1550_CHG_LINEAR_ONLY: 103 + *val = POWER_SUPPLY_CHARGE_TYPE_NONE; 104 + break; 105 + default: 106 + *val = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; 107 + } 108 + 109 + return 0; 110 + } 111 + 112 + /* 113 + * Supported health statuses: 114 + * - POWER_SUPPLY_HEALTH_DEAD 115 + * - POWER_SUPPLY_HEALTH_GOOD 116 + * - POWER_SUPPLY_HEALTH_OVERVOLTAGE 117 + * - POWER_SUPPLY_HEALTH_UNKNOWN 118 + */ 119 + static int pf1550_get_battery_health(struct regmap *regmap, int *val) 120 + { 121 + unsigned int data; 122 + int ret; 123 + 124 + ret = regmap_read(regmap, PF1550_CHARG_REG_BATT_SNS, &data); 125 + if (ret < 0) 126 + return ret; 127 + 128 + data &= PF1550_BAT_SNS_MASK; 129 + 130 + switch (data) { 131 + case PF1550_BAT_NO_DETECT: 132 + *val = POWER_SUPPLY_HEALTH_NO_BATTERY; 133 + break; 134 + case PF1550_BAT_NO_VBUS: 135 + case PF1550_BAT_LOW_THAN_PRECHARG: 136 + case PF1550_BAT_CHARG_FAIL: 137 + case PF1550_BAT_HIGH_THAN_PRECHARG: 138 + *val = POWER_SUPPLY_HEALTH_GOOD; 139 + break; 140 + case PF1550_BAT_OVER_VOL: 141 + *val = POWER_SUPPLY_HEALTH_OVERVOLTAGE; 142 + break; 143 + default: 144 + *val = POWER_SUPPLY_HEALTH_UNKNOWN; 145 + break; 146 + } 147 + 148 + return 0; 149 + } 150 + 151 + static int pf1550_get_present(struct regmap *regmap, int *val) 152 + { 153 + unsigned int data; 154 + int ret; 155 + 156 + ret = regmap_read(regmap, PF1550_CHARG_REG_BATT_SNS, &data); 157 + if (ret < 0) 158 + return ret; 159 + 160 + data &= PF1550_BAT_SNS_MASK; 161 + *val = (data == PF1550_BAT_NO_DETECT) ? 0 : 1; 162 + 163 + return 0; 164 + } 165 + 166 + static int pf1550_get_online(struct regmap *regmap, int *val) 167 + { 168 + unsigned int data; 169 + int ret; 170 + 171 + ret = regmap_read(regmap, PF1550_CHARG_REG_VBUS_SNS, &data); 172 + if (ret < 0) 173 + return ret; 174 + 175 + *val = (data & PF1550_VBUS_VALID) ? 1 : 0; 176 + 177 + return 0; 178 + } 179 + 180 + static void pf1550_chg_bat_work(struct work_struct *work) 181 + { 182 + struct pf1550_charger *chg = container_of(to_delayed_work(work), 183 + struct pf1550_charger, 184 + bat_sense_work); 185 + unsigned int data; 186 + 187 + if (regmap_read(chg->pf1550->regmap, PF1550_CHARG_REG_BATT_SNS, &data)) { 188 + dev_err(chg->dev, "Read BATT_SNS error.\n"); 189 + return; 190 + } 191 + 192 + switch (data & PF1550_BAT_SNS_MASK) { 193 + case PF1550_BAT_NO_VBUS: 194 + dev_dbg(chg->dev, "No valid VBUS input.\n"); 195 + break; 196 + case PF1550_BAT_LOW_THAN_PRECHARG: 197 + dev_dbg(chg->dev, "VBAT < VPRECHG.LB.\n"); 198 + break; 199 + case PF1550_BAT_CHARG_FAIL: 200 + dev_dbg(chg->dev, "Battery charging failed.\n"); 201 + break; 202 + case PF1550_BAT_HIGH_THAN_PRECHARG: 203 + dev_dbg(chg->dev, "VBAT > VPRECHG.LB.\n"); 204 + break; 205 + case PF1550_BAT_OVER_VOL: 206 + dev_dbg(chg->dev, "VBAT > VBATOV.\n"); 207 + break; 208 + case PF1550_BAT_NO_DETECT: 209 + dev_dbg(chg->dev, "Battery not detected.\n"); 210 + break; 211 + default: 212 + dev_err(chg->dev, "Unknown value read:%x\n", 213 + data & PF1550_CHG_SNS_MASK); 214 + } 215 + } 216 + 217 + static void pf1550_chg_chg_work(struct work_struct *work) 218 + { 219 + struct pf1550_charger *chg = container_of(to_delayed_work(work), 220 + struct pf1550_charger, 221 + chg_sense_work); 222 + unsigned int data; 223 + 224 + if (regmap_read(chg->pf1550->regmap, PF1550_CHARG_REG_CHG_SNS, &data)) { 225 + dev_err(chg->dev, "Read CHG_SNS error.\n"); 226 + return; 227 + } 228 + 229 + switch (data & PF1550_CHG_SNS_MASK) { 230 + case PF1550_CHG_PRECHARGE: 231 + dev_dbg(chg->dev, "In pre-charger mode.\n"); 232 + break; 233 + case PF1550_CHG_CONSTANT_CURRENT: 234 + dev_dbg(chg->dev, "In fast-charge constant current mode.\n"); 235 + break; 236 + case PF1550_CHG_CONSTANT_VOL: 237 + dev_dbg(chg->dev, "In fast-charge constant voltage mode.\n"); 238 + break; 239 + case PF1550_CHG_EOC: 240 + dev_dbg(chg->dev, "In EOC mode.\n"); 241 + break; 242 + case PF1550_CHG_DONE: 243 + dev_dbg(chg->dev, "In DONE mode.\n"); 244 + break; 245 + case PF1550_CHG_TIMER_FAULT: 246 + dev_info(chg->dev, "In timer fault mode.\n"); 247 + break; 248 + case PF1550_CHG_SUSPEND: 249 + dev_info(chg->dev, "In thermistor suspend mode.\n"); 250 + break; 251 + case PF1550_CHG_OFF_INV: 252 + dev_info(chg->dev, "Input invalid, charger off.\n"); 253 + break; 254 + case PF1550_CHG_BAT_OVER: 255 + dev_warn(chg->dev, "Battery over-voltage.\n"); 256 + break; 257 + case PF1550_CHG_OFF_TEMP: 258 + dev_info(chg->dev, "Temp high, charger off.\n"); 259 + break; 260 + case PF1550_CHG_LINEAR_ONLY: 261 + dev_dbg(chg->dev, "In Linear mode, not charging.\n"); 262 + break; 263 + default: 264 + dev_err(chg->dev, "Unknown value read:%x\n", 265 + data & PF1550_CHG_SNS_MASK); 266 + } 267 + } 268 + 269 + static void pf1550_chg_vbus_work(struct work_struct *work) 270 + { 271 + struct pf1550_charger *chg = container_of(to_delayed_work(work), 272 + struct pf1550_charger, 273 + vbus_sense_work); 274 + unsigned int data; 275 + 276 + if (regmap_read(chg->pf1550->regmap, PF1550_CHARG_REG_VBUS_SNS, &data)) { 277 + dev_err(chg->dev, "Read VBUS_SNS error.\n"); 278 + return; 279 + } 280 + 281 + if (data & PF1550_VBUS_UVLO) { 282 + dev_dbg(chg->dev, "VBUS detached.\n"); 283 + power_supply_changed(chg->battery); 284 + } 285 + if (data & PF1550_VBUS_IN2SYS) 286 + dev_dbg(chg->dev, "VBUS_IN2SYS_SNS.\n"); 287 + if (data & PF1550_VBUS_OVLO) 288 + dev_dbg(chg->dev, "VBUS_OVLO_SNS.\n"); 289 + if (data & PF1550_VBUS_VALID) { 290 + dev_dbg(chg->dev, "VBUS attached.\n"); 291 + power_supply_changed(chg->charger); 292 + } 293 + } 294 + 295 + static irqreturn_t pf1550_charger_irq_handler(int irq, void *data) 296 + { 297 + struct pf1550_charger *chg = data; 298 + struct device *dev = chg->dev; 299 + int i, irq_type = -1; 300 + 301 + for (i = 0; i < PF1550_CHARGER_IRQ_NR; i++) 302 + if (irq == chg->virqs[i]) 303 + irq_type = i; 304 + 305 + switch (irq_type) { 306 + case PF1550_CHARG_IRQ_BAT2SOCI: 307 + dev_info(dev, "BAT to SYS Overcurrent interrupt.\n"); 308 + break; 309 + case PF1550_CHARG_IRQ_BATI: 310 + schedule_delayed_work(&chg->bat_sense_work, 311 + msecs_to_jiffies(10)); 312 + break; 313 + case PF1550_CHARG_IRQ_CHGI: 314 + schedule_delayed_work(&chg->chg_sense_work, 315 + msecs_to_jiffies(10)); 316 + break; 317 + case PF1550_CHARG_IRQ_VBUSI: 318 + schedule_delayed_work(&chg->vbus_sense_work, 319 + msecs_to_jiffies(10)); 320 + break; 321 + case PF1550_CHARG_IRQ_THMI: 322 + dev_info(dev, "Thermal interrupt.\n"); 323 + break; 324 + default: 325 + dev_err(dev, "unknown interrupt occurred.\n"); 326 + } 327 + 328 + return IRQ_HANDLED; 329 + } 330 + 331 + static enum power_supply_property pf1550_charger_props[] = { 332 + POWER_SUPPLY_PROP_ONLINE, 333 + POWER_SUPPLY_PROP_MODEL_NAME, 334 + POWER_SUPPLY_PROP_MANUFACTURER, 335 + }; 336 + 337 + static enum power_supply_property pf1550_battery_props[] = { 338 + POWER_SUPPLY_PROP_STATUS, 339 + POWER_SUPPLY_PROP_CHARGE_TYPE, 340 + POWER_SUPPLY_PROP_HEALTH, 341 + POWER_SUPPLY_PROP_PRESENT, 342 + POWER_SUPPLY_PROP_MODEL_NAME, 343 + POWER_SUPPLY_PROP_MANUFACTURER, 344 + }; 345 + 346 + static int pf1550_charger_get_property(struct power_supply *psy, 347 + enum power_supply_property psp, 348 + union power_supply_propval *val) 349 + { 350 + struct pf1550_charger *chg = power_supply_get_drvdata(psy); 351 + struct regmap *regmap = chg->pf1550->regmap; 352 + int ret = 0; 353 + 354 + switch (psp) { 355 + case POWER_SUPPLY_PROP_STATUS: 356 + ret = pf1550_get_charger_state(regmap, &val->intval); 357 + break; 358 + case POWER_SUPPLY_PROP_CHARGE_TYPE: 359 + ret = pf1550_get_charge_type(regmap, &val->intval); 360 + break; 361 + case POWER_SUPPLY_PROP_HEALTH: 362 + ret = pf1550_get_battery_health(regmap, &val->intval); 363 + break; 364 + case POWER_SUPPLY_PROP_PRESENT: 365 + ret = pf1550_get_present(regmap, &val->intval); 366 + break; 367 + case POWER_SUPPLY_PROP_ONLINE: 368 + ret = pf1550_get_online(regmap, &val->intval); 369 + break; 370 + case POWER_SUPPLY_PROP_MODEL_NAME: 371 + val->strval = "PF1550"; 372 + break; 373 + case POWER_SUPPLY_PROP_MANUFACTURER: 374 + val->strval = "NXP"; 375 + break; 376 + default: 377 + return -EINVAL; 378 + } 379 + 380 + return ret; 381 + } 382 + 383 + static const struct power_supply_desc pf1550_charger_desc = { 384 + .name = "pf1550-charger", 385 + .type = POWER_SUPPLY_TYPE_MAINS, 386 + .properties = pf1550_charger_props, 387 + .num_properties = ARRAY_SIZE(pf1550_charger_props), 388 + .get_property = pf1550_charger_get_property, 389 + }; 390 + 391 + static const struct power_supply_desc pf1550_battery_desc = { 392 + .name = "pf1550-battery", 393 + .type = POWER_SUPPLY_TYPE_BATTERY, 394 + .properties = pf1550_battery_props, 395 + .num_properties = ARRAY_SIZE(pf1550_battery_props), 396 + .get_property = pf1550_charger_get_property, 397 + }; 398 + 399 + static int pf1550_set_constant_volt(struct pf1550_charger *chg, 400 + unsigned int uvolt) 401 + { 402 + unsigned int data; 403 + 404 + if (uvolt >= 3500000 && uvolt <= 4440000) 405 + data = 8 + (uvolt - 3500000) / 20000; 406 + else 407 + return dev_err_probe(chg->dev, -EINVAL, 408 + "Wrong value for constant voltage\n"); 409 + 410 + dev_dbg(chg->dev, "Charging constant voltage: %u (0x%x)\n", uvolt, 411 + data); 412 + 413 + return regmap_update_bits(chg->pf1550->regmap, 414 + PF1550_CHARG_REG_BATT_REG, 415 + PF1550_CHARG_REG_BATT_REG_CHGCV_MASK, data); 416 + } 417 + 418 + static int pf1550_set_min_system_volt(struct pf1550_charger *chg, 419 + unsigned int uvolt) 420 + { 421 + unsigned int data; 422 + 423 + switch (uvolt) { 424 + case 3500000: 425 + data = 0x0; 426 + break; 427 + case 3700000: 428 + data = 0x1; 429 + break; 430 + case 4300000: 431 + data = 0x2; 432 + break; 433 + default: 434 + return dev_err_probe(chg->dev, -EINVAL, 435 + "Wrong value for minimum system voltage\n"); 436 + } 437 + 438 + data <<= PF1550_CHARG_REG_BATT_REG_VMINSYS_SHIFT; 439 + 440 + dev_dbg(chg->dev, "Minimum system regulation voltage: %u (0x%x)\n", 441 + uvolt, data); 442 + 443 + return regmap_update_bits(chg->pf1550->regmap, 444 + PF1550_CHARG_REG_BATT_REG, 445 + PF1550_CHARG_REG_BATT_REG_VMINSYS_MASK, data); 446 + } 447 + 448 + static int pf1550_set_thermal_regulation_temp(struct pf1550_charger *chg, 449 + unsigned int cells) 450 + { 451 + unsigned int data; 452 + 453 + switch (cells) { 454 + case 80: 455 + data = 0x0; 456 + break; 457 + case 95: 458 + data = 0x1; 459 + break; 460 + case 110: 461 + data = 0x2; 462 + break; 463 + case 125: 464 + data = 0x3; 465 + break; 466 + default: 467 + return dev_err_probe(chg->dev, -EINVAL, 468 + "Wrong value for thermal temperature\n"); 469 + } 470 + 471 + data <<= PF1550_CHARG_REG_THM_REG_CNFG_REGTEMP_SHIFT; 472 + 473 + dev_dbg(chg->dev, "Thermal regulation loop temperature: %u (0x%x)\n", 474 + cells, data); 475 + 476 + return regmap_update_bits(chg->pf1550->regmap, 477 + PF1550_CHARG_REG_THM_REG_CNFG, 478 + PF1550_CHARG_REG_THM_REG_CNFG_REGTEMP_MASK, 479 + data); 480 + } 481 + 482 + /* 483 + * Sets charger registers to proper and safe default values. 484 + */ 485 + static int pf1550_reg_init(struct pf1550_charger *chg) 486 + { 487 + struct power_supply_battery_info *info; 488 + struct device *dev = chg->dev; 489 + int ret; 490 + 491 + /* Unmask charger interrupt, mask DPMI and reserved bit */ 492 + ret = regmap_write(chg->pf1550->regmap, PF1550_CHARG_REG_CHG_INT_MASK, 493 + PF1550_CHG_INT_MASK); 494 + if (ret) 495 + return dev_err_probe(dev, ret, 496 + "Error unmask charger interrupt\n"); 497 + 498 + ret = pf1550_set_constant_volt(chg, chg->constant_volt); 499 + if (ret) 500 + return ret; 501 + 502 + ret = pf1550_set_min_system_volt(chg, chg->min_system_volt); 503 + if (ret) 504 + return ret; 505 + 506 + ret = pf1550_set_thermal_regulation_temp(chg, 507 + chg->thermal_regulation_temp); 508 + if (ret) 509 + return ret; 510 + 511 + /* 512 + * The PF1550 charger has 3 modes of operation. By default, the charger 513 + * is in mode 1; it remains off. Appropriate for applications not using 514 + * a battery. The other supported mode is mode 2, the charger is turned 515 + * on to charge a battery when present. 516 + */ 517 + if (power_supply_get_battery_info(chg->charger, &info)) { 518 + ret = regmap_write(chg->pf1550->regmap, 519 + PF1550_CHARG_REG_CHG_OPER, 520 + PF1550_CHG_BAT_ON); 521 + if (ret) 522 + return dev_err_probe(dev, ret, 523 + "Error turn on charger\n"); 524 + } 525 + 526 + return 0; 527 + } 528 + 529 + static void pf1550_dt_parse_dev_info(struct pf1550_charger *chg) 530 + { 531 + struct power_supply_battery_info *info; 532 + struct device *dev = chg->dev; 533 + 534 + if (device_property_read_u32(dev->parent, "nxp,min-system-microvolt", 535 + &chg->min_system_volt)) 536 + chg->min_system_volt = PF1550_DEFAULT_MIN_SYSTEM_VOLT; 537 + 538 + if (device_property_read_u32(dev->parent, 539 + "nxp,thermal-regulation-celsius", 540 + &chg->thermal_regulation_temp)) 541 + chg->thermal_regulation_temp = PF1550_DEFAULT_THERMAL_TEMP; 542 + 543 + if (power_supply_get_battery_info(chg->charger, &info)) 544 + chg->constant_volt = PF1550_DEFAULT_CONSTANT_VOLT; 545 + else 546 + chg->constant_volt = info->constant_charge_voltage_max_uv; 547 + } 548 + 549 + static int pf1550_charger_probe(struct platform_device *pdev) 550 + { 551 + const struct pf1550_ddata *pf1550 = dev_get_drvdata(pdev->dev.parent); 552 + struct power_supply_config psy_cfg = {}; 553 + struct pf1550_charger *chg; 554 + int i, irq, ret; 555 + 556 + chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); 557 + if (!chg) 558 + return -ENOMEM; 559 + 560 + chg->dev = &pdev->dev; 561 + chg->pf1550 = pf1550; 562 + 563 + if (!chg->pf1550->regmap) 564 + return dev_err_probe(&pdev->dev, -ENODEV, 565 + "failed to get regmap\n"); 566 + 567 + platform_set_drvdata(pdev, chg); 568 + 569 + ret = devm_delayed_work_autocancel(chg->dev, &chg->vbus_sense_work, 570 + pf1550_chg_vbus_work); 571 + if (ret) 572 + return dev_err_probe(chg->dev, ret, 573 + "failed to add vbus sense work\n"); 574 + 575 + ret = devm_delayed_work_autocancel(chg->dev, &chg->chg_sense_work, 576 + pf1550_chg_chg_work); 577 + if (ret) 578 + return dev_err_probe(chg->dev, ret, 579 + "failed to add charger sense work\n"); 580 + 581 + ret = devm_delayed_work_autocancel(chg->dev, &chg->bat_sense_work, 582 + pf1550_chg_bat_work); 583 + if (ret) 584 + return dev_err_probe(chg->dev, ret, 585 + "failed to add battery sense work\n"); 586 + 587 + for (i = 0; i < PF1550_CHARGER_IRQ_NR; i++) { 588 + irq = platform_get_irq(pdev, i); 589 + if (irq < 0) 590 + return irq; 591 + 592 + chg->virqs[i] = irq; 593 + 594 + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 595 + pf1550_charger_irq_handler, 596 + IRQF_NO_SUSPEND, 597 + "pf1550-charger", chg); 598 + if (ret) 599 + return dev_err_probe(&pdev->dev, ret, 600 + "failed irq request\n"); 601 + } 602 + 603 + psy_cfg.drv_data = chg; 604 + 605 + chg->charger = devm_power_supply_register(&pdev->dev, 606 + &pf1550_charger_desc, 607 + &psy_cfg); 608 + if (IS_ERR(chg->charger)) 609 + return dev_err_probe(&pdev->dev, PTR_ERR(chg->charger), 610 + "failed: power supply register\n"); 611 + 612 + chg->battery = devm_power_supply_register(&pdev->dev, 613 + &pf1550_battery_desc, 614 + &psy_cfg); 615 + if (IS_ERR(chg->battery)) 616 + return dev_err_probe(&pdev->dev, PTR_ERR(chg->battery), 617 + "failed: power supply register\n"); 618 + 619 + pf1550_dt_parse_dev_info(chg); 620 + 621 + return pf1550_reg_init(chg); 622 + } 623 + 624 + static const struct platform_device_id pf1550_charger_id[] = { 625 + { "pf1550-charger", }, 626 + { /* sentinel */ } 627 + }; 628 + MODULE_DEVICE_TABLE(platform, pf1550_charger_id); 629 + 630 + static struct platform_driver pf1550_charger_driver = { 631 + .driver = { 632 + .name = "pf1550-charger", 633 + }, 634 + .probe = pf1550_charger_probe, 635 + .id_table = pf1550_charger_id, 636 + }; 637 + module_platform_driver(pf1550_charger_driver); 638 + 639 + MODULE_AUTHOR("Robin Gong <yibin.gong@freescale.com>"); 640 + MODULE_DESCRIPTION("PF1550 charger driver"); 641 + MODULE_LICENSE("GPL");
+9
drivers/regulator/Kconfig
··· 1116 1116 Say y here to support the voltage regulators and convertors 1117 1117 on PV88090 1118 1118 1119 + config REGULATOR_PF1550 1120 + tristate "NXP PF1550 regulator" 1121 + depends on MFD_PF1550 1122 + help 1123 + Say y here to select this option to enable the regulators on 1124 + the PF1550 PMICs. 1125 + This driver controls the PF1550 regulators via I2C bus. 1126 + The regulators include three bucks and three ldos. 1127 + 1119 1128 config REGULATOR_PWM 1120 1129 tristate "PWM voltage regulator" 1121 1130 depends on PWM
+1
drivers/regulator/Makefile
··· 131 131 obj-$(CONFIG_REGULATOR_PCA9450) += pca9450-regulator.o 132 132 obj-$(CONFIG_REGULATOR_PF0900) += pf0900-regulator.o 133 133 obj-$(CONFIG_REGULATOR_PF9453) += pf9453-regulator.o 134 + obj-$(CONFIG_REGULATOR_PF1550) += pf1550-regulator.o 134 135 obj-$(CONFIG_REGULATOR_PF530X) += pf530x-regulator.o 135 136 obj-$(CONFIG_REGULATOR_PF8X00) += pf8x00-regulator.o 136 137 obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
+4 -4
drivers/regulator/bd71815-regulator.c
··· 173 173 const struct regulator_desc *desc, 174 174 struct regulator_config *cfg) 175 175 { 176 - struct bd71815_regulator *data; 176 + const struct bd71815_regulator *data; 177 177 178 - data = container_of(desc, struct bd71815_regulator, desc); 178 + data = container_of_const(desc, struct bd71815_regulator, desc); 179 179 return rohm_regulator_set_dvs_levels(data->dvs, np, desc, cfg->regmap); 180 180 } 181 181 ··· 195 195 const struct regulator_desc *desc, 196 196 struct regulator_config *cfg) 197 197 { 198 - struct bd71815_regulator *data; 198 + const struct bd71815_regulator *data; 199 199 int ret = 0, val; 200 200 201 - data = container_of(desc, struct bd71815_regulator, desc); 201 + data = container_of_const(desc, struct bd71815_regulator, desc); 202 202 203 203 if (of_property_present(np, "rohm,dvs-run-voltage") || 204 204 of_property_present(np, "rohm,dvs-suspend-voltage") ||
+2 -2
drivers/regulator/bd71828-regulator.c
··· 95 95 const struct regulator_desc *desc, 96 96 struct regulator_config *cfg) 97 97 { 98 - struct bd71828_regulator_data *data; 98 + const struct bd71828_regulator_data *data; 99 99 100 - data = container_of(desc, struct bd71828_regulator_data, desc); 100 + data = container_of_const(desc, struct bd71828_regulator_data, desc); 101 101 102 102 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); 103 103 }
+2 -2
drivers/regulator/bd718x7-regulator.c
··· 698 698 const struct regulator_desc *desc, 699 699 struct regulator_config *cfg) 700 700 { 701 - struct bd718xx_regulator_data *data; 701 + const struct bd718xx_regulator_data *data; 702 702 703 - data = container_of(desc, struct bd718xx_regulator_data, desc); 703 + data = container_of_const(desc, struct bd718xx_regulator_data, desc); 704 704 705 705 return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); 706 706 }
+5 -5
drivers/regulator/bd96801-regulator.c
··· 337 337 int i; 338 338 339 339 for (i = 0; i < rid->num_states; i++) { 340 - struct bd96801_regulator_data *rdata; 340 + const struct bd96801_regulator_data *rdata; 341 341 struct regulator_dev *rdev; 342 342 343 343 rdev = rid->states[i].rdev; 344 - rdata = container_of(rdev->desc, struct bd96801_regulator_data, 345 - desc); 344 + rdata = container_of_const(rdev->desc, struct bd96801_regulator_data, 345 + desc); 346 346 rid->states[i].notifs = regulator_err2notif(rdata->ldo_errs); 347 347 rid->states[i].errors = rdata->ldo_errs; 348 348 *dev_mask |= BIT(i); ··· 354 354 unsigned int selector) 355 355 { 356 356 int voltage; 357 - struct bd96801_regulator_data *data; 357 + const struct bd96801_regulator_data *data; 358 358 359 - data = container_of(rdev->desc, struct bd96801_regulator_data, desc); 359 + data = container_of_const(rdev->desc, struct bd96801_regulator_data, desc); 360 360 361 361 /* 362 362 * The BD096801 has voltage setting in two registers. One giving the
+5 -5
drivers/regulator/hi6421-regulator.c
··· 387 387 const struct hi6421_regulator_info *info; 388 388 unsigned int reg_val; 389 389 390 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 390 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 391 391 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 392 392 if (reg_val & info->mode_mask) 393 393 return REGULATOR_MODE_IDLE; ··· 400 400 const struct hi6421_regulator_info *info; 401 401 unsigned int reg_val; 402 402 403 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 403 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 404 404 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 405 405 if (reg_val & info->mode_mask) 406 406 return REGULATOR_MODE_STANDBY; ··· 414 414 const struct hi6421_regulator_info *info; 415 415 unsigned int new_mode; 416 416 417 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 417 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 418 418 switch (mode) { 419 419 case REGULATOR_MODE_NORMAL: 420 420 new_mode = 0; ··· 439 439 const struct hi6421_regulator_info *info; 440 440 unsigned int new_mode; 441 441 442 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 442 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 443 443 switch (mode) { 444 444 case REGULATOR_MODE_NORMAL: 445 445 new_mode = 0; ··· 464 464 { 465 465 const struct hi6421_regulator_info *info; 466 466 467 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 467 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 468 468 469 469 if (load_uA > info->eco_microamp) 470 470 return REGULATOR_MODE_NORMAL;
+2 -2
drivers/regulator/hi6421v530-regulator.c
··· 110 110 const struct hi6421v530_regulator_info *info; 111 111 unsigned int reg_val; 112 112 113 - info = container_of(rdev->desc, struct hi6421v530_regulator_info, rdesc); 113 + info = container_of_const(rdev->desc, struct hi6421v530_regulator_info, rdesc); 114 114 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 115 115 116 116 if (reg_val & (info->mode_mask)) ··· 125 125 const struct hi6421v530_regulator_info *info; 126 126 unsigned int new_mode; 127 127 128 - info = container_of(rdev->desc, struct hi6421v530_regulator_info, rdesc); 128 + info = container_of_const(rdev->desc, struct hi6421v530_regulator_info, rdesc); 129 129 switch (mode) { 130 130 case REGULATOR_MODE_NORMAL: 131 131 new_mode = 0;
+3 -3
drivers/regulator/hi6421v600-regulator.c
··· 121 121 const struct hi6421_spmi_reg_info *sreg; 122 122 unsigned int reg_val; 123 123 124 - sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc); 124 + sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc); 125 125 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 126 126 127 127 if (reg_val & sreg->eco_mode_mask) ··· 136 136 const struct hi6421_spmi_reg_info *sreg; 137 137 unsigned int val; 138 138 139 - sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc); 139 + sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc); 140 140 switch (mode) { 141 141 case REGULATOR_MODE_NORMAL: 142 142 val = 0; ··· 162 162 { 163 163 const struct hi6421_spmi_reg_info *sreg; 164 164 165 - sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc); 165 + sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc); 166 166 167 167 if (!sreg->eco_uA || ((unsigned int)load_uA > sreg->eco_uA)) 168 168 return REGULATOR_MODE_NORMAL;
+3 -3
drivers/regulator/max77650-regulator.c
··· 68 68 struct regmap *map; 69 69 int val, rv, en; 70 70 71 - rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc); 71 + rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc); 72 72 map = rdev_get_regmap(rdev); 73 73 74 74 rv = regmap_read(map, rdesc->regB, &val); ··· 85 85 const struct max77650_regulator_desc *rdesc; 86 86 struct regmap *map; 87 87 88 - rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc); 88 + rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc); 89 89 map = rdev_get_regmap(rdev); 90 90 91 91 return regmap_update_bits(map, rdesc->regB, ··· 98 98 const struct max77650_regulator_desc *rdesc; 99 99 struct regmap *map; 100 100 101 - rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc); 101 + rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc); 102 102 map = rdev_get_regmap(rdev); 103 103 104 104 return regmap_update_bits(map, rdesc->regB,
+3 -3
drivers/regulator/mt6315-regulator.c
··· 80 80 int ret, regval; 81 81 u32 modeset_mask; 82 82 83 - info = container_of(rdev->desc, struct mt6315_regulator_info, desc); 83 + info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc); 84 84 modeset_mask = init->modeset_mask[rdev_get_id(rdev)]; 85 85 ret = regmap_read(rdev->regmap, MT6315_BUCK_TOP_4PHASE_ANA_CON42, &regval); 86 86 if (ret != 0) { ··· 111 111 int ret, val, curr_mode; 112 112 u32 modeset_mask; 113 113 114 - info = container_of(rdev->desc, struct mt6315_regulator_info, desc); 114 + info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc); 115 115 modeset_mask = init->modeset_mask[rdev_get_id(rdev)]; 116 116 curr_mode = mt6315_regulator_get_mode(rdev); 117 117 switch (mode) { ··· 165 165 int ret; 166 166 u32 regval; 167 167 168 - info = container_of(rdev->desc, struct mt6315_regulator_info, desc); 168 + info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc); 169 169 ret = regmap_read(rdev->regmap, info->status_reg, &regval); 170 170 if (ret < 0) { 171 171 dev_err(&rdev->dev, "Failed to get enable reg: %d\n", ret);
+1 -1
drivers/regulator/mt6358-regulator.c
··· 31 31 u32 modeset_mask; 32 32 }; 33 33 34 - #define to_regulator_info(x) container_of((x), struct mt6358_regulator_info, desc) 34 + #define to_regulator_info(x) container_of_const((x), struct mt6358_regulator_info, desc) 35 35 36 36 #define MT6358_BUCK(match, vreg, supply, min, max, step, \ 37 37 vosel_mask, _da_vsel_reg, _da_vsel_mask, \
+4 -4
drivers/regulator/pca9450-regulator.c
··· 249 249 } 250 250 251 251 if (ret == 0) { 252 - struct pca9450_regulator_desc *regulator = container_of(desc, 252 + const struct pca9450_regulator_desc *regulator = container_of_const(desc, 253 253 struct pca9450_regulator_desc, desc); 254 254 255 255 /* Enable DVS control through PMIC_STBY_REQ for this BUCK */ ··· 263 263 const struct regulator_desc *desc, 264 264 struct regulator_config *cfg) 265 265 { 266 - struct pca9450_regulator_desc *data = container_of(desc, 266 + const struct pca9450_regulator_desc *data = container_of_const(desc, 267 267 struct pca9450_regulator_desc, desc); 268 268 const struct pc9450_dvs_config *dvs = &data->dvs; 269 269 unsigned int reg, mask; ··· 308 308 309 309 static int pca9450_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) 310 310 { 311 - struct pca9450_regulator_desc *desc = container_of(rdev->desc, 311 + const struct pca9450_regulator_desc *desc = container_of_const(rdev->desc, 312 312 struct pca9450_regulator_desc, desc); 313 313 const struct pc9450_dvs_config *dvs = &desc->dvs; 314 314 int val; ··· 333 333 334 334 static unsigned int pca9450_buck_get_mode(struct regulator_dev *rdev) 335 335 { 336 - struct pca9450_regulator_desc *desc = container_of(rdev->desc, 336 + const struct pca9450_regulator_desc *desc = container_of_const(rdev->desc, 337 337 struct pca9450_regulator_desc, desc); 338 338 const struct pc9450_dvs_config *dvs = &desc->dvs; 339 339 int ret = 0, regval;
+429
drivers/regulator/pf1550-regulator.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // 3 + // regulator driver for the PF1550 4 + // 5 + // Copyright (C) 2016 Freescale Semiconductor, Inc. 6 + // Robin Gong <yibin.gong@freescale.com> 7 + // 8 + // Portions Copyright (c) 2025 Savoir-faire Linux Inc. 9 + // Samuel Kayode <samuel.kayode@savoirfairelinux.com> 10 + // 11 + 12 + #include <linux/err.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/mfd/pf1550.h> 15 + #include <linux/module.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/regulator/driver.h> 18 + #include <linux/regulator/machine.h> 19 + 20 + #define PF1550_REGULATOR_IRQ_NR 11 21 + #define PF1550_MAX_REGULATOR 7 22 + 23 + struct pf1550_desc { 24 + struct regulator_desc desc; 25 + unsigned char stby_reg; 26 + unsigned char stby_mask; 27 + unsigned char stby_enable_reg; 28 + unsigned char stby_enable_mask; 29 + }; 30 + 31 + struct pf1550_regulator_info { 32 + struct device *dev; 33 + const struct pf1550_ddata *pf1550; 34 + struct pf1550_desc regulator_descs[PF1550_MAX_REGULATOR]; 35 + struct regulator_dev *rdevs[PF1550_MAX_REGULATOR]; 36 + }; 37 + 38 + static const int pf1550_sw12_volts[] = { 39 + 1100000, 1200000, 1350000, 1500000, 1800000, 2500000, 3000000, 3300000, 40 + }; 41 + 42 + static const int pf1550_ldo13_volts[] = { 43 + 750000, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 44 + 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 45 + 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, 46 + 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000, 47 + }; 48 + 49 + static int pf1550_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) 50 + { 51 + int id = rdev_get_id(rdev); 52 + unsigned int ramp_bits = 0; 53 + int ret; 54 + 55 + if (id > PF1550_VREFDDR) 56 + return -EACCES; 57 + 58 + if (ramp_delay < 0 || ramp_delay > 6250) 59 + return -EINVAL; 60 + 61 + ramp_delay = 6250 / ramp_delay; 62 + ramp_bits = ramp_delay >> 1; 63 + 64 + ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg + 4, 0x10, 65 + ramp_bits << 4); 66 + if (ret < 0) 67 + dev_err(&rdev->dev, "ramp failed, err %d\n", ret); 68 + 69 + return ret; 70 + } 71 + 72 + static int pf1550_set_suspend_enable(struct regulator_dev *rdev) 73 + { 74 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 75 + struct pf1550_desc, 76 + desc); 77 + unsigned int val = desc->stby_enable_mask; 78 + 79 + return regmap_update_bits(rdev->regmap, desc->stby_enable_reg, 80 + desc->stby_enable_mask, val); 81 + } 82 + 83 + static int pf1550_set_suspend_disable(struct regulator_dev *rdev) 84 + { 85 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 86 + struct pf1550_desc, 87 + desc); 88 + 89 + return regmap_update_bits(rdev->regmap, desc->stby_enable_reg, 90 + desc->stby_enable_mask, 0); 91 + } 92 + 93 + static int pf1550_buck_set_table_suspend_voltage(struct regulator_dev *rdev, 94 + int uV) 95 + { 96 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 97 + struct pf1550_desc, 98 + desc); 99 + int ret; 100 + 101 + ret = regulator_map_voltage_ascend(rdev, uV, uV); 102 + if (ret < 0) { 103 + dev_err(rdev_get_dev(rdev), "failed to map %i uV\n", uV); 104 + return ret; 105 + } 106 + 107 + return regmap_update_bits(rdev->regmap, desc->stby_reg, 108 + desc->stby_mask, ret); 109 + } 110 + 111 + static int pf1550_buck_set_linear_suspend_voltage(struct regulator_dev *rdev, 112 + int uV) 113 + { 114 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 115 + struct pf1550_desc, 116 + desc); 117 + int ret; 118 + 119 + ret = regulator_map_voltage_linear(rdev, uV, uV); 120 + if (ret < 0) { 121 + dev_err(rdev_get_dev(rdev), "failed to map %i uV\n", uV); 122 + return ret; 123 + } 124 + 125 + return regmap_update_bits(rdev->regmap, desc->stby_reg, 126 + desc->stby_mask, ret); 127 + } 128 + 129 + static const struct regulator_ops pf1550_sw1_ops = { 130 + .enable = regulator_enable_regmap, 131 + .disable = regulator_disable_regmap, 132 + .set_suspend_enable = pf1550_set_suspend_enable, 133 + .set_suspend_disable = pf1550_set_suspend_disable, 134 + .is_enabled = regulator_is_enabled_regmap, 135 + .list_voltage = regulator_list_voltage_table, 136 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 137 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 138 + .set_voltage_time_sel = regulator_set_voltage_time_sel, 139 + .set_suspend_voltage = pf1550_buck_set_table_suspend_voltage, 140 + .map_voltage = regulator_map_voltage_ascend, 141 + .set_ramp_delay = pf1550_set_ramp_delay, 142 + }; 143 + 144 + static const struct regulator_ops pf1550_sw2_ops = { 145 + .enable = regulator_enable_regmap, 146 + .disable = regulator_disable_regmap, 147 + .set_suspend_enable = pf1550_set_suspend_enable, 148 + .set_suspend_disable = pf1550_set_suspend_disable, 149 + .is_enabled = regulator_is_enabled_regmap, 150 + .list_voltage = regulator_list_voltage_linear, 151 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 152 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 153 + .set_voltage_time_sel = regulator_set_voltage_time_sel, 154 + .set_suspend_voltage = pf1550_buck_set_linear_suspend_voltage, 155 + .map_voltage = regulator_map_voltage_linear, 156 + .set_ramp_delay = pf1550_set_ramp_delay, 157 + }; 158 + 159 + static const struct regulator_ops pf1550_ldo1_ops = { 160 + .enable = regulator_enable_regmap, 161 + .disable = regulator_disable_regmap, 162 + .set_suspend_enable = pf1550_set_suspend_enable, 163 + .set_suspend_disable = pf1550_set_suspend_disable, 164 + .is_enabled = regulator_is_enabled_regmap, 165 + .list_voltage = regulator_list_voltage_table, 166 + .map_voltage = regulator_map_voltage_ascend, 167 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 168 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 169 + }; 170 + 171 + static const struct regulator_ops pf1550_ldo2_ops = { 172 + .enable = regulator_enable_regmap, 173 + .disable = regulator_disable_regmap, 174 + .set_suspend_enable = pf1550_set_suspend_enable, 175 + .set_suspend_disable = pf1550_set_suspend_disable, 176 + .is_enabled = regulator_is_enabled_regmap, 177 + .list_voltage = regulator_list_voltage_linear, 178 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 179 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 180 + .map_voltage = regulator_map_voltage_linear, 181 + }; 182 + 183 + static const struct regulator_ops pf1550_fixed_ops = { 184 + .enable = regulator_enable_regmap, 185 + .disable = regulator_disable_regmap, 186 + .set_suspend_enable = pf1550_set_suspend_enable, 187 + .set_suspend_disable = pf1550_set_suspend_disable, 188 + .is_enabled = regulator_is_enabled_regmap, 189 + .list_voltage = regulator_list_voltage_linear, 190 + }; 191 + 192 + #define PF_VREF(_chip, match, _name, voltage) { \ 193 + .desc = { \ 194 + .name = #_name, \ 195 + .of_match = of_match_ptr(match), \ 196 + .regulators_node = of_match_ptr("regulators"), \ 197 + .n_voltages = 1, \ 198 + .ops = &pf1550_fixed_ops, \ 199 + .type = REGULATOR_VOLTAGE, \ 200 + .id = _chip ## _ ## _name, \ 201 + .owner = THIS_MODULE, \ 202 + .min_uV = (voltage), \ 203 + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 204 + .enable_mask = 0x1, \ 205 + }, \ 206 + .stby_enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 207 + .stby_enable_mask = 0x2, \ 208 + } 209 + 210 + #define PF_SW(_chip, match, _name, min, max, mask, step) { \ 211 + .desc = { \ 212 + .name = #_name, \ 213 + .of_match = of_match_ptr(match), \ 214 + .regulators_node = of_match_ptr("regulators"), \ 215 + .n_voltages = ((max) - (min)) / (step) + 1, \ 216 + .ops = &pf1550_sw2_ops, \ 217 + .type = REGULATOR_VOLTAGE, \ 218 + .id = _chip ## _ ## _name, \ 219 + .owner = THIS_MODULE, \ 220 + .min_uV = (min), \ 221 + .uV_step = (step), \ 222 + .linear_min_sel = 0, \ 223 + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ 224 + .vsel_mask = (mask), \ 225 + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 226 + .enable_mask = 0x1, \ 227 + }, \ 228 + .stby_reg = _chip ## _PMIC_REG_ ## _name ## _STBY_VOLT, \ 229 + .stby_mask = (mask), \ 230 + .stby_enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 231 + .stby_enable_mask = 0x2, \ 232 + } 233 + 234 + #define PF_LDO1(_chip, match, _name, mask, voltages) { \ 235 + .desc = { \ 236 + .name = #_name, \ 237 + .of_match = of_match_ptr(match), \ 238 + .regulators_node = of_match_ptr("regulators"), \ 239 + .n_voltages = ARRAY_SIZE(voltages), \ 240 + .ops = &pf1550_ldo1_ops, \ 241 + .type = REGULATOR_VOLTAGE, \ 242 + .id = _chip ## _ ## _name, \ 243 + .owner = THIS_MODULE, \ 244 + .volt_table = voltages, \ 245 + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ 246 + .vsel_mask = (mask), \ 247 + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 248 + .enable_mask = 0x1, \ 249 + }, \ 250 + .stby_enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 251 + .stby_enable_mask = 0x2, \ 252 + } 253 + 254 + #define PF_LDO2(_chip, match, _name, mask, min, max, step) { \ 255 + .desc = { \ 256 + .name = #_name, \ 257 + .of_match = of_match_ptr(match), \ 258 + .regulators_node = of_match_ptr("regulators"), \ 259 + .n_voltages = ((max) - (min)) / (step) + 1, \ 260 + .ops = &pf1550_ldo2_ops, \ 261 + .type = REGULATOR_VOLTAGE, \ 262 + .id = _chip ## _ ## _name, \ 263 + .owner = THIS_MODULE, \ 264 + .min_uV = (min), \ 265 + .uV_step = (step), \ 266 + .linear_min_sel = 0, \ 267 + .vsel_reg = _chip ## _PMIC_REG_ ## _name ## _VOLT, \ 268 + .vsel_mask = (mask), \ 269 + .enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 270 + .enable_mask = 0x1, \ 271 + }, \ 272 + .stby_enable_reg = _chip ## _PMIC_REG_ ## _name ## _CTRL, \ 273 + .stby_enable_mask = 0x2, \ 274 + } 275 + 276 + static struct pf1550_desc pf1550_regulators[] = { 277 + PF_SW(PF1550, "sw1", SW1, 600000, 1387500, 0x3f, 12500), 278 + PF_SW(PF1550, "sw2", SW2, 600000, 1387500, 0x3f, 12500), 279 + PF_SW(PF1550, "sw3", SW3, 1800000, 3300000, 0xf, 100000), 280 + PF_VREF(PF1550, "vrefddr", VREFDDR, 1200000), 281 + PF_LDO1(PF1550, "ldo1", LDO1, 0x1f, pf1550_ldo13_volts), 282 + PF_LDO2(PF1550, "ldo2", LDO2, 0xf, 1800000, 3300000, 100000), 283 + PF_LDO1(PF1550, "ldo3", LDO3, 0x1f, pf1550_ldo13_volts), 284 + }; 285 + 286 + static irqreturn_t pf1550_regulator_irq_handler(int irq, void *data) 287 + { 288 + struct pf1550_regulator_info *info = data; 289 + struct device *dev = info->dev; 290 + struct platform_device *pdev = to_platform_device(dev); 291 + int i, irq_type = -1; 292 + unsigned int event; 293 + 294 + for (i = 0; i < PF1550_REGULATOR_IRQ_NR; i++) 295 + if (irq == platform_get_irq(pdev, i)) 296 + irq_type = i; 297 + 298 + switch (irq_type) { 299 + /* The _LS interrupts indicate over-current event. The _HS interrupts 300 + * which are more accurate and can detect catastrophic faults, issue 301 + * an error event. The current limit FAULT interrupt is similar to the 302 + * _HS' 303 + */ 304 + case PF1550_PMIC_IRQ_SW1_LS: 305 + case PF1550_PMIC_IRQ_SW2_LS: 306 + case PF1550_PMIC_IRQ_SW3_LS: 307 + event = REGULATOR_EVENT_OVER_CURRENT_WARN; 308 + for (i = 0; i < PF1550_MAX_REGULATOR; i++) 309 + if (!strcmp(rdev_get_name(info->rdevs[i]), "SW3")) 310 + regulator_notifier_call_chain(info->rdevs[i], 311 + event, NULL); 312 + break; 313 + case PF1550_PMIC_IRQ_SW1_HS: 314 + case PF1550_PMIC_IRQ_SW2_HS: 315 + case PF1550_PMIC_IRQ_SW3_HS: 316 + event = REGULATOR_EVENT_OVER_CURRENT; 317 + for (i = 0; i < PF1550_MAX_REGULATOR; i++) 318 + if (!strcmp(rdev_get_name(info->rdevs[i]), "SW3")) 319 + regulator_notifier_call_chain(info->rdevs[i], 320 + event, NULL); 321 + break; 322 + case PF1550_PMIC_IRQ_LDO1_FAULT: 323 + case PF1550_PMIC_IRQ_LDO2_FAULT: 324 + case PF1550_PMIC_IRQ_LDO3_FAULT: 325 + event = REGULATOR_EVENT_OVER_CURRENT; 326 + for (i = 0; i < PF1550_MAX_REGULATOR; i++) 327 + if (!strcmp(rdev_get_name(info->rdevs[i]), "LDO3")) 328 + regulator_notifier_call_chain(info->rdevs[i], 329 + event, NULL); 330 + break; 331 + case PF1550_PMIC_IRQ_TEMP_110: 332 + case PF1550_PMIC_IRQ_TEMP_125: 333 + event = REGULATOR_EVENT_OVER_TEMP; 334 + for (i = 0; i < PF1550_MAX_REGULATOR; i++) 335 + regulator_notifier_call_chain(info->rdevs[i], 336 + event, NULL); 337 + break; 338 + default: 339 + dev_err(dev, "regulator interrupt: irq %d occurred\n", 340 + irq_type); 341 + } 342 + 343 + return IRQ_HANDLED; 344 + } 345 + 346 + static int pf1550_regulator_probe(struct platform_device *pdev) 347 + { 348 + const struct pf1550_ddata *pf1550 = dev_get_drvdata(pdev->dev.parent); 349 + struct regulator_config config = { }; 350 + struct pf1550_regulator_info *info; 351 + int i, irq = -1, ret = 0; 352 + 353 + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 354 + if (!info) 355 + return -ENOMEM; 356 + 357 + config.regmap = dev_get_regmap(pf1550->dev, NULL); 358 + if (!config.regmap) 359 + return dev_err_probe(&pdev->dev, -ENODEV, 360 + "failed to get parent regmap\n"); 361 + 362 + config.dev = pf1550->dev; 363 + config.regmap = pf1550->regmap; 364 + info->dev = &pdev->dev; 365 + info->pf1550 = pf1550; 366 + 367 + memcpy(info->regulator_descs, pf1550_regulators, 368 + sizeof(info->regulator_descs)); 369 + 370 + for (i = 0; i < ARRAY_SIZE(pf1550_regulators); i++) { 371 + struct regulator_desc *desc; 372 + 373 + desc = &info->regulator_descs[i].desc; 374 + 375 + if ((desc->id == PF1550_SW2 && !pf1550->dvs2_enable) || 376 + (desc->id == PF1550_SW1 && !pf1550->dvs1_enable)) { 377 + /* OTP_SW2_DVS_ENB == 1? or OTP_SW1_DVS_ENB == 1? */ 378 + desc->volt_table = pf1550_sw12_volts; 379 + desc->n_voltages = ARRAY_SIZE(pf1550_sw12_volts); 380 + desc->ops = &pf1550_sw1_ops; 381 + } 382 + 383 + info->rdevs[i] = devm_regulator_register(&pdev->dev, desc, 384 + &config); 385 + if (IS_ERR(info->rdevs[i])) 386 + return dev_err_probe(&pdev->dev, 387 + PTR_ERR(info->rdevs[i]), 388 + "failed to initialize regulator-%d\n", 389 + i); 390 + } 391 + 392 + platform_set_drvdata(pdev, info); 393 + 394 + for (i = 0; i < PF1550_REGULATOR_IRQ_NR; i++) { 395 + irq = platform_get_irq(pdev, i); 396 + if (irq < 0) 397 + return irq; 398 + 399 + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 400 + pf1550_regulator_irq_handler, 401 + IRQF_NO_SUSPEND, 402 + "pf1550-regulator", info); 403 + if (ret) 404 + return dev_err_probe(&pdev->dev, ret, 405 + "failed: irq request (IRQ: %d)\n", 406 + i); 407 + } 408 + 409 + return 0; 410 + } 411 + 412 + static const struct platform_device_id pf1550_regulator_id[] = { 413 + { "pf1550-regulator", }, 414 + { /* sentinel */ } 415 + }; 416 + MODULE_DEVICE_TABLE(platform, pf1550_regulator_id); 417 + 418 + static struct platform_driver pf1550_regulator_driver = { 419 + .driver = { 420 + .name = "pf1550-regulator", 421 + }, 422 + .probe = pf1550_regulator_probe, 423 + .id_table = pf1550_regulator_id, 424 + }; 425 + module_platform_driver(pf1550_regulator_driver); 426 + 427 + MODULE_DESCRIPTION("NXP PF1550 regulator driver"); 428 + MODULE_AUTHOR("Robin Gong <yibin.gong@freescale.com>"); 429 + MODULE_LICENSE("GPL");
+3 -1
drivers/regulator/pf9453-regulator.c
··· 538 538 static int pf9453_set_dvs_levels(struct device_node *np, const struct regulator_desc *desc, 539 539 struct regulator_config *cfg) 540 540 { 541 - struct pf9453_regulator_desc *data = container_of(desc, struct pf9453_regulator_desc, desc); 541 + const struct pf9453_regulator_desc *data = container_of_const(desc, 542 + struct pf9453_regulator_desc, 543 + desc); 542 544 struct pf9453 *pf9453 = dev_get_drvdata(cfg->dev); 543 545 const struct pf9453_dvs_config *dvs = &data->dvs; 544 546 unsigned int reg, mask;
+273
include/linux/mfd/pf1550.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 2 + * 3 + * Declarations for the PF1550 PMIC 4 + * 5 + * Copyright (C) 2016 Freescale Semiconductor, Inc. 6 + * Robin Gong <yibin.gong@freescale.com> 7 + * 8 + * Portions Copyright (c) 2025 Savoir-faire Linux Inc. 9 + * Samuel Kayode <samuel.kayode@savoirfairelinux.com> 10 + */ 11 + 12 + #ifndef __LINUX_MFD_PF1550_H 13 + #define __LINUX_MFD_PF1550_H 14 + 15 + #include <linux/i2c.h> 16 + #include <linux/regmap.h> 17 + 18 + enum pf1550_pmic_reg { 19 + /* PMIC regulator part */ 20 + PF1550_PMIC_REG_DEVICE_ID = 0x00, 21 + PF1550_PMIC_REG_OTP_FLAVOR = 0x01, 22 + PF1550_PMIC_REG_SILICON_REV = 0x02, 23 + 24 + PF1550_PMIC_REG_INT_CATEGORY = 0x06, 25 + PF1550_PMIC_REG_SW_INT_STAT0 = 0x08, 26 + PF1550_PMIC_REG_SW_INT_MASK0 = 0x09, 27 + PF1550_PMIC_REG_SW_INT_SENSE0 = 0x0a, 28 + PF1550_PMIC_REG_SW_INT_STAT1 = 0x0b, 29 + PF1550_PMIC_REG_SW_INT_MASK1 = 0x0c, 30 + PF1550_PMIC_REG_SW_INT_SENSE1 = 0x0d, 31 + PF1550_PMIC_REG_SW_INT_STAT2 = 0x0e, 32 + PF1550_PMIC_REG_SW_INT_MASK2 = 0x0f, 33 + PF1550_PMIC_REG_SW_INT_SENSE2 = 0x10, 34 + PF1550_PMIC_REG_LDO_INT_STAT0 = 0x18, 35 + PF1550_PMIC_REG_LDO_INT_MASK0 = 0x19, 36 + PF1550_PMIC_REG_LDO_INT_SENSE0 = 0x1a, 37 + PF1550_PMIC_REG_TEMP_INT_STAT0 = 0x20, 38 + PF1550_PMIC_REG_TEMP_INT_MASK0 = 0x21, 39 + PF1550_PMIC_REG_TEMP_INT_SENSE0 = 0x22, 40 + PF1550_PMIC_REG_ONKEY_INT_STAT0 = 0x24, 41 + PF1550_PMIC_REG_ONKEY_INT_MASK0 = 0x25, 42 + PF1550_PMIC_REG_ONKEY_INT_SENSE0 = 0x26, 43 + PF1550_PMIC_REG_MISC_INT_STAT0 = 0x28, 44 + PF1550_PMIC_REG_MISC_INT_MASK0 = 0x29, 45 + PF1550_PMIC_REG_MISC_INT_SENSE0 = 0x2a, 46 + 47 + PF1550_PMIC_REG_COINCELL_CONTROL = 0x30, 48 + 49 + PF1550_PMIC_REG_SW1_VOLT = 0x32, 50 + PF1550_PMIC_REG_SW1_STBY_VOLT = 0x33, 51 + PF1550_PMIC_REG_SW1_SLP_VOLT = 0x34, 52 + PF1550_PMIC_REG_SW1_CTRL = 0x35, 53 + PF1550_PMIC_REG_SW1_CTRL1 = 0x36, 54 + PF1550_PMIC_REG_SW2_VOLT = 0x38, 55 + PF1550_PMIC_REG_SW2_STBY_VOLT = 0x39, 56 + PF1550_PMIC_REG_SW2_SLP_VOLT = 0x3a, 57 + PF1550_PMIC_REG_SW2_CTRL = 0x3b, 58 + PF1550_PMIC_REG_SW2_CTRL1 = 0x3c, 59 + PF1550_PMIC_REG_SW3_VOLT = 0x3e, 60 + PF1550_PMIC_REG_SW3_STBY_VOLT = 0x3f, 61 + PF1550_PMIC_REG_SW3_SLP_VOLT = 0x40, 62 + PF1550_PMIC_REG_SW3_CTRL = 0x41, 63 + PF1550_PMIC_REG_SW3_CTRL1 = 0x42, 64 + PF1550_PMIC_REG_VSNVS_CTRL = 0x48, 65 + PF1550_PMIC_REG_VREFDDR_CTRL = 0x4a, 66 + PF1550_PMIC_REG_LDO1_VOLT = 0x4c, 67 + PF1550_PMIC_REG_LDO1_CTRL = 0x4d, 68 + PF1550_PMIC_REG_LDO2_VOLT = 0x4f, 69 + PF1550_PMIC_REG_LDO2_CTRL = 0x50, 70 + PF1550_PMIC_REG_LDO3_VOLT = 0x52, 71 + PF1550_PMIC_REG_LDO3_CTRL = 0x53, 72 + PF1550_PMIC_REG_PWRCTRL0 = 0x58, 73 + PF1550_PMIC_REG_PWRCTRL1 = 0x59, 74 + PF1550_PMIC_REG_PWRCTRL2 = 0x5a, 75 + PF1550_PMIC_REG_PWRCTRL3 = 0x5b, 76 + PF1550_PMIC_REG_SW1_PWRDN_SEQ = 0x5f, 77 + PF1550_PMIC_REG_SW2_PWRDN_SEQ = 0x60, 78 + PF1550_PMIC_REG_SW3_PWRDN_SEQ = 0x61, 79 + PF1550_PMIC_REG_LDO1_PWRDN_SEQ = 0x62, 80 + PF1550_PMIC_REG_LDO2_PWRDN_SEQ = 0x63, 81 + PF1550_PMIC_REG_LDO3_PWRDN_SEQ = 0x64, 82 + PF1550_PMIC_REG_VREFDDR_PWRDN_SEQ = 0x65, 83 + 84 + PF1550_PMIC_REG_STATE_INFO = 0x67, 85 + PF1550_PMIC_REG_I2C_ADDR = 0x68, 86 + PF1550_PMIC_REG_IO_DRV0 = 0x69, 87 + PF1550_PMIC_REG_IO_DRV1 = 0x6a, 88 + PF1550_PMIC_REG_RC_16MHZ = 0x6b, 89 + PF1550_PMIC_REG_KEY = 0x6f, 90 + 91 + /* Charger part */ 92 + PF1550_CHARG_REG_CHG_INT = 0x80, 93 + PF1550_CHARG_REG_CHG_INT_MASK = 0x82, 94 + PF1550_CHARG_REG_CHG_INT_OK = 0x84, 95 + PF1550_CHARG_REG_VBUS_SNS = 0x86, 96 + PF1550_CHARG_REG_CHG_SNS = 0x87, 97 + PF1550_CHARG_REG_BATT_SNS = 0x88, 98 + PF1550_CHARG_REG_CHG_OPER = 0x89, 99 + PF1550_CHARG_REG_CHG_TMR = 0x8a, 100 + PF1550_CHARG_REG_CHG_EOC_CNFG = 0x8d, 101 + PF1550_CHARG_REG_CHG_CURR_CNFG = 0x8e, 102 + PF1550_CHARG_REG_BATT_REG = 0x8f, 103 + PF1550_CHARG_REG_BATFET_CNFG = 0x91, 104 + PF1550_CHARG_REG_THM_REG_CNFG = 0x92, 105 + PF1550_CHARG_REG_VBUS_INLIM_CNFG = 0x94, 106 + PF1550_CHARG_REG_VBUS_LIN_DPM = 0x95, 107 + PF1550_CHARG_REG_USB_PHY_LDO_CNFG = 0x96, 108 + PF1550_CHARG_REG_DBNC_DELAY_TIME = 0x98, 109 + PF1550_CHARG_REG_CHG_INT_CNFG = 0x99, 110 + PF1550_CHARG_REG_THM_ADJ_SETTING = 0x9a, 111 + PF1550_CHARG_REG_VBUS2SYS_CNFG = 0x9b, 112 + PF1550_CHARG_REG_LED_PWM = 0x9c, 113 + PF1550_CHARG_REG_FAULT_BATFET_CNFG = 0x9d, 114 + PF1550_CHARG_REG_LED_CNFG = 0x9e, 115 + PF1550_CHARG_REG_CHGR_KEY2 = 0x9f, 116 + 117 + PF1550_TEST_REG_FMRADDR = 0xc4, 118 + PF1550_TEST_REG_FMRDATA = 0xc5, 119 + PF1550_TEST_REG_KEY3 = 0xdf, 120 + 121 + PF1550_PMIC_REG_END = 0xff, 122 + }; 123 + 124 + /* One-Time Programmable(OTP) memory */ 125 + enum pf1550_otp_reg { 126 + PF1550_OTP_SW1_SW2 = 0x1e, 127 + PF1550_OTP_SW2_SW3 = 0x1f, 128 + }; 129 + 130 + #define PF1550_DEVICE_ID 0x7c 131 + 132 + /* Keys for reading OTP */ 133 + #define PF1550_OTP_PMIC_KEY 0x15 134 + #define PF1550_OTP_CHGR_KEY 0x50 135 + #define PF1550_OTP_TEST_KEY 0xab 136 + 137 + /* Supported charger modes */ 138 + #define PF1550_CHG_BAT_OFF 1 139 + #define PF1550_CHG_BAT_ON 2 140 + 141 + #define PF1550_CHG_PRECHARGE 0 142 + #define PF1550_CHG_CONSTANT_CURRENT 1 143 + #define PF1550_CHG_CONSTANT_VOL 2 144 + #define PF1550_CHG_EOC 3 145 + #define PF1550_CHG_DONE 4 146 + #define PF1550_CHG_TIMER_FAULT 6 147 + #define PF1550_CHG_SUSPEND 7 148 + #define PF1550_CHG_OFF_INV 8 149 + #define PF1550_CHG_BAT_OVER 9 150 + #define PF1550_CHG_OFF_TEMP 10 151 + #define PF1550_CHG_LINEAR_ONLY 12 152 + #define PF1550_CHG_SNS_MASK 0xf 153 + #define PF1550_CHG_INT_MASK 0x51 154 + 155 + #define PF1550_BAT_NO_VBUS 0 156 + #define PF1550_BAT_LOW_THAN_PRECHARG 1 157 + #define PF1550_BAT_CHARG_FAIL 2 158 + #define PF1550_BAT_HIGH_THAN_PRECHARG 4 159 + #define PF1550_BAT_OVER_VOL 5 160 + #define PF1550_BAT_NO_DETECT 6 161 + #define PF1550_BAT_SNS_MASK 0x7 162 + 163 + #define PF1550_VBUS_UVLO BIT(2) 164 + #define PF1550_VBUS_IN2SYS BIT(3) 165 + #define PF1550_VBUS_OVLO BIT(4) 166 + #define PF1550_VBUS_VALID BIT(5) 167 + 168 + #define PF1550_CHARG_REG_BATT_REG_CHGCV_MASK 0x3f 169 + #define PF1550_CHARG_REG_BATT_REG_VMINSYS_SHIFT 6 170 + #define PF1550_CHARG_REG_BATT_REG_VMINSYS_MASK GENMASK(7, 6) 171 + #define PF1550_CHARG_REG_THM_REG_CNFG_REGTEMP_SHIFT 2 172 + #define PF1550_CHARG_REG_THM_REG_CNFG_REGTEMP_MASK GENMASK(3, 2) 173 + 174 + #define PF1550_ONKEY_RST_EN BIT(7) 175 + 176 + /* DVS enable masks */ 177 + #define OTP_SW1_DVS_ENB BIT(1) 178 + #define OTP_SW2_DVS_ENB BIT(3) 179 + 180 + /* Top level interrupt masks */ 181 + #define IRQ_REGULATOR (BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(6)) 182 + #define IRQ_ONKEY BIT(5) 183 + #define IRQ_CHG BIT(0) 184 + 185 + /* Regulator interrupt masks */ 186 + #define PMIC_IRQ_SW1_LS BIT(0) 187 + #define PMIC_IRQ_SW2_LS BIT(1) 188 + #define PMIC_IRQ_SW3_LS BIT(2) 189 + #define PMIC_IRQ_SW1_HS BIT(0) 190 + #define PMIC_IRQ_SW2_HS BIT(1) 191 + #define PMIC_IRQ_SW3_HS BIT(2) 192 + #define PMIC_IRQ_LDO1_FAULT BIT(0) 193 + #define PMIC_IRQ_LDO2_FAULT BIT(1) 194 + #define PMIC_IRQ_LDO3_FAULT BIT(2) 195 + #define PMIC_IRQ_TEMP_110 BIT(0) 196 + #define PMIC_IRQ_TEMP_125 BIT(1) 197 + 198 + /* Onkey interrupt masks */ 199 + #define ONKEY_IRQ_PUSHI BIT(0) 200 + #define ONKEY_IRQ_1SI BIT(1) 201 + #define ONKEY_IRQ_2SI BIT(2) 202 + #define ONKEY_IRQ_3SI BIT(3) 203 + #define ONKEY_IRQ_4SI BIT(4) 204 + #define ONKEY_IRQ_8SI BIT(5) 205 + 206 + /* Charger interrupt masks */ 207 + #define CHARG_IRQ_BAT2SOCI BIT(1) 208 + #define CHARG_IRQ_BATI BIT(2) 209 + #define CHARG_IRQ_CHGI BIT(3) 210 + #define CHARG_IRQ_VBUSI BIT(5) 211 + #define CHARG_IRQ_DPMI BIT(6) 212 + #define CHARG_IRQ_THMI BIT(7) 213 + 214 + enum pf1550_irq { 215 + PF1550_IRQ_CHG, 216 + PF1550_IRQ_REGULATOR, 217 + PF1550_IRQ_ONKEY, 218 + }; 219 + 220 + enum pf1550_pmic_irq { 221 + PF1550_PMIC_IRQ_SW1_LS, 222 + PF1550_PMIC_IRQ_SW2_LS, 223 + PF1550_PMIC_IRQ_SW3_LS, 224 + PF1550_PMIC_IRQ_SW1_HS, 225 + PF1550_PMIC_IRQ_SW2_HS, 226 + PF1550_PMIC_IRQ_SW3_HS, 227 + PF1550_PMIC_IRQ_LDO1_FAULT, 228 + PF1550_PMIC_IRQ_LDO2_FAULT, 229 + PF1550_PMIC_IRQ_LDO3_FAULT, 230 + PF1550_PMIC_IRQ_TEMP_110, 231 + PF1550_PMIC_IRQ_TEMP_125, 232 + }; 233 + 234 + enum pf1550_onkey_irq { 235 + PF1550_ONKEY_IRQ_PUSHI, 236 + PF1550_ONKEY_IRQ_1SI, 237 + PF1550_ONKEY_IRQ_2SI, 238 + PF1550_ONKEY_IRQ_3SI, 239 + PF1550_ONKEY_IRQ_4SI, 240 + PF1550_ONKEY_IRQ_8SI, 241 + }; 242 + 243 + enum pf1550_charg_irq { 244 + PF1550_CHARG_IRQ_BAT2SOCI, 245 + PF1550_CHARG_IRQ_BATI, 246 + PF1550_CHARG_IRQ_CHGI, 247 + PF1550_CHARG_IRQ_VBUSI, 248 + PF1550_CHARG_IRQ_THMI, 249 + }; 250 + 251 + enum pf1550_regulators { 252 + PF1550_SW1, 253 + PF1550_SW2, 254 + PF1550_SW3, 255 + PF1550_VREFDDR, 256 + PF1550_LDO1, 257 + PF1550_LDO2, 258 + PF1550_LDO3, 259 + }; 260 + 261 + struct pf1550_ddata { 262 + struct regmap_irq_chip_data *irq_data_regulator; 263 + struct regmap_irq_chip_data *irq_data_charger; 264 + struct regmap_irq_chip_data *irq_data_onkey; 265 + struct regmap_irq_chip_data *irq_data; 266 + struct regmap *regmap; 267 + struct device *dev; 268 + bool dvs1_enable; 269 + bool dvs2_enable; 270 + int irq; 271 + }; 272 + 273 + #endif /* __LINUX_MFD_PF1550_H */