Beispiel #1
0
static int headsetdet_probe(struct platform_device *pdev)
{
	struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
	struct headset_switch_data *switch_data;
	int ret = 0;
	struct input_dev *ip_dev;  

	if (!pdata)
		return -EBUSY;
	switch_data = kzalloc(sizeof(struct headset_switch_data), GFP_KERNEL);
	if (!switch_data)
		return -ENOMEM;

	// 20110425 [email protected] detect headset during sleep [START]
	/* wake lock for headset detection */
	wake_lock_init(&headset_wlock.wake_lock, WAKE_LOCK_SUSPEND, "headset_det");
	set_wakelock(0);		
	// 20110425 [email protected] detect headset during sleep [END]

	switch_data->sdev.name = pdata->name;
	switch_data->gpio = pdata->gpio;
	switch_data->name_on = pdata->name_on;
	switch_data->name_off = pdata->name_off;
	switch_data->state_on = pdata->state_on;
	switch_data->state_off = pdata->state_off;
	switch_data->sdev.print_state = switch_gpio_print_state;

         switch_data->hook_gpio = HOOK_ADC_GPIO;
    
#if defined(CONFIG_PRODUCT_LGE_KU5900)||defined(CONFIG_PRODUCT_LGE_P970) || defined(CONFIG_PRODUCT_LGE_LU6800)	// 20100814 [email protected], dmb ant detect [START_LGE]
	//nothing
#elif defined(CONFIG_PRODUCT_LGE_HUB) // [email protected] : Mach_Hub use external ant for dmb
	switch_data->dmb_ant_gpio = 164;
	switch_data->dmb_ant_detected = 0;
#endif	// 20100814 [email protected], dmb ant detect [END_LGE]

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

	omap_mux_init_gpio(switch_data->gpio, OMAP_PIN_INPUT_PULLDOWN | OMAP_PIN_OFF_WAKEUPENABLE);	//20101004 [email protected], ear sense wakable setting

#if 1	//20101109 [email protected], hook key wakable setting
	omap_mux_init_gpio(switch_data->hook_gpio, OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);	
#endif

	ret = gpio_request(switch_data->gpio, pdev->name);

	ret = gpio_request(switch_data->hook_gpio, pdev->name);

#if defined(CONFIG_PRODUCT_LGE_KU5900)||defined(CONFIG_PRODUCT_LGE_P970) || defined(CONFIG_PRODUCT_LGE_LU6800) // 20100814 [email protected], dmb ant detect [START_LGE]
	//nothing
#else
	ret = gpio_request(switch_data->dmb_ant_gpio, pdev->name);
#endif	// 20100814 [email protected], dmb ant detect [END_LGE]

	if (ret < 0)
		goto err_request_gpio;

	ret = gpio_direction_input(switch_data->gpio);

	ret = gpio_direction_input(switch_data->hook_gpio);

#if defined(CONFIG_PRODUCT_LGE_KU5900)||defined(CONFIG_PRODUCT_LGE_P970) || defined(CONFIG_PRODUCT_LGE_HUB)// 20100814 [email protected], dmb ant detect [START_LGE]
	//nothing
#else
//--[[ LGE_UBIQUIX_MODIFIED_START : [email protected] [2011.08.11] - GPIO direction input error fixed.
	ret = gpio_request(switch_data->dmb_ant_gpio, pdev->name);
	if (ret < 0)
		goto err_request_gpio;
//--]] LGE_UBIQUIX_MODIFIED_END : [email protected] [2011.08.11]- GPIO direction input error fixed.

	ret = gpio_direction_input(switch_data->dmb_ant_gpio);
#endif	// 20100814 [email protected], dmb ant detect [END_LGE]

	if (ret < 0)
		goto err_set_gpio_input;

    ip_dev = input_allocate_device();
    
	switch_data->ip_dev = ip_dev;

	switch_data->ip_dev->name = "Hookkey";	//20100830, [email protected], define the input dev name
	
	set_bit(EV_SYN, switch_data->ip_dev->evbit);
	set_bit(EV_KEY, switch_data->ip_dev->evbit);
	set_bit(KEY_HOOK, switch_data->ip_dev->keybit); 	//for short pressed hook key
		
	ret = input_register_device(switch_data->ip_dev);
	    
	INIT_WORK(&switch_data->work, headset_det_work);
    INIT_DELAYED_WORK(&switch_data->delayed_work, type_det_work);
	INIT_DELAYED_WORK(&switch_data->hook_delayed_work, hook_det_work);

	switch_data->irq = gpio_to_irq(switch_data->gpio);
	switch_data->hook_irq = gpio_to_irq(switch_data->hook_gpio);
// 20100814 [email protected], dmb ant detect [START_LGE]	
#if defined(CONFIG_PRODUCT_LGE_KU5900) ||defined(CONFIG_PRODUCT_LGE_P970)
	//nothing
#else
	switch_data->dmb_ant_irq = gpio_to_irq(switch_data->dmb_ant_gpio);	// 20100814 [email protected], dmb ant gpio [START_LGE]
#endif	
// 20100814 [email protected], dmb ant detect [END_LGE]
	
	if (switch_data->irq < 0) {
		ret = switch_data->irq;
		goto err_detect_irq_num_failed;
	}

#if 1		//20101004 [email protected], ear sense wakable setting
	/* Make the interrupt on wake up OMAP which is in suspend mode */		
	ret = enable_irq_wake(switch_data->irq);		
	if(ret < 0){
		DBG(KERN_INFO "[LUCKYJUN77] EAR SENSE 170 wake up source setting failed!\n");
		disable_irq_wake(switch_data->irq);
		return -ENOSYS;
	}
#endif			

#if 1		//20101109 [email protected], hook key wakable setting
	/* Make the interrupt on wake up OMAP which is in suspend mode */		
	ret = enable_irq_wake(switch_data->hook_irq);		
	if(ret < 0){
		DBG(KERN_INFO "[LUCKYJUN77] Hook key 163 wake up source setting failed!\n");
		disable_irq_wake(switch_data->hook_irq);
		return -ENOSYS;
	}
#endif			



	ret = request_irq(switch_data->irq, headset_int_handler,
			  IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, pdev->name, switch_data);
	if (ret < 0)
		goto err_request_irq;

    ret = request_irq(switch_data->hook_irq, headset_hook_int_handler,
			  IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "headset_hook", switch_data);
	if (ret < 0)
		goto err_request_irq;
			  
// 20100825 [email protected], mic bias LDO control test [START_LGE]
#if 1
	omap_mux_init_gpio(MIC_BIAS_LDO, OMAP_PIN_OUTPUT);
	ret = gpio_request(MIC_BIAS_LDO,  pdev->name);
	if(ret < 0) {	
		DBG("can't get hub Mic bias LDO enable GPIO\n");
		goto err_request_gpio;
	}
#endif
// 20100825 [email protected], mic bias LDO control test [END_LGE]

// 20100814 [email protected], dmb ant detect [START_LGE]
#if defined(CONFIG_PRODUCT_LGE_KU5900) || defined(CONFIG_PRODUCT_LGE_LU6800)||defined(CONFIG_PRODUCT_LGE_P970)
	//nothing
#else
    ret = request_irq(switch_data->dmb_ant_irq, dmb_ant_int_handler,
			  IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "dmb_ant", switch_data);
#endif
// 20100814 [email protected], dmb ant detect [END_LGE]

	/* Perform initial detection */
	headset_sw_data = switch_data;

	headset_sw_data->is_suspend = 0;	//resume
	
	headset_det_work(&switch_data->work);

// 20100603 [email protected], headset suspend/resume [START_LGE]
#ifdef CONFIG_HAS_EARLYSUSPEND
	switch_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 2;
	switch_data->early_suspend.suspend = headsetdet_early_suspend;
	switch_data->early_suspend.resume = headsetdet_late_resume;
	register_early_suspend(&switch_data->early_suspend);
#endif
// 20100603 [email protected], headset suspend/resume [END_LGE]	

	return 0;

err_request_irq:
err_detect_irq_num_failed:
err_set_gpio_input:
	gpio_free(switch_data->gpio);
err_request_gpio:
    switch_dev_unregister(&switch_data->sdev);
err_switch_dev_register:
	kfree(switch_data);

	return ret;
}
Beispiel #2
0
/*
 * The functions for inserting/removing us as a module.
 */
static int __init s3c_ts_probe(struct platform_device *pdev)
{
	struct device *dev;
	struct input_dev *input_dev;
	struct s3c_ts_mach_info * s3c_ts_cfg;
	int ret;
	int err;

	dev = &pdev->dev;

	s3c_ts_cfg = (struct s3c_ts_mach_info *) dev->platform_data;
	if (s3c_ts_cfg == NULL)
		return -EINVAL;

	ts = kzalloc(sizeof(struct s3c_ts_mach_info), GFP_KERNEL);
	data = kzalloc(sizeof(struct s3c_ts_data), GFP_KERNEL);

	memcpy (ts, s3c_ts_cfg, sizeof(struct s3c_ts_mach_info));
	
	input_dev = input_allocate_device();

	if (!input_dev) {
		ret = -ENOMEM;
		goto input_dev_fail;
	}
	
	data->dev = input_dev;

	data->xp_old = data->yp_old = -1;
	data->dev->evbit[0] = data->dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
	data->dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);

        input_set_abs_params(data->dev, ABS_X, 0, ts->screen_size_x, 0, 0);
        input_set_abs_params(data->dev, ABS_Y, 0, ts->screen_size_y, 0, 0);
	// [SEC_BSP.khLEE 2009.08.24 : Intialize variables for calibration mode
#ifdef CONFIG_SAMSUNG_CALIBRATION_MODE
	ret = init_samsung_cal_mode(ts->screen_size_x, ts->screen_size_y, ts->tscal);
	if(ret) 
	{
		dev_err(dev, "s3c_ts.c: Could not initialization(touchscreen)!\n");
		goto s3c_adcts_register_fail;
	}
		
#endif
	// ]

        set_bit(0,data->dev->evbit);
        set_bit(1,data->dev->evbit);
        set_bit(2,data->dev->evbit);
        set_bit(3,data->dev->evbit);
        set_bit(5,data->dev->evbit);

        set_bit(0,data->dev->relbit);
        set_bit(1,data->dev->relbit);

        set_bit(0,data->dev->absbit);
        set_bit(1,data->dev->absbit);
        set_bit(2,data->dev->absbit);

        set_bit(0,data->dev->swbit);

        for(err=0;err<512;err++) set_bit(err,data->dev->keybit);

        input_event(data->dev,5,0,1);

	input_set_abs_params(data->dev, ABS_PRESSURE, 0, 1, 0, 0);

	data->dev->name = s3c_ts_name;
	data->dev->id.bustype = BUS_RS232;
	data->dev->id.vendor = 0xDEAD;
	data->dev->id.product = 0xBEEF;
	data->dev->id.version = S3C_TSVERSION;

	ret = s3c_adcts_register_ts (ts, s3c_ts_done_callback);
	if(ret) {
		dev_err(dev, "s3c_ts.c: Could not register adcts device(touchscreen)!\n");
		ret = -EIO;
		goto s3c_adcts_register_fail;
	}

	/* All went ok, so register to the input system */
	ret = input_register_device(data->dev);
	
	if(ret) {
		dev_err(dev, "s3c_ts.c: Could not register input device(touchscreen)!\n");
		ret = -EIO;
		goto input_register_fail;
	}
	return 0;

input_register_fail:
	s3c_adcts_unregister_ts();

s3c_adcts_register_fail:
	input_free_device (data->dev);

input_dev_fail:
	kfree (ts);
	kfree (data);

	return ret;
}
static int usb_mouse_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;
	struct usb_mouse *mouse;
	struct input_dev *input_dev;
	int pipe, maxp;
	int error = -ENOMEM;

	interface = intf->cur_altsetting;

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

	endpoint = &interface->endpoint[0].desc;
	if (!usb_endpoint_is_int_in(endpoint))
		return -ENODEV;

	pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
	maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));

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

	mouse->data = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &mouse->data_dma);
	if (!mouse->data)
		goto fail1;

	mouse->irq = usb_alloc_urb(0, GFP_KERNEL);
	if (!mouse->irq)
		goto fail2;

	mouse->usbdev = dev;
	mouse->dev = input_dev;

	if (dev->manufacturer)
		strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name));

	if (dev->product) {
		if (dev->manufacturer)
			strlcat(mouse->name, " ", sizeof(mouse->name));
		strlcat(mouse->name, dev->product, sizeof(mouse->name));
	}

	if (!strlen(mouse->name))
		snprintf(mouse->name, sizeof(mouse->name),
			 "USB HIDBP Mouse %04x:%04x",
			 le16_to_cpu(dev->descriptor.idVendor),
			 le16_to_cpu(dev->descriptor.idProduct));

	usb_make_path(dev, mouse->phys, sizeof(mouse->phys));
	strlcat(mouse->phys, "/input0", sizeof(mouse->phys));

	input_dev->name = mouse->name;
	input_dev->phys = mouse->phys;
	usb_to_input_id(dev, &input_dev->id);
	input_dev->dev.parent = &intf->dev;

	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
	input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
		BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
	input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
	input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) |
		BIT_MASK(BTN_EXTRA);
	input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);

	input_set_drvdata(input_dev, mouse);

	input_dev->open = usb_mouse_open;
	input_dev->close = usb_mouse_close;

	usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
			 (maxp > 8 ? 8 : maxp),
			 usb_mouse_irq, mouse, endpoint->bInterval);
	mouse->irq->transfer_dma = mouse->data_dma;
	mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

	error = input_register_device(mouse->dev);
	if (error)
		goto fail3;

	usb_set_intfdata(intf, mouse);
	return 0;

fail3:	
	usb_free_urb(mouse->irq);
fail2:	
	usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
