5 #include <asm/arch/mfp.h>
6 #include <asm/arch/sprd_keypad.h>
7 #include <asm/arch/chip_drv_common_io.h>
9 struct key_map_info * sprd_key_map = 0;
11 void board_keypad_init(void)
13 unsigned int key_type;
15 sprd_key_map = malloc(sizeof(struct key_map_info));
17 if(NULL == sprd_key_map){
18 printf("%s malloc faild\n", __FUNCTION__);
22 sprd_key_map->total_size = ARRAY_SIZE(board_key_map);
23 sprd_key_map->keycode_size = sizeof(board_key_map[0])*2;
24 sprd_key_map->key_map = board_key_map;
25 sprd_key_map->total_row = CONFIG_KEYPAD_ROW_CNT;
26 sprd_key_map->total_col = CONFIG_KEYPAD_COL_CNT;
28 if(sprd_key_map->total_size % sprd_key_map->keycode_size){
29 printf("%s: board_key_map config error, it should be %d aligned\n", __FUNCTION__, sprd_key_map->keycode_size);
33 /* init sprd keypad controller */
34 REG32(REG_AON_APB_APB_EB0) |= BIT_8;
35 REG32(REG_AON_APB_APB_RTC_EB) |= BIT_1;
36 REG32(REG_AON_APB_APB_RST0) |= BIT_8;
38 REG32(REG_AON_APB_APB_RST0) &= ~BIT_8;
40 REG_KPD_INT_CLR = KPD_INT_ALL;
41 REG_KPD_POLARITY = CFG_ROW_POLARITY | CFG_COL_POLARITY;
42 REG_KPD_CLK_DIV_CNT = CFG_CLK_DIV & KPDCLK0_CLK_DIV0;
43 REG_KPD_LONG_KEY_CNT = CONFIG_KEYPAD_LONG_CNT;
44 REG_KPD_DEBOUNCE_CNT = CONFIG_KEYPAD_DEBOUNCE_CNT;//0x8;0x13
45 REG_KPD_CTRL = (7<<8)/*Col0-Col2 Enable*/|(7<<16)/*Row0-Row2 Enable*/;
46 REG_KPD_CTRL |= 1; /*Keypad Enable*/;
49 static char handle_scan_code(unsigned char scan_code)
53 unsigned char * key_map;
56 if(NULL == sprd_key_map){
57 printf("plase call board_keypad_init first\n");
61 key_map_cnt = sprd_key_map->total_size / sprd_key_map->keycode_size;
62 key_map = sprd_key_map->key_map;
64 printf("scan code %d\n", scan_code);
66 for(cnt = 0; cnt<key_map_cnt; cnt++){
68 if(key_map[pos] == scan_code)
69 return key_map[pos + 1];
74 //it can only handle one key now
75 unsigned char board_key_scan(void)
77 uint32_t s_int_status = REG_KPD_INT_RAW_STATUS;
78 uint32_t s_key_status = REG_KPD_KEY_STATUS;
79 uint32_t scan_code = 0;
82 printf("key operation flags is %08x, key %08x\n", REG_KPD_INT_RAW_STATUS, REG_KPD_KEY_STATUS);
84 if((s_int_status & KPD_PRESS_INT0) || (s_int_status & KPD_LONG_KEY_INT0)){
85 scan_code = s_key_status & (KPD1_ROW_CNT | KPD1_COL_CNT);
86 key_code += handle_scan_code(scan_code);
87 } if((s_int_status & KPD_PRESS_INT1) || (s_int_status & KPD_LONG_KEY_INT1)){
88 scan_code = (s_key_status & (KPD2_ROW_CNT | KPD2_COL_CNT))>>8;
89 key_code += handle_scan_code(scan_code);
90 }if((s_int_status & KPD_PRESS_INT2) || (s_int_status & KPD_LONG_KEY_INT2)){
91 scan_code = (s_key_status & (KPD3_ROW_CNT | KPD3_COL_CNT))>>16;
92 key_code += handle_scan_code(scan_code);
93 }if((s_int_status & KPD_PRESS_INT3) || (s_int_status & KPD_LONG_KEY_INT3)){
94 scan_code = (s_key_status & (KPD4_ROW_CNT | KPD4_COL_CNT))>>24;
95 key_code += handle_scan_code(scan_code);
99 REG_KPD_INT_CLR = KPD_INT_ALL;
103 unsigned int check_key_boot(unsigned char key)
105 if(KEY_VOLUMEUP == key)
106 return BOOT_CALIBRATE;
107 else if(KEY_HOME == key)
108 return BOOT_FASTBOOT;
109 else if(KEY_VOLUMEDOWN== key)
110 return BOOT_RECOVERY;