static int htc_headset_mgr_probe(struct platform_device *pdev) { int ret; struct htc_headset_mgr_platform_data *pdata = pdev->dev.platform_data; HS_LOG("++++++++++++++++++++"); hi = kzalloc(sizeof(struct htc_headset_mgr_info), GFP_KERNEL); if (!hi) return -ENOMEM; hi->pdata.driver_flag = pdata->driver_flag; hi->pdata.headset_devices_num = pdata->headset_devices_num; hi->pdata.headset_devices = pdata->headset_devices; hi->pdata.headset_config_num = pdata->headset_config_num; hi->pdata.headset_config = pdata->headset_config; hi->pdata.hptv_det_hp_gpio = pdata->hptv_det_hp_gpio; hi->pdata.hptv_det_tv_gpio = pdata->hptv_det_tv_gpio; hi->pdata.hptv_sel_gpio = pdata->hptv_sel_gpio; hi->pdata.headset_init = pdata->headset_init; hi->pdata.headset_power = pdata->headset_power; if (hi->pdata.headset_init) hi->pdata.headset_init(); hi->driver_init_seq = 0; hi->early_suspend.suspend = htc_headset_mgr_early_suspend; hi->early_suspend.resume = htc_headset_mgr_late_resume; register_early_suspend(&hi->early_suspend); wake_lock_init(&hi->hs_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME); hi->hpin_jiffies = jiffies; hi->usb_headset.type = USB_NO_HEADSET; hi->usb_headset.status = STATUS_DISCONNECTED; hi->hs_35mm_type = HEADSET_UNPLUG; hi->h2w_35mm_type = HEADSET_UNPLUG; hi->is_ext_insert = 0; hi->mic_bias_state = 0; hi->mic_detect_counter = 0; hi->key_level_flag = -1; hi->quick_boot_status = 0; atomic_set(&hi->btn_state, 0); hi->tty_enable_flag = 0; hi->fm_flag = 0; hi->debug_flag = 0; mutex_init(&hi->mutex_lock); hi->sdev_h2w.name = "h2w"; hi->sdev_h2w.print_name = h2w_print_name; ret = switch_dev_register(&hi->sdev_h2w); if (ret < 0) goto err_h2w_switch_dev_register; hi->sdev_usb_audio.name = "usb_audio"; hi->sdev_usb_audio.print_name = usb_audio_print_name; ret = switch_dev_register(&hi->sdev_usb_audio); if (ret < 0) goto err_usb_audio_switch_dev_register; detect_wq = create_workqueue("detect"); if (detect_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create detect workqueue"); goto err_create_detect_work_queue; } button_wq = create_workqueue("button"); if (button_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create button workqueue"); goto err_create_button_work_queue; } hi->input = input_allocate_device(); if (!hi->input) { ret = -ENOMEM; goto err_request_input_dev; } hi->input->name = "h2w headset"; set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(KEY_END, hi->input->keybit); set_bit(KEY_MUTE, hi->input->keybit); set_bit(KEY_VOLUMEDOWN, hi->input->keybit); set_bit(KEY_VOLUMEUP, hi->input->keybit); set_bit(KEY_NEXTSONG, hi->input->keybit); set_bit(KEY_PLAYPAUSE, hi->input->keybit); set_bit(KEY_PREVIOUSSONG, hi->input->keybit); set_bit(KEY_MEDIA, hi->input->keybit); set_bit(KEY_SEND, hi->input->keybit); ret = input_register_device(hi->input); if (ret < 0) goto err_register_input_dev; ret = register_attributes(); if (ret) goto err_register_attributes; #ifdef HTC_HEADSET_CONFIG_MSM_RPC if (hi->pdata.driver_flag & DRIVER_HS_MGR_RPC_SERVER) { /* Create RPC server */ ret = msm_rpc_create_server(&hs_rpc_server); if (ret < 0) { HS_ERR("Failed to create RPC server"); goto err_create_rpc_server; } HS_LOG("Create RPC server successfully"); } #else HS_DBG("NOT support RPC (%du, %du)", hs_rpc_server.prog, hs_rpc_server.vers); #endif headset_mgr_init(); hs_notify_driver_ready(DRIVER_NAME); HS_LOG("--------------------"); return 0; #ifdef HTC_HEADSET_CONFIG_MSM_RPC err_create_rpc_server: #endif err_register_attributes: input_unregister_device(hi->input); err_register_input_dev: input_free_device(hi->input); err_request_input_dev: destroy_workqueue(button_wq); err_create_button_work_queue: destroy_workqueue(detect_wq); err_create_detect_work_queue: switch_dev_unregister(&hi->sdev_usb_audio); err_usb_audio_switch_dev_register: switch_dev_unregister(&hi->sdev_h2w); err_h2w_switch_dev_register: mutex_destroy(&hi->mutex_lock); wake_lock_destroy(&hi->hs_wake_lock); kfree(hi); HS_ERR("Failed to register %s driver", DRIVER_NAME); return ret; }
static int htc_headset_mgr_probe(struct platform_device *pdev) { int ret,i; struct htc_headset_mgr_platform_data *pdata = pdev->dev.platform_data; HS_LOG("++++++++++++++++++++"); hi = kzalloc(sizeof(struct htc_headset_mgr_info), GFP_KERNEL); if (!hi) return -ENOMEM; hi->pdata.eng_cfg = pdata->eng_cfg; hi->pdata.driver_flag = pdata->driver_flag; hi->pdata.headset_devices_num = pdata->headset_devices_num; hi->pdata.headset_devices = pdata->headset_devices; hi->pdata.headset_config_num = pdata->headset_config_num; hi->pdata.headset_config = pdata->headset_config; hi->pdata.headset_config_1wire_num = pdata->headset_config_1wire_num; hi->pdata.headset_config_1wire = pdata->headset_config_1wire; hi->pdata.tx_1wire_gpio = pdata->tx_1wire_gpio; hi->pdata.rx_1wire_gpio = pdata->rx_1wire_gpio; hi->pdata.level_1wire_gpio = pdata->level_1wire_gpio; hi->pdata.enable_1wire = pdata->enable_1wire; strncpy(hi->pdata.dev_1wire, pdata->dev_1wire, UART_DEV_NAME_LEN); hi->pdata.hptv_det_hp_gpio = pdata->hptv_det_hp_gpio; hi->pdata.hptv_det_tv_gpio = pdata->hptv_det_tv_gpio; hi->pdata.hptv_sel_gpio = pdata->hptv_sel_gpio; hi->pdata.headset_init = pdata->headset_init; hi->pdata.headset_power = pdata->headset_power; if (hi->pdata.headset_init) hi->pdata.headset_init(); hi->driver_init_seq = 0; hi->early_suspend.suspend = htc_headset_mgr_early_suspend; hi->early_suspend.resume = htc_headset_mgr_late_resume; register_early_suspend(&hi->early_suspend); wake_lock_init(&hi->hs_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME); hi->hpin_jiffies = jiffies; hi->usb_headset.type = USB_NO_HEADSET; hi->usb_headset.status = STATUS_DISCONNECTED; hi->detect_type = HEADSET_ADC; hi->hs_35mm_type = HEADSET_UNPLUG; hi->h2w_35mm_type = HEADSET_UNPLUG; hi->is_ext_insert = 0; hi->mic_bias_state = 0; hi->mic_detect_counter = 0; hi->key_level_flag = -1; hi->quick_boot_status = 0; atomic_set(&hi->btn_state, 0); hi->tty_enable_flag = 0; hi->fm_flag = 0; hi->debug_flag = 0; mutex_init(&hi->mutex_lock); hi->sdev.name = "h2w"; hi->sdev.print_name = h2w_print_name; for (i=0;i<HS_BUTTON_EVENT_QUEUE;i++){ key_event[i] = kzalloc(sizeof(struct button_work), GFP_KERNEL); if (!key_event[i]) { HS_ERR("Failed to allocate button memory"); return -ENOMEM; } } key_event_flag = -1; ret = switch_dev_register(&hi->sdev); if (ret < 0) goto err_switch_dev_register; detect_wq = create_workqueue("detect"); if (detect_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create detect workqueue"); goto err_create_detect_work_queue; } button_wq = create_workqueue("button"); if (button_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create button workqueue"); goto err_create_button_work_queue; } hi->input = input_allocate_device(); if (!hi->input) { ret = -ENOMEM; goto err_request_input_dev; } hi->input->name = "h2w headset"; set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(KEY_END, hi->input->keybit); set_bit(KEY_MUTE, hi->input->keybit); set_bit(KEY_VOLUMEDOWN, hi->input->keybit); set_bit(KEY_VOLUMEUP, hi->input->keybit); set_bit(KEY_NEXTSONG, hi->input->keybit); set_bit(KEY_PLAYPAUSE, hi->input->keybit); set_bit(KEY_PREVIOUSSONG, hi->input->keybit); set_bit(KEY_MEDIA, hi->input->keybit); set_bit(KEY_SEND, hi->input->keybit); ret = input_register_device(hi->input); if (ret < 0) goto err_register_input_dev; ret = register_attributes(); if (ret) goto err_register_attributes; if (hi->pdata.driver_flag & DRIVER_HS_MGR_RPC_SERVER) { /* Create RPC server */ /* FIXME */ /* ret = msm_rpc_create_server(&hs_rpc_server); */ ret = -1; if (ret < 0) { HS_ERR("Failed to create RPC server"); goto err_create_rpc_server; } HS_LOG("Create RPC server successfully"); } headset_mgr_init(); hs_notify_driver_ready(DRIVER_NAME); HS_LOG("--------------------"); return 0; err_create_rpc_server: err_register_attributes: input_unregister_device(hi->input); err_register_input_dev: input_free_device(hi->input); err_request_input_dev: destroy_workqueue(button_wq); err_create_button_work_queue: destroy_workqueue(detect_wq); err_create_detect_work_queue: switch_dev_unregister(&hi->sdev); err_switch_dev_register: mutex_destroy(&hi->mutex_lock); wake_lock_destroy(&hi->hs_wake_lock); kfree(hi); HS_ERR("Failed to register %s driver", DRIVER_NAME); return ret; }
static int htc_headset_mgr_probe(struct platform_device *pdev) { int ret; struct htc_headset_mgr_platform_data *pdata = pdev->dev.platform_data; HS_LOG("++++++++++++++++++++"); hi = kzalloc(sizeof(struct htc_headset_mgr_info), GFP_KERNEL); if (!hi) return -ENOMEM; hi->pdata.driver_flag = pdata->driver_flag; hi->pdata.headset_devices_num = pdata->headset_devices_num; hi->pdata.headset_devices = pdata->headset_devices; hi->driver_init_seq = 0; wake_lock_init(&hi->hs_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME); hi->hpin_jiffies = jiffies; hi->usb_headset.type = USB_NO_HEADSET; hi->usb_headset.status = STATUS_DISCONNECTED; hi->ext_35mm_status = HTC_35MM_UNPLUG; hi->h2w_35mm_status = HTC_35MM_UNPLUG; hi->is_ext_insert = 0; hi->mic_bias_state = 0; hi->mic_detect_counter = 0; hi->key_level_flag = -1; atomic_set(&hi->btn_state, 0); hi->tty_enable_flag = 0; hi->fm_flag = 0; hi->debug_flag = 0; mutex_init(&hi->mutex_lock); hi->sdev.name = "h2w"; hi->sdev.print_name = h2w_print_name; ret = switch_dev_register(&hi->sdev); if (ret < 0) goto err_switch_dev_register; detect_wq = create_workqueue("detect"); if (detect_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create detect workqueue"); goto err_create_detect_work_queue; } button_wq = create_workqueue("button"); if (button_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create button workqueue"); goto err_create_button_work_queue; } hi->input = input_allocate_device(); if (!hi->input) { ret = -ENOMEM; goto err_request_input_dev; } hi->input->name = "h2w headset"; set_bit(EV_SYN, hi->input->evbit); set_bit(EV_KEY, hi->input->evbit); set_bit(KEY_END, hi->input->keybit); set_bit(KEY_MUTE, hi->input->keybit); set_bit(KEY_VOLUMEDOWN, hi->input->keybit); set_bit(KEY_VOLUMEUP, hi->input->keybit); set_bit(KEY_NEXTSONG, hi->input->keybit); set_bit(KEY_PLAYPAUSE, hi->input->keybit); set_bit(KEY_PREVIOUSSONG, hi->input->keybit); set_bit(KEY_MEDIA, hi->input->keybit); set_bit(KEY_SEND, hi->input->keybit); ret = input_register_device(hi->input); if (ret < 0) goto err_register_input_dev; ret = register_attributes(); if (ret) goto err_register_attributes; if (hi->pdata.driver_flag & DRIVER_HS_MGR_RPC_SERVER) { /* Create RPC server */ ret = msm_rpc_create_server(&hs_rpc_server); if (ret < 0) { HS_ERR("Failed to create RPC server"); goto err_create_rpc_server; } HS_LOG("Create RPC server successfully"); } hs_notify_driver_ready(DRIVER_NAME); HS_LOG("--------------------"); return 0; err_create_rpc_server: err_register_attributes: input_unregister_device(hi->input); err_register_input_dev: input_free_device(hi->input); err_request_input_dev: destroy_workqueue(button_wq); err_create_button_work_queue: destroy_workqueue(detect_wq); err_create_detect_work_queue: switch_dev_unregister(&hi->sdev); err_switch_dev_register: mutex_destroy(&hi->mutex_lock); wake_lock_destroy(&hi->hs_wake_lock); kfree(hi); HS_ERR("Failed to register %s driver", DRIVER_NAME); return ret; }
int server_example_init(void) { return register_attributes(); }
static int htc_headset_pmic_probe(struct platform_device *pdev) { int ret = 0; struct htc_headset_pmic_platform_data *pdata = pdev->dev.platform_data; #ifdef HTC_HEADSET_CONFIG_MSM_RPC uint32_t vers = 0; #endif HS_LOG("++++++++++++++++++++"); hi = kzalloc(sizeof(struct htc_35mm_pmic_info), GFP_KERNEL); if (!hi) return -ENOMEM; hi->pdata.driver_flag = pdata->driver_flag; hi->pdata.hpin_gpio = pdata->hpin_gpio; hi->pdata.hpin_irq = pdata->hpin_irq; hi->pdata.key_gpio = pdata->key_gpio; hi->pdata.key_irq = pdata->key_irq; hi->pdata.key_enable_gpio = pdata->key_enable_gpio; hi->pdata.adc_mpp = pdata->adc_mpp; hi->pdata.adc_amux = pdata->adc_amux; hi->pdata.hs_controller = pdata->hs_controller; hi->pdata.hs_switch = pdata->hs_switch; hi->pdata.adc_mic = pdata->adc_mic; hi->htc_accessory_class = hs_get_attribute_class(); register_attributes(); if (!hi->pdata.adc_mic) hi->pdata.adc_mic = HS_DEF_MIC_ADC_16_BIT_MIN; if (pdata->adc_mic_bias[0] && pdata->adc_mic_bias[1]) { memcpy(hi->pdata.adc_mic_bias, pdata->adc_mic_bias, sizeof(hi->pdata.adc_mic_bias)); hi->pdata.adc_mic = hi->pdata.adc_mic_bias[0]; } else { hi->pdata.adc_mic_bias[0] = hi->pdata.adc_mic; hi->pdata.adc_mic_bias[1] = HS_DEF_MIC_ADC_16_BIT_MAX; } if (pdata->adc_remote[5]) memcpy(hi->pdata.adc_remote, pdata->adc_remote, sizeof(hi->pdata.adc_remote)); if (pdata->adc_metrico[0] && pdata->adc_metrico[1]) memcpy(hi->pdata.adc_metrico, pdata->adc_metrico, sizeof(hi->pdata.adc_metrico)); hi->hpin_irq_type = IRQF_TRIGGER_NONE; hi->hpin_debounce = HS_JIFFIES_ZERO; hi->key_irq_type = IRQF_TRIGGER_NONE; wake_lock_init(&hi->hs_wake_lock, WAKE_LOCK_SUSPEND, DRIVER_NAME); detect_wq = create_workqueue("HS_PMIC_DETECT"); if (detect_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create detect workqueue"); goto err_create_detect_work_queue; } button_wq = create_workqueue("HS_PMIC_BUTTON"); if (button_wq == NULL) { ret = -ENOMEM; HS_ERR("Failed to create button workqueue"); goto err_create_button_work_queue; } if (hi->pdata.hpin_gpio) { ret = hs_pmic_request_irq(hi->pdata.hpin_gpio, &hi->pdata.hpin_irq, detect_irq_handler, hi->hpin_irq_type, "HS_PMIC_DETECT", 1); if (ret < 0) { HS_ERR("Failed to request PMIC HPIN IRQ (0x%X)", ret); goto err_request_detect_irq; } disable_irq(hi->pdata.hpin_irq); } if (hi->pdata.key_gpio) { ret = hs_pmic_request_irq(hi->pdata.key_gpio, &hi->pdata.key_irq, button_irq_handler, hi->key_irq_type, "HS_PMIC_BUTTON", 1); if (ret < 0) { HS_ERR("Failed to request PMIC button IRQ (0x%X)", ret); goto err_request_button_irq; } disable_irq(hi->pdata.key_irq); } #ifdef HTC_HEADSET_CONFIG_MSM_RPC if (hi->pdata.driver_flag & DRIVER_HS_PMIC_RPC_KEY) { /* Register ADC RPC client */ endpoint_adc = msm_rpc_connect(HS_RPC_CLIENT_PROG, HS_RPC_CLIENT_VERS, 0); if (IS_ERR(endpoint_adc)) { hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_RPC_KEY; HS_LOG("Failed to register ADC RPC client"); } else HS_LOG("Register ADC RPC client successfully"); } if (hi->pdata.driver_flag & DRIVER_HS_PMIC_DYNAMIC_THRESHOLD) { /* Register threshold RPC client */ vers = HS_PMIC_RPC_CLIENT_VERS_3_1; endpoint_current = msm_rpc_connect_compatible( HS_PMIC_RPC_CLIENT_PROG, vers, 0); if (!endpoint_current) { vers = HS_PMIC_RPC_CLIENT_VERS_2_1; endpoint_current = msm_rpc_connect( HS_PMIC_RPC_CLIENT_PROG, vers, 0); } if (!endpoint_current) { vers = HS_PMIC_RPC_CLIENT_VERS_1_1; endpoint_current = msm_rpc_connect( HS_PMIC_RPC_CLIENT_PROG, vers, 0); } if (!endpoint_current) { vers = HS_PMIC_RPC_CLIENT_VERS; endpoint_current = msm_rpc_connect( HS_PMIC_RPC_CLIENT_PROG, vers, 0); } if (IS_ERR(endpoint_current)) { hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_DYNAMIC_THRESHOLD; HS_LOG("Failed to register threshold RPC client"); } else HS_LOG("Register threshold RPC client successfully" " (0x%X)", vers); } #else hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_RPC_KEY; hi->pdata.driver_flag &= ~DRIVER_HS_PMIC_DYNAMIC_THRESHOLD; #endif queue_delayed_work(detect_wq, &irq_init_work, HS_JIFFIES_IRQ_INIT); hs_pmic_register(); hs_notify_driver_ready(DRIVER_NAME); HS_LOG("--------------------"); return 0; err_request_button_irq: if (hi->pdata.hpin_gpio) { free_irq(hi->pdata.hpin_irq, 0); gpio_free(hi->pdata.hpin_gpio); } err_request_detect_irq: destroy_workqueue(button_wq); err_create_button_work_queue: destroy_workqueue(detect_wq); err_create_detect_work_queue: wake_lock_destroy(&hi->hs_wake_lock); kfree(hi); HS_ERR("Failed to register %s driver", DRIVER_NAME); return ret; }