fail1:	
	input_free_device(input_dev);
	kfree(mouse);
	return error;
}
Beispiel #4
0
static int omap4_keypad_probe(struct platform_device *pdev)
{
	struct omap4_keypad *keypad_data;
	struct input_dev *input_dev;
	struct resource *res;
	unsigned int max_keys;
	int rev;
	int irq;
	int error;

	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;
	}

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

	keypad_data->irq = irq;

	error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
	if (error)
		return error;

	res = request_mem_region(res->start, resource_size(res), 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;
	}


	/*
	 * Enable clocks for the keypad module so that we can read
	 * revision register.
	 */
	pm_runtime_enable(&pdev->dev);
	error = pm_runtime_get_sync(&pdev->dev);
	if (error) {
		dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
		goto err_unmap;
	}
	rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION);
	rev &= 0x03 << 30;
	rev >>= 30;
	switch (rev) {
	case KBD_REVISION_OMAP4:
		keypad_data->reg_offset = 0x00;
		keypad_data->irqreg_offset = 0x00;
		break;
	case KBD_REVISION_OMAP5:
		keypad_data->reg_offset = 0x10;
		keypad_data->irqreg_offset = 0x0c;
		break;
	default:
		dev_err(&pdev->dev,
			"Keypad reports unsupported revision %d", rev);
		error = -EINVAL;
		goto err_pm_put_sync;
	}

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

	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_set_capability(input_dev, EV_MSC, MSC_SCAN);
	if (!keypad_data->no_autorepeat)
		__set_bit(EV_REP, input_dev->evbit);

	input_set_drvdata(input_dev, keypad_data);

	keypad_data->row_shift = get_count_order(keypad_data->cols);
	max_keys = keypad_data->rows << keypad_data->row_shift;
	keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]),
				      GFP_KERNEL);
	if (!keypad_data->keymap) {
		dev_err(&pdev->dev, "Not enough memory for keymap\n");
		error = -ENOMEM;
		goto err_free_input;
	}

	error = matrix_keypad_build_keymap(NULL, NULL,
					   keypad_data->rows, keypad_data->cols,
					   keypad_data->keymap, input_dev);
	if (error) {
		dev_err(&pdev->dev, "failed to build keymap\n");
		goto err_free_keymap;
	}

	error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler,
				     omap4_keypad_irq_thread_fn, 0,
				     "omap4-keypad", keypad_data);
	if (error) {
		dev_err(&pdev->dev, "failed to register interrupt\n");
		goto err_free_input;
	}

	device_init_wakeup(&pdev->dev, true);
	pm_runtime_put_sync(&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);
	return 0;

err_pm_disable:
	pm_runtime_disable(&pdev->dev);
	device_init_wakeup(&pdev->dev, false);
	free_irq(keypad_data->irq, keypad_data);
err_free_keymap:
	kfree(keypad_data->keymap);
err_free_input:
	input_free_device(input_dev);
err_pm_put_sync:
	pm_runtime_put_sync(&pdev->dev);
err_unmap:
	iounmap(keypad_data->base);
err_release_mem:
	release_mem_region(res->start, resource_size(res));
err_free_keypad:
	kfree(keypad_data);
	return error;
}
Beispiel #5
0
static int pm8058_kp_config_drv(int gpio_start, int num_gpios)
{
	int	rc;
	struct pm8058_gpio kypd_drv = {
		.direction	= PM_GPIO_DIR_OUT,
		.output_buffer	= PM_GPIO_OUT_BUF_OPEN_DRAIN,
		.output_value	= 0,
		.pull		= PM_GPIO_PULL_NO,
		.vin_sel	= 2,
		.out_strength	= PM_GPIO_STRENGTH_LOW,
		.function	= PM_GPIO_FUNC_1,
		.inv_int_pol	= 1,
	};

	if (gpio_start < 0 || num_gpios < 0 || num_gpios > PM8058_GPIOS)
		return -EINVAL;

	while (num_gpios--) {
		rc = pm8058_gpio_config(gpio_start++, &kypd_drv);
		if (rc) {
			pr_err("%s: FAIL pm8058_gpio_config(): rc=%d.\n",
				__func__, rc);
			return rc;
		}
	}

	return 0;
}

static int pm8058_kp_config_sns(int gpio_start, int num_gpios)
{
	int	rc;
	struct pm8058_gpio kypd_sns = {
		.direction	= PM_GPIO_DIR_IN,
		.pull		= PM_GPIO_PULL_UP_31P5,
		.vin_sel	= 2,
		.out_strength	= PM_GPIO_STRENGTH_NO,
		.function	= PM_GPIO_FUNC_NORMAL,
		.inv_int_pol	= 1,
	};

	if (gpio_start < 0 || num_gpios < 0 || num_gpios > PM8058_GPIOS)
		return -EINVAL;

	while (num_gpios--) {
		rc = pm8058_gpio_config(gpio_start++, &kypd_sns);
		if (rc) {
			pr_err("%s: FAIL pm8058_gpio_config(): rc=%d.\n",
				__func__, rc);
			return rc;
		}
	}

	return 0;
}

/*
 * keypad controller should be initialized in the following sequence
 * only, otherwise it might get into FSM stuck state.
 *
 * - Initialize keypad control parameters, like no. of rows, columns,
 *   timing values etc.,
 * - configure rows and column gpios pull up/down.
 * - set irq edge type.
 * - enable the keypad controller.
 */
static int __devinit pmic8058_kp_probe(struct platform_device *pdev)
{
	struct pmic8058_keypad_data *pdata = pdev->dev.platform_data;
	const struct matrix_keymap_data *keymap_data;
	struct pmic8058_kp *kp;
	int rc;
	unsigned short *keycodes;
	u8 ctrl_val;
	struct pm8058_chip	*pm_chip;

	pm_chip = dev_get_drvdata(pdev->dev.parent);
	if (pm_chip == NULL) {
		dev_err(&pdev->dev, "no parent data passed in\n");
		return -EFAULT;
	}

	if (!pdata || !pdata->num_cols || !pdata->num_rows ||
		pdata->num_cols > PM8058_MAX_COLS ||
		pdata->num_rows > PM8058_MAX_ROWS ||
		pdata->num_cols < PM8058_MIN_COLS ||
		pdata->num_rows < PM8058_MIN_ROWS) {
		dev_err(&pdev->dev, "invalid platform data\n");
		return -EINVAL;
	}

	if (pdata->rows_gpio_start < 0 || pdata->cols_gpio_start < 0) {
		dev_err(&pdev->dev, "invalid gpio_start platform data\n");
		return -EINVAL;
	}

	if (!pdata->scan_delay_ms || pdata->scan_delay_ms > MAX_SCAN_DELAY
		|| pdata->scan_delay_ms < MIN_SCAN_DELAY ||
		!is_power_of_2(pdata->scan_delay_ms)) {
		dev_err(&pdev->dev, "invalid keypad scan time supplied\n");
		return -EINVAL;
	}

	if (!pdata->row_hold_ns || pdata->row_hold_ns > MAX_ROW_HOLD_DELAY
		|| pdata->row_hold_ns < MIN_ROW_HOLD_DELAY ||
		((pdata->row_hold_ns % MIN_ROW_HOLD_DELAY) != 0)) {
		dev_err(&pdev->dev, "invalid keypad row hold time supplied\n");
		return -EINVAL;
	}

	if (pm8058_rev(pm_chip) == PM_8058_REV_1p0) {
		if (!pdata->debounce_ms
			|| !is_power_of_2(pdata->debounce_ms[0])
			|| pdata->debounce_ms[0] > MAX_DEBOUNCE_A0_TIME
			|| pdata->debounce_ms[0] < MIN_DEBOUNCE_A0_TIME) {
			dev_err(&pdev->dev, "invalid debounce time supplied\n");
			return -EINVAL;
		}
	} else {
		if (!pdata->debounce_ms
			|| ((pdata->debounce_ms[1] % 5) != 0)
			|| pdata->debounce_ms[1] > MAX_DEBOUNCE_B0_TIME
			|| pdata->debounce_ms[1] < MIN_DEBOUNCE_B0_TIME) {
			dev_err(&pdev->dev, "invalid debounce time supplied\n");
			return -EINVAL;
		}
	}

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

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

	keycodes = kzalloc(PM8058_MATRIX_MAX_SIZE * sizeof(*keycodes),
				 GFP_KERNEL);
	if (!keycodes) {
		rc = -ENOMEM;
		goto err_alloc_mem;
	}

	platform_set_drvdata(pdev, kp);
	mutex_init(&kp->mutex);

	kp->pdata	= pdata;
	kp->dev		= &pdev->dev;
	kp->keycodes	= keycodes;
	kp->pm_chip	= pm_chip;

	if (pm8058_rev(pm_chip) == PM_8058_REV_1p0)
		kp->flags |= KEYF_FIX_LAST_ROW;

	kp->input = input_allocate_device();
	if (!kp->input) {
		dev_err(&pdev->dev, "unable to allocate input device\n");
		rc = -ENOMEM;
		goto err_alloc_device;
	}

	/* Enable runtime PM ops, start in ACTIVE mode */
	rc = pm_runtime_set_active(&pdev->dev);
	if (rc < 0)
		dev_dbg(&pdev->dev, "unable to set runtime pm state\n");
	pm_runtime_enable(&pdev->dev);

	kp->key_sense_irq = platform_get_irq(pdev, 0);
	if (kp->key_sense_irq < 0) {
		dev_err(&pdev->dev, "unable to get keypad sense irq\n");
		rc = -ENXIO;
		goto err_get_irq;
	}

	kp->key_stuck_irq = platform_get_irq(pdev, 1);
	if (kp->key_stuck_irq < 0) {
		dev_err(&pdev->dev, "unable to get keypad stuck irq\n");
		rc = -ENXIO;
		goto err_get_irq;
	}

	if (pdata->input_name)
		kp->input->name = pdata->input_name;
	else
		kp->input->name = "PMIC8058 keypad";

	if (pdata->input_phys_device)
		kp->input->phys = pdata->input_phys_device;
	else
		kp->input->phys = "pmic8058_keypad/input0";

	kp->input->dev.parent	= &pdev->dev;

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

	kp->input->evbit[0]	= BIT_MASK(EV_KEY);

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

	kp->input->keycode	= keycodes;
	kp->input->keycodemax	= PM8058_MATRIX_MAX_SIZE;
	kp->input->keycodesize	= sizeof(*keycodes);

	matrix_keypad_build_keymap(keymap_data, PM8058_ROW_SHIFT,
					kp->input->keycode, kp->input->keybit);

	input_set_capability(kp->input, EV_MSC, MSC_SCAN);
	input_set_drvdata(kp->input, kp);

	rc = input_register_device(kp->input);
	if (rc < 0) {
		dev_err(&pdev->dev, "unable to register keypad input device\n");
		goto err_get_irq;
	}

	/* initialize keypad state */
	memset(kp->keystate, 0xff, sizeof(kp->keystate));
	memset(kp->stuckstate, 0xff, sizeof(kp->stuckstate));

	rc = pmic8058_kpd_init(kp);
	if (rc < 0) {
		dev_err(&pdev->dev, "unable to initialize keypad controller\n");
		goto err_kpd_init;
	}

	rc = pm8058_kp_config_sns(pdata->cols_gpio_start,
			pdata->num_cols);
	if (rc < 0) {
		dev_err(&pdev->dev, "unable to configure keypad sense lines\n");
		goto err_gpio_config;
	}

	rc = pm8058_kp_config_drv(pdata->rows_gpio_start,
			pdata->num_rows);
	if (rc < 0) {
		dev_err(&pdev->dev, "unable to configure keypad drive lines\n");
		goto err_gpio_config;
	}

	rc = request_threaded_irq(kp->key_sense_irq, NULL, pmic8058_kp_irq,
				 IRQF_TRIGGER_RISING, "pmic-keypad", kp);
	if (rc < 0) {
		dev_err(&pdev->dev, "failed to request keypad sense irq\n");
		goto err_req_sense_irq;
	}

	rc = request_threaded_irq(kp->key_stuck_irq, NULL,
				 pmic8058_kp_stuck_irq, IRQF_TRIGGER_RISING,
				 "pmic-keypad-stuck", kp);
	if (rc < 0) {
		dev_err(&pdev->dev, "failed to request keypad stuck irq\n");
		goto err_req_stuck_irq;
	}

	rc = pmic8058_kp_read_u8(kp, &ctrl_val, KEYP_CTRL);
	ctrl_val |= KEYP_CTRL_KEYP_EN;
	rc = pmic8058_kp_write_u8(kp, ctrl_val, KEYP_CTRL);

	kp->ctrl_reg = ctrl_val;

	__dump_kp_regs(kp, "probe");

	rc = device_create_file(&pdev->dev, &dev_attr_disable_kp);
	if (rc < 0)
		goto err_create_file;

	device_init_wakeup(&pdev->dev, pdata->wakeup);

	return 0;

err_create_file:
	free_irq(kp->key_stuck_irq, NULL);
err_req_stuck_irq:
	free_irq(kp->key_sense_irq, NULL);
err_req_sense_irq:
err_gpio_config:
err_kpd_init:
	input_unregister_device(kp->input);
	kp->input = NULL;
err_get_irq:
	pm_runtime_set_suspended(&pdev->dev);
	pm_runtime_disable(&pdev->dev);
	input_free_device(kp->input);
err_alloc_device:
	kfree(keycodes);
err_alloc_mem:
	kfree(kp);
	return rc;
}

static int __devexit pmic8058_kp_remove(struct platform_device *pdev)
{
	struct pmic8058_kp *kp = platform_get_drvdata(pdev);

	pm_runtime_set_suspended(&pdev->dev);
	pm_runtime_disable(&pdev->dev);
	device_remove_file(&pdev->dev, &dev_attr_disable_kp);
	device_init_wakeup(&pdev->dev, 0);
	free_irq(kp->key_stuck_irq, NULL);
	free_irq(kp->key_sense_irq, NULL);
	input_unregister_device(kp->input);
	platform_set_drvdata(pdev, NULL);
	kfree(kp->input->keycode);
	kfree(kp);

	return 0;
}

