Input: export input_reset_device() for use in KGDB

KGDB, much like the resume process, needs to be able to mark all keys that
were pressed at the time we dropped into the debuggers as "released", since
it is unlikely that the keys stay pressed for the entire duration of the
debug session.

Also we need to make sure that input_reset_device() and input_dev_suspend()
only attempt to change state of currenlt opened devices since closed devices
may not be ready to accept IO requests.

Tested-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+38 -16
+35 -15
drivers/input/input.c
··· 1565 } \ 1566 } while (0) 1567 1568 - #ifdef CONFIG_PM 1569 - static void input_dev_reset(struct input_dev *dev, bool activate) 1570 { 1571 if (!dev->event) 1572 return; ··· 1579 } 1580 } 1581 1582 static int input_dev_suspend(struct device *dev) 1583 { 1584 struct input_dev *input_dev = to_input_dev(dev); 1585 1586 mutex_lock(&input_dev->mutex); 1587 - input_dev_reset(input_dev, false); 1588 mutex_unlock(&input_dev->mutex); 1589 1590 return 0; ··· 1626 { 1627 struct input_dev *input_dev = to_input_dev(dev); 1628 1629 - mutex_lock(&input_dev->mutex); 1630 - input_dev_reset(input_dev, true); 1631 - 1632 - /* 1633 - * Keys that have been pressed at suspend time are unlikely 1634 - * to be still pressed when we resume. 1635 - */ 1636 - spin_lock_irq(&input_dev->event_lock); 1637 - input_dev_release_keys(input_dev); 1638 - spin_unlock_irq(&input_dev->event_lock); 1639 - 1640 - mutex_unlock(&input_dev->mutex); 1641 1642 return 0; 1643 }
··· 1565 } \ 1566 } while (0) 1567 1568 + static void input_dev_toggle(struct input_dev *dev, bool activate) 1569 { 1570 if (!dev->event) 1571 return; ··· 1580 } 1581 } 1582 1583 + /** 1584 + * input_reset_device() - reset/restore the state of input device 1585 + * @dev: input device whose state needs to be reset 1586 + * 1587 + * This function tries to reset the state of an opened input device and 1588 + * bring internal state and state if the hardware in sync with each other. 1589 + * We mark all keys as released, restore LED state, repeat rate, etc. 1590 + */ 1591 + void input_reset_device(struct input_dev *dev) 1592 + { 1593 + mutex_lock(&dev->mutex); 1594 + 1595 + if (dev->users) { 1596 + input_dev_toggle(dev, true); 1597 + 1598 + /* 1599 + * Keys that have been pressed at suspend time are unlikely 1600 + * to be still pressed when we resume. 1601 + */ 1602 + spin_lock_irq(&dev->event_lock); 1603 + input_dev_release_keys(dev); 1604 + spin_unlock_irq(&dev->event_lock); 1605 + } 1606 + 1607 + mutex_unlock(&dev->mutex); 1608 + } 1609 + EXPORT_SYMBOL(input_reset_device); 1610 + 1611 + #ifdef CONFIG_PM 1612 static int input_dev_suspend(struct device *dev) 1613 { 1614 struct input_dev *input_dev = to_input_dev(dev); 1615 1616 mutex_lock(&input_dev->mutex); 1617 + 1618 + if (input_dev->users) 1619 + input_dev_toggle(input_dev, false); 1620 + 1621 mutex_unlock(&input_dev->mutex); 1622 1623 return 0; ··· 1595 { 1596 struct input_dev *input_dev = to_input_dev(dev); 1597 1598 + input_reset_device(input_dev); 1599 1600 return 0; 1601 }
+3 -1
include/linux/input.h
··· 1406 int __must_check input_register_device(struct input_dev *); 1407 void input_unregister_device(struct input_dev *); 1408 1409 int __must_check input_register_handler(struct input_handler *); 1410 void input_unregister_handler(struct input_handler *); 1411 ··· 1423 int input_open_device(struct input_handle *); 1424 void input_close_device(struct input_handle *); 1425 1426 - int input_flush_device(struct input_handle* handle, struct file* file); 1427 1428 void input_event(struct input_dev *dev, 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);
··· 1406 int __must_check input_register_device(struct input_dev *); 1407 void input_unregister_device(struct input_dev *); 1408 1409 + void input_reset_device(struct input_dev *); 1410 + 1411 int __must_check input_register_handler(struct input_handler *); 1412 void input_unregister_handler(struct input_handler *); 1413 ··· 1421 int input_open_device(struct input_handle *); 1422 void input_close_device(struct input_handle *); 1423 1424 + int input_flush_device(struct input_handle *handle, struct file *file); 1425 1426 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);