.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright 2012 Texas Instruments |
---|
3 | 4 | * |
---|
4 | 5 | * Author: Milo(Woogyom) Kim <milo.kim@ti.com> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License version 2 as |
---|
8 | | - * published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | 6 | */ |
---|
11 | 7 | |
---|
12 | 8 | #include <linux/module.h> |
---|
.. | .. |
---|
353 | 349 | return val & LP872X_VOUT_M; |
---|
354 | 350 | } |
---|
355 | 351 | |
---|
356 | | -static int lp8725_buck_set_current_limit(struct regulator_dev *rdev, |
---|
357 | | - int min_uA, int max_uA) |
---|
358 | | -{ |
---|
359 | | - struct lp872x *lp = rdev_get_drvdata(rdev); |
---|
360 | | - enum lp872x_regulator_id buck = rdev_get_id(rdev); |
---|
361 | | - int i; |
---|
362 | | - u8 addr; |
---|
363 | | - |
---|
364 | | - switch (buck) { |
---|
365 | | - case LP8725_ID_BUCK1: |
---|
366 | | - addr = LP8725_BUCK1_VOUT2; |
---|
367 | | - break; |
---|
368 | | - case LP8725_ID_BUCK2: |
---|
369 | | - addr = LP8725_BUCK2_VOUT2; |
---|
370 | | - break; |
---|
371 | | - default: |
---|
372 | | - return -EINVAL; |
---|
373 | | - } |
---|
374 | | - |
---|
375 | | - for (i = ARRAY_SIZE(lp8725_buck_uA) - 1; i >= 0; i--) { |
---|
376 | | - if (lp8725_buck_uA[i] >= min_uA && |
---|
377 | | - lp8725_buck_uA[i] <= max_uA) |
---|
378 | | - return lp872x_update_bits(lp, addr, |
---|
379 | | - LP8725_BUCK_CL_M, |
---|
380 | | - i << LP8725_BUCK_CL_S); |
---|
381 | | - } |
---|
382 | | - |
---|
383 | | - return -EINVAL; |
---|
384 | | -} |
---|
385 | | - |
---|
386 | | -static int lp8725_buck_get_current_limit(struct regulator_dev *rdev) |
---|
387 | | -{ |
---|
388 | | - struct lp872x *lp = rdev_get_drvdata(rdev); |
---|
389 | | - enum lp872x_regulator_id buck = rdev_get_id(rdev); |
---|
390 | | - u8 addr, val; |
---|
391 | | - int ret; |
---|
392 | | - |
---|
393 | | - switch (buck) { |
---|
394 | | - case LP8725_ID_BUCK1: |
---|
395 | | - addr = LP8725_BUCK1_VOUT2; |
---|
396 | | - break; |
---|
397 | | - case LP8725_ID_BUCK2: |
---|
398 | | - addr = LP8725_BUCK2_VOUT2; |
---|
399 | | - break; |
---|
400 | | - default: |
---|
401 | | - return -EINVAL; |
---|
402 | | - } |
---|
403 | | - |
---|
404 | | - ret = lp872x_read_byte(lp, addr, &val); |
---|
405 | | - if (ret) |
---|
406 | | - return ret; |
---|
407 | | - |
---|
408 | | - val = (val & LP8725_BUCK_CL_M) >> LP8725_BUCK_CL_S; |
---|
409 | | - |
---|
410 | | - return (val < ARRAY_SIZE(lp8725_buck_uA)) ? |
---|
411 | | - lp8725_buck_uA[val] : -EINVAL; |
---|
412 | | -} |
---|
413 | | - |
---|
414 | 352 | static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) |
---|
415 | 353 | { |
---|
416 | 354 | struct lp872x *lp = rdev_get_drvdata(rdev); |
---|
.. | .. |
---|
478 | 416 | return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; |
---|
479 | 417 | } |
---|
480 | 418 | |
---|
481 | | -static struct regulator_ops lp872x_ldo_ops = { |
---|
| 419 | +static const struct regulator_ops lp872x_ldo_ops = { |
---|
482 | 420 | .list_voltage = regulator_list_voltage_table, |
---|
483 | 421 | .map_voltage = regulator_map_voltage_ascend, |
---|
484 | 422 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
---|
.. | .. |
---|
489 | 427 | .enable_time = lp872x_regulator_enable_time, |
---|
490 | 428 | }; |
---|
491 | 429 | |
---|
492 | | -static struct regulator_ops lp8720_buck_ops = { |
---|
| 430 | +static const struct regulator_ops lp8720_buck_ops = { |
---|
493 | 431 | .list_voltage = regulator_list_voltage_table, |
---|
494 | 432 | .map_voltage = regulator_map_voltage_ascend, |
---|
495 | 433 | .set_voltage_sel = lp872x_buck_set_voltage_sel, |
---|
.. | .. |
---|
502 | 440 | .get_mode = lp872x_buck_get_mode, |
---|
503 | 441 | }; |
---|
504 | 442 | |
---|
505 | | -static struct regulator_ops lp8725_buck_ops = { |
---|
| 443 | +static const struct regulator_ops lp8725_buck_ops = { |
---|
506 | 444 | .list_voltage = regulator_list_voltage_table, |
---|
507 | 445 | .map_voltage = regulator_map_voltage_ascend, |
---|
508 | 446 | .set_voltage_sel = lp872x_buck_set_voltage_sel, |
---|
.. | .. |
---|
513 | 451 | .enable_time = lp872x_regulator_enable_time, |
---|
514 | 452 | .set_mode = lp872x_buck_set_mode, |
---|
515 | 453 | .get_mode = lp872x_buck_get_mode, |
---|
516 | | - .set_current_limit = lp8725_buck_set_current_limit, |
---|
517 | | - .get_current_limit = lp8725_buck_get_current_limit, |
---|
| 454 | + .set_current_limit = regulator_set_current_limit_regmap, |
---|
| 455 | + .get_current_limit = regulator_get_current_limit_regmap, |
---|
518 | 456 | }; |
---|
519 | 457 | |
---|
520 | | -static struct regulator_desc lp8720_regulator_desc[] = { |
---|
| 458 | +static const struct regulator_desc lp8720_regulator_desc[] = { |
---|
521 | 459 | { |
---|
522 | 460 | .name = "ldo1", |
---|
523 | 461 | .of_match = of_match_ptr("ldo1"), |
---|
.. | .. |
---|
602 | 540 | }, |
---|
603 | 541 | }; |
---|
604 | 542 | |
---|
605 | | -static struct regulator_desc lp8725_regulator_desc[] = { |
---|
| 543 | +static const struct regulator_desc lp8725_regulator_desc[] = { |
---|
606 | 544 | { |
---|
607 | 545 | .name = "ldo1", |
---|
608 | 546 | .of_match = of_match_ptr("ldo1"), |
---|
.. | .. |
---|
712 | 650 | .owner = THIS_MODULE, |
---|
713 | 651 | .enable_reg = LP872X_GENERAL_CFG, |
---|
714 | 652 | .enable_mask = LP8725_BUCK1_EN_M, |
---|
| 653 | + .curr_table = lp8725_buck_uA, |
---|
| 654 | + .n_current_limits = ARRAY_SIZE(lp8725_buck_uA), |
---|
| 655 | + .csel_reg = LP8725_BUCK1_VOUT2, |
---|
| 656 | + .csel_mask = LP8725_BUCK_CL_M, |
---|
715 | 657 | }, |
---|
716 | 658 | { |
---|
717 | 659 | .name = "buck2", |
---|
.. | .. |
---|
724 | 666 | .owner = THIS_MODULE, |
---|
725 | 667 | .enable_reg = LP872X_GENERAL_CFG, |
---|
726 | 668 | .enable_mask = LP8725_BUCK2_EN_M, |
---|
| 669 | + .curr_table = lp8725_buck_uA, |
---|
| 670 | + .n_current_limits = ARRAY_SIZE(lp8725_buck_uA), |
---|
| 671 | + .csel_reg = LP8725_BUCK2_VOUT2, |
---|
| 672 | + .csel_mask = LP8725_BUCK_CL_M, |
---|
727 | 673 | }, |
---|
728 | 674 | }; |
---|
729 | 675 | |
---|
.. | .. |
---|
820 | 766 | |
---|
821 | 767 | static int lp872x_regulator_register(struct lp872x *lp) |
---|
822 | 768 | { |
---|
823 | | - struct regulator_desc *desc; |
---|
| 769 | + const struct regulator_desc *desc; |
---|
824 | 770 | struct regulator_config cfg = { }; |
---|
825 | 771 | struct regulator_dev *rdev; |
---|
826 | 772 | int i; |
---|