This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335x USB CHARGER DETECTION

Other Parts Discussed in Thread: AM3352

Hi,

Im using AM3352 processor.
The kernel is from mainline, linux-4.1.15 LTS

I want to detect whether the USB0 is connected to PC or 5V mobile charger adapter.

The following was observed in both cases (USB0 connected to PC or adapter)

 1.Read at address  0x44E10620 (USB_CTRL0): 0x3C18640C
 2.Read at address  0x44E10624 (USB_STS0 ): 0x00000000
 3.Pin USB_CE is low

After changing function am335x_phy_power in drivers/usb/phy/phy-am335x-control.c ,

---
 drivers/usb/phy/phy-am335x-control.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c
index 7b3035f..c572460 100644
--- a/drivers/usb/phy/phy-am335x-control.c
+++ b/drivers/usb/phy/phy-am335x-control.c
@@ -20,6 +20,9 @@ struct am335x_control_usb {
 
 #define USBPHY_CM_PWRDN		(1 << 0)
 #define USBPHY_OTG_PWRDN	(1 << 1)
+#define USBPHY_CHGDET_DIS	(1 << 2)
+#define USBPHY_CHGDET_RSTRT	(1 << 3)
+#define USBPHY_CDET_EXTCTL	(1 << 10)
 #define USBPHY_OTGVDET_EN	(1 << 19)
 #define USBPHY_OTGSESSEND_EN	(1 << 20)
 
@@ -80,10 +83,10 @@ static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on)
 
 	val = readl(usb_ctrl->phy_reg + reg);
 	if (on) {
-		val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN);
-		val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN;
+		val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN | USBPHY_CHGDET_DIS | USBPHY_CHGDET_RSTRT | USBPHY_CDET_EXTCTL);
+		val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN ;
 	} else {
-		val |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN;
+		val |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN | USBPHY_CHGDET_DIS | USBPHY_CHGDET_RSTRT | USBPHY_CDET_EXTCTL;
 	}
 
 	writel(val, usb_ctrl->phy_reg + reg);
-- 
1.9.1


following result is obtained.

When connected to Adapter
 1.Read at address  0x44E10620 (USB_CTRL0): 0x3C186000
 2.Read at address  0x44E10624 (USB_STS0 ): 0x000000A3
 3.Pin USB_CE is high.

When connected to PC
 1.Read at address  0x44E10620 (USB_CTRL0): 0x3C186000
 2.Read at address  0x44E10624 (USB_STS0 ): 0x000000C0
 3.Pin USB_CE is low.
 
The adapter is detected as HOST charger not dedicated charger.Is this the correct result?
Is this the right way of detecting whether the USB0 is connected to PC or adapter?

  • Hi Sooraj,

    This is the right way for detecting USB charger type. More clarifications from the TRM:
    The USB_CTRLn and USB_STSn registers reflect the Control and Status of the USB instances. The USB IO lines can be used as UART TX and RX lines the USB Control register bit field GPIOMODE has settings that configures the USB lines as GPIO lines. The other USB PHY control settings for controlling the OTG
    settings and PHY are part of the USB_CTRLn register.
    The USB_STSn register gives the status of the USB PHY module. See the USB_STSn register description for further details.

    BR
    Tsvetolin Shulev
  • Why USB Charger detection is not implemented in default driver? Will this have an effect on some other feature?