Skip to content

Commit

Permalink
usb: gadget: remove usb_gadget_controller_number()
Browse files Browse the repository at this point in the history
The bcdDevice field is defined as
|Device release number in binary-coded decimal
in the USB 2.0 specification. We use this field to distinguish the UDCs
from each other. In theory this could be used on the host side to apply
certain quirks if the "special" UDC in combination with this gadget is
used. This hasn't been done as far as I am aware. In practice it would
be better to fix the UDC driver before shipping since a later release
might not need this quirk anymore.

There are some driver in tree (on the host side) which use the bcdDevice
field to figure out special workarounds for a given firmware revision.
This seems to make sense. Therefore this patch converts all gadgets
(except a few) to use the kernel version instead a random 2 or 3 plus
the UDC number. The few that don't report kernel's version are:
- webcam
  This one reports always a version 0x10 so allow it to do so in future.
- nokia
  This one reports always 0x211. The comment says that this gadget works
  only if the UDC supports altsettings so I added a check for this.
- serial
  This one reports 0x2400 + UDC number. Since the gadget version is 2.4
  this could make sense. Therefore bcdDevice is 0x2400 here.

I also remove various gadget_is_<name> macros which are unused. The
remaining few macros should be moved to feature / bug bitfield.

Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Sep 10, 2012
1 parent 9c6d196 commit ed9cbda
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 311 deletions.
2 changes: 1 addition & 1 deletion drivers/usb/gadget/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
obj-$(CONFIG_USB_GADGET) += udc-core.o
obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
libcomposite-y := usbstring.o config.o epautoconf.o
libcomposite-y += gadget_chips.o composite.o
libcomposite-y += composite.o
obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
obj-$(CONFIG_USB_NET2272) += net2272.o
obj-$(CONFIG_USB_NET2280) += net2280.o
Expand Down
13 changes: 0 additions & 13 deletions drivers/usb/gadget/acm_ms.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ static struct usb_configuration acm_ms_config_driver = {

static int __init acm_ms_bind(struct usb_composite_dev *cdev)
{
int gcnum;
struct usb_gadget *gadget = cdev->gadget;
int status;
void *retp;
Expand All @@ -165,18 +164,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
goto fail0;
}

/* set bcdDevice */
gcnum = usb_gadget_controller_number(gadget);
if (gcnum >= 0) {
device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
} else {
WARNING(cdev, "controller '%s' not recognized; trying %s\n",
gadget->name,
acm_ms_config_driver.label);
device_desc.bcdDevice =
cpu_to_le16(0x0300 | 0x0099);
}

/*
* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue.
Expand Down
12 changes: 0 additions & 12 deletions drivers/usb/gadget/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,8 @@ static struct usb_configuration audio_config_driver = {

static int __init audio_bind(struct usb_composite_dev *cdev)
{
int gcnum;
int status;

gcnum = usb_gadget_controller_number(cdev->gadget);
if (gcnum >= 0)
device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
else {
ERROR(cdev, "controller '%s' not recognized; trying %s\n",
cdev->gadget->name,
audio_config_driver.label);
device_desc.bcdDevice =
__constant_cpu_to_le16(0x0300 | 0x0099);
}

status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0)
goto fail;
Expand Down
16 changes: 0 additions & 16 deletions drivers/usb/gadget/cdc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ static struct usb_configuration cdc_config_driver = {

static int __init cdc_bind(struct usb_composite_dev *cdev)
{
int gcnum;
struct usb_gadget *gadget = cdev->gadget;
int status;

Expand All @@ -163,21 +162,6 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
if (status < 0)
goto fail0;

gcnum = usb_gadget_controller_number(gadget);
if (gcnum >= 0)
device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
else {
/* We assume that can_support_ecm() tells the truth;
* but if the controller isn't recognized at all then
* that assumption is a bit more likely to be wrong.
*/
WARNING(cdev, "controller '%s' not recognized; trying %s\n",
gadget->name,
cdc_config_driver.label);
device_desc.bcdDevice =
cpu_to_le16(0x0300 | 0x0099);
}

/* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue.
*/
Expand Down
2 changes: 2 additions & 0 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,8 @@ static void update_unchanged_dev_desc(struct usb_device_descriptor *new,
new->idProduct = idProduct;
if (bcdDevice)
new->bcdDevice = bcdDevice;
else
new->bcdDevice = cpu_to_le16(get_default_bcdDevice());
if (iSerialNumber)
new->iSerialNumber = iSerialNumber;
if (iManufacturer)
Expand Down
17 changes: 0 additions & 17 deletions drivers/usb/gadget/ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ static struct usb_configuration eth_config_driver = {

static int __init eth_bind(struct usb_composite_dev *cdev)
{
int gcnum;
struct usb_gadget *gadget = cdev->gadget;
int status;

Expand Down Expand Up @@ -310,22 +309,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
device_desc.bNumConfigurations = 2;
}

gcnum = usb_gadget_controller_number(gadget);
if (gcnum >= 0)
device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
else {
/* We assume that can_support_ecm() tells the truth;
* but if the controller isn't recognized at all then
* that assumption is a bit more likely to be wrong.
*/
dev_warn(&gadget->dev,
"controller '%s' not recognized; trying %s\n",
gadget->name,
eth_config_driver.label);
device_desc.bcdDevice =
cpu_to_le16(0x0300 | 0x0099);
}

/* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue.
*/
Expand Down
15 changes: 1 addition & 14 deletions drivers/usb/gadget/f_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ struct fsg_config {

const char *vendor_name; /* 8 characters or less */
const char *product_name; /* 16 characters or less */
u16 release;

char can_stall;
};
Expand Down Expand Up @@ -2772,18 +2771,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
bh->next = common->buffhds;

/* Prepare inquiryString */
if (cfg->release != 0xffff) {
i = cfg->release;
} else {
i = usb_gadget_controller_number(gadget);
if (i >= 0) {
i = 0x0300 + i;
} else {
WARNING(common, "controller '%s' not recognized\n",
gadget->name);
i = 0x0399;
}
}
i = get_default_bcdDevice();
snprintf(common->inquiry_string, sizeof common->inquiry_string,
"%-8s%-16s%04x", cfg->vendor_name ?: "Linux",
/* Assume product name dependent on the first LUN */
Expand Down Expand Up @@ -3109,7 +3097,6 @@ fsg_config_from_params(struct fsg_config *cfg,
/* Let MSF use defaults */
cfg->vendor_name = 0;
cfg->product_name = 0;
cfg->release = 0xffff;

cfg->ops = NULL;
cfg->private_data = NULL;
Expand Down
14 changes: 3 additions & 11 deletions drivers/usb/gadget/file_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
#include <linux/freezer.h>
#include <linux/utsname.h>

#include <linux/usb/composite.h>
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>

Expand Down Expand Up @@ -3198,7 +3199,6 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
static int __init check_parameters(struct fsg_dev *fsg)
{
int prot;
int gcnum;

/* Store the default values */
mod_data.transport_type = USB_PR_BULK;
Expand All @@ -3213,16 +3213,8 @@ static int __init check_parameters(struct fsg_dev *fsg)
if (gadget_is_at91(fsg->gadget))
mod_data.can_stall = 0;

if (mod_data.release == 0xffff) { // Parameter wasn't set
gcnum = usb_gadget_controller_number(fsg->gadget);
if (gcnum >= 0)
mod_data.release = 0x0300 + gcnum;
else {
WARNING(fsg, "controller '%s' not recognized\n",
fsg->gadget->name);
mod_data.release = 0x0399;
}
}
if (mod_data.release == 0xffff)
mod_data.release = get_default_bcdDevice();

prot = simple_strtol(mod_data.protocol_parm, NULL, 0);

Expand Down
94 changes: 0 additions & 94 deletions drivers/usb/gadget/gadget_chips.c

This file was deleted.

23 changes: 0 additions & 23 deletions drivers/usb/gadget/gadget_chips.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,12 @@
* If you have forgotten the alphabetical order let VIM/EMACS
* do that for you.
*/
#define gadget_is_amd5536udc(g) (!strcmp("amd5536udc", (g)->name))
#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name))
#define gadget_is_atmel_usba(g) (!strcmp("atmel_usba_udc", (g)->name))
#define gadget_is_bcm63xx(g) (!strcmp("bcm63xx_udc", (g)->name))
#define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name))
#define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name))
#define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name))
#define gadget_is_dwc3(g) (!strcmp("dwc3-gadget", (g)->name))
#define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name))
#define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name))
#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name))
#define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name))
#define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name))
#define gadget_is_lpc32xx(g) (!strcmp("lpc32xx_udc", (g)->name))
#define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name))
#define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name))
#define gadget_is_net2272(g) (!strcmp("net2272", (g)->name))
#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name))
#define gadget_is_omap(g) (!strcmp("omap_udc", (g)->name))
#define gadget_is_pch(g) (!strcmp("pch_udc", (g)->name))
#define gadget_is_pxa(g) (!strcmp("pxa25x_udc", (g)->name))
#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name))
#define gadget_is_r8a66597(g) (!strcmp("r8a66597_udc", (g)->name))
#define gadget_is_renesas_usbhs(g) (!strcmp("renesas_usbhs_udc", (g)->name))
#define gadget_is_s3c2410(g) (!strcmp("s3c2410_udc", (g)->name))
#define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
#define gadget_is_s3c_hsudc(g) (!strcmp("s3c-hsudc", (g)->name))

int usb_gadget_controller_number(struct usb_gadget *gadget);

/**
* gadget_supports_altsettings - return true if altsettings work
Expand Down
16 changes: 1 addition & 15 deletions drivers/usb/gadget/gmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ static int __init midi_bind_config(struct usb_configuration *c)

static int __init midi_bind(struct usb_composite_dev *cdev)
{
struct usb_gadget *gadget = cdev->gadget;
int gcnum, status;
int status;

status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0)
Expand All @@ -147,19 +146,6 @@ static int __init midi_bind(struct usb_composite_dev *cdev)
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;

gcnum = usb_gadget_controller_number(gadget);
if (gcnum < 0) {
/* gmidi is so simple (no altsettings) that
* it SHOULD NOT have problems with bulk-capable hardware.
* so warn about unrecognized controllers, don't panic.
*/
pr_warning("%s: controller '%s' not recognized\n",
__func__, gadget->name);
device_desc.bcdDevice = cpu_to_le16(0x9999);
} else {
device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
}

status = usb_add_config(cdev, &midi_config, midi_bind_config);
if (status < 0)
return status;
Expand Down
8 changes: 1 addition & 7 deletions drivers/usb/gadget/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
{
struct usb_gadget *gadget = cdev->gadget;
struct list_head *tmp;
int status, gcnum, funcs = 0;
int status, funcs = 0;

list_for_each(tmp, &hidg_func_list)
funcs++;
Expand All @@ -156,12 +156,6 @@ static int __init hid_bind(struct usb_composite_dev *cdev)
if (status < 0)
return status;

gcnum = usb_gadget_controller_number(gadget);
if (gcnum >= 0)
device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
else
device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);

/* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue.
*/
Expand Down
Loading

0 comments on commit ed9cbda

Please sign in to comment.