Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/drivers/hid/hid-roccat-common.c
15109 views
1
/*
2
* Roccat common functions for device specific drivers
3
*
4
* Copyright (c) 2011 Stefan Achatz <[email protected]>
5
*/
6
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.
12
*/
13
14
#include <linux/slab.h>
15
#include "hid-roccat-common.h"
16
17
int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
18
void *data, uint size)
19
{
20
char *buf;
21
int len;
22
23
buf = kmalloc(size, GFP_KERNEL);
24
if (buf == NULL)
25
return -ENOMEM;
26
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);
31
32
memcpy(data, buf, size);
33
kfree(buf);
34
return ((len < 0) ? len : ((len != size) ? -EIO : 0));
35
}
36
EXPORT_SYMBOL_GPL(roccat_common_receive);
37
38
int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
39
void const *data, uint size)
40
{
41
char *buf;
42
int len;
43
44
buf = kmalloc(size, GFP_KERNEL);
45
if (buf == NULL)
46
return -ENOMEM;
47
48
memcpy(buf, data, size);
49
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);
54
55
kfree(buf);
56
return ((len < 0) ? len : ((len != size) ? -EIO : 0));
57
}
58
EXPORT_SYMBOL_GPL(roccat_common_send);
59
60
MODULE_AUTHOR("Stefan Achatz");
61
MODULE_DESCRIPTION("USB Roccat common driver");
62
MODULE_LICENSE("GPL v2");
63
64