i2c-hid-acpi.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * HID over I2C ACPI Subclass
  3. *
  4. * Copyright (c) 2012 Benjamin Tissoires <[email protected]>
  5. * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
  6. * Copyright (c) 2012 Red Hat, Inc
  7. *
  8. * This code was forked out of the core code, which was partly based on
  9. * "USB HID support for Linux":
  10. *
  11. * Copyright (c) 1999 Andreas Gal
  12. * Copyright (c) 2000-2005 Vojtech Pavlik <[email protected]>
  13. * Copyright (c) 2005 Michael Haboustak <[email protected]> for Concept2, Inc
  14. * Copyright (c) 2007-2008 Oliver Neukum
  15. * Copyright (c) 2006-2010 Jiri Kosina
  16. *
  17. * This file is subject to the terms and conditions of the GNU General Public
  18. * License. See the file COPYING in the main directory of this archive for
  19. * more details.
  20. */
  21. #include <linux/acpi.h>
  22. #include <linux/device.h>
  23. #include <linux/i2c.h>
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/pm.h>
  27. #include <linux/uuid.h>
  28. #include "i2c-hid.h"
  29. struct i2c_hid_acpi {
  30. struct i2chid_ops ops;
  31. struct acpi_device *adev;
  32. };
  33. static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
  34. /*
  35. * The CHPN0001 ACPI device, which is used to describe the Chipone
  36. * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible.
  37. */
  38. {"CHPN0001", 0 },
  39. { },
  40. };
  41. /* HID I²C Device: 3cdff6f7-4267-4555-ad05-b30a3d8938de */
  42. static guid_t i2c_hid_guid =
  43. GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
  44. 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
  45. static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
  46. {
  47. acpi_handle handle = acpi_device_handle(adev);
  48. union acpi_object *obj;
  49. u16 hid_descriptor_address;
  50. if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
  51. return -ENODEV;
  52. obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
  53. ACPI_TYPE_INTEGER);
  54. if (!obj) {
  55. acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
  56. return -ENODEV;
  57. }
  58. hid_descriptor_address = obj->integer.value;
  59. ACPI_FREE(obj);
  60. return hid_descriptor_address;
  61. }
  62. static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
  63. {
  64. struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
  65. acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
  66. }
  67. static int i2c_hid_acpi_probe(struct i2c_client *client)
  68. {
  69. struct device *dev = &client->dev;
  70. struct i2c_hid_acpi *ihid_acpi;
  71. struct acpi_device *adev;
  72. u16 hid_descriptor_address;
  73. int ret;
  74. adev = ACPI_COMPANION(dev);
  75. if (!adev) {
  76. dev_err(&client->dev, "Error could not get ACPI device\n");
  77. return -ENODEV;
  78. }
  79. ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
  80. if (!ihid_acpi)
  81. return -ENOMEM;
  82. ihid_acpi->adev = adev;
  83. ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
  84. ret = i2c_hid_acpi_get_descriptor(adev);
  85. if (ret < 0)
  86. return ret;
  87. hid_descriptor_address = ret;
  88. acpi_device_fix_up_power(adev);
  89. if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
  90. device_set_wakeup_capable(dev, true);
  91. device_set_wakeup_enable(dev, false);
  92. }
  93. return i2c_hid_core_probe(client, &ihid_acpi->ops,
  94. hid_descriptor_address, 0);
  95. }
  96. static const struct acpi_device_id i2c_hid_acpi_match[] = {
  97. {"ACPI0C50", 0 },
  98. {"PNP0C50", 0 },
  99. { },
  100. };
  101. MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
  102. static struct i2c_driver i2c_hid_acpi_driver = {
  103. .driver = {
  104. .name = "i2c_hid_acpi",
  105. .pm = &i2c_hid_core_pm,
  106. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  107. .acpi_match_table = i2c_hid_acpi_match,
  108. },
  109. .probe_new = i2c_hid_acpi_probe,
  110. .remove = i2c_hid_core_remove,
  111. .shutdown = i2c_hid_core_shutdown,
  112. };
  113. module_i2c_driver(i2c_hid_acpi_driver);
  114. MODULE_DESCRIPTION("HID over I2C ACPI driver");
  115. MODULE_AUTHOR("Benjamin Tissoires <[email protected]>");
  116. MODULE_LICENSE("GPL");