Beispiel #1
0
static int gpio_event_probe(struct platform_device *pdev)
{
	int err;
	struct gpio_event *ip;
	struct gpio_event_platform_data *event_info;
	int dev_count = 1;
	int i;
	int registered = 0;

	event_info = pdev->dev.platform_data;
	if (event_info == NULL) {
		pr_err("gpio_event_probe: No pdata\n");
		return -ENODEV;
	}
	if ((!event_info->name && !event_info->names[0]) ||
	    !event_info->info || !event_info->info_count) {
		pr_err("gpio_event_probe: Incomplete pdata\n");
		return -ENODEV;
	}
	if (!event_info->name)
		while (event_info->names[dev_count])
			dev_count++;
	ip = kzalloc(sizeof(*ip) +
		     sizeof(ip->state[0]) * event_info->info_count +
		     sizeof(*ip->input_devs) +
		     sizeof(ip->input_devs->dev[0]) * dev_count, GFP_KERNEL);
	if (ip == NULL) {
		err = -ENOMEM;
		pr_err("gpio_event_probe: Failed to allocate private data\n");
		goto err_kp_alloc_failed;
	}
	ip->input_devs = (void*)&ip->state[event_info->info_count];
	platform_set_drvdata(pdev, ip);

	for (i = 0; i < dev_count; i++) {
		struct input_dev *input_dev = input_allocate_device();
		if (input_dev == NULL) {
			err = -ENOMEM;
			pr_err("gpio_event_probe: "
				"Failed to allocate input device\n");
			goto err_input_dev_alloc_failed;
		}
		input_set_drvdata(input_dev, ip);
		input_dev->name = event_info->name ?
					event_info->name : event_info->names[i];
		input_dev->event = gpio_input_event;
		ip->input_devs->dev[i] = input_dev;
#ifdef CONFIG_TOUCHSCREEN_CYPRESS_SWEEP2WAKE
		if (!strcmp(input_dev->name, "vigor-keypad")) {
			sweep2wake_setdev(input_dev);
			printk(KERN_INFO "[sweep2wake]: set device %s\n", input_dev->name);
		}
#endif
	}
	ip->input_devs->count = dev_count;
	ip->info = event_info;
	if (event_info->power) {
#ifdef CONFIG_HAS_EARLYSUSPEND
		ip->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
		ip->early_suspend.suspend = gpio_event_suspend;
		ip->early_suspend.resume = gpio_event_resume;
		register_early_suspend(&ip->early_suspend);
#endif
		ip->info->power(ip->info, 1);
	}

	err = gpio_event_call_all_func(ip, GPIO_EVENT_FUNC_INIT);
	if (err)
		goto err_call_all_func_failed;

	for (i = 0; i < dev_count; i++) {
		err = input_register_device(ip->input_devs->dev[i]);
		if (err) {
			pr_err("gpio_event_probe: Unable to register %s "
				"input device\n", ip->input_devs->dev[i]->name);
			goto err_input_register_device_failed;
		}
		registered++;
	}

	return 0;

err_input_register_device_failed:
	gpio_event_call_all_func(ip, GPIO_EVENT_FUNC_UNINIT);
err_call_all_func_failed:
	if (event_info->power) {
#ifdef CONFIG_HAS_EARLYSUSPEND
		unregister_early_suspend(&ip->early_suspend);
#endif
		ip->info->power(ip->info, 0);
	}
	for (i = 0; i < registered; i++)
		input_unregister_device(ip->input_devs->dev[i]);
	for (i = dev_count - 1; i >= registered; i--) {
		input_free_device(ip->input_devs->dev[i]);
err_input_dev_alloc_failed:
		;
	}
	kfree(ip);
err_kp_alloc_failed:
	return err;
}
Beispiel #2
0
/*
 * lkkbd_connect() probes for a LK keyboard and fills the necessary structures.
 */
static int lkkbd_connect(struct serio *serio, struct serio_driver *drv)
{
	struct lkkbd *lk;
	struct input_dev *input_dev;
	int i;
	int err;

	lk = kzalloc(sizeof(struct lkkbd), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!lk || !input_dev) {
		err = -ENOMEM;
		goto fail1;
	}

	lk->serio = serio;
	lk->dev = input_dev;
	INIT_WORK(&lk->tq, lkkbd_reinit);
	lk->bell_volume = bell_volume;
	lk->keyclick_volume = keyclick_volume;
	lk->ctrlclick_volume = ctrlclick_volume;
	memcpy(lk->keycode, lkkbd_keycode, sizeof(lk->keycode));

	strlcpy(lk->name, "DEC LK keyboard", sizeof(lk->name));
	snprintf(lk->phys, sizeof(lk->phys), "%s/input0", serio->phys);

	input_dev->name = lk->name;
	input_dev->phys = lk->phys;
	input_dev->id.bustype = BUS_RS232;
	input_dev->id.vendor = SERIO_LKKBD;
	input_dev->id.product = 0;
	input_dev->id.version = 0x0100;
	input_dev->dev.parent = &serio->dev;
	input_dev->event = lkkbd_event;

	input_set_drvdata(input_dev, lk);

	__set_bit(EV_KEY, input_dev->evbit);
	__set_bit(EV_LED, input_dev->evbit);
	__set_bit(EV_SND, input_dev->evbit);
	__set_bit(EV_REP, input_dev->evbit);
	__set_bit(LED_CAPSL, input_dev->ledbit);
	__set_bit(LED_SLEEP, input_dev->ledbit);
	__set_bit(LED_COMPOSE, input_dev->ledbit);
	__set_bit(LED_SCROLLL, input_dev->ledbit);
	__set_bit(SND_BELL, input_dev->sndbit);
	__set_bit(SND_CLICK, input_dev->sndbit);

	input_dev->keycode = lk->keycode;
	input_dev->keycodesize = sizeof(lk->keycode[0]);
	input_dev->keycodemax = ARRAY_SIZE(lk->keycode);

	for (i = 0; i < LK_NUM_KEYCODES; i++)
		__set_bit(lk->keycode[i], input_dev->keybit);
	__clear_bit(KEY_RESERVED, input_dev->keybit);

	serio_set_drvdata(serio, lk);

	err = serio_open(serio, drv);
	if (err)
		goto fail2;

	err = input_register_device(lk->dev);
	if (err)
		goto fail3;

	serio_write(lk->serio, LK_CMD_POWERCYCLE_RESET);

	return 0;

 fail3:	serio_close(serio);
 fail2:	serio_set_drvdata(serio, NULL);
 fail1:	input_free_device(input_dev);
	kfree(lk);
	return err;
}
Beispiel #3
0
static int __devinit adp5520_keys_probe(struct platform_device *pdev)
{
	struct adp5520_keys_platform_data *pdata = pdev->dev.platform_data;
	struct input_dev *input;
	struct adp5520_keys *dev;
	int ret, i;
	unsigned char en_mask, ctl_mask = 0;

	if (pdev->id != ID_ADP5520) {
		dev_err(&pdev->dev, "only ADP5520 supports Keypad\n");
		return -EINVAL;
	}

	if (pdata == NULL) {
		dev_err(&pdev->dev, "missing platform data\n");
		return -EINVAL;
	}

	if (!(pdata->rows_en_mask && pdata->cols_en_mask))
		return -EINVAL;

	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (dev == NULL) {
		dev_err(&pdev->dev, "failed to alloc memory\n");
		return -ENOMEM;
	}

	input = input_allocate_device();
	if (!input) {
		ret = -ENOMEM;
		goto err;
	}

	dev->master = pdev->dev.parent;
	dev->input = input;

	input->name = pdev->name;
	input->phys = "adp5520-keys/input0";
	input->dev.parent = &pdev->dev;

	input_set_drvdata(input, dev);

	input->id.bustype = BUS_I2C;
	input->id.vendor = 0x0001;
	input->id.product = 0x5520;
	input->id.version = 0x0001;

	input->keycodesize = sizeof(dev->keycode[0]);
	input->keycodemax = pdata->keymapsize;
	input->keycode = dev->keycode;

	memcpy(dev->keycode, pdata->keymap,
		pdata->keymapsize * input->keycodesize);

	/* setup input device */
	__set_bit(EV_KEY, input->evbit);

	if (pdata->repeat)
		__set_bit(EV_REP, input->evbit);

	for (i = 0; i < input->keycodemax; i++)
		__set_bit(dev->keycode[i], input->keybit);
	__clear_bit(KEY_RESERVED, input->keybit);

	ret = input_register_device(input);
	if (ret) {
		dev_err(&pdev->dev, "unable to register input device\n");
		goto err;
	}

	en_mask = pdata->rows_en_mask | pdata->cols_en_mask;

	ret = adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_1, en_mask);

	if (en_mask & ADP5520_COL_C3)
		ctl_mask |= ADP5520_C3_MODE;

	if (en_mask & ADP5520_ROW_R3)
		ctl_mask |= ADP5520_R3_MODE;

	if (ctl_mask)
		ret |= adp5520_set_bits(dev->master, ADP5520_LED_CONTROL,
			ctl_mask);

	ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP,
		pdata->rows_en_mask);

	if (ret) {
		dev_err(&pdev->dev, "failed to write\n");
		ret = -EIO;
		goto err1;
	}

	dev->notifier.notifier_call = adp5520_keys_notifier;
	ret = adp5520_register_notifier(dev->master, &dev->notifier,
			ADP5520_KP_IEN | ADP5520_KR_IEN);
	if (ret) {
		dev_err(&pdev->dev, "failed to register notifier\n");
		goto err1;
	}

	platform_set_drvdata(pdev, dev);
	return 0;

err1:
	input_unregister_device(input);
	input = NULL;
