void keypress_test(void) { /*following is test code to test ADC & key pad*/ int i; int count = sizeof(g_key_K1_info)/sizeof(struct adckey_info); int nKeyVal = 0; int nCnt = 0; printf("waiting for keypress test..\npress key \'sw3\' 3 times please...\n"); saradc_enable(); while(nCnt < 3) { udelay(KEY_DELAY_US); nKeyVal = get_adc_sample(4); if(nKeyVal > 1000) continue; for(i = 0; i < count; i++){ int v = g_key_K1_info[i].value; if(nKeyVal >= v && nKeyVal <= (v + g_key_K1_info[i].tolerance)){ printf("key:%s pressed.\n",g_key_K1_info[i].key); break; } } if(i >= count) printf("unknown key pressed. keyvalue=%d\n",nKeyVal); nCnt++; for(i = 0; i < 100; i++) udelay(KEY_DELAY_US); } saradc_disable(); }
/*following is test code to test ADC & key pad*/ static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if(argc > 2) goto usage; u32 nDelay = 0xffff; int nKeyVal = 0; int nCnt = 0; char *endp; int nMaxCnt; int adc_chan = 0; //m8 adc channel 0;m6 adc channel 4 if(2 == argc) nMaxCnt = simple_strtoul(argv[1], &endp, 10); else nMaxCnt = 10; saradc_enable(); while(nCnt < nMaxCnt) { udelay(nDelay); nKeyVal = get_adc_sample(adc_chan); if(nKeyVal > 1021) continue; printf("SARADC CH-4 Get key : %d [%d]\n", nKeyVal,(100*nKeyVal)/1024); nCnt++; } saradc_disable(); return 0; usage: return cmd_usage(cmdtp); }
static unsigned int detect_key(unsigned int suspend_from) { int exit_reason = 0; unsigned int time_out = readl(AO_DEBUG_REG2); unsigned time_out_ms = time_out*100; unsigned char adc_key_cnt = 0; unsigned *irq = (unsigned *)WAKEUP_SRC_IRQ_ADDR_BASE; /* unsigned *wakeup_en = (unsigned *)SECURE_TASK_RESPONSE_WAKEUP_EN; */ /* start timer and enable adc*/ reset_ao_timera(); saradc_enable(); /* setup wakeup resources*/ /*auto suspend: timerA 10ms resolution*/ if (time_out_ms != 0) wakeup_timer_setup(); saradc_enable(); reset_ao_timera(); init_remote(); #ifdef CONFIG_CEC_WAKEUP if (hdmi_cec_func_config & 0x1) { remote_cec_hw_reset(); cec_node_init(); } #endif /* *wakeup_en = 1;*/ do { #ifdef CONFIG_CEC_WAKEUP if (irq[IRQ_AO_CEC] == IRQ_AO_CEC_NUM) { irq[IRQ_AO_CEC] = 0xFFFFFFFF; // if (suspend_from == SYS_POWEROFF) // continue; if (cec_msg.log_addr) { if (hdmi_cec_func_config & 0x1) { cec_handler(); if (cec_msg.cec_power == 0x1) { /*cec power key*/ exit_reason = CEC_WAKEUP; break; } } } else if (hdmi_cec_func_config & 0x1) cec_node_init(); } #endif if (irq[IRQ_TIMERA] == IRQ_TIMERA_NUM) { irq[IRQ_TIMERA] = 0xFFFFFFFF; /*uart_puts("timera ...\n");*/ if (time_out_ms != 0) time_out_ms--; if (time_out_ms == 0) { wakeup_timer_clear(); exit_reason = AUTO_WAKEUP; } } if (irq[IRQ_AO_TIMERA] == IRQ_AO_TIMERA_NUM) { irq[IRQ_AO_TIMERA] = 0xFFFFFFFF; if (check_adc_key_resume()) { adc_key_cnt++; /*using variable 'adc_key_cnt' to eliminate the dithering of the key*/ if (2 == adc_key_cnt) exit_reason = POWER_KEY_WAKEUP; } else { adc_key_cnt = 0; } } if (irq[IRQ_AO_IR_DEC] == IRQ_AO_IR_DEC_NUM) { irq[IRQ_AO_IR_DEC] = 0xFFFFFFFF; if (remote_detect_key()) exit_reason = REMOTE_WAKEUP; } if (irq[IRQ_ETH_PHY] == IRQ_ETH_PHY_NUM) { irq[IRQ_ETH_PHY] = 0xFFFFFFFF; exit_reason = ETH_PHY_WAKEUP; } if (exit_reason) break; else asm volatile("wfi"); } while (1); restore_ao_timer(); saradc_disable(); return exit_reason; }