void __init sec_init_battery(void)
{
	cable_nb.notifier_call = muic_notify;
	cable_accessory_nb.notifier_call = muic_accessory_notify;

	if (use_ab8505_iddet) {
		micro_usb_register_usb_notifier(&cable_nb);
		micro_usb_register_notifier(&cable_accessory_nb);
	} else
		usb_switch_register_notify(&cable_nb);

	platform_device_register(&sec_device_battery);
}
void __init sec_init_battery(void)
{
	cable_nb.notifier_call = muic_notify;
	cable_accessory_nb.notifier_call = muic_accessory_notify;

	if (board_id < 0x103) {
		battery_info.resis_high = 100000;
		battery_info.resis_low = 64000;
	}

	if (use_ab8505_iddet) {
		micro_usb_register_usb_notifier(&cable_nb);
		micro_usb_register_notifier(&cable_accessory_nb);
	} else
		usb_switch_register_notify(&cable_nb);

	platform_device_register(&sec_device_battery);
}
Esempio n. 3
0
static int pm800_headset_switch_probe(struct platform_device *pdev)
{
	struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
	struct pm800_headset_info *info;
	struct gpio_switch_platform_data *pdata_headset = pdev->dev.platform_data;
	struct headset_switch_data *switch_data_headset = NULL;
	struct pm80x_platform_data *pm80x_pdata;
	int irq_headset, irq_hook, ret = 0;
#if 1 //KSND
	struct class *audio;
	struct device *earjack;
#endif

	if (pdev->dev.parent->platform_data) {
		pm80x_pdata = pdev->dev.parent->platform_data;
	} else {
		pr_debug("Invalid pm800 platform data!\n");
		return -EINVAL;
	}
	if (!pm80x_pdata->headset) {
		dev_err(&pdev->dev, "No headset platform info!\n");
		return -EINVAL;
	}
	if (pdata_headset == NULL) {
		pr_debug("Invalid gpio switch platform data!\n");
		return -EBUSY;
	}
	irq_headset = platform_get_irq(pdev, 0);
	if (irq_headset < 0) {
		dev_err(&pdev->dev, "No IRQ resource for headset!\n");
		return -EINVAL;
	}
	irq_hook = platform_get_irq(pdev, 1);
	if (irq_hook < 0) {
		dev_err(&pdev->dev, "No IRQ resource for hook/mic!\n");
		return -EINVAL;
	}
	info =
	    devm_kzalloc(&pdev->dev, sizeof(struct pm800_headset_info),
			 GFP_KERNEL);
	if (!info)
		return -ENOMEM;

	info->pdata = pm80x_pdata->headset; //KSND

	info->chip = chip;
	info->mic_set_power = pm80x_pdata->headset->mic_set_power;
	info->headset_flag = pm80x_pdata->headset->headset_flag;
	info->map = chip->regmap;
	info->map_gpadc = chip->subchip->regmap_gpadc;
	info->dev = &pdev->dev;
	info->irq_headset = irq_headset + chip->irq_base;
	info->irq_hook = irq_hook + chip->irq_base;

	info->idev = input_allocate_device();
	if (!info->idev) {
		dev_err(&pdev->dev, "Failed to allocate input dev\n");
		ret = -ENOMEM;
		goto input_allocate_fail;
	}

	info->idev->name = "88pm800_hook_vol";
	info->idev->phys = "88pm800_hook_vol/input0";
	info->idev->id.bustype = BUS_I2C;
	info->idev->dev.parent = &pdev->dev;

	__set_bit(EV_KEY, info->idev->evbit);
	__set_bit(KEY_MEDIA, info->idev->keybit);
	__set_bit(KEY_VOLUMEUP, info->idev->keybit);
	__set_bit(KEY_VOLUMEDOWN, info->idev->keybit);
	info->hook_vol_status = HOOK_VOL_ALL_RELEASED;

	switch_data_headset =
	    devm_kzalloc(&pdev->dev, sizeof(struct headset_switch_data),
			 GFP_KERNEL);
	if (!switch_data_headset) {
		dev_err(&pdev->dev, "Failed to allocate headset data\n");
		ret = -ENOMEM;
		goto headset_allocate_fail;
	}

	switch_data_headset->sdev.name = pdata_headset->name;
	switch_data_headset->name_on = pdata_headset->name_on;
	switch_data_headset->name_off = pdata_headset->name_off;
	switch_data_headset->state_on = pdata_headset->state_on;
	switch_data_headset->state_off = pdata_headset->state_off;
	switch_data_headset->sdev.print_state = switch_headset_print_state;
	info->psw_data_headset = switch_data_headset;

	ret = switch_dev_register(&switch_data_headset->sdev);
	if (ret < 0)
		goto err_switch_dev_register;

	
#ifdef FET_EN_CONTROL //KSND
		if(system_rev < LT02_R0_3){
			info->gpio_fet_en = mfp_to_gpio(GPIO008_GPIO_8);
		
			if( gpio_request(info->gpio_fet_en,"FET EN CTRL") ){
				gpio_free(info->gpio_fet_en);
				pr_info("%s: FET_EN CTRL Request Fail!!\n", __func__);
			}
			gpio_direction_output(info->gpio_fet_en, 0 );
		}
#endif /* FET_EN_CONTROL */
	
#ifdef COM_DET_CONTROL 
		info->gpio_com = mfp_to_gpio(GPIO012_GPIO_12);
	
		if( gpio_request(info->gpio_com,"COM_DET CTRL") ){
			gpio_free(info->gpio_com);
			pr_info("%s: COM_DET CTRL Request Fail!!\n", __func__);
		}
		gpio_direction_input(info->gpio_com);
#endif /* COM_DET_CONTROL */
	
#ifdef HP_MUTE_CONTROL
		if(system_rev < LT02_R0_2){
			info->gpio_hp_mute = mfp_to_gpio(GPIO031_GPIO_31);
		
			if( gpio_request(info->gpio_hp_mute,"HP_MUTE CTRL") ){
				gpio_free(info->gpio_hp_mute);
				pr_info("%s: HP_MUTE CTRL Request Fail!!\n", __func__);
			}
			gpio_direction_output(info->gpio_hp_mute, 0 );
		}
#endif

	mutex_init(&info->hs_mutex);
#ifdef COM_DET_CONTROL //KSND
	/* com detection irq initialization(only rising edge detect) - ffkaka */
	info->irq_com = gpio_to_irq(info->gpio_com);
	ret = 
		request_threaded_irq(info->irq_com,NULL,pm800_jack_com_det_irq_thread,
		IRQF_ONESHOT|IRQF_TRIGGER_RISING, "headset com detect", info);
	if (ret < 0) {
		pr_info( "[headset] Failed to request IRQ com detect : #%d: %d\n",
			info->irq_com, ret);
		goto out_irq_com;
	}
	disable_irq(info->irq_com);
#endif

	ret =
	    request_threaded_irq(info->irq_headset, NULL, pm800_jack_detect_irq_thread,
				 IRQF_ONESHOT, "headset", info);
	if (ret < 0) {
		dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
			info->irq_headset, ret);
		goto out_irq_headset;
	}

	ret =
	    request_threaded_irq(info->irq_hook, NULL, pm800_jack_buttons_irq_thread,
				 IRQF_ONESHOT, "hook", info);
	if (ret < 0) {
		dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
			info->irq_hook, ret);
		goto out_irq_hook;
	}
	
	voice_call_enable = 0;
	if (info->proc_file == NULL) {
		info->proc_file =
			create_proc_entry(PM800_HEADSET_PROC_FILE, 0644, NULL);
		if (info->proc_file) {
			info->proc_file->read_proc = pm800_headset_proc_read;
			info->proc_file->write_proc = (write_proc_t  *)pm800_headset_proc_write;
			info->proc_file->data = info;
		} else
			pr_info("pm800 headset proc file create failed!\n");
	}