err:
	input_free_device(input);
	kfree(dev);
	return ret;
}
Beispiel #4
0
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_keys_drvdata *ddata;
	struct device *dev = &pdev->dev;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;

	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
			pdata->nbuttons * sizeof(struct gpio_button_data),
			GFP_KERNEL);
	input = input_allocate_device();
	if (!ddata || !input) {
		dev_err(dev, "failed to allocate state\n");
		error = -ENOMEM;
		goto fail1;
	}

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
	mutex_init(&ddata->disable_lock);

	platform_set_drvdata(pdev, ddata);
	input_set_drvdata(input, ddata);

	input->name = pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

	input->id.bustype = BUS_HOST;
	input->id.vendor = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0100;

	/* Enable auto repeat feature of Linux input subsystem */
	if (pdata->rep)
		__set_bit(EV_REP, input->evbit);

	for (i = 0; i < pdata->nbuttons; i++) {
		struct gpio_keys_button *button = &pdata->buttons[i];
		struct gpio_button_data *bdata = &ddata->data[i];
		unsigned int type = button->type ?: EV_KEY;

		bdata->input = input;
		bdata->button = button;

		error = gpio_keys_setup_key(pdev, bdata, button);
		if (error)
			goto fail2;

		if (button->wakeup)
			wakeup = 1;

		input_set_capability(input, type, button->code);
	}

	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
	if (error) {
		dev_err(dev, "Unable to export keys/switches, error: %d\n",
			error);
		goto fail2;
	}

	error = input_register_device(input);
	if (error) {
		dev_err(dev, "Unable to register input device, error: %d\n",
			error);
		goto fail3;
	}

	/* get current state of buttons */
	for (i = 0; i < pdata->nbuttons; i++)
		gpio_keys_report_event(&ddata->data[i]);
	input_sync(input);

	device_init_wakeup(&pdev->dev, wakeup);

	return 0;

 fail3:
	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
 fail2:
	while (--i >= 0) {
		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
		if (ddata->data[i].timer_debounce)
			del_timer_sync(&ddata->data[i].timer);
		cancel_work_sync(&ddata->data[i].work);
		gpio_free(pdata->buttons[i].gpio);
	}

	platform_set_drvdata(pdev, NULL);
 fail1:
	input_free_device(input);
	kfree(ddata);

	return error;
}
static int rockchip_headsetobserve_probe(struct platform_device *pdev)
{
	int ret;
	struct headset_priv *headset;
	struct rk_headset_pdata *pdata;

	headset = kzalloc(sizeof(struct headset_priv), GFP_KERNEL);
	if (headset == NULL) {
		dev_err(&pdev->dev, "failed to allocate driver data\n");
		return -ENOMEM;
	}
	headset_info = headset;
	headset->pdata = pdev->dev.platform_data;
	pdata = headset->pdata;
	headset->headset_status = HEADSET_OUT;
	headset->heatset_irq_working = IDLE;
	headset->hook_status = HOOK_UP;
	headset->hook_time = HOOK_ADC_SAMPLE_TIME;
	headset->cur_headset_status = 0;
	headset->sdev.name = "h2w";
	headset->sdev.print_name = h2w_print_name;
	ret = switch_dev_register(&headset->sdev);
	if (ret < 0)
		goto failed_free;
	
//	mutex_init(&headset->mutex_lock[HEADSET]);
//	mutex_init(&headset->mutex_lock[HOOK]);
	wake_lock_init(&headset->headset_on_wake, WAKE_LOCK_SUSPEND, "headset_on_wake");
	INIT_DELAYED_WORK(&headset->h_delayed_work[HEADSET], headsetobserve_work);

	headset->isMic = 0;
//------------------------------------------------------------------		
	// Create and register the input driver. 
	headset->input_dev = input_allocate_device();
	if (!headset->input_dev) {
		dev_err(&pdev->dev, "failed to allocate input device\n");
		ret = -ENOMEM;
		goto failed_free;
	}	
	headset->input_dev->name = pdev->name;
	headset->input_dev->open = rk_Hskey_open;
	headset->input_dev->close = rk_Hskey_close;
	headset->input_dev->dev.parent = &pdev->dev;
	//input_dev->phys = KEY_PHYS_NAME;
	headset->input_dev->id.vendor = 0x0001;
	headset->input_dev->id.product = 0x0001;
	headset->input_dev->id.version = 0x0100;
	// Register the input device 
	ret = input_register_device(headset->input_dev);
	if (ret) {
		dev_err(&pdev->dev, "failed to register input device\n");
		goto failed_free_dev;
	}

	input_set_capability(headset->input_dev, EV_KEY, pdata->hook_key_code);
//------------------------------------------------------------------
	if (pdata->Headset_gpio) {
		ret = pdata->headset_io_init(pdata->Headset_gpio, pdata->headset_gpio_info.iomux_name, pdata->headset_gpio_info.iomux_mode);
		if (ret) 
			goto failed_free;

		headset->irq[HEADSET] = gpio_to_irq(pdata->Headset_gpio);

		if(pdata->headset_in_type == HEADSET_IN_HIGH)
			headset->irq_type[HEADSET] = IRQF_TRIGGER_HIGH|IRQF_ONESHOT;
		else
			headset->irq_type[HEADSET] = IRQF_TRIGGER_LOW|IRQF_ONESHOT;
		ret = request_threaded_irq(headset->irq[HEADSET], NULL,headset_interrupt, headset->irq_type[HEADSET]|IRQF_NO_SUSPEND, "headset_input", NULL);
		if (ret) 
			goto failed_free;
		enable_irq_wake(headset->irq[HEADSET]);
	}
	else
		goto failed_free;
//------------------------------------------------------------------
	if(pdata->Hook_adc_chn>=0 && 3>=pdata->Hook_adc_chn)
	{
		headset->client = adc_register(pdata->Hook_adc_chn, hook_adc_callback, (void *)headset);
		if(!headset->client) {
			printk("hook adc register error\n");
			ret = -EINVAL;
			goto failed_free;
		}
		setup_timer(&headset->hook_timer,hook_timer_callback, (unsigned long)headset);	
		printk("headset adc default value = %d\n",adc_sync_read(headset->client));
	}
	
#ifdef CONFIG_HAS_EARLYSUSPEND
	hs_early_suspend.suspend = NULL;
	hs_early_suspend.resume = headset_early_resume;
	hs_early_suspend.level = ~0x0;
	register_early_suspend(&hs_early_suspend);
#endif

	return 0;	
	
failed_free_dev:
	platform_set_drvdata(pdev, NULL);
	input_free_device(headset->input_dev);
failed_free:
	dev_err(&pdev->dev, "failed to headset probe\n");
	kfree(headset);
	return ret;
}
Beispiel #6
0
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_keys_drvdata *ddata;
	struct device *dev = &pdev->dev;
	struct gpio_keys_platform_data alt_pdata;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;

	if (!pdata) {
		error = gpio_keys_get_devtree_pdata(dev, &alt_pdata);
		if (error)
			return error;
		pdata = &alt_pdata;
	}

	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
			pdata->nbuttons * sizeof(struct gpio_button_data),
			GFP_KERNEL);
	input = input_allocate_device();
	if (!ddata || !input) {
		dev_err(dev, "failed to allocate state\n");
		error = -ENOMEM;
		goto fail1;
	}

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
	mutex_init(&ddata->disable_lock);

	platform_set_drvdata(pdev, ddata);
	input_set_drvdata(input, ddata);

	input->name = pdata->name ? : pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

	input->id.bustype = BUS_HOST;
	input->id.vendor = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0100;

	/* Enable auto repeat feature of Linux input subsystem */
	if (pdata->rep)
		__set_bit(EV_REP, input->evbit);

	for (i = 0; i < pdata->nbuttons; i++) {
		const struct gpio_keys_button *button = &pdata->buttons[i];
		struct gpio_button_data *bdata = &ddata->data[i];

		error = gpio_keys_setup_key(pdev, input, bdata, button);
		if (error)
			goto fail2;

		if (button->wakeup)
			wakeup = 1;
	}

	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
	if (error) {
		dev_err(dev, "Unable to export keys/switches, error: %d\n",
			error);
		goto fail2;
	}

	error = input_register_device(input);
	if (error) {
		dev_err(dev, "Unable to register input device, error: %d\n",
			error);
		goto fail3;
	}

	device_init_wakeup(&pdev->dev, wakeup);

	return 0;

 fail3:
	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
 fail2:
	while (--i >= 0)
		gpio_remove_key(&ddata->data[i]);

	platform_set_drvdata(pdev, NULL);
 fail1:
	input_free_device(input);
	kfree(ddata);
	/* If we have no platform_data, we allocated buttons dynamically. */
	if (!pdev->dev.platform_data)
		kfree(pdata->buttons);

	return error;
}
Beispiel #7
0
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_keys_drvdata *ddata;
	struct device *dev = &pdev->dev;
	struct gpio_keys_platform_data alt_pdata;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;

	if (!pdata) {
		error = gpio_keys_get_devtree_pdata(dev, &alt_pdata);
		if (error)
			return error;
		pdata = &alt_pdata;
	}

	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
			pdata->nbuttons * sizeof(struct gpio_button_data),
			GFP_KERNEL);
	input = input_allocate_device();
	if (!ddata || !input) {
		dev_err(dev, "failed to allocate state\n");
		error = -ENOMEM;
		goto fail1;
	}

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
	mutex_init(&ddata->disable_lock);

	platform_set_drvdata(pdev, ddata);
	input_set_drvdata(input, ddata);

	input->name = pdata->name ? : pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

	input->id.bustype = BUS_HOST;
	input->id.vendor = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0100;

	/* Enable auto repeat feature of Linux input subsystem */
	if (pdata->rep)
		__set_bit(EV_REP, input->evbit);

	for (i = 0; i < pdata->nbuttons; i++) {
		const struct gpio_keys_button *button = &pdata->buttons[i];
		struct gpio_button_data *bdata = &ddata->data[i];

		error = gpio_keys_setup_key(pdev, input, bdata, button);
		if (error)
			goto fail2;

		if (button->wakeup)
			wakeup = 1;
	}

	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
	if (error) {
		dev_err(dev, "Unable to export keys/switches, error: %d\n",
			error);
		goto fail2;
	}

	/* If any single key button can wake the device, we need to inform
	   the input subsystem not to mess with our key state during a suspend
	   and resume cycle. */
	if (wakeup) {
		device_set_wakeup_capable(&input->dev, true);
	}

	error = input_register_device(input);
	if (error) {
		dev_err(dev, "Unable to register input device, error: %d\n",
			error);
		goto fail3;
	}

	/* get current state of buttons that are connected to GPIOs */
	for (i = 0; i < pdata->nbuttons; i++) {
		struct gpio_button_data *bdata = &ddata->data[i];
		if (gpio_is_valid(bdata->button->gpio))
			gpio_keys_gpio_report_event(bdata);
	}
	input_sync(input);

	sweep2wake_setdev(input);
	printk(KERN_INFO "[sweep2wake]: set device %s\n", input->name); 


	device_init_wakeup(&pdev->dev, wakeup);

	return 0;

 fail3:
	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
 fail2:
	while (--i >= 0)
		gpio_remove_key(&ddata->data[i]);

	platform_set_drvdata(pdev, NULL);
 fail1:
	input_free_device(input);
	kfree(ddata);
	/* If we have no platform_data, we allocated buttons dynamically. */
	if (!pdev->dev.platform_data)
		kfree(pdata->buttons);

	return error;
}
Beispiel #8
0
static int cypress_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    struct cypress_ts_data *ts;
     //uint8_t buf0[4];
     uint8_t buf1[13];
     //	struct i2c_msg msg[2];
     int ret = 0;
     uint16_t max_x, max_y;
     // struct rmi_i2c_data *pdata;
	   struct proc_dir_entry *dir,*refresh;//ZTE_WLY_CRDB00509514
	   ret = gpio_request(GPIO_TOUCH_EN_OUT, "touch voltage");
	if (ret)
	{
		printk("gpio 31 request is error!\n");
		goto err_check_functionality_failed;
	}	   
    gpio_direction_output(GPIO_TOUCH_EN_OUT, 1);
/*ZTE_DELET_TIMER_WLY_001,2010-5-06 START*/
    msleep(20);
/*ZTE_DELET_TIMER_WLY_001,2010-5-06 START*/
    if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
    {
        printk(KERN_ERR "cypress_ts_probe: need I2C_FUNC_I2C\n");
        ret = -ENODEV;
        goto err_check_functionality_failed;
    }
    ts = kzalloc(sizeof(*ts), GFP_KERNEL);
    if (ts == NULL)
    {
        ret = -ENOMEM;
        goto err_alloc_data_failed;
    }

    INIT_WORK(&ts->work, cypress_ts_work_func);
    ts->client = client;
    	
    i2c_set_clientdata(client, ts);
    client->driver = &cypress_ts_driver;
    printk("wly: %s\n", __FUNCTION__);
    {
        int retry = 3;
		
        while (retry-- > 0)
        {
            ret = cypress_i2c_read(ts->client, 0x00, buf1, 13);
	/*ZTE_DELET_TIMER_WLY_001,2010-5-06 START*/   
	     if (ret >= 0)
    	     break;	
    	       msleep(10);
/*ZTE_DELET_TIMER_WLY_001,2010-5-06 START*/
        }
	 if (retry < 0)
	 {
	     ret = -1;
	     goto err_detect_failed;
	 }
    }
    firmware_version = buf1[12];
    ts->input_dev = input_allocate_device();

    if (ts->input_dev == NULL)
    {
        ret = -ENOMEM;
        printk(KERN_ERR "cypress_ts_probe: Failed to allocate input device\n");
        goto err_input_dev_alloc_failed;
    }
    // cypress_td = ts;
    ts->input_dev->name = "cypress_touch";
    ts->input_dev->phys = "cypress_touch/input0";
//ZTE_SET_BIT_WLY_0518,BEGIN
/*
    ts->input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
    ts->input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
    ts->input_dev->absbit[BIT_WORD(ABS_MISC)] = BIT_MASK(ABS_MISC);
    ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
*/
//ZTE_SET_BIT_WLY_0518,END
    set_bit(EV_SYN, ts->input_dev->evbit);
    set_bit(EV_KEY, ts->input_dev->evbit);
    set_bit(BTN_TOUCH, ts->input_dev->keybit);
    set_bit(EV_ABS, ts->input_dev->evbit);
    /*ZTE_TOUCH_WLY_006, @2010-04-14,begin*/
    //ZTE_SET_BIT_WLY_0518,BEGIN
    set_bit(ABS_MT_TOUCH_MAJOR, ts->input_dev->absbit);
    set_bit(ABS_MT_POSITION_X, ts->input_dev->absbit);
    set_bit(ABS_MT_POSITION_Y, ts->input_dev->absbit);
    set_bit(ABS_MT_WIDTH_MAJOR, ts->input_dev->absbit);
    /*ZTE_TOUCH_WLY_006, @2010-04-14,end*/
#ifdef CYPRESS_GESTURE//ZTE_TOUCH_ZT_002
    set_bit(EVENT_SINGLE_CLICK, ts->input_dev->absbit);
    set_bit(EVENT_TAP_HOLD, ts->input_dev->absbit);
    set_bit(EVENT_EARLY_TAP, ts->input_dev->absbit);
    set_bit(EVENT_FLICK, ts->input_dev->absbit);
    set_bit(EVENT_PRESS, ts->input_dev->absbit);
     set_bit(EVENT_PINCH, ts->input_dev->absbit);
    //ZTE_SET_BIT_WLY_0518,END
#endif
    /*ZTE_TOUCH_WLY_006, @2010-04-14,begin*/
	
    //ZTE_TS_ZT_20100428_001 begin
#if defined(CONFIG_MACH_BLADE)//P729B
    max_x=479;
    max_y=799;
#elif defined(CONFIG_MACH_R750)||defined(CONFIG_MACH_JOECDMA)
    max_x=319;
    max_y=479;
#else//other projects
    max_x=319;
    max_y=479;
#endif
    //ZTE_TS_ZT_20100428_001 end

    //ZTE_XUKE_TOUCH_20100901 //ZTE_TOUCH_LIWEI_20101014
    #ifdef TOUCHSCREEN_DUPLICATED_FILTER	
    ts->dup_threshold = (max_y+1)/LCD_MAX_Y; 
    printk("xuke:dup_threshold %d\n", ts->dup_threshold);
    #endif


    //ZTE_SET_BIT_WLY_0518,BEGIN
    /*
    input_set_abs_params(ts->input_dev, ABS_X, 0, max_x, 0, 0);
    input_set_abs_params(ts->input_dev, ABS_Y, 0, max_y, 0, 0);
    input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, 0, 0);
    */
    //ZTE_SET_BIT_WLY_0518,END
    input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
    input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0);
    input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0);
    input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
    /*ZTE_TOUCH_WLY_006, @2010-04-14,end*/
#ifdef CYPRESS_GESTURE//ZTE_TOUCH_ZT_002
    input_set_abs_params(ts->input_dev, EVENT_SINGLE_CLICK, 0, 255, 0, 0);
    input_set_abs_params(ts->input_dev, EVENT_TAP_HOLD, 0, 255, 0, 0);
    input_set_abs_params(ts->input_dev, EVENT_EARLY_TAP, 0, 255, 0, 0);
    input_set_abs_params(ts->input_dev, EVENT_FLICK, 0, 255, 0, 0);
    input_set_abs_params(ts->input_dev, EVENT_PRESS, 0, 128, 0, 0);
    input_set_abs_params(ts->input_dev, EVENT_PINCH, 0, 255, 0, 0);//wly add
#endif

    ret = input_register_device(ts->input_dev);
    if (ret)
    {
        printk(KERN_ERR "cypress_ts_probe: Unable to register %s input device\n", ts->input_dev->name);
        goto err_input_register_device_failed;
    }
	
    /*ZTE_WLY_RESUME_001,2010-4-23 START*/
    /*ZTE_DELET_TIMER_WLY_001,2010-5-06 START*/
    //hrtimer_init(&ts->resume_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
    //ts->resume_timer.function = cypress_ts_resume_func;
    /*ZTE_DELET_TIMER_WLY_001,2010-5-06 START*/
    /*ZTE_WLY_RESUME_001,2010-4-23 START*/

    cypress_td = ts;
    if (client->irq)
    {
        ret = request_irq(ts->client->irq, cypress_ts_irq_handler, IRQF_TRIGGER_FALLING, "cypress_touch", ts);
        if (ret == 0) ts->use_irq = 1;
    }
    if (!ts->use_irq)
    {
        hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        ts->timer.function = cypress_ts_timer_func;
        hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
    }
#ifdef CONFIG_HAS_EARLYSUSPEND
    ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    ts->early_suspend.suspend = cypress_ts_early_suspend;
    ts->early_suspend.resume = cypress_ts_late_resume;
    register_early_suspend(&ts->early_suspend);
#endif

    printk(KERN_INFO "cypress_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name,
        ts->use_irq ? "interrupt" : "polling");
    //ZTE_WLY_CRDB00509514,BEGIN
    dir = proc_mkdir("touchscreen", NULL);
    refresh = create_proc_entry("ts_information", 0777, dir);//ZTE_WLY_CRDB00517999
    if (refresh) {
        refresh->data		= NULL;
        refresh->read_proc  = proc_read_val;
        refresh->write_proc = proc_write_val;	
    }
    //ZTE_WLY_CRDB00509514,END

#if defined(CONFIG_TOUCHSCREEN_VIRTUAL_KEYS)//ZTE_TS_ZT_20100513_001
	ts_key_report_init();
#endif

    return 0;
err_input_register_device_failed:
    input_unregister_device(ts->input_dev);

err_input_dev_alloc_failed:
    input_free_device(ts->input_dev);
err_detect_failed:
    //err_power_failed:
    kfree(ts);
