Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * License Terms: GNU General Public License v2 |
| 5 | * |
| 6 | * Authors: Bengt Jonsson <bengt.g.jonsson@stericsson.com> |
| 7 | * |
| 8 | * This file is based on drivers/regulator/ab8500.c |
| 9 | * |
| 10 | * AB8500 external regulators |
| 11 | * |
| 12 | * ab8500-ext supports the following regulators: |
| 13 | * - VextSupply3 |
| 14 | */ |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/module.h> |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 19 | #include <linux/of.h> |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regulator/driver.h> |
| 22 | #include <linux/regulator/machine.h> |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 23 | #include <linux/regulator/of_regulator.h> |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 24 | #include <linux/mfd/abx500.h> |
| 25 | #include <linux/mfd/abx500/ab8500.h> |
| 26 | #include <linux/regulator/ab8500.h> |
| 27 | |
Arnd Bergmann | 79886be | 2016-03-18 16:21:36 +0100 | [diff] [blame] | 28 | static struct regulator_consumer_supply ab8500_vaux1_consumers[] = { |
| 29 | /* Main display, u8500 R3 uib */ |
| 30 | REGULATOR_SUPPLY("vddi", "mcde_disp_sony_acx424akp.0"), |
| 31 | /* Main display, u8500 uib and ST uib */ |
| 32 | REGULATOR_SUPPLY("vdd1", "samsung_s6d16d0.0"), |
| 33 | /* Secondary display, ST uib */ |
| 34 | REGULATOR_SUPPLY("vdd1", "samsung_s6d16d0.1"), |
| 35 | /* SFH7741 proximity sensor */ |
| 36 | REGULATOR_SUPPLY("vcc", "gpio-keys.0"), |
| 37 | /* BH1780GLS ambient light sensor */ |
| 38 | REGULATOR_SUPPLY("vcc", "2-0029"), |
| 39 | /* lsm303dlh accelerometer */ |
| 40 | REGULATOR_SUPPLY("vdd", "2-0018"), |
| 41 | /* lsm303dlhc accelerometer */ |
| 42 | REGULATOR_SUPPLY("vdd", "2-0019"), |
| 43 | /* lsm303dlh magnetometer */ |
| 44 | REGULATOR_SUPPLY("vdd", "2-001e"), |
| 45 | /* Rohm BU21013 Touchscreen devices */ |
| 46 | REGULATOR_SUPPLY("avdd", "3-005c"), |
| 47 | REGULATOR_SUPPLY("avdd", "3-005d"), |
| 48 | /* Synaptics RMI4 Touchscreen device */ |
| 49 | REGULATOR_SUPPLY("vdd", "3-004b"), |
| 50 | /* L3G4200D Gyroscope device */ |
| 51 | REGULATOR_SUPPLY("vdd", "2-0068"), |
| 52 | /* Ambient light sensor device */ |
| 53 | REGULATOR_SUPPLY("vdd", "3-0029"), |
| 54 | /* Pressure sensor device */ |
| 55 | REGULATOR_SUPPLY("vdd", "2-005c"), |
| 56 | /* Cypress TrueTouch Touchscreen device */ |
| 57 | REGULATOR_SUPPLY("vcpin", "spi8.0"), |
| 58 | /* Camera device */ |
| 59 | REGULATOR_SUPPLY("vaux12v5", "mmio_camera"), |
| 60 | }; |
| 61 | |
| 62 | static struct regulator_consumer_supply ab8500_vaux2_consumers[] = { |
| 63 | /* On-board eMMC power */ |
| 64 | REGULATOR_SUPPLY("vmmc", "sdi4"), |
| 65 | /* AB8500 audio codec */ |
| 66 | REGULATOR_SUPPLY("vcc-N2158", "ab8500-codec.0"), |
| 67 | /* AB8500 accessory detect 1 */ |
| 68 | REGULATOR_SUPPLY("vcc-N2158", "ab8500-acc-det.0"), |
| 69 | /* AB8500 Tv-out device */ |
| 70 | REGULATOR_SUPPLY("vcc-N2158", "mcde_tv_ab8500.4"), |
| 71 | /* AV8100 HDMI device */ |
| 72 | REGULATOR_SUPPLY("vcc-N2158", "av8100_hdmi.3"), |
| 73 | }; |
| 74 | |
| 75 | static struct regulator_consumer_supply ab8500_vaux3_consumers[] = { |
| 76 | REGULATOR_SUPPLY("v-SD-STM", "stm"), |
| 77 | /* External MMC slot power */ |
| 78 | REGULATOR_SUPPLY("vmmc", "sdi0"), |
| 79 | }; |
| 80 | |
| 81 | static struct regulator_consumer_supply ab8500_vtvout_consumers[] = { |
| 82 | /* TV-out DENC supply */ |
| 83 | REGULATOR_SUPPLY("vtvout", "ab8500-denc.0"), |
| 84 | /* Internal general-purpose ADC */ |
| 85 | REGULATOR_SUPPLY("vddadc", "ab8500-gpadc.0"), |
| 86 | /* ADC for charger */ |
| 87 | REGULATOR_SUPPLY("vddadc", "ab8500-charger.0"), |
| 88 | /* AB8500 Tv-out device */ |
| 89 | REGULATOR_SUPPLY("vtvout", "mcde_tv_ab8500.4"), |
| 90 | }; |
| 91 | |
| 92 | static struct regulator_consumer_supply ab8500_vaud_consumers[] = { |
| 93 | /* AB8500 audio-codec main supply */ |
| 94 | REGULATOR_SUPPLY("vaud", "ab8500-codec.0"), |
| 95 | }; |
| 96 | |
| 97 | static struct regulator_consumer_supply ab8500_vamic1_consumers[] = { |
| 98 | /* AB8500 audio-codec Mic1 supply */ |
| 99 | REGULATOR_SUPPLY("vamic1", "ab8500-codec.0"), |
| 100 | }; |
| 101 | |
| 102 | static struct regulator_consumer_supply ab8500_vamic2_consumers[] = { |
| 103 | /* AB8500 audio-codec Mic2 supply */ |
| 104 | REGULATOR_SUPPLY("vamic2", "ab8500-codec.0"), |
| 105 | }; |
| 106 | |
| 107 | static struct regulator_consumer_supply ab8500_vdmic_consumers[] = { |
| 108 | /* AB8500 audio-codec DMic supply */ |
| 109 | REGULATOR_SUPPLY("vdmic", "ab8500-codec.0"), |
| 110 | }; |
| 111 | |
| 112 | static struct regulator_consumer_supply ab8500_vintcore_consumers[] = { |
| 113 | /* SoC core supply, no device */ |
| 114 | REGULATOR_SUPPLY("v-intcore", NULL), |
| 115 | /* USB Transceiver */ |
| 116 | REGULATOR_SUPPLY("vddulpivio18", "ab8500-usb.0"), |
| 117 | /* Handled by abx500 clk driver */ |
| 118 | REGULATOR_SUPPLY("v-intcore", "abx500-clk.0"), |
| 119 | }; |
| 120 | |
| 121 | static struct regulator_consumer_supply ab8500_vana_consumers[] = { |
| 122 | /* DB8500 DSI */ |
| 123 | REGULATOR_SUPPLY("vdddsi1v2", "mcde"), |
| 124 | REGULATOR_SUPPLY("vdddsi1v2", "b2r2_core"), |
| 125 | REGULATOR_SUPPLY("vdddsi1v2", "b2r2_1_core"), |
| 126 | REGULATOR_SUPPLY("vdddsi1v2", "dsilink.0"), |
| 127 | REGULATOR_SUPPLY("vdddsi1v2", "dsilink.1"), |
| 128 | REGULATOR_SUPPLY("vdddsi1v2", "dsilink.2"), |
| 129 | /* DB8500 CSI */ |
| 130 | REGULATOR_SUPPLY("vddcsi1v2", "mmio_camera"), |
| 131 | }; |
| 132 | |
| 133 | /* ab8500 regulator register initialization */ |
| 134 | static struct ab8500_regulator_reg_init ab8500_reg_init[] = { |
| 135 | /* |
| 136 | * VanaRequestCtrl = HP/LP depending on VxRequest |
| 137 | * VextSupply1RequestCtrl = HP/LP depending on VxRequest |
| 138 | */ |
| 139 | INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL2, 0xf0, 0x00), |
| 140 | /* |
| 141 | * VextSupply2RequestCtrl = HP/LP depending on VxRequest |
| 142 | * VextSupply3RequestCtrl = HP/LP depending on VxRequest |
| 143 | * Vaux1RequestCtrl = HP/LP depending on VxRequest |
| 144 | * Vaux2RequestCtrl = HP/LP depending on VxRequest |
| 145 | */ |
| 146 | INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL3, 0xff, 0x00), |
| 147 | /* |
| 148 | * Vaux3RequestCtrl = HP/LP depending on VxRequest |
| 149 | * SwHPReq = Control through SWValid disabled |
| 150 | */ |
| 151 | INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL4, 0x07, 0x00), |
| 152 | /* |
| 153 | * VanaSysClkReq1HPValid = disabled |
| 154 | * Vaux1SysClkReq1HPValid = disabled |
| 155 | * Vaux2SysClkReq1HPValid = disabled |
| 156 | * Vaux3SysClkReq1HPValid = disabled |
| 157 | */ |
| 158 | INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQ1HPVALID1, 0xe8, 0x00), |
| 159 | /* |
| 160 | * VextSupply1SysClkReq1HPValid = disabled |
| 161 | * VextSupply2SysClkReq1HPValid = disabled |
| 162 | * VextSupply3SysClkReq1HPValid = SysClkReq1 controlled |
| 163 | */ |
| 164 | INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQ1HPVALID2, 0x70, 0x40), |
| 165 | /* |
| 166 | * VanaHwHPReq1Valid = disabled |
| 167 | * Vaux1HwHPreq1Valid = disabled |
| 168 | * Vaux2HwHPReq1Valid = disabled |
| 169 | * Vaux3HwHPReqValid = disabled |
| 170 | */ |
| 171 | INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ1VALID1, 0xe8, 0x00), |
| 172 | /* |
| 173 | * VextSupply1HwHPReq1Valid = disabled |
| 174 | * VextSupply2HwHPReq1Valid = disabled |
| 175 | * VextSupply3HwHPReq1Valid = disabled |
| 176 | */ |
| 177 | INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ1VALID2, 0x07, 0x00), |
| 178 | /* |
| 179 | * VanaHwHPReq2Valid = disabled |
| 180 | * Vaux1HwHPReq2Valid = disabled |
| 181 | * Vaux2HwHPReq2Valid = disabled |
| 182 | * Vaux3HwHPReq2Valid = disabled |
| 183 | */ |
| 184 | INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ2VALID1, 0xe8, 0x00), |
| 185 | /* |
| 186 | * VextSupply1HwHPReq2Valid = disabled |
| 187 | * VextSupply2HwHPReq2Valid = disabled |
| 188 | * VextSupply3HwHPReq2Valid = HWReq2 controlled |
| 189 | */ |
| 190 | INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ2VALID2, 0x07, 0x04), |
| 191 | /* |
| 192 | * VanaSwHPReqValid = disabled |
| 193 | * Vaux1SwHPReqValid = disabled |
| 194 | */ |
| 195 | INIT_REGULATOR_REGISTER(AB8500_REGUSWHPREQVALID1, 0xa0, 0x00), |
| 196 | /* |
| 197 | * Vaux2SwHPReqValid = disabled |
| 198 | * Vaux3SwHPReqValid = disabled |
| 199 | * VextSupply1SwHPReqValid = disabled |
| 200 | * VextSupply2SwHPReqValid = disabled |
| 201 | * VextSupply3SwHPReqValid = disabled |
| 202 | */ |
| 203 | INIT_REGULATOR_REGISTER(AB8500_REGUSWHPREQVALID2, 0x1f, 0x00), |
| 204 | /* |
| 205 | * SysClkReq2Valid1 = SysClkReq2 controlled |
| 206 | * SysClkReq3Valid1 = disabled |
| 207 | * SysClkReq4Valid1 = SysClkReq4 controlled |
| 208 | * SysClkReq5Valid1 = disabled |
| 209 | * SysClkReq6Valid1 = SysClkReq6 controlled |
| 210 | * SysClkReq7Valid1 = disabled |
| 211 | * SysClkReq8Valid1 = disabled |
| 212 | */ |
| 213 | INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQVALID1, 0xfe, 0x2a), |
| 214 | /* |
| 215 | * SysClkReq2Valid2 = disabled |
| 216 | * SysClkReq3Valid2 = disabled |
| 217 | * SysClkReq4Valid2 = disabled |
| 218 | * SysClkReq5Valid2 = disabled |
| 219 | * SysClkReq6Valid2 = SysClkReq6 controlled |
| 220 | * SysClkReq7Valid2 = disabled |
| 221 | * SysClkReq8Valid2 = disabled |
| 222 | */ |
| 223 | INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQVALID2, 0xfe, 0x20), |
| 224 | /* |
| 225 | * VTVoutEna = disabled |
| 226 | * Vintcore12Ena = disabled |
| 227 | * Vintcore12Sel = 1.25 V |
| 228 | * Vintcore12LP = inactive (HP) |
| 229 | * VTVoutLP = inactive (HP) |
| 230 | */ |
| 231 | INIT_REGULATOR_REGISTER(AB8500_REGUMISC1, 0xfe, 0x10), |
| 232 | /* |
| 233 | * VaudioEna = disabled |
| 234 | * VdmicEna = disabled |
| 235 | * Vamic1Ena = disabled |
| 236 | * Vamic2Ena = disabled |
| 237 | */ |
| 238 | INIT_REGULATOR_REGISTER(AB8500_VAUDIOSUPPLY, 0x1e, 0x00), |
| 239 | /* |
| 240 | * Vamic1_dzout = high-Z when Vamic1 is disabled |
| 241 | * Vamic2_dzout = high-Z when Vamic2 is disabled |
| 242 | */ |
| 243 | INIT_REGULATOR_REGISTER(AB8500_REGUCTRL1VAMIC, 0x03, 0x00), |
| 244 | /* |
| 245 | * VPll = Hw controlled (NOTE! PRCMU bits) |
| 246 | * VanaRegu = force off |
| 247 | */ |
| 248 | INIT_REGULATOR_REGISTER(AB8500_VPLLVANAREGU, 0x0f, 0x02), |
| 249 | /* |
| 250 | * VrefDDREna = disabled |
| 251 | * VrefDDRSleepMode = inactive (no pulldown) |
| 252 | */ |
| 253 | INIT_REGULATOR_REGISTER(AB8500_VREFDDR, 0x03, 0x00), |
| 254 | /* |
| 255 | * VextSupply1Regu = force LP |
| 256 | * VextSupply2Regu = force OFF |
| 257 | * VextSupply3Regu = force HP (-> STBB2=LP and TPS=LP) |
| 258 | * ExtSupply2Bypass = ExtSupply12LPn ball is 0 when Ena is 0 |
| 259 | * ExtSupply3Bypass = ExtSupply3LPn ball is 0 when Ena is 0 |
| 260 | */ |
| 261 | INIT_REGULATOR_REGISTER(AB8500_EXTSUPPLYREGU, 0xff, 0x13), |
| 262 | /* |
| 263 | * Vaux1Regu = force HP |
| 264 | * Vaux2Regu = force off |
| 265 | */ |
| 266 | INIT_REGULATOR_REGISTER(AB8500_VAUX12REGU, 0x0f, 0x01), |
| 267 | /* |
| 268 | * Vaux3Regu = force off |
| 269 | */ |
| 270 | INIT_REGULATOR_REGISTER(AB8500_VRF1VAUX3REGU, 0x03, 0x00), |
| 271 | /* |
| 272 | * Vaux1Sel = 2.8 V |
| 273 | */ |
| 274 | INIT_REGULATOR_REGISTER(AB8500_VAUX1SEL, 0x0f, 0x0C), |
| 275 | /* |
| 276 | * Vaux2Sel = 2.9 V |
| 277 | */ |
| 278 | INIT_REGULATOR_REGISTER(AB8500_VAUX2SEL, 0x0f, 0x0d), |
| 279 | /* |
| 280 | * Vaux3Sel = 2.91 V |
| 281 | */ |
| 282 | INIT_REGULATOR_REGISTER(AB8500_VRF1VAUX3SEL, 0x07, 0x07), |
| 283 | /* |
| 284 | * VextSupply12LP = disabled (no LP) |
| 285 | */ |
| 286 | INIT_REGULATOR_REGISTER(AB8500_REGUCTRL2SPARE, 0x01, 0x00), |
| 287 | /* |
| 288 | * Vaux1Disch = short discharge time |
| 289 | * Vaux2Disch = short discharge time |
| 290 | * Vaux3Disch = short discharge time |
| 291 | * Vintcore12Disch = short discharge time |
| 292 | * VTVoutDisch = short discharge time |
| 293 | * VaudioDisch = short discharge time |
| 294 | */ |
| 295 | INIT_REGULATOR_REGISTER(AB8500_REGUCTRLDISCH, 0xfc, 0x00), |
| 296 | /* |
| 297 | * VanaDisch = short discharge time |
| 298 | * VdmicPullDownEna = pulldown disabled when Vdmic is disabled |
| 299 | * VdmicDisch = short discharge time |
| 300 | */ |
| 301 | INIT_REGULATOR_REGISTER(AB8500_REGUCTRLDISCH2, 0x16, 0x00), |
| 302 | }; |
| 303 | |
| 304 | /* AB8500 regulators */ |
| 305 | static struct regulator_init_data ab8500_regulators[AB8500_NUM_REGULATORS] = { |
| 306 | /* supplies to the display/camera */ |
| 307 | [AB8500_LDO_AUX1] = { |
| 308 | .supply_regulator = "ab8500-ext-supply3", |
| 309 | .constraints = { |
| 310 | .name = "V-DISPLAY", |
| 311 | .min_uV = 2800000, |
| 312 | .max_uV = 3300000, |
| 313 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | |
| 314 | REGULATOR_CHANGE_STATUS, |
| 315 | .boot_on = 1, /* display is on at boot */ |
| 316 | }, |
| 317 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux1_consumers), |
| 318 | .consumer_supplies = ab8500_vaux1_consumers, |
| 319 | }, |
| 320 | /* supplies to the on-board eMMC */ |
| 321 | [AB8500_LDO_AUX2] = { |
| 322 | .supply_regulator = "ab8500-ext-supply3", |
| 323 | .constraints = { |
| 324 | .name = "V-eMMC1", |
| 325 | .min_uV = 1100000, |
| 326 | .max_uV = 3300000, |
| 327 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | |
| 328 | REGULATOR_CHANGE_STATUS | |
| 329 | REGULATOR_CHANGE_MODE, |
| 330 | .valid_modes_mask = REGULATOR_MODE_NORMAL | |
| 331 | REGULATOR_MODE_IDLE, |
| 332 | }, |
| 333 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux2_consumers), |
| 334 | .consumer_supplies = ab8500_vaux2_consumers, |
| 335 | }, |
| 336 | /* supply for VAUX3, supplies to SDcard slots */ |
| 337 | [AB8500_LDO_AUX3] = { |
| 338 | .supply_regulator = "ab8500-ext-supply3", |
| 339 | .constraints = { |
| 340 | .name = "V-MMC-SD", |
| 341 | .min_uV = 1100000, |
| 342 | .max_uV = 3300000, |
| 343 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | |
| 344 | REGULATOR_CHANGE_STATUS | |
| 345 | REGULATOR_CHANGE_MODE, |
| 346 | .valid_modes_mask = REGULATOR_MODE_NORMAL | |
| 347 | REGULATOR_MODE_IDLE, |
| 348 | }, |
| 349 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux3_consumers), |
| 350 | .consumer_supplies = ab8500_vaux3_consumers, |
| 351 | }, |
| 352 | /* supply for tvout, gpadc, TVOUT LDO */ |
| 353 | [AB8500_LDO_TVOUT] = { |
| 354 | .constraints = { |
| 355 | .name = "V-TVOUT", |
| 356 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 357 | }, |
| 358 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vtvout_consumers), |
| 359 | .consumer_supplies = ab8500_vtvout_consumers, |
| 360 | }, |
| 361 | /* supply for ab8500-vaudio, VAUDIO LDO */ |
| 362 | [AB8500_LDO_AUDIO] = { |
| 363 | .constraints = { |
| 364 | .name = "V-AUD", |
| 365 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 366 | }, |
| 367 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vaud_consumers), |
| 368 | .consumer_supplies = ab8500_vaud_consumers, |
| 369 | }, |
| 370 | /* supply for v-anamic1 VAMic1-LDO */ |
| 371 | [AB8500_LDO_ANAMIC1] = { |
| 372 | .constraints = { |
| 373 | .name = "V-AMIC1", |
| 374 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 375 | }, |
| 376 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vamic1_consumers), |
| 377 | .consumer_supplies = ab8500_vamic1_consumers, |
| 378 | }, |
| 379 | /* supply for v-amic2, VAMIC2 LDO, reuse constants for AMIC1 */ |
| 380 | [AB8500_LDO_ANAMIC2] = { |
| 381 | .constraints = { |
| 382 | .name = "V-AMIC2", |
| 383 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 384 | }, |
| 385 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vamic2_consumers), |
| 386 | .consumer_supplies = ab8500_vamic2_consumers, |
| 387 | }, |
| 388 | /* supply for v-dmic, VDMIC LDO */ |
| 389 | [AB8500_LDO_DMIC] = { |
| 390 | .constraints = { |
| 391 | .name = "V-DMIC", |
| 392 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 393 | }, |
| 394 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vdmic_consumers), |
| 395 | .consumer_supplies = ab8500_vdmic_consumers, |
| 396 | }, |
| 397 | /* supply for v-intcore12, VINTCORE12 LDO */ |
| 398 | [AB8500_LDO_INTCORE] = { |
| 399 | .constraints = { |
| 400 | .name = "V-INTCORE", |
| 401 | .min_uV = 1250000, |
| 402 | .max_uV = 1350000, |
| 403 | .input_uV = 1800000, |
| 404 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | |
| 405 | REGULATOR_CHANGE_STATUS | |
| 406 | REGULATOR_CHANGE_MODE | |
| 407 | REGULATOR_CHANGE_DRMS, |
| 408 | .valid_modes_mask = REGULATOR_MODE_NORMAL | |
| 409 | REGULATOR_MODE_IDLE, |
| 410 | }, |
| 411 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vintcore_consumers), |
| 412 | .consumer_supplies = ab8500_vintcore_consumers, |
| 413 | }, |
| 414 | /* supply for U8500 CSI-DSI, VANA LDO */ |
| 415 | [AB8500_LDO_ANA] = { |
| 416 | .constraints = { |
| 417 | .name = "V-CSI-DSI", |
| 418 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 419 | }, |
| 420 | .num_consumer_supplies = ARRAY_SIZE(ab8500_vana_consumers), |
| 421 | .consumer_supplies = ab8500_vana_consumers, |
| 422 | }, |
| 423 | }; |
| 424 | |
| 425 | /* supply for VextSupply3 */ |
| 426 | static struct regulator_consumer_supply ab8500_ext_supply3_consumers[] = { |
| 427 | /* SIM supply for 3 V SIM cards */ |
| 428 | REGULATOR_SUPPLY("vinvsim", "sim-detect.0"), |
| 429 | }; |
| 430 | |
| 431 | /* |
| 432 | * AB8500 external regulators |
| 433 | */ |
| 434 | static struct regulator_init_data ab8500_ext_regulators[] = { |
| 435 | /* fixed Vbat supplies VSMPS1_EXT_1V8 */ |
| 436 | [AB8500_EXT_SUPPLY1] = { |
| 437 | .constraints = { |
| 438 | .name = "ab8500-ext-supply1", |
| 439 | .min_uV = 1800000, |
| 440 | .max_uV = 1800000, |
| 441 | .initial_mode = REGULATOR_MODE_IDLE, |
| 442 | .boot_on = 1, |
| 443 | .always_on = 1, |
| 444 | }, |
| 445 | }, |
| 446 | /* fixed Vbat supplies VSMPS2_EXT_1V36 and VSMPS5_EXT_1V15 */ |
| 447 | [AB8500_EXT_SUPPLY2] = { |
| 448 | .constraints = { |
| 449 | .name = "ab8500-ext-supply2", |
| 450 | .min_uV = 1360000, |
| 451 | .max_uV = 1360000, |
| 452 | }, |
| 453 | }, |
| 454 | /* fixed Vbat supplies VSMPS3_EXT_3V4 and VSMPS4_EXT_3V4 */ |
| 455 | [AB8500_EXT_SUPPLY3] = { |
| 456 | .constraints = { |
| 457 | .name = "ab8500-ext-supply3", |
| 458 | .min_uV = 3400000, |
| 459 | .max_uV = 3400000, |
| 460 | .valid_ops_mask = REGULATOR_CHANGE_STATUS, |
| 461 | .boot_on = 1, |
| 462 | }, |
| 463 | .num_consumer_supplies = |
| 464 | ARRAY_SIZE(ab8500_ext_supply3_consumers), |
| 465 | .consumer_supplies = ab8500_ext_supply3_consumers, |
| 466 | }, |
| 467 | }; |
| 468 | |
| 469 | static struct ab8500_regulator_platform_data ab8500_regulator_plat_data = { |
| 470 | .reg_init = ab8500_reg_init, |
| 471 | .num_reg_init = ARRAY_SIZE(ab8500_reg_init), |
| 472 | .regulator = ab8500_regulators, |
| 473 | .num_regulator = ARRAY_SIZE(ab8500_regulators), |
| 474 | .ext_regulator = ab8500_ext_regulators, |
| 475 | .num_ext_regulator = ARRAY_SIZE(ab8500_ext_regulators), |
| 476 | }; |
| 477 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 478 | /** |
| 479 | * struct ab8500_ext_regulator_info - ab8500 regulator information |
| 480 | * @dev: device pointer |
| 481 | * @desc: regulator description |
| 482 | * @rdev: regulator device |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 483 | * @cfg: regulator configuration (extension of regulator FW configuration) |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 484 | * @update_bank: bank to control on/off |
| 485 | * @update_reg: register to control on/off |
| 486 | * @update_mask: mask to enable/disable and set mode of regulator |
| 487 | * @update_val: bits holding the regulator current mode |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 488 | * @update_val_hp: bits to set EN pin active (LPn pin deactive) |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 489 | * normally this means high power mode |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 490 | * @update_val_lp: bits to set EN pin active and LPn pin active |
| 491 | * normally this means low power mode |
| 492 | * @update_val_hw: bits to set regulator pins in HW control |
| 493 | * SysClkReq pins and logic will choose mode |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 494 | */ |
| 495 | struct ab8500_ext_regulator_info { |
| 496 | struct device *dev; |
| 497 | struct regulator_desc desc; |
| 498 | struct regulator_dev *rdev; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 499 | struct ab8500_ext_regulator_cfg *cfg; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 500 | u8 update_bank; |
| 501 | u8 update_reg; |
| 502 | u8 update_mask; |
| 503 | u8 update_val; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 504 | u8 update_val_hp; |
| 505 | u8 update_val_lp; |
| 506 | u8 update_val_hw; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 509 | static int ab8500_ext_regulator_enable(struct regulator_dev *rdev) |
| 510 | { |
| 511 | int ret; |
| 512 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
| 513 | u8 regval; |
| 514 | |
| 515 | if (info == NULL) { |
| 516 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 517 | return -EINVAL; |
| 518 | } |
| 519 | |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 520 | /* |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 521 | * To satisfy both HW high power request and SW request, the regulator |
| 522 | * must be on in high power. |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 523 | */ |
| 524 | if (info->cfg && info->cfg->hwreq) |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 525 | regval = info->update_val_hp; |
| 526 | else |
| 527 | regval = info->update_val; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 528 | |
| 529 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 530 | info->update_bank, info->update_reg, |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 531 | info->update_mask, regval); |
Axel Lin | 37daa8a | 2013-04-02 20:56:16 +0800 | [diff] [blame] | 532 | if (ret < 0) { |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 533 | dev_err(rdev_get_dev(info->rdev), |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 534 | "couldn't set enable bits for regulator\n"); |
Axel Lin | 37daa8a | 2013-04-02 20:56:16 +0800 | [diff] [blame] | 535 | return ret; |
| 536 | } |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 537 | |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 538 | dev_dbg(rdev_get_dev(rdev), |
| 539 | "%s-enable (bank, reg, mask, value): 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 540 | info->desc.name, info->update_bank, info->update_reg, |
| 541 | info->update_mask, regval); |
| 542 | |
| 543 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static int ab8500_ext_regulator_disable(struct regulator_dev *rdev) |
| 547 | { |
| 548 | int ret; |
| 549 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 550 | u8 regval; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 551 | |
| 552 | if (info == NULL) { |
| 553 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 554 | return -EINVAL; |
| 555 | } |
| 556 | |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 557 | /* |
| 558 | * Set the regulator in HW request mode if configured |
| 559 | */ |
| 560 | if (info->cfg && info->cfg->hwreq) |
| 561 | regval = info->update_val_hw; |
| 562 | else |
| 563 | regval = 0; |
| 564 | |
| 565 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 566 | info->update_bank, info->update_reg, |
| 567 | info->update_mask, regval); |
| 568 | if (ret < 0) { |
| 569 | dev_err(rdev_get_dev(info->rdev), |
| 570 | "couldn't set disable bits for regulator\n"); |
| 571 | return ret; |
| 572 | } |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 573 | |
| 574 | dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):" |
| 575 | " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 576 | info->desc.name, info->update_bank, info->update_reg, |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 577 | info->update_mask, regval); |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 578 | |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 579 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev) |
| 583 | { |
| 584 | int ret; |
| 585 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
| 586 | u8 regval; |
| 587 | |
| 588 | if (info == NULL) { |
| 589 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 590 | return -EINVAL; |
| 591 | } |
| 592 | |
| 593 | ret = abx500_get_register_interruptible(info->dev, |
| 594 | info->update_bank, info->update_reg, ®val); |
| 595 | if (ret < 0) { |
| 596 | dev_err(rdev_get_dev(rdev), |
| 597 | "couldn't read 0x%x register\n", info->update_reg); |
| 598 | return ret; |
| 599 | } |
| 600 | |
| 601 | dev_dbg(rdev_get_dev(rdev), "%s-is_enabled (bank, reg, mask, value):" |
| 602 | " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 603 | info->desc.name, info->update_bank, info->update_reg, |
| 604 | info->update_mask, regval); |
| 605 | |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 606 | if (((regval & info->update_mask) == info->update_val_lp) || |
| 607 | ((regval & info->update_mask) == info->update_val_hp)) |
Axel Lin | 9ab51a0 | 2013-04-07 23:13:39 +0800 | [diff] [blame] | 608 | return 1; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 609 | else |
Axel Lin | 9ab51a0 | 2013-04-07 23:13:39 +0800 | [diff] [blame] | 610 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, |
| 614 | unsigned int mode) |
| 615 | { |
| 616 | int ret = 0; |
| 617 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 618 | u8 regval; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 619 | |
| 620 | if (info == NULL) { |
| 621 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 622 | return -EINVAL; |
| 623 | } |
| 624 | |
| 625 | switch (mode) { |
| 626 | case REGULATOR_MODE_NORMAL: |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 627 | regval = info->update_val_hp; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 628 | break; |
| 629 | case REGULATOR_MODE_IDLE: |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 630 | regval = info->update_val_lp; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 631 | break; |
| 632 | |
| 633 | default: |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 637 | /* If regulator is enabled and info->cfg->hwreq is set, the regulator |
| 638 | must be on in high power, so we don't need to write the register with |
| 639 | the same value. |
| 640 | */ |
| 641 | if (ab8500_ext_regulator_is_enabled(rdev) && |
| 642 | !(info->cfg && info->cfg->hwreq)) { |
| 643 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 644 | info->update_bank, info->update_reg, |
| 645 | info->update_mask, regval); |
| 646 | if (ret < 0) { |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 647 | dev_err(rdev_get_dev(rdev), |
| 648 | "Could not set regulator mode.\n"); |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 649 | return ret; |
| 650 | } |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 651 | |
| 652 | dev_dbg(rdev_get_dev(rdev), |
| 653 | "%s-set_mode (bank, reg, mask, value): " |
| 654 | "0x%x, 0x%x, 0x%x, 0x%x\n", |
| 655 | info->desc.name, info->update_bank, info->update_reg, |
| 656 | info->update_mask, regval); |
| 657 | } |
| 658 | |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 659 | info->update_val = regval; |
| 660 | |
| 661 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev) |
| 665 | { |
| 666 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
| 667 | int ret; |
| 668 | |
| 669 | if (info == NULL) { |
| 670 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 671 | return -EINVAL; |
| 672 | } |
| 673 | |
| 674 | if (info->update_val == info->update_val_hp) |
| 675 | ret = REGULATOR_MODE_NORMAL; |
| 676 | else if (info->update_val == info->update_val_lp) |
| 677 | ret = REGULATOR_MODE_IDLE; |
| 678 | else |
| 679 | ret = -EINVAL; |
| 680 | |
| 681 | return ret; |
| 682 | } |
| 683 | |
Lee Jones | 33fb880 | 2013-06-07 17:11:25 +0100 | [diff] [blame] | 684 | static int ab8500_ext_set_voltage(struct regulator_dev *rdev, int min_uV, |
| 685 | int max_uV, unsigned *selector) |
| 686 | { |
| 687 | struct regulation_constraints *regu_constraints = rdev->constraints; |
| 688 | |
| 689 | if (!regu_constraints) { |
| 690 | dev_err(rdev_get_dev(rdev), "No regulator constraints\n"); |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | |
| 694 | if (regu_constraints->min_uV == min_uV && |
| 695 | regu_constraints->max_uV == max_uV) |
| 696 | return 0; |
| 697 | |
| 698 | dev_err(rdev_get_dev(rdev), |
| 699 | "Requested min %duV max %duV != constrained min %duV max %duV\n", |
| 700 | min_uV, max_uV, |
| 701 | regu_constraints->min_uV, regu_constraints->max_uV); |
| 702 | |
| 703 | return -EINVAL; |
| 704 | } |
| 705 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 706 | static int ab8500_ext_list_voltage(struct regulator_dev *rdev, |
| 707 | unsigned selector) |
| 708 | { |
| 709 | struct regulation_constraints *regu_constraints = rdev->constraints; |
| 710 | |
| 711 | if (regu_constraints == NULL) { |
| 712 | dev_err(rdev_get_dev(rdev), "regulator constraints null pointer\n"); |
| 713 | return -EINVAL; |
| 714 | } |
| 715 | /* return the uV for the fixed regulators */ |
| 716 | if (regu_constraints->min_uV && regu_constraints->max_uV) { |
| 717 | if (regu_constraints->min_uV == regu_constraints->max_uV) |
| 718 | return regu_constraints->min_uV; |
| 719 | } |
| 720 | return -EINVAL; |
| 721 | } |
| 722 | |
| 723 | static struct regulator_ops ab8500_ext_regulator_ops = { |
| 724 | .enable = ab8500_ext_regulator_enable, |
| 725 | .disable = ab8500_ext_regulator_disable, |
| 726 | .is_enabled = ab8500_ext_regulator_is_enabled, |
| 727 | .set_mode = ab8500_ext_regulator_set_mode, |
| 728 | .get_mode = ab8500_ext_regulator_get_mode, |
Lee Jones | 33fb880 | 2013-06-07 17:11:25 +0100 | [diff] [blame] | 729 | .set_voltage = ab8500_ext_set_voltage, |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 730 | .list_voltage = ab8500_ext_list_voltage, |
| 731 | }; |
| 732 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 733 | static struct ab8500_ext_regulator_info |
| 734 | ab8500_ext_regulator_info[AB8500_NUM_EXT_REGULATORS] = { |
| 735 | [AB8500_EXT_SUPPLY1] = { |
| 736 | .desc = { |
| 737 | .name = "VEXTSUPPLY1", |
| 738 | .ops = &ab8500_ext_regulator_ops, |
| 739 | .type = REGULATOR_VOLTAGE, |
| 740 | .id = AB8500_EXT_SUPPLY1, |
| 741 | .owner = THIS_MODULE, |
| 742 | .n_voltages = 1, |
| 743 | }, |
| 744 | .update_bank = 0x04, |
| 745 | .update_reg = 0x08, |
| 746 | .update_mask = 0x03, |
| 747 | .update_val = 0x01, |
| 748 | .update_val_hp = 0x01, |
| 749 | .update_val_lp = 0x03, |
| 750 | .update_val_hw = 0x02, |
| 751 | }, |
| 752 | [AB8500_EXT_SUPPLY2] = { |
| 753 | .desc = { |
| 754 | .name = "VEXTSUPPLY2", |
| 755 | .ops = &ab8500_ext_regulator_ops, |
| 756 | .type = REGULATOR_VOLTAGE, |
| 757 | .id = AB8500_EXT_SUPPLY2, |
| 758 | .owner = THIS_MODULE, |
| 759 | .n_voltages = 1, |
| 760 | }, |
| 761 | .update_bank = 0x04, |
| 762 | .update_reg = 0x08, |
| 763 | .update_mask = 0x0c, |
| 764 | .update_val = 0x04, |
| 765 | .update_val_hp = 0x04, |
| 766 | .update_val_lp = 0x0c, |
| 767 | .update_val_hw = 0x08, |
| 768 | }, |
| 769 | [AB8500_EXT_SUPPLY3] = { |
| 770 | .desc = { |
| 771 | .name = "VEXTSUPPLY3", |
| 772 | .ops = &ab8500_ext_regulator_ops, |
| 773 | .type = REGULATOR_VOLTAGE, |
| 774 | .id = AB8500_EXT_SUPPLY3, |
| 775 | .owner = THIS_MODULE, |
| 776 | .n_voltages = 1, |
| 777 | }, |
| 778 | .update_bank = 0x04, |
| 779 | .update_reg = 0x08, |
| 780 | .update_mask = 0x30, |
| 781 | .update_val = 0x10, |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 782 | .update_val_hp = 0x10, |
| 783 | .update_val_lp = 0x30, |
| 784 | .update_val_hw = 0x20, |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 785 | }, |
| 786 | }; |
| 787 | |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 788 | static struct of_regulator_match ab8500_ext_regulator_match[] = { |
| 789 | { .name = "ab8500_ext1", .driver_data = (void *) AB8500_EXT_SUPPLY1, }, |
| 790 | { .name = "ab8500_ext2", .driver_data = (void *) AB8500_EXT_SUPPLY2, }, |
| 791 | { .name = "ab8500_ext3", .driver_data = (void *) AB8500_EXT_SUPPLY3, }, |
| 792 | }; |
| 793 | |
Sachin Kamat | 08d49f4 | 2013-06-26 10:13:37 +0530 | [diff] [blame] | 794 | static int ab8500_ext_regulator_probe(struct platform_device *pdev) |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 795 | { |
| 796 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
Arnd Bergmann | 79886be | 2016-03-18 16:21:36 +0100 | [diff] [blame] | 797 | struct ab8500_regulator_platform_data *pdata = &ab8500_regulator_plat_data; |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 798 | struct device_node *np = pdev->dev.of_node; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 799 | struct regulator_config config = { }; |
| 800 | int i, err; |
| 801 | |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 802 | if (np) { |
| 803 | err = of_regulator_match(&pdev->dev, np, |
| 804 | ab8500_ext_regulator_match, |
| 805 | ARRAY_SIZE(ab8500_ext_regulator_match)); |
| 806 | if (err < 0) { |
| 807 | dev_err(&pdev->dev, |
| 808 | "Error parsing regulator init data: %d\n", err); |
| 809 | return err; |
| 810 | } |
| 811 | } |
| 812 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 813 | if (!ab8500) { |
| 814 | dev_err(&pdev->dev, "null mfd parent\n"); |
| 815 | return -EINVAL; |
| 816 | } |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 817 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 818 | /* make sure the platform data has the correct size */ |
| 819 | if (pdata->num_ext_regulator != ARRAY_SIZE(ab8500_ext_regulator_info)) { |
| 820 | dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); |
| 821 | return -EINVAL; |
| 822 | } |
| 823 | |
| 824 | /* check for AB8500 2.x */ |
Bengt Jonsson | a632470 | 2013-03-28 16:11:13 +0000 | [diff] [blame] | 825 | if (is_ab8500_2p0_or_earlier(ab8500)) { |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 826 | struct ab8500_ext_regulator_info *info; |
| 827 | |
| 828 | /* VextSupply3LPn is inverted on AB8500 2.x */ |
| 829 | info = &ab8500_ext_regulator_info[AB8500_EXT_SUPPLY3]; |
| 830 | info->update_val = 0x30; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 831 | info->update_val_hp = 0x30; |
| 832 | info->update_val_lp = 0x10; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /* register all regulators */ |
| 836 | for (i = 0; i < ARRAY_SIZE(ab8500_ext_regulator_info); i++) { |
| 837 | struct ab8500_ext_regulator_info *info = NULL; |
| 838 | |
| 839 | /* assign per-regulator data */ |
| 840 | info = &ab8500_ext_regulator_info[i]; |
| 841 | info->dev = &pdev->dev; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 842 | info->cfg = (struct ab8500_ext_regulator_cfg *) |
| 843 | pdata->ext_regulator[i].driver_data; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 844 | |
| 845 | config.dev = &pdev->dev; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 846 | config.driver_data = info; |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 847 | config.of_node = ab8500_ext_regulator_match[i].of_node; |
| 848 | config.init_data = (np) ? |
| 849 | ab8500_ext_regulator_match[i].init_data : |
| 850 | &pdata->ext_regulator[i]; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 851 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 852 | /* register regulator with framework */ |
Jingoo Han | a4a6b9d | 2013-09-30 09:52:37 +0900 | [diff] [blame] | 853 | info->rdev = devm_regulator_register(&pdev->dev, &info->desc, |
| 854 | &config); |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 855 | if (IS_ERR(info->rdev)) { |
| 856 | err = PTR_ERR(info->rdev); |
| 857 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 858 | info->desc.name); |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 859 | return err; |
| 860 | } |
| 861 | |
| 862 | dev_dbg(rdev_get_dev(info->rdev), |
| 863 | "%s-probed\n", info->desc.name); |
| 864 | } |
| 865 | |
| 866 | return 0; |
| 867 | } |
| 868 | |
Lee Jones | 5a49b4a | 2013-06-07 17:11:26 +0100 | [diff] [blame] | 869 | static struct platform_driver ab8500_ext_regulator_driver = { |
| 870 | .probe = ab8500_ext_regulator_probe, |
Lee Jones | 5a49b4a | 2013-06-07 17:11:26 +0100 | [diff] [blame] | 871 | .driver = { |
| 872 | .name = "ab8500-ext-regulator", |
Lee Jones | 5a49b4a | 2013-06-07 17:11:26 +0100 | [diff] [blame] | 873 | }, |
| 874 | }; |
| 875 | |
| 876 | static int __init ab8500_ext_regulator_init(void) |
| 877 | { |
| 878 | int ret; |
| 879 | |
| 880 | ret = platform_driver_register(&ab8500_ext_regulator_driver); |
| 881 | if (ret) |
| 882 | pr_err("Failed to register ab8500 ext regulator: %d\n", ret); |
| 883 | |
| 884 | return ret; |
| 885 | } |
| 886 | subsys_initcall(ab8500_ext_regulator_init); |
| 887 | |
| 888 | static void __exit ab8500_ext_regulator_exit(void) |
| 889 | { |
| 890 | platform_driver_unregister(&ab8500_ext_regulator_driver); |
| 891 | } |
| 892 | module_exit(ab8500_ext_regulator_exit); |
| 893 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 894 | MODULE_LICENSE("GPL v2"); |
| 895 | MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>"); |
| 896 | MODULE_DESCRIPTION("AB8500 external regulator driver"); |
| 897 | MODULE_ALIAS("platform:ab8500-ext-regulator"); |