From dc0438f2188c8b4de7569ce4f9ed6d221acc27c3 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Tue, 12 Jan 2010 10:33:59 -0800 Subject: [PATCH] USB: gadget: android: android USB gadget improvements: usb: gadget: f_mass_storage: use dev_set_name() Replacing strcpy() to device->bus_id which no longer exists in 2.6.32 Change-Id: Id978c881f457044c750bfd62f4c5bcc35bcd4fc5 Signed-off-by: Mike Lockwood USB: gadget: f_adb: Claim endpoints so they are not reused by another function. Change-Id: Ic9536cca800162e701c81cab36054f51ea759b72 Signed-off-by: Mike Lockwood USB: gadget: f_acm: Fix crashes in acm_set_alt() Change-Id: I91b761d392f8b1ca8784c69069b43e402b90d6a4 Signed-off-by: Mike Lockwood USB: gadget: f_acm: Include android code only if CONFIG_USB_ANDROID_ACM is set. Signed-off-by: Mike Lockwood USB: gadget: Android support for RNDIS serial ethernet function. Signed-off-by: Mike Lockwood USB: gadget: android: Add function name to android_register_function printk. Change-Id: I38bf79d9b544cdeaec9385f7482a131417fc4b23 Signed-off-by: Mike Lockwood --- drivers/usb/gadget/Kconfig | 14 +++++--- drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/android.c | 2 +- drivers/usb/gadget/f_acm.c | 21 +++++++----- drivers/usb/gadget/f_adb.c | 2 ++ drivers/usb/gadget/f_mass_storage_tmp.c | 6 ++-- drivers/usb/gadget/f_rndis.c | 45 +++++++++++++++++++++---- drivers/usb/gadget/u_ether.h | 2 +- 8 files changed, 68 insertions(+), 25 deletions(-) diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 3703e7e07242..977fe76de6e7 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -846,22 +846,28 @@ config USB_ANDROID enabled and disabled dynamically. config USB_ANDROID_ACM - boolean "Android gadget ACM function" + boolean "Android gadget ACM serial function" depends on USB_ANDROID help - Provides adb function for adb gadget driver. + Provides ACM serial function for android gadget driver. config USB_ANDROID_ADB boolean "Android gadget adb function" depends on USB_ANDROID help - Provides adb function for adb gadget driver. + Provides adb function for android gadget driver. config USB_ANDROID_MASS_STORAGE boolean "Android gadget mass storage function" depends on USB_ANDROID && SWITCH help - Provides USB mass storage function for adb gadget driver. + Provides USB mass storage function for android gadget driver. + +config USB_ANDROID_RNDIS + boolean "Android gadget RNDIS ethernet function" + depends on USB_ANDROID + help + Provides RNDIS ethernet function for android gadget driver. config USB_CDC_COMPOSITE tristate "CDC Composite Device (Ethernet and ACM)" diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index ae968c84816b..dad49e306654 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -68,4 +68,5 @@ obj-$(CONFIG_USB_ANDROID) += android.o obj-$(CONFIG_USB_ANDROID_ACM) += f_acm.o u_serial.o obj-$(CONFIG_USB_ANDROID_ADB) += f_adb.o obj-$(CONFIG_USB_ANDROID_MASS_STORAGE) += f_mass_storage_tmp.o +obj-$(CONFIG_USB_ANDROID_RNDIS) += f_rndis.o u_ether.o diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index d10568ef8940..ce7426be487d 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -305,7 +305,7 @@ void android_register_function(struct android_usb_function *f) { struct android_dev *dev = _android_dev; - printk(KERN_INFO "android_register_function\n"); + printk(KERN_INFO "android_register_function %s\n", f->name); list_add_tail(&f->list, &_functions); _registered_function_count++; diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index 2ccf8b20f0b9..e3e5410d922f 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c @@ -17,10 +17,10 @@ #include #include #include +#include #include "u_serial.h" #include "gadget_chips.h" -#include "linux/usb/android_composite.h" /* @@ -406,10 +406,10 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) usb_ep_disable(acm->notify); } else { VDBG(cdev, "init acm ctrl interface %d\n", intf); - acm->notify_desc = ep_choose(cdev->gadget, - acm->hs.notify, - acm->fs.notify); } + acm->notify_desc = ep_choose(cdev->gadget, + acm->hs.notify, + acm->fs.notify); usb_ep_enable(acm->notify, acm->notify_desc); acm->notify->driver_data = acm; @@ -419,11 +419,11 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) gserial_disconnect(&acm->port); } else { DBG(cdev, "activate acm ttyGS%d\n", acm->port_num); - acm->port.in_desc = ep_choose(cdev->gadget, - acm->hs.in, acm->fs.in); - acm->port.out_desc = ep_choose(cdev->gadget, - acm->hs.out, acm->fs.out); } + acm->port.in_desc = ep_choose(cdev->gadget, + acm->hs.in, acm->fs.in); + acm->port.out_desc = ep_choose(cdev->gadget, + acm->hs.out, acm->fs.out); gserial_connect(&acm->port, acm->port_num); } else @@ -784,6 +784,8 @@ int acm_bind_config(struct usb_configuration *c, u8 port_num) return status; } +#ifdef CONFIG_USB_ANDROID_ACM + int acm_function_bind_config(struct usb_configuration *c) { int ret = acm_bind_config(c, 0); @@ -799,7 +801,10 @@ static struct android_usb_function acm_function = { static int __init init(void) { + printk(KERN_INFO "f_acm init\n"); android_register_function(&acm_function); return 0; } module_init(init); + +#endif /* CONFIG_USB_ANDROID_ACM */ diff --git a/drivers/usb/gadget/f_adb.c b/drivers/usb/gadget/f_adb.c index d1afe0ed1ec8..301300e04cab 100644 --- a/drivers/usb/gadget/f_adb.c +++ b/drivers/usb/gadget/f_adb.c @@ -235,6 +235,7 @@ static int __init create_bulk_endpoints(struct adb_dev *dev, return -ENODEV; } DBG(cdev, "usb_ep_autoconfig for ep_in got %s\n", ep->name); + ep->driver_data = dev; /* claim the endpoint */ dev->ep_in = ep; ep = usb_ep_autoconfig(cdev->gadget, out_desc); @@ -243,6 +244,7 @@ static int __init create_bulk_endpoints(struct adb_dev *dev, return -ENODEV; } DBG(cdev, "usb_ep_autoconfig for adb ep_out got %s\n", ep->name); + ep->driver_data = dev; /* claim the endpoint */ dev->ep_out = ep; /* now allocate requests for our endpoints */ diff --git a/drivers/usb/gadget/f_mass_storage_tmp.c b/drivers/usb/gadget/f_mass_storage_tmp.c index 79044f72652c..065448a8dd79 100644 --- a/drivers/usb/gadget/f_mass_storage_tmp.c +++ b/drivers/usb/gadget/f_mass_storage_tmp.c @@ -69,10 +69,9 @@ #include #include +#include #include #include -#include -#include #include #include "gadget_chips.h" @@ -2756,8 +2755,7 @@ fsg_function_bind(struct usb_configuration *c, struct usb_function *f) else curlun->dev.parent = &cdev->gadget->dev; dev_set_drvdata(&curlun->dev, fsg); - snprintf(curlun->dev.bus_id, BUS_ID_SIZE, - "lun%d", i); + dev_set_name(&curlun->dev,"lun%d", i); rc = device_register(&curlun->dev); if (rc != 0) { diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 882484a40398..31f29dc14bbe 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -487,10 +488,10 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt) usb_ep_disable(rndis->notify); } else { VDBG(cdev, "init rndis ctrl %d\n", intf); - rndis->notify_desc = ep_choose(cdev->gadget, - rndis->hs.notify, - rndis->fs.notify); } + rndis->notify_desc = ep_choose(cdev->gadget, + rndis->hs.notify, + rndis->fs.notify); usb_ep_enable(rndis->notify, rndis->notify_desc); rndis->notify->driver_data = rndis; @@ -504,11 +505,11 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt) if (!rndis->port.in) { DBG(cdev, "init rndis\n"); - rndis->port.in = ep_choose(cdev->gadget, - rndis->hs.in, rndis->fs.in); - rndis->port.out = ep_choose(cdev->gadget, - rndis->hs.out, rndis->fs.out); } + rndis->port.in = ep_choose(cdev->gadget, + rndis->hs.in, rndis->fs.in); + rndis->port.out = ep_choose(cdev->gadget, + rndis->hs.out, rndis->fs.out); /* Avoid ZLPs; they can be troublesome. */ rndis->port.is_zlp_ok = false; @@ -858,3 +859,33 @@ fail: } return status; } + +#ifdef CONFIG_USB_ANDROID_RNDIS +#include "rndis.c" + +// FIXME - using bogus MAC address for now + +static u8 ethaddr[ETH_ALEN] = { 11, 22, 33, 44, 55, 66 }; + +int rndis_function_bind_config(struct usb_configuration *c) +{ + int ret = gether_setup(c->cdev->gadget, ethaddr); + if (ret == 0) + ret = rndis_bind_config(c, ethaddr); + return ret; +} + +static struct android_usb_function rndis_function = { + .name = "rndis", + .bind_config = rndis_function_bind_config, +}; + +static int __init init(void) +{ + printk(KERN_INFO "f_rndis init\n"); + android_register_function(&rndis_function); + return 0; +} +module_init(init); + +#endif /* CONFIG_USB_ANDROID_RNDIS */ diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 3c8c0c9f9d72..99e4aa3b1374 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h @@ -105,7 +105,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); int eem_bind_config(struct usb_configuration *c); -#ifdef USB_ETH_RNDIS +#if defined(USB_ETH_RNDIS) || defined(CONFIG_USB_ANDROID_RNDIS) int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); -- 2.34.1