#ifdef CONFIG_PM
static int pmic8058_kp_suspend(struct device *dev)
{
	struct pmic8058_kp *kp = dev_get_drvdata(dev);

	if (device_may_wakeup(dev) && !pmic8058_kp_disabled(kp)) {
		enable_irq_wake(kp->key_sense_irq);
	} else {
		mutex_lock(&kp->mutex);
		pmic8058_kp_disable(kp);
		mutex_unlock(&kp->mutex);
	}

	return 0;
}

static int pmic8058_kp_resume(struct device *dev)
{
	struct pmic8058_kp *kp = dev_get_drvdata(dev);

	if (device_may_wakeup(dev) && !pmic8058_kp_disabled(kp)) {
		disable_irq_wake(kp->key_sense_irq);
	} else {
		mutex_lock(&kp->mutex);
		pmic8058_kp_enable(kp);
		mutex_unlock(&kp->mutex);
	}

	return 0;
}

static struct dev_pm_ops pm8058_kp_pm_ops = {
	.suspend	= pmic8058_kp_suspend,
	.resume		= pmic8058_kp_resume,
};
#endif

static struct platform_driver pmic8058_kp_driver = {
	.probe		= pmic8058_kp_probe,
	.remove		= __devexit_p(pmic8058_kp_remove),
	.driver		= {
		.name = "pm8058-keypad",
		.owner = THIS_MODULE,
#ifdef CONFIG_PM
		.pm = &pm8058_kp_pm_ops,
#endif
	},
};

static int __init pmic8058_kp_init(void)
{
	return platform_driver_register(&pmic8058_kp_driver);
}
module_init(pmic8058_kp_init);

static void __exit pmic8058_kp_exit(void)
{
	platform_driver_unregister(&pmic8058_kp_driver);
}
static int mlx90615_i2c_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	int ret = -ENODEV;
	struct mlx90615_data *mlx90615 = NULL;

	pr_info("[BODYTEMP] %s is called.\n", __func__);

	/* Check i2c functionality */
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		pr_err("[BODYTEMP] %s: i2c functionality check failed!\n",
			__func__);
		return ret;
	}

	mlx90615 = kzalloc(sizeof(struct mlx90615_data), GFP_KERNEL);
	if (!mlx90615) {
		pr_err("[BODYTEMP] %s: failed to alloc memory mlx90615_data\n",
			__func__);
		return -ENOMEM;
	}

	if (client-> dev.of_node)
		pr_info("[BODYTEMP] %s : of node\n", __func__);
	else {
		pr_err("[BODYTEMP] %s : no of node\n", __func__);
		goto err_setup_reg;
	}

	ret = mlx90615_parse_dt(&client->dev, mlx90615);

	if (ret) {
		pr_err("[BODYTEMP] %s : parse dt error\n", __func__);
		//goto err_parse_dt;
	}

	mlx90615->i2c_client = client;
	mlx90615->always_on = 0;

	i2c_set_clientdata(client, mlx90615);

	mutex_init(&mlx90615->power_lock);
	mutex_init(&mlx90615->read_lock);
#if 0
	/* Check if the device is there or not. */
	ret = i2c_master_send(mlx90615->i2c_client,
				CMD_READ_ID_REG, MLX90615_CMD_LENGTH);
	if (ret < 0) {
		pr_err("[BODYTEMP] %s: failed i2c_master_send (err = %d)\n",
			__func__, ret);
		/* goto err_i2c_master_send;*/
	}
#endif
	/* allocate mlx90615 input_device */
	mlx90615->input = input_allocate_device();
	if (!mlx90615->input) {
		pr_err("[BODYTEMP] %s: could not allocate input device\n",
			__func__);
		goto err_input_allocate_device;
	}

	mlx90615->input->name = "bodytemp_sensor";
	input_set_capability(mlx90615->input, EV_REL, EVENT_TYPE_AMBIENT_TEMP);
	input_set_capability(mlx90615->input, EV_REL, EVENT_TYPE_OBJECT_TEMP);
	input_set_drvdata(mlx90615->input, mlx90615);

	ret = input_register_device(mlx90615->input);
	if (ret < 0) {
		input_free_device(mlx90615->input);
		pr_err("[BODYTEMP] %s: could not register input device\n",
			__func__);
		goto err_input_register_device;
	}

	ret = sensors_create_symlink(&mlx90615->input->dev.kobj,
					mlx90615->input->name);
	if (ret < 0) {
		input_unregister_device(mlx90615->input);
		goto err_sysfs_create_symlink;
	}

	ret = sysfs_create_group(&mlx90615->input->dev.kobj,
				&mlx90615_attribute_group);
	if (ret) {
		pr_err("[BODYTEMP] %s: could not create sysfs group\n",
			__func__);
		goto err_sysfs_create_group;
	}
	ret = sensors_register(mlx90615->mlx90615_dev,
			mlx90615, bodytemp_sensor_attrs, "bodytemp_sensor");
	if (ret) {
		pr_err("[BODYTEMP] %s: cound not register sensor device(%d).\n",
			__func__, ret);
		goto err_sysfs_create_symlink;
	}
	/* Timer settings. We poll for mlx90615 values using a timer. */
	hrtimer_init(&mlx90615->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	mlx90615->poll_delay = ns_to_ktime(DEFAULT_DELAY * NSEC_PER_MSEC);
	mlx90615->timer.function = timer_func;

	/* Timer just fires off a work queue request.  We need a thread
	   to read the i2c (can be slow and blocking). */
	mlx90615->mlx90615_wq =
		create_singlethread_workqueue("mlx90615_bidytemp_wq");
	if (!mlx90615->mlx90615_wq) {
		ret = -ENOMEM;
		pr_err("[BODYTEMP] %s: could not create mlx90615 workqueue\n", __func__);
		goto err_create_workqueue;
	}

	/* This is the thread function we run on the work queue */
	INIT_WORK(&mlx90615->work_mlx90615, mlx90615_work_func);

	pr_info("[BODYTEMP] %s is success.\n", __func__);

	goto done;


err_create_workqueue:
	sysfs_remove_group(&mlx90615->input->dev.kobj,
				&mlx90615_attribute_group);
	/* sensors_classdev_unregister(mlx90615->mlx90615_dev);*/
	destroy_workqueue(mlx90615->mlx90615_wq);
err_sysfs_create_group:
	input_unregister_device(mlx90615->input);
err_sysfs_create_symlink:
	sensors_remove_symlink(&mlx90615->input->dev.kobj,
			mlx90615->input->name);
err_input_register_device:
err_input_allocate_device:
	mutex_destroy(&mlx90615->read_lock);
	mutex_destroy(&mlx90615->power_lock);
err_setup_reg:
//err_parse_dt:
	kfree(mlx90615);
done:
	return ret;
}
int cx231xx_ir_init(struct cx231xx *dev)
{
	struct cx231xx_IR *ir;
	struct input_dev *input_dev;
	u8 ir_config;
	int err = -ENOMEM;

	if (dev->board.ir_codes == NULL) {
		/* No remote control support */
		return 0;
	}

	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!ir || !input_dev)
		goto err_out_free;

	ir->input = input_dev;

	/* Setup the proper handler based on the chip */
	switch (dev->chip_id) {
	default:
		printk("Unrecognized cx231xx chip id: IR not supported\n");
		goto err_out_free;
	}

	/* This is how often we ask the chip for IR information */
	ir->polling = 100;	/* ms */

	/* init input device */
	snprintf(ir->name, sizeof(ir->name), "cx231xx IR (%s)", dev->name);

	usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
	strlcat(ir->phys, "/input0", sizeof(ir->phys));

	err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
	if (err < 0)
		goto err_out_free;

	input_dev->name = ir->name;
	input_dev->phys = ir->phys;
	input_dev->id.bustype = BUS_USB;
	input_dev->id.version = 1;
	input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
	input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);

	input_dev->dev.parent = &dev->udev->dev;
	/* record handles to ourself */
	ir->dev = dev;
	dev->ir = ir;

	cx231xx_ir_start(ir);

	/* all done */
	err = ir_input_register(ir->input, dev->board.ir_codes, NULL);
	if (err)
		goto err_out_stop;

	return 0;
err_out_stop:
	cx231xx_ir_stop(ir);
	dev->ir = NULL;
err_out_free:
	kfree(ir);
	return err;
}
int cx23885_input_init(struct cx23885_dev *dev)
{
	struct card_ir *ir;
	struct input_dev *input_dev;
	struct ir_scancode_table *ir_codes = NULL;
	int ir_type, ir_addr, ir_start;
	int ret;

	/*
	 * If the IR device (hardware registers, chip, GPIO lines, etc.) isn't
	 * encapsulated in a v4l2_subdev, then I'm not going to deal with it.
	 */
	if (dev->sd_ir == NULL)
		return -ENODEV;

	switch (dev->board) {
	case CX23885_BOARD_HAUPPAUGE_HVR1850:
	case CX23885_BOARD_HAUPPAUGE_HVR1290:
		/* Parameters for the grey Hauppauge remote for the HVR-1850 */
		ir_codes = &ir_codes_hauppauge_new_table;
		ir_type = IR_TYPE_RC5;
		ir_addr = 0x1e; /* RC-5 system bits emitted by the remote */
		ir_start = RC5_START_BITS_NORMAL; /* A basic RC-5 remote */
		break;
	}
	if (ir_codes == NULL)
		return -ENODEV;

	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!ir || !input_dev) {
		ret = -ENOMEM;
		goto err_out_free;
	}

	ir->dev = input_dev;
	ir->addr = ir_addr;
	ir->start = ir_start;

	/* init input device */
	snprintf(ir->name, sizeof(ir->name), "cx23885 IR (%s)",
		 cx23885_boards[dev->board].name);
	snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(dev->pci));

	ret = ir_input_init(input_dev, &ir->ir, ir_type);
	if (ret < 0)
		goto err_out_free;

	input_dev->name = ir->name;
	input_dev->phys = ir->phys;
	input_dev->id.bustype = BUS_PCI;
	input_dev->id.version = 1;
	if (dev->pci->subsystem_vendor) {
		input_dev->id.vendor  = dev->pci->subsystem_vendor;
		input_dev->id.product = dev->pci->subsystem_device;
	} else {
		input_dev->id.vendor  = dev->pci->vendor;
		input_dev->id.product = dev->pci->device;
	}
	input_dev->dev.parent = &dev->pci->dev;

	dev->ir_input = ir;
	cx23885_input_ir_start(dev);

	ret = ir_input_register(ir->dev, ir_codes);
	if (ret)
		goto err_out_stop;

	return 0;

err_out_stop:
	cx23885_input_ir_stop(dev);
	dev->ir_input = NULL;
err_out_free:
	kfree(ir);
	return ret;
}
Beispiel #9
0
static int __devinit matrix_keypad_probe(struct platform_device *pdev)
{
	const struct matrix_keypad_platform_data *pdata;
	const struct matrix_keymap_data *keymap_data;
	struct matrix_keypad *keypad;
	struct input_dev *input_dev;
	unsigned short *keycodes;
	unsigned int row_shift;
	int err;

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

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

	row_shift = get_count_order(pdata->num_col_gpios);

	keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL);
	keycodes = kzalloc((pdata->num_row_gpios << row_shift) *
				sizeof(*keycodes),
			   GFP_KERNEL);
	input_dev = input_allocate_device();
	if (!keypad || !keycodes || !input_dev) {
		err = -ENOMEM;
		goto err_free_mem;
	}

	keypad->input_dev = input_dev;
	keypad->pdata = pdata;
	keypad->keycodes = keycodes;
	keypad->row_shift = row_shift;
	keypad->stopped = true;
	INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan);
	spin_lock_init(&keypad->lock);

	input_dev->name		= pdev->name;
	input_dev->id.bustype	= BUS_HOST;
	input_dev->dev.parent	= &pdev->dev;
	input_dev->evbit[0]	= BIT_MASK(EV_KEY);
	if (!pdata->no_autorepeat)
		input_dev->evbit[0] |= BIT_MASK(EV_REP);
	input_dev->open		= matrix_keypad_start;
	input_dev->close	= matrix_keypad_stop;

	input_dev->keycode	= keycodes;
	input_dev->keycodesize	= sizeof(*keycodes);
	input_dev->keycodemax	= pdata->num_row_gpios << row_shift;

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

	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
	input_set_drvdata(input_dev, keypad);

	err = init_matrix_gpio(pdev, keypad);
	if (err)
		goto err_free_mem;

	err = input_register_device(keypad->input_dev);
	if (err)
		goto err_free_mem;

	device_init_wakeup(&pdev->dev, pdata->wakeup);
	platform_set_drvdata(pdev, keypad);

	return 0;

