[U-Boot] [PATCH V3 00/20] Make mv_udc work for i.mx6

Hi Marek, Stefano
This series is based on u-boot-usb/master branch. After this series, nitrogen6x works with tftpboot to transfer files over usb.
V2 was dropped to my bad posting of it and should be ignored.
This V3 is a rebase and most patches had to be changed slightly. I also ran a ./MAKEALL -a arm and fixed the errors that the V1 series had.
The most noticeable change is the addition of
usb: gadget: mv_udc: fix hardware udc address for i.MX6
Let me know if you want to go back to a udc variable to store the address instead of using hcor.
Stefano, would you like to take patches 1-5 ? I'll likely need a V3, but maybe the early ones will be approved.
Thanks
Troy Kisky (20): Add functions for use with i.mx6 otg udc mx6: iomux: add GPR1 defines nitrogen6x: add otg usb ethernet gadget support nitrogen6x: add CONFIG_MV_UDC arch-mxs/sys_proto.h: include regs-common.h usb: gadget: mv_udc: fix hardware udc address for i.MX6 usb: gadget: config: fix unaligned access issues usb: gadget: mv_udc: add MX6Q specific reset usb: gadget: ether set wMaxPacketSize usb: gadget: ether: return error from rx_submit if no request usb: gadget: mv_udc: split mv_udc.h file usb: udc: add udc.h include file usb: gadget: mv_udc: fix typo in error message usb: gadget: mv_udc: set is_dualspeed = 1 usb: gadget: mv_udc: fix full speed connections usb: gadget: mv_udc: optimize bounce usb: gadget: mv_udc: flush item before head usb: gadget: mv_udc: optimize ep_enable usb: gadget: mv_udc: zero transfer descriptor memory on probe usb: gadget: mv_udc: clear desc upon ep_disable
arch/arm/cpu/armv7/mx6/soc.c | 47 ++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h | 3 + arch/arm/include/asm/arch-mx6/imx-regs.h | 17 ++++ arch/arm/include/asm/arch-mx6/iomux.h | 6 ++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 + arch/arm/include/asm/arch-mxs/sys_proto.h | 2 + board/boundary/nitrogen6x/nitrogen6x.c | 16 ++++ drivers/serial/usbtty.h | 3 +- drivers/usb/gadget/config.c | 6 +- drivers/usb/gadget/designware_udc.c | 1 + drivers/usb/gadget/ether.c | 4 + drivers/usb/gadget/mpc8xx_udc.c | 1 + drivers/usb/gadget/mv_udc.c | 141 +++++++++++++++++++----------- drivers/usb/gadget/mv_udc.h | 115 ++++++++++++++++++++++++ drivers/usb/gadget/omap1510_udc.c | 1 + drivers/usb/gadget/pxa27x_udc.c | 1 + drivers/usb/musb/musb_udc.c | 3 +- include/configs/nitrogen6x.h | 6 ++ include/usb/designware_udc.h | 31 ------- include/usb/mpc8xx_udc.h | 19 +--- include/usb/musb_udc.h | 40 --------- include/usb/mv_udc.h | 118 ------------------------- include/usb/omap1510_udc.h | 27 +----- include/usb/pxa27x_udc.h | 26 +----- include/usb/udc.h | 63 +++++++++++++ 25 files changed, 389 insertions(+), 312 deletions(-) create mode 100644 drivers/usb/gadget/mv_udc.h delete mode 100644 include/usb/musb_udc.h create mode 100644 include/usb/udc.h

Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- arch/arm/cpu/armv7/mx6/soc.c | 47 +++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h | 3 ++ arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
diff --git a/arch/arm/cpu/armv7/mx6/soc.c b/arch/arm/cpu/armv7/mx6/soc.c index 32572ee..37e8c7f 100644 --- a/arch/arm/cpu/armv7/mx6/soc.c +++ b/arch/arm/cpu/armv7/mx6/soc.c @@ -12,11 +12,58 @@ #include <asm/io.h> #include <asm/arch/imx-regs.h> #include <asm/arch/clock.h> +#include <asm/arch/crm_regs.h> #include <asm/arch/sys_proto.h> #include <asm/imx-common/boot_mode.h> #include <asm/imx-common/dma.h> #include <stdbool.h>
+#ifdef CONFIG_MV_UDC +static void enable_usb_phy1_clk(unsigned char enable) +{ + struct usbphy *phy = (struct usbphy *)USB_PHY0_BASE_ADDR; + + writel(BM_USBPHY_CTRL_CLKGATE, + enable ? &phy->ctrl.clr : &phy->ctrl.set); +} + +void reset_usb_phy1(void) +{ + struct usbphy *phy = (struct usbphy *)USB_PHY0_BASE_ADDR; + + /* Reset USBPHY module */ + writel(BM_USBPHY_CTRL_SFTRST, &phy->ctrl.set); + udelay(10); + + /* Remove CLKGATE and SFTRST */ + writel(BM_USBPHY_CTRL_CLKGATE | BM_USBPHY_CTRL_SFTRST, &phy->ctrl.clr); + udelay(10); + + /* Power up the PHY */ + writel(0, &phy->pwd.val); +} + +static void set_usb_phy1_clk(void) +{ + struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR; + + writel(BM_ANADIG_USB1_CHRG_DETECT_EN_B + | BM_ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B, + &anatop->usb1_chrg_detect_set); + + /* make sure pll is enable here */ + writel(BM_ANADIG_USB1_PLL_480_CTRL_EN_USB_CLKS, + &anatop->usb1_pll_480_ctrl_set); +} + +void otg_enable(void) +{ + set_usb_phy1_clk(); + enable_usboh3_clk(1); + enable_usb_phy1_clk(1); +} +#endif + struct scu_regs { u32 ctrl; u32 config; diff --git a/arch/arm/include/asm/arch-mx6/crm_regs.h b/arch/arm/include/asm/arch-mx6/crm_regs.h index 74aefe6..364d9a4 100644 --- a/arch/arm/include/asm/arch-mx6/crm_regs.h +++ b/arch/arm/include/asm/arch-mx6/crm_regs.h @@ -647,6 +647,9 @@ struct mxc_ccm_reg { #define BF_ANADIG_USB1_PLL_480_CTRL_DIV_SELECT(v) \ (((v) << 0) & BM_ANADIG_USB1_PLL_480_CTRL_DIV_SELECT)
+#define BM_ANADIG_USB1_CHRG_DETECT_EN_B 0x00100000 +#define BM_ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B 0x00080000 + #define BM_ANADIG_PLL_528_LOCK 0x80000000 #define BP_ANADIG_PLL_528_RSVD1 19 #define BM_ANADIG_PLL_528_RSVD1 0x7FF80000 diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs { ECSPI5_BASE_ADDR #endif
+struct set_clr_tog { + u32 val; + u32 set; + u32 clr; + u32 tog; +}; + +struct usbphy { + struct set_clr_tog pwd; + struct set_clr_tog tx; + struct set_clr_tog rx; + struct set_clr_tog ctrl; +}; + +#define BM_USBPHY_CTRL_CLKGATE 0x40000000 +#define BM_USBPHY_CTRL_SFTRST 0x80000000 + struct ocotp_regs { u32 ctrl; u32 ctrl_set; diff --git a/arch/arm/include/asm/arch-mx6/sys_proto.h b/arch/arm/include/asm/arch-mx6/sys_proto.h index bfdfd29..4413c3f 100644 --- a/arch/arm/include/asm/arch-mx6/sys_proto.h +++ b/arch/arm/include/asm/arch-mx6/sys_proto.h @@ -40,4 +40,8 @@ int mxs_wait_mask_set(struct mxs_register_32 *reg, int mxs_wait_mask_clr(struct mxs_register_32 *reg, uint32_t mask, unsigned int timeout); + +void otg_enable(void); +void reset_usb_phy1(void); + #endif

