hid-lg2ff.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Force feedback support for Logitech RumblePad and Rumblepad 2
  3. *
  4. * Copyright (c) 2008 Anssi Hannula <anssi.hannula@gmail.com>
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/input.h>
  22. #include <linux/slab.h>
  23. #include <linux/hid.h>
  24. #include "hid-lg.h"
  25. struct lg2ff_device {
  26. struct hid_report *report;
  27. };
  28. static int play_effect(struct input_dev *dev, void *data,
  29. struct ff_effect *effect)
  30. {
  31. struct hid_device *hid = input_get_drvdata(dev);
  32. struct lg2ff_device *lg2ff = data;
  33. int weak, strong;
  34. strong = effect->u.rumble.strong_magnitude;
  35. weak = effect->u.rumble.weak_magnitude;
  36. if (weak || strong) {
  37. weak = weak * 0xff / 0xffff;
  38. strong = strong * 0xff / 0xffff;
  39. lg2ff->report->field[0]->value[0] = 0x51;
  40. lg2ff->report->field[0]->value[2] = weak;
  41. lg2ff->report->field[0]->value[4] = strong;
  42. } else {
  43. lg2ff->report->field[0]->value[0] = 0xf3;
  44. lg2ff->report->field[0]->value[2] = 0x00;
  45. lg2ff->report->field[0]->value[4] = 0x00;
  46. }
  47. hid_hw_request(hid, lg2ff->report, HID_REQ_SET_REPORT);
  48. return 0;
  49. }
  50. int lg2ff_init(struct hid_device *hid)
  51. {
  52. struct lg2ff_device *lg2ff;
  53. struct hid_report *report;
  54. struct hid_input *hidinput = list_entry(hid->inputs.next,
  55. struct hid_input, list);
  56. struct input_dev *dev = hidinput->input;
  57. int error;
  58. /* Check that the report looks ok */
  59. report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7);
  60. if (!report)
  61. return -ENODEV;
  62. lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
  63. if (!lg2ff)
  64. return -ENOMEM;
  65. set_bit(FF_RUMBLE, dev->ffbit);
  66. error = input_ff_create_memless(dev, lg2ff, play_effect);
  67. if (error) {
  68. kfree(lg2ff);
  69. return error;
  70. }
  71. lg2ff->report = report;
  72. report->field[0]->value[0] = 0xf3;
  73. report->field[0]->value[1] = 0x00;
  74. report->field[0]->value[2] = 0x00;
  75. report->field[0]->value[3] = 0x00;
  76. report->field[0]->value[4] = 0x00;
  77. report->field[0]->value[5] = 0x00;
  78. report->field[0]->value[6] = 0x00;
  79. hid_hw_request(hid, report, HID_REQ_SET_REPORT);
  80. hid_info(hid, "Force feedback for Logitech variant 2 rumble devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
  81. return 0;
  82. }