err_free_mem:
	input_free_device(input_dev);
	kfree(keycodes);
	kfree(keypad);
	return err;
}
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_WAKEUP);//ZTE_HS_ZHENGCHAO_01
	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_SW, SW_MICROPHONE_INSERT);
	input_set_capability(ipdev, EV_KEY, KEY_POWER);
	/*ZTE_HS_ZHUYF_002*/
	 //disable KEY_END, enable KEY_SLEEP
	//input_set_capability(ipdev, EV_KEY, KEY_END);
	input_set_capability(ipdev, EV_KEY, KEY_SLEEP);
	/*end, ZTE_HS_ZHUYF_002*/
	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;
}
Beispiel #11
0
static int __init ecompass_init(void)
{
	int res = 0;

	pr_info("ecompass driver: init\n");

	ecs_data_device = input_allocate_device();
	if (!ecs_data_device) {
		res = -ENOMEM;
		pr_err("%s: failed to allocate input device\n", __FUNCTION__);
		goto out;
	}

	set_bit(EV_ABS, ecs_data_device->evbit);

	/* 32768 == 1g, range -4g ~ +4g */
	/* acceleration x-axis */
	input_set_abs_params(ecs_data_device, ABS_X,
		-32768*4, 32768*4, 0, 0);
	/* acceleration y-axis */
	input_set_abs_params(ecs_data_device, ABS_Y,
		-32768*4, 32768*4, 0, 0);
	/* acceleration z-axis */
	input_set_abs_params(ecs_data_device, ABS_Z,
		-32768*4, 32768*4, 0, 0);

	/* 32768 == 1gauss, range -4gauss ~ +4gauss */
	/* magnetic raw x-axis */
	input_set_abs_params(ecs_data_device, ABS_HAT0X,
		-32768*4, 32768*4, 0, 0);
	/* magnetic raw y-axis */
	input_set_abs_params(ecs_data_device, ABS_HAT0Y,
		-32768*4, 32768*4, 0, 0);
	/* magnetic raw z-axis */
	input_set_abs_params(ecs_data_device, ABS_BRAKE,
		-32768*4, 32768*4, 0, 0);

	/* 65536 == 360degree */
	/* orientation yaw, 0 ~ 360 */
	input_set_abs_params(ecs_data_device, ABS_RX,
		0, 65536, 0, 0);
	/* orientation pitch, -180 ~ 180 */
	input_set_abs_params(ecs_data_device, ABS_RY,
		-65536/2, 65536/2, 0, 0);
	/* orientation roll, -90 ~ 90 */
	input_set_abs_params(ecs_data_device, ABS_RZ,
		-65536/4, 65536/4, 0, 0);

	ecs_data_device->name = ECS_DATA_DEV_NAME;
	res = input_register_device(ecs_data_device);
	if (res) {
		pr_err("%s: unable to register input device: %s\n",
			__FUNCTION__, ecs_data_device->name);
		goto out_free_input;
	}

	res = misc_register(&ecs_ctrl_device);
	if (res) {
		pr_err("%s: ecs_ctrl_device register failed\n", __FUNCTION__);
		goto out_free_input;
	}
	res = device_create_file(ecs_ctrl_device.this_device, &dev_attr_ecs_ctrl);
	if (res) {
		pr_err("%s: device_create_file failed\n", __FUNCTION__);
		goto out_deregister_misc;
	}

	return 0;

out_deregister_misc:
	misc_deregister(&ecs_ctrl_device);
out_free_input:
	input_free_device(ecs_data_device);
out:
	return res;
}
/**
 * Creates a new Xen Virtrual Pointer Device.
 *
 * @param info The information structure for the combined input device
 *      for which this device should belong to.
 * @param name The new device's name, as reported to the user.
 */
static struct input_dev * __allocate_pointer_device(struct openxt_kbd_info *info,
        char * name, int is_absolute, int is_multitouch)
{
    int i, ret;
    struct input_dev *ptr = input_allocate_device();

    //If we weren't able to allocate a new input device, fail out!
    if (!ptr)
        return NULL;

    //Otherwise, set up some of the device's defaults.
    ptr->name       = name;
    ptr->phys       = info->phys;
    ptr->id.bustype = BUS_PCI;
    ptr->id.vendor  = 0x5853;
    ptr->id.product = 0xfffe;

    //If we're creating an absolute device, register it as a provider
    //of absolute events.
    if (is_absolute) {
        __set_bit(EV_ABS, ptr->evbit);
        input_set_abs_params(ptr, ABS_X, 0, default_max_x, 0, 0);
        input_set_abs_params(ptr, ABS_Y, 0, default_max_y, 0, 0);

        if (is_multitouch) {
            input_set_abs_params(ptr, ABS_MT_POSITION_X, 0, default_max_x, 0, 0);
            input_set_abs_params(ptr, ABS_MT_POSITION_Y, 0, default_max_y, 0, 0);

            //Accept touches, as well.
            input_set_capability(ptr, EV_KEY, BTN_TOUCH);

            //And allow up to ten fingers of touch.
            input_mt_init_slots(ptr, 10, INPUT_MT_DIRECT);
        }
    }
    //Otherwise, register it as providing relative ones.
    else {
        input_set_capability(ptr, EV_REL, REL_X);
        input_set_capability(ptr, EV_REL, REL_Y);
    }

    //Enable scroll events on non-multitouch displays.
    if (!is_multitouch)
        input_set_capability(ptr, EV_REL, REL_WHEEL);

    //Mark this device as providing the typical mouse keys.
    if (!is_multitouch) {
        __set_bit(EV_KEY, ptr->evbit);

    for (i = BTN_LEFT; i <= BTN_TASK; i++)
        __set_bit(i, ptr->keybit);
  }

    //Finally, register the new input device with evdev.
    ret = input_register_device(ptr);
    if (ret) {
        input_free_device(ptr);
        return NULL;
    }

    return ptr;
}
Beispiel #13
0
static int accfix_probe(struct platform_device *xxx)	
{
	int ret = 0;
#ifdef SW_WORK_AROUND_ACCDET_REMOTE_BUTTON_ISSUE
     struct task_struct *keyEvent_thread = NULL;
	 int error=0;
#endif
	ACCFIX_DEBUG("[accfix]accfix_probe begin!\n");

	//------------------------------------------------------------------
	// 							below register accdet as switch class
	//------------------------------------------------------------------	
		
	//------------------------------------------------------------------
	// 							Create normal device for auido use
	//------------------------------------------------------------------
	ret = alloc_chrdev_region(&accfix_devno, 0, 1, ACCFIX_DEVNAME);
	if (ret)
	{
		ACCFIX_DEBUG("[accfix]alloc_chrdev_region: Get Major number error!\n");			
		return -1;
	} 
		
	accfix_cdev = cdev_alloc();
    accfix_cdev->owner = THIS_MODULE;
    accfix_cdev->ops = &accfix_fops;
    ret = cdev_add(accfix_cdev, accfix_devno, 1);
	if(ret)
	{
		ACCFIX_DEBUG("[accfix]accfix error: cdev_add\n");
		return -1;
	}
	
	
	
	ACCFIX_DEBUG("[accfix]try create classd\n");
	accfix_class = class_create(THIS_MODULE, ACCFIX_DEVNAME);
	if (accfix_class == NULL){
		ACCFIX_DEBUG("[accfix]class_create failed\n");
		return -1; 
	}  else {
		ACCFIX_DEBUG("[accfix]class_create success\n");
	}  
  	
	//ACCFIX_DEBUG("[accfix]try destroy device\n");
	//device_destroy(accfix_class, accfix_devno);  
	//ACCFIX_DEBUG("[accfix]destroy device success\n");
	
    // if we want auto creat device node, we must call this

	accfix_nor_device = device_create(accfix_class, NULL, accfix_devno, NULL, ACCFIX_DEVNAME);  
	if (accfix_nor_device == NULL){
		ACCFIX_DEBUG("[accfix]device_create failed\n");
		return -1; 
	} else {
		ACCFIX_DEBUG("[accfix]device_create success\n");
	}  

	//sys_chmod("/dev/accfix", 777);

	/*ACCFIX_DEBUG("[accfix]try device_rename \n");
    	ret= device_rename(accfix_nor_device, "accdet");  
	if(ret)
	{
	    ACCFIX_DEBUG("[accfix]device_rename returned:%d!\n", ret);
	    return -1;
	} else {
	    ACCFIX_DEBUG("[accfix]device_rename success\n");
	}  

	//zzzzz
	ACCFIX_DEBUG("[accfix] DEBUG EXIT\n");
	return -1;
	*/
	
	
	//switch dev
	accfix_data.name = "h2w_test"; //zzz
	accfix_data.index = 0;
	accfix_data.state = NO_DEVICE;
	
	
	//zzz
	//ACCFIX_DEBUG("[accfix]try switch_dev_unregister returned:%d!\n", ret);
	//switch_dev_unregister(&accfix_data);
	
	ret = switch_dev_register(&accfix_data);
	if(ret)
	{
		ACCFIX_DEBUG("[accfix]switch_dev_register returned:%d!\n", ret);
		return -1; //switch doesnt matter - just an icon in taskbar
	}

//------------------------------------------------------------------make: *** [_module_../med
	// 							Create input device 
	//------------------------------------------------------------------
	kpd_accfix_dev = input_allocate_device();
	if (!kpd_accfix_dev) 
	{
		ACCFIX_DEBUG("[accfix]kpd_accfix_dev : fail!\n");
		return -ENOMEM;
	}
	__set_bit(EV_KEY, kpd_accfix_dev->evbit);
	__set_bit(KEY_CALL, kpd_accfix_dev->keybit);
	__set_bit(KEY_ENDCALL, kpd_accfix_dev->keybit);
    
//longxuewei add
	__set_bit(KEY_F24, kpd_accfix_dev->keybit);
	__set_bit(114, kpd_accfix_dev->keybit);
	__set_bit(115, kpd_accfix_dev->keybit);
	__set_bit(163, kpd_accfix_dev->keybit);
	__set_bit(165, kpd_accfix_dev->keybit);
	__set_bit(226, kpd_accfix_dev->keybit);
//longxuewei add end    
	kpd_accfix_dev->id.bustype = BUS_HOST;
	kpd_accfix_dev->name = "ACCFIX";
	if(input_register_device(kpd_accfix_dev))
	{
		ACCFIX_DEBUG("[accfix]kpd_accfix_dev register : fail!\n");
	}else
	{
		ACCFIX_DEBUG("[accfix]kpd_accfix_dev register : success!!\n");
	} 
	//------------------------------------------------------------------
	// 							Create workqueue 
	//------------------------------------------------------------------	
	accfix_workqueue = create_singlethread_workqueue("accfix");
	INIT_WORK(&accfix_work, accfix_work_callback);

	#ifdef ACCFIX_EINT

    accfix_eint_workqueue = create_singlethread_workqueue("accfix_eint");
	INIT_WORK(&accfix_eint_work, accfix_eint_work_callback);
	accfix_setup_eint();
    #endif	

/* #if defined(SUPPORT_CALLINGLIGHT)
	hrtimer_init(&accfix_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	accfix_timer.function = calling_light_decate;
#endif */
    //------------------------------------------------------------------
	//							wake lock
	//------------------------------------------------------------------
	wake_lock_init(&accfix_suspend_lock, WAKE_LOCK_SUSPEND, "accfix wakelock");
#ifdef SW_WORK_AROUND_ACCDET_REMOTE_BUTTON_ISSUE
     init_waitqueue_head(&send_event_wq);
     //start send key event thread
	 keyEvent_thread = kthread_run(sendKeyEvent, 0, "keyEvent_send");
     if (IS_ERR(keyEvent_thread)) 
	 { 
        error = PTR_ERR(keyEvent_thread);
        ACCFIX_DEBUG( " failed to create kernel thread: %d\n", error);
     }
#endif
	
	#if DEBUG_THREAD

	if((ret = accfix_create_attr(&accfix_driver.driver)))
	{
		ACCFIX_DEBUG("create attribute err = %d\n", ret);
		
	}

	#endif

	/* For early porting before audio driver add */
	//temp_func();
	ACCFIX_DEBUG("[accfix]accfix_probe : ACCFIX_INIT\n");  
	if (g_accfix_first == 1) 
	{	
		long_press_time_ns = (s64)long_press_time * NSEC_PER_MSEC;
				
		//Accdet Hardware Init
		accfix_init();
                
		//mt6575_irq_set_sens(MT6575_ACCDET_IRQ_ID, MT65xx_EDGE_SENSITIVE);
		mt6575_irq_set_sens(MT6575_ACCDET_IRQ_ID, MT65xx_LEVEL_SENSITIVE);
		mt6575_irq_set_polarity(MT6575_ACCDET_IRQ_ID, MT65xx_POLARITY_LOW);
		//register accdet interrupt
		
		ret =  request_irq(MT6575_ACCDET_IRQ_ID, accfix_irq_handler, 0, "ACCFIX", NULL);
		if(ret)
		{
			ACCFIX_DEBUG("[accfix]accfix register interrupt error\n");
			ACCFIX_DEBUG("[accfix]try free IRQ\n");
			free_irq(MT6575_ACCDET_IRQ_ID,NULL);
			ACCFIX_DEBUG("[accfix]IRQ freed success\n");
			ret =  request_irq(MT6575_ACCDET_IRQ_ID, accfix_irq_handler, 0, "ACCFIX", NULL);
			if(ret){
			  ACCFIX_DEBUG("[accfix]accfix register interrupt error twice\n");
			}  
		}
                
		queue_work(accfix_workqueue, &accfix_work); //schedule a work for the first detection					
		g_accfix_first = 0;
	}

        ACCFIX_DEBUG("[accfix]accfix_probe done!\n");
	return 0;
}
/* touch panel probe */
static int tpd_probe(struct platform_device *pdev)
{
	int touch_type = 1;	/* 0:R-touch, 1: Cap-touch */
	int i = 0;
	TPD_DMESG("enter %s, %d\n", __func__, __LINE__);
	/* Select R-Touch */
	/* if(g_tpd_drv == NULL||tpd_load_status == 0) */
#if 0
	if (g_tpd_drv == NULL) {
		g_tpd_drv = &tpd_driver_list[0];
		/* touch_type:0: r-touch, 1: C-touch */
		touch_type = 0;
		TPD_DMESG("Generic touch panel driver\n");
	}
#ifdef CONFIG_HAS_EARLYSUSPEND
	MTK_TS_early_suspend_handler.suspend = g_tpd_drv->suspend;
	MTK_TS_early_suspend_handler.resume = g_tpd_drv->resume;
	register_early_suspend(&MTK_TS_early_suspend_handler);
#endif
#endif

	if (misc_register(&tpd_misc_device)) {
		printk("mtk_tpd: tpd_misc_device register failed\n");
	}

	if ((tpd = (struct tpd_device *)kmalloc(sizeof(struct tpd_device), GFP_KERNEL)) == NULL)
		return -ENOMEM;
	memset(tpd, 0, sizeof(struct tpd_device));

	/* allocate input device */
	if ((tpd->dev = input_allocate_device()) == NULL) {
		kfree(tpd);
		return -ENOMEM;
	}
	/* TPD_RES_X = simple_strtoul(LCM_WIDTH, NULL, 0); */
	/* TPD_RES_Y = simple_strtoul(LCM_HEIGHT, NULL, 0); */

	#ifdef CONFIG_MTK_LCM_PHYSICAL_ROTATION
    if(0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "90", 2) || 0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "270", 3))
    {
        TPD_RES_Y = DISP_GetScreenWidth();
        TPD_RES_X = DISP_GetScreenHeight();
    }
    else
    #endif
    { 
#ifdef CONFIG_CUSTOM_LCM_X
#ifndef CONFIG_MTK_FPGA
        TPD_RES_X = DISP_GetScreenWidth();
        TPD_RES_Y = DISP_GetScreenHeight();
#endif
#else
		TPD_RES_X = simple_strtoul(CONFIG_LCM_WIDTH, NULL, 0);
        TPD_RES_Y = simple_strtoul(CONFIG_LCM_HEIGHT, NULL, 0);
#endif     
    }

	printk("mtk_tpd: TPD_RES_X = %d, TPD_RES_Y = %d\n", TPD_RES_X, TPD_RES_Y);

	tpd_mode = TPD_MODE_NORMAL;
	tpd_mode_axis = 0;
	tpd_mode_min = TPD_RES_Y / 2;
	tpd_mode_max = TPD_RES_Y;
	tpd_mode_keypad_tolerance = TPD_RES_X * TPD_RES_X / 1600;
	/* struct input_dev dev initialization and registration */
	tpd->dev->name = TPD_DEVICE;
	set_bit(EV_ABS, tpd->dev->evbit);
	set_bit(EV_KEY, tpd->dev->evbit);
	set_bit(ABS_X, tpd->dev->absbit);
	set_bit(ABS_Y, tpd->dev->absbit);
	set_bit(ABS_PRESSURE, tpd->dev->absbit);
