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