Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * HID over I2C ACPI Subclass
0003  *
0004  * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
0005  * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
0006  * Copyright (c) 2012 Red Hat, Inc
0007  *
0008  * This code was forked out of the core code, which was partly based on
0009  * "USB HID support for Linux":
0010  *
0011  *  Copyright (c) 1999 Andreas Gal
0012  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
0013  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
0014  *  Copyright (c) 2007-2008 Oliver Neukum
0015  *  Copyright (c) 2006-2010 Jiri Kosina
0016  *
0017  * This file is subject to the terms and conditions of the GNU General Public
0018  * License.  See the file COPYING in the main directory of this archive for
0019  * more details.
0020  */
0021 
0022 #include <linux/acpi.h>
0023 #include <linux/device.h>
0024 #include <linux/i2c.h>
0025 #include <linux/kernel.h>
0026 #include <linux/module.h>
0027 #include <linux/pm.h>
0028 #include <linux/uuid.h>
0029 
0030 #include "i2c-hid.h"
0031 
0032 struct i2c_hid_acpi {
0033     struct i2chid_ops ops;
0034     struct acpi_device *adev;
0035 };
0036 
0037 static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
0038     /*
0039      * The CHPN0001 ACPI device, which is used to describe the Chipone
0040      * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible.
0041      */
0042     {"CHPN0001", 0 },
0043     { },
0044 };
0045 
0046 /* HID I²C Device: 3cdff6f7-4267-4555-ad05-b30a3d8938de */
0047 static guid_t i2c_hid_guid =
0048     GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
0049           0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
0050 
0051 static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
0052 {
0053     acpi_handle handle = acpi_device_handle(adev);
0054     union acpi_object *obj;
0055     u16 hid_descriptor_address;
0056 
0057     if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
0058         return -ENODEV;
0059 
0060     obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
0061                       ACPI_TYPE_INTEGER);
0062     if (!obj) {
0063         acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
0064         return -ENODEV;
0065     }
0066 
0067     hid_descriptor_address = obj->integer.value;
0068     ACPI_FREE(obj);
0069 
0070     return hid_descriptor_address;
0071 }
0072 
0073 static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
0074 {
0075     struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
0076 
0077     acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
0078 }
0079 
0080 static int i2c_hid_acpi_probe(struct i2c_client *client)
0081 {
0082     struct device *dev = &client->dev;
0083     struct i2c_hid_acpi *ihid_acpi;
0084     struct acpi_device *adev;
0085     u16 hid_descriptor_address;
0086     int ret;
0087 
0088     adev = ACPI_COMPANION(dev);
0089     if (!adev) {
0090         dev_err(&client->dev, "Error could not get ACPI device\n");
0091         return -ENODEV;
0092     }
0093 
0094     ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
0095     if (!ihid_acpi)
0096         return -ENOMEM;
0097 
0098     ihid_acpi->adev = adev;
0099     ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
0100 
0101     ret = i2c_hid_acpi_get_descriptor(adev);
0102     if (ret < 0)
0103         return ret;
0104     hid_descriptor_address = ret;
0105 
0106     acpi_device_fix_up_power(adev);
0107 
0108     if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
0109         device_set_wakeup_capable(dev, true);
0110         device_set_wakeup_enable(dev, false);
0111     }
0112 
0113     return i2c_hid_core_probe(client, &ihid_acpi->ops,
0114                   hid_descriptor_address, 0);
0115 }
0116 
0117 static const struct acpi_device_id i2c_hid_acpi_match[] = {
0118     {"ACPI0C50", 0 },
0119     {"PNP0C50", 0 },
0120     { },
0121 };
0122 MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
0123 
0124 static struct i2c_driver i2c_hid_acpi_driver = {
0125     .driver = {
0126         .name   = "i2c_hid_acpi",
0127         .pm = &i2c_hid_core_pm,
0128         .probe_type = PROBE_PREFER_ASYNCHRONOUS,
0129         .acpi_match_table = i2c_hid_acpi_match,
0130     },
0131 
0132     .probe_new  = i2c_hid_acpi_probe,
0133     .remove     = i2c_hid_core_remove,
0134     .shutdown   = i2c_hid_core_shutdown,
0135 };
0136 
0137 module_i2c_driver(i2c_hid_acpi_driver);
0138 
0139 MODULE_DESCRIPTION("HID over I2C ACPI driver");
0140 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
0141 MODULE_LICENSE("GPL");