#if !defined(CONFIG_MTK_S3320) && !defined(CONFIG_MTK_S3320_47) && !defined(CONFIG_MTK_S3320_50) && !defined(CONFIG_MTK_MIT200) && !defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) && !defined(CONFIG_MTK_S7020)
	set_bit(BTN_TOUCH, tpd->dev->keybit);
#endif /* CONFIG_MTK_S3320 */
	set_bit(INPUT_PROP_DIRECT, tpd->dev->propbit);

	/* save dev for regulator_get() before tpd_local_init() */
	tpd->tpd_dev = &pdev->dev;
#if 1
	for (i = 1; i < TP_DRV_MAX_COUNT; i++) {
		/* add tpd driver into list */
		if (tpd_driver_list[i].tpd_device_name != NULL) {
			tpd_driver_list[i].tpd_local_init();
			/* msleep(1); */
			if (tpd_load_status == 1) {
				TPD_DMESG("[mtk-tpd]tpd_probe, tpd_driver_name=%s\n",
					  tpd_driver_list[i].tpd_device_name);
				g_tpd_drv = &tpd_driver_list[i];
				break;
			}
		}
	}
	if (g_tpd_drv == NULL) {
		if (tpd_driver_list[0].tpd_device_name != NULL) {
			g_tpd_drv = &tpd_driver_list[0];
			/* touch_type:0: r-touch, 1: C-touch */
			touch_type = 0;
			g_tpd_drv->tpd_local_init();
			TPD_DMESG("[mtk-tpd]Generic touch panel driver\n");
		} else {
			TPD_DMESG("[mtk-tpd]cap touch and Generic touch both are not loaded!!\n");
			return 0;
		}
	}
#ifdef CONFIG_HAS_EARLYSUSPEND
#ifndef CONFIG_MTK_FPGA
	MTK_TS_early_suspend_handler.suspend = g_tpd_drv->suspend;
	MTK_TS_early_suspend_handler.resume = g_tpd_drv->resume;
#ifdef CONFIG_EARLYSUSPEND
	register_early_suspend(&MTK_TS_early_suspend_handler);
#endif
#endif
#endif
#endif
/* #ifdef TPD_TYPE_CAPACITIVE */
	/* TPD_TYPE_CAPACITIVE handle */
	if (touch_type == 1) {

		set_bit(ABS_MT_TRACKING_ID, tpd->dev->absbit);
		set_bit(ABS_MT_TOUCH_MAJOR, tpd->dev->absbit);
		set_bit(ABS_MT_TOUCH_MINOR, tpd->dev->absbit);
		set_bit(ABS_MT_POSITION_X, tpd->dev->absbit);
		set_bit(ABS_MT_POSITION_Y, tpd->dev->absbit);
#if 0				/* linux kernel update from 2.6.35 --> 3.0 */
		tpd->dev->absmax[ABS_MT_POSITION_X] = TPD_RES_X;
		tpd->dev->absmin[ABS_MT_POSITION_X] = 0;
		tpd->dev->absmax[ABS_MT_POSITION_Y] = TPD_RES_Y;
		tpd->dev->absmin[ABS_MT_POSITION_Y] = 0;
		tpd->dev->absmax[ABS_MT_TOUCH_MAJOR] = 100;
		tpd->dev->absmin[ABS_MT_TOUCH_MINOR] = 0;
#else
		input_set_abs_params(tpd->dev, ABS_MT_POSITION_X, 0, TPD_RES_X, 0, 0);
		input_set_abs_params(tpd->dev, ABS_MT_POSITION_Y, 0, TPD_RES_Y, 0, 0);
#if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_47) || defined(CONFIG_MTK_S3320_50) || defined(CONFIG_MTK_MIT200) || defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) || defined(CONFIG_MTK_S7020)
		input_set_abs_params(tpd->dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
		input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
		input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MINOR, 0, 15, 0, 0);
        input_mt_init_slots(tpd->dev, 10, 0);
#else
		input_set_abs_params(tpd->dev, ABS_MT_TOUCH_MAJOR, 0, 100, 0, 0);
		input_set_abs_params(tpd->dev, ABS_MT_TOUCH_MINOR, 0, 100, 0, 0);
#endif /* CONFIG_MTK_S3320 */
#endif
		TPD_DMESG("Cap touch panel driver\n");
	}
/* #endif */
#if 0				/* linux kernel update from 2.6.35 --> 3.0 */
	tpd->dev->absmax[ABS_X] = TPD_RES_X;
	tpd->dev->absmin[ABS_X] = 0;
	tpd->dev->absmax[ABS_Y] = TPD_RES_Y;
	tpd->dev->absmin[ABS_Y] = 0;

	tpd->dev->absmax[ABS_PRESSURE] = 255;
	tpd->dev->absmin[ABS_PRESSURE] = 0;
#else
	input_set_abs_params(tpd->dev, ABS_X, 0, TPD_RES_X, 0, 0);
	input_set_abs_params(tpd->dev, ABS_Y, 0, TPD_RES_Y, 0, 0);
	input_abs_set_res(tpd->dev, ABS_X, TPD_RES_X);
	input_abs_set_res(tpd->dev, ABS_Y, TPD_RES_Y);
	input_set_abs_params(tpd->dev, ABS_PRESSURE, 0, 255, 0, 0);
    input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);

#endif
	if (input_register_device(tpd->dev))
		TPD_DMESG("input_register_device failed.(tpd)\n");
	else
		tpd_register_flag = 1;
	/* init R-Touch */
#if 0
	if (touch_type == 0) {
		g_tpd_drv->tpd_local_init();
	}
#endif
	if (g_tpd_drv->tpd_have_button) {
		tpd_button_init();
	}

	if (g_tpd_drv->attrs.num)
		tpd_create_attributes(&pdev->dev, &g_tpd_drv->attrs);

	return 0;
}
Beispiel #15
0
static int sh_keysc_probe(struct platform_device *pdev)
{
	struct sh_keysc_priv *priv;
	struct sh_keysc_info *pdata;
	struct resource *res;
	struct input_dev *input;
	int i;
	int irq, error;

	if (!pdev->dev.platform_data) {
		dev_err(&pdev->dev, "no platform data defined\n");
		error = -EINVAL;
		goto err0;
	}

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

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

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (priv == NULL) {
		dev_err(&pdev->dev, "failed to allocate driver data\n");
		error = -ENOMEM;
		goto err0;
	}

	platform_set_drvdata(pdev, priv);
	memcpy(&priv->pdata, pdev->dev.platform_data, sizeof(priv->pdata));
	pdata = &priv->pdata;

	priv->iomem_base = ioremap_nocache(res->start, resource_size(res));
	if (priv->iomem_base == NULL) {
		dev_err(&pdev->dev, "failed to remap I/O memory\n");
		error = -ENXIO;
		goto err1;
	}

	priv->input = input_allocate_device();
	if (!priv->input) {
		dev_err(&pdev->dev, "failed to allocate input device\n");
		error = -ENOMEM;
		goto err2;
	}

	input = priv->input;
	input->evbit[0] = BIT_MASK(EV_KEY);

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

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

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

	error = request_threaded_irq(irq, NULL, sh_keysc_isr, IRQF_ONESHOT,
				     dev_name(&pdev->dev), pdev);
	if (error) {
		dev_err(&pdev->dev, "failed to request IRQ\n");
		goto err3;
	}

	for (i = 0; i < SH_KEYSC_MAXKEYS; i++)
		__set_bit(pdata->keycodes[i], input->keybit);
	__clear_bit(KEY_RESERVED, input->keybit);

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

	pm_runtime_enable(&pdev->dev);
	pm_runtime_get_sync(&pdev->dev);

	sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) |
		       pdata->scan_timing);
	sh_keysc_level_mode(priv, 0);

	device_init_wakeup(&pdev->dev, 1);

	return 0;

 err4:
	free_irq(irq, pdev);
 err3:
	input_free_device(input);
 err2:
	iounmap(priv->iomem_base);
 err1:
	kfree(priv);
 err0:
	return error;
}
Beispiel #16
0
static int __init amikbd_init(void)
{
    int i, j, err;

    if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
        return -ENODEV;

    if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
        return -EBUSY;

    amikbd_dev = input_allocate_device();
    if (!amikbd_dev) {
        printk(KERN_ERR "amikbd: not enough memory for input device\n");
        err = -ENOMEM;
        goto fail1;
    }

    amikbd_dev->name = "Amiga Keyboard";
    amikbd_dev->phys = "amikbd/input0";
    amikbd_dev->id.bustype = BUS_AMIGA;
    amikbd_dev->id.vendor = 0x0001;
    amikbd_dev->id.product = 0x0001;
    amikbd_dev->id.version = 0x0100;

    amikbd_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);

    for (i = 0; i < 0x78; i++)
        set_bit(i, amikbd_dev->keybit);

    for (i = 0; i < MAX_NR_KEYMAPS; i++) {
        static u_short temp_map[NR_KEYS] __initdata;
        if (!key_maps[i])
            continue;
        memset(temp_map, 0, sizeof(temp_map));
        for (j = 0; j < 0x78; j++) {
            if (!amikbd_keycode[j])
                continue;
            temp_map[j] = key_maps[i][amikbd_keycode[j]];
        }
        for (j = 0; j < NR_KEYS; j++) {
            if (!temp_map[j])
                temp_map[j] = 0xf200;
        }
        memcpy(key_maps[i], temp_map, sizeof(temp_map));
    }
    ciaa.cra &= ~0x41;     /* serial data in, turn off TA */
    if (request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
            amikbd_interrupt)) {
        err = -EBUSY;
        goto fail2;
    }

    err = input_register_device(amikbd_dev);
    if (err)
        goto fail3;

    return 0;

 fail3:    free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
 fail2:    input_free_device(amikbd_dev);
 fail1:    release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
    return err;
}
Beispiel #17
0
/**
 * bu21013_probe() - initializes the i2c-client touchscreen driver
 * @client: i2c client structure pointer
 * @id: i2c device id pointer
 *
 * This function used to initializes the i2c-client touchscreen
 * driver and returns integer.
 */
static int __devinit bu21013_probe(struct i2c_client *client,
					const struct i2c_device_id *id)
{
	struct bu21013_ts_data *bu21013_data;
	struct input_dev *in_dev;
	const struct bu21013_platform_device *pdata =
					client->dev.platform_data;
	int error;

	if (!i2c_check_functionality(client->adapter,
					I2C_FUNC_SMBUS_BYTE_DATA)) {
		dev_err(&client->dev, "i2c smbus byte data not supported\n");
		return -EIO;
	}

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

	bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL);
	in_dev = input_allocate_device();
	if (!bu21013_data || !in_dev) {
		dev_err(&client->dev, "device memory alloc failed\n");
		error = -ENOMEM;
		goto err_free_mem;
	}

	bu21013_data->in_dev = in_dev;
	bu21013_data->chip = pdata;
	bu21013_data->client = client;
	bu21013_data->touch_stopped = false;
	init_waitqueue_head(&bu21013_data->wait);

	/* configure the gpio pins */
	if (pdata->cs_en) {
		error = pdata->cs_en(pdata->cs_pin);
		if (error < 0) {
			dev_err(&client->dev, "chip init failed\n");
			goto err_free_mem;
		}
	}

	/* configure the touch panel controller */
	error = bu21013_init_chip(bu21013_data);
	if (error) {
		dev_err(&client->dev, "error in bu21013 config\n");
		goto err_cs_disable;
	}

	/* register the device to input subsystem */
	in_dev->name = DRIVER_TP;
	in_dev->id.bustype = BUS_I2C;
	in_dev->dev.parent = &client->dev;

	__set_bit(EV_SYN, in_dev->evbit);
	__set_bit(EV_KEY, in_dev->evbit);
	__set_bit(EV_ABS, in_dev->evbit);

	input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0,
						pdata->x_max_res, 0, 0);
	input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0,
						pdata->y_max_res, 0, 0);
	input_set_drvdata(in_dev, bu21013_data);

	error = request_threaded_irq(pdata->irq, NULL, bu21013_gpio_irq,
				     IRQF_TRIGGER_FALLING | IRQF_SHARED,
				     DRIVER_TP, bu21013_data);
	if (error) {
		dev_err(&client->dev, "request irq %d failed\n", pdata->irq);
		goto err_cs_disable;
	}

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

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

	return 0;