Dear Troy Kisky,
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47 +++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h | 3 ++ arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
[...]
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs { ECSPI5_BASE_ADDR #endif
+struct set_clr_tog {
- u32 val;
- u32 set;
- u32 clr;
- u32 tog;
+};
+struct usbphy {
- struct set_clr_tog pwd;
- struct set_clr_tog tx;
- struct set_clr_tog rx;
- struct set_clr_tog ctrl;
+};
Maybe you want to keep the naming here consistent with MX28 and MX6?
See arch/arm/include/asm/imx-common/regs-common.h
[...]
Best regards, Marek Vasut

On 8/2/2013 3:48 AM, Marek Vasut wrote:
Dear Troy Kisky,
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47 +++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h | 3 ++ arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
[...]
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs { ECSPI5_BASE_ADDR #endif
+struct set_clr_tog {
- u32 val;
- u32 set;
- u32 clr;
- u32 tog;
+};
+struct usbphy {
- struct set_clr_tog pwd;
- struct set_clr_tog tx;
- struct set_clr_tog rx;
- struct set_clr_tog ctrl;
+};
Maybe you want to keep the naming here consistent with MX28 and MX6?
See arch/arm/include/asm/imx-common/regs-common.h
[...]
Best regards, Marek Vasut
Wow, arch/arm/include/asm/imx-common/regs-common.h is damn ugly. I personally hate unions even when there is a very good reason.
Would you like to see me attempt to clean it up or do you like it the way it is since your commit started the unions ?
Troy

Dear Troy Kisky,
On 8/2/2013 3:48 AM, Marek Vasut wrote:
Dear Troy Kisky,
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47
+++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h
| 3 ++
arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
[...]
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs {
ECSPI5_BASE_ADDR
#endif
+struct set_clr_tog {
- u32 val;
- u32 set;
- u32 clr;
- u32 tog;
+};
+struct usbphy {
- struct set_clr_tog pwd;
- struct set_clr_tog tx;
- struct set_clr_tog rx;
- struct set_clr_tog ctrl;
+};
Maybe you want to keep the naming here consistent with MX28 and MX6?
See arch/arm/include/asm/imx-common/regs-common.h
[...]
Best regards, Marek Vasut
Wow, arch/arm/include/asm/imx-common/regs-common.h is damn ugly. I personally hate unions even when there is a very good reason.
Would you like to see me attempt to clean it up or do you like it the way it is since your commit started the unions ?
I think it works perfectly well and does exactly what it's supposed to do. What's your problem with the file?
Best regards, Marek Vasut

On 8/2/2013 3:10 PM, Marek Vasut wrote:
Dear Troy Kisky,
On 8/2/2013 3:48 AM, Marek Vasut wrote:
Dear Troy Kisky,
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47
+++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h
| 3 ++
arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
[...]
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs {
ECSPI5_BASE_ADDR
#endif
+struct set_clr_tog {
- u32 val;
- u32 set;
- u32 clr;
- u32 tog;
+};
+struct usbphy {
- struct set_clr_tog pwd;
- struct set_clr_tog tx;
- struct set_clr_tog rx;
- struct set_clr_tog ctrl;
+};
Maybe you want to keep the naming here consistent with MX28 and MX6?
See arch/arm/include/asm/imx-common/regs-common.h
[...]
Best regards, Marek Vasut
Wow, arch/arm/include/asm/imx-common/regs-common.h is damn ugly. I personally hate unions even when there is a very good reason.
Would you like to see me attempt to clean it up or do you like it the way it is since your commit started the unions ?
I think it works perfectly well and does exactly what it's supposed to do. What's your problem with the file?
Best regards, Marek Vasut
Why is there a union ? It looks to me like you just want to access the same variable with 2 naming strategies.
Troy

Dear Troy Kisky,
On 8/2/2013 3:10 PM, Marek Vasut wrote:
Dear Troy Kisky,
On 8/2/2013 3:48 AM, Marek Vasut wrote:
Dear Troy Kisky,
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47
+++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h
| 3 ++ | arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
[...]
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs {
ECSPI5_BASE_ADDR
#endif
+struct set_clr_tog {
- u32 val;
- u32 set;
- u32 clr;
- u32 tog;
+};
+struct usbphy {
- struct set_clr_tog pwd;
- struct set_clr_tog tx;
- struct set_clr_tog rx;
- struct set_clr_tog ctrl;
+};
Maybe you want to keep the naming here consistent with MX28 and MX6?
See arch/arm/include/asm/imx-common/regs-common.h
[...]
Best regards, Marek Vasut
Wow, arch/arm/include/asm/imx-common/regs-common.h is damn ugly. I personally hate unions even when there is a very good reason.
Would you like to see me attempt to clean it up or do you like it the way it is since your commit started the unions ?
I think it works perfectly well and does exactly what it's supposed to do. What's your problem with the file?
Best regards, Marek Vasut
Why is there a union ? It looks to me like you just want to access the same variable with 2 naming strategies.
That is correct. I can either pass it further into functions as the struct mxs_register_32 name_reg or I can directly access it as name_set/_clr/_tog . Works just fine.
Best regards, Marek Vasut

On 8/2/2013 6:45 PM, Marek Vasut wrote:
Dear Troy Kisky,
On 8/2/2013 3:10 PM, Marek Vasut wrote:
Dear Troy Kisky,
On 8/2/2013 3:48 AM, Marek Vasut wrote:
Dear Troy Kisky,
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47
+++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h
| 3 ++ | arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
[...]
diff --git a/arch/arm/include/asm/arch-mx6/imx-regs.h b/arch/arm/include/asm/arch-mx6/imx-regs.h index 5d6bccb..3eed4d8 100644 --- a/arch/arm/include/asm/arch-mx6/imx-regs.h +++ b/arch/arm/include/asm/arch-mx6/imx-regs.h @@ -419,6 +419,23 @@ struct cspi_regs {
ECSPI5_BASE_ADDR #endif
+struct set_clr_tog {
- u32 val;
- u32 set;
- u32 clr;
- u32 tog;
+};
+struct usbphy {
- struct set_clr_tog pwd;
- struct set_clr_tog tx;
- struct set_clr_tog rx;
- struct set_clr_tog ctrl;
+};
Maybe you want to keep the naming here consistent with MX28 and MX6?
See arch/arm/include/asm/imx-common/regs-common.h
[...]
Best regards, Marek Vasut
Wow, arch/arm/include/asm/imx-common/regs-common.h is damn ugly. I personally hate unions even when there is a very good reason.
Would you like to see me attempt to clean it up or do you like it the way it is since your commit started the unions ?
I think it works perfectly well and does exactly what it's supposed to do. What's your problem with the file?
Best regards, Marek Vasut
Why is there a union ? It looks to me like you just want to access the same variable with 2 naming strategies.
That is correct. I can either pass it further into functions as the struct mxs_register_32 name_reg or I can directly access it as name_set/_clr/_tog . Works just fine.
I never said it didn't work, obviously it does.
Best regards, Marek Vasut
There may be code that you can point at that would make this useful, but I have a hard time envisioning it. The code I added, I know doesn't need a union, and I bet most of the other variable accesses don't need a union. That's why I asked if you'd like me to attempt to clean it up (always access thru struct, ie replace name_set with name.set).
I don't want to change the code I added to use this. I can see a small advantage in consistency with the mx28.
Troy

Dear Troy Kisky,
[...]
Why is there a union ? It looks to me like you just want to access the same variable with 2 naming strategies.
That is correct. I can either pass it further into functions as the struct mxs_register_32 name_reg or I can directly access it as name_set/_clr/_tog . Works just fine.
I never said it didn't work, obviously it does.
Best regards, Marek Vasut
There may be code that you can point at that would make this useful, but I have a hard time envisioning it. The code I added, I know doesn't need a union, and I bet most of the other variable accesses don't need a union. That's why I asked if you'd like me to attempt to clean it up (always access thru struct, ie replace name_set with name.set).
No, I want to keep this as-is. Especially because the MX28 has the registers named exactly by this scheme.
I don't want to change the code I added to use this.
Please do, I do not want a duplicit implementation of these register structures in the tree.
I can see a small advantage in consistency with the mx28.
THe MX6 uses many IP blocks from MX28 -- APBH DMA, NAND, USB -- to name a few. Keeping mx28 and mx6 aligned is more than helpful.
Best regards, Marek Vasut

On 8/3/2013 9:47 AM, Marek Vasut wrote:
Dear Troy Kisky,
[...]
Why is there a union ? It looks to me like you just want to access the same variable with 2 naming strategies.
That is correct. I can either pass it further into functions as the struct mxs_register_32 name_reg or I can directly access it as name_set/_clr/_tog . Works just fine.
I never said it didn't work, obviously it does.
Best regards, Marek Vasut
There may be code that you can point at that would make this useful, but I have a hard time envisioning it. The code I added, I know doesn't need a union, and I bet most of the other variable accesses don't need a union. That's why I asked if you'd like me to attempt to clean it up (always access thru struct, ie replace name_set with name.set).
No, I want to keep this as-is. Especially because the MX28 has the registers named exactly by this scheme.
Exactly matching documentation is a good advantage.
I don't want to change the code I added to use this.
Please do, I do not want a duplicit implementation of these register structures in the tree.
I can see a small advantage in consistency with the mx28.
THe MX6 uses many IP blocks from MX28 -- APBH DMA, NAND, USB -- to name a few. Keeping mx28 and mx6 aligned is more than helpful.
Best regards, Marek Vasut
Marek, I really appreciate your willingness to explain your reasoning. Though I wouldn't do this without prompting, perhaps my dislike of unions is a bit irrational. But since there are also many other places where this change could be made (grep _tog in arch-mx6/crm_regs.h, imx-regs.h,) I'd like Stefano to say he is OK with using mxs_reg_32 and doesn't share my opinion and doesn't want to rename it to something else. After all, you're talking about removing a structure with only 4 members, not a great amount of duplication.
Troy

Dear Troy Kisky,
On 8/3/2013 9:47 AM, Marek Vasut wrote:
Dear Troy Kisky,
[...]
Why is there a union ? It looks to me like you just want to access the same variable with 2 naming strategies.
That is correct. I can either pass it further into functions as the struct mxs_register_32 name_reg or I can directly access it as name_set/_clr/_tog . Works just fine.
I never said it didn't work, obviously it does.
Best regards, Marek Vasut
There may be code that you can point at that would make this useful, but I have a hard time envisioning it. The code I added, I know doesn't need a union, and I bet most of the other variable accesses don't need a union. That's why I asked if you'd like me to attempt to clean it up (always access thru struct, ie replace name_set with name.set).
No, I want to keep this as-is. Especially because the MX28 has the registers named exactly by this scheme.
Exactly matching documentation is a good advantage.
I don't want to change the code I added to use this.
Please do, I do not want a duplicit implementation of these register structures in the tree.
I can see a small advantage in consistency with the mx28.
THe MX6 uses many IP blocks from MX28 -- APBH DMA, NAND, USB -- to name a few. Keeping mx28 and mx6 aligned is more than helpful.
Best regards, Marek Vasut
Marek, I really appreciate your willingness to explain your reasoning. Though I wouldn't do this without prompting, perhaps my dislike of unions is a bit irrational. But since there are also many other places where this change could be made (grep _tog in arch-mx6/crm_regs.h, imx-regs.h,)
This clearly means that someone didn't look around before coding this stuff. Brief look indicates the OCOTP is taken from MX28 too and so is ANATOP.
I'd like Stefano to say he is OK with using mxs_reg_32 and doesn't share my opinion and doesn't want to rename it to something else. After all, you're talking about removing a structure with only 4 members, not a great amount of duplication.
I think I lost you here, sorry. To put down what I am talking about:
- Use what already is in imx-common/regs-common.h - imx-common/regs-common.h does not need change
I did not yet hear any reasonable argument to change the imx-common/regs- common.h file. Unions being ugly in your opinion is not a valid argument.
Note that MX28 was in the tree much earlier than MX6 and if MX6 did reinvent the wheel, it should be fixed before this duplication spreads. Especially so the MX6 and MX28 do not diverge and can share much of the code.
Best regards, Marek Vasut

Are there any news on this front? If not, please fix as requested so I can apply this stuff for .10 , thanks.
Best regards, Marek Vasut

On 8/15/2013 2:36 PM, Marek Vasut wrote:
Are there any news on this front? If not, please fix as requested so I can apply this stuff for .10 , thanks.
Best regards, Marek Vasut
I will update, I'm just sidetracked with Windows work for a little while.
Thanks Troy

Dear Troy Kisky,
In message 1375399657-25642-2-git-send-email-troy.kisky@boundarydevices.com you wrote:
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47 +++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h | 3 ++ arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
This appears to be V3 of this patch series, but I cannot see any kind of change log? Please note that this is a mandatory requirement, see http://www.denx.de/wiki/view/U-Boot/Patches#Sending_updated_patch_versions
Note this applies to the whole patch series.
Thanks!
Best regards,
Wolfgang Denk

On 8/4/2013 1:15 PM, Wolfgang Denk wrote:
Dear Troy Kisky,
In message 1375399657-25642-2-git-send-email-troy.kisky@boundarydevices.com you wrote:
Add functions for use with mx6 soc void otg_enable(void); void reset_usb_phy1(void);
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
arch/arm/cpu/armv7/mx6/soc.c | 47 +++++++++++++++++++++++++++++++ arch/arm/include/asm/arch-mx6/crm_regs.h | 3 ++ arch/arm/include/asm/arch-mx6/imx-regs.h | 17 +++++++++++ arch/arm/include/asm/arch-mx6/sys_proto.h | 4 +++ 4 files changed, 71 insertions(+)
This appears to be V3 of this patch series, but I cannot see any kind of change log? Please note that this is a mandatory requirement, see http://www.denx.de/wiki/view/U-Boot/Patches#Sending_updated_patch_versions
Note this applies to the whole patch series.
Yes, that does look wrong. V1 was not reviewed, I was asked to rebase because of many conflicting changes to the same file. I screwed up the posting of V2 and it also was not reviewed. I finally got a reviewable set of changes with V3. Sorry about the mess-up.
Troy

Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- arch/arm/include/asm/arch-mx6/iomux.h | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/arm/include/asm/arch-mx6/iomux.h b/arch/arm/include/asm/arch-mx6/iomux.h index f4cfd4f..9e6d40f 100644 --- a/arch/arm/include/asm/arch-mx6/iomux.h +++ b/arch/arm/include/asm/arch-mx6/iomux.h @@ -10,6 +10,12 @@ #define MX6_IOMUXC_GPR7 0x020e001c
/* + * IOMUXC_GPR1 bit fields + */ +#define IOMUXC_GPR1_OTG_ID_ENET_RX_ERR (0<<13) +#define IOMUXC_GPR1_OTG_ID_GPIO1 (1<<13) +#define IOMUXC_GPR1_OTG_ID_MASK (1<<13) +/* * IOMUXC_GPR13 bit fields */ #define IOMUXC_GPR13_SDMA_STOP_REQ (1<<30)

Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- board/boundary/nitrogen6x/nitrogen6x.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/board/boundary/nitrogen6x/nitrogen6x.c b/board/boundary/nitrogen6x/nitrogen6x.c index 1a29b6f..eedcd77 100644 --- a/board/boundary/nitrogen6x/nitrogen6x.c +++ b/board/boundary/nitrogen6x/nitrogen6x.c @@ -30,6 +30,7 @@ #include <i2c.h>
DECLARE_GLOBAL_DATA_PTR; +#define GP_USB_OTG_PWR IMX_GPIO_NR(3, 22)
#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ @@ -369,6 +370,13 @@ int board_eth_init(bd_t *bis) free(bus); } #endif + +#ifdef CONFIG_MV_UDC + otg_enable(); + + /* For otg ethernet*/ + usb_eth_initialize(bis); +#endif return 0; }
@@ -717,6 +725,7 @@ int board_early_init_f(void) gpio_direction_input(WL12XX_WL_IRQ_GP); gpio_direction_output(WL12XX_WL_ENABLE_GP, 0); gpio_direction_output(WL12XX_BT_ENABLE_GP, 0); + gpio_direction_output(GP_USB_OTG_PWR, 0); /* OTG power off */
imx_iomux_v3_setup_multiple_pads(wl12xx_pads, ARRAY_SIZE(wl12xx_pads)); setup_buttons(); @@ -738,6 +747,13 @@ int overwrite_console(void)
int board_init(void) { + struct iomuxc_base_regs *const iomuxc_regs + = (struct iomuxc_base_regs *)IOMUXC_BASE_ADDR; + + clrsetbits_le32(&iomuxc_regs->gpr[1], + IOMUXC_GPR1_OTG_ID_MASK, + IOMUXC_GPR1_OTG_ID_GPIO1); + /* address of boot parameters */ gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;

Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- include/configs/nitrogen6x.h | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/include/configs/nitrogen6x.h b/include/configs/nitrogen6x.h index 4242414..ce43b62 100644 --- a/include/configs/nitrogen6x.h +++ b/include/configs/nitrogen6x.h @@ -30,6 +30,12 @@ #define CONFIG_BOARD_EARLY_INIT_F #define CONFIG_MISC_INIT_R #define CONFIG_MXC_GPIO +#define CONFIG_MV_UDC +#define CONFIG_USBD_HS +#define CONFIG_USB_GADGET_DUALSPEED +#define CONFIG_USB_ETHER +#define CONFIG_USB_ETH_CDC +#define CONFIG_NETCONSOLE
#define CONFIG_CMD_FUSE #ifdef CONFIG_CMD_FUSE

sys_proto uses mxs_register_32 so include <asm/imx-common/regs-common.h>
like arch-mx6/sys_proto.h does.
This prevents warnings when building m28evk after the next patch in the series.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- arch/arm/include/asm/arch-mxs/sys_proto.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/arch/arm/include/asm/arch-mxs/sys_proto.h b/arch/arm/include/asm/arch-mxs/sys_proto.h index 1038592..5ed6070 100644 --- a/arch/arm/include/asm/arch-mxs/sys_proto.h +++ b/arch/arm/include/asm/arch-mxs/sys_proto.h @@ -10,6 +10,8 @@ #ifndef __SYS_PROTO_H__ #define __SYS_PROTO_H__
+#include <asm/imx-common/regs-common.h> + int mxs_reset_block(struct mxs_register_32 *reg); int mxs_wait_mask_set(struct mxs_register_32 *reg, uint32_t mask,

The hcor for i.MX6 is 02184340 and the udc should be 02184140
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
--- I don't know if this is a correct fix, please check carefully. --- drivers/usb/gadget/mv_udc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 7574e31..359b8e1 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -110,6 +110,16 @@ static struct mv_drv controller = { }, };
+struct mv_udc *get_mv_udc(void) +{ +#ifdef CONFIG_MXC_USB_PORT + return (struct mv_udc *)((unsigned)controller.ctrl->hcor + - (0x200 * CONFIG_MXC_USB_PORT)); +#else + return (struct mv_udc *)controller.ctrl->hcor; +#endif +} + /** * mv_get_qh() - return queue head for endpoint * @ep_num: Endpoint number @@ -213,7 +223,7 @@ static void mv_ep_free_request(struct usb_ep *ep, struct usb_request *_req) static void ep_enable(int num, int in) { struct ept_queue_head *head; - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); unsigned n; head = mv_get_qh(num, in);
@@ -316,7 +326,7 @@ static int mv_ep_queue(struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) { struct mv_ep *mv_ep = container_of(ep, struct mv_ep, ep); - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); struct ept_queue_item *item; struct ept_queue_head *head; int bit, num, len, in, ret; @@ -389,7 +399,7 @@ static void handle_ep_complete(struct mv_ep *ep) static void handle_setup(void) { struct usb_request *req = &controller.ep[0].req; - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); struct ept_queue_head *head; struct usb_ctrlrequest r; int status = 0; @@ -462,7 +472,7 @@ static void stop_activity(void) { int i, num, in; struct ept_queue_head *head; - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); writel(readl(&udc->epcomp), &udc->epcomp); writel(readl(&udc->epstat), &udc->epstat); writel(0xffffffff, &udc->epflush); @@ -485,7 +495,7 @@ static void stop_activity(void)
void udc_irq(void) { - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); unsigned n = readl(&udc->usbsts); writel(n, &udc->usbsts); int bit, i, num, in; @@ -543,7 +553,7 @@ void udc_irq(void) int usb_gadget_handle_interrupts(void) { u32 value; - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc();
value = readl(&udc->usbsts); if (value) @@ -554,7 +564,7 @@ int usb_gadget_handle_interrupts(void)
static int mv_pullup(struct usb_gadget *gadget, int is_on) { - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); if (is_on) { /* RESET */ writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd); @@ -582,7 +592,7 @@ static int mv_pullup(struct usb_gadget *gadget, int is_on)
void udc_disconnect(void) { - struct mv_udc *udc = (struct mv_udc *)controller.ctrl->hcor; + struct mv_udc *udc = get_mv_udc(); /* disable pullup */ stop_activity(); writel(USBCMD_FS2, &udc->usbcmd); @@ -694,7 +704,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
ret = mvudc_probe(); if (!ret) { - udc = (struct mv_udc *)controller.ctrl->hcor; + udc = get_mv_udc();
/* select ULPI phy */ writel(PTS(PTS_ENABLE) | PFSC, &udc->portsc);

Dear Troy Kisky,
The hcor for i.MX6 is 02184340 and the udc should be 02184140
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
I don't know if this is a correct fix, please check carefully.
drivers/usb/gadget/mv_udc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 7574e31..359b8e1 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -110,6 +110,16 @@ static struct mv_drv controller = { }, };
+struct mv_udc *get_mv_udc(void) +{ +#ifdef CONFIG_MXC_USB_PORT
- return (struct mv_udc *)((unsigned)controller.ctrl->hcor
- (0x200 * CONFIG_MXC_USB_PORT));
+#else
- return (struct mv_udc *)controller.ctrl->hcor;
+#endif +}
This in particular is something I wanted to avoid happening.
Can you instead call
usb_lowlevel_init(0, (void **)&controller.ctrl);
for different number than 0 in usb_gadget_register_driver() instead ? THe effect will be the same, yet the patch will be smaller.
Best regards, Marek Vasut

Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/config.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c index f563afe..014a679 100644 --- a/drivers/usb/gadget/config.c +++ b/drivers/usb/gadget/config.c @@ -10,6 +10,7 @@ */
#include <common.h> +#include <asm/unaligned.h> #include <asm/errno.h> #include <linux/list.h> #include <linux/string.h> @@ -86,7 +87,8 @@ int usb_gadget_config_buf( /* config descriptor first */ if (length < USB_DT_CONFIG_SIZE || !desc) return -EINVAL; - *cp = *config; + /* config need not be aligned */ + memcpy(cp, config, sizeof(*cp));
/* then interface/endpoint/class/vendor/... */ len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8 *)buf, @@ -100,7 +102,7 @@ int usb_gadget_config_buf( /* patch up the config descriptor */ cp->bLength = USB_DT_CONFIG_SIZE; cp->bDescriptorType = USB_DT_CONFIG; - cp->wTotalLength = cpu_to_le16(len); + put_unaligned_le16(len, &cp->wTotalLength); cp->bmAttributes |= USB_CONFIG_ATT_ONE; return len; }

Dear Troy Kisky,
I don't understand what this patch does and why. It's not very clear from the (missing) commit message either.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
drivers/usb/gadget/config.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c index f563afe..014a679 100644 --- a/drivers/usb/gadget/config.c +++ b/drivers/usb/gadget/config.c @@ -10,6 +10,7 @@ */
#include <common.h> +#include <asm/unaligned.h> #include <asm/errno.h> #include <linux/list.h> #include <linux/string.h> @@ -86,7 +87,8 @@ int usb_gadget_config_buf( /* config descriptor first */ if (length < USB_DT_CONFIG_SIZE || !desc) return -EINVAL;
- *cp = *config;
/* config need not be aligned */
memcpy(cp, config, sizeof(*cp));
/* then interface/endpoint/class/vendor/... */ len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8 *)buf,
@@ -100,7 +102,7 @@ int usb_gadget_config_buf( /* patch up the config descriptor */ cp->bLength = USB_DT_CONFIG_SIZE; cp->bDescriptorType = USB_DT_CONFIG;
- cp->wTotalLength = cpu_to_le16(len);
- put_unaligned_le16(len, &cp->wTotalLength); cp->bmAttributes |= USB_CONFIG_ATT_ONE; return len;
}
Best regards, Marek Vasut

Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
--- I don't know if this is needed, but it doesn't hurt. --- drivers/usb/gadget/mv_udc.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 359b8e1..26f193d 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -13,6 +13,7 @@ #include <config.h> #include <net.h> #include <malloc.h> +#include <asm/arch/sys_proto.h> #include <asm/io.h> #include <linux/types.h> #include <usb/mv_udc.h> @@ -569,6 +570,9 @@ static int mv_pullup(struct usb_gadget *gadget, int is_on) /* RESET */ writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd); udelay(200); +#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6DL) + reset_usb_phy1(); +#endif
writel((unsigned)controller.epts, &udc->epinitaddr);

Dear Troy Kisky,
Why are you adding this? Any kind of explanation is missing.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
I don't know if this is needed, but it doesn't hurt.
drivers/usb/gadget/mv_udc.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 359b8e1..26f193d 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -13,6 +13,7 @@ #include <config.h> #include <net.h> #include <malloc.h> +#include <asm/arch/sys_proto.h> #include <asm/io.h> #include <linux/types.h> #include <usb/mv_udc.h> @@ -569,6 +570,9 @@ static int mv_pullup(struct usb_gadget *gadget, int is_on) /* RESET */ writel(USBCMD_ITC(MICRO_8FRAME) | USBCMD_RST, &udc->usbcmd); udelay(200); +#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6DL)
reset_usb_phy1();
+#endif
writel((unsigned)controller.epts, &udc->epinitaddr);
Best regards, Marek Vasut

set wMaxPacketSize for full speed descriptors
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/ether.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 579893c..f583c6e 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -635,6 +635,7 @@ fs_source_desc = {
.bEndpointAddress = USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = __constant_cpu_to_le16(64), };
static struct usb_endpoint_descriptor @@ -644,6 +645,7 @@ fs_sink_desc = {
.bEndpointAddress = USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = __constant_cpu_to_le16(64), };
static const struct usb_descriptor_header *fs_eth_function[11] = {

Dear Troy Kisky,
set wMaxPacketSize for full speed descriptors
Why? Please elaborate more.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
drivers/usb/gadget/ether.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 579893c..f583c6e 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -635,6 +635,7 @@ fs_source_desc = {
.bEndpointAddress = USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = __constant_cpu_to_le16(64),
};
static struct usb_endpoint_descriptor @@ -644,6 +645,7 @@ fs_sink_desc = {
.bEndpointAddress = USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = __constant_cpu_to_le16(64),
};
static const struct usb_descriptor_header *fs_eth_function[11] = {
Best regards, Marek Vasut

This prevents a crash if tftpboot is given a bad filename.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/ether.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index f583c6e..fe73c7b 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1535,6 +1535,8 @@ static int rx_submit(struct eth_dev *dev, struct usb_request *req, */
debug("%s\n", __func__); + if (!req) + return -EINVAL;
size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA); size += dev->out_ep->maxpacket - 1;

Dear Troy Kisky,
This prevents a crash if tftpboot is given a bad filename.
How is bad filename related to struct usb_request?
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com
drivers/usb/gadget/ether.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index f583c6e..fe73c7b 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1535,6 +1535,8 @@ static int rx_submit(struct eth_dev *dev, struct usb_request *req, */
debug("%s\n", __func__);
if (!req)
return -EINVAL;
size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA); size += dev->out_ep->maxpacket - 1;
Best regards, Marek Vasut

Move defines only needed by mv_udc.c to a file in the same directory.
This allows usbtty to compile for mv_udc, but it still doesn't link.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 6 +++ drivers/usb/gadget/mv_udc.h | 115 ++++++++++++++++++++++++++++++++++++++++++ include/usb/mv_udc.h | 118 -------------------------------------------- 3 files changed, 121 insertions(+), 118 deletions(-) create mode 100644 drivers/usb/gadget/mv_udc.h
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 26f193d..0ff2e5e 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -14,9 +14,15 @@ #include <net.h> #include <malloc.h> #include <asm/arch/sys_proto.h> +#include <asm/byteorder.h> #include <asm/io.h> +#include <asm/errno.h> #include <linux/types.h> +#include <linux/usb/ch9.h> +#include <linux/usb/gadget.h> #include <usb/mv_udc.h> +#include "../host/ehci.h" +#include "mv_udc.h"
#if CONFIG_USB_MAX_CONTROLLER_COUNT > 1 #error This driver only supports one single controller. diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h new file mode 100644 index 0000000..c7d8b33 --- /dev/null +++ b/drivers/usb/gadget/mv_udc.h @@ -0,0 +1,115 @@ +/* + * Copyright 2011, Marvell Semiconductor Inc. + * + * Licensed under the GPL-2 or later. + */ +#ifndef __GADGET__MV_UDC_H__ +#define __GADGET__MV_UDC_H__ + +#define NUM_ENDPOINTS 6 + +struct mv_udc { +#define MICRO_8FRAME 0x8 +#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) +#define USBCMD_FS2 (1 << 15) +#define USBCMD_RST (1 << 1) +#define USBCMD_RUN (1) + u32 usbcmd; /* 0x140 */ +#define STS_SLI (1 << 8) +#define STS_URI (1 << 6) +#define STS_PCI (1 << 2) +#define STS_UEI (1 << 1) +#define STS_UI (1 << 0) + u32 usbsts; /* 0x144 */ + u32 pad1[3]; + u32 devaddr; /* 0x154 */ + u32 epinitaddr; /* 0x158 */ + u32 pad2[10]; +#define PTS_ENABLE 2 +#define PTS(x) (((x) & 0x3) << 30) +#define PFSC (1 << 24) + u32 portsc; /* 0x184 */ + u32 pad3[8]; +#define USBMODE_DEVICE 2 + u32 usbmode; /* 0x1a8 */ + u32 epstat; /* 0x1ac */ +#define EPT_TX(x) (1 << (((x) & 0xffff) + 16)) +#define EPT_RX(x) (1 << ((x) & 0xffff)) + u32 epprime; /* 0x1b0 */ + u32 epflush; /* 0x1b4 */ + u32 pad4; + u32 epcomp; /* 0x1bc */ +#define CTRL_TXE (1 << 23) +#define CTRL_TXR (1 << 22) +#define CTRL_RXE (1 << 7) +#define CTRL_RXR (1 << 6) +#define CTRL_TXT_BULK (2 << 18) +#define CTRL_RXT_BULK (2 << 2) + u32 epctrl[16]; /* 0x1c0 */ +}; + +struct mv_ep { + struct usb_ep ep; + struct list_head queue; + const struct usb_endpoint_descriptor *desc; + + struct usb_request req; + uint8_t *b_buf; + uint32_t b_len; + uint8_t b_fast[64] __aligned(ARCH_DMA_MINALIGN); +}; + +struct mv_drv { + struct usb_gadget gadget; + struct usb_gadget_driver *driver; + struct ehci_ctrl *ctrl; + struct ept_queue_head *epts; + struct ept_queue_item *items[2 * NUM_ENDPOINTS]; + uint8_t *items_mem; + struct mv_ep ep[NUM_ENDPOINTS]; +}; + +struct ept_queue_head { + unsigned config; + unsigned current; /* read-only */ + + unsigned next; + unsigned info; + unsigned page0; + unsigned page1; + unsigned page2; + unsigned page3; + unsigned page4; + unsigned reserved_0; + + unsigned char setup_data[8]; + + unsigned reserved_1; + unsigned reserved_2; + unsigned reserved_3; + unsigned reserved_4; +}; + +#define CONFIG_MAX_PKT(n) ((n) << 16) +#define CONFIG_ZLT (1 << 29) /* stop on zero-len xfer */ +#define CONFIG_IOS (1 << 15) /* IRQ on setup */ + +struct ept_queue_item { + unsigned next; + unsigned info; + unsigned page0; + unsigned page1; + unsigned page2; + unsigned page3; + unsigned page4; + unsigned reserved; +}; + +#define TERMINATE 1 +#define INFO_BYTES(n) ((n) << 16) +#define INFO_IOC (1 << 15) +#define INFO_ACTIVE (1 << 7) +#define INFO_HALTED (1 << 6) +#define INFO_BUFFER_ERROR (1 << 5) +#define INFO_TX_ERROR (1 << 3) +#endif diff --git a/include/usb/mv_udc.h b/include/usb/mv_udc.h index c71516c..f6c7b5e 100644 --- a/include/usb/mv_udc.h +++ b/include/usb/mv_udc.h @@ -9,124 +9,6 @@ #ifndef __MV_UDC_H__ #define __MV_UDC_H__
-#include <asm/byteorder.h> -#include <asm/errno.h> -#include <linux/usb/ch9.h> -#include <linux/usb/gadget.h> - -#include "../../drivers/usb/host/ehci.h" - -#define NUM_ENDPOINTS 6 - -/* Endpoint parameters */ -#define MAX_ENDPOINTS 4 - #define EP_MAX_PACKET_SIZE 0x200 #define EP0_MAX_PACKET_SIZE 64 - -struct mv_udc { -#define MICRO_8FRAME 0x8 -#define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) -#define USBCMD_FS2 (1 << 15) -#define USBCMD_RST (1 << 1) -#define USBCMD_RUN (1) - u32 usbcmd; /* 0x140 */ -#define STS_SLI (1 << 8) -#define STS_URI (1 << 6) -#define STS_PCI (1 << 2) -#define STS_UEI (1 << 1) -#define STS_UI (1 << 0) - u32 usbsts; /* 0x144 */ - u32 pad1[3]; - u32 devaddr; /* 0x154 */ - u32 epinitaddr; /* 0x158 */ - u32 pad2[10]; -#define PTS_ENABLE 2 -#define PTS(x) (((x) & 0x3) << 30) -#define PFSC (1 << 24) - u32 portsc; /* 0x184 */ - u32 pad3[8]; -#define USBMODE_DEVICE 2 - u32 usbmode; /* 0x1a8 */ - u32 epstat; /* 0x1ac */ -#define EPT_TX(x) (1 << (((x) & 0xffff) + 16)) -#define EPT_RX(x) (1 << ((x) & 0xffff)) - u32 epprime; /* 0x1b0 */ - u32 epflush; /* 0x1b4 */ - u32 pad4; - u32 epcomp; /* 0x1bc */ -#define CTRL_TXE (1 << 23) -#define CTRL_TXR (1 << 22) -#define CTRL_RXE (1 << 7) -#define CTRL_RXR (1 << 6) -#define CTRL_TXT_BULK (2 << 18) -#define CTRL_RXT_BULK (2 << 2) - u32 epctrl[16]; /* 0x1c0 */ -}; - -struct mv_ep { - struct usb_ep ep; - struct list_head queue; - const struct usb_endpoint_descriptor *desc; - - struct usb_request req; - uint8_t *b_buf; - uint32_t b_len; - uint8_t b_fast[64] __aligned(ARCH_DMA_MINALIGN); -}; - -struct mv_drv { - struct usb_gadget gadget; - struct usb_gadget_driver *driver; - struct ehci_ctrl *ctrl; - struct ept_queue_head *epts; - struct ept_queue_item *items[2 * NUM_ENDPOINTS]; - uint8_t *items_mem; - struct mv_ep ep[NUM_ENDPOINTS]; -}; - -struct ept_queue_head { - unsigned config; - unsigned current; /* read-only */ - - unsigned next; - unsigned info; - unsigned page0; - unsigned page1; - unsigned page2; - unsigned page3; - unsigned page4; - unsigned reserved_0; - - unsigned char setup_data[8]; - - unsigned reserved_1; - unsigned reserved_2; - unsigned reserved_3; - unsigned reserved_4; -}; - -#define CONFIG_MAX_PKT(n) ((n) << 16) -#define CONFIG_ZLT (1 << 29) /* stop on zero-len xfer */ -#define CONFIG_IOS (1 << 15) /* IRQ on setup */ - -struct ept_queue_item { - unsigned next; - unsigned info; - unsigned page0; - unsigned page1; - unsigned page2; - unsigned page3; - unsigned page4; - unsigned reserved; -}; - -#define TERMINATE 1 -#define INFO_BYTES(n) ((n) << 16) -#define INFO_IOC (1 << 15) -#define INFO_ACTIVE (1 << 7) -#define INFO_HALTED (1 << 6) -#define INFO_BUFFER_ERROR (1 << 5) -#define INFO_TX_ERROR (1 << 3) - #endif /* __MV_UDC_H__ */

Move common defintions to udc.h
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/serial/usbtty.h | 3 +- drivers/usb/gadget/designware_udc.c | 1 + drivers/usb/gadget/mpc8xx_udc.c | 1 + drivers/usb/gadget/omap1510_udc.c | 1 + drivers/usb/gadget/pxa27x_udc.c | 1 + drivers/usb/musb/musb_udc.c | 3 +- include/usb/designware_udc.h | 31 ------------------ include/usb/mpc8xx_udc.h | 19 +---------- include/usb/musb_udc.h | 40 ----------------------- include/usb/omap1510_udc.h | 27 ++-------------- include/usb/pxa27x_udc.h | 26 +-------------- include/usb/udc.h | 63 +++++++++++++++++++++++++++++++++++++ 12 files changed, 75 insertions(+), 141 deletions(-) delete mode 100644 include/usb/musb_udc.h create mode 100644 include/usb/udc.h
diff --git a/drivers/serial/usbtty.h b/drivers/serial/usbtty.h index e243a8e..819dec6 100644 --- a/drivers/serial/usbtty.h +++ b/drivers/serial/usbtty.h @@ -16,8 +16,6 @@ #include <usb/mpc8xx_udc.h> #elif defined(CONFIG_OMAP1510) #include <usb/omap1510_udc.h> -#elif defined(CONFIG_MUSB_UDC) -#include <usb/musb_udc.h> #elif defined(CONFIG_CPU_PXA27X) #include <usb/pxa27x_udc.h> #elif defined(CONFIG_DW_UDC) @@ -26,6 +24,7 @@ #include <usb/mv_udc.h> #endif
+#include <usb/udc.h> #include <version.h>
/* If no VendorID/ProductID is defined in config.h, pretend to be Linux diff --git a/drivers/usb/gadget/designware_udc.c b/drivers/usb/gadget/designware_udc.c index 1aab31b..b7c1038 100644 --- a/drivers/usb/gadget/designware_udc.c +++ b/drivers/usb/gadget/designware_udc.c @@ -14,6 +14,7 @@ #include <usbdevice.h> #include "ep0.h" #include <usb/designware_udc.h> +#include <usb/udc.h> #include <asm/arch/hardware.h>
#define UDC_INIT_MDELAY 80 /* Device settle delay */ diff --git a/drivers/usb/gadget/mpc8xx_udc.c b/drivers/usb/gadget/mpc8xx_udc.c index 0207d39..7f72972 100644 --- a/drivers/usb/gadget/mpc8xx_udc.c +++ b/drivers/usb/gadget/mpc8xx_udc.c @@ -47,6 +47,7 @@ #include <commproc.h> #include <usbdevice.h> #include <usb/mpc8xx_udc.h> +#include <usb/udc.h>
#include "ep0.h"
diff --git a/drivers/usb/gadget/omap1510_udc.c b/drivers/usb/gadget/omap1510_udc.c index 8553fe5..bdc1b88 100644 --- a/drivers/usb/gadget/omap1510_udc.c +++ b/drivers/usb/gadget/omap1510_udc.c @@ -20,6 +20,7 @@ #endif #include <usbdevice.h> #include <usb/omap1510_udc.h> +#include <usb/udc.h>
#include "ep0.h"
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 05d1b56..733558d 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c @@ -16,6 +16,7 @@ #include <asm/arch/hardware.h> #include <asm/io.h> #include <usb/pxa27x_udc.h> +#include <usb/udc.h>
#include "ep0.h"
diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c index 3e3e05e..87640f4 100644 --- a/drivers/usb/musb/musb_udc.c +++ b/drivers/usb/musb/musb_udc.c @@ -39,7 +39,8 @@ */
#include <common.h> -#include <usb/musb_udc.h> +#include <usbdevice.h> +#include <usb/udc.h> #include "../gadget/ep0.h" #include "musb_core.h" #if defined(CONFIG_USB_OMAP3) diff --git a/include/usb/designware_udc.h b/include/usb/designware_udc.h index 2e29a7e..2e1cdf1 100644 --- a/include/usb/designware_udc.h +++ b/include/usb/designware_udc.h @@ -174,19 +174,6 @@ struct udcfifo_regs { };
/* - * USBTTY definitions - */ -#define EP0_MAX_PACKET_SIZE 64 -#define UDC_INT_ENDPOINT 1 -#define UDC_INT_PACKET_SIZE 64 -#define UDC_OUT_ENDPOINT 2 -#define UDC_BULK_PACKET_SIZE 64 -#define UDC_BULK_HS_PACKET_SIZE 512 -#define UDC_IN_ENDPOINT 3 -#define UDC_OUT_PACKET_SIZE 64 -#define UDC_IN_PACKET_SIZE 64 - -/* * UDC endpoint definitions */ #define UDC_EP0 0 @@ -194,22 +181,4 @@ struct udcfifo_regs { #define UDC_EP2 2 #define UDC_EP3 3
-/* - * Function declarations - */ - -void udc_irq(void); - -void udc_set_nak(int epid); -void udc_unset_nak(int epid); -int udc_endpoint_write(struct usb_endpoint_instance *endpoint); -int udc_init(void); -void udc_enable(struct usb_device_instance *device); -void udc_disable(void); -void udc_connect(void); -void udc_disconnect(void); -void udc_startup_events(struct usb_device_instance *device); -void udc_setup_ep(struct usb_device_instance *device, unsigned int ep, - struct usb_endpoint_instance *endpoint); - #endif /* __DW_UDC_H */ diff --git a/include/usb/mpc8xx_udc.h b/include/usb/mpc8xx_udc.h index 475dd41..9906c75 100644 --- a/include/usb/mpc8xx_udc.h +++ b/include/usb/mpc8xx_udc.h @@ -111,11 +111,9 @@
/* UDC device defines */ #define EP0_MAX_PACKET_SIZE EP_MAX_PKT -#define UDC_OUT_ENDPOINT 0x02 + #define UDC_OUT_PACKET_SIZE EP_MIN_PACKET_SIZE -#define UDC_IN_ENDPOINT 0x03 #define UDC_IN_PACKET_SIZE EP_MIN_PACKET_SIZE -#define UDC_INT_ENDPOINT 0x01 #define UDC_INT_PACKET_SIZE UDC_IN_PACKET_SIZE #define UDC_BULK_PACKET_SIZE EP_MIN_PACKET_SIZE
@@ -178,18 +176,3 @@ typedef enum mpc8xx_udc_state{ STATE_READY, }mpc8xx_udc_state_t;
-/* Declarations */ -int udc_init(void); -void udc_irq(void); -int udc_endpoint_write(struct usb_endpoint_instance *endpoint); -void udc_setup_ep(struct usb_device_instance *device, unsigned int ep, - struct usb_endpoint_instance *endpoint); -void udc_connect(void); -void udc_disconnect(void); -void udc_enable(struct usb_device_instance *device); -void udc_disable(void); -void udc_startup_events(struct usb_device_instance *device); - -/* Flow control */ -void udc_set_nak(int epid); -void udc_unset_nak (int epid); diff --git a/include/usb/musb_udc.h b/include/usb/musb_udc.h deleted file mode 100644 index 3500c7a..0000000 --- a/include/usb/musb_udc.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2009 Wind River Systems, Inc. - * Tom Rix Tom.Rix@windriver.com - * - * SPDX-License-Identifier: GPL-2.0+ - */ -#ifndef __MUSB_UDC_H__ -#define __MUSB_UDC_H__ - -#include <usbdevice.h> - -/* UDC level routines */ -void udc_irq(void); -void udc_set_nak(int ep_num); -void udc_unset_nak(int ep_num); -int udc_endpoint_write(struct usb_endpoint_instance *endpoint); -void udc_setup_ep(struct usb_device_instance *device, unsigned int id, - struct usb_endpoint_instance *endpoint); -void udc_connect(void); -void udc_disconnect(void); -void udc_enable(struct usb_device_instance *device); -void udc_disable(void); -void udc_startup_events(struct usb_device_instance *device); -int udc_init(void); - -/* usbtty */ -#ifdef CONFIG_USB_TTY - -#define EP0_MAX_PACKET_SIZE 64 /* MUSB_EP0_FIFOSIZE */ -#define UDC_INT_ENDPOINT 1 -#define UDC_INT_PACKET_SIZE 64 -#define UDC_OUT_ENDPOINT 2 -#define UDC_OUT_PACKET_SIZE 64 -#define UDC_IN_ENDPOINT 3 -#define UDC_IN_PACKET_SIZE 64 -#define UDC_BULK_PACKET_SIZE 64 - -#endif /* CONFIG_USB_TTY */ - -#endif /* __MUSB_UDC_H__ */ diff --git a/include/usb/omap1510_udc.h b/include/usb/omap1510_udc.h index ece0e95..934930b 100644 --- a/include/usb/omap1510_udc.h +++ b/include/usb/omap1510_udc.h @@ -162,32 +162,11 @@ #define UDC_VBUS_MODE (1 << 18)
/* OMAP Endpoint parameters */ -#define EP0_MAX_PACKET_SIZE 64 -#define UDC_OUT_ENDPOINT 2 -#define UDC_OUT_PACKET_SIZE 64 -#define UDC_IN_ENDPOINT 1 -#define UDC_IN_PACKET_SIZE 64 -#define UDC_INT_ENDPOINT 5 #define UDC_INT_PACKET_SIZE 16 #define UDC_BULK_PACKET_SIZE 16
-void udc_irq (void); -/* Flow control */ -void udc_set_nak(int epid); -void udc_unset_nak (int epid); - -/* Higher level functions for abstracting away from specific device */ -int udc_endpoint_write(struct usb_endpoint_instance *endpoint); - -int udc_init (void); - -void udc_enable(struct usb_device_instance *device); -void udc_disable(void); - -void udc_connect(void); -void udc_disconnect(void); - -void udc_startup_events(struct usb_device_instance *device); -void udc_setup_ep(struct usb_device_instance *device, unsigned int ep, struct usb_endpoint_instance *endpoint); +#define UDC_INT_ENDPOINT 5 +#define UDC_OUT_ENDPOINT 2 +#define UDC_IN_ENDPOINT 1
#endif diff --git a/include/usb/pxa27x_udc.h b/include/usb/pxa27x_udc.h index 7fdbe2a..7eaa000 100644 --- a/include/usb/pxa27x_udc.h +++ b/include/usb/pxa27x_udc.h @@ -22,35 +22,11 @@
/* Endpoint parameters */ #define MAX_ENDPOINTS 4 -#define EP_MAX_PACKET_SIZE 64
#define EP0_MAX_PACKET_SIZE 16 + #define UDC_OUT_ENDPOINT 0x02 -#define UDC_OUT_PACKET_SIZE EP_MAX_PACKET_SIZE #define UDC_IN_ENDPOINT 0x01 -#define UDC_IN_PACKET_SIZE EP_MAX_PACKET_SIZE #define UDC_INT_ENDPOINT 0x05 -#define UDC_INT_PACKET_SIZE EP_MAX_PACKET_SIZE -#define UDC_BULK_PACKET_SIZE EP_MAX_PACKET_SIZE - -void udc_irq(void); -/* Flow control */ -void udc_set_nak(int epid); -void udc_unset_nak(int epid); - -/* Higher level functions for abstracting away from specific device */ -int udc_endpoint_write(struct usb_endpoint_instance *endpoint); - -int udc_init(void); - -void udc_enable(struct usb_device_instance *device); -void udc_disable(void); - -void udc_connect(void); -void udc_disconnect(void); - -void udc_startup_events(struct usb_device_instance *device); -void udc_setup_ep(struct usb_device_instance *device, - unsigned int ep, struct usb_endpoint_instance *endpoint);
#endif diff --git a/include/usb/udc.h b/include/usb/udc.h new file mode 100644 index 0000000..a7bd128 --- /dev/null +++ b/include/usb/udc.h @@ -0,0 +1,63 @@ +/* + * SPDX-License-Identifier: GPL-2.0+ + */ +#ifndef USB_UDC_H +#define USB_UDC_H + +#ifndef EP0_MAX_PACKET_SIZE +#define EP0_MAX_PACKET_SIZE 64 +#endif + +#ifndef EP_MAX_PACKET_SIZE +#define EP_MAX_PACKET_SIZE 64 +#endif + +#ifndef UDC_OUT_PACKET_SIZE +#define UDC_OUT_PACKET_SIZE EP_MAX_PACKET_SIZE +#endif + +#ifndef UDC_IN_PACKET_SIZE +#define UDC_IN_PACKET_SIZE EP_MAX_PACKET_SIZE +#endif + +#ifndef UDC_INT_PACKET_SIZE +#define UDC_INT_PACKET_SIZE EP_MAX_PACKET_SIZE +#endif + +#ifndef UDC_BULK_PACKET_SIZE +#define UDC_BULK_PACKET_SIZE EP_MAX_PACKET_SIZE +#endif + +#ifndef UDC_BULK_HS_PACKET_SIZE +#define UDC_BULK_HS_PACKET_SIZE 512 +#endif + +#ifndef UDC_INT_ENDPOINT +#define UDC_INT_ENDPOINT 1 +#endif + +#ifndef UDC_OUT_ENDPOINT +#define UDC_OUT_ENDPOINT 2 +#endif + +#ifndef UDC_IN_ENDPOINT +#define UDC_IN_ENDPOINT 3 +#endif + +/* function declarations */ +int udc_init(void); +void udc_irq(void); +int udc_endpoint_write(struct usb_endpoint_instance *endpoint); +void udc_setup_ep(struct usb_device_instance *device, unsigned int ep, + struct usb_endpoint_instance *endpoint); +void udc_connect(void); +void udc_disconnect(void); +void udc_enable(struct usb_device_instance *device); +void udc_disable(void); +void udc_startup_events(struct usb_device_instance *device); + +/* Flow control */ +void udc_set_nak(int epid); +void udc_unset_nak(int epid); + +#endif

Change 'nfo=' to 'info='
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 0ff2e5e..3ad51b7 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -383,8 +383,8 @@ static void handle_ep_complete(struct mv_ep *ep) mv_invalidate_qtd(num); if (item->info & 0xff) - printf("EP%d/%s FAIL nfo=%x pg0=%x\n", - num, in ? "in" : "out", item->info, item->page0); + printf("EP%d/%s FAIL info=%x pg0=%x\n", + num, in ? "in" : "out", item->info, item->page0);
len = (item->info >> 16) & 0x7fff;

This controller support full and high speed.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 3ad51b7..fcfbfa3 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -114,6 +114,7 @@ static struct mv_drv controller = { .gadget = { .name = "mv_udc", .ops = &mv_udc_ops, + .is_dualspeed = 1, }, };

Set maximum packet length in queue header to wMaxPacketSize of endpoint.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 48 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index fcfbfa3..c9bd0a7 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -17,6 +17,7 @@ #include <asm/byteorder.h> #include <asm/io.h> #include <asm/errno.h> +#include <asm/unaligned.h> #include <linux/types.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> @@ -228,7 +229,7 @@ static void mv_ep_free_request(struct usb_ep *ep, struct usb_request *_req) return; }
-static void ep_enable(int num, int in) +static void ep_enable(int num, int in, int maxpacket) { struct ept_queue_head *head; struct mv_udc *udc = get_mv_udc(); @@ -242,7 +243,7 @@ static void ep_enable(int num, int in) n |= (CTRL_RXE | CTRL_RXR | CTRL_RXT_BULK);
if (num != 0) { - head->config = CONFIG_MAX_PKT(EP_MAX_PACKET_SIZE) | CONFIG_ZLT; + head->config = CONFIG_MAX_PKT(maxpacket) | CONFIG_ZLT; mv_flush_qh(num); } writel(n, &udc->epctrl[num]); @@ -255,8 +256,21 @@ static int mv_ep_enable(struct usb_ep *ep, int num, in; num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; in = (desc->bEndpointAddress & USB_DIR_IN) != 0; - ep_enable(num, in); mv_ep->desc = desc; + + if (num) { + int max = get_unaligned_le16(&desc->wMaxPacketSize); + + if ((max > 64) && (controller.gadget.speed == USB_SPEED_FULL)) + max = 64; + if (ep->maxpacket != max) { + DBG("%s: from %d to %d\n", __func__, + ep->maxpacket, max); + ep->maxpacket = max; + } + } + ep_enable(num, in, ep->maxpacket); + DBG("%s: num=%d maxpacket=%d\n", __func__, num, ep->maxpacket); return 0; }
@@ -429,14 +443,16 @@ static void handle_setup(void) if ((r.wValue == 0) && (r.wLength == 0)) { req->length = 0; for (i = 0; i < NUM_ENDPOINTS; i++) { - if (!controller.ep[i].desc) + struct mv_ep *ep = &controller.ep[i]; + + if (!ep->desc) continue; - num = controller.ep[i].desc->bEndpointAddress + num = ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; - in = (controller.ep[i].desc->bEndpointAddress + in = (ep->desc->bEndpointAddress & USB_DIR_IN) != 0; if ((num == _num) && (in == _in)) { - ep_enable(num, in); + ep_enable(num, in, ep->ep.maxpacket); usb_ep_queue(controller.gadget.ep0, req, 0); break; @@ -520,15 +536,19 @@ void udc_irq(void) DBG("-- suspend --\n");
if (n & STS_PCI) { - DBG("-- portchange --\n"); + int max = 64; + int speed = USB_SPEED_FULL; + bit = (readl(&udc->portsc) >> 26) & 3; + DBG("-- portchange %x %s\n", bit, (bit == 2) ? "High" : "Full"); if (bit == 2) { - controller.gadget.speed = USB_SPEED_HIGH; - for (i = 1; i < NUM_ENDPOINTS && n; i++) - if (controller.ep[i].desc) - controller.ep[i].ep.maxpacket = 512; - } else { - controller.gadget.speed = USB_SPEED_FULL; + speed = USB_SPEED_HIGH; + max = 512; + } + controller.gadget.speed = speed; + for (i = 1; i < NUM_ENDPOINTS; i++) { + if (controller.ep[i].ep.maxpacket > max) + controller.ep[i].ep.maxpacket = max; } }

Only perform one copy, either in the bounce routine for IN transfers, or the debounce rtn for OUT transfer.
On out transfers, only copy the number of bytes received from the bounce buffer
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index c9bd0a7..6e0f9bb 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -279,7 +279,7 @@ static int mv_ep_disable(struct usb_ep *ep) return 0; }
-static int mv_bounce(struct mv_ep *ep) +static int mv_bounce(struct mv_ep *ep, int in) { uint32_t addr = (uint32_t)ep->req.buf; uint32_t ba; @@ -308,8 +308,8 @@ align: if (!ep->b_buf) return -ENOMEM; } - - memcpy(ep->b_buf, ep->req.buf, ep->req.length); + if (in) + memcpy(ep->b_buf, ep->req.buf, ep->req.length);
flush: ba = (uint32_t)ep->b_buf; @@ -318,29 +318,25 @@ flush: return 0; }
-static void mv_debounce(struct mv_ep *ep) +static void mv_debounce(struct mv_ep *ep, int in) { uint32_t addr = (uint32_t)ep->req.buf; uint32_t ba = (uint32_t)ep->b_buf;
+ if (in) { + if (addr == ba) + return; /* not a bounce */ + goto free; + } invalidate_dcache_range(ba, ba + ep->b_len);
- /* Input buffer address is not aligned. */ - if (addr & (ARCH_DMA_MINALIGN - 1)) - goto copy; - - /* Input buffer length is not aligned. */ - if (ep->req.length & (ARCH_DMA_MINALIGN - 1)) - goto copy; - - /* The buffer is well aligned, only invalidate cache. */ - return; + if (addr == ba) + return; /* not a bounce */
-copy: memcpy(ep->req.buf, ep->b_buf, ep->req.length); - +free: /* Large payloads use allocated buffer, free it. */ - if (ep->req.length > 64) + if (ep->b_buf != ep->b_fast) free(ep->b_buf); }
@@ -358,7 +354,7 @@ static int mv_ep_queue(struct usb_ep *ep, head = mv_get_qh(num, in); len = req->length;
- ret = mv_bounce(mv_ep); + ret = mv_bounce(mv_ep, in); if (ret) return ret;
@@ -402,10 +398,9 @@ static void handle_ep_complete(struct mv_ep *ep) num, in ? "in" : "out", item->info, item->page0);
len = (item->info >> 16) & 0x7fff; - - mv_debounce(ep); - ep->req.length -= len; + mv_debounce(ep, in); + DBG("ept%d %s complete %x\n", num, in ? "in" : "out", len); ep->req.complete(&ep->ep, &ep->req);

Make sure the transfer descriptor is flushed before the queue is updated so that the controller will not see old information.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 6e0f9bb..2bf4bc0 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -362,21 +362,20 @@ static int mv_ep_queue(struct usb_ep *ep, item->info = INFO_BYTES(len) | INFO_IOC | INFO_ACTIVE; item->page0 = (uint32_t)mv_ep->b_buf; item->page1 = ((uint32_t)mv_ep->b_buf & 0xfffff000) + 0x1000; + mv_flush_qtd(num);
head->next = (unsigned) item; head->info = 0;
DBG("ept%d %s queue len %x, buffer %p\n", num, in ? "in" : "out", len, mv_ep->b_buf); + mv_flush_qh(num);
if (in) bit = EPT_TX(num); else bit = EPT_RX(num);
- mv_flush_qh(num); - mv_flush_qtd(num); - writel(bit, &udc->epprime);
return 0;

Only get head if not ep0.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 2bf4bc0..82df9ab 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -231,10 +231,8 @@ static void mv_ep_free_request(struct usb_ep *ep, struct usb_request *_req)
static void ep_enable(int num, int in, int maxpacket) { - struct ept_queue_head *head; struct mv_udc *udc = get_mv_udc(); unsigned n; - head = mv_get_qh(num, in);
n = readl(&udc->epctrl[num]); if (in) @@ -243,6 +241,8 @@ static void ep_enable(int num, int in, int maxpacket) n |= (CTRL_RXE | CTRL_RXR | CTRL_RXT_BULK);
if (num != 0) { + struct ept_queue_head *head = mv_get_qh(num, in); + head->config = CONFIG_MAX_PKT(maxpacket) | CONFIG_ZLT; mv_flush_qh(num); }

Since we flush the TD, we may as well set it to a known value.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 82df9ab..4876894 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -661,6 +661,7 @@ static int mvudc_probe(void) free(controller.epts); return -ENOMEM; } + memset(controller.items_mem, 0, ilist_sz);
for (i = 0; i < 2 * NUM_ENDPOINTS; i++) { /*

desc is set at ep_enable, so for symmetry, clear it at ep_disable.
Signed-off-by: Troy Kisky troy.kisky@boundarydevices.com --- drivers/usb/gadget/mv_udc.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index 4876894..74fa065 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -276,6 +276,9 @@ static int mv_ep_enable(struct usb_ep *ep,
static int mv_ep_disable(struct usb_ep *ep) { + struct mv_ep *mv_ep = container_of(ep, struct mv_ep, ep); + + mv_ep->desc = NULL; return 0; }

Dear Troy Kisky,
Hi Marek, Stefano
This series is based on u-boot-usb/master branch. After this series, nitrogen6x works with tftpboot to transfer files over usb.
V2 was dropped to my bad posting of it and should be ignored.
This V3 is a rebase and most patches had to be changed slightly. I also ran a ./MAKEALL -a arm and fixed the errors that the V1 series had.
The most noticeable change is the addition of
usb: gadget: mv_udc: fix hardware udc address for i.MX6
Let me know if you want to go back to a udc variable to store the address instead of using hcor.
Stefano, would you like to take patches 1-5 ? I'll likely need a V3, but maybe the early ones will be approved.
Thanks
In general, cool stuff. I want this in, you just need to learn to write proper commit messages. I don't understand the middle part of your patchset very well, that's where I was rambling the most. Otherwise, it's almost OK, one or two more loop and you're in.
Best regards, Marek Vasut

Hi Troy,
On 02/08/2013 01:27, Troy Kisky wrote:
Hi Marek, Stefano
This series is based on u-boot-usb/master branch. After this series, nitrogen6x works with tftpboot to transfer files over usb.
V2 was dropped to my bad posting of it and should be ignored.
This V3 is a rebase and most patches had to be changed slightly. I also ran a ./MAKEALL -a arm and fixed the errors that the V1 series had.
The most noticeable change is the addition of
usb: gadget: mv_udc: fix hardware udc address for i.MX6
Let me know if you want to go back to a udc variable to store the address instead of using hcor.
Stefano, would you like to take patches 1-5 ? I'll likely need a V3, but maybe the early ones will be approved.
Fine with me - I merge the first 5 patches.
Regards, Stefano
participants (4)
-
Marek Vasut
-
Stefano Babic
-
Troy Kisky
-
Wolfgang Denk