2 * Greybus "AP" USB driver for "ES2" controller chips
4 * Copyright 2014-2015 Google Inc.
5 * Copyright 2014-2015 Linaro Ltd.
7 * Released under the GPLv2 only.
9 #include <linux/kthread.h>
10 #include <linux/sizes.h>
11 #include <linux/usb.h>
12 #include <linux/kfifo.h>
13 #include <linux/debugfs.h>
14 #include <asm/unaligned.h>
17 #include "kernel_ver.h"
18 #include "connection.h"
19 #include "greybus_trace.h"
21 /* Memory sizes for the buffers sent to/from the ES2 controller */
22 #define ES2_GBUF_MSG_SIZE_MAX 2048
24 static const struct usb_device_id id_table[] = {
25 { USB_DEVICE(0x18d1, 0x1eaf) },
28 MODULE_DEVICE_TABLE(usb, id_table);
30 #define APB1_LOG_SIZE SZ_16K
32 /* Number of bulk in and bulk out couple */
36 * Number of CPort IN urbs in flight at any point in time.
37 * Adjust if we are having stalls in the USB buffer due to not enough urbs in
40 #define NUM_CPORT_IN_URB 4
42 /* Number of CPort OUT urbs in flight at any point in time.
43 * Adjust if we get messages saying we are out of urbs in the system log.
45 #define NUM_CPORT_OUT_URB (8 * NUM_BULKS)
47 /* vendor request APB1 log */
48 #define REQUEST_LOG 0x02
50 /* vendor request to map a cport to bulk in and bulk out endpoints */
51 #define REQUEST_EP_MAPPING 0x03
53 /* vendor request to get the number of cports available */
54 #define REQUEST_CPORT_COUNT 0x04
56 /* vendor request to reset a cport state */
57 #define REQUEST_RESET_CPORT 0x05
59 /* vendor request to time the latency of messages on a given cport */
60 #define REQUEST_LATENCY_TAG_EN 0x06
61 #define REQUEST_LATENCY_TAG_DIS 0x07
64 * @endpoint: bulk in endpoint for CPort data
65 * @urb: array of urbs for the CPort in messages
66 * @buffer: array of buffers for the @cport_in_urb urbs
70 struct urb *urb[NUM_CPORT_IN_URB];
71 u8 *buffer[NUM_CPORT_IN_URB];
75 * @endpoint: bulk out endpoint for CPort data
77 struct es2_cport_out {
82 * es2_ap_dev - ES2 USB Bridge to AP structure
83 * @usb_dev: pointer to the USB device we are.
84 * @usb_intf: pointer to the USB interface we are bound to.
85 * @hd: pointer to our gb_host_device structure
87 * @cport_in: endpoint, urbs and buffer for cport in messages
88 * @cport_out: endpoint for for cport out messages
89 * @cport_out_urb: array of urbs for the CPort out messages
90 * @cport_out_urb_busy: array of flags to see if the @cport_out_urb is busy or
92 * @cport_out_urb_cancelled: array of flags indicating whether the
93 * corresponding @cport_out_urb is being cancelled
94 * @cport_out_urb_lock: locks the @cport_out_urb_busy "list"
96 * @apb_log_task: task pointer for logging thread
97 * @apb_log_dentry: file system entry for the log file interface
98 * @apb_log_enable_dentry: file system entry for enabling logging
99 * @apb_log_fifo: kernel FIFO to carry logged data
102 struct usb_device *usb_dev;
103 struct usb_interface *usb_intf;
104 struct gb_host_device *hd;
106 struct es2_cport_in cport_in[NUM_BULKS];
107 struct es2_cport_out cport_out[NUM_BULKS];
108 struct urb *cport_out_urb[NUM_CPORT_OUT_URB];
109 bool cport_out_urb_busy[NUM_CPORT_OUT_URB];
110 bool cport_out_urb_cancelled[NUM_CPORT_OUT_URB];
111 spinlock_t cport_out_urb_lock;
115 struct task_struct *apb_log_task;
116 struct dentry *apb_log_dentry;
117 struct dentry *apb_log_enable_dentry;
118 DECLARE_KFIFO(apb_log_fifo, char, APB1_LOG_SIZE);
122 * cport_to_ep - information about cport to endpoints mapping
123 * @cport_id: the id of cport to map to endpoints
124 * @endpoint_in: the endpoint number to use for in transfer
125 * @endpoint_out: he endpoint number to use for out transfer
133 static inline struct es2_ap_dev *hd_to_es2(struct gb_host_device *hd)
135 return (struct es2_ap_dev *)&hd->hd_priv;
138 static void cport_out_callback(struct urb *urb);
139 static void usb_log_enable(struct es2_ap_dev *es2);
140 static void usb_log_disable(struct es2_ap_dev *es2);
142 /* Get the endpoints pair mapped to the cport */
143 static int cport_to_ep_pair(struct es2_ap_dev *es2, u16 cport_id)
145 if (cport_id >= es2->hd->num_cports)
147 return es2->cport_to_ep[cport_id];
150 #define ES2_TIMEOUT 500 /* 500 ms for the SVC to do something */
152 /* Disable for now until we work all of this out to keep a warning-free build */
154 /* Test if the endpoints pair is already mapped to a cport */
155 static int ep_pair_in_use(struct es2_ap_dev *es2, int ep_pair)
159 for (i = 0; i < es2->hd->num_cports; i++) {
160 if (es2->cport_to_ep[i] == ep_pair)
166 /* Configure the endpoint mapping and send the request to APBridge */
167 static int map_cport_to_ep(struct es2_ap_dev *es2,
168 u16 cport_id, int ep_pair)
171 struct cport_to_ep *cport_to_ep;
173 if (ep_pair < 0 || ep_pair >= NUM_BULKS)
175 if (cport_id >= es2->hd->num_cports)
177 if (ep_pair && ep_pair_in_use(es2, ep_pair))
180 cport_to_ep = kmalloc(sizeof(*cport_to_ep), GFP_KERNEL);
184 es2->cport_to_ep[cport_id] = ep_pair;
185 cport_to_ep->cport_id = cpu_to_le16(cport_id);
186 cport_to_ep->endpoint_in = es2->cport_in[ep_pair].endpoint;
187 cport_to_ep->endpoint_out = es2->cport_out[ep_pair].endpoint;
189 retval = usb_control_msg(es2->usb_dev,
190 usb_sndctrlpipe(es2->usb_dev, 0),
192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
195 sizeof(*cport_to_ep),
197 if (retval == sizeof(*cport_to_ep))
204 /* Unmap a cport: use the muxed endpoints pair */
205 static int unmap_cport(struct es2_ap_dev *es2, u16 cport_id)
207 return map_cport_to_ep(es2, cport_id, 0);
211 static int es2_cport_in_enable(struct es2_ap_dev *es2,
212 struct es2_cport_in *cport_in)
218 for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
219 urb = cport_in->urb[i];
221 ret = usb_submit_urb(urb, GFP_KERNEL);
223 dev_err(&es2->usb_dev->dev,
224 "failed to submit in-urb: %d\n", ret);
232 for (--i; i >= 0; --i) {
233 urb = cport_in->urb[i];
240 static void es2_cport_in_disable(struct es2_ap_dev *es2,
241 struct es2_cport_in *cport_in)
246 for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
247 urb = cport_in->urb[i];
252 static struct urb *next_free_urb(struct es2_ap_dev *es2, gfp_t gfp_mask)
254 struct urb *urb = NULL;
258 spin_lock_irqsave(&es2->cport_out_urb_lock, flags);
260 /* Look in our pool of allocated urbs first, as that's the "fastest" */
261 for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
262 if (es2->cport_out_urb_busy[i] == false &&
263 es2->cport_out_urb_cancelled[i] == false) {
264 es2->cport_out_urb_busy[i] = true;
265 urb = es2->cport_out_urb[i];
269 spin_unlock_irqrestore(&es2->cport_out_urb_lock, flags);
274 * Crap, pool is empty, complain to the syslog and go allocate one
275 * dynamically as we have to succeed.
277 dev_dbg(&es2->usb_dev->dev,
278 "No free CPort OUT urbs, having to dynamically allocate one!\n");
279 return usb_alloc_urb(0, gfp_mask);
282 static void free_urb(struct es2_ap_dev *es2, struct urb *urb)
287 * See if this was an urb in our pool, if so mark it "free", otherwise
288 * we need to free it ourselves.
290 spin_lock_irqsave(&es2->cport_out_urb_lock, flags);
291 for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
292 if (urb == es2->cport_out_urb[i]) {
293 es2->cport_out_urb_busy[i] = false;
298 spin_unlock_irqrestore(&es2->cport_out_urb_lock, flags);
300 /* If urb is not NULL, then we need to free this urb */
305 * We (ab)use the operation-message header pad bytes to transfer the
306 * cport id in order to minimise overhead.
309 gb_message_cport_pack(struct gb_operation_msg_hdr *header, u16 cport_id)
311 header->pad[0] = cport_id;
314 /* Clear the pad bytes used for the CPort id */
315 static void gb_message_cport_clear(struct gb_operation_msg_hdr *header)
320 /* Extract the CPort id packed into the header, and clear it */
321 static u16 gb_message_cport_unpack(struct gb_operation_msg_hdr *header)
323 u16 cport_id = header->pad[0];
325 gb_message_cport_clear(header);
331 * Returns zero if the message was successfully queued, or a negative errno
334 static int message_send(struct gb_host_device *hd, u16 cport_id,
335 struct gb_message *message, gfp_t gfp_mask)
337 struct es2_ap_dev *es2 = hd_to_es2(hd);
338 struct usb_device *udev = es2->usb_dev;
346 * The data actually transferred will include an indication
347 * of where the data should be sent. Do one last check of
348 * the target CPort id before filling it in.
350 if (!cport_id_valid(hd, cport_id)) {
351 dev_err(&udev->dev, "invalid cport %u\n", cport_id);
355 /* Find a free urb */
356 urb = next_free_urb(es2, gfp_mask);
360 spin_lock_irqsave(&es2->cport_out_urb_lock, flags);
361 message->hcpriv = urb;
362 spin_unlock_irqrestore(&es2->cport_out_urb_lock, flags);
364 /* Pack the cport id into the message header */
365 gb_message_cport_pack(message->header, cport_id);
367 buffer_size = sizeof(*message->header) + message->payload_size;
369 ep_pair = cport_to_ep_pair(es2, cport_id);
370 usb_fill_bulk_urb(urb, udev,
371 usb_sndbulkpipe(udev,
372 es2->cport_out[ep_pair].endpoint),
373 message->buffer, buffer_size,
374 cport_out_callback, message);
375 urb->transfer_flags |= URB_ZERO_PACKET;
376 trace_gb_host_device_send(hd, cport_id, buffer_size);
377 retval = usb_submit_urb(urb, gfp_mask);
379 dev_err(&udev->dev, "failed to submit out-urb: %d\n", retval);
381 spin_lock_irqsave(&es2->cport_out_urb_lock, flags);
382 message->hcpriv = NULL;
383 spin_unlock_irqrestore(&es2->cport_out_urb_lock, flags);
386 gb_message_cport_clear(message->header);
395 * Can not be called in atomic context.
397 static void message_cancel(struct gb_message *message)
399 struct gb_host_device *hd = message->operation->connection->hd;
400 struct es2_ap_dev *es2 = hd_to_es2(hd);
406 spin_lock_irq(&es2->cport_out_urb_lock);
407 urb = message->hcpriv;
409 /* Prevent dynamically allocated urb from being deallocated. */
412 /* Prevent pre-allocated urb from being reused. */
413 for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
414 if (urb == es2->cport_out_urb[i]) {
415 es2->cport_out_urb_cancelled[i] = true;
419 spin_unlock_irq(&es2->cport_out_urb_lock);
423 if (i < NUM_CPORT_OUT_URB) {
424 spin_lock_irq(&es2->cport_out_urb_lock);
425 es2->cport_out_urb_cancelled[i] = false;
426 spin_unlock_irq(&es2->cport_out_urb_lock);
432 static int cport_reset(struct gb_host_device *hd, u16 cport_id)
434 struct es2_ap_dev *es2 = hd_to_es2(hd);
435 struct usb_device *udev = es2->usb_dev;
438 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
440 USB_DIR_OUT | USB_TYPE_VENDOR |
441 USB_RECIP_INTERFACE, cport_id, 0,
442 NULL, 0, ES2_TIMEOUT);
444 dev_err(&udev->dev, "failed to reset cport %u: %d\n", cport_id,
452 static int cport_enable(struct gb_host_device *hd, u16 cport_id)
456 if (cport_id != GB_SVC_CPORT_ID) {
457 retval = cport_reset(hd, cport_id);
465 static int latency_tag_enable(struct gb_host_device *hd, u16 cport_id)
468 struct es2_ap_dev *es2 = hd_to_es2(hd);
469 struct usb_device *udev = es2->usb_dev;
471 if (!cport_id_valid(hd, cport_id)) {
472 dev_err(&udev->dev, "invalid cport %u\n", cport_id);
476 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
477 REQUEST_LATENCY_TAG_EN,
478 USB_DIR_OUT | USB_TYPE_VENDOR |
479 USB_RECIP_INTERFACE, cport_id, 0, NULL,
483 dev_err(&udev->dev, "Cannot enable latency tag for cport %d\n",
488 static int latency_tag_disable(struct gb_host_device *hd, u16 cport_id)
491 struct es2_ap_dev *es2 = hd_to_es2(hd);
492 struct usb_device *udev = es2->usb_dev;
494 if (!cport_id_valid(hd, cport_id)) {
495 dev_err(&udev->dev, "invalid cport %u\n", cport_id);
499 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
500 REQUEST_LATENCY_TAG_DIS,
501 USB_DIR_OUT | USB_TYPE_VENDOR |
502 USB_RECIP_INTERFACE, cport_id, 0, NULL,
506 dev_err(&udev->dev, "Cannot disable latency tag for cport %d\n",
511 static struct gb_hd_driver es2_driver = {
512 .hd_priv_size = sizeof(struct es2_ap_dev),
513 .message_send = message_send,
514 .message_cancel = message_cancel,
515 .cport_enable = cport_enable,
516 .latency_tag_enable = latency_tag_enable,
517 .latency_tag_disable = latency_tag_disable,
520 /* Common function to report consistent warnings based on URB status */
521 static int check_urb_status(struct urb *urb)
523 struct device *dev = &urb->dev->dev;
524 int status = urb->status;
531 dev_err(dev, "%s: overflow actual length is %d\n",
532 __func__, urb->actual_length);
538 /* device is gone, stop sending */
541 dev_err(dev, "%s: unknown status %d\n", __func__, status);
546 static void es2_destroy(struct es2_ap_dev *es2)
548 struct usb_device *udev;
552 debugfs_remove(es2->apb_log_enable_dentry);
553 usb_log_disable(es2);
555 /* Tear down everything! */
556 for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
557 struct urb *urb = es2->cport_out_urb[i];
563 es2->cport_out_urb[i] = NULL;
564 es2->cport_out_urb_busy[i] = false; /* just to be anal */
567 for (bulk_in = 0; bulk_in < NUM_BULKS; bulk_in++) {
568 struct es2_cport_in *cport_in = &es2->cport_in[bulk_in];
570 for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
571 struct urb *urb = cport_in->urb[i];
576 kfree(cport_in->buffer[i]);
577 cport_in->buffer[i] = NULL;
581 kfree(es2->cport_to_ep);
589 static void ap_disconnect(struct usb_interface *interface)
591 struct es2_ap_dev *es2 = usb_get_intfdata(interface);
594 for (i = 0; i < NUM_BULKS; ++i)
595 es2_cport_in_disable(es2, &es2->cport_in[i]);
602 static void cport_in_callback(struct urb *urb)
604 struct gb_host_device *hd = urb->context;
605 struct device *dev = &urb->dev->dev;
606 struct gb_operation_msg_hdr *header;
607 int status = check_urb_status(urb);
612 if ((status == -EAGAIN) || (status == -EPROTO))
614 dev_err(dev, "urb cport in error %d (dropped)\n", status);
618 if (urb->actual_length < sizeof(*header)) {
619 dev_err(dev, "short message received\n");
623 /* Extract the CPort id, which is packed in the message header */
624 header = urb->transfer_buffer;
625 cport_id = gb_message_cport_unpack(header);
627 if (cport_id_valid(hd, cport_id)) {
628 trace_gb_host_device_recv(hd, cport_id, urb->actual_length);
629 greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
632 dev_err(dev, "invalid cport id %u received\n", cport_id);
635 /* put our urb back in the request pool */
636 retval = usb_submit_urb(urb, GFP_ATOMIC);
638 dev_err(dev, "failed to resubmit in-urb: %d\n", retval);
641 static void cport_out_callback(struct urb *urb)
643 struct gb_message *message = urb->context;
644 struct gb_host_device *hd = message->operation->connection->hd;
645 struct es2_ap_dev *es2 = hd_to_es2(hd);
646 int status = check_urb_status(urb);
649 gb_message_cport_clear(message->header);
651 spin_lock_irqsave(&es2->cport_out_urb_lock, flags);
652 message->hcpriv = NULL;
653 spin_unlock_irqrestore(&es2->cport_out_urb_lock, flags);
656 * Tell the submitter that the message send (attempt) is
657 * complete, and report the status.
659 greybus_message_sent(hd, message, status);
664 #define APB1_LOG_MSG_SIZE 64
665 static void apb_log_get(struct es2_ap_dev *es2, char *buf)
669 /* SVC messages go down our control pipe */
671 retval = usb_control_msg(es2->usb_dev,
672 usb_rcvctrlpipe(es2->usb_dev, 0),
674 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
680 kfifo_in(&es2->apb_log_fifo, buf, retval);
681 } while (retval > 0);
684 static int apb_log_poll(void *data)
686 struct es2_ap_dev *es2 = data;
689 buf = kmalloc(APB1_LOG_MSG_SIZE, GFP_KERNEL);
693 while (!kthread_should_stop()) {
695 apb_log_get(es2, buf);
703 static ssize_t apb_log_read(struct file *f, char __user *buf,
704 size_t count, loff_t *ppos)
706 struct es2_ap_dev *es2 = f->f_inode->i_private;
711 if (count > APB1_LOG_SIZE)
712 count = APB1_LOG_SIZE;
714 tmp_buf = kmalloc(count, GFP_KERNEL);
718 copied = kfifo_out(&es2->apb_log_fifo, tmp_buf, count);
719 ret = simple_read_from_buffer(buf, count, ppos, tmp_buf, copied);
726 static const struct file_operations apb_log_fops = {
727 .read = apb_log_read,
730 static void usb_log_enable(struct es2_ap_dev *es2)
732 if (!IS_ERR_OR_NULL(es2->apb_log_task))
735 /* get log from APB1 */
736 es2->apb_log_task = kthread_run(apb_log_poll, es2, "apb_log");
737 if (IS_ERR(es2->apb_log_task))
739 /* XXX We will need to rename this per APB */
740 es2->apb_log_dentry = debugfs_create_file("apb_log", S_IRUGO,
741 gb_debugfs_get(), NULL,
745 static void usb_log_disable(struct es2_ap_dev *es2)
747 if (IS_ERR_OR_NULL(es2->apb_log_task))
750 debugfs_remove(es2->apb_log_dentry);
751 es2->apb_log_dentry = NULL;
753 kthread_stop(es2->apb_log_task);
754 es2->apb_log_task = NULL;
757 static ssize_t apb_log_enable_read(struct file *f, char __user *buf,
758 size_t count, loff_t *ppos)
760 struct es2_ap_dev *es2 = f->f_inode->i_private;
761 int enable = !IS_ERR_OR_NULL(es2->apb_log_task);
764 sprintf(tmp_buf, "%d\n", enable);
765 return simple_read_from_buffer(buf, count, ppos, tmp_buf, 3);
768 static ssize_t apb_log_enable_write(struct file *f, const char __user *buf,
769 size_t count, loff_t *ppos)
773 struct es2_ap_dev *es2 = f->f_inode->i_private;
775 retval = kstrtoint_from_user(buf, count, 10, &enable);
782 usb_log_disable(es2);
787 static const struct file_operations apb_log_enable_fops = {
788 .read = apb_log_enable_read,
789 .write = apb_log_enable_write,
792 static int apb_get_cport_count(struct usb_device *udev)
797 cport_count = kmalloc(sizeof(*cport_count), GFP_KERNEL);
801 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
803 USB_DIR_IN | USB_TYPE_VENDOR |
804 USB_RECIP_INTERFACE, 0, 0, cport_count,
805 sizeof(*cport_count), ES2_TIMEOUT);
807 dev_err(&udev->dev, "Cannot retrieve CPort count: %d\n",
812 retval = le16_to_cpu(*cport_count);
814 /* We need to fit a CPort ID in one byte of a message header */
815 if (retval > U8_MAX) {
817 dev_warn(&udev->dev, "Limiting number of CPorts to U8_MAX\n");
826 * The ES2 USB Bridge device has 15 endpoints
827 * 1 Control - usual USB stuff + AP -> APBridgeA messages
828 * 7 Bulk IN - CPort data in
829 * 7 Bulk OUT - CPort data out
831 static int ap_probe(struct usb_interface *interface,
832 const struct usb_device_id *id)
834 struct es2_ap_dev *es2;
835 struct gb_host_device *hd;
836 struct usb_device *udev;
837 struct usb_host_interface *iface_desc;
838 struct usb_endpoint_descriptor *endpoint;
841 int retval = -ENOMEM;
846 udev = usb_get_dev(interface_to_usbdev(interface));
848 num_cports = apb_get_cport_count(udev);
849 if (num_cports < 0) {
851 dev_err(&udev->dev, "Cannot retrieve CPort count: %d\n",
856 hd = gb_hd_create(&es2_driver, &udev->dev, ES2_GBUF_MSG_SIZE_MAX,
864 * CPorts 16 and 17 are reserved for CDSI0 and CDSI1, make sure they
865 * won't be allocated dynamically.
868 cport_id = ida_simple_get(&hd->cport_id_map, 16, 18, GFP_KERNEL);
869 } while (cport_id > 0);
873 es2->usb_intf = interface;
875 spin_lock_init(&es2->cport_out_urb_lock);
876 INIT_KFIFO(es2->apb_log_fifo);
877 usb_set_intfdata(interface, es2);
879 es2->cport_to_ep = kcalloc(hd->num_cports, sizeof(*es2->cport_to_ep),
881 if (!es2->cport_to_ep) {
886 /* find all bulk endpoints */
887 iface_desc = interface->cur_altsetting;
888 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
889 endpoint = &iface_desc->endpoint[i].desc;
891 if (usb_endpoint_is_bulk_in(endpoint)) {
892 es2->cport_in[bulk_in++].endpoint =
893 endpoint->bEndpointAddress;
894 } else if (usb_endpoint_is_bulk_out(endpoint)) {
895 es2->cport_out[bulk_out++].endpoint =
896 endpoint->bEndpointAddress;
899 "Unknown endpoint type found, address 0x%02x\n",
900 endpoint->bEndpointAddress);
903 if (bulk_in != NUM_BULKS || bulk_out != NUM_BULKS) {
904 dev_err(&udev->dev, "Not enough endpoints found in device, aborting!\n");
908 /* Allocate buffers for our cport in messages */
909 for (bulk_in = 0; bulk_in < NUM_BULKS; bulk_in++) {
910 struct es2_cport_in *cport_in = &es2->cport_in[bulk_in];
912 for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
916 urb = usb_alloc_urb(0, GFP_KERNEL);
919 buffer = kmalloc(ES2_GBUF_MSG_SIZE_MAX, GFP_KERNEL);
923 usb_fill_bulk_urb(urb, udev,
924 usb_rcvbulkpipe(udev,
926 buffer, ES2_GBUF_MSG_SIZE_MAX,
927 cport_in_callback, hd);
928 cport_in->urb[i] = urb;
929 cport_in->buffer[i] = buffer;
933 /* Allocate urbs for our CPort OUT messages */
934 for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
937 urb = usb_alloc_urb(0, GFP_KERNEL);
941 es2->cport_out_urb[i] = urb;
942 es2->cport_out_urb_busy[i] = false; /* just to be anal */
945 /* XXX We will need to rename this per APB */
946 es2->apb_log_enable_dentry = debugfs_create_file("apb_log_enable",
948 gb_debugfs_get(), es2,
949 &apb_log_enable_fops);
951 retval = gb_hd_add(hd);
955 for (i = 0; i < NUM_BULKS; ++i) {
956 retval = es2_cport_in_enable(es2, &es2->cport_in[i]);
958 goto err_disable_cport_in;
963 err_disable_cport_in:
964 for (--i; i >= 0; --i)
965 es2_cport_in_disable(es2, &es2->cport_in[i]);
973 static struct usb_driver es2_ap_driver = {
974 .name = "es2_ap_driver",
976 .disconnect = ap_disconnect,
977 .id_table = id_table,
980 module_usb_driver(es2_ap_driver);
982 MODULE_LICENSE("GPL v2");
983 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");