err_alloc_data_failed:
err_check_functionality_failed:
    gpio_free(GPIO_TOUCH_EN_OUT);	
    return ret;
}
/* Interrupt handler */
static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id)
{
	struct omap4_keypad *keypad_data = dev_id;
	struct input_dev *input_dev = keypad_data->input;
	unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)];
	unsigned int col, row, code, changed;
	u32 *new_state = (u32 *) key_state;

	/* LGE_SJIT 2012-01-05 [[email protected]] wake lock from P940 GB
	 * 2011.12.07 [email protected] For Volume Control.
	 */
	wake_lock_timeout(&keypad_data->wlock, 1 * HZ);

	*new_state = __raw_readl(keypad_data->base + OMAP4_KBD_FULLCODE31_0);
	*(new_state + 1) = __raw_readl(keypad_data->base
						+ OMAP4_KBD_FULLCODE63_32);

	// LGE_CHANGE_S [[email protected]] 2012-06-06 , add to check H/W status
	if(debug_mask) {
		printk("========================================================\n");
		printk("%s: [%#x][%#x]\n", __func__, *new_state, *(new_state+1));
		printk("========================================================\n");
	}
	// LGE_CHANGE_E [[email protected]] 2012-06-06

	for (col = 0; col < keypad_data->cols; col++) {
		changed = key_state[col] ^ keypad_data->key_state[col];

		if (!changed)
			continue;
		for (row = 0; row < keypad_data->rows; row++) {
			if (changed & (1 << row)) {
				code = MATRIX_SCAN_CODE(row, col,
						keypad_data->row_shift);

				// LGE_CHANGE_S [[email protected]] 2012-06-06 , add to check H/W status
				if(debug_mask) {
					printk("%s: [changed][col][row][code] = [%#x][%d][%d][%d]\n", __func__, changed, col, row, code);
					printk("========================================================\n");
				}
				// LGE_CHANGE_E [[email protected]] 2012-06-06

                                //[email protected] => [START]  keylock command
#ifdef CONFIG_MACH_LGE_COSMO
				if( keypad_data->keymap[code] && !atcmd_keylock) {
#else
				if( keypad_data->keymap[code] ) {
#endif
                                //[email protected] <= [END]
				    input_event(input_dev, EV_MSC, MSC_SCAN, code);
				    input_report_key(input_dev,
                            keypad_data->keymap[code],
                            (bool)(key_state[col] & (1 << row)));

#ifdef CONFIG_MACH_LGE_U2	/* [email protected] - 2012/05/21 - the HOME_key is added */
                    printk("[omap4-keypad] %s KEY %s\n",
                                                (keypad_data->keymap[code] == KEY_VOLUMEUP) ? "Vol_UP" : ((keypad_data->keymap[code] == KEY_VOLUMEDOWN) ? "Vol_DOWN" : "HOME"),
                                                (key_state[col] & (1 << row)) ? "PRESS" : "RELEASE" );
#else
                    printk("[omap4-keypad] %s KEY %s\n",
						(keypad_data->keymap[code] == KEY_VOLUMEUP) ? "Vol_UP" : ((keypad_data->keymap[code] == KEY_VOLUMEDOWN) ? "Vol_DOWN" : "CAPTURE"),
						(key_state[col] & (1 << row)) ? "PRESS" : "RELEASE" );
#endif

#ifdef CONFIG_INPUT_LGE_GKPD
                    gkpd_report_key(keypad_data->keymap[code], (bool)(key_state[col] & (1 << row)));
#endif

                    break;
				}

				/* LGE_SJIT 2012-01-05 [[email protected]]
				 * for Android SafeMode
				 * [[email protected]] 2011-06-10,
				 * [P940] for enable the saving-mode
				 */
#ifdef CONFIG_KEYBOARD_OMAP4_SAFEMODE
				if (keypad_data->keymap[code] == KEY_VOLUMEUP) {
					safemode_key = !!(key_state[col] & (1 << row));
				}
#endif
			}
		}
	}

	input_sync(input_dev);

	memcpy(keypad_data->key_state, key_state,
		sizeof(keypad_data->key_state));

	/* clear pending interrupts */
	__raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
			keypad_data->base + OMAP4_KBD_IRQSTATUS);


	printk("#################################### %s is finished!!!!!\n", __func__);
	return IRQ_HANDLED;
}

static int omap4_keypad_open(struct input_dev *input)
{
	struct omap4_keypad *keypad_data = input_get_drvdata(input);

#ifdef KBD_DEBUG
	printk("omap4-keypad: omap4_keypad_open \n");
#endif

	pm_runtime_get_sync(input->dev.parent);

	disable_irq(keypad_data->irq);

	__raw_writel(OMAP4_DEF_CTRL_NOSOFTMODE |
			(OMAP4_VAL_PVT << OMAP4_DEF_CTRL_PTV),
			keypad_data->base + OMAP4_KBD_CTRL);

	__raw_writel(OMAP4_VAL_DEBOUNCINGTIME,
			keypad_data->base + OMAP4_KBD_DEBOUNCINGTIME);

	/* Enable event IRQ*/
	__raw_writel(OMAP4_DEF_IRQENABLE_EVENTEN,
			keypad_data->base + OMAP4_KBD_IRQENABLE);

	/* Enable event wkup*/
	__raw_writel(OMAP4_DEF_WUP_EVENT_ENA,
			keypad_data->base + OMAP4_KBD_WAKEUPENABLE);

	/* clear pending interrupts */
	__raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
			keypad_data->base + OMAP4_KBD_IRQSTATUS);
	enable_irq(keypad_data->irq);

	return 0;
}

static void omap4_keypad_close(struct input_dev *input)
{
	struct omap4_keypad *keypad_data = input_get_drvdata(input);

	disable_irq(keypad_data->irq);

	/* Disable interrupts */
	__raw_writel(OMAP4_VAL_IRQDISABLE,
		     keypad_data->base + OMAP4_KBD_IRQENABLE);

	/* clear pending interrupts */
	__raw_writel(__raw_readl(keypad_data->base + OMAP4_KBD_IRQSTATUS),
			keypad_data->base + OMAP4_KBD_IRQSTATUS);

	enable_irq(keypad_data->irq);

#ifdef KBD_DEBUG
	printk("omap4-keypad: omap4_keypad_close \n");
#endif

	pm_runtime_put_sync(input->dev.parent);
}

static int __devinit omap4_keypad_probe(struct platform_device *pdev)
{
	const struct omap4_keypad_platform_data *pdata;
	struct omap4_keypad *keypad_data;
	struct input_dev *input_dev;
	struct resource *res;
	resource_size_t size;
	unsigned int row_shift, max_keys;
	int irq;
	int error;

	/* platform data */
	pdata = pdev->dev.platform_data;
	if (!pdata) {
		dev_err(&pdev->dev, "no platform data defined\n");
		return -EINVAL;
	}

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res) {
		dev_err(&pdev->dev, "no base address specified\n");
		return -EINVAL;
	}

	irq = platform_get_irq(pdev, 0);
	if (!irq) {
		dev_err(&pdev->dev, "no keyboard irq assigned\n");
		return -EINVAL;
	}

	if (!pdata->keymap_data) {
		dev_err(&pdev->dev, "no keymap data defined\n");
		return -EINVAL;
	}

	row_shift = get_count_order(pdata->cols);
	max_keys = pdata->rows << row_shift;

	keypad_data = kzalloc(sizeof(struct omap4_keypad) +
				max_keys * sizeof(keypad_data->keymap[0]),
			      GFP_KERNEL);
	if (!keypad_data) {
		dev_err(&pdev->dev, "keypad_data memory allocation failed\n");
		return -ENOMEM;
	}

	size = resource_size(res);

	res = request_mem_region(res->start, size, pdev->name);
	if (!res) {
		dev_err(&pdev->dev, "can't request mem region\n");
		error = -EBUSY;
		goto err_free_keypad;
	}

	keypad_data->base = ioremap(res->start, resource_size(res));
	if (!keypad_data->base) {
		dev_err(&pdev->dev, "can't ioremap mem resource\n");
		error = -ENOMEM;
		goto err_release_mem;
	}

	keypad_data->irq = irq;
	keypad_data->row_shift = row_shift;
	keypad_data->rows = pdata->rows;
	keypad_data->cols = pdata->cols;
	keypad_data->keypad_pad_wkup = pdata->keypad_pad_wkup;

	/* input device allocation */
	keypad_data->input = input_dev = input_allocate_device();
	if (!input_dev) {
		error = -ENOMEM;
		goto err_unmap;
	}

	input_dev->name = pdev->name;
	input_dev->dev.parent = &pdev->dev;
	input_dev->id.bustype = BUS_HOST;
	input_dev->id.vendor = 0x0001;
	input_dev->id.product = 0x0001;
	input_dev->id.version = 0x0001;

	input_dev->open = omap4_keypad_open;
	input_dev->close = omap4_keypad_close;

	input_dev->keycode	= keypad_data->keymap;
	input_dev->keycodesize	= sizeof(keypad_data->keymap[0]);
	input_dev->keycodemax	= max_keys;

	__set_bit(EV_KEY, input_dev->evbit);
	__set_bit(EV_REP, input_dev->evbit);

	input_set_capability(input_dev, EV_MSC, MSC_SCAN);

	input_set_drvdata(input_dev, keypad_data);

	matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
			input_dev->keycode, input_dev->keybit);

	/* LGE_SJIT 2011-12-06 [[email protected]] MHL keybits
	 * jk.koo kibu.lee 20110810 MHL RCP codes into media keys and
	 * transfer these to the input manager
	 */
#if defined(CONFIG_MHL_INPUT_RCP)
	hdmi_common_register_keys(input_dev);
#endif
	/* LGE_SJIT 2011-12-09 [[email protected]] for hook key */
#if defined(CONFIG_SND_OMAP_SOC_LGE_JACK)
	__set_bit(KEY_HOOK, input_dev->keybit);
#endif
	/* LGE_SJIT 2011-01-05 [[email protected]] Add wake lock */
	wake_lock_init(&keypad_data->wlock, WAKE_LOCK_SUSPEND, "omap4-keypad");

	/*
	 * Set irq level detection for mpu. Edge event are missed
	 * in gic if the mpu is in low power and keypad event
	 * is a wakeup.
	 */
	error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
			     IRQF_TRIGGER_HIGH,
			     "omap4-keypad", keypad_data);
	if (error) {
		dev_err(&pdev->dev, "failed to register interrupt\n");
		goto err_free_input;
	}
	enable_irq_wake(OMAP44XX_IRQ_KBD_CTL);

	pm_runtime_enable(&pdev->dev);

	error = input_register_device(keypad_data->input);
	if (error < 0) {
		dev_err(&pdev->dev, "failed to register input device\n");
		goto err_pm_disable;
	}

	platform_set_drvdata(pdev, keypad_data);

	/* LGE_SJIT 2012-01-05 [[email protected]] for Android SafeMode
	 * [[email protected]] 2011-06-10, [P940] for enable the saving-mode
	 */
#ifdef CONFIG_KEYBOARD_OMAP4_SAFEMODE
	error = device_create_file(&pdev->dev, &dev_attr_key_saving);
	if (error < 0) {
		dev_warn(&pdev->dev, "failed to create sysfs for key_saving\n");
	}
#endif

// LGE_CHANGE_S [[email protected]] 2012-06-06 , add debug_mask to check the H/W status for keypad immediately
	error = device_create_file(&pdev->dev, &dev_attr_keypad_debug);
	if (error < 0) {
		dev_warn(&pdev->dev, "failed to create sysfs for keypad_debug\n");
	}
// LGE_CHANGE_E [[email protected]] 2012-06-06

//[email protected] => [START]  keylock command
#ifdef CONFIG_MACH_LGE_COSMO
	error = device_create_file(&pdev->dev, &dev_attr_keylock);
	if (error) {
		printk( "keypad: keylock create file: Fail\n");
		device_remove_file(&pdev->dev, &dev_attr_keylock);
	}
#endif
//[email protected] <= [END]

	/* LGE_SJIT 2011-12-06 [[email protected]] export input handle */
#ifdef CONFIG_MACH_LGE
	lge_input_set(input_dev);
#endif

	return 0;

err_pm_disable:
	pm_runtime_disable(&pdev->dev);
	free_irq(keypad_data->irq, keypad_data);
	/* LGE_SJIT 2011-01-05 [[email protected]] Add wake lock */
	wake_lock_destroy(&keypad_data->wlock);
err_free_input:
	input_free_device(input_dev);
err_unmap:
	iounmap(keypad_data->base);
err_release_mem:
	release_mem_region(res->start, size);
err_free_keypad:
	kfree(keypad_data);
	return error;
}

static int __devexit omap4_keypad_remove(struct platform_device *pdev)
{
	struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
	struct resource *res;

// LGE_CHANGE_S [[email protected]] 2012-06-06 , add debug_mask to check the H/W status for keypad immediately
	device_remove_file(&pdev->dev, &dev_attr_keypad_debug);
// LGE_CHANGE_E [[email protected]] 2012-06-06

//[email protected] => [START]  keylock command
#ifdef CONFIG_MACH_LGE_COSMO
	device_remove_file(&pdev->dev, &dev_attr_keylock);
#endif
//[email protected] <= [END]

	/* LGE_SJIT 2012-01-05 [[email protected]] for Android SafeMode
	 * [[email protected]] 2011-06-10, [P940] for enable the saving-mode
	 */
#ifdef CONFIG_KEYBOARD_OMAP4_SAFEMODE
	device_remove_file(&pdev->dev, &dev_attr_key_saving);
#endif

	free_irq(keypad_data->irq, keypad_data);

	/* LGE_SJIT 2011-01-05 [[email protected]] Add wake lock */
	wake_lock_destroy(&keypad_data->wlock);

	pm_runtime_disable(&pdev->dev);

	input_unregister_device(keypad_data->input);

	iounmap(keypad_data->base);

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	release_mem_region(res->start, resource_size(res));

	kfree(keypad_data);
	platform_set_drvdata(pdev, NULL);

	return 0;
}
static int omap4_keypad_suspend(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);

	if (keypad_data->keypad_pad_wkup)
		keypad_data->keypad_pad_wkup(1);

	return 0;
}
static int omap4_keypad_resume(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);

	if (keypad_data->keypad_pad_wkup)
		keypad_data->keypad_pad_wkup(0);

	return 0;
}
static const struct dev_pm_ops omap4_keypad_pm_ops = {
	.suspend = omap4_keypad_suspend,
	.resume = omap4_keypad_resume,
};

static struct platform_driver omap4_keypad_driver = {
	.probe		= omap4_keypad_probe,
	.remove		= __devexit_p(omap4_keypad_remove),
	.driver		= {
		.name	= "omap4-keypad",
		.owner	= THIS_MODULE,
		.pm	= &omap4_keypad_pm_ops,
	},
};

static int __init omap4_keypad_init(void)
{
	return platform_driver_register(&omap4_keypad_driver);
}
module_init(omap4_keypad_init);

static void __exit omap4_keypad_exit(void)
{
	platform_driver_unregister(&omap4_keypad_driver);
}
Beispiel #10
0
static int bcm5974_probe(struct usb_interface *iface,
			 const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(iface);
	const struct bcm5974_config *cfg;
	struct bcm5974 *dev;
	struct input_dev *input_dev;
	int error = -ENOMEM;

	/* find the product index */
	cfg = bcm5974_get_config(udev);

	/* allocate memory for our device state and initialize it */
	dev = kzalloc(sizeof(struct bcm5974), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!dev || !input_dev) {
		dev_err(&iface->dev, "out of memory\n");
		goto err_free_devs;
	}

	dev->udev = udev;
	dev->intf = iface;
	dev->input = input_dev;
	dev->cfg = *cfg;
	mutex_init(&dev->pm_mutex);

	/* setup urbs */
	dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!dev->bt_urb)
		goto err_free_devs;

	dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!dev->tp_urb)
		goto err_free_bt_urb;

	dev->bt_data = usb_alloc_coherent(dev->udev,
					  dev->cfg.bt_datalen, GFP_KERNEL,
					  &dev->bt_urb->transfer_dma);
	if (!dev->bt_data)
		goto err_free_urb;

	dev->tp_data = usb_alloc_coherent(dev->udev,
					  dev->cfg.tp_datalen, GFP_KERNEL,
					  &dev->tp_urb->transfer_dma);
	if (!dev->tp_data)
		goto err_free_bt_buffer;

	usb_fill_int_urb(dev->bt_urb, udev,
			 usb_rcvintpipe(udev, cfg->bt_ep),
			 dev->bt_data, dev->cfg.bt_datalen,
			 bcm5974_irq_button, dev, 1);

	usb_fill_int_urb(dev->tp_urb, udev,
			 usb_rcvintpipe(udev, cfg->tp_ep),
			 dev->tp_data, dev->cfg.tp_datalen,
			 bcm5974_irq_trackpad, dev, 1);

	/* create bcm5974 device */
	usb_make_path(udev, dev->phys, sizeof(dev->phys));
	strlcat(dev->phys, "/input0", sizeof(dev->phys));

	input_dev->name = "bcm5974";
	input_dev->phys = dev->phys;
	usb_to_input_id(dev->udev, &input_dev->id);
	/* report driver capabilities via the version field */
	input_dev->id.version = cfg->caps;
	input_dev->dev.parent = &iface->dev;

	input_set_drvdata(input_dev, dev);

	input_dev->open = bcm5974_open;
	input_dev->close = bcm5974_close;

	setup_events_to_report(input_dev, cfg);

	error = input_register_device(dev->input);
	if (error)
		goto err_free_buffer;

	/* save our data pointer in this interface device */
	usb_set_intfdata(iface, dev);

	return 0;

