| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) ST-Ericsson SA 2010 |
|---|
| 3 | 4 | * |
|---|
| 4 | | - * License Terms: GNU General Public License v2 |
|---|
| 5 | 5 | * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson |
|---|
| 6 | 6 | * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson |
|---|
| 7 | 7 | * |
|---|
| .. | .. |
|---|
| 75 | 75 | } |
|---|
| 76 | 76 | |
|---|
| 77 | 77 | /* db8500 regulator operations */ |
|---|
| 78 | | -static struct regulator_ops db8500_regulator_ops = { |
|---|
| 78 | +static const struct regulator_ops db8500_regulator_ops = { |
|---|
| 79 | 79 | .enable = db8500_regulator_enable, |
|---|
| 80 | 80 | .disable = db8500_regulator_disable, |
|---|
| 81 | 81 | .is_enabled = db8500_regulator_is_enabled, |
|---|
| .. | .. |
|---|
| 181 | 181 | goto out; |
|---|
| 182 | 182 | } |
|---|
| 183 | 183 | |
|---|
| 184 | | - info->is_enabled = 0; |
|---|
| 184 | + info->is_enabled = false; |
|---|
| 185 | 185 | out: |
|---|
| 186 | 186 | return ret; |
|---|
| 187 | 187 | } |
|---|
| .. | .. |
|---|
| 200 | 200 | return info->is_enabled; |
|---|
| 201 | 201 | } |
|---|
| 202 | 202 | |
|---|
| 203 | | -static struct regulator_ops db8500_regulator_switch_ops = { |
|---|
| 203 | +static const struct regulator_ops db8500_regulator_switch_ops = { |
|---|
| 204 | 204 | .enable = db8500_regulator_switch_enable, |
|---|
| 205 | 205 | .disable = db8500_regulator_switch_disable, |
|---|
| 206 | 206 | .is_enabled = db8500_regulator_switch_is_enabled, |
|---|
| .. | .. |
|---|
| 214 | 214 | [DB8500_REGULATOR_VAPE] = { |
|---|
| 215 | 215 | .desc = { |
|---|
| 216 | 216 | .name = "db8500-vape", |
|---|
| 217 | + .of_match = of_match_ptr("db8500_vape"), |
|---|
| 217 | 218 | .id = DB8500_REGULATOR_VAPE, |
|---|
| 218 | 219 | .ops = &db8500_regulator_ops, |
|---|
| 219 | 220 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 223 | 224 | [DB8500_REGULATOR_VARM] = { |
|---|
| 224 | 225 | .desc = { |
|---|
| 225 | 226 | .name = "db8500-varm", |
|---|
| 227 | + .of_match = of_match_ptr("db8500_varm"), |
|---|
| 226 | 228 | .id = DB8500_REGULATOR_VARM, |
|---|
| 227 | 229 | .ops = &db8500_regulator_ops, |
|---|
| 228 | 230 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 232 | 234 | [DB8500_REGULATOR_VMODEM] = { |
|---|
| 233 | 235 | .desc = { |
|---|
| 234 | 236 | .name = "db8500-vmodem", |
|---|
| 237 | + .of_match = of_match_ptr("db8500_vmodem"), |
|---|
| 235 | 238 | .id = DB8500_REGULATOR_VMODEM, |
|---|
| 236 | 239 | .ops = &db8500_regulator_ops, |
|---|
| 237 | 240 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 241 | 244 | [DB8500_REGULATOR_VPLL] = { |
|---|
| 242 | 245 | .desc = { |
|---|
| 243 | 246 | .name = "db8500-vpll", |
|---|
| 247 | + .of_match = of_match_ptr("db8500_vpll"), |
|---|
| 244 | 248 | .id = DB8500_REGULATOR_VPLL, |
|---|
| 245 | 249 | .ops = &db8500_regulator_ops, |
|---|
| 246 | 250 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 250 | 254 | [DB8500_REGULATOR_VSMPS1] = { |
|---|
| 251 | 255 | .desc = { |
|---|
| 252 | 256 | .name = "db8500-vsmps1", |
|---|
| 257 | + .of_match = of_match_ptr("db8500_vsmps1"), |
|---|
| 253 | 258 | .id = DB8500_REGULATOR_VSMPS1, |
|---|
| 254 | 259 | .ops = &db8500_regulator_ops, |
|---|
| 255 | 260 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 259 | 264 | [DB8500_REGULATOR_VSMPS2] = { |
|---|
| 260 | 265 | .desc = { |
|---|
| 261 | 266 | .name = "db8500-vsmps2", |
|---|
| 267 | + .of_match = of_match_ptr("db8500_vsmps2"), |
|---|
| 262 | 268 | .id = DB8500_REGULATOR_VSMPS2, |
|---|
| 263 | 269 | .ops = &db8500_regulator_ops, |
|---|
| 264 | 270 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 271 | 277 | [DB8500_REGULATOR_VSMPS3] = { |
|---|
| 272 | 278 | .desc = { |
|---|
| 273 | 279 | .name = "db8500-vsmps3", |
|---|
| 280 | + .of_match = of_match_ptr("db8500_vsmps3"), |
|---|
| 274 | 281 | .id = DB8500_REGULATOR_VSMPS3, |
|---|
| 275 | 282 | .ops = &db8500_regulator_ops, |
|---|
| 276 | 283 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 280 | 287 | [DB8500_REGULATOR_VRF1] = { |
|---|
| 281 | 288 | .desc = { |
|---|
| 282 | 289 | .name = "db8500-vrf1", |
|---|
| 290 | + .of_match = of_match_ptr("db8500_vrf1"), |
|---|
| 283 | 291 | .id = DB8500_REGULATOR_VRF1, |
|---|
| 284 | 292 | .ops = &db8500_regulator_ops, |
|---|
| 285 | 293 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 289 | 297 | [DB8500_REGULATOR_SWITCH_SVAMMDSP] = { |
|---|
| 290 | 298 | .desc = { |
|---|
| 291 | 299 | .name = "db8500-sva-mmdsp", |
|---|
| 300 | + .of_match = of_match_ptr("db8500_sva_mmdsp"), |
|---|
| 292 | 301 | .id = DB8500_REGULATOR_SWITCH_SVAMMDSP, |
|---|
| 293 | 302 | .ops = &db8500_regulator_switch_ops, |
|---|
| 294 | 303 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 299 | 308 | [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = { |
|---|
| 300 | 309 | .desc = { |
|---|
| 301 | 310 | .name = "db8500-sva-mmdsp-ret", |
|---|
| 311 | + .of_match = of_match_ptr("db8500_sva_mmdsp_ret"), |
|---|
| 302 | 312 | .id = DB8500_REGULATOR_SWITCH_SVAMMDSPRET, |
|---|
| 303 | 313 | .ops = &db8500_regulator_switch_ops, |
|---|
| 304 | 314 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 310 | 320 | [DB8500_REGULATOR_SWITCH_SVAPIPE] = { |
|---|
| 311 | 321 | .desc = { |
|---|
| 312 | 322 | .name = "db8500-sva-pipe", |
|---|
| 323 | + .of_match = of_match_ptr("db8500_sva_pipe"), |
|---|
| 313 | 324 | .id = DB8500_REGULATOR_SWITCH_SVAPIPE, |
|---|
| 314 | 325 | .ops = &db8500_regulator_switch_ops, |
|---|
| 315 | 326 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 320 | 331 | [DB8500_REGULATOR_SWITCH_SIAMMDSP] = { |
|---|
| 321 | 332 | .desc = { |
|---|
| 322 | 333 | .name = "db8500-sia-mmdsp", |
|---|
| 334 | + .of_match = of_match_ptr("db8500_sia_mmdsp"), |
|---|
| 323 | 335 | .id = DB8500_REGULATOR_SWITCH_SIAMMDSP, |
|---|
| 324 | 336 | .ops = &db8500_regulator_switch_ops, |
|---|
| 325 | 337 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 330 | 342 | [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = { |
|---|
| 331 | 343 | .desc = { |
|---|
| 332 | 344 | .name = "db8500-sia-mmdsp-ret", |
|---|
| 345 | + .of_match = of_match_ptr("db8500_sia_mmdsp_ret"), |
|---|
| 333 | 346 | .id = DB8500_REGULATOR_SWITCH_SIAMMDSPRET, |
|---|
| 334 | 347 | .ops = &db8500_regulator_switch_ops, |
|---|
| 335 | 348 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 341 | 354 | [DB8500_REGULATOR_SWITCH_SIAPIPE] = { |
|---|
| 342 | 355 | .desc = { |
|---|
| 343 | 356 | .name = "db8500-sia-pipe", |
|---|
| 357 | + .of_match = of_match_ptr("db8500_sia_pipe"), |
|---|
| 344 | 358 | .id = DB8500_REGULATOR_SWITCH_SIAPIPE, |
|---|
| 345 | 359 | .ops = &db8500_regulator_switch_ops, |
|---|
| 346 | 360 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 351 | 365 | [DB8500_REGULATOR_SWITCH_SGA] = { |
|---|
| 352 | 366 | .desc = { |
|---|
| 353 | 367 | .name = "db8500-sga", |
|---|
| 368 | + .of_match = of_match_ptr("db8500_sga"), |
|---|
| 354 | 369 | .id = DB8500_REGULATOR_SWITCH_SGA, |
|---|
| 355 | 370 | .ops = &db8500_regulator_switch_ops, |
|---|
| 356 | 371 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 361 | 376 | [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = { |
|---|
| 362 | 377 | .desc = { |
|---|
| 363 | 378 | .name = "db8500-b2r2-mcde", |
|---|
| 379 | + .of_match = of_match_ptr("db8500_b2r2_mcde"), |
|---|
| 364 | 380 | .id = DB8500_REGULATOR_SWITCH_B2R2_MCDE, |
|---|
| 365 | 381 | .ops = &db8500_regulator_switch_ops, |
|---|
| 366 | 382 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 371 | 387 | [DB8500_REGULATOR_SWITCH_ESRAM12] = { |
|---|
| 372 | 388 | .desc = { |
|---|
| 373 | 389 | .name = "db8500-esram12", |
|---|
| 390 | + .of_match = of_match_ptr("db8500_esram12"), |
|---|
| 374 | 391 | .id = DB8500_REGULATOR_SWITCH_ESRAM12, |
|---|
| 375 | 392 | .ops = &db8500_regulator_switch_ops, |
|---|
| 376 | 393 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 382 | 399 | [DB8500_REGULATOR_SWITCH_ESRAM12RET] = { |
|---|
| 383 | 400 | .desc = { |
|---|
| 384 | 401 | .name = "db8500-esram12-ret", |
|---|
| 402 | + .of_match = of_match_ptr("db8500_esram12_ret"), |
|---|
| 385 | 403 | .id = DB8500_REGULATOR_SWITCH_ESRAM12RET, |
|---|
| 386 | 404 | .ops = &db8500_regulator_switch_ops, |
|---|
| 387 | 405 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 393 | 411 | [DB8500_REGULATOR_SWITCH_ESRAM34] = { |
|---|
| 394 | 412 | .desc = { |
|---|
| 395 | 413 | .name = "db8500-esram34", |
|---|
| 414 | + .of_match = of_match_ptr("db8500_esram34"), |
|---|
| 396 | 415 | .id = DB8500_REGULATOR_SWITCH_ESRAM34, |
|---|
| 397 | 416 | .ops = &db8500_regulator_switch_ops, |
|---|
| 398 | 417 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 404 | 423 | [DB8500_REGULATOR_SWITCH_ESRAM34RET] = { |
|---|
| 405 | 424 | .desc = { |
|---|
| 406 | 425 | .name = "db8500-esram34-ret", |
|---|
| 426 | + .of_match = of_match_ptr("db8500_esram34_ret"), |
|---|
| 407 | 427 | .id = DB8500_REGULATOR_SWITCH_ESRAM34RET, |
|---|
| 408 | 428 | .ops = &db8500_regulator_switch_ops, |
|---|
| 409 | 429 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 414 | 434 | }, |
|---|
| 415 | 435 | }; |
|---|
| 416 | 436 | |
|---|
| 417 | | -static int db8500_regulator_register(struct platform_device *pdev, |
|---|
| 418 | | - struct regulator_init_data *init_data, |
|---|
| 419 | | - int id, |
|---|
| 420 | | - struct device_node *np) |
|---|
| 421 | | -{ |
|---|
| 422 | | - struct dbx500_regulator_info *info; |
|---|
| 423 | | - struct regulator_config config = { }; |
|---|
| 424 | | - int err; |
|---|
| 425 | | - |
|---|
| 426 | | - /* assign per-regulator data */ |
|---|
| 427 | | - info = &dbx500_regulator_info[id]; |
|---|
| 428 | | - info->dev = &pdev->dev; |
|---|
| 429 | | - |
|---|
| 430 | | - config.dev = &pdev->dev; |
|---|
| 431 | | - config.init_data = init_data; |
|---|
| 432 | | - config.driver_data = info; |
|---|
| 433 | | - config.of_node = np; |
|---|
| 434 | | - |
|---|
| 435 | | - /* register with the regulator framework */ |
|---|
| 436 | | - info->rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); |
|---|
| 437 | | - if (IS_ERR(info->rdev)) { |
|---|
| 438 | | - err = PTR_ERR(info->rdev); |
|---|
| 439 | | - dev_err(&pdev->dev, "failed to register %s: err %i\n", |
|---|
| 440 | | - info->desc.name, err); |
|---|
| 441 | | - return err; |
|---|
| 442 | | - } |
|---|
| 443 | | - |
|---|
| 444 | | - dev_dbg(rdev_get_dev(info->rdev), |
|---|
| 445 | | - "regulator-%s-probed\n", info->desc.name); |
|---|
| 446 | | - |
|---|
| 447 | | - return 0; |
|---|
| 448 | | -} |
|---|
| 449 | | - |
|---|
| 450 | | -static struct of_regulator_match db8500_regulator_matches[] = { |
|---|
| 451 | | - { .name = "db8500_vape", .driver_data = (void *) DB8500_REGULATOR_VAPE, }, |
|---|
| 452 | | - { .name = "db8500_varm", .driver_data = (void *) DB8500_REGULATOR_VARM, }, |
|---|
| 453 | | - { .name = "db8500_vmodem", .driver_data = (void *) DB8500_REGULATOR_VMODEM, }, |
|---|
| 454 | | - { .name = "db8500_vpll", .driver_data = (void *) DB8500_REGULATOR_VPLL, }, |
|---|
| 455 | | - { .name = "db8500_vsmps1", .driver_data = (void *) DB8500_REGULATOR_VSMPS1, }, |
|---|
| 456 | | - { .name = "db8500_vsmps2", .driver_data = (void *) DB8500_REGULATOR_VSMPS2, }, |
|---|
| 457 | | - { .name = "db8500_vsmps3", .driver_data = (void *) DB8500_REGULATOR_VSMPS3, }, |
|---|
| 458 | | - { .name = "db8500_vrf1", .driver_data = (void *) DB8500_REGULATOR_VRF1, }, |
|---|
| 459 | | - { .name = "db8500_sva_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSP, }, |
|---|
| 460 | | - { .name = "db8500_sva_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSPRET, }, |
|---|
| 461 | | - { .name = "db8500_sva_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAPIPE, }, |
|---|
| 462 | | - { .name = "db8500_sia_mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSP, }, |
|---|
| 463 | | - { .name = "db8500_sia_mmdsp_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSPRET, }, |
|---|
| 464 | | - { .name = "db8500_sia_pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAPIPE, }, |
|---|
| 465 | | - { .name = "db8500_sga", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SGA, }, |
|---|
| 466 | | - { .name = "db8500_b2r2_mcde", .driver_data = (void *) DB8500_REGULATOR_SWITCH_B2R2_MCDE, }, |
|---|
| 467 | | - { .name = "db8500_esram12", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12, }, |
|---|
| 468 | | - { .name = "db8500_esram12_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12RET, }, |
|---|
| 469 | | - { .name = "db8500_esram34", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34, }, |
|---|
| 470 | | - { .name = "db8500_esram34_ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34RET, }, |
|---|
| 471 | | -}; |
|---|
| 472 | | - |
|---|
| 473 | | -static int |
|---|
| 474 | | -db8500_regulator_of_probe(struct platform_device *pdev, |
|---|
| 475 | | - struct device_node *np) |
|---|
| 476 | | -{ |
|---|
| 477 | | - int i, err; |
|---|
| 478 | | - |
|---|
| 479 | | - for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { |
|---|
| 480 | | - err = db8500_regulator_register( |
|---|
| 481 | | - pdev, db8500_regulator_matches[i].init_data, |
|---|
| 482 | | - i, db8500_regulator_matches[i].of_node); |
|---|
| 483 | | - if (err) |
|---|
| 484 | | - return err; |
|---|
| 485 | | - } |
|---|
| 486 | | - |
|---|
| 487 | | - return 0; |
|---|
| 488 | | -} |
|---|
| 489 | | - |
|---|
| 490 | 437 | static int db8500_regulator_probe(struct platform_device *pdev) |
|---|
| 491 | 438 | { |
|---|
| 492 | | - struct regulator_init_data *db8500_init_data = |
|---|
| 493 | | - dev_get_platdata(&pdev->dev); |
|---|
| 494 | | - struct device_node *np = pdev->dev.of_node; |
|---|
| 495 | | - int i, err; |
|---|
| 439 | + struct regulator_init_data *db8500_init_data; |
|---|
| 440 | + struct dbx500_regulator_info *info; |
|---|
| 441 | + struct regulator_config config = { }; |
|---|
| 442 | + struct regulator_dev *rdev; |
|---|
| 443 | + int err, i; |
|---|
| 496 | 444 | |
|---|
| 497 | | - /* register all regulators */ |
|---|
| 498 | | - if (np) { |
|---|
| 499 | | - err = of_regulator_match(&pdev->dev, np, |
|---|
| 500 | | - db8500_regulator_matches, |
|---|
| 501 | | - ARRAY_SIZE(db8500_regulator_matches)); |
|---|
| 502 | | - if (err < 0) { |
|---|
| 503 | | - dev_err(&pdev->dev, |
|---|
| 504 | | - "Error parsing regulator init data: %d\n", err); |
|---|
| 445 | + db8500_init_data = dev_get_platdata(&pdev->dev); |
|---|
| 446 | + |
|---|
| 447 | + for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { |
|---|
| 448 | + /* assign per-regulator data */ |
|---|
| 449 | + info = &dbx500_regulator_info[i]; |
|---|
| 450 | + |
|---|
| 451 | + config.driver_data = info; |
|---|
| 452 | + config.dev = &pdev->dev; |
|---|
| 453 | + if (db8500_init_data) |
|---|
| 454 | + config.init_data = &db8500_init_data[i]; |
|---|
| 455 | + |
|---|
| 456 | + rdev = devm_regulator_register(&pdev->dev, &info->desc, |
|---|
| 457 | + &config); |
|---|
| 458 | + if (IS_ERR(rdev)) { |
|---|
| 459 | + err = PTR_ERR(rdev); |
|---|
| 460 | + dev_err(&pdev->dev, "failed to register %s: err %i\n", |
|---|
| 461 | + info->desc.name, err); |
|---|
| 505 | 462 | return err; |
|---|
| 506 | 463 | } |
|---|
| 507 | | - |
|---|
| 508 | | - err = db8500_regulator_of_probe(pdev, np); |
|---|
| 509 | | - if (err) |
|---|
| 510 | | - return err; |
|---|
| 511 | | - } else { |
|---|
| 512 | | - for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { |
|---|
| 513 | | - err = db8500_regulator_register(pdev, |
|---|
| 514 | | - &db8500_init_data[i], |
|---|
| 515 | | - i, NULL); |
|---|
| 516 | | - if (err) |
|---|
| 517 | | - return err; |
|---|
| 518 | | - } |
|---|
| 464 | + dev_dbg(&pdev->dev, "regulator-%s-probed\n", info->desc.name); |
|---|
| 519 | 465 | } |
|---|
| 520 | 466 | |
|---|
| 521 | | - err = ux500_regulator_debug_init(pdev, |
|---|
| 522 | | - dbx500_regulator_info, |
|---|
| 523 | | - ARRAY_SIZE(dbx500_regulator_info)); |
|---|
| 467 | + ux500_regulator_debug_init(pdev, dbx500_regulator_info, |
|---|
| 468 | + ARRAY_SIZE(dbx500_regulator_info)); |
|---|
| 524 | 469 | return 0; |
|---|
| 525 | 470 | } |
|---|
| 526 | 471 | |
|---|