blob: bebef6dbae7b28857ad8badd06e02290e19342d3 [file] [log] [blame]
Greg Kroah-Hartmanba4468d42014-08-30 17:06:54 -07001/*
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
15static const struct usb_device_id id_table[] = {
16 { USB_DEVICE(0x0000, 0x0000) }, // FIXME
17 { },
18};
19MODULE_DEVICE_TABLE(usb, id_table);
20
Greg Kroah-Hartman6f83ab72014-08-30 17:30:04 -070021struct 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-Hartmanf1eec302014-08-30 17:18:14 -070031/*
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-Hartman6f83ab72014-08-30 17:30:04 -070035static struct es1_ap_dev *es1_ap_dev;
Greg Kroah-Hartmanf1eec302014-08-30 17:18:14 -070036
Greg Kroah-Hartmanba4468d42014-08-30 17:06:54 -070037
38static int ap_probe(struct usb_interface *interface,
39 const struct usb_device_id *id)
40{
Greg Kroah-Hartman6f83ab72014-08-30 17:30:04 -070041 struct usb_host_interface *iface_desc;
42 struct usb_endpoint_descriptor *endpoint;
43 size_t buffer_size;
44 int i;
45
Greg Kroah-Hartmanf1eec302014-08-30 17:18:14 -070046 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-Hartmanba4468d42014-08-30 17:06:54 -070053
Greg Kroah-Hartman6f83ab72014-08-30 17:30:04 -070054 // 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-Hartmanf1eec302014-08-30 17:18:14 -070076 es1_ap_dev->usb_intf = interface;
Greg Kroah-Hartman6f83ab72014-08-30 17:30:04 -070077 es1_ap_dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
Greg Kroah-Hartmanf1eec302014-08-30 17:18:14 -070078 usb_set_intfdata(interface, es1_ap_dev);
Greg Kroah-Hartmanba4468d42014-08-30 17:06:54 -070079 return 0;
80}
81
82static void ap_disconnect(struct usb_interface *interface)
83{
Greg Kroah-Hartmanf1eec302014-08-30 17:18:14 -070084 es1_ap_dev = usb_get_intfdata(interface);
Greg Kroah-Hartmanba4468d42014-08-30 17:06:54 -070085
Greg Kroah-Hartmanf1eec302014-08-30 17:18:14 -070086 /* Tear down everything! */
87
Greg Kroah-Hartman6f83ab72014-08-30 17:30:04 -070088 usb_put_dev(es1_ap_dev->usb_dev);
89 kfree(es1_ap_dev->ap_buffer);
Greg Kroah-Hartmanf1eec302014-08-30 17:18:14 -070090 kfree(es1_ap_dev);
91 es1_ap_dev = NULL;
Greg Kroah-Hartmanba4468d42014-08-30 17:06:54 -070092
93}
94
95static 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
102module_usb_driver(es1_ap_driver);
103
104MODULE_LICENSE("GPL");
105MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");