forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/regulator/pv88060-regulator.c
....@@ -1,17 +1,7 @@
1
-/*
2
- * pv88060-regulator.c - Regulator device driver for PV88060
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
+// pv88060-regulator.c - Regulator device driver for PV88060
4
+// Copyright (C) 2015 Powerventure Semiconductor Ltd.
155
166 #include <linux/err.h>
177 #include <linux/i2c.h>
....@@ -53,10 +43,6 @@
5343
5444 struct pv88060_regulator {
5545 struct regulator_desc desc;
56
- /* Current limiting */
57
- unsigned n_current_limits;
58
- const int *current_limits;
59
- unsigned int limit_mask;
6046 unsigned int conf; /* buck configuration register */
6147 };
6248
....@@ -75,7 +61,7 @@
7561 * Entry indexes corresponds to register values.
7662 */
7763
78
-static const int pv88060_buck1_limits[] = {
64
+static const unsigned int pv88060_buck1_limits[] = {
7965 1496000, 2393000, 3291000, 4189000
8066 };
8167
....@@ -128,40 +114,6 @@
128114 PV88060_BUCK_MODE_MASK, val);
129115 }
130116
131
-static int pv88060_set_current_limit(struct regulator_dev *rdev, int min,
132
- int max)
133
-{
134
- struct pv88060_regulator *info = rdev_get_drvdata(rdev);
135
- int i;
136
-
137
- /* search for closest to maximum */
138
- for (i = info->n_current_limits - 1; i >= 0; i--) {
139
- if (min <= info->current_limits[i]
140
- && max >= info->current_limits[i]) {
141
- return regmap_update_bits(rdev->regmap,
142
- info->conf,
143
- info->limit_mask,
144
- i << PV88060_BUCK_ILIM_SHIFT);
145
- }
146
- }
147
-
148
- return -EINVAL;
149
-}
150
-
151
-static int pv88060_get_current_limit(struct regulator_dev *rdev)
152
-{
153
- struct pv88060_regulator *info = rdev_get_drvdata(rdev);
154
- unsigned int data;
155
- int ret;
156
-
157
- ret = regmap_read(rdev->regmap, info->conf, &data);
158
- if (ret < 0)
159
- return ret;
160
-
161
- data = (data & info->limit_mask) >> PV88060_BUCK_ILIM_SHIFT;
162
- return info->current_limits[data];
163
-}
164
-
165117 static const struct regulator_ops pv88060_buck_ops = {
166118 .get_mode = pv88060_buck_get_mode,
167119 .set_mode = pv88060_buck_set_mode,
....@@ -171,8 +123,8 @@
171123 .set_voltage_sel = regulator_set_voltage_sel_regmap,
172124 .get_voltage_sel = regulator_get_voltage_sel_regmap,
173125 .list_voltage = regulator_list_voltage_linear,
174
- .set_current_limit = pv88060_set_current_limit,
175
- .get_current_limit = pv88060_get_current_limit,
126
+ .set_current_limit = regulator_set_current_limit_regmap,
127
+ .get_current_limit = regulator_get_current_limit_regmap,
176128 };
177129
178130 static const struct regulator_ops pv88060_ldo_ops = {
....@@ -182,6 +134,12 @@
182134 .set_voltage_sel = regulator_set_voltage_sel_regmap,
183135 .get_voltage_sel = regulator_get_voltage_sel_regmap,
184136 .list_voltage = regulator_list_voltage_linear,
137
+};
138
+
139
+static const struct regulator_ops pv88060_sw_ops = {
140
+ .enable = regulator_enable_regmap,
141
+ .disable = regulator_disable_regmap,
142
+ .is_enabled = regulator_is_enabled_regmap,
185143 };
186144
187145 #define PV88060_BUCK(chip, regl_name, min, step, max, limits_array) \
....@@ -201,10 +159,11 @@
201159 .enable_mask = PV88060_BUCK_EN, \
202160 .vsel_reg = PV88060_REG_##regl_name##_CONF0,\
203161 .vsel_mask = PV88060_VBUCK_MASK,\
162
+ .curr_table = limits_array,\
163
+ .n_current_limits = ARRAY_SIZE(limits_array),\
164
+ .csel_reg = PV88060_REG_##regl_name##_CONF1,\
165
+ .csel_mask = PV88060_BUCK_ILIM_MASK,\
204166 },\
205
- .current_limits = limits_array,\
206
- .n_current_limits = ARRAY_SIZE(limits_array),\
207
- .limit_mask = PV88060_BUCK_ILIM_MASK, \
208167 .conf = PV88060_REG_##regl_name##_CONF1,\
209168 }
210169
....@@ -237,9 +196,8 @@
237196 .regulators_node = of_match_ptr("regulators"),\
238197 .type = REGULATOR_VOLTAGE,\
239198 .owner = THIS_MODULE,\
240
- .ops = &pv88060_ldo_ops,\
241
- .min_uV = max,\
242
- .uV_step = 0,\
199
+ .ops = &pv88060_sw_ops,\
200
+ .fixed_uV = max,\
243201 .n_voltages = 1,\
244202 .enable_reg = PV88060_REG_##regl_name##_CONF,\
245203 .enable_mask = PV88060_SW_EN,\
....@@ -275,11 +233,10 @@
275233
276234 if (reg_val & PV88060_E_VDD_FLT) {
277235 for (i = 0; i < PV88060_MAX_REGULATORS; i++) {
278
- if (chip->rdev[i] != NULL) {
236
+ if (chip->rdev[i] != NULL)
279237 regulator_notifier_call_chain(chip->rdev[i],
280238 REGULATOR_EVENT_UNDER_VOLTAGE,
281239 NULL);
282
- }
283240 }
284241
285242 err = regmap_write(chip->regmap, PV88060_REG_EVENT_A,
....@@ -292,11 +249,10 @@
292249
293250 if (reg_val & PV88060_E_OVER_TEMP) {
294251 for (i = 0; i < PV88060_MAX_REGULATORS; i++) {
295
- if (chip->rdev[i] != NULL) {
252
+ if (chip->rdev[i] != NULL)
296253 regulator_notifier_call_chain(chip->rdev[i],
297254 REGULATOR_EVENT_OVER_TEMP,
298255 NULL);
299
- }
300256 }
301257
302258 err = regmap_write(chip->regmap, PV88060_REG_EVENT_A,
....@@ -317,8 +273,7 @@
317273 /*
318274 * I2C driver interface functions
319275 */
320
-static int pv88060_i2c_probe(struct i2c_client *i2c,
321
- const struct i2c_device_id *id)
276
+static int pv88060_i2c_probe(struct i2c_client *i2c)
322277 {
323278 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
324279 struct pv88060 *chip;
....@@ -423,7 +378,7 @@
423378 .name = "pv88060",
424379 .of_match_table = of_match_ptr(pv88060_dt_ids),
425380 },
426
- .probe = pv88060_i2c_probe,
381
+ .probe_new = pv88060_i2c_probe,
427382 .id_table = pv88060_i2c_id,
428383 };
429384