err_free_buffer:
	usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
		dev->tp_data, dev->tp_urb->transfer_dma);
err_free_bt_buffer:
	usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
		dev->bt_data, dev->bt_urb->transfer_dma);
err_free_urb:
	usb_free_urb(dev->tp_urb);
err_free_bt_urb:
	usb_free_urb(dev->bt_urb);
err_free_devs:
	usb_set_intfdata(iface, NULL);
	input_free_device(input_dev);
	kfree(dev);
	return error;
}
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;

    // faux123, no need to have a multi-thread/multi-cpu bound work queue!
    //detect_wq = create_workqueue("detect");
    detect_wq = create_singlethread_workqueue("detect");
    if (detect_wq == NULL) {
        ret = -ENOMEM;
        HS_ERR("Failed to create detect workqueue");
        goto err_create_detect_work_queue;
    }

    // faux123, no need to have a multi-thread/multi-cpu bound work queue!
    //button_wq = create_workqueue("button");
    button_wq = create_singlethread_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");
    }

    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_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;
}
Beispiel #12
0
static int __devinit w90p910_keypad_probe(struct platform_device *pdev)
{
	const struct w90p910_keypad_platform_data *pdata =
						pdev->dev.platform_data;
	const struct matrix_keymap_data *keymap_data;
	struct w90p910_keypad *keypad;
	struct input_dev *input_dev;
	struct resource *res;
	int irq;
	int error;

	if (!pdata) {
		dev_err(&pdev->dev, "no platform data defined\n");
		return -EINVAL;
	}

	keymap_data = pdata->keymap_data;

	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		dev_err(&pdev->dev, "failed to get keypad irq\n");
		return -ENXIO;
	}

	keypad = kzalloc(sizeof(struct w90p910_keypad), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!keypad || !input_dev) {
		dev_err(&pdev->dev, "failed to allocate driver data\n");
		error = -ENOMEM;
		goto failed_free;
	}

	keypad->pdata = pdata;
	keypad->input_dev = input_dev;
	keypad->irq = irq;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (res == NULL) {
		dev_err(&pdev->dev, "failed to get I/O memory\n");
		error = -ENXIO;
		goto failed_free;
	}

	res = request_mem_region(res->start, resource_size(res), pdev->name);
	if (res == NULL) {
		dev_err(&pdev->dev, "failed to request I/O memory\n");
		error = -EBUSY;
		goto failed_free;
	}

	keypad->mmio_base = ioremap(res->start, resource_size(res));
	if (keypad->mmio_base == NULL) {
		dev_err(&pdev->dev, "failed to remap I/O memory\n");
		error = -ENXIO;
		goto failed_free_res;
	}

	keypad->clk = clk_get(&pdev->dev, NULL);
	if (IS_ERR(keypad->clk)) {
		dev_err(&pdev->dev, "failed to get keypad clock\n");
		error = PTR_ERR(keypad->clk);
		goto failed_free_io;
	}

	/* set multi-function pin for w90p910 kpi. */
	mfp_set_groupi(&pdev->dev);

	input_dev->name = pdev->name;
	input_dev->id.bustype = BUS_HOST;
	input_dev->open = w90p910_keypad_open;
	input_dev->close = w90p910_keypad_close;
	input_dev->dev.parent = &pdev->dev;

	input_dev->keycode = keypad->keymap;
	input_dev->keycodesize = sizeof(keypad->keymap[0]);
	input_dev->keycodemax = ARRAY_SIZE(keypad->keymap);

	input_set_drvdata(input_dev, keypad);

	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
	input_set_capability(input_dev, EV_MSC, MSC_SCAN);

	matrix_keypad_build_keymap(keymap_data, W90P910_ROW_SHIFT,
				   input_dev->keycode, input_dev->keybit);

	error = request_irq(keypad->irq, w90p910_keypad_irq_handler,
			    IRQF_DISABLED, pdev->name, keypad);
	if (error) {
		dev_err(&pdev->dev, "failed to request IRQ\n");
		goto failed_put_clk;
	}

	/* Register the input device */
	error = input_register_device(input_dev);
	if (error) {
		dev_err(&pdev->dev, "failed to register input device\n");
		goto failed_free_irq;
	}

	platform_set_drvdata(pdev, keypad);
	return 0;

failed_free_irq:
	free_irq(irq, pdev);
failed_put_clk:
	clk_put(keypad->clk);
failed_free_io:
	iounmap(keypad->mmio_base);
failed_free_res:
	release_mem_region(res->start, resource_size(res));
failed_free:
	input_free_device(input_dev);
	kfree(keypad);
	return error;
}
static int __devinit cy8ctmg110_probe(struct i2c_client *client,
					const struct i2c_device_id *id)
{
	const struct cy8ctmg110_pdata *pdata = client->dev.platform_data;
	struct cy8ctmg110 *ts;
	struct input_dev *input_dev;
	int err;

	/* No pdata no way forward */
	if (pdata == NULL) {
		dev_err(&client->dev, "no pdata\n");
		return -ENODEV;
	}

	if (!i2c_check_functionality(client->adapter,
					I2C_FUNC_SMBUS_READ_WORD_DATA))
		return -EIO;

	ts = kzalloc(sizeof(struct cy8ctmg110), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!ts || !input_dev) {
		err = -ENOMEM;
		goto err_free_mem;
	}

	ts->client = client;
	ts->input = input_dev;
	ts->reset_pin = pdata->reset_pin;
	ts->irq_pin = pdata->irq_pin;

	snprintf(ts->phys, sizeof(ts->phys),
		 "%s/input0", dev_name(&client->dev));

	input_dev->name = CY8CTMG110_DRIVER_NAME " Touchscreen";
	input_dev->phys = ts->phys;
	input_dev->id.bustype = BUS_I2C;
	input_dev->dev.parent = &client->dev;

	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
	input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);

	input_set_abs_params(input_dev, ABS_X,
			CY8CTMG110_X_MIN, CY8CTMG110_X_MAX, 4, 0);
	input_set_abs_params(input_dev, ABS_Y,
			CY8CTMG110_Y_MIN, CY8CTMG110_Y_MAX, 4, 0);

	if (ts->reset_pin) {
		err = gpio_request(ts->reset_pin, NULL);
		if (err) {
			dev_err(&client->dev,
				"Unable to request GPIO pin %d.\n",
				ts->reset_pin);
			goto err_free_mem;
		}
	}

	cy8ctmg110_power(ts, true);
	cy8ctmg110_set_sleepmode(ts, false);

	err = gpio_request(ts->irq_pin, "touch_irq_key");
	if (err < 0) {
		dev_err(&client->dev,
			"Failed to request GPIO %d, error %d\n",
			ts->irq_pin, err);
		goto err_shutoff_device;
	}

	err = gpio_direction_input(ts->irq_pin);
	if (err < 0) {
		dev_err(&client->dev,
			"Failed to configure input direction for GPIO %d, error %d\n",
			ts->irq_pin, err);
		goto err_free_irq_gpio;
	}

	client->irq = gpio_to_irq(ts->irq_pin);
	if (client->irq < 0) {
		err = client->irq;
		dev_err(&client->dev,
			"Unable to get irq number for GPIO %d, error %d\n",
			ts->irq_pin, err);
		goto err_free_irq_gpio;
	}

	err = request_threaded_irq(client->irq, NULL, cy8ctmg110_irq_thread,
				   IRQF_TRIGGER_RISING, "touch_reset_key", ts);
	if (err < 0) {
		dev_err(&client->dev,
			"irq %d busy? error %d\n", client->irq, err);
		goto err_free_irq_gpio;
	}

	err = input_register_device(input_dev);
	if (err)
		goto err_free_irq;

	i2c_set_clientdata(client, ts);
	device_init_wakeup(&client->dev, 1);
	return 0;

err_free_irq:
	free_irq(client->irq, ts);
err_free_irq_gpio:
	gpio_free(ts->irq_pin);
err_shutoff_device:
	cy8ctmg110_set_sleepmode(ts, true);
	cy8ctmg110_power(ts, false);
	if (ts->reset_pin)
		gpio_free(ts->reset_pin);
err_free_mem:
	input_free_device(input_dev);
	kfree(ts);
	return err;
}
Beispiel #14
0
static int __devinit dm355evm_keys_probe(struct platform_device *pdev)
{
	struct dm355evm_keys	*keys;
	struct input_dev	*input;
	int			status;
	int			i;

	/* allocate instance struct and input dev */
	keys = kzalloc(sizeof *keys, GFP_KERNEL);
	input = input_allocate_device();
	if (!keys || !input) {
		status = -ENOMEM;
		goto fail1;
	}

	keys->dev = &pdev->dev;
	keys->input = input;

	/* set up "threaded IRQ handler" */
	status = platform_get_irq(pdev, 0);
	if (status < 0)
		goto fail1;
	keys->irq = status;

	input_set_drvdata(input, keys);

	input->name = "DM355 EVM Controls";
	input->phys = "dm355evm/input0";
	input->dev.parent = &pdev->dev;

	input->id.bustype = BUS_I2C;
	input->id.product = 0x0355;
	input->id.version = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);

	input->evbit[0] = BIT(EV_KEY);
	for (i = 0; i < ARRAY_SIZE(dm355evm_keys); i++)
		__set_bit(dm355evm_keys[i].keycode, input->keybit);

	input->setkeycode = dm355evm_setkeycode;
	input->getkeycode = dm355evm_getkeycode;

	/* REVISIT:  flush the event queue? */

	status = request_threaded_irq(keys->irq,
			dm355evm_keys_hardirq, dm355evm_keys_irq,
			IRQF_TRIGGER_FALLING,
			dev_name(&pdev->dev), keys);
	if (status < 0)
		goto fail1;

	/* register */
	status = input_register_device(input);
	if (status < 0)
		goto fail2;

	platform_set_drvdata(pdev, keys);

	return 0;

fail2:
	free_irq(keys->irq, keys);
fail1:
	input_free_device(input);
	kfree(keys);
	dev_err(&pdev->dev, "can't register, err %d\n", status);

	return status;
}
Beispiel #15
0
static int qt2160_probe(struct i2c_client *client,
				  const struct i2c_device_id *id)
{
	struct qt2160_data *qt2160;
	struct input_dev *input;
	int i;
	int error;

	/* Check functionality */
	error = i2c_check_functionality(client->adapter,
			I2C_FUNC_SMBUS_BYTE);
	if (!error) {
		dev_err(&client->dev, "%s adapter not supported\n",
				dev_driver_string(&client->adapter->dev));
		return -ENODEV;
	}

	if (!qt2160_identify(client))
		return -ENODEV;

	/* Chip is valid and active. Allocate structure */
	qt2160 = kzalloc(sizeof(struct qt2160_data), GFP_KERNEL);
	input = input_allocate_device();
	if (!qt2160 || !input) {
		dev_err(&client->dev, "insufficient memory\n");
		error = -ENOMEM;
		goto err_free_mem;
	}

	qt2160->client = client;
	qt2160->input = input;
	INIT_DELAYED_WORK(&qt2160->dwork, qt2160_worker);
	spin_lock_init(&qt2160->lock);

	input->name = "AT42QT2160 Touch Sense Keyboard";
	input->id.bustype = BUS_I2C;

	input->keycode = qt2160->keycodes;
	input->keycodesize = sizeof(qt2160->keycodes[0]);
	input->keycodemax = ARRAY_SIZE(qt2160_key2code);

	__set_bit(EV_KEY, input->evbit);
	__clear_bit(EV_REP, input->evbit);
	for (i = 0; i < ARRAY_SIZE(qt2160_key2code); i++) {
		qt2160->keycodes[i] = qt2160_key2code[i];
		__set_bit(qt2160_key2code[i], input->keybit);
	}
	__clear_bit(KEY_RESERVED, input->keybit);

	/* Calibrate device */
	error = qt2160_write(client, QT2160_CMD_CALIBRATE, 1);
	if (error) {
		dev_err(&client->dev, "failed to calibrate device\n");
		goto err_free_mem;
	}

	if (client->irq) {
		error = request_irq(client->irq, qt2160_irq,
				    IRQF_TRIGGER_FALLING, "qt2160", qt2160);
		if (error) {
			dev_err(&client->dev,
				"failed to allocate irq %d\n", client->irq);
			goto err_free_mem;
		}
	}

	error = input_register_device(qt2160->input);
	if (error) {
		dev_err(&client->dev,
			"Failed to register input device\n");
		goto err_free_irq;
	}

	i2c_set_clientdata(client, qt2160);
	qt2160_schedule_read(qt2160);

	return 0;

err_free_irq:
	if (client->irq)
		free_irq(client->irq, qt2160);
err_free_mem:
	input_free_device(input);
	kfree(qt2160);
	return error;
}
static int gp2a_i2c_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	int ret = -ENODEV;
	struct input_dev *input_dev;
	struct gp2a_data *gp2a;
	struct gp2a_platform_data *pdata = client->dev.platform_data;

	pr_info("==============================\n");
	pr_info("=========     GP2A     =======\n");
	pr_info("==============================\n");

	if (!pdata) {
		pr_err("%s: missing pdata!\n", __func__);
		return ret;
	}
	/*
	if (!pdata->power || !pdata->light_adc_value) {
		pr_err("%s: incomplete pdata!\n", __func__);
		return ret;
	}
	*/
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("%s: i2c functionality check failed!\n", __func__);
		return ret;
	}

	gp2a = kzalloc(sizeof(struct gp2a_data), GFP_KERNEL);
	if (!gp2a) {
		pr_err("%s: failed to alloc memory for module data\n",
			__func__);
		return -ENOMEM;
	}

#if defined(CONFIG_OPTICAL_WAKE_ENABLE)
	if (system_rev >= 0x03) {
		pr_info("GP2A Reset GPIO = GPX0(1) (rev%02d)\n", system_rev);
		gp2a->enable_wakeup = true;
	} else {
		pr_info("GP2A Reset GPIO = GPL0(6) (rev%02d)\n", system_rev);
		gp2a->enable_wakeup = false;
	}
#else
	gp2a->enable_wakeup = false;
