3 #include <asm/arch/sprd_reg.h>
4 #include <asm/arch/sci_types.h>
5 #include <asm/arch/adi_hal_internal.h>
7 extern void __raw_bits_or(unsigned int v, unsigned int a);
10 REG_AON_APB_BOND_OPT0 ==> romcode set
11 REG_AON_APB_BOND_OPT1 ==> set it later
13 !!! notice: these two registers can be set only one time!!!
22 /*************************************************
23 * 1 : enable jtag success *
24 * 0 : enable jtag fail *
25 *************************************************/
26 int sprd_jtag_enable(void)
28 if (*((volatile unsigned int *)(REG_AON_APB_BOND_OPT0)) & 1)
30 *((volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) = 1;
31 if (!((*(volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) & 1))
37 /*************************************************
38 * 1 : disable jtag success *
39 * 0 : disable jtag fail *
40 *************************************************/
41 int sprd_jtag_disable(void)
43 if (!(*((volatile unsigned int *)(REG_AON_APB_BOND_OPT0)) & 1))
49 *((volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) = 0;
50 if (*((volatile unsigned int *)(REG_AON_APB_BOND_OPT1)) & 1)
57 static void ap_slp_cp_dbg_cfg(void)
59 *((volatile unsigned int *)(REG_AP_AHB_MCU_PAUSE)) |= BIT_MCU_SLEEP_FOLLOW_CA7_EN; //when ap sleep, cp can continue debug
62 static void ap_cpll_rel_cfg(void)
64 *((volatile unsigned int *)(REG_PMU_APB_CPLL_REL_CFG)) |= BIT_CPLL_AP_SEL;
68 static void ap_close_wpll_en(void)
70 *((volatile unsigned int *)(REG_PMU_APB_CGM_AP_EN)) &= ~BIT_CGM_WPLL_AP_EN;
73 static void ap_close_cpll_en(void)
75 *((volatile unsigned int *)(REG_PMU_APB_CGM_AP_EN)) &= ~BIT_CGM_CPLL_AP_EN;
78 static void ap_close_wifipll_en(void)
80 *((volatile unsigned int *)(REG_PMU_APB_CGM_AP_EN)) &= ~BIT_CGM_WIFIPLL1_AP_EN;
85 static void bb_bg_auto_en(void)
87 *((volatile unsigned int *)(REG_AON_APB_RES_REG0)) |= 1<<8;
90 static void bb_ldo_auto_en(void)
92 *((volatile unsigned int *)(REG_AON_APB_RES_REG0)) |= 1<<9;
96 #ifdef CONFIG_PBINT_7S_RESET_V1
98 #define PBINT_7S_HW_FLAG (BIT(7))
99 #define PBINT_7S_SW_FLAG (BIT(12))
101 #define CONFIG_7S_RESET_SW_FLAG
102 #ifdef CONFIG_7S_RESET_SW_FLAG
103 static u32 pbint_7s_flag = 0;
105 int is_7s_reset(void)
107 #ifdef CONFIG_7S_RESET_SW_FLAG
108 return pbint_7s_flag & PBINT_7S_SW_FLAG;
110 return sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & PBINT_7S_SW_FLAG;
114 int is_7s_reset_for_systemdump(void)
118 int mask = PBINT_7S_SW_FLAG | PBINT_7S_HW_FLAG;
119 /* some chip just care software flag */
120 int chip_id = ANA_GET_CHIP_ID();
121 if (((chip_id >> 16) & 0xFFFF) == 0x2711) {
122 if ((chip_id & 0xFFFF) <= 0xA100) {
123 mask = PBINT_7S_SW_FLAG;
126 #ifdef CONFIG_7S_RESET_SW_FLAG
127 val = pbint_7s_flag & mask;
129 val = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & mask;
131 return (val == PBINT_7S_SW_FLAG);
134 static inline int pbint_7s_rst_disable(uint32 disable)
137 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_DISABLE);
139 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_DISABLE);
143 static inline int pbint_7s_rst_set_2keymode(uint32 mode)
145 #if defined CONFIG_ADIE_SC2723S || defined CONFIG_ADIE_SC2723
146 if(sci_adi_read(ANA_REG_GLB_CHIP_ID_LOW) == 0xA000) {
148 sci_adi_clr(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
150 sci_adi_set(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
154 sci_adi_set(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
156 sci_adi_clr(ANA_REG_GLB_SWRST_CTRL, BIT_KEY2_7S_RST_EN);
160 #error "please check pbint_7s_rst_set_2keymode reg"
164 static inline int pbint_7s_rst_set_sw(uint32 mode)
167 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_MODE);
169 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_MODE);
174 static inline int pbint_7s_rst_set_swmode(uint32 mode)
177 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_SWMODE);
179 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_RST_SWMODE);
184 static inline int pbint_7s_rst_set_threshold(uint32 th)
186 int mask = BITS_PBINT_7S_RST_THRESHOLD(-1);
187 int shift = ffs(mask) - 1;
190 sci_adi_write(ANA_REG_GLB_POR_7S_CTRL, (th << shift) & mask, mask);
194 int pbint_7s_rst_cfg(uint32 en, uint32 sw_rst, uint32 short_rst)
196 #ifdef CONFIG_7S_RESET_SW_FLAG
197 pbint_7s_flag = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG);
198 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
200 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
202 /* ignore sw_rst, please refer to config.h */
204 pbint_7s_rst_set_threshold(CONFIG_7S_RST_THRESHOLD);
205 pbint_7s_rst_set_sw(!sw_rst);
207 pbint_7s_rst_set_swmode(short_rst);
209 pbint_7s_rst_set_2keymode(CONFIG_7S_RST_2KEY_MODE);
211 return pbint_7s_rst_disable(!en);
213 #elif defined CONFIG_PBINT_7S_RESET_V0
215 #define PBINT_7S_HW_FLAG (BIT(7))
216 #define PBINT_7S_SW_FLAG (BIT(12))
218 #define CONFIG_7S_RESET_SW_FLAG
219 #ifdef CONFIG_7S_RESET_SW_FLAG
220 static u32 pbint_7s_flag = 0;
222 int is_7s_reset(void)
224 #ifdef CONFIG_7S_RESET_SW_FLAG
225 return pbint_7s_flag & PBINT_7S_SW_FLAG;
227 return sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & PBINT_7S_SW_FLAG;
231 int is_7s_reset_for_systemdump(void)
234 int mask = PBINT_7S_SW_FLAG;
235 #ifdef CONFIG_7S_RESET_SW_FLAG
236 val = pbint_7s_flag & mask;
238 val = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG) & mask;
240 return (val == mask);
243 void pbint_7s_rst_cfg(uint32 en_rst, uint32 sw_rst, uint32 short_rst)
245 uint16 reg_data = ANA_REG_GET(ANA_REG_GLB_POR_7S_CTRL);
247 #ifdef CONFIG_7S_RESET_SW_FLAG
248 pbint_7s_flag = sci_adi_read(ANA_REG_GLB_POR_SRC_FLAG);
249 sci_adi_set(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
251 sci_adi_clr(ANA_REG_GLB_POR_7S_CTRL, BIT_PBINT_7S_FLAG_CLR);
256 reg_data |= BIT_PBINT_7S_RST_DISABLE;
260 reg_data &= ~BIT_PBINT_7S_RST_DISABLE;
264 reg_data |= BIT_PBINT_7S_RST_MODE_RTCSET;
265 reg_data &= ~BIT_PBINT_7S_RST_MODE_RTCCLR;
269 reg_data &= ~BIT_PBINT_7S_RST_MODE_RTCSET;
270 reg_data |= BIT_PBINT_7S_RST_MODE_RTCCLR;
275 reg_data |= BIT_PBINT_7S_RST_SWMODE_RTCSET;
276 reg_data &= ~BIT_PBINT_7S_RST_SWMODE_RTCCLR;
280 reg_data &= ~BIT_PBINT_7S_RST_SWMODE_RTCSET;
281 reg_data |= BIT_PBINT_7S_RST_SWMODE_RTCCLR;
284 ANA_REG_SET(ANA_REG_GLB_POR_7S_CTRL, reg_data);
285 printf("ANA_REG_GLB_POR_7S_CTRL:%04X\r\n", ANA_REG_GET(ANA_REG_GLB_POR_7S_CTRL));
289 #if defined (CONFIG_OF_LIBFDT) && !defined (CONFIG_SPX30G)
290 void scx35_pmu_reconfig(void)
293 * turn on gpu/mm domain for clock device initcall, and then turn off asap.
295 __raw_writel(__raw_readl(REG_PMU_APB_PD_MM_TOP_CFG)
296 & ~(BIT_PD_MM_TOP_FORCE_SHUTDOWN),
297 REG_PMU_APB_PD_MM_TOP_CFG);
299 __raw_writel(__raw_readl(REG_PMU_APB_PD_GPU_TOP_CFG)
300 & ~(BIT_PD_GPU_TOP_FORCE_SHUTDOWN),
301 REG_PMU_APB_PD_GPU_TOP_CFG);
303 __raw_writel(__raw_readl(REG_AON_APB_APB_EB0) | BIT_MM_EB |
304 BIT_GPU_EB, REG_AON_APB_APB_EB0);
306 __raw_writel(__raw_readl(REG_MM_AHB_AHB_EB) | BIT_MM_CKG_EB,
309 __raw_writel(__raw_readl(REG_MM_AHB_GEN_CKG_CFG)
310 | BIT_MM_MTX_AXI_CKG_EN | BIT_MM_AXI_CKG_EN,
311 REG_MM_AHB_GEN_CKG_CFG);
313 __raw_writel(__raw_readl(REG_MM_CLK_MM_AHB_CFG) | 0x3,
314 REG_MM_CLK_MM_AHB_CFG);
319 void scx35_pmu_reconfig(void) {}
321 inline int is_hw_smpl_enable(void)
323 #if defined CONFIG_ADIE_SC2723S || defined CONFIG_ADIE_SC2723
324 return !!(sci_adi_read(ANA_REG_GLB_SMPL_CTRL1) & BIT_SMPL_EN);
329 #if !defined CONFIG_SPX15 && !defined CONFIG_SPX30G
330 int is_smpl_bootup(void)
332 if(sci_adi_read(ANA_REG_GLB_CHIP_ID_LOW) == 0xCA00) {
333 return sci_adi_read(ANA_REG_GLB_CA_CTRL2) & BIT_IS_SMPL_ON;
339 #define SMPL_MODE_ENABLE_SET (0x1935)
340 static int smpl_config(void)
343 if(sci_adi_read(ANA_REG_GLB_CHIP_ID_LOW) == 0xCA00) {
344 val = BITS_SMPL_ENABLE(SMPL_MODE_ENABLE_SET);
345 return sci_adi_write_fast(ANA_REG_GLB_CA_CTRL1, val, 1);
349 #ifdef CONFIG_SMPL_MODE
350 #if defined(CONFIG_TSHARK2TABE) || defined(CONFIG_GRANDPRIME3G_VE)|| defined(CONFIG_COREPRIME3G_VE) || defined(CONFIG_TSHARK2J2_3G) || defined(CONFIG_TIZENZ3_3G) || defined(CONFIG_GRANDPRIME_DTV)
351 //#define CONFIG_SMPL_SW_FLAG
353 #define CONFIG_SMPL_SW_FLAG
355 #ifdef CONFIG_SMPL_SW_FLAG
356 static u32 smpl_flag = 0;
358 int is_smpl_bootup(void)
360 #ifdef CONFIG_SMPL_SW_FLAG
361 return smpl_flag & BIT_IS_SMPL_ON_SW_FLAG;
363 #ifdef CONFIG_PBINT_7S_RST_HW_SHORT
364 return sci_adi_read(ANA_REG_GLB_SMPL_CTRL1) & BIT_SMPL_PWR_ON_SET;
366 return sci_adi_read(ANA_REG_GLB_SMPL_CTRL1) & BIT_SMPL_PWR_ON_FLAG;
371 #define SMPL_MODE_ENABLE_SET (0x1935)
372 static int smpl_config(void)
374 u32 val = BITS_SMPL_ENABLE(SMPL_MODE_ENABLE_SET);
375 #ifdef CONFIG_SMPL_THRESHOLD
376 val |= BITS_SMPL_THRESHOLD(CONFIG_SMPL_THRESHOLD);
378 #ifdef CONFIG_SMPL_SW_FLAG
379 smpl_flag = sci_adi_read(ANA_REG_GLB_BA_CTRL1);
380 sci_adi_set(ANA_REG_GLB_BA_CTRL1, BIT_IS_SMPL_ON_SW_CLR);
382 #if defined(CONFIG_TSHARK2TABE) || defined(CONFIG_GRANDPRIME3G_VE) || defined(CONFIG_COREPRIME3G_VE) || defined(CONFIG_TSHARK2J2_3G) || defined(CONFIG_TIZENZ3_3G) || defined(CONFIG_GRANDPRIME_DTV)
383 return sci_adi_write_fast(ANA_REG_GLB_SMPL_CTRL0, val, 1);
385 return sci_adi_write_fast(ANA_REG_GLB_BA_CTRL0, val, 1);
389 __attribute__ ((gnu_inline))inline int is_smpl_bootup(void)
394 inline static int smpl_config(void)
400 static void vbat_crash_vol_set(void)
402 #if !defined CONFIG_SPX15 && !defined CONFIG_SPX30G
404 if(sci_adi_read(ANA_REG_GLB_CHIP_ID_LOW) == 0xCA00) {
405 val = sci_adi_read(ANA_REG_GLB_CA_CTRL3);
408 sci_adi_write(ANA_REG_GLB_CA_CTRL3, val, 0xffff);
418 pbint_7s_rst_cfg(CONFIG_7S_RST_MODULE_EN,
419 CONFIG_7S_RST_SW_MODE,
420 CONFIG_7S_RST_SHORT_MODE);
423 #if defined CONFIG_ADIE_SC2723S || defined CONFIG_ADIE_SC2723
424 sci_adi_set(ANA_REG_GLB_LDO_SHPT_PD2, BIT_LDO_VIBR_SHPT_PD); //close vibr short protection
426 val = BITS_SMPL_ENABLE(SMPL_MODE_DISABLE_SET);
427 ci_adi_write_fast(ANA_REG_GLB_SMPL_CTRL0, val, 1);
428 #endif /* CONFIG_TIZEN */
434 #define REBOOT_MODE_MASK (0xFFFFFFF0)
435 #define REBOOT_MODE_PREFIX (0x12345670)
436 #define REBOOT_THOR_DOWNLOAD (0x1)
437 #define REBOOT_RECOVERY (0x4)
438 int tizen_reboot_check(void)
440 int inform3 = readl(INFORM3);
442 if ((inform3 & REBOOT_MODE_MASK) == REBOOT_MODE_PREFIX) {
443 if ((inform3 & 0xf) == REBOOT_THOR_DOWNLOAD) {
452 int tizen_reboot_recovery_check(void)
454 int inform3 = readl(INFORM3);
456 if ((inform3 & REBOOT_MODE_MASK) == REBOOT_MODE_PREFIX) {
457 if ((inform3 & 0xf) == REBOOT_RECOVERY) {
467 #define REG32(x) (*((volatile uint32 *)(x)))
468 void gpu_clk_auto_gate_disable(void)
470 REG32(REG_PMU_APB_CGM_GPU_MM_AUTO_GATE_EN) &= ~(0x7F);
475 scx35_pmu_reconfig();
479 // ap_close_wpll_en();
480 // ap_close_cpll_en();
481 // ap_close_wifipll_en();
483 #ifndef CONFIG_SPX30G
488 * To avoid GPU lockup issue (Bug 413283, 428056),
489 * disable GPU clk auto gating on SC7730 board
491 gpu_clk_auto_gate_disable();
495 vbat_crash_vol_set();
498 /*csi0_phy_powerdow & csi1_phy_powerdow*/
499 __raw_bits_or((BIT_CSI1_PHY_PD | BIT_CSI0_PHY_PD), REG_AON_APB_PWR_CTRL);
501 __raw_bits_or(BIT_DSI_PHY_PD, REG_AON_APB_PWR_CTRL);
503 /* Fix /dev/stty_w open issues */
504 ANA_REG_SET(ANA_REG_GLB_WDG_RST_MONITOR, 0);
507 typedef struct mem_cs_info
510 uint32 cs0_size;//bytes
511 uint32 cs1_size;//bytes
513 PUBLIC int get_dram_cs_number(void)
515 mem_cs_info_t *cs_info_ptr = (mem_cs_info_t *)0x1C00;
516 return cs_info_ptr->cs_number;
518 PUBLIC int get_dram_cs0_size(void)
520 mem_cs_info_t *cs_info_ptr = (mem_cs_info_t *)0x1C00;
521 return cs_info_ptr->cs0_size;