blob: 00c83492f774125ce2ce3e6a75143fefc065d00c [file] [log] [blame]
Axel Lin6a1beee2019-04-19 08:58:24 +08001// SPDX-License-Identifier: GPL-2.0
2//
3// FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver.
4//
5// Supported Part Numbers:
6// FAN53555UC00X/01X/03X/04X/05X
7//
8// Copyright (c) 2012 Marvell Technology Ltd.
9// Yunfan Zhang <yfzhang@marvell.com>
10
Yunfan Zhang49d8c592012-09-08 03:52:18 -070011#include <linux/module.h>
12#include <linux/param.h>
13#include <linux/err.h>
14#include <linux/platform_device.h>
15#include <linux/regulator/driver.h>
16#include <linux/regulator/machine.h>
Heiko Stuebner91f23d82014-09-16 21:22:53 +020017#include <linux/regulator/of_regulator.h>
18#include <linux/of_device.h>
Yunfan Zhang49d8c592012-09-08 03:52:18 -070019#include <linux/i2c.h>
20#include <linux/slab.h>
21#include <linux/regmap.h>
22#include <linux/regulator/fan53555.h>
23
24/* Voltage setting */
25#define FAN53555_VSEL0 0x00
26#define FAN53555_VSEL1 0x01
27/* Control register */
28#define FAN53555_CONTROL 0x02
29/* IC Type */
30#define FAN53555_ID1 0x03
31/* IC mask version */
32#define FAN53555_ID2 0x04
33/* Monitor register */
34#define FAN53555_MONITOR 0x05
35
36/* VSEL bit definitions */
37#define VSEL_BUCK_EN (1 << 7)
38#define VSEL_MODE (1 << 6)
Yunfan Zhang49d8c592012-09-08 03:52:18 -070039/* Chip ID and Verison */
40#define DIE_ID 0x0F /* ID1 */
41#define DIE_REV 0x0F /* ID2 */
42/* Control bit definitions */
43#define CTL_OUTPUT_DISCHG (1 << 7)
44#define CTL_SLEW_MASK (0x7 << 4)
45#define CTL_SLEW_SHIFT 4
46#define CTL_RESET (1 << 2)
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -080047#define CTL_MODE_VSEL0_MODE BIT(0)
48#define CTL_MODE_VSEL1_MODE BIT(1)
Yunfan Zhang49d8c592012-09-08 03:52:18 -070049
50#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -080051#define FAN53526_NVOLTAGES 128
Yunfan Zhang49d8c592012-09-08 03:52:18 -070052
Heiko Stuebneree309282014-09-16 21:22:54 +020053enum fan53555_vendor {
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -080054 FAN53526_VENDOR_FAIRCHILD = 0,
55 FAN53555_VENDOR_FAIRCHILD,
Heiko Stuebneree309282014-09-16 21:22:54 +020056 FAN53555_VENDOR_SILERGY,
57};
58
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -080059enum {
60 FAN53526_CHIP_ID_01 = 1,
61};
62
63enum {
64 FAN53526_CHIP_REV_08 = 8,
65};
66
Yunfan Zhang49d8c592012-09-08 03:52:18 -070067/* IC Type */
68enum {
69 FAN53555_CHIP_ID_00 = 0,
70 FAN53555_CHIP_ID_01,
71 FAN53555_CHIP_ID_02,
72 FAN53555_CHIP_ID_03,
73 FAN53555_CHIP_ID_04,
74 FAN53555_CHIP_ID_05,
Wadim Egorov5e39cf42016-04-20 10:01:07 +020075 FAN53555_CHIP_ID_08 = 8,
Yunfan Zhang49d8c592012-09-08 03:52:18 -070076};
77
Wadim Egorove57cbb72016-04-20 10:01:08 +020078/* IC mask revision */
79enum {
80 FAN53555_CHIP_REV_00 = 0x3,
81 FAN53555_CHIP_REV_13 = 0xf,
82};
83
Heiko Stuebneree309282014-09-16 21:22:54 +020084enum {
85 SILERGY_SYR82X = 8,
Vasily Khoruzhick5365e3d2019-11-06 08:12:11 -080086 SILERGY_SYR83X = 9,
Heiko Stuebneree309282014-09-16 21:22:54 +020087};
88
Yunfan Zhang49d8c592012-09-08 03:52:18 -070089struct fan53555_device_info {
Heiko Stuebneree309282014-09-16 21:22:54 +020090 enum fan53555_vendor vendor;
Yunfan Zhang49d8c592012-09-08 03:52:18 -070091 struct device *dev;
92 struct regulator_desc desc;
Yunfan Zhang49d8c592012-09-08 03:52:18 -070093 struct regulator_init_data *regulator;
94 /* IC Type and Rev */
95 int chip_id;
96 int chip_rev;
97 /* Voltage setting register */
98 unsigned int vol_reg;
99 unsigned int sleep_reg;
100 /* Voltage range and step(linear) */
101 unsigned int vsel_min;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700102 unsigned int vsel_step;
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800103 unsigned int vsel_count;
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800104 /* Mode */
105 unsigned int mode_reg;
106 unsigned int mode_mask;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700107 /* Sleep voltage cache */
108 unsigned int sleep_vol_cache;
109};
110
111static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV)
112{
113 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
114 int ret;
115
116 if (di->sleep_vol_cache == uV)
117 return 0;
118 ret = regulator_map_voltage_linear(rdev, uV, uV);
119 if (ret < 0)
Sachin Kamat145fe1e2014-02-18 16:11:04 +0530120 return ret;
Axel Lina69929c2019-04-19 08:58:23 +0800121 ret = regmap_update_bits(rdev->regmap, di->sleep_reg,
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800122 di->desc.vsel_mask, ret);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700123 if (ret < 0)
Sachin Kamat145fe1e2014-02-18 16:11:04 +0530124 return ret;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700125 /* Cache the sleep voltage setting.
126 * Might not be the real voltage which is rounded */
127 di->sleep_vol_cache = uV;
128
129 return 0;
130}
131
zhangqingab7cad32016-01-12 03:05:56 -0800132static int fan53555_set_suspend_enable(struct regulator_dev *rdev)
133{
134 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
135
Axel Lina69929c2019-04-19 08:58:23 +0800136 return regmap_update_bits(rdev->regmap, di->sleep_reg,
zhangqingab7cad32016-01-12 03:05:56 -0800137 VSEL_BUCK_EN, VSEL_BUCK_EN);
138}
139
140static int fan53555_set_suspend_disable(struct regulator_dev *rdev)
141{
142 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
143
Axel Lina69929c2019-04-19 08:58:23 +0800144 return regmap_update_bits(rdev->regmap, di->sleep_reg,
zhangqingab7cad32016-01-12 03:05:56 -0800145 VSEL_BUCK_EN, 0);
146}
147
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700148static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode)
149{
150 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
151
152 switch (mode) {
153 case REGULATOR_MODE_FAST:
Axel Lina69929c2019-04-19 08:58:23 +0800154 regmap_update_bits(rdev->regmap, di->mode_reg,
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800155 di->mode_mask, di->mode_mask);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700156 break;
157 case REGULATOR_MODE_NORMAL:
Axel Lina69929c2019-04-19 08:58:23 +0800158 regmap_update_bits(rdev->regmap, di->vol_reg, di->mode_mask, 0);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700159 break;
160 default:
161 return -EINVAL;
162 }
163 return 0;
164}
165
166static unsigned int fan53555_get_mode(struct regulator_dev *rdev)
167{
168 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
169 unsigned int val;
170 int ret = 0;
171
Axel Lina69929c2019-04-19 08:58:23 +0800172 ret = regmap_read(rdev->regmap, di->mode_reg, &val);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700173 if (ret < 0)
174 return ret;
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800175 if (val & di->mode_mask)
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700176 return REGULATOR_MODE_FAST;
177 else
178 return REGULATOR_MODE_NORMAL;
179}
180
Krzysztof Kozlowski121b5672015-01-05 10:04:19 +0100181static const int slew_rates[] = {
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200182 64000,
183 32000,
184 16000,
185 8000,
186 4000,
187 2000,
188 1000,
189 500,
190};
191
192static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp)
193{
194 struct fan53555_device_info *di = rdev_get_drvdata(rdev);
195 int regval = -1, i;
196
197 for (i = 0; i < ARRAY_SIZE(slew_rates); i++) {
198 if (ramp <= slew_rates[i])
199 regval = i;
200 else
201 break;
202 }
203
204 if (regval < 0) {
205 dev_err(di->dev, "unsupported ramp value %d\n", ramp);
206 return -EINVAL;
207 }
208
Axel Lina69929c2019-04-19 08:58:23 +0800209 return regmap_update_bits(rdev->regmap, FAN53555_CONTROL,
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200210 CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT);
211}
212
Bhumika Goyal71880ab2017-01-28 19:32:05 +0530213static const struct regulator_ops fan53555_regulator_ops = {
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700214 .set_voltage_sel = regulator_set_voltage_sel_regmap,
215 .get_voltage_sel = regulator_get_voltage_sel_regmap,
Heiko Stuebnerfda87a42015-05-26 18:19:45 +0200216 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700217 .map_voltage = regulator_map_voltage_linear,
218 .list_voltage = regulator_list_voltage_linear,
219 .set_suspend_voltage = fan53555_set_suspend_voltage,
220 .enable = regulator_enable_regmap,
221 .disable = regulator_disable_regmap,
222 .is_enabled = regulator_is_enabled_regmap,
223 .set_mode = fan53555_set_mode,
224 .get_mode = fan53555_get_mode,
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200225 .set_ramp_delay = fan53555_set_ramp,
zhangqingab7cad32016-01-12 03:05:56 -0800226 .set_suspend_enable = fan53555_set_suspend_enable,
227 .set_suspend_disable = fan53555_set_suspend_disable,
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700228};
229
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800230static int fan53526_voltages_setup_fairchild(struct fan53555_device_info *di)
231{
232 /* Init voltage range and step */
233 switch (di->chip_id) {
234 case FAN53526_CHIP_ID_01:
235 switch (di->chip_rev) {
236 case FAN53526_CHIP_REV_08:
237 di->vsel_min = 600000;
238 di->vsel_step = 6250;
239 break;
240 default:
241 dev_err(di->dev,
242 "Chip ID %d with rev %d not supported!\n",
243 di->chip_id, di->chip_rev);
244 return -EINVAL;
245 }
246 break;
247 default:
248 dev_err(di->dev,
249 "Chip ID %d not supported!\n", di->chip_id);
250 return -EINVAL;
251 }
252
253 di->vsel_count = FAN53526_NVOLTAGES;
254
255 return 0;
256}
257
Heiko Stuebneree309282014-09-16 21:22:54 +0200258static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700259{
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700260 /* Init voltage range and step */
261 switch (di->chip_id) {
262 case FAN53555_CHIP_ID_00:
Wadim Egorove57cbb72016-04-20 10:01:08 +0200263 switch (di->chip_rev) {
264 case FAN53555_CHIP_REV_00:
265 di->vsel_min = 600000;
266 di->vsel_step = 10000;
267 break;
268 case FAN53555_CHIP_REV_13:
269 di->vsel_min = 800000;
270 di->vsel_step = 10000;
271 break;
272 default:
273 dev_err(di->dev,
274 "Chip ID %d with rev %d not supported!\n",
275 di->chip_id, di->chip_rev);
276 return -EINVAL;
277 }
278 break;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700279 case FAN53555_CHIP_ID_01:
280 case FAN53555_CHIP_ID_03:
281 case FAN53555_CHIP_ID_05:
Wadim Egorov5e39cf42016-04-20 10:01:07 +0200282 case FAN53555_CHIP_ID_08:
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700283 di->vsel_min = 600000;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700284 di->vsel_step = 10000;
285 break;
286 case FAN53555_CHIP_ID_04:
287 di->vsel_min = 603000;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700288 di->vsel_step = 12826;
289 break;
290 default:
291 dev_err(di->dev,
Heiko Stuebneree309282014-09-16 21:22:54 +0200292 "Chip ID %d not supported!\n", di->chip_id);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700293 return -EINVAL;
294 }
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200295
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800296 di->vsel_count = FAN53555_NVOLTAGES;
297
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200298 return 0;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700299}
300
Heiko Stuebneree309282014-09-16 21:22:54 +0200301static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
302{
303 /* Init voltage range and step */
304 switch (di->chip_id) {
305 case SILERGY_SYR82X:
Vasily Khoruzhick5365e3d2019-11-06 08:12:11 -0800306 case SILERGY_SYR83X:
Heiko Stuebneree309282014-09-16 21:22:54 +0200307 di->vsel_min = 712500;
308 di->vsel_step = 12500;
309 break;
310 default:
311 dev_err(di->dev,
312 "Chip ID %d not supported!\n", di->chip_id);
313 return -EINVAL;
314 }
315
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800316 di->vsel_count = FAN53555_NVOLTAGES;
317
Heiko Stuebneree309282014-09-16 21:22:54 +0200318 return 0;
319}
320
321/* For 00,01,03,05 options:
322 * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V.
323 * For 04 option:
324 * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V.
325 * */
326static int fan53555_device_setup(struct fan53555_device_info *di,
327 struct fan53555_platform_data *pdata)
328{
329 int ret = 0;
330
331 /* Setup voltage control register */
332 switch (pdata->sleep_vsel_id) {
333 case FAN53555_VSEL_ID_0:
334 di->sleep_reg = FAN53555_VSEL0;
335 di->vol_reg = FAN53555_VSEL1;
336 break;
337 case FAN53555_VSEL_ID_1:
338 di->sleep_reg = FAN53555_VSEL1;
339 di->vol_reg = FAN53555_VSEL0;
340 break;
341 default:
342 dev_err(di->dev, "Invalid VSEL ID!\n");
343 return -EINVAL;
344 }
345
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800346 /* Setup mode control register */
Heiko Stuebneree309282014-09-16 21:22:54 +0200347 switch (di->vendor) {
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800348 case FAN53526_VENDOR_FAIRCHILD:
349 di->mode_reg = FAN53555_CONTROL;
350
351 switch (pdata->sleep_vsel_id) {
352 case FAN53555_VSEL_ID_0:
353 di->mode_mask = CTL_MODE_VSEL1_MODE;
354 break;
355 case FAN53555_VSEL_ID_1:
356 di->mode_mask = CTL_MODE_VSEL0_MODE;
357 break;
358 }
359 break;
360 case FAN53555_VENDOR_FAIRCHILD:
361 case FAN53555_VENDOR_SILERGY:
362 di->mode_reg = di->vol_reg;
363 di->mode_mask = VSEL_MODE;
364 break;
365 default:
366 dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
367 return -EINVAL;
368 }
369
370 /* Setup voltage range */
371 switch (di->vendor) {
372 case FAN53526_VENDOR_FAIRCHILD:
373 ret = fan53526_voltages_setup_fairchild(di);
374 break;
Heiko Stuebneree309282014-09-16 21:22:54 +0200375 case FAN53555_VENDOR_FAIRCHILD:
376 ret = fan53555_voltages_setup_fairchild(di);
377 break;
378 case FAN53555_VENDOR_SILERGY:
379 ret = fan53555_voltages_setup_silergy(di);
380 break;
381 default:
Axel Linfe230532014-09-18 21:48:48 +0800382 dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
Heiko Stuebneree309282014-09-16 21:22:54 +0200383 return -EINVAL;
384 }
385
386 return ret;
387}
388
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700389static int fan53555_regulator_register(struct fan53555_device_info *di,
390 struct regulator_config *config)
391{
392 struct regulator_desc *rdesc = &di->desc;
Axel Lina69929c2019-04-19 08:58:23 +0800393 struct regulator_dev *rdev;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700394
395 rdesc->name = "fan53555-reg";
Heiko Stuebner3415d602014-09-14 21:23:01 +0200396 rdesc->supply_name = "vin";
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700397 rdesc->ops = &fan53555_regulator_ops;
398 rdesc->type = REGULATOR_VOLTAGE;
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800399 rdesc->n_voltages = di->vsel_count;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700400 rdesc->enable_reg = di->vol_reg;
401 rdesc->enable_mask = VSEL_BUCK_EN;
402 rdesc->min_uV = di->vsel_min;
403 rdesc->uV_step = di->vsel_step;
404 rdesc->vsel_reg = di->vol_reg;
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800405 rdesc->vsel_mask = di->vsel_count - 1;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700406 rdesc->owner = THIS_MODULE;
407
Axel Lina69929c2019-04-19 08:58:23 +0800408 rdev = devm_regulator_register(di->dev, &di->desc, config);
409 return PTR_ERR_OR_ZERO(rdev);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700410}
411
Krzysztof Kozlowski121b5672015-01-05 10:04:19 +0100412static const struct regmap_config fan53555_regmap_config = {
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700413 .reg_bits = 8,
414 .val_bits = 8,
415};
416
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200417static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
Javier Martinez Canillas072e78b2014-11-10 14:43:53 +0100418 struct device_node *np,
419 const struct regulator_desc *desc)
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200420{
421 struct fan53555_platform_data *pdata;
422 int ret;
423 u32 tmp;
424
425 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
426 if (!pdata)
427 return NULL;
428
Javier Martinez Canillas072e78b2014-11-10 14:43:53 +0100429 pdata->regulator = of_get_regulator_init_data(dev, np, desc);
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200430
431 ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
432 &tmp);
433 if (!ret)
434 pdata->sleep_vsel_id = tmp;
435
436 return pdata;
437}
438
439static const struct of_device_id fan53555_dt_ids[] = {
440 {
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800441 .compatible = "fcs,fan53526",
442 .data = (void *)FAN53526_VENDOR_FAIRCHILD,
443 }, {
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200444 .compatible = "fcs,fan53555",
Heiko Stuebneree309282014-09-16 21:22:54 +0200445 .data = (void *)FAN53555_VENDOR_FAIRCHILD
446 }, {
447 .compatible = "silergy,syr827",
448 .data = (void *)FAN53555_VENDOR_SILERGY,
449 }, {
450 .compatible = "silergy,syr828",
451 .data = (void *)FAN53555_VENDOR_SILERGY,
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200452 },
453 { }
454};
455MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
456
Bill Pembertona5023572012-11-19 13:22:22 -0500457static int fan53555_regulator_probe(struct i2c_client *client,
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700458 const struct i2c_device_id *id)
459{
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200460 struct device_node *np = client->dev.of_node;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700461 struct fan53555_device_info *di;
462 struct fan53555_platform_data *pdata;
463 struct regulator_config config = { };
Axel Lina69929c2019-04-19 08:58:23 +0800464 struct regmap *regmap;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700465 unsigned int val;
466 int ret;
467
Javier Martinez Canillas072e78b2014-11-10 14:43:53 +0100468 di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info),
469 GFP_KERNEL);
470 if (!di)
471 return -ENOMEM;
472
Jingoo Handff91d02013-07-30 17:20:47 +0900473 pdata = dev_get_platdata(&client->dev);
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200474 if (!pdata)
Javier Martinez Canillas072e78b2014-11-10 14:43:53 +0100475 pdata = fan53555_parse_dt(&client->dev, np, &di->desc);
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200476
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700477 if (!pdata || !pdata->regulator) {
478 dev_err(&client->dev, "Platform data not found!\n");
479 return -ENODEV;
480 }
481
Axel Line13426b2014-09-18 21:49:38 +0800482 di->regulator = pdata->regulator;
Heiko Stuebneree309282014-09-16 21:22:54 +0200483 if (client->dev.of_node) {
Jisheng Zhangd110e3e2017-07-20 16:42:17 +0800484 di->vendor =
485 (unsigned long)of_device_get_match_data(&client->dev);
Heiko Stuebneree309282014-09-16 21:22:54 +0200486 } else {
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200487 /* if no ramp constraint set, get the pdata ramp_delay */
488 if (!di->regulator->constraints.ramp_delay) {
Axel Lin87919e02019-02-24 11:21:46 +0800489 if (pdata->slew_rate >= ARRAY_SIZE(slew_rates)) {
490 dev_err(&client->dev, "Invalid slew_rate\n");
491 return -EINVAL;
492 }
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200493
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200494 di->regulator->constraints.ramp_delay
Axel Lin87919e02019-02-24 11:21:46 +0800495 = slew_rates[pdata->slew_rate];
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200496 }
Heiko Stuebneree309282014-09-16 21:22:54 +0200497
498 di->vendor = id->driver_data;
Heiko Stuebnerdd7e71f2014-09-16 17:54:01 +0200499 }
500
Axel Lina69929c2019-04-19 08:58:23 +0800501 regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
502 if (IS_ERR(regmap)) {
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700503 dev_err(&client->dev, "Failed to allocate regmap!\n");
Axel Lina69929c2019-04-19 08:58:23 +0800504 return PTR_ERR(regmap);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700505 }
506 di->dev = &client->dev;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700507 i2c_set_clientdata(client, di);
508 /* Get chip ID */
Axel Lina69929c2019-04-19 08:58:23 +0800509 ret = regmap_read(regmap, FAN53555_ID1, &val);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700510 if (ret < 0) {
511 dev_err(&client->dev, "Failed to get chip ID!\n");
Sachin Kamat145fe1e2014-02-18 16:11:04 +0530512 return ret;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700513 }
514 di->chip_id = val & DIE_ID;
515 /* Get chip revision */
Axel Lina69929c2019-04-19 08:58:23 +0800516 ret = regmap_read(regmap, FAN53555_ID2, &val);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700517 if (ret < 0) {
518 dev_err(&client->dev, "Failed to get chip Rev!\n");
Sachin Kamat145fe1e2014-02-18 16:11:04 +0530519 return ret;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700520 }
521 di->chip_rev = val & DIE_REV;
522 dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n",
523 di->chip_id, di->chip_rev);
524 /* Device init */
525 ret = fan53555_device_setup(di, pdata);
526 if (ret < 0) {
527 dev_err(&client->dev, "Failed to setup device!\n");
528 return ret;
529 }
530 /* Register regulator */
531 config.dev = di->dev;
532 config.init_data = di->regulator;
Axel Lina69929c2019-04-19 08:58:23 +0800533 config.regmap = regmap;
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700534 config.driver_data = di;
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200535 config.of_node = np;
536
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700537 ret = fan53555_regulator_register(di, &config);
538 if (ret < 0)
539 dev_err(&client->dev, "Failed to register regulator!\n");
540 return ret;
541
542}
543
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700544static const struct i2c_device_id fan53555_id[] = {
Heiko Stuebneree309282014-09-16 21:22:54 +0200545 {
Bjorn Anderssonf2a9eb92019-02-20 16:43:03 -0800546 .name = "fan53526",
547 .driver_data = FAN53526_VENDOR_FAIRCHILD
548 }, {
Heiko Stuebneree309282014-09-16 21:22:54 +0200549 .name = "fan53555",
550 .driver_data = FAN53555_VENDOR_FAIRCHILD
551 }, {
Guillaume Tuckerfc1111b2017-08-21 13:47:43 +0100552 .name = "syr827",
553 .driver_data = FAN53555_VENDOR_SILERGY
554 }, {
555 .name = "syr828",
Heiko Stuebneree309282014-09-16 21:22:54 +0200556 .driver_data = FAN53555_VENDOR_SILERGY
557 },
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700558 { },
559};
Javier Martinez Canillase80c47b2015-07-30 18:18:40 +0200560MODULE_DEVICE_TABLE(i2c, fan53555_id);
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700561
562static struct i2c_driver fan53555_regulator_driver = {
563 .driver = {
564 .name = "fan53555-regulator",
Heiko Stuebner91f23d82014-09-16 21:22:53 +0200565 .of_match_table = of_match_ptr(fan53555_dt_ids),
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700566 },
567 .probe = fan53555_regulator_probe,
Yunfan Zhang49d8c592012-09-08 03:52:18 -0700568 .id_table = fan53555_id,
569};
570
571module_i2c_driver(fan53555_regulator_driver);
572
573MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>");
574MODULE_DESCRIPTION("FAN53555 regulator driver");
575MODULE_LICENSE("GPL v2");