blob: e2966f87c860b49e46a7148e51e35a76ca15685c [file] [log] [blame]
Fabien Chouteau71adf112010-04-08 09:31:15 +02001/*
2 * f_hid.c -- USB HID function driver
3 *
4 * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
Fabien Chouteau71adf112010-04-08 09:31:15 +020010 */
11
12#include <linux/kernel.h>
Fabien Chouteau71adf112010-04-08 09:31:15 +020013#include <linux/module.h>
14#include <linux/hid.h>
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +010015#include <linux/idr.h>
Fabien Chouteau71adf112010-04-08 09:31:15 +020016#include <linux/cdev.h>
17#include <linux/mutex.h>
18#include <linux/poll.h>
Fabien Chouteau71adf112010-04-08 09:31:15 +020019#include <linux/uaccess.h>
20#include <linux/wait.h>
Sebastian Andrzej Siewior721e2e92012-09-06 20:11:27 +020021#include <linux/sched.h>
Fabien Chouteau71adf112010-04-08 09:31:15 +020022#include <linux/usb/g_hid.h>
23
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010024#include "u_f.h"
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +010025#include "u_hid.h"
26
27#define HIDG_MINORS 4
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +010028
Fabien Chouteau71adf112010-04-08 09:31:15 +020029static int major, minors;
30static struct class *hidg_class;
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +010031static DEFINE_IDA(hidg_ida);
32static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */
Fabien Chouteau71adf112010-04-08 09:31:15 +020033
34/*-------------------------------------------------------------------------*/
35/* HID gadget struct */
36
Daniel Mack99c5150052012-06-13 12:54:45 +020037struct f_hidg_req_list {
38 struct usb_request *req;
39 unsigned int pos;
40 struct list_head list;
41};
42
Fabien Chouteau71adf112010-04-08 09:31:15 +020043struct f_hidg {
44 /* configuration */
45 unsigned char bInterfaceSubClass;
46 unsigned char bInterfaceProtocol;
47 unsigned short report_desc_length;
48 char *report_desc;
49 unsigned short report_length;
50
51 /* recv report */
Daniel Mack99c5150052012-06-13 12:54:45 +020052 struct list_head completed_out_req;
Fabien Chouteau71adf112010-04-08 09:31:15 +020053 spinlock_t spinlock;
54 wait_queue_head_t read_queue;
Daniel Mack99c5150052012-06-13 12:54:45 +020055 unsigned int qlen;
Fabien Chouteau71adf112010-04-08 09:31:15 +020056
57 /* send report */
58 struct mutex lock;
59 bool write_pending;
60 wait_queue_head_t write_queue;
61 struct usb_request *req;
62
63 int minor;
64 struct cdev cdev;
65 struct usb_function func;
Daniel Mack99c5150052012-06-13 12:54:45 +020066
Fabien Chouteau71adf112010-04-08 09:31:15 +020067 struct usb_ep *in_ep;
Daniel Mack99c5150052012-06-13 12:54:45 +020068 struct usb_ep *out_ep;
Fabien Chouteau71adf112010-04-08 09:31:15 +020069};
70
71static inline struct f_hidg *func_to_hidg(struct usb_function *f)
72{
73 return container_of(f, struct f_hidg, func);
74}
75
76/*-------------------------------------------------------------------------*/
77/* Static descriptors */
78
79static struct usb_interface_descriptor hidg_interface_desc = {
80 .bLength = sizeof hidg_interface_desc,
81 .bDescriptorType = USB_DT_INTERFACE,
82 /* .bInterfaceNumber = DYNAMIC */
83 .bAlternateSetting = 0,
Daniel Mack99c5150052012-06-13 12:54:45 +020084 .bNumEndpoints = 2,
Fabien Chouteau71adf112010-04-08 09:31:15 +020085 .bInterfaceClass = USB_CLASS_HID,
86 /* .bInterfaceSubClass = DYNAMIC */
87 /* .bInterfaceProtocol = DYNAMIC */
88 /* .iInterface = DYNAMIC */
89};
90
91static struct hid_descriptor hidg_desc = {
92 .bLength = sizeof hidg_desc,
93 .bDescriptorType = HID_DT_HID,
94 .bcdHID = 0x0101,
95 .bCountryCode = 0x00,
96 .bNumDescriptors = 0x1,
97 /*.desc[0].bDescriptorType = DYNAMIC */
98 /*.desc[0].wDescriptorLenght = DYNAMIC */
99};
100
101/* High-Speed Support */
102
103static struct usb_endpoint_descriptor hidg_hs_in_ep_desc = {
104 .bLength = USB_DT_ENDPOINT_SIZE,
105 .bDescriptorType = USB_DT_ENDPOINT,
106 .bEndpointAddress = USB_DIR_IN,
107 .bmAttributes = USB_ENDPOINT_XFER_INT,
108 /*.wMaxPacketSize = DYNAMIC */
109 .bInterval = 4, /* FIXME: Add this field in the
110 * HID gadget configuration?
111 * (struct hidg_func_descriptor)
112 */
113};
114
Daniel Mack99c5150052012-06-13 12:54:45 +0200115static struct usb_endpoint_descriptor hidg_hs_out_ep_desc = {
116 .bLength = USB_DT_ENDPOINT_SIZE,
117 .bDescriptorType = USB_DT_ENDPOINT,
118 .bEndpointAddress = USB_DIR_OUT,
119 .bmAttributes = USB_ENDPOINT_XFER_INT,
120 /*.wMaxPacketSize = DYNAMIC */
121 .bInterval = 4, /* FIXME: Add this field in the
122 * HID gadget configuration?
123 * (struct hidg_func_descriptor)
124 */
125};
126
Fabien Chouteau71adf112010-04-08 09:31:15 +0200127static struct usb_descriptor_header *hidg_hs_descriptors[] = {
128 (struct usb_descriptor_header *)&hidg_interface_desc,
129 (struct usb_descriptor_header *)&hidg_desc,
130 (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
Daniel Mack99c5150052012-06-13 12:54:45 +0200131 (struct usb_descriptor_header *)&hidg_hs_out_ep_desc,
Fabien Chouteau71adf112010-04-08 09:31:15 +0200132 NULL,
133};
134
135/* Full-Speed Support */
136
137static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
138 .bLength = USB_DT_ENDPOINT_SIZE,
139 .bDescriptorType = USB_DT_ENDPOINT,
140 .bEndpointAddress = USB_DIR_IN,
141 .bmAttributes = USB_ENDPOINT_XFER_INT,
142 /*.wMaxPacketSize = DYNAMIC */
143 .bInterval = 10, /* FIXME: Add this field in the
144 * HID gadget configuration?
145 * (struct hidg_func_descriptor)
146 */
147};
148
Daniel Mack99c5150052012-06-13 12:54:45 +0200149static struct usb_endpoint_descriptor hidg_fs_out_ep_desc = {
150 .bLength = USB_DT_ENDPOINT_SIZE,
151 .bDescriptorType = USB_DT_ENDPOINT,
152 .bEndpointAddress = USB_DIR_OUT,
153 .bmAttributes = USB_ENDPOINT_XFER_INT,
154 /*.wMaxPacketSize = DYNAMIC */
155 .bInterval = 10, /* FIXME: Add this field in the
156 * HID gadget configuration?
157 * (struct hidg_func_descriptor)
158 */
159};
160
Fabien Chouteau71adf112010-04-08 09:31:15 +0200161static struct usb_descriptor_header *hidg_fs_descriptors[] = {
162 (struct usb_descriptor_header *)&hidg_interface_desc,
163 (struct usb_descriptor_header *)&hidg_desc,
164 (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
Daniel Mack99c5150052012-06-13 12:54:45 +0200165 (struct usb_descriptor_header *)&hidg_fs_out_ep_desc,
Fabien Chouteau71adf112010-04-08 09:31:15 +0200166 NULL,
167};
168
169/*-------------------------------------------------------------------------*/
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100170/* Strings */
171
172#define CT_FUNC_HID_IDX 0
173
174static struct usb_string ct_func_string_defs[] = {
175 [CT_FUNC_HID_IDX].s = "HID Interface",
176 {}, /* end of list */
177};
178
179static struct usb_gadget_strings ct_func_string_table = {
180 .language = 0x0409, /* en-US */
181 .strings = ct_func_string_defs,
182};
183
184static struct usb_gadget_strings *ct_func_strings[] = {
185 &ct_func_string_table,
186 NULL,
187};
188
189/*-------------------------------------------------------------------------*/
Fabien Chouteau71adf112010-04-08 09:31:15 +0200190/* Char Device */
191
192static ssize_t f_hidg_read(struct file *file, char __user *buffer,
193 size_t count, loff_t *ptr)
194{
Daniel Mack99c5150052012-06-13 12:54:45 +0200195 struct f_hidg *hidg = file->private_data;
196 struct f_hidg_req_list *list;
197 struct usb_request *req;
198 unsigned long flags;
199 int ret;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200200
201 if (!count)
202 return 0;
203
204 if (!access_ok(VERIFY_WRITE, buffer, count))
205 return -EFAULT;
206
207 spin_lock_irqsave(&hidg->spinlock, flags);
208
Daniel Mack99c5150052012-06-13 12:54:45 +0200209#define READ_COND (!list_empty(&hidg->completed_out_req))
Fabien Chouteau71adf112010-04-08 09:31:15 +0200210
Daniel Mack99c5150052012-06-13 12:54:45 +0200211 /* wait for at least one buffer to complete */
Fabien Chouteau71adf112010-04-08 09:31:15 +0200212 while (!READ_COND) {
213 spin_unlock_irqrestore(&hidg->spinlock, flags);
214 if (file->f_flags & O_NONBLOCK)
215 return -EAGAIN;
216
217 if (wait_event_interruptible(hidg->read_queue, READ_COND))
218 return -ERESTARTSYS;
219
220 spin_lock_irqsave(&hidg->spinlock, flags);
221 }
222
Daniel Mack99c5150052012-06-13 12:54:45 +0200223 /* pick the first one */
224 list = list_first_entry(&hidg->completed_out_req,
225 struct f_hidg_req_list, list);
226 req = list->req;
227 count = min_t(unsigned int, count, req->actual - list->pos);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200228 spin_unlock_irqrestore(&hidg->spinlock, flags);
229
Daniel Mack99c5150052012-06-13 12:54:45 +0200230 /* copy to user outside spinlock */
231 count -= copy_to_user(buffer, req->buf + list->pos, count);
232 list->pos += count;
233
234 /*
235 * if this request is completely handled and transfered to
236 * userspace, remove its entry from the list and requeue it
237 * again. Otherwise, we will revisit it again upon the next
238 * call, taking into account its current read position.
239 */
240 if (list->pos == req->actual) {
241 spin_lock_irqsave(&hidg->spinlock, flags);
242 list_del(&list->list);
243 kfree(list);
244 spin_unlock_irqrestore(&hidg->spinlock, flags);
245
246 req->length = hidg->report_length;
247 ret = usb_ep_queue(hidg->out_ep, req, GFP_KERNEL);
248 if (ret < 0)
249 return ret;
250 }
Fabien Chouteau71adf112010-04-08 09:31:15 +0200251
252 return count;
253}
254
255static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
256{
257 struct f_hidg *hidg = (struct f_hidg *)ep->driver_data;
258
259 if (req->status != 0) {
260 ERROR(hidg->func.config->cdev,
261 "End Point Request ERROR: %d\n", req->status);
262 }
263
264 hidg->write_pending = 0;
265 wake_up(&hidg->write_queue);
266}
267
268static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
269 size_t count, loff_t *offp)
270{
Joe Perchesfd63b102010-07-12 13:50:11 -0700271 struct f_hidg *hidg = file->private_data;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200272 ssize_t status = -ENOMEM;
273
274 if (!access_ok(VERIFY_READ, buffer, count))
275 return -EFAULT;
276
277 mutex_lock(&hidg->lock);
278
279#define WRITE_COND (!hidg->write_pending)
280
281 /* write queue */
282 while (!WRITE_COND) {
283 mutex_unlock(&hidg->lock);
284 if (file->f_flags & O_NONBLOCK)
285 return -EAGAIN;
286
287 if (wait_event_interruptible_exclusive(
288 hidg->write_queue, WRITE_COND))
289 return -ERESTARTSYS;
290
291 mutex_lock(&hidg->lock);
292 }
293
294 count = min_t(unsigned, count, hidg->report_length);
295 status = copy_from_user(hidg->req->buf, buffer, count);
296
297 if (status != 0) {
298 ERROR(hidg->func.config->cdev,
299 "copy_from_user error\n");
300 mutex_unlock(&hidg->lock);
301 return -EINVAL;
302 }
303
304 hidg->req->status = 0;
305 hidg->req->zero = 0;
306 hidg->req->length = count;
307 hidg->req->complete = f_hidg_req_complete;
308 hidg->req->context = hidg;
309 hidg->write_pending = 1;
310
311 status = usb_ep_queue(hidg->in_ep, hidg->req, GFP_ATOMIC);
312 if (status < 0) {
313 ERROR(hidg->func.config->cdev,
314 "usb_ep_queue error on int endpoint %zd\n", status);
315 hidg->write_pending = 0;
316 wake_up(&hidg->write_queue);
317 } else {
318 status = count;
319 }
320
321 mutex_unlock(&hidg->lock);
322
323 return status;
324}
325
326static unsigned int f_hidg_poll(struct file *file, poll_table *wait)
327{
Joe Perchesfd63b102010-07-12 13:50:11 -0700328 struct f_hidg *hidg = file->private_data;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200329 unsigned int ret = 0;
330
331 poll_wait(file, &hidg->read_queue, wait);
332 poll_wait(file, &hidg->write_queue, wait);
333
334 if (WRITE_COND)
335 ret |= POLLOUT | POLLWRNORM;
336
337 if (READ_COND)
338 ret |= POLLIN | POLLRDNORM;
339
340 return ret;
341}
342
343#undef WRITE_COND
344#undef READ_COND
345
346static int f_hidg_release(struct inode *inode, struct file *fd)
347{
348 fd->private_data = NULL;
349 return 0;
350}
351
352static int f_hidg_open(struct inode *inode, struct file *fd)
353{
354 struct f_hidg *hidg =
355 container_of(inode->i_cdev, struct f_hidg, cdev);
356
357 fd->private_data = hidg;
358
359 return 0;
360}
361
362/*-------------------------------------------------------------------------*/
363/* usb_function */
364
Andrzej Pietrasiewicz1efd54e2013-11-07 08:41:26 +0100365static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep,
366 unsigned length)
Daniel Mack99c5150052012-06-13 12:54:45 +0200367{
Felipe F. Tonelloaadbe812016-08-23 18:24:49 +0100368 return alloc_ep_req(ep, length);
Daniel Mack99c5150052012-06-13 12:54:45 +0200369}
370
Fabien Chouteau71adf112010-04-08 09:31:15 +0200371static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
372{
Daniel Mack99c5150052012-06-13 12:54:45 +0200373 struct f_hidg *hidg = (struct f_hidg *) req->context;
374 struct f_hidg_req_list *req_list;
375 unsigned long flags;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200376
Daniel Mack99c5150052012-06-13 12:54:45 +0200377 req_list = kzalloc(sizeof(*req_list), GFP_ATOMIC);
378 if (!req_list)
Fabien Chouteau71adf112010-04-08 09:31:15 +0200379 return;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200380
Daniel Mack99c5150052012-06-13 12:54:45 +0200381 req_list->req = req;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200382
Daniel Mack99c5150052012-06-13 12:54:45 +0200383 spin_lock_irqsave(&hidg->spinlock, flags);
384 list_add_tail(&req_list->list, &hidg->completed_out_req);
385 spin_unlock_irqrestore(&hidg->spinlock, flags);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200386
387 wake_up(&hidg->read_queue);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200388}
389
390static int hidg_setup(struct usb_function *f,
391 const struct usb_ctrlrequest *ctrl)
392{
393 struct f_hidg *hidg = func_to_hidg(f);
394 struct usb_composite_dev *cdev = f->config->cdev;
395 struct usb_request *req = cdev->req;
396 int status = 0;
397 __u16 value, length;
398
399 value = __le16_to_cpu(ctrl->wValue);
400 length = __le16_to_cpu(ctrl->wLength);
401
Julia Lawallc9b3bde2014-12-07 20:21:00 +0100402 VDBG(cdev,
403 "%s crtl_request : bRequestType:0x%x bRequest:0x%x Value:0x%x\n",
404 __func__, ctrl->bRequestType, ctrl->bRequest, value);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200405
406 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
407 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
408 | HID_REQ_GET_REPORT):
409 VDBG(cdev, "get_report\n");
410
411 /* send an empty report */
412 length = min_t(unsigned, length, hidg->report_length);
413 memset(req->buf, 0x0, length);
414
415 goto respond;
416 break;
417
418 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
419 | HID_REQ_GET_PROTOCOL):
420 VDBG(cdev, "get_protocol\n");
421 goto stall;
422 break;
423
424 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
425 | HID_REQ_SET_REPORT):
Masanari Iida6774def2014-11-05 22:26:48 +0900426 VDBG(cdev, "set_report | wLength=%d\n", ctrl->wLength);
Daniel Mack99c5150052012-06-13 12:54:45 +0200427 goto stall;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200428 break;
429
430 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
431 | HID_REQ_SET_PROTOCOL):
432 VDBG(cdev, "set_protocol\n");
433 goto stall;
434 break;
435
436 case ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8
437 | USB_REQ_GET_DESCRIPTOR):
438 switch (value >> 8) {
Sebastian Bauerc240d782011-07-21 15:40:07 +0200439 case HID_DT_HID:
Krzysztof Opasiakf286d482015-03-27 09:35:44 +0100440 {
441 struct hid_descriptor hidg_desc_copy = hidg_desc;
442
Sebastian Bauerc240d782011-07-21 15:40:07 +0200443 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n");
Krzysztof Opasiakf286d482015-03-27 09:35:44 +0100444 hidg_desc_copy.desc[0].bDescriptorType = HID_DT_REPORT;
445 hidg_desc_copy.desc[0].wDescriptorLength =
446 cpu_to_le16(hidg->report_desc_length);
447
Sebastian Bauerc240d782011-07-21 15:40:07 +0200448 length = min_t(unsigned short, length,
Krzysztof Opasiakf286d482015-03-27 09:35:44 +0100449 hidg_desc_copy.bLength);
450 memcpy(req->buf, &hidg_desc_copy, length);
Sebastian Bauerc240d782011-07-21 15:40:07 +0200451 goto respond;
452 break;
Krzysztof Opasiakf286d482015-03-27 09:35:44 +0100453 }
Fabien Chouteau71adf112010-04-08 09:31:15 +0200454 case HID_DT_REPORT:
455 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n");
456 length = min_t(unsigned short, length,
457 hidg->report_desc_length);
458 memcpy(req->buf, hidg->report_desc, length);
459 goto respond;
460 break;
461
462 default:
Masanari Iida1c1301d2012-04-19 00:04:46 +0900463 VDBG(cdev, "Unknown descriptor request 0x%x\n",
Fabien Chouteau71adf112010-04-08 09:31:15 +0200464 value >> 8);
465 goto stall;
466 break;
467 }
468 break;
469
470 default:
471 VDBG(cdev, "Unknown request 0x%x\n",
472 ctrl->bRequest);
473 goto stall;
474 break;
475 }
476
477stall:
478 return -EOPNOTSUPP;
479
480respond:
481 req->zero = 0;
482 req->length = length;
483 status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
484 if (status < 0)
485 ERROR(cdev, "usb_ep_queue error on ep0 %d\n", value);
486 return status;
487}
488
489static void hidg_disable(struct usb_function *f)
490{
491 struct f_hidg *hidg = func_to_hidg(f);
Daniel Mack99c5150052012-06-13 12:54:45 +0200492 struct f_hidg_req_list *list, *next;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200493
494 usb_ep_disable(hidg->in_ep);
Daniel Mack99c5150052012-06-13 12:54:45 +0200495 usb_ep_disable(hidg->out_ep);
Daniel Mack99c5150052012-06-13 12:54:45 +0200496
497 list_for_each_entry_safe(list, next, &hidg->completed_out_req, list) {
498 list_del(&list->list);
499 kfree(list);
500 }
Fabien Chouteau71adf112010-04-08 09:31:15 +0200501}
502
503static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
504{
505 struct usb_composite_dev *cdev = f->config->cdev;
506 struct f_hidg *hidg = func_to_hidg(f);
Daniel Mack99c5150052012-06-13 12:54:45 +0200507 int i, status = 0;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200508
509 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
510
511 if (hidg->in_ep != NULL) {
512 /* restart endpoint */
Robert Baldyga2516a682015-09-16 12:10:46 +0200513 usb_ep_disable(hidg->in_ep);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200514
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300515 status = config_ep_by_speed(f->config->cdev->gadget, f,
516 hidg->in_ep);
517 if (status) {
518 ERROR(cdev, "config_ep_by_speed FAILED!\n");
519 goto fail;
520 }
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300521 status = usb_ep_enable(hidg->in_ep);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200522 if (status < 0) {
Daniel Mack99c5150052012-06-13 12:54:45 +0200523 ERROR(cdev, "Enable IN endpoint FAILED!\n");
Fabien Chouteau71adf112010-04-08 09:31:15 +0200524 goto fail;
525 }
526 hidg->in_ep->driver_data = hidg;
527 }
Daniel Mack99c5150052012-06-13 12:54:45 +0200528
529
530 if (hidg->out_ep != NULL) {
531 /* restart endpoint */
Robert Baldyga2516a682015-09-16 12:10:46 +0200532 usb_ep_disable(hidg->out_ep);
Daniel Mack99c5150052012-06-13 12:54:45 +0200533
534 status = config_ep_by_speed(f->config->cdev->gadget, f,
535 hidg->out_ep);
536 if (status) {
537 ERROR(cdev, "config_ep_by_speed FAILED!\n");
538 goto fail;
539 }
540 status = usb_ep_enable(hidg->out_ep);
541 if (status < 0) {
542 ERROR(cdev, "Enable IN endpoint FAILED!\n");
543 goto fail;
544 }
545 hidg->out_ep->driver_data = hidg;
546
547 /*
548 * allocate a bunch of read buffers and queue them all at once.
549 */
550 for (i = 0; i < hidg->qlen && status == 0; i++) {
551 struct usb_request *req =
552 hidg_alloc_ep_req(hidg->out_ep,
553 hidg->report_length);
554 if (req) {
555 req->complete = hidg_set_report_complete;
556 req->context = hidg;
557 status = usb_ep_queue(hidg->out_ep, req,
558 GFP_ATOMIC);
559 if (status)
560 ERROR(cdev, "%s queue req --> %d\n",
561 hidg->out_ep->name, status);
562 } else {
563 usb_ep_disable(hidg->out_ep);
Daniel Mack99c5150052012-06-13 12:54:45 +0200564 status = -ENOMEM;
565 goto fail;
566 }
567 }
568 }
569
Fabien Chouteau71adf112010-04-08 09:31:15 +0200570fail:
571 return status;
572}
573
Lad, Prabhakar7a3cc462015-02-04 17:49:36 +0000574static const struct file_operations f_hidg_fops = {
Fabien Chouteau71adf112010-04-08 09:31:15 +0200575 .owner = THIS_MODULE,
576 .open = f_hidg_open,
577 .release = f_hidg_release,
578 .write = f_hidg_write,
579 .read = f_hidg_read,
580 .poll = f_hidg_poll,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200581 .llseek = noop_llseek,
Fabien Chouteau71adf112010-04-08 09:31:15 +0200582};
583
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100584static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
Fabien Chouteau71adf112010-04-08 09:31:15 +0200585{
586 struct usb_ep *ep;
587 struct f_hidg *hidg = func_to_hidg(f);
Andrzej Pietrasiewicz5ca8d3ec2014-11-06 11:12:02 +0100588 struct usb_string *us;
Andrzej Pietrasiewicz63406082014-11-06 11:11:57 +0100589 struct device *device;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200590 int status;
591 dev_t dev;
592
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100593 /* maybe allocate device-global string IDs, and patch descriptors */
Andrzej Pietrasiewicz5ca8d3ec2014-11-06 11:12:02 +0100594 us = usb_gstrings_attach(c->cdev, ct_func_strings,
595 ARRAY_SIZE(ct_func_string_defs));
596 if (IS_ERR(us))
597 return PTR_ERR(us);
598 hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100599
Fabien Chouteau71adf112010-04-08 09:31:15 +0200600 /* allocate instance-specific interface IDs, and patch descriptors */
601 status = usb_interface_id(c, f);
602 if (status < 0)
603 goto fail;
604 hidg_interface_desc.bInterfaceNumber = status;
605
Fabien Chouteau71adf112010-04-08 09:31:15 +0200606 /* allocate instance-specific endpoints */
607 status = -ENODEV;
608 ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_in_ep_desc);
609 if (!ep)
610 goto fail;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200611 hidg->in_ep = ep;
612
Daniel Mack99c5150052012-06-13 12:54:45 +0200613 ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_out_ep_desc);
614 if (!ep)
615 goto fail;
Daniel Mack99c5150052012-06-13 12:54:45 +0200616 hidg->out_ep = ep;
617
Fabien Chouteau71adf112010-04-08 09:31:15 +0200618 /* preallocate request and buffer */
619 status = -ENOMEM;
Felipe F. Tonelloba1582f2016-08-23 18:24:51 +0100620 hidg->req = alloc_ep_req(hidg->in_ep, hidg->report_length);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200621 if (!hidg->req)
622 goto fail;
623
Fabien Chouteau71adf112010-04-08 09:31:15 +0200624 /* set descriptor dynamic values */
625 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
626 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
627 hidg_hs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
628 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
Daniel Mack99c5150052012-06-13 12:54:45 +0200629 hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
630 hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
Krzysztof Opasiakf286d482015-03-27 09:35:44 +0100631 /*
632 * We can use hidg_desc struct here but we should not relay
633 * that its content won't change after returning from this function.
634 */
Fabien Chouteau71adf112010-04-08 09:31:15 +0200635 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT;
636 hidg_desc.desc[0].wDescriptorLength =
637 cpu_to_le16(hidg->report_desc_length);
638
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200639 hidg_hs_in_ep_desc.bEndpointAddress =
640 hidg_fs_in_ep_desc.bEndpointAddress;
641 hidg_hs_out_ep_desc.bEndpointAddress =
642 hidg_fs_out_ep_desc.bEndpointAddress;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200643
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200644 status = usb_assign_descriptors(f, hidg_fs_descriptors,
John Youneaef50c2016-02-05 17:06:07 -0800645 hidg_hs_descriptors, NULL, NULL);
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200646 if (status)
647 goto fail;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200648
649 mutex_init(&hidg->lock);
650 spin_lock_init(&hidg->spinlock);
651 init_waitqueue_head(&hidg->write_queue);
652 init_waitqueue_head(&hidg->read_queue);
Daniel Mack99c5150052012-06-13 12:54:45 +0200653 INIT_LIST_HEAD(&hidg->completed_out_req);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200654
655 /* create char device */
656 cdev_init(&hidg->cdev, &f_hidg_fops);
657 dev = MKDEV(major, hidg->minor);
658 status = cdev_add(&hidg->cdev, dev, 1);
659 if (status)
Pavitrakumar Managutted12a8722014-10-22 19:24:58 +0530660 goto fail_free_descs;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200661
Andrzej Pietrasiewicz63406082014-11-06 11:11:57 +0100662 device = device_create(hidg_class, NULL, dev, NULL,
663 "%s%d", "hidg", hidg->minor);
664 if (IS_ERR(device)) {
665 status = PTR_ERR(device);
666 goto del;
667 }
Fabien Chouteau71adf112010-04-08 09:31:15 +0200668
669 return 0;
Andrzej Pietrasiewicz63406082014-11-06 11:11:57 +0100670del:
671 cdev_del(&hidg->cdev);
Pavitrakumar Managutted12a8722014-10-22 19:24:58 +0530672fail_free_descs:
673 usb_free_all_descriptors(f);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200674fail:
675 ERROR(f->config->cdev, "hidg_bind FAILED\n");
Felipe F. Tonello14794d72016-08-23 18:24:50 +0100676 if (hidg->req != NULL)
677 free_ep_req(hidg->in_ep, hidg->req);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200678
Fabien Chouteau71adf112010-04-08 09:31:15 +0200679 return status;
680}
681
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100682static inline int hidg_get_minor(void)
683{
684 int ret;
685
686 ret = ida_simple_get(&hidg_ida, 0, 0, GFP_KERNEL);
Andrzej Pietrasiewicz774cf722015-07-24 09:48:40 +0200687 if (ret >= HIDG_MINORS) {
688 ida_simple_remove(&hidg_ida, ret);
689 ret = -ENODEV;
690 }
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100691
692 return ret;
693}
694
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100695static inline struct f_hid_opts *to_f_hid_opts(struct config_item *item)
696{
697 return container_of(to_config_group(item), struct f_hid_opts,
698 func_inst.group);
699}
700
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100701static void hid_attr_release(struct config_item *item)
702{
703 struct f_hid_opts *opts = to_f_hid_opts(item);
704
705 usb_put_function_instance(&opts->func_inst);
706}
707
708static struct configfs_item_operations hidg_item_ops = {
709 .release = hid_attr_release,
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100710};
711
712#define F_HID_OPT(name, prec, limit) \
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200713static ssize_t f_hid_opts_##name##_show(struct config_item *item, char *page)\
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100714{ \
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200715 struct f_hid_opts *opts = to_f_hid_opts(item); \
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100716 int result; \
717 \
718 mutex_lock(&opts->lock); \
719 result = sprintf(page, "%d\n", opts->name); \
720 mutex_unlock(&opts->lock); \
721 \
722 return result; \
723} \
724 \
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200725static ssize_t f_hid_opts_##name##_store(struct config_item *item, \
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100726 const char *page, size_t len) \
727{ \
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200728 struct f_hid_opts *opts = to_f_hid_opts(item); \
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100729 int ret; \
730 u##prec num; \
731 \
732 mutex_lock(&opts->lock); \
733 if (opts->refcnt) { \
734 ret = -EBUSY; \
735 goto end; \
736 } \
737 \
738 ret = kstrtou##prec(page, 0, &num); \
739 if (ret) \
740 goto end; \
741 \
742 if (num > limit) { \
743 ret = -EINVAL; \
744 goto end; \
745 } \
746 opts->name = num; \
747 ret = len; \
748 \
749end: \
750 mutex_unlock(&opts->lock); \
751 return ret; \
752} \
753 \
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200754CONFIGFS_ATTR(f_hid_opts_, name)
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100755
756F_HID_OPT(subclass, 8, 255);
757F_HID_OPT(protocol, 8, 255);
Andrzej Pietrasiewicz39a2ac272014-12-15 13:50:05 +0100758F_HID_OPT(report_length, 16, 65535);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100759
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200760static ssize_t f_hid_opts_report_desc_show(struct config_item *item, char *page)
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100761{
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200762 struct f_hid_opts *opts = to_f_hid_opts(item);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100763 int result;
764
765 mutex_lock(&opts->lock);
766 result = opts->report_desc_length;
767 memcpy(page, opts->report_desc, opts->report_desc_length);
768 mutex_unlock(&opts->lock);
769
770 return result;
771}
772
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200773static ssize_t f_hid_opts_report_desc_store(struct config_item *item,
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100774 const char *page, size_t len)
775{
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200776 struct f_hid_opts *opts = to_f_hid_opts(item);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100777 int ret = -EBUSY;
778 char *d;
779
780 mutex_lock(&opts->lock);
781
782 if (opts->refcnt)
783 goto end;
784 if (len > PAGE_SIZE) {
785 ret = -ENOSPC;
786 goto end;
787 }
788 d = kmemdup(page, len, GFP_KERNEL);
789 if (!d) {
790 ret = -ENOMEM;
791 goto end;
792 }
793 kfree(opts->report_desc);
794 opts->report_desc = d;
795 opts->report_desc_length = len;
796 opts->report_desc_alloc = true;
797 ret = len;
798end:
799 mutex_unlock(&opts->lock);
800 return ret;
801}
802
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200803CONFIGFS_ATTR(f_hid_opts_, report_desc);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100804
Johannes Berged6fe1f2016-06-23 22:28:54 +0200805static ssize_t f_hid_opts_dev_show(struct config_item *item, char *page)
806{
807 struct f_hid_opts *opts = to_f_hid_opts(item);
808
809 return sprintf(page, "%d:%d\n", major, opts->minor);
810}
811
812CONFIGFS_ATTR_RO(f_hid_opts_, dev);
813
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100814static struct configfs_attribute *hid_attrs[] = {
Christoph Hellwigda4e5272015-10-03 15:32:40 +0200815 &f_hid_opts_attr_subclass,
816 &f_hid_opts_attr_protocol,
817 &f_hid_opts_attr_report_length,
818 &f_hid_opts_attr_report_desc,
Johannes Berged6fe1f2016-06-23 22:28:54 +0200819 &f_hid_opts_attr_dev,
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100820 NULL,
821};
822
823static struct config_item_type hid_func_type = {
824 .ct_item_ops = &hidg_item_ops,
825 .ct_attrs = hid_attrs,
826 .ct_owner = THIS_MODULE,
827};
828
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100829static inline void hidg_put_minor(int minor)
830{
831 ida_simple_remove(&hidg_ida, minor);
832}
833
834static void hidg_free_inst(struct usb_function_instance *f)
835{
836 struct f_hid_opts *opts;
837
838 opts = container_of(f, struct f_hid_opts, func_inst);
839
840 mutex_lock(&hidg_ida_lock);
841
842 hidg_put_minor(opts->minor);
843 if (idr_is_empty(&hidg_ida.idr))
844 ghid_cleanup();
845
846 mutex_unlock(&hidg_ida_lock);
847
848 if (opts->report_desc_alloc)
849 kfree(opts->report_desc);
850
851 kfree(opts);
852}
853
854static struct usb_function_instance *hidg_alloc_inst(void)
855{
856 struct f_hid_opts *opts;
857 struct usb_function_instance *ret;
858 int status = 0;
859
860 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
861 if (!opts)
862 return ERR_PTR(-ENOMEM);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100863 mutex_init(&opts->lock);
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100864 opts->func_inst.free_func_inst = hidg_free_inst;
865 ret = &opts->func_inst;
866
867 mutex_lock(&hidg_ida_lock);
868
869 if (idr_is_empty(&hidg_ida.idr)) {
870 status = ghid_setup(NULL, HIDG_MINORS);
871 if (status) {
872 ret = ERR_PTR(status);
873 kfree(opts);
874 goto unlock;
875 }
876 }
877
878 opts->minor = hidg_get_minor();
879 if (opts->minor < 0) {
880 ret = ERR_PTR(opts->minor);
881 kfree(opts);
882 if (idr_is_empty(&hidg_ida.idr))
883 ghid_cleanup();
Dan Carpenter828f6142014-11-13 09:19:47 +0300884 goto unlock;
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100885 }
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100886 config_group_init_type_name(&opts->func_inst.group, "", &hid_func_type);
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100887
888unlock:
889 mutex_unlock(&hidg_ida_lock);
890 return ret;
891}
892
893static void hidg_free(struct usb_function *f)
894{
895 struct f_hidg *hidg;
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100896 struct f_hid_opts *opts;
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100897
898 hidg = func_to_hidg(f);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100899 opts = container_of(f->fi, struct f_hid_opts, func_inst);
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100900 kfree(hidg->report_desc);
901 kfree(hidg);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100902 mutex_lock(&opts->lock);
903 --opts->refcnt;
904 mutex_unlock(&opts->lock);
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100905}
906
Fabien Chouteau71adf112010-04-08 09:31:15 +0200907static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
908{
909 struct f_hidg *hidg = func_to_hidg(f);
910
911 device_destroy(hidg_class, MKDEV(major, hidg->minor));
912 cdev_del(&hidg->cdev);
913
914 /* disable/free request and end point */
915 usb_ep_disable(hidg->in_ep);
Felipe F. Tonello14794d72016-08-23 18:24:50 +0100916 free_ep_req(hidg->in_ep, hidg->req);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200917
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200918 usb_free_all_descriptors(f);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200919}
920
Fengguang Wu0fc57ea2014-11-12 22:44:05 +0800921static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
Fabien Chouteau71adf112010-04-08 09:31:15 +0200922{
923 struct f_hidg *hidg;
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100924 struct f_hid_opts *opts;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200925
926 /* allocate and initialize one new instance */
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100927 hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200928 if (!hidg)
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100929 return ERR_PTR(-ENOMEM);
Fabien Chouteau71adf112010-04-08 09:31:15 +0200930
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100931 opts = container_of(fi, struct f_hid_opts, func_inst);
932
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100933 mutex_lock(&opts->lock);
934 ++opts->refcnt;
935
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100936 hidg->minor = opts->minor;
937 hidg->bInterfaceSubClass = opts->subclass;
938 hidg->bInterfaceProtocol = opts->protocol;
939 hidg->report_length = opts->report_length;
940 hidg->report_desc_length = opts->report_desc_length;
941 if (opts->report_desc) {
942 hidg->report_desc = kmemdup(opts->report_desc,
943 opts->report_desc_length,
944 GFP_KERNEL);
945 if (!hidg->report_desc) {
946 kfree(hidg);
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100947 mutex_unlock(&opts->lock);
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100948 return ERR_PTR(-ENOMEM);
949 }
Fabien Chouteau71adf112010-04-08 09:31:15 +0200950 }
951
Andrzej Pietrasiewicz21a94762014-11-06 11:12:03 +0100952 mutex_unlock(&opts->lock);
953
Fabien Chouteau71adf112010-04-08 09:31:15 +0200954 hidg->func.name = "hid";
Fabien Chouteau71adf112010-04-08 09:31:15 +0200955 hidg->func.bind = hidg_bind;
956 hidg->func.unbind = hidg_unbind;
957 hidg->func.set_alt = hidg_set_alt;
958 hidg->func.disable = hidg_disable;
959 hidg->func.setup = hidg_setup;
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100960 hidg->func.free_func = hidg_free;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200961
Daniel Mack99c5150052012-06-13 12:54:45 +0200962 /* this could me made configurable at some point */
963 hidg->qlen = 4;
964
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100965 return &hidg->func;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200966}
967
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100968DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc);
969MODULE_LICENSE("GPL");
970MODULE_AUTHOR("Fabien Chouteau");
971
Andrzej Pietrasiewiczcb382532014-11-06 11:11:59 +0100972int ghid_setup(struct usb_gadget *g, int count)
Fabien Chouteau71adf112010-04-08 09:31:15 +0200973{
974 int status;
975 dev_t dev;
976
977 hidg_class = class_create(THIS_MODULE, "hidg");
Andrzej Pietrasiewicz06529402014-11-06 11:11:56 +0100978 if (IS_ERR(hidg_class)) {
Dan Carpenter0448d382014-11-13 09:20:59 +0300979 status = PTR_ERR(hidg_class);
Andrzej Pietrasiewicz06529402014-11-06 11:11:56 +0100980 hidg_class = NULL;
Dan Carpenter0448d382014-11-13 09:20:59 +0300981 return status;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200982 }
983
Fabien Chouteau71adf112010-04-08 09:31:15 +0200984 status = alloc_chrdev_region(&dev, 0, count, "hidg");
Dan Carpenter0448d382014-11-13 09:20:59 +0300985 if (status) {
986 class_destroy(hidg_class);
987 hidg_class = NULL;
988 return status;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200989 }
990
Dan Carpenter0448d382014-11-13 09:20:59 +0300991 major = MAJOR(dev);
992 minors = count;
993
994 return 0;
Fabien Chouteau71adf112010-04-08 09:31:15 +0200995}
996
997void ghid_cleanup(void)
998{
999 if (major) {
1000 unregister_chrdev_region(MKDEV(major, 0), minors);
1001 major = minors = 0;
1002 }
1003
1004 class_destroy(hidg_class);
1005 hidg_class = NULL;
1006}