#if 1 //KSND
	audio = class_create(THIS_MODULE, "audio");
	if (IS_ERR(audio))
		pr_err("Failed to create class(audio)!\n");

	earjack = device_create(audio, NULL, 0, NULL, "earjack");
	if (IS_ERR(earjack))
		pr_err("Failed to create device(earjack)!\n");

	ret = device_create_file(earjack, &dev_attr_key_state);
	if (ret)
		pr_err("Failed to create device file in sysfs entries!\n");

	ret = device_create_file(earjack, &dev_attr_state);
	if (ret)
		pr_err("Failed to create device file in sysfs entries!\n");
    
	ret = device_create_file(earjack, &dev_attr_select_jack);
	if (ret)
		pr_err("Failed to create device file in sysfs entries(%s)!\n", dev_attr_select_jack.attr.name);
#endif

	/* Initialize timer for detecting loop */
	setup_timer(&info->headset_timer,pm800_jack_timer_handler,(unsigned long)info);

  /* Init Timer for Button Release */ //KSND
	setup_timer(&info->button_timer,pm800_button_timer_handler,(unsigned 	long)info); 

	/*
	 * disable hook irq to ensure this irq will be enabled
	 * after plugging in headset
	 */
	info->hook_count = 1;
	pm800_hook_int(info, 0);
	ret = input_register_device(info->idev);
	if (ret < 0)
		goto err_input_dev_register;

	platform_set_drvdata(pdev, info);
	INIT_WORK(&info->work_headset, pm800_jack_det_work);
	INIT_WORK(&info->work_hook, pm800_jack_buttons_work);
	INIT_WORK(&info->work_release, pm800_hook_release_work);
	hsdetect_dev = &pdev->dev;
	hs_detect.hsdetect_status = 0;
	hs_detect.hookswitch_status = 0;
	/* default 4_POLES */
	hs_detect.hsmic_status = PM8XXX_HS_MIC_ADD;

	/* Pointer for handling info in this driver KSND */
	local_info = info;

	/* Hook:32 ms debounce time */
	regmap_update_bits(info->map, PM800_MIC_CNTRL, MIC_DET_DBS,
			   MIC_DET_DBS_32MS);
	/* Hook:256ms period duty cycle */
	regmap_update_bits(info->map, PM800_MIC_CNTRL, MIC_DET_PRD,
			   MIC_DET_PRD_CTN_256MS);
	/* set GPADC_DIR to 1, set to 0 cause pop noise in recording */
	regmap_update_bits(info->map_gpadc, PM800_GPADC_MISC_CONFIG1,
			   PM800_GPADC4_DIR, PM800_GPADC4_DIR);
	/* enable headset detection on GPIO3 */
	regmap_update_bits(info->map, PM800_HEADSET_CNTRL, PM800_HEADSET_DET_EN,
			   PM800_HEADSET_DET_EN);
	pm800_jack_det_work(&info->work_headset);

	dev_set_drvdata(earjack, info);  //KSND  

#if defined(CONFIG_MACH_LT02) || defined(CONFIG_MACH_COCOA7)
	usb_switch_register_notify(&dock_nb);
#endif

	return 0;

out_irq_hook:	
	free_irq(info->irq_hook, info);
out_irq_headset:
	free_irq(info->irq_headset, info);
#ifdef COM_DET_CONTROL
out_irq_com:
	free_irq(info->irq_com,info);
#endif
err_input_dev_register:
	input_free_device(info->idev);
err_switch_dev_register:
	switch_dev_unregister(&switch_data_headset->sdev);
headset_allocate_fail:
	devm_kfree(&pdev->dev, switch_data_headset);
input_allocate_fail:
	devm_kfree(&pdev->dev, info);
	return ret;
}