拨码开关的调试
平台 mtk 6572 kaios
硬件原理图中引脚为 KROW6_EINT14-> GPIO100中断是下降沿触发
DrvGen中设置GPIO100的 Def.Mode为 EINT14
1、kaios_72_normal\vendor\mediatek\proprietary\scripts\dct\EINT_YuSu.cmp
[EINT_variables]
KEY_LOCK
2、DrvGen中EINT Setting栏
设置 EINT Var Debounce Time(ms) Polarity Sensitive_Level Debounce En
EINT14 KEY_LOCK 256 LOW Level Enable
3、DrvGen中 Een code 在目标文件中找到生成的 cust_eint.h
查看cust_eint.h会发现
#define CUST_EINT_KEY_LOCK_NUM 14
#define CUST_EINT_KEY_LOCK_DEBOUNCE_CN 256
#define CUST_EINT_KEY_LOCK_POLARITY CUST_EINT_POLARITY_LOW
#define CUST_EINT_KEY_LOCK_SENSITIVE CUST_EINT_LEVEL_SENSITIVE
#define CUST_EINT_KEY_LOCK_DEBOUNCE_EN CUST_EINT_DEBOUNCE_ENABLE
4、Q:\kaios_72_normal\kernel-3.4\include\linux\input.h
#define KEYMAP_LOCK_F1 249
#define KEYMAP_LOCK_F2 250
5、Q:\kaios_72_normal\kernel-3.4\drivers\misc\mediatek\keypad\kpd.c
struct work_struct keymap_lock_eint_work;
static int keymap_lock_state_flag = 0;
static bool keymap_lock_state = 1; //0: close 1:far
#define keymap_lock_gpio GPIO100
static volatile int keymap_lock_status = 0;
static ssize_t store_keymap_lock_state(struct device_driver *ddri, const char *buf, size_t count)
{
if (sscanf(buf, "%u", &keymap_lock_status) != 1) {
kpd_print("kpd call state: Invalid values\n");
return -EINVAL;
}
keymap_lock_state = (bool)keymap_lock_status;
return count;
}
static ssize_t show_keymap_lock_state(struct device_driver *ddri, char *buf)
{
ssize_t res;
res = snprintf(buf, PAGE_SIZE, "%d\n", keymap_lock_state);
return res;
}
static DRIVER_ATTR(keymap_lock_state, S_IWUSR | S_IALLUGO, show_keymap_lock_state, store_keymap_lock_state);
static struct driver_attribute *kpd_attr_list[] = {
&driver_attr_kpd_call_state,
#ifdef CUSTOM_HALL_SUPPORT
&driver_attr_hall_state,
#endif
&driver_attr_keymap_lock_state,
}
static int kpd_create_attr(struct device_driver *driver)
{
int num = (int)(sizeof(kpd_attr_list)/sizeof(kpd_attr_list[0]));
for(idx = 0; idx < num; idx++)
{
if((err = driver_create_file(driver, kpd_attr_list[idx])))
{
kpd_print("driver_create_file (%s) = %d\n", kpd_attr_list[idx]->attr.name, err);
break;
}
}
}
void keymap_lock_key_handler(unsigned long pressed, u16 linux_keycode)
{
if(!kpd_input_dev) {
printk("KPD input device not ready\n");
return;
}
input_report_key(kpd_input_dev, linux_keycode, pressed);
input_sync(kpd_input_dev);
if (kpd_show_hw_keycode) {
printk(KPD_SAY "(%s) keymap_lock keycode =%d \n",
pressed ? "pressed" : "released", linux_keycode);
}
}
static void keymap_lock_work_func(struct work_struct *work)
{
printk("key keymap_lock_work_func not ready\n");
if(keymap_lock_state == 1) {
keymap_lock_key_handler(1, KEYMAP_LOCK_F1);
keymap_lock_key_handler(0, KEYMAP_LOCK_F1);
}
else if(keymap_lock_state == 0) {
keymap_lock_key_handler(1, KEYMAP_LOCK_F2);
keymap_lock_key_handler(0, KEYMAP_LOCK_F2);
}
}
void keymap_lock_eint_func(void)
{
mt_eint_mask(CUST_EINT_KEY_LOCK_NUM);
if(keymap_lock_state_flag)
{
keymap_lock_state_flag = 0;
keymap_lock_state = 1;
mt_eint_set_polarity(CUST_EINT_KEY_LOCK_NUM, CUST_EINT_POLARITY_LOW);
/*if(0 == hall_suspend)
{
mt_eint_unmask(CUST_EINT_HALL_NUM);
return;
}*/
}
else
{
keymap_lock_state_flag = 1;
keymap_lock_state = 0;
mt_eint_set_polarity(CUST_EINT_KEY_LOCK_NUM, CUST_EINT_POLARITY_HIGH);
/*if(1 == hall_suspend)
{
mt_eint_unmask(CUST_EINT_HALL_NUM);
return;
}*/
}
mt_eint_unmask(CUST_EINT_KEY_LOCK_NUM);
schedule_work(&keymap_lock_eint_work);
}
int keymap_lock_setup_eint(void)
{
mt_set_gpio_dir(keymap_lock_gpio, GPIO_DIR_OUT);
mt_set_gpio_mode(keymap_lock_gpio, GPIO_MODE_04);
mt_set_gpio_pull_enable(keymap_lock_gpio, 0);
mt_eint_registration(CUST_EINT_KEY_LOCK_NUM, EINTF_TRIGGER_LOW, keymap_lock_eint_func, 0);
mt_eint_unmask(CUST_EINT_KEY_LOCK_NUM);
return 0;
}
static int kpd_pdrv_probe(struct platform_device *pdev)
{
__set_bit(KEYMAP_LOCK_F1, kpd_input_dev->keybit);//pangjw add keymap_lock
__set_bit(KEYMAP_LOCK_F2, kpd_input_dev->keybit);//pangjw add keymap_lock
r = input_register_device(kpd_input_dev);
INIT_WORK(&keymap_lock_eint_work, keymap_lock_work_func);//pangjw add keymap_lock
keymap_lock_setup_eint();//pangjw add keymap_lock
}