RK29SmartPhone:switch to 32k when sleep
authorxsf@rock-chips.com <root@xxx-desktop.(none)>
Mon, 27 Jun 2011 12:18:27 +0000 (20:18 +0800)
committerxsf@rock-chips.com <root@xxx-desktop.(none)>
Mon, 27 Jun 2011 12:18:27 +0000 (20:18 +0800)
arch/arm/mach-rk29/Kconfig
arch/arm/mach-rk29/Makefile
arch/arm/mach-rk29/board-rk29-phonesdk.c [changed mode: 0644->0755]
arch/arm/mach-rk29/pm.c
arch/arm/mach-rk29/spi_sram.c

index eac7f56550a5ce7f61843a9e5bc00fc2c8b9f9f0..37efd90fb2c148da2e4766252004a96f5a32667b 100755 (executable)
@@ -203,15 +203,26 @@ config RK29_LAST_LOG
        default y
        help
          It is only intended for debugging.
-menu "The control interface support for RK29 suspend "
+
+menu "support for RK29 power manage "
+config RK29_CLK_SWITCH_TO_32K
+       bool "Support clock switch to 32.768k"
+       default n
+
+config RK29_GPIO_SUSPEND
+       bool "Support gpio suspend"
+       default n
+
 config RK29_SPI_INSRAM
        tristate "Support spi control interface"
        depends on REGULATOR_WM831X
-       default n
+       default ns
+
 config RK29_PWM_INSRAM
        tristate "Support pwm control interface"
        depends on RK29_PWM_REGULATOR
        default y
 endmenu
 
+
 endif
index 46309ddb0002ead51f49811d0b065cfaf1c1305f..d094cdb5b5e72964d005f627dad76ec402e94fa2 100755 (executable)
@@ -9,7 +9,7 @@ obj-$(CONFIG_USB_GADGET) += usb_detect.o
 obj-$(CONFIG_PM) += pm.o
 obj-$(CONFIG_CPU_FREQ) += cpufreq.o
 obj-$(CONFIG_RK29_VPU) += vpu.o vpu_mem.o
-obj-$(CONFIG_RK29_SPI_INSRAM) += spi_sram.o
+obj-y += spi_sram.o
 obj-$(CONFIG_RK29_PWM_INSRAM) += pwm_sram.o
 obj-$(CONFIG_MACH_RK29SDK) += board-rk29sdk.o board-rk29sdk-key.o board-rk29sdk-rfkill.o board-rk29sdk-power.o
 obj-$(CONFIG_MACH_RK29SDK_DDR3) += board-rk29-ddr3sdk.o board-rk29sdk-key.o board-rk29sdk-rfkill.o board-rk29sdk-power.o
old mode 100644 (file)
new mode 100755 (executable)
index 7e56806..8e5b2fd
@@ -707,7 +707,7 @@ int wm831x_post_init(struct wm831x *parm)
        
        dcdc = regulator_get(NULL, "dcdc3");            // 1th IO
        regulator_set_voltage(dcdc,3000000,3000000);