#endif

	gp2a->pdata = pdata;
	gp2a->i2c_client = client;
	i2c_set_clientdata(client, gp2a);

	/* wake lock init */
	wake_lock_init(&gp2a->prx_wake_lock, WAKE_LOCK_SUSPEND,
			"prx_wake_lock");
	mutex_init(&gp2a->power_mutex);
	mutex_init(&gp2a->adc_mutex);

	ret = gp2a_setup_irq(gp2a);
	if (ret) {
		pr_err("%s: could not setup irq\n", __func__);
		goto err_setup_irq;
	}

	/* allocate proximity input_device */
	input_dev = input_allocate_device();
	if (!input_dev) {
		pr_err("%s: could not allocate input device\n", __func__);
		goto err_input_allocate_device_proximity;
	}

	gp2a->proximity_input_dev = input_dev;
	input_set_drvdata(input_dev, gp2a);
	input_dev->name = "proximity_sensor";
	input_set_capability(input_dev, EV_ABS, ABS_DISTANCE);
	input_set_abs_params(input_dev, ABS_DISTANCE, 0, 1, 0, 0);

	gp2a_dbgmsg("registering proximity input device\n");
	ret = input_register_device(input_dev);
	if (ret < 0) {
		pr_err("%s: could not register input device\n", __func__);
		input_free_device(input_dev);
		goto err_input_register_device_proximity;
	}

	ret = sysfs_create_group(&input_dev->dev.kobj,
				 &proximity_attribute_group);
	if (ret) {
		pr_err("%s: could not create sysfs group\n", __func__);
		goto err_sysfs_create_group_proximity;
	}

	/* hrtimer settings.  we poll for light values using a timer. */
	hrtimer_init(&gp2a->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	gp2a->light_poll_delay =
			ns_to_ktime(LIGHT_TIMER_PERIOD_MS * NSEC_PER_MSEC);
	gp2a->timer.function = gp2a_timer_func;

	/* the timer just fires off a work queue request.  we need a thread
	   to read the i2c (can be slow and blocking). */
	gp2a->wq = create_singlethread_workqueue("gp2a_wq");
	if (!gp2a->wq) {
		ret = -ENOMEM;
		pr_err("%s: could not create workqueue\n", __func__);
		goto err_create_workqueue;
	}

	/* this is the thread function we run on the work queue */
	INIT_WORK(&gp2a->work_light, gp2a_work_func_light);

#ifdef GP2A_MODE_B
	/* this is the thread function we run on the work queue */
	INIT_WORK(&gp2a->work_proximity, gp2a_work_func_proximity);
#endif

	/* allocate lightsensor-level input_device */
	input_dev = input_allocate_device();
	if (!input_dev) {
		pr_err("%s: could not allocate input device\n", __func__);
		ret = -ENOMEM;
		goto err_input_allocate_device_light;
	}

	input_set_drvdata(input_dev, gp2a);
	input_dev->name = "light_sensor";
	input_set_capability(input_dev, EV_ABS, ABS_MISC);
	input_set_abs_params(input_dev, ABS_MISC, 0, 1, 0, 0);

	gp2a_dbgmsg("registering lightsensor-level input device\n");
	ret = input_register_device(input_dev);
	if (ret < 0) {
		pr_err("%s: could not register input device\n", __func__);
		input_free_device(input_dev);
		goto err_input_register_device_light;
	}

	gp2a->light_input_dev = input_dev;
	ret = sysfs_create_group(&input_dev->dev.kobj,
				&light_attribute_group);
	if (ret) {
		pr_err("%s: could not create sysfs group\n", __func__);
		goto err_sysfs_create_group_light;
	}

	/* alloc platform device for adc client */
	pdev_gp2a_adc = platform_device_alloc("gp2a-adc", -1);
	if (!pdev_gp2a_adc) {
		pr_err("%s: could not allocation pdev_gp2a_adc.\n", __func__);
		ret = -ENOMEM;
		goto err_platform_allocate_device_adc;
	}

	/* Register adc client */
	gp2a->padc = s3c_adc_register(pdev_gp2a_adc, NULL, NULL, 0);

	if (IS_ERR(gp2a->padc)) {
		dev_err(&pdev_gp2a_adc->dev, "cannot register adc\n");
		ret = PTR_ERR(gp2a->padc);
		goto err_platform_register_device_adc;
	}

	/* set sysfs for light sensor */

	ret = misc_register(&light_device);
	if (ret)
		pr_err(KERN_ERR "misc_register failed - light\n");

	gp2a->lightsensor_class = class_create(THIS_MODULE, "lightsensor");
	if (IS_ERR(gp2a->lightsensor_class))
		pr_err("Failed to create class(lightsensor)!\n");

	gp2a->switch_cmd_dev = device_create(gp2a->lightsensor_class,
		NULL, 0, NULL, "switch_cmd");
	if (IS_ERR(gp2a->switch_cmd_dev))
		pr_err("Failed to create device(switch_cmd_dev)!\n");

	if (device_create_file(gp2a->switch_cmd_dev,
		&dev_attr_lightsensor_file_illuminance) < 0)
		pr_err("Failed to create device file(%s)!\n",
			dev_attr_lightsensor_file_illuminance.attr.name);

	dev_set_drvdata(gp2a->switch_cmd_dev, gp2a);

/* new sysfs */
	ret = sensors_register(gp2a->light_dev, gp2a, light_sensor_attrs,
						"light_sensor");
	if (ret) {
		pr_err("%s: cound not register light sensor device(%d).\n",
		__func__, ret);
		goto out_light_sensor_register_failed;
	}

	ret = sensors_register(gp2a->proximity_dev,
			gp2a, proximity_sensor_attrs, "proximity_sensor");
	if (ret) {
		pr_err("%s: cound not register proximity sensor device(%d).\n",
		__func__, ret);
		goto out_proximity_sensor_register_failed;
	}

	/* set initial proximity value as 1 */
	gp2a->prox_value = 1;
	input_report_abs(gp2a->proximity_input_dev, ABS_DISTANCE, 1);
	input_sync(gp2a->proximity_input_dev);

	gp2a->adc_total = 0;

	goto done;

	/* error, unwind it all */
out_light_sensor_register_failed:
	sensors_unregister(gp2a->light_dev);
out_proximity_sensor_register_failed:
	sensors_unregister(gp2a->proximity_dev);

err_sysfs_create_group_light:
	input_unregister_device(gp2a->light_input_dev);
err_input_register_device_light:
err_input_allocate_device_light:
	destroy_workqueue(gp2a->wq);
err_platform_allocate_device_adc:
	platform_device_unregister(pdev_gp2a_adc);
err_platform_register_device_adc:
	s3c_adc_release(gp2a->padc);
err_create_workqueue:
	sysfs_remove_group(&gp2a->proximity_input_dev->dev.kobj,
			&proximity_attribute_group);
err_sysfs_create_group_proximity:
	input_unregister_device(gp2a->proximity_input_dev);
err_input_register_device_proximity:
err_input_allocate_device_proximity:
	free_irq(gp2a->irq, 0);
	gpio_free(gp2a->pdata->p_out);
err_setup_irq:
	mutex_destroy(&gp2a->adc_mutex);
	mutex_destroy(&gp2a->power_mutex);

	wake_lock_destroy(&gp2a->prx_wake_lock);
	kfree(gp2a);
done:
	return ret;
}
int cma3000_init(struct cma3000_accl_data *data)
{
	int ret = 0, fuzz_x, fuzz_y, fuzz_z, g_range;
	uint32_t irqflags;
	uint8_t ctrl;

	INIT_DELAYED_WORK(&data->input_work, cma3000_input_work_func);

	if (data->client->dev.platform_data == NULL) {
		dev_err(&data->client->dev, "platform data not found\n");
		goto err_op2_failed;
	}

	memcpy(&(data->pdata), data->client->dev.platform_data,
		sizeof(struct cma3000_platform_data));

	ret = cma3000_reset(data);
	if (ret)
		goto err_op2_failed;

	ret = cma3000_read(data, CMA3000_REVID, "Revid");
	if (ret < 0)
		goto err_op2_failed;

	pr_info("CMA3000 Acclerometer : Revision %x\n", ret);

	/* Bring it out of default power down state */
	ret = cma3000_poweron(data);
	if (ret < 0)
		goto err_op2_failed;

	data->req_poll_rate = data->pdata.def_poll_rate;
	fuzz_x = data->pdata.fuzz_x;
	fuzz_y = data->pdata.fuzz_y;
	fuzz_z = data->pdata.fuzz_z;
	g_range = data->pdata.g_range;
	irqflags = data->pdata.irqflags;

	data->input_dev = input_allocate_device();
	if (data->input_dev == NULL) {
		ret = -ENOMEM;
		dev_err(&data->client->dev,
			"Failed to allocate input device\n");
		goto err_op2_failed;
	}

	data->input_dev->name = "cma3000-acclerometer";

#ifdef CONFIG_INPUT_CMA3000_I2C
	data->input_dev->id.bustype = BUS_I2C;
#endif

	 __set_bit(EV_ABS, data->input_dev->evbit);
	 __set_bit(EV_MSC, data->input_dev->evbit);

	input_set_abs_params(data->input_dev, ABS_X, -g_range,
				g_range, fuzz_x, 0);
	input_set_abs_params(data->input_dev, ABS_Y, -g_range,
				g_range, fuzz_y, 0);
	input_set_abs_params(data->input_dev, ABS_Z, -g_range,
				g_range, fuzz_z, 0);
	input_set_abs_params(data->input_dev, ABS_MISC, 0,
				1, 0, 0);

	ret = input_register_device(data->input_dev);
	if (ret) {
		dev_err(&data->client->dev,
			"Unable to register input device\n");
		goto err_op2_failed;
	}

	mutex_init(&data->mutex);

	if (data->client->irq) {
		ret = request_irq(data->client->irq, cma3000_isr,
					irqflags | IRQF_ONESHOT,
					data->client->name, data);

		if (ret < 0) {
			dev_err(&data->client->dev,
				"request_threaded_irq failed\n");
			goto err_op1_failed;
		}
	} else {
		/*There is no IRQ set, disable IRQ on CMA*/
		ctrl = cma3000_read(data, CMA3000_CTRL, "Status");
		ctrl |= 0x1;
		cma3000_set(data, CMA3000_CTRL, ctrl, "Disable IRQ");
	}

	ret = sysfs_create_group(&data->client->dev.kobj, &cma3000_attr_group);
	if (ret) {
		dev_err(&data->client->dev,
			"failed to create sysfs entries\n");
		goto err_op1_failed;
	}

	cma3000_set_mode(data, CMAMODE_POFF);

	return 0;

err_op1_failed:
	mutex_destroy(&data->mutex);
	input_unregister_device(data->input_dev);
err_op2_failed:
	if (data != NULL) {
		if (data->input_dev != NULL)
			input_free_device(data->input_dev);
	}

	return ret;
}
static int __devinit tca6416_keypad_probe(struct i2c_client *client,
				   const struct i2c_device_id *id)
{
	struct tca6416_keys_platform_data *pdata;
	struct tca6416_keypad_chip *chip;
	struct input_dev *input;
	int error;
	int i;

	/* Check functionality */
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
		dev_err(&client->dev, "%s adapter not supported\n",
			dev_driver_string(&client->adapter->dev));
		return -ENODEV;
	}

	pdata = client->dev.platform_data;
	if (!pdata) {
		dev_dbg(&client->dev, "no platform data\n");
		return -EINVAL;
	}

	chip = kzalloc(sizeof(struct tca6416_keypad_chip) +
		       pdata->nbuttons * sizeof(struct tca6416_button),
		       GFP_KERNEL);
	input = input_allocate_device();
	if (!chip || !input) {
		error = -ENOMEM;
		goto fail1;
	}

	chip->client = client;
	chip->input = input;
	chip->pinmask = pdata->pinmask;
	chip->use_polling = pdata->use_polling;

	INIT_DELAYED_WORK(&chip->dwork, tca6416_keys_work_func);

	input->phys = "tca6416-keys/input0";
	input->name = client->name;
	input->dev.parent = &client->dev;

	input->open = tca6416_keys_open;
	input->close = tca6416_keys_close;

	input->id.bustype = BUS_HOST;
	input->id.vendor = 0x0001;
	input->id.product = 0x0001;
	input->id.version = 0x0100;

	/* Enable auto repeat feature of Linux input subsystem */
	if (pdata->rep)
		__set_bit(EV_REP, input->evbit);

	for (i = 0; i < pdata->nbuttons; i++) {
		unsigned int type;

		chip->buttons[i] = pdata->buttons[i];
		type = (pdata->buttons[i].type) ?: EV_KEY;
		input_set_capability(input, type, pdata->buttons[i].code);
	}

	input_set_drvdata(input, chip);

	/*
	 * Initialize cached registers from their original values.
	 * we can't share this chip with another i2c master.
	 */
	error = tca6416_setup_registers(chip);
	if (error)
		goto fail1;

	if (!chip->use_polling) {
		if (pdata->irq_is_gpio)
			chip->irqnum = gpio_to_irq(client->irq);
		else
			chip->irqnum = client->irq;

		error = request_threaded_irq(chip->irqnum, NULL,
					     tca6416_keys_isr,
					     IRQF_TRIGGER_FALLING,
					     "tca6416-keypad", chip);
		if (error) {
			dev_dbg(&client->dev,
				"Unable to claim irq %d; error %d\n",
				chip->irqnum, error);
			goto fail1;
		}
		disable_irq(chip->irqnum);
	}

	error = input_register_device(input);
	if (error) {
		dev_dbg(&client->dev,
			"Unable to register input device, error: %d\n", error);
		goto fail2;
	}

	i2c_set_clientdata(client, chip);

	return 0;

fail2:
	if (!chip->use_polling) {
		free_irq(chip->irqnum, chip);
		enable_irq(chip->irqnum);
	}
fail1:
	input_free_device(input);
	kfree(chip);
	return error;
}
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;
}
/*
 * Registers keypad device with input subsystem
 * and configures TWL4030 keypad registers
 */
