usb: gadget: fix: Call usb_gadget_connect() for dummy_udc
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / regulator / sc2723-regulator.c
1 /*
2  * Copyright (C) 2013 Spreadtrum Communications Inc.
3  *
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.
8  *
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.
13  *
14  * Fixes:
15  *      0.2 unprotect dcdc/ldo before turn on and off
16  *              remove dcdc/ldo calibration
17  * To Fix:
18  *
19  *
20  */
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/version.h>
25 #include <linux/spinlock.h>
26 #include <linux/debugfs.h>
27 #include <linux/slab.h>
28 #include <linux/sort.h>
29 #include <linux/delay.h>
30 #include <linux/err.h>
31 #include <linux/io.h>
32 #include <linux/platform_device.h>
33 #ifdef CONFIG_OF
34 #include <linux/of.h>
35 #include <linux/of_device.h>
36 #include <linux/of_address.h>
37 #include <linux/regulator/of_regulator.h>
38 #endif
39 #include <linux/regulator/consumer.h>
40 #include <linux/regulator/driver.h>
41 #include <linux/regulator/machine.h>
42
43 #include <mach/hardware.h>
44 #include <mach/sci.h>
45 #include <mach/sci_glb_regs.h>
46 #include <mach/adi.h>
47 #include <mach/adc.h>
48 #include <mach/arch_misc.h>
49
50 #define REGULATOR_ROOT_DIR      "sprd-regulator"
51
52 #undef debug
53 #define debug(format, arg...) pr_debug("regu: " "@@@%s: " format, __func__, ## arg)
54 #define debug0(format, arg...)  //pr_debug("regu: " "@@@%s: " format, __func__, ## arg)
55 #define debug2(format, arg...)  pr_debug("regu: " "@@@%s: " format, __func__, ## arg)
56
57 #ifndef ANA_REG_OR
58 #define ANA_REG_OR(_r, _b)      sci_adi_write(_r, _b, 0)
59 #endif
60
61 #ifndef ANA_REG_BIC
62 #define ANA_REG_BIC(_r, _b)     sci_adi_write(_r, 0, _b)
63 #endif
64
65 #ifndef ANA_REG_GET
66 #define ANA_REG_GET(_r)         sci_adi_read(_r)
67 #endif
68
69 #ifndef ANA_REG_SET
70 #define ANA_REG_SET(_r, _v, _m) sci_adi_write((_r), ((_v) & (_m)), (_m))
71 #endif
72
73 struct sci_regulator_regs {
74         int typ; /* BIT4: default on/off(0: off, 1: on); BIT0~BIT3: dcdc/ldo type(0: ldo; 2: dcdc) */
75         unsigned long pd_set;
76         u32 pd_set_bit;
77         unsigned long pwr_sel; /* otp pwr select reg */
78         u32 pwr_sel_bit; /* 0: otp enable(from emmc), 1: otp disable(from sw register) */
79         unsigned long vol_trm;
80         u32 vol_trm_bits;
81         unsigned long cal_ctl;
82         u32 cal_ctl_bits, cal_chan;
83         //u32 min_uV, step_uV;
84         u32 vol_def;
85         unsigned long vol_ctl;
86         u32 vol_ctl_bits;
87         u32 vol_sel_cnt, vol_sel[];
88 };
89
90 struct sci_regulator_data {
91         struct regulator_dev *rdev;
92 };
93
94 struct sci_regulator_desc {
95         struct regulator_desc desc;
96         struct sci_regulator_regs *regs;
97         struct sci_regulator_data data; /* FIXME: dynamic */
98 #if defined(CONFIG_DEBUG_FS)
99         struct dentry *debugfs;
100 #endif
101 };
102
103 enum {
104         VDD_TYP_LDO = 0,
105         VDD_TYP_LDO_D = 1,
106         VDD_TYP_DCDC = 2,
107         VDD_TYP_LPREF = 3,
108         VDD_TYP_BOOST = 4,
109 };
110
111 #define REGU_VERIFY_DLY (1000)  /*ms */
112
113 static u32 ana_chip_id;
114 static u16 ana_mixed_ctl, otp_pwr_sel;
115
116 static DEFINE_MUTEX(adc_chan_mutex);
117 static int regulator_get_trimming_step(struct regulator_dev *rdev, int to_vol);
118 static int __is_valid_adc_cal(void);
119 extern int sci_efuse_get_cal(unsigned int * pdata, int num);
120
121 #define SCI_REGU_REG(VDD, TYP, PD_SET, SET_BIT, PWR_SEL, PWR_SEL_BIT, \
122                      VOL_TRM, VOL_TRM_BITS, CAL_CTL, CAL_CTL_BITS, VOL_DEF, \
123                      VOL_CTL, VOL_CTL_BITS, VOL_SEL_CNT, ...)   \
124 do {                                                                                                            \
125         static struct sci_regulator_regs REGS_##VDD = { \
126                 .typ            = TYP,                                                                  \
127                 .pd_set = PD_SET,                                       \
128                 .pd_set_bit = SET_BIT,                                  \
129                 .pwr_sel = PWR_SEL,                                     \
130                 .pwr_sel_bit = PWR_SEL_BIT,                             \
131                 .vol_trm = VOL_TRM,                                 \
132                 .vol_trm_bits = VOL_TRM_BITS,                       \
133                 .cal_ctl = CAL_CTL,                                                             \
134                 .cal_ctl_bits = CAL_CTL_BITS,                                           \
135                 .vol_def = VOL_DEF,                                                                     \
136                 .vol_ctl = VOL_CTL,                                     \
137                 .vol_ctl_bits = VOL_CTL_BITS,                           \
138                 .vol_sel_cnt = VOL_SEL_CNT,                             \
139                 .vol_sel = {__VA_ARGS__},                               \
140         };                                                                                                              \
141         static struct sci_regulator_desc DESC_##VDD = {                 \
142                 .desc.name = #VDD,                                                                      \
143                 .desc.id = 0,                                                                           \
144                 .desc.ops = 0,                                                                          \
145                 .desc.type = REGULATOR_VOLTAGE,                                         \
146                 .desc.owner = THIS_MODULE,                                                      \
147                 .regs = &REGS_##VDD,                                                            \
148         };                                                                                                              \
149         sci_regulator_register(pdev, &DESC_##VDD);                              \
150 } while (0)
151
152 static struct sci_regulator_desc *__get_desc(struct regulator_dev *rdev)
153 {
154         return (struct sci_regulator_desc *)rdev->desc;
155 }
156
157 /* standard ldo ops*/
158 static int ldo_turn_on(struct regulator_dev *rdev)
159 {
160         struct sci_regulator_desc *desc = __get_desc(rdev);
161         struct sci_regulator_regs *regs = desc->regs;
162
163         debug0("regu 0x%p (%s), power down 0x%08x[%d]\n", regs,
164                desc->desc.name, regs->pd_set, __ffs(regs->pd_set_bit));
165
166         if (regs->pd_set == ANA_REG_GLB_LDO_DCDC_PD)
167                 sci_adi_raw_write(ANA_REG_GLB_PWR_WR_PROT_VALUE,
168                                   BITS_PWR_WR_PROT_VALUE(0x6e7f));
169
170         if (regs->pd_set)
171                 ANA_REG_BIC(regs->pd_set, regs->pd_set_bit);
172
173         if (regs->pd_set == ANA_REG_GLB_LDO_DCDC_PD)
174                 sci_adi_raw_write(ANA_REG_GLB_PWR_WR_PROT_VALUE, 0);
175
176         debug("regu 0x%p (%s), turn on\n", regs, desc->desc.name);
177         return 0;
178 }
179
180 static int ldo_turn_off(struct regulator_dev *rdev)
181 {
182         struct sci_regulator_desc *desc = __get_desc(rdev);
183         struct sci_regulator_regs *regs = desc->regs;
184
185         debug0("regu 0x%p (%s), power down 0x%08x[%d]\n", regs,
186                desc->desc.name, regs->pd_set, __ffs(regs->pd_set_bit));
187
188 #if !defined(CONFIG_REGULATOR_CAL_DUMMY)
189         if (regs->pd_set == ANA_REG_GLB_LDO_DCDC_PD)
190                 sci_adi_raw_write(ANA_REG_GLB_PWR_WR_PROT_VALUE,
191                                   BITS_PWR_WR_PROT_VALUE(0x6e7f));
192
193         if (regs->pd_set)
194                 ANA_REG_OR(regs->pd_set, regs->pd_set_bit);
195
196         if (regs->pd_set == ANA_REG_GLB_LDO_DCDC_PD)
197                 sci_adi_raw_write(ANA_REG_GLB_PWR_WR_PROT_VALUE, 0);
198
199 #endif
200
201         debug("regu 0x%p (%s), turn off\n", regs, desc->desc.name);
202         return 0;
203 }
204
205 static int ldo_is_on(struct regulator_dev *rdev)
206 {
207         int ret = -EINVAL;
208         struct sci_regulator_desc *desc = __get_desc(rdev);
209         struct sci_regulator_regs *regs = desc->regs;
210
211         debug0("regu 0x%p (%s), power down 0x%08x[%d]\n", regs,
212                desc->desc.name, regs->pd_set, __ffs(regs->pd_set_bit));
213
214         if (regs->pd_set) {
215                 ret = !(ANA_REG_GET(regs->pd_set) & regs->pd_set_bit);
216         }
217
218         debug2("regu 0x%p (%s) turn on, return %d\n", regs, desc->desc.name, ret);
219         return ret;
220 }
221
222 static int ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
223 {
224 #if 0
225         struct sci_regulator_desc *desc = __get_desc(rdev);
226         struct sci_regulator_regs *regs = desc->regs;
227
228         debug("regu 0x%p (%s), slp 0x%08x[%d] mode %x\n", regs, desc->desc.name,
229               regs->slp_ctl, regs->slp_ctl_bit, mode);
230
231         if (!regs->slp_ctl)
232                 return -EINVAL;
233
234         if (mode == REGULATOR_MODE_STANDBY) {   /* disable auto slp */
235                 ANA_REG_BIC(regs->slp_ctl, regs->slp_ctl_bit);
236         } else {
237                 ANA_REG_OR(regs->slp_ctl, regs->slp_ctl_bit);
238         }
239 #endif
240
241         return 0;
242 }
243
244 static int ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
245                            int max_uV, unsigned *selector)
246 {
247         struct sci_regulator_desc *desc = __get_desc(rdev);
248         struct sci_regulator_regs *regs = desc->regs;
249         int mv = min_uV / 1000;
250         int ret = -EINVAL;
251
252         debug("regu 0x%p (%s) set voltage, %d(uV) %d(uV)\n", regs, desc->desc.name, min_uV, max_uV);
253
254         if (regs->vol_trm /* && regs->vol_sel_cnt == 2 */) {
255                 int shft = __ffs(regs->vol_trm_bits);
256                 u32 trim =      /* vol_sel[0]: output (mV), [1]:step (uV) */
257                     DIV_ROUND_UP((mv - regs->vol_sel[0]) * 1000, regs->vol_sel[1]);
258
259                 ret = trim > (regs->vol_trm_bits >> shft);
260                 WARN(0 != ret,
261                      "warning: regulator (%s) not support %dmV\n",
262                      desc->desc.name, mv);
263
264                 if (0 == ret) {
265                         ANA_REG_SET(regs->vol_trm,
266                                     trim << shft,
267                                     regs->vol_trm_bits);
268                 }
269         }
270
271         return ret;
272 }
273
274 static int ldo_get_voltage(struct regulator_dev *rdev)
275 {
276         struct sci_regulator_desc *desc = __get_desc(rdev);
277         struct sci_regulator_regs *regs = desc->regs;
278         u32 vol;
279
280         debug0("regu 0x%p (%s), vol trm 0x%08x, mask 0x%08x\n",
281                regs, desc->desc.name, regs->vol_trm, regs->vol_trm_bits);
282
283         if (regs->vol_trm /* && regs->vol_sel_cnt == 2 */) {
284                 int shft = __ffs(regs->vol_trm_bits);
285                 u32 trim =
286                     (ANA_REG_GET(regs->vol_trm) & regs->vol_trm_bits) >> shft;
287                 vol = regs->vol_sel[0] * 1000 + trim * regs->vol_sel[1];
288                 debug2("regu 0x%p (%s), voltage %d\n", regs, desc->desc.name, vol);
289                 return vol;
290         }
291
292         return -EFAULT;
293 }
294
295
296 extern u32 __adie_efuse_read(int blk_index);
297 extern int sci_otp_get_offset(const char *name);
298
299 static int set_regu_offset(struct regulator_dev *rdev)
300 {
301         struct sci_regulator_desc *desc = __get_desc(rdev);
302         struct sci_regulator_regs *regs = desc->regs;
303         const char *regu_name = desc->desc.name;
304         int efuse_data = 0;
305
306         if (NULL == regu_name)
307                 return -1;
308
309         efuse_data = sci_otp_get_offset(regu_name);
310         if (!(desc->regs->typ & BIT(4)))
311                 rdev->constraints->uV_offset = efuse_data * regulator_get_trimming_step(rdev, 0);
312         else
313                 rdev->constraints->uV_offset = 0;
314
315         debug("%s otp delta: %d, voltage offset: %d(uV)\n", desc->desc.name, efuse_data, rdev->constraints->uV_offset);
316
317         /* switch sw register control from otp emmc only for vddmem/vdd25 */
318         if ((0 == strcmp(regu_name, "vddmem"))
319                  || (0 == strcmp(regu_name, "vdd25"))) {
320                 if (regs->pwr_sel) {
321                         int shft = __ffs(regs->vol_trm_bits);
322                         u32 trim = 0;
323
324                         if (regs->vol_trm) {
325                                 trim = (ANA_REG_GET(regs->vol_trm) & regs->vol_trm_bits) >> shft;
326                                 trim += efuse_data;
327                                 ANA_REG_SET(regs->vol_trm,
328                                             trim << shft,
329                                             regs->vol_trm_bits);
330                         }
331
332                         /* set pwr sel bit for sw control */
333                         ANA_REG_OR(regs->pwr_sel, regs->pwr_sel_bit);
334                 }
335         }
336
337         return 0;
338 }
339
340
341 /* FIXME: get dcdc cal offset config from uboot */
342 typedef struct {
343         u16 ideal_vol;
344         const char name[14];
345 }vol_para_t;
346
347
348 int regulator_default_get(const char con_id[])
349 {
350 #define PP_VOL_PARA             ( 0x50005C20 )  /* assert in iram2 */
351 #define TO_IRAM2(_p_)           ( SPRD_IRAM2_BASE + (unsigned long)(_p_) - SPRD_IRAM2_PHYS )
352 #define IN_IRAM2(_p_)           ( (unsigned long)(_p_) >= SPRD_IRAM2_PHYS && (unsigned long)(_p_) < SPRD_IRAM2_PHYS + SPRD_IRAM2_SIZE )
353
354         int i = 0, res = 0;
355         vol_para_t *pvol_para = (vol_para_t *)__raw_readl((void *)TO_IRAM2(PP_VOL_PARA));
356
357         if (!(IN_IRAM2(pvol_para)))
358                 return 0;
359
360         pvol_para = (vol_para_t *)TO_IRAM2(pvol_para);
361
362         if(strcmp((pvol_para)[0].name, "volpara_begin") || (0xfaed != (pvol_para)[0].ideal_vol))
363                 return 0;
364
365         while(0 != strcmp((pvol_para)[i++].name, "volpara_end")) {
366                 if (0 == strcmp((pvol_para)[i].name, con_id)) {
367                         debug("%s name %s, ideal_vol %d\n", __func__, (pvol_para)[i].name, (pvol_para)[i].ideal_vol);
368                         return res = (pvol_para)[i].ideal_vol;
369                 }
370         }
371         return res;
372 }
373
374 static int __init_trimming(struct regulator_dev *rdev)
375 {
376         struct sci_regulator_desc *desc = __get_desc(rdev);
377         struct sci_regulator_regs *regs = desc->regs;
378         int ctl_vol, to_vol;
379         uint otp_ana_flag = 0;
380
381         if (!regs->vol_trm)
382                 return -1;
383
384         if(!__is_valid_adc_cal())
385                 return -2;
386
387         otp_ana_flag = (u8)__adie_efuse_read(0) & BIT(7);
388         if(!otp_ana_flag) {
389                 set_regu_offset(rdev);
390         } else {
391                 to_vol = regulator_default_get(desc->desc.name);
392                 if (!to_vol)
393                         to_vol = regs->vol_def;
394
395                 if (to_vol && rdev->desc->ops->get_voltage) {
396                         ctl_vol = rdev->desc->ops->get_voltage(rdev);
397                         rdev->constraints->uV_offset = ctl_vol - to_vol * 1000;//uV
398                         debug("regu 0x%p (%s), uV offset %d\n", regs, desc->desc.name, rdev->constraints->uV_offset);
399                 }
400         }
401
402         return 0;
403 }
404
405
406 static int regulator_get_trimming_step(struct regulator_dev *rdev, int to_vol)
407 {
408 #if 0
409         struct sci_regulator_desc *desc = __get_desc(rdev);
410         if (0 == strcmp(desc->desc.name, "vddmem")) { /* FIXME: vddmem step 200/32mV */
411                 return 1000 * 200 / 32; /*uV */
412         }
413 #endif
414         return 1000 * 100 / 32; /*uV */
415 }
416
417
418 static int __match_dcdc_vol(struct sci_regulator_regs *regs, u32 vol)
419 {
420         int i, j = -1;
421         int ds, min_ds = 100;   /* mV, the max range of small voltage */
422         for (i = 0; i < regs->vol_sel_cnt; i++) {
423                 ds = vol - regs->vol_sel[i];
424                 if (ds >= 0 && ds < min_ds) {
425                         min_ds = ds;
426                         j = i;
427                 }
428         }
429         return j;
430 }
431
432 static int __dcdc_enable_time(struct regulator_dev *rdev, int old_vol)
433 {
434         int vol = rdev->desc->ops->get_voltage(rdev) / 1000;
435         if (vol > old_vol) {
436                 /* FIXME: for dcdc, each step (50mV) takes 10us */
437                 int dly = (vol - old_vol) * 10 / 50;
438                 WARN_ON(dly > 1000);
439                 udelay(dly);
440         }
441         return 0;
442 }
443
444 static int dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
445                             int max_uV, unsigned *selector)
446 {
447         struct sci_regulator_desc *desc = __get_desc(rdev);
448         struct sci_regulator_regs *regs = desc->regs;
449         int i, mv = min_uV / 1000;
450         int old_vol = rdev->desc->ops->get_voltage(rdev) / 1000;
451
452         debug0("regu 0x%p (%s) %d %d\n", regs, desc->desc.name, min_uV, max_uV);
453
454         BUG_ON(regs->vol_sel_cnt > 8);
455
456         if (regs->vol_ctl) {
457                 /* found the closely vol ctrl bits */
458                 i = __match_dcdc_vol(regs, mv);
459                 if (i < 0)
460                         return WARN(-EINVAL, "not found %s closely ctrl bits for %dmV\n",
461                                     desc->desc.name, mv);
462         }
463
464 #if !defined(CONFIG_REGULATOR_CAL_DUMMY)
465         /* dcdc calibration control bits (default 00000),
466          * small adjust voltage: 100/32mv ~= 3.125mv
467          */
468         {
469                 int shft_trm = __ffs(regs->vol_trm_bits);
470                 int shft_ctl = 0;
471                 int step = 0;
472                 int j = 0;
473
474                 if (regs->vol_ctl) {
475                         shft_ctl = __ffs(regs->vol_ctl_bits);
476                         step = regulator_get_trimming_step(rdev, 0);
477
478                         j = DIV_ROUND_UP((int)(mv - (int)regs->vol_sel[i]) * 1000, step);
479                         //j += dcdc_initial_value(desc);
480
481                         debug("regu 0x%p (%s) %d = %d %+dmV(trim %#x)\n", regs, desc->desc.name,
482                                    mv, regs->vol_sel[i], mv - regs->vol_sel[i], j);
483                 } else {
484                         if(regs->vol_sel_cnt == 2) {
485                                 step = regs->vol_sel[1];
486                                 j = DIV_ROUND_UP((int)(mv - regs->vol_sel[0]) * 1000, step);
487
488                                 debug("regu 0x%p (%s) %d = %d %+duV(trim %#x)\n", regs, desc->desc.name,
489                                            mv, regs->vol_sel[0], mv - regs->vol_sel[0], j);
490                         }
491                 }
492
493                 BUG_ON(j > (regs->vol_trm_bits >> shft_trm));
494
495                 if (regs->vol_trm == regs->vol_ctl) {
496                         ANA_REG_SET(regs->vol_ctl, (j << shft_trm) | (i << shft_ctl),
497                                     regs->vol_trm_bits | regs->vol_ctl_bits);
498                 } else {
499                         if (regs->vol_trm) {    /* small adjust first */
500                                 ANA_REG_SET(regs->vol_trm, j << shft_trm,
501                                         regs->vol_trm_bits);
502                         }
503
504                         if (regs->vol_ctl) {
505                                 ANA_REG_SET(regs->vol_ctl, i << shft_ctl,
506                                         regs->vol_ctl_bits);
507                         }
508                 }
509         }
510
511         __dcdc_enable_time(rdev, old_vol);
512 #endif
513
514         return 0;
515 }
516
517
518 static int dcdc_get_voltage(struct regulator_dev *rdev)
519 {
520         struct sci_regulator_desc *desc = __get_desc(rdev);
521         struct sci_regulator_regs *regs = desc->regs;
522         u32 mv;
523         int i, cal = 0 /* uV */;
524
525         BUG_ON(regs->vol_sel_cnt > 8);
526
527         if (regs->vol_ctl) {
528                 int shft_ctl = __ffs(regs->vol_ctl_bits);
529                 int shft_trm = __ffs(regs->vol_trm_bits);
530
531                 debug0("regu 0x%p (%s), vol ctl 0x%08x, shft %d, mask 0x%08x, sel %d\n",
532                            regs, desc->desc.name, regs->vol_ctl,
533                            shft_ctl, regs->vol_ctl_bits, regs->vol_sel_cnt);
534
535                 i = (ANA_REG_GET(regs->vol_ctl) & regs->vol_ctl_bits) >> shft_ctl;
536                 mv = regs->vol_sel[i];
537
538                 if (regs->vol_trm) {
539                         cal = (ANA_REG_GET(regs->vol_trm) & regs->vol_trm_bits) >> shft_trm;
540                         //cal -= dcdc_initial_value(desc);
541                         cal *= regulator_get_trimming_step(rdev, 0);    /* uV */
542                 }
543
544         } else if (regs->vol_trm) {
545                 int shft_trm = __ffs(regs->vol_trm_bits);
546                 u32 trim =
547                     (ANA_REG_GET(regs->vol_trm) & regs->vol_trm_bits) >> shft_trm;
548                 mv = regs->vol_sel[0] * 1000 + trim * regs->vol_sel[1];
549         }
550
551         debug2("%s get voltage, %d +%dmv\n", desc->desc.name, mv, cal / 1000);
552
553         return (mv * 1000 + cal) /*uV */;
554 }
555
556
557 /* standard boost ops*/
558 #define MAX_CURRENT_SINK        (500)   /*FIXME: max current sink */
559 static int boost_set_current_limit(struct regulator_dev *rdev, int min_uA,
560                                    int max_uA)
561 {
562         struct sci_regulator_desc *desc = __get_desc(rdev);
563         struct sci_regulator_regs *regs = desc->regs;
564         int ma = min_uA / 1000;
565         int ret = -EACCES;
566         int i, shft = __ffs(regs->vol_ctl_bits);
567         int trim = (int)regs->vol_def / 1000;
568         int steps = (regs->vol_ctl_bits >> shft) + 1;
569
570         debug("regu 0x%p (%s) %d %d\n", regs, desc->desc.name, min_uA, max_uA);
571
572         if (!regs->vol_ctl)
573                 goto exit;
574
575         if (trim > 0) {
576                 trim <<= __ffs(regs->vol_trm_bits);
577         }
578
579         i = ma * steps / MAX_CURRENT_SINK;
580         if (i >= 0 && i < steps) {
581                 ANA_REG_SET(regs->vol_ctl, (i << shft) | trim,
582                             regs->vol_ctl_bits | regs->vol_trm_bits);
583
584                 ret = 0;
585         }
586
587         WARN(0 != ret,
588              "warning: regulator (%s) not support %dmA\n", desc->desc.name, ma);
589
590 exit:
591         return ret;
592 }
593
594 static int boost_get_current_limit(struct regulator_dev *rdev)
595 {
596         struct sci_regulator_desc *desc = __get_desc(rdev);
597         struct sci_regulator_regs *regs = desc->regs;
598         u32 cur;
599         int i, shft = __ffs(regs->vol_ctl_bits);
600         int steps = (regs->vol_ctl_bits >> shft) + 1;
601
602         debug0("regu 0x%p (%s), vol ctl 0x%08x, shft %d, mask 0x%08x\n",
603                regs, desc->desc.name, regs->vol_ctl, shft, regs->vol_ctl_bits);
604
605         if (!regs->vol_ctl)
606                 return -EACCES;
607
608         i = ((ANA_REG_GET(regs->vol_ctl) & regs->vol_ctl_bits) >> shft);
609         cur = i * MAX_CURRENT_SINK / steps;
610         debug("regu 0x%p (%s) get current %d\n", regs, desc->desc.name, cur);
611         return cur * 1000;
612 }
613
614 static int adc_sample_bit = 1;  /*12bits mode */
615 static short adc_data[3][2]
616 #if defined(CONFIG_REGULATOR_ADC_DEBUG)
617     = {
618         {4200, 3387},  /* same as nv adc_t */
619         {3600, 2905},
620         {400, 316},  /* 0.4@VBAT, Reserved IdealC Value */
621 }
622 #endif
623 ;
624
625 static int __is_valid_adc_cal(void)
626 {
627         return 0 != adc_data[0][0];
628 }
629
630 static int __init __adc_cal_setup(char *str)
631 {
632         u32 *p = (u32 *) adc_data;
633         *p = simple_strtoul(str, &str, 0);
634         if (*p++ && *++str) {
635                 *p = simple_strtoul(str, &str, 0);
636                 if (*p) {
637                         debug("%d : %d -- %d : %d\n",
638                               (int)adc_data[0][0], (int)adc_data[0][1],
639                               (int)adc_data[1][0], (int)adc_data[1][1]);
640                         if (adc_data[0][1] < BIT(10)
641                             && adc_data[1][1] < BIT(10))
642                                 adc_sample_bit = 0;     /*10bits mode */
643                 }
644         }
645
646         return 0;
647 }
648 early_param("adc_cal", __adc_cal_setup);
649
650 static int __init __adc_cal_fuse_setup(void)
651 {
652         if (!__is_valid_adc_cal() &&
653             (0 == sci_efuse_get_cal((u32 *) adc_data, 2))) {
654                 debug("%d : %d -- %d : %d\n",
655                       (int)adc_data[0][0], (int)adc_data[0][1],
656                       (int)adc_data[1][0], (int)adc_data[1][1]);
657         }
658
659         return 0;
660 }
661
662 static int __adc2vbat(int adc_res)
663 {
664         int t = adc_data[0][0] - adc_data[1][0];
665         t *= (adc_res - adc_data[0][1]);
666         t /= (adc_data[0][1] - adc_data[1][1]);
667         t += adc_data[0][0];
668         return t;
669 }
670
671 #define MEASURE_TIMES   (15)
672
673 static void __dump_adc_result(u32 adc_val[])
674 {
675 #if defined(CONFIG_REGULATOR_ADC_DEBUG)
676         int i;
677         for (i = 0; i < MEASURE_TIMES; i++) {
678                 printk("%d ", adc_val[i]);
679         }
680         printk("\n");
681 #endif
682 }
683
684 static int cmp_val(const void *a, const void *b)
685 {
686         return *(int *)a - *(int *)b;
687 }
688
689 /**
690  * __adc_voltage - get regulator output voltage through auxadc
691  * @regulator: regulator source
692  *
693  * This returns the current regulator voltage in mV.
694  *
695  * NOTE: If the regulator is disabled it will return the voltage value. This
696  * function should not be used to determine regulator state.
697  */
698 static int regu_adc_voltage(struct regulator_dev *rdev)
699 {
700         struct sci_regulator_desc *desc = __get_desc(rdev);
701         struct sci_regulator_regs *regs = desc->regs;
702
703         int ret, adc_chan = regs->cal_chan;
704         u16 ldo_cal_sel = regs->cal_ctl_bits & 0xFFFF;
705         u32 adc_res, adc_val[MEASURE_TIMES];
706         u32 ratio = 1, chan_numerators = 1, chan_denominators = 1;
707         u32 bat_numerators, bat_denominators;
708
709         struct adc_sample_data data = {
710                 .channel_id = adc_chan,
711                 .channel_type = 0,      /*sw */
712                 .hw_channel_delay = 0,  /*reserved */
713                 .scale = (((adc_chan != 13) && (adc_chan != 14)) ? 1 : 0),      /* chanel = 13/14: small scale, others: big scale */
714                 .pbuf = &adc_val[0],
715                 .sample_num = MEASURE_TIMES,
716                 .sample_bits = adc_sample_bit,
717                 .sample_speed = 0,      /*quick mode */
718                 .signal_mode = 0,       /*resistance path */
719         };
720
721         if (!__is_valid_adc_cal())
722                 return -EACCES;
723
724         if (!regs->cal_ctl)
725                 return -EINVAL;
726
727         /* enable ldo cal before adc sampling and ldo calibration */
728         if (ldo_cal_sel) {
729                 mutex_lock(&adc_chan_mutex);
730                 ANA_REG_OR(regs->cal_ctl, ldo_cal_sel);
731                 debug0("%s adc channel %d : %04x\n",
732                        desc->desc.name, data.channel_id, ldo_cal_sel);
733         }
734
735         ret = sci_adc_get_values(&data);
736         BUG_ON(0 != ret);
737
738         /* close ldo cal and release multiplexed aux adc channel */
739         if (ldo_cal_sel) {
740                 ANA_REG_BIC(regs->cal_ctl, ldo_cal_sel);
741                 mutex_unlock(&adc_chan_mutex);
742         }
743
744         __dump_adc_result(adc_val);
745         sort(adc_val, MEASURE_TIMES, sizeof(u32), cmp_val, 0);
746         /*__dump_adc_result(adc_val);*/
747
748         ratio = (u32)sci_adc_get_ratio(data.channel_id, data.scale, ldo_cal_sel);
749         chan_numerators = ratio >> 16;
750         chan_denominators = ratio & 0xFFFF;
751
752         ratio = (u32)sci_adc_get_ratio(ADC_CHANNEL_VBAT, 1, 0);
753         bat_numerators = ratio >> 16;
754         bat_denominators = ratio & 0xFFFF;
755
756         adc_res = adc_val[MEASURE_TIMES / 2];
757         debug("%s adc channel %d : 0x%04x, ratio (%d/%d), result value %d\n",
758               desc->desc.name, data.channel_id, ldo_cal_sel,
759               chan_numerators, chan_denominators, adc_res);
760
761         if (adc_res == 0)
762                 return -EAGAIN;
763         else
764                 return __adc2vbat(adc_res)
765                     * (bat_numerators * chan_denominators)
766                     / (bat_denominators * chan_numerators);
767 }
768
769 /**
770  * regulator_strongly_disable - strongly disable regulator output
771  * @regulator: regulator source
772  *
773  * Strongly try disable the regulator output voltage or current.
774  * NOTE: this *will* disable the regulator output even if other consumer
775  * devices have it enabled. This should be used for situations when device
776  * had unbalanced with calls to regulator_enable().
777  * *Not* recommended to call this function before try to balance the use_count.
778  */
779 int regulator_strongly_disable(struct regulator *regulator)
780 {
781         struct regulator_dev *rdev = regulator_get_drvdata(regulator);
782         int ret = 0;
783
784         if (rdev)
785                 while (rdev->use_count--)
786                         regulator_disable(regulator);
787
788         return ret;
789 }
790
791 EXPORT_SYMBOL_GPL(regulator_strongly_disable);
792
793 static struct regulator_ops ldo_ops = {
794         .enable = ldo_turn_on,
795         .disable = ldo_turn_off,
796         .is_enabled = ldo_is_on,
797         .set_voltage = ldo_set_voltage,
798         .get_voltage = ldo_get_voltage,
799         .set_mode = ldo_set_mode,
800 };
801
802 static struct regulator_ops dcdc_ops = {
803         .enable = ldo_turn_on,
804         .disable = ldo_turn_off,
805         .is_enabled = ldo_is_on,
806         .set_voltage = dcdc_set_voltage,
807         .get_voltage = dcdc_get_voltage,
808 };
809
810 static struct regulator_ops boost_ops = {
811         .enable = ldo_turn_on,
812         .disable = ldo_turn_off,
813         .is_enabled = ldo_is_on,
814         .set_current_limit = boost_set_current_limit,
815         .get_current_limit = boost_get_current_limit,
816         .set_mode = ldo_set_mode,
817 };
818
819 /*
820  * Consider the following machine :-
821  *
822  *   Regulator-1 -+-> [Consumer A @ 1.8V]
823  *                |
824  *                +-> [Consumer B @ 1.8V]
825  *
826  *   Regulator-2 ---> [Consumer C @ 3.3V]
827  *
828  * The drivers for consumers A & B must be mapped to the correct regulator in
829  * order to control their power supply. This mapping can be achieved in board/machine
830  * initialisation code by creating a struct regulator_consumer_supply for each regulator.
831  * Alternatively, we built a regulator supply-consumers map, the format is as follow:
832  *
833  *      supply source-1, consumer A, consumer B, ..., NULL
834  *      supply source-2, consumer C, ..., NULL
835  *      ...
836  *      NULL
837  *
838  */
839 static struct regulator_consumer_supply *set_supply_map(struct device *dev,
840                                                         const char *supply_name,
841                                                         int *num)
842 {
843         char **map = (char **)dev_get_platdata(dev);
844         int i, n;
845         struct regulator_consumer_supply *consumer_supplies = NULL;
846
847         if (!supply_name || !(map && map[0]))
848                 return NULL;
849
850         for (i = 0; map[i] || map[i + 1]; i++) {
851                 if (map[i] && 0 == strcmp(map[i], supply_name))
852                         break;
853         }
854
855         /* i++; *//* Do not skip supply name */
856
857         for (n = 0; map[i + n]; n++) ;
858
859         if (n) {
860                 debug0("supply %s consumers %d - %d\n", supply_name, i, n);
861                 consumer_supplies =
862                     kzalloc(n * sizeof(*consumer_supplies), GFP_KERNEL);
863                 BUG_ON(!consumer_supplies);
864                 for (n = 0; map[i]; i++, n++) {
865                         consumer_supplies[n].supply = map[i];
866                 }
867                 if (num)
868                         *num = n;
869         }
870         return consumer_supplies;
871 }
872
873 #if defined(CONFIG_DEBUG_FS)
874 static struct dentry *debugfs_root = NULL;
875
876 static u32 ana_addr = 0;
877 static int debugfs_ana_addr_get(void *data, u64 * val)
878 {
879         if (ana_addr < PAGE_SIZE) {
880                 *val = ANA_REG_GET(ana_addr + (ANA_REGS_GLB_BASE & PAGE_MASK));
881         } else {
882                 void *addr = ioremap(ana_addr, PAGE_SIZE);
883                 *val = __raw_readl(addr);
884                 iounmap(addr);
885         }
886         return 0;
887 }
888
889 static int debugfs_ana_addr_set(void *data, u64 val)
890 {
891         if (ana_addr < PAGE_SIZE) {
892                 ANA_REG_SET(ana_addr + (ANA_REGS_GLB_BASE & PAGE_MASK), val, -1);
893         } else {
894                 void *addr = ioremap(ana_addr, PAGE_SIZE);
895                 __raw_writel(val, addr);
896                 iounmap(addr);
897         }
898         return 0;
899 }
900
901 static int adc_chan = 5 /*VBAT*/;
902 static int debugfs_adc_chan_get(void *pdata, u64 * val)
903 {
904         int i, ret;
905         u32 adc_res, adc_val[MEASURE_TIMES];
906         struct adc_sample_data data = {
907                 .channel_id = adc_chan,
908                 .channel_type = 0,      /*sw */
909                 .hw_channel_delay = 0,  /*reserved */
910                 .scale = 1,     /*big scale */
911                 .pbuf = &adc_val[0],
912                 .sample_num = MEASURE_TIMES,
913                 .sample_bits = adc_sample_bit,
914                 .sample_speed = 0,      /*quick mode */
915                 .signal_mode = 0,       /*resistance path */
916         };
917
918         ret = sci_adc_get_values(&data);
919         BUG_ON(0 != ret);
920
921         for (i = 0; i < MEASURE_TIMES; i++) {
922                 printk("%d ", adc_val[i]);
923         }
924         printk("\n");
925
926         sort(adc_val, MEASURE_TIMES, sizeof(u32), cmp_val, 0);
927         adc_res = adc_val[MEASURE_TIMES / 2];
928         pr_info("adc chan %d, result value %d, vbat %d\n",
929                 data.channel_id, adc_res, __adc2vbat(adc_res));
930         *val = adc_res;
931         return 0;
932 }
933
934 static int debugfs_adc_chan_set(void *data, u64 val)
935 {
936         adc_chan = val;
937         return 0;
938 }
939
940 static int debugfs_enable_get(void *data, u64 * val)
941 {
942         struct regulator_dev *rdev = data;
943         if (rdev && rdev->desc->ops->is_enabled)
944                 *val = rdev->desc->ops->is_enabled(rdev);
945         else
946                 *val = -1;
947         return 0;
948 }
949
950 static int debugfs_enable_set(void *data, u64 val)
951 {
952         struct regulator_dev *rdev = data;
953         if (rdev && rdev->desc->ops->enable)
954                 (val) ? rdev->desc->ops->enable(rdev)
955                     : rdev->desc->ops->disable(rdev);
956         return 0;
957 }
958
959 static int debugfs_voltage_get(void *data, u64 * val)
960 {
961         struct regulator_dev *rdev = data;
962         if (rdev)
963                 *val = regu_adc_voltage(rdev);
964         else
965                 *val = -1;
966         return 0;
967 }
968
969 static int debugfs_voltage_set(void *data, u64 val)
970 {
971         struct regulator_dev *rdev = data;
972         if (rdev && rdev->desc->ops->set_voltage) {
973                 u32 min_uV = (u32)val * 1000;
974                 min_uV += rdev->constraints->uV_offset;
975                 rdev->desc->ops->set_voltage(rdev, min_uV, min_uV, 0);
976         }
977         return 0;
978 }
979
980 static int debugfs_boost_get(void *data, u64 * val)
981 {
982         struct regulator_dev *rdev = data;
983         if (rdev && rdev->desc->ops->get_current_limit)
984                 *val = rdev->desc->ops->get_current_limit(rdev) / 1000;
985         else
986                 *val = -1;
987         return 0;
988 }
989
990 static int debugfs_boost_set(void *data, u64 val)
991 {
992         struct regulator_dev *rdev = data;
993         if (rdev && rdev->desc->ops->set_current_limit)
994                 rdev->desc->ops->set_current_limit(rdev, val * 1000,
995                                                    val * 1000);
996         return 0;
997 }
998
999 DEFINE_SIMPLE_ATTRIBUTE(fops_ana_addr,
1000                         debugfs_ana_addr_get, debugfs_ana_addr_set, "%llu\n");
1001 DEFINE_SIMPLE_ATTRIBUTE(fops_adc_chan,
1002                         debugfs_adc_chan_get, debugfs_adc_chan_set, "%llu\n");
1003 DEFINE_SIMPLE_ATTRIBUTE(fops_enable,
1004                         debugfs_enable_get, debugfs_enable_set, "%llu\n");
1005 DEFINE_SIMPLE_ATTRIBUTE(fops_ldo,
1006                         debugfs_voltage_get, debugfs_voltage_set, "%llu\n");
1007 DEFINE_SIMPLE_ATTRIBUTE(fops_boost,
1008                         debugfs_boost_get, debugfs_boost_set, "%llu\n");
1009
1010 static void rdev_init_debugfs(struct regulator_dev *rdev)
1011 {
1012         struct sci_regulator_desc *desc = __get_desc(rdev);
1013         desc->debugfs = debugfs_create_dir(rdev->desc->name, debugfs_root);
1014         if (IS_ERR_OR_NULL(rdev->debugfs)) {
1015                 pr_warn("Failed to create debugfs directory\n");
1016                 rdev->debugfs = NULL;
1017                 return;
1018         }
1019
1020         debugfs_create_file("enable", S_IRUGO | S_IWUSR,
1021                             desc->debugfs, rdev, &fops_enable);
1022
1023         if (desc->desc.type == REGULATOR_CURRENT)
1024                 debugfs_create_file("current", S_IRUGO | S_IWUSR,
1025                                     desc->debugfs, rdev, &fops_boost);
1026         else
1027                 debugfs_create_file("voltage", S_IRUGO | S_IWUSR,
1028                                     desc->debugfs, rdev, &fops_ldo);
1029 }
1030 #else
1031 static void rdev_init_debugfs(struct regulator_dev *rdev)
1032 {
1033 }
1034 #endif
1035
1036 static int reconfig_regulator(struct sci_regulator_desc *desc)
1037 {
1038         struct sci_regulator_regs *regs = desc->regs;
1039
1040         /* Fixme: Config DCDC  linear/no linear control
1041          *   accoring to BIT14 of Reg(0x40038800 + 0x0118)
1042          */
1043         if (ana_mixed_ctl & BIT_DCDC_V_CTRL_MODE) {
1044                 /* dcdc linear control */
1045                 if ((0 == strcmp(desc->desc.name, "vddcore"))
1046                          || (0 == strcmp(desc->desc.name, "vddarm"))) {
1047                         regs->vol_trm_bits = (BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4) \
1048                                                                                 |BIT(5)|BIT(6)|BIT(7)|BIT(8)|BIT(9));
1049                         regs->vol_ctl = 0;
1050                         regs->vol_ctl_bits = 0;
1051
1052                         regs->vol_sel_cnt = 2;
1053                         regs->vol_sel[0] = 600;
1054                         regs->vol_sel[1] = 3125;
1055                 }
1056         } else {
1057                 /* dcdc Non-linear control */
1058                 if ((0 == strcmp(desc->desc.name, "vddcore"))
1059                          || (0 == strcmp(desc->desc.name, "vddarm"))) {
1060                         regs->vol_ctl = regs->vol_trm;
1061                         regs->vol_trm_bits = (BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4));
1062                         regs->vol_ctl_bits = (BIT(5)|BIT(6)|BIT(7));
1063                         regs->vol_sel_cnt = 8;
1064                         regs->vol_sel[0] = 1100;
1065                         regs->vol_sel[1] = 700;
1066                         regs->vol_sel[2] = 800;
1067                         regs->vol_sel[3] = 900;
1068                         regs->vol_sel[4] = 1000;
1069                         regs->vol_sel[5] = 650;
1070                         regs->vol_sel[6] = 1200;
1071                         regs->vol_sel[7] = 1300;
1072                 }
1073         }
1074
1075         return 0;
1076 }
1077
1078 static void *sci_regulator_register(struct platform_device *pdev,
1079                                        struct sci_regulator_desc *desc)
1080 {
1081         static atomic_t idx = ATOMIC_INIT(1);   /* 0: dummy */
1082         struct regulator_dev *rdev;
1083         struct regulator_ops *__regs_ops[] = {
1084                 &ldo_ops, 0, &dcdc_ops, 0 /*lpref_ops */ , &boost_ops,
1085                 0,
1086         };
1087         struct regulator_consumer_supply consumer_supplies_default[] = {
1088                 [0] = {
1089                        .supply = desc->desc.name,
1090                        }
1091         };
1092         struct regulator_config config = { };
1093
1094         struct regulator_init_data init_data = {
1095                 .supply_regulator = 0,
1096                 .constraints = {
1097                                 .min_uV = 0,
1098                                 .max_uV = 4200 * 1000,
1099                                 .valid_modes_mask =
1100                                 REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY,
1101                                 .valid_ops_mask =
1102                                 REGULATOR_CHANGE_STATUS |
1103                                 REGULATOR_CHANGE_VOLTAGE |
1104                                 REGULATOR_CHANGE_MODE,
1105                                 },
1106                 .num_consumer_supplies = 1,
1107                 .consumer_supplies = consumer_supplies_default,
1108                 .regulator_init = 0,
1109                 .driver_data = 0,
1110         };
1111
1112         desc->desc.id = atomic_inc_return(&idx) - 1;
1113
1114         reconfig_regulator(desc);
1115
1116         BUG_ON((desc->regs->typ & (BIT(4) - 1)) >= ARRAY_SIZE(__regs_ops));
1117         if (!desc->desc.ops)
1118                 desc->desc.ops = __regs_ops[desc->regs->typ & (BIT(4) - 1)];
1119
1120         init_data.consumer_supplies =
1121             set_supply_map(&pdev->dev, desc->desc.name,
1122                            &init_data.num_consumer_supplies);
1123
1124         if (!init_data.consumer_supplies)
1125                 init_data.consumer_supplies = consumer_supplies_default;
1126
1127         debug0("regu 0x%p (%s)\n", desc->regs, desc->desc.name);
1128
1129 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
1130     config.dev = &pdev->dev;
1131     config.init_data = &init_data;
1132     config.driver_data = NULL;
1133     config.of_node = NULL;
1134     rdev = regulator_register(&desc->desc, &config);
1135 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
1136         rdev = regulator_register(&desc->desc, &pdev->dev, &init_data, 0, 0);
1137 #else
1138         rdev = regulator_register(&desc->desc, &pdev->dev, &init_data, 0);
1139 #endif
1140
1141         if (init_data.consumer_supplies != consumer_supplies_default)
1142                 kfree(init_data.consumer_supplies);
1143
1144         if (!IS_ERR_OR_NULL(rdev)) {
1145                 rdev->reg_data = rdev;
1146                 desc->data.rdev = rdev;
1147                 __init_trimming(rdev);
1148                 rdev_init_debugfs(rdev);
1149         }
1150         return rdev;
1151 }
1152
1153 /**
1154  * IMPORTANT!!!
1155  * spreadtrum power regulators is intergrated on the chip, include LDOs and DCDCs.
1156  * so i autogen all regulators non-variable description in plat or mach directory,
1157  * which named __xxxx_regulator_map.h, BUT register all in regulator driver probe func,
1158  * just like other regulator vendor drivers.
1159  */
1160 static int sci_regulator_probe(struct platform_device *pdev)
1161 {
1162 #ifdef CONFIG_DEBUG_FS
1163         debugfs_root =
1164                 debugfs_create_dir(REGULATOR_ROOT_DIR, NULL);
1165         if (IS_ERR_OR_NULL(debugfs_root)) {
1166                 WARN(!debugfs_root,
1167                          "%s: Failed to create debugfs directory\n", REGULATOR_ROOT_DIR);
1168                 debugfs_root = NULL;
1169         }
1170
1171         /* compatible with 8810 adc test */
1172         debugfs_create_u32("ana_addr", S_IRUGO | S_IWUSR,
1173                            debugfs_root, (u32 *) & ana_addr);
1174         debugfs_create_file("ana_valu", S_IRUGO | S_IWUSR,
1175                                 debugfs_root, &ana_addr, &fops_ana_addr);
1176         debugfs_create_file("adc_chan", S_IRUGO | S_IWUSR,
1177                                 debugfs_root, &adc_chan, &fops_adc_chan);
1178         debugfs_create_u64("adc_data", S_IRUGO | S_IWUSR,
1179                            debugfs_root, (u64 *) & adc_data);
1180
1181         { /* vddarm/vddcore/vddmem common debugfs interface */
1182                 char str[NAME_MAX];
1183                 struct dentry *vol_root = debugfs_create_dir("vol", NULL);
1184                 sprintf(str, "../%s/vddarm/voltage", REGULATOR_ROOT_DIR);
1185                 debugfs_create_symlink("dcdcarm", vol_root, str);
1186                 sprintf(str, "../%s/vddcore/voltage", REGULATOR_ROOT_DIR);
1187                 debugfs_create_symlink("dcdccore", vol_root, str);
1188                 sprintf(str, "../%s/vddmem/voltage", REGULATOR_ROOT_DIR);
1189                 debugfs_create_symlink("dcdcmem", vol_root, str);
1190         }
1191 #endif
1192
1193         ana_chip_id = ((u32)ANA_REG_GET(ANA_REG_GLB_CHIP_ID_HIGH) << 16) |
1194                                 ((u32)ANA_REG_GET(ANA_REG_GLB_CHIP_ID_LOW) & 0xFFFF);
1195         ana_mixed_ctl = ANA_REG_GET(ANA_REG_GLB_MIXED_CTRL0);
1196         otp_pwr_sel = ANA_REG_GET(ANA_REG_GLB_PWR_SEL);
1197
1198         pr_info("sc272x ana chipid:(0x%08x), ana_mixed_ctl:(0x%08x), otp_sel:(0x%08x)\n", ana_chip_id, ana_mixed_ctl, otp_pwr_sel);
1199
1200 #include CONFIG_REGULATOR_SPRD_MAP_V1
1201         return 0;
1202 }
1203
1204 static int sci_regulator_remove(struct platform_device *pdev)
1205 {
1206         return 0;
1207 }
1208
1209 static struct platform_driver sci_regulator_driver = {
1210         .driver = {
1211                    .name = "sc2723-regulator",
1212                    .owner = THIS_MODULE,
1213                    },
1214         .probe = sci_regulator_probe,
1215         .remove = sci_regulator_remove
1216 };
1217
1218 static int __init regu_driver_init(void)
1219 {
1220         __adc_cal_fuse_setup();
1221
1222         return platform_driver_register(&sci_regulator_driver);
1223 }
1224
1225 int __init sci_regulator_init(void)
1226 {
1227         static struct platform_device regulator_device = {
1228                 .name = "sc2723-regulator",
1229                 .id = -1,
1230         };
1231
1232         sci_adi_raw_write(ANA_REG_GLB_PWR_WR_PROT_VALUE,
1233                           BITS_PWR_WR_PROT_VALUE(0x6e7f));
1234         WARN_ON(!
1235                 (sci_adi_read(ANA_REG_GLB_PWR_WR_PROT_VALUE) &
1236                  BIT_PWR_WR_PROT));
1237         sci_adi_raw_write(ANA_REG_GLB_PWR_WR_PROT_VALUE, 0);
1238
1239         return platform_device_register(&regulator_device);
1240 }
1241
1242 subsys_initcall(regu_driver_init);
1243
1244 MODULE_LICENSE("GPL v2");
1245 MODULE_DESCRIPTION("Spreadtrum voltage regulator driver");
1246 MODULE_AUTHOR("kevin <ronghua.yu@spreadtrum.com>");
1247 MODULE_VERSION("0.6");