static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_keys_drvdata *ddata;
	struct gpio_keys_button *button = NULL;
	struct gpio_button_data *bdata = NULL ;
	struct device *dev = &pdev->dev;
	struct gpio_keys_platform_data alt_pdata;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;
#ifdef CONFIG_SENSORS_HALL
	int ret;
	struct device *sec_key;
#endif

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

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

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
#ifdef CONFIG_SENSORS_HALL
	ddata->gpio_flip_cover = pdata->gpio_flip_cover;
	ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover);
#endif
	mutex_init(&ddata->disable_lock);

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

	input->name = pdata->name ? : pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
#ifdef CONFIG_SENSORS_HALL
	input->evbit[0] |= BIT_MASK(EV_SW);
	input_set_capability(input, EV_SW, SW_FLIP);
#endif
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

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

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

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

		error = gpio_keys_setup_key(pdev, input, bdata, button);
		if (error)
			goto fail2;
#ifdef KEY_BOOSTER
		error = gpio_key_init_dvfs(bdata);
		if (error < 0) {
			dev_err(dev, "Fail get dvfs level for touch booster\n");
			goto fail2;
		}
#endif
		if (button->wakeup)
			wakeup = 1;
	}
	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
	if (error) {
		dev_err(dev, "Unable to export keys/switches, error: %d\n",
			error);
		goto fail2;
	}

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

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

#ifdef CONFIG_SENSORS_HALL
	sec_key = device_create(sec_class, NULL, 0, NULL, "sec_key");
	if (IS_ERR(sec_key))
		pr_err("Failed to create device(sec_key)!\n");

	ret = device_create_file(sec_key, &dev_attr_hall_detect);
	if (ret < 0) {
		pr_err("Failed to create device file(%s)!, error: %d\n",
			dev_attr_hall_detect.attr.name, ret);
	}

	ret = device_create_file(sec_key, &dev_attr_sec_key_pressed);
	if (ret) {
		pr_err("Failed to create device file in sysfs entries(%s)!\n",
		dev_attr_sec_key_pressed.attr.name);
	}
	ret = device_create_file(sec_key, &dev_attr_wakeup_keys);
	if (ret < 0) {
		pr_err("Failed to create device file(%s), error: %d\n",
			dev_attr_wakeup_keys.attr.name, ret);
	}
	dev_set_drvdata(sec_key, ddata);
#endif
	device_init_wakeup(&pdev->dev, 1);

	return 0;

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

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

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

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

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

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
#ifdef CONFIG_SENSORS_HALL
	ddata->gpio_flip_cover = pdata->gpio_flip_cover;
	ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover);;

	wake_lock_init(&ddata->flip_wake_lock, WAKE_LOCK_SUSPEND,
		"flip wake lock");
#endif
	mutex_init(&ddata->disable_lock);

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

	input->name = pdata->name ? : pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
#ifdef CONFIG_SENSORS_HALL
	input->evbit[0] |= BIT_MASK(EV_SW);
	input_set_capability(input, EV_SW, SW_FLIP);
#endif
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

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

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

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

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

		if (button->wakeup)
			wakeup = 1;

#ifdef KEY_BOOSTER
		if (button->code == KEY_HOMEPAGE) {
			error = gpio_key_init_dvfs(bdata);
			if (error < 0) {
				dev_err(dev, "Fail get dvfs level for touch booster\n");
				goto fail2;
			}
		}
