xref: /linux/drivers/hid/i2c-hid/i2c-hid-acpi.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
1b33752c3SDouglas Anderson /*
2b33752c3SDouglas Anderson  * HID over I2C ACPI Subclass
3b33752c3SDouglas Anderson  *
4b33752c3SDouglas Anderson  * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
5b33752c3SDouglas Anderson  * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
6b33752c3SDouglas Anderson  * Copyright (c) 2012 Red Hat, Inc
7b33752c3SDouglas Anderson  *
8b33752c3SDouglas Anderson  * This code was forked out of the core code, which was partly based on
9b33752c3SDouglas Anderson  * "USB HID support for Linux":
10b33752c3SDouglas Anderson  *
11b33752c3SDouglas Anderson  *  Copyright (c) 1999 Andreas Gal
12b33752c3SDouglas Anderson  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
13b33752c3SDouglas Anderson  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
14b33752c3SDouglas Anderson  *  Copyright (c) 2007-2008 Oliver Neukum
15b33752c3SDouglas Anderson  *  Copyright (c) 2006-2010 Jiri Kosina
16b33752c3SDouglas Anderson  *
17b33752c3SDouglas Anderson  * This file is subject to the terms and conditions of the GNU General Public
18b33752c3SDouglas Anderson  * License.  See the file COPYING in the main directory of this archive for
19b33752c3SDouglas Anderson  * more details.
20b33752c3SDouglas Anderson  */
21b33752c3SDouglas Anderson 
22b33752c3SDouglas Anderson #include <linux/acpi.h>
23b33752c3SDouglas Anderson #include <linux/device.h>
24b33752c3SDouglas Anderson #include <linux/i2c.h>
25b33752c3SDouglas Anderson #include <linux/kernel.h>
26b33752c3SDouglas Anderson #include <linux/module.h>
27b33752c3SDouglas Anderson #include <linux/pm.h>
28a3836a02SAndy Shevchenko #include <linux/uuid.h>
29b33752c3SDouglas Anderson 
30b33752c3SDouglas Anderson #include "i2c-hid.h"
31b33752c3SDouglas Anderson 
32b33752c3SDouglas Anderson struct i2c_hid_acpi {
33b33752c3SDouglas Anderson 	struct i2chid_ops ops;
346d97010eSAndy Shevchenko 	struct acpi_device *adev;
35b33752c3SDouglas Anderson };
36b33752c3SDouglas Anderson 
37b33752c3SDouglas Anderson static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
38b33752c3SDouglas Anderson 	/*
39b33752c3SDouglas Anderson 	 * The CHPN0001 ACPI device, which is used to describe the Chipone
40b33752c3SDouglas Anderson 	 * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible.
41b33752c3SDouglas Anderson 	 */
424122abfeSAndy Shevchenko 	{ "CHPN0001" },
43*a9f68ffeSMario Limonciello 	/*
44*a9f68ffeSMario Limonciello 	 * The IDEA5002 ACPI device causes high interrupt usage and spurious
45*a9f68ffeSMario Limonciello 	 * wakeups from suspend.
46*a9f68ffeSMario Limonciello 	 */
47*a9f68ffeSMario Limonciello 	{ "IDEA5002" },
484122abfeSAndy Shevchenko 	{ }
49b33752c3SDouglas Anderson };
50b33752c3SDouglas Anderson 
51a3836a02SAndy Shevchenko /* HID I²C Device: 3cdff6f7-4267-4555-ad05-b30a3d8938de */
52b33752c3SDouglas Anderson static guid_t i2c_hid_guid =
53b33752c3SDouglas Anderson 	GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
54b33752c3SDouglas Anderson 		  0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
55a3836a02SAndy Shevchenko 
i2c_hid_acpi_get_descriptor(struct i2c_hid_acpi * ihid_acpi)56572eaeb7SAndy Shevchenko static int i2c_hid_acpi_get_descriptor(struct i2c_hid_acpi *ihid_acpi)
57a3836a02SAndy Shevchenko {
58572eaeb7SAndy Shevchenko 	struct acpi_device *adev = ihid_acpi->adev;
596d97010eSAndy Shevchenko 	acpi_handle handle = acpi_device_handle(adev);
60b33752c3SDouglas Anderson 	union acpi_object *obj;
61b33752c3SDouglas Anderson 	u16 hid_descriptor_address;
62b33752c3SDouglas Anderson 
63b33752c3SDouglas Anderson 	if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
64b33752c3SDouglas Anderson 		return -ENODEV;
65b33752c3SDouglas Anderson 
66b33752c3SDouglas Anderson 	obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
67b33752c3SDouglas Anderson 				      ACPI_TYPE_INTEGER);
68b33752c3SDouglas Anderson 	if (!obj) {
696d97010eSAndy Shevchenko 		acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
70b33752c3SDouglas Anderson 		return -ENODEV;
71b33752c3SDouglas Anderson 	}
72b33752c3SDouglas Anderson 
73b33752c3SDouglas Anderson 	hid_descriptor_address = obj->integer.value;
74b33752c3SDouglas Anderson 	ACPI_FREE(obj);
75b33752c3SDouglas Anderson 
76b33752c3SDouglas Anderson 	return hid_descriptor_address;
77b33752c3SDouglas Anderson }
78b33752c3SDouglas Anderson 
i2c_hid_acpi_shutdown_tail(struct i2chid_ops * ops)79b33752c3SDouglas Anderson static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
80b33752c3SDouglas Anderson {
816d97010eSAndy Shevchenko 	struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
826d97010eSAndy Shevchenko 
836d97010eSAndy Shevchenko 	acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
84b33752c3SDouglas Anderson }
85b33752c3SDouglas Anderson 
i2c_hid_acpi_probe(struct i2c_client * client)864cecff8fSAndy Shevchenko static int i2c_hid_acpi_probe(struct i2c_client *client)
87b33752c3SDouglas Anderson {
88b33752c3SDouglas Anderson 	struct device *dev = &client->dev;
89b33752c3SDouglas Anderson 	struct i2c_hid_acpi *ihid_acpi;
90b33752c3SDouglas Anderson 	u16 hid_descriptor_address;
91b33752c3SDouglas Anderson 	int ret;
92b33752c3SDouglas Anderson 
93b33752c3SDouglas Anderson 	ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
94b33752c3SDouglas Anderson 	if (!ihid_acpi)
95b33752c3SDouglas Anderson 		return -ENOMEM;
96b33752c3SDouglas Anderson 
97572eaeb7SAndy Shevchenko 	ihid_acpi->adev = ACPI_COMPANION(dev);
98b33752c3SDouglas Anderson 	ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
99b33752c3SDouglas Anderson 
100572eaeb7SAndy Shevchenko 	ret = i2c_hid_acpi_get_descriptor(ihid_acpi);
101b33752c3SDouglas Anderson 	if (ret < 0)
102b33752c3SDouglas Anderson 		return ret;
103b33752c3SDouglas Anderson 	hid_descriptor_address = ret;
104b33752c3SDouglas Anderson 
105572eaeb7SAndy Shevchenko 	acpi_device_fix_up_power(ihid_acpi->adev);
106b33752c3SDouglas Anderson 
107b33752c3SDouglas Anderson 	return i2c_hid_core_probe(client, &ihid_acpi->ops,
108b60d3c80SAlistair Francis 				  hid_descriptor_address, 0);
109b33752c3SDouglas Anderson }
110b33752c3SDouglas Anderson 
111b33752c3SDouglas Anderson static const struct acpi_device_id i2c_hid_acpi_match[] = {
1124122abfeSAndy Shevchenko 	{ "ACPI0C50" },
1134122abfeSAndy Shevchenko 	{ "PNP0C50" },
1144122abfeSAndy Shevchenko 	{ }
115b33752c3SDouglas Anderson };
116b33752c3SDouglas Anderson MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
117b33752c3SDouglas Anderson 
118b33752c3SDouglas Anderson static struct i2c_driver i2c_hid_acpi_driver = {
119b33752c3SDouglas Anderson 	.driver = {
120b33752c3SDouglas Anderson 		.name	= "i2c_hid_acpi",
121b33752c3SDouglas Anderson 		.pm	= &i2c_hid_core_pm,
122b33752c3SDouglas Anderson 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
12309609410SAndy Shevchenko 		.acpi_match_table = i2c_hid_acpi_match,
124b33752c3SDouglas Anderson 	},
125b33752c3SDouglas Anderson 
126e4b88075SUwe Kleine-König 	.probe		= i2c_hid_acpi_probe,
127b33752c3SDouglas Anderson 	.remove		= i2c_hid_core_remove,
128b33752c3SDouglas Anderson 	.shutdown	= i2c_hid_core_shutdown,
129b33752c3SDouglas Anderson };
130b33752c3SDouglas Anderson 
131b33752c3SDouglas Anderson module_i2c_driver(i2c_hid_acpi_driver);
132b33752c3SDouglas Anderson 
133b33752c3SDouglas Anderson MODULE_DESCRIPTION("HID over I2C ACPI driver");
134b33752c3SDouglas Anderson MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
135b33752c3SDouglas Anderson MODULE_LICENSE("GPL");
136