i.MX USB PHY fixes
Subsystems (4)
cover i.MX USB PHY fixes
Everyone:
This is a small series of patches I made while investigating USB issue on RDU2 board. First three patches are just optional improvements. The actual fix is in "usb: imx-usb-phy: Disable charger detect during initialization" and "ARM: i.MX: Drop unused usb-imx6.c" removes some abandoned code. Hopefully each patch is self-explanatory.
Feedback is welcome!
Thanks,
Andrey Smirnov
Andrey Smirnov (5):
usb: imx-usb-phy: Import register definitions from Linux driver
usb: imx-usb-phy: Wrap lines to silence checkpatch
usb: imx-usb-phy: Use stmp_reset_block() to reset PHY
usb: imx-usb-phy: Disable charger detect during initialization
ARM: i.MX: Drop unused usb-imx6.c
arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/usb-imx6.c | 111 ---------------------------------- drivers/usb/imx/imx-usb-phy.c | 87 ++++++++++++++++++-------- 3 files changed, 62 insertions(+), 138 deletions(-) delete mode 100644 arch/arm/mach-imx/usb-imx6.c
Signature · 7 lines
2.21.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/5 usb: imx-usb-phy: Import register definitions from Linux driver
Import register definitions from Linux driver to simplify comparing/sharing code a bit. No functional change intended.
--- drivers/usb/imx/imx-usb-phy.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/usb/imx/imx-usb-phy.c +18 -17
@@ -24,16 +24,17 @@#include <linux/clk.h> #include <linux/err.h> -#define SET 0x4 -#define CLR 0x8 - -#define USBPHY_CTRL 0x30 +#define HW_USBPHY_PWD 0x00 +#define HW_USBPHY_TX 0x10 +#define HW_USBPHY_CTRL 0x30 +#define HW_USBPHY_CTRL_SET 0x34 +#define HW_USBPHY_CTRL_CLR 0x38#define USBPHY_CTRL_SFTRST (1 << 31)#define USBPHY_CTRL_CLKGATE (1 << 30) -#define USBPHY_CTRL_ENUTMILEVEL3 (1 << 15) -#define USBPHY_CTRL_ENUTMILEVEL2 (1 << 14) -#define USBPHY_CTRL_ENHOSTDISCONDETECT (1 << 1) +#define BM_USBPHY_CTRL_ENUTMILEVEL3 BIT(15) +#define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14) +#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)struct imx_usbphy {struct usb_phy usb_phy;
@@ -50,20 +51,20 @@ static int imx_usbphy_phy_init(struct phy *phy)clk_enable (imxphy->clk);/* reset usbphy */ -writel (USBPHY_CTRL_SFTRST , imxphy->base +USBPHY_CTRL +SET ); +writel (USBPHY_CTRL_SFTRST , imxphy->base +HW_USBPHY_CTRL_SET );udelay (10 );/* clr reset and clkgate */ writel (USBPHY_CTRL_SFTRST |USBPHY_CTRL_CLKGATE , - imxphy->base +USBPHY_CTRL +CLR ); + imxphy->base +HW_USBPHY_CTRL_CLR ); -/* clr all pwd bits => power up phy */ -writel (0xffffffff , imxphy->base +CLR ); +/* Power up the PHY */ +writel (0 , imxphy->base +HW_USBPHY_PWD );/* set utmilvl2/3 */ -writel (USBPHY_CTRL_ENUTMILEVEL3 |USBPHY_CTRL_ENUTMILEVEL2 , - imxphy->base +USBPHY_CTRL +SET ); +writel (BM_USBPHY_CTRL_ENUTMILEVEL3 |BM_USBPHY_CTRL_ENUTMILEVEL2 , + imxphy->base +HW_USBPHY_CTRL_SET );return 0 ; }
@@ -74,8 +75,8 @@ static int imx_usbphy_notify_connect(struct usb_phy *phy, struct imx_usbphy *imxphy = container_of(phy, struct imx_usbphy, usb_phy);if (speed ==USB_SPEED_HIGH ) { -writel (USBPHY_CTRL_ENHOSTDISCONDETECT , - imxphy->base +USBPHY_CTRL +SET ); +writel (BM_USBPHY_CTRL_ENHOSTDISCONDETECT , + imxphy->base +HW_USBPHY_CTRL_SET ); }return 0 ;
@@ -86,8 +87,8 @@ static int imx_usbphy_notify_disconnect(struct usb_phy *phy, { struct imx_usbphy *imxphy = container_of(phy, struct imx_usbphy, usb_phy); -writel (USBPHY_CTRL_ENHOSTDISCONDETECT , - imxphy->base +USBPHY_CTRL +CLR ); +writel (BM_USBPHY_CTRL_ENHOSTDISCONDETECT , + imxphy->base +HW_USBPHY_CTRL_CLR );return 0 ; }
Signature · 7 lines
2.21.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/5 usb: imx-usb-phy: Wrap lines to silence checkpatch
In reply to Andrey SmirnovThose two line are the only thing that checkpatch is complaining about. Wrap them to slince it. No functional change intended.
--- drivers/usb/imx/imx-usb-phy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/imx/imx-usb-phy.c +4 -2
@@ -72,7 +72,8 @@ static int imx_usbphy_phy_init(struct phy *phy)static int imx_usbphy_notify_connect (struct usb_phy *phy,enum usb_device_speed speed) { - struct imx_usbphy *imxphy = container_of(phy, struct imx_usbphy, usb_phy); + struct imx_usbphy *imxphy = container_of(phy, struct imx_usbphy, + usb_phy);if (speed ==USB_SPEED_HIGH ) { writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
@@ -85,7 +86,8 @@ static int imx_usbphy_notify_connect(struct usb_phy *phy,static int imx_usbphy_notify_disconnect (struct usb_phy *phy,enum usb_device_speed speed) { - struct imx_usbphy *imxphy = container_of(phy, struct imx_usbphy, usb_phy); + struct imx_usbphy *imxphy = container_of(phy, struct imx_usbphy, + usb_phy);writel (BM_USBPHY_CTRL_ENHOSTDISCONDETECT , imxphy->base +HW_USBPHY_CTRL_CLR );
Signature · 7 lines
2.21.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/5 usb: imx-usb-phy: Use stmp_reset_block() to reset PHY
In reply to Andrey SmirnovUpstream kernel driver uses stmp_reset_block() to reset the PHY, so convert the code to do so as well to save some code and sync both drivers.
--- drivers/usb/imx/imx-usb-phy.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/usb/imx/imx-usb-phy.c +5 -10
@@ -23,6 +23,7 @@#include <linux/phy/phy.h> #include <linux/clk.h> #include <linux/err.h> +#include <stmp-device.h> #define HW_USBPHY_PWD 0x00#define HW_USBPHY_TX 0x10
@@ -30,8 +31,6 @@#define HW_USBPHY_CTRL_SET 0x34#define HW_USBPHY_CTRL_CLR 0x38 -#define USBPHY_CTRL_SFTRST (1 << 31) -#define USBPHY_CTRL_CLKGATE (1 << 30)#define BM_USBPHY_CTRL_ENUTMILEVEL3 BIT(15)#define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14)#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
@@ -47,17 +46,13 @@ struct imx_usbphy {static int imx_usbphy_phy_init (struct phy *phy) {struct imx_usbphy *imxphy =phy_get_drvdata (phy); +int ret;clk_enable (imxphy->clk); -/* reset usbphy */ -writel (USBPHY_CTRL_SFTRST , imxphy->base +HW_USBPHY_CTRL_SET ); - -udelay (10 ); - -/* clr reset and clkgate */ -writel (USBPHY_CTRL_SFTRST |USBPHY_CTRL_CLKGATE , - imxphy->base +HW_USBPHY_CTRL_CLR ); + ret =stmp_reset_block (imxphy->base +HW_USBPHY_CTRL , false); +if (ret) +return ret;/* Power up the PHY */ writel (0 , imxphy->base +HW_USBPHY_PWD );
Signature · 7 lines
2.21.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/5 usb: imx-usb-phy: Disable charger detect during initialization
In reply to Andrey SmirnovI can't find any erratas this is in refernce to, but apparently external changer detector needs to be disabled to prevent poor USB data signal quality. The problem manifest itself as a intermittent USB transfer corruption that happens to some device under and only under specific circumstances.
In my case the failure was observed with Transcent SD/micro-SD card reader (05e3:0745 Genesys Logic, Inc. Logilink CR0012) when connected directly to front panel USB of ZII RDU2 board (the problem would go away if device was conntecte via a hub/USB-analyzer/male-female type A extender cable).
Note that this fix is present in Linux kernel as well as some abandoned Barebox code removed in the next patch.
--- drivers/usb/imx/imx-usb-phy.c | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/usb/imx/imx-usb-phy.c +37 -0
@@ -24,6 +24,7 @@#include <linux/clk.h> #include <linux/err.h> #include <stmp-device.h> +#include <mfd/syscon.h> #define HW_USBPHY_PWD 0x00#define HW_USBPHY_TX 0x10
@@ -35,12 +36,19 @@#define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14)#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1) +#define ANADIG_USB1_CHRG_DETECT_SET 0x1b4 +#define ANADIG_USB2_CHRG_DETECT_SET 0x214 +#define ANADIG_USB1_CHRG_DETECT_EN_B BIT(20) +#define ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B BIT(19) +struct imx_usbphy {struct usb_phy usb_phy;struct phy *phy;void __iomem *base; +void __iomem *anatop;struct clk *clk;struct phy_provider *provider; +int port_id; };static int imx_usbphy_phy_init (struct phy *phy)
@@ -61,6 +69,19 @@ static int imx_usbphy_phy_init(struct phy *phy)writel (BM_USBPHY_CTRL_ENUTMILEVEL3 |BM_USBPHY_CTRL_ENUTMILEVEL2 , imxphy->base +HW_USBPHY_CTRL_SET ); +if (imxphy->anatop) { +unsigned int reg = imxphy->port_id ? +ANADIG_USB1_CHRG_DETECT_SET : +ANADIG_USB2_CHRG_DETECT_SET ; +/* +* The external charger detector needs to be disabled, +* or the signal at DP will be poor +*/ +writel (ANADIG_USB1_CHRG_DETECT_EN_B | +ANADIG_USB1_CHRG_DETECT_CHK_CHRG_B , + imxphy->anatop + reg); + } +return 0 ; }
@@ -113,11 +134,27 @@ static const struct phy_ops imx_phy_ops = {static int imx_usbphy_probe (struct device_d *dev) {struct resource *iores; +struct device_node *np = dev->device_node;int ret;struct imx_usbphy *imxphy; imxphy =xzalloc (sizeof (*imxphy)); + ret =of_alias_get_id (np,"usbphy" ); +if (ret <0 ) { +dev_dbg (dev,"failed to get alias id, errno %d\n" , ret); + goto err_free; + } + imxphy->port_id = ret; + +if (of_get_property (np,"fsl,anatop" ,NULL )) { + imxphy->anatop = +syscon_base_lookup_by_phandle (np,"fsl,anatop" ); + ret =PTR_ERR_OR_ZERO (imxphy->anatop); +if (ret) + goto err_free; + } + iores =dev_request_mem_resource (dev,0 );if (IS_ERR (iores)) { ret =PTR_ERR (iores);
Signature · 7 lines
2.21.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/5 ARM: i.MX: Drop unused usb-imx6.c
In reply to Andrey SmirnovLooks like usb-imx6.c was abandoned and there are no references to either of the functions difined there. Drop it.
--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/usb-imx6.c | 111 ----------------------------------- 2 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 arch/arm/mach-imx/usb-imx6.c
arch/arm/mach-imx/Makefile +1 -1
@@ -10,7 +10,7 @@ obj-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o pbl-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o obj-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o pbl-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o -obj-$(CONFIG_ARCH_IMX6) += imx6.o usb-imx6.o +obj-$(CONFIG_ARCH_IMX6) += imx6.o CFLAGS_imx6.o := -march=armv7-a lwl-$(CONFIG_ARCH_IMX6) += imx6-mmdc.o obj-$(CONFIG_ARCH_IMX7) += imx7.o
arch/arm/mach-imx/usb-imx6.c deleted +0 -111
111 lines not on this page · raw message
Signature · 7 lines
2.21.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 5/5] ARM: i.MX: Drop unused usb-imx6.c
Quoted 29 lines · Andrey Smirnov
Looks like
usb-imx6.cwas abandoned and there are no references to either of the functions difined there. Drop it.Signed-off-by Andrey Smirnov <[email protected]>--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/usb-imx6.c | 111 ----------------------------------- 2 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 arch/arm/mach-imx/usb-imx6.carch/arm/mach-imx/Makefile +1
-1@@ -10,7 +10,7 @@ obj-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o pbl-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o obj-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o pbl-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o -obj-$(CONFIG_ARCH_IMX6) += imx6.o usb-imx6.o +obj-$(CONFIG_ARCH_IMX6) += imx6.o CFLAGS_imx6.o := -march=armv7-a lwl-$(CONFIG_ARCH_IMX6) += imx6-mmdc.o obj-$(CONFIG_ARCH_IMX7) += imx7.oarch/arm/mach-imx/usb-imx6.c deleted +0
-0
arch/arm/mach-imx/usb-imx6.c line 3
Quoted 3 lines
arch/arm/mach-imx/usb-imx6.c deleted +0
-3@@ -1,111 +0,0 @@ - -int imx6_usb_phy2_disable_oc (void ) -{
You leave the function prototypes in arch/arm/mach-imx/include/mach/usb.h. Could you remove them aswell?
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 5/5] ARM: i.MX: Drop unused usb-imx6.c
Quoted 28 lines · Sascha Hauer
Quoted 27 lines · Andrey Smirnov
Looks like
usb-imx6.cwas abandoned and there are no references to either of the functions difined there. Drop it.Signed-off-by Andrey Smirnov <[email protected]>--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/usb-imx6.c | 111 ----------------------------------- 2 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 arch/arm/mach-imx/usb-imx6.carch/arm/mach-imx/Makefile +1
-1@@ -10,7 +10,7 @@ obj-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o pbl-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o obj-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o pbl-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o -obj-$(CONFIG_ARCH_IMX6) += imx6.o usb-imx6.o +obj-$(CONFIG_ARCH_IMX6) += imx6.o CFLAGS_imx6.o := -march=armv7-a lwl-$(CONFIG_ARCH_IMX6) += imx6-mmdc.o obj-$(CONFIG_ARCH_IMX7) += imx7.oarch/arm/mach-imx/usb-imx6.c deleted +0
-1--- a/arch/arm/mach-imx/usb-imx6.c
Quoted 8 lines
arch/arm/mach-imx/usb-imx6.c line 3
Quoted 5 lines
+++
/dev/nullarch/arm/mach-imx/usb-imx6.c deleted +0
-3@@ -1,111 +0,0 @@ - -int imx6_usb_phy2_disable_oc (void ) -{You leave the function prototypes in
arch/arm/mach-imx/include/mach/usb.h. Could you remove them aswell?
Don't mind, I fixed this up while applying
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 5/5] ARM: i.MX: Drop unused usb-imx6.c
Quoted 39 lines · Sascha Hauer
Quoted 28 lines · Sascha Hauer
Quoted 27 lines · Andrey Smirnov
Looks like
usb-imx6.cwas abandoned and there are no references to either of the functions difined there. Drop it.Signed-off-by Andrey Smirnov <[email protected]>--- arch/arm/mach-imx/Makefile | 2 +- arch/arm/mach-imx/usb-imx6.c | 111 ----------------------------------- 2 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 arch/arm/mach-imx/usb-imx6.carch/arm/mach-imx/Makefile +1
-1@@ -10,7 +10,7 @@ obj-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o pbl-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o obj-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o pbl-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o -obj-$(CONFIG_ARCH_IMX6) += imx6.o usb-imx6.o +obj-$(CONFIG_ARCH_IMX6) += imx6.o CFLAGS_imx6.o := -march=armv7-a lwl-$(CONFIG_ARCH_IMX6) += imx6-mmdc.o obj-$(CONFIG_ARCH_IMX7) += imx7.oarch/arm/mach-imx/usb-imx6.c deleted +0
-1--- a/arch/arm/mach-imx/usb-imx6.cQuoted 8 lines
arch/arm/mach-imx/usb-imx6.c line 3
Quoted 5 lines
+++
/dev/nullarch/arm/mach-imx/usb-imx6.c deleted +0
-3@@ -1,111 +0,0 @@ - -int imx6_usb_phy2_disable_oc (void ) -{You leave the function prototypes in
arch/arm/mach-imx/include/mach/usb.h. Could you remove them aswell?
Quoted 2 lines
Don't mind, I fixed this up while applying
I knew I was forgetting something! Thanks for fixing that!
Thanks,
Andrey Smirnov
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox