···9090 To compile this driver as a module, choose M here: the9191 module will be called uinput.92929393+config INPUT_POLLDEV9494+ tristate "Polled input device skeleton"9595+ help9696+ Say Y here if you are using a driver for an input9797+ device that periodically polls hardware state. This9898+ option is only useful for out-of-tree drivers since9999+ in-tree drivers select it automatically.100100+101101+ To compile this driver as a module, choose M here: the102102+ module will be called input-polldev.103103+93104config HP_SDC_RTC94105 tristate "HP SDC Real Time Clock"95106 depends on GSC || HP300
+1
drivers/input/misc/Makefile
···4455# Each configuration option enables a list of files.6677+obj-$(CONFIG_INPUT_POLLDEV) += input-polldev.o78obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o89obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o910obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
+171
drivers/input/misc/input-polldev.c
···11+/*22+ * Generic implementation of a polled input device33+44+ * Copyright (c) 2007 Dmitry Torokhov55+ *66+ * This program is free software; you can redistribute it and/or modify it77+ * under the terms of the GNU General Public License version 2 as published by88+ * the Free Software Foundation.99+ */1010+1111+#include <linux/jiffies.h>1212+#include <linux/mutex.h>1313+#include <linux/input-polldev.h>1414+1515+static DEFINE_MUTEX(polldev_mutex);1616+static int polldev_users;1717+static struct workqueue_struct *polldev_wq;1818+1919+static int input_polldev_start_workqueue(void)2020+{2121+ int retval;2222+2323+ retval = mutex_lock_interruptible(&polldev_mutex);2424+ if (retval)2525+ return retval;2626+2727+ if (!polldev_users) {2828+ polldev_wq = create_singlethread_workqueue("ipolldevd");2929+ if (!polldev_wq) {3030+ printk(KERN_ERR "input-polldev: failed to create "3131+ "ipolldevd workqueue\n");3232+ retval = -ENOMEM;3333+ goto out;3434+ }3535+ }3636+3737+ polldev_users++;3838+3939+ out:4040+ mutex_unlock(&polldev_mutex);4141+ return retval;4242+}4343+4444+static void input_polldev_stop_workqueue(void)4545+{4646+ mutex_lock(&polldev_mutex);4747+4848+ if (!--polldev_users)4949+ destroy_workqueue(polldev_wq);5050+5151+ mutex_unlock(&polldev_mutex);5252+}5353+5454+static void input_polled_device_work(struct work_struct *work)5555+{5656+ struct input_polled_dev *dev =5757+ container_of(work, struct input_polled_dev, work.work);5858+5959+ dev->poll(dev);6060+ queue_delayed_work(polldev_wq, &dev->work,6161+ msecs_to_jiffies(dev->poll_interval));6262+}6363+6464+static int input_open_polled_device(struct input_dev *input)6565+{6666+ struct input_polled_dev *dev = input->private;6767+ int error;6868+6969+ error = input_polldev_start_workqueue();7070+ if (error)7171+ return error;7272+7373+ if (dev->flush)7474+ dev->flush(dev);7575+7676+ queue_delayed_work(polldev_wq, &dev->work,7777+ msecs_to_jiffies(dev->poll_interval));7878+7979+ return 0;8080+}8181+8282+static void input_close_polled_device(struct input_dev *input)8383+{8484+ struct input_polled_dev *dev = input->private;8585+8686+ cancel_rearming_delayed_workqueue(polldev_wq, &dev->work);8787+ input_polldev_stop_workqueue();8888+}8989+9090+/**9191+ * input_allocate_polled_device - allocated memory polled device9292+ *9393+ * The function allocates memory for a polled device and also9494+ * for an input device associated with this polled device.9595+ */9696+struct input_polled_dev *input_allocate_polled_device(void)9797+{9898+ struct input_polled_dev *dev;9999+100100+ dev = kzalloc(sizeof(struct input_polled_dev), GFP_KERNEL);101101+ if (!dev)102102+ return NULL;103103+104104+ dev->input = input_allocate_device();105105+ if (!dev->input) {106106+ kfree(dev);107107+ return NULL;108108+ }109109+110110+ return dev;111111+}112112+EXPORT_SYMBOL(input_allocate_polled_device);113113+114114+/**115115+ * input_free_polled_device - free memory allocated for polled device116116+ * @dev: device to free117117+ *118118+ * The function frees memory allocated for polling device and drops119119+ * reference to the associated input device (if present).120120+ */121121+void input_free_polled_device(struct input_polled_dev *dev)122122+{123123+ if (dev) {124124+ input_free_device(dev->input);125125+ kfree(dev);126126+ }127127+}128128+EXPORT_SYMBOL(input_free_polled_device);129129+130130+/**131131+ * input_register_polled_device - register polled device132132+ * @dev: device to register133133+ *134134+ * The function registers previously initialized polled input device135135+ * with input layer. The device should be allocated with call to136136+ * input_allocate_polled_device(). Callers should also set up poll()137137+ * method and set up capabilities (id, name, phys, bits) of the138138+ * corresponing input_dev structure.139139+ */140140+int input_register_polled_device(struct input_polled_dev *dev)141141+{142142+ struct input_dev *input = dev->input;143143+144144+ INIT_DELAYED_WORK(&dev->work, input_polled_device_work);145145+ if (!dev->poll_interval)146146+ dev->poll_interval = 500;147147+ input->private = dev;148148+ input->open = input_open_polled_device;149149+ input->close = input_close_polled_device;150150+151151+ return input_register_device(input);152152+}153153+EXPORT_SYMBOL(input_register_polled_device);154154+155155+/**156156+ * input_unregister_polled_device - unregister polled device157157+ * @dev: device to unregister158158+ *159159+ * The function unregisters previously registered polled input160160+ * device from input layer. Polling is stopped and device is161161+ * ready to be freed with call to input_free_polled_device().162162+ * Callers should not attempt to access dev->input pointer163163+ * after calling this function.164164+ */165165+void input_unregister_polled_device(struct input_polled_dev *dev)166166+{167167+ input_unregister_device(dev->input);168168+ dev->input = NULL;169169+}170170+EXPORT_SYMBOL(input_unregister_polled_device);171171+
+46
include/linux/input-polldev.h
···11+#ifndef _INPUT_POLLDEV_H22+#define _INPUT_POLLDEV_H33+44+/*55+ * Copyright (c) 2007 Dmitry Torokhov66+ *77+ * This program is free software; you can redistribute it and/or modify it88+ * under the terms of the GNU General Public License version 2 as published by99+ * the Free Software Foundation.1010+ */1111+1212+#include <linux/input.h>1313+#include <linux/workqueue.h>1414+1515+/**1616+ * struct input_polled_dev - simple polled input device1717+ * @private: private driver data1818+ * @flush: driver-supplied method that flushes device's state upon1919+ * opening (optional)2020+ * @poll: driver-supplied method that polls the device and posts2121+ * input events (mandatory).2222+ * @poll_interval: specifies how often the poll() method shoudl be called.2323+ * @input: input device structire associated with the polled device.2424+ * Must be properly initialized by the driver (id, name, phys, bits).2525+ *2626+ * Polled input device provides a skeleton for supporting simple input2727+ * devices that do not raise interrupts but have to be periodically2828+ * scanned or polled to detect changes in their state.2929+ */3030+struct input_polled_dev {3131+ void *private;3232+3333+ void (*flush)(struct input_polled_dev *dev);3434+ void (*poll)(struct input_polled_dev *dev);3535+ unsigned int poll_interval; /* msec */3636+3737+ struct input_dev *input;3838+ struct delayed_work work;3939+};4040+4141+struct input_polled_dev *input_allocate_polled_device(void);4242+void input_free_polled_device(struct input_polled_dev *dev);4343+int input_register_polled_device(struct input_polled_dev *dev);4444+void input_unregister_polled_device(struct input_polled_dev *dev);4545+4646+#endif