Skip to content

Commit 914df8f

Browse files
JosephChen2017broonie
authored andcommitted
regulator: fan53555: Add TCS4525 DCDC support
TCS4525 main features: - 2.7V to 5.5V Input Voltage Range; - 3MHz Constant Switching Frequency; - 5A Available Load Current; - Programmable Output Voltage: 0.6V to 1.4V in 6.25mV Steps; - PFM/PWM Operation for Optimum Increased Efficiency; Signed-off-by: Joseph Chen <chenjh@rock-chips.com> [Ezequiel: Forward port] Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com> Link: https://lore.kernel.org/r/20210421210338.43819-3-ezequiel@collabora.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 3007acc commit 914df8f

1 file changed

Lines changed: 122 additions & 14 deletions

File tree

drivers/regulator/fan53555.c

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
/* Voltage setting */
2525
#define FAN53555_VSEL0 0x00
2626
#define FAN53555_VSEL1 0x01
27+
28+
#define TCS4525_VSEL0 0x11
29+
#define TCS4525_VSEL1 0x10
30+
#define TCS4525_TIME 0x13
31+
#define TCS4525_COMMAND 0x14
32+
2733
/* Control register */
2834
#define FAN53555_CONTROL 0x02
2935
/* IC Type */
@@ -49,11 +55,20 @@
4955

5056
#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
5157
#define FAN53526_NVOLTAGES 128
58+
#define TCS4525_NVOLTAGES 127 /* Numbers of voltages */
59+
60+
#define TCS_VSEL_NSEL_MASK 0x7f
61+
#define TCS_VSEL0_MODE (1 << 7)
62+
#define TCS_VSEL1_MODE (1 << 6)
63+
64+
#define TCS_SLEW_SHIFT 3
65+
#define TCS_SLEW_MASK (0x3 < 3)
5266

5367
enum fan53555_vendor {
5468
FAN53526_VENDOR_FAIRCHILD = 0,
5569
FAN53555_VENDOR_FAIRCHILD,
5670
FAN53555_VENDOR_SILERGY,
71+
FAN53555_VENDOR_TCS,
5772
};
5873

5974
enum {
@@ -106,6 +121,11 @@ struct fan53555_device_info {
106121
unsigned int mode_mask;
107122
/* Sleep voltage cache */
108123
unsigned int sleep_vol_cache;
124+
/* Slew rate */
125+
unsigned int slew_reg;
126+
unsigned int slew_mask;
127+
unsigned int slew_shift;
128+
unsigned int slew_rate;
109129
};
110130

111131
static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV)
@@ -189,13 +209,37 @@ static const int slew_rates[] = {
189209
500,
190210
};
191211

212+
static const int tcs_slew_rates[] = {
213+
18700,
214+
9300,
215+
4600,
216+
2300,
217+
};
218+
192219
static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp)
193220
{
194221
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
195222
int regval = -1, i;
223+
const int *slew_rate_t;
224+
int slew_rate_n;
196225

197-
for (i = 0; i < ARRAY_SIZE(slew_rates); i++) {
198-
if (ramp <= slew_rates[i])
226+
switch (di->vendor) {
227+
case FAN53526_VENDOR_FAIRCHILD:
228+
case FAN53555_VENDOR_FAIRCHILD:
229+
case FAN53555_VENDOR_SILERGY:
230+
slew_rate_t = slew_rates;
231+
slew_rate_n = ARRAY_SIZE(slew_rates);
232+
break;
233+
case FAN53555_VENDOR_TCS:
234+
slew_rate_t = tcs_slew_rates;
235+
slew_rate_n = ARRAY_SIZE(tcs_slew_rates);
236+
break;
237+
default:
238+
return -EINVAL;
239+
}
240+
241+
for (i = 0; i < slew_rate_n; i++) {
242+
if (ramp <= slew_rate_t[i])
199243
regval = i;
200244
else
201245
break;
@@ -206,8 +250,8 @@ static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp)
206250
return -EINVAL;
207251
}
208252

209-
return regmap_update_bits(rdev->regmap, FAN53555_CONTROL,
210-
CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT);
253+
return regmap_update_bits(rdev->regmap, di->slew_reg,
254+
di->slew_mask, regval << di->slew_shift);
211255
}
212256

213257
static const struct regulator_ops fan53555_regulator_ops = {
@@ -292,7 +336,9 @@ static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
292336
"Chip ID %d not supported!\n", di->chip_id);
293337
return -EINVAL;
294338
}
295-
339+
di->slew_reg = FAN53555_CONTROL;
340+
di->slew_mask = CTL_SLEW_MASK;
341+
di->slew_shift = CTL_SLEW_SHIFT;
296342
di->vsel_count = FAN53555_NVOLTAGES;
297343

