greybus: esX: encapsulate packing cport id into header
[cascardo/linux.git] / drivers / staging / greybus / es2.c
1 /*
2  * Greybus "AP" USB driver for "ES2" controller chips
3  *
4  * Copyright 2014-2015 Google Inc.
5  * Copyright 2014-2015 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  */
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>
15
16 #include "greybus.h"
17 #include "svc_msg.h"
18 #include "kernel_ver.h"
19
20 /* Memory sizes for the buffers sent to/from the ES1 controller */
21 #define ES1_SVC_MSG_SIZE        (sizeof(struct svc_msg) + SZ_64K)
22 #define ES1_GBUF_MSG_SIZE_MAX   2048
23
24 static const struct usb_device_id id_table[] = {
25         /* Made up numbers for the SVC USB Bridge in ES2 */
26         { USB_DEVICE(0xffff, 0x0002) },
27         { },
28 };
29 MODULE_DEVICE_TABLE(usb, id_table);
30
31 #define APB1_LOG_SIZE           SZ_16K
32 static struct dentry *apb1_log_dentry;
33 static struct dentry *apb1_log_enable_dentry;
34 static struct task_struct *apb1_log_task;
35 static DEFINE_KFIFO(apb1_log_fifo, char, APB1_LOG_SIZE);
36
37 /*
38  * Number of CPort IN urbs in flight at any point in time.
39  * Adjust if we are having stalls in the USB buffer due to not enough urbs in
40  * flight.
41  */
42 #define NUM_CPORT_IN_URB        4
43
44 /* Number of CPort OUT urbs in flight at any point in time.
45  * Adjust if we get messages saying we are out of urbs in the system log.
46  */
47 #define NUM_CPORT_OUT_URB       8
48
49 /**
50  * es1_ap_dev - ES1 USB Bridge to AP structure
51  * @usb_dev: pointer to the USB device we are.
52  * @usb_intf: pointer to the USB interface we are bound to.
53  * @hd: pointer to our greybus_host_device structure
54  * @control_endpoint: endpoint to send data to SVC
55  * @svc_endpoint: endpoint for SVC data in
56  * @cport_in_endpoint: bulk in endpoint for CPort data
57  * @cport-out_endpoint: bulk out endpoint for CPort data
58  * @svc_buffer: buffer for SVC messages coming in on @svc_endpoint
59  * @svc_urb: urb for SVC messages coming in on @svc_endpoint
60  * @cport_in_urb: array of urbs for the CPort in messages
61  * @cport_in_buffer: array of buffers for the @cport_in_urb urbs
62  * @cport_out_urb: array of urbs for the CPort out messages
63  * @cport_out_urb_busy: array of flags to see if the @cport_out_urb is busy or
64  *                      not.
65  * @cport_out_urb_lock: locks the @cport_out_urb_busy "list"
66  */
67 struct es1_ap_dev {
68         struct usb_device *usb_dev;
69         struct usb_interface *usb_intf;
70         struct greybus_host_device *hd;
71
72         __u8 control_endpoint;
73         __u8 svc_endpoint;
74         __u8 cport_in_endpoint;
75         __u8 cport_out_endpoint;
76
77         u8 *svc_buffer;
78         struct urb *svc_urb;
79
80         struct urb *cport_in_urb[NUM_CPORT_IN_URB];
81         u8 *cport_in_buffer[NUM_CPORT_IN_URB];
82         struct urb *cport_out_urb[NUM_CPORT_OUT_URB];
83         bool cport_out_urb_busy[NUM_CPORT_OUT_URB];
84         spinlock_t cport_out_urb_lock;
85 };
86
87 static inline struct es1_ap_dev *hd_to_es1(struct greybus_host_device *hd)
88 {
89         return (struct es1_ap_dev *)&hd->hd_priv;
90 }
91
92 static void cport_out_callback(struct urb *urb);
93 static void usb_log_enable(struct es1_ap_dev *es1);
94 static void usb_log_disable(struct es1_ap_dev *es1);
95
96 #define ES1_TIMEOUT     500     /* 500 ms for the SVC to do something */
97 static int submit_svc(struct svc_msg *svc_msg, struct greybus_host_device *hd)
98 {
99         struct es1_ap_dev *es1 = hd_to_es1(hd);
100         int retval;
101
102         /* SVC messages go down our control pipe */
103         retval = usb_control_msg(es1->usb_dev,
104                                  usb_sndctrlpipe(es1->usb_dev,
105                                                  es1->control_endpoint),
106                                  0x01,  /* vendor request AP message */
107                                  USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
108                                  0x00, 0x00,
109                                  (char *)svc_msg,
110                                  sizeof(*svc_msg),
111                                  ES1_TIMEOUT);
112         if (retval != sizeof(*svc_msg))
113                 return retval;
114
115         return 0;
116 }
117
118 static struct urb *next_free_urb(struct es1_ap_dev *es1, gfp_t gfp_mask)
119 {
120         struct urb *urb = NULL;
121         unsigned long flags;
122         int i;
123
124         spin_lock_irqsave(&es1->cport_out_urb_lock, flags);
125
126         /* Look in our pool of allocated urbs first, as that's the "fastest" */
127         for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
128                 if (es1->cport_out_urb_busy[i] == false) {
129                         es1->cport_out_urb_busy[i] = true;
130                         urb = es1->cport_out_urb[i];
131                         break;
132                 }
133         }
134         spin_unlock_irqrestore(&es1->cport_out_urb_lock, flags);
135         if (urb)
136                 return urb;
137
138         /*
139          * Crap, pool is empty, complain to the syslog and go allocate one
140          * dynamically as we have to succeed.
141          */
142         dev_err(&es1->usb_dev->dev,
143                 "No free CPort OUT urbs, having to dynamically allocate one!\n");
144         return usb_alloc_urb(0, gfp_mask);
145 }
146
147 static void free_urb(struct es1_ap_dev *es1, struct urb *urb)
148 {
149         unsigned long flags;
150         int i;
151         /*
152          * See if this was an urb in our pool, if so mark it "free", otherwise
153          * we need to free it ourselves.
154          */
155         spin_lock_irqsave(&es1->cport_out_urb_lock, flags);
156         for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
157                 if (urb == es1->cport_out_urb[i]) {
158                         es1->cport_out_urb_busy[i] = false;
159                         urb = NULL;
160                         break;
161                 }
162         }
163         spin_unlock_irqrestore(&es1->cport_out_urb_lock, flags);
164
165         /* If urb is not NULL, then we need to free this urb */
166         usb_free_urb(urb);
167 }
168
169 /*
170  * We (ab)use the operation-message header pad bytes to transfer the
171  * cport id in order to minimise overhead.
172  */
173 static void
174 gb_message_cport_pack(struct gb_operation_msg_hdr *header, u16 cport_id)
175 {
176         put_unaligned_le16(cport_id, header->pad);
177 }
178
179 /* Clear the pad bytes used for the CPort id */
180 static void gb_message_cport_clear(struct gb_operation_msg_hdr *header)
181 {
182         put_unaligned_le16(0, header->pad);
183 }
184
185 /* Extract the CPort id packed into the header, and clear it */
186 static u16 gb_message_cport_unpack(struct gb_operation_msg_hdr *header)
187 {
188         u16 cport_id = get_unaligned_le16(header->pad);
189
190         gb_message_cport_clear(header);
191
192         return cport_id;
193 }
194
195 /*
196  * Returns an opaque cookie value if successful, or a pointer coded
197  * error otherwise.  If the caller wishes to cancel the in-flight
198  * buffer, it must supply the returned cookie to the cancel routine.
199  */
200 static void *message_send(struct greybus_host_device *hd, u16 cport_id,
201                         struct gb_message *message, gfp_t gfp_mask)
202 {
203         struct es1_ap_dev *es1 = hd_to_es1(hd);
204         struct usb_device *udev = es1->usb_dev;
205         size_t buffer_size;
206         int retval;
207         struct urb *urb;
208
209         /*
210          * The data actually transferred will include an indication
211          * of where the data should be sent.  Do one last check of
212          * the target CPort id before filling it in.
213          */
214         if (!cport_id_valid(cport_id)) {
215                 pr_err("invalid destination cport 0x%02x\n", cport_id);
216                 return ERR_PTR(-EINVAL);
217         }
218
219         /* Find a free urb */
220         urb = next_free_urb(es1, gfp_mask);
221         if (!urb)
222                 return ERR_PTR(-ENOMEM);
223
224         /* Pack the cport id into the message header */
225         gb_message_cport_pack(message->header, cport_id);
226
227         buffer_size = sizeof(*message->header) + message->payload_size;
228
229         usb_fill_bulk_urb(urb, udev,
230                           usb_sndbulkpipe(udev, es1->cport_out_endpoint),
231                           message->buffer, buffer_size,
232                           cport_out_callback, message);
233         retval = usb_submit_urb(urb, gfp_mask);
234         if (retval) {
235                 pr_err("error %d submitting URB\n", retval);
236                 free_urb(es1, urb);
237                 gb_message_cport_clear(message->header);
238                 return ERR_PTR(retval);
239         }
240
241         return urb;
242 }
243
244 /*
245  * The cookie value supplied is the value that message_send()
246  * returned to its caller.  It identifies the message that should be
247  * canceled.  This function must also handle (which is to say,
248  * ignore) a null cookie value.
249  */
250 static void message_cancel(void *cookie)
251 {
252
253         /*
254          * We really should be defensive and track all outstanding
255          * (sent) messages rather than trusting the cookie provided
256          * is valid.  For the time being, this will do.
257          */
258         if (cookie)
259                 usb_kill_urb(cookie);
260 }
261
262 static struct greybus_host_driver es1_driver = {
263         .hd_priv_size           = sizeof(struct es1_ap_dev),
264         .message_send           = message_send,
265         .message_cancel         = message_cancel,
266         .submit_svc             = submit_svc,
267 };
268
269 /* Common function to report consistent warnings based on URB status */
270 static int check_urb_status(struct urb *urb)
271 {
272         struct device *dev = &urb->dev->dev;
273         int status = urb->status;
274
275         switch (status) {
276         case 0:
277                 return 0;
278
279         case -EOVERFLOW:
280                 dev_err(dev, "%s: overflow actual length is %d\n",
281                         __func__, urb->actual_length);
282         case -ECONNRESET:
283         case -ENOENT:
284         case -ESHUTDOWN:
285         case -EILSEQ:
286         case -EPROTO:
287                 /* device is gone, stop sending */
288                 return status;
289         }
290         dev_err(dev, "%s: unknown status %d\n", __func__, status);
291
292         return -EAGAIN;
293 }
294
295 static void ap_disconnect(struct usb_interface *interface)
296 {
297         struct es1_ap_dev *es1;
298         struct usb_device *udev;
299         int i;
300
301         es1 = usb_get_intfdata(interface);
302         if (!es1)
303                 return;
304
305         usb_log_disable(es1);
306
307         /* Tear down everything! */
308         for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
309                 struct urb *urb = es1->cport_out_urb[i];
310
311                 if (!urb)
312                         break;
313                 usb_kill_urb(urb);
314                 usb_free_urb(urb);
315                 es1->cport_out_urb[i] = NULL;
316                 es1->cport_out_urb_busy[i] = false;     /* just to be anal */
317         }
318
319         for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
320                 struct urb *urb = es1->cport_in_urb[i];
321
322                 if (!urb)
323                         break;
324                 usb_kill_urb(urb);
325                 usb_free_urb(urb);
326                 kfree(es1->cport_in_buffer[i]);
327                 es1->cport_in_buffer[i] = NULL;
328         }
329
330         usb_kill_urb(es1->svc_urb);
331         usb_free_urb(es1->svc_urb);
332         es1->svc_urb = NULL;
333         kfree(es1->svc_buffer);
334         es1->svc_buffer = NULL;
335
336         usb_set_intfdata(interface, NULL);
337         udev = es1->usb_dev;
338         greybus_remove_hd(es1->hd);
339
340         usb_put_dev(udev);
341 }
342
343 /* Callback for when we get a SVC message */
344 static void svc_in_callback(struct urb *urb)
345 {
346         struct greybus_host_device *hd = urb->context;
347         struct device *dev = &urb->dev->dev;
348         int status = check_urb_status(urb);
349         int retval;
350
351         if (status) {
352                 if ((status == -EAGAIN) || (status == -EPROTO))
353                         goto exit;
354                 dev_err(dev, "urb svc in error %d (dropped)\n", status);
355                 return;
356         }
357
358         /* We have a message, create a new message structure, add it to the
359          * list, and wake up our thread that will process the messages.
360          */
361         greybus_svc_in(hd, urb->transfer_buffer, urb->actual_length);
362
363 exit:
364         /* resubmit the urb to get more messages */
365         retval = usb_submit_urb(urb, GFP_ATOMIC);
366         if (retval)
367                 dev_err(dev, "Can not submit urb for AP data: %d\n", retval);
368 }
369
370 static void cport_in_callback(struct urb *urb)
371 {
372         struct greybus_host_device *hd = urb->context;
373         struct device *dev = &urb->dev->dev;
374         struct gb_operation_msg_hdr *header;
375         int status = check_urb_status(urb);
376         int retval;
377         u16 cport_id;
378
379         if (status) {
380                 if ((status == -EAGAIN) || (status == -EPROTO))
381                         goto exit;
382                 dev_err(dev, "urb cport in error %d (dropped)\n", status);
383                 return;
384         }
385
386         if (urb->actual_length < sizeof(*header)) {
387                 dev_err(dev, "%s: short message received\n", __func__);
388                 goto exit;
389         }
390
391         /* Extract the CPort id, which is packed in the message header */
392         header = urb->transfer_buffer;
393         cport_id = gb_message_cport_unpack(header);
394
395         if (cport_id_valid(cport_id))
396                 greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
397                                                         urb->actual_length);
398         else
399                 dev_err(dev, "%s: invalid cport id 0x%02x received\n",
400                                 __func__, cport_id);
401 exit:
402         /* put our urb back in the request pool */
403         retval = usb_submit_urb(urb, GFP_ATOMIC);
404         if (retval)
405                 dev_err(dev, "%s: error %d in submitting urb.\n",
406                         __func__, retval);
407 }
408
409 static void cport_out_callback(struct urb *urb)
410 {
411         struct gb_message *message = urb->context;
412         struct greybus_host_device *hd = message->operation->connection->hd;
413         struct es1_ap_dev *es1 = hd_to_es1(hd);
414         int status = check_urb_status(urb);
415
416         gb_message_cport_clear(message->header);
417
418         /*
419          * Tell the submitter that the message send (attempt) is
420          * complete, and report the status.
421          */
422         greybus_message_sent(hd, message, status);
423
424         free_urb(es1, urb);
425 }
426
427 #define APB1_LOG_MSG_SIZE       64
428 static void apb1_log_get(struct es1_ap_dev *es1, char *buf)
429 {
430         int retval;
431
432         /* SVC messages go down our control pipe */
433         do {
434                 retval = usb_control_msg(es1->usb_dev,
435                                         usb_rcvctrlpipe(es1->usb_dev,
436                                                         es1->control_endpoint),
437                                         0x02,   /* vendor request APB1 log */
438                                         USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
439                                         0x00, 0x00,
440                                         buf,
441                                         APB1_LOG_MSG_SIZE,
442                                         ES1_TIMEOUT);
443                 if (retval > 0)
444                         kfifo_in(&apb1_log_fifo, buf, retval);
445         } while (retval > 0);
446 }
447
448 static int apb1_log_poll(void *data)
449 {
450         struct es1_ap_dev *es1 = data;
451         char *buf;
452
453         buf = kmalloc(APB1_LOG_MSG_SIZE, GFP_KERNEL);
454         if (!buf)
455                 return -ENOMEM;
456
457         while (!kthread_should_stop()) {
458                 msleep(1000);
459                 apb1_log_get(es1, buf);
460         }
461
462         kfree(buf);
463
464         return 0;
465 }
466
467 static ssize_t apb1_log_read(struct file *f, char __user *buf,
468                                 size_t count, loff_t *ppos)
469 {
470         ssize_t ret;
471         size_t copied;
472         char *tmp_buf;
473
474         if (count > APB1_LOG_SIZE)
475                 count = APB1_LOG_SIZE;
476
477         tmp_buf = kmalloc(count, GFP_KERNEL);
478         if (!tmp_buf)
479                 return -ENOMEM;
480
481         copied = kfifo_out(&apb1_log_fifo, tmp_buf, count);
482         ret = simple_read_from_buffer(buf, count, ppos, tmp_buf, copied);
483
484         kfree(tmp_buf);
485
486         return ret;
487 }
488
489 static const struct file_operations apb1_log_fops = {
490         .read   = apb1_log_read,
491 };
492
493 static void usb_log_enable(struct es1_ap_dev *es1)
494 {
495         if (!IS_ERR_OR_NULL(apb1_log_task))
496                 return;
497
498         /* get log from APB1 */
499         apb1_log_task = kthread_run(apb1_log_poll, es1, "apb1_log");
500         if (IS_ERR(apb1_log_task))
501                 return;
502         apb1_log_dentry = debugfs_create_file("apb1_log", S_IRUGO,
503                                                 gb_debugfs_get(), NULL,
504                                                 &apb1_log_fops);
505 }
506
507 static void usb_log_disable(struct es1_ap_dev *es1)
508 {
509         if (IS_ERR_OR_NULL(apb1_log_task))
510                 return;
511
512         debugfs_remove(apb1_log_dentry);
513         apb1_log_dentry = NULL;
514
515         kthread_stop(apb1_log_task);
516         apb1_log_task = NULL;
517 }
518
519 static ssize_t apb1_log_enable_read(struct file *f, char __user *buf,
520                                 size_t count, loff_t *ppos)
521 {
522         char tmp_buf[3];
523         int enable = !IS_ERR_OR_NULL(apb1_log_task);
524
525         sprintf(tmp_buf, "%d\n", enable);
526         return simple_read_from_buffer(buf, count, ppos, tmp_buf, 3);
527 }
528
529 static ssize_t apb1_log_enable_write(struct file *f, const char __user *buf,
530                                 size_t count, loff_t *ppos)
531 {
532         int enable;
533         ssize_t retval;
534         struct es1_ap_dev *es1 = (struct es1_ap_dev *)f->f_inode->i_private;
535
536         retval = kstrtoint_from_user(buf, count, 10, &enable);
537         if (retval)
538                 return retval;
539
540         if (enable)
541                 usb_log_enable(es1);
542         else
543                 usb_log_disable(es1);
544
545         return count;
546 }
547
548 static const struct file_operations apb1_log_enable_fops = {
549         .read   = apb1_log_enable_read,
550         .write  = apb1_log_enable_write,
551 };
552
553 /*
554  * The ES1 USB Bridge device contains 4 endpoints
555  * 1 Control - usual USB stuff + AP -> SVC messages
556  * 1 Interrupt IN - SVC -> AP messages
557  * 1 Bulk IN - CPort data in
558  * 1 Bulk OUT - CPort data out
559  */
560 static int ap_probe(struct usb_interface *interface,
561                     const struct usb_device_id *id)
562 {
563         struct es1_ap_dev *es1;
564         struct greybus_host_device *hd;
565         struct usb_device *udev;
566         struct usb_host_interface *iface_desc;
567         struct usb_endpoint_descriptor *endpoint;
568         bool int_in_found = false;
569         bool bulk_in_found = false;
570         bool bulk_out_found = false;
571         int retval = -ENOMEM;
572         int i;
573         u16 endo_id = 0x4755;   // FIXME - get endo "ID" from the SVC
574         u8 ap_intf_id = 0x01;   // FIXME - get endo "ID" from the SVC
575         u8 svc_interval = 0;
576
577         udev = usb_get_dev(interface_to_usbdev(interface));
578
579         hd = greybus_create_hd(&es1_driver, &udev->dev, ES1_GBUF_MSG_SIZE_MAX);
580         if (IS_ERR(hd)) {
581                 usb_put_dev(udev);
582                 return PTR_ERR(hd);
583         }
584
585         es1 = hd_to_es1(hd);
586         es1->hd = hd;
587         es1->usb_intf = interface;
588         es1->usb_dev = udev;
589         spin_lock_init(&es1->cport_out_urb_lock);
590         usb_set_intfdata(interface, es1);
591
592         /* Control endpoint is the pipe to talk to this AP, so save it off */
593         endpoint = &udev->ep0.desc;
594         es1->control_endpoint = endpoint->bEndpointAddress;
595
596         /* find all 3 of our endpoints */
597         iface_desc = interface->cur_altsetting;
598         for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
599                 endpoint = &iface_desc->endpoint[i].desc;
600
601                 if (usb_endpoint_is_int_in(endpoint)) {
602                         es1->svc_endpoint = endpoint->bEndpointAddress;
603                         svc_interval = endpoint->bInterval;
604                         int_in_found = true;
605                 } else if (usb_endpoint_is_bulk_in(endpoint)) {
606                         es1->cport_in_endpoint = endpoint->bEndpointAddress;
607                         bulk_in_found = true;
608                 } else if (usb_endpoint_is_bulk_out(endpoint)) {
609                         es1->cport_out_endpoint = endpoint->bEndpointAddress;
610                         bulk_out_found = true;
611                 } else {
612                         dev_err(&udev->dev,
613                                 "Unknown endpoint type found, address %x\n",
614                                 endpoint->bEndpointAddress);
615                 }
616         }
617         if ((int_in_found == false) ||
618             (bulk_in_found == false) ||
619             (bulk_out_found == false)) {
620                 dev_err(&udev->dev, "Not enough endpoints found in device, aborting!\n");
621                 goto error;
622         }
623
624         /* Create our buffer and URB to get SVC messages, and start it up */
625         es1->svc_buffer = kmalloc(ES1_SVC_MSG_SIZE, GFP_KERNEL);
626         if (!es1->svc_buffer)
627                 goto error;
628
629         es1->svc_urb = usb_alloc_urb(0, GFP_KERNEL);
630         if (!es1->svc_urb)
631                 goto error;
632
633         usb_fill_int_urb(es1->svc_urb, udev,
634                          usb_rcvintpipe(udev, es1->svc_endpoint),
635                          es1->svc_buffer, ES1_SVC_MSG_SIZE, svc_in_callback,
636                          hd, svc_interval);
637
638         /* Allocate buffers for our cport in messages and start them up */
639         for (i = 0; i < NUM_CPORT_IN_URB; ++i) {
640                 struct urb *urb;
641                 u8 *buffer;
642
643                 urb = usb_alloc_urb(0, GFP_KERNEL);
644                 if (!urb)
645                         goto error;
646                 buffer = kmalloc(ES1_GBUF_MSG_SIZE_MAX, GFP_KERNEL);
647                 if (!buffer)
648                         goto error;
649
650                 usb_fill_bulk_urb(urb, udev,
651                                   usb_rcvbulkpipe(udev, es1->cport_in_endpoint),
652                                   buffer, ES1_GBUF_MSG_SIZE_MAX,
653                                   cport_in_callback, hd);
654                 es1->cport_in_urb[i] = urb;
655                 es1->cport_in_buffer[i] = buffer;
656                 retval = usb_submit_urb(urb, GFP_KERNEL);
657                 if (retval)
658                         goto error;
659         }
660
661         /* Allocate urbs for our CPort OUT messages */
662         for (i = 0; i < NUM_CPORT_OUT_URB; ++i) {
663                 struct urb *urb;
664
665                 urb = usb_alloc_urb(0, GFP_KERNEL);
666                 if (!urb)
667                         goto error;
668
669                 es1->cport_out_urb[i] = urb;
670                 es1->cport_out_urb_busy[i] = false;     /* just to be anal */
671         }
672
673         /* Start up our svc urb, which allows events to start flowing */
674         retval = usb_submit_urb(es1->svc_urb, GFP_KERNEL);
675         if (retval)
676                 goto error;
677
678         apb1_log_enable_dentry = debugfs_create_file("apb1_log_enable",
679                                                         (S_IWUSR | S_IRUGO),
680                                                         gb_debugfs_get(), es1,
681                                                         &apb1_log_enable_fops);
682
683         /*
684          * XXX Soon this will be initiated later, with a combination
685          * XXX of a Control protocol probe operation and a
686          * XXX subsequent Control protocol connected operation for
687          * XXX the SVC connection.  At that point we know we're
688          * XXX properly connected to an Endo.
689          */
690         retval = greybus_endo_setup(hd, endo_id, ap_intf_id);
691         if (retval)
692                 goto error;
693
694         return 0;
695 error:
696         ap_disconnect(interface);
697
698         return retval;
699 }
700
701 static struct usb_driver es1_ap_driver = {
702         .name =         "es2_ap_driver",
703         .probe =        ap_probe,
704         .disconnect =   ap_disconnect,
705         .id_table =     id_table,
706 };
707
708 module_usb_driver(es1_ap_driver);
709
710 MODULE_LICENSE("GPL v2");
711 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");