12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
28215d557SHenrik Rydberg /*
38215d557SHenrik Rydberg * HID support for Linux
48215d557SHenrik Rydberg *
58215d557SHenrik Rydberg * Copyright (c) 1999 Andreas Gal
68215d557SHenrik Rydberg * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
78215d557SHenrik Rydberg * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
88215d557SHenrik Rydberg * Copyright (c) 2007-2008 Oliver Neukum
98215d557SHenrik Rydberg * Copyright (c) 2006-2012 Jiri Kosina
108215d557SHenrik Rydberg * Copyright (c) 2012 Henrik Rydberg
118215d557SHenrik Rydberg */
128215d557SHenrik Rydberg
138215d557SHenrik Rydberg /*
148215d557SHenrik Rydberg */
158215d557SHenrik Rydberg
168215d557SHenrik Rydberg #include <linux/module.h>
178215d557SHenrik Rydberg #include <linux/slab.h>
188215d557SHenrik Rydberg #include <linux/kernel.h>
19*5f60d5f6SAl Viro #include <linux/unaligned.h>
208215d557SHenrik Rydberg #include <asm/byteorder.h>
218215d557SHenrik Rydberg
228215d557SHenrik Rydberg #include <linux/hid.h>
238215d557SHenrik Rydberg
24e04a0442SBenjamin Tissoires static struct hid_driver hid_generic;
25e04a0442SBenjamin Tissoires
__check_hid_generic(struct device_driver * drv,void * data)26e04a0442SBenjamin Tissoires static int __check_hid_generic(struct device_driver *drv, void *data)
27e04a0442SBenjamin Tissoires {
28e04a0442SBenjamin Tissoires struct hid_driver *hdrv = to_hid_driver(drv);
29e04a0442SBenjamin Tissoires struct hid_device *hdev = data;
30e04a0442SBenjamin Tissoires
31e04a0442SBenjamin Tissoires if (hdrv == &hid_generic)
32e04a0442SBenjamin Tissoires return 0;
33e04a0442SBenjamin Tissoires
34e04a0442SBenjamin Tissoires return hid_match_device(hdev, hdrv) != NULL;
35e04a0442SBenjamin Tissoires }
36e04a0442SBenjamin Tissoires
hid_generic_match(struct hid_device * hdev,bool ignore_special_driver)37e04a0442SBenjamin Tissoires static bool hid_generic_match(struct hid_device *hdev,
38e04a0442SBenjamin Tissoires bool ignore_special_driver)
39e04a0442SBenjamin Tissoires {
40e04a0442SBenjamin Tissoires if (ignore_special_driver)
41e04a0442SBenjamin Tissoires return true;
42e04a0442SBenjamin Tissoires
43e04a0442SBenjamin Tissoires if (hdev->quirks & HID_QUIRK_HAVE_SPECIAL_DRIVER)
44e04a0442SBenjamin Tissoires return false;
45e04a0442SBenjamin Tissoires
46e04a0442SBenjamin Tissoires /*
47e04a0442SBenjamin Tissoires * If any other driver wants the device, leave the device to this other
48e04a0442SBenjamin Tissoires * driver.
49e04a0442SBenjamin Tissoires */
50e04a0442SBenjamin Tissoires if (bus_for_each_drv(&hid_bus_type, NULL, hdev, __check_hid_generic))
51e04a0442SBenjamin Tissoires return false;
52e04a0442SBenjamin Tissoires
53e04a0442SBenjamin Tissoires return true;
54e04a0442SBenjamin Tissoires }
55e04a0442SBenjamin Tissoires
hid_generic_probe(struct hid_device * hdev,const struct hid_device_id * id)56f07b3c1dSBenjamin Tissoires static int hid_generic_probe(struct hid_device *hdev,
57f07b3c1dSBenjamin Tissoires const struct hid_device_id *id)
58f07b3c1dSBenjamin Tissoires {
59f07b3c1dSBenjamin Tissoires int ret;
60f07b3c1dSBenjamin Tissoires
61f07b3c1dSBenjamin Tissoires hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
62f07b3c1dSBenjamin Tissoires
63f07b3c1dSBenjamin Tissoires ret = hid_parse(hdev);
64f07b3c1dSBenjamin Tissoires if (ret)
65f07b3c1dSBenjamin Tissoires return ret;
66f07b3c1dSBenjamin Tissoires
67f07b3c1dSBenjamin Tissoires return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
68f07b3c1dSBenjamin Tissoires }
69f07b3c1dSBenjamin Tissoires
708215d557SHenrik Rydberg static const struct hid_device_id hid_table[] = {
71e04a0442SBenjamin Tissoires { HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, HID_ANY_ID, HID_ANY_ID) },
728215d557SHenrik Rydberg { }
738215d557SHenrik Rydberg };
748215d557SHenrik Rydberg MODULE_DEVICE_TABLE(hid, hid_table);
758215d557SHenrik Rydberg
768215d557SHenrik Rydberg static struct hid_driver hid_generic = {
778215d557SHenrik Rydberg .name = "hid-generic",
788215d557SHenrik Rydberg .id_table = hid_table,
79e04a0442SBenjamin Tissoires .match = hid_generic_match,
80f07b3c1dSBenjamin Tissoires .probe = hid_generic_probe,
818215d557SHenrik Rydberg };
82f425458eSH Hartley Sweeten module_hid_driver(hid_generic);
838215d557SHenrik Rydberg
848215d557SHenrik Rydberg MODULE_AUTHOR("Henrik Rydberg");
858215d557SHenrik Rydberg MODULE_DESCRIPTION("HID generic driver");
868215d557SHenrik Rydberg MODULE_LICENSE("GPL");
87