-       regulator_set_suspend_voltage(dcdc, 3000000);
+       regulator_set_suspend_voltage(dcdc, 2800000);
        regulator_enable(dcdc);                 
        printk("%s set dcdc3=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc));
        regulator_put(dcdc);
@@ -2519,9 +2519,37 @@ static struct platform_device gpio_wave_device = {
 
 static void __init rk29_board_iomux_init(void)
 {
+       int err;
        #ifdef CONFIG_RK29_PWM_REGULATOR
        rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
        #endif
+       rk29_mux_api_set(GPIO4C0_RMIICLKOUT_RMIICLKIN_NAME,GPIO4H_GPIO4C0);
+
+/****************************clock change********************************************/
+       err = gpio_request(RK29_PIN4_PC0, "clk27M_control");
+       if (err) {
+               gpio_free(RK29_PIN4_PC0);
+               printk("-------request RK29_PIN4_PC0 fail--------\n");
+               return -1;
+       }
+       //phy power down
+       gpio_direction_output(RK29_PIN4_PC0, GPIO_LOW);// 27M  32K
+       gpio_set_value(RK29_PIN4_PC0, GPIO_LOW);
+
+       rk29_mux_api_set(GPIO4C5_RMIICSRDVALID_MIIRXDVALID_NAME,GPIO4H_GPIO4C5);
+
+       err = gpio_request(RK29_PIN4_PC5, "clk24M_control");
+       if (err) {
+               gpio_free(RK29_PIN4_PC5);
+               printk("-------request RK29_PIN4_PC5 fail--------\n");
+               return -1;
+       }
+       //phy power down
+       gpio_direction_output(RK29_PIN4_PC5, GPIO_LOW);// control 24M
+       gpio_set_value(RK29_PIN4_PC5, GPIO_LOW);
+/*******************************************************************/
+
+
 }
 
 static struct platform_device *devices[] __initdata = {
index ed7a6ef7e89b9ff5e863904c754b23eb28a57b59..ed840cfc00c71fa5a72730465a2c16105cb99246 100755 (executable)
@@ -42,7 +42,7 @@ static inline void delay_300us(void)
 }
 
 #ifdef DEBUG
-static void/* inline*/ __sramfunc printch(char byte)
+ void/* inline*/ __sramfunc sram_printch(char byte)
 {
        unsigned long flags;
        u32 gate1, gate2;
@@ -64,33 +64,33 @@ static void/* inline*/ __sramfunc printch(char byte)
        cru_writel(gate1, CRU_CLKGATE1_CON);
        local_irq_restore(flags);
        if (byte == '\n')
-               printch('\r');
+               sram_printch('\r');
 }
 
-static void __sramfunc printascii(const char *s)
+ void __sramfunc sram_printascii(const char *s)
 {
        while (*s) {
                if (*s == '\n')
                {
-                   printch('\r');
+                   sram_printch('\r');
                }
-           printch(*s);
+           sram_printch(*s);
            s++;
        }
 }
 void print(const char *s)
 {
-    printascii(s);
+    sram_printascii(s);
 }
 
 void __sramfunc print_Hex(unsigned int hex)
 {
        int i = 8;
-       printch('0');
-       printch('x');
+       sram_printch('0');
+       sram_printch('x');
        while (i--) {
                unsigned char c = (hex & 0xF0000000) >> 28;
-               printch(c < 0xa ? c + '0' : c - 0xa + 'a');
+               sram_printch(c < 0xa ? c + '0' : c - 0xa + 'a');
                hex <<= 4;
        }
 }
@@ -102,7 +102,7 @@ void __sramfunc print_Dec (uint32_t n)
         print_Dec(n / 10);
         n %= 10;
     }
-    printch((char)(n + '0'));
+    sram_printch((char)(n + '0'));
 }
 
 void print_Dec_3(uint32_t value)
@@ -124,17 +124,17 @@ void print_Dec_3(uint32_t value)
 static void /* inline*/ __sramfunc printhex(unsigned int hex)
 {
        int i = 8;
-       printch('0');
-       printch('x');
+       sram_printch('0');
+       sram_printch('x');
        while (i--) {
                unsigned char c = (hex & 0xF0000000) >> 28;
-               printch(c < 0xa ? c + '0' : c - 0xa + 'a');
+               sram_printch(c < 0xa ? c + '0' : c - 0xa + 'a');
                hex <<= 4;
        }
 }
 #else
-static void inline printch(char byte) {}
-static void inline printascii(const char *s) {}
+static void inline sram_printch(char byte) {}
+static void inline sram_printascii(const char *s) {}
 static void inline printhex(unsigned int hex) {}
 #endif /* DEBUG */
 
