1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (C) 2018 ROHM Semiconductors 3 // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver 4 5 #include <linux/delay.h> 6 #include <linux/err.h> 7 #include <linux/gpio.h> 8 #include <linux/interrupt.h> 9 #include <linux/kernel.h> 10 #include <linux/mfd/rohm-bd718x7.h> 11 #include <linux/module.h> 12 #include <linux/of.h> 13 #include <linux/platform_device.h> 14 #include <linux/regulator/driver.h> 15 #include <linux/regulator/machine.h> 16 #include <linux/regulator/of_regulator.h> 17 #include <linux/slab.h> 18 19 /* 20 * BUCK1/2/3/4 21 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting 22 * 00: 10.00mV/usec 10mV 1uS 23 * 01: 5.00mV/usec 10mV 2uS 24 * 10: 2.50mV/usec 10mV 4uS 25 * 11: 1.25mV/usec 10mV 8uS 26 */ 27 static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev, 28 int ramp_delay) 29 { 30 int id = rdev->desc->id; 31 unsigned int ramp_value = BUCK_RAMPRATE_10P00MV; 32 33 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1, 34 ramp_delay); 35 switch (ramp_delay) { 36 case 1 ... 1250: 37 ramp_value = BUCK_RAMPRATE_1P25MV; 38 break; 39 case 1251 ... 2500: 40 ramp_value = BUCK_RAMPRATE_2P50MV; 41 break; 42 case 2501 ... 5000: 43 ramp_value = BUCK_RAMPRATE_5P00MV; 44 break; 45 case 5001 ... 10000: 46 ramp_value = BUCK_RAMPRATE_10P00MV; 47 break; 48 default: 49 ramp_value = BUCK_RAMPRATE_10P00MV; 50 dev_err(&rdev->dev, 51 "%s: ramp_delay: %d not supported, setting 10000mV//us\n", 52 rdev->desc->name, ramp_delay); 53 } 54 55 return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id, 56 BUCK_RAMPRATE_MASK, ramp_value << 6); 57 } 58 59 /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed. 60 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage 61 * is changed. Hence we return -EBUSY for these if voltage is changed 62 * when BUCK/LDO is enabled. 63 */ 64 static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev, 65 unsigned int sel) 66 { 67 if (regulator_is_enabled_regmap(rdev)) 68 return -EBUSY; 69 70 return regulator_set_voltage_sel_regmap(rdev, sel); 71 } 72 73 static int bd718xx_set_voltage_sel_pickable_restricted( 74 struct regulator_dev *rdev, unsigned int sel) 75 { 76 if (regulator_is_enabled_regmap(rdev)) 77 return -EBUSY; 78 79 return regulator_set_voltage_sel_pickable_regmap(rdev, sel); 80 } 81 82 static struct regulator_ops bd718xx_pickable_range_ldo_ops = { 83 .enable = regulator_enable_regmap, 84 .disable = regulator_disable_regmap, 85 .is_enabled = regulator_is_enabled_regmap, 86 .list_voltage = regulator_list_voltage_pickable_linear_range, 87 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted, 88 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, 89 }; 90 91 static struct regulator_ops bd718xx_pickable_range_buck_ops = { 92 .enable = regulator_enable_regmap, 93 .disable = regulator_disable_regmap, 94 .is_enabled = regulator_is_enabled_regmap, 95 .list_voltage = regulator_list_voltage_pickable_linear_range, 96 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted, 97 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, 98 .set_voltage_time_sel = regulator_set_voltage_time_sel, 99 }; 100 101 static struct regulator_ops bd718xx_ldo_regulator_ops = { 102 .enable = regulator_enable_regmap, 103 .disable = regulator_disable_regmap, 104 .is_enabled = regulator_is_enabled_regmap, 105 .list_voltage = regulator_list_voltage_linear_range, 106 .set_voltage_sel = bd718xx_set_voltage_sel_restricted, 107 .get_voltage_sel = regulator_get_voltage_sel_regmap, 108 }; 109 110 static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = { 111 .enable = regulator_enable_regmap, 112 .disable = regulator_disable_regmap, 113 .is_enabled = regulator_is_enabled_regmap, 114 .list_voltage = regulator_list_voltage_table, 115 .set_voltage_sel = bd718xx_set_voltage_sel_restricted, 116 .get_voltage_sel = regulator_get_voltage_sel_regmap, 117 }; 118 119 static struct regulator_ops bd718xx_buck_regulator_ops = { 120 .enable = regulator_enable_regmap, 121 .disable = regulator_disable_regmap, 122 .is_enabled = regulator_is_enabled_regmap, 123 .list_voltage = regulator_list_voltage_linear_range, 124 .set_voltage_sel = bd718xx_set_voltage_sel_restricted, 125 .get_voltage_sel = regulator_get_voltage_sel_regmap, 126 .set_voltage_time_sel = regulator_set_voltage_time_sel, 127 }; 128 129 static struct regulator_ops bd718xx_buck_regulator_nolinear_ops = { 130 .enable = regulator_enable_regmap, 131 .disable = regulator_disable_regmap, 132 .is_enabled = regulator_is_enabled_regmap, 133 .list_voltage = regulator_list_voltage_table, 134 .map_voltage = regulator_map_voltage_ascend, 135 .set_voltage_sel = bd718xx_set_voltage_sel_restricted, 136 .get_voltage_sel = regulator_get_voltage_sel_regmap, 137 .set_voltage_time_sel = regulator_set_voltage_time_sel, 138 }; 139 140 static struct regulator_ops bd718xx_dvs_buck_regulator_ops = { 141 .enable = regulator_enable_regmap, 142 .disable = regulator_disable_regmap, 143 .is_enabled = regulator_is_enabled_regmap, 144 .list_voltage = regulator_list_voltage_linear_range, 145 .set_voltage_sel = regulator_set_voltage_sel_regmap, 146 .get_voltage_sel = regulator_get_voltage_sel_regmap, 147 .set_voltage_time_sel = regulator_set_voltage_time_sel, 148 .set_ramp_delay = bd718xx_buck1234_set_ramp_delay, 149 }; 150 151 /* 152 * BD71837 BUCK1/2/3/4 153 * BD71847 BUCK1/2 154 * 0.70 to 1.30V (10mV step) 155 */ 156 static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = { 157 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000), 158 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0), 159 }; 160 161 /* 162 * BD71837 BUCK5 163 * 0.7V to 1.35V (range 0) 164 * and 165 * 0.675 to 1.325 (range 1) 166 */ 167 static const struct regulator_linear_range bd71837_buck5_volts[] = { 168 /* Ranges when VOLT_SEL bit is 0 */ 169 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), 170 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), 171 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), 172 /* Ranges when VOLT_SEL bit is 1 */ 173 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), 174 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), 175 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), 176 }; 177 178 /* 179 * Range selector for first 3 linear ranges is 0x0 180 * and 0x1 for last 3 ranges. 181 */ 182 static const unsigned int bd71837_buck5_volt_range_sel[] = { 183 0x0, 0x0, 0x0, 0x80, 0x80, 0x80 184 }; 185 186 /* 187 * BD71847 BUCK3 188 */ 189 static const struct regulator_linear_range bd71847_buck3_volts[] = { 190 /* Ranges when VOLT_SEL bits are 00 */ 191 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), 192 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), 193 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), 194 /* Ranges when VOLT_SEL bits are 01 */ 195 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000), 196 /* Ranges when VOLT_SEL bits are 11 */ 197 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), 198 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), 199 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), 200 }; 201 202 static const unsigned int bd71847_buck3_volt_range_sel[] = { 203 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80 204 }; 205 206 static const struct regulator_linear_range bd71847_buck4_volts[] = { 207 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), 208 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000), 209 }; 210 211 static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 }; 212 213 /* 214 * BUCK6 215 * 3.0V to 3.3V (step 100mV) 216 */ 217 static const struct regulator_linear_range bd71837_buck6_volts[] = { 218 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), 219 }; 220 221 /* 222 * BD71837 BUCK7 223 * BD71847 BUCK5 224 * 000 = 1.605V 225 * 001 = 1.695V 226 * 010 = 1.755V 227 * 011 = 1.8V (Initial) 228 * 100 = 1.845V 229 * 101 = 1.905V 230 * 110 = 1.95V 231 * 111 = 1.995V 232 */ 233 static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = { 234 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000 235 }; 236 237 /* 238 * BUCK8 239 * 0.8V to 1.40V (step 10mV) 240 */ 241 static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = { 242 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000), 243 }; 244 245 /* 246 * LDO1 247 * 3.0 to 3.3V (100mV step) 248 */ 249 static const struct regulator_linear_range bd718xx_ldo1_volts[] = { 250 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), 251 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000), 252 }; 253 254 static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 }; 255 256 /* 257 * LDO2 258 * 0.8 or 0.9V 259 */ 260 static const unsigned int ldo_2_volts[] = { 261 900000, 800000 262 }; 263 264 /* 265 * LDO3 266 * 1.8 to 3.3V (100mV step) 267 */ 268 static const struct regulator_linear_range bd718xx_ldo3_volts[] = { 269 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), 270 }; 271 272 /* 273 * LDO4 274 * 0.9 to 1.8V (100mV step) 275 */ 276 static const struct regulator_linear_range bd718xx_ldo4_volts[] = { 277 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), 278 }; 279 280 /* 281 * LDO5 for BD71837 282 * 1.8 to 3.3V (100mV step) 283 */ 284 static const struct regulator_linear_range bd71837_ldo5_volts[] = { 285 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), 286 }; 287 288 /* 289 * LDO5 for BD71837 290 * 1.8 to 3.3V (100mV step) 291 */ 292 static const struct regulator_linear_range bd71847_ldo5_volts[] = { 293 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), 294 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000), 295 }; 296 297 static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 }; 298 299 /* 300 * LDO6 301 * 0.9 to 1.8V (100mV step) 302 */ 303 static const struct regulator_linear_range bd718xx_ldo6_volts[] = { 304 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), 305 }; 306 307 /* 308 * LDO7 309 * 1.8 to 3.3V (100mV step) 310 */ 311 static const struct regulator_linear_range bd71837_ldo7_volts[] = { 312 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), 313 }; 314 315 struct reg_init { 316 unsigned int reg; 317 unsigned int mask; 318 unsigned int val; 319 }; 320 struct bd718xx_regulator_data { 321 struct regulator_desc desc; 322 const struct reg_init init; 323 const struct reg_init *additional_inits; 324 int additional_init_amnt; 325 }; 326 327 /* 328 * There is a HW quirk in BD71837. The shutdown sequence timings for 329 * bucks/LDOs which are controlled via register interface are changed. 330 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the 331 * beginning of shut-down sequence. As bucks 6 and 7 are parent 332 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage 333 * monitoring to errorneously detect under voltage and force PMIC to 334 * emergency state instead of poweroff. In order to avoid this we 335 * disable voltage monitoring for LDO5 and LDO6 336 */ 337 static const struct reg_init bd71837_ldo5_inits[] = { 338 { 339 .reg = BD718XX_REG_MVRFLTMASK2, 340 .mask = BD718XX_LDO5_VRMON80, 341 .val = BD718XX_LDO5_VRMON80, 342 }, 343 }; 344 345 static const struct reg_init bd71837_ldo6_inits[] = { 346 { 347 .reg = BD718XX_REG_MVRFLTMASK2, 348 .mask = BD718XX_LDO6_VRMON80, 349 .val = BD718XX_LDO6_VRMON80, 350 }, 351 }; 352 353 static const struct bd718xx_regulator_data bd71847_regulators[] = { 354 { 355 .desc = { 356 .name = "buck1", 357 .of_match = of_match_ptr("BUCK1"), 358 .regulators_node = of_match_ptr("regulators"), 359 .id = BD718XX_BUCK1, 360 .ops = &bd718xx_dvs_buck_regulator_ops, 361 .type = REGULATOR_VOLTAGE, 362 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, 363 .linear_ranges = bd718xx_dvs_buck_volts, 364 .n_linear_ranges = 365 ARRAY_SIZE(bd718xx_dvs_buck_volts), 366 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, 367 .vsel_mask = DVS_BUCK_RUN_MASK, 368 .enable_reg = BD718XX_REG_BUCK1_CTRL, 369 .enable_mask = BD718XX_BUCK_EN, 370 .owner = THIS_MODULE, 371 }, 372 .init = { 373 .reg = BD718XX_REG_BUCK1_CTRL, 374 .mask = BD718XX_BUCK_SEL, 375 .val = BD718XX_BUCK_SEL, 376 }, 377 }, 378 { 379 .desc = { 380 .name = "buck2", 381 .of_match = of_match_ptr("BUCK2"), 382 .regulators_node = of_match_ptr("regulators"), 383 .id = BD718XX_BUCK2, 384 .ops = &bd718xx_dvs_buck_regulator_ops, 385 .type = REGULATOR_VOLTAGE, 386 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, 387 .linear_ranges = bd718xx_dvs_buck_volts, 388 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), 389 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, 390 .vsel_mask = DVS_BUCK_RUN_MASK, 391 .enable_reg = BD718XX_REG_BUCK2_CTRL, 392 .enable_mask = BD718XX_BUCK_EN, 393 .owner = THIS_MODULE, 394 }, 395 .init = { 396 .reg = BD718XX_REG_BUCK2_CTRL, 397 .mask = BD718XX_BUCK_SEL, 398 .val = BD718XX_BUCK_SEL, 399 }, 400 }, 401 { 402 .desc = { 403 .name = "buck3", 404 .of_match = of_match_ptr("BUCK3"), 405 .regulators_node = of_match_ptr("regulators"), 406 .id = BD718XX_BUCK3, 407 .ops = &bd718xx_pickable_range_buck_ops, 408 .type = REGULATOR_VOLTAGE, 409 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM, 410 .linear_ranges = bd71847_buck3_volts, 411 .n_linear_ranges = 412 ARRAY_SIZE(bd71847_buck3_volts), 413 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, 414 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK, 415 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, 416 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK, 417 .linear_range_selectors = bd71847_buck3_volt_range_sel, 418 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, 419 .enable_mask = BD718XX_BUCK_EN, 420 .owner = THIS_MODULE, 421 }, 422 .init = { 423 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, 424 .mask = BD718XX_BUCK_SEL, 425 .val = BD718XX_BUCK_SEL, 426 }, 427 }, 428 { 429 .desc = { 430 .name = "buck4", 431 .of_match = of_match_ptr("BUCK4"), 432 .regulators_node = of_match_ptr("regulators"), 433 .id = BD718XX_BUCK4, 434 .ops = &bd718xx_pickable_range_buck_ops, 435 .type = REGULATOR_VOLTAGE, 436 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM, 437 .linear_ranges = bd71847_buck4_volts, 438 .n_linear_ranges = 439 ARRAY_SIZE(bd71847_buck4_volts), 440 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, 441 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, 442 .vsel_mask = BD71847_BUCK4_MASK, 443 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, 444 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK, 445 .linear_range_selectors = bd71847_buck4_volt_range_sel, 446 .enable_mask = BD718XX_BUCK_EN, 447 .owner = THIS_MODULE, 448 }, 449 .init = { 450 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, 451 .mask = BD718XX_BUCK_SEL, 452 .val = BD718XX_BUCK_SEL, 453 }, 454 }, 455 { 456 .desc = { 457 .name = "buck5", 458 .of_match = of_match_ptr("BUCK5"), 459 .regulators_node = of_match_ptr("regulators"), 460 .id = BD718XX_BUCK5, 461 .ops = &bd718xx_buck_regulator_nolinear_ops, 462 .type = REGULATOR_VOLTAGE, 463 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], 464 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), 465 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, 466 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, 467 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, 468 .enable_mask = BD718XX_BUCK_EN, 469 .owner = THIS_MODULE, 470 }, 471 .init = { 472 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, 473 .mask = BD718XX_BUCK_SEL, 474 .val = BD718XX_BUCK_SEL, 475 }, 476 }, 477 { 478 .desc = { 479 .name = "buck6", 480 .of_match = of_match_ptr("BUCK6"), 481 .regulators_node = of_match_ptr("regulators"), 482 .id = BD718XX_BUCK6, 483 .ops = &bd718xx_buck_regulator_ops, 484 .type = REGULATOR_VOLTAGE, 485 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, 486 .linear_ranges = bd718xx_4th_nodvs_buck_volts, 487 .n_linear_ranges = 488 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), 489 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, 490 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, 491 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, 492 .enable_mask = BD718XX_BUCK_EN, 493 .owner = THIS_MODULE, 494 }, 495 .init = { 496 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, 497 .mask = BD718XX_BUCK_SEL, 498 .val = BD718XX_BUCK_SEL, 499 }, 500 }, 501 { 502 .desc = { 503 .name = "ldo1", 504 .of_match = of_match_ptr("LDO1"), 505 .regulators_node = of_match_ptr("regulators"), 506 .id = BD718XX_LDO1, 507 .ops = &bd718xx_pickable_range_ldo_ops, 508 .type = REGULATOR_VOLTAGE, 509 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, 510 .linear_ranges = bd718xx_ldo1_volts, 511 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), 512 .vsel_reg = BD718XX_REG_LDO1_VOLT, 513 .vsel_mask = BD718XX_LDO1_MASK, 514 .vsel_range_reg = BD718XX_REG_LDO1_VOLT, 515 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, 516 .linear_range_selectors = bd718xx_ldo1_volt_range_sel, 517 .enable_reg = BD718XX_REG_LDO1_VOLT, 518 .enable_mask = BD718XX_LDO_EN, 519 .owner = THIS_MODULE, 520 }, 521 .init = { 522 .reg = BD718XX_REG_LDO1_VOLT, 523 .mask = BD718XX_LDO_SEL, 524 .val = BD718XX_LDO_SEL, 525 }, 526 }, 527 { 528 .desc = { 529 .name = "ldo2", 530 .of_match = of_match_ptr("LDO2"), 531 .regulators_node = of_match_ptr("regulators"), 532 .id = BD718XX_LDO2, 533 .ops = &bd718xx_ldo_regulator_nolinear_ops, 534 .type = REGULATOR_VOLTAGE, 535 .volt_table = &ldo_2_volts[0], 536 .vsel_reg = BD718XX_REG_LDO2_VOLT, 537 .vsel_mask = BD718XX_LDO2_MASK, 538 .n_voltages = ARRAY_SIZE(ldo_2_volts), 539 .enable_reg = BD718XX_REG_LDO2_VOLT, 540 .enable_mask = BD718XX_LDO_EN, 541 .owner = THIS_MODULE, 542 }, 543 .init = { 544 .reg = BD718XX_REG_LDO2_VOLT, 545 .mask = BD718XX_LDO_SEL, 546 .val = BD718XX_LDO_SEL, 547 }, 548 }, 549 { 550 .desc = { 551 .name = "ldo3", 552 .of_match = of_match_ptr("LDO3"), 553 .regulators_node = of_match_ptr("regulators"), 554 .id = BD718XX_LDO3, 555 .ops = &bd718xx_ldo_regulator_ops, 556 .type = REGULATOR_VOLTAGE, 557 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, 558 .linear_ranges = bd718xx_ldo3_volts, 559 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), 560 .vsel_reg = BD718XX_REG_LDO3_VOLT, 561 .vsel_mask = BD718XX_LDO3_MASK, 562 .enable_reg = BD718XX_REG_LDO3_VOLT, 563 .enable_mask = BD718XX_LDO_EN, 564 .owner = THIS_MODULE, 565 }, 566 .init = { 567 .reg = BD718XX_REG_LDO3_VOLT, 568 .mask = BD718XX_LDO_SEL, 569 .val = BD718XX_LDO_SEL, 570 }, 571 }, 572 { 573 .desc = { 574 .name = "ldo4", 575 .of_match = of_match_ptr("LDO4"), 576 .regulators_node = of_match_ptr("regulators"), 577 .id = BD718XX_LDO4, 578 .ops = &bd718xx_ldo_regulator_ops, 579 .type = REGULATOR_VOLTAGE, 580 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, 581 .linear_ranges = bd718xx_ldo4_volts, 582 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), 583 .vsel_reg = BD718XX_REG_LDO4_VOLT, 584 .vsel_mask = BD718XX_LDO4_MASK, 585 .enable_reg = BD718XX_REG_LDO4_VOLT, 586 .enable_mask = BD718XX_LDO_EN, 587 .owner = THIS_MODULE, 588 }, 589 .init = { 590 .reg = BD718XX_REG_LDO4_VOLT, 591 .mask = BD718XX_LDO_SEL, 592 .val = BD718XX_LDO_SEL, 593 }, 594 }, 595 { 596 .desc = { 597 .name = "ldo5", 598 .of_match = of_match_ptr("LDO5"), 599 .regulators_node = of_match_ptr("regulators"), 600 .id = BD718XX_LDO5, 601 .ops = &bd718xx_pickable_range_ldo_ops, 602 .type = REGULATOR_VOLTAGE, 603 .n_voltages = BD71847_LDO5_VOLTAGE_NUM, 604 .linear_ranges = bd71847_ldo5_volts, 605 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts), 606 .vsel_reg = BD718XX_REG_LDO5_VOLT, 607 .vsel_mask = BD71847_LDO5_MASK, 608 .vsel_range_reg = BD718XX_REG_LDO5_VOLT, 609 .vsel_range_mask = BD71847_LDO5_RANGE_MASK, 610 .linear_range_selectors = bd71847_ldo5_volt_range_sel, 611 .enable_reg = BD718XX_REG_LDO5_VOLT, 612 .enable_mask = BD718XX_LDO_EN, 613 .owner = THIS_MODULE, 614 }, 615 .init = { 616 .reg = BD718XX_REG_LDO5_VOLT, 617 .mask = BD718XX_LDO_SEL, 618 .val = BD718XX_LDO_SEL, 619 }, 620 }, 621 { 622 .desc = { 623 .name = "ldo6", 624 .of_match = of_match_ptr("LDO6"), 625 .regulators_node = of_match_ptr("regulators"), 626 .id = BD718XX_LDO6, 627 .ops = &bd718xx_ldo_regulator_ops, 628 .type = REGULATOR_VOLTAGE, 629 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, 630 .linear_ranges = bd718xx_ldo6_volts, 631 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), 632 /* LDO6 is supplied by buck5 */ 633 .supply_name = "buck5", 634 .vsel_reg = BD718XX_REG_LDO6_VOLT, 635 .vsel_mask = BD718XX_LDO6_MASK, 636 .enable_reg = BD718XX_REG_LDO6_VOLT, 637 .enable_mask = BD718XX_LDO_EN, 638 .owner = THIS_MODULE, 639 }, 640 .init = { 641 .reg = BD718XX_REG_LDO6_VOLT, 642 .mask = BD718XX_LDO_SEL, 643 .val = BD718XX_LDO_SEL, 644 }, 645 }, 646 }; 647 648 static const struct bd718xx_regulator_data bd71837_regulators[] = { 649 { 650 .desc = { 651 .name = "buck1", 652 .of_match = of_match_ptr("BUCK1"), 653 .regulators_node = of_match_ptr("regulators"), 654 .id = BD718XX_BUCK1, 655 .ops = &bd718xx_dvs_buck_regulator_ops, 656 .type = REGULATOR_VOLTAGE, 657 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, 658 .linear_ranges = bd718xx_dvs_buck_volts, 659 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), 660 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, 661 .vsel_mask = DVS_BUCK_RUN_MASK, 662 .enable_reg = BD718XX_REG_BUCK1_CTRL, 663 .enable_mask = BD718XX_BUCK_EN, 664 .owner = THIS_MODULE, 665 }, 666 .init = { 667 .reg = BD718XX_REG_BUCK1_CTRL, 668 .mask = BD718XX_BUCK_SEL, 669 .val = BD718XX_BUCK_SEL, 670 }, 671 }, 672 { 673 .desc = { 674 .name = "buck2", 675 .of_match = of_match_ptr("BUCK2"), 676 .regulators_node = of_match_ptr("regulators"), 677 .id = BD718XX_BUCK2, 678 .ops = &bd718xx_dvs_buck_regulator_ops, 679 .type = REGULATOR_VOLTAGE, 680 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, 681 .linear_ranges = bd718xx_dvs_buck_volts, 682 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), 683 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, 684 .vsel_mask = DVS_BUCK_RUN_MASK, 685 .enable_reg = BD718XX_REG_BUCK2_CTRL, 686 .enable_mask = BD718XX_BUCK_EN, 687 .owner = THIS_MODULE, 688 }, 689 .init = { 690 .reg = BD718XX_REG_BUCK2_CTRL, 691 .mask = BD718XX_BUCK_SEL, 692 .val = BD718XX_BUCK_SEL, 693 }, 694 }, 695 { 696 .desc = { 697 .name = "buck3", 698 .of_match = of_match_ptr("BUCK3"), 699 .regulators_node = of_match_ptr("regulators"), 700 .id = BD718XX_BUCK3, 701 .ops = &bd718xx_dvs_buck_regulator_ops, 702 .type = REGULATOR_VOLTAGE, 703 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, 704 .linear_ranges = bd718xx_dvs_buck_volts, 705 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), 706 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN, 707 .vsel_mask = DVS_BUCK_RUN_MASK, 708 .enable_reg = BD71837_REG_BUCK3_CTRL, 709 .enable_mask = BD718XX_BUCK_EN, 710 .owner = THIS_MODULE, 711 }, 712 .init = { 713 .reg = BD71837_REG_BUCK3_CTRL, 714 .mask = BD718XX_BUCK_SEL, 715 .val = BD718XX_BUCK_SEL, 716 }, 717 }, 718 { 719 .desc = { 720 .name = "buck4", 721 .of_match = of_match_ptr("BUCK4"), 722 .regulators_node = of_match_ptr("regulators"), 723 .id = BD718XX_BUCK4, 724 .ops = &bd718xx_dvs_buck_regulator_ops, 725 .type = REGULATOR_VOLTAGE, 726 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, 727 .linear_ranges = bd718xx_dvs_buck_volts, 728 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), 729 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN, 730 .vsel_mask = DVS_BUCK_RUN_MASK, 731 .enable_reg = BD71837_REG_BUCK4_CTRL, 732 .enable_mask = BD718XX_BUCK_EN, 733 .owner = THIS_MODULE, 734 }, 735 .init = { 736 .reg = BD71837_REG_BUCK4_CTRL, 737 .mask = BD718XX_BUCK_SEL, 738 .val = BD718XX_BUCK_SEL, 739 }, 740 }, 741 { 742 .desc = { 743 .name = "buck5", 744 .of_match = of_match_ptr("BUCK5"), 745 .regulators_node = of_match_ptr("regulators"), 746 .id = BD718XX_BUCK5, 747 .ops = &bd718xx_pickable_range_buck_ops, 748 .type = REGULATOR_VOLTAGE, 749 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM, 750 .linear_ranges = bd71837_buck5_volts, 751 .n_linear_ranges = 752 ARRAY_SIZE(bd71837_buck5_volts), 753 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, 754 .vsel_mask = BD71837_BUCK5_MASK, 755 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, 756 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK, 757 .linear_range_selectors = bd71837_buck5_volt_range_sel, 758 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, 759 .enable_mask = BD718XX_BUCK_EN, 760 .owner = THIS_MODULE, 761 }, 762 .init = { 763 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, 764 .mask = BD718XX_BUCK_SEL, 765 .val = BD718XX_BUCK_SEL, 766 }, 767 }, 768 { 769 .desc = { 770 .name = "buck6", 771 .of_match = of_match_ptr("BUCK6"), 772 .regulators_node = of_match_ptr("regulators"), 773 .id = BD718XX_BUCK6, 774 .ops = &bd718xx_buck_regulator_ops, 775 .type = REGULATOR_VOLTAGE, 776 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM, 777 .linear_ranges = bd71837_buck6_volts, 778 .n_linear_ranges = 779 ARRAY_SIZE(bd71837_buck6_volts), 780 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, 781 .vsel_mask = BD71837_BUCK6_MASK, 782 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, 783 .enable_mask = BD718XX_BUCK_EN, 784 .owner = THIS_MODULE, 785 }, 786 .init = { 787 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, 788 .mask = BD718XX_BUCK_SEL, 789 .val = BD718XX_BUCK_SEL, 790 }, 791 }, 792 { 793 .desc = { 794 .name = "buck7", 795 .of_match = of_match_ptr("BUCK7"), 796 .regulators_node = of_match_ptr("regulators"), 797 .id = BD718XX_BUCK7, 798 .ops = &bd718xx_buck_regulator_nolinear_ops, 799 .type = REGULATOR_VOLTAGE, 800 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], 801 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), 802 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, 803 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, 804 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, 805 .enable_mask = BD718XX_BUCK_EN, 806 .owner = THIS_MODULE, 807 }, 808 .init = { 809 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, 810 .mask = BD718XX_BUCK_SEL, 811 .val = BD718XX_BUCK_SEL, 812 }, 813 }, 814 { 815 .desc = { 816 .name = "buck8", 817 .of_match = of_match_ptr("BUCK8"), 818 .regulators_node = of_match_ptr("regulators"), 819 .id = BD718XX_BUCK8, 820 .ops = &bd718xx_buck_regulator_ops, 821 .type = REGULATOR_VOLTAGE, 822 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, 823 .linear_ranges = bd718xx_4th_nodvs_buck_volts, 824 .n_linear_ranges = 825 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), 826 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, 827 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, 828 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, 829 .enable_mask = BD718XX_BUCK_EN, 830 .owner = THIS_MODULE, 831 }, 832 .init = { 833 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, 834 .mask = BD718XX_BUCK_SEL, 835 .val = BD718XX_BUCK_SEL, 836 }, 837 }, 838 { 839 .desc = { 840 .name = "ldo1", 841 .of_match = of_match_ptr("LDO1"), 842 .regulators_node = of_match_ptr("regulators"), 843 .id = BD718XX_LDO1, 844 .ops = &bd718xx_pickable_range_ldo_ops, 845 .type = REGULATOR_VOLTAGE, 846 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, 847 .linear_ranges = bd718xx_ldo1_volts, 848 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), 849 .vsel_reg = BD718XX_REG_LDO1_VOLT, 850 .vsel_mask = BD718XX_LDO1_MASK, 851 .vsel_range_reg = BD718XX_REG_LDO1_VOLT, 852 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, 853 .linear_range_selectors = bd718xx_ldo1_volt_range_sel, 854 .enable_reg = BD718XX_REG_LDO1_VOLT, 855 .enable_mask = BD718XX_LDO_EN, 856 .owner = THIS_MODULE, 857 }, 858 .init = { 859 .reg = BD718XX_REG_LDO1_VOLT, 860 .mask = BD718XX_LDO_SEL, 861 .val = BD718XX_LDO_SEL, 862 }, 863 }, 864 { 865 .desc = { 866 .name = "ldo2", 867 .of_match = of_match_ptr("LDO2"), 868 .regulators_node = of_match_ptr("regulators"), 869 .id = BD718XX_LDO2, 870 .ops = &bd718xx_ldo_regulator_nolinear_ops, 871 .type = REGULATOR_VOLTAGE, 872 .volt_table = &ldo_2_volts[0], 873 .vsel_reg = BD718XX_REG_LDO2_VOLT, 874 .vsel_mask = BD718XX_LDO2_MASK, 875 .n_voltages = ARRAY_SIZE(ldo_2_volts), 876 .enable_reg = BD718XX_REG_LDO2_VOLT, 877 .enable_mask = BD718XX_LDO_EN, 878 .owner = THIS_MODULE, 879 }, 880 .init = { 881 .reg = BD718XX_REG_LDO2_VOLT, 882 .mask = BD718XX_LDO_SEL, 883 .val = BD718XX_LDO_SEL, 884 }, 885 }, 886 { 887 .desc = { 888 .name = "ldo3", 889 .of_match = of_match_ptr("LDO3"), 890 .regulators_node = of_match_ptr("regulators"), 891 .id = BD718XX_LDO3, 892 .ops = &bd718xx_ldo_regulator_ops, 893 .type = REGULATOR_VOLTAGE, 894 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, 895 .linear_ranges = bd718xx_ldo3_volts, 896 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), 897 .vsel_reg = BD718XX_REG_LDO3_VOLT, 898 .vsel_mask = BD718XX_LDO3_MASK, 899 .enable_reg = BD718XX_REG_LDO3_VOLT, 900 .enable_mask = BD718XX_LDO_EN, 901 .owner = THIS_MODULE, 902 }, 903 .init = { 904 .reg = BD718XX_REG_LDO3_VOLT, 905 .mask = BD718XX_LDO_SEL, 906 .val = BD718XX_LDO_SEL, 907 }, 908 }, 909 { 910 .desc = { 911 .name = "ldo4", 912 .of_match = of_match_ptr("LDO4"), 913 .regulators_node = of_match_ptr("regulators"), 914 .id = BD718XX_LDO4, 915 .ops = &bd718xx_ldo_regulator_ops, 916 .type = REGULATOR_VOLTAGE, 917 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, 918 .linear_ranges = bd718xx_ldo4_volts, 919 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), 920 .vsel_reg = BD718XX_REG_LDO4_VOLT, 921 .vsel_mask = BD718XX_LDO4_MASK, 922 .enable_reg = BD718XX_REG_LDO4_VOLT, 923 .enable_mask = BD718XX_LDO_EN, 924 .owner = THIS_MODULE, 925 }, 926 .init = { 927 .reg = BD718XX_REG_LDO4_VOLT, 928 .mask = BD718XX_LDO_SEL, 929 .val = BD718XX_LDO_SEL, 930 }, 931 }, 932 { 933 .desc = { 934 .name = "ldo5", 935 .of_match = of_match_ptr("LDO5"), 936 .regulators_node = of_match_ptr("regulators"), 937 .id = BD718XX_LDO5, 938 .ops = &bd718xx_ldo_regulator_ops, 939 .type = REGULATOR_VOLTAGE, 940 .n_voltages = BD71837_LDO5_VOLTAGE_NUM, 941 .linear_ranges = bd71837_ldo5_volts, 942 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts), 943 /* LDO5 is supplied by buck6 */ 944 .supply_name = "buck6", 945 .vsel_reg = BD718XX_REG_LDO5_VOLT, 946 .vsel_mask = BD71837_LDO5_MASK, 947 .enable_reg = BD718XX_REG_LDO5_VOLT, 948 .enable_mask = BD718XX_LDO_EN, 949 .owner = THIS_MODULE, 950 }, 951 .init = { 952 .reg = BD718XX_REG_LDO5_VOLT, 953 .mask = BD718XX_LDO_SEL, 954 .val = BD718XX_LDO_SEL, 955 }, 956 .additional_inits = bd71837_ldo5_inits, 957 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits), 958 }, 959 { 960 .desc = { 961 .name = "ldo6", 962 .of_match = of_match_ptr("LDO6"), 963 .regulators_node = of_match_ptr("regulators"), 964 .id = BD718XX_LDO6, 965 .ops = &bd718xx_ldo_regulator_ops, 966 .type = REGULATOR_VOLTAGE, 967 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, 968 .linear_ranges = bd718xx_ldo6_volts, 969 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), 970 /* LDO6 is supplied by buck7 */ 971 .supply_name = "buck7", 972 .vsel_reg = BD718XX_REG_LDO6_VOLT, 973 .vsel_mask = BD718XX_LDO6_MASK, 974 .enable_reg = BD718XX_REG_LDO6_VOLT, 975 .enable_mask = BD718XX_LDO_EN, 976 .owner = THIS_MODULE, 977 }, 978 .init = { 979 .reg = BD718XX_REG_LDO6_VOLT, 980 .mask = BD718XX_LDO_SEL, 981 .val = BD718XX_LDO_SEL, 982 }, 983 .additional_inits = bd71837_ldo6_inits, 984 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits), 985 }, 986 { 987 .desc = { 988 .name = "ldo7", 989 .of_match = of_match_ptr("LDO7"), 990 .regulators_node = of_match_ptr("regulators"), 991 .id = BD718XX_LDO7, 992 .ops = &bd718xx_ldo_regulator_ops, 993 .type = REGULATOR_VOLTAGE, 994 .n_voltages = BD71837_LDO7_VOLTAGE_NUM, 995 .linear_ranges = bd71837_ldo7_volts, 996 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts), 997 .vsel_reg = BD71837_REG_LDO7_VOLT, 998 .vsel_mask = BD71837_LDO7_MASK, 999 .enable_reg = BD71837_REG_LDO7_VOLT, 1000 .enable_mask = BD718XX_LDO_EN, 1001 .owner = THIS_MODULE, 1002 }, 1003 .init = { 1004 .reg = BD71837_REG_LDO7_VOLT, 1005 .mask = BD718XX_LDO_SEL, 1006 .val = BD718XX_LDO_SEL, 1007 }, 1008 }, 1009 }; 1010 1011 struct bd718xx_pmic_inits { 1012 const struct bd718xx_regulator_data *r_datas; 1013 unsigned int r_amount; 1014 }; 1015 1016 static int bd718xx_probe(struct platform_device *pdev) 1017 { 1018 struct bd718xx *mfd; 1019 struct regulator_config config = { 0 }; 1020 struct bd718xx_pmic_inits pmic_regulators[] = { 1021 [BD718XX_TYPE_BD71837] = { 1022 .r_datas = bd71837_regulators, 1023 .r_amount = ARRAY_SIZE(bd71837_regulators), 1024 }, 1025 [BD718XX_TYPE_BD71847] = { 1026 .r_datas = bd71847_regulators, 1027 .r_amount = ARRAY_SIZE(bd71847_regulators), 1028 }, 1029 }; 1030 1031 int i, j, err; 1032 1033 mfd = dev_get_drvdata(pdev->dev.parent); 1034 if (!mfd) { 1035 dev_err(&pdev->dev, "No MFD driver data\n"); 1036 err = -EINVAL; 1037 goto err; 1038 } 1039 1040 if (mfd->chip_type >= BD718XX_TYPE_AMOUNT || 1041 !pmic_regulators[mfd->chip_type].r_datas) { 1042 dev_err(&pdev->dev, "Unsupported chip type\n"); 1043 err = -EINVAL; 1044 goto err; 1045 } 1046 1047 /* Register LOCK release */ 1048 err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK, 1049 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); 1050 if (err) { 1051 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); 1052 goto err; 1053 } else { 1054 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", 1055 BD718XX_REG_REGLOCK); 1056 } 1057 1058 /* At poweroff transition PMIC HW disables EN bit for regulators but 1059 * leaves SEL bit untouched. So if state transition from POWEROFF 1060 * is done to SNVS - then all power rails controlled by SW (having 1061 * SEL bit set) stay disabled as EN is cleared. This may result boot 1062 * failure if any crucial systems are powered by these rails. 1063 * 1064 * Change the next stage from poweroff to be READY instead of SNVS 1065 * for all reset types because OTP loading at READY will clear SEL 1066 * bit allowing HW defaults for power rails to be used 1067 */ 1068 err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1, 1069 BD718XX_ON_REQ_POWEROFF_MASK | 1070 BD718XX_SWRESET_POWEROFF_MASK | 1071 BD718XX_WDOG_POWEROFF_MASK | 1072 BD718XX_KEY_L_POWEROFF_MASK, 1073 BD718XX_POWOFF_TO_RDY); 1074 if (err) { 1075 dev_err(&pdev->dev, "Failed to change reset target\n"); 1076 goto err; 1077 } else { 1078 dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n"); 1079 } 1080 1081 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) { 1082 1083 const struct regulator_desc *desc; 1084 struct regulator_dev *rdev; 1085 const struct bd718xx_regulator_data *r; 1086 1087 r = &pmic_regulators[mfd->chip_type].r_datas[i]; 1088 desc = &r->desc; 1089 1090 config.dev = pdev->dev.parent; 1091 config.regmap = mfd->regmap; 1092 1093 rdev = devm_regulator_register(&pdev->dev, desc, &config); 1094 if (IS_ERR(rdev)) { 1095 dev_err(&pdev->dev, 1096 "failed to register %s regulator\n", 1097 desc->name); 1098 err = PTR_ERR(rdev); 1099 goto err; 1100 } 1101 /* Regulator register gets the regulator constraints and 1102 * applies them (set_machine_constraints). This should have 1103 * turned the control register(s) to correct values and we 1104 * can now switch the control from PMIC state machine to the 1105 * register interface 1106 */ 1107 err = regmap_update_bits(mfd->regmap, r->init.reg, 1108 r->init.mask, r->init.val); 1109 if (err) { 1110 dev_err(&pdev->dev, 1111 "Failed to write BUCK/LDO SEL bit for (%s)\n", 1112 desc->name); 1113 goto err; 1114 } 1115 for (j = 0; j < r->additional_init_amnt; j++) { 1116 err = regmap_update_bits(mfd->regmap, 1117 r->additional_inits[j].reg, 1118 r->additional_inits[j].mask, 1119 r->additional_inits[j].val); 1120 if (err) { 1121 dev_err(&pdev->dev, 1122 "Buck (%s) initialization failed\n", 1123 desc->name); 1124 goto err; 1125 } 1126 } 1127 } 1128 1129 err: 1130 return err; 1131 } 1132 1133 static struct platform_driver bd718xx_regulator = { 1134 .driver = { 1135 .name = "bd718xx-pmic", 1136 }, 1137 .probe = bd718xx_probe, 1138 }; 1139 1140 module_platform_driver(bd718xx_regulator); 1141 1142 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); 1143 MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver"); 1144 MODULE_LICENSE("GPL"); 1145