On Thu, Sep 09, 2010 at 07:23:13AM -0500, Balbi, Felipe wrote:
On Thu, Sep 09, 2010 at 06:08:11AM -0500, Balbi, Felipe wrote:
Hi Matthieu,
On Thu, Sep 09, 2010 at 04:17:34AM -0500, Matthieu CASTET wrote:
For information I am developing a something similar
for allowing building more than one controller in kernel.
My patch is much simpler, but it does only that.
yeah, I saw that now. It also doesn't work if you have a board with two
gadget controllers, right ?
I wanted to abstract most of the stuff, so we can add an atomic notifier
sending information about the gadget to whoever is interested. Charger
chips wants to know when the gadget is enumerated so they can fix the
input current to USB charging (for example).
I will have a look to your proposal.
the version attached probably has more to see, it shows better the
approach, I think.
Dave, if you have any tips on how I should link struct usb_gadget and
struct usb_composite_dev I would be glad to hear. I can't of anything
other than saving a pointer to usb_composite_dev inside usb_gadget,
since with this gadget->dev->drvdata contains a gadget and not a cdev.
what I mean is something like below:
8<------------------------------------------------------------------------------
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 1f5ba2f..aa9e103 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -166,7 +166,7 @@ static int __ref cdc_bind(struct usb_composite_dev *cdev)
int status;
if (!can_support_ecm(cdev->gadget)) {
- dev_err(&gadget->dev, "controller '%s' not usable\n",
+ dev_err(gadget->dev, "controller '%s' not usable\n",
gadget->name);
return -EINVAL;
}
@@ -222,7 +222,7 @@ static int __ref cdc_bind(struct usb_composite_dev *cdev)
if (status < 0)
goto fail1;
- dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
+ dev_info(gadget->dev, "%s, version: " DRIVER_VERSION "\n",
DRIVER_DESC);
return 0;
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1160c55..985c89e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -770,7 +770,7 @@ static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
static int
composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
{
- struct usb_composite_dev *cdev = get_gadget_data(gadget);
+ struct usb_composite_dev *cdev = gadget->cdev;
struct usb_request *req = cdev->req;
int value = -EOPNOTSUPP;
u16 w_index = le16_to_cpu(ctrl->wIndex);
@@ -947,7 +947,7 @@ done:
static void composite_disconnect(struct usb_gadget *gadget)
{
- struct usb_composite_dev *cdev = get_gadget_data(gadget);
+ struct usb_composite_dev *cdev = gadget->cdev;
unsigned long flags;
/* REVISIT: should we have config and device level
@@ -967,8 +967,8 @@ static ssize_t composite_show_suspended(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- struct usb_gadget *gadget = dev_to_usb_gadget(dev);
- struct usb_composite_dev *cdev = get_gadget_data(gadget);
+ struct usb_gadget *gadget = dev_get_drvdata(dev);
+ struct usb_composite_dev *cdev = gadget->cdev;
return sprintf(buf, "%d\n", cdev->suspended);
}
@@ -978,7 +978,7 @@ static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
static void
composite_unbind(struct usb_gadget *gadget)
{
- struct usb_composite_dev *cdev = get_gadget_data(gadget);
+ struct usb_composite_dev *cdev = gadget->cdev;
/* composite_disconnect() must already have been called
* by the underlying peripheral controller driver!
@@ -1021,7 +1021,7 @@ composite_unbind(struct usb_gadget *gadget)
}
kfree(cdev);
set_gadget_data(gadget, NULL);
- device_remove_file(&gadget->dev, &dev_attr_suspended);
+ device_remove_file(gadget->dev, &dev_attr_suspended);
composite = NULL;
}
@@ -1057,6 +1057,7 @@ static int composite_bind(struct usb_gadget *gadget)
return status;
spin_lock_init(&cdev->lock);
+ gadget->cdev = cdev;
cdev->gadget = gadget;
set_gadget_data(gadget, cdev);
INIT_LIST_HEAD(&cdev->configs);
@@ -1114,7 +1115,7 @@ static int composite_bind(struct usb_gadget *gadget)
string_override(composite->strings,
cdev->desc.iSerialNumber, iSerialNumber);
- status = device_create_file(&gadget->dev, &dev_attr_suspended);
+ status = device_create_file(gadget->dev, &dev_attr_suspended);
if (status)
goto fail;
@@ -1131,7 +1132,7 @@ fail:
static void
composite_suspend(struct usb_gadget *gadget)
{
- struct usb_composite_dev *cdev = get_gadget_data(gadget);
+ struct usb_composite_dev *cdev = gadget->cdev;
struct usb_function *f;
/* REVISIT: should we have config level
@@ -1153,7 +1154,7 @@ composite_suspend(struct usb_gadget *gadget)
static void
composite_resume(struct usb_gadget *gadget)
{
- struct usb_composite_dev *cdev = get_gadget_data(gadget);
+ struct usb_composite_dev *cdev = gadget->cdev;
struct usb_function *f;
/* REVISIT: should we have config level
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index 0ed50a2..4beadc0 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -128,7 +128,7 @@ release_req:
usb_ep_free_request(dbgp.o_ep, req);
dbgp_disable_ep();
fail:
- dev_dbg(&dbgp.gadget->dev,
+ dev_dbg(dbgp.gadget->dev,
"complete: failure (%d:%d) ==> %d\n", stp, err, status);
}
@@ -166,7 +166,7 @@ fail_3:
fail_2:
usb_ep_free_request(dbgp.o_ep, req);
fail_1:
- dev_dbg(&dbgp.gadget->dev,
+ dev_dbg(dbgp.gadget->dev,
"enable ep req: failure (%d:%d)\n", stp, err);
return err;
}
@@ -207,7 +207,7 @@ fail_3:
fail_2:
__disable_ep(dbgp.i_ep);
fail_1:
- dev_dbg(&dbgp.gadget->dev, "enable ep: failure (%d:%d)\n", stp, err);
+ dev_dbg(dbgp.gadget->dev, "enable ep: failure (%d:%d)\n", stp, err);
return err;
}
#endif
@@ -286,7 +286,7 @@ fail_3:
fail_2:
dbgp.i_ep->driver_data = NULL;
fail_1:
- dev_dbg(&dbgp.gadget->dev, "ep config: failure (%d)\n", stp);
+ dev_dbg(dbgp.gadget->dev, "ep config: failure (%d)\n", stp);
return -ENODEV;
}
@@ -327,11 +327,11 @@ static int __init dbgp_bind(struct usb_gadget *gadget)
goto fail;
}
- dev_dbg(&dbgp.gadget->dev, "bind: success\n");
+ dev_dbg(dbgp.gadget->dev, "bind: success\n");
return 0;
fail:
- dev_dbg(&gadget->dev, "bind: failure (%d:%d)\n", stp, err);
+ dev_dbg(gadget->dev, "bind: failure (%d:%d)\n", stp, err);
dbgp_unbind(gadget);
return err;
}
@@ -339,7 +339,7 @@ fail:
static void dbgp_setup_complete(struct usb_ep *ep,
struct usb_request *req)
{
- dev_dbg(&dbgp.gadget->dev, "setup complete: %d, %d/%d\n",
+ dev_dbg(dbgp.gadget->dev, "setup complete: %d, %d/%d\n",
req->status, req->actual, req->length);
}
@@ -359,12 +359,12 @@ static int dbgp_setup(struct usb_gadget *gadget,
if (request == USB_REQ_GET_DESCRIPTOR) {
switch (value>>8) {
case USB_DT_DEVICE:
- dev_dbg(&dbgp.gadget->dev, "setup: desc device\n");
+ dev_dbg(dbgp.gadget->dev, "setup: desc device\n");
len = sizeof device_desc;
data = &device_desc;
break;
case USB_DT_DEBUG:
- dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n");
+ dev_dbg(dbgp.gadget->dev, "setup: desc debug\n");
len = sizeof dbg_desc;
data = &dbg_desc;
break;
@@ -375,7 +375,7 @@ static int dbgp_setup(struct usb_gadget *gadget,
value == USB_DEVICE_DEBUG_MODE) {
len = 0;
data = NULL;
- dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n");
+ dev_dbg(dbgp.gadget->dev, "setup: feat debug\n");
#ifdef CONFIG_USB_G_DBGP_PRINTK
err = dbgp_enable_ep();
#else
@@ -397,7 +397,7 @@ static int dbgp_setup(struct usb_gadget *gadget,
}
fail:
- dev_dbg(&dbgp.gadget->dev,
+ dev_dbg(dbgp.gadget->dev,
"setup: failure req %x v %x\n", request, value);
return err;
}
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 32cce02..12ff3bc 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2699,7 +2699,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
/* Find out how many LUNs there should be */
nluns = cfg->nluns;
if (nluns < 1 || nluns > FSG_MAX_LUNS) {
- dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns);
+ dev_err(gadget->dev, "invalid number of LUNs: %u\n", nluns);
return ERR_PTR(-EINVAL);
}
@@ -2746,7 +2746,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
curlun->ro = lcfg->cdrom || lcfg->ro;
curlun->removable = lcfg->removable;
curlun->dev.release = fsg_lun_release;
- curlun->dev.parent = &gadget->dev;
+ curlun->dev.parent = gadget->dev;
/* curlun->dev.driver = &fsg_driver.driver; XXX */
dev_set_drvdata(&curlun->dev, &common->filesem);
dev_set_name(&curlun->dev,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a857b7a..6ce72c7 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3405,11 +3405,11 @@ static int __ref fsg_bind(struct usb_gadget *gadget)
curlun->removable = mod_data.removable;
curlun->nofua = mod_data.nofua[i];
curlun->dev.release = lun_release;
- curlun->dev.parent = &gadget->dev;
+ curlun->dev.parent = gadget->dev;
curlun->dev.driver = &fsg_driver.driver;
dev_set_drvdata(&curlun->dev, &fsg->filesem);
dev_set_name(&curlun->dev,"%s-lun%d",
- dev_name(&gadget->dev), i);
+ dev_name(gadget->dev), i);
if ((rc = device_register(&curlun->dev)) != 0) {
INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 1b413a5..8b35d59 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -149,13 +149,13 @@ static void gmidi_transmit(struct gmidi_device* dev, struct usb_request* req);
#define DBG(d, fmt, args...) \
- dev_dbg(&(d)->gadget->dev , fmt , ## args)
+ dev_dbg((d)->gadget->dev , fmt , ## args)
#define VDBG(d, fmt, args...) \
- dev_vdbg(&(d)->gadget->dev , fmt , ## args)
+ dev_vdbg((d)->gadget->dev , fmt , ## args)
#define ERROR(d, fmt, args...) \
- dev_err(&(d)->gadget->dev , fmt , ## args)
+ dev_err((d)->gadget->dev , fmt , ## args)
#define INFO(d, fmt, args...) \
- dev_info(&(d)->gadget->dev , fmt , ## args)
+ dev_info((d)->gadget->dev , fmt , ## args)
static unsigned buflen = 256;
@@ -1134,7 +1134,7 @@ static int gmidi_register_card(struct gmidi_device *dev)
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &gmidi_in_ops);
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &gmidi_out_ops);
- snd_card_set_dev(card, &dev->gadget->dev);
+ snd_card_set_dev(card, dev->gadget->dev);
/* register it - we're ready to go */
err = snd_card_register(card);
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 735495b..43fca48 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -205,7 +205,7 @@ static int __ref hid_bind(struct usb_composite_dev *cdev)
if (status < 0)
return status;
- dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
+ dev_info(gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
return 0;
}
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 795d762..9e0cd7e 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -280,7 +280,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
int status, gcnum;
if (!can_support_ecm(cdev->gadget)) {
- dev_err(&gadget->dev, "controller '%s' not usable\n",
+ dev_err(gadget->dev, "controller '%s' not usable\n",
gadget->name);
return -EINVAL;
}
@@ -338,7 +338,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
goto fail2;
/* we're done */
- dev_info(&gadget->dev, DRIVER_DESC "\n");
+ dev_info(gadget->dev, DRIVER_DESC "\n");
fsg_common_put(&fsg_common);
return 0;
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index 7d6b66a..c3d1ed5 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -214,7 +214,7 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
if (status < 0)
goto err_usb;
- dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
+ dev_info(gadget->dev, "%s\n", NOKIA_LONG_NAME);
return 0;
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index cf241c3..1a8ae96 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -1385,7 +1385,7 @@ printer_bind(struct usb_gadget *gadget)
if (gcnum >= 0) {
device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
} else {
- dev_warn(&gadget->dev, "controller '%s' not recognized\n",
+ dev_warn(gadget->dev, "controller '%s' not recognized\n",
gadget->name);
/* unrecognized, but safe unless bulk is REALLY quirky */
device_desc.bcdDevice =
@@ -1403,7 +1403,7 @@ printer_bind(struct usb_gadget *gadget)
/* support optional vendor/distro customization */
if (idVendor) {
if (!idProduct) {
- dev_err(&gadget->dev, "idVendor needs idProduct!\n");
+ dev_err(gadget->dev, "idVendor needs idProduct!\n");
return -ENODEV;
}
device_desc.idVendor = cpu_to_le16(idVendor);
@@ -1433,7 +1433,7 @@ printer_bind(struct usb_gadget *gadget)
in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc);
if (!in_ep) {
autoconf_fail:
- dev_err(&gadget->dev, "can't autoconfigure on %s\n",
+ dev_err(gadget->dev, "can't autoconfigure on %s\n",
gadget->name);
return -ENODEV;
}
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 484acfb..7fd3d79 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -107,11 +107,11 @@
* using MSF). If someone changes them in composite.h it will produce
* a warning in this file when building MSF.
*/
-#define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args)
-#define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args)
-#define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args)
-#define WARNING(d, fmt, args...) dev_warn(&(d)->gadget->dev , fmt , ## args)
-#define INFO(d, fmt, args...) dev_info(&(d)->gadget->dev , fmt , ## args)
+#define DBG(d, fmt, args...) dev_dbg((d)->gadget->dev , fmt , ## args)
+#define VDBG(d, fmt, args...) dev_vdbg((d)->gadget->dev , fmt , ## args)
+#define ERROR(d, fmt, args...) dev_err((d)->gadget->dev , fmt , ## args)
+#define WARNING(d, fmt, args...) dev_warn((d)->gadget->dev , fmt , ## args)
+#define INFO(d, fmt, args...) dev_info((d)->gadget->dev , fmt , ## args)
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 6bb876d..532d84b 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -177,7 +177,7 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
strlcpy(p->driver, "g_ether", sizeof p->driver);
strlcpy(p->version, UETH__VERSION, sizeof p->version);
strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version);
- strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info);
+ strlcpy(p->bus_info, dev_name(dev->gadget->dev), sizeof p->bus_info);
}
/* REVISIT can also support:
@@ -780,10 +780,10 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
strcpy(net->name, "usb%d");
if (get_ether_addr(dev_addr, net->dev_addr))
- dev_warn(&g->dev,
+ dev_warn(g->dev,
"using random %s ethernet address\n", "self");
if (get_ether_addr(host_addr, dev->host_mac))
- dev_warn(&g->dev,
+ dev_warn(g->dev,
"using random %s ethernet address\n", "host");
if (ethaddr)
@@ -801,12 +801,12 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
netif_carrier_off(net);
dev->gadget = g;
- SET_NETDEV_DEV(net, &g->dev);
+ SET_NETDEV_DEV(net, g->dev);
SET_NETDEV_DEVTYPE(net, &gadget_type);
status = register_netdev(net);
if (status < 0) {
- dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
+ dev_dbg(g->dev, "register_netdev failed, %d\n", status);
free_netdev(net);
} else {
INFO(dev, "MAC %pM\n", net->dev_addr);
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 01e5354..172f4a1 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -1114,7 +1114,7 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count)
for (i = 0; i < count; i++) {
struct device *tty_dev;
- tty_dev = tty_register_device(gs_tty_driver, i, &g->dev);
+ tty_dev = tty_register_device(gs_tty_driver, i, g->dev);
if (IS_ERR(tty_dev))
pr_warning("%s: no classdev for port %d, err %ld\n",
__func__, i, PTR_ERR(tty_dev));
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 6170681..e8d1613 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -352,14 +352,14 @@ extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
/* messaging utils */
#define DBG(d, fmt, args...) \
- dev_dbg(&(d)->gadget->dev , fmt , ## args)
+ dev_dbg((d)->gadget->dev , fmt , ## args)
#define VDBG(d, fmt, args...) \
- dev_vdbg(&(d)->gadget->dev , fmt , ## args)
+ dev_vdbg((d)->gadget->dev , fmt , ## args)
#define ERROR(d, fmt, args...) \
- dev_err(&(d)->gadget->dev , fmt , ## args)
+ dev_err((d)->gadget->dev , fmt , ## args)
#define WARNING(d, fmt, args...) \
- dev_warn(&(d)->gadget->dev , fmt , ## args)
+ dev_warn((d)->gadget->dev , fmt , ## args)
#define INFO(d, fmt, args...) \
- dev_info(&(d)->gadget->dev , fmt , ## args)
+ dev_info((d)->gadget->dev , fmt , ## args)
#endif /* __LINUX_USB_COMPOSITE_H */
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 42e3d6f..7a145ed 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -19,6 +19,7 @@
struct usb_ep;
struct usb_gadget_driver;
+struct usb_composite_dev;
/**
* struct usb_request - describes one i/o request
@@ -493,6 +494,7 @@ struct usb_gadget {
unsigned a_alt_hnp_support:1;
unsigned busy:1;
const char *name;
+ struct usb_composite_dev *cdev;
struct device *dev;
};
--
balbi
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html