hid-sony.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * HID driver for some sony "special" devices
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2007 Paul Walmsley
  8. * Copyright (c) 2008 Jiri Slaby
  9. * Copyright (c) 2006-2008 Jiri Kosina
  10. */
  11. /*
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the Free
  14. * Software Foundation; either version 2 of the License, or (at your option)
  15. * any later version.
  16. */
  17. #include <linux/device.h>
  18. #include <linux/hid.h>
  19. #include <linux/module.h>
  20. #include <linux/usb.h>
  21. #include "hid-ids.h"
  22. #define VAIO_RDESC_CONSTANT 0x0001
  23. struct sony_sc {
  24. unsigned long quirks;
  25. };
  26. /* Sony Vaio VGX has wrongly mouse pointer declared as constant */
  27. static void sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  28. unsigned int rsize)
  29. {
  30. struct sony_sc *sc = hid_get_drvdata(hdev);
  31. if ((sc->quirks & VAIO_RDESC_CONSTANT) &&
  32. rsize >= 56 && rdesc[54] == 0x81 && rdesc[55] == 0x07) {
  33. dev_info(&hdev->dev, "Fixing up Sony Vaio VGX report "
  34. "descriptor\n");
  35. rdesc[55] = 0x06;
  36. }
  37. }
  38. /*
  39. * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
  40. * to "operational". Without this, the ps3 controller will not report any
  41. * events.
  42. */
  43. static int sony_set_operational(struct hid_device *hdev)
  44. {
  45. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  46. struct usb_device *dev = interface_to_usbdev(intf);
  47. __u16 ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
  48. int ret;
  49. char *buf = kmalloc(18, GFP_KERNEL);
  50. if (!buf)
  51. return -ENOMEM;
  52. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  53. HID_REQ_GET_REPORT,
  54. USB_DIR_IN | USB_TYPE_CLASS |
  55. USB_RECIP_INTERFACE,
  56. (3 << 8) | 0xf2, ifnum, buf, 17,
  57. USB_CTRL_GET_TIMEOUT);
  58. if (ret < 0)
  59. dev_err(&hdev->dev, "can't set operational mode\n");
  60. kfree(buf);
  61. return ret;
  62. }
  63. static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
  64. {
  65. int ret;
  66. unsigned long quirks = id->driver_data;
  67. struct sony_sc *sc;
  68. sc = kzalloc(sizeof(*sc), GFP_KERNEL);
  69. if (sc == NULL) {
  70. dev_err(&hdev->dev, "can't alloc apple descriptor\n");
  71. return -ENOMEM;
  72. }
  73. sc->quirks = quirks;
  74. hid_set_drvdata(hdev, sc);
  75. ret = hid_parse(hdev);
  76. if (ret) {
  77. dev_err(&hdev->dev, "parse failed\n");
  78. goto err_free;
  79. }
  80. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
  81. HID_CONNECT_HIDDEV_FORCE);
  82. if (ret) {
  83. dev_err(&hdev->dev, "hw start failed\n");
  84. goto err_free;
  85. }
  86. ret = sony_set_operational(hdev);
  87. if (ret)
  88. goto err_stop;
  89. return 0;
  90. err_stop:
  91. hid_hw_stop(hdev);
  92. err_free:
  93. kfree(sc);
  94. return ret;
  95. }
  96. static void sony_remove(struct hid_device *hdev)
  97. {
  98. hid_hw_stop(hdev);
  99. kfree(hid_get_drvdata(hdev));
  100. }
  101. static const struct hid_device_id sony_devices[] = {
  102. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  103. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
  104. .driver_data = VAIO_RDESC_CONSTANT },
  105. { }
  106. };
  107. MODULE_DEVICE_TABLE(hid, sony_devices);
  108. static struct hid_driver sony_driver = {
  109. .name = "sony",
  110. .id_table = sony_devices,
  111. .probe = sony_probe,
  112. .remove = sony_remove,
  113. .report_fixup = sony_report_fixup,
  114. };
  115. static int sony_init(void)
  116. {
  117. return hid_register_driver(&sony_driver);
  118. }
  119. static void sony_exit(void)
  120. {
  121. hid_unregister_driver(&sony_driver);
  122. }
  123. module_init(sony_init);
  124. module_exit(sony_exit);
  125. MODULE_LICENSE("GPL");
  126. HID_COMPAT_LOAD_DRIVER(sony);