static int __devinit twl4030_kp_probe(struct platform_device *pdev)
{
	u8 reg;
	int i;
	int ret = 0;
	struct twl4030_keypad *kp;
	struct twl4030_keypad_data *pdata = pdev->dev.platform_data;

	if (!pdata || !pdata->rows || !pdata->cols || !pdata->keymap
			|| pdata->rows > 8 || pdata->cols > 8) {
		dev_err(&pdev->dev, "Invalid platform_data\n");
		return -EINVAL;
	}

	kp = kzalloc(sizeof(*kp), GFP_KERNEL);
	if (!kp)
		return -ENOMEM;

	platform_set_drvdata(pdev, kp);

	/* Get the debug Device */
	kp->dbg_dev = &pdev->dev;

	kp->input = input_allocate_device();
	if (!kp->input) {
		kfree(kp);
		return -ENOMEM;
	}

	kp->keymap = pdata->keymap;
	kp->keymapsize = pdata->keymapsize;
	kp->n_rows = pdata->rows;
	kp->n_cols = pdata->cols;
	kp->irq = platform_get_irq(pdev, 0);

	/* setup input device */
	__set_bit(EV_KEY, kp->input->evbit);

	/* Enable auto repeat feature of Linux input subsystem */
	if (pdata->rep)
		__set_bit(EV_REP, kp->input->evbit);

	for (i = 0; i < kp->keymapsize; i++)
		__set_bit(kp->keymap[i] & KEYNUM_MASK,
				kp->input->keybit);

	kp->input->name		= "TWL4030 Keypad";
	kp->input->phys		= "twl4030_keypad/input0";
	kp->input->dev.parent	= &pdev->dev;

	kp->input->id.bustype	= BUS_HOST;
	kp->input->id.vendor	= 0x0001;
	kp->input->id.product	= 0x0001;
	kp->input->id.version	= 0x0003;

	kp->input->keycode	= kp->keymap;
	kp->input->keycodesize	= sizeof(unsigned int);
	kp->input->keycodemax	= kp->keymapsize;

	ret = input_register_device(kp->input);
	if (ret < 0) {
		dev_err(kp->dbg_dev,
			"Unable to register twl4030 keypad device\n");
		goto err2;
	}

	/* Enable controller, with hardware decoding but not autorepeat */
	reg = KEYP_CTRL_SOFT_NRST | KEYP_CTRL_SOFTMODEN
		| KEYP_CTRL_TOE_EN | KEYP_CTRL_KBD_ON;
	ret = twl4030_kpwrite_u8(kp, reg, KEYP_CTRL);
	if (ret < 0)
		goto err3;

	/* NOTE:  we could use sih_setup() here to package keypad
	 * event sources as four different IRQs ... but we don't.
	 */

	/* Enable TO rising and KP rising and falling edge detection */
	reg = KEYP_EDR_KP_BOTH | KEYP_EDR_TO_RISING;
	ret = twl4030_kpwrite_u8(kp, reg, KEYP_EDR);
	if (ret < 0)
		goto err3;

	/* Set PTV prescaler Field */
	reg = (PTV_PRESCALER << KEYP_LK_PTV_PTV_SHIFT);
	ret = twl4030_kpwrite_u8(kp, reg, KEYP_LK_PTV);
	if (ret < 0)
		goto err3;

	/* Set key debounce time to 20 ms */
	i = KEYP_PERIOD_US(20000, PTV_PRESCALER);
	ret = twl4030_kpwrite_u8(kp, i, KEYP_DEB);
	if (ret < 0)
		goto err3;

	/* Set timeout period to 100 ms */
	i = KEYP_PERIOD_US(200000, PTV_PRESCALER);
	ret = twl4030_kpwrite_u8(kp, (i & 0xFF), KEYP_TIMEOUT_L);
	if (ret < 0)
		goto err3;
	ret = twl4030_kpwrite_u8(kp, (i >> 8), KEYP_TIMEOUT_H);
	if (ret < 0)
		goto err3;

	/* Enable Clear-on-Read; disable remembering events that fire
	 * after the IRQ but before our handler acks (reads) them,
	 */
	reg = TWL4030_SIH_CTRL_COR_MASK | TWL4030_SIH_CTRL_PENDDIS_MASK;
	ret = twl4030_kpwrite_u8(kp, reg, KEYP_SIH_CTRL);
	if (ret < 0)
		goto err3;

	/* initialize key state; irqs update it from here on */
	ret = twl4030_read_kp_matrix_state(kp, kp->kp_state);
	if (ret < 0)
		goto err3;

	/*
	 * This ISR will always execute in kernel thread context because of
	 * the need to access the TWL4030 over the I2C bus.
	 *
	 * NOTE:  we assume this host is wired to TWL4040 INT1, not INT2 ...
	 */
	ret = request_irq(kp->irq, do_kp_irq, 0, pdev->name, kp);
	if (ret < 0) {
		dev_info(kp->dbg_dev, "request_irq failed for irq no=%d\n",
			kp->irq);
		goto err3;
	} else {
		/* Enable KP and TO interrupts now. */
		reg = (u8) ~(KEYP_IMR1_KP | KEYP_IMR1_TO);
		ret = twl4030_kpwrite_u8(kp, reg, KEYP_IMR1);
		if (ret < 0)
			goto err5;
	}

	return ret;
err5:
	/* mask all events - we don't care about the result */
	(void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1);
	free_irq(kp->irq, NULL);
err3:
	input_unregister_device(kp->input);
	kp->input = NULL;
err2:
	input_free_device(kp->input);
	kfree(kp);
	return -ENODEV;
}
Beispiel #21
0
static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(intf);
	struct usb_xpad *xpad;
	struct input_dev *input_dev;
	struct usb_endpoint_descriptor *ep_irq_in;
	int i;
	int error = -ENOMEM;

	for (i = 0; xpad_device[i].idVendor; i++) {
		if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
		    (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
			break;
	}

	xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!xpad || !input_dev)
		goto fail1;

	xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
				       GFP_KERNEL, &xpad->idata_dma);
	if (!xpad->idata)
		goto fail1;

	xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
	if (!xpad->irq_in)
		goto fail2;

	xpad->udev = udev;
	xpad->dpad_mapping = xpad_device[i].dpad_mapping;
	xpad->xtype = xpad_device[i].xtype;
	if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN)
		xpad->dpad_mapping = !dpad_to_buttons;
	if (xpad->xtype == XTYPE_UNKNOWN) {
		if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
			if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
				xpad->xtype = XTYPE_XBOX360W;
			else
				xpad->xtype = XTYPE_XBOX360;
		} else
			xpad->xtype = XTYPE_XBOX;
	}
	xpad->dev = input_dev;
	usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
	strlcat(xpad->phys, "/input0", sizeof(xpad->phys));

	input_dev->name = xpad_device[i].name;
	input_dev->phys = xpad->phys;
	usb_to_input_id(udev, &input_dev->id);
	input_dev->dev.parent = &intf->dev;

	input_set_drvdata(input_dev, xpad);

	input_dev->open = xpad_open;
	input_dev->close = xpad_close;

	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);

	/* set up buttons */
	for (i = 0; xpad_common_btn[i] >= 0; i++)
		set_bit(xpad_common_btn[i], input_dev->keybit);
	if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W))
		for (i = 0; xpad360_btn[i] >= 0; i++)
			set_bit(xpad360_btn[i], input_dev->keybit);
	else
		for (i = 0; xpad_btn[i] >= 0; i++)
			set_bit(xpad_btn[i], input_dev->keybit);
	if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS)
		for (i = 0; xpad_btn_pad[i] >= 0; i++)
			set_bit(xpad_btn_pad[i], input_dev->keybit);

	/* set up axes */
	for (i = 0; xpad_abs[i] >= 0; i++)
		xpad_set_up_abs(input_dev, xpad_abs[i]);
	if (xpad->dpad_mapping == MAP_DPAD_TO_AXES)
		for (i = 0; xpad_abs_pad[i] >= 0; i++)
		    xpad_set_up_abs(input_dev, xpad_abs_pad[i]);

	error = xpad_init_output(intf, xpad);
	if (error)
		goto fail2;

	error = xpad_init_ff(xpad);
	if (error)
		goto fail3;

	error = xpad_led_probe(xpad);
	if (error)
		goto fail3;

	ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
	usb_fill_int_urb(xpad->irq_in, udev,
			 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
			 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
			 xpad, ep_irq_in->bInterval);
	xpad->irq_in->transfer_dma = xpad->idata_dma;
	xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

	INIT_WORK(&xpad->submit_urb, xpad_do_submit_urb);

	error = input_register_device(xpad->dev);
	if (error)
		goto fail4;

	usb_set_intfdata(intf, xpad);

	xpad->interface_number = intf->cur_altsetting->desc.bInterfaceNumber;

	/*
	 * Submit the int URB immediatly rather than waiting for open
	 * because we get status messages from the device whether
	 * or not any controllers are attached.  In fact, it's
	 * exactly the message that a controller has arrived that
	 * we're waiting for.
	 */
	if (xpad->xtype == XTYPE_XBOX360W) {
		xpad->irq_in->dev = xpad->udev;
		error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
		if (error)
			goto fail4;
	}

	return 0;

 fail4:	cancel_work_sync(&xpad->submit_urb);
	usb_free_urb(xpad->irq_in);
 fail3:	xpad_deinit_output(xpad);
 fail2:	usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
 fail1:	input_free_device(input_dev);
	kfree(xpad);
	return error;

}
Beispiel #22
0
static int usbmouse_as_key_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
	struct usb_device *dev = interface_to_usbdev(intf);
	struct usb_host_interface *interface;
	struct usb_endpoint_descriptor *endpoint;

    int error = -ENOMEM;
    int pipe;

//    printk("Invoking usbmouse_as_key_probe function....\n");

//    printk("bcdUSB      = %x\n", dev->descriptor.bcdUSB);
//    printk("idVendor    = %x\n", dev->descriptor.idVendor);
//    printk("idProduct   = %x\n", dev->descriptor.idProduct);

	interface = intf->cur_altsetting;

	if (interface->desc.bNumEndpoints != 1)
		return -ENODEV;

	endpoint = &interface->endpoint[0].desc;

    /*  1. Allocate an input_dev structure */
    usbmouse_key_dev = input_allocate_device();
    
    /*  2. Configure this input_dev structure */
    /*  2.1 Which event will occur */
    set_bit(EV_KEY, usbmouse_key_dev->evbit);
    set_bit(EV_REP, usbmouse_key_dev->evbit);

    /*  2.2 In the specific event, which sub-event will occur */
    set_bit(KEY_L, usbmouse_key_dev->keybit);
    set_bit(KEY_S, usbmouse_key_dev->keybit);
    set_bit(KEY_ENTER, usbmouse_key_dev->keybit);
    
    /*  3. Register */
    error = input_register_device(usbmouse_key_dev);
    if(error) {
        input_free_device(usbmouse_key_dev);
        return error;
    }
    
    /*  4. Hardware specific configurations */
    /*  Focusing on the 3 major key elements of data transfer 
     *  a) Source  b) Destination c) Length
     */
    /* Source: one of the USB device endpoint */
	pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);

    /* Length:  */
    len = endpoint->wMaxPacketSize;

    /* Destination:  */
	usb_buffer = usb_alloc_coherent(dev, len, GFP_ATOMIC, &usb_buffer_phys);

    /* Use these 3 major key elements */
    /* Allocate urb ( USB Request Block ) */
	usbmouse_key_urb = usb_alloc_urb(0, GFP_KERNEL);    

    /* Use these 3 major key elements, configure this urb */
	usb_fill_int_urb(usbmouse_key_urb, dev, pipe, usb_buffer,
			 (len > 8 ? 8 : len),
			 usbmouse_as_key_irq, NULL, endpoint->bInterval);
	usbmouse_key_urb->transfer_dma = usb_buffer_phys;
	usbmouse_key_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

    /* Use URB */
	if (usb_submit_urb(usbmouse_key_urb, GFP_KERNEL))
		return -EIO;
    
    return 0;
}
static int gt801_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    struct gt801_ts_data *ts;
	struct gt801_platform_data	*pdata = client->dev.platform_data;
    int ret = 0;

    gt801printk("%s \n",__FUNCTION__);
	
    if (!pdata) {
		dev_err(&client->dev, "empty platform_data\n");
		goto err_check_functionality_failed;
    }
    if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
        printk(KERN_ERR "gt801_ts_probe: need I2C_FUNC_I2C\n");
        ret = -ENODEV;
        goto err_check_functionality_failed;
    }
	
    ts = kzalloc(sizeof(*ts), GFP_KERNEL);
    if (ts == NULL) {
        ret = -ENOMEM;
        goto err_alloc_data_failed;
    }
    INIT_WORK(&ts->work, gt801_ts_work_func);
    ts->client = client;
    i2c_set_clientdata(client, ts);

	ret = setup_resetPin(client,ts);
	if(ret)
	{
		 printk("%s:setup_resetPin fail\n",__FUNCTION__);
		 goto err_input_dev_alloc_failed;
	}
	
	ret=gt801_chip_Init(ts->client);
	if(ret<0)
	{
		printk("%s:chips init failed\n",__FUNCTION__);
		goto err_resetpin_failed;
	}
	
    /* allocate input device */
    ts->input_dev = input_allocate_device();
    if (ts->input_dev == NULL) {
        ret = -ENOMEM;
        printk(KERN_ERR "%s: Failed to allocate input device\n",__FUNCTION__);
        goto err_input_dev_alloc_failed;
    }
	
	ts->model = pdata->model ? : 801;
	ts->swap_xy = pdata->swap_xy;
	ts->x_min = pdata->x_min;
	ts->x_max = pdata->x_max;
	ts->y_min = pdata->y_min;
	ts->y_max = pdata->y_max;
	snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&client->dev));
	snprintf(ts->name, sizeof(ts->name), "gt%d-touchscreen", ts->model);
	ts->input_dev->phys = ts->phys;
	ts->input_dev->name = ts->name;
	ts->input_dev->dev.parent = &client->dev;

#if SINGLTOUCH_MODE
	ts->input_dev->evbit[0] = BIT_MASK(EV_ABS)|BIT_MASK(EV_KEY);
	ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
	input_set_abs_params(ts->input_dev,ABS_X,
		    ts->x_min ? : 0,
			ts->x_max ? : 480,
			0, 0);
	input_set_abs_params(ts->input_dev,ABS_Y,
			ts->y_min ? : 0,
			ts->y_max ? : 800,
			0, 0);

#else
    ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS);
  //  ts->input_dev->absbit[0] = 
	//	BIT(ABS_MT_POSITION_X) | BIT(ABS_MT_POSITION_Y) | 
	//	BIT(ABS_MT_TOUCH_MAJOR) | BIT(ABS_MT_WIDTH_MAJOR);  // for android
    input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 
		    ts->x_min ? : 0,
			ts->x_max ? : 480,
			0, 0);
    input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y,
			ts->y_min ? : 0,
			ts->y_max ? : 800,
			0, 0);
    input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0); //Finger Size
    input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 10, 0, 0); //Touch Size
#endif
    ret = input_register_device(ts->input_dev);
    if (ret) {
        printk(KERN_ERR "%s: Unable to register %s input device\n", __FUNCTION__,ts->input_dev->name);
        goto err_input_register_device_failed;
    }
	
	client->irq = gpio_to_irq(client->irq);
    if (client->irq) {
		ret = setup_pendown(client,ts);
		if(ret)
		{
			 printk("%s:setup_pendown fail\n",__FUNCTION__);
			 goto err_input_register_device_failed;
		}
		
        ret = request_irq(client->irq, gt801_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, client->name, ts);
        if (ret == 0) {
            gt801printk("%s:register ISR (irq=%d)\n", __FUNCTION__,client->irq);
            ts->use_irq = 1;
        }
        else 
			dev_err(&client->dev, "request_irq failed\n");
    }

    if (!ts->use_irq) {
        hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        ts->timer.function = gt801_ts_timer_func;
        hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
    }
#ifdef CONFIG_HAS_EARLYSUSPEND
    ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    ts->early_suspend.suspend = gt801_ts_early_suspend;
    ts->early_suspend.resume = gt801_ts_late_resume;
    register_early_suspend(&ts->early_suspend);
