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