err_free_irq:
	bu21013_free_irq(bu21013_data);
err_cs_disable:
	pdata->cs_dis(pdata->cs_pin);
err_free_mem:
	input_free_device(in_dev);
	kfree(bu21013_data);

	return error;
}
Beispiel #18
0
static int __init hub_proxi_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int ret;
	struct hub_proxi_data *data;
	struct device *dev = &client->dev;

	// 20100827 [email protected] [START_LGE]
	hub_proximity_client = client;
	// 20100827 [email protected] [END_LGE]

	//Event_to_application(client);

	data = kzalloc(sizeof(struct hub_proxi_data), GFP_KERNEL);
	if (!data) {
		return -ENOMEM;
	}

	// 20100810 [email protected] GPIO Initialization [START_LGE]
	omap_mux_init_gpio(PROXI_LDO_EN, OMAP_PIN_OUTPUT);
	omap_mux_init_gpio(PROXI_OUT, OMAP_PIN_INPUT_PULLUP | OMAP_PIN_OFF_WAKEUPENABLE);

	ret = gpio_request(PROXI_LDO_EN, "proximity enable gpio");
	if(ret < 0) {	
		printk("can't get hub proximity enable GPIO\n");
		kzfree(data);
		return -ENOSYS;
	}

	data->use_int_mode = true; //interrupt mode
	//	gpio_request(proxi_output_1, "proxi int gpio");
	//	gpio_direction_input(proxi_output_1); 
	//	request_irq(client->irq, hub_proxi_sleep_int_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "proxi_driver", data); 
	//	enable_irq_wake(client->irq); //wake up irq

	if (data->use_int_mode) {

/* LGE_CHANGE_S, [email protected], 2011-04-06, Disable Proximity Log */
		//printk(KERN_WARNING"%s() : interrupt mode. START\n", __func__);
/* LGE_CHANGE_E, [email protected], 2011-04-06, Disable Proximity Log */

		if (gpio_request(PROXI_OUT, "proxi interrupt gpio") < 0) {
			printk("can't get hub proxi irq GPIO\n");
			kzfree(data);
			return -ENOSYS;
		}

		ret = gpio_direction_input(PROXI_OUT); 

		ret = request_irq(gpio_to_irq(PROXI_OUT), hub_proxi_int_handler, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "proximity_interrupt", data); 
		if (ret < 0){
			printk(KERN_INFO "[Proximity INT] GPIO 14 IRQ line set up failed!\n");
			free_irq(gpio_to_irq(PROXI_OUT), data);
			return -ENOSYS;
		}	

		/* Make the interrupt on wake up OMAP which is in suspend mode */		
		ret = enable_irq_wake(gpio_to_irq(PROXI_OUT));		
		if(ret < 0){
			printk(KERN_INFO "[Proximity INT] GPIO 14 wake up source setting failed!\n");
			disable_irq_wake(gpio_to_irq(PROXI_OUT));
			return -ENOSYS;
		}

/* LGE_CHANGE_S, [email protected], 2011-04-06, Disable Proximity Log */
		//printk(KERN_WARNING"%s() : interrupt mode. END\n", __func__);
/* LGE_CHANGE_E, [email protected], 2011-04-06, Disable Proximity Log */

		//		ret = request_irq(client->irq, hub_proxi_int_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "proxi_driver", data); 
	} 
	else {
		hrtimer_init(&data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
		data->timer.function = hub_proxi_timer_func;
		data->delay = PROXI_DEFAULT_DELAY_NS;
		//hrtimer_start(&data->timer, ktime_set(0, data->delay), HRTIMER_MODE_REL);
	}
	INIT_WORK(&data->work, hub_proxi_det_work);

	/*LGE_CHANGE_S [[email protected]] 2010-01-04, ldoc control*/

#if defined(CONFIG_MACH_LGE_HEAVEN_REV_A)
	reg = regulator_get(dev, "vaux3");
	if (reg == NULL) {
		printk(KERN_ERR": Failed to get PROXI power resources !! \n");
		return -ENODEV;
	}
#elif defined(CONFIG_MACH_LGE_HUB)
	reg = regulator_get(dev, "vaux2");
	if (reg == NULL) {
		printk(KERN_ERR": Failed to get PROXI power resources !! \n");
		return -ENODEV;
	}
#endif
	/*LGE_CHANGE_S [[email protected]] 2010-01-04, ldoc control*/

	//hub_proxi_power_onoff(1);
	//hub_proxi_i2c_init(client);

	data->client = client;
	i2c_set_clientdata(client, data);

	data->input_dev = input_allocate_device();
	if (data->input_dev == NULL) {
		printk(KERN_ERR "%s: input_allocate: not enough memory\n",
				__FUNCTION__);
		return -ENOMEM;
	}

	set_bit(EV_KEY, data->input_dev->evbit);
	set_bit(KEY_POWER, data->input_dev->keybit);
	set_bit(EV_ABS, data->input_dev->evbit);
	input_set_abs_params(data->input_dev, ABS_DISTANCE, 0, 1, 0, 0);
	data->input_dev->name = "proximity";
// 20101004 [email protected], fix initial operation of proximity sensor [START_LGE]
	data->input_dev->abs[ABS_DISTANCE] = -1;
// 20101004 [email protected], fix initial operation of proximity sensor [END_LGE]
	ret = input_register_device(data->input_dev);
	if (ret) {
		printk(KERN_ERR "%s: Fail to register device\n", __FUNCTION__);
		goto ERROR1;
	}

	if ((ret = sysfs_create_group(&dev->kobj, &hub_proxi_group)))
		goto ERROR3;

/* LGE_CHANGE_S, [email protected], 2011-04-13, Sync with P970 */
#ifdef CONFIG_HAS_EARLYSUSPEND /* 20110304 [email protected] late_resume_lcd [START] */
	data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 1;
	data->early_suspend.suspend = hub_proxi_early_suspend;
	data->early_suspend.resume = hub_proxi_late_resume;
	register_early_suspend(&data->early_suspend);
#endif /* 20110304 [email protected] late_resume_lcd [END] */
/* LGE_CHANGE_E, [email protected], 2011-04-13, Sync with P970 */

	return 0;

ERROR3:
	input_unregister_device(data->input_dev);
ERROR1:
	kfree(data);

	return ret;
}
static int cyttsp4_proximity_probe(struct cyttsp4_device *ttsp)
{
	struct cyttsp4_proximity_data *pd;
	struct device *dev = &ttsp->dev;
	struct cyttsp4_proximity_platform_data *pdata = dev_get_platdata(dev);
	int rc = 0;

	dev_info(dev, "%s\n", __func__);
	dev_dbg(dev, "%s: debug on\n", __func__);
	dev_vdbg(dev, "%s: verbose debug on\n", __func__);

	if (pdata == NULL) {
		dev_err(dev, "%s: Missing platform data\n", __func__);
		rc = -ENODEV;
		goto error_no_pdata;
	}

	pd = kzalloc(sizeof(*pd), GFP_KERNEL);
	if (pd == NULL) {
		dev_err(dev, "%s: Error, kzalloc\n", __func__);
		rc = -ENOMEM;
		goto error_alloc_data_failed;
	}

	mutex_init(&pd->report_lock);
	mutex_init(&pd->sysfs_lock);
	pd->ttsp = ttsp;
	pd->pdata = pdata;
	dev_set_drvdata(dev, pd);
	/* Create the input device and register it. */
	dev_vdbg(dev, "%s: Create the input device and register it\n",
		__func__);
	pd->input = input_allocate_device();
	if (pd->input == NULL) {
		dev_err(dev, "%s: Error, failed to allocate input device\n",
			__func__);
		rc = -ENOSYS;
		goto error_alloc_failed;
	}

	pd->input->name = ttsp->name;
	scnprintf(pd->phys, sizeof(pd->phys)-1, "%s", dev_name(dev));
	pd->input->phys = pd->phys;
	pd->input->dev.parent = &pd->ttsp->dev;
	input_set_drvdata(pd->input, pd);

	pm_runtime_enable(dev);

	/* get sysinfo */
	pd->si = cyttsp4_request_sysinfo(ttsp);
	if (pd->si) {
		rc = cyttsp4_setup_input_device_and_sysfs(ttsp);
		if (rc)
			goto error_init_input;
	} else {
		dev_err(dev, "%s: Fail get sysinfo pointer from core p=%p\n",
			__func__, pd->si);
		cyttsp4_subscribe_attention(ttsp, CY_ATTEN_STARTUP,
			cyttsp4_setup_input_attention, 0);
	}

	dev_dbg(dev, "%s: ok\n", __func__);
	return 0;

error_init_input:
	pm_runtime_suspend(dev);
	pm_runtime_disable(dev);
	input_free_device(pd->input);
error_alloc_failed:
	dev_set_drvdata(dev, NULL);
	kfree(pd);
error_alloc_data_failed:
error_no_pdata:
	dev_err(dev, "%s failed.\n", __func__);
	return rc;
}
static int __devinit twl6040_vibra_probe(struct platform_device *pdev)
{
	struct twl6040_vibra_data *pdata = pdev->dev.platform_data;
	struct vibra_info *info;
	int ret;

	if (!pdata) {
		dev_err(&pdev->dev, "platform_data not available\n");
		return -EINVAL;
	}

	info = kzalloc(sizeof(*info), GFP_KERNEL);
	if (!info) {
		dev_err(&pdev->dev, "couldn't allocate memory\n");
		return -ENOMEM;
	}

	info->dev = &pdev->dev;
	info->twl6040 = dev_get_drvdata(pdev->dev.parent);
	info->vibldrv_res = pdata->vibldrv_res;
	info->vibrdrv_res = pdata->vibrdrv_res;
	info->viblmotor_res = pdata->viblmotor_res;
	info->vibrmotor_res = pdata->vibrmotor_res;
	if ((!info->vibldrv_res && !info->viblmotor_res) ||
	    (!info->vibrdrv_res && !info->vibrmotor_res)) {
		dev_err(info->dev, "invalid vibra driver/motor resistance\n");
		ret = -EINVAL;
		goto err_kzalloc;
	}

	info->irq = platform_get_irq(pdev, 0);
	if (info->irq < 0) {
		dev_err(info->dev, "invalid irq\n");
		ret = -EINVAL;
		goto err_kzalloc;
	}

	mutex_init(&info->mutex);

	info->input_dev = input_allocate_device();
	if (info->input_dev == NULL) {
		dev_err(info->dev, "couldn't allocate input device\n");
		ret = -ENOMEM;
		goto err_kzalloc;
	}

	input_set_drvdata(info->input_dev, info);

	info->input_dev->name = "twl6040:vibrator";
	info->input_dev->id.version = 1;
	info->input_dev->dev.parent = pdev->dev.parent;
	info->input_dev->close = twl6040_vibra_close;
	__set_bit(FF_RUMBLE, info->input_dev->ffbit);

	ret = input_ff_create_memless(info->input_dev, NULL, vibra_play);
	if (ret < 0) {
		dev_err(info->dev, "couldn't register vibrator to FF\n");
		goto err_ialloc;
	}

	ret = input_register_device(info->input_dev);
	if (ret < 0) {
		dev_err(info->dev, "couldn't register input device\n");
		goto err_iff;
	}

	platform_set_drvdata(pdev, info);

	ret = request_threaded_irq(info->irq, NULL, twl6040_vib_irq_handler, 0,
				   "twl6040_irq_vib", info);
	if (ret) {
		dev_err(info->dev, "VIB IRQ request failed: %d\n", ret);
		goto err_irq;
	}

	info->supplies[0].supply = "vddvibl";
	info->supplies[1].supply = "vddvibr";
	ret = regulator_bulk_get(info->dev, ARRAY_SIZE(info->supplies),
				 info->supplies);
	if (ret) {
		dev_err(info->dev, "couldn't get regulators %d\n", ret);
		goto err_regulator;
	}

	if (pdata->vddvibl_uV) {
		ret = regulator_set_voltage(info->supplies[0].consumer,
					    pdata->vddvibl_uV,
					    pdata->vddvibl_uV);
		if (ret) {
			dev_err(info->dev, "failed to set VDDVIBL volt %d\n",
				ret);
			goto err_voltage;
		}
	}

	if (pdata->vddvibr_uV) {
		ret = regulator_set_voltage(info->supplies[1].consumer,
					    pdata->vddvibr_uV,
					    pdata->vddvibr_uV);
		if (ret) {
			dev_err(info->dev, "failed to set VDDVIBR volt %d\n",
				ret);
			goto err_voltage;
		}
	}

	info->workqueue = alloc_workqueue("twl6040-vibra", 0, 0);
	if (info->workqueue == NULL) {
		dev_err(info->dev, "couldn't create workqueue\n");
		ret = -ENOMEM;
		goto err_voltage;
	}
	INIT_WORK(&info->play_work, vibra_play_work);

	return 0;

err_voltage:
	regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
err_regulator:
	free_irq(info->irq, info);
err_irq:
	input_unregister_device(info->input_dev);
	info->input_dev = NULL;
err_iff:
	if (info->input_dev)
		input_ff_destroy(info->input_dev);
err_ialloc:
	input_free_device(info->input_dev);
err_kzalloc:
	kfree(info);
	return ret;
}
static int __init wake_gestures_init(void)
{
	int rc = 0;

	rc = input_register_handler(&wg_input_handler);
	if (rc)
		pr_err("%s: Failed to register wg_input_handler\n", __func__);

	s2w_input_wq = create_workqueue("s2wiwq");
	if (!s2w_input_wq) {
		pr_err("%s: Failed to create s2wiwq workqueue\n", __func__);
		return -EFAULT;
	}
	INIT_WORK(&s2w_input_work, s2w_input_callback);
		
	dt2w_input_wq = create_workqueue("dt2wiwq");
	if (!dt2w_input_wq) {
		pr_err("%s: Failed to create dt2wiwq workqueue\n", __func__);
		return -EFAULT;
	}
	INIT_WORK(&dt2w_input_work, dt2w_input_callback);
		
	wake_lock_init(&dt2w_wakelock, WAKE_LOCK_SUSPEND, "dt2w_wakelock");
		
#if (WAKE_GESTURES_ENABLED)
	gesture_dev = input_allocate_device();
	if (!gesture_dev) {
		pr_err("Can't allocate gesture device\n");
		goto err_alloc_dev;
	}
	
	gesture_dev->name = "wake_gesture";
	gesture_dev->phys = "wake_gesture/input0";
	input_set_capability(gesture_dev, EV_REL, WAKE_GESTURE);

	rc = input_register_device(gesture_dev);
	if (rc) {
		pr_err("%s: input_register_device err=%d\n", __func__, rc);
		goto err_gesture_dev;
	}
#endif

	android_touch_kobj = kobject_create_and_add("android_touch", NULL) ;
	if (android_touch_kobj == NULL) {
		pr_warn("%s: android_touch_kobj create_and_add failed\n", __func__);
	}
	rc = sysfs_create_file(android_touch_kobj, &dev_attr_sweep2wake.attr);
	if (rc) {
		pr_warn("%s: sysfs_create_file failed for sweep2wake\n", __func__);
	}
	rc = sysfs_create_file(android_touch_kobj, &dev_attr_sweep2sleep.attr);
	if (rc) {
		pr_warn("%s: sysfs_create_file failed for sweep2sleep\n", __func__);
	}
		rc = sysfs_create_file(android_touch_kobj, &dev_attr_doubletap2wake.attr);
	if (rc) {
		pr_warn("%s: sysfs_create_file failed for doubletap2wake\n", __func__);
	}
	rc = sysfs_create_file(android_touch_kobj, &dev_attr_vib_strength.attr);
	if (rc) {
		pr_warn("%s: sysfs_create_file failed for vib_strength\n", __func__);
	}
	rc = sysfs_create_file(android_touch_kobj, &dev_attr_camera_gesture.attr);
	if (rc) {
		pr_warn("%s: sysfs_create_file failed for camera_gesture\n", __func__);
	}
#if (WAKE_GESTURES_ENABLED)
	rc = sysfs_create_file(android_touch_kobj, &dev_attr_wake_gestures.attr);
	if (rc) {
		pr_warn("%s: sysfs_create_file failed for wake_gestures\n", __func__);
	}

	return 0;

err_gesture_dev:
	input_free_device(gesture_dev);
err_alloc_dev:
#endif

	return 0;
}
Beispiel #22
0
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;

	/* 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);

	error = request_irq(keypad_data->irq, omap4_keypad_interrupt,
			     IRQF_TRIGGER_RISING,
			     "omap4-keypad", keypad_data);
	if (error) {
		dev_err(&pdev->dev, "failed to register interrupt\n");
		goto err_free_input;
	}

	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);
	return 0;

err_pm_disable:
	pm_runtime_disable(&pdev->dev);
	free_irq(keypad_data->irq, keypad_data);
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;
}
/**
 * snd_jack_new - Create a new jack
 * @card:  the card instance
 * @id:    an identifying string for this jack
 * @type:  a bitmask of enum snd_jack_type values that can be detected by
 *         this jack
 * @jjack: Used to provide the allocated jack object to the caller.
 *
 * Creates a new jack object.
 *
 * Returns zero if successful, or a negative error code on failure.
 * On success jjack will be initialised.
 */
