diff options
-rw-r--r-- | drivers/input/input.c | 50 | ||||
-rw-r--r-- | include/linux/input.h | 4 |
2 files changed, 38 insertions, 16 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index d092ef9291da..75bed635b98d 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -1565,8 +1565,7 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env) | |||
1565 | } \ | 1565 | } \ |
1566 | } while (0) | 1566 | } while (0) |
1567 | 1567 | ||
1568 | #ifdef CONFIG_PM | 1568 | static void input_dev_toggle(struct input_dev *dev, bool activate) |
1569 | static void input_dev_reset(struct input_dev *dev, bool activate) | ||
1570 | { | 1569 | { |
1571 | if (!dev->event) | 1570 | if (!dev->event) |
1572 | return; | 1571 | return; |
@@ -1580,12 +1579,44 @@ static void input_dev_reset(struct input_dev *dev, bool activate) | |||
1580 | } | 1579 | } |
1581 | } | 1580 | } |
1582 | 1581 | ||
1582 | /** | ||
1583 | * input_reset_device() - reset/restore the state of input device | ||
1584 | * @dev: input device whose state needs to be reset | ||
1585 | * | ||
1586 | * This function tries to reset the state of an opened input device and | ||
1587 | * bring internal state and state if the hardware in sync with each other. | ||
1588 | * We mark all keys as released, restore LED state, repeat rate, etc. | ||
1589 | */ | ||
1590 | void input_reset_device(struct input_dev *dev) | ||
1591 | { | ||
1592 | mutex_lock(&dev->mutex); | ||
1593 | |||
1594 | if (dev->users) { | ||
1595 | input_dev_toggle(dev, true); | ||
1596 | |||
1597 | /* | ||
1598 | * Keys that have been pressed at suspend time are unlikely | ||
1599 | * to be still pressed when we resume. | ||
1600 | */ | ||
1601 | spin_lock_irq(&dev->event_lock); | ||
1602 | input_dev_release_keys(dev); | ||
1603 | spin_unlock_irq(&dev->event_lock); | ||
1604 | } | ||
1605 | |||
1606 | mutex_unlock(&dev->mutex); | ||
1607 | } | ||
1608 | EXPORT_SYMBOL(input_reset_device); | ||
1609 | |||
1610 | #ifdef CONFIG_PM | ||
1583 | static int input_dev_suspend(struct device *dev) | 1611 | static int input_dev_suspend(struct device *dev) |
1584 | { | 1612 | { |
1585 | struct input_dev *input_dev = to_input_dev(dev); | 1613 | struct input_dev *input_dev = to_input_dev(dev); |
1586 | 1614 | ||
1587 | mutex_lock(&input_dev->mutex); | 1615 | mutex_lock(&input_dev->mutex); |
1588 | input_dev_reset(input_dev, false); | 1616 | |
1617 | if (input_dev->users) | ||
1618 | input_dev_toggle(input_dev, false); | ||
1619 | |||
1589 | mutex_unlock(&input_dev->mutex); | 1620 | mutex_unlock(&input_dev->mutex); |
1590 | 1621 | ||
1591 | return 0; | 1622 | return 0; |
@@ -1595,18 +1626,7 @@ static int input_dev_resume(struct device *dev) | |||
1595 | { | 1626 | { |
1596 | struct input_dev *input_dev = to_input_dev(dev); | 1627 | struct input_dev *input_dev = to_input_dev(dev); |
1597 | 1628 | ||
1598 | mutex_lock(&input_dev->mutex); | 1629 | input_reset_device(input_dev); |
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); | ||
1610 | 1630 | ||
1611 | return 0; | 1631 | return 0; |
1612 | } | 1632 | } |
diff --git a/include/linux/input.h b/include/linux/input.h index 51af441f3a21..6ef44465db8d 100644 --- a/include/linux/input.h +++ b/include/linux/input.h | |||
@@ -1406,6 +1406,8 @@ static inline void input_set_drvdata(struct input_dev *dev, void *data) | |||
1406 | int __must_check input_register_device(struct input_dev *); | 1406 | int __must_check input_register_device(struct input_dev *); |
1407 | void input_unregister_device(struct input_dev *); | 1407 | void input_unregister_device(struct input_dev *); |
1408 | 1408 | ||
1409 | void input_reset_device(struct input_dev *); | ||
1410 | |||
1409 | int __must_check input_register_handler(struct input_handler *); | 1411 | int __must_check input_register_handler(struct input_handler *); |
1410 | void input_unregister_handler(struct input_handler *); | 1412 | void input_unregister_handler(struct input_handler *); |
1411 | 1413 | ||
@@ -1421,7 +1423,7 @@ void input_release_device(struct input_handle *); | |||
1421 | int input_open_device(struct input_handle *); | 1423 | int input_open_device(struct input_handle *); |
1422 | void input_close_device(struct input_handle *); | 1424 | void input_close_device(struct input_handle *); |
1423 | 1425 | ||
1424 | int input_flush_device(struct input_handle* handle, struct file* file); | 1426 | int input_flush_device(struct input_handle *handle, struct file *file); |
1425 | 1427 | ||
1426 | void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value); | 1428 | void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value); |
1427 | void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value); | 1429 | void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value); |