Skip to content

Commit 7803c05

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: Input: do not pass injected events back to the originating handler Input: pcf8574_keypad - fix error handling in pcf8574_kp_probe Input: acecad - fix a memory leak in usb_acecad_probe error path Input: atkbd - add 'terminal' parameter for IBM Terminal keyboards Input: i8042 - add Sony VAIOs to MUX blacklist kgdboc: reset input devices (keyboards) when exiting debugger Input: export input_reset_device() for use in KGDB Input: adp5588-keys - unify common header defines
2 parents 522a991 + 5fdbe44 commit 7803c05

File tree

9 files changed

+196
-92
lines changed

9 files changed

+196
-92
lines changed

drivers/input/input.c

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
7474
* dev->event_lock held and interrupts disabled.
7575
*/
7676
static void input_pass_event(struct input_dev *dev,
77+
struct input_handler *src_handler,
7778
unsigned int type, unsigned int code, int value)
7879
{
7980
struct input_handler *handler;
@@ -92,6 +93,15 @@ static void input_pass_event(struct input_dev *dev,
9293
continue;
9394

9495
handler = handle->handler;
96+
97+
/*
98+
* If this is the handler that injected this
99+
* particular event we want to skip it to avoid
100+
* filters firing again and again.
101+
*/
102+
if (handler == src_handler)
103+
continue;
104+
95105
if (!handler->filter) {
96106
if (filtered)
97107
break;
@@ -121,7 +131,7 @@ static void input_repeat_key(unsigned long data)
121131
if (test_bit(dev->repeat_key, dev->key) &&
122132
is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
123133

124-
input_pass_event(dev, EV_KEY, dev->repeat_key, 2);
134+
input_pass_event(dev, NULL, EV_KEY, dev->repeat_key, 2);
125135

126136
if (dev->sync) {
127137
/*
@@ -130,7 +140,7 @@ static void input_repeat_key(unsigned long data)
130140
* Otherwise assume that the driver will send
131141
* SYN_REPORT once it's done.
132142
*/
133-
input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
143+
input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
134144
}
135145

136146
if (dev->rep[REP_PERIOD])
@@ -163,6 +173,7 @@ static void input_stop_autorepeat(struct input_dev *dev)
163173
#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
164174

165175
static int input_handle_abs_event(struct input_dev *dev,
176+
struct input_handler *src_handler,
166177
unsigned int code, int *pval)
167178
{
168179
bool is_mt_event;
@@ -206,13 +217,15 @@ static int input_handle_abs_event(struct input_dev *dev,
206217
/* Flush pending "slot" event */
207218
if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
208219
input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
209-
input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
220+
input_pass_event(dev, src_handler,
221+
EV_ABS, ABS_MT_SLOT, dev->slot);
210222
}
211223

212224
return INPUT_PASS_TO_HANDLERS;
213225
}
214226

215227
static void input_handle_event(struct input_dev *dev,
228+
struct input_handler *src_handler,
216229
unsigned int type, unsigned int code, int value)
217230
{
218231
int disposition = INPUT_IGNORE_EVENT;
@@ -265,7 +278,8 @@ static void input_handle_event(struct input_dev *dev,
265278

266279
case EV_ABS:
267280
if (is_event_supported(code, dev->absbit, ABS_MAX))
268-
disposition = input_handle_abs_event(dev, code, &value);
281+
disposition = input_handle_abs_event(dev, src_handler,
282+
code, &value);
269283

270284
break;
271285

@@ -323,7 +337,7 @@ static void input_handle_event(struct input_dev *dev,
323337
dev->event(dev, type, code, value);
324338

325339
if (disposition & INPUT_PASS_TO_HANDLERS)
326-
input_pass_event(dev, type, code, value);
340+
input_pass_event(dev, src_handler, type, code, value);
327341
}
328342

329343
/**
@@ -352,7 +366,7 @@ void input_event(struct input_dev *dev,
352366

353367
spin_lock_irqsave(&dev->event_lock, flags);
354368
add_input_randomness(type, code, value);
355-
input_handle_event(dev, type, code, value);
369+
input_handle_event(dev, NULL, type, code, value);
356370
spin_unlock_irqrestore(&dev->event_lock, flags);
357371
}
358372
}
@@ -382,7 +396,8 @@ void input_inject_event(struct input_handle *handle,
382396
rcu_read_lock();
383397
grab = rcu_dereference(dev->grab);
384398
if (!grab || grab == handle)
385-
input_handle_event(dev, type, code, value);
399+
input_handle_event(dev, handle->handler,
400+
type, code, value);
386401
rcu_read_unlock();
387402

388403
spin_unlock_irqrestore(&dev->event_lock, flags);
@@ -595,10 +610,10 @@ static void input_dev_release_keys(struct input_dev *dev)
595610
for (code = 0; code <= KEY_MAX; code++) {
596611
if (is_event_supported(code, dev->keybit, KEY_MAX) &&
597612
__test_and_clear_bit(code, dev->key)) {
598-
input_pass_event(dev, EV_KEY, code, 0);
613+
input_pass_event(dev, NULL, EV_KEY, code, 0);
599614
}
600615
}
601-
input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
616+
input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
602617
}
603618
}
604619

@@ -873,9 +888,9 @@ int input_set_keycode(struct input_dev *dev,
873888
!is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
874889
__test_and_clear_bit(old_keycode, dev->key)) {
875890

876-
input_pass_event(dev, EV_KEY, old_keycode, 0);
891+
input_pass_event(dev, NULL, EV_KEY, old_keycode, 0);
877892
if (dev->sync)
878-
input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
893+
input_pass_event(dev, NULL, EV_SYN, SYN_REPORT, 1);
879894
}
880895

881896
out:
@@ -1565,8 +1580,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
15651580
} \
15661581
} while (0)
15671582

1568-
#ifdef CONFIG_PM
1569-
static void input_dev_reset(struct input_dev *dev, bool activate)
1583+
static void input_dev_toggle(struct input_dev *dev, bool activate)
15701584
{
15711585
if (!dev->event)
15721586
return;
@@ -1580,12 +1594,44 @@ static void input_dev_reset(struct input_dev *dev, bool activate)
15801594
}
15811595
}
15821596

1597+
/**
1598+
* input_reset_device() - reset/restore the state of input device
1599+
* @dev: input device whose state needs to be reset
1600+
*
1601+
* This function tries to reset the state of an opened input device and
1602+
* bring internal state and state if the hardware in sync with each other.
1603+
* We mark all keys as released, restore LED state, repeat rate, etc.
1604+
*/
1605+
void input_reset_device(struct input_dev *dev)
1606+
{
1607+
mutex_lock(&dev->mutex);
1608+
1609+
if (dev->users) {
1610+
input_dev_toggle(dev, true);
1611+
1612+
/*
1613+
* Keys that have been pressed at suspend time are unlikely
1614+
* to be still pressed when we resume.
1615+
*/
1616+
spin_lock_irq(&dev->event_lock);
1617+
input_dev_release_keys(dev);
1618+
spin_unlock_irq(&dev->event_lock);
1619+
}
1620+
1621+
mutex_unlock(&dev->mutex);
1622+
}
1623+
EXPORT_SYMBOL(input_reset_device);
1624+
1625+
#ifdef CONFIG_PM
15831626
static int input_dev_suspend(struct device *dev)
15841627
{
15851628
struct input_dev *input_dev = to_input_dev(dev);
15861629

15871630
mutex_lock(&input_dev->mutex);
1588-
input_dev_reset(input_dev, false);
1631+
1632+
if (input_dev->users)
1633+
input_dev_toggle(input_dev, false);
1634+
15891635
mutex_unlock(&input_dev->mutex);
15901636

15911637
return 0;
@@ -1595,18 +1641,7 @@ static int input_dev_resume(struct device *dev)
15951641
{
15961642
struct input_dev *input_dev = to_input_dev(dev);
15971643

1598-
mutex_lock(&input_dev->mutex);
1599-
input_dev_reset(input_dev, true);
1600-
1601-
/*
1602-
* Keys that have been pressed at suspend time are unlikely
1603-
* to be still pressed when we resume.
1604-
*/
1605-
spin_lock_irq(&input_dev->event_lock);
1606-
input_dev_release_keys(input_dev);
1607-
spin_unlock_irq(&input_dev->event_lock);
1608-
1609-
mutex_unlock(&input_dev->mutex);
1644+
input_reset_device(input_dev);
16101645

16111646
return 0;
16121647
}

drivers/input/keyboard/adp5588-keys.c

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* I2C QWERTY Keypad and IO Expander
55
* Bugs: Enter bugs at http://blackfin.uclinux.org/
66
*
7-
* Copyright (C) 2008-2009 Analog Devices Inc.
7+
* Copyright (C) 2008-2010 Analog Devices Inc.
88
* Licensed under the GPL-2 or later.
99
*/
1010

@@ -24,29 +24,6 @@
2424

2525
#include <linux/i2c/adp5588.h>
2626

27-
/* Configuration Register1 */
28-
#define AUTO_INC (1 << 7)
29-
#define GPIEM_CFG (1 << 6)
30-
#define OVR_FLOW_M (1 << 5)
31-
#define INT_CFG (1 << 4)
32-
#define OVR_FLOW_IEN (1 << 3)
33-
#define K_LCK_IM (1 << 2)
34-
#define GPI_IEN (1 << 1)
35-
#define KE_IEN (1 << 0)
36-
37-
/* Interrupt Status Register */
38-
#define CMP2_INT (1 << 5)
39-
#define CMP1_INT (1 << 4)
40-
#define OVR_FLOW_INT (1 << 3)
41-
#define K_LCK_INT (1 << 2)
42-
#define GPI_INT (1 << 1)
43-
#define KE_INT (1 << 0)
44-
45-
/* Key Lock and Event Counter Register */
46-
#define K_LCK_EN (1 << 6)
47-
#define LCK21 0x30
48-
#define KEC 0xF
49-
5027
/* Key Event Register xy */
5128
#define KEY_EV_PRESSED (1 << 7)
5229
#define KEY_EV_MASK (0x7F)
@@ -55,10 +32,6 @@
5532

5633
#define KEYP_MAX_EVENT 10
5734

58-
#define MAXGPIO 18
59-
#define ADP_BANK(offs) ((offs) >> 3)
60-
#define ADP_BIT(offs) (1u << ((offs) & 0x7))
61-
6235
/*
6336
* Early pre 4.0 Silicon required to delay readout by at least 25ms,
6437
* since the Event Counter Register updated 25ms after the interrupt
@@ -75,7 +48,7 @@ struct adp5588_kpad {
7548
const struct adp5588_gpi_map *gpimap;
7649
unsigned short gpimapsize;
7750
#ifdef CONFIG_GPIOLIB
78-
unsigned char gpiomap[MAXGPIO];
51+
unsigned char gpiomap[ADP5588_MAXGPIO];
7952
bool export_gpio;
8053
struct gpio_chip gc;
8154
struct mutex gpio_lock; /* Protect cached dir, dat_out */
@@ -103,8 +76,8 @@ static int adp5588_write(struct i2c_client *client, u8 reg, u8 val)
10376
static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
10477
{
10578
struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
106-
unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
107-
unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
79+
unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
80+
unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
10881

10982
return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit);
11083
}
@@ -113,8 +86,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
11386
unsigned off, int val)
11487
{
11588
struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
116-
unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
117-
unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
89+
unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
90+
unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
11891

11992
mutex_lock(&kpad->gpio_lock);
12093

@@ -132,8 +105,8 @@ static void adp5588_gpio_set_value(struct gpio_chip *chip,
132105
static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned off)
133106
{
134107
struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
135-
unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
136-
unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
108+
unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
109+
unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
137110
int ret;
138111

139112
mutex_lock(&kpad->gpio_lock);
@@ -150,8 +123,8 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
150123
unsigned off, int val)
151124
{
152125
struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
153-
unsigned int bank = ADP_BANK(kpad->gpiomap[off]);
154-
unsigned int bit = ADP_BIT(kpad->gpiomap[off]);
126+
unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
127+
unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
155128
int ret;
156129

157130
mutex_lock(&kpad->gpio_lock);
@@ -176,7 +149,7 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
176149
static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
177150
const struct adp5588_kpad_platform_data *pdata)
178151
{
179-
bool pin_used[MAXGPIO];
152+
bool pin_used[ADP5588_MAXGPIO];
180153
int n_unused = 0;
181154
int i;
182155

@@ -191,7 +164,7 @@ static int __devinit adp5588_build_gpiomap(struct adp5588_kpad *kpad,
191164
for (i = 0; i < kpad->gpimapsize; i++)
192165
pin_used[kpad->gpimap[i].pin - GPI_PIN_BASE] = true;
193166

194-
for (i = 0; i < MAXGPIO; i++)
167+
for (i = 0; i < ADP5588_MAXGPIO; i++)
195168
if (!pin_used[i])
196169
kpad->gpiomap[n_unused++] = i;
197170

@@ -234,7 +207,7 @@ static int __devinit adp5588_gpio_add(struct adp5588_kpad *kpad)
234207
return error;
235208
}
236209

237-
for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
210+
for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
238211
kpad->dat_out[i] = adp5588_read(kpad->client,
239212
GPIO_DAT_OUT1 + i);
240213
kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i);
@@ -318,11 +291,11 @@ static void adp5588_work(struct work_struct *work)
318291

319292
status = adp5588_read(client, INT_STAT);
320293

321-
if (status & OVR_FLOW_INT) /* Unlikely and should never happen */
294+
if (status & ADP5588_OVR_FLOW_INT) /* Unlikely and should never happen */
322295
dev_err(&client->dev, "Event Overflow Error\n");
323296

324-
if (status & KE_INT) {
325-
ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & KEC;
297+
if (status & ADP5588_KE_INT) {
298+
ev_cnt = adp5588_read(client, KEY_LCK_EC_STAT) & ADP5588_KEC;
326299
if (ev_cnt) {
327300
adp5588_report_events(kpad, ev_cnt);
328301
input_sync(kpad->input);
@@ -360,7 +333,7 @@ static int __devinit adp5588_setup(struct i2c_client *client)
360333
if (pdata->en_keylock) {
361334
ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
362335
ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
363-
ret |= adp5588_write(client, KEY_LCK_EC_STAT, K_LCK_EN);
336+
ret |= adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
364337
}
365338

366339
for (i = 0; i < KEYP_MAX_EVENT; i++)
@@ -384,19 +357,22 @@ static int __devinit adp5588_setup(struct i2c_client *client)
384357
}
385358

386359
if (gpio_data) {
387-
for (i = 0; i <= ADP_BANK(MAXGPIO); i++) {
360+
for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
388361
int pull_mask = gpio_data->pullup_dis_mask;
389362

390363
ret |= adp5588_write(client, GPIO_PULL1 + i,
391364
(pull_mask >> (8 * i)) & 0xFF);
392365
}
393366
}
394367

395-
ret |= adp5588_write(client, INT_STAT, CMP2_INT | CMP1_INT |
396-
OVR_FLOW_INT | K_LCK_INT |
397-
GPI_INT | KE_INT); /* Status is W1C */
368+
ret |= adp5588_write(client, INT_STAT,
369+
ADP5588_CMP2_INT | ADP5588_CMP1_INT |
370+
ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
371+
ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
398372

399-
ret |= adp5588_write(client, CFG, INT_CFG | OVR_FLOW_IEN | KE_IEN);
373+
ret |= adp5588_write(client, CFG, ADP5588_INT_CFG |
374+
ADP5588_OVR_FLOW_IEN |
375+
ADP5588_KE_IEN);
400376

401377
if (ret < 0) {
402378
dev_err(&client->dev, "Write Error\n");

0 commit comments

Comments
 (0)