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

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

Pull regulator updates from Mark Brown:
"This has been an extremely quiet release for the regulator API, aside
from bugfixes and small enhancements the only thing that really stands
out are the new drivers for Action Semiconductors ACT8945A, HiSilicon
HI665x, and the Maxim MAX20024 and MAX77620"

* tag 'regulator-v4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (46 commits)
regulator: pwm: Add support to have multiple instance of pwm regulator
regulator: pwm: Fix calculation of voltage-to-duty cycle
regulator: of: Use of_property_read_u32() for reading min/max
regulator: pv88060: fix incorrect clear of event register
regulator: pv88090: fix incorrect clear of event register
regulator: max77620: Add support to configure active-discharge
regulator: core: Add support for active-discharge configuration
regulator: helper: Add helper to configure active-discharge using regmap
regulator: core: Add support for active-discharge configuration
regulator: DT: Add DT property for active-discharge configuration
regulator: act8865: Specify fixed voltage of 3.3V for ACT8600's REG9
regulator: act8865: Rename platform_data field to init_data
regulator: act8865: Remove "static" from local variable
ASoC: cs4271: add regulator consumer support
regulator: max77620: Remove duplicate module alias
regulator: max77620: Eliminate duplicate code
regulator: max77620: Remove unused fields
regulator: core: fix crash in error path of regulator_register
regulator: core: Request GPIO before creating sysfs entries
regulator: gpio: don't print error on EPROBE_DEFER
...