int snd_jack_new(struct snd_card *card, const char *id, int type,
		 struct snd_jack **jjack)
{
	struct snd_jack *jack;
	int err;
	int i;
	static struct snd_device_ops ops = {
		.dev_free = snd_jack_dev_free,
		.dev_register = snd_jack_dev_register,
	};

	jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
	if (jack == NULL)
		return -ENOMEM;

	jack->id = kstrdup(id, GFP_KERNEL);

// AUD_MOD start
	if( !strcmp(jack->id, "Headset Jack"))
	{
		printk("Headset Jack swdev register\n");
		jack->swdev.name = "h2w";
		jack->swdev.print_name = simple_remote_print_name;
		err = switch_dev_register(&jack->swdev);
		if (err < 0) {
			printk("switch_dev_register failed:%d\n", err);
		}
	}
	else if( !strcmp(jack->id, "Button Jack"))
	{
		printk("Button Jack swdev register\n");
		jack->swdev.name = "h2w_Bt";
		jack->swdev.print_name = simple_remote_print_name;
		err = switch_dev_register(&jack->swdev);
		if (err < 0) {
			printk("switch_dev_register failed:%d\n", err);
		}
	}
	// SoMC Uevent End

	// SoMC Input Event Start
	jack->indev_appkey = input_allocate_device();
	if (jack->indev_appkey == NULL) {
		err = -ENOMEM;
		goto fail_input;
	}

	jack->indev_appkey->phys = "ALSA";

	jack->type = type;

	for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++)
		if (type & (1 << i))
			input_set_capability(jack->indev_appkey, EV_SW,
						 jack_switch_types[i]);
// AUD_MOD end

	jack->input_dev = input_allocate_device();
	if (jack->input_dev == NULL) {
		err = -ENOMEM;
		goto fail_input;
	}

	jack->input_dev->phys = "ALSA";

	jack->type = type;

	for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++)
		if (type & (1 << i))
			input_set_capability(jack->input_dev, EV_SW,
					     jack_switch_types[i]);

	err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
	if (err < 0)
		goto fail_input;

	*jjack = jack;

	return 0;

fail_input:
	input_free_device(jack->indev_appkey);  // AUD_MOD
	input_free_device(jack->input_dev);
	kfree(jack->id);
	kfree(jack);
	return err;
}
Beispiel #24
0
static int lge_hsd_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct max1462x_platform_data *pdata = pdev->dev.platform_data;


	struct hsd_info *hi;

	HSD_DBG("lge_hsd_probe\n");

	hi = kzalloc(sizeof(struct hsd_info), GFP_KERNEL);

	if ( hi == NULL) {
		HSD_ERR("Failed to allloate headset per device info\n");
		return -ENOMEM;
	}

	if(pdev->dev.of_node){
		pdata = devm_kzalloc(&pdev->dev,sizeof(struct max1462x_platform_data),GFP_KERNEL);
		if(!pdata){
			HSD_ERR("Failed to allocate memory\n");
			return -ENOMEM;
		}
		pdev->dev.platform_data = pdata;

		max1462x_parse_dt(&pdev->dev,pdata);
	} else {
		pdata = devm_kzalloc(&pdev->dev,sizeof(struct max1462x_platform_data),GFP_KERNEL);
		if(!pdata){
			HSD_ERR("Failed to allocate memory\n");
			return -ENOMEM;
		}
		else
			pdata = pdev->dev.platform_data;
	}
	hi->key_code = pdata->key_code;

	platform_set_drvdata(pdev, hi);

	atomic_set(&hi->btn_state, 0);
	atomic_set(&hi->is_3_pole_or_not, 1);
	atomic_set(&hi->irq_key_enabled, FALSE);

	hi->gpio_mic_en = pdata->gpio_mic_en;
	hi->gpio_detect = pdata->gpio_detect;
	hi->gpio_key = pdata->gpio_key;
	hi->gpio_set_value_func = pdata->gpio_set_value_func;
	hi->gpio_get_value_func = pdata->gpio_get_value_func;
#ifdef CONFIG_SWITCH_MAX1462X_WA
	hi->latency_for_key = msecs_to_jiffies(50);
#else
	hi->latency_for_key = msecs_to_jiffies(50); /* convert milli to jiffies */
#endif
	mutex_init(&hi->mutex_lock);
	INIT_WORK(&hi->work, detect_work);
	INIT_DELAYED_WORK(&hi->work_for_key_pressed, button_pressed);
	INIT_DELAYED_WORK(&hi->work_for_key_released, button_released);

	ret = gpio_request(hi->gpio_mic_en, "gpio_mic_en");
	if (ret < 0) {
		HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_request\n", hi->gpio_mic_en);
		goto error_02;
	}

	ret = gpio_direction_output(hi->gpio_mic_en, 0);
	if (ret < 0) {
		HSD_ERR("Failed to configure gpio%d (gpio_mic_en) gpio_direction_input\n", hi->gpio_mic_en);
		goto error_02;
	}
	HSD_DBG("gpio_get_value_cansleep(hi->gpio_mic_en) = %d\n", gpio_get_value_cansleep(hi->gpio_mic_en));

	/* init gpio_detect */
	ret = gpio_request(hi->gpio_detect, "gpio_detect");
	if (ret < 0) {
		HSD_ERR("Failed to configure gpio%d (gpio_det) gpio_request\n", hi->gpio_detect);
		goto error_03;
	}

	ret = gpio_direction_input(hi->gpio_detect);
	if (ret < 0) {
		HSD_ERR("Failed to configure gpio%d (gpio_det) gpio_direction_input\n", hi->gpio_detect);
		goto error_03;
	}

	/*init gpio_key */
	ret = gpio_request(hi->gpio_key, "gpio_key");
	if (ret < 0) {
		HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_request\n", hi->gpio_key);
		goto error_04;
	}

	ret = gpio_direction_input(hi->gpio_key);
	if (ret < 0) {
		HSD_ERR("Failed to configure gpio%d (gpio_key) gpio_direction_input\n", hi->gpio_key);
		goto error_04;
	}


	/* initialize irq of gpio_key */
	hi->irq_key = gpio_to_irq(hi->gpio_key);

	HSD_DBG("hi->irq_key = %d\n", hi->irq_key);

	if (hi->irq_key < 0) {
		HSD_ERR("Failed to get interrupt number\n");
		ret = hi->irq_key;
		goto error_06;
	}
	ret = request_threaded_irq(hi->irq_key, NULL, button_irq_handler,
			IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi);
	if (ret) {
		HSD_ERR("failed to request button irq\n");
		goto error_06;
	}

	ret = irq_set_irq_wake(hi->irq_key, 1);
	if (ret < 0) {
		HSD_ERR("Failed to set irq_key interrupt wake\n");
		goto error_06;
	}
	enable_irq(hi->irq_key);

	hi->irq_detect = gpio_to_irq(hi->gpio_detect);
	HSD_DBG("hi->irq_detect = %d\n", hi->irq_detect);

	if (hi->irq_detect < 0) {
		HSD_ERR("Failed to get interrupt number\n");
		ret = hi->irq_detect;
		goto error_07;
	}
	ret = request_threaded_irq(hi->irq_detect, NULL, earjack_det_irq_handler,
			IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, pdev->name, hi);

	if (ret) {
		HSD_ERR("failed to request button irq\n");
		goto error_07;
	}

	ret = irq_set_irq_wake(hi->irq_detect, 1);
	if (ret < 0) {
		HSD_ERR("Failed to set gpio_detect interrupt wake\n");
		goto error_07;
	}
	/* initialize switch device */
	hi->sdev.name = pdata->switch_name;
	hi->sdev.print_state = lge_hsd_print_state;
	hi->sdev.print_name = lge_hsd_print_name;

	ret = switch_dev_register(&hi->sdev);
	if (ret < 0) {
		HSD_ERR("Failed to register switch device\n");
		goto error_08;
	}

	/* initialize input device */
	hi->input = input_allocate_device();
	if (!hi->input) {
		HSD_ERR("Failed to allocate input device\n");
		ret = -ENOMEM;
		goto error_09;
	}

	hi->input->name = pdata->keypad_name;

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

#ifdef CONFIG_SWITCH_MAX1462X_WA
	setup_timer( &hi->hook_disable_timer, hook_disable_timer_func, 0 );
	hook_disable = 0;
#endif
	/* headset tx noise */
	{
		struct qpnp_vadc_result result;
		int acc_read_value = 0;
		int i, rc;
		int count = 3;

		for (i = 0; i < count; i++)
		{
			rc = qpnp_vadc_read(P_MUX6_1_1,&result);

			if (rc < 0)
			{
				if (rc == -ETIMEDOUT) {
					pr_err("[DEBUG]adc read timeout \n");
				} else {
					pr_err("[DEBUG]adc read error - %d\n", rc);
				}
			}
			else
			{
				acc_read_value = (int)result.physical;
				pr_info("%s: acc_read_value - %d\n", __func__, (int)result.physical);
				break;
			}
		}
	}

	set_bit(EV_SYN, hi->input->evbit);
	set_bit(EV_KEY, hi->input->evbit);
	set_bit(EV_SW, hi->input->evbit);
	set_bit(hi->key_code, hi->input->keybit);
	set_bit(SW_HEADPHONE_INSERT, hi->input->swbit);
	set_bit(SW_MICROPHONE_INSERT, hi->input->swbit);
	input_set_capability(hi->input, EV_KEY, KEY_MEDIA);
	input_set_capability(hi->input, EV_KEY, KEY_VOLUMEUP);
	input_set_capability(hi->input, EV_KEY, KEY_VOLUMEDOWN);
	ret = input_register_device(hi->input);
	if (ret) {
		HSD_ERR("Failed to register input device\n");
		goto error_09;
	}

	if (!(hi->gpio_get_value_func(hi->gpio_detect)))

#ifdef CONFIG_MAX1462X_USE_LOCAL_WORK_QUEUE
		/* to detect in initialization with eacjack insertion */
		queue_work(local_max1462x_workqueue, &(hi->work));
#else
	/* to detect in initialization with eacjack insertion */
	schedule_work(&(hi->work));
#endif

	zw_irqs_info_register(hi->irq_key, 1);
	zw_irqs_info_register(hi->irq_detect, 1);
	return ret;

error_09:
	input_free_device(hi->input);
error_08:
	switch_dev_unregister(&hi->sdev);
error_07:
	free_irq(hi->irq_detect, 0);
