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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'regulator-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator updates from Mark Brown:
"This has been a very quiet release, we've got support for one device
added, another removed, and some smaller fixes and API improvements.

The main thing of note is the rework of the PCA9450 LDO5 handling.

- A rework of the handling of LDO5 on the PCA9450, this was quite
wrong in how it handled the SD_VSEL conrol and only worked for some
system designs. This includes a DTS update since there was a not
quite ABI compatible change as part of the fix

- A devres change introducing devm_kmemdup_array() was pulled in so
it could be used with some regulator conversions to that function,
this pulled in some other devres and IIO stuff that was part of the
same pull request

- Removal of the PCF50633 driver, the SoC for the OpenMoko platform
that used it has been removed

- Support for the NXP PF9453"

* tag 'regulator-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (24 commits)
regulator: axp20x: AXP717: dcdc4 doesn't have delay
regulator: dt-bindings: rtq2208: Cleanup whitespace
regulator: dt-bindings: rtq2208: Mark fixed LDO VOUT property as deprecated
regulator: rtq6752: make const read-only array fault_mask static
regulator: pf9453: add PMIC PF9453 support
regulator: dt-bindings: pca9450: Add nxp,pf9453 compatible string
regulator: pcf50633-regulator: Remove
regulator: pca9450: Handle hardware with fixed SD_VSEL for LDO5
regulator: cros-ec: use devm_kmemdup_array()
regulator: devres: use devm_kmemdup_array()
regulator: Add (devm_)of_regulator_get()
devres: Introduce devm_kmemdup_array()
iio: imu: st_lsm9ds0: Replace device.h with what is needed
driver core: Split devres APIs to device/devres.h
err.h: move IOMEM_ERR_PTR() to err.h
regulator: pca9450: Remove duplicate code in probe
regulator: ad5398: Fix incorrect power down bit mask
regulator: pca9450: Fix enable register for LDO5
regulator: pca9450: Fix control register for LDO5
Revert "regulator: pca9450: Add SD_VSEL GPIO for LDO5"
...

