forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-20 ea08eeccae9297f7aabd2ef7f0c2517ac4549acc
kernel/drivers/regulator/pv88090-regulator.c
....@@ -1,17 +1,7 @@
1
-/*
2
- * pv88090-regulator.c - Regulator device driver for PV88090
3
- * Copyright (C) 2015 Powerventure Semiconductor Ltd.
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * as published by the Free Software Foundation; either version 2
8
- * of the License, or (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// pv88090-regulator.c - Regulator device driver for PV88090
4
+// Copyright (C) 2015 Powerventure Semiconductor Ltd.
155
166 #include <linux/err.h>
177 #include <linux/i2c.h>
....@@ -42,10 +32,6 @@
4232
4333 struct pv88090_regulator {
4434 struct regulator_desc desc;
45
- /* Current limiting */
46
- unsigned int n_current_limits;
47
- const int *current_limits;
48
- unsigned int limit_mask;
4935 unsigned int conf;
5036 unsigned int conf2;
5137 };
....@@ -71,14 +57,14 @@
7157 * Entry indexes corresponds to register values.
7258 */
7359
74
-static const int pv88090_buck1_limits[] = {
60
+static const unsigned int pv88090_buck1_limits[] = {
7561 220000, 440000, 660000, 880000, 1100000, 1320000, 1540000, 1760000,
7662 1980000, 2200000, 2420000, 2640000, 2860000, 3080000, 3300000, 3520000,
7763 3740000, 3960000, 4180000, 4400000, 4620000, 4840000, 5060000, 5280000,
7864 5500000, 5720000, 5940000, 6160000, 6380000, 6600000, 6820000, 7040000
7965 };
8066
81
-static const int pv88090_buck23_limits[] = {
67
+static const unsigned int pv88090_buck23_limits[] = {
8268 1496000, 2393000, 3291000, 4189000
8369 };
8470
....@@ -150,40 +136,6 @@
150136 PV88090_BUCK1_MODE_MASK, val);
151137 }
152138
153
-static int pv88090_set_current_limit(struct regulator_dev *rdev, int min,
154
- int max)
155
-{
156
- struct pv88090_regulator *info = rdev_get_drvdata(rdev);
157
- int i;
158
-
159
- /* search for closest to maximum */
160
- for (i = info->n_current_limits - 1; i >= 0; i--) {
161
- if (min <= info->current_limits[i]
162
- && max >= info->current_limits[i]) {
163
- return regmap_update_bits(rdev->regmap,
164
- info->conf,
165
- info->limit_mask,
166
- i << PV88090_BUCK1_ILIM_SHIFT);
167
- }
168
- }
169
-
170
- return -EINVAL;
171
-}
172
-
173
-static int pv88090_get_current_limit(struct regulator_dev *rdev)
174
-{
175
- struct pv88090_regulator *info = rdev_get_drvdata(rdev);
176
- unsigned int data;
177
- int ret;
178
-
179
- ret = regmap_read(rdev->regmap, info->conf, &data);
180
- if (ret < 0)
181
- return ret;
182
-
183
- data = (data & info->limit_mask) >> PV88090_BUCK1_ILIM_SHIFT;
184
- return info->current_limits[data];
185
-}
186
-
187139 static const struct regulator_ops pv88090_buck_ops = {
188140 .get_mode = pv88090_buck_get_mode,
189141 .set_mode = pv88090_buck_set_mode,
....@@ -193,8 +145,8 @@
193145 .set_voltage_sel = regulator_set_voltage_sel_regmap,
194146 .get_voltage_sel = regulator_get_voltage_sel_regmap,
195147 .list_voltage = regulator_list_voltage_linear,
196
- .set_current_limit = pv88090_set_current_limit,
197
- .get_current_limit = pv88090_get_current_limit,
148
+ .set_current_limit = regulator_set_current_limit_regmap,
149
+ .get_current_limit = regulator_get_current_limit_regmap,
198150 };
199151
200152 static const struct regulator_ops pv88090_ldo_ops = {
....@@ -223,10 +175,11 @@
223175 .enable_mask = PV88090_##regl_name##_EN, \
224176 .vsel_reg = PV88090_REG_##regl_name##_CONF0, \
225177 .vsel_mask = PV88090_V##regl_name##_MASK, \
178
+ .curr_table = limits_array, \
179
+ .n_current_limits = ARRAY_SIZE(limits_array), \
180
+ .csel_reg = PV88090_REG_##regl_name##_CONF1, \
181
+ .csel_mask = PV88090_##regl_name##_ILIM_MASK, \
226182 },\
227
- .current_limits = limits_array, \
228
- .n_current_limits = ARRAY_SIZE(limits_array), \
229
- .limit_mask = PV88090_##regl_name##_ILIM_MASK, \
230183 .conf = PV88090_REG_##regl_name##_CONF1, \
231184 .conf2 = PV88090_REG_##regl_name##_CONF2, \
232185 }
....@@ -273,11 +226,10 @@
273226
274227 if (reg_val & PV88090_E_VDD_FLT) {
275228 for (i = 0; i < PV88090_MAX_REGULATORS; i++) {
276
- if (chip->rdev[i] != NULL) {
229
+ if (chip->rdev[i] != NULL)
277230 regulator_notifier_call_chain(chip->rdev[i],
278231 REGULATOR_EVENT_UNDER_VOLTAGE,
279232 NULL);
280
- }
281233 }
282234
283235 err = regmap_write(chip->regmap, PV88090_REG_EVENT_A,
....@@ -290,11 +242,10 @@
290242
291243 if (reg_val & PV88090_E_OVER_TEMP) {
292244 for (i = 0; i < PV88090_MAX_REGULATORS; i++) {
293
- if (chip->rdev[i] != NULL) {
245
+ if (chip->rdev[i] != NULL)
294246 regulator_notifier_call_chain(chip->rdev[i],
295247 REGULATOR_EVENT_OVER_TEMP,
296248 NULL);
297
- }
298249 }
299250
300251 err = regmap_write(chip->regmap, PV88090_REG_EVENT_A,
....@@ -315,8 +266,7 @@
315266 /*
316267 * I2C driver interface functions
317268 */
318
-static int pv88090_i2c_probe(struct i2c_client *i2c,
319
- const struct i2c_device_id *id)
269
+static int pv88090_i2c_probe(struct i2c_client *i2c)
320270 {
321271 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
322272 struct pv88090 *chip;
....@@ -449,7 +399,7 @@
449399 .name = "pv88090",
450400 .of_match_table = of_match_ptr(pv88090_dt_ids),
451401 },
452
- .probe = pv88090_i2c_probe,
402
+ .probe_new = pv88090_i2c_probe,
453403 .id_table = pv88090_i2c_id,
454404 };
455405