Add vbus status to udc-core
Subsystems (6)
cover Add vbus status to udc-core
Vbus event is a common event for gadget, this patchset move vbus status from individual driver private data to common struct usb_gadget, after that, the udc core can know vbus status well.
The last patch uses this vbus_active to determine if we can pullup dp when load gadget module.
Peter Chen (14):
usb: udc-core: introduce vbus_active for struct usb_gadget
usb: chipidea: using common vbus_active
usb: at91_udc: using common vbus_active
usb: fsl_udc_core: using common vbus_active
usb: lpc32xx_udc: using common vbus_active
usb: mv_u3d_core: using common vbus_active
usb: mv_udc: using common vbus_active
usb: omap_udc: using common vbus_active
usb: pch_udc: using common vbus_active
usb: pxa25x_udc: using common vbus_active
usb: pxa27x_udc: using common vbus_active
usb: s3c2410_udc: using common vbus_active
usb: udc-core: small cleanup for udc->gadget
usb: udc-core: add judgement logic for usb_gadget_connect
drivers/usb/chipidea/ci.h | 2 -- drivers/usb/chipidea/udc.c | 6 +++--- drivers/usb/gadget/at91_udc.c | 16 ++++++++-------- drivers/usb/gadget/at91_udc.h | 1 - drivers/usb/gadget/fsl_udc_core.c | 4 ++-- drivers/usb/gadget/fsl_usb2_udc.h | 1 - drivers/usb/gadget/lpc32xx_udc.c | 1 + drivers/usb/gadget/mv_u3d.h | 1 - drivers/usb/gadget/mv_u3d_core.c | 14 +++++++------- drivers/usb/gadget/mv_udc.h | 1 - drivers/usb/gadget/mv_udc_core.c | 14 +++++++------- drivers/usb/gadget/omap_udc.c | 4 ++-- drivers/usb/gadget/omap_udc.h | 1 - drivers/usb/gadget/pch_udc.c | 10 ++++------ drivers/usb/gadget/pxa25x_udc.c | 6 +++--- drivers/usb/gadget/pxa25x_udc.h | 1 - drivers/usb/gadget/pxa27x_udc.c | 8 ++++---- drivers/usb/gadget/pxa27x_udc.h | 1 - drivers/usb/gadget/s3c2410_udc.c | 6 +++--- drivers/usb/gadget/s3c2410_udc.h | 1 - drivers/usb/gadget/udc-core.c | 24 ++++++++++++++++-------- include/linux/usb/gadget.h | 1 + 22 files changed, 61 insertions(+), 63 deletions(-)
PATCH 1/14 usb: udc-core: introduce vbus_active for struct usb_gadget
If there is an vbus session event for udc driver, let the udc core know vbus's status.
--- include/linux/usb/gadget.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/usb/gadget.h +1 -0
@@ -531,6 +531,7 @@ struct usb_gadget { unsigned b_hnp_enable:1; unsigned a_hnp_support:1; unsigned a_alt_hnp_support:1; + unsigned vbus_active:1;const char *name;struct device dev;unsigned out_epnum;
Signature · 1 line
1.7.0.4
PATCH 2/14 usb: chipidea: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/chipidea/ci.h | 2 -- drivers/usb/chipidea/udc.c | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/usb/chipidea/ci.h +0 -2
@@ -126,7 +126,6 @@ struct hw_bank {* @suspended: suspended by host * @test_mode: the selected test mode * @platdata: platform specific information supplied by parent device -* @vbus_active: is VBUS active * @transceiver: pointer to USB PHY, if any * @hcd: pointer to usb_hcd for ehci host driver */
@@ -160,7 +159,6 @@ struct ci13xxx {u8 test_mode;struct ci13xxx_platform_data *platdata; -int vbus_active;/* FIXME: some day, we'll not use global phy */ bool global_phy;struct usb_phy *transceiver;
drivers/usb/chipidea/udc.c +3 -3
@@ -1383,7 +1383,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)return -EOPNOTSUPP ;spin_lock_irqsave (&ci->lock, flags); - ci->vbus_active = is_active; + _gadget->vbus_active = is_active;if (ci->driver) gadget_ready =1 ;spin_unlock_irqrestore (&ci->lock, flags);
@@ -1566,7 +1566,7 @@ static int ci13xxx_start(struct usb_gadget *gadget, ci->driver = driver;pm_runtime_get_sync (&ci->gadget.dev);if (ci->platdata->flags &CI13XXX_PULLUP_ON_VBUS ) { -if (ci->vbus_active) { +if (gadget->vbus_active) {if (ci->platdata->flags &CI13XXX_REGS_SHARED ) {hw_device_reset (ci,USBMODE_CM_DC );hw_enable_vbus_intr (ci);
@@ -1598,7 +1598,7 @@ static int ci13xxx_stop(struct usb_gadget *gadget,spin_lock_irqsave (&ci->lock, flags);if (!(ci->platdata->flags &CI13XXX_PULLUP_ON_VBUS ) || - ci->vbus_active) { + gadget->vbus_active) {hw_device_state (ci,0 );if (ci->platdata->notify_event) ci->platdata->notify_event(ci,
Signature · 1 line
1.7.0.4
PATCH 3/14 usb: at91_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/at91_udc.c | 16 ++++++++-------- drivers/usb/gadget/at91_udc.h | 1 - 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/usb/gadget/at91_udc.c +8 -8
@@ -173,9 +173,9 @@ static int proc_udc_show(struct seq_file *s, void *unused)seq_printf (s,"%s: version %s\n" , driver_name,DRIVER_VERSION ); seq_printf(s, "vbus %s, pullup %s, %s powered%s, gadget %s\n\n", - udc->vbus ? "present" : "off", + udc->gadget.vbus_active ? "present" : "off", udc->enabled - ? (udc->vbus ? "active" : "enabled") + ? (udc->gadget.vbus_active ? "active" : "enabled") : "disabled", udc->selfpowered ? "self" : "VBUS", udc->suspended ? ", suspended" : "",
@@ -209,7 +209,7 @@ static int proc_udc_show(struct seq_file *s, void *unused)proc_irq_show (s,"imr " ,at91_udp_read (udc,AT91_UDP_IMR ));proc_irq_show (s,"isr " ,at91_udp_read (udc,AT91_UDP_ISR )); -if (udc->enabled && udc->vbus) { +if (udc->enabled && udc->gadget.vbus_active) {proc_ep_show (s, &udc->ep[0 ]); list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {if (ep->ep.desc)
@@ -892,7 +892,7 @@ static void pullup(struct at91_udc *udc, int is_on) {int active = !udc->board.pullup_active_low; -if (!udc->enabled || !udc->vbus) +if (!udc->enabled || !udc->gadget.vbus_active) is_on =0 ;DBG ("%sactive\n" , is_on ?"" :"in" );
@@ -944,7 +944,7 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active)/* VDBG("vbus %s\n", is_active ? "on" : "off"); */ spin_lock_irqsave (&udc->lock, flags); - udc->vbus = (is_active !=0 ); + gadget->vbus_active = (is_active !=0 );if (udc->driver)pullup (udc, is_active);else
@@ -1586,7 +1586,7 @@ static struct at91_udc controller = {static void at91_vbus_update (struct at91_udc *udc,unsigned value) { value ^= udc->board.vbus_active_low; -if (value != udc->vbus) +if (value != udc->gadget.vbus_active)at91_vbus_session (&udc->gadget, value); }
@@ -1817,7 +1817,7 @@ static int at91udc_probe(struct platform_device *pdev)* Get the initial state of VBUS - we cannot expect * a pending interrupt. */ - udc->vbus =gpio_get_value_cansleep (udc->board.vbus_pin) ^ + udc->gadget.vbus_active =gpio_get_value_cansleep (udc->board.vbus_pin) ^ udc->board.vbus_active_low;if (udc->board.vbus_polled) {
@@ -1837,7 +1837,7 @@ static int at91udc_probe(struct platform_device *pdev) } }else {DBG ("no VBUS detection, assuming always-on\n" ); - udc->vbus =1 ; + udc->gadget.vbus_active =1 ; } retval =usb_add_gadget_udc (dev, &udc->gadget);if (retval)
drivers/usb/gadget/at91_udc.h +0 -1
@@ -115,7 +115,6 @@ struct at91_udc {struct usb_gadget gadget;struct at91_ep ep[NUM_ENDPOINTS ];struct usb_gadget_driver *driver; - unsigned vbus:1; unsigned enabled:1; unsigned clocked:1; unsigned suspended:1;
Signature · 1 line
1.7.0.4
PATCH 4/14 usb: fsl_udc_core: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/fsl_udc_core.c | 4 ++-- drivers/usb/gadget/fsl_usb2_udc.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/usb/gadget/fsl_udc_core.c +2 -2
@@ -1195,7 +1195,7 @@ static int fsl_wakeup(struct usb_gadget *gadget)static int can_pullup (struct fsl_udc *udc) { -return udc->driver && udc->softconnect && udc->vbus_active; +return udc->driver && udc->softconnect && udc->gadget.vbus_active; }/* Notify controller that VBUS is powered, Called by whatever
@@ -1208,7 +1208,7 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active) udc = container_of(gadget, struct fsl_udc, gadget);spin_lock_irqsave (&udc->lock, flags);VDBG ("VBUS %s" , is_active ?"on" :"off" ); - udc->vbus_active = (is_active !=0 ); + udc->gadget.vbus_active = (is_active !=0 );if (can_pullup (udc))fsl_writel ((fsl_readl (&dr_regs->usbcmd) |USB_CMD_RUN_STOP ), &dr_regs->usbcmd);
drivers/usb/gadget/fsl_usb2_udc.h +0 -1
@@ -483,7 +483,6 @@ struct fsl_udc {spinlock_t lock;struct usb_phy *transceiver; unsigned softconnect:1; - unsigned vbus_active:1; unsigned stopped:1; unsigned remote_wakeup:1; unsigned already_stopped:1;
Signature · 1 line
1.7.0.4
PATCH 5/14 usb: lpc32xx_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/lpc32xx_udc.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/usb/gadget/lpc32xx_udc.c +1 -0
@@ -2550,6 +2550,7 @@ static int lpc32xx_vbus_session(struct usb_gadget *gadget, int is_active)spin_lock_irqsave (&udc->lock, flags); + gadget->vbus_active = is_active;/* Doesn't need lock */ if (udc->driver) {udc_clk_set (udc,1 );
Signature · 1 line
1.7.0.4
PATCH 6/14 usb: mv_u3d_core: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/mv_u3d.h | 1 - drivers/usb/gadget/mv_u3d_core.c | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/usb/gadget/mv_u3d.h +0 -1
@@ -274,7 +274,6 @@ struct mv_u3d {unsigned int errors; unsigned softconnect:1; - unsigned vbus_active:1; /* vbus is active or not */ unsigned remote_wakeup:1; /* support remote wakeup */ unsigned clock_gating:1; /* clock gating or not */ unsigned active:1; /* udc is active or not */
drivers/usb/gadget/mv_u3d_core.c +7 -7
@@ -1159,15 +1159,15 @@ static int mv_u3d_vbus_session(struct usb_gadget *gadget, int is_active)spin_lock_irqsave (&u3d->lock, flags); - u3d->vbus_active = (is_active !=0 ); + u3d->gadget.vbus_active = (is_active !=0 );dev_dbg (u3d->dev,"%s: softconnect %d, vbus_active %d\n" , - __func__, u3d->softconnect, u3d->vbus_active); + __func__, u3d->softconnect, u3d->gadget.vbus_active);/* * 1. external VBUS detect: we can disable/enable clock on demand. * 2. UDC VBUS detect: we have to enable clock all the time. * 3. No VBUS detect: we have to enable clock all the time. */ -if (u3d->driver && u3d->softconnect && u3d->vbus_active) { +if (u3d->driver && u3d->softconnect && u3d->gadget.vbus_active) { retval =mv_u3d_enable (u3d);if (retval ==0 ) {/*
@@ -1218,9 +1218,9 @@ static int mv_u3d_pullup(struct usb_gadget *gadget, int is_on)spin_lock_irqsave (&u3d->lock, flags);dev_dbg (u3d->dev,"%s: softconnect %d, vbus_active %d\n" , - __func__, u3d->softconnect, u3d->vbus_active); + __func__, u3d->softconnect, u3d->gadget.vbus_active); u3d->softconnect = (is_on !=0 ); -if (u3d->driver && u3d->softconnect && u3d->vbus_active) { +if (u3d->driver && u3d->softconnect && u3d->gadget.vbus_active) { retval =mv_u3d_enable (u3d);if (retval ==0 ) {/*
@@ -1231,7 +1231,7 @@ static int mv_u3d_pullup(struct usb_gadget *gadget, int is_on)mv_u3d_ep0_reset (u3d);mv_u3d_controller_start (u3d); } - }else if (u3d->driver && u3d->vbus_active) { + }else if (u3d->driver && u3d->gadget.vbus_active) {/* stop all the transfer in queue*/ mv_u3d_stop_activity (u3d, u3d->driver);mv_u3d_controller_stop (u3d);
@@ -1976,7 +1976,7 @@ static int mv_u3d_probe(struct platform_device *dev) }if (!u3d->clock_gating) - u3d->vbus_active =1 ; + u3d->gadget.vbus_active =1 ;/* enable usb3 controller vbus detection */ u3d->vbus_valid_detect =1 ;
Signature · 1 line
1.7.0.4
PATCH 7/14 usb: mv_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/mv_udc.h | 1 - drivers/usb/gadget/mv_udc_core.c | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/usb/gadget/mv_udc.h +0 -1
@@ -206,7 +206,6 @@ struct mv_udc {int errors; unsigned softconnect:1, - vbus_active:1, remote_wakeup:1, softconnected:1, force_fs:1,
drivers/usb/gadget/mv_udc_core.c +7 -7
@@ -1204,12 +1204,12 @@ static int mv_udc_vbus_session(struct usb_gadget *gadget, int is_active) udc = container_of(gadget, struct mv_udc, gadget);spin_lock_irqsave (&udc->lock, flags); - udc->vbus_active = (is_active !=0 ); + gadget->vbus_active = (is_active !=0 );dev_dbg (&udc->dev->dev,"%s: softconnect %d, vbus_active %d\n" , - __func__, udc->softconnect, udc->vbus_active); + __func__, udc->softconnect, gadget->vbus_active); -if (udc->driver && udc->softconnect && udc->vbus_active) { +if (udc->driver && udc->softconnect && gadget->vbus_active) { retval =mv_udc_enable (udc);if (retval ==0 ) {/* Clock is disabled, need re-init registers */
@@ -1244,9 +1244,9 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on) udc->softconnect = (is_on !=0 );dev_dbg (&udc->dev->dev,"%s: softconnect %d, vbus_active %d\n" , - __func__, udc->softconnect, udc->vbus_active); + __func__, udc->softconnect, gadget->vbus_active); -if (udc->driver && udc->softconnect && udc->vbus_active) { +if (udc->driver && udc->softconnect && gadget->vbus_active) { retval =mv_udc_enable (udc);if (retval ==0 ) {/* Clock is disabled, need re-init registers */
@@ -1254,7 +1254,7 @@ static int mv_udc_pullup(struct usb_gadget *gadget, int is_on)ep0_reset (udc);udc_start (udc); } - }else if (udc->driver && udc->vbus_active) { + }else if (udc->driver && gadget->vbus_active) {/* stop all the transfer in queue*/ stop_activity (udc, udc->driver);udc_stop (udc);
@@ -2356,7 +2356,7 @@ static int mv_udc_probe(struct platform_device *pdev)if (udc->clock_gating)mv_udc_disable_internal (udc);else - udc->vbus_active =1 ; + udc->gadget.vbus_active =1 ; retval =usb_add_gadget_udc (&pdev->dev, &udc->gadget);if (retval)
Signature · 1 line
1.7.0.4
PATCH 8/14 usb: omap_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/omap_udc.c | 4 ++-- drivers/usb/gadget/omap_udc.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/usb/gadget/omap_udc.c +2 -2
@@ -1186,7 +1186,7 @@ omap_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)static int can_pullup (struct omap_udc *udc) { -return udc->driver && udc->softconnect && udc->vbus_active; +return udc->driver && udc->softconnect && udc->gadget.vbus_active; }static void pullup_enable (struct omap_udc *udc)
@@ -1253,7 +1253,7 @@ static int omap_vbus_session(struct usb_gadget *gadget, int is_active) udc = container_of(gadget, struct omap_udc, gadget);spin_lock_irqsave (&udc->lock, flags);VDBG ("VBUS %s\n" , is_active ?"on" :"off" ); - udc->vbus_active = (is_active !=0 ); + gadget->vbus_active = (is_active !=0 );if (cpu_is_omap15xx ()) {/* "software" detect, ignored if !VBUS_MODE_1510 */ l =omap_readl (FUNC_MUX_CTRL_0 );
drivers/usb/gadget/omap_udc.h +0 -1
@@ -166,7 +166,6 @@ struct omap_udc {struct usb_phy *transceiver;struct list_head iso; unsigned softconnect:1; - unsigned vbus_active:1; unsigned ep0_pending:1; unsigned ep0_in:1; unsigned ep0_set_config:1;
Signature · 1 line
1.7.0.4
PATCH 9/14 usb: pch_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/pch_udc.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)
drivers/usb/gadget/pch_udc.c +4 -6
@@ -333,7 +333,6 @@ struct pch_vbus_gpio_data {* @registered: driver regsitered with system * @suspended: driver in suspended state * @connected: gadget driver associated -* @vbus_session: required vbus_session state * @set_cfg_not_acked: pending acknowledgement 4 setup * @waiting_zlp_ack: pending acknowledgement 4 ZLP * @data_requests: DMA pool for data requests
@@ -361,7 +360,6 @@ struct pch_udc_dev { registered:1, suspended:1, connected:1, - vbus_session:1, set_cfg_not_acked:1, waiting_zlp_ack:1;struct pci_pool *data_requests;
@@ -614,7 +612,7 @@ static inline void pch_udc_vbus_session(struct pch_udc_dev *dev, {if (is_active) {pch_udc_reconnect (dev); - dev->vbus_session =1 ; + dev->gadget.vbus_active =1 ; }else {if (dev->driver && dev->driver->disconnect) {spin_unlock (&dev->lock);
@@ -622,7 +620,7 @@ static inline void pch_udc_vbus_session(struct pch_udc_dev *dev,spin_lock (&dev->lock); }pch_udc_set_disconnect (dev); - dev->vbus_session =0 ; + dev->gadget.vbus_active =0 ; } }
@@ -2745,7 +2743,7 @@ static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr) } vbus =pch_vbus_gpio_get_value (dev); -if ((dev->vbus_session ==0 ) +if ((dev->gadget.vbus_active ==0 ) && (vbus !=1 )) {if (dev->driver && dev->driver->disconnect) {spin_unlock (&dev->lock);
@@ -2753,7 +2751,7 @@ static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr)spin_lock (&dev->lock); }pch_udc_reconnect (dev); - }else if ((dev->vbus_session ==0 ) + }else if ((dev->gadget.vbus_active ==0 ) && (vbus ==1 ) && !dev->vbus_gpio.intr)schedule_work (&dev->vbus_gpio.irq_work_fall);
Signature · 1 line
1.7.0.4
PATCH 10/14 usb: pxa25x_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/pxa25x_udc.c | 6 +++--- drivers/usb/gadget/pxa25x_udc.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/usb/gadget/pxa25x_udc.c +3 -3
@@ -926,7 +926,7 @@ static void udc_disable(struct pxa25x_udc *);*/ static int pullup (struct pxa25x_udc *udc) { -int is_active = udc->vbus && udc->pullup && !udc->suspended; +int is_active = udc->gadget.vbus_active && udc->pullup && !udc->suspended;DMSG ("%s\n" , is_active ?"active" :"inactive" );if (is_active) {if (!udc->active) {
@@ -959,7 +959,7 @@ static int pxa25x_udc_vbus_session(struct usb_gadget *_gadget, int is_active)struct pxa25x_udc *udc; udc = container_of(_gadget, struct pxa25x_udc, gadget); - udc->vbus = is_active; + udc->gadget.vbus_active = is_active;DMSG ("vbus %s\n" , is_active ?"supplied" :"inactive" );pullup (udc);return 0 ;
@@ -2152,7 +2152,7 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)udc_disable (dev);udc_reinit (dev); - dev->vbus =0 ; + dev->gadget.vbus_active =0 ;/* irq setup after old hardware state is cleaned up */ retval = request_irq(irq, pxa25x_udc_irq,
drivers/usb/gadget/pxa25x_udc.h +0 -1
@@ -103,7 +103,6 @@ struct pxa25x_udc {enum ep0_state ep0state;struct udc_stats stats; unsigned got_irq : 1, - vbus : 1, pullup : 1, has_cfr : 1, req_pending : 1,
Signature · 1 line
1.7.0.4
PATCH 11/14 usb: pxa27x_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/pxa27x_udc.c | 8 ++++---- drivers/usb/gadget/pxa27x_udc.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/usb/gadget/pxa27x_udc.c +4 -4
@@ -1574,7 +1574,7 @@ static int should_enable_udc(struct pxa_udc *udc)int put_on; put_on = ((udc->pullup_on) && (udc->driver)); - put_on &= ((udc->vbus_sensed) || (IS_ERR_OR_NULL (udc->transceiver))); + put_on &= ((udc->gadget.vbus_active) || (IS_ERR_OR_NULL (udc->transceiver)));return put_on; }
@@ -1595,7 +1595,7 @@ static int should_disable_udc(struct pxa_udc *udc)int put_off; put_off = ((!udc->pullup_on) || (!udc->driver)); - put_off |= ((!udc->vbus_sensed) && (!IS_ERR_OR_NULL (udc->transceiver))); + put_off |= ((!udc->gadget.vbus_active) && (!IS_ERR_OR_NULL (udc->transceiver)));return put_off; }
@@ -1640,7 +1640,7 @@ static int pxa_udc_vbus_session(struct usb_gadget *_gadget, int is_active) {struct pxa_udc *udc =to_gadget_udc (_gadget); - udc->vbus_sensed = is_active; + _gadget->vbus_active = is_active;if (should_enable_udc (udc))udc_enable (udc);if (should_disable_udc (udc))
@@ -2465,7 +2465,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)device_initialize (&udc->gadget.dev); udc->gadget.dev.parent = &pdev->dev; udc->gadget.dev.dma_mask =NULL ; - udc->vbus_sensed =0 ; + udc->gadget.vbus_active =0 ; the_controller = udc;platform_set_drvdata (pdev, udc);
drivers/usb/gadget/pxa27x_udc.h +0 -1
@@ -458,7 +458,6 @@ struct pxa_udc { unsigned enabled:1; unsigned pullup_on:1; unsigned pullup_resume:1; - unsigned vbus_sensed:1; unsigned config:2; unsigned last_interface:3; unsigned last_alternate:3;
Signature · 1 line
1.7.0.4
PATCH 12/14 usb: s3c2410_udc: using common vbus_active
In reply to Peter ChenUsing common vbus_active to indicate vbus status
--- drivers/usb/gadget/s3c2410_udc.c | 6 +++--- drivers/usb/gadget/s3c2410_udc.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/usb/gadget/s3c2410_udc.c +3 -3
@@ -1494,7 +1494,7 @@ static int s3c2410_udc_vbus_session(struct usb_gadget *gadget, int is_active)dprintk (DEBUG_NORMAL ,"%s()\n" , __func__); - udc->vbus = (is_active !=0 ); + gadget->vbus_active = (is_active !=0 );s3c2410_udc_set_pullup (udc, is_active);return 0 ; }
@@ -1520,7 +1520,7 @@ static irqreturn_t s3c2410_udc_vbus_irq(int irq, void *_dev)if (udc_info->vbus_pin_inverted) value = !value; -if (value != dev->vbus) +if (value != &dev->gadget.vbus)s3c2410_udc_vbus_session (&dev->gadget, value);return IRQ_HANDLED ;
@@ -1887,7 +1887,7 @@ static int s3c2410_udc_probe(struct platform_device *pdev)dev_dbg (dev,"got irq %i\n" , irq); }else { - udc->vbus =1 ; + udc->gadget.vbus =1 ; } if (udc_info && !udc_info->udc_command &&
drivers/usb/gadget/s3c2410_udc.h +0 -1
@@ -92,7 +92,6 @@ struct s3c2410_udc { unsigned req_std : 1; unsigned req_config : 1; unsigned req_pending : 1; -u8 vbus;struct dentry *regs_info; };#define to_s3c2410 (g) (container_of((g), struct s3c2410_udc, gadget))
Signature · 1 line
1.7.0.4
PATCH 13/14 usb: udc-core: small cleanup for udc->gadget
In reply to Peter Chen:s/udc->gadget/gadget
--- drivers/usb/gadget/udc-core.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc-core.c +10 -8
@@ -262,6 +262,7 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);static int udc_bind_to_driver (struct usb_udc *udc,struct usb_gadget_driver *driver) {int ret; +struct usb_gadget *gadget = udc->gadget;dev_dbg (&udc->dev,"registering UDC driver [%s]\n" , driver->function);
@@ -269,15 +270,15 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri udc->driver = driver; udc->dev.driver = &driver->driver; - ret = driver->bind (udc->gadget, driver); + ret = driver->bind (gadget, driver);if (ret) goto err1; - ret =usb_gadget_udc_start (udc->gadget, driver); + ret =usb_gadget_udc_start (gadget, driver);if (ret) { - driver->unbind (udc->gadget); + driver->unbind (gadget); goto err1; } -usb_gadget_connect (udc->gadget); +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;
@@ -379,13 +380,14 @@ static ssize_t usb_udc_softconn_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) { struct usb_udc *udc = container_of(dev, struct usb_udc, dev); +struct usb_gadget *gadget = udc->gadget;if (sysfs_streq (buf,"connect" )) { -usb_gadget_udc_start (udc->gadget, udc->driver); -usb_gadget_connect (udc->gadget); +usb_gadget_udc_start (gadget, udc->driver); +usb_gadget_connect (gadget); }else if (sysfs_streq (buf,"disconnect" )) { -usb_gadget_disconnect (udc->gadget); -usb_gadget_udc_stop (udc->gadget, udc->driver); +usb_gadget_disconnect (gadget); +usb_gadget_udc_stop (gadget, udc->driver); }else {dev_err (dev,"unsupported command '%s'\n" , buf);return -EINVAL ;
Signature · 1 line
1.7.0.4
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
In reply to Peter Chen- If there is no vbus control to indicate connection. and disconnect, we can pullup dp when we load gadget module.
- If we have vbus control logic, the dp is better pull up when there is a vbus session.
--- drivers/usb/gadget/udc-core.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/usb/gadget/udc-core.c +8 -2
@@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind (gadget); goto err1; } -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;
@@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,if (sysfs_streq (buf,"connect" )) {usb_gadget_udc_start (gadget, udc->driver); -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget); }else if (sysfs_streq (buf,"disconnect" )) {usb_gadget_disconnect (gadget);usb_gadget_udc_stop (gadget, udc->driver);
Signature · 1 line
1.7.0.4
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Hi,
Quoted 27 lines · Peter Chen
- If there is no vbus control to indicate connection. and disconnect, we can pullup dp when we load gadget module.
- If we have vbus control logic, the dp is better pull up when there is a vbus session.Signed-off-by Peter Chen <[email protected]>--- drivers/usb/gadget/udc-core.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)drivers/usb/gadget/udc-core.c +4
-1@@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind (gadget); goto err1; } -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;
drivers/usb/gadget/udc-core.c static ssize_t usb_udc_softconn_store(struct device *dev, · line 393
Quoted 8 lines
drivers/usb/gadget/udc-core.c +4
-1@@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,if (sysfs_streq (buf,"connect" )) {usb_gadget_udc_start (gadget, udc->driver); -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);
this patch is incomplete. What happens if this test fails ? Who will connect pullup then ?
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130314/6cfd0ff2/attachment.sig>
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Quoted 31 lines · Felipe Balbi
Hi,
Quoted 28 lines · Peter Chen
- If there is no vbus control to indicate connection. and disconnect, we can pullup dp when we load gadget module.
- If we have vbus control logic, the dp is better pull up when there is a vbus session.Signed-off-by Peter Chen <[email protected]>--- drivers/usb/gadget/udc-core.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)drivers/usb/gadget/udc-core.c +4
-1@@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind (gadget); goto err1; } -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;@@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
Quoted 10 lines
drivers/usb/gadget/udc-core.c static ssize_t usb_udc_softconn_store(struct device *dev, · line 393
Quoted 7 lines
drivers/usb/gadget/udc-core.c +4
-1if (sysfs_streq (buf,"connect" )) {usb_gadget_udc_start (gadget, udc->driver); -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);this patch is incomplete. What happens if this test fails ? Who will connect pullup then ?
gadget->ops->vbus_session will handle it when the vbus interrupt comes
Quoted 3 lines
Signature · 2 lines
-- balbi
Signature · 2 lines
Best Regards, Peter Chen
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Hi,
Quoted 25 lines · Peter Chen
Quoted 14 lines
Quoted 14 lines
drivers/usb/gadget/udc-core.c +4
-1@@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind (gadget); goto err1; } -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;@@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,Quoted 10 lines
drivers/usb/gadget/udc-core.c static ssize_t usb_udc_softconn_store(struct device *dev, · line 393
Quoted 7 lines
drivers/usb/gadget/udc-core.c +4
-1if (sysfs_streq (buf,"connect" )) {usb_gadget_udc_start (gadget, udc->driver); -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);this patch is incomplete. What happens if this test fails ? Who will connect pullup then ?
Quoted 1 line
gadget->ops->vbus_sessionwill handle it when the vbus interrupt comes
for your driver, what about all the others ? Also, we shouldn't allow this ping-pong between who handles pullup and who handles vbus_session.
It should all be managed by udc-core with UDC drivers just providing enough hooks. If we allow the UDC driver to connect pullups when VBUS IRQ comes, we could fall into all sorts of traps:
a) we could connect cable with no gadget driver loaded
b) there will be code duplication among all UDC drivers to call usb_gadge_connect() from vbus_session
c) we might screw up the usb_function_activate()/deactivate() counter
Need to be very careful with all these details, there are many, many users to udc-core with different requirements. So unless we can come up with a way which wouldn't cause code duplication or regressions, I don't think we can solve the real problem.
I guess the best solution to all problems is to start deferring pullup to when gadget driver says it's ok to connect them. It's far more likely that we will already have connection to a host and VBUS will be alive.
Also, I'm not sure what does this all mean for SRP. Should we connect pullup before or after SRP ?
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130314/4423ce01/attachment-0001.sig>
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Quoted 28 lines · Felipe Balbi
Hi,
Quoted 25 lines · Peter Chen
Quoted 24 lines
Quoted 13 lines
drivers/usb/gadget/udc-core.c +4
-1@@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind (gadget); goto err1; } -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;drivers/usb/gadget/udc-core.c static ssize_t usb_udc_softconn_store(struct device *dev, · line 393
Quoted 8 lines
drivers/usb/gadget/udc-core.c +4
-1@@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,if (sysfs_streq (buf,"connect" )) {usb_gadget_udc_start (gadget, udc->driver); -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);this patch is incomplete. What happens if this test fails ? Who will connect pullup then ?
Quoted 3 lines
Quoted 1 line
gadget->ops->vbus_sessionwill handle it when the vbus interrupt comesfor your driver, what about all the others ?
All drivers have .vbus_session will try to pullup, but some still check if .pullup (using .softconnect) is called beforehand, it is duplicated with this patch. Sorry, my careless.
If you have a look with these drivers, even usb_gadget_connect is called at udc_bind_to_driver, they will NOT pull up if vbus is not there.
The most strict condition is :gadget_is_loaded && vbus_session_is_called && pullup_is_called
In fact, calling usb_gadget_connect(gadget) unconditionally at udc-core may hang system if low power is enabled as udc will enter low power mode after udc_start if no vbus is there.
Quoted 8 lines
Also, we shouldn't allow
this ping-pong between who handles pullup and who handlesvbus_session.It should all be managed by udc-core with UDC drivers just providing enough hooks. If we allow the UDC driver to connect pullups when VBUS IRQ comes, we could fall into all sorts of traps:
a) we could connect cable with no gadget driver loaded
In that case, the pullup will not be called, it will check if gadget module is loaded.
Quoted 2 lines
b) there will be code duplication among all UDC drivers to call
usb_gadge_connect()fromvbus_session
Yes
Quoted 2 lines
c) we might screw up the usb_function_activate()/deactivate() counter
why?
Quoted 4 lines
Need to be very careful with all these details, there are many, many users to udc-core with different requirements. So unless we can come up with a way which wouldn't cause code duplication or regressions, I don't think we can solve the real problem.
Yes, udc has vendor specific, no uniform spec like host.
Quoted 5 lines
I guess the best solution to all problems is to start deferring pullup to when gadget driver says it's ok to connect them. It's far more likely that we will already have connection to a host and VBUS will be alive.
I still think (gadget_is_loaded && vbus_is_there) is enough.
Quoted 3 lines
Also, I'm not sure what does this all mean for SRP. Should we connect pullup before or after SRP ?
I am not familiar with SRP, but I think vbus is pre-condition.
Signature · 2 lines
Best Regards, Peter Chen
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Hi,
Quoted 27 lines · Peter Chen
Quoted 27 lines
Quoted 26 lines
Quoted 14 lines
Quoted 14 lines
drivers/usb/gadget/udc-core.c +4
-1@@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri driver->unbind (gadget); goto err1; } -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);kobject_uevent (&udc->dev.kobj,KOBJ_CHANGE );return 0 ;@@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,Quoted 10 lines
drivers/usb/gadget/udc-core.c static ssize_t usb_udc_softconn_store(struct device *dev, · line 393
Quoted 7 lines
drivers/usb/gadget/udc-core.c +4
-1if (sysfs_streq (buf,"connect" )) {usb_gadget_udc_start (gadget, udc->driver); -usb_gadget_connect (gadget); +if (!gadget->ops->vbus_session || + (gadget->ops->vbus_session + && gadget->vbus_active)) +usb_gadget_connect (gadget);this patch is incomplete. What happens if this test fails ? Who will connect pullup then ?
gadget->ops->vbus_sessionwill handle it when the vbus interrupt comes
Quoted 7 lines
Quoted 1 line
for your driver, what about all the others ?
All drivers have .vbus_session will try to pullup, but some still check if .pullup (using .softconnect) is called beforehand, it is duplicated with this patch. Sorry, my careless.
If you have a look with these drivers, evenusb_gadget_connectis called atudc_bind_to_driver, they will NOT pull up if vbus is not there.
that's all wrong and needs to be fixed. UDC-core has to be the central point for all these details. We start with the easiest way (call connect unconditionally after gadget driver is loaded) and optimize it as we go (making sure that there is VBUS before connecting pullups); but we can't bypass UDC-core and call usb_gadget_connect() directly from UDC driver.
Quoted 6 lines
The most strict condition is :
gadget_is_loaded&&vbus_session_is_called&&pullup_is_calledIn fact, calling
usb_gadget_connect(gadget)unconditionally at udc-core may hang system if low power is enabled as udc will enter low power mode afterudc_startif no vbus is there.
that's a bug in the UDC driver though. It should add proper pm_runtime_get_sync() and pm_runtime_put() (or put_sync()) around register accesses, which means that ->pullup() should take care of that too.
Quoted 11 lines
Quoted 8 lines
Also, we shouldn't allow
this ping-pong between who handles pullup and who handlesvbus_session.It should all be managed by udc-core with UDC drivers just providing enough hooks. If we allow the UDC driver to connect pullups when VBUS IRQ comes, we could fall into all sorts of traps:
a) we could connect cable with no gadget driver loaded
In that case, the pullup will not be called, it will check if gadget module is loaded.
I don't see that in your patch.
Quoted 4 lines
Quoted 2 lines
b) there will be code duplication among all UDC drivers to call
usb_gadge_connect()fromvbus_sessionYes
yeah, we need to avoid it.
Quoted 4 lines
Quoted 2 lines
c) we might screw up the usb_function_activate()/deactivate() counter
why?
(USB cable already attached to a host, VBUS alive) gadget driver is loaded, gadget driver calls usb_function_deactive() to prevent enumeration until userland is ready, UDC driver calls usb_gadget_connect() because there is a gadget driver and vbus is alive.
Quoted 6 lines
Quoted 4 lines
Need to be very careful with all these details, there are many, many users to udc-core with different requirements. So unless we can come up with a way which wouldn't cause code duplication or regressions, I don't think we can solve the real problem.
Yes, udc has vendor specific, no uniform spec like host.
there are plenty of non-uniform hosts as well. MUSB and dwc2 are just two instances of them. Still usbcore works just fine with those and the standard ones.
Quoted 6 lines
Quoted 4 lines
I guess the best solution to all problems is to start deferring pullup to when gadget driver says it's ok to connect them. It's far more likely that we will already have connection to a host and VBUS will be alive.
I still think (
gadget_is_loaded&&vbus_is_there) is enough.
it's not, see above.
Quoted 4 lines
Quoted 2 lines
Also, I'm not sure what does this all mean for SRP. Should we connect pullup before or after SRP ?
I am not familiar with SRP, but I think vbus is pre-condition.
hehe, google SRP.
Nah, I'll save you the trouble. SRP is a mechanism for the USB peripheral to ask the host to enable VBUS. This means that we can keep the VBUS charge pump disabled, and thus save power, until peripheral requests for a session.
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130315/75ace05b/attachment-0001.sig>
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Quoted 6 lines · Felipe Balbi
that's all wrong and needs to be fixed. UDC-core has to be the central point for all these details. We start with the easiest way (call connect unconditionally after gadget driver is loaded) and optimize it as we go (making sure that there is VBUS before connecting pullups); but we can't bypass UDC-core and call
usb_gadget_connect()directly from UDC driver.
I have an idea that let the gadget driver call usb_gadget_connect/disconnect, and make a refcount for calling .pullup at usb_gadget_connect/disconnect. Below is an initial idea for it, I think it can also cover both udc and uvc case.
drivers/usb/chipidea/udc.c | 6 ++---- drivers/usb/gadget/composite.c | 6 ++++++ include/linux/usb/gadget.h | 21 +++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-)
drivers/usb/chipidea/udc.c +2 -4
@@ -1386,17 +1386,15 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)pm_runtime_get_sync (&_gadget->dev);hw_device_reset (ci,USBMODE_CM_DC );hw_device_state (ci, ci->ep0out->qh.dma); -ci13xxx_pullup (_gadget, true); + ci->driver->connect (&ci->gadget);dev_dbg (ci->dev,"Connected to host\n" ); }else { -if (ci->driver) - ci->driver->disconnect (&ci->gadget); + ci->driver->disconnect (&ci->gadget);hw_device_state (ci,0 );if (ci->platdata->notify_event) ci->platdata->notify_event (ci,CI13XXX_CONTROLLER_STOPPED_EVENT );_gadget_stop_activity (&ci->gadget); -ci13xxx_pullup (_gadget, false);pm_runtime_put_sync (&_gadget->dev);dev_dbg (ci->dev,"Disconnected from host\n" ); }
drivers/usb/gadget/composite.c +6 -0
@@ -1479,6 +1479,11 @@ done:return value; } +void composite_connect (struct usb_gadget *gadget) +{ +usb_gadget_connect (gadget); +} +void composite_disconnect (struct usb_gadget *gadget) {struct usb_composite_dev *cdev =get_gadget_data (gadget);
@@ -1492,6 +1497,7 @@ void composite_disconnect(struct usb_gadget *gadget)reset_config (cdev);if (cdev->driver->disconnect) cdev->driver->disconnect (cdev); +usb_gadget_disconnect (gadget);spin_unlock_irqrestore (&cdev->lock, flags); }
include/linux/usb/gadget.h +19 -2
@@ -536,6 +536,7 @@ struct usb_gadget {struct device dev;unsigned out_epnum;unsigned in_epnum; +int connection; };static inline void set_gadget_data (struct usb_gadget *gadget,void *data)
@@ -722,9 +723,16 @@ static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)*/ static inline int usb_gadget_connect (struct usb_gadget *gadget) { +int ret =0 ;if (!gadget->ops->pullup)return -EOPNOTSUPP ; -return gadget->ops->pullup (gadget,1 ); + +if (gadget->connection ==0 ) + ret = gadget->ops->pullup (gadget,1 ); +if (!ret) + gadget->connection ++; + +return ret; }/**
@@ -744,9 +752,18 @@ static inline int usb_gadget_connect(struct usb_gadget *gadget)*/ static inline int usb_gadget_disconnect (struct usb_gadget *gadget) { +int ret =0 ; +if (!gadget->ops->pullup)return -EOPNOTSUPP ; -return gadget->ops->pullup (gadget,0 ); + +if (gadget->connection ==1 ) + ret = gadget->ops->pullup (gadget,0 ); + +if (!ret) + gadget->connection --; + +return ret; }
Quoted 5 lines
Quoted 3 lines
In that case, the pullup will not be called, it will check if gadget module is loaded.
I don't see that in your patch.
At each udc driver, it makes sure it, maybe we can move it to usb_gaget_connect /usb_gadget_disconnect or its abstract layer.
Quoted 9 lines
Quoted 2 lines
I am not familiar with SRP, but I think vbus is pre-condition.
hehe, google SRP.
Nah, I'll save you the trouble. SRP is a mechanism for the USB peripheral to ask the host to enable VBUS. This means that we can keep the VBUS charge pump disabled, and thus save power, until peripheral requests for a session.
Thanks.
Quoted 3 lines
Signature · 2 lines
-- balbi
Signature · 2 lines
Best Regards, Peter Chen
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Hi,
Quoted 104 lines · Peter Chen
Quoted 6 lines · Felipe Balbi
that's all wrong and needs to be fixed. UDC-core has to be the central point for all these details. We start with the easiest way (call connect unconditionally after gadget driver is loaded) and optimize it as we go (making sure that there is VBUS before connecting pullups); but we can't bypass UDC-core and call
usb_gadget_connect()directly from UDC driver.I have an idea that let the gadget driver call usb_gadget_connect/disconnect, and make a refcount for calling .pullup at usb_gadget_connect/disconnect. Below is an initial idea for it, I think it can also cover both udc and uvc case.
drivers/usb/chipidea/udc.c | 6 ++---- drivers/usb/gadget/composite.c | 6 ++++++ include/linux/usb/gadget.h | 21 +++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-)drivers/usb/chipidea/udc.c +2
-4@@ -1386,17 +1386,15 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)pm_runtime_get_sync (&_gadget->dev);hw_device_reset (ci,USBMODE_CM_DC );hw_device_state (ci, ci->ep0out->qh.dma); -ci13xxx_pullup (_gadget, true); + ci->driver->connect (&ci->gadget);dev_dbg (ci->dev,"Connected to host\n" ); }else { -if (ci->driver) - ci->driver->disconnect (&ci->gadget); + ci->driver->disconnect (&ci->gadget);hw_device_state (ci,0 );if (ci->platdata->notify_event) ci->platdata->notify_event (ci,CI13XXX_CONTROLLER_STOPPED_EVENT );_gadget_stop_activity (&ci->gadget); -ci13xxx_pullup (_gadget, false);pm_runtime_put_sync (&_gadget->dev);dev_dbg (ci->dev,"Disconnected from host\n" ); }drivers/usb/gadget/composite.c +6
-0@@ -1479,6 +1479,11 @@ done:return value; } +void composite_connect (struct usb_gadget *gadget) +{ +usb_gadget_connect (gadget); +} +void composite_disconnect (struct usb_gadget *gadget) {struct usb_composite_dev *cdev =get_gadget_data (gadget);@@ -1492,6 +1497,7 @@ void composite_disconnect(struct usb_gadget *gadget)reset_config (cdev);if (cdev->driver->disconnect) cdev->driver->disconnect (cdev); +usb_gadget_disconnect (gadget);spin_unlock_irqrestore (&cdev->lock, flags); }include/linux/usb/gadget.h +11
-1@@ -536,6 +536,7 @@ struct usb_gadget {struct device dev;unsigned out_epnum;unsigned in_epnum; +int connection; };static inline void set_gadget_data (struct usb_gadget *gadget,void *data)@@ -722,9 +723,16 @@ static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)*/ static inline int usb_gadget_connect (struct usb_gadget *gadget) { +int ret =0 ;if (!gadget->ops->pullup)return -EOPNOTSUPP ; -return gadget->ops->pullup (gadget,1 ); + +if (gadget->connection ==0 ) + ret = gadget->ops->pullup (gadget,1 ); +if (!ret) + gadget->connection ++; + +return ret; }/** @@ -744,9 +752,18 @@ static inline int usb_gadget_connect(struct usb_gadget *gadget)*/ static inline int usb_gadget_disconnect (struct usb_gadget *gadget) { +int ret =0 ; +if (!gadget->ops->pullup)return -EOPNOTSUPP ;
include/linux/usb/gadget.h static inline int usb_gadget_connect(struct usb_gadget *gadget) · line 767
Quoted 10 lines
include/linux/usb/gadget.h +8
-1-return gadget->ops->pullup (gadget,0 ); + +if (gadget->connection ==1 ) + ret = gadget->ops->pullup (gadget,0 ); + +if (!ret) + gadget->connection --; + +return ret; }
this might be a good idea. But we already have something similar, although it's managed at composite device level. Maybe we need to move that to the gadget layer. Still, I don't want to let UDC drivers call usb_gadget_connect()/disconnect() directly.
It's easy enough for udc-core to handle that.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
In that case, the pullup will not be called, it will check if gadget module is loaded.
I don't see that in your patch.
At each udc driver, it makes sure it, maybe we can move it to
usb_gaget_connect/usb_gadget_disconnect or its abstract layer.
we shouldn't add more clutter to all UDC drivers. The target has to be into concentrating generic/duplicated code in udc-core.c
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130315/2782da5a/attachment.sig>
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
Quoted 12 lines · Felipe Balbi
Quoted 12 lines
*/
static inline intusb_gadget_disconnect(struct usb_gadget *gadget){include/linux/usb/gadget.h +6
-1+int ret =0 ; +if (!gadget->ops->pullup)return -EOPNOTSUPP ; -return gadget->ops->pullup (gadget,0 ); + +if (gadget->connection ==1 ) + ret = gadget->ops->pullup (gadget,0 ); +
Quoted 8 lines
include/linux/usb/gadget.h static inline int usb_gadget_connect(struct usb_gadget *gadget) · line 767
Quoted 5 lines
include/linux/usb/gadget.h +4
-0+if (!ret) + gadget->connection --; + +return ret; }this might be a good idea. But we already have something similar, although it's managed at composite device level.
Yes, I know, it should only be managed at one place at last.
Quoted 5 lines
Maybe we need to move
that to the gadget layer. Still, I don't want to let UDC drivers call usb_gadget_connect()/disconnect() directly.It's easy enough for udc-core to handle that.
Below are all cases I can think about pullup_dp
1. No vbus interrupt support udc driver, manage pullup at load/unload gadget module.
2. For vbus interrupt supported udc driver, manage pullup at vbus interrupt
3. For gadget module, like uvc, it will call pullup_dp through its app.
Are there any cases? We need to design one solution to cover all cases, then, we can try to delete the duplicate pullup calling at all udc drivers, and make it be generic.
Signature · 2 lines
Best Regards, Peter Chen
PATCH 14/14 usb: udc-core: add judgement logic for usb_gadget_connect
In reply to Felipe BalbiQuoted 123 lines · Felipe Balbi
Hi,
Quoted 104 lines · Peter Chen
Quoted 6 lines · Felipe Balbi
that's all wrong and needs to be fixed. UDC-core has to be the central point for all these details. We start with the easiest way (call connect unconditionally after gadget driver is loaded) and optimize it as we go (making sure that there is VBUS before connecting pullups); but we can't bypass UDC-core and call
usb_gadget_connect()directly from UDC driver.I have an idea that let the gadget driver call usb_gadget_connect/disconnect, and make a refcount for calling .pullup at usb_gadget_connect/disconnect. Below is an initial idea for it, I think it can also cover both udc and uvc case.
drivers/usb/chipidea/udc.c | 6 ++---- drivers/usb/gadget/composite.c | 6 ++++++ include/linux/usb/gadget.h | 21 +++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-)drivers/usb/chipidea/udc.c +2
-4@@ -1386,17 +1386,15 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)pm_runtime_get_sync (&_gadget->dev);hw_device_reset (ci,USBMODE_CM_DC );hw_device_state (ci, ci->ep0out->qh.dma); -ci13xxx_pullup (_gadget, true); + ci->driver->connect (&ci->gadget);dev_dbg (ci->dev,"Connected to host\n" ); }else { -if (ci->driver) - ci->driver->disconnect (&ci->gadget); + ci->driver->disconnect (&ci->gadget);hw_device_state (ci,0 );if (ci->platdata->notify_event) ci->platdata->notify_event (ci,CI13XXX_CONTROLLER_STOPPED_EVENT );_gadget_stop_activity (&ci->gadget); -ci13xxx_pullup (_gadget, false);pm_runtime_put_sync (&_gadget->dev);dev_dbg (ci->dev,"Disconnected from host\n" ); }drivers/usb/gadget/composite.c +6
-0@@ -1479,6 +1479,11 @@ done:return value; } +void composite_connect (struct usb_gadget *gadget) +{ +usb_gadget_connect (gadget); +} +void composite_disconnect (struct usb_gadget *gadget) {struct usb_composite_dev *cdev =get_gadget_data (gadget);@@ -1492,6 +1497,7 @@ void composite_disconnect(struct usb_gadget *gadget)reset_config (cdev);if (cdev->driver->disconnect) cdev->driver->disconnect (cdev); +usb_gadget_disconnect (gadget);spin_unlock_irqrestore (&cdev->lock, flags); }include/linux/usb/gadget.h +11
-1@@ -536,6 +536,7 @@ struct usb_gadget {struct device dev;unsigned out_epnum;unsigned in_epnum; +int connection; };static inline void set_gadget_data (struct usb_gadget *gadget,void *data)@@ -722,9 +723,16 @@ static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)*/ static inline int usb_gadget_connect (struct usb_gadget *gadget) { +int ret =0 ;if (!gadget->ops->pullup)return -EOPNOTSUPP ; -return gadget->ops->pullup (gadget,1 ); + +if (gadget->connection ==0 ) + ret = gadget->ops->pullup (gadget,1 ); +if (!ret) + gadget->connection ++; + +return ret; }/** @@ -744,9 +752,18 @@ static inline int usb_gadget_connect(struct usb_gadget *gadget)*/ static inline int usb_gadget_disconnect (struct usb_gadget *gadget) { +int ret =0 ; +if (!gadget->ops->pullup)return -EOPNOTSUPP ;include/linux/usb/gadget.h static inline int usb_gadget_connect(struct usb_gadget *gadget) · line 767
Quoted 10 lines
include/linux/usb/gadget.h +8
-1-return gadget->ops->pullup (gadget,0 ); + +if (gadget->connection ==1 ) + ret = gadget->ops->pullup (gadget,0 ); + +if (!ret) + gadget->connection --; + +return ret; }this might be a good idea. But we already have something similar, although it's managed at composite device level. Maybe we need to move that to the gadget layer. Still, I don't want to let UDC drivers call usb_gadget_connect()/disconnect() directly.
Quoted 2 lines
It's easy enough for udc-core to handle that.
Not so easy, how let udc-core know vbus interrupt?
And we need to consider the udc drivers which support or not support vbus interrupt together.
Signature · 2 lines
Best Regards, Peter Chen