@@ -155,64 +155,64 @@ void __sramfunc ddr_testmode(void)
     {
         for (;;)
         {
-               printch(' ');
-               printch('8');
-               printch('8');
-               printch('8');
-               printch(' ');
+               sram_printch(' ');
+               sram_printch('8');
+               sram_printch('8');
+               sram_printch('8');
+               sram_printch(' ');
             g_crc1 = calc_crc32((u32)_stext, (size_t)(_etext-_stext));
             nMHz = 333 + (random32()>>25);
             if(nMHz > 402)
                 nMHz = 402;
                printhex(nMHz);
-               printch(' ');
+               sram_printch(' ');
                printhex(n++);
             //ddr_print("%s change freq to: %d MHz\n", __func__, nMHz);
             ddr_change_freq(nMHz);
             g_crc2 = calc_crc32((u32)_stext, (size_t)(_etext-_stext));
             if (g_crc1!=g_crc2)
             {
-                   printch(' ');
-                   printch('f');
-                   printch('a');
-                   printch('i');
-                   printch('l');
+                   sram_printch(' ');
+                   sram_printch('f');
+                   sram_printch('a');
+                   sram_printch('i');
+                   sram_printch('l');
                }
                //ddr_print("check image crc32 success--crc value = 0x%x!, count:%d\n",g_crc1, n++);
-           //     printascii("change freq success\n");
+           //     sram_printascii("change freq success\n");
         }
     }
     else if(ddr_debug == 2)
     {
         for (;;)
         {
-               printch(' ');
-               printch('9');
-               printch('9');
-               printch('9');
-               printch(' ');
+               sram_printch(' ');
+               sram_printch('9');
+               sram_printch('9');
+               sram_printch('9');
+               sram_printch(' ');
             g_crc1 = calc_crc32((u32)_stext, (size_t)(_etext-_stext));
             nMHz = (random32()>>13);// 16.7s max
             ddr_suspend();
             delayus(nMHz);
             ddr_resume();
                printhex(nMHz);
-               printch(' ');
+               sram_printch(' ');
                printhex(n++);
             g_crc2 = calc_crc32((u32)_stext, (size_t)(_etext-_stext));
             if (g_crc1!=g_crc2)
             {
-                   printch(' ');
-                   printch('f');
-                   printch('a');
-                   printch('i');
-                   printch('l');
+                   sram_printch(' ');
+                   sram_printch('f');
+                   sram_printch('a');
+                   sram_printch('i');
+                   sram_printch('l');
                }
               // ddr_print("check image crc32 fail!, count:%d\n", n++);
-            //    printascii("self refresh fail\n");
+            //    sram_printascii("self refresh fail\n");
             //else
                //ddr_print("check image crc32 success--crc value = 0x%x!, count:%d\n",g_crc1, n++);
-            //    printascii("self refresh success\n");
+            //    sram_printascii("self refresh success\n");
         }
     }
     else if(ddr_debug == 3)
@@ -225,41 +225,50 @@ void __sramfunc ddr_testmode(void)
 {}
 
 #endif 
-void __sramfunc pm_spi_gpio_suspend(void);
-void __sramfunc pm_spi_gpio_resume(void);
-static void __sramfunc rk29_sram_suspend(void)
+void __sramfunc pm_clk_switch_32k(void);
+
+void __sramfunc pm_wfi(void)
 {
        u32 clksel0;
-       u32 vol;
-
-       if ((ddr_debug == 1) || (ddr_debug == 2))
-               ddr_testmode();
-
-       printch('5');
-       ddr_suspend();
-
-       printch('6');
-       vol=rk29_suspend_voltage_set(1000000);
-
-       printch('7');
+       sram_printch('7');
        clksel0 = cru_readl(CRU_CLKSEL0_CON);
        /* set arm clk 24MHz/32 = 750KHz */
        cru_writel(clksel0 | 0x1F, CRU_CLKSEL0_CON);
 
-       printch('8');
+       sram_printch('8');
        dsb();
        asm("wfi");
-       printch('8');
+       sram_printch('8');
 
        /* resume arm clk */
        cru_writel(clksel0, CRU_CLKSEL0_CON);
-       printch('7');
-       
+       sram_printch('7');
+
+
+}
+
+static void __sramfunc rk29_sram_suspend(void)
+{
+       u32 vol;
+
+       if ((ddr_debug == 1) || (ddr_debug == 2))
+               ddr_testmode();
+
+       sram_printch('5');
+       ddr_suspend();
+
+       sram_printch('6');
+       vol=rk29_suspend_voltage_set(1000000);
+#ifdef CONFIG_RK29_CLK_SWITCH_TO_32K
+       pm_clk_switch_32k();
+#else
+       pm_wfi();
+#endif
        rk29_suspend_voltage_resume(vol);
-       printch('6');
+       sram_printch('6');
 
        ddr_resume();
-       printch('5');
+       sram_printch('5');
 }
 
 static void noinline rk29_suspend(void)
