2 * Copyright (C) 2013 Spreadtrum Communications Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 * Bug#183980 add dcdc and pll enable time
17 * Change-Id: I6e6e06ee0beb306cd846964d0ba24aef449e5beb
19 * Bug#164001 add dcdc mem/gen/wpa/wrf map
20 * Change-Id: I07dac5700c0907aca99f6112bd4b5799358a9a88
22 * Bug#164001 shark dcam: add camera ldo calibration
23 * Change-Id: Icaee2706b8b0985ae6f3122b236d8e278dcc0db2
25 * sc8830: fix adc cal data from cmdline fail
26 * Change-Id: Id85d58178aca40fdf13b996853711e92e1171801
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/version.h>
36 #include <linux/spinlock.h>
37 #include <linux/debugfs.h>
38 #include <linux/slab.h>
39 #include <linux/sort.h>
40 #include <linux/delay.h>
41 #include <linux/err.h>
43 #include <linux/platform_device.h>
46 #include <linux/of_device.h>
47 #include <linux/of_address.h>
48 #include <linux/regulator/of_regulator.h>
50 #include <linux/regulator/consumer.h>
51 #include <linux/regulator/driver.h>
52 #include <linux/regulator/machine.h>
54 #include <soc/sprd/hardware.h>
55 #include <soc/sprd/sci.h>
56 #include <soc/sprd/sci_glb_regs.h>
57 #include <soc/sprd/adi.h>
58 #include <soc/sprd/adc.h>
59 #include <soc/sprd/arch_misc.h>
61 #define REGULATOR_ROOT_DIR "sprd-regulator"
64 #define debug(format, arg...) pr_info("regu: " "@@@%s: " format, __func__, ## arg)
65 #define debug0(format, arg...) //pr_debug("regu: " "@@@%s: " format, __func__, ## arg)
66 #define debug2(format, arg...) pr_debug("regu: " "@@@%s: " format, __func__, ## arg)
70 #define ANA_REG_OR(_r, _b) sci_adi_write(_r, _b, 0)
74 #define ANA_REG_BIC(_r, _b) sci_adi_write(_r, 0, _b)
78 #define ANA_REG_GET(_r) sci_adi_read(_r)
82 #define ANA_REG_SET(_r, _v, _m) sci_adi_write((_r), ((_v) & (_m)), (_m))
85 #define REGU_VERIFY_DLY (1000) /*ms */
87 struct sci_regulator_regs{
89 u32 pd_set, pd_set_bit;
91 * at new feature, some LDOs had only set, no rst bits.
92 * and DCDCs voltage and trimming controller is the same register
94 u32 pd_rst, pd_rst_bit;
95 u32 slp_ctl, slp_ctl_bit;
96 u32 vol_trm, vol_trm_bits;
97 u32 cal_ctl, cal_ctl_bits, cal_chan;
100 u32 vol_ctl, vol_ctl_bits;
105 struct sci_regulator_data {
106 struct regulator_dev *rdev;
109 struct sci_regulator_desc {
110 struct regulator_desc desc;
111 struct regulator_init_data *init_data;
112 struct sci_regulator_regs regs;
113 struct sci_regulator_data data; /* FIXME: dynamic */
114 #if defined(CONFIG_DEBUG_FS)
115 struct dentry *debugfs;
127 static struct sci_regulator_desc *sci_desc_list = NULL;
129 static atomic_t idx = ATOMIC_INIT(1); /* 0: dummy */
132 /*************************************************************************
133 Reg: 0x40038800 + 0x00E4
134 --------------------------------------------
135 BIT | FieldName | Description
136 --------------------------------------------
138 BIT6 BONDOPT6 28nm/40nm dcdccore/dcdcarm default voltage select:
139 0: dcdccore/dcdcarm = 1.1v, vdd25 = 2.5v
140 1: dcdccore/dcdcarm = 0.9v, vdd25 = 1.8v
141 BIT5 BONDOPT5 crystal 32k buffer select:
142 0: new low power 32k buffer output, 1: backup 32k buffer output
143 BIT4 BONDOPT4 dcdcwrf out voltage select: dcdc_wrf_ctl[2]
144 BIT3 BONDOPT3 charge mode option:
145 0: continues charging, 1: dcdc mode charging
146 BIT2 BONDOPT2 dcdcmem option 2: dcdc_mem_ctl[2]
147 BIT1 BONDOPT1 dcdcmem option 1: dcdc_mem_ctl[1]
152 BIT0 BONDOPT0 New power on reset option:
153 0: manual power on without hardware debounce
154 1: auto power on with 1s hardware debounce
155 **************************************************************************/
156 static u16 ana_status;
157 static u32 ana_chip_id;
159 static DEFINE_MUTEX(adc_chan_mutex);
160 extern int sci_efuse_get_cal(unsigned int * pdata, int num);
163 static struct sci_regulator_desc *__get_desc(struct regulator_dev *rdev)
165 return (struct sci_regulator_desc *)rdev->desc;
168 /* standard ldo ops*/
169 static int ldo_turn_on(struct regulator_dev *rdev)
171 struct sci_regulator_desc *desc = __get_desc(rdev);
172 struct sci_regulator_regs *regs = &desc->regs;
174 debug0("regu 0x%p (%s), set 0x%08x[%d], rst 0x%08x[%d]\n", regs,
175 desc->desc.name, regs->pd_set, __ffs(regs->pd_set_bit),
176 regs->pd_rst, __ffs(regs->pd_rst_bit));
179 ANA_REG_OR(regs->pd_rst, regs->pd_rst_bit);
182 ANA_REG_BIC(regs->pd_set, regs->pd_set_bit);
184 debug("regu 0x%p (%s), turn on\n", regs, desc->desc.name);
188 static int ldo_turn_off(struct regulator_dev *rdev)
190 struct sci_regulator_desc *desc = __get_desc(rdev);
191 struct sci_regulator_regs *regs = &desc->regs;
193 debug0("regu 0x%p (%s), set 0x%08x[%d], rst 0x%08x[%d]\n", regs,
194 desc->desc.name, regs->pd_set, __ffs(regs->pd_set_bit),
195 regs->pd_rst, __ffs(regs->pd_rst_bit));
197 #if !defined(CONFIG_REGULATOR_CAL_DUMMY)
199 ANA_REG_OR(regs->pd_set, regs->pd_set_bit);
202 ANA_REG_BIC(regs->pd_rst, regs->pd_rst_bit);
205 debug("regu 0x%p (%s), turn off\n", regs, desc->desc.name);
209 static int ldo_is_on(struct regulator_dev *rdev)
212 struct sci_regulator_desc *desc = __get_desc(rdev);
213 struct sci_regulator_regs *regs = &desc->regs;
215 debug0("regu 0x%p (%s), set 0x%08x[%d], rst 0x%08x[%d]\n", regs,
216 desc->desc.name, regs->pd_set, __ffs(regs->pd_set_bit),
217 regs->pd_rst, __ffs(regs->pd_rst_bit));
219 if (regs->pd_rst && regs->pd_set) {
220 /*for pd_rst has higher prioty than pd_set, what's more, their reset values are the same, 0 */
221 ret = ! !(ANA_REG_GET(regs->pd_rst) & regs->pd_rst_bit);
222 /* FIXME: when reset, pd_set & pd_rst are all zero, always get here */
223 if (ret == ! !(ANA_REG_GET(regs->pd_set) & regs->pd_set_bit))
225 } else if (regs->pd_rst) {
226 ret = ! !(ANA_REG_GET(regs->pd_rst) & regs->pd_rst_bit);
227 } else if (regs->pd_set) { /* new feature */
228 ret = !(ANA_REG_GET(regs->pd_set) & regs->pd_set_bit);
231 debug2("regu 0x%p (%s) turn on, return %d\n", regs, desc->desc.name, ret);
235 static int ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
237 struct sci_regulator_desc *desc = __get_desc(rdev);
238 struct sci_regulator_regs *regs = &desc->regs;
240 debug("regu 0x%p (%s), slp 0x%08x[%d] mode %x\n", regs, desc->desc.name,
241 regs->slp_ctl, regs->slp_ctl_bit, mode);
246 if (mode == REGULATOR_MODE_STANDBY) { /* disable auto slp */
247 ANA_REG_BIC(regs->slp_ctl, regs->slp_ctl_bit);
249 ANA_REG_OR(regs->slp_ctl, regs->slp_ctl_bit);
255 static int ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
256 int max_uV, unsigned *selector)
258 struct sci_regulator_desc *desc = __get_desc(rdev);
259 struct sci_regulator_regs *regs = &desc->regs;
260 //int mv = min_uV / 1000;
262 int i, shft = __ffs(regs->vol_ctl_bits);
264 BUG_ON(regs->vol_sel_cnt > 4);
266 debug("regu 0x%p (%s) set voltage, %d(uV) %d(uV)\n", regs, desc->desc.name, min_uV, max_uV);
271 for (i = 0; i < regs->vol_sel_cnt; i++) {
272 if (regs->vol_sel[i] == min_uV) {
273 ANA_REG_SET(regs->vol_ctl,
276 //clear_bit(desc->desc.id, trimming_state);
282 WARN(0 != ret, "warning: regulator (%s) not support %d(uV)\n", desc->desc.name, min_uV);
286 static int ldo_get_voltage(struct regulator_dev *rdev)
288 struct sci_regulator_desc *desc = __get_desc(rdev);
289 struct sci_regulator_regs *regs = &desc->regs;
291 int i, shft = __ffs(regs->vol_ctl_bits);
293 debug0("regu 0x%p (%s), vol ctl 0x%08x, shft %d, mask 0x%08x\n",
294 regs, desc->desc.name, regs->vol_ctl, shft, regs->vol_ctl_bits);
299 BUG_ON(regs->vol_sel_cnt != 4);
300 i = ((ANA_REG_GET(regs->vol_ctl) & regs->vol_ctl_bits) >> shft);
302 vol = regs->vol_sel[i];
304 debug2("regu 0x%p (%s) get voltage %d(uV)\n", regs, desc->desc.name, vol);
309 /* FIXME: get dcdc cal offset config from uboot */
318 int regulator_default_get(const char con_id[])
320 #define PP_VOL_PARA ( 0x50005C20 ) /* assert in iram2 */
321 #define TO_IRAM2(_p_) ( SPRD_IRAM2_BASE + (u32)(_p_) - SPRD_IRAM2_PHYS )
322 #define IN_IRAM2(_p_) ( (u32)(_p_) >= SPRD_IRAM2_PHYS && (u32)(_p_) < SPRD_IRAM2_PHYS + SPRD_IRAM2_SIZE )
325 vol_para_t *pvol_para = (vol_para_t *)__raw_readl((void *)TO_IRAM2(PP_VOL_PARA));
327 if (!(IN_IRAM2(pvol_para)))
330 pvol_para = (vol_para_t *)TO_IRAM2(pvol_para);
332 if(strcmp((pvol_para)[0].name, "volpara_begin") || (0xfaed != (pvol_para)[0].ideal_vol))
335 while(0 != strcmp((pvol_para)[i++].name, "volpara_end")) {
336 if (0 == strcmp((pvol_para)[i].name, con_id)) {
337 debug("%s name %s, ideal_vol %d\n", __func__, (pvol_para)[i].name, (pvol_para)[i].ideal_vol);
338 return res = (pvol_para)[i].ideal_vol;
344 static int __init_trimming(struct regulator_dev *rdev)
346 struct sci_regulator_desc *desc = __get_desc(rdev);
347 struct sci_regulator_regs *regs = &desc->regs;
353 to_vol = regulator_default_get(desc->desc.name);
356 to_vol = regs->vol_def;
359 if (to_vol && rdev->desc->ops->get_voltage) {
360 ctl_vol = rdev->desc->ops->get_voltage(rdev);
361 rdev->constraints->uV_offset = ctl_vol - to_vol;//uV
362 debug("regu 0x%p (%s), uV offset %d\n", regs, desc->desc.name, rdev->constraints->uV_offset);
368 static int dcdc_get_trimming_step(struct regulator_dev *rdev, int to_vol)
370 struct sci_regulator_desc *desc = __get_desc(rdev);
371 struct sci_regulator_regs *regs = &desc->regs;
373 BUG_ON(!regs->step_uV);
375 return regs->step_uV;
378 static int dcdc_initial_value(struct sci_regulator_desc *desc)
380 return ((0 == strcmp(desc->desc.name, "vddmem")) ? 0x10 : 0);
383 static int __match_dcdc_vol(struct sci_regulator_regs *regs, u32 vol)
386 int ds, min_ds = 100 * 1000; /* uV, the max range of small voltage */
388 for (i = 0; i < regs->vol_sel_cnt; i++) {
389 ds = vol - regs->vol_sel[i];
390 if (ds >= 0 && ds < min_ds) {
397 if ((2 == regs->typ) && (j < 0)) {
398 for (i = 0; i < regs->vol_sel_cnt; i++) {
399 ds = abs(vol - regs->vol_sel[i]);
411 static int __dcdc_enable_time(struct regulator_dev *rdev, int old_vol)
413 int vol = rdev->desc->ops->get_voltage(rdev);
415 /* FIXME: for dcdc, each step (50mV) takes 10us */
416 int dly = (vol - old_vol) * 10 / (50 * 1000);
423 static int dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
424 int max_uV, unsigned *selector)
426 struct sci_regulator_desc *desc = __get_desc(rdev);
427 struct sci_regulator_regs *regs = &desc->regs;
429 //int mV = min_uV / 1000;
430 int old_vol = rdev->desc->ops->get_voltage(rdev);
432 debug0("regu 0x%p (%s) %d %d\n", regs, desc->desc.name, min_uV, max_uV);
434 //BUG_ON(0 != __ffs(regs->vol_trm_bits));
435 BUG_ON(regs->vol_sel_cnt > 8);
440 /* found the closely vol ctrl bits */
441 i = __match_dcdc_vol(regs, min_uV);
443 return WARN(-EINVAL, "not found %s closely ctrl bits for %d(uV)\n",
444 desc->desc.name, min_uV);
446 debug("regu 0x%p (%s) %d = %d %+duV\n", regs, desc->desc.name,
447 min_uV, regs->vol_sel[i], min_uV - regs->vol_sel[i]);
449 #if !defined(CONFIG_REGULATOR_CAL_DUMMY)
450 /* dcdc calibration control bits (default 00000),
451 * small adjust voltage: 100/32mv ~= 3.125mv
454 int shft_ctl = __ffs(regs->vol_ctl_bits);
455 int shft_trm = __ffs(regs->vol_trm_bits);
456 int j = (int)(min_uV - regs->vol_sel[i]) / dcdc_get_trimming_step(rdev, min_uV) % 32;
458 j += dcdc_initial_value(desc);
460 BUG_ON(j > (regs->vol_trm_bits >> shft_trm));
462 if (regs->vol_trm == regs->vol_ctl) { /* new feature */
463 ANA_REG_SET(regs->vol_ctl, (j << shft_trm) | (i << shft_ctl),
464 regs->vol_trm_bits | regs->vol_ctl_bits);
466 if (regs->vol_trm) { /* small adjust first */
467 ANA_REG_SET(regs->vol_trm, j << shft_trm,
472 ANA_REG_SET(regs->vol_ctl, i << shft_ctl,
478 __dcdc_enable_time(rdev, old_vol);
484 static int dcdc_get_voltage(struct regulator_dev *rdev)
486 struct sci_regulator_desc *desc = __get_desc(rdev);
487 struct sci_regulator_regs *regs = &desc->regs;
489 int i, cal = 0 /* uV */;
490 int shft_ctl = __ffs(regs->vol_ctl_bits);
491 int shft_trm = __ffs(regs->vol_trm_bits);
493 debug0("regu 0x%p (%s), vol ctl 0x%08x, shft %d, mask 0x%08x, sel %d\n",
494 regs, desc->desc.name, regs->vol_ctl,
495 shft_ctl, regs->vol_ctl_bits, regs->vol_sel_cnt);
500 //BUG_ON(0 != shft_trm);
501 BUG_ON(regs->vol_sel_cnt > 8);
503 i = (ANA_REG_GET(regs->vol_ctl) & regs->vol_ctl_bits) >> shft_ctl;
505 uV = regs->vol_sel[i];
508 cal = (ANA_REG_GET(regs->vol_trm) & regs->vol_trm_bits) >> shft_trm;
509 cal -= dcdc_initial_value(desc);
510 cal *= dcdc_get_trimming_step(rdev, 0); /*uV */
513 debug2("regu 0x%p (%s) %d +%duv\n", regs, desc->desc.name, uV, cal);
515 return (uV + cal) /*uV */;
519 /* standard boost ops*/
520 #define MAX_CURRENT_SINK (500) /*FIXME: max current sink */
521 static int boost_set_current_limit(struct regulator_dev *rdev, int min_uA,
524 struct sci_regulator_desc *desc = __get_desc(rdev);
525 struct sci_regulator_regs *regs = &desc->regs;
526 int ma = min_uA / 1000;
528 int i, shft = __ffs(regs->vol_ctl_bits);
529 int trim = (int)regs->vol_def / (1000 * 1000);
530 int steps = (regs->vol_ctl_bits >> shft) + 1;
532 debug("regu 0x%p (%s) %d %d\n", regs, desc->desc.name, min_uA, max_uA);
538 trim <<= __ffs(regs->vol_trm_bits);
541 i = ma * steps / MAX_CURRENT_SINK;
542 if (i >= 0 && i < steps) {
543 ANA_REG_SET(regs->vol_ctl, (i << shft) | trim,
544 regs->vol_ctl_bits | regs->vol_trm_bits);
550 "warning: regulator (%s) not support %dmA\n", desc->desc.name, ma);
556 static int boost_get_current_limit(struct regulator_dev *rdev)
558 struct sci_regulator_desc *desc = __get_desc(rdev);
559 struct sci_regulator_regs *regs = &desc->regs;
561 int i, shft = __ffs(regs->vol_ctl_bits);
562 int steps = (regs->vol_ctl_bits >> shft) + 1;
564 debug0("regu 0x%p (%s), vol ctl 0x%08x, shft %d, mask 0x%08x\n",
565 regs, desc->desc.name, regs->vol_ctl, shft, regs->vol_ctl_bits);
570 i = ((ANA_REG_GET(regs->vol_ctl) & regs->vol_ctl_bits) >> shft);
571 cur = i * MAX_CURRENT_SINK / steps;
572 debug("regu 0x%p (%s) get current %d\n", regs, desc->desc.name, cur);
576 static int adc_sample_bit = 1; /*12bits mode */
577 static short adc_data[3][2]
578 #if defined(CONFIG_REGULATOR_ADC_DEBUG)
580 {4200, 3320}, /* same as nv adc_t */
582 {400, 316}, /* 0.4@VBAT, Reserved IdealC Value */
587 static int __is_valid_adc_cal(void)
589 return 0 != adc_data[0][0];
592 static int __init __adc_cal_setup(char *str)
594 u32 *p = (u32 *) adc_data;
595 *p = simple_strtoul(str, &str, 0);
597 if (*p++ && *++str) {
598 *p = simple_strtoul(str, &str, 0);
600 debug("%d : %d -- %d : %d\n",
601 (int)adc_data[0][0], (int)adc_data[0][1],
602 (int)adc_data[1][0], (int)adc_data[1][1]);
603 if (adc_data[0][1] < BIT(10)
604 && adc_data[1][1] < BIT(10))
605 adc_sample_bit = 0; /*10bits mode */
610 early_param("adc_cal", __adc_cal_setup);
612 static int __init __adc_cal_fuse_setup(void)
614 if (!__is_valid_adc_cal() &&
615 (0 == sci_efuse_get_cal((u32 *) adc_data, 2))) {
616 debug("%d : %d -- %d : %d\n",
617 (int)adc_data[0][0], (int)adc_data[0][1],
618 (int)adc_data[1][0], (int)adc_data[1][1]);
623 static int __adc2vbat(int adc_res)
625 int t = adc_data[0][0] - adc_data[1][0];
626 t *= (adc_res - adc_data[0][1]);
627 t /= (adc_data[0][1] - adc_data[1][1]);
632 #define MEASURE_TIMES (15)
634 static void __dump_adc_result(u32 adc_val[])
636 #if defined(CONFIG_REGULATOR_ADC_DEBUG)
638 for (i = 0; i < MEASURE_TIMES; i++) {
639 printk("%d ", adc_val[i]);
645 static int cmp_val(const void *a, const void *b)
647 return *(int *)a - *(int *)b;
651 * __adc_voltage - get regulator output voltage through auxadc
652 * @regulator: regulator source
654 * This returns the current regulator voltage in mV.
656 * NOTE: If the regulator is disabled it will return the voltage value. This
657 * function should not be used to determine regulator state.
659 static int regu_adc_voltage(struct regulator_dev *rdev)
661 struct sci_regulator_desc *desc = __get_desc(rdev);
662 struct sci_regulator_regs *regs = &desc->regs;
664 int ret, adc_chan = regs->cal_chan;
665 u16 ldo_cal_sel = regs->cal_ctl_bits & 0xFFFF;
666 u32 adc_res, adc_val[MEASURE_TIMES];
667 u32 chan_numerators = 1, chan_denominators = 1;
668 u32 bat_numerators, bat_denominators;
670 struct adc_sample_data data = {
671 .channel_id = adc_chan,
672 .channel_type = 0, /*sw */
673 .hw_channel_delay = 0, /*reserved */
674 .scale = 1, /*big scale */
676 .sample_num = MEASURE_TIMES,
677 .sample_bits = adc_sample_bit,
678 .sample_speed = 0, /*quick mode */
679 .signal_mode = 0, /*resistance path */
682 if (!__is_valid_adc_cal())
688 /* enable ldo cal before adc sampling and ldo calibration */
690 mutex_lock(&adc_chan_mutex);
691 ANA_REG_OR(regs->cal_ctl, ldo_cal_sel);
692 debug0("%s adc channel %d : %04x\n",
693 desc->desc.name, data.channel_id, ldo_cal_sel);
696 ret = sci_adc_get_values(&data);
699 /* close ldo cal and release multiplexed aux adc channel */
701 ANA_REG_BIC(regs->cal_ctl, ldo_cal_sel);
702 mutex_unlock(&adc_chan_mutex);
705 __dump_adc_result(adc_val);
706 sort(adc_val, MEASURE_TIMES, sizeof(u32), cmp_val, 0);
707 /*__dump_adc_result(adc_val);*/
709 sci_adc_get_vol_ratio(data.channel_id, data.scale,
710 &chan_numerators, &chan_denominators);
712 sci_adc_get_vol_ratio(ADC_CHANNEL_VBAT, 0, &bat_numerators, &bat_denominators);
714 adc_res = adc_val[MEASURE_TIMES / 2];
715 debug("%s adc channel %d : 0x%04x, ratio (%d/%d), result value %d\n",
716 desc->desc.name, data.channel_id, ldo_cal_sel,
717 chan_numerators, chan_denominators, adc_res);
722 return __adc2vbat(adc_res)
723 * (bat_numerators * chan_denominators)
724 / (bat_denominators * chan_numerators);
727 #ifndef CONFIG_REGULATOR_SC2713
729 * regulator_strongly_disable - strongly disable regulator output
730 * @regulator: regulator source
732 * Strongly try disable the regulator output voltage or current.
733 * NOTE: this *will* disable the regulator output even if other consumer
734 * devices have it enabled. This should be used for situations when device
735 * had unbalanced with calls to regulator_enable().
736 * *Not* recommended to call this function before try to balance the use_count.
738 int regulator_strongly_disable(struct regulator *regulator)
740 struct regulator_dev *rdev = regulator_get_drvdata(regulator);
744 while (rdev->use_count--)
745 regulator_disable(regulator);
750 EXPORT_SYMBOL_GPL(regulator_strongly_disable);
753 static struct regulator_ops ldo_ops = {
754 .enable = ldo_turn_on,
755 .disable = ldo_turn_off,
756 .is_enabled = ldo_is_on,
757 .set_voltage = ldo_set_voltage,
758 .get_voltage = ldo_get_voltage,
759 .set_mode = ldo_set_mode,
760 /* .enable_time = ldo_enable_time, */
764 static struct regulator_ops dcdc_ops = {
765 .enable = ldo_turn_on,
766 .disable = ldo_turn_off,
767 .is_enabled = ldo_is_on,
768 .set_voltage = dcdc_set_voltage,
769 .get_voltage = dcdc_get_voltage,
772 static struct regulator_ops boost_ops = {
773 .enable = ldo_turn_on,
774 .disable = ldo_turn_off,
775 .is_enabled = ldo_is_on,
776 .set_current_limit = boost_set_current_limit,
777 .get_current_limit = boost_get_current_limit,
778 .set_mode = ldo_set_mode,
783 * Consider the following machine :-
785 * Regulator-1 -+-> [Consumer A @ 1.8V]
787 * +-> [Consumer B @ 1.8V]
789 * Regulator-2 ---> [Consumer C @ 3.3V]
791 * The drivers for consumers A & B must be mapped to the correct regulator in
792 * order to control their power supply. This mapping can be achieved in board/machine
793 * initialisation code by creating a struct regulator_consumer_supply for each regulator.
794 * Alternatively, we built a regulator supply-consumers map, the format is as follow:
796 * supply source-1, consumer A, consumer B, ..., NULL
797 * supply source-2, consumer C, ..., NULL
802 static struct regulator_consumer_supply *set_supply_map(struct device *dev,
803 const char *supply_name,
806 char **map = (char **)dev_get_platdata(dev);
808 struct regulator_consumer_supply *consumer_supplies = NULL;
810 if (!supply_name || !(map && map[0]))
813 for (i = 0; map[i] || map[i + 1]; i++) {
814 if (map[i] && 0 == strcmp(map[i], supply_name))
818 /* i++; *//* Do not skip supply name */
820 for (n = 0; map[i + n]; n++) ;
823 debug0("supply %s consumers %d - %d\n", supply_name, i, n);
825 kzalloc(n * sizeof(*consumer_supplies), GFP_KERNEL);
826 BUG_ON(!consumer_supplies);
827 for (n = 0; map[i]; i++, n++) {
828 consumer_supplies[n].supply = map[i];
833 return consumer_supplies;
836 #if defined(CONFIG_DEBUG_FS)
837 static struct dentry *debugfs_root = NULL;
839 static u32 ana_addr = 0;
840 static int debugfs_ana_addr_get(void *data, u64 * val)
842 if (ana_addr < PAGE_SIZE) {
843 *val = ANA_REG_GET(ana_addr + (ANA_REGS_GLB_BASE & PAGE_MASK));
845 void *addr = ioremap(ana_addr, PAGE_SIZE);
846 *val = __raw_readl(addr);
852 static int debugfs_ana_addr_set(void *data, u64 val)
854 if (ana_addr < PAGE_SIZE) {
855 ANA_REG_SET(ana_addr + (ANA_REGS_GLB_BASE & PAGE_MASK), val, -1);
857 void *addr = ioremap(ana_addr, PAGE_SIZE);
858 __raw_writel(val, addr);
864 static int adc_chan = 5 /*VBAT*/;
865 static int debugfs_adc_chan_get(void *pdata, u64 * val)
868 u32 adc_res, adc_val[MEASURE_TIMES];
869 struct adc_sample_data data = {
870 .channel_id = adc_chan,
871 .channel_type = 0, /*sw */
872 .hw_channel_delay = 0, /*reserved */
873 .scale = 1, /*big scale */
875 .sample_num = MEASURE_TIMES,
876 .sample_bits = adc_sample_bit,
877 .sample_speed = 0, /*quick mode */
878 .signal_mode = 0, /*resistance path */
881 ret = sci_adc_get_values(&data);
884 for (i = 0; i < MEASURE_TIMES; i++) {
885 printk("%d ", adc_val[i]);
889 sort(adc_val, MEASURE_TIMES, sizeof(u32), cmp_val, 0);
890 adc_res = adc_val[MEASURE_TIMES / 2];
891 pr_info("adc chan %d, result value %d, vbat %d\n",
892 data.channel_id, adc_res, __adc2vbat(adc_res));
897 static int debugfs_adc_chan_set(void *data, u64 val)
903 static int debugfs_enable_get(void *data, u64 * val)
905 struct regulator_dev *rdev = data;
906 if (rdev && rdev->desc->ops->is_enabled)
907 *val = rdev->desc->ops->is_enabled(rdev);
913 static int debugfs_enable_set(void *data, u64 val)
915 struct regulator_dev *rdev = data;
916 if (rdev && rdev->desc->ops->enable)
917 (val) ? rdev->desc->ops->enable(rdev)
918 : rdev->desc->ops->disable(rdev);
922 static int debugfs_voltage_get(void *data, u64 * val)
924 struct regulator_dev *rdev = data;
926 *val = regu_adc_voltage(rdev);
932 static int debugfs_voltage_set(void *data, u64 val)
934 struct regulator_dev *rdev = data;
935 if (rdev && rdev->desc->ops->set_voltage) {
936 u32 min_uV = (u32)val * 1000;
937 min_uV += rdev->constraints->uV_offset;
938 rdev->desc->ops->set_voltage(rdev, min_uV, min_uV, 0);
944 static int debugfs_boost_get(void *data, u64 * val)
946 struct regulator_dev *rdev = data;
947 if (rdev && rdev->desc->ops->get_current_limit)
948 *val = rdev->desc->ops->get_current_limit(rdev) / 1000;
954 static int debugfs_boost_set(void *data, u64 val)
956 struct regulator_dev *rdev = data;
957 if (rdev && rdev->desc->ops->set_current_limit)
958 rdev->desc->ops->set_current_limit(rdev, val * 1000,
963 DEFINE_SIMPLE_ATTRIBUTE(fops_ana_addr,
964 debugfs_ana_addr_get, debugfs_ana_addr_set, "%llu\n");
965 DEFINE_SIMPLE_ATTRIBUTE(fops_adc_chan,
966 debugfs_adc_chan_get, debugfs_adc_chan_set, "%llu\n");
967 DEFINE_SIMPLE_ATTRIBUTE(fops_enable,
968 debugfs_enable_get, debugfs_enable_set, "%llu\n");
969 DEFINE_SIMPLE_ATTRIBUTE(fops_ldo,
970 debugfs_voltage_get, debugfs_voltage_set, "%llu\n");
971 DEFINE_SIMPLE_ATTRIBUTE(fops_boost,
972 debugfs_boost_get, debugfs_boost_set, "%llu\n");
974 static void rdev_init_debugfs(struct regulator_dev *rdev)
976 struct sci_regulator_desc *desc = __get_desc(rdev);
977 desc->debugfs = debugfs_create_dir(rdev->desc->name, debugfs_root);
978 if (IS_ERR_OR_NULL(rdev->debugfs)) {
979 pr_warn("Failed to create debugfs directory\n");
980 rdev->debugfs = NULL;
984 debugfs_create_file("enable", S_IRUGO | S_IWUSR,
985 desc->debugfs, rdev, &fops_enable);
987 if (desc->desc.type == REGULATOR_CURRENT)
988 debugfs_create_file("current", S_IRUGO | S_IWUSR,
989 desc->debugfs, rdev, &fops_boost);
991 debugfs_create_file("voltage", S_IRUGO | S_IWUSR,
992 desc->debugfs, rdev, &fops_ldo);
995 static void rdev_init_debugfs(struct regulator_dev *rdev)
1001 static inline int __strcmp(const char *cs, const char *ct)
1006 return strcmp(cs, ct);
1009 static struct of_device_id sprd_regulator_of_match[] = {
1010 { .compatible = "sprd,sc2713s-regulator", },
1013 //MODULE_DEVICE_TABLE(of, sprd_regulator_of_match);
1015 #undef REGS_ANA_GLB_BASE
1016 #ifndef REGS_ANA_GLB_BASE
1017 #define REGS_ANA_GLB_PHYS (SPRD_ADI_PHYS + 0x8800)
1018 #define REGS_ANA_GLB_BASE (SPRD_ADI_BASE + 0x8800)
1019 #define REGS_ANA_GLB_SIZE (SZ_2K) //0x40038800 ~ 0x40039000
1022 #define IS_VALID_ANA_ADDR(pa, pa_base, size) ( (pa) >= (pa_base) && (pa) < (pa_base) + (size) )
1023 #define PHY_TO_VIR(pa, pa_base, va_base) ( (pa) - (pa_base) + (va_base) )
1025 static u32 phy2vir(const u32 reg_phy)
1032 if (IS_VALID_ANA_ADDR(reg_phy, REGS_ANA_GLB_PHYS, REGS_ANA_GLB_SIZE)) {
1033 reg_vir = (u32)(PHY_TO_VIR(reg_phy, REGS_ANA_GLB_PHYS, REGS_ANA_GLB_BASE));
1035 WARN(1, "reg(0x%08x) physical address is invalid!\n", reg_phy);
1041 static int reconfig_regulator(struct sci_regulator_desc *desc)
1043 struct sci_regulator_regs *regs = &desc->regs;
1045 /* Fixme: Config dynamically dcdc/ldo
1046 * accoring to bit BONDOPT4 & BONDOPT6 for Reg(0x40038800 + 0x00E4)
1050 if ((ana_status >> 6) & 0x1) {
1051 if (0 == strcmp(desc->desc.name, "vddcore")) {
1052 regs->vol_def = 900;
1053 regs->vol_ctl = (u32)ANA_REG_GLB_MP_MISC_CTRL;
1054 regs->vol_ctl_bits = BIT(3)|BIT(4)|BIT(5);
1055 } else if (0 == strcmp(desc->desc.name, "vddarm")) {
1056 regs->vol_def = 900;
1057 regs->vol_ctl = (u32)ANA_REG_GLB_MP_MISC_CTRL;
1058 regs->vol_ctl_bits = BIT(6)|BIT(7)|BIT(8);
1059 } else if (0 == strcmp(desc->desc.name, "vdd25")) {
1060 regs->vol_def = 1800;
1061 regs->vol_ctl = (u32)ANA_REG_GLB_MP_MISC_CTRL;
1062 regs->vol_ctl_bits = BIT(9)|BIT(10);
1063 regs->vol_sel[0] = 2500;
1064 regs->vol_sel[1] = 2750;
1065 regs->vol_sel[2] = 1800;
1066 regs->vol_sel[3] = 1900;
1069 if (0 == strcmp(desc->desc.name, "vddcore")) {
1070 regs->vol_def = 1100;
1071 regs->vol_ctl = (u32)ANA_REG_GLB_DCDC_CORE_ADI;
1072 regs->vol_ctl_bits = BIT(5)|BIT(6)|BIT(7);
1073 } else if (0 == strcmp(desc->desc.name, "vddarm")) {
1074 regs->vol_def = 1100;
1075 regs->vol_ctl = (u32)ANA_REG_GLB_DCDC_ARM_ADI;
1076 regs->vol_ctl_bits = BIT(5)|BIT(6)|BIT(7);
1077 } else if (0 == strcmp(desc->desc.name, "vdd25")) {
1078 regs->vol_def = 2500;
1079 regs->vol_ctl = (u32)ANA_REG_GLB_LDO_V_CTRL0;
1080 regs->vol_ctl_bits = BIT(4)|BIT(5);
1081 regs->vol_sel[0] = 2500;
1082 regs->vol_sel[1] = 2750;
1083 regs->vol_sel[2] = 3000;
1084 regs->vol_sel[3] = 2900;
1089 if ((ana_status >> 4) & 0x1) {
1090 if (0 == strcmp(desc->desc.name, "vddwrf")) {
1091 regs->vol_def = 2800;
1092 regs->vol_sel[0] = 2600;
1093 regs->vol_sel[1] = 2700;
1094 regs->vol_sel[2] = 2800;
1095 regs->vol_sel[3] = 2900;
1096 } else if (0 == strcmp(desc->desc.name, "vddrf1")) {
1097 regs->vol_def = 2850;
1098 regs->vol_ctl = (u32)ANA_REG_GLB_LDO_V_CTRL0;
1099 regs->vol_ctl_bits = BIT(8)|BIT(9);
1102 if (0 == strcmp(desc->desc.name, "vddwrf")) {
1103 regs->vol_def = 1500;
1104 regs->vol_sel[0] = 1300;
1105 regs->vol_sel[1] = 1400;
1106 regs->vol_sel[2] = 1500;
1107 regs->vol_sel[3] = 1600;
1108 } else if (0 == strcmp(desc->desc.name, "vddrf1")) {
1109 regs->vol_def = 1200;
1110 regs->vol_ctl = (u32)ANA_REG_GLB_MP_MISC_CTRL;
1111 regs->vol_ctl_bits = BIT(11)|BIT(12);
1118 #define GET_CTL_BITS(bh, bl) ( ((1 << ((bh) - (bl) + 1)) - 1) << (bl) )
1120 static int of_regu_read_reg(struct device_node *np, int idx,
1121 struct sci_regulator_regs *regs)
1130 cell = of_get_property(np, "reg", &count);
1133 WARN_ON(idx >= count);
1135 cell = of_get_address(np, idx, NULL, NULL);
1138 case 0: /* ldo/dcdc power down */
1140 reg_phy = (u32)be32_to_cpu(*(cell++));
1141 regs->pd_set = phy2vir(reg_phy);
1142 regs->pd_set_bit = (u32)be32_to_cpu(*(cell++));
1143 debug0("reg(%s) pd_set phy addr: 0x%08x, vir addr: 0x%08x, msk: 0x%08x\n",
1144 np->name, reg_phy, regs->pd_set, regs->pd_set_bit);
1147 case 1: /* ldo/dcdc power reset */
1149 reg_phy = (u32)be32_to_cpu(*(cell++));
1150 regs->pd_rst = phy2vir(reg_phy);
1151 regs->pd_rst_bit = (u32)be32_to_cpu(*(cell++));
1152 debug0("reg(%s) pd_rst phy addr: 0x%08x, vir addr: 0x%08x, msk: 0x%08x\n",
1153 np->name, reg_phy, regs->pd_rst, regs->pd_rst_bit);
1156 case 2: /* ldo/dcdc auto sleep control */
1158 reg_phy = (u32)be32_to_cpu(*(cell++));
1159 regs->slp_ctl = phy2vir(reg_phy);
1160 regs->slp_ctl_bit = (u32)be32_to_cpu(*(cell++));
1161 debug0("reg(%s) slp_ctl phy addr: 0x%08x, vir addr: 0x%08x, msk: 0x%08x\n",
1162 np->name, reg_phy, regs->slp_ctl, regs->slp_ctl_bit);
1172 static int sci_regulator_parse_dt(struct platform_device *pdev,
1173 struct device_node *np, struct sci_regulator_desc *desc,
1174 struct regulator_consumer_supply *supply, int sz)
1176 struct sci_regulator_regs *regs = &desc->regs;
1180 int type = 0, cnt = 0, ret = 0;
1182 if(!pdev || !np || !desc || !supply) {
1186 desc->desc.name = np->name;
1187 desc->desc.id = (atomic_inc_return(&idx) - 1);
1188 desc->desc.type = REGULATOR_VOLTAGE;
1189 desc->desc.owner = THIS_MODULE;
1191 supply[0].dev_name = NULL;
1192 supply[0].supply = np->name;
1193 desc->init_data = of_get_regulator_init_data(&pdev->dev, np);
1194 if (!desc->init_data || 0 != __strcmp(desc->init_data->constraints.name, np->name)) {
1195 dev_err(&pdev->dev, "failed to parse regulator(%s) init data! \n", np->name);
1199 desc->init_data->supply_regulator = 0;
1200 desc->init_data->constraints.valid_modes_mask =
1201 REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY;
1202 desc->init_data->constraints.valid_ops_mask =
1203 REGULATOR_CHANGE_MODE | REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE;
1204 desc->init_data->num_consumer_supplies = sz;
1206 desc->init_data->consumer_supplies =
1207 set_supply_map(&pdev->dev, desc->desc.name,
1208 &desc->init_data->num_consumer_supplies);
1210 if (!desc->init_data->consumer_supplies)
1211 desc->init_data->consumer_supplies = supply;
1213 /* Fill struct sci_regulator_regs variable desc->regs */
1214 type = (of_property_read_bool(np, "dcdc") ? 2 : 0);
1217 of_regu_read_reg(np, 0, regs);
1218 of_regu_read_reg(np, 1, regs);
1219 of_regu_read_reg(np, 2, regs);
1221 regs->min_uV = desc->init_data->constraints.min_uV;
1223 //ret = of_property_read_u32(np, "regulator-min-microvolt", &desc->regs.vol_def);
1224 tmp = of_get_property(np, "regulator-min-microvolt", NULL);
1226 regs->vol_def = be32_to_cpu(*tmp);
1229 ret = of_property_read_u32(np, "regulator-step-microvolt", &tmp_val_u32);
1231 regs->step_uV = tmp_val_u32;
1233 ret = of_property_read_u32(np, "regulator-default-microvolt", &tmp_val_u32);
1235 regs->vol_def = tmp_val_u32;
1237 debug("[%d] %s type %d, range %d(uV) - %d(uV), step %d(uV), defult %d(uV)\n", (idx.counter - 1),
1238 np->name, type, desc->init_data->constraints.min_uV, desc->init_data->constraints.max_uV,
1239 regs->step_uV, regs->vol_def);
1241 tmp = of_get_property(np, "reg-vol", &cnt);
1243 debug0("prop reg-vol len %d\n", cnt);
1245 ret = of_property_read_u32_array(np, "reg-vol", data, cnt);
1247 regs->vol_ctl = phy2vir(data[0]);
1248 regs->vol_ctl_bits = data[1];
1249 regs->vol_trm = phy2vir(data[2]);
1250 regs->vol_trm_bits = data[3];
1253 debug0("vol_ctl (phyaddr: 0x%08x, vir addr: 0x%08x, msk: 0x%08x) \n",
1254 data[0], regs->vol_ctl, regs->vol_ctl_bits);
1256 debug0("vol_trm (phyaddr: 0x%08x, vir addr: 0x%08x, msk: 0x%08x)\n",
1257 data[2], regs->vol_trm, regs->vol_trm_bits);
1260 tmp = of_get_property(np, "regulator-cal-channel", &cnt);
1263 ret = of_property_read_u32_array(np, "regulator-cal-channel", data, cnt);
1265 regs->cal_ctl = phy2vir(data[0]);
1266 regs->cal_ctl_bits = data[1];
1267 regs->cal_chan = data[2];
1270 debug0("cal_ctl (phyaddr: 0x%08x, vir addr: 0x%08x, msk: 0x%08x, chan: %d)\n",
1271 data[0], regs->cal_ctl, regs->cal_ctl_bits, regs->cal_chan);
1274 tmp = of_get_property(np, "regulator-selects", &cnt);
1276 debug0("prop regulator-selects count(%d)\n", cnt);
1278 ret = of_property_read_u32_array(np, "regulator-selects", data, cnt);
1282 /* Dynamically allocate memory for voltage select array */
1283 regs->vol_sel = kzalloc(cnt * sizeof(*regs->vol_sel), GFP_KERNEL);
1284 if (!regs->vol_sel) {
1285 pr_err("%s() failed to allocate memory for voltage select\n", __func__);
1289 regs->vol_sel_cnt = cnt;
1290 for(i = 0; i < cnt; i++) {
1291 regs->vol_sel[i] = data[i];
1299 static int sci_regulator_register_dt(struct platform_device *pdev)
1301 struct sci_regulator_desc *sci_desc = NULL;
1303 struct regulator_dev *rdev;
1304 struct regulator_ops *__regs_ops[] = {
1305 &ldo_ops, 0, &dcdc_ops, 0 /*lpref_ops */ , &boost_ops, 0,
1307 struct regulator_consumer_supply consumer_supplies_default[1] = { };
1308 struct regulator_config config = { };
1310 struct device_node *dev_np = pdev->dev.of_node;
1311 struct device_node *child_np;
1312 int regu_cnt = 0, ret = 0;
1314 regu_cnt = of_get_child_count(dev_np);
1318 regu_cnt -= 1; /* exclude dummy node */
1320 sci_desc_list = devm_kzalloc(&pdev->dev, regu_cnt * sizeof(struct sci_regulator_desc), GFP_KERNEL);
1321 if (!sci_desc_list) {
1322 dev_err(&pdev->dev, "failed allocate memory for sci_regulator_desc list\n");
1325 sci_desc = sci_desc_list;
1327 debug("regulators desc list 0x%p, count %d, sci_regulator_desc size %d\n", sci_desc, regu_cnt, sizeof(struct sci_regulator_desc));
1329 for_each_child_of_node(dev_np, child_np) {
1330 if(0 == strcmp(child_np->name, "dummy")) /* skip dummy node */
1333 ret = sci_regulator_parse_dt(pdev, child_np, sci_desc, consumer_supplies_default, ARRAY_SIZE(consumer_supplies_default));
1335 dev_err(&pdev->dev, "failed to parse regulator(%s) dts\n", child_np->name);
1339 reconfig_regulator(sci_desc);
1341 BUG_ON(sci_desc->regs.pd_set
1342 && sci_desc->regs.pd_set == sci_desc->regs.pd_rst
1343 && sci_desc->regs.pd_set_bit == sci_desc->regs.pd_rst_bit);
1345 BUG_ON(sci_desc->regs.typ >= ARRAY_SIZE(__regs_ops));
1346 if (!sci_desc->desc.ops)
1347 sci_desc->desc.ops = __regs_ops[sci_desc->regs.typ];
1349 config.dev = &pdev->dev;
1350 config.init_data = sci_desc->init_data;
1351 config.driver_data = NULL;
1352 config.of_node = child_np;
1353 rdev = regulator_register(&sci_desc->desc, &config);
1355 debug0("regulator_desc 0x%p, rdev 0x%p\n", &sci_desc->desc, rdev);
1357 if (sci_desc->init_data->consumer_supplies != consumer_supplies_default)
1358 kfree(sci_desc->init_data->consumer_supplies);
1360 if (!IS_ERR_OR_NULL(rdev)) {
1361 rdev->reg_data = rdev;
1362 sci_desc->data.rdev = rdev;
1363 __init_trimming(rdev);
1364 rdev_init_debugfs(rdev);
1375 * spreadtrum power regulators is intergrated on the chip, include LDOs and DCDCs.
1376 * so i autogen all regulators non-variable description in plat or mach directory,
1377 * which named __xxxx_regulator_map.h, BUT register all in regulator driver probe func,
1378 * just like other regulator vendor drivers.
1380 static int sci_regulator_probe(struct platform_device *pdev)
1382 #ifdef CONFIG_DEBUG_FS
1384 debugfs_create_dir(REGULATOR_ROOT_DIR, NULL);
1385 if (IS_ERR_OR_NULL(debugfs_root)) {
1387 "%s: Failed to create debugfs directory\n", REGULATOR_ROOT_DIR);
1388 debugfs_root = NULL;
1391 debugfs_create_u32("ana_addr", S_IRUGO | S_IWUSR,
1392 debugfs_root, (u32 *) & ana_addr);
1393 debugfs_create_file("ana_valu", S_IRUGO | S_IWUSR,
1394 debugfs_root, &ana_addr, &fops_ana_addr);
1395 debugfs_create_file("adc_chan", S_IRUGO | S_IWUSR,
1396 debugfs_root, &adc_chan, &fops_adc_chan);
1397 debugfs_create_u64("adc_data", S_IRUGO | S_IWUSR,
1398 debugfs_root, (u64 *) & adc_data);
1400 {/* vddarm/vddcore/vddmem common debugfs interface */
1402 struct dentry *vol_root = debugfs_create_dir("vol", NULL);
1403 sprintf(str, "../%s/vddarm/voltage", REGULATOR_ROOT_DIR);
1404 debugfs_create_symlink("dcdcarm", vol_root, str);
1405 sprintf(str, "../%s/vddcore/voltage", REGULATOR_ROOT_DIR);
1406 debugfs_create_symlink("dcdccore", vol_root, str);
1407 sprintf(str, "../%s/vddmem/voltage", REGULATOR_ROOT_DIR);
1408 debugfs_create_symlink("dcdcmem", vol_root, str);
1412 ana_chip_id = (sci_get_ana_chip_id() | sci_get_ana_chip_ver());
1413 ana_status = ANA_REG_GET(ANA_REG_GLB_ANA_STATUS);
1415 pr_info("sc271x ana chip id: (0x%08x), bond opt (0x%08x)\n", ana_chip_id, ana_status);
1417 #ifdef CONFIG_REGULATOR_SUPPORT_CAMIO_1200MV
1418 ANA_REG_OR(ANA_REG_GLB_CA_CTRL0, BIT_LDO_CAMIO_V_B2);
1420 ANA_REG_BIC(ANA_REG_GLB_CA_CTRL0, BIT_LDO_CAMIO_V_B2);
1423 sci_regulator_register_dt(pdev);
1428 static int sci_regulator_remove(struct platform_device *pdev)
1431 if(sci_desc_list->init_data) {
1432 kfree(sci_desc_list->init_data);
1434 kfree(sci_desc_list);
1440 static struct platform_driver sci_regulator_driver = {
1442 .name = "sc2713s-regulator",
1443 .owner = THIS_MODULE,
1444 .of_match_table = of_match_ptr(sprd_regulator_of_match),
1446 .probe = sci_regulator_probe,
1447 .remove = sci_regulator_remove
1450 static int __init regu_driver_init(void)
1452 __adc_cal_fuse_setup();
1454 return platform_driver_register(&sci_regulator_driver);
1457 #ifndef CONFIG_REGULATOR_SC2713
1458 int __init sci_regulator_init(void)
1460 return of_platform_populate(of_find_node_by_path("/sprd-regulators"),
1461 sprd_regulator_of_match, NULL, NULL);
1465 subsys_initcall(regu_driver_init);
1467 MODULE_LICENSE("GPL v2");
1468 MODULE_DESCRIPTION("Spreadtrum voltage regulator driver");
1469 MODULE_AUTHOR("robot <zhulin.lian@spreadtrum.com>");
1470 MODULE_VERSION("0.5");