static void button_pressed(struct work_struct *work) { struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct hsd_info *hi = container_of(dwork, struct hsd_info, work_for_key_pressed); struct qpnp_vadc_result result; int acc_read_value = 0; int i, rc; struct ear_3button_info_table *table; int table_size = ARRAY_SIZE(max1462x_ear_3button_type_data); if (hi->gpio_get_value_func(hi->gpio_detect)||(atomic_read(&hi->is_3_pole_or_not))) { HSD_ERR("button_pressed but 4 pole ear jack is plugged out already! just ignore the event.\n"); return; } /* LIMIT: Include ONLY A1, B1, Vu3, Z models used MSM8974 AA/AB */ #ifdef CONFIG_ADC_READY_CHECK_JB rc = qpnp_vadc_read_lge(P_MUX6_1_1,&result); #else /* MUST BE IMPLEMENT : * After MSM8974 AC and later version(PMIC combination change), * ADC AMUX of PMICs are separated in each dual PMIC. * * Ref. * qpnp-adc-voltage.c : *qpnp_get_vadc(), qpnp_vadc_read(). * qpnp-charger.c : new implementation by QCT. */ return; #endif if (rc < 0) { if (rc == -ETIMEDOUT) { pr_err("[DEBUG] button_pressed : adc read timeout \n"); } else { pr_err("button_pressed: adc read error - %d\n", rc); } } acc_read_value = (int)result.physical; pr_info("%s: acc_read_value - %d\n", __func__, acc_read_value); for (i = 0; i < table_size; i++) { table = &max1462x_ear_3button_type_data[i]; /* [AUDIO_BSP] 20130110, junday.lee, * include min value '=' for 1 button earjack (ADC value= 0) */ if ((acc_read_value <= table->PERMISS_REANGE_MAX) && (acc_read_value >= table->PERMISS_REANGE_MIN)) { HSD_DBG("button_pressed \n"); atomic_set(&hi->btn_state, 1); switch(table->ADC_HEADSET_BUTTON){ case KEY_MEDIA : input_report_key(hi->input, KEY_MEDIA, 1); pr_info("%s: KEY_MEDIA \n", __func__); break; case KEY_VOLUMEUP : input_report_key(hi->input, KEY_VOLUMEUP, 1); pr_info("%s: KEY_VOLUMEUP \n", __func__); break; case KEY_VOLUMEDOWN : input_report_key(hi->input, KEY_VOLUMEDOWN, 1); pr_info("%s: KEY_VOLUMDOWN \n", __func__); break; default: break; } table->PRESS_OR_NOT = 1; input_sync(hi->input); break; } } return; }
static int lge_hsd_probe(struct platform_device *pdev) { int ret = 0; struct max1462x_platform_data *pdata = pdev->dev.platform_data; struct hsd_info *hi; HSD_DBG("lge_hsd_probe\n"); hi = kzalloc(sizeof(struct hsd_info), GFP_KERNEL); if ( hi == NULL) { HSD_ERR("Failed to allloate headset per device info\n"); return -ENOMEM; } if(pdev->dev.of_node){ pdata = devm_kzalloc(&pdev->dev,sizeof(struct max1462x_platform_data),GFP_KERNEL); if(!pdata){ HSD_ERR("Failed to allocate memory\n"); return -ENOMEM; } pdev->dev.platform_data = pdata; max1462x_parse_dt(&pdev->dev,pdata); } else { pdata = devm_kzalloc(&pdev->dev,sizeof(struct max1462x_platform_data),GFP_KERNEL); if(!pdata){ HSD_ERR("Failed to allocate memory\n"); return -ENOMEM; } else pdata = pdev->dev.platform_data; } hi->key_code = pdata->key_code; platform_set_drvdata(pdev, hi); atomic_set(&hi->btn_state, 0); atomic_set(&hi->is_3_pole_or_not, 1); atomic_set(&hi->irq_key_enabled, FALSE); hi->gpio_mic_en = pdata->gpio_mic_en; hi->gpio_detect = pdata->gpio_detect; hi->gpio_key = pdata->gpio_key; hi->gpio_set_value_func = pdata->gpio_set_value_func; hi->gpio_get_value_func = pdata->gpio_get_value_func; #ifdef CONFIG_SWITCH_MAX1462X_WA hi->latency_for_key = msecs_to_jiffies(80); #else hi->latency_for_key = msecs_to_jiffies(50); /* convert milli to jiffies */ #endif mutex_init(&hi->mutex_lock); INIT_WORK(&hi->work, detect_work); INIT_DELAYED_WORK(&hi->work_for_key_pressed, button_pressed); INIT_DELAYED_WORK(&hi->work_for_key_released, button_released); ret = gpio_request(hi->gpio_mic_en, "gpio_mic_en"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_request\n", hi->gpio_mic_en); goto error_02; } ret = gpio_direction_output(hi->gpio_mic_en, 0); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_direction_input\n", hi->gpio_mic_en); goto error_02; } HSD_DBG("gpio_get_value_cansleep(hi->gpio_mic_en) = %d\n", gpio_get_value_cansleep(hi->gpio_mic_en)); /* init gpio_detect */ ret = gpio_request(hi->gpio_detect, "gpio_detect"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_det) gpio_request\n", hi->gpio_detect); goto error_03; } ret = gpio_direction_input(hi->gpio_detect); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_det) gpio_direction_input\n", hi->gpio_detect); goto error_03; } /*init gpio_key */ ret = gpio_request(hi->gpio_key, "gpio_key"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_request\n", hi->gpio_key); goto error_04; } ret = gpio_direction_input(hi->gpio_key); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_direction_input\n", hi->gpio_key); goto error_04; } /* initialize irq of gpio_key */ hi->irq_key = gpio_to_irq(hi->gpio_key); HSD_DBG("hi->irq_key = %d\n", hi->irq_key); if (hi->irq_key < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_key; goto error_06; } ret = request_threaded_irq(hi->irq_key, NULL, button_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING|IRQF_ONESHOT, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq\n"); goto error_06; } ret = irq_set_irq_wake(hi->irq_key, 1); if (ret < 0) { HSD_ERR("Failed to set irq_key interrupt wake\n"); goto error_06; } hi->irq_detect = gpio_to_irq(hi->gpio_detect); HSD_DBG("hi->irq_detect = %d\n", hi->irq_detect); if (hi->irq_detect < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_detect; goto error_07; } ret = request_threaded_irq(hi->irq_detect, NULL, earjack_det_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING|IRQF_ONESHOT, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq\n"); goto error_07; } ret = irq_set_irq_wake(hi->irq_detect, 1); if (ret < 0) { HSD_ERR("Failed to set gpio_detect interrupt wake\n"); goto error_07; } /* initialize switch device */ hi->sdev.name = pdata->switch_name; hi->sdev.print_state = lge_hsd_print_state; hi->sdev.print_name = lge_hsd_print_name; ret = switch_dev_register(&hi->sdev); if (ret < 0) { HSD_ERR("Failed to register switch device\n"); goto error_08; } /* initialize input device */ hi->input = input_allocate_device(); if (!hi->input) { HSD_ERR("Failed to allocate input device\n"); ret = -ENOMEM; goto error_09; } hi->input->name = pdata->keypad_name; hi->input->id.vendor = 0x0001; hi->input->id.product = 1; hi->input->id.version = 1; /* headset tx noise */ { struct qpnp_vadc_result result; int acc_read_value = 0; int i, rc = 0; int count = 3; for (i = 0; i < count; i++) { /* LIMIT: Include ONLY A1, B1, Vu3, Z models used MSM8974 AA/AB */ #ifdef CONFIG_ADC_READY_CHECK_JB rc = qpnp_vadc_read_lge(P_MUX6_1_1,&result); #else /* MUST BE IMPLEMENT : * After MSM8974 AC and later version(PMIC combination change), * ADC AMUX of PMICs are separated in each dual PMIC. * * Ref. * qpnp-adc-voltage.c : *qpnp_get_vadc(), qpnp_vadc_read(). * qpnp-charger.c : new implementation by QCT. */ #endif if (rc < 0) { if (rc == -ETIMEDOUT) { pr_err("[DEBUG]adc read timeout \n"); } else { pr_err("[DEBUG]adc read error - %d\n", rc); } } else { acc_read_value = (int)result.physical; pr_info("%s: acc_read_value - %d\n", __func__, (int)result.physical); break; } } } set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(EV_SW, hi->input->evbit); set_bit(hi->key_code, hi->input->keybit); set_bit(SW_HEADPHONE_INSERT, hi->input->swbit); set_bit(SW_MICROPHONE_INSERT, hi->input->swbit); input_set_capability(hi->input, EV_KEY, KEY_MEDIA); input_set_capability(hi->input, EV_KEY, KEY_VOLUMEUP); input_set_capability(hi->input, EV_KEY, KEY_VOLUMEDOWN); ret = input_register_device(hi->input); if (ret) { HSD_ERR("Failed to register input device\n"); goto error_09; } if (!(hi->gpio_get_value_func(hi->gpio_detect))) #ifdef CONFIG_MAX1462X_USE_LOCAL_WORK_QUEUE /* to detect in initialization with eacjack insertion */ queue_work(local_max1462x_workqueue, &(hi->work)); #else /* to detect in initialization with eacjack insertion */ schedule_work(&(hi->work)); #endif return ret; error_09: input_free_device(hi->input); error_08: switch_dev_unregister(&hi->sdev); error_07: free_irq(hi->irq_detect, 0); error_06: free_irq(hi->irq_key, 0); error_04: gpio_free(hi->gpio_key); error_03: gpio_free(hi->gpio_detect); error_02: gpio_free(hi->gpio_mic_en); kfree(hi); return ret; }
static int lge_hsd_probe(struct platform_device *pdev) { int ret = 0; struct max1462x_platform_data *pdata = pdev->dev.platform_data; struct hsd_info *hi; HSD_DBG("lge_hsd_probe\n"); hi = kzalloc(sizeof(struct hsd_info), GFP_KERNEL); if (hi == NULL) { HSD_ERR("Failed to allloate headset per device info\n"); return -ENOMEM; } if (pdev->dev.of_node) { pdata = devm_kzalloc(&pdev->dev, sizeof(struct max1462x_platform_data), GFP_KERNEL); if (!pdata) { HSD_ERR("Failed to allocate memory\n"); return -ENOMEM; } pdev->dev.platform_data = pdata; max1462x_parse_dt(&pdev->dev, pdata); } else { pdata = devm_kzalloc(&pdev->dev, sizeof(struct max1462x_platform_data), GFP_KERNEL); if (!pdata) { HSD_ERR("Failed to allocate memory\n"); return -ENOMEM; } else { pdata = pdev->dev.platform_data; } } hi->key_code = pdata->key_code; platform_set_drvdata(pdev, hi); atomic_set(&hi->btn_state, 0); atomic_set(&hi->is_3_pole_or_not, 1); atomic_set(&hi->irq_key_enabled, FALSE); hi->gpio_mic_en = pdata->gpio_mic_en; hi->gpio_detect = pdata->gpio_detect; hi->gpio_key = pdata->gpio_key; hi->gpio_set_value_func = pdata->gpio_set_value_func; hi->gpio_get_value_func = pdata->gpio_get_value_func; hi->latency_for_key = msecs_to_jiffies(50); /* */ mutex_init(&hi->mutex_lock); INIT_WORK(&hi->work, detect_work); INIT_DELAYED_WORK(&hi->work_for_key_pressed, button_pressed); INIT_DELAYED_WORK(&hi->work_for_key_released, button_released); ret = gpio_request(hi->gpio_mic_en, "gpio_mic_en"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_request\n", hi->gpio_mic_en); goto error_02; } ret = gpio_direction_output(hi->gpio_mic_en, 0); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_direction_input\n", hi->gpio_mic_en); goto error_02; } HSD_DBG("gpio_get_value_cansleep(hi->gpio_mic_en) = %d\n", gpio_get_value_cansleep(hi->gpio_mic_en)); /* */ ret = gpio_request(hi->gpio_detect, "gpio_detect"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_det) gpio_request\n", hi->gpio_detect); goto error_03; } ret = gpio_direction_input(hi->gpio_detect); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_det) gpio_direction_input\n", hi->gpio_detect); goto error_03; } /* */ ret = gpio_request(hi->gpio_key, "gpio_key"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_request\n", hi->gpio_key); goto error_04; } ret = gpio_direction_input(hi->gpio_key); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_direction_input\n", hi->gpio_key); goto error_04; } /* */ hi->irq_key = gpio_to_irq(hi->gpio_key); HSD_DBG("hi->irq_key = %d\n", hi->irq_key); if (hi->irq_key < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_key; goto error_06; } ret = request_threaded_irq(hi->irq_key, NULL, button_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq\n"); goto error_06; } ret = irq_set_irq_wake(hi->irq_key, 1); if (ret < 0) { HSD_ERR("Failed to set irq_key interrupt wake\n"); goto error_06; } hi->irq_detect = gpio_to_irq(hi->gpio_detect); HSD_DBG("hi->irq_detect = %d\n", hi->irq_detect); if (hi->irq_detect < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_detect; goto error_07; } ret = request_threaded_irq(hi->irq_detect, NULL, earjack_det_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq\n"); goto error_07; } ret = irq_set_irq_wake(hi->irq_detect, 1); if (ret < 0) { HSD_ERR("Failed to set gpio_detect interrupt wake\n"); goto error_07; } /* */ hi->sdev.name = pdata->switch_name; hi->sdev.print_state = lge_hsd_print_state; ret = switch_dev_register(&hi->sdev); if (ret < 0) { HSD_ERR("Failed to register switch device\n"); goto error_08; } /* */ hi->input = input_allocate_device(); if (!hi->input) { HSD_ERR("Failed to allocate input device\n"); ret = -ENOMEM; goto error_09; } hi->input->name = pdata->keypad_name; hi->input->id.vendor = 0x0001; hi->input->id.product = 1; hi->input->id.version = 1; set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(EV_SW, hi->input->evbit); set_bit(hi->key_code, hi->input->keybit); set_bit(SW_HEADPHONE_INSERT, hi->input->swbit); set_bit(SW_MICROPHONE_INSERT, hi->input->swbit); input_set_capability(hi->input, EV_KEY, KEY_MEDIA); input_set_capability(hi->input, EV_KEY, KEY_VOLUMEUP); input_set_capability(hi->input, EV_KEY, KEY_VOLUMEDOWN); ret = input_register_device(hi->input); if (ret) { HSD_ERR("Failed to register input device\n"); goto error_09; } if (!(hi->gpio_get_value_func(hi->gpio_detect))) #ifdef CONFIG_MAX1462X_USE_LOCAL_WORK_QUEUE /* */ queue_work(local_max1462x_workqueue, &(hi->work)); #else /* */ schedule_work(&(hi->work)); #endif return ret; error_09: input_free_device(hi->input); error_08: switch_dev_unregister(&hi->sdev); error_07: free_irq(hi->irq_detect, 0); error_06: free_irq(hi->irq_key, 0); error_04: gpio_free(hi->gpio_key); error_03: gpio_free(hi->gpio_detect); error_02: gpio_free(hi->gpio_mic_en); kfree(hi); return ret; }
static int lge_hsd_probe(struct platform_device *pdev) { int ret; struct gpio_switch_platform_data *pdata = pdev->dev.platform_data; HSD_DBG("%s\n", pdata->name); if (!pdata) { HSD_ERR("The platform data is null\n"); return -EBUSY; } hi = kzalloc(sizeof(struct hsd_info), GFP_KERNEL); if (!hi) { HSD_ERR("Failed to allloate headset per device info\n"); return -ENOMEM; } hi->gpio = pdata->gpio; mutex_init(&hi->mutex_lock); hi->sdev.name = pdata->name; hi->sdev.print_state = lge_hsd_print_state; hi->sdev.print_name = lge_hsd_print_name; ret = switch_dev_register(&hi->sdev); if (ret < 0) { HSD_ERR("Failed to register switch device\n"); goto err_switch_dev_register; } hs_detect_work_queue = create_workqueue("hs_detect"); if (hs_detect_work_queue == NULL) { HSD_ERR("Failed to create workqueue\n"); goto err_create_work_queue; } ret = gpio_request(hi->gpio, pdev->name); if (ret < 0) { HSD_ERR("Failed to request gpio%d\n", hi->gpio); goto err_request_detect_gpio; } ret = gpio_direction_input(hi->gpio); if (ret < 0) { HSD_ERR("Failed to set gpio%d as input\n", hi->gpio); goto err_set_detect_gpio; } if (hi->gpio == LGE_HEADSET_DETECT_GPIO) { ret = gpio_tlmm_config(GPIO_CFG(hi->gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE); if (ret < 0) { HSD_ERR("Failed to configure gpio%d tlmm\n", hi->gpio); goto err_set_detect_gpio; } } hi->irq = gpio_to_irq(pdata->gpio); if (hi->irq < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq; goto err_get_irq_num_failed; } ret = request_irq(hi->irq, gpio_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, NULL); if (ret < 0) { HSD_ERR("Failed to request interrupt handler\n"); goto err_request_detect_irq; } ret = irq_set_irq_wake(hi->irq, 1); if (ret < 0) { HSD_ERR("Failed to set interrupt wake\n"); goto err_request_input_dev; } hi->input = input_allocate_device(); if (!hi->input) { HSD_ERR("Failed to allocate input device\n"); ret = -ENOMEM; goto err_request_input_dev; } if (pdev->dev.platform_data) hi->input->name = "7k_headset"; else hi->input->name = "hsd_headset"; hi->input->id.vendor = 0x0001; hi->input->id.product = 1; hi->input->id.version = 1; input_set_capability(hi->input, EV_SW, SW_HEADPHONE_INSERT); ret = input_register_device(hi->input); if (ret) { HSD_ERR("Failed to register input device\n"); goto err_register_input_dev; } /* Perform initial detection */ return 0; err_register_input_dev: input_free_device(hi->input); err_request_input_dev: free_irq(hi->irq, 0); err_request_detect_irq: err_get_irq_num_failed: err_set_detect_gpio: gpio_free(hi->gpio); err_request_detect_gpio: destroy_workqueue(hs_detect_work_queue); err_create_work_queue: switch_dev_unregister(&hi->sdev); err_switch_dev_register: HSD_ERR("Failed to register driver\n"); return ret; }
static void button_pressed(struct work_struct *work) { struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct hsd_info *hi = container_of(dwork, struct hsd_info, work_for_key_pressed); struct qpnp_vadc_result result; int acc_read_value = 0; int i, rc; struct ear_3button_info_table *table; int table_size = ARRAY_SIZE(max1462x_ear_3button_type_data); if (hi->gpio_get_value_func(hi->gpio_detect) || (atomic_read(&hi->is_3_pole_or_not))) { HSD_ERR("button_pressed but 4 pole ear jack is plugged out already! just ignore the event.\n"); return; } rc = qpnp_vadc_read_lge(P_MUX6_1_1,&result); if (rc < 0) { if (rc == -ETIMEDOUT) { pr_err("[DEBUG] button_pressed : adc read timeout \n"); } else { pr_err("button_pressed: adc read error - %d\n", rc); } } acc_read_value = (int)result.physical; pr_info("%s: acc_read_value - %d\n", __func__, acc_read_value); for (i = 0; i < table_size; i++) { table = &max1462x_ear_3button_type_data[i]; /* [AUDIO_BSP] 20130110, junday.lee, * include min value '=' for 1 button earjack (ADC value= 0) */ if ((acc_read_value <= table->PERMISS_REANGE_MAX) && (acc_read_value >= table->PERMISS_REANGE_MIN)) { HSD_DBG("%s: button_pressed and acc_read_value :%d \n ", __func__, acc_read_value); atomic_set(&hi->btn_state, 1); switch (table->ADC_HEADSET_BUTTON) { case KEY_MEDIA: input_report_key(hi->input, KEY_MEDIA, 1); pr_info("%s: KEY_MEDIA \n", __func__); break; case KEY_VOLUMEUP: input_report_key(hi->input, KEY_VOLUMEUP, 1); pr_info("%s: KEY_VOLUMEUP \n", __func__); break; case KEY_VOLUMEDOWN: input_report_key(hi->input, KEY_VOLUMEDOWN, 1); pr_info("%s: KEY_VOLUMDOWN \n", __func__); break; case 582: //KEY_ASSIST input_report_key(hi->input, 582, 1); pr_info("%s: KEY_ASSIST \n", __func__); break; default: break; } table->PRESS_OR_NOT = 1; input_sync(hi->input); break; } } return; }
static int lge_hsd_probe(struct platform_device *pdev) { #ifdef AT_TEST_GPKD int err; #endif int ret = 0; struct fsa8008_platform_data *pdata = pdev->dev.platform_data; struct hsd_info *hi; HSD_DBG("lge_hsd_probe"); hi = kzalloc(sizeof(struct hsd_info), GFP_KERNEL); if (NULL == hi) { HSD_ERR("Failed to allloate headset per device info\n"); return -ENOMEM; } hi->key_code = pdata->key_code; platform_set_drvdata(pdev, hi); atomic_set(&hi->btn_state, 0); atomic_set(&hi->is_3_pole_or_not, 1); hi->gpio_detect = pdata->gpio_detect; hi->gpio_mic_en = pdata->gpio_mic_en; hi->gpio_jpole = pdata->gpio_jpole; hi->gpio_key = pdata->gpio_key; hi->set_headset_mic_bias = pdata->set_headset_mic_bias; hi->latency_for_detection = pdata->latency_for_detection; // hi->latency_for_key = 0; hi->latency_for_key = 200 /* milli */ * HZ / 1000; /* convert milli to jiffies */ mutex_init(&hi->mutex_lock); INIT_DELAYED_WORK(&hi->work, detect_work); INIT_DELAYED_WORK(&hi->work_for_key_pressed, button_pressed); INIT_DELAYED_WORK(&hi->work_for_key_released, button_released); /* initialize gpio_detect */ ret = gpio_request(hi->gpio_detect, "gpio_detect"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_detect) gpio_request\n", hi->gpio_detect); goto error_01; } ret = gpio_direction_input(hi->gpio_detect); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_detect) gpio_direction_input\n", hi->gpio_detect); goto error_02; } /* initialize gpio_jpole */ ret = gpio_request(hi->gpio_jpole, "gpio_jpole"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_jpole) gpio_request\n", hi->gpio_jpole); goto error_02; } ret = gpio_direction_input(hi->gpio_jpole); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_jpole) gpio_direction_input\n", hi->gpio_jpole); goto error_03; } /* initialize gpio_key */ ret = gpio_request(hi->gpio_key, "gpio_key"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_request\n", hi->gpio_key); goto error_03; } ret = gpio_direction_input(hi->gpio_key); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_direction_input\n", hi->gpio_key); goto error_04; } /* initialize gpio_mic_en */ ret = gpio_request(hi->gpio_mic_en, "gpio_mic_en"); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_request\n", hi->gpio_mic_en); goto error_04; } ret = gpio_direction_output(hi->gpio_mic_en, 0); if (ret < 0) { HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_direction_output\n", hi->gpio_mic_en); goto error_05; } /* initialize irq of gpio_jpole */ hi->irq_detect = gpio_to_irq(hi->gpio_detect); HSD_DBG("hi->irq_detect = %d\n", hi->irq_detect); if (hi->irq_detect < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_detect; goto error_05; } ret = request_threaded_irq(hi->irq_detect, NULL, gpio_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq"); goto error_05; } ret = set_irq_wake(hi->irq_detect, 1); if (ret < 0) { HSD_ERR("Failed to set irq_detect interrupt wake\n"); goto error_06; } /* initialize irq of gpio_key */ hi->irq_key = gpio_to_irq(hi->gpio_key); HSD_DBG("hi->irq_key = %d\n", hi->irq_key); if (hi->irq_key < 0) { HSD_ERR("Failed to get interrupt number\n"); ret = hi->irq_key; goto error_06; } ret = request_threaded_irq(hi->irq_key, NULL, button_irq_handler, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi); if (ret) { HSD_ERR("failed to request button irq"); goto error_06; } disable_irq(hi->irq_key); ret = set_irq_wake(hi->irq_key, 1); if (ret < 0) { HSD_ERR("Failed to set irq_key interrupt wake\n"); goto error_07; } /* initialize switch device */ hi->sdev.name = pdata->switch_name; hi->sdev.print_state = lge_hsd_print_state; hi->sdev.print_name = lge_hsd_print_name; ret = switch_dev_register(&hi->sdev); if (ret < 0) { HSD_ERR("Failed to register switch device\n"); goto error_07; } /* initialize input device */ hi->input = input_allocate_device(); if (!hi->input) { HSD_ERR("Failed to allocate input device\n"); ret = -ENOMEM; goto error_08; } hi->input->name = pdata->keypad_name; hi->input->id.vendor = 0x0001; hi->input->id.product = 1; hi->input->id.version = 1; // input_set_capability(hi->input, EV_SW, SW_HEADPHONE_INSERT); set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(hi->key_code, hi->input->keybit); ret = input_register_device(hi->input); if (ret) { HSD_ERR("Failed to register input device\n"); goto error_09; } if (!gpio_get_value_cansleep(hi->gpio_detect)) #ifdef CONFIG_FSA8008_USE_LOCAL_WORK_QUEUE queue_delayed_work(local_fsa8008_workqueue, &(hi->work), 0); /* to detect in initialization with eacjack insertion */ #else schedule_delayed_work(&(hi->work), 0); /* to detect in initialization with eacjack insertion */ #endif #ifdef AT_TEST_GPKD err = device_create_file(&pdev->dev, &dev_attr_hookkeylog); #endif return ret; error_09 : input_free_device(hi->input); error_08 : switch_dev_unregister(&hi->sdev); error_07 : free_irq(hi->irq_key, 0); error_06 : free_irq(hi->irq_detect, 0); error_05 : gpio_free(hi->gpio_mic_en); error_04 : gpio_free(hi->gpio_key); error_03 : gpio_free(hi->gpio_jpole); error_02 : gpio_free(hi->gpio_detect); error_01 : mutex_destroy(&hi->mutex_lock); kfree(hi); return ret; }
static void insert_headset(struct work_struct *work) { struct delayed_work *dwork = container_of(work, struct delayed_work, work); struct hsd_info *hi = container_of(dwork, struct hsd_info, work_for_insert); int earjack_type; int value = gpio_get_value_cansleep(hi->gpio_detect); if(value != EARJACK_INSERTED) { HSD_ERR("insert_headset but actually Fake inserted state!!\n"); return; } else { #ifdef HEADSET_REMOVE_ERROR insert_state_check = 1; #endif // mutex_lock(&hi->mutex_lock); // switch_set_state(&hi->sdev, LGE_HEADSET); // mutex_unlock(&hi->mutex_lock); } HSD_DBG("insert_headset"); if (hi->set_headset_mic_bias) hi->set_headset_mic_bias(TRUE); gpio_set_value_cansleep(hi->gpio_mic_en, 1); msleep(hi->latency_for_detection); // 75 -> 10 ms earjack_type = gpio_get_value_cansleep(hi->gpio_jpole); if (earjack_type == EARJACK_TYPE_3_POLE) { HSD_DBG("3 polarity earjack"); if (hi->set_headset_mic_bias) hi->set_headset_mic_bias(FALSE); atomic_set(&hi->is_3_pole_or_not, 1); mutex_lock(&hi->mutex_lock); switch_set_state(&hi->sdev, LGE_HEADSET_NO_MIC); mutex_unlock(&hi->mutex_lock); input_report_switch(hi->input, SW_HEADPHONE_INSERT, 1); input_sync(hi->input); } else { HSD_DBG("4 polarity earjack"); atomic_set(&hi->is_3_pole_or_not, 0); cancel_delayed_work_sync(&(hi->work_for_key_det_enable)); queue_delayed_work(local_fsa8008_workqueue, &(hi->work_for_key_det_enable), FSA8008_KEY_EN_DELAY_MS ); mutex_lock(&hi->mutex_lock); switch_set_state(&hi->sdev, LGE_HEADSET); mutex_unlock(&hi->mutex_lock); input_report_switch(hi->input, SW_HEADPHONE_INSERT, 1); input_sync(hi->input); // 2012-07-01, [email protected] - to prevent a lost uevent of earjack inserted input_report_switch(hi->input, SW_MICROPHONE_INSERT, 1); input_sync(hi->input); } #ifdef HEADSET_REMOVE_ERROR insert_state_check = 0; #endif }