@@ -296,9 +305,9 @@ static void dump_irq(void)
 do { \
        u32 en = readl(RK29_GPIO##ID##_BASE + GPIO_INTEN); \
        if (en) { \
-               printascii("GPIO" #ID "_INTEN: "); \
+               sram_printascii("GPIO" #ID "_INTEN: "); \
                printhex(en); \
-               printch('\n'); \
+               sram_printch('\n'); \
        } \
 } while (0)
 
@@ -318,9 +327,9 @@ static void dump_inten(void)
 #define DUMP_GPIO_PULL(ID) \
 do { \
        u32 state = readl(RK29_GRF_BASE + GRF_GPIO0_PULL + (ID<<2)); \
-       printascii("GPIO" #ID "_PULL: "); \
+       sram_printascii("GPIO" #ID "_PULL: "); \
        printhex(state); \
-       printch('\n'); \
+       sram_printch('\n'); \
 } while (0)
 
 static void dump_io_pull(void)
@@ -333,6 +342,8 @@ static void dump_io_pull(void)
        DUMP_GPIO_PULL(5);
        DUMP_GPIO_PULL(6);
 }
+void pm_gpio_suspend(void);
+void pm_gpio_resume(void);
 
 static int rk29_pm_enter(suspend_state_t state)
 {
@@ -351,7 +362,7 @@ static int rk29_pm_enter(suspend_state_t state)
        dump_io_pull();
 #endif
 
-       printch('0');
+       sram_printch('0');
        flush_tlb_all();
        interface_ctr_reg_pread();
 
@@ -393,7 +404,7 @@ static int rk29_pm_enter(suspend_state_t state)
 #endif
                   ) | clkgate[2], CRU_CLKGATE2_CON);
        cru_writel(~0, CRU_CLKGATE3_CON);
-       printch('1');
+       sram_printch('1');
 
        mode = cru_readl(CRU_MODE_CON);
        clksel0 = cru_readl(CRU_CLKSEL0_CON);
@@ -406,7 +417,7 @@ static int rk29_pm_enter(suspend_state_t state)
        delay_500ns();
        /* set core = aclk_cpu = hclk_cpu = pclk_cpu = 24MHz */
        cru_writel(clksel0 & 0xFFFFF000, CRU_CLKSEL0_CON);
-       printch('2');
+       sram_printch('2');
 
        /* suspend codec pll */
        cpll = cru_readl(CRU_CPLL_CON);
@@ -414,7 +425,7 @@ static int rk29_pm_enter(suspend_state_t state)
        cru_writel(cpll | PLL_BYPASS, CRU_CPLL_CON);
        cru_writel(cpll | PLL_PD | PLL_BYPASS, CRU_CPLL_CON);
        delay_500ns();
-       printch('3');
+       sram_printch('3');
 
        /* suspend general pll */
        gpll = cru_readl(CRU_GPLL_CON);
@@ -425,9 +436,11 @@ static int rk29_pm_enter(suspend_state_t state)
        /* set aclk_periph = hclk_periph = pclk_periph = 24MHz */
        cru_writel(clksel0 & ~0x7FC000, CRU_CLKSEL0_CON);
 
-       printch('4');
+       sram_printch('4');
+       pm_gpio_suspend();
        rk29_suspend();
-       printch('4');
+       pm_gpio_resume();
+       sram_printch('4');
        
        /* resume general pll */
        cru_writel(gpll, CRU_GPLL_CON);
@@ -435,13 +448,13 @@ static int rk29_pm_enter(suspend_state_t state)
        /* restore aclk_periph/hclk_periph/pclk_periph */
        cru_writel(cru_readl(CRU_CLKSEL0_CON) | (clksel0 & 0x7FC000), CRU_CLKSEL0_CON);
        cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_GENERAL_MODE_MASK) | (mode & CRU_GENERAL_MODE_MASK), CRU_MODE_CON);
-       printch('3');
+       sram_printch('3');
 
        /* resume codec pll */
        cru_writel(cpll, CRU_CPLL_CON);
        delay_300us();
        cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CODEC_MODE_MASK) | (mode & CRU_CODEC_MODE_MASK), CRU_MODE_CON);