+1921 -141
+80
Documentation/devicetree/bindings/regulator/act8945a-regulator.txt
··· 1 + Device-Tree bindings for regulators of Active-semi ACT8945A Multi-Function Device 2 + 3 + Required properties: 4 + - compatible: "active-semi,act8945a", please refer to ../mfd/act8945a.txt. 5 + 6 + Optional properties: 7 + - active-semi,vsel-high: Indicates if the VSEL pin is set to logic-high. 8 + If this property is missing, assume the VSEL pin is set to logic-low. 9 + 10 + Optional input supply properties: 11 + - vp1-supply: The input supply for REG_DCDC1 12 + - vp2-supply: The input supply for REG_DCDC2 13 + - vp3-supply: The input supply for REG_DCDC3 14 + - inl45-supply: The input supply for REG_LDO1 and REG_LDO2 15 + - inl67-supply: The input supply for REG_LDO3 and REG_LDO4 16 + 17 + Any standard regulator properties can be used to configure the single regulator. 18 + 19 + The valid names for regulators are: 20 + REG_DCDC1, REG_DCDC2, REG_DCDC3, REG_LDO1, REG_LDO2, REG_LDO3, REG_LDO4. 21 + 22 + Example: 23 + pmic@5b { 24 + compatible = "active-semi,act8945a"; 25 + reg = <0x5b>; 26 + status = "okay"; 27 + 28 + active-semi,vsel-high; 29 + 30 + regulators { 31 + vdd_1v35_reg: REG_DCDC1 { 32 + regulator-name = "VDD_1V35"; 33 + regulator-min-microvolt = <1350000>; 34 + regulator-max-microvolt = <1350000>; 35 + regulator-always-on; 36 + }; 37 + 38 + vdd_1v2_reg: REG_DCDC2 { 39 + regulator-name = "VDD_1V2"; 40 + regulator-min-microvolt = <1100000>; 41 + regulator-max-microvolt = <1300000>; 42 + regulator-always-on; 43 + }; 44 + 45 + vdd_3v3_reg: REG_DCDC3 { 46 + regulator-name = "VDD_3V3"; 47 + regulator-min-microvolt = <3300000>; 48 + regulator-max-microvolt = <3300000>; 49 + regulator-always-on; 50 + }; 51 + 52 + vdd_fuse_reg: REG_LDO1 { 53 + regulator-name = "VDD_FUSE"; 54 + regulator-min-microvolt = <2500000>; 55 + regulator-max-microvolt = <2500000>; 56 + regulator-always-on; 57 + }; 58 + 59 + vdd_3v3_lp_reg: REG_LDO2 { 60 + regulator-name = "VDD_3V3_LP"; 61 + regulator-min-microvolt = <3300000>; 62 + regulator-max-microvolt = <3300000>; 63 + regulator-always-on; 64 + }; 65 + 66 + vdd_led_reg: REG_LDO3 { 67 + regulator-name = "VDD_LED"; 68 + regulator-min-microvolt = <3300000>; 69 + regulator-max-microvolt = <3300000>; 70 + regulator-always-on; 71 + }; 72 + 73 + vdd_sdhc_1v8_reg: REG_LDO4 { 74 + regulator-name = "VDD_SDHC_1V8"; 75 + regulator-min-microvolt = <1800000>; 76 + regulator-max-microvolt = <1800000>; 77 + regulator-always-on; 78 + }; 79 + }; 80 + };
+29
Documentation/devicetree/bindings/regulator/hisilicon,hi655x-regulator.txt
··· 1 + Hisilicon Hi655x Voltage regulators 2 + 3 + Note: 4 + The Hi655x regulator control is managed by Hi655x PMIC. 5 + So the node of this regulator must be child node of Hi655x 6 + PMIC node. 7 + 8 + The driver uses the regulator core framework, so please also 9 + take the bindings of regulator.txt for reference. 10 + 11 + The valid names for regulators are: 12 + 13 + LDO2_2V8 LDO7_SDIO LDO10_2V85 LDO13_1V8 LDO14_2V8 14 + LDO15_1V8 LDO17_2V5 LDO19_3V0 LDO21_1V8 LDO22_1V2 15 + 16 + Example: 17 + pmic: pmic@f8000000 { 18 + compatible = "hisilicon,hi655x-pmic"; 19 + ... 20 + regulators { 21 + ldo2: LDO2@a21 { 22 + regulator-name = "LDO2_2V8"; 23 + regulator-min-microvolt = <2500000>; 24 + regulator-max-microvolt = <3200000>; 25 + regulator-enable-ramp-delay = <120>; 26 + }; 27 + ... 28 + } 29 + }
+1
Documentation/devicetree/bindings/regulator/lp872x.txt
··· 28 28 - ti,dvs-gpio: GPIO specifier for external DVS pin control of LP872x devices. 29 29 - ti,dvs-vsel: DVS selector. 0 = SEL_V1, 1 = SEL_V2. 30 30 - ti,dvs-state: initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH. 31 + - enable-gpios: GPIO specifier for EN pin control of LP872x devices. 31 32 32 33 Sub nodes for regulator_init_data 33 34 LP8720 has maximum 6 nodes. (child name: ldo1 ~ 5 and buck)
+1 -1
Documentation/devicetree/bindings/regulator/max77802.txt
··· 60 60 1: Normal regulator voltage output mode. 61 61 3: Low Power which reduces the quiescent current down to only 1uA 62 62 63 - The list of valid modes are defined in the dt-bindings/clock/maxim,max77802.h 63 + The valid modes list is defined in the dt-bindings/regulator/maxim,max77802.h 64 64 header and can be included by device tree source files. 65 65 66 66 The standard "regulator-mode" property can only be used for regulators that
+200
Documentation/devicetree/bindings/regulator/regulator-max77620.txt
··· 1 + Regulator DT binding for MAX77620 Power management IC from Maxim Semiconductor. 2 + 3 + Device has multiple DCDC(sd[0-3] and LDOs(ldo[0-8]). The input supply 4 + of these regulators are defined under parent device node. 5 + Details of regulator properties are defined as child node under 6 + sub-node "regulators" which is child node of device node. 7 + 8 + Please refer file <Documentation/devicetree/bindings/regulator/regulator.txt> 9 + for common regulator bindings used by client. 10 + 11 + Following are properties of parent node related to regulators. 12 + 13 + Optional properties: 14 + ------------------- 15 + The input supply of regulators are the optional properties on the 16 + parent device node. The input supply of these regulators are provided 17 + through following properties: 18 + in-sd0-supply: Input supply for SD0, INA-SD0 or INB-SD0 pins. 19 + in-sd1-supply: Input supply for SD1. 20 + in-sd2-supply: Input supply for SD2. 21 + in-sd3-supply: Input supply for SD3. 22 + in-ldo0-1-supply: Input supply for LDO0 and LDO1. 23 + in-ldo2-supply: Input supply for LDO2. 24 + in-ldo3-5-supply: Input supply for LDO3 and LDO5 25 + in-ldo4-6-supply: Input supply for LDO4 and LDO6. 26 + in-ldo7-8-supply: Input supply for LDO7 and LDO8. 27 + 28 + Optional sub nodes for regulators under "regulators" subnode: 29 + ------------------------------------------------------------ 30 + The subnodes name is the name of regulator and it must be one of: 31 + sd[0-3], ldo[0-8] 32 + 33 + Each sub-node should contain the constraints and initialization 34 + information for that regulator. The definition for each of these 35 + nodes is defined using the standard binding for regulators found at 36 + <Documentation/devicetree/bindings/regulator/regulator.txt>. 37 + 38 + Theres are also additional properties for SD/LDOs. These additional properties 39 + are required to configure FPS configuration parameters for SDs and LDOs. 40 + Please refer <devicetree/bindings/mfd/max77620.txt> for more detail of Flexible 41 + Power Sequence (FPS). 42 + Following are additional properties: 43 + 44 + - maxim,active-fps-source: FPS source for the regulators to get 45 + enabled/disabled when system is in 46 + active state. Valid values are: 47 + - MAX77620_FPS_SRC_0, 48 + FPS source is FPS0. 49 + - MAX77620_FPS_SRC_1, 50 + FPS source is FPS1 51 + - MAX77620_FPS_SRC_2 and 52 + FPS source is FPS2 53 + - MAX77620_FPS_SRC_NONE. 54 + Regulator is not controlled 55 + by FPS events and it gets 56 + enabled/disabled by register 57 + access. 58 + Absence of this property will leave 59 + the FPS configuration register for that 60 + regulator to default configuration. 61 + 62 + - maxim,active-fps-power-up-slot: Sequencing event slot number on which 63 + the regulator get enabled when 64 + master FPS input event set to HIGH. 65 + Valid values are 0 to 7. 66 + This is applicable if FPS source is 67 + selected as FPS0, FPS1 or FPS2. 68 + 69 + - maxim,active-fps-power-down-slot: Sequencing event slot number on which 70 + the regulator get disabled when master 71 + FPS input event set to LOW. 72 + Valid values are 0 to 7. 73 + This is applicable if FPS source is 74 + selected as FPS0, FPS1 or FPS2. 75 + 76 + - maxim,suspend-fps-source: This is same as property 77 + "maxim,active-fps-source" but value 78 + get configured when system enters in 79 + to suspend state. 80 + 81 + - maxim,suspend-fps-power-up-slot: This is same as property 82 + "maxim,active-fps-power-up-slot" but 83 + this value get configured into FPS 84 + configuration register when system 85 + enters into suspend. 86 + This is applicable if suspend state 87 + FPS source is selected as FPS0, FPS1 or 88 + 89 + - maxim,suspend-fps-power-down-slot: This is same as property 90 + "maxim,active-fps-power-down-slot" but 91 + this value get configured into FPS 92 + configuration register when system 93 + enters into suspend. 94 + This is applicable if suspend state 95 + FPS source is selected as FPS0, FPS1 or 96 + FPS2. 97 + 98 + Example: 99 + -------- 100 + #include <dt-bindings/mfd/max77620.h> 101 + ... 102 + max77620@3c { 103 + in-ldo0-1-supply = <&max77620_sd2>; 104 + in-ldo7-8-supply = <&max77620_sd2>; 105 + regulators { 106 + sd0 { 107 + regulator-name = "vdd-core"; 108 + regulator-min-microvolt = <600000>; 109 + regulator-max-microvolt = <1400000>; 110 + regulator-boot-on; 111 + regulator-always-on; 112 + maxim,active-fps-source = <MAX77620_FPS_SRC_1>; 113 + }; 114 + 115 + sd1 { 116 + regulator-name = "vddio-ddr"; 117 + regulator-min-microvolt = <1200000>; 118 + regulator-max-microvolt = <1200000>; 119 + regulator-always-on; 120 + regulator-boot-on; 121 + maxim,active-fps-source = <MAX77620_FPS_SRC_0>; 122 + }; 123 + 124 + sd2 { 125 + regulator-name = "vdd-pre-reg"; 126 + regulator-min-microvolt = <1350000>; 127 + regulator-max-microvolt = <1350000>; 128 + }; 129 + 130 + sd3 { 131 + regulator-name = "vdd-1v8"; 132 + regulator-min-microvolt = <1800000>; 133 + regulator-max-microvolt = <1800000>; 134 + regulator-always-on; 135 + regulator-boot-on; 136 + }; 137 + 138 + ldo0 { 139 + regulator-name = "avdd-sys"; 140 + regulator-min-microvolt = <1200000>; 141 + regulator-max-microvolt = <1200000>; 142 + regulator-always-on; 143 + regulator-boot-on; 144 + }; 145 + 146 + ldo1 { 147 + regulator-name = "vdd-pex"; 148 + regulator-min-microvolt = <1050000>; 149 + regulator-max-microvolt = <1050000>; 150 + }; 151 + 152 + ldo2 { 153 + regulator-name = "vddio-sdmmc3"; 154 + regulator-min-microvolt = <1800000>; 155 + regulator-max-microvolt = <3300000>; 156 + }; 157 + 158 + ldo3 { 159 + regulator-name = "vdd-cam-hv"; 160 + regulator-min-microvolt = <2800000>; 161 + regulator-max-microvolt = <2800000>; 162 + }; 163 + 164 + ldo4 { 165 + regulator-name = "vdd-rtc"; 166 + regulator-min-microvolt = <1250000>; 167 + regulator-max-microvolt = <1250000>; 168 + regulator-always-on; 169 + regulator-boot-on; 170 + }; 171 + 172 + ldo5 { 173 + regulator-name = "avdd-ts-hv"; 174 + regulator-min-microvolt = <3000000>; 175 + regulator-max-microvolt = <3000000>; 176 + }; 177 + 178 + ldo6 { 179 + regulator-name = "vdd-ts"; 180 + regulator-min-microvolt = <1800000>; 181 + regulator-max-microvolt = <1800000>; 182 + regulator-always-on; 183 + regulator-boot-on; 184 + }; 185 + 186 + ldo7 { 187 + regulator-name = "vdd-gen-pll-edp"; 188 + regulator-min-microvolt = <1050000>; 189 + regulator-max-microvolt = <1050000>; 190 + regulator-always-on; 191 + regulator-boot-on; 192 + }; 193 + 194 + ldo8 { 195 + regulator-name = "vdd-hdmi-dp"; 196 + regulator-min-microvolt = <1050000>; 197 + regulator-max-microvolt = <1050000>; 198 + }; 199 + }; 200 + };
+5
Documentation/devicetree/bindings/regulator/regulator.txt
··· 44 44 any consumer request. 45 45 - regulator-pull-down: Enable pull down resistor when the regulator is disabled. 46 46 - regulator-over-current-protection: Enable over current protection. 47 + - regulator-active-discharge: tristate, enable/disable active discharge of 48 + regulators. The values are: 49 + 0: Disable active discharge. 50 + 1: Enable active discharge. 51 + Absence of this property will leave configuration to default. 47 52 48 53 Deprecated properties: 49 54 - regulator-compatible: If a regulator chip contains multiple
+7
Documentation/devicetree/bindings/sound/cs4271.txt
··· 33 33 Note that this is not needed in case the clocks are stable 34 34 throughout the entire runtime of the codec. 35 35 36 + - vd-supply: Digital power 37 + - vl-supply: Logic power 38 + - va-supply: Analog Power 39 + 36 40 Examples: 37 41 38 42 codec_i2c: cs4271@10 { 39 43 compatible = "cirrus,cs4271"; 40 44 reg = <0x10>; 41 45 reset-gpio = <&gpio 23 0>; 46 + vd-supply = <&vdd_3v3_reg>; 47 + vl-supply = <&vdd_3v3_reg>; 48 + va-supply = <&vdd_3v3_reg>; 42 49 }; 43 50 44 51 codec_spi: cs4271@0 {
+2 -2
MAINTAINERS
··· 6910 6910 M: Javier Martinez Canillas <javier@osg.samsung.com> 6911 6911 L: linux-kernel@vger.kernel.org 6912 6912 S: Supported 6913 - F: drivers/*/*max77802.c 6913 + F: drivers/*/*max77802*.c 6914 6914 F: Documentation/devicetree/bindings/*/*max77802.txt 6915 6915 F: include/dt-bindings/*/*max77802.h 6916 6916 ··· 6920 6920 L: linux-kernel@vger.kernel.org 6921 6921 S: Supported 6922 6922 F: drivers/*/max14577.c 6923 - F: drivers/*/max77686.c 6923 + F: drivers/*/max77686*.c 6924 6924 F: drivers/*/max77693.c 6925 6925 F: drivers/extcon/extcon-max14577.c 6926 6926 F: drivers/extcon/extcon-max77693.c
+26
drivers/regulator/Kconfig
··· 78 78 This driver controls a active-semi act8865 voltage output 79 79 regulator via I2C bus. 80 80 81 + config REGULATOR_ACT8945A 82 + tristate "Active-semi ACT8945A voltage regulator" 83 + depends on MFD_ACT8945A 84 + help 85 + This driver controls a active-semi ACT8945A voltage regulator 86 + via I2C bus. The ACT8945A features three step-down DC/DC converters 87 + and four low-dropout linear regulators, along with a ActivePath 88 + battery charger. 89 + 81 90 config REGULATOR_AD5398 82 91 tristate "Analog Devices AD5398/AD5821 regulators" 83 92 depends on I2C ··· 270 261 21 general purpose LDOs, 3 dedicated LDOs, and 5 BUCKs. All 271 262 of them come with support to either ECO (idle) or sleep mode. 272 263 264 + config REGULATOR_HI655X 265 + tristate "Hisilicon HI655X PMIC regulators support" 266 + depends on ARCH_HISI || COMPILE_TEST 267 + depends on MFD_HI655X_PMIC && OF 268 + help 269 + This driver provides support for the voltage regulators of the 270 + Hisilicon Hi655x PMIC device. 271 + 273 272 config REGULATOR_ISL9305 274 273 tristate "Intersil ISL9305 regulator" 275 274 depends on I2C ··· 359 342 This driver controls a Maxim 1586 or 1587 voltage output 360 343 regulator via I2C bus. The provided regulator is suitable 361 344 for PXA27x chips to control VCC_CORE and VCC_USIM voltages. 345 + 346 + config REGULATOR_MAX77620 347 + tristate "Maxim 77620/MAX20024 voltage regulator" 348 + depends on MFD_MAX77620 349 + help 350 + This driver controls Maxim MAX77620 voltage output regulator 351 + via I2C bus. The provided regulator is suitable for Tegra 352 + chip to control Step-Down DC-DC and LDOs. Say Y here to 353 + enable the regulator driver. 362 354 363 355 config REGULATOR_MAX8649 364 356 tristate "Maxim 8649 voltage regulator"
+6 -3
drivers/regulator/Makefile
··· 15 15 obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 16 16 obj-$(CONFIG_REGULATOR_AB8500) += ab8500-ext.o ab8500.o 17 17 obj-$(CONFIG_REGULATOR_ACT8865) += act8865-regulator.o 18 + obj-$(CONFIG_REGULATOR_ACT8945A) += act8945a-regulator.o 18 19 obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o 19 20 obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o 20 21 obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o ··· 35 34 obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 36 35 obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o 37 36 obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o 37 + obj-$(CONFIG_REGULATOR_HI655X) += hi655x-regulator.o 38 38 obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 39 39 obj-$(CONFIG_REGULATOR_ISL9305) += isl9305.o 40 40 obj-$(CONFIG_REGULATOR_LM363X) += lm363x-regulator.o ··· 48 46 obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o 49 47 obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o 50 48 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 49 + obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o 51 50 obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 52 51 obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 53 52 obj-$(CONFIG_REGULATOR_MAX8907) += max8907-regulator.o ··· 57 54 obj-$(CONFIG_REGULATOR_MAX8973) += max8973-regulator.o 58 55 obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o 59 56 obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o 60 - obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o 57 + obj-$(CONFIG_REGULATOR_MAX77686) += max77686-regulator.o 61 58 obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o 62 - obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o 59 + obj-$(CONFIG_REGULATOR_MAX77802) += max77802-regulator.o 63 60 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 64 61 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 65 62 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o ··· 101 98 obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o 102 99 obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o 103 100 obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o 104 - obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress.o 101 + obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o 105 102 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 106 103 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 107 104 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
+4 -4
drivers/regulator/act8865-regulator.c
··· 218 218 .ops = &act8865_ldo_ops, 219 219 .type = REGULATOR_VOLTAGE, 220 220 .n_voltages = 1, 221 - .fixed_uV = 1800000, 221 + .fixed_uV = 3300000, 222 222 .enable_reg = ACT8600_LDO910_CTRL, 223 223 .enable_mask = ACT8865_ENA, 224 224 .owner = THIS_MODULE, ··· 369 369 for (i = 0; i < num_matches; i++) { 370 370 regulator->id = i; 371 371 regulator->name = matches[i].name; 372 - regulator->platform_data = matches[i].init_data; 372 + regulator->init_data = matches[i].init_data; 373 373 of_node[i] = matches[i].of_node; 374 374 regulator++; 375 375 } ··· 396 396 397 397 for (i = 0; i < pdata->num_regulators; i++) { 398 398 if (pdata->regulators[i].id == id) 399 - return pdata->regulators[i].platform_data; 399 + return pdata->regulators[i].init_data; 400 400 } 401 401 402 402 return NULL; ··· 415 415 static int act8865_pmic_probe(struct i2c_client *client, 416 416 const struct i2c_device_id *i2c_id) 417 417 { 418 - static const struct regulator_desc *regulators; 418 + const struct regulator_desc *regulators; 419 419 struct act8865_platform_data pdata_of, *pdata; 420 420 struct device *dev = &client->dev; 421 421 struct device_node **of_node;
+165
drivers/regulator/act8945a-regulator.c
··· 1 + /* 2 + * Voltage regulation driver for active-semi ACT8945A PMIC 3 + * 4 + * Copyright (C) 2015 Atmel Corporation 5 + * 6 + * Author: Wenyou Yang <wenyou.yang@atmel.com> 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation; either version 2 of the 11 + * License, or (at your option) any later version. 12 + * 13 + */ 14 + 15 + #include <linux/module.h> 16 + #include <linux/of_device.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/regulator/driver.h> 19 + #include <linux/regulator/machine.h> 20 + 21 + /** 22 + * ACT8945A Global Register Map. 23 + */ 24 + #define ACT8945A_SYS_MODE 0x00 25 + #define ACT8945A_SYS_CTRL 0x01 26 + #define ACT8945A_DCDC1_VSET1 0x20 27 + #define ACT8945A_DCDC1_VSET2 0x21 28 + #define ACT8945A_DCDC1_CTRL 0x22 29 + #define ACT8945A_DCDC2_VSET1 0x30 30 + #define ACT8945A_DCDC2_VSET2 0x31 31 + #define ACT8945A_DCDC2_CTRL 0x32 32 + #define ACT8945A_DCDC3_VSET1 0x40 33 + #define ACT8945A_DCDC3_VSET2 0x41 34 + #define ACT8945A_DCDC3_CTRL 0x42 35 + #define ACT8945A_LDO1_VSET 0x50 36 + #define ACT8945A_LDO1_CTRL 0x51 37 + #define ACT8945A_LDO2_VSET 0x54 38 + #define ACT8945A_LDO2_CTRL 0x55 39 + #define ACT8945A_LDO3_VSET 0x60 40 + #define ACT8945A_LDO3_CTRL 0x61 41 + #define ACT8945A_LDO4_VSET 0x64 42 + #define ACT8945A_LDO4_CTRL 0x65 43 + 44 + /** 45 + * Field Definitions. 46 + */ 47 + #define ACT8945A_ENA 0x80 /* ON - [7] */ 48 + #define ACT8945A_VSEL_MASK 0x3F /* VSET - [5:0] */ 49 + 50 + /** 51 + * ACT8945A Voltage Number 52 + */ 53 + #define ACT8945A_VOLTAGE_NUM 64 54 + 55 + enum { 56 + ACT8945A_ID_DCDC1, 57 + ACT8945A_ID_DCDC2, 58 + ACT8945A_ID_DCDC3, 59 + ACT8945A_ID_LDO1, 60 + ACT8945A_ID_LDO2, 61 + ACT8945A_ID_LDO3, 62 + ACT8945A_ID_LDO4, 63 + ACT8945A_REG_NUM, 64 + }; 65 + 66 + static const struct regulator_linear_range act8945a_voltage_ranges[] = { 67 + REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000), 68 + REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000), 69 + REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), 70 + }; 71 + 72 + static struct regulator_ops act8945a_ops = { 73 + .list_voltage = regulator_list_voltage_linear_range, 74 + .map_voltage = regulator_map_voltage_linear_range, 75 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 76 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 77 + .enable = regulator_enable_regmap, 78 + .disable = regulator_disable_regmap, 79 + .is_enabled = regulator_is_enabled_regmap, 80 + }; 81 + 82 + #define ACT89xx_REG(_name, _family, _id, _vsel_reg, _supply) \ 83 + [_family##_ID_##_id] = { \ 84 + .name = _name, \ 85 + .supply_name = _supply, \ 86 + .of_match = of_match_ptr("REG_"#_id), \ 87 + .regulators_node = of_match_ptr("regulators"), \ 88 + .id = _family##_ID_##_id, \ 89 + .type = REGULATOR_VOLTAGE, \ 90 + .ops = &act8945a_ops, \ 91 + .n_voltages = ACT8945A_VOLTAGE_NUM, \ 92 + .linear_ranges = act8945a_voltage_ranges, \ 93 + .n_linear_ranges = ARRAY_SIZE(act8945a_voltage_ranges), \ 94 + .vsel_reg = _family##_##_id##_##_vsel_reg, \ 95 + .vsel_mask = ACT8945A_VSEL_MASK, \ 96 + .enable_reg = _family##_##_id##_CTRL, \ 97 + .enable_mask = ACT8945A_ENA, \ 98 + .owner = THIS_MODULE, \ 99 + } 100 + 101 + static const struct regulator_desc act8945a_regulators[] = { 102 + ACT89xx_REG("DCDC_REG1", ACT8945A, DCDC1, VSET1, "vp1"), 103 + ACT89xx_REG("DCDC_REG2", ACT8945A, DCDC2, VSET1, "vp2"), 104 + ACT89xx_REG("DCDC_REG3", ACT8945A, DCDC3, VSET1, "vp3"), 105 + ACT89xx_REG("LDO_REG1", ACT8945A, LDO1, VSET, "inl45"), 106 + ACT89xx_REG("LDO_REG2", ACT8945A, LDO2, VSET, "inl45"), 107 + ACT89xx_REG("LDO_REG3", ACT8945A, LDO3, VSET, "inl67"), 108 + ACT89xx_REG("LDO_REG4", ACT8945A, LDO4, VSET, "inl67"), 109 + }; 110 + 111 + static const struct regulator_desc act8945a_alt_regulators[] = { 112 + ACT89xx_REG("DCDC_REG1", ACT8945A, DCDC1, VSET2, "vp1"), 113 + ACT89xx_REG("DCDC_REG2", ACT8945A, DCDC2, VSET2, "vp2"), 114 + ACT89xx_REG("DCDC_REG3", ACT8945A, DCDC3, VSET2, "vp3"), 115 + ACT89xx_REG("LDO_REG1", ACT8945A, LDO1, VSET, "inl45"), 116 + ACT89xx_REG("LDO_REG2", ACT8945A, LDO2, VSET, "inl45"), 117 + ACT89xx_REG("LDO_REG3", ACT8945A, LDO3, VSET, "inl67"), 118 + ACT89xx_REG("LDO_REG4", ACT8945A, LDO4, VSET, "inl67"), 119 + }; 120 + 121 + static int act8945a_pmic_probe(struct platform_device *pdev) 122 + { 123 + struct regulator_config config = { }; 124 + const struct regulator_desc *regulators; 125 + struct regulator_dev *rdev; 126 + int i, num_regulators; 127 + bool voltage_select; 128 + 129 + voltage_select = of_property_read_bool(pdev->dev.parent->of_node, 130 + "active-semi,vsel-high"); 131 + 132 + if (voltage_select) { 133 + regulators = act8945a_alt_regulators; 134 + num_regulators = ARRAY_SIZE(act8945a_alt_regulators); 135 + } else { 136 + regulators = act8945a_regulators; 137 + num_regulators = ARRAY_SIZE(act8945a_regulators); 138 + } 139 + 140 + config.dev = &pdev->dev; 141 + config.dev->of_node = pdev->dev.parent->of_node; 142 + for (i = 0; i < num_regulators; i++) { 143 + rdev = devm_regulator_register(&pdev->dev, &regulators[i], &config); 144 + if (IS_ERR(rdev)) { 145 + dev_err(&pdev->dev, 146 + "failed to register %s regulator\n", 147 + regulators[i].name); 148 + return PTR_ERR(rdev); 149 + } 150 + } 151 + 152 + return 0; 153 + } 154 + 155 + static struct platform_driver act8945a_pmic_driver = { 156 + .driver = { 157 + .name = "act8945a-regulator", 158 + }, 159 + .probe = act8945a_pmic_probe, 160 + }; 161 + module_platform_driver(act8945a_pmic_driver); 162 + 163 + MODULE_DESCRIPTION("Active-semi ACT8945A voltage regulator driver"); 164 + MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>"); 165 + MODULE_LICENSE("GPL");
+4 -2
drivers/regulator/ad5398.c
··· 58 58 59 59 val = cpu_to_be16(data); 60 60 ret = i2c_master_send(client, (char *)&val, 2); 61 - if (ret < 0) 61 + if (ret != 2) { 62 62 dev_err(&client->dev, "I2C write error\n"); 63 + return ret < 0 ? ret : -EIO; 64 + } 63 65 64 - return ret; 66 + return 0; 65 67 } 66 68 67 69 static int ad5398_get_current_limit(struct regulator_dev *rdev)
+25 -31
drivers/regulator/axp20x-regulator.c
··· 39 39 #define AXP_DESC_IO(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 40 40 _vmask, _ereg, _emask, _enable_val, _disable_val) \ 41 41 [_family##_##_id] = { \ 42 - .name = #_id, \ 42 + .name = (_match), \ 43 43 .supply_name = (_supply), \ 44 44 .of_match = of_match_ptr(_match), \ 45 45 .regulators_node = of_match_ptr("regulators"), \ ··· 61 61 #define AXP_DESC(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 62 62 _vmask, _ereg, _emask) \ 63 63 [_family##_##_id] = { \ 64 - .name = #_id, \ 64 + .name = (_match), \ 65 65 .supply_name = (_supply), \ 66 66 .of_match = of_match_ptr(_match), \ 67 67 .regulators_node = of_match_ptr("regulators"), \ ··· 78 78 .ops = &axp20x_ops, \ 79 79 } 80 80 81 - #define AXP_DESC_SW(_family, _id, _match, _supply, _min, _max, _step, _vreg, \ 82 - _vmask, _ereg, _emask) \ 81 + #define AXP_DESC_SW(_family, _id, _match, _supply, _ereg, _emask) \ 83 82 [_family##_##_id] = { \ 84 - .name = #_id, \ 83 + .name = (_match), \ 85 84 .supply_name = (_supply), \ 86 85 .of_match = of_match_ptr(_match), \ 87 86 .regulators_node = of_match_ptr("regulators"), \ 88 87 .type = REGULATOR_VOLTAGE, \ 89 88 .id = _family##_##_id, \ 90 - .n_voltages = (((_max) - (_min)) / (_step) + 1), \ 91 89 .owner = THIS_MODULE, \ 92 - .min_uV = (_min) * 1000, \ 93 - .uV_step = (_step) * 1000, \ 94 - .vsel_reg = (_vreg), \ 95 - .vsel_mask = (_vmask), \ 96 90 .enable_reg = (_ereg), \ 97 91 .enable_mask = (_emask), \ 98 92 .ops = &axp20x_ops_sw, \ ··· 94 100 95 101 #define AXP_DESC_FIXED(_family, _id, _match, _supply, _volt) \ 96 102 [_family##_##_id] = { \ 97 - .name = #_id, \ 103 + .name = (_match), \ 98 104 .supply_name = (_supply), \ 99 105 .of_match = of_match_ptr(_match), \ 100 106 .regulators_node = of_match_ptr("regulators"), \ ··· 106 112 .ops = &axp20x_ops_fixed \ 107 113 } 108 114 109 - #define AXP_DESC_TABLE(_family, _id, _match, _supply, _table, _vreg, _vmask, \ 110 - _ereg, _emask) \ 115 + #define AXP_DESC_RANGES(_family, _id, _match, _supply, _ranges, _n_voltages, \ 116 + _vreg, _vmask, _ereg, _emask) \ 111 117 [_family##_##_id] = { \ 112 - .name = #_id, \ 118 + .name = (_match), \ 113 119 .supply_name = (_supply), \ 114 120 .of_match = of_match_ptr(_match), \ 115 121 .regulators_node = of_match_ptr("regulators"), \ 116 122 .type = REGULATOR_VOLTAGE, \ 117 123 .id = _family##_##_id, \ 118 - .n_voltages = ARRAY_SIZE(_table), \ 124 + .n_voltages = (_n_voltages), \ 119 125 .owner = THIS_MODULE, \ 120 126 .vsel_reg = (_vreg), \ 121 127 .vsel_mask = (_vmask), \ 122 128 .enable_reg = (_ereg), \ 123 129 .enable_mask = (_emask), \ 124 - .volt_table = (_table), \ 125 - .ops = &axp20x_ops_table, \ 130 + .linear_ranges = (_ranges), \ 131 + .n_linear_ranges = ARRAY_SIZE(_ranges), \ 132 + .ops = &axp20x_ops_range, \ 126 133 } 127 - 128 - static const int axp20x_ldo4_data[] = { 1250000, 1300000, 1400000, 1500000, 1600000, 129 - 1700000, 1800000, 1900000, 2000000, 2500000, 130 - 2700000, 2800000, 3000000, 3100000, 3200000, 131 - 3300000 }; 132 134 133 135 static struct regulator_ops axp20x_ops_fixed = { 134 136 .list_voltage = regulator_list_voltage_linear, 135 137 }; 136 138 137 - static struct regulator_ops axp20x_ops_table = { 139 + static struct regulator_ops axp20x_ops_range = { 138 140 .set_voltage_sel = regulator_set_voltage_sel_regmap, 139 141 .get_voltage_sel = regulator_get_voltage_sel_regmap, 140 - .list_voltage = regulator_list_voltage_table, 141 - .map_voltage = regulator_map_voltage_ascend, 142 + .list_voltage = regulator_list_voltage_linear_range, 142 143 .enable = regulator_enable_regmap, 143 144 .disable = regulator_disable_regmap, 144 145 .is_enabled = regulator_is_enabled_regmap, ··· 149 160 }; 150 161 151 162 static struct regulator_ops axp20x_ops_sw = { 152 - .get_voltage_sel = regulator_get_voltage_sel_regmap, 153 - .list_voltage = regulator_list_voltage_linear, 154 163 .enable = regulator_enable_regmap, 155 164 .disable = regulator_disable_regmap, 156 165 .is_enabled = regulator_is_enabled_regmap, 166 + }; 167 + 168 + static const struct regulator_linear_range axp20x_ldo4_ranges[] = { 169 + REGULATOR_LINEAR_RANGE(1250000, 0x0, 0x0, 0), 170 + REGULATOR_LINEAR_RANGE(1300000, 0x1, 0x8, 100000), 171 + REGULATOR_LINEAR_RANGE(2500000, 0x9, 0xf, 100000), 157 172 }; 158 173 159 174 static const struct regulator_desc axp20x_regulators[] = { ··· 170 177 AXP20X_LDO24_V_OUT, 0xf0, AXP20X_PWR_OUT_CTRL, 0x04), 171 178 AXP_DESC(AXP20X, LDO3, "ldo3", "ldo3in", 700, 3500, 25, 172 179 AXP20X_LDO3_V_OUT, 0x7f, AXP20X_PWR_OUT_CTRL, 0x40), 173 - AXP_DESC_TABLE(AXP20X, LDO4, "ldo4", "ldo24in", axp20x_ldo4_data, 174 - AXP20X_LDO24_V_OUT, 0x0f, AXP20X_PWR_OUT_CTRL, 0x08), 180 + AXP_DESC_RANGES(AXP20X, LDO4, "ldo4", "ldo24in", axp20x_ldo4_ranges, 181 + 16, AXP20X_LDO24_V_OUT, 0x0f, AXP20X_PWR_OUT_CTRL, 182 + 0x08), 175 183 AXP_DESC_IO(AXP20X, LDO5, "ldo5", "ldo5in", 1800, 3300, 100, 176 184 AXP20X_LDO5_V_OUT, 0xf0, AXP20X_GPIO0_CTRL, 0x07, 177 185 AXP20X_IO_ENABLED, AXP20X_IO_DISABLED), ··· 190 196 AXP_DESC(AXP22X, DCDC5, "dcdc5", "vin5", 1000, 2550, 50, 191 197 AXP22X_DCDC5_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL1, BIT(5)), 192 198 /* secondary switchable output of DCDC1 */ 193 - AXP_DESC_SW(AXP22X, DC1SW, "dc1sw", NULL, 1600, 3400, 100, 194 - AXP22X_DCDC1_V_OUT, 0x1f, AXP22X_PWR_OUT_CTRL2, BIT(7)), 199 + AXP_DESC_SW(AXP22X, DC1SW, "dc1sw", NULL, AXP22X_PWR_OUT_CTRL2, 200 + BIT(7)), 195 201 /* LDO regulator internally chained to DCDC5 */ 196 202 AXP_DESC(AXP22X, DC5LDO, "dc5ldo", NULL, 700, 1400, 100, 197 203 AXP22X_DC5LDO_V_OUT, 0x7, AXP22X_PWR_OUT_CTRL1, BIT(0)),
+46 -29
drivers/regulator/core.c
··· 1057 1057 1058 1058 ret = machine_constraints_voltage(rdev, rdev->constraints); 1059 1059 if (ret != 0) 1060 - goto out; 1060 + return ret; 1061 1061 1062 1062 ret = machine_constraints_current(rdev, rdev->constraints); 1063 1063 if (ret != 0) 1064 - goto out; 1064 + return ret; 1065 1065 1066 1066 if (rdev->constraints->ilim_uA && ops->set_input_current_limit) { 1067 1067 ret = ops->set_input_current_limit(rdev, 1068 1068 rdev->constraints->ilim_uA); 1069 1069 if (ret < 0) { 1070 1070 rdev_err(rdev, "failed to set input limit\n"); 1071 - goto out; 1071 + return ret; 1072 1072 } 1073 1073 } 1074 1074 ··· 1077 1077 ret = suspend_prepare(rdev, rdev->constraints->initial_state); 1078 1078 if (ret < 0) { 1079 1079 rdev_err(rdev, "failed to set suspend state\n"); 1080 - goto out; 1080 + return ret; 1081 1081 } 1082 1082 } 1083 1083 1084 1084 if (rdev->constraints->initial_mode) { 1085 1085 if (!ops->set_mode) { 1086 1086 rdev_err(rdev, "no set_mode operation\n"); 1087 - ret = -EINVAL; 1088 - goto out; 1087 + return -EINVAL; 1089 1088 } 1090 1089 1091 1090 ret = ops->set_mode(rdev, rdev->constraints->initial_mode); 1092 1091 if (ret < 0) { 1093 1092 rdev_err(rdev, "failed to set initial mode: %d\n", ret); 1094 - goto out; 1093 + return ret; 1095 1094 } 1096 1095 } 1097 1096 ··· 1101 1102 ret = _regulator_do_enable(rdev); 1102 1103 if (ret < 0 && ret != -EINVAL) { 1103 1104 rdev_err(rdev, "failed to enable\n"); 1104 - goto out; 1105 + return ret; 1105 1106 } 1106 1107 } 1107 1108 ··· 1110 1111 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); 1111 1112 if (ret < 0) { 1112 1113 rdev_err(rdev, "failed to set ramp_delay\n"); 1113 - goto out; 1114 + return ret; 1114 1115 } 1115 1116 } 1116 1117 ··· 1118 1119 ret = ops->set_pull_down(rdev); 1119 1120 if (ret < 0) { 1120 1121 rdev_err(rdev, "failed to set pull down\n"); 1121 - goto out; 1122 + return ret; 1122 1123 } 1123 1124 } 1124 1125 ··· 1126 1127 ret = ops->set_soft_start(rdev); 1127 1128 if (ret < 0) { 1128 1129 rdev_err(rdev, "failed to set soft start\n"); 1129 - goto out; 1130 + return ret; 1130 1131 } 1131 1132 } 1132 1133 ··· 1135 1136 ret = ops->set_over_current_protection(rdev); 1136 1137 if (ret < 0) { 1137 1138 rdev_err(rdev, "failed to set over current protection\n"); 1138 - goto out; 1139 + return ret; 1140 + } 1141 + } 1142 + 1143 + if (rdev->constraints->active_discharge && ops->set_active_discharge) { 1144 + bool ad_state = (rdev->constraints->active_discharge == 1145 + REGULATOR_ACTIVE_DISCHARGE_ENABLE) ? true : false; 1146 + 1147 + ret = ops->set_active_discharge(rdev, ad_state); 1148 + if (ret < 0) { 1149 + rdev_err(rdev, "failed to set active discharge\n"); 1150 + return ret; 1151 + } 1152 + } 1153 + 1154 + if (rdev->constraints->active_discharge && ops->set_active_discharge) { 1155 + bool ad_state = (rdev->constraints->active_discharge == 1156 + REGULATOR_ACTIVE_DISCHARGE_ENABLE) ? true : false; 1157 + 1158 + ret = ops->set_active_discharge(rdev, ad_state); 1159 + if (ret < 0) { 1160 + rdev_err(rdev, "failed to set active discharge\n"); 1161 + return ret; 1139 1162 } 1140 1163 } 1141 1164 1142 1165 print_constraints(rdev); 1143 1166 return 0; 1144 - out: 1145 - kfree(rdev->constraints); 1146 - rdev->constraints = NULL; 1147 - return ret; 1148 1167 } 1149 1168 1150 1169 /** ··· 3935 3918 goto clean; 3936 3919 } 3937 3920 3921 + if ((config->ena_gpio || config->ena_gpio_initialized) && 3922 + gpio_is_valid(config->ena_gpio)) { 3923 + ret = regulator_ena_gpio_request(rdev, config); 3924 + if (ret != 0) { 3925 + rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", 3926 + config->ena_gpio, ret); 3927 + goto clean; 3928 + } 3929 + } 3930 + 3938 3931 /* register with sysfs */ 3939 3932 rdev->dev.class = &regulator_class; 3940 3933 rdev->dev.parent = dev; ··· 3953 3926 ret = device_register(&rdev->dev); 3954 3927 if (ret != 0) { 3955 3928 put_device(&rdev->dev); 3956 - goto clean; 3929 + goto wash; 3957 3930 } 3958 3931 3959 3932 dev_set_drvdata(&rdev->dev, rdev); 3960 - 3961 - if ((config->ena_gpio || config->ena_gpio_initialized) && 3962 - gpio_is_valid(config->ena_gpio)) { 3963 - ret = regulator_ena_gpio_request(rdev, config); 3964 - if (ret != 0) { 3965 - rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", 3966 - config->ena_gpio, ret); 3967 - goto wash; 3968 - } 3969 - } 3970 3933 3971 3934 /* set regulator constraints */ 3972 3935 if (init_data) ··· 3996 3979 3997 3980 scrub: 3998 3981 regulator_ena_gpio_free(rdev); 3999 - kfree(rdev->constraints); 4000 - wash: 4001 3982 device_unregister(&rdev->dev); 4002 3983 /* device core frees rdev */ 4003 3984 rdev = ERR_PTR(ret); 4004 3985 goto out; 4005 3986 3987 + wash: 3988 + regulator_ena_gpio_free(rdev); 4006 3989 clean: 4007 3990 kfree(rdev); 4008 3991 rdev = ERR_PTR(ret);
+5
drivers/regulator/da9210-regulator.c
··· 132 132 if (error < 0) 133 133 goto error_i2c; 134 134 135 + mutex_lock(&chip->rdev->mutex); 136 + 135 137 if (val & DA9210_E_OVCURR) { 136 138 regulator_notifier_call_chain(chip->rdev, 137 139 REGULATOR_EVENT_OVER_CURRENT, ··· 157 155 NULL); 158 156 handled |= DA9210_E_VMAX; 159 157 } 158 + 159 + mutex_unlock(&chip->rdev->mutex); 160 + 160 161 if (handled) { 161 162 /* Clear handled events */ 162 163 error = regmap_write(chip->regmap, DA9210_REG_EVENT_B, handled);
+18
drivers/regulator/fan53555.c
··· 114 114 return 0; 115 115 } 116 116 117 + static int fan53555_set_suspend_enable(struct regulator_dev *rdev) 118 + { 119 + struct fan53555_device_info *di = rdev_get_drvdata(rdev); 120 + 121 + return regmap_update_bits(di->regmap, di->sleep_reg, 122 + VSEL_BUCK_EN, VSEL_BUCK_EN); 123 + } 124 + 125 + static int fan53555_set_suspend_disable(struct regulator_dev *rdev) 126 + { 127 + struct fan53555_device_info *di = rdev_get_drvdata(rdev); 128 + 129 + return regmap_update_bits(di->regmap, di->sleep_reg, 130 + VSEL_BUCK_EN, 0); 131 + } 132 + 117 133 static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode) 118 134 { 119 135 struct fan53555_device_info *di = rdev_get_drvdata(rdev); ··· 208 192 .set_mode = fan53555_set_mode, 209 193 .get_mode = fan53555_get_mode, 210 194 .set_ramp_delay = fan53555_set_ramp, 195 + .set_suspend_enable = fan53555_set_suspend_enable, 196 + .set_suspend_disable = fan53555_set_suspend_disable, 211 197 }; 212 198 213 199 static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
+4 -2
drivers/regulator/gpio-regulator.c
··· 283 283 drvdata->nr_gpios = config->nr_gpios; 284 284 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); 285 285 if (ret) { 286 - dev_err(&pdev->dev, 287 - "Could not obtain regulator setting GPIOs: %d\n", ret); 286 + if (ret != -EPROBE_DEFER) 287 + dev_err(&pdev->dev, 288 + "Could not obtain regulator setting GPIOs: %d\n", 289 + ret); 288 290 goto err_memstate; 289 291 } 290 292 }
+23
drivers/regulator/helpers.c
··· 465 465 return 0; 466 466 } 467 467 EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap); 468 + 469 + /** 470 + * regulator_set_active_discharge_regmap - Default set_active_discharge() 471 + * using regmap 472 + * 473 + * @rdev: device to operate on. 474 + * @enable: state to set, 0 to disable and 1 to enable. 475 + */ 476 + int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, 477 + bool enable) 478 + { 479 + unsigned int val; 480 + 481 + if (enable) 482 + val = rdev->desc->active_discharge_on; 483 + else 484 + val = rdev->desc->active_discharge_off; 485 + 486 + return regmap_update_bits(rdev->regmap, 487 + rdev->desc->active_discharge_reg, 488 + rdev->desc->active_discharge_mask, val); 489 + } 490 + EXPORT_SYMBOL_GPL(regulator_set_active_discharge_regmap);
+227
drivers/regulator/hi655x-regulator.c
··· 1 + /* 2 + * Device driver for regulators in Hi655x IC 3 + * 4 + * Copyright (c) 2016 Hisilicon. 5 + * 6 + * Authors: 7 + * Chen Feng <puck.chen@hisilicon.com> 8 + * Fei Wang <w.f@huawei.com> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + */ 14 + 15 + #include <linux/bitops.h> 16 + #include <linux/device.h> 17 + #include <linux/err.h> 18 + #include <linux/module.h> 19 + #include <linux/io.h> 20 + #include <linux/of.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/regmap.h> 23 + #include <linux/regulator/driver.h> 24 + #include <linux/regulator/machine.h> 25 + #include <linux/regulator/of_regulator.h> 26 + #include <linux/mfd/hi655x-pmic.h> 27 + 28 + struct hi655x_regulator { 29 + unsigned int disable_reg; 30 + unsigned int status_reg; 31 + unsigned int ctrl_regs; 32 + unsigned int ctrl_mask; 33 + struct regulator_desc rdesc; 34 + }; 35 + 36 + /* LDO7 & LDO10 */ 37 + static const unsigned int ldo7_voltages[] = { 38 + 1800000, 1850000, 2850000, 2900000, 39 + 3000000, 3100000, 3200000, 3300000, 40 + }; 41 + 42 + static const unsigned int ldo19_voltages[] = { 43 + 1800000, 1850000, 1900000, 1750000, 44 + 2800000, 2850000, 2900000, 3000000, 45 + }; 46 + 47 + static const unsigned int ldo22_voltages[] = { 48 + 900000, 1000000, 1050000, 1100000, 49 + 1150000, 1175000, 1185000, 1200000, 50 + }; 51 + 52 + enum hi655x_regulator_id { 53 + HI655X_LDO0, 54 + HI655X_LDO1, 55 + HI655X_LDO2, 56 + HI655X_LDO3, 57 + HI655X_LDO4, 58 + HI655X_LDO5, 59 + HI655X_LDO6, 60 + HI655X_LDO7, 61 + HI655X_LDO8, 62 + HI655X_LDO9, 63 + HI655X_LDO10, 64 + HI655X_LDO11, 65 + HI655X_LDO12, 66 + HI655X_LDO13, 67 + HI655X_LDO14, 68 + HI655X_LDO15, 69 + HI655X_LDO16, 70 + HI655X_LDO17, 71 + HI655X_LDO18, 72 + HI655X_LDO19, 73 + HI655X_LDO20, 74 + HI655X_LDO21, 75 + HI655X_LDO22, 76 + }; 77 + 78 + static int hi655x_is_enabled(struct regulator_dev *rdev) 79 + { 80 + unsigned int value = 0; 81 + 82 + struct hi655x_regulator *regulator = rdev_get_drvdata(rdev); 83 + 84 + regmap_read(rdev->regmap, regulator->status_reg, &value); 85 + return (value & BIT(regulator->ctrl_mask)); 86 + } 87 + 88 + static int hi655x_disable(struct regulator_dev *rdev) 89 + { 90 + int ret = 0; 91 + 92 + struct hi655x_regulator *regulator = rdev_get_drvdata(rdev); 93 + 94 + ret = regmap_write(rdev->regmap, regulator->disable_reg, 95 + BIT(regulator->ctrl_mask)); 96 + return ret; 97 + } 98 + 99 + static struct regulator_ops hi655x_regulator_ops = { 100 + .enable = regulator_enable_regmap, 101 + .disable = hi655x_disable, 102 + .is_enabled = hi655x_is_enabled, 103 + .list_voltage = regulator_list_voltage_table, 104 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 105 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 106 + }; 107 + 108 + static struct regulator_ops hi655x_ldo_linear_ops = { 109 + .enable = regulator_enable_regmap, 110 + .disable = hi655x_disable, 111 + .is_enabled = hi655x_is_enabled, 112 + .list_voltage = regulator_list_voltage_linear, 113 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 114 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 115 + }; 116 + 117 + #define HI655X_LDO(_ID, vreg, vmask, ereg, dreg, \ 118 + sreg, cmask, vtable) { \ 119 + .rdesc = { \ 120 + .name = #_ID, \ 121 + .of_match = of_match_ptr(#_ID), \ 122 + .ops = &hi655x_regulator_ops, \ 123 + .regulators_node = of_match_ptr("regulators"), \ 124 + .type = REGULATOR_VOLTAGE, \ 125 + .id = HI655X_##_ID, \ 126 + .owner = THIS_MODULE, \ 127 + .n_voltages = ARRAY_SIZE(vtable), \ 128 + .volt_table = vtable, \ 129 + .vsel_reg = HI655X_BUS_ADDR(vreg), \ 130 + .vsel_mask = vmask, \ 131 + .enable_reg = HI655X_BUS_ADDR(ereg), \ 132 + .enable_mask = BIT(cmask), \ 133 + }, \ 134 + .disable_reg = HI655X_BUS_ADDR(dreg), \ 135 + .status_reg = HI655X_BUS_ADDR(sreg), \ 136 + .ctrl_mask = cmask, \ 137 + } 138 + 139 + #define HI655X_LDO_LINEAR(_ID, vreg, vmask, ereg, dreg, \ 140 + sreg, cmask, minv, nvolt, vstep) { \ 141 + .rdesc = { \ 142 + .name = #_ID, \ 143 + .of_match = of_match_ptr(#_ID), \ 144 + .ops = &hi655x_ldo_linear_ops, \ 145 + .regulators_node = of_match_ptr("regulators"), \ 146 + .type = REGULATOR_VOLTAGE, \ 147 + .id = HI655X_##_ID, \ 148 + .owner = THIS_MODULE, \ 149 + .min_uV = minv, \ 150 + .n_voltages = nvolt, \ 151 + .uV_step = vstep, \ 152 + .vsel_reg = HI655X_BUS_ADDR(vreg), \ 153 + .vsel_mask = vmask, \ 154 + .enable_reg = HI655X_BUS_ADDR(ereg), \ 155 + .enable_mask = BIT(cmask), \ 156 + }, \ 157 + .disable_reg = HI655X_BUS_ADDR(dreg), \ 158 + .status_reg = HI655X_BUS_ADDR(sreg), \ 159 + .ctrl_mask = cmask, \ 160 + } 161 + 162 + static struct hi655x_regulator regulators[] = { 163 + HI655X_LDO_LINEAR(LDO2, 0x72, 0x07, 0x29, 0x2a, 0x2b, 0x01, 164 + 2500000, 8, 100000), 165 + HI655X_LDO(LDO7, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x06, ldo7_voltages), 166 + HI655X_LDO(LDO10, 0x78, 0x07, 0x29, 0x2a, 0x2b, 0x01, ldo7_voltages), 167 + HI655X_LDO_LINEAR(LDO13, 0x7e, 0x07, 0x2c, 0x2d, 0x2e, 0x04, 168 + 1600000, 8, 50000), 169 + HI655X_LDO_LINEAR(LDO14, 0x7f, 0x07, 0x2c, 0x2d, 0x2e, 0x05, 170 + 2500000, 8, 100000), 171 + HI655X_LDO_LINEAR(LDO15, 0x80, 0x07, 0x2c, 0x2d, 0x2e, 0x06, 172 + 1600000, 8, 50000), 173 + HI655X_LDO_LINEAR(LDO17, 0x82, 0x07, 0x2f, 0x30, 0x31, 0x00, 174 + 2500000, 8, 100000), 175 + HI655X_LDO(LDO19, 0x84, 0x07, 0x2f, 0x30, 0x31, 0x02, ldo19_voltages), 176 + HI655X_LDO_LINEAR(LDO21, 0x86, 0x07, 0x2f, 0x30, 0x31, 0x04, 177 + 1650000, 8, 50000), 178 + HI655X_LDO(LDO22, 0x87, 0x07, 0x2f, 0x30, 0x31, 0x05, ldo22_voltages), 179 + }; 180 + 181 + static int hi655x_regulator_probe(struct platform_device *pdev) 182 + { 183 + unsigned int i; 184 + struct hi655x_regulator *regulator; 185 + struct hi655x_pmic *pmic; 186 + struct regulator_config config = { }; 187 + struct regulator_dev *rdev; 188 + 189 + pmic = dev_get_drvdata(pdev->dev.parent); 190 + if (!pmic) { 191 + dev_err(&pdev->dev, "no pmic in the regulator parent node\n"); 192 + return -ENODEV; 193 + } 194 + 195 + regulator = devm_kzalloc(&pdev->dev, sizeof(*regulator), GFP_KERNEL); 196 + if (!regulator) 197 + return -ENOMEM; 198 + 199 + platform_set_drvdata(pdev, regulator); 200 + 201 + config.dev = pdev->dev.parent; 202 + config.regmap = pmic->regmap; 203 + config.driver_data = regulator; 204 + for (i = 0; i < ARRAY_SIZE(regulators); i++) { 205 + rdev = devm_regulator_register(&pdev->dev, 206 + &regulators[i].rdesc, 207 + &config); 208 + if (IS_ERR(rdev)) { 209 + dev_err(&pdev->dev, "failed to register regulator %s\n", 210 + regulator->rdesc.name); 211 + return PTR_ERR(rdev); 212 + } 213 + } 214 + return 0; 215 + } 216 + 217 + static struct platform_driver hi655x_regulator_driver = { 218 + .driver = { 219 + .name = "hi655x-regulator", 220 + }, 221 + .probe = hi655x_regulator_probe, 222 + }; 223 + module_platform_driver(hi655x_regulator_driver); 224 + 225 + MODULE_AUTHOR("Chen Feng <puck.chen@hisilicon.com>"); 226 + MODULE_DESCRIPTION("Hisilicon Hi655x regulator driver"); 227 + MODULE_LICENSE("GPL v2");
+35 -3
drivers/regulator/lp872x.c
··· 15 15 #include <linux/regmap.h> 16 16 #include <linux/err.h> 17 17 #include <linux/gpio.h> 18 + #include <linux/delay.h> 18 19 #include <linux/regulator/lp872x.h> 19 20 #include <linux/regulator/driver.h> 20 21 #include <linux/platform_device.h> ··· 739 738 goto set_default_dvs_mode; 740 739 741 740 gpio = dvs->gpio; 742 - if (!gpio_is_valid(gpio)) { 743 - dev_warn(lp->dev, "invalid gpio: %d\n", gpio); 741 + if (!gpio_is_valid(gpio)) 744 742 goto set_default_dvs_mode; 745 - } 746 743 747 744 pinstate = dvs->init_state; 748 745 ret = devm_gpio_request_one(lp->dev, gpio, pinstate, "LP872X DVS"); ··· 756 757 set_default_dvs_mode: 757 758 return lp872x_update_bits(lp, LP872X_GENERAL_CFG, mask[lp->chipid], 758 759 default_dvs_mode[lp->chipid]); 760 + } 761 + 762 + static int lp872x_hw_enable(struct lp872x *lp) 763 + { 764 + int ret, gpio; 765 + 766 + if (!lp->pdata) 767 + return -EINVAL; 768 + 769 + gpio = lp->pdata->enable_gpio; 770 + if (!gpio_is_valid(gpio)) 771 + return 0; 772 + 773 + /* Always set enable GPIO high. */ 774 + ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN"); 775 + if (ret) { 776 + dev_err(lp->dev, "gpio request err: %d\n", ret); 777 + return ret; 778 + } 779 + 780 + /* Each chip has a different enable delay. */ 781 + if (lp->chipid == LP8720) 782 + usleep_range(LP8720_ENABLE_DELAY, 1.5 * LP8720_ENABLE_DELAY); 783 + else 784 + usleep_range(LP8725_ENABLE_DELAY, 1.5 * LP8725_ENABLE_DELAY); 785 + 786 + return 0; 759 787 } 760 788 761 789 static int lp872x_config(struct lp872x *lp) ··· 903 877 of_property_read_u8(np, "ti,dvs-state", &dvs_state); 904 878 pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW; 905 879 880 + pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0); 881 + 906 882 if (of_get_child_count(np) == 0) 907 883 goto out; 908 884 ··· 977 949 lp->pdata = pdata; 978 950 lp->chipid = id->driver_data; 979 951 i2c_set_clientdata(cl, lp); 952 + 953 + ret = lp872x_hw_enable(lp); 954 + if (ret) 955 + return ret; 980 956 981 957 ret = lp872x_config(lp); 982 958 if (ret)
+9 -6
drivers/regulator/ltc3589.c
··· 520 520 } 521 521 } 522 522 523 - ret = devm_request_threaded_irq(dev, client->irq, NULL, ltc3589_isr, 524 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 525 - client->name, ltc3589); 526 - if (ret) { 527 - dev_err(dev, "Failed to request IRQ: %d\n", ret); 528 - return ret; 523 + if (client->irq) { 524 + ret = devm_request_threaded_irq(dev, client->irq, NULL, 525 + ltc3589_isr, 526 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 527 + client->name, ltc3589); 528 + if (ret) { 529 + dev_err(dev, "Failed to request IRQ: %d\n", ret); 530 + return ret; 531 + } 529 532 } 530 533 531 534 return 0;
+813
drivers/regulator/max77620-regulator.c
··· 1 + /* 2 + * Maxim MAX77620 Regulator driver 3 + * 4 + * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 5 + * 6 + * Author: Mallikarjun Kasoju <mkasoju@nvidia.com> 7 + * Laxman Dewangan <ldewangan@nvidia.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify it 10 + * under the terms and conditions of the GNU General Public License, 11 + * version 2, as published by the Free Software Foundation. 12 + */ 13 + 14 + #include <linux/init.h> 15 + #include <linux/mfd/max77620.h> 16 + #include <linux/module.h> 17 + #include <linux/of.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/regmap.h> 20 + #include <linux/regulator/driver.h> 21 + #include <linux/regulator/machine.h> 22 + #include <linux/regulator/of_regulator.h> 23 + 24 + #define max77620_rails(_name) "max77620-"#_name 25 + 26 + /* Power Mode */ 27 + #define MAX77620_POWER_MODE_NORMAL 3 28 + #define MAX77620_POWER_MODE_LPM 2 29 + #define MAX77620_POWER_MODE_GLPM 1 30 + #define MAX77620_POWER_MODE_DISABLE 0 31 + 32 + /* SD Slew Rate */ 33 + #define MAX77620_SD_SR_13_75 0 34 + #define MAX77620_SD_SR_27_5 1 35 + #define MAX77620_SD_SR_55 2 36 + #define MAX77620_SD_SR_100 3 37 + 38 + enum max77620_regulators { 39 + MAX77620_REGULATOR_ID_SD0, 40 + MAX77620_REGULATOR_ID_SD1, 41 + MAX77620_REGULATOR_ID_SD2, 42 + MAX77620_REGULATOR_ID_SD3, 43 + MAX77620_REGULATOR_ID_SD4, 44 + MAX77620_REGULATOR_ID_LDO0, 45 + MAX77620_REGULATOR_ID_LDO1, 46 + MAX77620_REGULATOR_ID_LDO2, 47 + MAX77620_REGULATOR_ID_LDO3, 48 + MAX77620_REGULATOR_ID_LDO4, 49 + MAX77620_REGULATOR_ID_LDO5, 50 + MAX77620_REGULATOR_ID_LDO6, 51 + MAX77620_REGULATOR_ID_LDO7, 52 + MAX77620_REGULATOR_ID_LDO8, 53 + MAX77620_NUM_REGS, 54 + }; 55 + 56 + /* Regulator types */ 57 + enum max77620_regulator_type { 58 + MAX77620_REGULATOR_TYPE_SD, 59 + MAX77620_REGULATOR_TYPE_LDO_N, 60 + MAX77620_REGULATOR_TYPE_LDO_P, 61 + }; 62 + 63 + struct max77620_regulator_info { 64 + u8 type; 65 + u8 fps_addr; 66 + u8 volt_addr; 67 + u8 cfg_addr; 68 + u8 power_mode_mask; 69 + u8 power_mode_shift; 70 + u8 remote_sense_addr; 71 + u8 remote_sense_mask; 72 + struct regulator_desc desc; 73 + }; 74 + 75 + struct max77620_regulator_pdata { 76 + struct regulator_init_data *reg_idata; 77 + int active_fps_src; 78 + int active_fps_pd_slot; 79 + int active_fps_pu_slot; 80 + int suspend_fps_src; 81 + int suspend_fps_pd_slot; 82 + int suspend_fps_pu_slot; 83 + int current_mode; 84 + }; 85 + 86 + struct max77620_regulator { 87 + struct device *dev; 88 + struct regmap *rmap; 89 + struct max77620_regulator_info *rinfo[MAX77620_NUM_REGS]; 90 + struct max77620_regulator_pdata reg_pdata[MAX77620_NUM_REGS]; 91 + int enable_power_mode[MAX77620_NUM_REGS]; 92 + int current_power_mode[MAX77620_NUM_REGS]; 93 + int active_fps_src[MAX77620_NUM_REGS]; 94 + }; 95 + 96 + #define fps_src_name(fps_src) \ 97 + (fps_src == MAX77620_FPS_SRC_0 ? "FPS_SRC_0" : \ 98 + fps_src == MAX77620_FPS_SRC_1 ? "FPS_SRC_1" : \ 99 + fps_src == MAX77620_FPS_SRC_2 ? "FPS_SRC_2" : "FPS_SRC_NONE") 100 + 101 + static int max77620_regulator_get_fps_src(struct max77620_regulator *pmic, 102 + int id) 103 + { 104 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 105 + unsigned int val; 106 + int ret; 107 + 108 + ret = regmap_read(pmic->rmap, rinfo->fps_addr, &val); 109 + if (ret < 0) { 110 + dev_err(pmic->dev, "Reg 0x%02x read failed %d\n", 111 + rinfo->fps_addr, ret); 112 + return ret; 113 + } 114 + 115 + return (val & MAX77620_FPS_SRC_MASK) >> MAX77620_FPS_SRC_SHIFT; 116 + } 117 + 118 + static int max77620_regulator_set_fps_src(struct max77620_regulator *pmic, 119 + int fps_src, int id) 120 + { 121 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 122 + unsigned int val; 123 + int ret; 124 + 125 + switch (fps_src) { 126 + case MAX77620_FPS_SRC_0: 127 + case MAX77620_FPS_SRC_1: 128 + case MAX77620_FPS_SRC_2: 129 + case MAX77620_FPS_SRC_NONE: 130 + break; 131 + 132 + case MAX77620_FPS_SRC_DEF: 133 + ret = regmap_read(pmic->rmap, rinfo->fps_addr, &val); 134 + if (ret < 0) { 135 + dev_err(pmic->dev, "Reg 0x%02x read failed %d\n", 136 + rinfo->fps_addr, ret); 137 + return ret; 138 + } 139 + ret = (val & MAX77620_FPS_SRC_MASK) >> MAX77620_FPS_SRC_SHIFT; 140 + pmic->active_fps_src[id] = ret; 141 + return 0; 142 + 143 + default: 144 + dev_err(pmic->dev, "Invalid FPS %d for regulator %d\n", 145 + fps_src, id); 146 + return -EINVAL; 147 + } 148 + 149 + ret = regmap_update_bits(pmic->rmap, rinfo->fps_addr, 150 + MAX77620_FPS_SRC_MASK, 151 + fps_src << MAX77620_FPS_SRC_SHIFT); 152 + if (ret < 0) { 153 + dev_err(pmic->dev, "Reg 0x%02x update failed %d\n", 154 + rinfo->fps_addr, ret); 155 + return ret; 156 + } 157 + pmic->active_fps_src[id] = fps_src; 158 + 159 + return 0; 160 + } 161 + 162 + static int max77620_regulator_set_fps_slots(struct max77620_regulator *pmic, 163 + int id, bool is_suspend) 164 + { 165 + struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[id]; 166 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 167 + unsigned int val = 0; 168 + unsigned int mask = 0; 169 + int pu = rpdata->active_fps_pu_slot; 170 + int pd = rpdata->active_fps_pd_slot; 171 + int ret = 0; 172 + 173 + if (is_suspend) { 174 + pu = rpdata->suspend_fps_pu_slot; 175 + pd = rpdata->suspend_fps_pd_slot; 176 + } 177 + 178 + /* FPS power up period setting */ 179 + if (pu >= 0) { 180 + val |= (pu << MAX77620_FPS_PU_PERIOD_SHIFT); 181 + mask |= MAX77620_FPS_PU_PERIOD_MASK; 182 + } 183 + 184 + /* FPS power down period setting */ 185 + if (pd >= 0) { 186 + val |= (pd << MAX77620_FPS_PD_PERIOD_SHIFT); 187 + mask |= MAX77620_FPS_PD_PERIOD_MASK; 188 + } 189 + 190 + if (mask) { 191 + ret = regmap_update_bits(pmic->rmap, rinfo->fps_addr, 192 + mask, val); 193 + if (ret < 0) { 194 + dev_err(pmic->dev, "Reg 0x%02x update failed: %d\n", 195 + rinfo->fps_addr, ret); 196 + return ret; 197 + } 198 + } 199 + 200 + return ret; 201 + } 202 + 203 + static int max77620_regulator_set_power_mode(struct max77620_regulator *pmic, 204 + int power_mode, int id) 205 + { 206 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 207 + u8 mask = rinfo->power_mode_mask; 208 + u8 shift = rinfo->power_mode_shift; 209 + u8 addr; 210 + int ret; 211 + 212 + switch (rinfo->type) { 213 + case MAX77620_REGULATOR_TYPE_SD: 214 + addr = rinfo->cfg_addr; 215 + break; 216 + default: 217 + addr = rinfo->volt_addr; 218 + break; 219 + } 220 + 221 + ret = regmap_update_bits(pmic->rmap, addr, mask, power_mode << shift); 222 + if (ret < 0) { 223 + dev_err(pmic->dev, "Regulator %d mode set failed: %d\n", 224 + id, ret); 225 + return ret; 226 + } 227 + pmic->current_power_mode[id] = power_mode; 228 + 229 + return ret; 230 + } 231 + 232 + static int max77620_regulator_get_power_mode(struct max77620_regulator *pmic, 233 + int id) 234 + { 235 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 236 + unsigned int val, addr; 237 + u8 mask = rinfo->power_mode_mask; 238 + u8 shift = rinfo->power_mode_shift; 239 + int ret; 240 + 241 + switch (rinfo->type) { 242 + case MAX77620_REGULATOR_TYPE_SD: 243 + addr = rinfo->cfg_addr; 244 + break; 245 + default: 246 + addr = rinfo->volt_addr; 247 + break; 248 + } 249 + 250 + ret = regmap_read(pmic->rmap, addr, &val); 251 + if (ret < 0) { 252 + dev_err(pmic->dev, "Regulator %d: Reg 0x%02x read failed: %d\n", 253 + id, addr, ret); 254 + return ret; 255 + } 256 + 257 + return (val & mask) >> shift; 258 + } 259 + 260 + static int max77620_read_slew_rate(struct max77620_regulator *pmic, int id) 261 + { 262 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 263 + unsigned int rval; 264 + int slew_rate; 265 + int ret; 266 + 267 + ret = regmap_read(pmic->rmap, rinfo->cfg_addr, &rval); 268 + if (ret < 0) { 269 + dev_err(pmic->dev, "Register 0x%02x read failed: %d\n", 270 + rinfo->cfg_addr, ret); 271 + return ret; 272 + } 273 + 274 + switch (rinfo->type) { 275 + case MAX77620_REGULATOR_TYPE_SD: 276 + slew_rate = (rval >> MAX77620_SD_SR_SHIFT) & 0x3; 277 + switch (slew_rate) { 278 + case 0: 279 + slew_rate = 13750; 280 + break; 281 + case 1: 282 + slew_rate = 27500; 283 + break; 284 + case 2: 285 + slew_rate = 55000; 286 + break; 287 + case 3: 288 + slew_rate = 100000; 289 + break; 290 + } 291 + rinfo->desc.ramp_delay = slew_rate; 292 + break; 293 + default: 294 + slew_rate = rval & 0x1; 295 + switch (slew_rate) { 296 + case 0: 297 + slew_rate = 100000; 298 + break; 299 + case 1: 300 + slew_rate = 5000; 301 + break; 302 + } 303 + rinfo->desc.ramp_delay = slew_rate; 304 + break; 305 + } 306 + 307 + return 0; 308 + } 309 + 310 + static int max77620_init_pmic(struct max77620_regulator *pmic, int id) 311 + { 312 + struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[id]; 313 + int ret; 314 + 315 + /* Update power mode */ 316 + ret = max77620_regulator_get_power_mode(pmic, id); 317 + if (ret < 0) 318 + return ret; 319 + 320 + pmic->current_power_mode[id] = ret; 321 + pmic->enable_power_mode[id] = MAX77620_POWER_MODE_NORMAL; 322 + 323 + if (rpdata->active_fps_src == MAX77620_FPS_SRC_DEF) { 324 + ret = max77620_regulator_get_fps_src(pmic, id); 325 + if (ret < 0) 326 + return ret; 327 + rpdata->active_fps_src = ret; 328 + } 329 + 330 + /* If rails are externally control of FPS then enable it always. */ 331 + if (rpdata->active_fps_src == MAX77620_FPS_SRC_NONE) { 332 + ret = max77620_regulator_set_power_mode(pmic, 333 + pmic->enable_power_mode[id], id); 334 + if (ret < 0) 335 + return ret; 336 + } else { 337 + if (pmic->current_power_mode[id] != 338 + pmic->enable_power_mode[id]) { 339 + ret = max77620_regulator_set_power_mode(pmic, 340 + pmic->enable_power_mode[id], id); 341 + if (ret < 0) 342 + return ret; 343 + } 344 + } 345 + 346 + ret = max77620_regulator_set_fps_src(pmic, rpdata->active_fps_src, id); 347 + if (ret < 0) 348 + return ret; 349 + 350 + ret = max77620_regulator_set_fps_slots(pmic, id, false); 351 + if (ret < 0) 352 + return ret; 353 + 354 + return 0; 355 + } 356 + 357 + static int max77620_regulator_enable(struct regulator_dev *rdev) 358 + { 359 + struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 360 + int id = rdev_get_id(rdev); 361 + 362 + if (pmic->active_fps_src[id] != MAX77620_FPS_SRC_NONE) 363 + return 0; 364 + 365 + return max77620_regulator_set_power_mode(pmic, 366 + pmic->enable_power_mode[id], id); 367 + } 368 + 369 + static int max77620_regulator_disable(struct regulator_dev *rdev) 370 + { 371 + struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 372 + int id = rdev_get_id(rdev); 373 + 374 + if (pmic->active_fps_src[id] != MAX77620_FPS_SRC_NONE) 375 + return 0; 376 + 377 + return max77620_regulator_set_power_mode(pmic, 378 + MAX77620_POWER_MODE_DISABLE, id); 379 + } 380 + 381 + static int max77620_regulator_is_enabled(struct regulator_dev *rdev) 382 + { 383 + struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 384 + int id = rdev_get_id(rdev); 385 + int ret = 1; 386 + 387 + if (pmic->active_fps_src[id] != MAX77620_FPS_SRC_NONE) 388 + return 1; 389 + 390 + ret = max77620_regulator_get_power_mode(pmic, id); 391 + if (ret < 0) 392 + return ret; 393 + 394 + if (ret != MAX77620_POWER_MODE_DISABLE) 395 + return 1; 396 + 397 + return 0; 398 + } 399 + 400 + static int max77620_regulator_set_mode(struct regulator_dev *rdev, 401 + unsigned int mode) 402 + { 403 + struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 404 + int id = rdev_get_id(rdev); 405 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 406 + struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[id]; 407 + bool fpwm = false; 408 + int power_mode; 409 + int ret; 410 + u8 val; 411 + 412 + switch (mode) { 413 + case REGULATOR_MODE_FAST: 414 + fpwm = true; 415 + power_mode = MAX77620_POWER_MODE_NORMAL; 416 + break; 417 + 418 + case REGULATOR_MODE_NORMAL: 419 + power_mode = MAX77620_POWER_MODE_NORMAL; 420 + break; 421 + 422 + case REGULATOR_MODE_IDLE: 423 + power_mode = MAX77620_POWER_MODE_LPM; 424 + break; 425 + 426 + default: 427 + dev_err(pmic->dev, "Regulator %d mode %d is invalid\n", 428 + id, mode); 429 + return -EINVAL; 430 + } 431 + 432 + if (rinfo->type != MAX77620_REGULATOR_TYPE_SD) 433 + goto skip_fpwm; 434 + 435 + val = (fpwm) ? MAX77620_SD_FPWM_MASK : 0; 436 + ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr, 437 + MAX77620_SD_FPWM_MASK, val); 438 + if (ret < 0) { 439 + dev_err(pmic->dev, "Reg 0x%02x update failed: %d\n", 440 + rinfo->cfg_addr, ret); 441 + return ret; 442 + } 443 + rpdata->current_mode = mode; 444 + 445 + skip_fpwm: 446 + ret = max77620_regulator_set_power_mode(pmic, power_mode, id); 447 + if (ret < 0) 448 + return ret; 449 + 450 + pmic->enable_power_mode[id] = power_mode; 451 + 452 + return 0; 453 + } 454 + 455 + static unsigned int max77620_regulator_get_mode(struct regulator_dev *rdev) 456 + { 457 + struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 458 + int id = rdev_get_id(rdev); 459 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 460 + int fpwm = 0; 461 + int ret; 462 + int pm_mode, reg_mode; 463 + unsigned int val; 464 + 465 + ret = max77620_regulator_get_power_mode(pmic, id); 466 + if (ret < 0) 467 + return 0; 468 + 469 + pm_mode = ret; 470 + 471 + if (rinfo->type == MAX77620_REGULATOR_TYPE_SD) { 472 + ret = regmap_read(pmic->rmap, rinfo->cfg_addr, &val); 473 + if (ret < 0) { 474 + dev_err(pmic->dev, "Reg 0x%02x read failed: %d\n", 475 + rinfo->cfg_addr, ret); 476 + return ret; 477 + } 478 + fpwm = !!(val & MAX77620_SD_FPWM_MASK); 479 + } 480 + 481 + switch (pm_mode) { 482 + case MAX77620_POWER_MODE_NORMAL: 483 + case MAX77620_POWER_MODE_DISABLE: 484 + if (fpwm) 485 + reg_mode = REGULATOR_MODE_FAST; 486 + else 487 + reg_mode = REGULATOR_MODE_NORMAL; 488 + break; 489 + case MAX77620_POWER_MODE_LPM: 490 + case MAX77620_POWER_MODE_GLPM: 491 + reg_mode = REGULATOR_MODE_IDLE; 492 + break; 493 + default: 494 + return 0; 495 + } 496 + 497 + return reg_mode; 498 + } 499 + 500 + static int max77620_regulator_set_ramp_delay(struct regulator_dev *rdev, 501 + int ramp_delay) 502 + { 503 + struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 504 + int id = rdev_get_id(rdev); 505 + struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 506 + int ret, val; 507 + u8 mask; 508 + 509 + if (rinfo->type == MAX77620_REGULATOR_TYPE_SD) { 510 + if (ramp_delay <= 13750) 511 + val = 0; 512 + else if (ramp_delay <= 27500) 513 + val = 1; 514 + else if (ramp_delay <= 55000) 515 + val = 2; 516 + else 517 + val = 3; 518 + val <<= MAX77620_SD_SR_SHIFT; 519 + mask = MAX77620_SD_SR_MASK; 520 + } else { 521 + if (ramp_delay <= 5000) 522 + val = 1; 523 + else 524 + val = 0; 525 + mask = MAX77620_LDO_SLEW_RATE_MASK; 526 + } 527 + 528 + ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr, mask, val); 529 + if (ret < 0) 530 + dev_err(pmic->dev, "Reg 0x%02x update failed: %d\n", 531 + rinfo->cfg_addr, ret); 532 + 533 + return ret; 534 + } 535 + 536 + static int max77620_of_parse_cb(struct device_node *np, 537 + const struct regulator_desc *desc, 538 + struct regulator_config *config) 539 + { 540 + struct max77620_regulator *pmic = config->driver_data; 541 + struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[desc->id]; 542 + u32 pval; 543 + int ret; 544 + 545 + ret = of_property_read_u32(np, "maxim,active-fps-source", &pval); 546 + rpdata->active_fps_src = (!ret) ? pval : MAX77620_FPS_SRC_DEF; 547 + 548 + ret = of_property_read_u32(np, "maxim,active-fps-power-up-slot", &pval); 549 + rpdata->active_fps_pu_slot = (!ret) ? pval : -1; 550 + 551 + ret = of_property_read_u32( 552 + np, "maxim,active-fps-power-down-slot", &pval); 553 + rpdata->active_fps_pd_slot = (!ret) ? pval : -1; 554 + 555 + ret = of_property_read_u32(np, "maxim,suspend-fps-source", &pval); 556 + rpdata->suspend_fps_src = (!ret) ? pval : -1; 557 + 558 + ret = of_property_read_u32( 559 + np, "maxim,suspend-fps-power-up-slot", &pval); 560 + rpdata->suspend_fps_pu_slot = (!ret) ? pval : -1; 561 + 562 + ret = of_property_read_u32( 563 + np, "maxim,suspend-fps-power-down-slot", &pval); 564 + rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1; 565 + 566 + return max77620_init_pmic(pmic, desc->id); 567 + } 568 + 569 + static struct regulator_ops max77620_regulator_ops = { 570 + .is_enabled = max77620_regulator_is_enabled, 571 + .enable = max77620_regulator_enable, 572 + .disable = max77620_regulator_disable, 573 + .list_voltage = regulator_list_voltage_linear, 574 + .map_voltage = regulator_map_voltage_linear, 575 + .get_voltage_sel = regulator_get_voltage_sel_regmap, 576 + .set_voltage_sel = regulator_set_voltage_sel_regmap, 577 + .set_mode = max77620_regulator_set_mode, 578 + .get_mode = max77620_regulator_get_mode, 579 + .set_ramp_delay = max77620_regulator_set_ramp_delay, 580 + .set_voltage_time_sel = regulator_set_voltage_time_sel, 581 + .set_active_discharge = regulator_set_active_discharge_regmap, 582 + }; 583 + 584 + #define MAX77620_SD_CNF2_ROVS_EN_NONE 0 585 + #define RAIL_SD(_id, _name, _sname, _volt_mask, _min_uV, _max_uV, \ 586 + _step_uV, _rs_add, _rs_mask) \ 587 + [MAX77620_REGULATOR_ID_##_id] = { \ 588 + .type = MAX77620_REGULATOR_TYPE_SD, \ 589 + .volt_addr = MAX77620_REG_##_id, \ 590 + .cfg_addr = MAX77620_REG_##_id##_CFG, \ 591 + .fps_addr = MAX77620_REG_FPS_##_id, \ 592 + .remote_sense_addr = _rs_add, \ 593 + .remote_sense_mask = MAX77620_SD_CNF2_ROVS_EN_##_rs_mask, \ 594 + .power_mode_mask = MAX77620_SD_POWER_MODE_MASK, \ 595 + .power_mode_shift = MAX77620_SD_POWER_MODE_SHIFT, \ 596 + .desc = { \ 597 + .name = max77620_rails(_name), \ 598 + .of_match = of_match_ptr(#_name), \ 599 + .regulators_node = of_match_ptr("regulators"), \ 600 + .of_parse_cb = max77620_of_parse_cb, \ 601 + .supply_name = _sname, \ 602 + .id = MAX77620_REGULATOR_ID_##_id, \ 603 + .ops = &max77620_regulator_ops, \ 604 + .n_voltages = ((_max_uV - _min_uV) / _step_uV) + 1, \ 605 + .min_uV = _min_uV, \ 606 + .uV_step = _step_uV, \ 607 + .enable_time = 500, \ 608 + .vsel_mask = MAX77620_##_volt_mask##_VOLT_MASK, \ 609 + .vsel_reg = MAX77620_REG_##_id, \ 610 + .active_discharge_off = 0, \ 611 + .active_discharge_on = MAX77620_SD_CFG1_ADE_ENABLE, \ 612 + .active_discharge_mask = MAX77620_SD_CFG1_ADE_MASK, \ 613 + .active_discharge_reg = MAX77620_REG_##_id##_CFG, \ 614 + .type = REGULATOR_VOLTAGE, \ 615 + }, \ 616 + } 617 + 618 + #define RAIL_LDO(_id, _name, _sname, _type, _min_uV, _max_uV, _step_uV) \ 619 + [MAX77620_REGULATOR_ID_##_id] = { \ 620 + .type = MAX77620_REGULATOR_TYPE_LDO_##_type, \ 621 + .volt_addr = MAX77620_REG_##_id##_CFG, \ 622 + .cfg_addr = MAX77620_REG_##_id##_CFG2, \ 623 + .fps_addr = MAX77620_REG_FPS_##_id, \ 624 + .remote_sense_addr = 0xFF, \ 625 + .power_mode_mask = MAX77620_LDO_POWER_MODE_MASK, \ 626 + .power_mode_shift = MAX77620_LDO_POWER_MODE_SHIFT, \ 627 + .desc = { \ 628 + .name = max77620_rails(_name), \ 629 + .of_match = of_match_ptr(#_name), \ 630 + .regulators_node = of_match_ptr("regulators"), \ 631 + .of_parse_cb = max77620_of_parse_cb, \ 632 + .supply_name = _sname, \ 633 + .id = MAX77620_REGULATOR_ID_##_id, \ 634 + .ops = &max77620_regulator_ops, \ 635 + .n_voltages = ((_max_uV - _min_uV) / _step_uV) + 1, \ 636 + .min_uV = _min_uV, \ 637 + .uV_step = _step_uV, \ 638 + .enable_time = 500, \ 639 + .vsel_mask = MAX77620_LDO_VOLT_MASK, \ 640 + .vsel_reg = MAX77620_REG_##_id##_CFG, \ 641 + .active_discharge_off = 0, \ 642 + .active_discharge_on = MAX77620_LDO_CFG2_ADE_ENABLE, \ 643 + .active_discharge_mask = MAX77620_LDO_CFG2_ADE_MASK, \ 644 + .active_discharge_reg = MAX77620_REG_##_id##_CFG2, \ 645 + .type = REGULATOR_VOLTAGE, \ 646 + }, \ 647 + } 648 + 649 + static struct max77620_regulator_info max77620_regs_info[MAX77620_NUM_REGS] = { 650 + RAIL_SD(SD0, sd0, "in-sd0", SD0, 600000, 1400000, 12500, 0x22, SD0), 651 + RAIL_SD(SD1, sd1, "in-sd1", SD1, 600000, 1550000, 12500, 0x22, SD1), 652 + RAIL_SD(SD2, sd2, "in-sd2", SDX, 600000, 3787500, 12500, 0xFF, NONE), 653 + RAIL_SD(SD3, sd3, "in-sd3", SDX, 600000, 3787500, 12500, 0xFF, NONE), 654 + RAIL_SD(SD4, sd4, "in-sd4", SDX, 600000, 3787500, 12500, 0xFF, NONE), 655 + 656 + RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 800000, 2375000, 25000), 657 + RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 800000, 2375000, 25000), 658 + RAIL_LDO(LDO2, ldo2, "in-ldo2", P, 800000, 3950000, 50000), 659 + RAIL_LDO(LDO3, ldo3, "in-ldo3-5", P, 800000, 3950000, 50000), 660 + RAIL_LDO(LDO4, ldo4, "in-ldo4-6", P, 800000, 1587500, 12500), 661 + RAIL_LDO(LDO5, ldo5, "in-ldo3-5", P, 800000, 3950000, 50000), 662 + RAIL_LDO(LDO6, ldo6, "in-ldo4-6", P, 800000, 3950000, 50000), 663 + RAIL_LDO(LDO7, ldo7, "in-ldo7-8", N, 800000, 3950000, 50000), 664 + RAIL_LDO(LDO8, ldo8, "in-ldo7-8", N, 800000, 3950000, 50000), 665 + }; 666 + 667 + static struct max77620_regulator_info max20024_regs_info[MAX77620_NUM_REGS] = { 668 + RAIL_SD(SD0, sd0, "in-sd0", SD0, 800000, 1587500, 12500, 0x22, SD0), 669 + RAIL_SD(SD1, sd1, "in-sd1", SD1, 600000, 3387500, 12500, 0x22, SD1), 670 + RAIL_SD(SD2, sd2, "in-sd2", SDX, 600000, 3787500, 12500, 0xFF, NONE), 671 + RAIL_SD(SD3, sd3, "in-sd3", SDX, 600000, 3787500, 12500, 0xFF, NONE), 672 + RAIL_SD(SD4, sd4, "in-sd4", SDX, 600000, 3787500, 12500, 0xFF, NONE), 673 + 674 + RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 800000, 2375000, 25000), 675 + RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 800000, 2375000, 25000), 676 + RAIL_LDO(LDO2, ldo2, "in-ldo2", P, 800000, 3950000, 50000), 677 + RAIL_LDO(LDO3, ldo3, "in-ldo3-5", P, 800000, 3950000, 50000), 678 + RAIL_LDO(LDO4, ldo4, "in-ldo4-6", P, 800000, 1587500, 12500), 679 + RAIL_LDO(LDO5, ldo5, "in-ldo3-5", P, 800000, 3950000, 50000), 680 + RAIL_LDO(LDO6, ldo6, "in-ldo4-6", P, 800000, 3950000, 50000), 681 + RAIL_LDO(LDO7, ldo7, "in-ldo7-8", N, 800000, 3950000, 50000), 682 + RAIL_LDO(LDO8, ldo8, "in-ldo7-8", N, 800000, 3950000, 50000), 683 + }; 684 + 685 + static int max77620_regulator_probe(struct platform_device *pdev) 686 + { 687 + struct max77620_chip *max77620_chip = dev_get_drvdata(pdev->dev.parent); 688 + struct max77620_regulator_info *rinfo; 689 + struct device *dev = &pdev->dev; 690 + struct regulator_config config = { }; 691 + struct max77620_regulator *pmic; 692 + int ret = 0; 693 + int id; 694 + 695 + pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL); 696 + if (!pmic) 697 + return -ENOMEM; 698 + 699 + platform_set_drvdata(pdev, pmic); 700 + pmic->dev = dev; 701 + pmic->rmap = max77620_chip->rmap; 702 + if (!dev->of_node) 703 + dev->of_node = pdev->dev.parent->of_node; 704 + 705 + switch (max77620_chip->chip_id) { 706 + case MAX77620: 707 + rinfo = max77620_regs_info; 708 + break; 709 + default: 710 + rinfo = max20024_regs_info; 711 + break; 712 + } 713 + 714 + config.regmap = pmic->rmap; 715 + config.dev = dev; 716 + config.driver_data = pmic; 717 + 718 + for (id = 0; id < MAX77620_NUM_REGS; id++) { 719 + struct regulator_dev *rdev; 720 + struct regulator_desc *rdesc; 721 + 722 + if ((max77620_chip->chip_id == MAX77620) && 723 + (id == MAX77620_REGULATOR_ID_SD4)) 724 + continue; 725 + 726 + rdesc = &rinfo[id].desc; 727 + pmic->rinfo[id] = &max77620_regs_info[id]; 728 + pmic->enable_power_mode[id] = MAX77620_POWER_MODE_NORMAL; 729 + 730 + ret = max77620_read_slew_rate(pmic, id); 731 + if (ret < 0) 732 + return ret; 733 + 734 + rdev = devm_regulator_register(dev, rdesc, &config); 735 + if (IS_ERR(rdev)) { 736 + ret = PTR_ERR(rdev); 737 + dev_err(dev, "Regulator registration %s failed: %d\n", 738 + rdesc->name, ret); 739 + return ret; 740 + } 741 + } 742 + 743 + return 0; 744 + } 745 + 746 + #ifdef CONFIG_PM_SLEEP 747 + static int max77620_regulator_suspend(struct device *dev) 748 + { 749 + struct max77620_regulator *pmic = dev_get_drvdata(dev); 750 + struct max77620_regulator_pdata *reg_pdata; 751 + int id; 752 + 753 + for (id = 0; id < MAX77620_NUM_REGS; id++) { 754 + reg_pdata = &pmic->reg_pdata[id]; 755 + 756 + max77620_regulator_set_fps_slots(pmic, id, true); 757 + if (reg_pdata->suspend_fps_src < 0) 758 + continue; 759 + 760 + max77620_regulator_set_fps_src(pmic, reg_pdata->suspend_fps_src, 761 + id); 762 + } 763 + 764 + return 0; 765 + } 766 + 767 + static int max77620_regulator_resume(struct device *dev) 768 + { 769 + struct max77620_regulator *pmic = dev_get_drvdata(dev); 770 + struct max77620_regulator_pdata *reg_pdata; 771 + int id; 772 + 773 + for (id = 0; id < MAX77620_NUM_REGS; id++) { 774 + reg_pdata = &pmic->reg_pdata[id]; 775 + 776 + max77620_regulator_set_fps_slots(pmic, id, false); 777 + if (reg_pdata->active_fps_src < 0) 778 + continue; 779 + max77620_regulator_set_fps_src(pmic, reg_pdata->active_fps_src, 780 + id); 781 + } 782 + 783 + return 0; 784 + } 785 + #endif 786 + 787 + static const struct dev_pm_ops max77620_regulator_pm_ops = { 788 + SET_SYSTEM_SLEEP_PM_OPS(max77620_regulator_suspend, 789 + max77620_regulator_resume) 790 + }; 791 + 792 + static const struct platform_device_id max77620_regulator_devtype[] = { 793 + { .name = "max77620-pmic", }, 794 + { .name = "max20024-pmic", }, 795 + {}, 796 + }; 797 + MODULE_DEVICE_TABLE(platform, max77620_regulator_devtype); 798 + 799 + static struct platform_driver max77620_regulator_driver = { 800 + .probe = max77620_regulator_probe, 801 + .id_table = max77620_regulator_devtype, 802 + .driver = { 803 + .name = "max77620-pmic", 804 + .pm = &max77620_regulator_pm_ops, 805 + }, 806 + }; 807 + 808 + module_platform_driver(max77620_regulator_driver); 809 + 810 + MODULE_DESCRIPTION("MAX77620/MAX20024 regulator driver"); 811 + MODULE_AUTHOR("Mallikarjun Kasoju <mkasoju@nvidia.com>"); 812 + MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); 813 + MODULE_LICENSE("GPL v2");
drivers/regulator/max77686.c drivers/regulator/max77686-regulator.c
drivers/regulator/max77802.c drivers/regulator/max77802-regulator.c
+14 -1
drivers/regulator/mt6397-regulator.c
··· 317 317 return 0; 318 318 } 319 319 320 + static const struct platform_device_id mt6397_platform_ids[] = { 321 + {"mt6397-regulator", 0}, 322 + { /* sentinel */ }, 323 + }; 324 + MODULE_DEVICE_TABLE(platform, mt6397_platform_ids); 325 + 326 + static const struct of_device_id mt6397_of_match[] = { 327 + { .compatible = "mediatek,mt6397-regulator", }, 328 + { /* sentinel */ }, 329 + }; 330 + MODULE_DEVICE_TABLE(of, mt6397_of_match); 331 + 320 332 static struct platform_driver mt6397_regulator_driver = { 321 333 .driver = { 322 334 .name = "mt6397-regulator", 335 + .of_match_table = of_match_ptr(mt6397_of_match), 323 336 }, 324 337 .probe = mt6397_regulator_probe, 338 + .id_table = mt6397_platform_ids, 325 339 }; 326 340 327 341 module_platform_driver(mt6397_regulator_driver); ··· 343 329 MODULE_AUTHOR("Flora Fu <flora.fu@mediatek.com>"); 344 330 MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6397 PMIC"); 345 331 MODULE_LICENSE("GPL"); 346 - MODULE_ALIAS("platform:mt6397-regulator");
+13 -8
drivers/regulator/of_regulator.c
··· 28 28 struct regulator_init_data **init_data, 29 29 const struct regulator_desc *desc) 30 30 { 31 - const __be32 *min_uV, *max_uV; 32 31 struct regulation_constraints *constraints = &(*init_data)->constraints; 33 32 struct regulator_state *suspend_state; 34 33 struct device_node *suspend_np; ··· 36 37 37 38 constraints->name = of_get_property(np, "regulator-name", NULL); 38 39 39 - min_uV = of_get_property(np, "regulator-min-microvolt", NULL); 40 - if (min_uV) 41 - constraints->min_uV = be32_to_cpu(*min_uV); 42 - max_uV = of_get_property(np, "regulator-max-microvolt", NULL); 43 - if (max_uV) 44 - constraints->max_uV = be32_to_cpu(*max_uV); 40 + if (!of_property_read_u32(np, "regulator-min-microvolt", &pval)) 41 + constraints->min_uV = pval; 42 + 43 + if (!of_property_read_u32(np, "regulator-max-microvolt", &pval)) 44 + constraints->max_uV = pval; 45 45 46 46 /* Voltage change possible? */ 47 47 if (constraints->min_uV != constraints->max_uV) 48 48 constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; 49 49 /* Only one voltage? Then make sure it's set. */ 50 - if (min_uV && max_uV && constraints->min_uV == constraints->max_uV) 50 + if (constraints->min_uV && constraints->max_uV && 51 + constraints->min_uV == constraints->max_uV) 51 52 constraints->apply_uV = true; 52 53 53 54 if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval)) ··· 92 93 93 94 constraints->soft_start = of_property_read_bool(np, 94 95 "regulator-soft-start"); 96 + ret = of_property_read_u32(np, "regulator-active-discharge", &pval); 97 + if (!ret) { 98 + constraints->active_discharge = 99 + (pval) ? REGULATOR_ACTIVE_DISCHARGE_ENABLE : 100 + REGULATOR_ACTIVE_DISCHARGE_DISABLE; 101 + } 95 102 96 103 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) { 97 104 if (desc && desc->of_map_mode) {
+4 -4
drivers/regulator/pv88060-regulator.c
··· 285 285 } 286 286 } 287 287 288 - err = regmap_update_bits(chip->regmap, PV88060_REG_EVENT_A, 289 - PV88060_E_VDD_FLT, PV88060_E_VDD_FLT); 288 + err = regmap_write(chip->regmap, PV88060_REG_EVENT_A, 289 + PV88060_E_VDD_FLT); 290 290 if (err < 0) 291 291 goto error_i2c; 292 292 ··· 302 302 } 303 303 } 304 304 305 - err = regmap_update_bits(chip->regmap, PV88060_REG_EVENT_A, 306 - PV88060_E_OVER_TEMP, PV88060_E_OVER_TEMP); 305 + err = regmap_write(chip->regmap, PV88060_REG_EVENT_A, 306 + PV88060_E_OVER_TEMP); 307 307 if (err < 0) 308 308 goto error_i2c; 309 309
+4 -4
drivers/regulator/pv88090-regulator.c
··· 283 283 } 284 284 } 285 285 286 - err = regmap_update_bits(chip->regmap, PV88090_REG_EVENT_A, 287 - PV88090_E_VDD_FLT, PV88090_E_VDD_FLT); 286 + err = regmap_write(chip->regmap, PV88090_REG_EVENT_A, 287 + PV88090_E_VDD_FLT); 288 288 if (err < 0) 289 289 goto error_i2c; 290 290 ··· 300 300 } 301 301 } 302 302 303 - err = regmap_update_bits(chip->regmap, PV88090_REG_EVENT_A, 304 - PV88090_E_OVER_TEMP, PV88090_E_OVER_TEMP); 303 + err = regmap_write(chip->regmap, PV88090_REG_EVENT_A, 304 + PV88090_E_OVER_TEMP); 305 305 if (err < 0) 306 306 goto error_i2c; 307 307
+21 -8
drivers/regulator/pwm-regulator.c
··· 27 27 28 28 /* Voltage table */ 29 29 struct pwm_voltages *duty_cycle_table; 30 + 31 + /* regulator descriptor */ 32 + struct regulator_desc desc; 33 + 34 + /* Regulator ops */ 35 + struct regulator_ops ops; 36 + 30 37 int state; 31 38 32 39 /* Continuous voltage */ ··· 122 115 int max_uV = rdev->constraints->max_uV; 123 116 int diff = max_uV - min_uV; 124 117 125 - return 100 - (((req_uV * 100) - (min_uV * 100)) / diff); 118 + return ((req_uV * 100) - (min_uV * 100)) / diff; 126 119 } 127 120 128 121 static int pwm_regulator_get_voltage(struct regulator_dev *rdev) ··· 219 212 } 220 213 221 214 drvdata->duty_cycle_table = duty_cycle_table; 222 - pwm_regulator_desc.ops = &pwm_regulator_voltage_table_ops; 223 - pwm_regulator_desc.n_voltages = length / sizeof(*duty_cycle_table); 215 + memcpy(&drvdata->ops, &pwm_regulator_voltage_table_ops, 216 + sizeof(drvdata->ops)); 217 + drvdata->desc.ops = &drvdata->ops; 218 + drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table); 224 219 225 220 return 0; 226 221 } ··· 230 221 static int pwm_regulator_init_continuous(struct platform_device *pdev, 231 222 struct pwm_regulator_data *drvdata) 232 223 { 233 - pwm_regulator_desc.ops = &pwm_regulator_voltage_continuous_ops; 234 - pwm_regulator_desc.continuous_voltage_range = true; 224 + memcpy(&drvdata->ops, &pwm_regulator_voltage_continuous_ops, 225 + sizeof(drvdata->ops)); 226 + drvdata->desc.ops = &drvdata->ops; 227 + drvdata->desc.continuous_voltage_range = true; 235 228 236 229 return 0; 237 230 } ··· 256 245 if (!drvdata) 257 246 return -ENOMEM; 258 247 248 + memcpy(&drvdata->desc, &pwm_regulator_desc, sizeof(drvdata->desc)); 249 + 259 250 if (of_find_property(np, "voltage-table", NULL)) 260 251 ret = pwm_regulator_init_table(pdev, drvdata); 261 252 else ··· 266 253 return ret; 267 254 268 255 init_data = of_get_regulator_init_data(&pdev->dev, np, 269 - &pwm_regulator_desc); 256 + &drvdata->desc); 270 257 if (!init_data) 271 258 return -ENOMEM; 272 259 ··· 282 269 } 283 270 284 271 regulator = devm_regulator_register(&pdev->dev, 285 - &pwm_regulator_desc, &config); 272 + &drvdata->desc, &config); 286 273 if (IS_ERR(regulator)) { 287 274 dev_err(&pdev->dev, "Failed to register regulator %s\n", 288 - pwm_regulator_desc.name); 275 + drvdata->desc.name); 289 276 return PTR_ERR(regulator); 290 277 } 291 278
+24 -19
drivers/regulator/s2mps11.c
··· 38 38 /* The highest number of possible regulators for supported devices. */ 39 39 #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX 40 40 struct s2mps11_info { 41 - unsigned int rdev_num; 42 41 int ramp_delay2; 43 42 int ramp_delay34; 44 43 int ramp_delay5; ··· 53 54 */ 54 55 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX); 55 56 56 - /* Array of size rdev_num with GPIO-s for external sleep control */ 57 + /* 58 + * Array (size: number of regulators) with GPIO-s for external 59 + * sleep control. 60 + */ 57 61 int *ext_control_gpio; 58 62 }; 59 63 ··· 821 819 } 822 820 823 821 static int s2mps11_pmic_dt_parse(struct platform_device *pdev, 824 - struct of_regulator_match *rdata, struct s2mps11_info *s2mps11) 822 + struct of_regulator_match *rdata, struct s2mps11_info *s2mps11, 823 + unsigned int rdev_num) 825 824 { 826 825 struct device_node *reg_np; 827 826 ··· 832 829 return -EINVAL; 833 830 } 834 831 835 - of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num); 832 + of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num); 836 833 if (s2mps11->dev_type == S2MPS14X) 837 834 s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11); 838 835 ··· 1080 1077 struct of_regulator_match *rdata = NULL; 1081 1078 struct regulator_config config = { }; 1082 1079 struct s2mps11_info *s2mps11; 1080 + unsigned int rdev_num = 0; 1083 1081 int i, ret = 0; 1084 1082 const struct regulator_desc *regulators; 1085 1083 ··· 1092 1088 s2mps11->dev_type = platform_get_device_id(pdev)->driver_data; 1093 1089 switch (s2mps11->dev_type) { 1094 1090 case S2MPS11X: 1095 - s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators); 1091 + rdev_num = ARRAY_SIZE(s2mps11_regulators); 1096 1092 regulators = s2mps11_regulators; 1097 - BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num); 1093 + BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators)); 1098 1094 break; 1099 1095 case S2MPS13X: 1100 - s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators); 1096 + rdev_num = ARRAY_SIZE(s2mps13_regulators); 1101 1097 regulators = s2mps13_regulators; 1102 - BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num); 1098 + BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators)); 1103 1099 break; 1104 1100 case S2MPS14X: 1105 - s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators); 1101 + rdev_num = ARRAY_SIZE(s2mps14_regulators); 1106 1102 regulators = s2mps14_regulators; 1107 - BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num); 1103 + BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators)); 1108 1104 break; 1109 1105 case S2MPS15X: 1110 - s2mps11->rdev_num = ARRAY_SIZE(s2mps15_regulators); 1106 + rdev_num = ARRAY_SIZE(s2mps15_regulators); 1111 1107 regulators = s2mps15_regulators; 1108 + BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators)); 1112 1109 break; 1113 1110 case S2MPU02: 1114 - s2mps11->rdev_num = ARRAY_SIZE(s2mpu02_regulators); 1111 + rdev_num = ARRAY_SIZE(s2mpu02_regulators); 1115 1112 regulators = s2mpu02_regulators; 1116 - BUILD_BUG_ON(S2MPS_REGULATOR_MAX < s2mps11->rdev_num); 1113 + BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators)); 1117 1114 break; 1118 1115 default: 1119 1116 dev_err(&pdev->dev, "Invalid device type: %u\n", ··· 1123 1118 } 1124 1119 1125 1120 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev, 1126 - sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num, 1121 + sizeof(*s2mps11->ext_control_gpio) * rdev_num, 1127 1122 GFP_KERNEL); 1128 1123 if (!s2mps11->ext_control_gpio) 1129 1124 return -ENOMEM; ··· 1131 1126 * 0 is a valid GPIO so initialize all GPIO-s to negative value 1132 1127 * to indicate that external control won't be used for this regulator. 1133 1128 */ 1134 - for (i = 0; i < s2mps11->rdev_num; i++) 1129 + for (i = 0; i < rdev_num; i++) 1135 1130 s2mps11->ext_control_gpio[i] = -EINVAL; 1136 1131 1137 1132 if (!iodev->dev->of_node) { ··· 1145 1140 } 1146 1141 } 1147 1142 1148 - rdata = kzalloc(sizeof(*rdata) * s2mps11->rdev_num, GFP_KERNEL); 1143 + rdata = kzalloc(sizeof(*rdata) * rdev_num, GFP_KERNEL); 1149 1144 if (!rdata) 1150 1145 return -ENOMEM; 1151 1146 1152 - for (i = 0; i < s2mps11->rdev_num; i++) 1147 + for (i = 0; i < rdev_num; i++) 1153 1148 rdata[i].name = regulators[i].name; 1154 1149 1155 - ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11); 1150 + ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num); 1156 1151 if (ret) 1157 1152 goto out; 1158 1153 ··· 1164 1159 config.driver_data = s2mps11; 1165 1160 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; 1166 1161 config.ena_gpio_initialized = true; 1167 - for (i = 0; i < s2mps11->rdev_num; i++) { 1162 + for (i = 0; i < rdev_num; i++) { 1168 1163 struct regulator_dev *regulator; 1169 1164 1170 1165 if (pdata) {
+9 -4
drivers/regulator/s5m8767.c
··· 202 202 } 203 203 } 204 204 205 - if (i < s5m8767->num_regulators) 206 - *enable_ctrl = 207 - s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT; 205 + if (i >= s5m8767->num_regulators) 206 + return -EINVAL; 207 + 208 + *enable_ctrl = s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT; 208 209 209 210 return 0; 210 211 } ··· 938 937 else 939 938 regulators[id].vsel_mask = 0xff; 940 939 941 - s5m8767_get_register(s5m8767, id, &enable_reg, 940 + ret = s5m8767_get_register(s5m8767, id, &enable_reg, 942 941 &enable_val); 942 + if (ret) { 943 + dev_err(s5m8767->dev, "error reading registers\n"); 944 + return ret; 945 + } 943 946 regulators[id].enable_reg = enable_reg; 944 947 regulators[id].enable_mask = S5M8767_ENCTRL_MASK; 945 948 regulators[id].enable_val = enable_val;
drivers/regulator/vexpress.c drivers/regulator/vexpress-regulator.c
+2 -2
include/linux/regulator/act8865.h
··· 68 68 * act8865_regulator_data - regulator data 69 69 * @id: regulator id 70 70 * @name: regulator name 71 - * @platform_data: regulator init data 71 + * @init_data: regulator init data 72 72 */ 73 73 struct act8865_regulator_data { 74 74 int id; 75 75 const char *name; 76 - struct regulator_init_data *platform_data; 76 + struct regulator_init_data *init_data; 77 77 }; 78 78 79 79 /**
+17
include/linux/regulator/driver.h
··· 93 93 * @get_current_limit: Get the configured limit for a current-limited regulator. 94 94 * @set_input_current_limit: Configure an input limit. 95 95 * 96 + * @set_active_discharge: Set active discharge enable/disable of regulators. 97 + * 96 98 * @set_mode: Set the configured operating mode for the regulator. 97 99 * @get_mode: Get the configured operating mode for the regulator. 98 100 * @get_status: Return actual (not as-configured) status of regulator, as a ··· 151 149 152 150 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); 153 151 int (*set_over_current_protection) (struct regulator_dev *); 152 + int (*set_active_discharge) (struct regulator_dev *, bool enable); 154 153 155 154 /* enable/disable regulator */ 156 155 int (*enable) (struct regulator_dev *); ··· 269 266 * @bypass_mask: Mask for control when using regmap set_bypass 270 267 * @bypass_val_on: Enabling value for control when using regmap set_bypass 271 268 * @bypass_val_off: Disabling value for control when using regmap set_bypass 269 + * @active_discharge_off: Enabling value for control when using regmap 270 + * set_active_discharge 271 + * @active_discharge_on: Disabling value for control when using regmap 272 + * set_active_discharge 273 + * @active_discharge_mask: Mask for control when using regmap 274 + * set_active_discharge 275 + * @active_discharge_reg: Register for control when using regmap 276 + * set_active_discharge 272 277 * 273 278 * @enable_time: Time taken for initial enable of regulator (in uS). 274 279 * @off_on_delay: guard time (in uS), before re-enabling a regulator ··· 326 315 unsigned int bypass_mask; 327 316 unsigned int bypass_val_on; 328 317 unsigned int bypass_val_off; 318 + unsigned int active_discharge_on; 319 + unsigned int active_discharge_off; 320 + unsigned int active_discharge_mask; 321 + unsigned int active_discharge_reg; 329 322 330 323 unsigned int enable_time; 331 324 ··· 462 447 int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable); 463 448 int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable); 464 449 450 + int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, 451 + bool enable); 465 452 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 466 453 467 454 #endif
+5
include/linux/regulator/lp872x.h
··· 18 18 19 19 #define LP872X_MAX_REGULATORS 9 20 20 21 + #define LP8720_ENABLE_DELAY 200 22 + #define LP8725_ENABLE_DELAY 30000 23 + 21 24 enum lp872x_regulator_id { 22 25 LP8720_ID_BASE, 23 26 LP8720_ID_LDO1 = LP8720_ID_BASE, ··· 82 79 * @update_config : if LP872X_GENERAL_CFG register is updated, set true 83 80 * @regulator_data : platform regulator id and init data 84 81 * @dvs : dvs data for buck voltage control 82 + * @enable_gpio : gpio pin number for enable control 85 83 */ 86 84 struct lp872x_platform_data { 87 85 u8 general_config; 88 86 bool update_config; 89 87 struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS]; 90 88 struct lp872x_dvs *dvs; 89 + int enable_gpio; 91 90 }; 92 91 93 92 #endif
+12
include/linux/regulator/machine.h
··· 42 42 #define REGULATOR_CHANGE_DRMS 0x10 43 43 #define REGULATOR_CHANGE_BYPASS 0x20 44 44 45 + /* Regulator active discharge flags */ 46 + enum regulator_active_discharge { 47 + REGULATOR_ACTIVE_DISCHARGE_DEFAULT, 48 + REGULATOR_ACTIVE_DISCHARGE_DISABLE, 49 + REGULATOR_ACTIVE_DISCHARGE_ENABLE, 50 + }; 51 + 45 52 /** 46 53 * struct regulator_state - regulator state during low power system states 47 54 * ··· 107 100 * @initial_state: Suspend state to set by default. 108 101 * @initial_mode: Mode to set at startup. 109 102 * @ramp_delay: Time to settle down after voltage change (unit: uV/us) 103 + * @active_discharge: Enable/disable active discharge. The enum 104 + * regulator_active_discharge values are used for 105 + * initialisation. 110 106 * @enable_time: Turn-on time of the rails (unit: microseconds) 111 107 */ 112 108 struct regulation_constraints { ··· 149 139 150 140 unsigned int ramp_delay; 151 141 unsigned int enable_time; 142 + 143 + unsigned int active_discharge; 152 144 153 145 /* constraint flags */ 154 146 unsigned always_on:1; /* regulator never off when system is on */
+61 -8
sound/soc/codecs/cs4271.c
··· 26 26 #include <linux/of.h> 27 27 #include <linux/of_device.h> 28 28 #include <linux/of_gpio.h> 29 + #include <linux/regulator/consumer.h> 29 30 #include <sound/pcm.h> 30 31 #include <sound/soc.h> 31 32 #include <sound/tlv.h> ··· 158 157 return reg == CS4271_CHIPID; 159 158 } 160 159 160 + static const char * const supply_names[] = { 161 + "vd", "vl", "va" 162 + }; 163 + 161 164 struct cs4271_private { 162 165 unsigned int mclk; 163 166 bool master; ··· 175 170 int gpio_disable; 176 171 /* enable soft reset workaround */ 177 172 bool enable_soft_reset; 173 + struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; 178 174 }; 179 175 180 176 static const struct snd_soc_dapm_widget cs4271_dapm_widgets[] = { ··· 493 487 .symmetric_rates = 1, 494 488 }; 495 489 490 + static int cs4271_reset(struct snd_soc_codec *codec) 491 + { 492 + struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 493 + 494 + if (gpio_is_valid(cs4271->gpio_nreset)) { 495 + gpio_set_value(cs4271->gpio_nreset, 0); 496 + mdelay(1); 497 + gpio_set_value(cs4271->gpio_nreset, 1); 498 + mdelay(1); 499 + } 500 + 501 + return 0; 502 + } 503 + 496 504 #ifdef CONFIG_PM 497 505 static int cs4271_soc_suspend(struct snd_soc_codec *codec) 498 506 { ··· 519 499 if (ret < 0) 520 500 return ret; 521 501 502 + regcache_mark_dirty(cs4271->regmap); 503 + regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); 504 + 522 505 return 0; 523 506 } 524 507 ··· 529 506 { 530 507 int ret; 531 508 struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); 509 + 510 + ret = regulator_bulk_enable(ARRAY_SIZE(cs4271->supplies), 511 + cs4271->supplies); 512 + if (ret < 0) { 513 + dev_err(codec->dev, "Failed to enable regulators: %d\n", ret); 514 + return ret; 515 + } 516 + 517 + /* Do a proper reset after power up */ 518 + cs4271_reset(codec); 532 519 533 520 /* Restore codec state */ 534 521 ret = regcache_sync(cs4271->regmap); ··· 586 553 } 587 554 #endif 588 555 556 + ret = regulator_bulk_enable(ARRAY_SIZE(cs4271->supplies), 557 + cs4271->supplies); 558 + if (ret < 0) { 559 + dev_err(codec->dev, "Failed to enable regulators: %d\n", ret); 560 + return ret; 561 + } 562 + 589 563 if (cs4271plat) { 590 564 amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; 591 565 cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; 592 566 } 593 567 594 - if (gpio_is_valid(cs4271->gpio_nreset)) { 595 - /* Reset codec */ 596 - gpio_direction_output(cs4271->gpio_nreset, 0); 597 - mdelay(1); 598 - gpio_set_value(cs4271->gpio_nreset, 1); 599 - /* Give the codec time to wake up */ 600 - mdelay(1); 601 - } 568 + /* Reset codec */ 569 + cs4271_reset(codec); 570 + 571 + ret = regcache_sync(cs4271->regmap); 572 + if (ret < 0) 573 + return ret; 602 574 603 575 ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, 604 576 CS4271_MODE2_PDN | CS4271_MODE2_CPEN, ··· 633 595 /* Set codec to the reset state */ 634 596 gpio_set_value(cs4271->gpio_nreset, 0); 635 597 598 + regcache_mark_dirty(cs4271->regmap); 599 + regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); 600 + 636 601 return 0; 637 602 }; 638 603 ··· 658 617 { 659 618 struct cs4271_platform_data *cs4271plat = dev->platform_data; 660 619 struct cs4271_private *cs4271; 620 + int i, ret; 661 621 662 622 cs4271 = devm_kzalloc(dev, sizeof(*cs4271), GFP_KERNEL); 663 623 if (!cs4271) ··· 678 636 "CS4271 Reset"); 679 637 if (ret < 0) 680 638 return ret; 639 + } 640 + 641 + for (i = 0; i < ARRAY_SIZE(supply_names); i++) 642 + cs4271->supplies[i].supply = supply_names[i]; 643 + 644 + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(cs4271->supplies), 645 + cs4271->supplies); 646 + 647 + if (ret < 0) { 648 + dev_err(dev, "Failed to get regulators: %d\n", ret); 649 + return ret; 681 650 } 682 651 683 652 *c = cs4271;