#endif
	}

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

	ddata->sec_key =
	    device_create(sec_class, NULL, 0, ddata, "sec_key");
	if (IS_ERR(ddata->sec_key))
		dev_err(dev, "Failed to create sec_key device\n");

	error = sysfs_create_group(&ddata->sec_key->kobj, &sec_key_attr_group);
	if (error) {
		dev_err(dev, "Failed to create the test sysfs: %d\n",
			error);
		goto fail2;
	}

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

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

	device_init_wakeup(&pdev->dev, wakeup);

	return 0;

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

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

	return error;
}
Ejemplo n.º 3
0
static int __devinit gpio_keys_probe(struct platform_device *pdev)
{
	const struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
	struct gpio_keys_drvdata *ddata;
	struct gpio_keys_button *button = NULL;
	struct gpio_button_data *bdata = NULL;
	struct device *dev = &pdev->dev;
	struct gpio_keys_platform_data alt_pdata;
	struct input_dev *input;
	int i, error;
	int wakeup = 0;
	int ret;
	struct device *sec_key;
#ifdef CONFIG_SEC_PATEK_PROJECT
	struct device *sec_keypad;
	struct device *sec_flip;
#endif

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

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

	ddata->input = input;
	ddata->n_buttons = pdata->nbuttons;
	ddata->enable = pdata->enable;
	ddata->disable = pdata->disable;
#ifdef CONFIG_SENSORS_HALL_DEBOUNCE
	ddata->debounce_set = pdata->debounce_set;
#endif
#ifdef CONFIG_SENSORS_HALL

#if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_BERLUTI_PROJECT)\
	|| defined (CONFIG_SEC_MATISSE_PROJECT)	|| defined (CONFIG_SEC_ATLANTIC_PROJECT)\
    || defined (CONFIG_SEC_MEGA2_PROJECT) || defined (CONFIG_SEC_T8_PROJECT) || defined (CONFIG_SEC_T10_PROJECT) || defined(CONFIG_SEC_HESTIA_PROJECT)
	ret = gpio_request(pdata->gpio_flip_cover,"HALL");
	if(ret)
		printk(KERN_CRIT "[HALL IC] gpio Request FAIL\n");
	else {
		gpio_tlmm_config(GPIO_CFG(pdata->gpio_flip_cover,0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL,GPIO_CFG_2MA),GPIO_CFG_DISABLE);
	}
#endif
	ddata->gpio_flip_cover = pdata->gpio_flip_cover;
	ddata->flip_code = pdata->flip_code;
	ddata->irq_flip_cover = gpio_to_irq(ddata->gpio_flip_cover);
	wake_lock_init(&ddata->flip_wake_lock, WAKE_LOCK_SUSPEND,
		"flip_wake_lock");
	flip_status_before = -1;
#endif
	mutex_init(&ddata->disable_lock);
#ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
	mutex_init(&ddata->irq_lock);
#endif

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

	input->name = pdata->name ? : pdev->name;
	input->phys = "gpio-keys/input0";
	input->dev.parent = &pdev->dev;
#ifdef CONFIG_SENSORS_HALL
	if(ddata->gpio_flip_cover != 0) {
		input->evbit[0] |= BIT_MASK(EV_SW);
		input_set_capability(input, EV_SW, ddata->flip_code);
	}
#endif
#ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
	ddata->gsm_area = false;
	ddata->cover_state = false;
	ddata->workaround_set = pdata->workaround_set;
	drv_data = ddata;
#endif
#ifdef CONFIG_SENSORS_HALL_DEBOUNCE
	ddata->debounce_set = false;
#endif
	input->open = gpio_keys_open;
	input->close = gpio_keys_close;

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

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

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

		error = gpio_keys_setup_key(pdev, input, bdata, button);
		if (error)
			goto fail2;
#ifdef KEY_BOOSTER
		error = gpio_key_init_dvfs(bdata);
		if (error < 0) {
			dev_err(dev, "Fail get dvfs level for touch booster\n");
			goto fail2;
		}
#endif
		if (button->wakeup)
			wakeup = 1;
	}

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

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

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

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

#ifdef CONFIG_SEC_PATEK_PROJECT
	sec_keypad=device_create(sec_class, NULL, 0, NULL, "sec_keypad");
	if (device_create_file(sec_keypad, &dev_attr_brightness) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_brightness.attr.name);

	sec_flip = device_create(sec_class, NULL, 0, NULL, "sec_flip");
	if (device_create_file(sec_flip, &dev_attr_flipStatus) < 0)
		pr_err("Failed to create device file(%s)!\n", dev_attr_flipStatus.attr.name);