-       printch('2');
+       sram_printch('2');
 
        /* resume arm pll */
        cru_writel(apll, CRU_APLL_CON);
@@ -449,14 +462,14 @@ static int rk29_pm_enter(suspend_state_t state)
        /* restore core/aclk_cpu/hclk_cpu/pclk_cpu */
        cru_writel(cru_readl(CRU_CLKSEL0_CON) | (clksel0 & 0xFFF), CRU_CLKSEL0_CON);
        cru_writel((cru_readl(CRU_MODE_CON) & ~CRU_CPU_MODE_MASK) | (mode & CRU_CPU_MODE_MASK), CRU_MODE_CON);
-       printch('1');
+       sram_printch('1');
 
        /* enable clock */
        cru_writel(clkgate[0], CRU_CLKGATE0_CON);
        cru_writel(clkgate[1], CRU_CLKGATE1_CON);
        cru_writel(clkgate[2], CRU_CLKGATE2_CON);
        cru_writel(clkgate[3], CRU_CLKGATE3_CON);
-       printascii("0\n");
+       sram_printascii("0\n");
 
        dump_irq();
        return 0;
index fcbab25c09afa223b8e0df81f41204cef5e2ec52..c9512a8ba68fe52ed372a6718cdc02e7597dced8 100755 (executable)
@@ -1,11 +1,10 @@
-
 #include <mach/rk29_iomap.h>
 #include <mach/board.h>
 #include <mach/sram.h>
 #include <mach/iomux.h>
 #include <mach/cru.h>
 #include <asm/io.h>
-
+#include <mach/gpio.h>
 
 #define SPI_KHZ (1000)
 #define SPI_MHZ (1000*1000) 
 
 
 
+#define GRF_GPIO0_DIR     0x000
+#define GRF_GPIO1_DIR     0x004
+#define GRF_GPIO2_DIR     0x008
+#define GRF_GPIO3_DIR     0x00c
+#define GRF_GPIO4_DIR     0x010
+#define GRF_GPIO5_DIR     0x014
+
+
+#define GRF_GPIO0_DO      0x018
+#define GRF_GPIO1_DO      0x01c
+#define GRF_GPIO2_DO      0x020
+#define GRF_GPIO3_DO      0x024
+#define GRF_GPIO4_DO      0x028
+#define GRF_GPIO5_DO      0x02c
+
+#define GRF_GPIO0_EN      0x030
+#define GRF_GPIO1_EN      0x034
+#define GRF_GPIO2_EN      0x038
+#define GRF_GPIO3_EN      0x03c
+#define GRF_GPIO4_EN      0x040
+#define GRF_GPIO5_EN      0x044
+
+
+#define GRF_GPIO0L_IOMUX  0x048
+#define GRF_GPIO0H_IOMUX  0x04c
+#define GRF_GPIO1L_IOMUX  0x050
+#define GRF_GPIO1H_IOMUX  0x054
+#define GRF_GPIO2L_IOMUX  0x058
+#define GRF_GPIO2H_IOMUX  0x05c
+#define GRF_GPIO3L_IOMUX  0x060
+#define GRF_GPIO3H_IOMUX  0x064
+#define GRF_GPIO4L_IOMUX  0x068
+#define GRF_GPIO4H_IOMUX  0x06c
+#define GRF_GPIO5L_IOMUX  0x070
+#define GRF_GPIO5H_IOMUX  0x074
 
 //#include <mach/spi_sram.h>
 
 #define SR_RF_EMPT                 (1 << 3)
 #define SR_RF_FULL                     (1 << 4)
 
+#define PM_GETGPIO_BASE(N) RK29_GPIO##N##_BASE
+#define PM_GPIO_DR 0
+#define PM_GPIO_DDR 0x4
+#define PM_GPIO_INTEN 0x30
+
+#define wm831x_RD_MSK (0x1<<15)
+#define wm831x_RD_VOID (0x7FFF)
+#define spi_ctr0_mask 0x1fffc3
+
 
