USB: option: add Nexpring NP10T terminal id
[linux/fpc-iii.git] / drivers / hid / hid-roccat-common.c
blob13b1eb0c8c65f932993db85c3885e71d9a2074aa
1 /*
2 * Roccat common functions for device specific drivers
4 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
5 */
7 /*
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
14 #include <linux/slab.h>
15 #include "hid-roccat-common.h"
17 int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
18 void *data, uint size)
20 char *buf;
21 int len;
23 buf = kmalloc(size, GFP_KERNEL);
24 if (buf == NULL)
25 return -ENOMEM;
27 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
28 USB_REQ_CLEAR_FEATURE,
29 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
30 usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
32 memcpy(data, buf, size);
33 kfree(buf);
34 return ((len < 0) ? len : ((len != size) ? -EIO : 0));
36 EXPORT_SYMBOL_GPL(roccat_common_receive);
38 int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
39 void const *data, uint size)
41 char *buf;
42 int len;
44 buf = kmalloc(size, GFP_KERNEL);
45 if (buf == NULL)
46 return -ENOMEM;
48 memcpy(buf, data, size);
50 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
51 USB_REQ_SET_CONFIGURATION,
52 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
53 usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
55 kfree(buf);
56 return ((len < 0) ? len : ((len != size) ? -EIO : 0));
58 EXPORT_SYMBOL_GPL(roccat_common_send);
60 MODULE_AUTHOR("Stefan Achatz");
61 MODULE_DESCRIPTION("USB Roccat common driver");
62 MODULE_LICENSE("GPL v2");