+1221 -304
+45 -6
Documentation/devicetree/bindings/regulator/nxp,pca9450-regulator.yaml
··· 17 17 Datasheet is available at 18 18 https://www.nxp.com/docs/en/data-sheet/PCA9450DS.pdf 19 19 20 + Support PF9453, Datasheet is available at 21 + https://www.nxp.com/docs/en/data-sheet/PF9453_SDS.pdf 22 + 20 23 # The valid names for PCA9450 regulator nodes are: 21 24 # BUCK1, BUCK2, BUCK3, BUCK4, BUCK5, BUCK6, 22 25 # LDO1, LDO2, LDO3, LDO4, LDO5 ··· 33 30 - nxp,pca9450c 34 31 - nxp,pca9451a 35 32 - nxp,pca9452 33 + - nxp,pf9453 36 34 37 35 reg: 38 36 maxItems: 1 ··· 46 42 description: | 47 43 list of regulators provided by this controller 48 44 45 + properties: 46 + LDO5: 47 + type: object 48 + $ref: regulator.yaml# 49 + description: 50 + Properties for single LDO5 regulator. 51 + 52 + properties: 53 + nxp,sd-vsel-fixed-low: 54 + type: boolean 55 + description: 56 + Let the driver know that SD_VSEL is hardwired to low level and 57 + there is no GPIO to get the actual value from. 58 + 59 + sd-vsel-gpios: 60 + description: 61 + GPIO that can be used to read the current status of the SD_VSEL 62 + signal in order for the driver to know if LDO5CTRL_L or LDO5CTRL_H 63 + is used by the hardware. 64 + 65 + unevaluatedProperties: false 66 + 49 67 patternProperties: 50 - "^LDO[1-5]$": 68 + "^LDO([1-4]|-SNVS)$": 51 69 type: object 52 70 $ref: regulator.yaml# 53 71 description: ··· 104 78 105 79 additionalProperties: false 106 80 107 - sd-vsel-gpios: 108 - description: GPIO that is used to switch LDO5 between being configured by 109 - LDO5CTRL_L or LDO5CTRL_H register. Use this if the SD_VSEL signal is 110 - connected to a host GPIO. 111 - 112 81 nxp,i2c-lt-enable: 113 82 type: boolean 114 83 description: ··· 121 100 - regulators 122 101 123 102 additionalProperties: false 103 + 104 + allOf: 105 + - if: 106 + properties: 107 + compatible: 108 + contains: 109 + const: nxp,pf9453 110 + then: 111 + properties: 112 + regulators: 113 + patternProperties: 114 + "^LDO[3-4]$": false 115 + "^BUCK[5-6]$": false 116 + else: 117 + properties: 118 + regulators: 119 + properties: 120 + LDO-SNVS: false 124 121 125 122 examples: 126 123 - |
+2 -1
Documentation/devicetree/bindings/regulator/richtek,rtq2208.yaml
··· 39 39 40 40 interrupts: 41 41 maxItems: 1 42 - 42 + 43 43 richtek,mtp-sel-high: 44 44 type: boolean 45 45 description: ··· 77 77 78 78 properties: 79 79 richtek,fixed-microvolt: 80 + deprecated: true 80 81 description: | 81 82 This property can be used to set a fixed operating voltage that lies outside 82 83 the range of the regulator's adjustable mode.
+3 -2
arch/arm64/boot/dts/freescale/imx8mp-skov-reva.dtsi
··· 232 232 pinctrl-names = "default"; 233 233 pinctrl-0 = <&pinctrl_pmic>; 234 234 interrupts-extended = <&gpio1 3 IRQ_TYPE_EDGE_RISING>; 235 - sd-vsel-gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>; 236 235 237 236 regulators { 238 237 reg_vdd_soc: BUCK1 { ··· 554 555 pinctrl_pmic: pmicirqgrp { 555 556 fsl,pins = < 556 557 MX8MP_IOMUXC_GPIO1_IO03__GPIO1_IO03 0x41 557 - MX8MP_IOMUXC_GPIO1_IO04__GPIO1_IO04 0x41 558 558 >; 559 559 }; 560 560 ··· 621 623 MX8MP_IOMUXC_SD2_DATA1__USDHC2_DATA1 0x1d0 622 624 MX8MP_IOMUXC_SD2_DATA2__USDHC2_DATA2 0x1d0 623 625 MX8MP_IOMUXC_SD2_DATA3__USDHC2_DATA3 0x1d0 626 + MX8MP_IOMUXC_GPIO1_IO04__USDHC2_VSELECT 0xc0 624 627 >; 625 628 }; 626 629 ··· 633 634 MX8MP_IOMUXC_SD2_DATA1__USDHC2_DATA1 0x1d4 634 635 MX8MP_IOMUXC_SD2_DATA2__USDHC2_DATA2 0x1d4 635 636 MX8MP_IOMUXC_SD2_DATA3__USDHC2_DATA3 0x1d4 637 + MX8MP_IOMUXC_GPIO1_IO04__USDHC2_VSELECT 0xc0 636 638 >; 637 639 }; 638 640 ··· 645 645 MX8MP_IOMUXC_SD2_DATA1__USDHC2_DATA1 0x1d6 646 646 MX8MP_IOMUXC_SD2_DATA2__USDHC2_DATA2 0x1d6 647 647 MX8MP_IOMUXC_SD2_DATA3__USDHC2_DATA3 0x1d6 648 + MX8MP_IOMUXC_GPIO1_IO04__USDHC2_VSELECT 0xc0 648 649 >; 649 650 }; 650 651
+1 -1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
··· 7 7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 8 8 */ 9 9 10 - #include <linux/device.h> 10 + #include <linux/device/devres.h> 11 11 #include <linux/err.h> 12 12 #include <linux/gfp_types.h> 13 13 #include <linux/i2c.h>
+1 -1
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
··· 7 7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 8 8 */ 9 9 10 - #include <linux/device.h> 10 + #include <linux/device/devres.h> 11 11 #include <linux/err.h> 12 12 #include <linux/gfp_types.h> 13 13 #include <linux/module.h>
+7 -7
drivers/regulator/Kconfig
··· 981 981 Say y here to support the NXP PCA9450A/PCA9450B/PCA9450C PMIC 982 982 regulator driver. 983 983 984 + config REGULATOR_PF9453 985 + tristate "NXP PF9453 regulator driver" 986 + depends on I2C 987 + select REGMAP_I2C 988 + help 989 + Say y here to support the NXP PF9453 PMIC regulator driver. 990 + 984 991 config REGULATOR_PCAP 985 992 tristate "Motorola PCAP2 regulator driver" 986 993 depends on EZX_PCAP 987 994 help 988 995 This driver provides support for the voltage regulators of the 989 996 PCAP2 PMIC. 990 - 991 - config REGULATOR_PCF50633 992 - tristate "NXP PCF50633 regulator driver" 993 - depends on MFD_PCF50633 994 - help 995 - Say Y here to support the voltage regulators and converters 996 - on PCF50633 997 997 998 998 config REGULATOR_PF8X00 999 999 tristate "NXP PF8100/PF8121A/PF8200 regulator driver"
+1 -1
drivers/regulator/Makefile
··· 123 123 obj-$(CONFIG_REGULATOR_QCOM_USB_VBUS) += qcom_usb_vbus-regulator.o 124 124 obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o 125 125 obj-$(CONFIG_REGULATOR_PCA9450) += pca9450-regulator.o 126 + obj-$(CONFIG_REGULATOR_PF9453) += pf9453-regulator.o 126 127 obj-$(CONFIG_REGULATOR_PF8X00) += pf8x00-regulator.o 127 128 obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o 128 129 obj-$(CONFIG_REGULATOR_PV88060) += pv88060-regulator.o ··· 133 132 obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o 134 133 obj-$(CONFIG_REGULATOR_PBIAS) += pbias-regulator.o 135 134 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 136 - obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 137 135 obj-$(CONFIG_REGULATOR_RAA215300) += raa215300.o 138 136 obj-$(CONFIG_REGULATOR_RASPBERRYPI_TOUCHSCREEN_ATTINY) += rpi-panel-attiny-regulator.o 139 137 obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
+18 -12
drivers/regulator/ad5398.c
··· 14 14 #include <linux/platform_device.h> 15 15 #include <linux/regulator/driver.h> 16 16 #include <linux/regulator/machine.h> 17 + #include <linux/regulator/of_regulator.h> 17 18 18 - #define AD5398_CURRENT_EN_MASK 0x8000 19 + #define AD5398_SW_POWER_DOWN BIT(15) 19 20 20 21 struct ad5398_chip_info { 21 22 struct i2c_client *client; ··· 114 113 115 114 /* prepare register data */ 116 115 selector = (selector << chip->current_offset) & chip->current_mask; 117 - data = (unsigned short)selector | (data & AD5398_CURRENT_EN_MASK); 116 + data = (unsigned short)selector | (data & AD5398_SW_POWER_DOWN); 118 117 119 118 /* write the new current value back as well as enable bit */ 120 119 ret = ad5398_write_reg(client, data); ··· 133 132 if (ret < 0) 134 133 return ret; 135 134 136 - if (data & AD5398_CURRENT_EN_MASK) 137 - return 1; 138 - else 135 + if (data & AD5398_SW_POWER_DOWN) 139 136 return 0; 137 + else 138 + return 1; 140 139 } 141 140 142 141 static int ad5398_enable(struct regulator_dev *rdev) ··· 150 149 if (ret < 0) 151 150 return ret; 152 151 153 - if (data & AD5398_CURRENT_EN_MASK) 152 + if (!(data & AD5398_SW_POWER_DOWN)) 154 153 return 0; 155 154 156 - data |= AD5398_CURRENT_EN_MASK; 155 + data &= ~AD5398_SW_POWER_DOWN; 157 156 158 157 ret = ad5398_write_reg(client, data); 159 158 ··· 171 170 if (ret < 0) 172 171 return ret; 173 172 174 - if (!(data & AD5398_CURRENT_EN_MASK)) 173 + if (data & AD5398_SW_POWER_DOWN) 175 174 return 0; 176 175 177 - data &= ~AD5398_CURRENT_EN_MASK; 176 + data |= AD5398_SW_POWER_DOWN; 178 177 179 178 ret = ad5398_write_reg(client, data); 180 179 ··· 222 221 const struct ad5398_current_data_format *df = 223 222 (struct ad5398_current_data_format *)id->driver_data; 224 223 225 - if (!init_data) 226 - return -EINVAL; 227 - 228 224 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 229 225 if (!chip) 230 226 return -ENOMEM; 231 227 232 228 config.dev = &client->dev; 229 + if (client->dev.of_node) 230 + init_data = of_get_regulator_init_data(&client->dev, 231 + client->dev.of_node, 232 + &ad5398_reg); 233 + if (!init_data) 234 + return -EINVAL; 235 + 233 236 config.init_data = init_data; 237 + config.of_node = client->dev.of_node; 234 238 config.driver_data = chip; 235 239 236 240 chip->client = client;
+4 -10
drivers/regulator/axp20x-regulator.c
··· 371 371 .ops = &axp20x_ops, \ 372 372 } 373 373 374 - #define AXP_DESC_DELAY(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 375 - _vmask, _ereg, _emask, _ramp_delay) \ 374 + #define AXP_DESC(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 375 + _vmask, _ereg, _emask) \ 376 376 [_family##_##_id] = { \ 377 377 .name = (_match), \ 378 378 .supply_name = (_supply), \ ··· 388 388 .vsel_mask = (_vmask), \ 389 389 .enable_reg = (_ereg), \ 390 390 .enable_mask = (_emask), \ 391 - .ramp_delay = (_ramp_delay), \ 392 391 .ops = &axp20x_ops, \ 393 392 } 394 - 395 - #define AXP_DESC(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 396 - _vmask, _ereg, _emask) \ 397 - AXP_DESC_DELAY(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 398 - _vmask, _ereg, _emask, 0) 399 393 400 394 #define AXP_DESC_SW(_family, _id, _match, _supply, _ereg, _emask) \ 401 395 [_family##_##_id] = { \ ··· 799 805 axp717_dcdc3_ranges, AXP717_DCDC3_NUM_VOLTAGES, 800 806 AXP717_DCDC3_CONTROL, AXP717_DCDC_V_OUT_MASK, 801 807 AXP717_DCDC_OUTPUT_CONTROL, BIT(2), 640), 802 - AXP_DESC_DELAY(AXP717, DCDC4, "dcdc4", "vin4", 1000, 3700, 100, 808 + AXP_DESC(AXP717, DCDC4, "dcdc4", "vin4", 1000, 3700, 100, 803 809 AXP717_DCDC4_CONTROL, AXP717_DCDC_V_OUT_MASK, 804 - AXP717_DCDC_OUTPUT_CONTROL, BIT(3), 6400), 810 + AXP717_DCDC_OUTPUT_CONTROL, BIT(3)), 805 811 AXP_DESC(AXP717, ALDO1, "aldo1", "aldoin", 500, 3500, 100, 806 812 AXP717_ALDO1_CONTROL, AXP717_LDO_V_OUT_MASK, 807 813 AXP717_LDO0_OUTPUT_CONTROL, BIT(0)),
+2 -2
drivers/regulator/cros-ec-regulator.c
··· 138 138 data->num_voltages = 139 139 min_t(u16, ARRAY_SIZE(resp.voltages_mv), resp.num_voltages); 140 140 data->voltages_mV = 141 - devm_kmemdup(dev, resp.voltages_mv, 142 - sizeof(u16) * data->num_voltages, GFP_KERNEL); 141 + devm_kmemdup_array(dev, resp.voltages_mv, data->num_voltages, 142 + sizeof(resp.voltages_mv[0]), GFP_KERNEL); 143 143 if (!data->voltages_mV) 144 144 return -ENOMEM; 145 145
+19 -3
drivers/regulator/devres.c
··· 332 332 const struct regulator_bulk_data *in_consumers, 333 333 struct regulator_bulk_data **out_consumers) 334 334 { 335 - *out_consumers = devm_kmemdup(dev, in_consumers, 336 - num_consumers * sizeof(*in_consumers), 337 - GFP_KERNEL); 335 + *out_consumers = devm_kmemdup_array(dev, in_consumers, num_consumers, 336 + sizeof(*in_consumers), GFP_KERNEL); 338 337 if (*out_consumers == NULL) 339 338 return -ENOMEM; 340 339 ··· 769 770 770 771 return regulator; 771 772 } 773 + 774 + /** 775 + * devm_of_regulator_get - Resource managed of_regulator_get() 776 + * @dev: device used for dev_printk() messages and resource lifetime management 777 + * @node: device node for regulator "consumer" 778 + * @id: supply name or regulator ID. 779 + * 780 + * Managed of_regulator_get(). Regulators returned from this 781 + * function are automatically regulator_put() on driver detach. See 782 + * of_regulator_get() for more information. 783 + */ 784 + struct regulator *devm_of_regulator_get(struct device *dev, struct device_node *node, 785 + const char *id) 786 + { 787 + return _devm_of_regulator_get(dev, node, id, NORMAL_GET); 788 + } 789 + EXPORT_SYMBOL_GPL(devm_of_regulator_get); 772 790 773 791 /** 774 792 * devm_of_regulator_get_optional - Resource managed of_regulator_get_optional()
+21
drivers/regulator/of_regulator.c
··· 698 698 } 699 699 700 700 /** 701 + * of_regulator_get - get regulator via device tree lookup 702 + * @dev: device used for dev_printk() messages 703 + * @node: device node for regulator "consumer" 704 + * @id: Supply name 705 + * 706 + * Return: pointer to struct regulator corresponding to the regulator producer, 707 + * or PTR_ERR() encoded error number. 708 + * 709 + * This is intended for use by consumers that want to get a regulator 710 + * supply directly from a device node. This will _not_ consider supply 711 + * aliases. See regulator_dev_lookup(). 712 + */ 713 + struct regulator *of_regulator_get(struct device *dev, 714 + struct device_node *node, 715 + const char *id) 716 + { 717 + return _of_regulator_get(dev, node, id, NORMAL_GET); 718 + } 719 + EXPORT_SYMBOL_GPL(of_regulator_get); 720 + 721 + /** 701 722 * of_regulator_get_optional - get optional regulator via device tree lookup 702 723 * @dev: device used for dev_printk() messages 703 724 * @node: device node for regulator "consumer"
+78 -13
drivers/regulator/pca9450-regulator.c
··· 36 36 enum pca9450_chip_type type; 37 37 unsigned int rcnt; 38 38 int irq; 39 + bool sd_vsel_fixed_low; 39 40 }; 40 41 41 42 static const struct regmap_range pca9450_status_range = { ··· 97 96 .list_voltage = regulator_list_voltage_linear_range, 98 97 .set_voltage_sel = regulator_set_voltage_sel_regmap, 99 98 .get_voltage_sel = regulator_get_voltage_sel_regmap, 99 + }; 100 + 101 + static unsigned int pca9450_ldo5_get_reg_voltage_sel(struct regulator_dev *rdev) 102 + { 103 + struct pca9450 *pca9450 = rdev_get_drvdata(rdev); 104 + 105 + if (pca9450->sd_vsel_fixed_low) 106 + return PCA9450_REG_LDO5CTRL_L; 107 + 108 + if (pca9450->sd_vsel_gpio && !gpiod_get_value(pca9450->sd_vsel_gpio)) 109 + return PCA9450_REG_LDO5CTRL_L; 110 + 111 + return rdev->desc->vsel_reg; 112 + } 113 + 114 + static int pca9450_ldo5_get_voltage_sel_regmap(struct regulator_dev *rdev) 115 + { 116 + unsigned int val; 117 + int ret; 118 + 119 + ret = regmap_read(rdev->regmap, pca9450_ldo5_get_reg_voltage_sel(rdev), &val); 120 + if (ret != 0) 121 + return ret; 122 + 123 + val &= rdev->desc->vsel_mask; 124 + val >>= ffs(rdev->desc->vsel_mask) - 1; 125 + 126 + return val; 127 + } 128 + 129 + static int pca9450_ldo5_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned int sel) 130 + { 131 + int ret; 132 + 133 + sel <<= ffs(rdev->desc->vsel_mask) - 1; 134 + 135 + ret = regmap_update_bits(rdev->regmap, pca9450_ldo5_get_reg_voltage_sel(rdev), 136 + rdev->desc->vsel_mask, sel); 137 + if (ret) 138 + return ret; 139 + 140 + if (rdev->desc->apply_bit) 141 + ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg, 142 + rdev->desc->apply_bit, 143 + rdev->desc->apply_bit); 144 + return ret; 145 + } 146 + 147 + static const struct regulator_ops pca9450_ldo5_regulator_ops = { 148 + .enable = regulator_enable_regmap, 149 + .disable = regulator_disable_regmap, 150 + .is_enabled = regulator_is_enabled_regmap, 151 + .list_voltage = regulator_list_voltage_linear_range, 152 + .set_voltage_sel = pca9450_ldo5_set_voltage_sel_regmap, 153 + .get_voltage_sel = pca9450_ldo5_get_voltage_sel_regmap, 100 154 }; 101 155 102 156 /* ··· 509 453 .of_match = of_match_ptr("LDO5"), 510 454 .regulators_node = of_match_ptr("regulators"), 511 455 .id = PCA9450_LDO5, 512 - .ops = &pca9450_ldo_regulator_ops, 456 + .ops = &pca9450_ldo5_regulator_ops, 513 457 .type = REGULATOR_VOLTAGE, 514 458 .n_voltages = PCA9450_LDO5_VOLTAGE_NUM, 515 459 .linear_ranges = pca9450_ldo5_volts, 516 460 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts), 517 461 .vsel_reg = PCA9450_REG_LDO5CTRL_H, 518 462 .vsel_mask = LDO5HOUT_MASK, 519 - .enable_reg = PCA9450_REG_LDO5CTRL_H, 463 + .enable_reg = PCA9450_REG_LDO5CTRL_L, 520 464 .enable_mask = LDO5H_EN_MASK, 521 465 .owner = THIS_MODULE, 522 466 }, ··· 723 667 .of_match = of_match_ptr("LDO5"), 724 668 .regulators_node = of_match_ptr("regulators"), 725 669 .id = PCA9450_LDO5, 726 - .ops = &pca9450_ldo_regulator_ops, 670 + .ops = &pca9450_ldo5_regulator_ops, 727 671 .type = REGULATOR_VOLTAGE, 728 672 .n_voltages = PCA9450_LDO5_VOLTAGE_NUM, 729 673 .linear_ranges = pca9450_ldo5_volts, 730 674 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts), 731 675 .vsel_reg = PCA9450_REG_LDO5CTRL_H, 732 676 .vsel_mask = LDO5HOUT_MASK, 733 - .enable_reg = PCA9450_REG_LDO5CTRL_H, 677 + .enable_reg = PCA9450_REG_LDO5CTRL_L, 734 678 .enable_mask = LDO5H_EN_MASK, 735 679 .owner = THIS_MODULE, 736 680 }, ··· 913 857 .of_match = of_match_ptr("LDO5"), 914 858 .regulators_node = of_match_ptr("regulators"), 915 859 .id = PCA9450_LDO5, 916 - .ops = &pca9450_ldo_regulator_ops, 860 + .ops = &pca9450_ldo5_regulator_ops, 917 861 .type = REGULATOR_VOLTAGE, 918 862 .n_voltages = PCA9450_LDO5_VOLTAGE_NUM, 919 863 .linear_ranges = pca9450_ldo5_volts, 920 864 .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts), 921 865 .vsel_reg = PCA9450_REG_LDO5CTRL_H, 922 866 .vsel_mask = LDO5HOUT_MASK, 923 - .enable_reg = PCA9450_REG_LDO5CTRL_H, 867 + .enable_reg = PCA9450_REG_LDO5CTRL_L, 924 868 .enable_mask = LDO5H_EN_MASK, 925 869 .owner = THIS_MODULE, 926 870 }, ··· 971 915 of_device_get_match_data(&i2c->dev); 972 916 const struct pca9450_regulator_desc *regulator_desc; 973 917 struct regulator_config config = { }; 918 + struct regulator_dev *ldo5; 974 919 struct pca9450 *pca9450; 975 920 unsigned int device_id, i; 976 921 unsigned int reset_ctrl; ··· 1037 980 1038 981 config.regmap = pca9450->regmap; 1039 982 config.dev = pca9450->dev; 983 + config.driver_data = pca9450; 1040 984 1041 985 rdev = devm_regulator_register(pca9450->dev, desc, &config); 1042 986 if (IS_ERR(rdev)) 1043 987 return dev_err_probe(pca9450->dev, PTR_ERR(rdev), 1044 988 "Failed to register regulator(%s)\n", desc->name); 989 + 990 + if (!strcmp(desc->name, "ldo5")) 991 + ldo5 = rdev; 1045 992 } 1046 993 1047 994 if (pca9450->irq) { ··· 1093 1032 } 1094 1033 1095 1034 /* 1096 - * The driver uses the LDO5CTRL_H register to control the LDO5 regulator. 1097 - * This is only valid if the SD_VSEL input of the PMIC is high. Let's 1098 - * check if the pin is available as GPIO and set it to high. 1035 + * For LDO5 we need to be able to check the status of the SD_VSEL input in 1036 + * order to know which control register is used. Most boards connect SD_VSEL 1037 + * to the VSELECT signal, so we can use the GPIO that is internally routed 1038 + * to this signal (if SION bit is set in IOMUX). 1099 1039 */ 1100 - pca9450->sd_vsel_gpio = gpiod_get_optional(pca9450->dev, "sd-vsel", GPIOD_OUT_HIGH); 1040 + pca9450->sd_vsel_gpio = gpiod_get_optional(&ldo5->dev, "sd-vsel", GPIOD_IN); 1041 + if (IS_ERR(pca9450->sd_vsel_gpio)) { 1042 + dev_err(&i2c->dev, "Failed to get SD_VSEL GPIO\n"); 1043 + return ret; 1044 + } 1101 1045 1102 - if (IS_ERR(pca9450->sd_vsel_gpio)) 1103 - return dev_err_probe(&i2c->dev, PTR_ERR(pca9450->sd_vsel_gpio), 1104 - "Failed to get SD_VSEL GPIO\n"); 1046 + pca9450->sd_vsel_fixed_low = 1047 + of_property_read_bool(ldo5->dev.of_node, "nxp,sd-vsel-fixed-low"); 1105 1048 1106 1049 dev_info(&i2c->dev, "%s probed.\n", 1107 1050 type == PCA9450_TYPE_PCA9450A ? "pca9450a" :
-124
drivers/regulator/pcf50633-regulator.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* NXP PCF50633 PMIC Driver 3 - * 4 - * (C) 2006-2008 by Openmoko, Inc. 5 - * Author: Balaji Rao <balajirrao@openmoko.org> 6 - * All rights reserved. 7 - * 8 - * Broken down from monstrous PCF50633 driver mainly by 9 - * Harald Welte and Andy Green and Werner Almesberger 10 - */ 11 - 12 - #include <linux/kernel.h> 13 - #include <linux/module.h> 14 - #include <linux/init.h> 15 - #include <linux/device.h> 16 - #include <linux/err.h> 17 - #include <linux/platform_device.h> 18 - 19 - #include <linux/mfd/pcf50633/core.h> 20 - #include <linux/mfd/pcf50633/pmic.h> 21 - 22 - #define PCF50633_REGULATOR(_name, _id, _min_uV, _uV_step, _min_sel, _n) \ 23 - { \ 24 - .name = _name, \ 25 - .id = PCF50633_REGULATOR_##_id, \ 26 - .ops = &pcf50633_regulator_ops, \ 27 - .n_voltages = _n, \ 28 - .min_uV = _min_uV, \ 29 - .uV_step = _uV_step, \ 30 - .linear_min_sel = _min_sel, \ 31 - .type = REGULATOR_VOLTAGE, \ 32 - .owner = THIS_MODULE, \ 33 - .vsel_reg = PCF50633_REG_##_id##OUT, \ 34 - .vsel_mask = 0xff, \ 35 - .enable_reg = PCF50633_REG_##_id##OUT + 1, \ 36 - .enable_mask = PCF50633_REGULATOR_ON, \ 37 - } 38 - 39 - static const struct regulator_ops pcf50633_regulator_ops = { 40 - .set_voltage_sel = regulator_set_voltage_sel_regmap, 41 - .get_voltage_sel = regulator_get_voltage_sel_regmap, 42 - .list_voltage = regulator_list_voltage_linear, 43 - .map_voltage = regulator_map_voltage_linear, 44 - .enable = regulator_enable_regmap, 45 - .disable = regulator_disable_regmap, 46 - .is_enabled = regulator_is_enabled_regmap, 47 - }; 48 - 49 - static const struct regulator_desc regulators[] = { 50 - [PCF50633_REGULATOR_AUTO] = 51 - PCF50633_REGULATOR("auto", AUTO, 1800000, 25000, 0x2f, 128), 52 - [PCF50633_REGULATOR_DOWN1] = 53 - PCF50633_REGULATOR("down1", DOWN1, 625000, 25000, 0, 96), 54 - [PCF50633_REGULATOR_DOWN2] = 55 - PCF50633_REGULATOR("down2", DOWN2, 625000, 25000, 0, 96), 56 - [PCF50633_REGULATOR_LDO1] = 57 - PCF50633_REGULATOR("ldo1", LDO1, 900000, 100000, 0, 28), 58 - [PCF50633_REGULATOR_LDO2] = 59 - PCF50633_REGULATOR("ldo2", LDO2, 900000, 100000, 0, 28), 60 - [PCF50633_REGULATOR_LDO3] = 61 - PCF50633_REGULATOR("ldo3", LDO3, 900000, 100000, 0, 28), 62 - [PCF50633_REGULATOR_LDO4] = 63 - PCF50633_REGULATOR("ldo4", LDO4, 900000, 100000, 0, 28), 64 - [PCF50633_REGULATOR_LDO5] = 65 - PCF50633_REGULATOR("ldo5", LDO5, 900000, 100000, 0, 28), 66 - [PCF50633_REGULATOR_LDO6] = 67 - PCF50633_REGULATOR("ldo6", LDO6, 900000, 100000, 0, 28), 68 - [PCF50633_REGULATOR_HCLDO] = 69 - PCF50633_REGULATOR("hcldo", HCLDO, 900000, 100000, 0, 28), 70 - [PCF50633_REGULATOR_MEMLDO] = 71 - PCF50633_REGULATOR("memldo", MEMLDO, 900000, 100000, 0, 28), 72 - }; 73 - 74 - static int pcf50633_regulator_probe(struct platform_device *pdev) 75 - { 76 - struct regulator_dev *rdev; 77 - struct pcf50633 *pcf; 78 - struct regulator_config config = { }; 79 - 80 - /* Already set by core driver */ 81 - pcf = dev_to_pcf50633(pdev->dev.parent); 82 - 83 - config.dev = &pdev->dev; 84 - config.init_data = dev_get_platdata(&pdev->dev); 85 - config.driver_data = pcf; 86 - config.regmap = pcf->regmap; 87 - 88 - rdev = devm_regulator_register(&pdev->dev, &regulators[pdev->id], 89 - &config); 90 - if (IS_ERR(rdev)) 91 - return PTR_ERR(rdev); 92 - 93 - platform_set_drvdata(pdev, rdev); 94 - 95 - if (pcf->pdata->regulator_registered) 96 - pcf->pdata->regulator_registered(pcf, pdev->id); 97 - 98 - return 0; 99 - } 100 - 101 - static struct platform_driver pcf50633_regulator_driver = { 102 - .driver = { 103 - .name = "pcf50633-regulator", 104 - .probe_type = PROBE_PREFER_ASYNCHRONOUS, 105 - }, 106 - .probe = pcf50633_regulator_probe, 107 - }; 108 - 109 - static int __init pcf50633_regulator_init(void) 110 - { 111 - return platform_driver_register(&pcf50633_regulator_driver); 112 - } 113 - subsys_initcall(pcf50633_regulator_init); 114 - 115 - static void __exit pcf50633_regulator_exit(void) 116 - { 117 - platform_driver_unregister(&pcf50633_regulator_driver); 118 - } 119 - module_exit(pcf50633_regulator_exit); 120 - 121 - MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>"); 122 - MODULE_DESCRIPTION("PCF50633 regulator driver"); 123 - MODULE_LICENSE("GPL"); 124 - MODULE_ALIAS("platform:pcf50633-regulator");
+879
drivers/regulator/pf9453-regulator.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright 2024 NXP. 4 + * NXP PF9453 pmic driver 5 + */ 6 + 7 + #include <linux/bits.h> 8 + #include <linux/err.h> 9 + #include <linux/gpio/consumer.h> 10 + #include <linux/i2c.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/of.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/regmap.h> 17 + #include <linux/regulator/driver.h> 18 + #include <linux/regulator/machine.h> 19 + #include <linux/regulator/of_regulator.h> 20 + 21 + struct pf9453_dvs_config { 22 + unsigned int run_reg; /* dvs0 */ 23 + unsigned int run_mask; 24 + unsigned int standby_reg; /* dvs1 */ 25 + unsigned int standby_mask; 26 + }; 27 + 28 + struct pf9453_regulator_desc { 29 + struct regulator_desc desc; 30 + const struct pf9453_dvs_config dvs; 31 + }; 32 + 33 + struct pf9453 { 34 + struct device *dev; 35 + struct regmap *regmap; 36 + struct gpio_desc *sd_vsel_gpio; 37 + int irq; 38 + }; 39 + 40 + enum { 41 + PF9453_BUCK1 = 0, 42 + PF9453_BUCK2, 43 + PF9453_BUCK3, 44 + PF9453_BUCK4, 45 + PF9453_LDO1, 46 + PF9453_LDO2, 47 + PF9453_LDOSNVS, 48 + PF9453_REGULATOR_CNT 49 + }; 50 + 51 + enum { 52 + PF9453_DVS_LEVEL_RUN = 0, 53 + PF9453_DVS_LEVEL_STANDBY, 54 + PF9453_DVS_LEVEL_DPSTANDBY, 55 + PF9453_DVS_LEVEL_MAX 56 + }; 57 + 58 + #define PF9453_BUCK1_VOLTAGE_NUM 0x80 59 + #define PF9453_BUCK2_VOLTAGE_NUM 0x80 60 + #define PF9453_BUCK3_VOLTAGE_NUM 0x80 61 + #define PF9453_BUCK4_VOLTAGE_NUM 0x80 62 + 63 + #define PF9453_LDO1_VOLTAGE_NUM 0x65 64 + #define PF9453_LDO2_VOLTAGE_NUM 0x3b 65 + #define PF9453_LDOSNVS_VOLTAGE_NUM 0x59 66 + 67 + enum { 68 + PF9453_REG_DEV_ID = 0x00, 69 + PF9453_REG_OTP_VER = 0x01, 70 + PF9453_REG_INT1 = 0x02, 71 + PF9453_REG_INT1_MASK = 0x03, 72 + PF9453_REG_INT1_STATUS = 0x04, 73 + PF9453_REG_VRFLT1_INT = 0x05, 74 + PF9453_REG_VRFLT1_MASK = 0x06, 75 + PF9453_REG_PWRON_STAT = 0x07, 76 + PF9453_REG_RESET_CTRL = 0x08, 77 + PF9453_REG_SW_RST = 0x09, 78 + PF9453_REG_PWR_CTRL = 0x0a, 79 + PF9453_REG_CONFIG1 = 0x0b, 80 + PF9453_REG_CONFIG2 = 0x0c, 81 + PF9453_REG_32K_CONFIG = 0x0d, 82 + PF9453_REG_BUCK1CTRL = 0x10, 83 + PF9453_REG_BUCK1OUT = 0x11, 84 + PF9453_REG_BUCK2CTRL = 0x14, 85 + PF9453_REG_BUCK2OUT = 0x15, 86 + PF9453_REG_BUCK2OUT_STBY = 0x1d, 87 + PF9453_REG_BUCK2OUT_MAX_LIMIT = 0x1f, 88 + PF9453_REG_BUCK2OUT_MIN_LIMIT = 0x20, 89 + PF9453_REG_BUCK3CTRL = 0x21, 90 + PF9453_REG_BUCK3OUT = 0x22, 91 + PF9453_REG_BUCK4CTRL = 0x2e, 92 + PF9453_REG_BUCK4OUT = 0x2f, 93 + PF9453_REG_LDO1OUT_L = 0x36, 94 + PF9453_REG_LDO1CFG = 0x37, 95 + PF9453_REG_LDO1OUT_H = 0x38, 96 + PF9453_REG_LDOSNVS_CFG1 = 0x39, 97 + PF9453_REG_LDOSNVS_CFG2 = 0x3a, 98 + PF9453_REG_LDO2CFG = 0x3b, 99 + PF9453_REG_LDO2OUT = 0x3c, 100 + PF9453_REG_BUCK_POK = 0x3d, 101 + PF9453_REG_LSW_CTRL1 = 0x40, 102 + PF9453_REG_LSW_CTRL2 = 0x41, 103 + PF9453_REG_LOCK = 0x4e, 104 + PF9453_MAX_REG 105 + }; 106 + 107 + #define PF9453_UNLOCK_KEY 0x5c 108 + #define PF9453_LOCK_KEY 0x0 109 + 110 + /* PF9453 BUCK ENMODE bits */ 111 + #define BUCK_ENMODE_OFF 0x00 112 + #define BUCK_ENMODE_ONREQ 0x01 113 + #define BUCK_ENMODE_ONREQ_STBY 0x02 114 + #define BUCK_ENMODE_ONREQ_STBY_DPSTBY 0x03 115 + 116 + /* PF9453 BUCK ENMODE bits */ 117 + #define LDO_ENMODE_OFF 0x00 118 + #define LDO_ENMODE_ONREQ 0x01 119 + #define LDO_ENMODE_ONREQ_STBY 0x02 120 + #define LDO_ENMODE_ONREQ_STBY_DPSTBY 0x03 121 + 122 + /* PF9453_REG_BUCK1_CTRL bits */ 123 + #define BUCK1_LPMODE 0x30 124 + #define BUCK1_AD 0x08 125 + #define BUCK1_FPWM 0x04 126 + #define BUCK1_ENMODE_MASK GENMASK(1, 0) 127 + 128 + /* PF9453_REG_BUCK2_CTRL bits */ 129 + #define BUCK2_RAMP_MASK GENMASK(7, 6) 130 + #define BUCK2_RAMP_25MV 0x0 131 + #define BUCK2_RAMP_12P5MV 0x1 132 + #define BUCK2_RAMP_6P25MV 0x2 133 + #define BUCK2_RAMP_3P125MV 0x3 134 + #define BUCK2_LPMODE 0x30 135 + #define BUCK2_AD 0x08 136 + #define BUCK2_FPWM 0x04 137 + #define BUCK2_ENMODE_MASK GENMASK(1, 0) 138 + 139 + /* PF9453_REG_BUCK3_CTRL bits */ 140 + #define BUCK3_LPMODE 0x30 141 + #define BUCK3_AD 0x08 142 + #define BUCK3_FPWM 0x04 143 + #define BUCK3_ENMODE_MASK GENMASK(1, 0) 144 + 145 + /* PF9453_REG_BUCK4_CTRL bits */ 146 + #define BUCK4_LPMODE 0x30 147 + #define BUCK4_AD 0x08 148 + #define BUCK4_FPWM 0x04 149 + #define BUCK4_ENMODE_MASK GENMASK(1, 0) 150 + 151 + /* PF9453_REG_BUCK123_PRESET_EN bit */ 152 + #define BUCK123_PRESET_EN 0x80 153 + 154 + /* PF9453_BUCK1OUT bits */ 155 + #define BUCK1OUT_MASK GENMASK(6, 0) 156 + 157 + /* PF9453_BUCK2OUT bits */ 158 + #define BUCK2OUT_MASK GENMASK(6, 0) 159 + #define BUCK2OUT_STBY_MASK GENMASK(6, 0) 160 + 161 + /* PF9453_REG_BUCK3OUT bits */ 162 + #define BUCK3OUT_MASK GENMASK(6, 0) 163 + 164 + /* PF9453_REG_BUCK4OUT bits */ 165 + #define BUCK4OUT_MASK GENMASK(6, 0) 166 + 167 + /* PF9453_REG_LDO1_VOLT bits */ 168 + #define LDO1_EN_MASK GENMASK(1, 0) 169 + #define LDO1OUT_MASK GENMASK(6, 0) 170 + 171 + /* PF9453_REG_LDO2_VOLT bits */ 172 + #define LDO2_EN_MASK GENMASK(1, 0) 173 + #define LDO2OUT_MASK GENMASK(6, 0) 174 + 175 + /* PF9453_REG_LDOSNVS_VOLT bits */ 176 + #define LDOSNVS_EN_MASK GENMASK(0, 0) 177 + #define LDOSNVSCFG1_MASK GENMASK(6, 0) 178 + 179 + /* PF9453_REG_IRQ bits */ 180 + #define IRQ_RSVD 0x80 181 + #define IRQ_RSTB 0x40 182 + #define IRQ_ONKEY 0x20 183 + #define IRQ_RESETKEY 0x10 184 + #define IRQ_VR_FLT1 0x08 185 + #define IRQ_LOWVSYS 0x04 186 + #define IRQ_THERM_100 0x02 187 + #define IRQ_THERM_80 0x01 188 + 189 + /* PF9453_REG_RESET_CTRL bits */ 190 + #define WDOG_B_CFG_MASK GENMASK(7, 6) 191 + #define WDOG_B_CFG_NONE 0x00 192 + #define WDOG_B_CFG_WARM 0x40 193 + #define WDOG_B_CFG_COLD 0x80 194 + 195 + /* PF9453_REG_CONFIG2 bits */ 196 + #define I2C_LT_MASK GENMASK(1, 0) 197 + #define I2C_LT_FORCE_DISABLE 0x00 198 + #define I2C_LT_ON_STANDBY_RUN 0x01 199 + #define I2C_LT_ON_RUN 0x02 200 + #define I2C_LT_FORCE_ENABLE 0x03 201 + 202 + static const struct regmap_range pf9453_status_range = { 203 + .range_min = PF9453_REG_INT1, 204 + .range_max = PF9453_REG_PWRON_STAT, 205 + }; 206 + 207 + static const struct regmap_access_table pf9453_volatile_regs = { 208 + .yes_ranges = &pf9453_status_range, 209 + .n_yes_ranges = 1, 210 + }; 211 + 212 + static const struct regmap_config pf9453_regmap_config = { 213 + .reg_bits = 8, 214 + .val_bits = 8, 215 + .volatile_table = &pf9453_volatile_regs, 216 + .max_register = PF9453_MAX_REG - 1, 217 + .cache_type = REGCACHE_RBTREE, 218 + }; 219 + 220 + /* 221 + * BUCK2 222 + * BUCK2RAM[1:0] BUCK2 DVS ramp rate setting 223 + * 00: 25mV/1usec 224 + * 01: 25mV/2usec 225 + * 10: 25mV/4usec 226 + * 11: 25mV/8usec 227 + */ 228 + static const unsigned int pf9453_dvs_buck_ramp_table[] = { 229 + 25000, 12500, 6250, 3125 230 + }; 231 + 232 + static bool is_reg_protect(uint reg) 233 + { 234 + switch (reg) { 235 + case PF9453_REG_BUCK1OUT: 236 + case PF9453_REG_BUCK2OUT: 237 + case PF9453_REG_BUCK3OUT: 238 + case PF9453_REG_BUCK4OUT: 239 + case PF9453_REG_LDO1OUT_L: 240 + case PF9453_REG_LDO1OUT_H: 241 + case PF9453_REG_LDO2OUT: 242 + case PF9453_REG_LDOSNVS_CFG1: 243 + case PF9453_REG_BUCK2OUT_MAX_LIMIT: 244 + case PF9453_REG_BUCK2OUT_MIN_LIMIT: 245 + return true; 246 + default: 247 + return false; 248 + } 249 + } 250 + 251 + static int pf9453_pmic_write(struct pf9453 *pf9453, unsigned int reg, u8 mask, unsigned int val) 252 + { 253 + int ret = -EINVAL; 254 + u8 data, key; 255 + u32 rxBuf; 256 + 257 + /* If not updating entire register, perform a read-mod-write */ 258 + data = val; 259 + key = PF9453_UNLOCK_KEY; 260 + 261 + if (mask != 0xffU) { 262 + /* Read data */ 263 + ret = regmap_read(pf9453->regmap, reg, &rxBuf); 264 + if (ret) { 265 + dev_err(pf9453->dev, "Read reg=%0x error!\n", reg); 266 + return ret; 267 + } 268 + data = (val & mask) | (rxBuf & (~mask)); 269 + } 270 + 271 + if (reg < PF9453_MAX_REG) { 272 + if (is_reg_protect(reg)) { 273 + ret = regmap_raw_write(pf9453->regmap, PF9453_REG_LOCK, &key, 1U); 274 + if (ret) { 275 + dev_err(pf9453->dev, "Write reg=%0x error!\n", reg); 276 + return ret; 277 + } 278 + 279 + ret = regmap_raw_write(pf9453->regmap, reg, &data, 1U); 280 + if (ret) { 281 + dev_err(pf9453->dev, "Write reg=%0x error!\n", reg); 282 + return ret; 283 + } 284 + 285 + key = PF9453_LOCK_KEY; 286 + ret = regmap_raw_write(pf9453->regmap, PF9453_REG_LOCK, &key, 1U); 287 + if (ret) { 288 + dev_err(pf9453->dev, "Write reg=%0x error!\n", reg); 289 + return ret; 290 + } 291 + } else { 292 + ret = regmap_raw_write(pf9453->regmap, reg, &data, 1U); 293 + if (ret) { 294 + dev_err(pf9453->dev, "Write reg=%0x error!\n", reg); 295 + return ret; 296 + } 297 + } 298 + } 299 + 300 + return ret; 301 + } 302 + 303 + /** 304 + * pf9453_regulator_enable_regmap for regmap users 305 + * 306 + * @rdev: regulator to operate on 307 + * 308 + * Regulators that use regmap for their register I/O can set the 309 + * enable_reg and enable_mask fields in their descriptor and then use 310 + * this as their enable() operation, saving some code. 311 + */ 312 + static int pf9453_regulator_enable_regmap(struct regulator_dev *rdev) 313 + { 314 + struct pf9453 *pf9453 = dev_get_drvdata(rdev->dev.parent); 315 + unsigned int val; 316 + 317 + if (rdev->desc->enable_is_inverted) { 318 + val = rdev->desc->disable_val; 319 + } else { 320 + val = rdev->desc->enable_val; 321 + if (!val) 322 + val = rdev->desc->enable_mask; 323 + } 324 + 325 + return pf9453_pmic_write(pf9453, rdev->desc->enable_reg, rdev->desc->enable_mask, val); 326 + } 327 + 328 + /** 329 + * pf9453_regulator_disable_regmap for regmap users 330 + * 331 + * @rdev: regulator to operate on 332 + * 333 + * Regulators that use regmap for their register I/O can set the 334 + * enable_reg and enable_mask fields in their descriptor and then use 335 + * this as their disable() operation, saving some code. 336 + */ 337 + static int pf9453_regulator_disable_regmap(struct regulator_dev *rdev) 338 + { 339 + struct pf9453 *pf9453 = dev_get_drvdata(rdev->dev.parent); 340 + unsigned int val; 341 + 342 + if (rdev->desc->enable_is_inverted) { 343 + val = rdev->desc->enable_val; 344 + if (!val) 345 + val = rdev->desc->enable_mask; 346 + } else { 347 + val = rdev->desc->disable_val; 348 + } 349 + 350 + return pf9453_pmic_write(pf9453, rdev->desc->enable_reg, rdev->desc->enable_mask, val); 351 + } 352 + 353 + /** 354 + * pf9453_regulator_set_voltage_sel_regmap for regmap users 355 + * 356 + * @rdev: regulator to operate on 357 + * @sel: Selector to set 358 + * 359 + * Regulators that use regmap for their register I/O can set the 360 + * vsel_reg and vsel_mask fields in their descriptor and then use this 361 + * as their set_voltage_vsel operation, saving some code. 362 + */ 363 + static int pf9453_regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned int sel) 364 + { 365 + struct pf9453 *pf9453 = dev_get_drvdata(rdev->dev.parent); 366 + int ret; 367 + 368 + sel <<= ffs(rdev->desc->vsel_mask) - 1; 369 + ret = pf9453_pmic_write(pf9453, rdev->desc->vsel_reg, rdev->desc->vsel_mask, sel); 370 + if (ret) 371 + return ret; 372 + 373 + if (rdev->desc->apply_bit) 374 + ret = pf9453_pmic_write(pf9453, rdev->desc->apply_reg, 375 + rdev->desc->apply_bit, rdev->desc->apply_bit); 376 + return ret; 377 + } 378 + 379 + static int find_closest_bigger(unsigned int target, const unsigned int *table, 380 + unsigned int num_sel, unsigned int *sel) 381 + { 382 + unsigned int s, tmp, max, maxsel = 0; 383 + bool found = false; 384 + 385 + max = table[0]; 386 + 387 + for (s = 0; s < num_sel; s++) { 388 + if (table[s] > max) { 389 + max = table[s]; 390 + maxsel = s; 391 + } 392 + if (table[s] >= target) { 393 + if (!found || table[s] - target < tmp - target) { 394 + tmp = table[s]; 395 + *sel = s; 396 + found = true; 397 + if (tmp == target) 398 + break; 399 + } 400 + } 401 + } 402 + 403 + if (!found) { 404 + *sel = maxsel; 405 + return -EINVAL; 406 + } 407 + 408 + return 0; 409 + } 410 + 411 + /** 412 + * pf9453_regulator_set_ramp_delay_regmap 413 + * 414 + * @rdev: regulator to operate on 415 + * 416 + * Regulators that use regmap for their register I/O can set the ramp_reg 417 + * and ramp_mask fields in their descriptor and then use this as their 418 + * set_ramp_delay operation, saving some code. 419 + */ 420 + static int pf9453_regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay) 421 + { 422 + struct pf9453 *pf9453 = dev_get_drvdata(rdev->dev.parent); 423 + unsigned int sel; 424 + int ret; 425 + 426 + if (WARN_ON(!rdev->desc->n_ramp_values || !rdev->desc->ramp_delay_table)) 427 + return -EINVAL; 428 + 429 + ret = find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table, 430 + rdev->desc->n_ramp_values, &sel); 431 + 432 + if (ret) { 433 + dev_warn(rdev_get_dev(rdev), 434 + "Can't set ramp-delay %u, setting %u\n", ramp_delay, 435 + rdev->desc->ramp_delay_table[sel]); 436 + } 437 + 438 + sel <<= ffs(rdev->desc->ramp_mask) - 1; 439 + 440 + return pf9453_pmic_write(pf9453, rdev->desc->ramp_reg, 441 + rdev->desc->ramp_mask, sel); 442 + } 443 + 444 + static const struct regulator_ops pf9453_dvs_buck_regulator_ops = { 445 + .enable = pf9453_regulator_enable_regmap, 446 + .disable = pf9453_regulator_disable_regmap, 447 + .is_enabled = regulator_is_enabled_regmap, 448 + .list_voltage = regulator_list_voltage_linear_range, 449 + .set_voltage_sel = pf9453_regulator_set_voltage_sel_regmap, 450 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 451 + .set_voltage_time_sel = regulator_set_voltage_time_sel, 452 + .set_ramp_delay = pf9453_regulator_set_ramp_delay_regmap, 453 + }; 454 + 455 + static const struct regulator_ops pf9453_buck_regulator_ops = { 456 + .enable = pf9453_regulator_enable_regmap, 457 + .disable = pf9453_regulator_disable_regmap, 458 + .is_enabled = regulator_is_enabled_regmap, 459 + .list_voltage = regulator_list_voltage_linear_range, 460 + .set_voltage_sel = pf9453_regulator_set_voltage_sel_regmap, 461 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 462 + .set_voltage_time_sel = regulator_set_voltage_time_sel, 463 + }; 464 + 465 + static const struct regulator_ops pf9453_ldo_regulator_ops = { 466 + .enable = pf9453_regulator_enable_regmap, 467 + .disable = pf9453_regulator_disable_regmap, 468 + .is_enabled = regulator_is_enabled_regmap, 469 + .list_voltage = regulator_list_voltage_linear_range, 470 + .set_voltage_sel = pf9453_regulator_set_voltage_sel_regmap, 471 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 472 + }; 473 + 474 + /* 475 + * BUCK1/3/4 476 + * 0.60 to 3.775V (25mV step) 477 + */ 478 + static const struct linear_range pf9453_buck134_volts[] = { 479 + REGULATOR_LINEAR_RANGE(600000, 0x00, 0x7F, 25000), 480 + }; 481 + 482 + /* 483 + * BUCK2 484 + * 0.60 to 2.1875V (12.5mV step) 485 + */ 486 + static const struct linear_range pf9453_buck2_volts[] = { 487 + REGULATOR_LINEAR_RANGE(600000, 0x00, 0x7F, 12500), 488 + }; 489 + 490 + /* 491 + * LDO1 492 + * 0.8 to 3.3V (25mV step) 493 + */ 494 + static const struct linear_range pf9453_ldo1_volts[] = { 495 + REGULATOR_LINEAR_RANGE(800000, 0x00, 0x64, 25000), 496 + }; 497 + 498 + /* 499 + * LDO2 500 + * 0.5 to 1.95V (25mV step) 501 + */ 502 + static const struct linear_range pf9453_ldo2_volts[] = { 503 + REGULATOR_LINEAR_RANGE(500000, 0x00, 0x3A, 25000), 504 + }; 505 + 506 + /* 507 + * LDOSNVS 508 + * 1.2 to 3.4V (25mV step) 509 + */ 510 + static const struct linear_range pf9453_ldosnvs_volts[] = { 511 + REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x58, 25000), 512 + }; 513 + 514 + static int buck_set_dvs(const struct regulator_desc *desc, 515 + struct device_node *np, struct pf9453 *pf9453, 516 + char *prop, unsigned int reg, unsigned int mask) 517 + { 518 + int ret, i; 519 + u32 uv; 520 + 521 + ret = of_property_read_u32(np, prop, &uv); 522 + if (ret == -EINVAL) 523 + return 0; 524 + else if (ret) 525 + return ret; 526 + 527 + for (i = 0; i < desc->n_voltages; i++) { 528 + ret = regulator_desc_list_voltage_linear_range(desc, i); 529 + if (ret < 0) 530 + continue; 531 + if (ret == uv) { 532 + i <<= ffs(desc->vsel_mask) - 1; 533 + ret = pf9453_pmic_write(pf9453, reg, mask, i); 534 + break; 535 + } 536 + } 537 + 538 + if (ret == 0) { 539 + struct pf9453_regulator_desc *regulator = container_of(desc, 540 + struct pf9453_regulator_desc, desc); 541 + 542 + /* Enable DVS control through PMIC_STBY_REQ for this BUCK */ 543 + ret = pf9453_pmic_write(pf9453, regulator->desc.enable_reg, 544 + BUCK2_LPMODE, BUCK2_LPMODE); 545 + } 546 + return ret; 547 + } 548 + 549 + static int pf9453_set_dvs_levels(struct device_node *np, const struct regulator_desc *desc, 550 + struct regulator_config *cfg) 551 + { 552 + struct pf9453_regulator_desc *data = container_of(desc, struct pf9453_regulator_desc, desc); 553 + struct pf9453 *pf9453 = dev_get_drvdata(cfg->dev); 554 + const struct pf9453_dvs_config *dvs = &data->dvs; 555 + unsigned int reg, mask; 556 + int i, ret = 0; 557 + char *prop; 558 + 559 + for (i = 0; i < PF9453_DVS_LEVEL_MAX; i++) { 560 + switch (i) { 561 + case PF9453_DVS_LEVEL_RUN: 562 + prop = "nxp,dvs-run-voltage"; 563 + reg = dvs->run_reg; 564 + mask = dvs->run_mask; 565 + break; 566 + case PF9453_DVS_LEVEL_DPSTANDBY: 567 + case PF9453_DVS_LEVEL_STANDBY: 568 + prop = "nxp,dvs-standby-voltage"; 569 + reg = dvs->standby_reg; 570 + mask = dvs->standby_mask; 571 + break; 572 + default: 573 + return -EINVAL; 574 + } 575 + 576 + ret = buck_set_dvs(desc, np, pf9453, prop, reg, mask); 577 + if (ret) 578 + break; 579 + } 580 + 581 + return ret; 582 + } 583 + 584 + static const struct pf9453_regulator_desc pf9453_regulators[] = { 585 + { 586 + .desc = { 587 + .name = "buck1", 588 + .of_match = of_match_ptr("BUCK1"), 589 + .regulators_node = of_match_ptr("regulators"), 590 + .id = PF9453_BUCK1, 591 + .ops = &pf9453_buck_regulator_ops, 592 + .type = REGULATOR_VOLTAGE, 593 + .n_voltages = PF9453_BUCK1_VOLTAGE_NUM, 594 + .linear_ranges = pf9453_buck134_volts, 595 + .n_linear_ranges = ARRAY_SIZE(pf9453_buck134_volts), 596 + .vsel_reg = PF9453_REG_BUCK1OUT, 597 + .vsel_mask = BUCK1OUT_MASK, 598 + .enable_reg = PF9453_REG_BUCK1CTRL, 599 + .enable_mask = BUCK1_ENMODE_MASK, 600 + .enable_val = BUCK_ENMODE_ONREQ, 601 + .owner = THIS_MODULE, 602 + }, 603 + }, 604 + { 605 + .desc = { 606 + .name = "buck2", 607 + .of_match = of_match_ptr("BUCK2"), 608 + .regulators_node = of_match_ptr("regulators"), 609 + .id = PF9453_BUCK2, 610 + .ops = &pf9453_dvs_buck_regulator_ops, 611 + .type = REGULATOR_VOLTAGE, 612 + .n_voltages = PF9453_BUCK2_VOLTAGE_NUM, 613 + .linear_ranges = pf9453_buck2_volts, 614 + .n_linear_ranges = ARRAY_SIZE(pf9453_buck2_volts), 615 + .vsel_reg = PF9453_REG_BUCK2OUT, 616 + .vsel_mask = BUCK2OUT_MASK, 617 + .enable_reg = PF9453_REG_BUCK2CTRL, 618 + .enable_mask = BUCK2_ENMODE_MASK, 619 + .enable_val = BUCK_ENMODE_ONREQ, 620 + .ramp_reg = PF9453_REG_BUCK2CTRL, 621 + .ramp_mask = BUCK2_RAMP_MASK, 622 + .ramp_delay_table = pf9453_dvs_buck_ramp_table, 623 + .n_ramp_values = ARRAY_SIZE(pf9453_dvs_buck_ramp_table), 624 + .owner = THIS_MODULE, 625 + .of_parse_cb = pf9453_set_dvs_levels, 626 + }, 627 + .dvs = { 628 + .run_reg = PF9453_REG_BUCK2OUT, 629 + .run_mask = BUCK2OUT_MASK, 630 + .standby_reg = PF9453_REG_BUCK2OUT_STBY, 631 + .standby_mask = BUCK2OUT_STBY_MASK, 632 + }, 633 + }, 634 + { 635 + .desc = { 636 + .name = "buck3", 637 + .of_match = of_match_ptr("BUCK3"), 638 + .regulators_node = of_match_ptr("regulators"), 639 + .id = PF9453_BUCK3, 640 + .ops = &pf9453_buck_regulator_ops, 641 + .type = REGULATOR_VOLTAGE, 642 + .n_voltages = PF9453_BUCK3_VOLTAGE_NUM, 643 + .linear_ranges = pf9453_buck134_volts, 644 + .n_linear_ranges = ARRAY_SIZE(pf9453_buck134_volts), 645 + .vsel_reg = PF9453_REG_BUCK3OUT, 646 + .vsel_mask = BUCK3OUT_MASK, 647 + .enable_reg = PF9453_REG_BUCK3CTRL, 648 + .enable_mask = BUCK3_ENMODE_MASK, 649 + .enable_val = BUCK_ENMODE_ONREQ, 650 + .owner = THIS_MODULE, 651 + }, 652 + }, 653 + { 654 + .desc = { 655 + .name = "buck4", 656 + .of_match = of_match_ptr("BUCK4"), 657 + .regulators_node = of_match_ptr("regulators"), 658 + .id = PF9453_BUCK4, 659 + .ops = &pf9453_buck_regulator_ops, 660 + .type = REGULATOR_VOLTAGE, 661 + .n_voltages = PF9453_BUCK4_VOLTAGE_NUM, 662 + .linear_ranges = pf9453_buck134_volts, 663 + .n_linear_ranges = ARRAY_SIZE(pf9453_buck134_volts), 664 + .vsel_reg = PF9453_REG_BUCK4OUT, 665 + .vsel_mask = BUCK4OUT_MASK, 666 + .enable_reg = PF9453_REG_BUCK4CTRL, 667 + .enable_mask = BUCK4_ENMODE_MASK, 668 + .enable_val = BUCK_ENMODE_ONREQ, 669 + .owner = THIS_MODULE, 670 + }, 671 + }, 672 + { 673 + .desc = { 674 + .name = "ldo1", 675 + .of_match = of_match_ptr("LDO1"), 676 + .regulators_node = of_match_ptr("regulators"), 677 + .id = PF9453_LDO1, 678 + .ops = &pf9453_ldo_regulator_ops, 679 + .type = REGULATOR_VOLTAGE, 680 + .n_voltages = PF9453_LDO1_VOLTAGE_NUM, 681 + .linear_ranges = pf9453_ldo1_volts, 682 + .n_linear_ranges = ARRAY_SIZE(pf9453_ldo1_volts), 683 + .vsel_reg = PF9453_REG_LDO1OUT_H, 684 + .vsel_mask = LDO1OUT_MASK, 685 + .enable_reg = PF9453_REG_LDO1CFG, 686 + .enable_mask = LDO1_EN_MASK, 687 + .enable_val = LDO_ENMODE_ONREQ, 688 + .owner = THIS_MODULE, 689 + }, 690 + }, 691 + { 692 + .desc = { 693 + .name = "ldo2", 694 + .of_match = of_match_ptr("LDO2"), 695 + .regulators_node = of_match_ptr("regulators"), 696 + .id = PF9453_LDO2, 697 + .ops = &pf9453_ldo_regulator_ops, 698 + .type = REGULATOR_VOLTAGE, 699 + .n_voltages = PF9453_LDO2_VOLTAGE_NUM, 700 + .linear_ranges = pf9453_ldo2_volts, 701 + .n_linear_ranges = ARRAY_SIZE(pf9453_ldo2_volts), 702 + .vsel_reg = PF9453_REG_LDO2OUT, 703 + .vsel_mask = LDO2OUT_MASK, 704 + .enable_reg = PF9453_REG_LDO2CFG, 705 + .enable_mask = LDO2_EN_MASK, 706 + .enable_val = LDO_ENMODE_ONREQ, 707 + .owner = THIS_MODULE, 708 + }, 709 + }, 710 + { 711 + .desc = { 712 + .name = "ldosnvs", 713 + .of_match = of_match_ptr("LDO-SNVS"), 714 + .regulators_node = of_match_ptr("regulators"), 715 + .id = PF9453_LDOSNVS, 716 + .ops = &pf9453_ldo_regulator_ops, 717 + .type = REGULATOR_VOLTAGE, 718 + .n_voltages = PF9453_LDOSNVS_VOLTAGE_NUM, 719 + .linear_ranges = pf9453_ldosnvs_volts, 720 + .n_linear_ranges = ARRAY_SIZE(pf9453_ldosnvs_volts), 721 + .vsel_reg = PF9453_REG_LDOSNVS_CFG1, 722 + .vsel_mask = LDOSNVSCFG1_MASK, 723 + .enable_reg = PF9453_REG_LDOSNVS_CFG2, 724 + .enable_mask = LDOSNVS_EN_MASK, 725 + .owner = THIS_MODULE, 726 + }, 727 + }, 728 + { } 729 + }; 730 + 731 + static irqreturn_t pf9453_irq_handler(int irq, void *data) 732 + { 733 + struct pf9453 *pf9453 = data; 734 + struct regmap *regmap = pf9453->regmap; 735 + unsigned int status; 736 + int ret; 737 + 738 + ret = regmap_read(regmap, PF9453_REG_INT1, &status); 739 + if (ret < 0) { 740 + dev_err(pf9453->dev, "Failed to read INT1(%d)\n", ret); 741 + return IRQ_NONE; 742 + } 743 + 744 + if (status & IRQ_RSTB) 745 + dev_warn(pf9453->dev, "IRQ_RSTB interrupt.\n"); 746 + 747 + if (status & IRQ_ONKEY) 748 + dev_warn(pf9453->dev, "IRQ_ONKEY interrupt.\n"); 749 + 750 + if (status & IRQ_VR_FLT1) 751 + dev_warn(pf9453->dev, "VRFLT1 interrupt.\n"); 752 + 753 + if (status & IRQ_RESETKEY) 754 + dev_warn(pf9453->dev, "IRQ_RESETKEY interrupt.\n"); 755 + 756 + if (status & IRQ_LOWVSYS) 757 + dev_warn(pf9453->dev, "LOWVSYS interrupt.\n"); 758 + 759 + if (status & IRQ_THERM_100) 760 + dev_warn(pf9453->dev, "IRQ_THERM_100 interrupt.\n"); 761 + 762 + if (status & IRQ_THERM_80) 763 + dev_warn(pf9453->dev, "IRQ_THERM_80 interrupt.\n"); 764 + 765 + return IRQ_HANDLED; 766 + } 767 + 768 + static int pf9453_i2c_probe(struct i2c_client *i2c) 769 + { 770 + const struct pf9453_regulator_desc *regulator_desc = of_device_get_match_data(&i2c->dev); 771 + struct regulator_config config = { }; 772 + unsigned int reset_ctrl; 773 + unsigned int device_id; 774 + struct pf9453 *pf9453; 775 + int ret; 776 + 777 + if (!i2c->irq) 778 + return dev_err_probe(&i2c->dev, -EINVAL, "No IRQ configured?\n"); 779 + 780 + pf9453 = devm_kzalloc(&i2c->dev, sizeof(struct pf9453), GFP_KERNEL); 781 + if (!pf9453) 782 + return -ENOMEM; 783 + 784 + pf9453->regmap = devm_regmap_init_i2c(i2c, &pf9453_regmap_config); 785 + if (IS_ERR(pf9453->regmap)) 786 + return dev_err_probe(&i2c->dev, PTR_ERR(pf9453->regmap), 787 + "regmap initialization failed\n"); 788 + 789 + pf9453->irq = i2c->irq; 790 + pf9453->dev = &i2c->dev; 791 + 792 + dev_set_drvdata(&i2c->dev, pf9453); 793 + 794 + ret = regmap_read(pf9453->regmap, PF9453_REG_DEV_ID, &device_id); 795 + if (ret) 796 + return dev_err_probe(&i2c->dev, ret, "Read device id error\n"); 797 + 798 + /* Check your board and dts for match the right pmic */ 799 + if ((device_id >> 4) != 0xb) 800 + return dev_err_probe(&i2c->dev, -EINVAL, "Device id(%x) mismatched\n", 801 + device_id >> 4); 802 + 803 + while (regulator_desc->desc.name) { 804 + const struct regulator_desc *desc; 805 + struct regulator_dev *rdev; 806 + 807 + desc = &regulator_desc->desc; 808 + 809 + config.regmap = pf9453->regmap; 810 + config.dev = pf9453->dev; 811 + 812 + rdev = devm_regulator_register(pf9453->dev, desc, &config); 813 + if (IS_ERR(rdev)) 814 + return dev_err_probe(pf9453->dev, PTR_ERR(rdev), 815 + "Failed to register regulator(%s)\n", desc->name); 816 + 817 + regulator_desc++; 818 + } 819 + 820 + ret = devm_request_threaded_irq(pf9453->dev, pf9453->irq, NULL, pf9453_irq_handler, 821 + (IRQF_TRIGGER_FALLING | IRQF_ONESHOT), 822 + "pf9453-irq", pf9453); 823 + if (ret) 824 + return dev_err_probe(pf9453->dev, ret, "Failed to request IRQ: %d\n", pf9453->irq); 825 + 826 + /* Unmask all interrupt except PWRON/WDOG/RSVD */ 827 + ret = pf9453_pmic_write(pf9453, PF9453_REG_INT1_MASK, 828 + IRQ_ONKEY | IRQ_RESETKEY | IRQ_RSTB | IRQ_VR_FLT1 829 + | IRQ_LOWVSYS | IRQ_THERM_100 | IRQ_THERM_80, IRQ_RSVD); 830 + if (ret) 831 + return dev_err_probe(&i2c->dev, ret, "Unmask irq error\n"); 832 + 833 + if (of_property_read_bool(i2c->dev.of_node, "nxp,wdog_b-warm-reset")) 834 + reset_ctrl = WDOG_B_CFG_WARM; 835 + else 836 + reset_ctrl = WDOG_B_CFG_COLD; 837 + 838 + /* Set reset behavior on assertion of WDOG_B signal */ 839 + ret = pf9453_pmic_write(pf9453, PF9453_REG_RESET_CTRL, WDOG_B_CFG_MASK, reset_ctrl); 840 + if (ret) 841 + return dev_err_probe(&i2c->dev, ret, "Failed to set WDOG_B reset behavior\n"); 842 + 843 + /* 844 + * The driver uses the LDO1OUT_H register to control the LDO1 regulator. 845 + * This is only valid if the SD_VSEL input of the PMIC is high. Let's 846 + * check if the pin is available as GPIO and set it to high. 847 + */ 848 + pf9453->sd_vsel_gpio = gpiod_get_optional(pf9453->dev, "sd-vsel", GPIOD_OUT_HIGH); 849 + 850 + if (IS_ERR(pf9453->sd_vsel_gpio)) 851 + return dev_err_probe(&i2c->dev, PTR_ERR(pf9453->sd_vsel_gpio), 852 + "Failed to get SD_VSEL GPIO\n"); 853 + 854 + return 0; 855 + } 856 + 857 + static const struct of_device_id pf9453_of_match[] = { 858 + { 859 + .compatible = "nxp,pf9453", 860 + .data = pf9453_regulators, 861 + }, 862 + { } 863 + }; 864 + MODULE_DEVICE_TABLE(of, pf9453_of_match); 865 + 866 + static struct i2c_driver pf9453_i2c_driver = { 867 + .driver = { 868 + .name = "nxp-pf9453", 869 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 870 + .of_match_table = pf9453_of_match, 871 + }, 872 + .probe = pf9453_i2c_probe, 873 + }; 874 + 875 + module_i2c_driver(pf9453_i2c_driver); 876 + 877 + MODULE_AUTHOR("Joy Zou <joy.zou@nxp.com>"); 878 + MODULE_DESCRIPTION("NXP PF9453 Power Management IC driver"); 879 + MODULE_LICENSE("GPL");
+1 -1
drivers/regulator/rtq6752-regulator.c
··· 105 105 unsigned int *flags) 106 106 { 107 107 unsigned int val, events = 0; 108 - const unsigned int fault_mask[] = { 108 + static const unsigned int fault_mask[] = { 109 109 RTQ6752_PAVDDF_MASK, RTQ6752_NAVDDF_MASK }; 110 110 int rid = rdev_get_id(rdev), ret; 111 111
+1 -118
include/linux/device.h
··· 26 26 #include <linux/atomic.h> 27 27 #include <linux/uidgid.h> 28 28 #include <linux/gfp.h> 29 - #include <linux/overflow.h> 30 29 #include <linux/device/bus.h> 31 30 #include <linux/device/class.h> 31 + #include <linux/device/devres.h> 32 32 #include <linux/device/driver.h> 33 33 #include <linux/cleanup.h> 34 34 #include <asm/device.h> ··· 280 280 const struct bin_attribute *attr); 281 281 void device_remove_bin_file(struct device *dev, 282 282 const struct bin_attribute *attr); 283 - 284 - /* device resource management */ 285 - typedef void (*dr_release_t)(struct device *dev, void *res); 286 - typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 287 - 288 - void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, 289 - int nid, const char *name) __malloc; 290 - #define devres_alloc(release, size, gfp) \ 291 - __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) 292 - #define devres_alloc_node(release, size, gfp, nid) \ 293 - __devres_alloc_node(release, size, gfp, nid, #release) 294 - 295 - void devres_for_each_res(struct device *dev, dr_release_t release, 296 - dr_match_t match, void *match_data, 297 - void (*fn)(struct device *, void *, void *), 298 - void *data); 299 - void devres_free(void *res); 300 - void devres_add(struct device *dev, void *res); 301 - void *devres_find(struct device *dev, dr_release_t release, 302 - dr_match_t match, void *match_data); 303 - void *devres_get(struct device *dev, void *new_res, 304 - dr_match_t match, void *match_data); 305 - void *devres_remove(struct device *dev, dr_release_t release, 306 - dr_match_t match, void *match_data); 307 - int devres_destroy(struct device *dev, dr_release_t release, 308 - dr_match_t match, void *match_data); 309 - int devres_release(struct device *dev, dr_release_t release, 310 - dr_match_t match, void *match_data); 311 - 312 - /* devres group */ 313 - void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); 314 - void devres_close_group(struct device *dev, void *id); 315 - void devres_remove_group(struct device *dev, void *id); 316 - int devres_release_group(struct device *dev, void *id); 317 - 318 - /* managed devm_k.alloc/kfree for device drivers */ 319 - void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2); 320 - void *devm_krealloc(struct device *dev, void *ptr, size_t size, 321 - gfp_t gfp) __must_check __realloc_size(3); 322 - __printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, 323 - const char *fmt, va_list ap) __malloc; 324 - __printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, 325 - const char *fmt, ...) __malloc; 326 - static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) 327 - { 328 - return devm_kmalloc(dev, size, gfp | __GFP_ZERO); 329 - } 330 - static inline void *devm_kmalloc_array(struct device *dev, 331 - size_t n, size_t size, gfp_t flags) 332 - { 333 - size_t bytes; 334 - 335 - if (unlikely(check_mul_overflow(n, size, &bytes))) 336 - return NULL; 337 - 338 - return devm_kmalloc(dev, bytes, flags); 339 - } 340 - static inline void *devm_kcalloc(struct device *dev, 341 - size_t n, size_t size, gfp_t flags) 342 - { 343 - return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 344 - } 345 - static inline __realloc_size(3, 4) void * __must_check 346 - devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) 347 - { 348 - size_t bytes; 349 - 350 - if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) 351 - return NULL; 352 - 353 - return devm_krealloc(dev, p, bytes, flags); 354 - } 355 - 356 - void devm_kfree(struct device *dev, const void *p); 357 - char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; 358 - const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); 359 - void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp) 360 - __realloc_size(3); 361 - 362 - unsigned long devm_get_free_pages(struct device *dev, 363 - gfp_t gfp_mask, unsigned int order); 364 - void devm_free_pages(struct device *dev, unsigned long addr); 365 - 366 - #ifdef CONFIG_HAS_IOMEM 367 - void __iomem *devm_ioremap_resource(struct device *dev, 368 - const struct resource *res); 369 - void __iomem *devm_ioremap_resource_wc(struct device *dev, 370 - const struct resource *res); 371 - 372 - void __iomem *devm_of_iomap(struct device *dev, 373 - struct device_node *node, int index, 374 - resource_size_t *size); 375 - #else 376 - 377 - static inline 378 - void __iomem *devm_ioremap_resource(struct device *dev, 379 - const struct resource *res) 380 - { 381 - return ERR_PTR(-EINVAL); 382 - } 383 - 384 - static inline 385 - void __iomem *devm_ioremap_resource_wc(struct device *dev, 386 - const struct resource *res) 387 - { 388 - return ERR_PTR(-EINVAL); 389 - } 390 - 391 - static inline 392 - void __iomem *devm_of_iomap(struct device *dev, 393 - struct device_node *node, int index, 394 - resource_size_t *size) 395 - { 396 - return ERR_PTR(-EINVAL); 397 - } 398 - 399 - #endif 400 283 401 284 /* allows to add/remove a custom action to devres stack */ 402 285 int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
+129
include/linux/device/devres.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _DEVICE_DEVRES_H_ 3 + #define _DEVICE_DEVRES_H_ 4 + 5 + #include <linux/err.h> 6 + #include <linux/gfp_types.h> 7 + #include <linux/numa.h> 8 + #include <linux/overflow.h> 9 + #include <linux/stdarg.h> 10 + #include <linux/types.h> 11 + 12 + struct device; 13 + struct device_node; 14 + struct resource; 15 + 16 + /* device resource management */ 17 + typedef void (*dr_release_t)(struct device *dev, void *res); 18 + typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 19 + 20 + void * __malloc 21 + __devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, const char *name); 22 + #define devres_alloc(release, size, gfp) \ 23 + __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) 24 + #define devres_alloc_node(release, size, gfp, nid) \ 25 + __devres_alloc_node(release, size, gfp, nid, #release) 26 + 27 + void devres_for_each_res(struct device *dev, dr_release_t release, 28 + dr_match_t match, void *match_data, 29 + void (*fn)(struct device *, void *, void *), 30 + void *data); 31 + void devres_free(void *res); 32 + void devres_add(struct device *dev, void *res); 33 + void *devres_find(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 34 + void *devres_get(struct device *dev, void *new_res, dr_match_t match, void *match_data); 35 + void *devres_remove(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 36 + int devres_destroy(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 37 + int devres_release(struct device *dev, dr_release_t release, dr_match_t match, void *match_data); 38 + 39 + /* devres group */ 40 + void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); 41 + void devres_close_group(struct device *dev, void *id); 42 + void devres_remove_group(struct device *dev, void *id); 43 + int devres_release_group(struct device *dev, void *id); 44 + 45 + /* managed devm_k.alloc/kfree for device drivers */ 46 + void * __alloc_size(2) 47 + devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); 48 + void * __must_check __realloc_size(3) 49 + devm_krealloc(struct device *dev, void *ptr, size_t size, gfp_t gfp); 50 + static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) 51 + { 52 + return devm_kmalloc(dev, size, gfp | __GFP_ZERO); 53 + } 54 + static inline void *devm_kmalloc_array(struct device *dev, size_t n, size_t size, gfp_t flags) 55 + { 56 + size_t bytes; 57 + 58 + if (unlikely(check_mul_overflow(n, size, &bytes))) 59 + return NULL; 60 + 61 + return devm_kmalloc(dev, bytes, flags); 62 + } 63 + static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags) 64 + { 65 + return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); 66 + } 67 + static inline __realloc_size(3, 4) void * __must_check 68 + devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) 69 + { 70 + size_t bytes; 71 + 72 + if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) 73 + return NULL; 74 + 75 + return devm_krealloc(dev, p, bytes, flags); 76 + } 77 + 78 + void devm_kfree(struct device *dev, const void *p); 79 + 80 + void * __realloc_size(3) 81 + devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); 82 + static inline void *devm_kmemdup_array(struct device *dev, const void *src, 83 + size_t n, size_t size, gfp_t flags) 84 + { 85 + return devm_kmemdup(dev, src, size_mul(size, n), flags); 86 + } 87 + 88 + char * __malloc 89 + devm_kstrdup(struct device *dev, const char *s, gfp_t gfp); 90 + const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); 91 + char * __printf(3, 0) __malloc 92 + devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap); 93 + char * __printf(3, 4) __malloc 94 + devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...); 95 + 96 + unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order); 97 + void devm_free_pages(struct device *dev, unsigned long addr); 98 + 99 + #ifdef CONFIG_HAS_IOMEM 100 + 101 + void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res); 102 + void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res); 103 + 104 + void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, 105 + resource_size_t *size); 106 + #else 107 + 108 + static inline 109 + void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res) 110 + { 111 + return IOMEM_ERR_PTR(-EINVAL); 112 + } 113 + 114 + static inline 115 + void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res) 116 + { 117 + return IOMEM_ERR_PTR(-EINVAL); 118 + } 119 + 120 + static inline 121 + void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, 122 + resource_size_t *size) 123 + { 124 + return IOMEM_ERR_PTR(-EINVAL); 125 + } 126 + 127 + #endif 128 + 129 + #endif /* _DEVICE_DEVRES_H_ */
+3
include/linux/err.h
··· 44 44 /* Return the pointer in the percpu address space. */ 45 45 #define ERR_PTR_PCPU(error) ((void __percpu *)(unsigned long)ERR_PTR(error)) 46 46 47 + /* Cast an error pointer to __iomem. */ 48 + #define IOMEM_ERR_PTR(error) (__force void __iomem *)ERR_PTR(error) 49 + 47 50 /** 48 51 * PTR_ERR - Extract the error code from an error pointer. 49 52 * @ptr: An error pointer.
-2
include/linux/io.h
··· 65 65 } 66 66 #endif 67 67 68 - #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err) 69 - 70 68 void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, 71 69 resource_size_t size); 72 70 void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
+6
include/linux/regulator/consumer.h
··· 677 677 #endif 678 678 679 679 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_REGULATOR) 680 + struct regulator *__must_check of_regulator_get(struct device *dev, 681 + struct device_node *node, 682 + const char *id); 683 + struct regulator *__must_check devm_of_regulator_get(struct device *dev, 684 + struct device_node *node, 685 + const char *id); 680 686 struct regulator *__must_check of_regulator_get_optional(struct device *dev, 681 687 struct device_node *node, 682 688 const char *id);