fsl_udc: update and fix
Subsystems (3)
PATCH v4 1/5 fsl_udc: update and fix
- this patch sync fsl_udc.c with linux's driver,
- add a poller on usb_gadget_poll to get serial gadget working,
- return -EIO in usb_gadget_poll when udc is stopped (do detect cable disonnection)
- tested on i.MX25 & i.MX35
--- drivers/usb/gadget/fsl_udc.c | 45 +++++++++++++++++++++++++++++++++-------- 1 files changed, 36 insertions(+), 9 deletions(-)
drivers/usb/gadget/fsl_udc.c +36 -9
@@ -6,6 +6,7 @@#include <usb/gadget.h> #include <usb/fsl_usb2.h> #include <io.h> +#include <poller.h> #include <asm/byteorder.h> #include <asm/mmu.h>
@@ -233,6 +234,7 @@ struct usb_dr_device {#define USB_MODE_CTRL_MODE_DEVICE 0x00000002#define USB_MODE_CTRL_MODE_HOST 0x00000003#define USB_MODE_CTRL_MODE_RSV 0x00000001 +#define USB_MODE_CTRL_MODE_MASK 0x00000003#define USB_MODE_SETUP_LOCK_OFF 0x00000008#define USB_MODE_STREAM_DISABLE 0x00000010/* Endpoint Flush Register */
@@ -603,7 +605,8 @@ static void nuke(struct fsl_ep *ep, int status)static int dr_controller_setup (struct fsl_udc *udc) { -unsigned int tmp, portctrl; +unsigned int tmp, portctrl, ep_num; +unsigned int max_no_of_ep;uint64_t to;/* Config PHY interface */
@@ -647,6 +650,7 @@ static int dr_controller_setup(struct fsl_udc *udc)/* Set the controller as device mode */ tmp =readl (&dr_regs->usbmode); + tmp &= ~USB_MODE_CTRL_MODE_MASK ;/* clear mode bits */ tmp |=USB_MODE_CTRL_MODE_DEVICE ;/* Disable Setup Lockout */ tmp |=USB_MODE_SETUP_LOCK_OFF ;
@@ -659,6 +663,14 @@ static int dr_controller_setup(struct fsl_udc *udc) tmp &=USB_EP_LIST_ADDRESS_MASK ;writel (tmp, &dr_regs->endpointlistaddr); + max_no_of_ep = (0x0000001F &readl (&dr_regs->dccparams)); +for (ep_num =1 ; ep_num < max_no_of_ep; ep_num++) { + tmp =readl (&dr_regs->endptctrl[ep_num]); + tmp &= ~(EPCTRL_TX_TYPE |EPCTRL_RX_TYPE ); + tmp |= (EPCTRL_EP_TYPE_BULK <<EPCTRL_TX_EP_TYPE_SHIFT ) + | (EPCTRL_EP_TYPE_BULK <<EPCTRL_RX_EP_TYPE_SHIFT ); +writel (tmp, &dr_regs->endptctrl[ep_num]); + }VDBG ("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x" , udc->ep_qh, (int )tmp,readl (&dr_regs->endpointlistaddr));
@@ -725,12 +737,14 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,if (ep_num) tmp_epctrl |=EPCTRL_TX_DATA_TOGGLE_RST ; tmp_epctrl |=EPCTRL_TX_ENABLE ; + tmp_epctrl &= ~EPCTRL_TX_TYPE ; tmp_epctrl |= ((unsigned int )(ep_type) <<EPCTRL_TX_EP_TYPE_SHIFT ); }else {if (ep_num) tmp_epctrl |=EPCTRL_RX_DATA_TOGGLE_RST ; tmp_epctrl |=EPCTRL_RX_ENABLE ; + tmp_epctrl &= ~EPCTRL_RX_TYPE ; tmp_epctrl |= ((unsigned int )(ep_type) <<EPCTRL_RX_EP_TYPE_SHIFT ); }
@@ -887,7 +901,7 @@ static int fsl_ep_enable(struct usb_ep *_ep,case USB_ENDPOINT_XFER_ISOC :/* Calculate transactions needed for high bandwidth iso */ mult = (unsigned char )(1 + ((max >>11 ) &0x03 )); - max = max &0x8ff ;/* bit 0~10 */ + max = max &0x7ff ;/* bit 0~10 */ /* 3 transactions at most */ if (mult >3 ) goto en_done;
@@ -924,7 +938,6 @@ static int fsl_ep_enable(struct usb_ep *_ep, (desc->bEndpointAddress &USB_DIR_IN ) ? "in" : "out", max); en_done: -printf ("%s: %d\n" , __func__, retval);return retval; }
@@ -948,10 +961,13 @@ static int fsl_ep_disable(struct usb_ep *_ep)/* disable ep on controller */ ep_num =ep_index (ep); epctrl =readl (&dr_regs->endptctrl[ep_num]); -if (ep_is_in (ep)) - epctrl &= ~EPCTRL_TX_ENABLE ; -else - epctrl &= ~EPCTRL_RX_ENABLE ; +if (ep_is_in (ep)) { + epctrl &= ~(EPCTRL_TX_ENABLE |EPCTRL_TX_TYPE ); + epctrl |=EPCTRL_EP_TYPE_BULK <<EPCTRL_TX_EP_TYPE_SHIFT ; + }else { + epctrl &= ~(EPCTRL_RX_ENABLE |EPCTRL_TX_TYPE ); + epctrl |=EPCTRL_EP_TYPE_BULK <<EPCTRL_RX_EP_TYPE_SHIFT ; + }writel (epctrl, &dr_regs->endptctrl[ep_num]); udc = (struct fsl_udc *)ep->udc;
@@ -1921,7 +1937,7 @@ int usb_gadget_poll(void)/* Disable ISR for OTG host mode */ if (udc->stopped) -return 0 ; +return -EIO ; irq_src =readl (&dr_regs->usbsts) &readl (&dr_regs->usbintr);/* Clear notification bits */
@@ -1999,7 +2015,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)/* bind udc driver to gadget driver */ retval = driver->bind (&udc_controller->gadget);if (retval) { -VDBG ("bind to %s --> %d" , driver->driver.name, retval); +VDBG ("bind to gadget --> %d" , retval); udc_controller->driver =NULL ; goto out; }
@@ -2231,6 +2247,15 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,return 0 ; } +static void fsl_udc_poller (struct poller_struct *poller) +{ +usb_gadget_poll (); +} + +static struct poller_struct poller = { + .func = fsl_udc_poller +}; +static int fsl_udc_probe (struct device_d *dev) {int ret, i;
@@ -2293,6 +2318,8 @@ static int fsl_udc_probe(struct device_d *dev)struct_ep_setup (udc_controller, i *2 +1 , name,1 ); } +poller_register (&poller); +return 0 ; err_out:return ret;
Signature · 7 lines
1.7.7.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v4 2/5 dfu: fill bwPollTimeout and better handle detach
- bwPollTimeout is set to 10 ms, from the DFU spec, this is the minimum time, in milliseconds, that the host should wait before sending a subsequent DFU_GETSTATUS request. Without this, I get 25 seconds value and dfu-util waits twice 25s during download
- when in IDLE and receiving DETACH, first return 0 to make dfu-util happy, then use a dfudetach variable to exit dfu (without an USB reset as per the comment on line 425) and return to runtime mode.
- tested on i.MX25 & i.MX35 & usb-a926x
--- drivers/usb/gadget/dfu.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
drivers/usb/gadget/dfu.c +8 -1
@@ -67,6 +67,7 @@ static int dfualt;static int dfufd = -EINVAL ;;static struct usb_dfu_dev *dfu_devs;static int dfu_num_alt; +static int dfudetach;/* USB DFU functional descriptor */ static struct usb_dfu_func_descriptor usb_dfu_func = {
@@ -204,6 +205,9 @@ static int dfu_status(struct usb_function *f, const struct usb_ctrlrequest *ctrl dstat->bStatus = dfu->dfu_status; dstat->bState = dfu->dfu_state; dstat->iString =0 ; + dstat->bwPollTimeout[0 ] =10 ; + dstat->bwPollTimeout[1 ] =0 ; + dstat->bwPollTimeout[2 ] =0 ;return sizeof (*dstat); }
@@ -425,6 +429,8 @@ static int dfu_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)* least the Linux USB stack likes to send a number of resets * in a row :( */ dfu->dfu_state = DFU_STATE_dfuMANIFEST_WAIT_RST; + value =0 ; + dfudetach =1 ;break ;default : dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -690,11 +696,12 @@ int usb_dfu_register(struct usb_dfu_pdata *pdata)while (1 ) {usb_gadget_poll (); -if (ctrlc ()) +if (ctrlc () || dfudetach) goto out; } out: + dfudetach =0 ;usb_composite_unregister (&dfu_driver);return 0 ;
Signature · 7 lines
1.7.7.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v4 3/5 serial gadget: enable/disable on request
In reply to Eric Bénard- add a usbserial command to enable/disable the serial gadget
- allow dfu and usbserial to cohexist in the same barebox
- add a timeout in u_serial so that we don't get locked if the user enable usbserial from a UART console but doesn't consume the data on the usbserial port created on the PC
- remove debug or verbose printf
- tested on i.MX25 & i.MX35 & usb-a926x
---
v4 : introduce HAVE_OBEX as suggested by Sascha v3 : fix comment in usbserial.c and add usbserial.h v2 : always recompile after fixing checkpatch notes ...
commands/Makefile | 1 + commands/usbserial.c | 108 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/Kconfig | 5 +-- drivers/usb/gadget/f_acm.c | 4 +- drivers/usb/gadget/serial.c | 48 ++++++++++++++++-- drivers/usb/gadget/u_serial.c | 22 +++++--- include/usb/usbserial.h | 19 +++++++ 7 files changed, 188 insertions(+), 19 deletions(-) create mode 100644 commands/usbserial.c create mode 100644 include/usb/usbserial.h
commands/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_CMD_LSMOD) += lsmod.o obj-$(CONFIG_CMD_INSMOD) += insmod.o obj-$(CONFIG_CMD_BMP) += bmp.o obj-$(CONFIG_USB_GADGET_DFU) += dfu.o +obj-$(CONFIG_USB_GADGET_SERIAL) += usbserial.o obj-$(CONFIG_CMD_GPIO) += gpio.o obj-$(CONFIG_CMD_UNCOMPRESS) += uncompress.o obj-$(CONFIG_CMD_I2C) += i2c.o
commands/usbserial.c new file +108 -0
108 lines not on this page · raw message
drivers/usb/gadget/Kconfig +1 -4
@@ -30,8 +30,7 @@ config USB_GADGET_DRIVER_PXA27X select POLLER endchoice -choice - prompt "USB Gadget drivers" +comment "USB Gadget drivers" config USB_GADGET_DFU bool
@@ -42,7 +41,5 @@ config USB_GADGET_SERIAL depends on EXPERIMENTAL prompt "Serial Gadget" -endchoice - endif
drivers/usb/gadget/f_acm.c +2 -2
@@ -407,7 +407,7 @@ static void acm_disable(struct usb_function *f) {struct f_acm *acm =func_to_acm (f); -printf ("acm ttyGS%d deactivated\n" , acm->port_num); +VDBG (cdev,"acm ttyGS%d deactivated\n" , acm->port_num);gserial_disconnect (&acm->port);usb_ep_disable (acm->notify); acm->notify->driver_data =NULL ;
@@ -473,7 +473,7 @@ static int acm_notify_serial_state(struct f_acm *acm)int status;if (acm->notify_req) { -printf ("acm ttyGS%d serial state %04x\n" , +VDBG (cdev,"acm ttyGS%d serial state %04x\n" , acm->port_num, acm->serial_state); status =acm_cdc_notify (acm,USB_CDC_NOTIFY_SERIAL_STATE ,0 , &acm->serial_state,sizeof (acm->serial_state));
drivers/usb/gadget/serial.c +43 -5
105 lines not on this page · raw message
drivers/usb/gadget/u_serial.c +14 -8
@@ -20,6 +20,7 @@#include <common.h> #include <usb/cdc.h> #include <kfifo.h> +#include <clock.h> #include "u_serial.h"
@@ -107,8 +108,6 @@ static unsigned n_ports;#define GS_CLOSE_TIMEOUT 15/* seconds */ - -#ifdef VERBOSE_DEBUG #define pr_vdebug(fmt, arg...) \ pr_debug(fmt, ##arg)
@@ -370,6 +369,7 @@ static void serial_putc(struct console_device *cdev, char c)struct usb_ep *in;struct usb_request *req;int status; +uint64_t to;if (list_empty (pool))return ;
@@ -382,8 +382,12 @@ static void serial_putc(struct console_device *cdev, char c) *(unsigned char *)req->buf = c; status =usb_ep_queue (in, req); -while (status >=0 &&list_empty (pool)) + to =get_time_ns (); +while (status >=0 &&list_empty (pool)) { status =usb_gadget_poll (); +if (is_timeout (to,300 *MSECOND )) +break ; + } }static int serial_tstc (struct console_device *cdev)
@@ -399,11 +403,16 @@ static int serial_getc(struct console_device *cdev)struct gs_port *port =container_of (cdev, struct gs_port, cdev);unsigned char ch; +uint64_t to;if (!port->port_usb)return -EIO ; -while (kfifo_getc (port->recv_fifo, &ch)) + to =get_time_ns (); +while (kfifo_getc (port->recv_fifo, &ch)) {usb_gadget_poll (); +if (is_timeout (to,300 *MSECOND )) +break ; + }return ch; }
@@ -420,8 +429,6 @@ int gserial_connect(struct gserial *gser, u8 port_num)int status;struct console_device *cdev; -printf ("%s %p %d\n" , __func__, gser, port_num); -/* we "know" gserial_cleanup() hasn't been called */ port = ports[port_num].port;
@@ -451,7 +458,7 @@ int gserial_connect(struct gserial *gser, u8 port_num) port->recv_fifo =kfifo_alloc (1024 ); -printf ("gserial_connect: start ttyGS%d\n" , port->port_num); +/*printf("gserial_connect: start ttyGS%d\n", port->port_num);*/ gs_start_io (port);if (gser->connect) gser->connect (gser);
@@ -508,7 +515,6 @@ void gserial_disconnect(struct gserial *gser)struct gs_port *port = gser->ioport;struct console_device *cdev; -printf ("%s\n" , __func__);if (!port)return ;
include/usb/usbserial.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef _USB_SERIAL_H +#define _USB_SERIAL_H + +struct usb_serial_pdata { +char *manufacturer; +char *productname; +u16 idVendor; +u16 idProduct; +int mode; +}; + +int usb_serial_register (struct usb_serial_pdata *pdata); +void usb_serial_unregister (void ); + +/* OBEX support is missing in barebox */ +/* #define HAVE_OBEX */ + +#endif /* _USB_SERIAL_H */ +
Signature · 7 lines
1.7.7.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v4 4/5 timeout: add poller_call
In reply to Eric Bénardwithout this, usb gadget can't enumerate during boot once the timeout command is launched (thus preventing usbserial console access to take control of the board before autoboot)
--- commands/timeout.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
commands/timeout.c +2 -0
@@ -25,6 +25,7 @@#include <errno.h> #include <getopt.h> #include <clock.h> +#include <poller.h> #define TIMEOUT_RETURN (1 << 0)#define TIMEOUT_CTRLC (1 << 1)
@@ -70,6 +71,7 @@ static int do_timeout(struct command *cmdtp, int argc, char *argv[])printf ("%2d" , countdown--); do { + poller_call(); if (tstc()) { int key = getc(); if (flags & TIMEOUT_CTRLC && key == 3)
Signature · 7 lines
1.7.7.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v4 5/5 eukrea_cpuimx35: fix compilation when CONFIG_USB_GADGET is enabled
In reply to Eric Bénardthis was introduced in "6b3e01a arm: eukrea: Fix compilation warning"
--- arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c +3 -0
@@ -144,6 +144,9 @@ postmmu_initcall(eukrea_cpuimx35_mmu_init);static int eukrea_cpuimx35_devices_init (void ) { +#ifdef CONFIG_USB_GADGET +unsigned int tmp; +#endif imx35_add_nand (&nand_info);devfs_add_partition ("nand0" ,0x00000 ,0x40000 ,PARTITION_FIXED ,"self_raw" );
Signature · 7 lines
1.7.7.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v4 4/5] timeout: add poller_call
In reply to Eric BénardQuoted 5 lines · Eric Bénard
without this, usb gadget can't enumerate during boot once the timeout command is launched (thus preventing usbserial console access to take control of the board before autoboot)
Signed-off-by Eric Bénard <[email protected]>
I send a patch to put it in the is_timeout c code
I think it's better
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v4 4/5] timeout: add poller_call
Hi Jean-Christophe,
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Eric Bénard
without this, usb gadget can't enumerate during boot once the timeout command is launched (thus preventing usbserial console access to take control of the board before autoboot)
Signed-off-by Eric Bénard <[email protected]>I send a patch to put it in the
is_timeoutc code
I just saw it.
Quoted 1 line
I think it's better
Maybe, I don't understand whyu you need to add if (time_offset_ns >= 100 * USECOND) which was not here before.
Eric
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v4 4/5] timeout: add poller_call
Quoted 12 lines · Eric Bénard
Hi Jean-Christophe,
Quoted 7 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Eric Bénard
without this, usb gadget can't enumerate during boot once the timeout command is launched (thus preventing usbserial console access to take control of the board before autoboot)
Signed-off-by Eric Bénard <[email protected]>
Quoted 7 lines
Quoted 2 lines
I send a patch to put it in the
is_timeoutc codeI just saw it.
Quoted 1 line
I think it's better
Maybe, I don't understand whyu you need to add if (
time_offset_ns>= 100 * USECOND) which was not here before.
I'm working to add bitbanging i2c so I do not want the small delay to be impacted by the pull
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v4 4/5] timeout: add poller_call
Hi Jean-Christophe,
Quoted 15 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 14 lines · Eric Bénard
Hi Jean-Christophe,
Quoted 9 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Eric Bénard
without this, usb gadget can't enumerate during boot once the timeout command is launched (thus preventing usbserial console access to take control of the board before autoboot)
Signed-off-by Eric Bénard <[email protected]>I send a patch to put it in the
is_timeoutc code
Quoted 8 lines
Quoted 5 lines
I just saw it.
Quoted 1 line
I think it's better
Maybe, I don't understand whyu you need to add if (
time_offset_ns>= 100 * USECOND) which was not here before.I'm working to add bitbanging i2c so I do not want the small delay to be impacted by the pull
then I suggest you first add the poll change without this test, and then add this test once you add bitbanging i2c. That will make the change more understandable.
Eric
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v4 4/5] timeout: add poller_call
In reply to Jean-Christophe PLAGNIOL-VILLARDHi Jean-Christophe,
Quoted 11 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Eric Bénard
without this, usb gadget can't enumerate during boot once the timeout command is launched (thus preventing usbserial console access to take control of the board before autoboot)
Signed-off-by Eric Bénard <[email protected]>I send a patch to put it in the
is_timeoutc codeI think it's better
I confirm it's better as it also fix the same problem when having a menu with autoselection.
Thanks !
Eric
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox