/********************************************************** ** Function: Headset driver init function ** Parameter: none ** Return value: none ** ************************************************************/ static int __init headset_init(void) { printk(KERN_INFO "%s+ #####\n", __func__); int ret; printk("HEADSET: Headset detection init\n"); hs_data = kzalloc(sizeof(struct headset_data), GFP_KERNEL); if (!hs_data) return -ENOMEM; hs_data->debouncing_time = ktime_set(0, 100000000); /* 100 ms */ hs_data->sdev.name = "h2w"; hs_data->sdev.print_name = headset_name_show; hs_data->sdev.print_state = headset_state_show; ret = switch_dev_register(&hs_data->sdev); if (ret < 0) goto err_switch_dev_register; g_detection_work_queue = create_workqueue("detection"); hrtimer_init(&hs_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hs_data->timer.function = detect_event_timer_func; printk("HEADSET: Headset detection mode\n"); btn_config_gpio();/*Config hook detection GPIO*/ jack_config_gpio();/*Config jack detection GPIO*/ INIT_WORK(&lineout_work, lineout_work_queue); lineout_config_gpio(); printk(KERN_INFO "%s- #####\n", __func__); return 0; err_switch_dev_register: printk(KERN_ERR "Headset: Failed to register driver\n"); return ret; }
/********************************************************** ** Function: Headset driver init function ** Parameter: none ** Return value: none ** ************************************************************/ static int __init headset_init(void) { int ret = 0; printk(KERN_INFO "%s+ #####\n", __func__); hs_data = kzalloc(sizeof(struct headset_data), GFP_KERNEL); if (!hs_data) return -ENOMEM; hs_data->hook_det_gpio = HS_HOOK_DET; hs_data->hp_det_gpio = JACK_GPIO; hs_data->debouncing_time = ktime_set(0, 100000000); /* 100 ms */ hs_data->btn_debouncing_time = ktime_set(0, 10000000); hs_data->sdev.name = "h2w"; hs_data->sdev.print_name = headset_name_show; hs_data->sdev.print_state = headset_state_show; hs_data->btn_ignore = false; hs_data->btn_pressed = false; ret = switch_dev_register(&hs_data->sdev); if (ret < 0) { printk(KERN_ERR "Headset: Failed to register driver\n"); goto err_switch_dev_register; } g_detection_work_queue = create_workqueue("detection"); g_button_press_work_queue = create_workqueue("button_press"); g_button_release_work_queue = create_workqueue("button_release"); INIT_WORK(&g_button_press_works[0], button_press_work); INIT_WORK(&g_button_press_works[1], button_press_work); INIT_WORK(&g_button_release_works[0], button_release_work); INIT_WORK(&g_button_release_works[1], button_release_work); hrtimer_init(&hs_data->btn_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hs_data->btn_timer.function = button_event_timer_func; hs_data->input = input_allocate_device(); if (!hs_data->input) { printk(KERN_ERR "Headset: Failed to request input device\n"); ret = -ENOMEM; goto err_input_dev_request; } hs_data->input->name = "h2w button"; set_bit(EV_SYN, hs_data->input->evbit); set_bit(EV_KEY, hs_data->input->evbit); set_bit(KEY_MEDIA, hs_data->input->keybit); ret = input_register_device(hs_data->input); if (ret < 0) { printk(KERN_ERR "Headset: Failed to register input device\n"); goto err_input_dev_register; } ret = btn_config_gpio(); if (ret < 0) printk(KERN_ERR "Headst: Failed to config button gpio\n"); printk(KERN_INFO "HEADSET: Headset detection mode\n"); jack_config_gpio();/*Config jack detection GPIO*/ printk(KERN_INFO "%s- #####\n", __func__); return 0; err_input_dev_register: input_free_device(hs_data->input); err_input_dev_request: switch_dev_unregister(&hs_data->sdev); err_switch_dev_register: kfree(hs_data); return ret; }
/********************************************************** ** Function: Headset driver init function ** Parameter: none ** Return value: none ** ************************************************************/ static int __init headset_init(void) { int ret; printk(KERN_INFO "%s+ #####\n", __func__); printk("HEADSET: Headset detection init\n"); console_disable = is_tegra_debug_uartport_hs(); project_info = tegra3_get_project_id(); hs_data = kzalloc(sizeof(struct headset_data), GFP_KERNEL); if (!hs_data) return -ENOMEM; hs_data->debouncing_time = ktime_set(0, 100000000); /* 100 ms */ hs_data->sdev.name = "h2w"; hs_data->sdev.print_name = headset_name_show; hs_data->sdev.print_state = headset_state_show; hs_data->ldev.name = "lineout"; hs_data->ldev.print_name = lineout_name_show; hs_data->ldev.print_state = lineout_state_show; ret = switch_dev_register(&hs_data->sdev); if (ret < 0) goto err_switch_dev_register; ret = switch_dev_register(&hs_data->ldev); if (ret < 0) goto err_switch_dev_register; g_detection_work_queue = create_workqueue("detection"); hrtimer_init(&hs_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hs_data->timer.function = detect_event_timer_func; printk("HEADSET: Headset detection mode\n"); btn_config_gpio();/*Config hook detection GPIO*/ if(project_info == TEGRA3_PROJECT_ME301T || project_info == TEGRA3_PROJECT_ME301TL || project_info == TEGRA3_PROJECT_ME570T) switch_config_gpio(); /*Config uart and headphone switch*/ wake_lock_init(&hp_detect_wakelock, WAKE_LOCK_SUSPEND, "headset detection"); INIT_WORK(&lineout_work, lineout_work_queue); if (project_info == TEGRA3_PROJECT_ME301T || project_info == TEGRA3_PROJECT_ME301TL) INIT_WORK(&hook_work, hook_work_queue); 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: hs_data->lineout_gpio = LINEOUT_GPIO; lineout_config_gpio(); break; case TEGRA3_PROJECT_ME301T: hs_data->lineout_gpio = LINEOUT_ME301T; lineout_config_no_dock(); break; default: hs_data->lineout_gpio = LINEOUT_GPIO; lineout_config_gpio(); break; } jack_config_gpio();/*Config jack detection GPIO*/ printk(KERN_INFO "%s- #####\n", __func__); return 0; err_switch_dev_register: printk(KERN_ERR "Headset: Failed to register driver\n"); return ret; }