1 /******************************************************************************
2 ** File Name: ldo_drv.c *
5 ** Copyright: 2007 Spreatrum, Incoporated. All Rights Reserved. *
6 ** Description: This file defines the basic function for ldo management. *
7 ******************************************************************************/
9 /******************************************************************************
11 ** ------------------------------------------------------------------------- *
12 ** DATE NAME DESCRIPTION *
13 ** 01/09/2009 Yi.Qiu Create. *
14 ******************************************************************************/
16 /**---------------------------------------------------------------------------*
18 **---------------------------------------------------------------------------*/
22 #include <asm/arch/ldo.h>
23 #include <asm/arch/chip_drv_common_io.h>
24 #include <asm/arch/sprd_reg.h>
26 #define LDO_INVALID_REG 0xFFFFFFFF
27 #define LDO_INVALID_BIT 0xFFFFFFFF
30 #define CURRENT_STATUS_INIT 0x00000001
31 #define CURRENT_STATUS_ON 0x00000002
32 #define CURRENT_STATUS_OFF 0x00000004
34 #define LDO_INVALID_REG_ADDR 0x1
36 #define SCI_PASSERT(condition, format...) \
39 printf("function :%s\r\n", __FUNCTION__);\
50 unsigned int bp_rst_reg;
51 unsigned int bp_rst;//bits
53 unsigned int level_reg_b0;
57 unsigned int level_reg_b1;
61 unsigned int init_level;
67 int current_volt_level;
70 #if defined(CONFIG_SPX15) || defined(CONFIG_ADIE_SC2723) || defined(CONFIG_ADIE_SC2723S)
76 .id = LDO_LDO_USB, .name = "vddusb",
79 .id = LDO_LDO_EMMCCORE, .name = "vddemmccore",
81 #if defined(CONFIG_ADIE_SC2723) || defined(CONFIG_ADIE_SC2723S)
83 .id = LDO_LDO_SDIO0, .name = "vddsdcore",
86 .id = LDO_LDO_SDIO1, .name = "vddsdio",
88 #if defined(CONFIG_SPX20)
90 .id = LDO_LDO_EMMCIO, .name = "vddgen0",
94 .id = LDO_LDO_EMMCIO, .name = "vddgen0",
99 .id = LDO_LDO_EMMCIO, .name = "vddemmcio",
102 .id = LDO_LDO_SDIO0, .name = "vddsd",
106 .id = LDO_LDO_SIM0, .name = "vddsim0",
109 .id = LDO_LDO_SIM1, .name = "vddsim1",
112 .id = LDO_LDO_SIM2, .name = "vddsim2",
116 struct s_ldo_ctl_info {
122 static struct s_ldo_ctl_info s_ldo_ctl_data[] = {
123 {LDO_LDO_USB, ANA_REG_GLB_LDO_PD_CTRL, BIT(8)},
124 {LDO_LDO_EMMCCORE, ANA_REG_GLB_LDO_DCDC_PD, BIT(7)},
125 {LDO_LDO_EMMCIO, ANA_REG_GLB_LDO_DCDC_PD, BIT(6)},
126 {LDO_LDO_SDIO3, ANA_REG_GLB_LDO_PD_CTRL, BIT(0)},
127 {LDO_LDO_SIM0, ANA_REG_GLB_LDO_PD_CTRL, BIT(1)},
128 {LDO_LDO_SIM1, ANA_REG_GLB_LDO_PD_CTRL, BIT(2)},
129 {LDO_LDO_SIM2, ANA_REG_GLB_LDO_PD_CTRL, BIT(3)},
130 {LDO_LDO_CAMMOT, ANA_REG_GLB_LDO_PD_CTRL, BIT(7)},
131 {LDO_LDO_WIFIPA, ANA_REG_GLB_LDO_PD_CTRL, BIT(11)},
134 static int __LDO_IDX(LDO_ID_E ldo_id)
137 for(i=0; i< ARRAY_SIZE(s_ldo_ctl_data);i++)
139 if(ldo_id == s_ldo_ctl_data[i].id)
145 const char* __LDO_NAME(LDO_ID_E ldo_id)
148 for(i = 0; i < ARRAY_SIZE(__ldo_names); i++) {
149 if (ldo_id == __ldo_names[i].id)
150 return __ldo_names[i].name;
157 return regulator_init();
160 void LDO_TurnOffAllLDO(void)
162 unsigned int reg_val;
164 ANA_REG_SET(ANA_REG_GLB_PWR_WR_PROT_VALUE,BITS_PWR_WR_PROT_VALUE(0x6e7f));
167 reg_val = (ANA_REG_GET(ANA_REG_GLB_PWR_WR_PROT_VALUE) & BIT_PWR_WR_PROT);
168 }while(reg_val == 0);
170 ANA_REG_SET(ANA_REG_GLB_LDO_PD_CTRL,0x0FFF);
171 ANA_REG_SET(ANA_REG_GLB_LDO_DCDC_PD,0x7FFF);
173 ANA_REG_SET(ANA_REG_GLB_PWR_WR_PROT_VALUE,BITS_PWR_WR_PROT_VALUE(0x0000));
174 //never return here and wait power down action
178 LDO_ERR_E LDO_TurnOffLDO(LDO_ID_E ldo_id)
180 #if defined(CONFIG_ADIE_SC2713S)
181 return regulator_disable(__LDO_NAME(ldo_id));
183 int i = __LDO_IDX(ldo_id);
188 ANA_REG_OR(s_ldo_ctl_data[i].reg, s_ldo_ctl_data[i].bit);
194 LDO_ERR_E LDO_TurnOnLDO(LDO_ID_E ldo_id)
196 #if defined(CONFIG_ADIE_SC2713S)
197 return regulator_enable(__LDO_NAME(ldo_id));
199 int i = __LDO_IDX(ldo_id);
204 ANA_REG_BIC(s_ldo_ctl_data[i].reg, s_ldo_ctl_data[i].bit);
210 static struct ldo_ctl_info* LDO_GetLdoCtl(LDO_ID_E ldo_id)
213 struct ldo_ctl_info* ctl = NULL;
215 for ( i = 0; i < ARRAY_SIZE(s_ldo_ctl_data); ++i)
217 if (s_ldo_ctl_data[i].id == ldo_id)
219 ctl = &s_ldo_ctl_data[i];
224 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
228 LDO_ERR_E LDO_SetVoltLevel(LDO_ID_E ldo_id, LDO_VOLT_LEVEL_E volt_level)
230 unsigned short reg_data;
231 struct ldo_ctl_info* ctl = NULL;
233 ctl = LDO_GetLdoCtl(ldo_id);
234 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
236 if (ctl->level_reg_b0 == LDO_INVALID_REG_ADDR)
241 if (ctl->level_reg_b0 != ctl->level_reg_b1)
243 printf("ldo_id:%d, level_reg_b0:%08x, level_reg_b1:%08x\r\n", ldo_id, ctl->level_reg_b0, ctl->level_reg_b1);
249 case LDO_VOLT_LEVEL0:
250 ANA_REG_AND(ctl->level_reg_b0, (~(ctl->b0|ctl->b1)));
253 case LDO_VOLT_LEVEL1:
254 reg_data = ANA_REG_GET(ctl->level_reg_b0);
257 ANA_REG_SET(ctl->level_reg_b0, reg_data);
260 case LDO_VOLT_LEVEL2:
261 reg_data = ANA_REG_GET(ctl->level_reg_b0);
264 ANA_REG_SET(ctl->level_reg_b0, reg_data);
267 case LDO_VOLT_LEVEL3:
268 ANA_REG_OR (ctl->level_reg_b0, (ctl->b0|ctl->b1));
275 ctl->current_volt_level = volt_level;
283 struct ldo_ctl_info {
289 unsigned int bp_bits;
290 unsigned int bp_rst_reg;
291 unsigned int bp_rst;//bits
293 unsigned int level_reg_b0;
297 unsigned int level_reg_b1;
301 unsigned int init_level;
307 int current_volt_level;
310 static struct ldo_ctl_info ldo_ctl_data[] =
313 .id = LDO_LDO_EMMCCORE,
314 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
316 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
318 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
321 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
324 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
327 .id = LDO_LDO_EMMCIO,
328 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
330 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
332 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
335 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
338 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
342 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
344 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
346 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
349 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
352 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
356 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
358 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
360 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
363 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
366 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
370 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
372 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
374 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
377 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
380 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
384 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
386 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
388 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
391 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
394 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
398 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
400 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
402 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
405 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
408 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
412 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
414 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
416 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL0,
419 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL0,
422 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
426 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
428 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
430 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL1,
433 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL1,
436 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
440 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
442 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
444 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL1,
447 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL1,
450 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
454 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
456 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
458 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL1,
461 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL1,
464 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
468 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
470 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
472 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL1,
475 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL1,
478 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
481 .id = LDO_LDO_AVDD18,
482 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
484 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
486 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL1,
489 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL1,
492 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
495 .id = LDO_LDO_VBAT_RES, //new
496 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
498 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
500 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
503 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
506 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
509 .id = LDO_LDO_VBAT_V, //new
510 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
512 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
514 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
517 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
520 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
524 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
526 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
528 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
531 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
534 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
538 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
540 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
542 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
545 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
548 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
551 .id = LDO_LDO_CAMM, //LDO_LDO_CAMMOT
552 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
554 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
556 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
559 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
562 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
565 .id = LDO_LDO_CAMD1, //LDO_LDO_CAMIO
566 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
568 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
570 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
573 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
576 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
579 .id = LDO_LDO_CAMD0, //LDO_LDO_CAMCORE
580 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
582 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
584 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
587 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
590 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
593 .id = LDO_LDO_CAMA, //LDO_LDO_CAMA
594 .bp_reg = ANA_REG_GLB_LDO_PD_CTRL,
596 .bp_rst_reg = ANA_REG_GLB_LDO_PD_CTRL,
598 .level_reg_b0 = ANA_REG_GLB_LDO_V_CTRL2,
601 .level_reg_b1 = ANA_REG_GLB_LDO_V_CTRL2,
604 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
606 /** config it later **/
609 .bp_reg = LDO_INVALID_REG_ADDR,
611 .bp_rst_reg = LDO_INVALID_REG_ADDR,
613 .level_reg_b0 = LDO_INVALID_REG_ADDR,
616 .level_reg_b1 = LDO_INVALID_REG_ADDR,
619 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
623 .bp_reg = LDO_INVALID_REG_ADDR,
625 .bp_rst_reg = LDO_INVALID_REG_ADDR,
627 .level_reg_b0 = LDO_INVALID_REG_ADDR,
630 .level_reg_b1 = LDO_INVALID_REG_ADDR,
633 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
637 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
639 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
641 .level_reg_b0 = ANA_REG_GLB_DCDC_MEM_ADI,
644 .level_reg_b1 = ANA_REG_GLB_DCDC_MEM_ADI,
647 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
651 .bp_reg = LDO_INVALID_REG_ADDR,
653 .bp_rst_reg = LDO_INVALID_REG_ADDR,
655 .level_reg_b0 = LDO_INVALID_REG_ADDR,
658 .level_reg_b1 = LDO_INVALID_REG_ADDR,
661 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
665 .bp_reg = LDO_INVALID_REG_ADDR,
667 .bp_rst_reg = LDO_INVALID_REG_ADDR,
669 .level_reg_b0 = LDO_INVALID_REG_ADDR,
672 .level_reg_b1 = LDO_INVALID_REG_ADDR,
675 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
679 .bp_reg = LDO_INVALID_REG_ADDR,
681 .bp_rst_reg = LDO_INVALID_REG_ADDR,
683 .level_reg_b0 = LDO_INVALID_REG_ADDR,
686 .level_reg_b1 = LDO_INVALID_REG_ADDR,
689 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
693 .bp_reg = LDO_INVALID_REG_ADDR,
695 .bp_rst_reg = LDO_INVALID_REG_ADDR,
697 .level_reg_b0 = LDO_INVALID_REG_ADDR,
700 .level_reg_b1 = LDO_INVALID_REG_ADDR,
703 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
707 .bp_reg = LDO_INVALID_REG_ADDR,
709 .bp_rst_reg = LDO_INVALID_REG_ADDR,
711 .level_reg_b0 = LDO_INVALID_REG_ADDR,
714 .level_reg_b1 = LDO_INVALID_REG_ADDR,
717 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
721 .bp_reg = LDO_INVALID_REG_ADDR,
723 .bp_rst_reg = LDO_INVALID_REG_ADDR,
725 .level_reg_b0 = LDO_INVALID_REG_ADDR,
728 .level_reg_b1 = LDO_INVALID_REG_ADDR,
731 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
735 .bp_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCSET,
737 .bp_rst_reg = ANA_REG_GLB_LDO_DCDC_PD_RTCCLR,
739 .level_reg_b0 = LDO_INVALID_REG_ADDR,
742 .level_reg_b1 = LDO_INVALID_REG_ADDR,
745 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
749 .bp_reg = LDO_INVALID_REG_ADDR,
751 .bp_rst_reg = LDO_INVALID_REG_ADDR,
753 .level_reg_b0 = LDO_INVALID_REG_ADDR,
756 .level_reg_b1 = LDO_INVALID_REG_ADDR,
759 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
763 .bp_reg = LDO_INVALID_REG_ADDR,
765 .bp_rst_reg = LDO_INVALID_REG_ADDR,
767 .level_reg_b0 = LDO_INVALID_REG_ADDR,
770 .level_reg_b1 = LDO_INVALID_REG_ADDR,
773 .init_level = LDO_VOLT_LEVEL_FAULT_MAX,
777 /**---------------------------------------------------------------------------*
778 ** Function Declaration *
779 **---------------------------------------------------------------------------*/
780 static struct ldo_ctl_info* LDO_GetLdoCtl(LDO_ID_E ldo_id)
783 struct ldo_ctl_info* ctl = NULL;
785 for ( i = 0; i < ARRAY_SIZE(ldo_ctl_data); ++i)
787 if (ldo_ctl_data[i].id == ldo_id)
789 ctl = &ldo_ctl_data[i];
794 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
798 LDO_ERR_E LDO_TurnOnLDO(LDO_ID_E ldo_id)
800 struct ldo_ctl_info* ctl = NULL;
802 if (ldo_id == LDO_LDO_SDIO3)
804 if (LDO_TurnOnLDO(LDO_LDO_EMMCCORE) != LDO_ERR_OK)
806 if (LDO_TurnOnLDO(LDO_LDO_EMMCIO) != LDO_ERR_OK)
811 ctl = LDO_GetLdoCtl(ldo_id);
812 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
814 //if ((ctl->ref++) == 0)
816 if(ctl->bp_reg == LDO_INVALID_REG_ADDR)
818 //if (LDO_LDO_USBD == ldo_id)
819 // CHIP_REG_AND((~LDO_USB_PD), GR_CLK_GEN5);
824 ANA_REG_OR (ctl->bp_rst_reg, ctl->bp_rst);
825 ANA_REG_AND(ctl->bp_reg, ~(ctl->bp_bits));
827 ctl->current_status = CURRENT_STATUS_ON;
832 LDO_ERR_E LDO_TurnOffLDO(LDO_ID_E ldo_id)
834 struct ldo_ctl_info* ctl = NULL;
836 if (ldo_id == LDO_LDO_SDIO3)
838 if (LDO_TurnOffLDO(LDO_LDO_EMMCCORE) != LDO_ERR_OK)
840 if (LDO_TurnOffLDO(LDO_LDO_EMMCIO) != LDO_ERR_OK)
845 ctl = LDO_GetLdoCtl(ldo_id);
846 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
848 //local_irq_save(flags);
850 //if ((--ctl->ref) == 0)
852 if(ctl->bp_reg == LDO_INVALID_REG_ADDR)
854 //if (LDO_LDO_USBD == ldo_id)
855 // CHIP_REG_OR((LDO_USB_PD), GR_CLK_GEN5);
859 ANA_REG_AND(ctl->bp_rst_reg, (~(ctl->bp_rst)));
860 ANA_REG_OR (ctl->bp_reg, ctl->bp_bits);
862 ctl->current_status = CURRENT_STATUS_OFF;
865 //local_irq_restore(flags);
870 int LDO_IsLDOOn(LDO_ID_E ldo_id)
872 unsigned int masked_val = 0;
873 struct ldo_ctl_info* ctl = NULL;
875 ctl = LDO_GetLdoCtl(ldo_id);
876 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
878 if (ctl->current_status == CURRENT_STATUS_INIT)
880 masked_val = (LDO_REG_GET(ctl->bp_reg) & ctl->bp_bits);
884 return (ctl->current_status == CURRENT_STATUS_OFF ? 0 : 1);
887 return (masked_val ? 0 : 1);
890 LDO_ERR_E LDO_SetVoltLevel(LDO_ID_E ldo_id, LDO_VOLT_LEVEL_E volt_level)
892 unsigned short reg_data;
893 struct ldo_ctl_info* ctl = NULL;
895 ctl = LDO_GetLdoCtl(ldo_id);
896 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
898 if (ctl->level_reg_b0 == LDO_INVALID_REG_ADDR)
903 if (ctl->level_reg_b0 != ctl->level_reg_b1)
905 printf("ldo_id:%d, level_reg_b0:%08x, level_reg_b1:%08x\r\n", ldo_id, ctl->level_reg_b0, ctl->level_reg_b1);
911 case LDO_VOLT_LEVEL0:
912 ANA_REG_AND(ctl->level_reg_b0, (~(ctl->b0|ctl->b1)));
915 case LDO_VOLT_LEVEL1:
916 reg_data = ANA_REG_GET(ctl->level_reg_b0);
919 ANA_REG_SET(ctl->level_reg_b0, reg_data);
922 case LDO_VOLT_LEVEL2:
923 reg_data = ANA_REG_GET(ctl->level_reg_b0);
926 ANA_REG_SET(ctl->level_reg_b0, reg_data);
929 case LDO_VOLT_LEVEL3:
930 ANA_REG_OR (ctl->level_reg_b0, (ctl->b0|ctl->b1));
937 ctl->current_volt_level = volt_level;
943 LDO_VOLT_LEVEL_E LDO_GetVoltLevel(LDO_ID_E ldo_id)
945 unsigned int level_ret = 0;
946 struct ldo_ctl_info* ctl = NULL;
948 ctl = LDO_GetLdoCtl(ldo_id);
949 SCI_PASSERT(ctl != NULL, ("ldo_id = %d", ldo_id));
951 if (ctl->current_volt_level == LDO_VOLT_LEVEL_FAULT_MAX)
953 if(ctl->level_reg_b0 == ctl->level_reg_b1)
960 SCI_PASSERT(0, ("shakr b0 must equal b1!"));
965 level_ret = ctl->current_volt_level;
974 for ( i = 0; i < ARRAY_SIZE(ldo_ctl_data); ++i)
976 if( ldo_ctl_data[i].init_level != LDO_VOLT_LEVEL_FAULT_MAX)
978 LDO_SetVoltLevel(ldo_ctl_data[i].id, ldo_ctl_data[i].init_level);
980 ldo_ctl_data[i].ref = 0;
981 ldo_ctl_data[i].current_status = CURRENT_STATUS_INIT;
982 ldo_ctl_data[i].current_volt_level = ldo_ctl_data[i].init_level;
987 static void LDO_TurnOffCoreLDO(void)
989 ANA_REG_SET(ANA_REG_GLB_LDO_DCDC_PD_RTCCLR, 0x0);
990 ANA_REG_SET(ANA_REG_GLB_LDO_DCDC_PD_RTCSET, 0x7FFF);
993 static void LDO_TurnOffAllModuleLDO(void)
995 ANA_REG_SET(ANA_REG_GLB_LDO_PD_CTRL, 0x1FFF);
998 void LDO_TurnOffAllLDO(void)
1000 LDO_TurnOffAllModuleLDO();
1001 LDO_TurnOffCoreLDO();