5 #include <asm/arch/mfp.h>
6 #include <asm/arch/sprd_keypad.h>
7 #include <asm/arch/chip_drv_common_io.h>
8 #include <asm/arch/sprd_eic.h>
10 struct key_map_info * sprd_key_map = 0;
12 void board_keypad_init(void)
14 unsigned int key_type;
16 sprd_key_map = malloc(sizeof(struct key_map_info));
18 if(NULL == sprd_key_map){
19 printf("%s malloc faild\n", __FUNCTION__);
23 sprd_key_map->total_size = ARRAY_SIZE(board_key_map);
24 sprd_key_map->keycode_size = sizeof(board_key_map[0])*2;
25 sprd_key_map->key_map = board_key_map;
26 sprd_key_map->total_row = CONFIG_KEYPAD_ROW_CNT;
27 sprd_key_map->total_col = CONFIG_KEYPAD_COL_CNT;
29 if(sprd_key_map->total_size % sprd_key_map->keycode_size){
30 printf("%s: board_key_map config error, it should be %d aligned\n", __FUNCTION__, sprd_key_map->keycode_size);
34 /* init sprd keypad controller */
35 REG32(REG_AON_APB_APB_EB0) |= BIT_8;
36 REG32(REG_AON_APB_APB_RTC_EB) |= BIT_1;
37 REG32(REG_AON_APB_APB_RST0) |= BIT_8;
39 REG32(REG_AON_APB_APB_RST0) &= ~BIT_8;
41 REG_KPD_INT_CLR = KPD_INT_ALL;
42 REG_KPD_POLARITY = CFG_ROW_POLARITY | CFG_COL_POLARITY;
43 REG_KPD_CLK_DIV_CNT = CFG_CLK_DIV & KPDCLK0_CLK_DIV0;
44 REG_KPD_LONG_KEY_CNT = CONFIG_KEYPAD_LONG_CNT;
45 REG_KPD_DEBOUNCE_CNT = CONFIG_KEYPAD_DEBOUNCE_CNT;//0x8;0x13
46 REG_KPD_CTRL = (7<<8)/*Col0-Col2 Enable*/|(7<<16)/*Row0-Row2 Enable*/;
47 REG_KPD_CTRL |= 1; /*Keypad Enable*/;
50 static char handle_scan_code(unsigned char scan_code)
54 unsigned char * key_map;
57 if(NULL == sprd_key_map){
58 printf("plase call board_keypad_init first\n");
62 key_map_cnt = sprd_key_map->total_size / sprd_key_map->keycode_size;
63 key_map = sprd_key_map->key_map;
65 printf("scan code %d\n", scan_code);
67 for(cnt = 0; cnt<key_map_cnt; cnt++){
69 if(key_map[pos] == scan_code)
70 return key_map[pos + 1];
75 //it can only handle one key now
76 unsigned char board_key_scan(void)
78 uint32_t s_int_status = REG_KPD_INT_RAW_STATUS;
79 uint32_t s_key_status = REG_KPD_KEY_STATUS;
80 uint32_t scan_code = 0;
83 printf("key operation flags is %08x, key %08x\n", REG_KPD_INT_RAW_STATUS, REG_KPD_KEY_STATUS);
85 if((s_int_status & KPD_PRESS_INT0) || (s_int_status & KPD_LONG_KEY_INT0)){
86 scan_code = s_key_status & (KPD1_ROW_CNT | KPD1_COL_CNT);
87 key_code += handle_scan_code(scan_code);
88 } if((s_int_status & KPD_PRESS_INT1) || (s_int_status & KPD_LONG_KEY_INT1)){
89 scan_code = (s_key_status & (KPD2_ROW_CNT | KPD2_COL_CNT))>>8;
90 key_code += handle_scan_code(scan_code);
91 }if((s_int_status & KPD_PRESS_INT2) || (s_int_status & KPD_LONG_KEY_INT2)){
92 scan_code = (s_key_status & (KPD3_ROW_CNT | KPD3_COL_CNT))>>16;
93 key_code += handle_scan_code(scan_code);
94 }if((s_int_status & KPD_PRESS_INT3) || (s_int_status & KPD_LONG_KEY_INT3)){
95 scan_code = (s_key_status & (KPD4_ROW_CNT | KPD4_COL_CNT))>>24;
96 key_code += handle_scan_code(scan_code);
100 REG_KPD_INT_CLR = KPD_INT_ALL;
102 /*Adie EIC10 as Key_Volumeup*/
104 sprd_eic_request(EIC_KEY2_7S_RST_EXT_RSTN_ACTIVE);
106 volumeup = sprd_eic_get(EIC_KEY2_7S_RST_EXT_RSTN_ACTIVE);
108 printf("[eic keys] volumeup : sprd_eic_get return ERROR!\n");
111 key_code = KEY_VOLUMEUP;
112 printf("[eic keys] volumeup pressed!\n");
118 unsigned int check_key_boot(unsigned char key)
120 if(KEY_VOLUMEUP == key)
121 return BOOT_CALIBRATE;
122 else if(KEY_HOME == key)
123 return BOOT_FASTBOOT;
124 else if(KEY_VOLUMEDOWN== key)
125 return BOOT_RECOVERY;