2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <asm/cacheflush.h>
5 #include <asm/tlbflush.h>
6 #include <asm/hardware/cache-l2x0.h>
7 #include <linux/module.h>
8 #include <linux/platform_device.h>
11 #include <linux/suspend.h>
15 #include <linux/of_address.h>
17 #include <linux/rockchip/cpu.h>
18 //#include <linux/rockchip/cru.h>
19 #include <linux/rockchip/grf.h>
20 #include <linux/rockchip/iomap.h>
28 /*************************cru define********************************************/
29 #define RK3288_CRU_UNGATING_OPS(id) cru_writel(CRU_W_MSK_SETBITS(0,id%16,0x1),RK3288_CRU_GATEID_CONS(id))
30 #define RK3288_CRU_GATING_OPS(id) cru_writel(CRU_W_MSK_SETBITS(1,id%16,0x1),RK3288_CRU_GATEID_CONS(id))
34 /*******************************gpio define **********************************************/
35 #define GPIO_INTEN 0x30
36 #define GPIO_INTMASK 0x34
37 #define GPIO_INTTYPE_LEVEL 0x38
38 #define GPIO_INT_POLARITY 0x3c
39 #define GPIO_INT_STATUS 0x40
41 /*******************************common code for rkxxx*********************************/
43 static void inline uart_printch(char byte)
46 u32 u_clk_id=(RK3288_CLKGATE_UART0_SRC+CONFIG_RK_DEBUG_UART);
47 u32 u_pclk_id=(RK3288_CLKGATE_PCLK_UART0+CONFIG_RK_DEBUG_UART);
49 reg_save[0]=cru_readl(RK3288_CRU_GATEID_CONS(u_clk_id));
50 reg_save[1]=cru_readl(RK3288_CRU_GATEID_CONS(u_pclk_id));
51 RK3288_CRU_UNGATING_OPS(u_clk_id);
52 RK3288_CRU_UNGATING_OPS(u_pclk_id);
56 writel_relaxed(byte, RK_DEBUG_UART_VIRT);
59 /* loop check LSR[6], Transmitter Empty bit */
60 while (!(readl_relaxed(RK_DEBUG_UART_VIRT + 0x14) & 0x40))
63 cru_writel(reg_save[0]|CRU_W_MSK(u_clk_id%16,0x1),RK3288_CRU_GATEID_CONS(u_clk_id));
64 cru_writel(reg_save[1]|CRU_W_MSK(u_pclk_id%16,0x1),RK3288_CRU_GATEID_CONS(u_pclk_id));
70 void PIE_FUNC(sram_printch)(char byte)
75 static void ddr_printch(char byte)
79 /*******************************gpio func*******************************************/
80 /* GPIO control registers */
81 #define GPIO_SWPORT_DR 0x00
82 #define GPIO_SWPORT_DDR 0x04
83 #define GPIO_INTEN 0x30
84 #define GPIO_INTMASK 0x34
85 #define GPIO_INTTYPE_LEVEL 0x38
86 #define GPIO_INT_POLARITY 0x3c
87 #define GPIO_INT_STATUS 0x40
88 #define GPIO_INT_RAWSTATUS 0x44
89 #define GPIO_DEBOUNCE 0x48
90 #define GPIO_PORTS_EOI 0x4c
91 #define GPIO_EXT_PORT 0x50
92 #define GPIO_LS_SYNC 0x60
94 //pin=0x0a21 gpio0a2,port=0,bank=a,b_gpio=2,fun=1
95 static inline void pin_set_fun(u8 port,u8 bank,u8 b_gpio,u8 fun)
99 off_set=port*(4*4)+bank*4;
101 if(off_set<RK3288_GRF_GPIO1D_IOMUX)
103 reg_writel(RKPM_W_MSK_SETBITS(fun,b_gpio*2,0x3),RK_GRF_VIRT+0+off_set);
106 static inline u8 pin_get_funset(u8 port,u8 bank,u8 b_gpio)
110 off_set=port*(4*4)+bank*4;
112 if(off_set<RK3288_GRF_GPIO1D_IOMUX)
114 return (reg_readl(RK_GRF_VIRT+0+off_set)>>(b_gpio*2))&0x3;
117 static inline void pin_set_pull(u8 port,u8 bank,u8 b_gpio,u8 pull)
128 //gpio1_d==0x14c ,form gpio0_a to gpio1_d offset 1*16+3*4= 0x1c
129 off_set=0x14c-0x1c+port*(4*4)+bank*4;
130 reg_writel(RKPM_W_MSK_SETBITS(pull,b_gpio*2,0x3),RK_GRF_VIRT+off_set);
135 if(bank>2)// gpio0_d is not support
137 pmu_writel(RKPM_VAL_SETBITS(pmu_readl(0x64+bank*4),pull,b_gpio*2,0x3),0x64+bank*4);
142 static inline u8 pin_get_pullset(u8 port,u8 bank,u8 b_gpio)
153 //gpio1_d==0x14c ,form gpio0_a to gpio1_d offset 1*16+3*4= 0x1c
154 off_set=0x14c-0x1c+port*(4*4)+bank*4;
155 return RKPM_GETBITS(reg_readl(RK_GRF_VIRT+off_set),b_gpio*2,0x3);
160 if(bank>2)// gpio0_d is not support
162 return RKPM_GETBITS(pmu_readl(0x64+bank*4),b_gpio*2,0x3);
169 static inline void gpio_set_in_output(u8 port,u8 bank,u8 b_gpio,u8 type)
174 b_gpio=bank*8+b_gpio;//
176 val=reg_readl(RK_GPIO_VIRT(port)+GPIO_SWPORT_DDR);
178 if(type==RKPM_GPIO_OUTPUT)
183 reg_writel(val,RK_GPIO_VIRT(port)+GPIO_SWPORT_DDR);
186 static inline u8 gpio_get_in_outputset(u8 port,u8 bank,u8 b_gpio)
189 b_gpio=bank*8+b_gpio;
190 return reg_readl(RK_GPIO_VIRT(port)+GPIO_SWPORT_DDR)&(0x1<<b_gpio);
193 //RKPM_GPIOS_OUT_L RKPM_GPIOS_OUT_H
194 static inline void gpio_set_output_level(u8 port,u8 bank,u8 b_gpio,u8 level)
199 b_gpio=bank*8+b_gpio;
201 val=reg_readl(RK_GPIO_VIRT(port)+GPIO_SWPORT_DR);
203 if(level==RKPM_GPIO_OUT_H)
208 reg_writel(val,RK_GPIO_VIRT(port)+GPIO_SWPORT_DR);
211 static inline u8 gpio_get_output_levelset(u8 port,u8 bank,u8 b_gpio)
214 b_gpio=bank*8+b_gpio;
215 return reg_readl(RK_GPIO_VIRT(port)+GPIO_SWPORT_DR)&(0x1<<b_gpio);
218 static inline u8 gpio_get_input_level(u8 port,u8 bank,u8 b_gpio)
222 b_gpio=bank*8+b_gpio;
224 return (reg_readl(RK_GPIO_VIRT(port)+GPIO_EXT_PORT)>>b_gpio)&0x1;
227 static void __sramfunc sram_pin_set_fun(u8 port,u8 bank,u8 b_gpio,u8 fun)
229 pin_set_fun(port,bank,b_gpio,fun);
231 static u8 __sramfunc sram_pin_get_funset(u8 port,u8 bank,u8 b_gpio)
233 return pin_get_funset(port,bank,b_gpio);
236 static void __sramfunc sram_pin_set_pull(u8 port,u8 bank,u8 b_gpio,u8 fun)
238 pin_set_pull(port,bank,b_gpio,fun);
240 static u8 __sramfunc sram_pin_get_pullset(u8 port,u8 bank,u8 b_gpio)
242 return pin_get_pullset(port,bank,b_gpio);
245 static void __sramfunc sram_gpio_set_in_output(u8 port,u8 bank,u8 b_gpio,u8 type)
247 gpio_set_in_output(port,bank,b_gpio,type);
250 static u8 __sramfunc sram_gpio_get_in_outputset(u8 port,u8 bank,u8 b_gpio)
252 return gpio_get_in_outputset(port,bank,b_gpio);
255 static void __sramfunc sram_gpio_set_output_level(u8 port,u8 bank,u8 b_gpio,u8 level)
258 gpio_set_output_level(port,bank,b_gpio,level);
262 static u8 __sramfunc sram_gpio_get_output_levelset(u8 port,u8 bank,u8 b_gpio)
264 return gpio_get_output_levelset(port,bank,b_gpio);
267 static u8 __sramfunc sram_gpio_get_input_level(u8 port,u8 bank,u8 b_gpio)
269 return gpio_get_input_level(port,bank,b_gpio);
272 static void ddr_pin_set_fun(u8 port,u8 bank,u8 b_gpio,u8 fun)
274 pin_set_fun(port,bank,b_gpio,fun);
276 static u8 ddr_pin_get_funset(u8 port,u8 bank,u8 b_gpio)
278 return pin_get_funset(port,bank,b_gpio);
281 static void ddr_pin_set_pull(u8 port,u8 bank,u8 b_gpio,u8 fun)
283 pin_set_pull(port,bank,b_gpio,fun);
285 static u8 ddr_pin_get_pullset(u8 port,u8 bank,u8 b_gpio)
287 return pin_get_pullset(port,bank,b_gpio);
290 static void ddr_gpio_set_in_output(u8 port,u8 bank,u8 b_gpio,u8 type)
292 gpio_set_in_output(port,bank,b_gpio,type);
295 static u8 ddr_gpio_get_in_outputset(u8 port,u8 bank,u8 b_gpio)
297 return gpio_get_in_outputset(port,bank,b_gpio);
300 static void ddr_gpio_set_output_level(u8 port,u8 bank,u8 b_gpio,u8 level)
302 gpio_set_output_level(port,bank,b_gpio,level);
305 static u8 ddr_gpio_get_output_levelset(u8 port,u8 bank,u8 b_gpio)
307 return gpio_get_output_levelset(port,bank,b_gpio);
310 static u8 ddr_gpio_get_input_level(u8 port,u8 bank,u8 b_gpio)
312 return gpio_get_input_level(port,bank,b_gpio);
317 static void __sramfunc rkpm_pin_gpio_config_sram(u32 pin_gpio_bits,u32 *save_bits)
321 u8 port,bank,b_gpio,fun,in_out, level, pull;
323 pins=RKPM_PINGPIO_BITS_PIN(pin_gpio_bits);
324 in_out=RKPM_PINGPIO_BITS_INOUT(pin_gpio_bits);
325 pull=RKPM_PINGPIO_BITS_PULL(pin_gpio_bits);
326 level=RKPM_PINGPIO_BITS_LEVEL(pin_gpio_bits);
328 port=RKPM_PINBITS_PORT(pins);
329 bank=RKPM_PINBITS_BANK(pins);
330 b_gpio=RKPM_PINBITS_BGPIO(pins);
331 fun=RKPM_PINBITS_FUN(pins);
336 pins=RKPM_PINBITS_SET_FUN(pins,sram_pin_get_funset(port,bank,b_gpio));
337 *save_bits=RKPM_PINGPIO_BITS(pins,sram_pin_get_pullset(port,bank,b_gpio),sram_gpio_get_in_outputset(port,bank,b_gpio),
338 sram_gpio_get_output_levelset(port,bank,b_gpio));
340 if(!fun&&(in_out==RKPM_GPIO_OUTPUT))
342 if(level==RKPM_GPIO_OUT_L)
343 pull=RKPM_GPIO_PULL_DN;
345 pull=RKPM_GPIO_PULL_UP;
347 sram_gpio_set_output_level(port,bank,b_gpio,level);
350 sram_pin_set_pull(port,bank,b_gpio,pull);
351 sram_pin_set_fun(port,bank,b_gpio,fun);
355 sram_gpio_set_in_output(port,bank,b_gpio,in_out);
360 static inline void rkpm_pin_gpio_config_ddr(u32 pin_gpio_bits,u32 *save_bits)
364 u8 port,bank,b_gpio,fun,in_out, level, pull;
366 pins=RKPM_PINGPIO_BITS_PIN(pin_gpio_bits);
367 in_out=RKPM_PINGPIO_BITS_INOUT(pin_gpio_bits);
368 pull=RKPM_PINGPIO_BITS_PULL(pin_gpio_bits);
369 level=RKPM_PINGPIO_BITS_LEVEL(pin_gpio_bits);
371 port=RKPM_PINBITS_PORT(pins);
372 bank=RKPM_PINBITS_BANK(pins);
373 b_gpio=RKPM_PINBITS_BGPIO(pins);
374 fun=RKPM_PINBITS_FUN(pins);
379 pins=RKPM_PINBITS_SET_FUN(pins,ddr_pin_get_funset(port,bank,b_gpio));
380 *save_bits=RKPM_PINGPIO_BITS(pins,ddr_pin_get_pullset(port,bank,b_gpio),ddr_gpio_get_in_outputset(port,bank,b_gpio),
381 ddr_gpio_get_output_levelset(port,bank,b_gpio));
383 if(!fun&&(in_out==RKPM_GPIO_OUTPUT))
385 if(level==RKPM_GPIO_OUT_L)
386 pull=RKPM_GPIO_PULL_DN;
388 pull=RKPM_GPIO_PULL_UP;
390 ddr_gpio_set_output_level(port,bank,b_gpio,level);
393 ddr_pin_set_pull(port,bank,b_gpio,pull);
394 ddr_pin_set_fun(port,bank,b_gpio,fun);
398 ddr_gpio_set_in_output(port,bank,b_gpio,in_out);
404 #define GPIO_DTS_NUM 10
406 static u32 gpio_dts_save[GPIO_DTS_NUM];
407 static u32 gpio_dts[GPIO_DTS_NUM];
409 #define PMICGPIO_DTS_NUM 3
412 u32 DEFINE_PIE_DATA(pmicgpio_dts[PMICGPIO_DTS_NUM]);
413 static u32 *p_pmicgpio_dts;
414 static __sramdata u32 pmicgpio_dts_save[PMICGPIO_DTS_NUM];
416 static void __sramfunc pmic_gpio_suspend(void)
421 if(DATA(pmicgpio_dts[i]))
422 rkpm_pin_gpio_config_sram(DATA(pmicgpio_dts[i]),& pmicgpio_dts_save[i]);
425 pmicgpio_dts_save[i]=0;
432 rkpm_sram_reg_dump(RK_GPIO_VIRT(i),0,0x4);
435 rkpm_sram_reg_dump(RK_GRF_VIRT,0xc,0x84);
436 rkpm_sram_reg_dump(RK_GRF_VIRT,0x14c,0x1b4);
437 rkpm_sram_reg_dump(RK_PMU_VIRT,0x64,0x6c);
438 rkpm_sram_reg_dump(RK_PMU_VIRT,0x84,0x9c);
443 static void __sramfunc pmic_gpio_resume(void)
448 if(pmicgpio_dts_save[i])
449 rkpm_pin_gpio_config_sram(pmicgpio_dts_save[i],NULL);
454 void PIE_FUNC(pmic_suspend)(void)
460 void PIE_FUNC(pmic_resume)(void)
466 static void rkpm_gpio_suspend(void)
471 if(DATA(pmicgpio_dts[i]))
472 rkpm_pin_gpio_config_ddr(DATA(pmicgpio_dts[i]),& pmicgpio_dts_save[i]);
475 pmicgpio_dts_save[i]=0;
482 rkpm_ddr_reg_dump(RK_GPIO_VIRT(i),0,0x4);
485 rkpm_ddr_reg_dump(RK_GRF_VIRT,0xc,0x84);
486 rkpm_ddr_reg_dump(RK_GRF_VIRT,0x14c,0x1b4);
487 rkpm_ddr_reg_dump(RK_PMU_VIRT,0x64,0x6c);
488 rkpm_ddr_reg_dump(RK_PMU_VIRT,0x84,0x9c);
493 static void rkpm_gpio_resume(void)
498 if(pmicgpio_dts_save[i])
499 rkpm_pin_gpio_config_ddr(pmicgpio_dts_save[i],NULL);
508 static void gpio_get_dts_info(struct device_node *parent)
512 for(i=0;i<PMICGPIO_DTS_NUM;i++)
515 for(i=0;i<GPIO_DTS_NUM;i++)
519 p_pmicgpio_dts= kern_to_pie(rockchip_pie_chunk, &DATA(pmicgpio_dts[0]));
521 if(of_property_read_u32_array(parent,"rockchip,pmic-gpios",p_pmicgpio_dts,PMICGPIO_DTS_NUM))
524 PM_ERR("%s:get pm ctr error\n",__FUNCTION__);
527 for(i=0;i<PMICGPIO_DTS_NUM;i++)
528 printk("%s:pmic gpio(%x)\n",__FUNCTION__,p_pmicgpio_dts[i]);
530 if(of_property_read_u32_array(parent,"rockchip,pm-gpios",gpio_dts,GPIO_DTS_NUM))
533 PM_ERR("%s:get pm ctr error\n",__FUNCTION__);
535 for(i=0;i<GPIO_DTS_NUM;i++)
536 printk("%s:pmic gpio(%x)\n",__FUNCTION__,gpio_dts[i]);
538 rkpm_set_ops_gpios(rkpm_gpio_suspend,rkpm_gpio_resume);
539 rkpm_set_sram_ops_gtclks(fn_to_pie(rockchip_pie_chunk, &FUNC(pmic_suspend)),
540 fn_to_pie(rockchip_pie_chunk, &FUNC(pmic_resume)));
550 /*******************************clk gating config*******************************************/
551 #define CLK_MSK_GATING(msk, con) cru_writel((msk << 16) | 0xffff, con)
552 #define CLK_MSK_UNGATING(msk, con) cru_writel(((~msk) << 16) | 0xffff, con)
555 static u32 clk_ungt_msk[RK3288_CRU_CLKGATES_CON_CNT];// first clk gating setting
556 static u32 clk_ungt_save[RK3288_CRU_CLKGATES_CON_CNT]; //first clk gating value saveing
559 u32 DEFINE_PIE_DATA(rkpm_clkgt_last_set[RK3288_CRU_CLKGATES_CON_CNT]);
560 static u32 *p_rkpm_clkgt_last_set;
562 static __sramdata u32 rkpm_clkgt_last_save[RK3288_CRU_CLKGATES_CON_CNT];
564 void PIE_FUNC(gtclks_sram_suspend)(void)
567 // u32 u_clk_id=(RK3188_CLKGATE_UART0_SRC+CONFIG_RK_DEBUG_UART);
568 // u32 u_pclk_id=(RK3188_CLKGATE_PCLK_UART0+CONFIG_RK_DEBUG_UART);
570 for(i=0;i<RK3288_CRU_CLKGATES_CON_CNT;i++)
572 rkpm_clkgt_last_save[i]=cru_readl(RK3288_CRU_CLKGATES_CON(i));
573 CLK_MSK_UNGATING( DATA(rkpm_clkgt_last_set[i]), RK3288_CRU_CLKGATES_CON(i));
575 rkpm_sram_printch('\n');
576 rkpm_sram_printhex(DATA(rkpm_clkgt_last_save[i]));
577 rkpm_sram_printch('-');
578 rkpm_sram_printhex(DATA(rkpm_clkgt_last_set[i]));
579 rkpm_sram_printch('-');
580 rkpm_sram_printhex(cru_readl(RK3188_CRU_CLKGATES_CON(i)));
581 if(i==(RK3288_CRU_CLKGATES_CON_CNT-1))
582 rkpm_sram_printch('\n');
586 //RK3288_CRU_UNGATING_OPS(u_clk_id);
587 //RK3288_CRU_UNGATING_OPS(u_pclk_id);
591 void PIE_FUNC(gtclks_sram_resume)(void)
594 for(i=0;i<RK3288_CRU_CLKGATES_CON_CNT;i++)
596 cru_writel(rkpm_clkgt_last_save[i]|0xffff0000, RK3288_CRU_CLKGATES_CON(i));
600 static void gtclks_suspend(void)
604 for(i=0;i<RK3288_CRU_CLKGATES_CON_CNT;i++)
607 clk_ungt_save[i]=cru_readl(RK3288_CRU_CLKGATES_CON(i));
609 CLK_MSK_UNGATING(clk_ungt_msk[i],RK3288_CRU_CLKGATES_CON(i));
611 rkpm_ddr_printch('\n');
612 rkpm_ddr_printhex(clk_ungt_save[i]);
613 rkpm_ddr_printch('-');
614 rkpm_ddr_printhex(clk_ungt_msk[i]);
615 rkpm_ddr_printch('-');
616 rkpm_ddr_printhex(cru_readl(RK3188_CRU_CLKGATES_CON(i))) ;
617 if(i==(RK3288_CRU_CLKGATES_CON_CNT-1))
618 rkpm_ddr_printch('\n');
624 static void gtclks_resume(void)
627 for(i=0;i<RK3288_CRU_CLKGATES_CON_CNT;i++)
629 cru_writel(clk_ungt_save[i]|0xffff0000,RK3288_CRU_CLKGATES_CON(i));
633 /********************************pll power down***************************************/
644 #define RK3288_PLL_PWR_DN_MSK (0x1<<1)
645 #define RK3288_PLL_PWR_DN CRU_W_MSK_SETBITS(1,1,0x1)
646 #define RK3288_PLL_PWR_ON CRU_W_MSK_SETBITS(0,1,0x1)
649 #define RK3288_PLL_RESET CRU_W_MSK_SETBITS(1,5,0x1)
650 #define RK3288_PLL_RESET_RESUME CRU_W_MSK_SETBITS(0,5,0x1)
652 #define RK3288_PLL_BYPASS_MSK (0x1<<0)
653 #define RK3288_PLL_BYPASS CRU_W_MSK_SETBITS(1,0,0x1)
654 #define RK3288_PLL_NO_BYPASS CRU_W_MSK_SETBITS(0,0,0x1)
656 static void pm_pll_wait_lock(u32 pll_idx)
660 mode=cru_readl(RK3288_CRU_MODE_CON);
668 if (cru_readl(RK3288_PLL_CONS(pll_idx,1))&(0x1<<31))
673 rkpm_ddr_printascii("unlock-pll:");
674 rkpm_ddr_printhex(pll_idx);
675 rkpm_ddr_printch('\n');
677 cru_writel(mode|(RK3288_PLL_MODE_MSK(pll_idx)<<16), RK3288_CRU_MODE_CON);
680 void pll_udelay(u32 udelay)
683 mode=cru_readl(RK3288_CRU_MODE_CON);
685 cru_writel(RK3288_PLL_MODE_SLOW(APLL_ID), RK3288_CRU_MODE_CON);
687 rkpm_udelay(udelay*5);
689 cru_writel(mode|(RK3288_PLL_MODE_MSK(APLL_ID)<<16), RK3288_CRU_MODE_CON);
692 static u32 plls_con3_save[END_PLL_ID];
693 static u32 cru_mode_con;
695 static inline void plls_suspend(u32 pll_id)
697 plls_con3_save[pll_id]=cru_readl(RK3288_PLL_CONS((pll_id), 3));
698 cru_writel(RK3288_PLL_PWR_DN, RK3288_PLL_CONS((pll_id), 3));
701 static inline void plls_resume(u32 pll_id)
703 u32 pllcon0, pllcon1, pllcon2;
705 if(plls_con3_save[pll_id]||RK3288_PLL_PWR_DN_MSK)
708 cru_writel(RK3288_PLL_MODE_SLOW(pll_id), RK3288_CRU_MODE_CON);
710 cru_writel(RK3288_PLL_PWR_ON, RK3288_PLL_CONS((pll_id),3));
711 cru_writel(RK3288_PLL_NO_BYPASS, RK3288_PLL_CONS((pll_id),3));
713 pllcon0 = cru_readl(RK3288_PLL_CONS((pll_id),0));
714 pllcon1 = cru_readl(RK3288_PLL_CONS((pll_id),1));
715 pllcon2 = cru_readl(RK3288_PLL_CONS((pll_id),2));
718 cru_writel(RK3288_PLL_RESET, RK3288_PLL_CONS(pll_id,3));
719 cru_writel(pllcon0, RK3288_PLL_CONS(pll_id,0));
720 cru_writel(pllcon1, RK3288_PLL_CONS(pll_id,1));
721 cru_writel(pllcon2, RK3288_PLL_CONS(pll_id,2));
724 //udelay(5); //timer7 delay
727 cru_writel(RK3288_PLL_RESET_RESUME, RK3288_PLL_CONS(pll_id,3));
731 pm_pll_wait_lock(pll_id);
733 cru_writel(plls_con3_save[pll_id]|(RK3288_PLL_BYPASS_MSK<<16),RK3288_PLL_CONS(pll_id,3));
736 static u32 clk_sel0,clk_sel1, clk_sel10,clk_sel26,clk_sel36, clk_sel37;
738 static void pm_plls_suspend(void)
740 clk_sel0=cru_readl(RK3288_CRU_CLKSELS_CON(0));
741 clk_sel1=cru_readl(RK3288_CRU_CLKSELS_CON(1));
742 clk_sel10=cru_readl(RK3288_CRU_CLKSELS_CON(10));
743 clk_sel26=cru_readl(RK3288_CRU_CLKSELS_CON(26));
744 clk_sel36=cru_readl(RK3288_CRU_CLKSELS_CON(36));
745 clk_sel37=cru_readl(RK3288_CRU_CLKSELS_CON(37));
747 cru_mode_con = cru_readl(RK3288_CRU_MODE_CON);
750 cru_writel(RK3288_PLL_MODE_SLOW(NPLL_ID), RK3288_CRU_MODE_CON);
751 plls_suspend(NPLL_ID);
755 cru_writel(RK3288_PLL_MODE_SLOW(CPLL_ID), RK3288_CRU_MODE_CON);
757 cru_writel(RK3288_PLL_MODE_SLOW(GPLL_ID), RK3288_CRU_MODE_CON);
759 // set 1,pdbus pll is gpll
760 cru_writel(CRU_W_MSK_SETBITS(1,15,0x1), RK3288_CRU_CLKSELS_CON(1));
762 // pd_bus clk ,aclk ,hclk ,pclk, pd bus pll sel
763 cru_writel(CRU_W_MSK_SETBITS(1,0,0x7)|CRU_W_MSK_SETBITS(1,3,0x1f)|CRU_W_MSK_SETBITS(1,8,0x3)|CRU_W_MSK_SETBITS(1,12,0x3)
764 , RK3288_CRU_CLKSELS_CON(1));
766 cru_writel(CRU_W_MSK_SETBITS(3,6,0x3), RK3288_CRU_CLKSELS_CON(26));
768 // peri aclk hclk pclk
769 cru_writel(CRU_W_MSK_SETBITS(1,0,0x1f)|CRU_W_MSK_SETBITS(1,8,0x3)
770 |CRU_W_MSK_SETBITS(2,12,0x7), RK3288_CRU_CLKSELS_CON(10));
773 plls_suspend(CPLL_ID);
774 plls_suspend(GPLL_ID);
777 cru_writel(RK3288_PLL_MODE_SLOW(APLL_ID), RK3288_CRU_MODE_CON);
778 // core_m0 core_mp a12_core
779 cru_writel(CRU_W_MSK_SETBITS(1,0,0xf)|CRU_W_MSK_SETBITS(3,4,0xf)
780 |CRU_W_MSK_SETBITS(0,8,0x1f), RK3288_CRU_CLKSELS_CON(0));
781 // core0 core1 core2 core3
782 cru_writel(CRU_W_MSK_SETBITS(0,0,0x7)|CRU_W_MSK_SETBITS(0,4,0x7)
783 |CRU_W_MSK_SETBITS(0,8,0x7)|CRU_W_MSK_SETBITS(0,12,0x7)
784 , RK3288_CRU_CLKSELS_CON(36));
786 cru_writel((CRU_W_MSK_SETBITS(3,0,0x7)|CRU_W_MSK_SETBITS(0xf,4,0x1f)
787 |CRU_W_MSK_SETBITS(0xf,9,0x1f)), RK3288_CRU_CLKSELS_CON(37));
788 plls_suspend(APLL_ID);
792 static void pm_plls_resume(void)
794 plls_resume(APLL_ID);
795 // core_m0 core_mp a12_core
796 cru_writel(clk_sel0|(CRU_W_MSK(0,0xf)|CRU_W_MSK(4,0xf)|CRU_W_MSK(8,0xf)),RK3288_CRU_CLKSELS_CON(0));
797 // core0 core1 core2 core3
798 cru_writel(clk_sel36|(CRU_W_MSK(0,0x7)|CRU_W_MSK(4,0x7)|CRU_W_MSK(8,0x7)|CRU_W_MSK(12,0x7))
799 , RK3288_CRU_CLKSELS_CON(36));
801 cru_writel(clk_sel37|(CRU_W_MSK(0,0x7)|CRU_W_MSK(4,0x1f)|CRU_W_MSK(9,0x1f)) , RK3288_CRU_CLKSELS_CON(37));
802 cru_writel(cru_mode_con|(RK3288_PLL_MODE_MSK(APLL_ID)<<16), RK3288_CRU_MODE_CON);
804 plls_resume(GPLL_ID);
805 plls_resume(CPLL_ID);
806 // peri aclk hclk pclk
807 cru_writel(clk_sel10|(CRU_W_MSK(0,0x1f)|CRU_W_MSK(8,0x3)|CRU_W_MSK(12,0x7))
808 , RK3288_CRU_CLKSELS_CON(10));
809 // pd_bus aclk hclk pclk
810 cru_writel(clk_sel1|(CRU_W_MSK(0,0x7)|CRU_W_MSK(3,0x1f)|CRU_W_MSK(8,0x3)|CRU_W_MSK(12,0x3))
811 , RK3288_CRU_CLKSELS_CON(1));
813 cru_writel(clk_sel26|CRU_W_MSK(6,0x3), RK3288_CRU_CLKSELS_CON(26));
815 cru_writel(clk_sel1|CRU_W_MSK(15,0x1), RK3288_CRU_CLKSELS_CON(1));
817 cru_writel(cru_mode_con|(RK3288_PLL_MODE_MSK(GPLL_ID)<<16), RK3288_CRU_MODE_CON);
818 cru_writel(cru_mode_con|(RK3288_PLL_MODE_MSK(CPLL_ID)<<16), RK3288_CRU_MODE_CON);
820 plls_resume(NPLL_ID);
821 cru_writel(cru_mode_con|(RK3288_PLL_MODE_MSK(NPLL_ID)<<16), RK3288_CRU_MODE_CON);
825 static __sramdata u32 sysclk_clksel0_con,sysclk_clksel1_con,sysclk_clksel10_con,sysclk_mode_con;
827 void PIE_FUNC(sysclk_suspend)(u32 sel_clk)
831 sysclk_clksel0_con = cru_readl(RK3288_CRU_CLKSELS_CON(0));
832 sysclk_clksel1_con = cru_readl(RK3288_CRU_CLKSELS_CON(1));
833 sysclk_clksel10_con= cru_readl(RK3288_CRU_CLKSELS_CON(10));
836 if(sel_clk&(RKPM_CTR_SYSCLK_32K))
839 sysclk_mode_con= cru_readl(RK3288_CRU_MODE_CON);
841 |RK3288_PLL_MODE_DEEP(APLL_ID)| RK3288_PLL_MODE_DEEP(CPLL_ID)
842 | RK3288_PLL_MODE_DEEP(GPLL_ID)|RK3288_PLL_MODE_DEEP(NPLL_ID)
843 , RK3288_CRU_MODE_CON);
845 else if(sel_clk&(RKPM_CTR_SYSCLK_DIV))
850 cru_writel(CRU_W_MSK_SETBITS(div,8,0x1f), RK3188_CRU_CLKSELS_CON(0)); //pd core
851 cru_writel(CRU_W_MSK_SETBITS(div,3,0x1f), RK3188_CRU_CLKSELS_CON(1));//pd bus
852 cru_writel(CRU_W_MSK_SETBITS(div,0,0x1f), RK3188_CRU_CLKSELS_CON(10));//pd peri
856 void PIE_FUNC(sysclk_resume)(u32 sel_clk)
859 cru_writel(sysclk_clksel0_con|CRU_W_MSK(8,0x1f), RK3188_CRU_CLKSELS_CON(0)); //pd core
860 cru_writel(sysclk_clksel1_con|CRU_W_MSK(3,0x1f), RK3188_CRU_CLKSELS_CON(1));//pd bus
861 cru_writel(sysclk_clksel10_con|CRU_W_MSK(0,0x1f), RK3188_CRU_CLKSELS_CON(10));//pd peri
862 cru_writel(sysclk_mode_con|(RK3288_PLL_MODE_MSK(APLL_ID)<<16)
863 |(RK3288_PLL_MODE_MSK(CPLL_ID)<<16)
864 |(RK3288_PLL_MODE_MSK(GPLL_ID)<<16)
865 |(RK3288_PLL_MODE_MSK(NPLL_ID)<<16), RK3288_CRU_MODE_CON);
870 static void clks_gating_suspend_init(void)
872 // get clk gating info
873 p_rkpm_clkgt_last_set= kern_to_pie(rockchip_pie_chunk, &DATA(rkpm_clkgt_last_set[0]));
875 if(clk_suspend_clkgt_info_get(clk_ungt_msk,p_rkpm_clkgt_last_set, RK3288_CRU_CLKGATES_CON_CNT)
876 ==RK3188_CRU_CLKGATES_CON(0))
878 rkpm_set_ops_gtclks(gtclks_suspend,gtclks_resume);
879 rkpm_set_sram_ops_gtclks(fn_to_pie(rockchip_pie_chunk, &FUNC(gtclks_sram_suspend)),
880 fn_to_pie(rockchip_pie_chunk, &FUNC(gtclks_sram_resume)));
882 PM_LOG("%s:clkgt info ok\n",__FUNCTION__);
885 rkpm_set_sram_ops_sysclk(fn_to_pie(rockchip_pie_chunk, &FUNC(sysclk_suspend))
886 ,fn_to_pie(rockchip_pie_chunk, &FUNC(sysclk_resume)));
889 /***************************prepare and finish reg_pread***********************************/
893 #define GIC_DIST_PENDING_SET 0x200
894 #define DUMP_GPIO_INT_STATUS(ID) \
896 if (irq_gpio & (1 << ID)) \
897 printk("wakeup gpio" #ID ": %08x\n", readl_relaxed(RK_GPIO_VIRT(ID) + GPIO_INT_STATUS)); \
899 static noinline void rk30_pm_dump_irq(void)
901 u32 irq_gpio = (readl_relaxed(RK_GIC_VIRT + GIC_DIST_PENDING_SET + 8) >> 22) & 0x7F;
902 printk("wakeup irq: %08x %08x %08x %08x\n",
903 readl_relaxed(RK_GIC_VIRT + GIC_DIST_PENDING_SET + 4),
904 readl_relaxed(RK_GIC_VIRT + GIC_DIST_PENDING_SET + 8),
905 readl_relaxed(RK_GIC_VIRT + GIC_DIST_PENDING_SET + 12),
906 readl_relaxed(RK_GIC_VIRT + GIC_DIST_PENDING_SET + 16));
907 DUMP_GPIO_INT_STATUS(0);
908 DUMP_GPIO_INT_STATUS(1);
909 DUMP_GPIO_INT_STATUS(2);
910 DUMP_GPIO_INT_STATUS(3);
911 DUMP_GPIO_INT_STATUS(4);
912 DUMP_GPIO_INT_STATUS(5);
913 DUMP_GPIO_INT_STATUS(6);
914 DUMP_GPIO_INT_STATUS(7);
915 DUMP_GPIO_INT_STATUS(8);
919 #define DUMP_GPIO_INTEN(ID) \
921 u32 en = readl_relaxed(RK_GPIO_VIRT(ID) + GPIO_INTEN); \
923 rkpm_ddr_printascii("GPIO" #ID "_INTEN: "); \
924 rkpm_ddr_printhex(en); \
925 rkpm_ddr_printch('\n'); \
926 printk(KERN_DEBUG "GPIO%d_INTEN: %08x\n", ID, en); \
930 //dump while irq is enable
931 static noinline void rk30_pm_dump_inten(void)
944 static void rkpm_prepare(void)
947 u32 temp =reg_readl(RK_GPIO_VIRT(0)+0x30);
949 // rkpm_ddr_printhex(temp);
950 reg_writel(temp|0x1<<4,RK_GPIO_VIRT(0)+0x30);
951 temp =reg_readl(RK_GPIO_VIRT(0)+0x30);
952 // rkpm_ddr_printhex(temp);
954 // dump GPIO INTEN for debug
955 //rk30_pm_dump_inten();
958 static void rkpm_finish(void)
960 //rk30_pm_dump_irq();
964 static void interface_ctr_reg_pread(void)
969 local_flush_tlb_all();
970 #if 0 // do it in ddr suspend
971 for (addr = (u32)SRAM_CODE_OFFSET; addr < (u32)(SRAM_CODE_OFFSET+rockchip_sram_size); addr += PAGE_SIZE)
974 readl_relaxed(RK_PMU_VIRT);
975 readl_relaxed(RK_GRF_VIRT);
976 readl_relaxed(RK_DDR_VIRT);
977 readl_relaxed(RK_GPIO_VIRT(0));
978 //readl_relaxed(RK30_I2C1_BASE+SZ_4K);
979 //readl_relaxed(RK_GPIO_VIRT(3));
982 static void __init rk3288_suspend_init(void)
984 struct device_node *parent;
987 PM_LOG("%s enter\n",__FUNCTION__);
989 parent = of_find_node_by_name(NULL, "rockchip_suspend");
991 if (IS_ERR_OR_NULL(parent)) {
992 PM_ERR("%s dev node err\n", __func__);
997 if(of_property_read_u32_array(parent,"rockchip,ctrbits",&pm_ctrbits,1))
999 PM_ERR("%s:get pm ctr error\n",__FUNCTION__);
1002 PM_LOG("%s: pm_ctrbits =%x\n",__FUNCTION__,pm_ctrbits);
1004 if(of_property_read_u32_array(parent,"rockchip,pmic-gpios",gpios_data,ARRAY_SIZE(gpios_data)))
1006 PM_ERR("%s:get pm ctr error\n",__FUNCTION__);
1010 rkpm_set_ctrbits(pm_ctrbits);
1012 clks_gating_suspend_init();
1014 rkpm_set_ops_plls(pm_plls_suspend,pm_plls_resume);
1016 //rkpm_set_ops_prepare_finish(rkpm_prepare,rkpm_finish);
1017 // rkpm_set_ops_regs_pread(interface_ctr_reg_pread);
1018 rkpm_set_sram_ops_printch(fn_to_pie(rockchip_pie_chunk, &FUNC(sram_printch)));
1019 rkpm_set_ops_printch(ddr_printch);