#include "pm.h"
//#include "sram.h"
+/*************************dump reg********************************************/
+
+static void __sramfunc rkpm_sram_reg_dump(u32 base_addr,u32 start_offset,u32 end_offset)
+{
+ u32 i;
+ rkpm_sram_printch('\n');
+ rkpm_sram_printhex(base_addr);
+ rkpm_sram_printch(':');
+ rkpm_sram_printch('\n');
+
+ for(i=start_offset;i<=end_offset;)
+ {
+ rkpm_sram_printhex(i);
+ rkpm_sram_printch('-');
+ rkpm_sram_printhex(readl_relaxed((void *)(base_addr + i)));
+ if(!(i%5)&&i!=0)
+ rkpm_sram_printch('\n');
+ i+=4;
+ }
+
+ rkpm_sram_printch('\n');
+
+}
+
struct rkpm_sram_ops DEFINE_PIE_DATA(pm_sram_ops);
//for sram
/******************************************pm main function******************************************/
#define RKPM_CTR_SYSCLK RKPM_OR_3BITS(SYSCLK_DIV,SYSCLK_32K,SYSCLK_OSC_DIS)
-void __sramfunc rkpm_sram_suspend(u32 ctrbits)
+static void __sramfunc rkpm_sram_suspend(u32 ctrbits)
{
rkpm_sram_printch('5');
}
-void rkpm_pie_init(void)
+static void rkpm_pie_init(void)
{
rkpm_set_pie_info(kern_to_pie(rockchip_pie_chunk, &DATA(pm_sram_ops))
,fn_to_pie(rockchip_pie_chunk, &FUNC(rkpm_sram_suspend_arg)));
#define rkpm_chk_val_ctrbit(val,bit) ((val)&(bit))//check bit
#define rkpm_chk_val_ctrbits(val,bits) ((val)&(bits)) //check bits
+/************************************reg ops*****************************************************/
+#define cru_readl(offset) readl_relaxed(RK_CRU_VIRT + offset)
+#define cru_writel(v, offset) do { writel_relaxed(v, RK_CRU_VIRT + offset); dsb(); } while (0)
+
+#define pmu_readl(offset) readl_relaxed(RK_PMU_VIRT + offset)
+#define pmu_writel(v,offset) do { writel_relaxed(v, RK_PMU_VIRT + offset); dsb(); } while (0)
+
+#define grf_readl(offset) readl_relaxed(RK_GRF_VIRT + offset)
+#define grf_writel(v, offset) do { writel_relaxed(v, RK_GRF_VIRT + offset); dsb(); } while (0)
+
+#define reg_readl(base) readl_relaxed(base)
+#define reg_writel(v, base) do { writel_relaxed(v, base); dsb(); } while (0)
+
+
+#define PM_ERR(fmt, args...) printk(KERN_ERR fmt, ##args)
+#define PM_LOG(fmt, args...) printk(KERN_ERR fmt, ##args)
+#define PM_WARNING(fmt, args...) printk(KERN_WARNING fmt, ##args)
+
/*********************************pm control******************************************/
+extern void rkpm_ddr_reg_dump(u32 base_addr,u32 start_offset,u32 end_offset);
extern void rkpm_set_pie_info(struct rkpm_sram_ops *pm_sram_ops,rkpm_sram_suspend_arg_cb pie_cb);
extern void rkpm_set_ops_prepare_finish(rkpm_ops_void_callback prepare,rkpm_ops_void_callback finish);
extern void rkpm_set_ops_pwr_dmns(rkpm_ops_void_callback pwr_dmns,rkpm_ops_void_callback re_pwr_dmns);
extern void rkpm_set_ops_printch(rkpm_ops_printch_callback printch);
extern void rkpm_set_ops_regs_pread(rkpm_ops_void_callback regs_pread);
-
-extern void rkpm_pie_init(void);
extern void rkpm_set_sram_ops_volt(rkpm_ops_void_callback volts,rkpm_ops_void_callback re_volts);
extern void rkpm_set_sram_ops_gtclks(rkpm_ops_void_callback gtclks,rkpm_ops_void_callback re_gtclks);
extern void rkpm_set_sram_ops_sysclk(rkpm_ops_paramter_u32_cb sysclk,rkpm_ops_paramter_u32_cb re_sysclk);
#ifndef __DT_BINDINGS_ROCKCHIP_PM_H__
#define __DT_BINDINGS_ROCKCHIP_PM_H__
+/******************************bits ops************************************/
+
+
+
+
+#define RKPM_BITS_W_MSK(bits_shift, msk) ((msk) << ((bits_shift) + 16))
+
+#define RKPM_BITS_CLR_VAL(val, bits_shift, msk) (val&~(msk<<bits_shift))
+
+#define RKPM_SETBITS(bits, bits_shift, msk) (((bits)&(msk)) << (bits_shift))
+
+#define RKPM_W_MSK_SETBITS(bits, bits_shift, msk) \
+ (RKPM_BITS_W_MSK(bits_shift, msk) | RKPM_SETBITS(bits, bits_shift, msk))
+
+#define RKPM_VAL_SETBITS(val,bits, bits_shift, msk) \
+ (RKPM_BITS_CLR_VAL(val,bits_shift, msk) | RKPM_SETBITS(bits, bits_shift, msk))
+
+#define RKPM_GETBITS(val, bits_shift, msk) (((val)>> (bits_shift))&(msk))
+
+
+
+
/*********************CTRBIT DEFINE*****************************/
#define RKPM_CTR_PWR_DMNS (0x1<<0)
/*********************CTRBIT DEFINE END*****************************/
-#define RKPM_GPIOBITS_LEVEL_PULL (24)
-#define RKPM_GPIOBITS_MSK_LEVEL_PULL (0xf<<RKPM_GPIOBITS_LEVEL_PULL)
+//pin=0x0a21 gpio0a2,port=0,bank=a,b_gpio=2,fun=1
+#define RKPM_PINBITS_BGPIO(pins) RKPM_GETBITS(pins,4,0xf)
+#define RKPM_PINBITS_BANK(pins) RKPM_GETBITS(pins,8,0xf) // a,b,c,d
+#define RKPM_PINBITS_PORT(pins) RKPM_GETBITS(pins,0xc,0xf)
+#define RKPM_PINBITS_FUN(pins) RKPM_GETBITS(pins,0,0xf)
+
+//#define RKPM_PINBITS(port,bank,bgpio,fun) 0
+
+#if 1
+#define RKPM_PINBITS(port,bank,bgpio,fun) (0\
+ |RKPM_SETBITS(fun,0,0xf)\
+ |RKPM_SETBITS(bgpio,0x4,0xf)\
+ |RKPM_SETBITS(bank,0x8,0xf)\
+ |RKPM_SETBITS(port,0xc,0xf)\
+ )
+#endif
+#define RKPM_PINBITS_SET_FUN(pins,fun) RKPM_VAL_SETBITS(pins,fun,0,0xf)
-#define RKPM_GPIOBITS_INOUT (20)
-#define RKPM_GPIOBITS_MSK_INOUT (0xf<<RKPM_GPIOBITS_INOUT)
+#define RKPM_PINGPIO_PIN (0)
+#define RKPM_PINGPIO_PIN_MSK (0xffff)
-#define RKPM_GPIOBITS_PINS (0)
-#define RKPM_GPIOBITS_MSK_PINS (0xffff<<RKPM_GPIOBITS_PINS)
+#define RKPM_PINGPIO_PULL (24)
+#define RKPM_PINGPIO_PULL_MSK (0x3)
+#define RKPM_PINGPIO_INOUT (26)
+#define RKPM_PINGPIO_INOUT_MSK (0x3)
-#define RKPM_GPIOS_INPUT (0)
-#define RKPM_GPIOS_OUTPUT (1)
+#define RKPM_PINGPIO_LEVEL (28)
+#define RKPM_PINGPIO_LEVEL_MSK (0x3)
-#define RKPM_GPIOS_OUT_H (1)
-#define RKPM_GPIOS_OUT_L (0)
+#define RKPM_GPIO_INPUT (0)
+#define RKPM_GPIO_OUTPUT (1)
-#define RKPM_GPIOS_IN_PULLUP (0)
-#define RKPM_GPIOS_IN_PULLDN (0)
-#define RKPM_GPIOS_IN_PULLNULL (0)
+#define RKPM_GPIO_OUT_L (0)
+#define RKPM_GPIO_OUT_H (1)
+#define RKPM_GPIO_PULL_Z (0)
+#define RKPM_GPIO_PULL_UP (0x1)
+#define RKPM_GPIO_PULL_DN (0x2)
+#define RKPM_GPIO_PULL_RPTR (0x3)
-#define RKPM_GPIOS_SETTING(pins,in_out,level_pull) (\
- ((pins)&RKPM_GPIOBITS_MSK_PINS)\
- |(((in_out)<<RKPM_GPIOBITS_INOUT)&RKPM_GPIOBITS_MSK_INOUT)\
- |(((level_pull)<<RKPM_GPIOBITS_LEVEL_PULL)&RKPM_GPIOBITS_MSK_LEVEL_PULL)\
+#define RKPM_PINGPIO_BITS(pin,pull,inout,_level) (0\
+ |RKPM_SETBITS(pin,RKPM_PINGPIO_PIN,RKPM_PINGPIO_PIN_MSK)\
+ |RKPM_SETBITS(inout,RKPM_PINGPIO_INOUT,RKPM_PINGPIO_INOUT_MSK)\
+ |RKPM_SETBITS(pull,RKPM_PINGPIO_PULL,RKPM_PINGPIO_PULL_MSK)\
+ |RKPM_SETBITS(_level,RKPM_PINGPIO_LEVEL,RKPM_PINGPIO_LEVEL_MSK)\
+ )
+
+#define RKPM_PINGPIO_BITS_OUTPUT(pin,_level) (0\
+ |RKPM_SETBITS(pin,RKPM_PINGPIO_PIN,RKPM_PINGPIO_PIN_MSK)\
+ |RKPM_SETBITS(RKPM_GPIO_OUTPUT,RKPM_PINGPIO_INOUT,RKPM_PINGPIO_INOUT_MSK)\
+ |RKPM_SETBITS(_level,RKPM_PINGPIO_LEVEL,RKPM_PINGPIO_LEVEL_MSK)\
)
+
+#define RKPM_PINGPIO_BITS_INTPUT(pin,pull) (0\
+ |RKPM_SETBITS(pin,RKPM_PINGPIO_PIN,RKPM_PINGPIO_PIN_MSK)\
+ |RKPM_SETBITS(RKPM_GPIO_INPUT,RKPM_PINGPIO_INOUT,RKPM_PINGPIO_INOUT_MSK)\
+ |RKPM_SETBITS(pull,RKPM_PINGPIO_PULL,RKPM_PINGPIO_PULL_MSK)\
+ )
+ #define RKPM_PINGPIO_BITS_FUN(pin,pull) (0\
+ |RKPM_SETBITS(pin,RKPM_PINGPIO_PIN,RKPM_PINGPIO_PIN_MSK)\
+ |RKPM_SETBITS(pull,RKPM_PINGPIO_PULL,RKPM_PINGPIO_PULL_MSK)\
+ )
+
+#define RKPM_PINGPIO_BITS_PIN(bits) RKPM_GETBITS(bits,RKPM_PINGPIO_PIN,RKPM_PINGPIO_PIN_MSK)
+#define RKPM_PINGPIO_BITS_LEVEL(bits) RKPM_GETBITS(bits,RKPM_PINGPIO_INOUT,RKPM_PINGPIO_INOUT_MSK)
+#define RKPM_PINGPIO_BITS_PULL(bits) RKPM_GETBITS(bits,RKPM_PINGPIO_PULL,RKPM_PINGPIO_PULL_MSK)
+#define RKPM_PINGPIO_BITS_INOUT(bits) RKPM_GETBITS(bits,RKPM_PINGPIO_LEVEL,RKPM_PINGPIO_LEVEL_MSK)
#endif