diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-17 13:06:02 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-17 13:06:02 -0500 |
| commit | d797da41b2aceed5daa8cd2eee92cd74b2a0c652 (patch) | |
| tree | f4de7daf5a81f425c057dd5a65a0e1b8056de5a9 /drivers/input/keyboard | |
| parent | d6666be6f0c43efb9475d1d35fbef9f8be61b7b1 (diff) | |
| parent | f20c86cd75f1c8c728dafd0218645ff3c5e8545d (diff) | |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
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
...
Diffstat (limited to 'drivers/input/keyboard')
| -rw-r--r-- | drivers/input/keyboard/Kconfig | 8 | ||||
| -rw-r--r-- | drivers/input/keyboard/Makefile | 2 | ||||
| -rw-r--r-- | drivers/input/keyboard/amikbd.c | 47 | ||||
| -rw-r--r-- | drivers/input/keyboard/atkbd.c | 6 | ||||
| -rw-r--r-- | drivers/input/keyboard/cap1106.c | 341 | ||||
| -rw-r--r-- | drivers/input/keyboard/cap11xx.c | 376 | ||||
| -rw-r--r-- | drivers/input/keyboard/gpio_keys.c | 37 | ||||
| -rw-r--r-- | drivers/input/keyboard/lm8323.c | 2 | ||||
| -rw-r--r-- | drivers/input/keyboard/lpc32xx-keys.c | 92 | ||||
| -rw-r--r-- | drivers/input/keyboard/mpr121_touchkey.c | 42 | ||||
| -rw-r--r-- | drivers/input/keyboard/pxa27x_keypad.c | 84 |
11 files changed, 490 insertions, 547 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index a3958c63d7d5..96ee26c555e0 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
| @@ -665,14 +665,14 @@ config KEYBOARD_CROS_EC | |||
| 665 | To compile this driver as a module, choose M here: the | 665 | To compile this driver as a module, choose M here: the |
| 666 | module will be called cros_ec_keyb. | 666 | module will be called cros_ec_keyb. |
| 667 | 667 | ||
| 668 | config KEYBOARD_CAP1106 | 668 | config KEYBOARD_CAP11XX |
| 669 | tristate "Microchip CAP1106 touch sensor" | 669 | tristate "Microchip CAP11XX based touch sensors" |
| 670 | depends on OF && I2C | 670 | depends on OF && I2C |
| 671 | select REGMAP_I2C | 671 | select REGMAP_I2C |
| 672 | help | 672 | help |
| 673 | Say Y here to enable the CAP1106 touch sensor driver. | 673 | Say Y here to enable the CAP11XX touch sensor driver. |
| 674 | 674 | ||
| 675 | To compile this driver as a module, choose M here: the | 675 | To compile this driver as a module, choose M here: the |
| 676 | module will be called cap1106. | 676 | module will be called cap11xx. |
| 677 | 677 | ||
| 678 | endif | 678 | endif |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 0a3345634d79..febafa527eb6 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
| @@ -11,7 +11,7 @@ obj-$(CONFIG_KEYBOARD_AMIGA) += amikbd.o | |||
| 11 | obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o | 11 | obj-$(CONFIG_KEYBOARD_ATARI) += atakbd.o |
| 12 | obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o | 12 | obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o |
| 13 | obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o | 13 | obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o |
| 14 | obj-$(CONFIG_KEYBOARD_CAP1106) += cap1106.o | 14 | obj-$(CONFIG_KEYBOARD_CAP11XX) += cap11xx.o |
| 15 | obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o | 15 | obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o |
| 16 | obj-$(CONFIG_KEYBOARD_CROS_EC) += cros_ec_keyb.o | 16 | obj-$(CONFIG_KEYBOARD_CROS_EC) += cros_ec_keyb.o |
| 17 | obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o | 17 | obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o |
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c index d3b8c58fcfdb..e04a3b4e55d6 100644 --- a/drivers/input/keyboard/amikbd.c +++ b/drivers/input/keyboard/amikbd.c | |||
| @@ -45,6 +45,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | |||
| 45 | MODULE_DESCRIPTION("Amiga keyboard driver"); | 45 | MODULE_DESCRIPTION("Amiga keyboard driver"); |
| 46 | MODULE_LICENSE("GPL"); | 46 | MODULE_LICENSE("GPL"); |
| 47 | 47 | ||
| 48 | #ifdef CONFIG_HW_CONSOLE | ||
| 48 | static unsigned char amikbd_keycode[0x78] __initdata = { | 49 | static unsigned char amikbd_keycode[0x78] __initdata = { |
| 49 | [0] = KEY_GRAVE, | 50 | [0] = KEY_GRAVE, |
| 50 | [1] = KEY_1, | 51 | [1] = KEY_1, |
| @@ -144,6 +145,32 @@ static unsigned char amikbd_keycode[0x78] __initdata = { | |||
| 144 | [103] = KEY_RIGHTMETA | 145 | [103] = KEY_RIGHTMETA |
| 145 | }; | 146 | }; |
| 146 | 147 | ||
| 148 | static void __init amikbd_init_console_keymaps(void) | ||
| 149 | { | ||
| 150 | /* We can spare 512 bytes on stack for temp_map in init path. */ | ||
| 151 | unsigned short temp_map[NR_KEYS]; | ||
| 152 | int i, j; | ||
| 153 | |||
| 154 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | ||
| 155 | if (!key_maps[i]) | ||
| 156 | continue; | ||
| 157 | memset(temp_map, 0, sizeof(temp_map)); | ||
| 158 | for (j = 0; j < 0x78; j++) { | ||
| 159 | if (!amikbd_keycode[j]) | ||
| 160 | continue; | ||
| 161 | temp_map[j] = key_maps[i][amikbd_keycode[j]]; | ||
| 162 | } | ||
| 163 | for (j = 0; j < NR_KEYS; j++) { | ||
| 164 | if (!temp_map[j]) | ||
| 165 | temp_map[j] = 0xf200; | ||
| 166 | } | ||
| 167 | memcpy(key_maps[i], temp_map, sizeof(temp_map)); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | #else /* !CONFIG_HW_CONSOLE */ | ||
| 171 | static inline void amikbd_init_console_keymaps(void) {} | ||
| 172 | #endif /* !CONFIG_HW_CONSOLE */ | ||
| 173 | |||
| 147 | static const char *amikbd_messages[8] = { | 174 | static const char *amikbd_messages[8] = { |
| 148 | [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n", | 175 | [0] = KERN_ALERT "amikbd: Ctrl-Amiga-Amiga reset warning!!\n", |
| 149 | [1] = KERN_WARNING "amikbd: keyboard lost sync\n", | 176 | [1] = KERN_WARNING "amikbd: keyboard lost sync\n", |
| @@ -186,7 +213,7 @@ static irqreturn_t amikbd_interrupt(int irq, void *data) | |||
| 186 | static int __init amikbd_probe(struct platform_device *pdev) | 213 | static int __init amikbd_probe(struct platform_device *pdev) |
| 187 | { | 214 | { |
| 188 | struct input_dev *dev; | 215 | struct input_dev *dev; |
| 189 | int i, j, err; | 216 | int i, err; |
| 190 | 217 | ||
| 191 | dev = input_allocate_device(); | 218 | dev = input_allocate_device(); |
| 192 | if (!dev) { | 219 | if (!dev) { |
| @@ -207,22 +234,8 @@ static int __init amikbd_probe(struct platform_device *pdev) | |||
| 207 | for (i = 0; i < 0x78; i++) | 234 | for (i = 0; i < 0x78; i++) |
| 208 | set_bit(i, dev->keybit); | 235 | set_bit(i, dev->keybit); |
| 209 | 236 | ||
| 210 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | 237 | amikbd_init_console_keymaps(); |
| 211 | static u_short temp_map[NR_KEYS] __initdata; | 238 | |
| 212 | if (!key_maps[i]) | ||
| 213 | continue; | ||
| 214 | memset(temp_map, 0, sizeof(temp_map)); | ||
| 215 | for (j = 0; j < 0x78; j++) { | ||
| 216 | if (!amikbd_keycode[j]) | ||
| 217 | continue; | ||
| 218 | temp_map[j] = key_maps[i][amikbd_keycode[j]]; | ||
| 219 | } | ||
| 220 | for (j = 0; j < NR_KEYS; j++) { | ||
| 221 | if (!temp_map[j]) | ||
| 222 | temp_map[j] = 0xf200; | ||
| 223 | } | ||
| 224 | memcpy(key_maps[i], temp_map, sizeof(temp_map)); | ||
| 225 | } | ||
| 226 | ciaa.cra &= ~0x41; /* serial data in, turn off TA */ | 239 | ciaa.cra &= ~0x41; /* serial data in, turn off TA */ |
| 227 | err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", | 240 | err = request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", |
| 228 | dev); | 241 | dev); |
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index 6f5d79569136..e27a25892db4 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c | |||
| @@ -456,8 +456,9 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, | |||
| 456 | 456 | ||
| 457 | keycode = atkbd->keycode[code]; | 457 | keycode = atkbd->keycode[code]; |
| 458 | 458 | ||
| 459 | if (keycode != ATKBD_KEY_NULL) | 459 | if (!(atkbd->release && test_bit(code, atkbd->force_release_mask))) |
| 460 | input_event(dev, EV_MSC, MSC_SCAN, code); | 460 | if (keycode != ATKBD_KEY_NULL) |
| 461 | input_event(dev, EV_MSC, MSC_SCAN, code); | ||
| 461 | 462 | ||
| 462 | switch (keycode) { | 463 | switch (keycode) { |
| 463 | case ATKBD_KEY_NULL: | 464 | case ATKBD_KEY_NULL: |
| @@ -511,6 +512,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, | |||
| 511 | input_sync(dev); | 512 | input_sync(dev); |
| 512 | 513 | ||
| 513 | if (value && test_bit(code, atkbd->force_release_mask)) { | 514 | if (value && test_bit(code, atkbd->force_release_mask)) { |
| 515 | input_event(dev, EV_MSC, MSC_SCAN, code); | ||
| 514 | input_report_key(dev, keycode, 0); | 516 | input_report_key(dev, keycode, 0); |
| 515 | input_sync(dev); | 517 | input_sync(dev); |
| 516 | } | 518 | } |
diff --git a/drivers/input/keyboard/cap1106.c b/drivers/input/keyboard/cap1106.c deleted file mode 100644 index d70b65a14ced..000000000000 --- a/drivers/input/keyboard/cap1106.c +++ /dev/null | |||
| @@ -1,341 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Input driver for Microchip CAP1106, 6 channel capacitive touch sensor | ||
| 3 | * | ||
| 4 | * http://www.microchip.com/wwwproducts/Devices.aspx?product=CAP1106 | ||
| 5 | * | ||
| 6 | * (c) 2014 Daniel Mack <linux@zonque.org> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License version 2 as | ||
| 10 | * published by the Free Software Foundation. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/kernel.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/interrupt.h> | ||
| 16 | #include <linux/input.h> | ||
| 17 | #include <linux/of_irq.h> | ||
| 18 | #include <linux/regmap.h> | ||
| 19 | #include <linux/i2c.h> | ||
| 20 | #include <linux/gpio/consumer.h> | ||
| 21 | |||
| 22 | #define CAP1106_REG_MAIN_CONTROL 0x00 | ||
| 23 | #define CAP1106_REG_MAIN_CONTROL_GAIN_SHIFT (6) | ||
| 24 | #define CAP1106_REG_MAIN_CONTROL_GAIN_MASK (0xc0) | ||
| 25 | #define CAP1106_REG_MAIN_CONTROL_DLSEEP BIT(4) | ||
| 26 | #define CAP1106_REG_GENERAL_STATUS 0x02 | ||
| 27 | #define CAP1106_REG_SENSOR_INPUT 0x03 | ||
| 28 | #define CAP1106_REG_NOISE_FLAG_STATUS 0x0a | ||
| 29 | #define CAP1106_REG_SENOR_DELTA(X) (0x10 + (X)) | ||
| 30 | #define CAP1106_REG_SENSITIVITY_CONTROL 0x1f | ||
| 31 | #define CAP1106_REG_CONFIG 0x20 | ||
| 32 | #define CAP1106_REG_SENSOR_ENABLE 0x21 | ||
| 33 | #define CAP1106_REG_SENSOR_CONFIG 0x22 | ||
| 34 | #define CAP1106_REG_SENSOR_CONFIG2 0x23 | ||
| 35 | #define CAP1106_REG_SAMPLING_CONFIG 0x24 | ||
| 36 | #define CAP1106_REG_CALIBRATION 0x26 | ||
| 37 | #define CAP1106_REG_INT_ENABLE 0x27 | ||
| 38 | #define CAP1106_REG_REPEAT_RATE 0x28 | ||
| 39 | #define CAP1106_REG_MT_CONFIG 0x2a | ||
| 40 | #define CAP1106_REG_MT_PATTERN_CONFIG 0x2b | ||
| 41 | #define CAP1106_REG_MT_PATTERN 0x2d | ||
| 42 | #define CAP1106_REG_RECALIB_CONFIG 0x2f | ||
| 43 | #define CAP1106_REG_SENSOR_THRESH(X) (0x30 + (X)) | ||
| 44 | #define CAP1106_REG_SENSOR_NOISE_THRESH 0x38 | ||
| 45 | #define CAP1106_REG_STANDBY_CHANNEL 0x40 | ||
| 46 | #define CAP1106_REG_STANDBY_CONFIG 0x41 | ||
| 47 | #define CAP1106_REG_STANDBY_SENSITIVITY 0x42 | ||
| 48 | #define CAP1106_REG_STANDBY_THRESH 0x43 | ||
| 49 | #define CAP1106_REG_CONFIG2 0x44 | ||
| 50 | #define CAP1106_REG_SENSOR_BASE_CNT(X) (0x50 + (X)) | ||
| 51 | #define CAP1106_REG_SENSOR_CALIB (0xb1 + (X)) | ||
| 52 | #define CAP1106_REG_SENSOR_CALIB_LSB1 0xb9 | ||
| 53 | #define CAP1106_REG_SENSOR_CALIB_LSB2 0xba | ||
| 54 | #define CAP1106_REG_PRODUCT_ID 0xfd | ||
| 55 | #define CAP1106_REG_MANUFACTURER_ID 0xfe | ||
| 56 | #define CAP1106_REG_REVISION 0xff | ||
| 57 | |||
| 58 | #define CAP1106_NUM_CHN 6 | ||
| 59 | #define CAP1106_PRODUCT_ID 0x55 | ||
| 60 | #define CAP1106_MANUFACTURER_ID 0x5d | ||
| 61 | |||
| 62 | struct cap1106_priv { | ||
| 63 | struct regmap *regmap; | ||
| 64 | struct input_dev *idev; | ||
| 65 | |||
| 66 | /* config */ | ||
| 67 | unsigned short keycodes[CAP1106_NUM_CHN]; | ||
| 68 | }; | ||
| 69 | |||
| 70 | static const struct reg_default cap1106_reg_defaults[] = { | ||
| 71 | { CAP1106_REG_MAIN_CONTROL, 0x00 }, | ||
| 72 | { CAP1106_REG_GENERAL_STATUS, 0x00 }, | ||
| 73 | { CAP1106_REG_SENSOR_INPUT, 0x00 }, | ||
| 74 | { CAP1106_REG_NOISE_FLAG_STATUS, 0x00 }, | ||
| 75 | { CAP1106_REG_SENSITIVITY_CONTROL, 0x2f }, | ||
| 76 | { CAP1106_REG_CONFIG, 0x20 }, | ||
| 77 | { CAP1106_REG_SENSOR_ENABLE, 0x3f }, | ||
| 78 | { CAP1106_REG_SENSOR_CONFIG, 0xa4 }, | ||
| 79 | { CAP1106_REG_SENSOR_CONFIG2, 0x07 }, | ||
| 80 | { CAP1106_REG_SAMPLING_CONFIG, 0x39 }, | ||
| 81 | { CAP1106_REG_CALIBRATION, 0x00 }, | ||
| 82 | { CAP1106_REG_INT_ENABLE, 0x3f }, | ||
| 83 | { CAP1106_REG_REPEAT_RATE, 0x3f }, | ||
| 84 | { CAP1106_REG_MT_CONFIG, 0x80 }, | ||
| 85 | { CAP1106_REG_MT_PATTERN_CONFIG, 0x00 }, | ||
| 86 | { CAP1106_REG_MT_PATTERN, 0x3f }, | ||
| 87 | { CAP1106_REG_RECALIB_CONFIG, 0x8a }, | ||
| 88 | { CAP1106_REG_SENSOR_THRESH(0), 0x40 }, | ||
| 89 | { CAP1106_REG_SENSOR_THRESH(1), 0x40 }, | ||
| 90 | { CAP1106_REG_SENSOR_THRESH(2), 0x40 }, | ||
| 91 | { CAP1106_REG_SENSOR_THRESH(3), 0x40 }, | ||
| 92 | { CAP1106_REG_SENSOR_THRESH(4), 0x40 }, | ||
| 93 | { CAP1106_REG_SENSOR_THRESH(5), 0x40 }, | ||
| 94 | { CAP1106_REG_SENSOR_NOISE_THRESH, 0x01 }, | ||
| 95 | { CAP1106_REG_STANDBY_CHANNEL, 0x00 }, | ||
| 96 | { CAP1106_REG_STANDBY_CONFIG, 0x39 }, | ||
| 97 | { CAP1106_REG_STANDBY_SENSITIVITY, 0x02 }, | ||
| 98 | { CAP1106_REG_STANDBY_THRESH, 0x40 }, | ||
| 99 | { CAP1106_REG_CONFIG2, 0x40 }, | ||
| 100 | { CAP1106_REG_SENSOR_CALIB_LSB1, 0x00 }, | ||
| 101 | { CAP1106_REG_SENSOR_CALIB_LSB2, 0x00 }, | ||
| 102 | }; | ||
| 103 | |||
| 104 | static bool cap1106_volatile_reg(struct device *dev, unsigned int reg) | ||
| 105 | { | ||
| 106 | switch (reg) { | ||
| 107 | case CAP1106_REG_MAIN_CONTROL: | ||
| 108 | case CAP1106_REG_SENSOR_INPUT: | ||
| 109 | case CAP1106_REG_SENOR_DELTA(0): | ||
| 110 | case CAP1106_REG_SENOR_DELTA(1): | ||
| 111 | case CAP1106_REG_SENOR_DELTA(2): | ||
| 112 | case CAP1106_REG_SENOR_DELTA(3): | ||
| 113 | case CAP1106_REG_SENOR_DELTA(4): | ||
| 114 | case CAP1106_REG_SENOR_DELTA(5): | ||
| 115 | case CAP1106_REG_PRODUCT_ID: | ||
| 116 | case CAP1106_REG_MANUFACTURER_ID: | ||
| 117 | case CAP1106_REG_REVISION: | ||
| 118 | return true; | ||
| 119 | } | ||
| 120 | |||
| 121 | return false; | ||
| 122 | } | ||
| 123 | |||
| 124 | static const struct regmap_config cap1106_regmap_config = { | ||
| 125 | .reg_bits = 8, | ||
| 126 | .val_bits = 8, | ||
| 127 | |||
| 128 | .max_register = CAP1106_REG_REVISION, | ||
| 129 | .reg_defaults = cap1106_reg_defaults, | ||
| 130 | |||
| 131 | .num_reg_defaults = ARRAY_SIZE(cap1106_reg_defaults), | ||
| 132 | .cache_type = REGCACHE_RBTREE, | ||
| 133 | .volatile_reg = cap1106_volatile_reg, | ||
| 134 | }; | ||
| 135 | |||
| 136 | static irqreturn_t cap1106_thread_func(int irq_num, void *data) | ||
| 137 | { | ||
| 138 | struct cap1106_priv *priv = data; | ||
| 139 | unsigned int status; | ||
| 140 | int ret, i; | ||
| 141 | |||
| 142 | /* | ||
| 143 | * Deassert interrupt. This needs to be done before reading the status | ||
| 144 | * registers, which will not carry valid values otherwise. | ||
| 145 | */ | ||
| 146 | ret = regmap_update_bits(priv->regmap, CAP1106_REG_MAIN_CONTROL, 1, 0); | ||
| 147 | if (ret < 0) | ||
| 148 | goto out; | ||
| 149 | |||
| 150 | ret = regmap_read(priv->regmap, CAP1106_REG_SENSOR_INPUT, &status); | ||
| 151 | if (ret < 0) | ||
| 152 | goto out; | ||
| 153 | |||
| 154 | for (i = 0; i < CAP1106_NUM_CHN; i++) | ||
| 155 | input_report_key(priv->idev, priv->keycodes[i], | ||
| 156 | status & (1 << i)); | ||
| 157 | |||
| 158 | input_sync(priv->idev); | ||
| 159 | |||
| 160 | out: | ||
| 161 | return IRQ_HANDLED; | ||
| 162 | } | ||
| 163 | |||
| 164 | static int cap1106_set_sleep(struct cap1106_priv *priv, bool sleep) | ||
| 165 | { | ||
| 166 | return regmap_update_bits(priv->regmap, CAP1106_REG_MAIN_CONTROL, | ||
| 167 | CAP1106_REG_MAIN_CONTROL_DLSEEP, | ||
| 168 | sleep ? CAP1106_REG_MAIN_CONTROL_DLSEEP : 0); | ||
| 169 | } | ||
| 170 | |||
| 171 | static int cap1106_input_open(struct input_dev *idev) | ||
| 172 | { | ||
| 173 | struct cap1106_priv *priv = input_get_drvdata(idev); | ||
| 174 | |||
| 175 | return cap1106_set_sleep(priv, false); | ||
| 176 | } | ||
| 177 | |||
| 178 | static void cap1106_input_close(struct input_dev *idev) | ||
| 179 | { | ||
| 180 | struct cap1106_priv *priv = input_get_drvdata(idev); | ||
| 181 | |||
| 182 | cap1106_set_sleep(priv, true); | ||
| 183 | } | ||
| 184 | |||
| 185 | static int cap1106_i2c_probe(struct i2c_client *i2c_client, | ||
| 186 | const struct i2c_device_id *id) | ||
| 187 | { | ||
| 188 | struct device *dev = &i2c_client->dev; | ||
| 189 | struct cap1106_priv *priv; | ||
| 190 | struct device_node *node; | ||
| 191 | int i, error, irq, gain = 0; | ||
| 192 | unsigned int val, rev; | ||
| 193 | u32 gain32, keycodes[CAP1106_NUM_CHN]; | ||
| 194 | |||
| 195 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | ||
| 196 | if (!priv) | ||
| 197 | return -ENOMEM; | ||
| 198 | |||
| 199 | priv->regmap = devm_regmap_init_i2c(i2c_client, &cap1106_regmap_config); | ||
| 200 | if (IS_ERR(priv->regmap)) | ||
| 201 | return PTR_ERR(priv->regmap); | ||
| 202 | |||
| 203 | error = regmap_read(priv->regmap, CAP1106_REG_PRODUCT_ID, &val); | ||
| 204 | if (error) | ||
| 205 | return error; | ||
| 206 | |||
| 207 | if (val != CAP1106_PRODUCT_ID) { | ||
| 208 | dev_err(dev, "Product ID: Got 0x%02x, expected 0x%02x\n", | ||
| 209 | val, CAP1106_PRODUCT_ID); | ||
| 210 | return -ENODEV; | ||
| 211 | } | ||
| 212 | |||
| 213 | error = regmap_read(priv->regmap, CAP1106_REG_MANUFACTURER_ID, &val); | ||
| 214 | if (error) | ||
| 215 | return error; | ||
| 216 | |||
| 217 | if (val != CAP1106_MANUFACTURER_ID) { | ||
| 218 | dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n", | ||
| 219 | val, CAP1106_MANUFACTURER_ID); | ||
| 220 | return -ENODEV; | ||
| 221 | } | ||
| 222 | |||
| 223 | error = regmap_read(priv->regmap, CAP1106_REG_REVISION, &rev); | ||
| 224 | if (error < 0) | ||
| 225 | return error; | ||
| 226 | |||
| 227 | dev_info(dev, "CAP1106 detected, revision 0x%02x\n", rev); | ||
| 228 | i2c_set_clientdata(i2c_client, priv); | ||
| 229 | node = dev->of_node; | ||
| 230 | |||
| 231 | if (!of_property_read_u32(node, "microchip,sensor-gain", &gain32)) { | ||
| 232 | if (is_power_of_2(gain32) && gain32 <= 8) | ||
| 233 | gain = ilog2(gain32); | ||
| 234 | else | ||
| 235 | dev_err(dev, "Invalid sensor-gain value %d\n", gain32); | ||
| 236 | } | ||
| 237 | |||
| 238 | BUILD_BUG_ON(ARRAY_SIZE(keycodes) != ARRAY_SIZE(priv->keycodes)); | ||
| 239 | |||
| 240 | /* Provide some useful defaults */ | ||
| 241 | for (i = 0; i < ARRAY_SIZE(keycodes); i++) | ||
| 242 | keycodes[i] = KEY_A + i; | ||
| 243 | |||
| 244 | of_property_read_u32_array(node, "linux,keycodes", | ||
| 245 | keycodes, ARRAY_SIZE(keycodes)); | ||
| 246 | |||
| 247 | for (i = 0; i < ARRAY_SIZE(keycodes); i++) | ||
| 248 | priv->keycodes[i] = keycodes[i]; | ||
| 249 | |||
| 250 | error = regmap_update_bits(priv->regmap, CAP1106_REG_MAIN_CONTROL, | ||
| 251 | CAP1106_REG_MAIN_CONTROL_GAIN_MASK, | ||
| 252 | gain << CAP1106_REG_MAIN_CONTROL_GAIN_SHIFT); | ||
| 253 | if (error) | ||
| 254 | return error; | ||
| 255 | |||
| 256 | /* Disable autorepeat. The Linux input system has its own handling. */ | ||
| 257 | error = regmap_write(priv->regmap, CAP1106_REG_REPEAT_RATE, 0); | ||
| 258 | if (error) | ||
| 259 | return error; | ||
| 260 | |||
| 261 | priv->idev = devm_input_allocate_device(dev); | ||
| 262 | if (!priv->idev) | ||
| 263 | return -ENOMEM; | ||
| 264 | |||
| 265 | priv->idev->name = "CAP1106 capacitive touch sensor"; | ||
| 266 | priv->idev->id.bustype = BUS_I2C; | ||
| 267 | priv->idev->evbit[0] = BIT_MASK(EV_KEY); | ||
| 268 | |||
| 269 | if (of_property_read_bool(node, "autorepeat")) | ||
| 270 | __set_bit(EV_REP, priv->idev->evbit); | ||
| 271 | |||
| 272 | for (i = 0; i < CAP1106_NUM_CHN; i++) | ||
| 273 | __set_bit(priv->keycodes[i], priv->idev->keybit); | ||
| 274 | |||
| 275 | __clear_bit(KEY_RESERVED, priv->idev->keybit); | ||
| 276 | |||
| 277 | priv->idev->keycode = priv->keycodes; | ||
| 278 | priv->idev->keycodesize = sizeof(priv->keycodes[0]); | ||
| 279 | priv->idev->keycodemax = ARRAY_SIZE(priv->keycodes); | ||
| 280 | |||
| 281 | priv->idev->id.vendor = CAP1106_MANUFACTURER_ID; | ||
| 282 | priv->idev->id.product = CAP1106_PRODUCT_ID; | ||
| 283 | priv->idev->id.version = rev; | ||
| 284 | |||
| 285 | priv->idev->open = cap1106_input_open; | ||
| 286 | priv->idev->close = cap1106_input_close; | ||
| 287 | |||
| 288 | input_set_drvdata(priv->idev, priv); | ||
| 289 | |||
| 290 | /* | ||
| 291 | * Put the device in deep sleep mode for now. | ||
| 292 | * ->open() will bring it back once the it is actually needed. | ||
| 293 | */ | ||
| 294 | cap1106_set_sleep(priv, true); | ||
| 295 | |||
| 296 | error = input_register_device(priv->idev); | ||
| 297 | if (error) | ||
| 298 | return error; | ||
| 299 | |||
| 300 | irq = irq_of_parse_and_map(node, 0); | ||
| 301 | if (!irq) { | ||
| 302 | dev_err(dev, "Unable to parse or map IRQ\n"); | ||
| 303 | return -ENXIO; | ||
| 304 | } | ||
| 305 | |||
| 306 | error = devm_request_threaded_irq(dev, irq, NULL, cap1106_thread_func, | ||
| 307 | IRQF_ONESHOT, dev_name(dev), priv); | ||
| 308 | if (error) | ||
| 309 | return error; | ||
| 310 | |||
| 311 | return 0; | ||
| 312 | } | ||
| 313 | |||
| 314 | static const struct of_device_id cap1106_dt_ids[] = { | ||
| 315 | { .compatible = "microchip,cap1106", }, | ||
| 316 | {} | ||
| 317 | }; | ||
| 318 | MODULE_DEVICE_TABLE(of, cap1106_dt_ids); | ||
| 319 | |||
| 320 | static const struct i2c_device_id cap1106_i2c_ids[] = { | ||
| 321 | { "cap1106", 0 }, | ||
| 322 | {} | ||
| 323 | }; | ||
| 324 | MODULE_DEVICE_TABLE(i2c, cap1106_i2c_ids); | ||
| 325 | |||
| 326 | static struct i2c_driver cap1106_i2c_driver = { | ||
| 327 | .driver = { | ||
| 328 | .name = "cap1106", | ||
| 329 | .owner = THIS_MODULE, | ||
| 330 | .of_match_table = cap1106_dt_ids, | ||
| 331 | }, | ||
| 332 | .id_table = cap1106_i2c_ids, | ||
| 333 | .probe = cap1106_i2c_probe, | ||
| 334 | }; | ||
| 335 | |||
| 336 | module_i2c_driver(cap1106_i2c_driver); | ||
| 337 | |||
| 338 | MODULE_ALIAS("platform:cap1106"); | ||
| 339 | MODULE_DESCRIPTION("Microchip CAP1106 driver"); | ||
| 340 | MODULE_AUTHOR("Daniel Mack <linux@zonque.org>"); | ||
| 341 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c new file mode 100644 index 000000000000..4f59f0bab28f --- /dev/null +++ b/drivers/input/keyboard/cap11xx.c | |||
| @@ -0,0 +1,376 @@ | |||
| 1 | /* | ||
| 2 | * Input driver for Microchip CAP11xx based capacitive touch sensors | ||
| 3 | * | ||
| 4 | * (c) 2014 Daniel Mack <linux@zonque.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/kernel.h> | ||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/interrupt.h> | ||
| 14 | #include <linux/input.h> | ||
| 15 | #include <linux/of_irq.h> | ||
| 16 | #include <linux/regmap.h> | ||
| 17 | #include <linux/i2c.h> | ||
| 18 | #include <linux/gpio/consumer.h> | ||
| 19 | |||
| 20 | #define CAP11XX_REG_MAIN_CONTROL 0x00 | ||
| 21 | #define CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT (6) | ||
| 22 | #define CAP11XX_REG_MAIN_CONTROL_GAIN_MASK (0xc0) | ||
| 23 | #define CAP11XX_REG_MAIN_CONTROL_DLSEEP BIT(4) | ||
| 24 | #define CAP11XX_REG_GENERAL_STATUS 0x02 | ||
| 25 | #define CAP11XX_REG_SENSOR_INPUT 0x03 | ||
| 26 | #define CAP11XX_REG_NOISE_FLAG_STATUS 0x0a | ||
| 27 | #define CAP11XX_REG_SENOR_DELTA(X) (0x10 + (X)) | ||
| 28 | #define CAP11XX_REG_SENSITIVITY_CONTROL 0x1f | ||
| 29 | #define CAP11XX_REG_CONFIG 0x20 | ||
| 30 | #define CAP11XX_REG_SENSOR_ENABLE 0x21 | ||
| 31 | #define CAP11XX_REG_SENSOR_CONFIG 0x22 | ||
| 32 | #define CAP11XX_REG_SENSOR_CONFIG2 0x23 | ||
| 33 | #define CAP11XX_REG_SAMPLING_CONFIG 0x24 | ||
| 34 | #define CAP11XX_REG_CALIBRATION 0x26 | ||
| 35 | #define CAP11XX_REG_INT_ENABLE 0x27 | ||
| 36 | #define CAP11XX_REG_REPEAT_RATE 0x28 | ||
| 37 | #define CAP11XX_REG_MT_CONFIG 0x2a | ||
| 38 | #define CAP11XX_REG_MT_PATTERN_CONFIG 0x2b | ||
| 39 | #define CAP11XX_REG_MT_PATTERN 0x2d | ||
| 40 | #define CAP11XX_REG_RECALIB_CONFIG 0x2f | ||
| 41 | #define CAP11XX_REG_SENSOR_THRESH(X) (0x30 + (X)) | ||
| 42 | #define CAP11XX_REG_SENSOR_NOISE_THRESH 0x38 | ||
| 43 | #define CAP11XX_REG_STANDBY_CHANNEL 0x40 | ||
| 44 | #define CAP11XX_REG_STANDBY_CONFIG 0x41 | ||
| 45 | #define CAP11XX_REG_STANDBY_SENSITIVITY 0x42 | ||
| 46 | #define CAP11XX_REG_STANDBY_THRESH 0x43 | ||
| 47 | #define CAP11XX_REG_CONFIG2 0x44 | ||
| 48 | #define CAP11XX_REG_CONFIG2_ALT_POL BIT(6) | ||
| 49 | #define CAP11XX_REG_SENSOR_BASE_CNT(X) (0x50 + (X)) | ||
| 50 | #define CAP11XX_REG_SENSOR_CALIB (0xb1 + (X)) | ||
| 51 | #define CAP11XX_REG_SENSOR_CALIB_LSB1 0xb9 | ||
| 52 | #define CAP11XX_REG_SENSOR_CALIB_LSB2 0xba | ||
| 53 | #define CAP11XX_REG_PRODUCT_ID 0xfd | ||
| 54 | #define CAP11XX_REG_MANUFACTURER_ID 0xfe | ||
| 55 | #define CAP11XX_REG_REVISION 0xff | ||
| 56 | |||
| 57 | #define CAP11XX_MANUFACTURER_ID 0x5d | ||
| 58 | |||
| 59 | struct cap11xx_priv { | ||
| 60 | struct regmap *regmap; | ||
| 61 | struct input_dev *idev; | ||
| 62 | |||
| 63 | /* config */ | ||
| 64 | u32 keycodes[]; | ||
| 65 | }; | ||
| 66 | |||
| 67 | struct cap11xx_hw_model { | ||
| 68 | u8 product_id; | ||
| 69 | unsigned int num_channels; | ||
| 70 | }; | ||
| 71 | |||
| 72 | enum { | ||
| 73 | CAP1106, | ||
| 74 | CAP1126, | ||
| 75 | CAP1188, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static const struct cap11xx_hw_model cap11xx_devices[] = { | ||
| 79 | [CAP1106] = { .product_id = 0x55, .num_channels = 6 }, | ||
| 80 | [CAP1126] = { .product_id = 0x53, .num_channels = 6 }, | ||
| 81 | [CAP1188] = { .product_id = 0x50, .num_channels = 8 }, | ||
| 82 | }; | ||
| 83 | |||
| 84 | static const struct reg_default cap11xx_reg_defaults[] = { | ||
| 85 | { CAP11XX_REG_MAIN_CONTROL, 0x00 }, | ||
| 86 | { CAP11XX_REG_GENERAL_STATUS, 0x00 }, | ||
| 87 | { CAP11XX_REG_SENSOR_INPUT, 0x00 }, | ||
| 88 | { CAP11XX_REG_NOISE_FLAG_STATUS, 0x00 }, | ||
| 89 | { CAP11XX_REG_SENSITIVITY_CONTROL, 0x2f }, | ||
| 90 | { CAP11XX_REG_CONFIG, 0x20 }, | ||
| 91 | { CAP11XX_REG_SENSOR_ENABLE, 0x3f }, | ||
| 92 | { CAP11XX_REG_SENSOR_CONFIG, 0xa4 }, | ||
| 93 | { CAP11XX_REG_SENSOR_CONFIG2, 0x07 }, | ||
| 94 | { CAP11XX_REG_SAMPLING_CONFIG, 0x39 }, | ||
| 95 | { CAP11XX_REG_CALIBRATION, 0x00 }, | ||
| 96 | { CAP11XX_REG_INT_ENABLE, 0x3f }, | ||
| 97 | { CAP11XX_REG_REPEAT_RATE, 0x3f }, | ||
| 98 | { CAP11XX_REG_MT_CONFIG, 0x80 }, | ||
| 99 | { CAP11XX_REG_MT_PATTERN_CONFIG, 0x00 }, | ||
| 100 | { CAP11XX_REG_MT_PATTERN, 0x3f }, | ||
| 101 | { CAP11XX_REG_RECALIB_CONFIG, 0x8a }, | ||
| 102 | { CAP11XX_REG_SENSOR_THRESH(0), 0x40 }, | ||
| 103 | { CAP11XX_REG_SENSOR_THRESH(1), 0x40 }, | ||
| 104 | { CAP11XX_REG_SENSOR_THRESH(2), 0x40 }, | ||
| 105 | { CAP11XX_REG_SENSOR_THRESH(3), 0x40 }, | ||
| 106 | { CAP11XX_REG_SENSOR_THRESH(4), 0x40 }, | ||
| 107 | { CAP11XX_REG_SENSOR_THRESH(5), 0x40 }, | ||
| 108 | { CAP11XX_REG_SENSOR_NOISE_THRESH, 0x01 }, | ||
| 109 | { CAP11XX_REG_STANDBY_CHANNEL, 0x00 }, | ||
| 110 | { CAP11XX_REG_STANDBY_CONFIG, 0x39 }, | ||
| 111 | { CAP11XX_REG_STANDBY_SENSITIVITY, 0x02 }, | ||
| 112 | { CAP11XX_REG_STANDBY_THRESH, 0x40 }, | ||
| 113 | { CAP11XX_REG_CONFIG2, 0x40 }, | ||
| 114 | { CAP11XX_REG_SENSOR_CALIB_LSB1, 0x00 }, | ||
| 115 | { CAP11XX_REG_SENSOR_CALIB_LSB2, 0x00 }, | ||
| 116 | }; | ||
| 117 | |||
| 118 | static bool cap11xx_volatile_reg(struct device *dev, unsigned int reg) | ||
| 119 | { | ||
| 120 | switch (reg) { | ||
| 121 | case CAP11XX_REG_MAIN_CONTROL: | ||
| 122 | case CAP11XX_REG_SENSOR_INPUT: | ||
| 123 | case CAP11XX_REG_SENOR_DELTA(0): | ||
| 124 | case CAP11XX_REG_SENOR_DELTA(1): | ||
| 125 | case CAP11XX_REG_SENOR_DELTA(2): | ||
| 126 | case CAP11XX_REG_SENOR_DELTA(3): | ||
| 127 | case CAP11XX_REG_SENOR_DELTA(4): | ||
| 128 | case CAP11XX_REG_SENOR_DELTA(5): | ||
| 129 | case CAP11XX_REG_PRODUCT_ID: | ||
| 130 | case CAP11XX_REG_MANUFACTURER_ID: | ||
| 131 | case CAP11XX_REG_REVISION: | ||
| 132 | return true; | ||
| 133 | } | ||
| 134 | |||
| 135 | return false; | ||
| 136 | } | ||
| 137 | |||
| 138 | static const struct regmap_config cap11xx_regmap_config = { | ||
| 139 | .reg_bits = 8, | ||
| 140 | .val_bits = 8, | ||
| 141 | |||
| 142 | .max_register = CAP11XX_REG_REVISION, | ||
| 143 | .reg_defaults = cap11xx_reg_defaults, | ||
| 144 | |||
| 145 | .num_reg_defaults = ARRAY_SIZE(cap11xx_reg_defaults), | ||
| 146 | .cache_type = REGCACHE_RBTREE, | ||
| 147 | .volatile_reg = cap11xx_volatile_reg, | ||
| 148 | }; | ||
| 149 | |||
| 150 | static irqreturn_t cap11xx_thread_func(int irq_num, void *data) | ||
| 151 | { | ||
| 152 | struct cap11xx_priv *priv = data; | ||
| 153 | unsigned int status; | ||
| 154 | int ret, i; | ||
| 155 | |||
| 156 | /* | ||
| 157 | * Deassert interrupt. This needs to be done before reading the status | ||
| 158 | * registers, which will not carry valid values otherwise. | ||
| 159 | */ | ||
| 160 | ret = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, 1, 0); | ||
| 161 | if (ret < 0) | ||
| 162 | goto out; | ||
| 163 | |||
| 164 | ret = regmap_read(priv->regmap, CAP11XX_REG_SENSOR_INPUT, &status); | ||
| 165 | if (ret < 0) | ||
| 166 | goto out; | ||
| 167 | |||
| 168 | for (i = 0; i < priv->idev->keycodemax; i++) | ||
| 169 | input_report_key(priv->idev, priv->keycodes[i], | ||
| 170 | status & (1 << i)); | ||
| 171 | |||
| 172 | input_sync(priv->idev); | ||
| 173 | |||
| 174 | out: | ||
| 175 | return IRQ_HANDLED; | ||
| 176 | } | ||
| 177 | |||
| 178 | static int cap11xx_set_sleep(struct cap11xx_priv *priv, bool sleep) | ||
| 179 | { | ||
| 180 | return regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, | ||
| 181 | CAP11XX_REG_MAIN_CONTROL_DLSEEP, | ||
| 182 | sleep ? CAP11XX_REG_MAIN_CONTROL_DLSEEP : 0); | ||
| 183 | } | ||
| 184 | |||
| 185 | static int cap11xx_input_open(struct input_dev *idev) | ||
| 186 | { | ||
| 187 | struct cap11xx_priv *priv = input_get_drvdata(idev); | ||
| 188 | |||
| 189 | return cap11xx_set_sleep(priv, false); | ||
| 190 | } | ||
| 191 | |||
| 192 | static void cap11xx_input_close(struct input_dev *idev) | ||
| 193 | { | ||
| 194 | struct cap11xx_priv *priv = input_get_drvdata(idev); | ||
| 195 | |||
| 196 | cap11xx_set_sleep(priv, true); | ||
| 197 | } | ||
| 198 | |||
| 199 | static int cap11xx_i2c_probe(struct i2c_client *i2c_client, | ||
| 200 | const struct i2c_device_id *id) | ||
| 201 | { | ||
| 202 | struct device *dev = &i2c_client->dev; | ||
| 203 | struct cap11xx_priv *priv; | ||
| 204 | struct device_node *node; | ||
| 205 | const struct cap11xx_hw_model *cap; | ||
| 206 | int i, error, irq, gain = 0; | ||
| 207 | unsigned int val, rev; | ||
| 208 | u32 gain32; | ||
| 209 | |||
| 210 | if (id->driver_data >= ARRAY_SIZE(cap11xx_devices)) { | ||
| 211 | dev_err(dev, "Invalid device ID %lu\n", id->driver_data); | ||
| 212 | return -EINVAL; | ||
| 213 | } | ||
| 214 | |||
| 215 | cap = &cap11xx_devices[id->driver_data]; | ||
| 216 | if (!cap || !cap->num_channels) { | ||
| 217 | dev_err(dev, "Invalid device configuration\n"); | ||
| 218 | return -EINVAL; | ||
| 219 | } | ||
| 220 | |||
| 221 | priv = devm_kzalloc(dev, | ||
| 222 | sizeof(*priv) + | ||
| 223 | cap->num_channels * sizeof(priv->keycodes[0]), | ||
| 224 | GFP_KERNEL); | ||
| 225 | if (!priv) | ||
| 226 | return -ENOMEM; | ||
| 227 | |||
| 228 | priv->regmap = devm_regmap_init_i2c(i2c_client, &cap11xx_regmap_config); | ||
| 229 | if (IS_ERR(priv->regmap)) | ||
| 230 | return PTR_ERR(priv->regmap); | ||
| 231 | |||
| 232 | error = regmap_read(priv->regmap, CAP11XX_REG_PRODUCT_ID, &val); | ||
| 233 | if (error) | ||
| 234 | return error; | ||
| 235 | |||
| 236 | if (val != cap->product_id) { | ||
| 237 | dev_err(dev, "Product ID: Got 0x%02x, expected 0x%02x\n", | ||
| 238 | val, cap->product_id); | ||
| 239 | return -ENXIO; | ||
| 240 | } | ||
| 241 | |||
| 242 | error = regmap_read(priv->regmap, CAP11XX_REG_MANUFACTURER_ID, &val); | ||
| 243 | if (error) | ||
| 244 | return error; | ||
| 245 | |||
| 246 | if (val != CAP11XX_MANUFACTURER_ID) { | ||
| 247 | dev_err(dev, "Manufacturer ID: Got 0x%02x, expected 0x%02x\n", | ||
| 248 | val, CAP11XX_MANUFACTURER_ID); | ||
| 249 | return -ENXIO; | ||
| 250 | } | ||
| 251 | |||
| 252 | error = regmap_read(priv->regmap, CAP11XX_REG_REVISION, &rev); | ||
| 253 | if (error < 0) | ||
| 254 | return error; | ||
| 255 | |||
| 256 | dev_info(dev, "CAP11XX detected, revision 0x%02x\n", rev); | ||
| 257 | i2c_set_clientdata(i2c_client, priv); | ||
| 258 | node = dev->of_node; | ||
| 259 | |||
| 260 | if (!of_property_read_u32(node, "microchip,sensor-gain", &gain32)) { | ||
| 261 | if (is_power_of_2(gain32) && gain32 <= 8) | ||
| 262 | gain = ilog2(gain32); | ||
| 263 | else | ||
| 264 | dev_err(dev, "Invalid sensor-gain value %d\n", gain32); | ||
| 265 | } | ||
| 266 | |||
| 267 | if (of_property_read_bool(node, "microchip,irq-active-high")) { | ||
| 268 | error = regmap_update_bits(priv->regmap, CAP11XX_REG_CONFIG2, | ||
| 269 | CAP11XX_REG_CONFIG2_ALT_POL, 0); | ||
| 270 | if (error) | ||
| 271 | return error; | ||
| 272 | } | ||
| 273 | |||
| 274 | /* Provide some useful defaults */ | ||
| 275 | for (i = 0; i < cap->num_channels; i++) | ||
| 276 | priv->keycodes[i] = KEY_A + i; | ||
| 277 | |||
| 278 | of_property_read_u32_array(node, "linux,keycodes", | ||
| 279 | priv->keycodes, cap->num_channels); | ||
| 280 | |||
| 281 | error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, | ||
| 282 | CAP11XX_REG_MAIN_CONTROL_GAIN_MASK, | ||
| 283 | gain << CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT); | ||
| 284 | if (error) | ||
| 285 | return error; | ||
| 286 | |||
| 287 | /* Disable autorepeat. The Linux input system has its own handling. */ | ||
| 288 | error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0); | ||
| 289 | if (error) | ||
| 290 | return error; | ||
| 291 | |||
| 292 | priv->idev = devm_input_allocate_device(dev); | ||
| 293 | if (!priv->idev) | ||
| 294 | return -ENOMEM; | ||
| 295 | |||
| 296 | priv->idev->name = "CAP11XX capacitive touch sensor"; | ||
| 297 | priv->idev->id.bustype = BUS_I2C; | ||
| 298 | priv->idev->evbit[0] = BIT_MASK(EV_KEY); | ||
| 299 | |||
| 300 | if (of_property_read_bool(node, "autorepeat")) | ||
| 301 | __set_bit(EV_REP, priv->idev->evbit); | ||
| 302 | |||
| 303 | for (i = 0; i < cap->num_channels; i++) | ||
| 304 | __set_bit(priv->keycodes[i], priv->idev->keybit); | ||
| 305 | |||
| 306 | __clear_bit(KEY_RESERVED, priv->idev->keybit); | ||
| 307 | |||
| 308 | priv->idev->keycode = priv->keycodes; | ||
| 309 | priv->idev->keycodesize = sizeof(priv->keycodes[0]); | ||
| 310 | priv->idev->keycodemax = cap->num_channels; | ||
| 311 | |||
| 312 | priv->idev->id.vendor = CAP11XX_MANUFACTURER_ID; | ||
| 313 | priv->idev->id.product = cap->product_id; | ||
| 314 | priv->idev->id.version = rev; | ||
| 315 | |||
| 316 | priv->idev->open = cap11xx_input_open; | ||
| 317 | priv->idev->close = cap11xx_input_close; | ||
| 318 | |||
| 319 | input_set_drvdata(priv->idev, priv); | ||
| 320 | |||
| 321 | /* | ||
| 322 | * Put the device in deep sleep mode for now. | ||
| 323 | * ->open() will bring it back once the it is actually needed. | ||
| 324 | */ | ||
| 325 | cap11xx_set_sleep(priv, true); | ||
| 326 | |||
| 327 | error = input_register_device(priv->idev); | ||
| 328 | if (error) | ||
| 329 | return error; | ||
| 330 | |||
| 331 | irq = irq_of_parse_and_map(node, 0); | ||
| 332 | if (!irq) { | ||
| 333 | dev_err(dev, "Unable to parse or map IRQ\n"); | ||
| 334 | return -ENXIO; | ||
| 335 | } | ||
| 336 | |||
| 337 | error = devm_request_threaded_irq(dev, irq, NULL, cap11xx_thread_func, | ||
| 338 | IRQF_ONESHOT, dev_name(dev), priv); | ||
| 339 | if (error) | ||
| 340 | return error; | ||
| 341 | |||
| 342 | return 0; | ||
| 343 | } | ||
| 344 | |||
| 345 | static const struct of_device_id cap11xx_dt_ids[] = { | ||
| 346 | { .compatible = "microchip,cap1106", }, | ||
| 347 | { .compatible = "microchip,cap1126", }, | ||
| 348 | { .compatible = "microchip,cap1188", }, | ||
| 349 | {} | ||
| 350 | }; | ||
| 351 | MODULE_DEVICE_TABLE(of, cap11xx_dt_ids); | ||
| 352 | |||
| 353 | static const struct i2c_device_id cap11xx_i2c_ids[] = { | ||
| 354 | { "cap1106", CAP1106 }, | ||
| 355 | { "cap1126", CAP1126 }, | ||
| 356 | { "cap1188", CAP1188 }, | ||
| 357 | {} | ||
| 358 | }; | ||
| 359 | MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids); | ||
| 360 | |||
| 361 | static struct i2c_driver cap11xx_i2c_driver = { | ||
| 362 | .driver = { | ||
| 363 | .name = "cap11xx", | ||
| 364 | .owner = THIS_MODULE, | ||
| 365 | .of_match_table = cap11xx_dt_ids, | ||
| 366 | }, | ||
| 367 | .id_table = cap11xx_i2c_ids, | ||
| 368 | .probe = cap11xx_i2c_probe, | ||
| 369 | }; | ||
| 370 | |||
| 371 | module_i2c_driver(cap11xx_i2c_driver); | ||
| 372 | |||
| 373 | MODULE_ALIAS("platform:cap11xx"); | ||
| 374 | MODULE_DESCRIPTION("Microchip CAP11XX driver"); | ||
| 375 | MODULE_AUTHOR("Daniel Mack <linux@zonque.org>"); | ||
| 376 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 8f3a24e15402..d4dd78a7d56b 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #include <linux/of.h> | 29 | #include <linux/of.h> |
| 30 | #include <linux/of_platform.h> | 30 | #include <linux/of_platform.h> |
| 31 | #include <linux/of_gpio.h> | 31 | #include <linux/of_gpio.h> |
| 32 | #include <linux/of_irq.h> | ||
| 32 | #include <linux/spinlock.h> | 33 | #include <linux/spinlock.h> |
| 33 | 34 | ||
| 34 | struct gpio_button_data { | 35 | struct gpio_button_data { |
| @@ -617,27 +618,31 @@ gpio_keys_get_devtree_pdata(struct device *dev) | |||
| 617 | 618 | ||
| 618 | i = 0; | 619 | i = 0; |
| 619 | for_each_child_of_node(node, pp) { | 620 | for_each_child_of_node(node, pp) { |
| 620 | int gpio; | 621 | int gpio = -1; |
| 621 | enum of_gpio_flags flags; | 622 | enum of_gpio_flags flags; |
| 622 | 623 | ||
| 623 | if (!of_find_property(pp, "gpios", NULL)) { | 624 | button = &pdata->buttons[i++]; |
| 624 | pdata->nbuttons--; | ||
| 625 | dev_warn(dev, "Found button without gpios\n"); | ||
| 626 | continue; | ||
| 627 | } | ||
| 628 | 625 | ||
| 629 | gpio = of_get_gpio_flags(pp, 0, &flags); | 626 | if (!of_find_property(pp, "gpios", NULL)) { |
| 630 | if (gpio < 0) { | 627 | button->irq = irq_of_parse_and_map(pp, 0); |
| 631 | error = gpio; | 628 | if (button->irq == 0) { |
| 632 | if (error != -EPROBE_DEFER) | 629 | i--; |
| 633 | dev_err(dev, | 630 | pdata->nbuttons--; |
| 634 | "Failed to get gpio flags, error: %d\n", | 631 | dev_warn(dev, "Found button without gpios or irqs\n"); |
| 635 | error); | 632 | continue; |
| 636 | return ERR_PTR(error); | 633 | } |
| 634 | } else { | ||
| 635 | gpio = of_get_gpio_flags(pp, 0, &flags); | ||
| 636 | if (gpio < 0) { | ||
| 637 | error = gpio; | ||
| 638 | if (error != -EPROBE_DEFER) | ||
| 639 | dev_err(dev, | ||
| 640 | "Failed to get gpio flags, error: %d\n", | ||
| 641 | error); | ||
| 642 | return ERR_PTR(error); | ||
| 643 | } | ||
| 637 | } | 644 | } |
| 638 | 645 | ||
| 639 | button = &pdata->buttons[i++]; | ||
| 640 | |||
| 641 | button->gpio = gpio; | 646 | button->gpio = gpio; |
| 642 | button->active_low = flags & OF_GPIO_ACTIVE_LOW; | 647 | button->active_low = flags & OF_GPIO_ACTIVE_LOW; |
| 643 | 648 | ||
diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c index cb32e2b506b7..21bea52d4365 100644 --- a/drivers/input/keyboard/lm8323.c +++ b/drivers/input/keyboard/lm8323.c | |||
| @@ -616,6 +616,8 @@ static ssize_t lm8323_set_disable(struct device *dev, | |||
| 616 | unsigned int i; | 616 | unsigned int i; |
| 617 | 617 | ||
| 618 | ret = kstrtouint(buf, 10, &i); | 618 | ret = kstrtouint(buf, 10, &i); |
| 619 | if (ret) | ||
| 620 | return ret; | ||
| 619 | 621 | ||
| 620 | mutex_lock(&lm->lock); | 622 | mutex_lock(&lm->lock); |
| 621 | lm->kp_enabled = !i; | 623 | lm->kp_enabled = !i; |
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c index 8c079371c2e7..265d641c40e2 100644 --- a/drivers/input/keyboard/lpc32xx-keys.c +++ b/drivers/input/keyboard/lpc32xx-keys.c | |||
| @@ -66,7 +66,6 @@ | |||
| 66 | struct lpc32xx_kscan_drv { | 66 | struct lpc32xx_kscan_drv { |
| 67 | struct input_dev *input; | 67 | struct input_dev *input; |
| 68 | struct clk *clk; | 68 | struct clk *clk; |
| 69 | struct resource *iores; | ||
| 70 | void __iomem *kscan_base; | 69 | void __iomem *kscan_base; |
| 71 | unsigned int irq; | 70 | unsigned int irq; |
| 72 | 71 | ||
| @@ -188,32 +187,27 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) | |||
| 188 | return -EINVAL; | 187 | return -EINVAL; |
| 189 | } | 188 | } |
| 190 | 189 | ||
| 191 | kscandat = kzalloc(sizeof(struct lpc32xx_kscan_drv), GFP_KERNEL); | 190 | kscandat = devm_kzalloc(&pdev->dev, sizeof(*kscandat), |
| 192 | if (!kscandat) { | 191 | GFP_KERNEL); |
| 193 | dev_err(&pdev->dev, "failed to allocate memory\n"); | 192 | if (!kscandat) |
| 194 | return -ENOMEM; | 193 | return -ENOMEM; |
| 195 | } | ||
| 196 | 194 | ||
| 197 | error = lpc32xx_parse_dt(&pdev->dev, kscandat); | 195 | error = lpc32xx_parse_dt(&pdev->dev, kscandat); |
| 198 | if (error) { | 196 | if (error) { |
| 199 | dev_err(&pdev->dev, "failed to parse device tree\n"); | 197 | dev_err(&pdev->dev, "failed to parse device tree\n"); |
| 200 | goto err_free_mem; | 198 | return error; |
| 201 | } | 199 | } |
| 202 | 200 | ||
| 203 | keymap_size = sizeof(kscandat->keymap[0]) * | 201 | keymap_size = sizeof(kscandat->keymap[0]) * |
| 204 | (kscandat->matrix_sz << kscandat->row_shift); | 202 | (kscandat->matrix_sz << kscandat->row_shift); |
| 205 | kscandat->keymap = kzalloc(keymap_size, GFP_KERNEL); | 203 | kscandat->keymap = devm_kzalloc(&pdev->dev, keymap_size, GFP_KERNEL); |
| 206 | if (!kscandat->keymap) { | 204 | if (!kscandat->keymap) |
| 207 | dev_err(&pdev->dev, "could not allocate memory for keymap\n"); | 205 | return -ENOMEM; |
| 208 | error = -ENOMEM; | ||
| 209 | goto err_free_mem; | ||
| 210 | } | ||
| 211 | 206 | ||
| 212 | kscandat->input = input = input_allocate_device(); | 207 | kscandat->input = input = devm_input_allocate_device(&pdev->dev); |
| 213 | if (!input) { | 208 | if (!input) { |
| 214 | dev_err(&pdev->dev, "failed to allocate input device\n"); | 209 | dev_err(&pdev->dev, "failed to allocate input device\n"); |
| 215 | error = -ENOMEM; | 210 | return -ENOMEM; |
| 216 | goto err_free_keymap; | ||
| 217 | } | 211 | } |
| 218 | 212 | ||
| 219 | /* Setup key input */ | 213 | /* Setup key input */ |
| @@ -234,39 +228,26 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) | |||
| 234 | kscandat->keymap, kscandat->input); | 228 | kscandat->keymap, kscandat->input); |
| 235 | if (error) { | 229 | if (error) { |
| 236 | dev_err(&pdev->dev, "failed to build keymap\n"); | 230 | dev_err(&pdev->dev, "failed to build keymap\n"); |
| 237 | goto err_free_input; | 231 | return error; |
| 238 | } | 232 | } |
| 239 | 233 | ||
| 240 | input_set_drvdata(kscandat->input, kscandat); | 234 | input_set_drvdata(kscandat->input, kscandat); |
| 241 | 235 | ||
| 242 | kscandat->iores = request_mem_region(res->start, resource_size(res), | 236 | kscandat->kscan_base = devm_ioremap_resource(&pdev->dev, res); |
| 243 | pdev->name); | 237 | if (IS_ERR(kscandat->kscan_base)) |
| 244 | if (!kscandat->iores) { | 238 | return PTR_ERR(kscandat->kscan_base); |
| 245 | dev_err(&pdev->dev, "failed to request I/O memory\n"); | ||
| 246 | error = -EBUSY; | ||
| 247 | goto err_free_input; | ||
| 248 | } | ||
| 249 | |||
| 250 | kscandat->kscan_base = ioremap(kscandat->iores->start, | ||
| 251 | resource_size(kscandat->iores)); | ||
| 252 | if (!kscandat->kscan_base) { | ||
| 253 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | ||
| 254 | error = -EBUSY; | ||
| 255 | goto err_release_memregion; | ||
| 256 | } | ||
| 257 | 239 | ||
| 258 | /* Get the key scanner clock */ | 240 | /* Get the key scanner clock */ |
| 259 | kscandat->clk = clk_get(&pdev->dev, NULL); | 241 | kscandat->clk = devm_clk_get(&pdev->dev, NULL); |
| 260 | if (IS_ERR(kscandat->clk)) { | 242 | if (IS_ERR(kscandat->clk)) { |
| 261 | dev_err(&pdev->dev, "failed to get clock\n"); | 243 | dev_err(&pdev->dev, "failed to get clock\n"); |
| 262 | error = PTR_ERR(kscandat->clk); | 244 | return PTR_ERR(kscandat->clk); |
| 263 | goto err_unmap; | ||
| 264 | } | 245 | } |
| 265 | 246 | ||
| 266 | /* Configure the key scanner */ | 247 | /* Configure the key scanner */ |
| 267 | error = clk_prepare_enable(kscandat->clk); | 248 | error = clk_prepare_enable(kscandat->clk); |
| 268 | if (error) | 249 | if (error) |
| 269 | goto err_clk_put; | 250 | return error; |
| 270 | 251 | ||
| 271 | writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base)); | 252 | writel(kscandat->deb_clks, LPC32XX_KS_DEB(kscandat->kscan_base)); |
| 272 | writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base)); | 253 | writel(kscandat->scan_delay, LPC32XX_KS_SCAN_CTL(kscandat->kscan_base)); |
| @@ -277,52 +258,20 @@ static int lpc32xx_kscan_probe(struct platform_device *pdev) | |||
| 277 | writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); | 258 | writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); |
| 278 | clk_disable_unprepare(kscandat->clk); | 259 | clk_disable_unprepare(kscandat->clk); |
| 279 | 260 | ||
| 280 | error = request_irq(irq, lpc32xx_kscan_irq, 0, pdev->name, kscandat); | 261 | error = devm_request_irq(&pdev->dev, irq, lpc32xx_kscan_irq, 0, |
| 262 | pdev->name, kscandat); | ||
| 281 | if (error) { | 263 | if (error) { |
| 282 | dev_err(&pdev->dev, "failed to request irq\n"); | 264 | dev_err(&pdev->dev, "failed to request irq\n"); |
| 283 | goto err_clk_put; | 265 | return error; |
| 284 | } | 266 | } |
| 285 | 267 | ||
| 286 | error = input_register_device(kscandat->input); | 268 | error = input_register_device(kscandat->input); |
| 287 | if (error) { | 269 | if (error) { |
| 288 | dev_err(&pdev->dev, "failed to register input device\n"); | 270 | dev_err(&pdev->dev, "failed to register input device\n"); |
| 289 | goto err_free_irq; | 271 | return error; |
| 290 | } | 272 | } |
| 291 | 273 | ||
| 292 | platform_set_drvdata(pdev, kscandat); | 274 | platform_set_drvdata(pdev, kscandat); |
| 293 | return 0; | ||
| 294 | |||
| 295 | err_free_irq: | ||
| 296 | free_irq(irq, kscandat); | ||
| 297 | err_clk_put: | ||
| 298 | clk_put(kscandat->clk); | ||
| 299 | err_unmap: | ||
| 300 | iounmap(kscandat->kscan_base); | ||
| 301 | err_release_memregion: | ||
| 302 | release_mem_region(kscandat->iores->start, | ||
| 303 | resource_size(kscandat->iores)); | ||
| 304 | err_free_input: | ||
| 305 | input_free_device(kscandat->input); | ||
| 306 | err_free_keymap: | ||
| 307 | kfree(kscandat->keymap); | ||
| 308 | err_free_mem: | ||
| 309 | kfree(kscandat); | ||
| 310 | |||
| 311 | return error; | ||
| 312 | } | ||
| 313 | |||
| 314 | static int lpc32xx_kscan_remove(struct platform_device *pdev) | ||
| 315 | { | ||
| 316 | struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); | ||
| 317 | |||
| 318 | free_irq(platform_get_irq(pdev, 0), kscandat); | ||
| 319 | clk_put(kscandat->clk); | ||
| 320 | iounmap(kscandat->kscan_base); | ||
| 321 | release_mem_region(kscandat->iores->start, | ||
| 322 | resource_size(kscandat->iores)); | ||
| 323 | input_unregister_device(kscandat->input); | ||
| 324 | kfree(kscandat->keymap); | ||
| 325 | kfree(kscandat); | ||
| 326 | 275 | ||
| 327 | return 0; | 276 | return 0; |
| 328 | } | 277 | } |
| @@ -378,7 +327,6 @@ MODULE_DEVICE_TABLE(of, lpc32xx_kscan_match); | |||
| 378 | 327 | ||
| 379 | static struct platform_driver lpc32xx_kscan_driver = { | 328 | static struct platform_driver lpc32xx_kscan_driver = { |
| 380 | .probe = lpc32xx_kscan_probe, | 329 | .probe = lpc32xx_kscan_probe, |
| 381 | .remove = lpc32xx_kscan_remove, | ||
| 382 | .driver = { | 330 | .driver = { |
| 383 | .name = DRV_NAME, | 331 | .name = DRV_NAME, |
| 384 | .pm = &lpc32xx_kscan_pm_ops, | 332 | .pm = &lpc32xx_kscan_pm_ops, |
diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c index 009c82256e89..3aa2ec45bcab 100644 --- a/drivers/input/keyboard/mpr121_touchkey.c +++ b/drivers/input/keyboard/mpr121_touchkey.c | |||
| @@ -214,13 +214,14 @@ static int mpr_touchkey_probe(struct i2c_client *client, | |||
| 214 | return -EINVAL; | 214 | return -EINVAL; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | mpr121 = kzalloc(sizeof(struct mpr121_touchkey), GFP_KERNEL); | 217 | mpr121 = devm_kzalloc(&client->dev, sizeof(*mpr121), |
| 218 | input_dev = input_allocate_device(); | 218 | GFP_KERNEL); |
| 219 | if (!mpr121 || !input_dev) { | 219 | if (!mpr121) |
| 220 | dev_err(&client->dev, "Failed to allocate memory\n"); | 220 | return -ENOMEM; |
| 221 | error = -ENOMEM; | 221 | |
| 222 | goto err_free_mem; | 222 | input_dev = devm_input_allocate_device(&client->dev); |
| 223 | } | 223 | if (!input_dev) |
| 224 | return -ENOMEM; | ||
| 224 | 225 | ||
| 225 | mpr121->client = client; | 226 | mpr121->client = client; |
| 226 | mpr121->input_dev = input_dev; | 227 | mpr121->input_dev = input_dev; |
| @@ -243,44 +244,26 @@ static int mpr_touchkey_probe(struct i2c_client *client, | |||
| 243 | error = mpr121_phys_init(pdata, mpr121, client); | 244 | error = mpr121_phys_init(pdata, mpr121, client); |
| 244 | if (error) { | 245 | if (error) { |
| 245 | dev_err(&client->dev, "Failed to init register\n"); | 246 | dev_err(&client->dev, "Failed to init register\n"); |
| 246 | goto err_free_mem; | 247 | return error; |
| 247 | } | 248 | } |
| 248 | 249 | ||
| 249 | error = request_threaded_irq(client->irq, NULL, | 250 | error = devm_request_threaded_irq(&client->dev, client->irq, NULL, |
| 250 | mpr_touchkey_interrupt, | 251 | mpr_touchkey_interrupt, |
| 251 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | 252 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
| 252 | client->dev.driver->name, mpr121); | 253 | client->dev.driver->name, mpr121); |
| 253 | if (error) { | 254 | if (error) { |
| 254 | dev_err(&client->dev, "Failed to register interrupt\n"); | 255 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 255 | goto err_free_mem; | 256 | return error; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | error = input_register_device(input_dev); | 259 | error = input_register_device(input_dev); |
| 259 | if (error) | 260 | if (error) |
| 260 | goto err_free_irq; | 261 | return error; |
| 261 | 262 | ||
| 262 | i2c_set_clientdata(client, mpr121); | 263 | i2c_set_clientdata(client, mpr121); |
| 263 | device_init_wakeup(&client->dev, pdata->wakeup); | 264 | device_init_wakeup(&client->dev, pdata->wakeup); |
| 264 | 265 | ||
| 265 | return 0; | 266 | return 0; |
| 266 | |||
| 267 | err_free_irq: | ||
| 268 | free_irq(client->irq, mpr121); | ||
| 269 | err_free_mem: | ||
| 270 | input_free_device(input_dev); | ||
| 271 | kfree(mpr121); | ||
| 272 | return error; | ||
| 273 | } | ||
| 274 | |||
| 275 | static int mpr_touchkey_remove(struct i2c_client *client) | ||
| 276 | { | ||
| 277 | struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client); | ||
| 278 | |||
| 279 | free_irq(client->irq, mpr121); | ||
| 280 | input_unregister_device(mpr121->input_dev); | ||
| 281 | kfree(mpr121); | ||
| 282 | |||
| 283 | return 0; | ||
| 284 | } | 267 | } |
| 285 | 268 | ||
| 286 | #ifdef CONFIG_PM_SLEEP | 269 | #ifdef CONFIG_PM_SLEEP |
| @@ -327,7 +310,6 @@ static struct i2c_driver mpr_touchkey_driver = { | |||
| 327 | }, | 310 | }, |
| 328 | .id_table = mpr121_id, | 311 | .id_table = mpr121_id, |
| 329 | .probe = mpr_touchkey_probe, | 312 | .probe = mpr_touchkey_probe, |
| 330 | .remove = mpr_touchkey_remove, | ||
| 331 | }; | 313 | }; |
| 332 | 314 | ||
| 333 | module_i2c_driver(mpr_touchkey_driver); | 315 | module_i2c_driver(mpr_touchkey_driver); |
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c index 6ab3e7c96329..a90d6bdc499e 100644 --- a/drivers/input/keyboard/pxa27x_keypad.c +++ b/drivers/input/keyboard/pxa27x_keypad.c | |||
| @@ -741,37 +741,27 @@ static int pxa27x_keypad_probe(struct platform_device *pdev) | |||
| 741 | return -ENXIO; | 741 | return -ENXIO; |
| 742 | } | 742 | } |
| 743 | 743 | ||
| 744 | keypad = kzalloc(sizeof(struct pxa27x_keypad), GFP_KERNEL); | 744 | keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), |
| 745 | input_dev = input_allocate_device(); | 745 | GFP_KERNEL); |
| 746 | if (!keypad || !input_dev) { | 746 | if (!keypad) |
| 747 | dev_err(&pdev->dev, "failed to allocate memory\n"); | 747 | return -ENOMEM; |
| 748 | error = -ENOMEM; | 748 | |
| 749 | goto failed_free; | 749 | input_dev = devm_input_allocate_device(&pdev->dev); |
| 750 | } | 750 | if (!input_dev) |
| 751 | return -ENOMEM; | ||
| 751 | 752 | ||
| 752 | keypad->pdata = pdata; | 753 | keypad->pdata = pdata; |
| 753 | keypad->input_dev = input_dev; | 754 | keypad->input_dev = input_dev; |
| 754 | keypad->irq = irq; | 755 | keypad->irq = irq; |
| 755 | 756 | ||
| 756 | res = request_mem_region(res->start, resource_size(res), pdev->name); | 757 | keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res); |
| 757 | if (res == NULL) { | 758 | if (IS_ERR(keypad->mmio_base)) |
| 758 | dev_err(&pdev->dev, "failed to request I/O memory\n"); | 759 | return PTR_ERR(keypad->mmio_base); |
| 759 | error = -EBUSY; | ||
| 760 | goto failed_free; | ||
| 761 | } | ||
| 762 | |||
| 763 | keypad->mmio_base = ioremap(res->start, resource_size(res)); | ||
| 764 | if (keypad->mmio_base == NULL) { | ||
| 765 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | ||
| 766 | error = -ENXIO; | ||
| 767 | goto failed_free_mem; | ||
| 768 | } | ||
| 769 | 760 | ||
| 770 | keypad->clk = clk_get(&pdev->dev, NULL); | 761 | keypad->clk = devm_clk_get(&pdev->dev, NULL); |
| 771 | if (IS_ERR(keypad->clk)) { | 762 | if (IS_ERR(keypad->clk)) { |
| 772 | dev_err(&pdev->dev, "failed to get keypad clock\n"); | 763 | dev_err(&pdev->dev, "failed to get keypad clock\n"); |
| 773 | error = PTR_ERR(keypad->clk); | 764 | return PTR_ERR(keypad->clk); |
| 774 | goto failed_free_io; | ||
| 775 | } | 765 | } |
| 776 | 766 | ||
| 777 | input_dev->name = pdev->name; | 767 | input_dev->name = pdev->name; |
| @@ -802,7 +792,7 @@ static int pxa27x_keypad_probe(struct platform_device *pdev) | |||
| 802 | } | 792 | } |
| 803 | if (error) { | 793 | if (error) { |
| 804 | dev_err(&pdev->dev, "failed to build keycode\n"); | 794 | dev_err(&pdev->dev, "failed to build keycode\n"); |
| 805 | goto failed_put_clk; | 795 | return error; |
| 806 | } | 796 | } |
| 807 | 797 | ||
| 808 | keypad->row_shift = get_count_order(pdata->matrix_key_cols); | 798 | keypad->row_shift = get_count_order(pdata->matrix_key_cols); |
| @@ -812,61 +802,26 @@ static int pxa27x_keypad_probe(struct platform_device *pdev) | |||
| 812 | input_dev->evbit[0] |= BIT_MASK(EV_REL); | 802 | input_dev->evbit[0] |= BIT_MASK(EV_REL); |
| 813 | } | 803 | } |
| 814 | 804 | ||
| 815 | error = request_irq(irq, pxa27x_keypad_irq_handler, 0, | 805 | error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler, |
| 816 | pdev->name, keypad); | 806 | 0, pdev->name, keypad); |
| 817 | if (error) { | 807 | if (error) { |
| 818 | dev_err(&pdev->dev, "failed to request IRQ\n"); | 808 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
| 819 | goto failed_put_clk; | 809 | return error; |
| 820 | } | 810 | } |
| 821 | 811 | ||
| 822 | /* Register the input device */ | 812 | /* Register the input device */ |
| 823 | error = input_register_device(input_dev); | 813 | error = input_register_device(input_dev); |
| 824 | if (error) { | 814 | if (error) { |
| 825 | dev_err(&pdev->dev, "failed to register input device\n"); | 815 | dev_err(&pdev->dev, "failed to register input device\n"); |
| 826 | goto failed_free_irq; | 816 | return error; |
| 827 | } | 817 | } |
| 828 | 818 | ||
| 829 | platform_set_drvdata(pdev, keypad); | 819 | platform_set_drvdata(pdev, keypad); |
| 830 | device_init_wakeup(&pdev->dev, 1); | 820 | device_init_wakeup(&pdev->dev, 1); |
| 831 | 821 | ||
| 832 | return 0; | 822 | return 0; |
| 833 | |||
| 834 | failed_free_irq: | ||
| 835 | free_irq(irq, keypad); | ||
| 836 | failed_put_clk: | ||
| 837 | clk_put(keypad->clk); | ||
| 838 | failed_free_io: | ||
| 839 | iounmap(keypad->mmio_base); | ||
| 840 | failed_free_mem: | ||
| 841 | release_mem_region(res->start, resource_size(res)); | ||
| 842 | failed_free: | ||
| 843 | input_free_device(input_dev); | ||
| 844 | kfree(keypad); | ||
| 845 | return error; | ||
| 846 | } | 823 | } |
| 847 | 824 | ||
| 848 | static int pxa27x_keypad_remove(struct platform_device *pdev) | ||
| 849 | { | ||
| 850 | struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); | ||
| 851 | struct resource *res; | ||
| 852 | |||
| 853 | free_irq(keypad->irq, keypad); | ||
| 854 | clk_put(keypad->clk); | ||
| 855 | |||
| 856 | input_unregister_device(keypad->input_dev); | ||
| 857 | iounmap(keypad->mmio_base); | ||
| 858 | |||
| 859 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 860 | release_mem_region(res->start, resource_size(res)); | ||
| 861 | |||
| 862 | kfree(keypad); | ||
| 863 | |||
| 864 | return 0; | ||
| 865 | } | ||
| 866 | |||
| 867 | /* work with hotplug and coldplug */ | ||
| 868 | MODULE_ALIAS("platform:pxa27x-keypad"); | ||
| 869 | |||
| 870 | #ifdef CONFIG_OF | 825 | #ifdef CONFIG_OF |
| 871 | static const struct of_device_id pxa27x_keypad_dt_match[] = { | 826 | static const struct of_device_id pxa27x_keypad_dt_match[] = { |
| 872 | { .compatible = "marvell,pxa27x-keypad" }, | 827 | { .compatible = "marvell,pxa27x-keypad" }, |
| @@ -877,7 +832,6 @@ MODULE_DEVICE_TABLE(of, pxa27x_keypad_dt_match); | |||
| 877 | 832 | ||
| 878 | static struct platform_driver pxa27x_keypad_driver = { | 833 | static struct platform_driver pxa27x_keypad_driver = { |
| 879 | .probe = pxa27x_keypad_probe, | 834 | .probe = pxa27x_keypad_probe, |
| 880 | .remove = pxa27x_keypad_remove, | ||
| 881 | .driver = { | 835 | .driver = { |
| 882 | .name = "pxa27x-keypad", | 836 | .name = "pxa27x-keypad", |
| 883 | .of_match_table = of_match_ptr(pxa27x_keypad_dt_match), | 837 | .of_match_table = of_match_ptr(pxa27x_keypad_dt_match), |
| @@ -888,3 +842,5 @@ module_platform_driver(pxa27x_keypad_driver); | |||
| 888 | 842 | ||
| 889 | MODULE_DESCRIPTION("PXA27x Keypad Controller Driver"); | 843 | MODULE_DESCRIPTION("PXA27x Keypad Controller Driver"); |
| 890 | MODULE_LICENSE("GPL"); | 844 | MODULE_LICENSE("GPL"); |
| 845 | /* work with hotplug and coldplug */ | ||
| 846 | MODULE_ALIAS("platform:pxa27x-keypad"); | ||
