Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 1 | /** |
| 2 | * twl4030-pwrbutton.c - TWL4030 Power Button Input Driver |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Nokia Corporation |
| 5 | * |
| 6 | * Written by Peter De Schrijver <peter.de-schrijver@nokia.com> |
| 7 | * Several fixes by Felipe Balbi <felipe.balbi@nokia.com> |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General |
| 10 | * Public License. See the file "COPYING" in the main directory of this |
| 11 | * archive for more details. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/platform_device.h> |
Santosh Shilimkar | b07682b | 2009-12-13 20:05:51 +0100 | [diff] [blame] | 30 | #include <linux/i2c/twl.h> |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 31 | |
| 32 | #define PWR_PWRON_IRQ (1 << 0) |
| 33 | |
| 34 | #define STS_HW_CONDITIONS 0xf |
| 35 | |
| 36 | static irqreturn_t powerbutton_irq(int irq, void *_pwr) |
| 37 | { |
| 38 | struct input_dev *pwr = _pwr; |
| 39 | int err; |
| 40 | u8 value; |
| 41 | |
Peter Ujfalusi | f321981 | 2012-11-14 10:10:49 -0800 | [diff] [blame] | 42 | err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &value, STS_HW_CONDITIONS); |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 43 | if (!err) { |
NeilBrown | 112b51c | 2012-07-29 22:25:51 -0700 | [diff] [blame] | 44 | pm_wakeup_event(pwr->dev.parent, 0); |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 45 | input_report_key(pwr, KEY_POWER, value & PWR_PWRON_IRQ); |
| 46 | input_sync(pwr); |
| 47 | } else { |
| 48 | dev_err(pwr->dev.parent, "twl4030: i2c error %d while reading" |
| 49 | " TWL4030 PM_MASTER STS_HW_CONDITIONS register\n", err); |
| 50 | } |
| 51 | |
| 52 | return IRQ_HANDLED; |
| 53 | } |
| 54 | |
Sebastian Reichel | c81e592 | 2013-11-19 13:55:12 -0800 | [diff] [blame] | 55 | static int twl4030_pwrbutton_probe(struct platform_device *pdev) |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 56 | { |
| 57 | struct input_dev *pwr; |
| 58 | int irq = platform_get_irq(pdev, 0); |
| 59 | int err; |
| 60 | |
Sebastian Reichel | 7f9ce64 | 2013-11-19 13:56:18 -0800 | [diff] [blame] | 61 | pwr = devm_input_allocate_device(&pdev->dev); |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 62 | if (!pwr) { |
Sebastian Reichel | 0330f93 | 2013-11-19 13:53:31 -0800 | [diff] [blame] | 63 | dev_err(&pdev->dev, "Can't allocate power button\n"); |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 64 | return -ENOMEM; |
| 65 | } |
| 66 | |
| 67 | pwr->evbit[0] = BIT_MASK(EV_KEY); |
| 68 | pwr->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); |
| 69 | pwr->name = "twl4030_pwrbutton"; |
| 70 | pwr->phys = "twl4030_pwrbutton/input0"; |
| 71 | pwr->dev.parent = &pdev->dev; |
| 72 | |
Sebastian Reichel | 7f9ce64 | 2013-11-19 13:56:18 -0800 | [diff] [blame] | 73 | err = devm_request_threaded_irq(&pwr->dev, irq, NULL, powerbutton_irq, |
Fabio Estevam | 5f4eede | 2015-05-15 15:55:23 -0700 | [diff] [blame] | 74 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | |
| 75 | IRQF_ONESHOT, |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 76 | "twl4030_pwrbutton", pwr); |
| 77 | if (err < 0) { |
Sebastian Reichel | 0330f93 | 2013-11-19 13:53:31 -0800 | [diff] [blame] | 78 | dev_err(&pdev->dev, "Can't get IRQ for pwrbutton: %d\n", err); |
Sebastian Reichel | 7f9ce64 | 2013-11-19 13:56:18 -0800 | [diff] [blame] | 79 | return err; |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | err = input_register_device(pwr); |
| 83 | if (err) { |
Sebastian Reichel | 0330f93 | 2013-11-19 13:53:31 -0800 | [diff] [blame] | 84 | dev_err(&pdev->dev, "Can't register power button: %d\n", err); |
Sebastian Reichel | 7f9ce64 | 2013-11-19 13:56:18 -0800 | [diff] [blame] | 85 | return err; |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | platform_set_drvdata(pdev, pwr); |
NeilBrown | c42bfd7 | 2014-11-07 15:46:56 -0800 | [diff] [blame] | 89 | device_init_wakeup(&pdev->dev, true); |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 90 | |
| 91 | return 0; |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Sebastian Reichel | c81e592 | 2013-11-19 13:55:12 -0800 | [diff] [blame] | 94 | #ifdef CONFIG_OF |
| 95 | static const struct of_device_id twl4030_pwrbutton_dt_match_table[] = { |
| 96 | { .compatible = "ti,twl4030-pwrbutton" }, |
| 97 | {}, |
| 98 | }; |
| 99 | MODULE_DEVICE_TABLE(of, twl4030_pwrbutton_dt_match_table); |
| 100 | #endif |
| 101 | |
Markus Lehtonen | dda7b73 | 2010-07-07 09:45:18 -0700 | [diff] [blame] | 102 | static struct platform_driver twl4030_pwrbutton_driver = { |
Sebastian Reichel | c81e592 | 2013-11-19 13:55:12 -0800 | [diff] [blame] | 103 | .probe = twl4030_pwrbutton_probe, |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 104 | .driver = { |
| 105 | .name = "twl4030_pwrbutton", |
Sebastian Reichel | c81e592 | 2013-11-19 13:55:12 -0800 | [diff] [blame] | 106 | .of_match_table = of_match_ptr(twl4030_pwrbutton_dt_match_table), |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 107 | }, |
| 108 | }; |
Sebastian Reichel | c81e592 | 2013-11-19 13:55:12 -0800 | [diff] [blame] | 109 | module_platform_driver(twl4030_pwrbutton_driver); |
Felipe Balbi | 68d8bf0 | 2009-04-19 23:07:50 -0700 | [diff] [blame] | 110 | |
| 111 | MODULE_ALIAS("platform:twl4030_pwrbutton"); |
| 112 | MODULE_DESCRIPTION("Triton2 Power Button"); |
| 113 | MODULE_LICENSE("GPL"); |
| 114 | MODULE_AUTHOR("Peter De Schrijver <peter.de-schrijver@nokia.com>"); |
| 115 | MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>"); |
| 116 | |