hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/regulator/lp872x.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright 2012 Texas Instruments
34 *
45 * 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
- *
106 */
117
128 #include <linux/module.h>
....@@ -353,64 +349,6 @@
353349 return val & LP872X_VOUT_M;
354350 }
355351
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
-
414352 static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
415353 {
416354 struct lp872x *lp = rdev_get_drvdata(rdev);
....@@ -478,7 +416,7 @@
478416 return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
479417 }
480418
481
-static struct regulator_ops lp872x_ldo_ops = {
419
+static const struct regulator_ops lp872x_ldo_ops = {
482420 .list_voltage = regulator_list_voltage_table,
483421 .map_voltage = regulator_map_voltage_ascend,
484422 .set_voltage_sel = regulator_set_voltage_sel_regmap,
....@@ -489,7 +427,7 @@
489427 .enable_time = lp872x_regulator_enable_time,
490428 };
491429
492
-static struct regulator_ops lp8720_buck_ops = {
430
+static const struct regulator_ops lp8720_buck_ops = {
493431 .list_voltage = regulator_list_voltage_table,
494432 .map_voltage = regulator_map_voltage_ascend,
495433 .set_voltage_sel = lp872x_buck_set_voltage_sel,
....@@ -502,7 +440,7 @@
502440 .get_mode = lp872x_buck_get_mode,
503441 };
504442
505
-static struct regulator_ops lp8725_buck_ops = {
443
+static const struct regulator_ops lp8725_buck_ops = {
506444 .list_voltage = regulator_list_voltage_table,
507445 .map_voltage = regulator_map_voltage_ascend,
508446 .set_voltage_sel = lp872x_buck_set_voltage_sel,
....@@ -513,11 +451,11 @@
513451 .enable_time = lp872x_regulator_enable_time,
514452 .set_mode = lp872x_buck_set_mode,
515453 .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,
518456 };
519457
520
-static struct regulator_desc lp8720_regulator_desc[] = {
458
+static const struct regulator_desc lp8720_regulator_desc[] = {
521459 {
522460 .name = "ldo1",
523461 .of_match = of_match_ptr("ldo1"),
....@@ -602,7 +540,7 @@
602540 },
603541 };
604542
605
-static struct regulator_desc lp8725_regulator_desc[] = {
543
+static const struct regulator_desc lp8725_regulator_desc[] = {
606544 {
607545 .name = "ldo1",
608546 .of_match = of_match_ptr("ldo1"),
....@@ -712,6 +650,10 @@
712650 .owner = THIS_MODULE,
713651 .enable_reg = LP872X_GENERAL_CFG,
714652 .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,
715657 },
716658 {
717659 .name = "buck2",
....@@ -724,6 +666,10 @@
724666 .owner = THIS_MODULE,
725667 .enable_reg = LP872X_GENERAL_CFG,
726668 .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,
727673 },
728674 };
729675
....@@ -820,7 +766,7 @@
820766
821767 static int lp872x_regulator_register(struct lp872x *lp)
822768 {
823
- struct regulator_desc *desc;
769
+ const struct regulator_desc *desc;
824770 struct regulator_config cfg = { };
825771 struct regulator_dev *rdev;
826772 int i;