| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Broadcom BCM590xx regulator driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2014 Linaro Limited |
|---|
| 5 | 6 | * Author: Matt Porter <mporter@linaro.org> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 8 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 9 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 10 | | - * option) any later version. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #include <linux/err.h> |
|---|
| .. | .. |
|---|
| 103 | 99 | ((n > BCM590XX_REG_VSR) && (n < BCM590XX_REG_VBUS)) |
|---|
| 104 | 100 | #define BCM590XX_REG_IS_VBUS(n) (n == BCM590XX_REG_VBUS) |
|---|
| 105 | 101 | |
|---|
| 106 | | -struct bcm590xx_board { |
|---|
| 107 | | - struct regulator_init_data *bcm590xx_pmu_init_data[BCM590XX_NUM_REGS]; |
|---|
| 108 | | -}; |
|---|
| 109 | | - |
|---|
| 110 | 102 | /* LDO group A: supported voltages in microvolts */ |
|---|
| 111 | 103 | static const unsigned int ldo_a_table[] = { |
|---|
| 112 | 104 | 1200000, 1800000, 2500000, 2700000, 2800000, |
|---|
| .. | .. |
|---|
| 124 | 116 | }; |
|---|
| 125 | 117 | |
|---|
| 126 | 118 | /* DCDC group CSR: supported voltages in microvolts */ |
|---|
| 127 | | -static const struct regulator_linear_range dcdc_csr_ranges[] = { |
|---|
| 119 | +static const struct linear_range dcdc_csr_ranges[] = { |
|---|
| 128 | 120 | REGULATOR_LINEAR_RANGE(860000, 2, 50, 10000), |
|---|
| 129 | 121 | REGULATOR_LINEAR_RANGE(1360000, 51, 55, 20000), |
|---|
| 130 | 122 | REGULATOR_LINEAR_RANGE(900000, 56, 63, 0), |
|---|
| 131 | 123 | }; |
|---|
| 132 | 124 | |
|---|
| 133 | 125 | /* DCDC group IOSR1: supported voltages in microvolts */ |
|---|
| 134 | | -static const struct regulator_linear_range dcdc_iosr1_ranges[] = { |
|---|
| 126 | +static const struct linear_range dcdc_iosr1_ranges[] = { |
|---|
| 135 | 127 | REGULATOR_LINEAR_RANGE(860000, 2, 51, 10000), |
|---|
| 136 | 128 | REGULATOR_LINEAR_RANGE(1500000, 52, 52, 0), |
|---|
| 137 | 129 | REGULATOR_LINEAR_RANGE(1800000, 53, 53, 0), |
|---|
| .. | .. |
|---|
| 139 | 131 | }; |
|---|
| 140 | 132 | |
|---|
| 141 | 133 | /* DCDC group SDSR1: supported voltages in microvolts */ |
|---|
| 142 | | -static const struct regulator_linear_range dcdc_sdsr1_ranges[] = { |
|---|
| 134 | +static const struct linear_range dcdc_sdsr1_ranges[] = { |
|---|
| 143 | 135 | REGULATOR_LINEAR_RANGE(860000, 2, 50, 10000), |
|---|
| 144 | 136 | REGULATOR_LINEAR_RANGE(1340000, 51, 51, 0), |
|---|
| 145 | 137 | REGULATOR_LINEAR_RANGE(900000, 52, 63, 0), |
|---|
| .. | .. |
|---|
| 151 | 143 | u8 n_voltages; |
|---|
| 152 | 144 | const unsigned int *volt_table; |
|---|
| 153 | 145 | u8 n_linear_ranges; |
|---|
| 154 | | - const struct regulator_linear_range *linear_ranges; |
|---|
| 146 | + const struct linear_range *linear_ranges; |
|---|
| 155 | 147 | }; |
|---|
| 156 | 148 | |
|---|
| 157 | 149 | #define BCM590XX_REG_TABLE(_name, _table) \ |
|---|
| .. | .. |
|---|
| 242 | 234 | case BCM590XX_REG_SDSR2: |
|---|
| 243 | 235 | reg = BCM590XX_SDSR2PMCTRL1; |
|---|
| 244 | 236 | break; |
|---|
| 237 | + case BCM590XX_REG_VSR: |
|---|
| 238 | + reg = BCM590XX_VSRPMCTRL1; |
|---|
| 239 | + break; |
|---|
| 245 | 240 | case BCM590XX_REG_VBUS: |
|---|
| 246 | 241 | reg = BCM590XX_OTG_CTRL; |
|---|
| 242 | + break; |
|---|
| 247 | 243 | } |
|---|
| 248 | 244 | |
|---|
| 249 | 245 | |
|---|
| .. | .. |
|---|
| 276 | 272 | .disable = regulator_disable_regmap, |
|---|
| 277 | 273 | }; |
|---|
| 278 | 274 | |
|---|
| 279 | | -#define BCM590XX_MATCH(_name, _id) \ |
|---|
| 280 | | - { \ |
|---|
| 281 | | - .name = #_name, \ |
|---|
| 282 | | - .driver_data = (void *)&bcm590xx_regs[BCM590XX_REG_##_id], \ |
|---|
| 283 | | - } |
|---|
| 284 | | - |
|---|
| 285 | | -static struct of_regulator_match bcm590xx_matches[] = { |
|---|
| 286 | | - BCM590XX_MATCH(rfldo, RFLDO), |
|---|
| 287 | | - BCM590XX_MATCH(camldo1, CAMLDO1), |
|---|
| 288 | | - BCM590XX_MATCH(camldo2, CAMLDO2), |
|---|
| 289 | | - BCM590XX_MATCH(simldo1, SIMLDO1), |
|---|
| 290 | | - BCM590XX_MATCH(simldo2, SIMLDO2), |
|---|
| 291 | | - BCM590XX_MATCH(sdldo, SDLDO), |
|---|
| 292 | | - BCM590XX_MATCH(sdxldo, SDXLDO), |
|---|
| 293 | | - BCM590XX_MATCH(mmcldo1, MMCLDO1), |
|---|
| 294 | | - BCM590XX_MATCH(mmcldo2, MMCLDO2), |
|---|
| 295 | | - BCM590XX_MATCH(audldo, AUDLDO), |
|---|
| 296 | | - BCM590XX_MATCH(micldo, MICLDO), |
|---|
| 297 | | - BCM590XX_MATCH(usbldo, USBLDO), |
|---|
| 298 | | - BCM590XX_MATCH(vibldo, VIBLDO), |
|---|
| 299 | | - BCM590XX_MATCH(csr, CSR), |
|---|
| 300 | | - BCM590XX_MATCH(iosr1, IOSR1), |
|---|
| 301 | | - BCM590XX_MATCH(iosr2, IOSR2), |
|---|
| 302 | | - BCM590XX_MATCH(msr, MSR), |
|---|
| 303 | | - BCM590XX_MATCH(sdsr1, SDSR1), |
|---|
| 304 | | - BCM590XX_MATCH(sdsr2, SDSR2), |
|---|
| 305 | | - BCM590XX_MATCH(vsr, VSR), |
|---|
| 306 | | - BCM590XX_MATCH(gpldo1, GPLDO1), |
|---|
| 307 | | - BCM590XX_MATCH(gpldo2, GPLDO2), |
|---|
| 308 | | - BCM590XX_MATCH(gpldo3, GPLDO3), |
|---|
| 309 | | - BCM590XX_MATCH(gpldo4, GPLDO4), |
|---|
| 310 | | - BCM590XX_MATCH(gpldo5, GPLDO5), |
|---|
| 311 | | - BCM590XX_MATCH(gpldo6, GPLDO6), |
|---|
| 312 | | - BCM590XX_MATCH(vbus, VBUS), |
|---|
| 313 | | -}; |
|---|
| 314 | | - |
|---|
| 315 | | -static struct bcm590xx_board *bcm590xx_parse_dt_reg_data( |
|---|
| 316 | | - struct platform_device *pdev, |
|---|
| 317 | | - struct of_regulator_match **bcm590xx_reg_matches) |
|---|
| 318 | | -{ |
|---|
| 319 | | - struct bcm590xx_board *data; |
|---|
| 320 | | - struct device_node *np = pdev->dev.parent->of_node; |
|---|
| 321 | | - struct device_node *regulators; |
|---|
| 322 | | - struct of_regulator_match *matches = bcm590xx_matches; |
|---|
| 323 | | - int count = ARRAY_SIZE(bcm590xx_matches); |
|---|
| 324 | | - int idx = 0; |
|---|
| 325 | | - int ret; |
|---|
| 326 | | - |
|---|
| 327 | | - if (!np) { |
|---|
| 328 | | - dev_err(&pdev->dev, "of node not found\n"); |
|---|
| 329 | | - return NULL; |
|---|
| 330 | | - } |
|---|
| 331 | | - |
|---|
| 332 | | - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
|---|
| 333 | | - if (!data) |
|---|
| 334 | | - return NULL; |
|---|
| 335 | | - |
|---|
| 336 | | - np = of_node_get(np); |
|---|
| 337 | | - regulators = of_get_child_by_name(np, "regulators"); |
|---|
| 338 | | - if (!regulators) { |
|---|
| 339 | | - dev_warn(&pdev->dev, "regulator node not found\n"); |
|---|
| 340 | | - return NULL; |
|---|
| 341 | | - } |
|---|
| 342 | | - |
|---|
| 343 | | - ret = of_regulator_match(&pdev->dev, regulators, matches, count); |
|---|
| 344 | | - of_node_put(regulators); |
|---|
| 345 | | - if (ret < 0) { |
|---|
| 346 | | - dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", |
|---|
| 347 | | - ret); |
|---|
| 348 | | - return NULL; |
|---|
| 349 | | - } |
|---|
| 350 | | - |
|---|
| 351 | | - *bcm590xx_reg_matches = matches; |
|---|
| 352 | | - |
|---|
| 353 | | - for (idx = 0; idx < count; idx++) { |
|---|
| 354 | | - if (!matches[idx].init_data || !matches[idx].of_node) |
|---|
| 355 | | - continue; |
|---|
| 356 | | - |
|---|
| 357 | | - data->bcm590xx_pmu_init_data[idx] = matches[idx].init_data; |
|---|
| 358 | | - } |
|---|
| 359 | | - |
|---|
| 360 | | - return data; |
|---|
| 361 | | -} |
|---|
| 362 | | - |
|---|
| 363 | 275 | static int bcm590xx_probe(struct platform_device *pdev) |
|---|
| 364 | 276 | { |
|---|
| 365 | 277 | struct bcm590xx *bcm590xx = dev_get_drvdata(pdev->dev.parent); |
|---|
| 366 | | - struct bcm590xx_board *pmu_data = NULL; |
|---|
| 367 | 278 | struct bcm590xx_reg *pmu; |
|---|
| 368 | 279 | struct regulator_config config = { }; |
|---|
| 369 | 280 | struct bcm590xx_info *info; |
|---|
| 370 | | - struct regulator_init_data *reg_data; |
|---|
| 371 | 281 | struct regulator_dev *rdev; |
|---|
| 372 | | - struct of_regulator_match *bcm590xx_reg_matches = NULL; |
|---|
| 373 | 282 | int i; |
|---|
| 374 | | - |
|---|
| 375 | | - pmu_data = bcm590xx_parse_dt_reg_data(pdev, |
|---|
| 376 | | - &bcm590xx_reg_matches); |
|---|
| 377 | 283 | |
|---|
| 378 | 284 | pmu = devm_kzalloc(&pdev->dev, sizeof(*pmu), GFP_KERNEL); |
|---|
| 379 | 285 | if (!pmu) |
|---|
| .. | .. |
|---|
| 393 | 299 | info = bcm590xx_regs; |
|---|
| 394 | 300 | |
|---|
| 395 | 301 | for (i = 0; i < BCM590XX_NUM_REGS; i++, info++) { |
|---|
| 396 | | - if (pmu_data) |
|---|
| 397 | | - reg_data = pmu_data->bcm590xx_pmu_init_data[i]; |
|---|
| 398 | | - else |
|---|
| 399 | | - reg_data = NULL; |
|---|
| 400 | | - |
|---|
| 401 | 302 | /* Register the regulators */ |
|---|
| 402 | 303 | pmu->desc[i].name = info->name; |
|---|
| 304 | + pmu->desc[i].of_match = of_match_ptr(info->name); |
|---|
| 305 | + pmu->desc[i].regulators_node = of_match_ptr("regulators"); |
|---|
| 403 | 306 | pmu->desc[i].supply_name = info->vin_name; |
|---|
| 404 | 307 | pmu->desc[i].id = i; |
|---|
| 405 | 308 | pmu->desc[i].volt_table = info->volt_table; |
|---|
| .. | .. |
|---|
| 429 | 332 | pmu->desc[i].owner = THIS_MODULE; |
|---|
| 430 | 333 | |
|---|
| 431 | 334 | config.dev = bcm590xx->dev; |
|---|
| 432 | | - config.init_data = reg_data; |
|---|
| 433 | 335 | config.driver_data = pmu; |
|---|
| 434 | 336 | if (BCM590XX_REG_IS_GPLDO(i) || BCM590XX_REG_IS_VBUS(i)) |
|---|
| 435 | 337 | config.regmap = bcm590xx->regmap_sec; |
|---|
| 436 | 338 | else |
|---|
| 437 | 339 | config.regmap = bcm590xx->regmap_pri; |
|---|
| 438 | | - |
|---|
| 439 | | - if (bcm590xx_reg_matches) |
|---|
| 440 | | - config.of_node = bcm590xx_reg_matches[i].of_node; |
|---|
| 441 | 340 | |
|---|
| 442 | 341 | rdev = devm_regulator_register(&pdev->dev, &pmu->desc[i], |
|---|
| 443 | 342 | &config); |
|---|