-#define spi_readl(offset) readl(SRAM_SPI_ADDRBASE + offset)
-#define spi_writel(v, offset) writel(v, SRAM_SPI_ADDRBASE + offset)
 
 enum
 {
@@ -83,16 +124,21 @@ static u32 __sramdata spi_data[DATE_END]={};
 #define sram_spi_cs_dis()  spi_writel(spi_readl(SPIM_SER)&~0x3,SPIM_SER)
 #define sram_spi_cs_en()  spi_writel((spi_readl(SPIM_SER)&~0x3)|(0x1<<SRAM_SPI_CS),SPIM_SER);
 #define sram_spi_busy() (spi_readl(SPIM_SR)&SR_BUSY)
+//RK29_PIN0_PA0
+#define pm_gpio_out_low(gpio) pm_gpio_set((gpio),GPIO_OUT,GPIO_LOW)
+#define pm_gpio_out_high(gpio) pm_gpio_set((gpio),GPIO_OUT,GPIO_HIGH)
 
-#define wm831x_RD_MSK (0x1<<15)
-#define wm831x_RD_VOID (0x7FFF)
-#define spi_ctr0_mask 0x1fffc3
+#define spi_readl(offset) readl(SRAM_SPI_ADDRBASE + offset)
+#define spi_writel(v, offset) writel(v, SRAM_SPI_ADDRBASE + offset)
+
+#define grf_readl(offset) readl(RK29_GRF_BASE + offset)
+#define grf_writel(v, offset) do { writel(v, RK29_GRF_BASE + offset); readl(RK29_GRF_BASE + offset); } while (0)
 
 
 
-#if 0
+#if 1
 void __sramfunc sram_printch(char byte);
-void __sramfunc sram_printHX(unsigned int hex);
+#define sram_printHX(a)
 #else
 #define sram_printch(a)
 #define sram_printHX(a)
@@ -100,44 +146,7 @@ void __sramfunc sram_printHX(unsigned int hex);
 
 #define sram_udelay(usecs,a) LOOP((usecs)*LOOPS_PER_USEC)
 
-#define GRF_GPIO0_DIR     0x000
-#define GRF_GPIO1_DIR     0x004
-#define GRF_GPIO2_DIR     0x008
-#define GRF_GPIO3_DIR     0x00c
-#define GRF_GPIO4_DIR     0x010
-#define GRF_GPIO5_DIR     0x014
-
-
-#define GRF_GPIO0_DO      0x018
-#define GRF_GPIO1_DO      0x01c
-#define GRF_GPIO2_DO      0x020
-#define GRF_GPIO3_DO      0x024
-#define GRF_GPIO4_DO      0x028
-#define GRF_GPIO5_DO      0x02c
-
-#define GRF_GPIO0_EN      0x030
-#define GRF_GPIO1_EN      0x034
-#define GRF_GPIO2_EN      0x038
-#define GRF_GPIO3_EN      0x03c
-#define GRF_GPIO4_EN      0x040
-#define GRF_GPIO5_EN      0x044
-
-
-#define GRF_GPIO0L_IOMUX  0x048
-#define GRF_GPIO0H_IOMUX  0x04c
-#define GRF_GPIO1L_IOMUX  0x050
-#define GRF_GPIO1H_IOMUX  0x054
-#define GRF_GPIO2L_IOMUX  0x058
-#define GRF_GPIO2H_IOMUX  0x05c
-#define GRF_GPIO3L_IOMUX  0x060
-#define GRF_GPIO3H_IOMUX  0x064
-#define GRF_GPIO4L_IOMUX  0x068
-#define GRF_GPIO4H_IOMUX  0x06c
-#define GRF_GPIO5L_IOMUX  0x070
-#define GRF_GPIO5H_IOMUX  0x074
 
-#define grf_readl(offset) readl(RK29_GRF_BASE + offset)
-#define grf_writel(v, offset) do { writel(v, RK29_GRF_BASE + offset); readl(RK29_GRF_BASE + offset); } while (0)
 
 typedef struct GPIO_IOMUX
 {
@@ -155,9 +164,22 @@ typedef  struct REG_FILE_GRF
    unsigned int GRF_GPIO_PULL[7];
 } GRF_REG_SAVE;
 
-static GRF_REG_SAVE __sramdata pm_grf;
+__sramdata u32 pm_gpio_base[7]=
+{
+RK29_GPIO0_BASE,
+RK29_GPIO1_BASE,
+RK29_GPIO2_BASE,
+RK29_GPIO3_BASE,
+RK29_GPIO4_BASE,
+RK29_GPIO5_BASE,
+RK29_GPIO6_BASE
+};
+static GRF_REG_SAVE  pm_grf;
+int __sramdata crumode;
+
+//static GRF_REG_SAVE __sramdata pm_grf;
 
-static void __sramfunc pm_spi_gpio_prepare(void)
+static void  pm_spi_gpio_prepare(void)
 {
        pm_grf.GRF_GPIO_IOMUX[1].GPIOL_IOMUX = grf_readl(GRF_GPIO1L_IOMUX);
        pm_grf.GRF_GPIO_IOMUX[2].GPIOH_IOMUX = grf_readl(GRF_GPIO2H_IOMUX);
@@ -169,7 +191,7 @@ static void __sramfunc pm_spi_gpio_prepare(void)
        pm_grf.GRF_GPIO_EN[2] = grf_readl(GRF_GPIO2_EN);
 }
 
-static void __sramfunc pm_spi_gpio_suspend(void)
+ void  pm_spi_gpio_suspend(void)
 {
        int io1L_iomux;
        int io2H_iomux;
@@ -199,7 +221,7 @@ static void __sramfunc pm_spi_gpio_suspend(void)
        grf_writel(io2_en|0x00ff0000,GRF_GPIO2_EN);
 }
 
-static void __sramfunc pm_spi_gpio_resume(void)
+ void  pm_spi_gpio_resume(void)
 {
        grf_writel(pm_grf.GRF_GPIO_EN[1],GRF_GPIO1_EN);
        grf_writel(pm_grf.GRF_GPIO_EN[2],GRF_GPIO2_EN);
@@ -210,6 +232,9 @@ static void __sramfunc pm_spi_gpio_resume(void)
        grf_writel(pm_grf.GRF_GPIO_IOMUX[2].GPIOH_IOMUX, GRF_GPIO2H_IOMUX);
 }
 
+
+#if defined(CONFIG_RK29_SPI_INSRAM)
+
 #define SPI_GATE1_MASK 0xCF
 
 void interface_ctr_reg_pread(void)
@@ -226,6 +251,14 @@ void interface_ctr_reg_pread(void)
 
     writel(temp2,RK29_CRU_BASE + CRU_CLKGATE2_CON);
     writel(temp,RK29_CRU_BASE + CRU_CLKGATE1_CON);
+       readl(RK29_GPIO0_BASE);
+       readl(RK29_GPIO1_BASE);
+       readl(RK29_GPIO2_BASE);
+       readl(RK29_GPIO3_BASE);
+       readl(RK29_GPIO4_BASE);
+       readl(RK29_GPIO5_BASE);
+       readl(RK29_GPIO6_BASE);
+
 
 }
 
