.. | .. |
---|
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. |
---|
15 | 5 | |
---|
16 | 6 | #include <linux/err.h> |
---|
17 | 7 | #include <linux/i2c.h> |
---|
.. | .. |
---|
53 | 43 | |
---|
54 | 44 | struct pv88060_regulator { |
---|
55 | 45 | struct regulator_desc desc; |
---|
56 | | - /* Current limiting */ |
---|
57 | | - unsigned n_current_limits; |
---|
58 | | - const int *current_limits; |
---|
59 | | - unsigned int limit_mask; |
---|
60 | 46 | unsigned int conf; /* buck configuration register */ |
---|
61 | 47 | }; |
---|
62 | 48 | |
---|
.. | .. |
---|
75 | 61 | * Entry indexes corresponds to register values. |
---|
76 | 62 | */ |
---|
77 | 63 | |
---|
78 | | -static const int pv88060_buck1_limits[] = { |
---|
| 64 | +static const unsigned int pv88060_buck1_limits[] = { |
---|
79 | 65 | 1496000, 2393000, 3291000, 4189000 |
---|
80 | 66 | }; |
---|
81 | 67 | |
---|
.. | .. |
---|
128 | 114 | PV88060_BUCK_MODE_MASK, val); |
---|
129 | 115 | } |
---|
130 | 116 | |
---|
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 | | - |
---|
165 | 117 | static const struct regulator_ops pv88060_buck_ops = { |
---|
166 | 118 | .get_mode = pv88060_buck_get_mode, |
---|
167 | 119 | .set_mode = pv88060_buck_set_mode, |
---|
.. | .. |
---|
171 | 123 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
---|
172 | 124 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
---|
173 | 125 | .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, |
---|
176 | 128 | }; |
---|
177 | 129 | |
---|
178 | 130 | static const struct regulator_ops pv88060_ldo_ops = { |
---|
.. | .. |
---|
182 | 134 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
---|
183 | 135 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
---|
184 | 136 | .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, |
---|
185 | 143 | }; |
---|
186 | 144 | |
---|
187 | 145 | #define PV88060_BUCK(chip, regl_name, min, step, max, limits_array) \ |
---|
.. | .. |
---|
201 | 159 | .enable_mask = PV88060_BUCK_EN, \ |
---|
202 | 160 | .vsel_reg = PV88060_REG_##regl_name##_CONF0,\ |
---|
203 | 161 | .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,\ |
---|
204 | 166 | },\ |
---|
205 | | - .current_limits = limits_array,\ |
---|
206 | | - .n_current_limits = ARRAY_SIZE(limits_array),\ |
---|
207 | | - .limit_mask = PV88060_BUCK_ILIM_MASK, \ |
---|
208 | 167 | .conf = PV88060_REG_##regl_name##_CONF1,\ |
---|
209 | 168 | } |
---|
210 | 169 | |
---|
.. | .. |
---|
237 | 196 | .regulators_node = of_match_ptr("regulators"),\ |
---|
238 | 197 | .type = REGULATOR_VOLTAGE,\ |
---|
239 | 198 | .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,\ |
---|
243 | 201 | .n_voltages = 1,\ |
---|
244 | 202 | .enable_reg = PV88060_REG_##regl_name##_CONF,\ |
---|
245 | 203 | .enable_mask = PV88060_SW_EN,\ |
---|
.. | .. |
---|
275 | 233 | |
---|
276 | 234 | if (reg_val & PV88060_E_VDD_FLT) { |
---|
277 | 235 | for (i = 0; i < PV88060_MAX_REGULATORS; i++) { |
---|
278 | | - if (chip->rdev[i] != NULL) { |
---|
| 236 | + if (chip->rdev[i] != NULL) |
---|
279 | 237 | regulator_notifier_call_chain(chip->rdev[i], |
---|
280 | 238 | REGULATOR_EVENT_UNDER_VOLTAGE, |
---|
281 | 239 | NULL); |
---|
282 | | - } |
---|
283 | 240 | } |
---|
284 | 241 | |
---|
285 | 242 | err = regmap_write(chip->regmap, PV88060_REG_EVENT_A, |
---|
.. | .. |
---|
292 | 249 | |
---|
293 | 250 | if (reg_val & PV88060_E_OVER_TEMP) { |
---|
294 | 251 | for (i = 0; i < PV88060_MAX_REGULATORS; i++) { |
---|
295 | | - if (chip->rdev[i] != NULL) { |
---|
| 252 | + if (chip->rdev[i] != NULL) |
---|
296 | 253 | regulator_notifier_call_chain(chip->rdev[i], |
---|
297 | 254 | REGULATOR_EVENT_OVER_TEMP, |
---|
298 | 255 | NULL); |
---|
299 | | - } |
---|
300 | 256 | } |
---|
301 | 257 | |
---|
302 | 258 | err = regmap_write(chip->regmap, PV88060_REG_EVENT_A, |
---|
.. | .. |
---|
317 | 273 | /* |
---|
318 | 274 | * I2C driver interface functions |
---|
319 | 275 | */ |
---|
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) |
---|
322 | 277 | { |
---|
323 | 278 | struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev); |
---|
324 | 279 | struct pv88060 *chip; |
---|
.. | .. |
---|
423 | 378 | .name = "pv88060", |
---|
424 | 379 | .of_match_table = of_match_ptr(pv88060_dt_ids), |
---|
425 | 380 | }, |
---|
426 | | - .probe = pv88060_i2c_probe, |
---|
| 381 | + .probe_new = pv88060_i2c_probe, |
---|
427 | 382 | .id_table = pv88060_i2c_id, |
---|
428 | 383 | }; |
---|
429 | 384 | |
---|