Blame view

drivers/hid/hid-roccat-common.c 1.76 KB
5772f6361   Stefan Achatz   HID: roccat: Intr...
1
2
3
4
5
6
7
8
9
10
11
12
  /*
   * Roccat common functions for device specific drivers
   *
   * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
   */
  
  /*
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the Free
   * Software Foundation; either version 2 of the License, or (at your option)
   * any later version.
   */
1edd5b42a   Stefan Achatz   HID: roccat: corr...
13
  #include <linux/hid.h>
5772f6361   Stefan Achatz   HID: roccat: Intr...
14
  #include <linux/slab.h>
8f86a2c3c   Paul Gortmaker   hid: Add module.h...
15
  #include <linux/module.h>
5772f6361   Stefan Achatz   HID: roccat: Intr...
16
  #include "hid-roccat-common.h"
1edd5b42a   Stefan Achatz   HID: roccat: corr...
17
18
19
20
21
22
  static inline uint16_t roccat_common_feature_report(uint8_t report_id)
  {
  	return 0x300 | report_id;
  }
  
  int roccat_common_receive(struct usb_device *usb_dev, uint report_id,
5772f6361   Stefan Achatz   HID: roccat: Intr...
23
24
25
26
27
28
29
30
31
32
  		void *data, uint size)
  {
  	char *buf;
  	int len;
  
  	buf = kmalloc(size, GFP_KERNEL);
  	if (buf == NULL)
  		return -ENOMEM;
  
  	len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
1edd5b42a   Stefan Achatz   HID: roccat: corr...
33
  			HID_REQ_GET_REPORT,
5772f6361   Stefan Achatz   HID: roccat: Intr...
34
  			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
1edd5b42a   Stefan Achatz   HID: roccat: corr...
35
36
  			roccat_common_feature_report(report_id),
  			0, buf, size, USB_CTRL_SET_TIMEOUT);
5772f6361   Stefan Achatz   HID: roccat: Intr...
37
38
39
40
41
42
  
  	memcpy(data, buf, size);
  	kfree(buf);
  	return ((len < 0) ? len : ((len != size) ? -EIO : 0));
  }
  EXPORT_SYMBOL_GPL(roccat_common_receive);
1edd5b42a   Stefan Achatz   HID: roccat: corr...
43
  int roccat_common_send(struct usb_device *usb_dev, uint report_id,
5772f6361   Stefan Achatz   HID: roccat: Intr...
44
45
46
47
  		void const *data, uint size)
  {
  	char *buf;
  	int len;
4c33a885a   Thomas Meyer   HID: roccat: Use ...
48
  	buf = kmemdup(data, size, GFP_KERNEL);
5772f6361   Stefan Achatz   HID: roccat: Intr...
49
50
  	if (buf == NULL)
  		return -ENOMEM;
5772f6361   Stefan Achatz   HID: roccat: Intr...
51
  	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
1edd5b42a   Stefan Achatz   HID: roccat: corr...
52
  			HID_REQ_SET_REPORT,
5772f6361   Stefan Achatz   HID: roccat: Intr...
53
  			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
1edd5b42a   Stefan Achatz   HID: roccat: corr...
54
55
  			roccat_common_feature_report(report_id),
  			0, buf, size, USB_CTRL_SET_TIMEOUT);
5772f6361   Stefan Achatz   HID: roccat: Intr...
56
57
58
59
60
61
62
63
64
  
  	kfree(buf);
  	return ((len < 0) ? len : ((len != size) ? -EIO : 0));
  }
  EXPORT_SYMBOL_GPL(roccat_common_send);
  
  MODULE_AUTHOR("Stefan Achatz");
  MODULE_DESCRIPTION("USB Roccat common driver");
  MODULE_LICENSE("GPL v2");