@@ -286,7 +319,6 @@ static void __sramfunc sram_spi_init(void)
        
        spi_data[SPI_CTRLR0] = spi_readl(SPIM_CTRLR0); 
        spi_data[SPI_BAUDR] = spi_readl(SPIM_BAUDR);
-       
        spi_writel((spi_data[SPI_CTRLR0]&~0x1fffc3)|0x1<<11|(SRAM_SPI_DATA_BYTE),SPIM_CTRLR0);//spi setting
        spi_writel((spi_data[SPI_BAUDR]&(~0xffff))|SRAM_SPI_DIV,SPIM_BAUDR);//setting spi speed
        spi_data[SPI_SER]=spi_readl(SPIM_SER);//spi cs
@@ -430,7 +462,6 @@ unsigned int __sramfunc rk29_suspend_voltage_set(unsigned int vol)
                sram_spi_deinit();
        #endif
 
-       pm_spi_gpio_suspend();
 
        return 0;
 }
@@ -441,8 +472,6 @@ void __sramfunc rk29_suspend_voltage_resume(unsigned int vol)
        unsigned short addr_4003=0x4003;
        unsigned short data_4003;
 
-       pm_spi_gpio_resume();
-
        sram_spi_init();    //iomux  clk
 
        data_4003=sram_spi_read(addr_4003|wm831x_RD_MSK,wm831x_RD_VOID);
