static void insert_headset(void) { unsigned int hook_irq = -1; if(gpio_get_value(hs_data->lineout_gpio) == 0 && (project_info == TEGRA3_PROJECT_ME301T || project_info == TEGRA3_PROJECT_ME301TL) ){ printk("%s: debug board\n", __func__); debugboard_alive = true; tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA0, TEGRA_TRI_NORMAL); gpio_direction_output(UART_HEADPHONE_SWITCH, 0); switch_set_state(&hs_data->sdev, NO_DEVICE); /* disable irq and irq_wake to avoid system can't suspend */ disable_irq(hs_data->irq); disable_irq_wake(hs_data->irq); hook_irq = TEGRA_GPIO_TO_IRQ(HOOK_GPIO); enable_irq(hook_irq); hs_micbias_power(ON); }else if(gpio_get_value(HOOK_GPIO) /*|| (factory_mode && (force_headphone == FORCE_HEADPHONE))*/ ){ printk("%s: headphone\n", __func__); switch_set_state(&hs_data->sdev, HEADSET_WITHOUT_MIC); hs_micbias_power(OFF); if(project_info == TEGRA3_PROJECT_ME570T){ if(console_disable) gpio_direction_output(UART_HEADPHONE_SWITCH, 1); else gpio_direction_output(UART_HEADPHONE_SWITCH, 0); } if(project_info == TEGRA3_PROJECT_ME301T || project_info == TEGRA3_PROJECT_ME301TL) { gpio_direction_output(UART_HEADPHONE_SWITCH, 1); tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA0, TEGRA_TRI_TRISTATE); } headset_alive = false; }else{ printk("%s: headset\n", __func__); switch_set_state(&hs_data->sdev, HEADSET_WITH_MIC); hs_micbias_power(ON); if(project_info == TEGRA3_PROJECT_ME570T){ if(console_disable) gpio_direction_output(UART_HEADPHONE_SWITCH, 1); else gpio_direction_output(UART_HEADPHONE_SWITCH, 0); } if(project_info == TEGRA3_PROJECT_ME301T || project_info == TEGRA3_PROJECT_ME301TL) { gpio_direction_output(UART_HEADPHONE_SWITCH, 1); tegra_pinmux_set_tristate(TEGRA_PINGROUP_ULPI_DATA0, TEGRA_TRI_TRISTATE); } headset_alive = true; } hs_data->debouncing_time = ktime_set(0, 20000000); /* 20 ms */ }
/********************************************************** ** Function: Jack detection-in gpio configuration function ** Parameter: none ** Return value: if sucess, then returns 0 ** ************************************************************/ static int jack_config_gpio() { int ret; printk("HEADSET: Config Jack-in detection gpio\n"); hs_micbias_power(ON); tegra_gpio_enable(JACK_GPIO); ret = gpio_request(JACK_GPIO, "h2w_detect"); ret = gpio_direction_input(JACK_GPIO); hs_data->irq = gpio_to_irq(JACK_GPIO); ret = request_irq(hs_data->irq, detect_irq_handler, IRQF_TRIGGER_FALLING|IRQF_TRIGGER_RISING, "h2w_detect", NULL); ret = irq_set_irq_wake(hs_data->irq, 1); msleep(1); if (gpio_get_value(JACK_GPIO) == 0){ insert_headset(); }else { hs_micbias_power(OFF); headset_alive = false; remove_headset(); } return 0; }
static void detection_work(struct work_struct *work) { unsigned long irq_flags; int cable_in1; int mic_in = 0; wake_lock(&hp_detect_wakelock); hs_micbias_power(ON); isHpDetecting = true; /* Disable headset interrupt while detecting.*/ local_irq_save(irq_flags); disable_irq(hs_data->irq); local_irq_restore(irq_flags); /* Delay 1000ms for pin stable. */ msleep(1000); /* Restore IRQs */ local_irq_save(irq_flags); enable_irq(hs_data->irq); local_irq_restore(irq_flags); if (gpio_get_value(JACK_GPIO) != 0) { /* Headset not plugged in */ if (switch_get_state(&hs_data->sdev) == HEADSET_WITH_MIC || switch_get_state(&hs_data->sdev) == HEADSET_WITHOUT_MIC) remove_headset(); goto closed_micbias; } cable_in1 = gpio_get_value(JACK_GPIO); mic_in = gpio_get_value(HOOK_GPIO); if (cable_in1 == 0) { printk("HOOK_GPIO value: %d\n", mic_in); if(switch_get_state(&hs_data->sdev) == NO_DEVICE) insert_headset(); else if ( mic_in == 1) goto closed_micbias; } else{ printk("HEADSET: Jack-in GPIO is low, but not a headset \n"); goto closed_micbias; } isHpDetecting = false; wake_unlock(&hp_detect_wakelock); return; closed_micbias: isHpDetecting = false; hs_micbias_power(OFF); wake_unlock(&hp_detect_wakelock); return; }
static void insert_headset(void) { if(gpio_get_value(HOOK_GPIO) || (factory_mode && (force_headphone == FORCE_HEADPHONE))){ printk("%s: headphone\n", __func__); switch_set_state(&hs_data->sdev, HEADSET_WITHOUT_MIC); hs_micbias_power(OFF); headset_alive = false; }else{ printk("%s: headset\n", __func__); switch_set_state(&hs_data->sdev, HEADSET_WITH_MIC); hs_micbias_power(ON); headset_alive = true; } hs_data->debouncing_time = ktime_set(0, 20000000); /* 20 ms */ }
/********************************************************** ** Function: Jack detection-in gpio configuration function ** Parameter: none ** Return value: if sucess, then returns 0 ** ************************************************************/ static int jack_config_gpio() { int ret; printk("HEADSET: Config Jack-in detection gpio\n"); hs_micbias_power(ON); ret = gpio_request(JACK_GPIO, "h2w_detect"); ret = gpio_direction_input(JACK_GPIO); hs_data->irq = gpio_to_irq(JACK_GPIO); ret = request_irq(hs_data->irq, detect_irq_handler, IRQF_TRIGGER_FALLING|IRQF_TRIGGER_RISING, "h2w_detect", NULL); ret = irq_set_irq_wake(hs_data->irq, 1); switch (project_info) { case TEGRA3_PROJECT_TF201: case TEGRA3_PROJECT_TF300T: case TEGRA3_PROJECT_TF300TG: case TEGRA3_PROJECT_TF300TL: case TEGRA3_PROJECT_TF500T: case TEGRA3_PROJECT_TF700T: case TEGRA3_PROJECT_ME301T: case TEGRA3_PROJECT_ME301TL: /* delay 100ms to wait hook_det stable */ msleep(100); break; case TEGRA3_PROJECT_P1801: /* delay 230ms to wait hook_det stable */ msleep(230); break; default: /* delay 100ms to wait hook_det stable */ msleep(100); break; } if (gpio_get_value(JACK_GPIO) == 0){ insert_headset(); }else { hs_micbias_power(OFF); headset_alive = false; switch_set_state(&hs_data->sdev, NO_DEVICE); remove_headset(); } return 0; }
int check_hs_type(void) { if(jack_alive){ hs_micbias_power(0); hs_micbias_power(1); } msleep(100); /* For No Mic dongle */ if(!gpio_get_value(JACK_GPIO)){ if (gpio_get_value(HOOK_GPIO)){ printk("HEADSET: No mic headset\n"); return 0; }else{ printk("HEADSET: With mic headset\n"); return 1; } }else{ printk("HEADSET: No headset plug-in\n"); return 0; } }