xref: /linux/drivers/hid/i2c-hid/i2c-hid-acpi.c (revision 4cecff8f1d0e52300e925ea6056acfd12cbc1bf2)
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>
28b33752c3SDouglas Anderson 
29b33752c3SDouglas Anderson #include "i2c-hid.h"
30b33752c3SDouglas Anderson 
31b33752c3SDouglas Anderson struct i2c_hid_acpi {
32b33752c3SDouglas Anderson 	struct i2chid_ops ops;
336d97010eSAndy Shevchenko 	struct acpi_device *adev;
34b33752c3SDouglas Anderson };
35b33752c3SDouglas Anderson 
36b33752c3SDouglas Anderson static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
37b33752c3SDouglas Anderson 	/*
38b33752c3SDouglas Anderson 	 * The CHPN0001 ACPI device, which is used to describe the Chipone
39b33752c3SDouglas Anderson 	 * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible.
40b33752c3SDouglas Anderson 	 */
41b33752c3SDouglas Anderson 	{"CHPN0001", 0 },
42b33752c3SDouglas Anderson 	{ },
43b33752c3SDouglas Anderson };
44b33752c3SDouglas Anderson 
456d97010eSAndy Shevchenko static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
46b33752c3SDouglas Anderson {
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);
506d97010eSAndy Shevchenko 	acpi_handle handle = acpi_device_handle(adev);
51b33752c3SDouglas Anderson 	union acpi_object *obj;
52b33752c3SDouglas Anderson 	u16 hid_descriptor_address;
53b33752c3SDouglas Anderson 
54b33752c3SDouglas Anderson 	if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
55b33752c3SDouglas Anderson 		return -ENODEV;
56b33752c3SDouglas Anderson 
57b33752c3SDouglas Anderson 	obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
58b33752c3SDouglas Anderson 				      ACPI_TYPE_INTEGER);
59b33752c3SDouglas Anderson 	if (!obj) {
606d97010eSAndy Shevchenko 		acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
61b33752c3SDouglas Anderson 		return -ENODEV;
62b33752c3SDouglas Anderson 	}
63b33752c3SDouglas Anderson 
64b33752c3SDouglas Anderson 	hid_descriptor_address = obj->integer.value;
65b33752c3SDouglas Anderson 	ACPI_FREE(obj);
66b33752c3SDouglas Anderson 
67b33752c3SDouglas Anderson 	return hid_descriptor_address;
68b33752c3SDouglas Anderson }
69b33752c3SDouglas Anderson 
70b33752c3SDouglas Anderson static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
71b33752c3SDouglas Anderson {
726d97010eSAndy Shevchenko 	struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
736d97010eSAndy Shevchenko 
746d97010eSAndy Shevchenko 	acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
75b33752c3SDouglas Anderson }
76b33752c3SDouglas Anderson 
77*4cecff8fSAndy Shevchenko static int i2c_hid_acpi_probe(struct i2c_client *client)
78b33752c3SDouglas Anderson {
79b33752c3SDouglas Anderson 	struct device *dev = &client->dev;
80b33752c3SDouglas Anderson 	struct i2c_hid_acpi *ihid_acpi;
81b33752c3SDouglas Anderson 	struct acpi_device *adev;
82b33752c3SDouglas Anderson 	u16 hid_descriptor_address;
83b33752c3SDouglas Anderson 	int ret;
84b33752c3SDouglas Anderson 
856d97010eSAndy Shevchenko 	adev = ACPI_COMPANION(dev);
866d97010eSAndy Shevchenko 	if (!adev) {
876d97010eSAndy Shevchenko 		dev_err(&client->dev, "Error could not get ACPI device\n");
886d97010eSAndy Shevchenko 		return -ENODEV;
896d97010eSAndy Shevchenko 	}
906d97010eSAndy Shevchenko 
91b33752c3SDouglas Anderson 	ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
92b33752c3SDouglas Anderson 	if (!ihid_acpi)
93b33752c3SDouglas Anderson 		return -ENOMEM;
94b33752c3SDouglas Anderson 
956d97010eSAndy Shevchenko 	ihid_acpi->adev = adev;
96b33752c3SDouglas Anderson 	ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
97b33752c3SDouglas Anderson 
986d97010eSAndy Shevchenko 	ret = i2c_hid_acpi_get_descriptor(adev);
99b33752c3SDouglas Anderson 	if (ret < 0)
100b33752c3SDouglas Anderson 		return ret;
101b33752c3SDouglas Anderson 	hid_descriptor_address = ret;
102b33752c3SDouglas Anderson 
103b33752c3SDouglas Anderson 	acpi_device_fix_up_power(adev);
104b33752c3SDouglas Anderson 
105b33752c3SDouglas Anderson 	if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
106b33752c3SDouglas Anderson 		device_set_wakeup_capable(dev, true);
107b33752c3SDouglas Anderson 		device_set_wakeup_enable(dev, false);
108b33752c3SDouglas Anderson 	}
109b33752c3SDouglas Anderson 
110b33752c3SDouglas Anderson 	return i2c_hid_core_probe(client, &ihid_acpi->ops,
111b33752c3SDouglas Anderson 				  hid_descriptor_address);
112b33752c3SDouglas Anderson }
113b33752c3SDouglas Anderson 
114b33752c3SDouglas Anderson static const struct acpi_device_id i2c_hid_acpi_match[] = {
115b33752c3SDouglas Anderson 	{"ACPI0C50", 0 },
116b33752c3SDouglas Anderson 	{"PNP0C50", 0 },
117b33752c3SDouglas Anderson 	{ },
118b33752c3SDouglas Anderson };
119b33752c3SDouglas Anderson MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
120b33752c3SDouglas Anderson 
121b33752c3SDouglas Anderson static struct i2c_driver i2c_hid_acpi_driver = {
122b33752c3SDouglas Anderson 	.driver = {
123b33752c3SDouglas Anderson 		.name	= "i2c_hid_acpi",
124b33752c3SDouglas Anderson 		.pm	= &i2c_hid_core_pm,
125b33752c3SDouglas Anderson 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
126b33752c3SDouglas Anderson 		.acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
127b33752c3SDouglas Anderson 	},
128b33752c3SDouglas Anderson 
129*4cecff8fSAndy Shevchenko 	.probe_new	= i2c_hid_acpi_probe,
130b33752c3SDouglas Anderson 	.remove		= i2c_hid_core_remove,
131b33752c3SDouglas Anderson 	.shutdown	= i2c_hid_core_shutdown,
132b33752c3SDouglas Anderson };
133b33752c3SDouglas Anderson 
134b33752c3SDouglas Anderson module_i2c_driver(i2c_hid_acpi_driver);
135b33752c3SDouglas Anderson 
136b33752c3SDouglas Anderson MODULE_DESCRIPTION("HID over I2C ACPI driver");
137b33752c3SDouglas Anderson MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
138b33752c3SDouglas Anderson MODULE_LICENSE("GPL");
139