Pull input subsystem updates from Dmitry Torokhov: "Two new drivers for Elan hardware (for I2C touchpad and touchscreen found in several Chromebooks and other devices), a driver for Goodix touch panel, and small fixes to Cypress I2C trackpad and other input drivers. Also we switched to use __maybe_unused instead of gating suspend/ resume code with #ifdef guards to get better compile coverage" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (27 commits) Input: gpio_keys - fix warning regarding uninitialized 'button' variable Input: add support for Elan eKTH I2C touchscreens Input: gpio_keys - fix warning regarding uninitialized 'irq' variable Input: cyapa - use 'error' for error codes Input: cyapa - fix resuming the device Input: gpio_keys - add device tree support for interrupt only keys Input: amikbd - allocate temporary keymap buffer on the stack Input: amikbd - fix build if !CONFIG_HW_CONSOLE Input: lm8323 - missing error check in lm8323_set_disable() Input: initialize device counter variables with -1 Input: initialize input_no to -1 to avoid subtraction Input: i8042 - do not try to load on Intel NUC D54250WYK Input: atkbd - correct MSC_SCAN events for force_release keys Input: cyapa - switch to using managed resources Input: lifebook - use "static inline" instead of "inline" in lifebook.h Input: touchscreen - use __maybe_unused instead of ifdef around suspend/resume Input: mouse - use __maybe_unused instead of ifdef around suspend/resume Input: misc - use __maybe_unused instead of ifdef around suspend/resume Input: cap11xx - support for irq-active-high option Input: cap11xx - add support for various cap11xx devices ...
		
			
				
	
	
		
			206 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			206 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
 | |
|  *
 | |
|  * This program is free software; you can redistribute it and/or modify
 | |
|  * it under the terms of the GNU General Public License version 2 and
 | |
|  * only version 2 as published by the Free Software Foundation.
 | |
|  *
 | |
|  * This program is distributed in the hope that it will be useful,
 | |
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | |
|  * GNU General Public License for more details.
 | |
|  */
 | |
| 
 | |
| #include <linux/module.h>
 | |
| #include <linux/kernel.h>
 | |
| #include <linux/errno.h>
 | |
| #include <linux/slab.h>
 | |
| #include <linux/input.h>
 | |
| #include <linux/interrupt.h>
 | |
| #include <linux/platform_device.h>
 | |
| #include <linux/regmap.h>
 | |
| #include <linux/log2.h>
 | |
| #include <linux/of.h>
 | |
| 
 | |
| #define PON_CNTL_1 0x1C
 | |
| #define PON_CNTL_PULL_UP BIT(7)
 | |
| #define PON_CNTL_TRIG_DELAY_MASK (0x7)
 | |
| 
 | |
| /**
 | |
|  * struct pmic8xxx_pwrkey - pmic8xxx pwrkey information
 | |
|  * @key_press_irq: key press irq number
 | |
|  */
 | |
| struct pmic8xxx_pwrkey {
 | |
| 	int key_press_irq;
 | |
| };
 | |
| 
 | |
| static irqreturn_t pwrkey_press_irq(int irq, void *_pwr)
 | |
| {
 | |
| 	struct input_dev *pwr = _pwr;
 | |
| 
 | |
| 	input_report_key(pwr, KEY_POWER, 1);
 | |
| 	input_sync(pwr);
 | |
| 
 | |
| 	return IRQ_HANDLED;
 | |
| }
 | |
| 
 | |
| static irqreturn_t pwrkey_release_irq(int irq, void *_pwr)
 | |
| {
 | |
| 	struct input_dev *pwr = _pwr;
 | |
| 
 | |
| 	input_report_key(pwr, KEY_POWER, 0);
 | |
| 	input_sync(pwr);
 | |
| 
 | |
| 	return IRQ_HANDLED;
 | |
| }
 | |
| 
 | |
| static int __maybe_unused pmic8xxx_pwrkey_suspend(struct device *dev)
 | |
