ARM: rockchip: rk3228: implement function rk3228_restart
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rockchip / pm-pie.c
1 #include <linux/kernel.h>
2 #include <linux/init.h>
3 #include <linux/suspend.h>
4 #include "pm.h"
5 //#include "sram.h"
6
7 /*************************dump reg********************************************/
8
9 #if 0 // not used
10
11 static void __sramfunc rkpm_sram_regs_dump(u32 base_addr,u32 start_offset,u32 end_offset)
12 {
13         u32 i;
14        /* 
15         rkpm_sram_printch('\n');
16         rkpm_sram_printhex(base_addr);
17         rkpm_sram_printch(':');
18         rkpm_sram_printch('\n');     
19      */
20         for(i=start_offset;i<=end_offset;)
21         {
22             rkpm_sram_printhex(i);       
23             rkpm_sram_printch('-');
24             rkpm_sram_printhex(readl_relaxed((void *)(base_addr + i)));  
25             if(!(i%5)&&i!=0)
26             rkpm_sram_printch('\n');
27             i+=4;
28         }
29     
30     rkpm_sram_printch('\n');
31
32 }
33 #endif
34
35 struct rkpm_sram_ops DEFINE_PIE_DATA(pm_sram_ops);
36 //for sram
37 static __sramdata u32 rkpm_sram_ctrbits;
38
39 /****************** for pm.c and in sram***************************************/
40 //only usr in sram function
41 #define rkpm_chk_sram_ctrbit(bit) (rkpm_sram_ctrbits&(bit))
42 #define rkpm_chk_sram_ctrbits(bits) (rkpm_sram_ctrbits&(bits))
43
44 #define  RKPM_SRAM_FUN(fun) \
45         if(DATA(pm_sram_ops).fun)\
46             (DATA(pm_sram_ops).fun)()
47                 
48 #define  RKPM_BITCTR_SRAM_FUN(ctr,fun) \
49         if(rkpm_chk_sram_ctrbit(RKPM_CTR_##ctr)&&DATA(pm_sram_ops).fun)\
50                 (DATA(pm_sram_ops).fun)()   
51                 
52 // fun with paramater
53 #define  RKPM_BITSCTR_SRAM_PFUN(bits,fun,fun_p) \
54     if(rkpm_chk_sram_ctrbits(bits)&&DATA(pm_sram_ops).fun_p) \
55         {DATA(pm_sram_ops).fun;} while(0)
56 /********************************sram print**********************************/
57
58 void PIE_FUNC(rkpm_sram_printch_pie)(char byte)
59 {
60     if(DATA(pm_sram_ops).printch)
61            DATA(pm_sram_ops).printch(byte); 
62     
63    // if (byte == '\n')
64         //FUNC(rkpm_sram_printch_pie)('\r');
65 }
66 EXPORT_PIE_SYMBOL(FUNC(rkpm_sram_printch_pie));
67
68
69 void  PIE_FUNC(rkpm_sram_printhex_pie)(unsigned int hex)
70 {
71     int i = 8;
72      FUNC(rkpm_sram_printch_pie)('0');
73      FUNC(rkpm_sram_printch_pie)('x');
74     while (i--) {
75         unsigned char c = (hex & 0xF0000000) >> 28;
76          FUNC(rkpm_sram_printch_pie)(c < 0xa ? c + '0' : c - 0xa + 'a');
77         hex <<= 4;
78     }
79 }
80 EXPORT_PIE_SYMBOL(FUNC(rkpm_sram_printhex_pie));
81
82
83 /******************************************pm main function******************************************/
84 #define RKPM_CTR_SYSCLK RKPM_OR_3BITS(SYSCLK_DIV,SYSCLK_32K,SYSCLK_OSC_DIS)
85
86 static void __sramfunc rkpm_sram_suspend(u32 ctrbits)
87 {
88         rkpm_sram_printch('7');
89         RKPM_BITCTR_SRAM_FUN(VOLTS, volts);
90         rkpm_sram_printch('8');
91         RKPM_BITCTR_SRAM_FUN(BUS_IDLE, bus_idle_request);
92         RKPM_BITCTR_SRAM_FUN(DDR, ddr);
93
94         /*rkpm_sram_printch('8');*/
95         /*RKPM_BITCTR_SRAM_FUN(VOLTS,volts);*/
96         /*rkpm_sram_printch('9');*/
97         /* RKPM_BITCTR_SRAM_FUN(GTCLKS,gtclks);*/
98
99         RKPM_BITSCTR_SRAM_PFUN(RKPM_CTR_SYSCLK,sysclk(rkpm_sram_ctrbits),sysclk);
100         
101         RKPM_BITCTR_SRAM_FUN(PMIC,pmic);
102          
103         //  if(rkpm_chk_sram_ctrbit(RKPM_CTR_SRAM_NO_WFI))
104         {
105             dsb();
106             wfi();
107         }
108
109         RKPM_BITCTR_SRAM_FUN(PMIC,re_pmic);
110      
111         RKPM_BITSCTR_SRAM_PFUN(RKPM_CTR_SYSCLK,re_sysclk(rkpm_sram_ctrbits),re_sysclk);
112     
113         /*RKPM_BITCTR_SRAM_FUN(GTCLKS,re_gtclks);*/
114     
115         rkpm_sram_printch('9');
116         RKPM_BITCTR_SRAM_FUN(VOLTS,re_volts);
117     
118         rkpm_sram_printch('8'); 
119         RKPM_BITCTR_SRAM_FUN(DDR,re_ddr);
120     
121         rkpm_sram_printch('7'); 
122 }
123
124 void PIE_FUNC(rkpm_sram_suspend_arg)(void *arg)
125 {
126     rkpm_sram_ctrbits=*((u32 *)arg);
127     
128    // rkpm_sram_printhex(rkpm_sram_ctrbits); 
129     //rkpm_sram_printhex(*((u32 *)arg));
130     rkpm_sram_suspend(rkpm_sram_ctrbits);    
131 }
132 EXPORT_PIE_SYMBOL(FUNC(rkpm_sram_suspend_arg));
133 static void rkpm_pie_init(void)
134 {
135     if(rockchip_pie_chunk)
136     {
137         rkpm_set_pie_info(kern_to_pie(rockchip_pie_chunk, &DATA(pm_sram_ops))
138                         ,fn_to_pie(rockchip_pie_chunk, &FUNC(rkpm_sram_suspend_arg)));
139     }
140 }