error_06:
	free_irq(hi->irq_key, 0);
error_04:
	gpio_free(hi->gpio_key);
error_03:
	gpio_free(hi->gpio_detect);
error_02:
	gpio_free(hi->gpio_mic_en);
	kfree(hi);
	return ret;
}
static int synaptics_rmi4_prox_init(struct synaptics_rmi4_data *rmi4_data)
{
	int retval;
	unsigned char attr_count;

	prox = kzalloc(sizeof(*prox), GFP_KERNEL);
	if (!prox) {
		dev_err(rmi4_data->pdev->dev.parent,
				"%s: Failed to alloc mem for prox\n",
				__func__);
		retval = -ENOMEM;
		goto exit;
	}

	prox->finger_data = kzalloc(sizeof(*(prox->finger_data)), GFP_KERNEL);
	if (!prox->finger_data) {
		dev_err(rmi4_data->pdev->dev.parent,
				"%s: Failed to alloc mem for finger_data\n",
				__func__);
		retval = -ENOMEM;
		goto exit_free_prox;
	}

	prox->rmi4_data = rmi4_data;

	retval = prox_scan_pdt();
	if (retval < 0)
		goto exit_free_finger_data;

	prox->hover_finger_en = true;

	retval = prox_set_hover_finger_en();
	if (retval < 0)
		return retval;

	prox->prox_dev = input_allocate_device();
	if (prox->prox_dev == NULL) {
		dev_err(rmi4_data->pdev->dev.parent,
				"%s: Failed to allocate proximity device\n",
				__func__);
		retval = -ENOMEM;
		goto exit_free_finger_data;
	}

	prox->prox_dev->name = PLATFORM_DRIVER_NAME;
	prox->prox_dev->phys = PROX_PHYS_NAME;
	prox->prox_dev->id.product = SYNAPTICS_DSX_DRIVER_PRODUCT;
	prox->prox_dev->id.version = SYNAPTICS_DSX_DRIVER_VERSION;
	prox->prox_dev->dev.parent = rmi4_data->pdev->dev.parent;
	input_set_drvdata(prox->prox_dev, rmi4_data);

	set_bit(EV_KEY, prox->prox_dev->evbit);
	set_bit(EV_ABS, prox->prox_dev->evbit);
	set_bit(BTN_TOUCH, prox->prox_dev->keybit);
	set_bit(BTN_TOOL_FINGER, prox->prox_dev->keybit);
#ifdef INPUT_PROP_DIRECT
	set_bit(INPUT_PROP_DIRECT, prox->prox_dev->propbit);
#endif

	prox_set_params();

	retval = input_register_device(prox->prox_dev);
	if (retval) {
		dev_err(rmi4_data->pdev->dev.parent,
				"%s: Failed to register proximity device\n",
				__func__);
		goto exit_free_input_device;
	}

	for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
		retval = sysfs_create_file(&rmi4_data->input_dev->dev.kobj,
				&attrs[attr_count].attr);
		if (retval < 0) {
			dev_err(rmi4_data->pdev->dev.parent,
					"%s: Failed to create sysfs attributes\n",
					__func__);
			goto exit_free_sysfs;
		}
	}

	return 0;

exit_free_sysfs:
	for (attr_count--; attr_count >= 0; attr_count--) {
		sysfs_remove_file(&rmi4_data->input_dev->dev.kobj,
				&attrs[attr_count].attr);
	}

	input_unregister_device(prox->prox_dev);
	prox->prox_dev = NULL;

exit_free_input_device:
	if (prox->prox_dev)
		input_free_device(prox->prox_dev);

exit_free_finger_data:
	kfree(prox->finger_data);

exit_free_prox:
	kfree(prox);
	prox = NULL;

exit:
	return retval;
}
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) {
		if(pdata->Headset_gpio == NULL){
			dev_err(&pdev->dev,"failed init headset,please full hook_io_init function in board\n");
			goto failed_free_dev;
		}
		ret = pdata->headset_io_init(pdata->Headset_gpio);
		if (ret) 
			goto failed_free_dev;

		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_dev;
		enable_irq_wake(headset->irq[HEADSET]);
	}
	else
		goto failed_free_dev;
//------------------------------------------------------------------
	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_dev;
		}
		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 #27
0
static int opencores_kbd_probe(struct platform_device *pdev)
{
	struct input_dev *input;
	struct opencores_kbd *opencores_kbd;
	struct resource *res;
	int irq, i, error;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res) {
		dev_err(&pdev->dev, "missing board memory resource\n");
		return -EINVAL;
	}

	irq = platform_get_irq(pdev, 0);
	if (irq < 0) {
		dev_err(&pdev->dev, "missing board IRQ resource\n");
		return -EINVAL;
	}

	opencores_kbd = kzalloc(sizeof(*opencores_kbd), GFP_KERNEL);
	input = input_allocate_device();
	if (!opencores_kbd || !input) {
		dev_err(&pdev->dev, "failed to allocate device structures\n");
		error = -ENOMEM;
		goto err_free_mem;
	}

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

	opencores_kbd->addr = ioremap(res->start, resource_size(res));
	if (!opencores_kbd->addr) {
		dev_err(&pdev->dev, "failed to remap I/O memory\n");
		error = -ENXIO;
		goto err_rel_mem;
	}

	opencores_kbd->input = input;
	opencores_kbd->irq = irq;

	input->name = pdev->name;
	input->phys = "opencores-kbd/input0";
	input->dev.parent = &pdev->dev;

	input_set_drvdata(input, opencores_kbd);

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

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

	__set_bit(EV_KEY, input->evbit);

	for (i = 0; i < ARRAY_SIZE(opencores_kbd->keycodes); i++) {
		/*
		 * OpenCores controller happens to have scancodes match
		 * our KEY_* definitions.
		 */
		opencores_kbd->keycodes[i] = i;
		__set_bit(opencores_kbd->keycodes[i], input->keybit);
	}
	__clear_bit(KEY_RESERVED, input->keybit);

	error = request_irq(irq, &opencores_kbd_isr,
			    IRQF_TRIGGER_RISING, pdev->name, opencores_kbd);
	if (error) {
		dev_err(&pdev->dev, "unable to claim irq %d\n", irq);
		goto err_unmap_mem;
	}

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

	platform_set_drvdata(pdev, opencores_kbd);

	return 0;

 err_free_irq:
	free_irq(irq, opencores_kbd);
 err_unmap_mem:
	iounmap(opencores_kbd->addr);
 err_rel_mem:
	release_mem_region(res->start, resource_size(res));
 err_free_mem:
	input_free_device(input);
	kfree(opencores_kbd);

	return error;
}
Beispiel #28
0
static int __init hdaps_init(void)
{
	int ret;

	/* Determine axis orientation orientation */
	if (hdaps_invert == HDAPS_ORIENT_UNDEFINED) /* set by module param? */
		if (dmi_check_system(hdaps_whitelist) < 1) /* in whitelist? */
			hdaps_invert = 0; /* default */

	/* Init timer before platform_driver_register, in case of suspend */
	init_timer(&hdaps_timer);
	hdaps_timer.function = hdaps_mousedev_poll;
	ret = platform_driver_register(&hdaps_driver);
	if (ret)
		goto out;

	pdev = platform_device_register_simple("hdaps", -1, NULL, 0);
	if (IS_ERR(pdev)) {
		ret = PTR_ERR(pdev);
		goto out_driver;
	}

	ret = sysfs_create_group(&pdev->dev.kobj, &hdaps_attribute_group);
	if (ret)
		goto out_device;

	hdaps_idev = input_allocate_device();
	if (!hdaps_idev) {
		ret = -ENOMEM;
		goto out_group;
	}

	hdaps_idev_raw = input_allocate_device();
	if (!hdaps_idev_raw) {
		ret = -ENOMEM;
		goto out_idev_first;
	}

	/* calibration for the input device (deferred to avoid delay) */
	needs_calibration = 1;

	/* initialize the joystick-like fuzzed input device */
	hdaps_idev->name = "hdaps";
	hdaps_idev->phys = "hdaps/input0";
	hdaps_idev->id.bustype = BUS_HOST;
	hdaps_idev->id.vendor  = HDAPS_INPUT_VENDOR;
	hdaps_idev->id.product = HDAPS_INPUT_PRODUCT;
	hdaps_idev->id.version = HDAPS_INPUT_JS_VERSION;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
	hdaps_idev->cdev.dev = &pdev->dev;
#endif
	hdaps_idev->evbit[0] = BIT(EV_ABS);
	hdaps_idev->open = hdaps_mousedev_open;
	hdaps_idev->close = hdaps_mousedev_close;
	input_set_abs_params(hdaps_idev, ABS_X,
			-256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
	input_set_abs_params(hdaps_idev, ABS_Y,
			-256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);

	ret = input_register_device(hdaps_idev);
	if (ret)
		goto out_idev;

	/* initialize the raw data input device */
	hdaps_idev_raw->name = "raw_hdaps_data";
	hdaps_idev_raw->phys = "hdaps/input1";
	hdaps_idev_raw->id.bustype = BUS_HOST;
	hdaps_idev_raw->id.vendor  = HDAPS_INPUT_VENDOR;
	hdaps_idev_raw->id.product = HDAPS_INPUT_PRODUCT;
	hdaps_idev_raw->id.version = HDAPS_INPUT_RAW_VERSION;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
	hdaps_idev_raw->cdev.dev = &pdev->dev;
#endif
	hdaps_idev_raw->evbit[0] = BIT(EV_ABS);
	hdaps_idev_raw->open = hdaps_mousedev_open;
	hdaps_idev_raw->close = hdaps_mousedev_close;
	input_set_abs_params(hdaps_idev_raw, ABS_X, -32768, 32767, 0, 0);
	input_set_abs_params(hdaps_idev_raw, ABS_Y, -32768, 32767, 0, 0);

	ret = input_register_device(hdaps_idev_raw);
	if (ret)
		goto out_idev_reg_first;

	printk(KERN_INFO "hdaps: driver successfully loaded.\n");
	return 0;

out_idev_reg_first:
	input_unregister_device(hdaps_idev);
out_idev:
	input_free_device(hdaps_idev_raw);
out_idev_first:
	input_free_device(hdaps_idev);
out_group:
	sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
out_device:
	platform_device_unregister(pdev);
out_driver:
	platform_driver_unregister(&hdaps_driver);
	hdaps_device_shutdown();
out:
	printk(KERN_WARNING "hdaps: driver init failed (ret=%d)!\n", ret);
	return ret;
}
static int hv_keypad_probe(struct i2c_client *client, const struct i2c_device_id *id)
{

	struct input_dev *input_dev;
	int err = 0;
	int i;

	printk("======================================hv_keypad_probe Begin=============================================\n");
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		err = -ENODEV;
		goto exit_check_functionality_failed;
	}

	hv_keypad = kzalloc(sizeof(*hv_keypad), GFP_KERNEL);
	if (!hv_keypad)	{
		err = -ENOMEM;
		goto exit_alloc_data_failed;
	}

	this_client = client;
	i2c_set_clientdata(client, hv_keypad);

	hv_init();
	
	INIT_DELAYED_WORK(&hv_keypad->work, hv_read_loop);
	hv_keypad->queue = create_singlethread_workqueue(dev_name(&client->dev));
	if (!hv_keypad->queue) {
		err = -ESRCH;
		goto exit_create_singlethread;
	}

	input_dev = input_allocate_device();
	if (!input_dev) {
		err = -ENOMEM;
		dev_err(&client->dev, "failed to allocate input device\n");
		goto exit_input_dev_alloc_failed;
	}

	hv_keypad->input_dev = input_dev;

	input_dev->name = HV_NAME;
	input_dev->phys = "sun4ikbd/inputx";
	input_dev->id.bustype = BUS_HOST;
	input_dev->id.vendor = 0x0001;
	input_dev->id.product = 0x0001;
	input_dev->id.version = 0x0100;

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

	for (i = 1; i < 6; i++)
		set_bit(i, input_dev->keybit);

	err = input_register_device(input_dev);
	if (err) {
		dev_err(&client->dev,
		"hv_ts_probe: failed to register input device: %s\n",
		dev_name(&client->dev));
		goto exit_input_register_device_failed;
	}

	queue_delayed_work(hv_keypad->queue, &hv_keypad->work, DELAY_PERIOD);
#ifdef CONFIG_HAS_EARLYSUSPEND
	printk("==register_early_suspend =\n");
	keyboard_data = kzalloc(sizeof(*keyboard_data), GFP_KERNEL);
	if (keyboard_data == NULL) {
		err = -ENOMEM;
		goto err_alloc_data_failed;
	}
	keyboard_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	keyboard_data->early_suspend.suspend = hv2605_keyboard_suspend;
	keyboard_data->early_suspend.resume	= hv2605_keyboard_resume;
	register_early_suspend(&keyboard_data->early_suspend);
#endif
	printk("==probe ======over =\n");

    return 0;

exit_input_register_device_failed:
	input_free_device(input_dev);
exit_input_dev_alloc_failed:
exit_create_singlethread:
	printk("==singlethread error =\n");
	i2c_set_clientdata(client, NULL);
	kfree(hv_keypad);
exit_alloc_data_failed:
exit_check_functionality_failed:
#ifdef CONFIG_HAS_EARLYSUSPEND
 err_alloc_data_failed:
#endif
	return err;
}
Beispiel #30
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;

#ifndef CONFIG_LGE_HEADSET
	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;
#endif

	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);
#ifdef CONFIG_MACH_MSM7X27_ALOHAV
	input_set_capability(ipdev, EV_SW, SW_MICROPHONE_INSERT);
#endif
	input_set_capability(ipdev, EV_KEY, KEY_POWER);
	input_set_capability(ipdev, EV_KEY, KEY_END);

	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:
#ifndef CONFIG_LGE_HEADSET
	switch_dev_unregister(&hs->sdev);
err_switch_dev_register:
#endif
	kfree(hs);
	return rc;
}