hid-roccat-common.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Roccat common functions for device specific drivers
  3. *
  4. * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include <linux/slab.h>
  13. #include "hid-roccat-common.h"
  14. int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
  15. void *data, uint size)
  16. {
  17. char *buf;
  18. int len;
  19. buf = kmalloc(size, GFP_KERNEL);
  20. if (buf == NULL)
  21. return -ENOMEM;
  22. len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
  23. USB_REQ_CLEAR_FEATURE,
  24. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
  25. usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
  26. memcpy(data, buf, size);
  27. kfree(buf);
  28. return ((len < 0) ? len : ((len != size) ? -EIO : 0));
  29. }
  30. EXPORT_SYMBOL_GPL(roccat_common_receive);
  31. int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
  32. void const *data, uint size)
  33. {
  34. char *buf;
  35. int len;
  36. buf = kmalloc(size, GFP_KERNEL);
  37. if (buf == NULL)
  38. return -ENOMEM;
  39. memcpy(buf, data, size);
  40. len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
  41. USB_REQ_SET_CONFIGURATION,
  42. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
  43. usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
  44. kfree(buf);
  45. return ((len < 0) ? len : ((len != size) ? -EIO : 0));
  46. }
  47. EXPORT_SYMBOL_GPL(roccat_common_send);
  48. MODULE_AUTHOR("Stefan Achatz");
  49. MODULE_DESCRIPTION("USB Roccat common driver");
  50. MODULE_LICENSE("GPL v2");