3 #include <asm/arch/sprd_reg.h>
4 #include <asm/arch/sci_types.h>
5 #include <asm/arch/adi_hal_internal.h>
7 REG_AON_APB_BOND_OPT0 ==> romcode set
8 REG_AON_APB_BOND_OPT1 ==> set it later
10 !!! notice: these two registers can be set only one time!!!
19 /*************************************************
20 * 1 : enable jtag success *
21 * 0 : enable jtag fail *
22 *************************************************/
23 int sprd_jtag_enable()
25 if (*((volatile unsigned int *)(REG_AON_APB_BOND_OPT0)) & 1)
27 *((volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) = 1;
28 if (!((*(volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) & 1))
34 /*************************************************
35 * 1 : disable jtag success *
36 * 0 : disable jtag fail *
37 *************************************************/
38 int sprd_jtag_disable()
40 if (!(*((volatile unsigned int *)(REG_AON_APB_BOND_OPT0)) & 1))
46 *((volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) = 0;
47 if (*((volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) & 1)
54 static void ap_slp_cp_dbg_cfg()
56 *((volatile unsigned int *)(REG_AP_AHB_MCU_PAUSE)) |= BIT_MCU_SLEEP_FOLLOW_CA7_EN; //when ap sleep, cp can continue debug
59 static void ap_cpll_rel_cfg()
61 #if !defined(CONFIG_ARCH_SCX35L)
62 *((volatile unsigned int *)(REG_PMU_APB_CPLL_REL_CFG)) |= BIT_CPLL_AP_SEL;
66 static void bb_bg_auto_en()
68 *((volatile unsigned int *)(REG_AON_APB_RES_REG0)) |= 1<<8;
72 static void ap_close_wpll_en()
74 #if !defined(CONFIG_ARCH_SCX35L)
75 *((volatile unsigned int *)(REG_PMU_APB_CGM_AP_EN)) &= ~BIT_CGM_WPLL_AP_EN;
79 static void ap_close_cpll_en()
81 #if !defined(CONFIG_ARCH_SCX35L)
82 *((volatile unsigned int *)(REG_PMU_APB_CGM_AP_EN)) &= ~BIT_CGM_CPLL_AP_EN;
86 static void ap_close_wifipll_en()
88 #if !defined(CONFIG_ARCH_SCX35L)
89 *((volatile unsigned int *)(REG_PMU_APB_CGM_AP_EN)) &= ~BIT_CGM_WIFIPLL1_AP_EN;
94 static void bb_ldo_auto_en()
96 *((volatile unsigned int *)(REG_AON_APB_RES_REG0)) |= 1<<9;
99 #ifdef CONFIG_PBINT_7S_RESET_V1
101 #define PBINT_7S_HW_FLAG (BIT(7))
102 #define PBINT_7S_SW_FLAG (BIT(12))
104 #define CONFIG_7S_RESET_SW_FLAG
105 #ifdef CONFIG_7S_RESET_SW_FLAG
106 static u32 pbint_7s_flag = 0;
108 int is_7s_reset(void)
110 #ifdef CONFIG_7S_RESET_SW_FLAG
111 return pbint_7s_flag & PBINT_7S_SW_FLAG;
113 return sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & PBINT_7S_SW_FLAG;
117 int is_7s_reset_for_systemdump(void)
121 int mask = PBINT_7S_SW_FLAG | PBINT_7S_HW_FLAG;
122 /* some chip just care software flag */
123 int chip_id = ANA_GET_CHIP_ID();
124 if (((chip_id >> 16) & 0xFFFF) == 0x2711) {
125 if ((chip_id & 0xFFFF) <= 0xA100) {
126 mask = PBINT_7S_SW_FLAG;
129 #ifdef CONFIG_7S_RESET_SW_FLAG
130 val = pbint_7s_flag & mask;
132 val = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & mask;
134 return (val == PBINT_7S_SW_FLAG);
137 static inline int pbint_7s_rst_disable(uint32 disable)
140 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_DISABLE);
142 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_DISABLE);
146 static inline int pbint_7s_rst_set_2keymode(uint32 mode)
148 #if defined CONFIG_ADIE_SC2723S || defined CONFIG_ADIE_SC2723
149 if(sci_adi_read(ANA_REG_GLB_CHIP_ID_LOW) == 0xA000) {
151 sci_adi_clr(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
153 sci_adi_set(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
157 sci_adi_set(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
159 sci_adi_clr(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
163 #error "please check pbint_7s_rst_set_2keymode reg"
167 static inline int pbint_7s_rst_set_sw(uint32 mode)
170 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_MODE);
172 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_MODE);
177 static inline int pbint_7s_rst_set_swmode(uint32 mode)
180 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_SWMODE);
182 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_SWMODE);
187 static inline int pbint_7s_rst_set_threshold(uint32 th)
189 int mask = BITS_PBINT_7S_RST_THRESHOLD(-1);
190 int shift = ffs(mask) - 1;
193 sci_adi_write(ANA_REG_GLB_POR_7S_CTRL, (th << shift) & mask, mask);
197 int pbint_7s_rst_cfg(uint32 en, uint32 sw_rst, uint32 short_rst)
199 #ifdef CONFIG_7S_RESET_SW_FLAG
200 pbint_7s_flag = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG);
201 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
203 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
205 /* ignore sw_rst, please refer to config.h */
207 pbint_7s_rst_set_threshold(CONFIG_7S_RST_THRESHOLD);
208 pbint_7s_rst_set_sw(!sw_rst);
210 pbint_7s_rst_set_swmode(short_rst);
212 pbint_7s_rst_set_2keymode(CONFIG_7S_RST_2KEY_MODE);
214 return pbint_7s_rst_disable(!en);
216 #elif defined CONFIG_PBINT_7S_RESET_V0
218 #define PBINT_7S_HW_FLAG (BIT(7))
219 #define PBINT_7S_SW_FLAG (BIT(12))
221 #define CONFIG_7S_RESET_SW_FLAG
222 #ifdef CONFIG_7S_RESET_SW_FLAG
223 static u32 pbint_7s_flag = 0;
225 int is_7s_reset(void)
227 #ifdef CONFIG_7S_RESET_SW_FLAG
228 return pbint_7s_flag & PBINT_7S_SW_FLAG;
230 return sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & PBINT_7S_SW_FLAG;
234 int is_7s_reset_for_systemdump(void)
237 int mask = PBINT_7S_SW_FLAG;
238 #ifdef CONFIG_7S_RESET_SW_FLAG
239 val = pbint_7s_flag & mask;
241 val = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & mask;
243 return (val == mask);
246 void pbint_7s_rst_cfg(uint32 en_rst, uint32 sw_rst, uint32 short_rst)
248 uint16 reg_data = ANA_REG_GET(ANA_REG_GLB_POR_7S_CTRL);
250 #ifdef CONFIG_7S_RESET_SW_FLAG
251 pbint_7s_flag = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG);
252 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
254 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
259 reg_data |= BIT_PBINT_7S_RST_DISABLE;
263 reg_data &= ~BIT_PBINT_7S_RST_DISABLE;
267 reg_data |= BIT_PBINT_7S_RST_MODE_RTCSET;
268 reg_data &= ~BIT_PBINT_7S_RST_MODE_RTCCLR;
272 reg_data &= ~BIT_PBINT_7S_RST_MODE_RTCSET;
273 reg_data |= BIT_PBINT_7S_RST_MODE_RTCCLR;
278 reg_data |= BIT_PBINT_7S_RST_SWMODE_RTCSET;
279 reg_data &= ~BIT_PBINT_7S_RST_SWMODE_RTCCLR;
283 reg_data &= ~BIT_PBINT_7S_RST_SWMODE_RTCSET;
284 reg_data |= BIT_PBINT_7S_RST_SWMODE_RTCCLR;
287 ANA_REG_SET(ANA_REG_GLB_POR_7S_CTRL, reg_data);
288 printf("ANA_REG_GLB_POR_7S_CTRL:%04X\r\n", ANA_REG_GET(ANA_REG_GLB_POR_7S_CTRL));
292 #ifdef CONFIG_OF_LIBFDT
293 void scx35_pmu_reconfig(void)
296 * turn on gpu/mm domain for clock device initcall, and then turn off asap.
298 __raw_writel(__raw_readl(REG_PMU_APB_PD_MM_TOP_CFG)
299 & ~(BIT_PD_MM_TOP_FORCE_SHUTDOWN),
300 REG_PMU_APB_PD_MM_TOP_CFG);
302 while (__raw_readl(REG_PMU_APB_PWR_STATUS0_DBG) & 0xf0000000) {};
304 __raw_writel(__raw_readl(REG_PMU_APB_PD_GPU_TOP_CFG)
305 & ~(BIT_PD_GPU_TOP_FORCE_SHUTDOWN),
306 REG_PMU_APB_PD_GPU_TOP_CFG);
308 while (__raw_readl(REG_PMU_APB_PWR_STATUS0_DBG) & 0x0f000000) {};
310 __raw_writel(__raw_readl(REG_AON_APB_APB_EB0) | BIT_MM_EB |
311 BIT_GPU_EB, REG_AON_APB_APB_EB0);
313 __raw_writel(__raw_readl(REG_MM_AHB_RF_AHB_EB) | BIT_CKG_EB,
314 REG_MM_AHB_RF_AHB_EB);
315 __raw_writel(__raw_readl(REG_MM_AHB_RF_GEN_CKG_CFG)
316 | BIT_MM_MTX_AXI_CKG_EN | BIT_MM_AXI_CKG_EN,
317 REG_MM_AHB_RF_GEN_CKG_CFG);
321 __raw_writel(__raw_readl(REG_MM_CLK_MM_AHB_CFG) | 0x3,
322 REG_MM_CLK_MM_AHB_CFG);
327 void scx35_pmu_reconfig(void) {}
329 inline int is_hw_smpl_enable(void)
331 #if defined CONFIG_ADIE_SC2723S || defined CONFIG_ADIE_SC2723
332 return !!(sci_adi_read(ANA_REG_GLB_SMPL_CTRL1) & BIT_SMPL_EN);
337 #ifdef CONFIG_SMPL_MODE
338 #define CONFIG_SMPL_SW_FLAG
339 #ifdef CONFIG_SMPL_SW_FLAG
340 static u32 smpl_flag = 0;
342 int is_smpl_bootup(void)
344 #ifdef CONFIG_SMPL_SW_FLAG
345 if( 0x2723A090 == ANA_GET_CHIP_ID() ){
346 return smpl_flag & BIT_SMPL_PWR_ON_FLAG;
352 return sci_adi_read(ANA_REG_GLB_BA_CTRL1) & BIT_IS_SMPL_ON;
356 #define SMPL_MODE_ENABLE_SET (0x1935)
357 static int smpl_config(void)
360 if( 0x2723A090 != ANA_GET_CHIP_ID() ){
363 val = BITS_SMPL_ENABLE(SMPL_MODE_ENABLE_SET);
364 #ifdef CONFIG_SMPL_THRESHOLD
365 val |= BITS_SMPL_THRESHOLD(CONFIG_SMPL_THRESHOLD);
367 #ifdef CONFIG_SMPL_SW_FLAG
368 smpl_flag = sci_adi_read(ANA_REG_GLB_SMPL_CTRL1);
369 sci_adi_set(ANA_REG_GLB_SMPL_CTRL1, BIT_SMPL_PWR_ON_FLAG_CLR);
371 return sci_adi_write_fast(ANA_REG_GLB_SMPL_CTRL0, val, 1);
374 inline int is_smpl_bootup(void)
379 inline static int smpl_config(void)
387 pbint_7s_rst_cfg(CONFIG_7S_RST_MODULE_EN,
388 CONFIG_7S_RST_SW_MODE,
389 CONFIG_7S_RST_SHORT_MODE);
391 sci_adi_set(ANA_REG_GLB_LDO_SHPT_PD2, BIT_LDO_VIBR_SHPT_PD); //close vibr short protection
395 scx35_pmu_reconfig();
401 ap_close_wifipll_en();
409 typedef struct mem_cs_info
412 uint32 cs0_size;//bytes
413 uint32 cs1_size;//bytes
415 PUBLIC int get_dram_cs_number(void)
417 mem_cs_info_t *cs_info_ptr = 0x1C00;
418 return cs_info_ptr->cs_number;
420 PUBLIC int get_dram_cs0_size(void)
422 mem_cs_info_t *cs_info_ptr = 0x1C00;
423 return cs_info_ptr->cs0_size;