#endif

    printk(KERN_INFO "%s: Start touchscreen %s in %s mode\n", __FUNCTION__,ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");

    return 0;

err_input_register_device_failed:
    input_free_device(ts->input_dev);
err_resetpin_failed:
	gpio_free(ts->gpio_reset);
err_input_dev_alloc_failed:
	kfree(ts);
err_alloc_data_failed:
err_check_functionality_failed:
	
    return ret;
}
static int __devinit lsm303dlhc_mag_probe(struct i2c_client *client,
        const struct i2c_device_id *id)
{
    struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
    struct lsm303dlhc_mag_platform_data *pdata = client->dev.platform_data;
    struct lsm303dlhc_mag_data *mag;
    int result = 0;

    dev_info(&client->dev, "%s \n", __func__);

    if (!pdata) {
        result = -EINVAL;
        dev_err(&client->dev, "%s: platform data required.\n",
                __func__);
        goto err_no_platform_data;
    }
    mag = kzalloc(sizeof(*mag), GFP_KERNEL);
    if (NULL == mag) {
        result = -ENOMEM;
        goto err_alloc_data_failed;
    }
    mag->client = client;
    mag->poll_interval_ms = pdata->poll_interval_ms;
    mag->range = pdata->range;
    dev_info(&client->dev, "%s:pdata->range:%d\n", __func__, pdata->range);
    i2c_set_clientdata(client, mag);
    if (pdata->power_on)
        mag->power_on = pdata->power_on;
    else
        mag->power_on = lsm303dlhc_mag_power_stub;
    if (pdata->power_off)
        mag->power_off = pdata->power_off;
    else
        mag->power_off = lsm303dlhc_mag_power_stub;
    mag->power_on();
    lsm303dlhc_mag_config_regulator( mag , true);
    msleep(500);
    if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
        result = -EIO;
        goto err_check_functionality;
    }
    result = i2c_smbus_write_byte_data(client, MR_REG_M, IDLE_MODE);
    mag->power_off();
    lsm303dlhc_mag_config_regulator( mag , false);
    if (result) {
        dev_err(&client->dev, "%s: Device not responding.\n",
                __func__);
        goto err_not_responding;
    }
    INIT_DELAYED_WORK(&mag->work, lsm303dlhc_mag_poll_func);
    mutex_init(&mag->lock);

    mag->dev = sensors_classdev_register("magnetometer");

    result = create_sysfs_interfaces(mag->dev);
    if (result)
        goto err_sys_attr;
    dev_set_drvdata(mag->dev, mag);
    mag->input_dev = input_allocate_device();
    if (!mag->input_dev) {
        dev_err(&client->dev, "%s: input_allocate_device failed\n",
                __func__);
        result = -ENOMEM;
        goto err_allocate_device;
    }
    input_set_drvdata(mag->input_dev, mag);

    mag->input_dev->name = "magnetometer";
    set_bit(EV_ABS, mag->input_dev->evbit);
    set_bit(ABS_X, mag->input_dev->absbit);
    set_bit(ABS_Y, mag->input_dev->absbit);
    set_bit(ABS_Z, mag->input_dev->absbit);
    input_set_abs_params(mag->input_dev, ABS_X, -MAG_RANGE_MG,
                         MAG_RANGE_MG - 1, 0, 0);
    input_set_abs_params(mag->input_dev, ABS_Y, -MAG_RANGE_MG,
                         MAG_RANGE_MG - 1, 0, 0);
    input_set_abs_params(mag->input_dev, ABS_Z, -MAG_RANGE_MG,
                         MAG_RANGE_MG - 1, 0, 0);

    result = input_register_device(mag->input_dev);
    if (result) {
        dev_err(&client->dev, "%s: input_register_device failed!",
                __func__);
        goto err_register_device;
    }
    dev_set_drvdata(&mag->input_dev->dev, mag);

    if (device_create_file(&mag->input_dev->dev,
                           &dev_attr_enable) < 0) {
        pr_err("%s: Failed to create device file(%s)!\n", __func__,
               dev_attr_enable.attr.name);
        goto err_check_functionality;
    }

    mag->irq_m = pdata->irq_m;
    if (mag->irq_m > 0) { /* interrupt */

        mag->interruptible = true;
        result = request_threaded_irq(gpio_to_irq(mag->irq_m), NULL,
                                      lsm303dlhc_m_gpio_irq,
                                      IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "lsm303dlhc_m",
                                      mag);
        if (result) {
            dev_err(&client->dev, "request irq EGPIO_PIN_1 failed\n");
            goto err_check_functionality;
        }

        disable_irq(gpio_to_irq(mag->irq_m));
    }
    mag->interruptible = false;
    dev_info(&client->dev, "%s mag->interruptible=%d completed.\n", __func__, mag->interruptible);
    return 0;

err_register_device:
    input_free_device(mag->input_dev);
err_allocate_device:
    remove_sysfs_interfaces(mag->dev);
err_sys_attr:
err_not_responding:
    kfree(mag);
err_alloc_data_failed:
err_no_platform_data:
err_check_functionality:
    dev_err(&client->dev, "%s failed.\n", __func__);
    return result;
}
Beispiel #25
0
static int gpio_event_probe(struct platform_device *pdev)
{
	int err;
	struct gpio_event *ip;
	struct gpio_event_platform_data *event_info;
	int dev_count = 1;
	int i;
	int registered = 0;

	event_info = pdev->dev.platform_data;
	if (event_info == NULL) {
		pr_err("gpio_event_probe: No pdata\n");
		return -ENODEV;
	}
	if ((!event_info->name && !event_info->names[0]) ||
	    !event_info->info || !event_info->info_count) {
		pr_err("gpio_event_probe: Incomplete pdata\n");
		return -ENODEV;
	}
	if (!event_info->name)
		while (event_info->names[dev_count])
			dev_count++;
	ip = kzalloc(sizeof(*ip) +
		     sizeof(ip->state[0]) * event_info->info_count +
		     sizeof(*ip->input_devs) +
		     sizeof(ip->input_devs->dev[0]) * dev_count, GFP_KERNEL);
	if (ip == NULL) {
		err = -ENOMEM;
		pr_err("gpio_event_probe: Failed to allocate private data\n");
		goto err_kp_alloc_failed;
	}
	ip->input_devs = (void*)&ip->state[event_info->info_count];
	platform_set_drvdata(pdev, ip);

	for (i = 0; i < dev_count; i++) {
		struct input_dev *input_dev = input_allocate_device();
		if (input_dev == NULL) {
			err = -ENOMEM;
			pr_err("gpio_event_probe: "
				"Failed to allocate input device\n");
			goto err_input_dev_alloc_failed;
		}
		input_set_drvdata(input_dev, ip);
		input_dev->name = event_info->name ?
					event_info->name : event_info->names[i];
		input_dev->event = gpio_input_event;
		ip->input_devs->dev[i] = input_dev;
	}
	ip->input_devs->count = dev_count;
	ip->info = event_info;
	if (event_info->power) {
#ifdef CONFIG_HAS_EARLYSUSPEND
		ip->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
		ip->early_suspend.suspend = gpio_event_suspend;
		ip->early_suspend.resume = gpio_event_resume;
		register_early_suspend(&ip->early_suspend);
#endif
		ip->info->power(ip->info, 1);
	}

	err = gpio_event_call_all_func(ip, GPIO_EVENT_FUNC_INIT);
	if (err)
		goto err_call_all_func_failed;

	for (i = 0; i < dev_count; i++) {
		err = input_register_device(ip->input_devs->dev[i]);
		if (err) {
			pr_err("gpio_event_probe: Unable to register %s "
				"input device\n", ip->input_devs->dev[i]->name);
			goto err_input_register_device_failed;
		}
		registered++;
	}

#if defined(CONFIG_MACH_VASTO)
	/* sys fs */
	key_class = class_create(THIS_MODULE, "key");
	if (IS_ERR(key_class))
		pr_err("Failed to create class(key)!\n");

	key_dev = device_create(key_class, NULL, 0, NULL, "key");
	if (IS_ERR(key_dev))
		pr_err("Failed to create device(key)!\n");

	if (device_create_file(key_dev, &dev_attr_key) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_key.attr.name); 
	/* sys fs */
#endif
	return 0;

err_input_register_device_failed:
	gpio_event_call_all_func(ip, GPIO_EVENT_FUNC_UNINIT);
err_call_all_func_failed:
	if (event_info->power) {
#ifdef CONFIG_HAS_EARLYSUSPEND
		unregister_early_suspend(&ip->early_suspend);
#endif
		ip->info->power(ip->info, 0);
	}
	for (i = 0; i < registered; i++)
		input_unregister_device(ip->input_devs->dev[i]);
	for (i = dev_count - 1; i >= registered; i--) {
		input_free_device(ip->input_devs->dev[i]);
err_input_dev_alloc_failed:
		;
	}
	kfree(ip);
err_kp_alloc_failed:
	return err;
}
Beispiel #26
0
static int max1462x_hsd_probe(struct platform_device *pdev)
{
	struct max1462x_platform_data *pdata = pdev->dev.platform_data;
	struct max1462x_hsd_info *hi;
	struct qpnp_vadc_result result;
	int acc_read_value = 0;
	int i;
	int adc_read_count = 3;
	int ret = 0;

	pr_debug("%s\n", __func__);

	if (pdev->dev.of_node) {
		pdata = devm_kzalloc(&pdev->dev,
				sizeof(struct max1462x_platform_data),
				GFP_KERNEL);
		if (!pdata) {
			pr_err("%s: Failed to allocate memory\n", __func__);
			return -ENOMEM;
		}
		pdev->dev.platform_data = pdata;
		max1462x_parse_dt(&pdev->dev, pdata);
	} else {
		pdata = pdev->dev.platform_data;
		if (!pdata) {
			pr_err("%s: No pdata\n", __func__);
			return -ENODEV;
		}
	}

	local_max1462x_workqueue = create_workqueue("max1462x");
	if (!local_max1462x_workqueue) {
		pr_err("%s: Failed to create_workqueue\n", __func__);
		return -ENOMEM;
	}

	wake_lock_init(&ear_hook_wake_lock, WAKE_LOCK_SUSPEND, "ear_hook");

	hi = kzalloc(sizeof(struct max1462x_hsd_info), GFP_KERNEL);
	if (!hi) {
		pr_err("%s: Failed to allloate memory for device info\n",
				__func__);
		ret = -ENOMEM;
		goto err_kzalloc;
	}

	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_mic_en = pdata->gpio_mic_en;
	hi->gpio_detect = pdata->gpio_detect;
	hi->gpio_key = pdata->gpio_key;

	hi->latency_for_key = msecs_to_jiffies(50); /* convert ms to jiffies */
	mutex_init(&hi->mutex_lock);
	INIT_WORK(&hi->work, max1462x_detect_work);
	INIT_DELAYED_WORK(&hi->work_for_key_pressed, max1462x_button_pressed);
	INIT_DELAYED_WORK(&hi->work_for_key_released, max1462x_button_released);

	/* init gpio_mic_en & set default value */
	ret = gpio_request_one(hi->gpio_mic_en, GPIOF_OUT_INIT_HIGH,
			"gpio_mic_en");
	if (ret < 0) {
		pr_err("%s: Failed to configure gpio%d(gpio_mic_en)n",
			__func__, hi->gpio_mic_en);
		goto err_gpio_mic_en;
	}
	pr_debug("gpio_get_value_cansleep(hi->gpio_mic_en)=%d\n",
		gpio_get_value_cansleep(hi->gpio_mic_en));

	/* init gpio_detect */
	ret = gpio_request_one(hi->gpio_detect, GPIOF_IN, "gpio_detect");
	if (ret < 0) {
		pr_err("%s: Failed to configure gpio%d(gpio_det)\n",
			__func__, hi->gpio_detect);
		goto err_gpio_detect;
	}

	/* init gpio_key */
	ret = gpio_request_one(hi->gpio_key, GPIOF_IN, "gpio_key");
	if (ret < 0) {
		pr_err("%s: Failed to configure gpio%d(gpio_key)\n",
			__func__, hi->gpio_key);
		goto err_gpio_key;
	}

	ret = gpio_to_irq(hi->gpio_detect);
	if (ret < 0) {
		pr_err("%s: Failed to get interrupt number\n", __func__);
		goto err_irq_detect;
	}
	hi->irq_detect = ret;
	pr_debug("%s: hi->irq_detect = %d\n", __func__, hi->irq_detect);

	ret = request_threaded_irq(hi->irq_detect, NULL,
				max1462x_earjack_det_irq_handler,
				IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,
				pdev->name, hi);
	if (ret < 0) {
		pr_err("%s: failed to request button irq\n", __func__);
		goto err_irq_detect_request;
	}

	ret = enable_irq_wake(hi->irq_detect);
	if (ret < 0) {
		pr_err("%s: Failed to set gpio_detect interrupt wake\n",
			__func__);
		goto err_irq_detect_wake;
	}

	/* initialize irq of gpio_key */
	ret = gpio_to_irq(hi->gpio_key);
	if (ret < 0) {
		pr_err("%s: Failed to get interrupt number\n", __func__);
		goto err_irq_key;
	}
	hi->irq_key = ret;
	pr_debug("%s: hi->irq_key = %d\n", __func__, hi->irq_key);

	ret = request_threaded_irq(hi->irq_key, NULL,
			max1462x_button_irq_handler,
			IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING,
			pdev->name, hi);
	if (ret < 0) {
		pr_err("%s: failed to request button irq\n", __func__);
		goto err_irq_key_request;
	}

        disable_irq(hi->irq_key);
        atomic_set(&hi->irq_key_enabled, false);

        /* initialize switch device */
	hi->sdev.name = pdata->switch_name;
	hi->sdev.print_state = max1462x_hsd_print_state;
	hi->sdev.print_name = max1462x_hsd_print_name;

	ret = switch_dev_register(&hi->sdev);
	if (ret < 0) {
		pr_err("%s: Failed to register switch device\n", __func__);
		goto err_switch_dev_register;
	}

	/* initialize input device */
	hi->input = input_allocate_device();
	if (!hi->input) {
		pr_err("%s: Failed to allocate input device\n", __func__);
		ret = -ENOMEM;
		goto err_input_allocate_device;
	}

	hi->input->name = pdata->keypad_name;
	hi->input->id.vendor    = 0x0001;
	hi->input->id.product   = 1;
	hi->input->id.version   = 1;

	/* headset tx noise */
	for (i = 0; i < adc_read_count; i++) {
		ret = qpnp_vadc_read(ADC_PORT_NUM, &result);
		if (ret < 0) {
			if (ret == -ETIMEDOUT)
				pr_warn("%s: warning: adc read timeout \n",
						__func__);
			else
				pr_warn("%s: warning: adc read error - %d\n",
						__func__, ret);
		} else {
			acc_read_value = (int)result.physical;
			pr_info("%s: acc_read_value - %d\n", __func__,
				acc_read_value);
			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);
	input_set_capability(hi->input, EV_SW, SW_HEADPHONE_INSERT);
	input_set_capability(hi->input, EV_SW, SW_MICROPHONE_INSERT);

	ret = input_register_device(hi->input);
	if (ret < 0) {
		pr_err("%s: Failed to register input device\n", __func__);
		goto err_input_register_device;
	}

	/* to detect in initialization with eacjack insertion */
	if (!(gpio_get_value(hi->gpio_detect)))
		queue_work(local_max1462x_workqueue, &(hi->work));

	return ret;

err_input_register_device:
	input_free_device(hi->input);
err_input_allocate_device:
	switch_dev_unregister(&hi->sdev);
err_switch_dev_register:
        free_irq(hi->irq_key, hi);
err_irq_key_request:
err_irq_key:
err_irq_detect_wake:
	free_irq(hi->irq_detect, hi);
err_irq_detect_request:
err_irq_detect:
	gpio_free(hi->gpio_key);
err_gpio_key:
	gpio_free(hi->gpio_detect);
err_gpio_detect:
	gpio_free(hi->gpio_mic_en);
err_gpio_mic_en:
	mutex_destroy(&hi->mutex_lock);
	kfree(hi);
err_kzalloc:
	destroy_workqueue(local_max1462x_workqueue);
	local_max1462x_workqueue = NULL;
	return ret;
}
Beispiel #27
0
static int mpr_touchkey_probe(struct i2c_client *client,
			      const struct i2c_device_id *id)
{
	const struct mpr121_platform_data *pdata =
			dev_get_platdata(&client->dev);
	struct mpr121_touchkey *mpr121;
	struct input_dev *input_dev;
	int error;
	int i;

	if (!pdata) {
		dev_err(&client->dev, "no platform data defined\n");
		return -EINVAL;
	}

	if (!pdata->keymap || !pdata->keymap_size) {
		dev_err(&client->dev, "missing keymap data\n");
		return -EINVAL;
	}

	if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) {
		dev_err(&client->dev, "too many keys defined\n");
		return -EINVAL;
	}

	if (!client->irq) {
		dev_err(&client->dev, "irq number should not be zero\n");
		return -EINVAL;
	}

	mpr121 = kzalloc(sizeof(struct mpr121_touchkey), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!mpr121 || !input_dev) {
		dev_err(&client->dev, "Failed to allocate memory\n");
		error = -ENOMEM;
		goto err_free_mem;
	}

	mpr121->client = client;
	mpr121->input_dev = input_dev;
	mpr121->keycount = pdata->keymap_size;

	input_dev->name = "Freescale MPR121 Touchkey";
	input_dev->id.bustype = BUS_I2C;
	input_dev->dev.parent = &client->dev;
	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);

	input_dev->keycode = mpr121->keycodes;
	input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
	input_dev->keycodemax = mpr121->keycount;

	for (i = 0; i < pdata->keymap_size; i++) {
		input_set_capability(input_dev, EV_KEY, pdata->keymap[i]);
		mpr121->keycodes[i] = pdata->keymap[i];
	}

	error = mpr121_phys_init(pdata, mpr121, client);
	if (error) {
		dev_err(&client->dev, "Failed to init register\n");
		goto err_free_mem;
	}

	error = request_threaded_irq(client->irq, NULL,
				     mpr_touchkey_interrupt,
				     IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
				     client->dev.driver->name, mpr121);
	if (error) {
		dev_err(&client->dev, "Failed to register interrupt\n");
		goto err_free_mem;
	}

	error = input_register_device(input_dev);
	if (error)
		goto err_free_irq;

	i2c_set_clientdata(client, mpr121);
	device_init_wakeup(&client->dev, pdata->wakeup);

	return 0;