| {
 | |
| 	struct pmic8xxx_pwrkey *pwrkey = dev_get_drvdata(dev);
 | |
| 
 | |
| 	if (device_may_wakeup(dev))
 | |
| 		enable_irq_wake(pwrkey->key_press_irq);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static int __maybe_unused pmic8xxx_pwrkey_resume(struct device *dev)
 | |
| {
 | |
| 	struct pmic8xxx_pwrkey *pwrkey = dev_get_drvdata(dev);
 | |
| 
 | |
| 	if (device_may_wakeup(dev))
 | |
| 		disable_irq_wake(pwrkey->key_press_irq);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static SIMPLE_DEV_PM_OPS(pm8xxx_pwr_key_pm_ops,
 | |
| 		pmic8xxx_pwrkey_suspend, pmic8xxx_pwrkey_resume);
 | |
| 
 | |
| static int pmic8xxx_pwrkey_probe(struct platform_device *pdev)
 | |
| {
 | |
| 	struct input_dev *pwr;
 | |
| 	int key_release_irq = platform_get_irq(pdev, 0);
 | |
| 	int key_press_irq = platform_get_irq(pdev, 1);
 | |
| 	int err;
 | |
| 	unsigned int delay;
 | |
| 	unsigned int pon_cntl;
 | |
| 	struct regmap *regmap;
 | |
| 	struct pmic8xxx_pwrkey *pwrkey;
 | |
| 	u32 kpd_delay;
 | |
| 	bool pull_up;
 | |
| 
 | |
| 	if (of_property_read_u32(pdev->dev.of_node, "debounce", &kpd_delay))
 | |
| 		kpd_delay = 15625;
 | |
| 
 | |
| 	if (kpd_delay > 62500 || kpd_delay == 0) {
 | |
| 		dev_err(&pdev->dev, "invalid power key trigger delay\n");
 | |
| 		return -EINVAL;
 | |
| 	}
 | |
| 
 | |
| 	pull_up = of_property_read_bool(pdev->dev.of_node, "pull-up");
 | |
| 
 | |
| 	regmap = dev_get_regmap(pdev->dev.parent, NULL);
 | |
| 	if (!regmap) {
 | |
| 		dev_err(&pdev->dev, "failed to locate regmap for the device\n");
 | |
| 		return -ENODEV;
 | |
| 	}
 | |
| 
 | |
| 	pwrkey = devm_kzalloc(&pdev->dev, sizeof(*pwrkey), GFP_KERNEL);
 | |
| 	if (!pwrkey)
 | |
| 		return -ENOMEM;
 | |
| 
 | |
| 	pwrkey->key_press_irq = key_press_irq;
 | |
| 
 | |
| 	pwr = devm_input_allocate_device(&pdev->dev);
 | |
| 	if (!pwr) {
 | |
| 		dev_dbg(&pdev->dev, "Can't allocate power button\n");
 | |
| 		return -ENOMEM;
 | |
| 	}
 | |
| 
 | |
| 	input_set_capability(pwr, EV_KEY, KEY_POWER);
 | |
| 
 | |
| 	pwr->name = "pmic8xxx_pwrkey";
 | |
| 	pwr->phys = "pmic8xxx_pwrkey/input0";
 | |
| 
 | |
| 	delay = (kpd_delay << 10) / USEC_PER_SEC;
 | |
| 	delay = 1 + ilog2(delay);
 | |
| 
 | |
| 	err = regmap_read(regmap, PON_CNTL_1, &pon_cntl);
 | |
| 	if (err < 0) {
 | |
| 		dev_err(&pdev->dev, "failed reading PON_CNTL_1 err=%d\n", err);
 | |
| 		return err;
 | |
| 	}
 | |
| 
 | |
| 	pon_cntl &= ~PON_CNTL_TRIG_DELAY_MASK;
 | |
| 	pon_cntl |= (delay & PON_CNTL_TRIG_DELAY_MASK);
 | |
| 	if (pull_up)
 | |
| 		pon_cntl |= PON_CNTL_PULL_UP;
 | |
| 	else
 | |
| 		pon_cntl &= ~PON_CNTL_PULL_UP;
 | |
| 
 | |
| 	err = regmap_write(regmap, PON_CNTL_1, pon_cntl);
 | |
| 	if (err < 0) {
 | |
| 		dev_err(&pdev->dev, "failed writing PON_CNTL_1 err=%d\n", err);
 | |
| 		return err;
 | |
| 	}
 | |
| 
 | |
| 	err = devm_request_irq(&pdev->dev, key_press_irq, pwrkey_press_irq,
 | |
| 			       IRQF_TRIGGER_RISING,
 | |
| 			       "pmic8xxx_pwrkey_press", pwr);
 | |
| 	if (err) {
 | |
| 		dev_err(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n",
 | |
| 			key_press_irq, err);
 | |
| 		return err;
 | |
| 	}
 | |
| 
 | |
| 	err = devm_request_irq(&pdev->dev, key_release_irq, pwrkey_release_irq,
 | |
| 			       IRQF_TRIGGER_RISING,
 | |
| 			       "pmic8xxx_pwrkey_release", pwr);
 | |
| 	if (err) {
 | |
| 		dev_err(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n",
 | |
| 			key_release_irq, err);
 | |
| 		return err;
 | |
| 	}
 | |
| 
 | |
| 	err = input_register_device(pwr);
 | |
| 	if (err) {
 | |
| 		dev_err(&pdev->dev, "Can't register power key: %d\n", err);
 | |
| 		return err;
 | |
| 	}
 | |
| 
 | |
| 	platform_set_drvdata(pdev, pwrkey);
 | |
| 	device_init_wakeup(&pdev->dev, 1);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static int pmic8xxx_pwrkey_remove(struct platform_device *pdev)
 | |
| {
 | |
| 	device_init_wakeup(&pdev->dev, 0);
 | |
| 
 | |
| 	return 0;
 | |
| }
 | |
| 
 | |
| static const struct of_device_id pm8xxx_pwr_key_id_table[] = {
 | |
| 	{ .compatible = "qcom,pm8058-pwrkey" },
 | |
| 	{ .compatible = "qcom,pm8921-pwrkey" },
 | |
| 	{ }
 | |
| };
 | |
| MODULE_DEVICE_TABLE(of, pm8xxx_pwr_key_id_table);
 | |
| 
 | |
| static struct platform_driver pmic8xxx_pwrkey_driver = {
 | |
| 	.probe		= pmic8xxx_pwrkey_probe,
 | |
| 	.remove		= pmic8xxx_pwrkey_remove,
 | |
| 	.driver		= {
 | |
| 		.name	= "pm8xxx-pwrkey",
 | |
| 		.pm	= &pm8xxx_pwr_key_pm_ops,
 | |
| 		.of_match_table = pm8xxx_pwr_key_id_table,
 | |
| 	},
 | |
| };
 | |
| module_platform_driver(pmic8xxx_pwrkey_driver);
 | |
| 
 | |
| MODULE_ALIAS("platform:pmic8xxx_pwrkey");
 | |
| MODULE_DESCRIPTION("PMIC8XXX Power Key driver");
 | |
| MODULE_LICENSE("GPL v2");
 | |
| MODULE_AUTHOR("Trilok Soni <tsoni@codeaurora.org>");
 |