Greg Kroah-Hartman | ba4468d4 | 2014-08-30 17:06:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Greybus "AP" USB driver |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 6 | * Released under the GPLv2 only. |
| 7 | */ |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/usb.h> |
| 13 | |
| 14 | |
| 15 | static const struct usb_device_id id_table[] = { |
| 16 | { USB_DEVICE(0x0000, 0x0000) }, // FIXME |
| 17 | { }, |
| 18 | }; |
| 19 | MODULE_DEVICE_TABLE(usb, id_table); |
| 20 | |
Greg Kroah-Hartman | 6f83ab7 | 2014-08-30 17:30:04 -0700 | [diff] [blame^] | 21 | struct es1_ap_dev { |
| 22 | struct usb_device *usb_dev; |
| 23 | struct usb_interface *usb_intf; |
| 24 | |
| 25 | __u8 ap_in_endpoint; |
| 26 | __u8 ap_out_endpoint; |
| 27 | u8 *ap_buffer; |
| 28 | |
| 29 | }; |
| 30 | |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Hack, we "know" we will only have one of these at any one time, so only |
| 33 | * create one static structure pointer. |
| 34 | */ |
Greg Kroah-Hartman | 6f83ab7 | 2014-08-30 17:30:04 -0700 | [diff] [blame^] | 35 | static struct es1_ap_dev *es1_ap_dev; |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 36 | |
Greg Kroah-Hartman | ba4468d4 | 2014-08-30 17:06:54 -0700 | [diff] [blame] | 37 | |
| 38 | static int ap_probe(struct usb_interface *interface, |
| 39 | const struct usb_device_id *id) |
| 40 | { |
Greg Kroah-Hartman | 6f83ab7 | 2014-08-30 17:30:04 -0700 | [diff] [blame^] | 41 | struct usb_host_interface *iface_desc; |
| 42 | struct usb_endpoint_descriptor *endpoint; |
| 43 | size_t buffer_size; |
| 44 | int i; |
| 45 | |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 46 | if (es1_ap_dev) { |
| 47 | dev_err(&interface->dev, "Already have a es1_ap_dev???\n"); |
| 48 | return -ENODEV; |
| 49 | } |
| 50 | es1_ap_dev = kzalloc(sizeof(*es1_ap_dev), GFP_KERNEL); |
| 51 | if (!es1_ap_dev) |
| 52 | return -ENOMEM; |
Greg Kroah-Hartman | ba4468d4 | 2014-08-30 17:06:54 -0700 | [diff] [blame] | 53 | |
Greg Kroah-Hartman | 6f83ab7 | 2014-08-30 17:30:04 -0700 | [diff] [blame^] | 54 | // FIXME |
| 55 | // figure out endpoint for talking to the AP. |
| 56 | iface_desc = interface->cur_altsetting; |
| 57 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
| 58 | endpoint = &iface_desc->endpoint[i].desc; |
| 59 | |
| 60 | if (usb_endpoint_is_bulk_in(endpoint)) { |
| 61 | buffer_size = usb_endpoint_maxp(endpoint); |
| 62 | // FIXME - Save buffer_size? |
| 63 | es1_ap_dev->ap_in_endpoint = endpoint->bEndpointAddress; |
| 64 | } |
| 65 | if (usb_endpoint_is_bulk_out(endpoint)) { |
| 66 | // FIXME - anything else about this we need? |
| 67 | es1_ap_dev->ap_out_endpoint = endpoint->bEndpointAddress; |
| 68 | } |
| 69 | // FIXME - properly exit once found the AP endpoint |
| 70 | // FIXME - set up cport endpoints |
| 71 | } |
| 72 | |
| 73 | // FIXME - allocate buffer |
| 74 | // FIXME = start up talking, then create the gb "devices" based on what the AP tells us. |
| 75 | |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 76 | es1_ap_dev->usb_intf = interface; |
Greg Kroah-Hartman | 6f83ab7 | 2014-08-30 17:30:04 -0700 | [diff] [blame^] | 77 | es1_ap_dev->usb_dev = usb_get_dev(interface_to_usbdev(interface)); |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 78 | usb_set_intfdata(interface, es1_ap_dev); |
Greg Kroah-Hartman | ba4468d4 | 2014-08-30 17:06:54 -0700 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static void ap_disconnect(struct usb_interface *interface) |
| 83 | { |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 84 | es1_ap_dev = usb_get_intfdata(interface); |
Greg Kroah-Hartman | ba4468d4 | 2014-08-30 17:06:54 -0700 | [diff] [blame] | 85 | |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 86 | /* Tear down everything! */ |
| 87 | |
Greg Kroah-Hartman | 6f83ab7 | 2014-08-30 17:30:04 -0700 | [diff] [blame^] | 88 | usb_put_dev(es1_ap_dev->usb_dev); |
| 89 | kfree(es1_ap_dev->ap_buffer); |
Greg Kroah-Hartman | f1eec30 | 2014-08-30 17:18:14 -0700 | [diff] [blame] | 90 | kfree(es1_ap_dev); |
| 91 | es1_ap_dev = NULL; |
Greg Kroah-Hartman | ba4468d4 | 2014-08-30 17:06:54 -0700 | [diff] [blame] | 92 | |
| 93 | } |
| 94 | |
| 95 | static struct usb_driver es1_ap_driver = { |
| 96 | .name = "es1_ap_driver", |
| 97 | .probe = ap_probe, |
| 98 | .disconnect = ap_disconnect, |
| 99 | .id_table = id_table, |
| 100 | }; |
| 101 | |
| 102 | module_usb_driver(es1_ap_driver); |
| 103 | |
| 104 | MODULE_LICENSE("GPL"); |
| 105 | MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>"); |