blob: 14821fd231c085ee64efa6ce627fdbce56d7b94c [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -04002#ifndef _INPUT_POLLDEV_H
3#define _INPUT_POLLDEV_H
4
5/*
6 * Copyright (c) 2007 Dmitry Torokhov
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -04007 */
8
9#include <linux/input.h>
10#include <linux/workqueue.h>
11
12/**
13 * struct input_polled_dev - simple polled input device
Samu Onkalob0aba1e2009-10-18 00:38:57 -070014 * @private: private driver data.
15 * @open: driver-supplied method that prepares device for polling
16 * (enabled the device and maybe flushes device state).
17 * @close: driver-supplied method that is called when device is no
18 * longer being polled. Used to put device into low power mode.
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040019 * @poll: driver-supplied method that polls the device and posts
20 * input events (mandatory).
Samu Onkalodad725d2009-11-13 21:13:22 -080021 * @poll_interval: specifies how often the poll() method should be called.
Dmitry Torokhov2546bcc2011-01-31 21:06:34 -080022 * Defaults to 500 msec unless overridden when registering the device.
Samu Onkalodad725d2009-11-13 21:13:22 -080023 * @poll_interval_max: specifies upper bound for the poll interval.
24 * Defaults to the initial value of @poll_interval.
25 * @poll_interval_min: specifies lower bound for the poll interval.
26 * Defaults to 0.
Dmitry Torokhov2546bcc2011-01-31 21:06:34 -080027 * @input: input device structure associated with the polled device.
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040028 * Must be properly initialized by the driver (id, name, phys, bits).
29 *
30 * Polled input device provides a skeleton for supporting simple input
31 * devices that do not raise interrupts but have to be periodically
32 * scanned or polled to detect changes in their state.
33 */
34struct input_polled_dev {
35 void *private;
36
Samu Onkalob0aba1e2009-10-18 00:38:57 -070037 void (*open)(struct input_polled_dev *dev);
38 void (*close)(struct input_polled_dev *dev);
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040039 void (*poll)(struct input_polled_dev *dev);
40 unsigned int poll_interval; /* msec */
Samu Onkalodad725d2009-11-13 21:13:22 -080041 unsigned int poll_interval_max; /* msec */
42 unsigned int poll_interval_min; /* msec */
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040043
44 struct input_dev *input;
Samu Onkalodad725d2009-11-13 21:13:22 -080045
46/* private: */
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040047 struct delayed_work work;
Dmitry Torokhovbf1de972014-04-28 10:49:51 -070048
49 bool devres_managed;
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040050};
51
52struct input_polled_dev *input_allocate_polled_device(void);
Dmitry Torokhovbf1de972014-04-28 10:49:51 -070053struct input_polled_dev *devm_input_allocate_polled_device(struct device *dev);
Dmitry Torokhov0dcd8072007-04-29 23:42:45 -040054void input_free_polled_device(struct input_polled_dev *dev);
55int input_register_polled_device(struct input_polled_dev *dev);
56void input_unregister_polled_device(struct input_polled_dev *dev);
57
58#endif