forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/regulator/lp873x-regulator.c
....@@ -1,7 +1,7 @@
11 /*
22 * Regulator driver for LP873X PMIC
33 *
4
- * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
4
+ * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/
55 *
66 * This program is free software; you can redistribute it and/or
77 * modify it under the terms of the GNU General Public License version 2 as
....@@ -39,6 +39,10 @@
3939 .ramp_delay = _delay, \
4040 .linear_ranges = _lr, \
4141 .n_linear_ranges = ARRAY_SIZE(_lr), \
42
+ .curr_table = lp873x_buck_uA, \
43
+ .n_current_limits = ARRAY_SIZE(lp873x_buck_uA), \
44
+ .csel_reg = (_cr), \
45
+ .csel_mask = LP873X_BUCK0_CTRL_2_BUCK0_ILIM,\
4246 }, \
4347 .ctrl2_reg = _cr, \
4448 }
....@@ -50,18 +54,18 @@
5054
5155 static const struct lp873x_regulator regulators[];
5256
53
-static const struct regulator_linear_range buck0_buck1_ranges[] = {
57
+static const struct linear_range buck0_buck1_ranges[] = {
5458 REGULATOR_LINEAR_RANGE(0, 0x0, 0x13, 0),
5559 REGULATOR_LINEAR_RANGE(700000, 0x14, 0x17, 10000),
5660 REGULATOR_LINEAR_RANGE(735000, 0x18, 0x9d, 5000),
5761 REGULATOR_LINEAR_RANGE(1420000, 0x9e, 0xff, 20000),
5862 };
5963
60
-static const struct regulator_linear_range ldo0_ldo1_ranges[] = {
64
+static const struct linear_range ldo0_ldo1_ranges[] = {
6165 REGULATOR_LINEAR_RANGE(800000, 0x0, 0x19, 100000),
6266 };
6367
64
-static unsigned int lp873x_buck_ramp_delay[] = {
68
+static const unsigned int lp873x_buck_ramp_delay[] = {
6569 30000, 15000, 10000, 7500, 3800, 1900, 940, 470
6670 };
6771
....@@ -108,45 +112,8 @@
108112 return 0;
109113 }
110114
111
-static int lp873x_buck_set_current_limit(struct regulator_dev *rdev,
112
- int min_uA, int max_uA)
113
-{
114
- int id = rdev_get_id(rdev);
115
- struct lp873x *lp873 = rdev_get_drvdata(rdev);
116
- int i;
117
-
118
- for (i = ARRAY_SIZE(lp873x_buck_uA) - 1; i >= 0; i--) {
119
- if (lp873x_buck_uA[i] >= min_uA &&
120
- lp873x_buck_uA[i] <= max_uA)
121
- return regmap_update_bits(lp873->regmap,
122
- regulators[id].ctrl2_reg,
123
- LP873X_BUCK0_CTRL_2_BUCK0_ILIM,
124
- i << __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM));
125
- }
126
-
127
- return -EINVAL;
128
-}
129
-
130
-static int lp873x_buck_get_current_limit(struct regulator_dev *rdev)
131
-{
132
- int id = rdev_get_id(rdev);
133
- struct lp873x *lp873 = rdev_get_drvdata(rdev);
134
- int ret;
135
- unsigned int val;
136
-
137
- ret = regmap_read(lp873->regmap, regulators[id].ctrl2_reg, &val);
138
- if (ret)
139
- return ret;
140
-
141
- val = (val & LP873X_BUCK0_CTRL_2_BUCK0_ILIM) >>
142
- __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM);
143
-
144
- return (val < ARRAY_SIZE(lp873x_buck_uA)) ?
145
- lp873x_buck_uA[val] : -EINVAL;
146
-}
147
-
148115 /* Operations permitted on BUCK0, BUCK1 */
149
-static struct regulator_ops lp873x_buck01_ops = {
116
+static const struct regulator_ops lp873x_buck01_ops = {
150117 .is_enabled = regulator_is_enabled_regmap,
151118 .enable = regulator_enable_regmap,
152119 .disable = regulator_disable_regmap,
....@@ -156,12 +123,12 @@
156123 .map_voltage = regulator_map_voltage_linear_range,
157124 .set_voltage_time_sel = regulator_set_voltage_time_sel,
158125 .set_ramp_delay = lp873x_buck_set_ramp_delay,
159
- .set_current_limit = lp873x_buck_set_current_limit,
160
- .get_current_limit = lp873x_buck_get_current_limit,
126
+ .set_current_limit = regulator_set_current_limit_regmap,
127
+ .get_current_limit = regulator_get_current_limit_regmap,
161128 };
162129
163130 /* Operations permitted on LDO0 and LDO1 */
164
-static struct regulator_ops lp873x_ldo01_ops = {
131
+static const struct regulator_ops lp873x_ldo01_ops = {
165132 .is_enabled = regulator_is_enabled_regmap,
166133 .enable = regulator_enable_regmap,
167134 .disable = regulator_disable_regmap,