err_free_irq:
	free_irq(client->irq, mpr121);
err_free_mem:
	input_free_device(input_dev);
	kfree(mpr121);
	return error;
}
Beispiel #28
0
/*******************************************************	
功能:
	触摸屏探测函数
	在注册驱动时调用(要求存在对应的client);
	用于IO,中断等资源申请;设备注册;触摸屏初始化等工作
参数:
	client:待驱动的设备结构体
	id:设备ID
return:
	执行结果码,0表示正常执行
********************************************************/
static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	struct goodix_ts_data *ts;
	int ret = 0;
	int retry=0;
	int count=0;
FNC_ENTERY;
	struct goodix_i2c_platform_data *pdata;
	dev_dbg(&client->dev,"Install touchscreen driver for guitar.\n");

	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 
	{
		dev_err(&client->dev, "System need I2C function.\n");
		ret = -ENODEV;
		goto err_check_functionality_failed;
	}
        
	if (!(((board_version == 1)&&(hw_version == 0))||(board_version == 0)))
        {
		printk("%s: system hardware version:%d, GOODIX touchscreen is unsupported!!!\n", __func__, hw_version);
		ret = -1;
		goto err_check_functionality_failed;
	}
	
	ts = kzalloc(sizeof(*ts), GFP_KERNEL);
	if (ts == NULL) {
		ret = -ENOMEM;
		goto err_alloc_data_failed;
	}

	/* 获取预定义资源 */
	pdata = client->dev.platform_data;
	if(pdata != NULL) {
		//ts->gpio_shutdown = pdata->gpio_shutdown;
		//ts->gpio_irq = pdata->gpio_irq;
		
		//use as s3c_gpio_cfgpin(ts->gpio_shutdown, pdata->shutdown_cfg);		/* output */
	}
	
#ifdef SHUTDOWN_PORT	
	ts->gpio_shutdown = SHUTDOWN_PORT;
	if(ts->gpio_shutdown)
	{
		//ret = gpio_request(ts->gpio_shutdown, "TS_SHUTDOWN");	//Request IO
		if (ret < 0) 
		{
			printk(KERN_ALERT "Failed to request GPIO:%d, ERRNO:%d\n", ts->gpio_shutdown, ret);
			goto err_gpio_request;
		}	
		gpio_direction_output(ts->gpio_shutdown, 0);	//Touchscreen is waiting to wake up
		ret = gpio_get_value(ts->gpio_shutdown);
		if (ret)
		{
			printk(KERN_ALERT  "Cannot set touchscreen to work.\n");
			goto err_i2c_failed;
		}
		ts->use_shutdown = 1;
		msleep(25);		//waiting for initialization of Guitar.
	}
#endif		
	RESETPIN_CFG;
	RESETPIN_SET1;
	mdelay(200);
	RESETPIN_SET0;
	mdelay(200);

	i2c_connect_client = client;				//used by Guitar Updating.
	//TODO: used to set speed of i2c transfer. Must change as your paltform.
//	s3c24xx_set_i2c_clockrate(client->adapter, 250, &count);	//set i2c <=250kHz
	dev_dbg(&client->dev, "i2c set frequency:%dkHz.\n", count);
#if 0
	for(retry=0; retry < 5; retry++)
	{
		
	ret=i2c_read_bytes(ts->client,version_data, GT80X_VERSION_LENGTH);
		ret =i2c_write_bytes(client, NULL, 0);	//Test i2c.
		if (ret > 0)
			break;
	}
	if(ret < 0)
	{
		dev_err(&client->dev, "Warnning: I2C connection might be something wrong!\n");
		goto err_i2c_failed;
	}
#endif
	if(ts->use_shutdown)
		gpio_set_value(ts->gpio_shutdown, 1);		//suspend
	
	INIT_WORK(&ts->work, goodix_ts_work_func);
	ts->client = client;
	i2c_set_clientdata(client, ts);
	pdata = client->dev.platform_data;
	
	ts->input_dev = input_allocate_device();
	if (ts->input_dev == NULL) {
		ret = -ENOMEM;
		dev_dbg(&client->dev,"Failed to allocate input device\n");
		goto err_input_dev_alloc_failed;
	}

	ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
#ifndef GOODIX_MULTI_TOUCH	
	ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
	ts->input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);

	input_set_abs_params(ts->input_dev, ABS_X, 0, SCREEN_MAX_HEIGHT, 0, 0);
	input_set_abs_params(ts->input_dev, ABS_Y, 0, SCREEN_MAX_WIDTH, 0, 0);
	input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, 0, 0);	
#else
	//ts->input_dev->absbit[0] = BIT_MASK(ABS_MT_TRACKING_ID) |
	ts->input_dev->absbit[0] = 
		BIT_MASK(ABS_MT_TOUCH_MAJOR)| BIT_MASK(ABS_MT_WIDTH_MAJOR) |
  		BIT_MASK(ABS_MT_POSITION_X) | BIT_MASK(ABS_MT_POSITION_Y); 	// for android
	input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
	input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
	input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_HEIGHT, 0, 0);
	input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_WIDTH, 0, 0);	
	//input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, MAX_FINGER_NUM-1, 0, 0);	
#endif	

	sprintf(ts->phys, "input/ts)");
	ts->input_dev->name = s3c_ts_name;
	ts->input_dev->phys = ts->phys;
	ts->input_dev->id.bustype = BUS_I2C;
	ts->input_dev->id.vendor = 0xDEAD;
	ts->input_dev->id.product = 0xBEEF;
	ts->input_dev->id.version = 0x1103;	

	finger_list.length = 0;
	ret = input_register_device(ts->input_dev);
	if (ret) {
		dev_err(&client->dev,"Probe: Unable to register %s input device\n", ts->input_dev->name);
		goto err_input_register_device_failed;
	}

	ts->use_irq = 1;
	//ts->use_irq = 0;
	ts->retry = 0;
	ts->bad_data = 0;

#if defined(INT_PORT)	
	ts->gpio_irq = INT_PORT;
	client->irq=TS_INT; //If not define in client
	if (client->irq)
	{
	
#ifdef CONFIG_MACH_EMEV
				writel(readl(CHG_PULL1)|0xC000, CHG_PULL1);
				gpio_direction_input(irq_to_gpio(client->irq));
#endif
		//ret = gpio_request(ts->gpio_irq, "TS_INT");	//Request IO
		if (ret < 0) 
		{
			dev_err(&client->dev, "Failed to request GPIO:%d, ERRNO:%d\n", ts->gpio_irq, ret);
			goto err_int_request_failed;
		}
//		ret = s3c_gpio_cfgpin(ts->gpio_irq, INT_CFG);	//Set IO port function
		ret  = request_irq(client->irq, goodix_ts_irq_handler ,  IRQ_TYPE_EDGE_RISING,
			"GoodixIRQ", ts);
		if (ret != 0) {
			dev_err(&client->dev,"Can't allocate touchscreen's interrupt%d!ERRNO:%d\n",client->irq, ret);
			gpio_direction_input(ts->gpio_irq);
			gpio_free(ts->gpio_irq);
			goto err_int_request_failed;
		}
		else 
		{	
			disable_irq(client->irq);
			ts->use_irq = 1;
			dev_dbg(&client->dev,"Reques EIRQ %d succesd on GPIO:%d\n",client->irq, ts->gpio_irq);
		}
	}
#endif

err_int_request_failed:	
	if (!ts->use_irq) 
	{
		hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
		ts->timer.function = goodix_ts_timer_func;
		hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
	}

	flush_workqueue(goodix_wq);
	if(ts->use_shutdown)
	{		
		gpio_set_value(ts->gpio_shutdown, 0);	
	#ifdef SHUTDOWN_PORT	
		ts->power = goodix_ts_power;
	#endif
		msleep(30);
	}	
	
	ret = goodix_init_panel(ts);
	if(ret != 0) 
		goto err_init_godix_ts;
	if(ts->use_irq)
		enable_irq(client->irq);
	
	goodix_read_version(ts);
	//msleep(500);
	
#ifdef CONFIG_HAS_EARLYSUSPEND
	ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	ts->early_suspend.suspend = goodix_ts_early_suspend;
	ts->early_suspend.resume = goodix_ts_late_resume;
	register_early_suspend(&ts->early_suspend);
#endif
	dev_dbg(&client->dev,"Start  %s in %s mode\n", 
		ts->input_dev->name, ts->use_irq ? "Interrupt" : "Polling");
	return 0;

err_init_godix_ts:
	if(ts->use_irq)
	{
		free_irq(client->irq,ts);	
		gpio_free(ts->gpio_irq);
	}

err_input_register_device_failed:
	input_free_device(ts->input_dev);

err_input_dev_alloc_failed:
	i2c_set_clientdata(client, NULL);
err_i2c_failed:
	if(ts->use_shutdown)
	{
		gpio_direction_input(ts->gpio_shutdown);
		gpio_free(ts->gpio_shutdown);
	}
err_gpio_request:
	kfree(ts);
err_alloc_data_failed:
err_check_functionality_failed:
	return ret;
}
Beispiel #29
0
static int __devinit hs_probe(struct platform_device *pdev)
{
	int rc = 0;
	struct input_dev *ipdev;

	hs = kzalloc(sizeof(struct msm_handset), GFP_KERNEL);
	if (!hs)
		return -ENOMEM;

	hs->sdev.name	= "h2w";
	hs->sdev.print_name = msm_headset_print_name;

	rc = switch_dev_register(&hs->sdev);
	if (rc)
		goto err_switch_dev_register;

	ipdev = input_allocate_device();
	if (!ipdev) {
		rc = -ENOMEM;
		goto err_alloc_input_dev;
	}
	input_set_drvdata(ipdev, hs);

	hs->ipdev = ipdev;

	if (pdev->dev.platform_data)
		hs->hs_pdata = pdev->dev.platform_data;

	if (hs->hs_pdata->hs_name)
		ipdev->name = hs->hs_pdata->hs_name;
	else
		ipdev->name	= DRIVER_NAME;

	ipdev->id.vendor	= 0x0001;
	ipdev->id.product	= 1;
	ipdev->id.version	= 1;

	input_set_capability(ipdev, EV_KEY, KEY_MEDIA);
	input_set_capability(ipdev, EV_KEY, KEY_VOLUMEUP);
	input_set_capability(ipdev, EV_KEY, KEY_VOLUMEDOWN);
	input_set_capability(ipdev, EV_SW, SW_HEADPHONE_INSERT);
	input_set_capability(ipdev, EV_KEY, KEY_POWER);
	input_set_capability(ipdev, EV_KEY, KEY_END);
	
	#if 0
	
	input_set_capability(ipdev, EV_KEY, KEY_HEADSETHOOK);
	#endif

	rc = input_register_device(ipdev);
	if (rc) {
		dev_err(&ipdev->dev,
				"hs_probe: input_register_device rc=%d\n", rc);
		goto err_reg_input_dev;
	}

	platform_set_drvdata(pdev, hs);

	rc = hs_rpc_init();
	if (rc) {
		dev_err(&ipdev->dev, "rpc init failure\n");
		goto err_hs_rpc_init;
	}

	return 0;

err_hs_rpc_init:
	input_unregister_device(ipdev);
	ipdev = NULL;
err_reg_input_dev:
	input_free_device(ipdev);
err_alloc_input_dev:
	switch_dev_unregister(&hs->sdev);
err_switch_dev_register:
	kfree(hs);
	return rc;
}
static int __devinit rotary_encoder_probe(struct platform_device *pdev)
{
	struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data;
	struct rotary_encoder *encoder;
	struct input_dev *input;
	int err;

	if (!pdata || !pdata->steps) {
		dev_err(&pdev->dev, "invalid platform data\n");
		return -ENOENT;
	}

	encoder = kzalloc(sizeof(struct rotary_encoder), GFP_KERNEL);
	input = input_allocate_device();
	if (!encoder || !input) {
		dev_err(&pdev->dev, "failed to allocate memory for device\n");
		err = -ENOMEM;
		goto exit_free_mem;
	}

	encoder->input = input;
	encoder->pdata = pdata;
	encoder->irq_a = gpio_to_irq(pdata->gpio_a);
	encoder->irq_b = gpio_to_irq(pdata->gpio_b);

	/* create and register the input driver */
	input->name = pdev->name;
	input->id.bustype = BUS_HOST;
	input->dev.parent = &pdev->dev;
	input->evbit[0] = BIT_MASK(EV_ABS);
	input_set_abs_params(encoder->input,
			     pdata->axis, 0, pdata->steps, 0, 1);

	err = input_register_device(input);
	if (err) {
		dev_err(&pdev->dev, "failed to register input device\n");
		goto exit_free_mem;
	}

	/* request the GPIOs */
	err = gpio_request(pdata->gpio_a, DRV_NAME);
	if (err) {
		dev_err(&pdev->dev, "unable to request GPIO %d\n",
			pdata->gpio_a);
		goto exit_unregister_input;
	}

	err = gpio_request(pdata->gpio_b, DRV_NAME);
	if (err) {
		dev_err(&pdev->dev, "unable to request GPIO %d\n",
			pdata->gpio_b);
		goto exit_free_gpio_a;
	}

	/* request the IRQs */
	err = request_irq(encoder->irq_a, &rotary_encoder_irq,
			  IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
			  DRV_NAME, encoder);
	if (err) {
		dev_err(&pdev->dev, "unable to request IRQ %d\n",
			encoder->irq_a);
		goto exit_free_gpio_b;
	}

	err = request_irq(encoder->irq_b, &rotary_encoder_irq,
			  IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
			  DRV_NAME, encoder);
	if (err) {
		dev_err(&pdev->dev, "unable to request IRQ %d\n",
			encoder->irq_b);
		goto exit_free_irq_a;
	}

	platform_set_drvdata(pdev, encoder);

	return 0;

exit_free_irq_a:
	free_irq(encoder->irq_a, encoder);
exit_free_gpio_b:
	gpio_free(pdata->gpio_b);
exit_free_gpio_a:
	gpio_free(pdata->gpio_a);
exit_unregister_input:
	input_unregister_device(input);
	input = NULL; /* so we don't try to free it */
exit_free_mem:
	input_free_device(input);
	kfree(encoder);
	return err;
}