xref: /linux/drivers/hid/i2c-hid/i2c-hid-acpi.c (revision 0960941043a19c0413b30dc5e88a55c593fda1cb)
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 	 */
42b33752c3SDouglas Anderson 	{"CHPN0001", 0 },
43b33752c3SDouglas Anderson 	{ },
44b33752c3SDouglas Anderson };
45b33752c3SDouglas Anderson 
46a3836a02SAndy Shevchenko /* HID I²C Device: 3cdff6f7-4267-4555-ad05-b30a3d8938de */
47b33752c3SDouglas Anderson static guid_t i2c_hid_guid =
48b33752c3SDouglas Anderson 	GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
49b33752c3SDouglas Anderson 		  0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
50a3836a02SAndy Shevchenko 
51a3836a02SAndy Shevchenko static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
52a3836a02SAndy Shevchenko {
536d97010eSAndy Shevchenko 	acpi_handle handle = acpi_device_handle(adev);
54b33752c3SDouglas Anderson 	union acpi_object *obj;
55b33752c3SDouglas Anderson 	u16 hid_descriptor_address;
56b33752c3SDouglas Anderson 
57b33752c3SDouglas Anderson 	if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
58b33752c3SDouglas Anderson 		return -ENODEV;
59b33752c3SDouglas Anderson 
60b33752c3SDouglas Anderson 	obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
61b33752c3SDouglas Anderson 				      ACPI_TYPE_INTEGER);
62b33752c3SDouglas Anderson 	if (!obj) {
636d97010eSAndy Shevchenko 		acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
64b33752c3SDouglas Anderson 		return -ENODEV;
65b33752c3SDouglas Anderson 	}
66b33752c3SDouglas Anderson 
67b33752c3SDouglas Anderson 	hid_descriptor_address = obj->integer.value;
68b33752c3SDouglas Anderson 	ACPI_FREE(obj);
69b33752c3SDouglas Anderson 
70b33752c3SDouglas Anderson 	return hid_descriptor_address;
71b33752c3SDouglas Anderson }
72b33752c3SDouglas Anderson 
73b33752c3SDouglas Anderson static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
74b33752c3SDouglas Anderson {
756d97010eSAndy Shevchenko 	struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
766d97010eSAndy Shevchenko 
776d97010eSAndy Shevchenko 	acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
78b33752c3SDouglas Anderson }
79b33752c3SDouglas Anderson 
804cecff8fSAndy Shevchenko static int i2c_hid_acpi_probe(struct i2c_client *client)
81b33752c3SDouglas Anderson {
82b33752c3SDouglas Anderson 	struct device *dev = &client->dev;
83b33752c3SDouglas Anderson 	struct i2c_hid_acpi *ihid_acpi;
84b33752c3SDouglas Anderson 	struct acpi_device *adev;
85b33752c3SDouglas Anderson 	u16 hid_descriptor_address;
86b33752c3SDouglas Anderson 	int ret;
87b33752c3SDouglas Anderson 
886d97010eSAndy Shevchenko 	adev = ACPI_COMPANION(dev);
896d97010eSAndy Shevchenko 	if (!adev) {
906d97010eSAndy Shevchenko 		dev_err(&client->dev, "Error could not get ACPI device\n");
916d97010eSAndy Shevchenko 		return -ENODEV;
926d97010eSAndy Shevchenko 	}
936d97010eSAndy Shevchenko 
94b33752c3SDouglas Anderson 	ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
95b33752c3SDouglas Anderson 	if (!ihid_acpi)
96b33752c3SDouglas Anderson 		return -ENOMEM;
97b33752c3SDouglas Anderson 
986d97010eSAndy Shevchenko 	ihid_acpi->adev = adev;
99b33752c3SDouglas Anderson 	ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
100b33752c3SDouglas Anderson 
1016d97010eSAndy Shevchenko 	ret = i2c_hid_acpi_get_descriptor(adev);
102b33752c3SDouglas Anderson 	if (ret < 0)
103b33752c3SDouglas Anderson 		return ret;
104b33752c3SDouglas Anderson 	hid_descriptor_address = ret;
105b33752c3SDouglas Anderson 
106b33752c3SDouglas Anderson 	acpi_device_fix_up_power(adev);
107b33752c3SDouglas Anderson 
108b33752c3SDouglas Anderson 	if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
109b33752c3SDouglas Anderson 		device_set_wakeup_capable(dev, true);
110b33752c3SDouglas Anderson 		device_set_wakeup_enable(dev, false);
111b33752c3SDouglas Anderson 	}
112b33752c3SDouglas Anderson 
113b33752c3SDouglas Anderson 	return i2c_hid_core_probe(client, &ihid_acpi->ops,
114b33752c3SDouglas Anderson 				  hid_descriptor_address);
115b33752c3SDouglas Anderson }
116b33752c3SDouglas Anderson 
117b33752c3SDouglas Anderson static const struct acpi_device_id i2c_hid_acpi_match[] = {
118b33752c3SDouglas Anderson 	{"ACPI0C50", 0 },
119b33752c3SDouglas Anderson 	{"PNP0C50", 0 },
120b33752c3SDouglas Anderson 	{ },
121b33752c3SDouglas Anderson };
122b33752c3SDouglas Anderson MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
123b33752c3SDouglas Anderson 
124b33752c3SDouglas Anderson static struct i2c_driver i2c_hid_acpi_driver = {
125b33752c3SDouglas Anderson 	.driver = {
126b33752c3SDouglas Anderson 		.name	= "i2c_hid_acpi",
127b33752c3SDouglas Anderson 		.pm	= &i2c_hid_core_pm,
128b33752c3SDouglas Anderson 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
129*09609410SAndy Shevchenko 		.acpi_match_table = i2c_hid_acpi_match,
130b33752c3SDouglas Anderson 	},
131b33752c3SDouglas Anderson 
1324cecff8fSAndy Shevchenko 	.probe_new	= i2c_hid_acpi_probe,
133b33752c3SDouglas Anderson 	.remove		= i2c_hid_core_remove,
134b33752c3SDouglas Anderson 	.shutdown	= i2c_hid_core_shutdown,
135b33752c3SDouglas Anderson };
136b33752c3SDouglas Anderson 
137b33752c3SDouglas Anderson module_i2c_driver(i2c_hid_acpi_driver);
138b33752c3SDouglas Anderson 
139b33752c3SDouglas Anderson MODULE_DESCRIPTION("HID over I2C ACPI driver");
140b33752c3SDouglas Anderson MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
141b33752c3SDouglas Anderson MODULE_LICENSE("GPL");
142