#endif

	ret = device_create_file(sec_key, &dev_attr_sec_key_pressed);
	if (ret) {
		pr_err("Failed to create device file in sysfs entries(%s)!\n",
				dev_attr_sec_key_pressed.attr.name);
	}
#if defined(CONFIG_SEC_S_PROJECT)
	ret = device_create_file(sec_key, &dev_attr_sec_key_pressed_code);
	if (ret) {
		pr_err("Failed to create device file in sysfs entries(%s)!\n",
				dev_attr_sec_key_pressed_code.attr.name);
	}
#endif

#ifdef CONFIG_SENSORS_HALL_IRQ_CTRL
	if(ddata->gpio_flip_cover != 0) {
		ret = device_create_file(sec_key, &dev_attr_hall_irq_ctrl);
		if (ret < 0) {
			pr_err("Failed to create device file(%s)!, error: %d\n",
				dev_attr_hall_irq_ctrl.attr.name, ret);
		}
	}
#endif
#if defined(CONFIG_SENSORS_HALL)
	if(ddata->gpio_flip_cover != 0) {
		ret = device_create_file(sec_key, &dev_attr_hall_detect);
		if (ret < 0) {
			pr_err("Failed to create device file(%s)!, error: %d\n",
				dev_attr_hall_detect.attr.name, ret);
		}
	}
#if defined(CONFIG_SENSORS_HALL_DEBOUNCE)
	if(ddata->gpio_flip_cover != 0) {
		ret = device_create_file(sec_key, &dev_attr_hall_irq_ctrl);
		if (ret < 0) {
			pr_err("Failed to create device file(%s)!, error: %d\n",
				dev_attr_hall_irq_ctrl.attr.name, ret);
		}
	}
#endif
#if defined (CONFIG_SEC_MILLET_PROJECT) || defined (CONFIG_SEC_BERLUTI_PROJECT) ||  defined (CONFIG_SEC_T8_PROJECT)
	if (!lvs1_1p8) {
		lvs1_1p8 = regulator_get(dev, "8226_lvs1");
		if(!lvs1_1p8)
			printk(KERN_CRIT "%s: regulator_get for 8226_lvs1 failed\n", __func__);
		else {
			ret = regulator_enable(lvs1_1p8);
			if (ret){
				regulator_put(lvs1_1p8);
				printk(KERN_CRIT "%s: Failed to enable regulator lvs1_1p8.\n",__func__);
			}
		}
	}
#endif

#endif

#ifdef CONFIG_USE_VM_KEYBOARD_REJECT
	reject_keyboard_specific_key = false;
	ret = device_create_file(sec_key, &dev_attr_reject_key_comb);
	if (ret < 0) {
		pr_err("Failed to create device file(%s), error: %d\n",
				dev_attr_reject_key_comb.attr.name, ret);
	}
#endif
	ret = device_create_file(sec_key, &dev_attr_wakeup_keys);
	if (ret < 0) {
		pr_err("Failed to create device file(%s), error: %d\n",
				dev_attr_wakeup_keys.attr.name, ret);
	}
	dev_set_drvdata(sec_key, ddata);

	device_init_wakeup(&pdev->dev, wakeup);

#if defined(CONFIG_SEC_PATEK_PROJECT)
	keypadled_powerset(&pdev->dev);
	dev_set_drvdata(sec_flip, ddata);
#endif

#ifdef PERIODIC_CHECK_GPIOS
    INIT_DELAYED_WORK_DEFERRABLE(&g_gpio_check_work,
            sec_gpiocheck_work);
    schedule_delayed_work(&g_gpio_check_work,
            msecs_to_jiffies(0));
#endif

	return 0;

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

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

	return error;
}