298344
return 0;
@@ -312,12 +358,29 @@ static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
312358
"Chip ID %d not supported!\n", di->chip_id);
313359
return -EINVAL;
314360
}
315-
361+
di->slew_reg = FAN53555_CONTROL;
362+
di->slew_reg = FAN53555_CONTROL;
363+
di->slew_mask = CTL_SLEW_MASK;
364+
di->slew_shift = CTL_SLEW_SHIFT;
316365
di->vsel_count = FAN53555_NVOLTAGES;
317366

318367
return 0;
319368
}
320369

370+
static int fan53555_voltages_setup_tcs(struct fan53555_device_info *di)
371+
{
372+
di->slew_reg = TCS4525_TIME;
373+
di->slew_mask = TCS_SLEW_MASK;
374+
di->slew_shift = TCS_SLEW_MASK;
375+
376+
/* Init voltage range and step */
377+
di->vsel_min = 600000;
378+
di->vsel_step = 6250;
379+
di->vsel_count = TCS4525_NVOLTAGES;
380+
381+
return 0;
382+
}
383+
321384
/* For 00,01,03,05 options:
322385
* VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V.
323386
* For 04 option:
@@ -329,17 +392,41 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
329392
int ret = 0;
330393

331394
/* 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;
395+
switch (di->vendor) {
396+
case FAN53526_VENDOR_FAIRCHILD:
397+
case FAN53555_VENDOR_FAIRCHILD:
398+
case FAN53555_VENDOR_SILERGY:
399+
switch (pdata->sleep_vsel_id) {
400+
case FAN53555_VSEL_ID_0:
401+
di->sleep_reg = FAN53555_VSEL0;
402+
di->vol_reg = FAN53555_VSEL1;
403+
break;
404+
case FAN53555_VSEL_ID_1:
405+
di->sleep_reg = FAN53555_VSEL1;
406+
di->vol_reg = FAN53555_VSEL0;
407+
break;
408+
default:
409+
dev_err(di->dev, "Invalid VSEL ID!\n");
410+
return -EINVAL;
411+
}
336412
break;
337-
case FAN53555_VSEL_ID_1:
338-
di->sleep_reg = FAN53555_VSEL1;
339-
di->vol_reg = FAN53555_VSEL0;
413+
case FAN53555_VENDOR_TCS:
414+
switch (pdata->sleep_vsel_id) {
415+
case FAN53555_VSEL_ID_0:
416+
di->sleep_reg = TCS4525_VSEL0;
417+
di->vol_reg = TCS4525_VSEL1;
418+
break;
419+
case FAN53555_VSEL_ID_1:
420+
di->sleep_reg = TCS4525_VSEL1;
421+
di->vol_reg = TCS4525_VSEL0;
422+
break;
423+
default:
424+
dev_err(di->dev, "Invalid VSEL ID!\n");
425+
return -EINVAL;
426+
}
340427
break;
341428
default:
342-
dev_err(di->dev, "Invalid VSEL ID!\n");
429+
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
343430
return -EINVAL;
344431
}
345432

@@ -362,6 +449,18 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
362449
di->mode_reg = di->vol_reg;
363450
di->mode_mask = VSEL_MODE;
364451
break;
452+
case FAN53555_VENDOR_TCS:
453+
di->mode_reg = TCS4525_COMMAND;
454+
455+
switch (pdata->sleep_vsel_id) {
456+
case FAN53555_VSEL_ID_0:
457+
di->mode_mask = TCS_VSEL1_MODE;
458+
break;
459+
case FAN53555_VSEL_ID_1:
460+
di->mode_mask = TCS_VSEL0_MODE;
461+
break;
462+
}
463+
break;
365464
default:
366465
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
367466
return -EINVAL;
@@ -378,6 +477,9 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
378477
case FAN53555_VENDOR_SILERGY:
379478
ret = fan53555_voltages_setup_silergy(di);
380479
break;
480+
case FAN53555_VENDOR_TCS:
481+
ret = fan53555_voltages_setup_tcs(di);
482+
break;
381483
default:
382484
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
383485
return -EINVAL;
@@ -449,6 +551,9 @@ static const struct of_device_id __maybe_unused fan53555_dt_ids[] = {
449551
}, {
450552
.compatible = "silergy,syr828",
451553
.data = (void *)FAN53555_VENDOR_SILERGY,
554+
}, {
555+
.compatible = "tcs,tcs4525",
556+
.data = (void *)FAN53555_VENDOR_TCS
452557
},
453558
{ }
454559
};
@@ -554,6 +659,9 @@ static const struct i2c_device_id fan53555_id[] = {
554659
}, {
555660
.name = "syr828",
556661
.driver_data = FAN53555_VENDOR_SILERGY
662+
}, {
663+
.name = "tcs4525",
664+
.driver_data = FAN53555_VENDOR_TCS
557665
},
558666
{ },
559667
};

0 commit comments

Comments
 (0)