@@ -451,15 +480,127 @@ void __sramfunc rk29_suspend_voltage_resume(unsigned int vol)
        sram_printch('G');
        data_4003&=~(0x1<<14);
        sram_spi_write(addr_4003,data_4003);// sleep
-       
-       
+
        data_4003=sram_spi_read(addr_4003|wm831x_RD_MSK,wm831x_RD_VOID);
        sram_printHX(data_4003);//sleep ctr
 
        
        sram_spi_deinit();
+       sram_udelay(100000, 24);
+       
+}
+#endif
+
+
+
+
+void __sramfunc sram_delay_loop(unsigned long count)
+{
+       while (count--) {
+               nop();
+               nop();
+               nop();
+               barrier();
+       }
+}
+
+void __sramfunc pm_gpio_set(unsigned gpio,eGPIOPinDirection_t direction,eGPIOPinLevel_t level)
+{
+       unsigned group,pin,value;
+       group=gpio/32;
+       pin=gpio%32;
+       if(group>6||pin>31)
+               return;
+       
+       if(direction==GPIO_OUT)
+       {
+               value=readl(pm_gpio_base[group]+PM_GPIO_DDR);
+               value|=0x1<<pin;
+               writel(value,pm_gpio_base[group]+PM_GPIO_DDR);
+
+               value=readl(pm_gpio_base[group]+PM_GPIO_DR);
+               
+               if(level==GPIO_HIGH)
+                       value|=0x1<<pin;
+               else
+                       value&=~(0x1<<pin);
+               
+               writel(value,pm_gpio_base[group]+PM_GPIO_DR);
+
+               
+       }
+       else
+       {
+               value=readl(pm_gpio_base[group]+PM_GPIO_DDR);
+               value&=~(0x1<<pin);
+               writel(value,pm_gpio_base[group]+PM_GPIO_DDR);
+
+       }
+}
+/*
+*flag=0,mask
+*/
+
+
+#ifdef CONFIG_RK29_CLK_SWITCH_TO_32K
+
+void __sramfunc pm_clk_switch_32k(void)
+{
+       int vol;
+       sram_printch('7');
+       pm_gpio_out_high(RK29_PIN4_PC0);
+       sram_delay_loop(30);
+
+       crumode=cru_readl(CRU_MODE_CON); //24M to 27M
+       cru_writel((crumode&(~0x7fff))|0x2baa, CRU_MODE_CON);
+       sram_delay_loop(30);
+
+//     pm_gpio_iomux(RK29_PIN4_PC5,0x0);// disable 24
+       pm_gpio_out_high(RK29_PIN4_PC5);
+
+       sram_delay_loop(30);
+       dsb();
+       asm("wfi");
        
-       sram_udelay(100000,24);
+       pm_gpio_out_low(RK29_PIN4_PC5);//enable 24M 
+       sram_udelay(1000,24);
+       cru_writel(crumode, CRU_MODE_CON); //externel clk 24M
        
+       pm_gpio_out_low(RK29_PIN4_PC0); //enable 27M
+       sram_udelay(1000,27);
+       sram_printch('7');
+
+
 }
 
+#else
+void __sramfunc pm_clk_switch(void)
+{
+
+}
+#endif
+
+
+
+#ifdef  CONFIG_RK29_GPIO_SUSPEND
+void pm_gpio_suspend(void)
+{
+       pm_spi_gpio_suspend(); // spi  pullup/pulldown  disable.....¡£
+
+}
+
+void pm_gpio_resume(void)
+{
+       pm_spi_gpio_resume(); // spi  pullup/pulldown  disable.....¡£
+
+}
+
+#else
+void pm_gpio_suspend(void)
+{}
+void pm_gpio_resume(void)
+{}
+#endif
+
+
+