Skip to contentSkip to conversation

usb: musb: charger detection

RFC PATCH New Kishon Vijay Abraham I 6 participants 12 messages Sep 15, 2011 – Sep 19, 2011 2 messages not in the archive

Subsystems (6)
lore
Share & tools
lore
#1 lore raw

RFC PATCH 1/6 usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection

In reply to Kishon Vijay Abraham I

Setting OTG_INTERFSEL to UTMI interferes with charger detection resulting in incorrect detection of charger type. Hence OTG_INTERFSEL is configured to ULPI initially and changed to UTMI only after receiving USB_EVENT_ID or USB_EVENT_VBUS notification.

[[email protected]: The interface selection has to be done before the PHY is activated and is not allowed to change when the PHY clock is already running]

---
 drivers/usb/musb/omap2430.c |   50 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 41 insertions(+), 9 deletions(-)
drivers/usb/musb/omap2430.c +41 -9
index fc9377c..724450b 100644
@@ -228,6 +228,7 @@ static inline void omap2430_low_level_init(struct musb *musb)
 static int musb_otg_notifications(struct notifier_block *nb,
 		unsigned long event, void *unused)
 {
+	u32 val;
 	struct musb	*musb = container_of(nb, struct musb, nb);
 	struct device *dev = musb->controller;
 	struct musb_hdrc_platform_data *pdata = dev->platform_data;
@@ -240,11 +241,32 @@ static int musb_otg_notifications(struct notifier_block *nb,
 		if (is_otg_enabled(musb)) {
 			if (musb->gadget_driver) {
 				pm_runtime_get_sync(musb->controller);
+
+				val = musb_readl(musb->mregs, OTG_INTERFSEL);
+				if (data->interface_type ==
+							MUSB_INTERFACE_UTMI) {
+					val &= ~ULPI_12PIN;
+					val |= UTMI_8BIT;
+				} else {
+					val |= ULPI_12PIN;
+				}
+				musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
 				usb_phy_init(musb->xceiv);
 				omap2430_musb_set_vbus(musb, 1);
 			}
 		} else {
 			pm_runtime_get_sync(musb->controller);
+
+			val = musb_readl(musb->mregs, OTG_INTERFSEL);
+			if (data->interface_type == MUSB_INTERFACE_UTMI) {
+				val &= ~ULPI_12PIN;
+				val |= UTMI_8BIT;
+			} else {
+				val |= ULPI_12PIN;
+			}
+			musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
 			usb_phy_init(musb->xceiv);
 			omap2430_musb_set_vbus(musb, 1);
 		}
@@ -255,6 +277,16 @@ static int musb_otg_notifications(struct notifier_block *nb,
 
 		if (musb->gadget_driver)
 			pm_runtime_get_sync(musb->controller);
+
+		val = musb_readl(musb->mregs, OTG_INTERFSEL);
+		if (data->interface_type == MUSB_INTERFACE_UTMI) {
+			val &= ~ULPI_12PIN;
+			val |= UTMI_8BIT;
+		} else {
+			val |= ULPI_12PIN;
+		}
+		musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
 		usb_phy_init(musb->xceiv);
 		break;
 
@@ -272,6 +304,11 @@ static int musb_otg_notifications(struct notifier_block *nb,
 				otg_set_vbus(musb->xceiv->otg, 0);
 		}
 		usb_phy_shutdown(musb->xceiv);
+
+		val = musb_readl(musb->mregs, OTG_INTERFSEL);
+		val |= ULPI_12PIN;
+		musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
 		break;
 	default:
 		dev_dbg(musb->controller, "ID float\n");
@@ -304,16 +341,11 @@ static int omap2430_musb_init(struct musb *musb)
 		goto err1;
 	}
 
+	/* Set OTG_INTERFSEL to ULPI for correct charger detection.
+	 * This should be later set to UTMI.
+	 */
 	l = musb_readl(musb->mregs, OTG_INTERFSEL);
-
-	if (data->interface_type == MUSB_INTERFACE_UTMI) {
-		/* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
-		l &= ~ULPI_12PIN;       /* Disable ULPI */
-		l |= UTMI_8BIT;         /* Enable UTMI  */
-	} else {
-		l |= ULPI_12PIN;
-	}
-
+	l |= ULPI_12PIN;
 	musb_writel(musb->mregs, OTG_INTERFSEL, l);
 
 	pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
Signature · 1 line
1.7.0.4
#8 lore raw

RFC PATCH 5/6 OMAP4: PHY internal: Add msleep_interruptible to charger detection function

In reply to Kishon Vijay Abraham I

From: Sergii Postulga <[email protected]>

Charger detection is given 500ms to complete until which it loops continuously taking all the processor time. If we plug USB-micro cable to board during playing video or audio we have a glitches. This patch frees time for doing other things during waiting the charger detecting flag.

---
 arch/arm/mach-omap2/omap_phy_internal.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/omap_phy_internal.c +1 -0
index 55918ea..2334de8 100644
@@ -135,6 +135,7 @@ int omap4_charger_detect(void)
 		chargertype = ((usb2phycore >> 21) & 0x7);
 		if (usb2phycore & USB2PHY_CHGDETECTED)
 			break;
+		msleep_interruptible(10);
 	} while (!time_after(jiffies, timeout));
 
 	switch (chargertype) {
Signature · 1 line
1.7.0.4
#0 lore raw

cover usb: musb: charger detection

This provides a series of patches contributed by several people to do correct charger detection and solve issues that came along with the charger detection implementation.

USB_EVENT_NONE notification is sent only when a PC cable/CDP cable or a device connected to MUSB is detached.

USB_EVENT_VBUS notification is sent only when a PC cable/CDP cable or a device is connected to MUSB.

Developed on:
git://github.com/torvalds/linux.git
commit id: cc39c6a9bbdebfcf1a7dee64d83bf302bc38d941

This patch series is developed and tested on top of Heikki Krogerus patch series (version4) [1]

Basic Testing:
Tested with gadget zero enabled for charger detection (PC/DCP). Data transfer testing is done on both omap4 and omap3 with ./testusb. Tested for device enumeration when a device is connected to MUSB.

[1] http://www.spinics.net/lists/linux-usb/msg51038.html

Balaji T K (2):
OMAP4: TWL6030: add USB charger detection
twl6030: set charger current to be used by battery charging module

Kishon Vijay Abraham I (2):
usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection
usb: musb: omap4430_phy_power to enable/disable clocks and power
up/down phy

Sergii Postulga (1):
OMAP4: PHY internal: Add msleep_interruptible to charger detection
function

Viswanath Puttagunta (1):
MUSB Charger Type Detection: Fix DCP detect during boot.

 arch/arm/mach-omap2/omap_phy_internal.c |   67 +++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/usb.h   |    1 +
 drivers/usb/musb/omap2430.c             |   50 +++++++++++++++++++----
 drivers/usb/otg/twl6030-usb.c           |   64 +++++++++++++++++++++++------
 4 files changed, 159 insertions(+), 23 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

RFC PATCH 2/6 usb: musb: omap4430_phy_power to enable/disable clocks and power up/down phy

In reply to a message not in the archive

omap4430_phy_power is modified to be self contained in that it enables clock and power up the phy in addition to modifying the USBOTGHS_CONTROL register during power on. Similarly while powering down, it disables clock and power down the phy.

---
 arch/arm/mach-omap2/omap_phy_internal.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/omap_phy_internal.c +11 -0
index 58775e3..a828833 100644
@@ -110,6 +110,13 @@ int omap4430_phy_set_clk(struct device *dev, int on)
 int omap4430_phy_power(struct device *dev, int ID, int on)
 {
 	if (on) {
+		/* enabled the clocks */
+		omap4430_phy_set_clk(dev, 1);
+		/* power on the phy */
+		if (__raw_readl(ctrl_base + CONTROL_DEV_CONF) & PHY_PD) {
+			__raw_writel(~PHY_PD, ctrl_base + CONTROL_DEV_CONF);
+			msleep_interruptible(200);
+		}
 		if (ID)
 			/* enable VBUS valid, IDDIG groung */
 			__raw_writel(AVALID | VBUSVALID, ctrl_base +
@@ -125,6 +132,10 @@ int omap4430_phy_power(struct device *dev, int ID, int on)
 		/* Enable session END and IDIG to high impedance. */
 		__raw_writel(SESSEND | IDDIG, ctrl_base +
 					USBOTGHS_CONTROL);
+		/* Power down the phy */
+		__raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
+		/* Disable the clocks */
+		omap4430_phy_set_clk(dev, 0);
 	}
 	return 0;
 }
Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw

RFC PATCH 3/6 OMAP4: TWL6030: add USB charger detection

In reply to a message not in the archive

From: Balaji T K <[email protected]>

Charger detection is done in threaded irq and is performed only when OMAP acts as B-device. Phy is powered on before charger detection and is powered down once charger detection is completed. The type of charger is sent through all the registered notifiers.

---
 arch/arm/mach-omap2/omap_phy_internal.c |   50 ++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/plat/usb.h   |    1 +
 drivers/usb/otg/twl6030-usb.c           |   51 ++++++++++++++++++++++--------
 3 files changed, 88 insertions(+), 14 deletions(-)
arch/arm/mach-omap2/omap_phy_internal.c +50 -0
index a828833..e5a6701 100644
@@ -27,6 +27,7 @@
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/usb.h>
+#include <linux/power_supply.h>
 
 #include <plat/usb.h>
 #include "control.h"
@@ -42,6 +43,13 @@
 #define	SESSEND				BIT(3)
 #define	IDDIG				BIT(4)
 
+#define CONTROL_USB2PHYCORE		0x620
+#define CHARGER_TYPE_PS2		0x2
+#define CHARGER_TYPE_DEDICATED		0x4
+#define CHARGER_TYPE_HOST		0x5
+#define CHARGER_TYPE_PC			0x6
+#define USB2PHY_CHGDETECTED		BIT(13)
+
 static struct clk *phyclk, *clk48m, *clk32k;
 static void __iomem *ctrl_base;
 static int usbotghs_control;
@@ -107,6 +115,48 @@ int omap4430_phy_set_clk(struct device *dev, int on)
 	return 0;
 }
 
+int omap4_charger_detect(void)
+{
+	unsigned long timeout;
+	int charger = 0;
+	u32 usb2phycore = 0;
+	u32 chargertype = 0;
+
+	omap4430_phy_power(NULL, 0, 1);
+
+	timeout = jiffies + msecs_to_jiffies(500);
+	do {
+		usb2phycore = omap4_ctrl_pad_readl(CONTROL_USB2PHYCORE);
+		chargertype = ((usb2phycore >> 21) & 0x7);
+		if (usb2phycore & USB2PHY_CHGDETECTED)
+			break;
+	} while (!time_after(jiffies, timeout));
+
+	switch (chargertype) {
+	case CHARGER_TYPE_DEDICATED:
+		charger = POWER_SUPPLY_TYPE_USB_DCP;
+		pr_info("DCP detected\n");
+		break;
+	case CHARGER_TYPE_HOST:
+		charger = POWER_SUPPLY_TYPE_USB_CDP;
+		pr_info("CDP detected\n");
+		break;
+	case CHARGER_TYPE_PC:
+		charger = POWER_SUPPLY_TYPE_USB;
+		pr_info("PC detected\n");
+		break;
+	case CHARGER_TYPE_PS2:
+		pr_info("PS/2 detected!\n");
+		break;
+	default:
+		pr_err(KERN_ERR"Unknown charger detected! %d\n", chargertype);
+	}
+
+	omap4430_phy_power(NULL, 0, 0);
+
+	return charger;
+}
+
 int omap4430_phy_power(struct device *dev, int ID, int on)
 {
 	if (on) {
arch/arm/plat-omap/include/plat/usb.h +1 -0
index 17d3c93..582851b 100644
@@ -107,6 +107,7 @@ extern int omap4430_phy_power(struct device *dev, int ID, int on);
 extern int omap4430_phy_set_clk(struct device *dev, int on);
 extern int omap4430_phy_init(struct device *dev);
 extern int omap4430_phy_exit(struct device *dev);
+extern int omap4_charger_detect(void);
 extern int omap4430_phy_suspend(struct device *dev, int suspend);
 #endif
 
drivers/usb/otg/twl6030-usb.c +37 -14

84 lines not on this page · raw message

Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

RFC PATCH 4/6 MUSB Charger Type Detection: Fix DCP detect during boot.

In reply to a message not in the archive

From: Viswanath Puttagunta <[email protected]>

The charger detection module is getting
disabled during boot up if a DCP (Dedicated charging port)
is connected before device is powered on (Bit 30 of CONTROL_USB2PHYCORE is set). This patch enables charger type detection each time the charger type wants to be detected.

---
 arch/arm/mach-omap2/omap_phy_internal.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/omap_phy_internal.c +5 -0
index e5a6701..55918ea 100644
@@ -49,6 +49,7 @@
 #define CHARGER_TYPE_HOST		0x5
 #define CHARGER_TYPE_PC			0x6
 #define USB2PHY_CHGDETECTED		BIT(13)
+#define USB2PHY_DISCHGDET		BIT(30)
 
 static struct clk *phyclk, *clk48m, *clk32k;
 static void __iomem *ctrl_base;
@@ -124,6 +125,10 @@ int omap4_charger_detect(void)
 
 	omap4430_phy_power(NULL, 0, 1);
 
+	usb2phycore = omap4_ctrl_pad_readl(CONTROL_USB2PHYCORE);
+	usb2phycore &= ~USB2PHY_DISCHGDET;
+	omap4_ctrl_pad_writel(usb2phycore, CONTROL_USB2PHYCORE);
+
 	timeout = jiffies + msecs_to_jiffies(500);
 	do {
 		usb2phycore = omap4_ctrl_pad_readl(CONTROL_USB2PHYCORE);
Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw

RFC PATCH 6/6 twl6030: set charger current to be used by battery charging module

In reply to a message not in the archive

From: Balaji T K <[email protected]>

Set the current supplied by dedicated charging port to 1800mV(according to battery charging specification). Also added a callback function for set_power to dynamically set the current to be supplied based on the state of the system.

---
 drivers/usb/otg/twl6030-usb.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/usb/otg/twl6030-usb.c +13 -0
index 6cb28ea..1f22c10 100644
@@ -102,6 +102,7 @@ struct twl6030_usb {
 
 	int			irq1;
 	int			irq2;
+	unsigned int		usb_cinlimit_mA;
 	u8			linkstat;
 	u8			asleep;
 	u8			prev_vbus;
@@ -305,6 +306,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
 			regulator_disable(twl->usb3v3);
 			status = USB_EVENT_CHARGER;
 			twl->xceiv.last_event = status;
+			twl->usb_cinlimit_mA = 1800;
 		} else {
 			regulator_disable(twl->usb3v3);
 			goto vbus_notify;
@@ -435,6 +437,16 @@ static int twl6030_set_host(struct usb_otg *otg, struct usb_bus *host)
 	return 0;
 }
 
+static int twl6030_set_power(struct usb_phy *x, unsigned int mA)
+{
+	struct twl6030_usb *twl = xceiv_to_twl(x);
+
+	twl->usb_cinlimit_mA = mA;
+	atomic_notifier_call_chain(&twl->xceiv.notifier, USB_EVENT_ENUMERATED,
+				&twl->usb_cinlimit_mA);
+	return 0;
+}
+
 static int __devinit twl6030_usb_probe(struct platform_device *pdev)
 {
 	struct twl6030_usb	*twl;
@@ -463,6 +475,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
 	twl->xceiv.label	= "twl6030";
 	twl->xceiv.otg		= otg;
 	twl->xceiv.init		= twl6030_phy_init;
+	twl->xceiv.set_power	= twl6030_set_power;
 	twl->xceiv.shutdown	= twl6030_phy_shutdown;
 	twl->xceiv.set_suspend	= twl6030_phy_suspend;
 
Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Re: [RFC PATCH 1/6] usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection

In reply to Kishon Vijay Abraham I

Hello.

Quoted 7 lines · Kishon Vijay Abraham I

Setting OTG_INTERFSEL to UTMI interferes with charger detection resulting in incorrect detection of charger type. Hence OTG_INTERFSEL is configured to ULPI initially and changed to UTMI only after receiving USB_EVENT_ID or USB_EVENT_VBUS notification.

AFAIK, full name is needed here.

Quoted 3 lines

[[email protected]: The interface selection has to be done before the PHY is activated and is not allowed to change when the PHY clock is already running]

No signoff from him?

Quoted 55 lines
---
  drivers/usb/musb/omap2430.c |   50 +++++++++++++++++++++++++++++++++++-------
  1 files changed, 41 insertions(+), 9 deletions(-)
drivers/usb/musb/omap2430.c +24 -0
index fc9377c..724450b 100644
@@ -228,6 +228,7 @@ static inline void omap2430_low_level_init(struct musb *musb)
  static int musb_otg_notifications(struct notifier_block *nb,
  		unsigned long event, void *unused)
  {
+	u32 val;
  	struct musb	*musb = container_of(nb, struct musb, nb);
  	struct device *dev = musb->controller;
  	struct musb_hdrc_platform_data *pdata = dev->platform_data;
@@ -240,11 +241,32 @@ static int musb_otg_notifications(struct notifier_block *nb,
  		if (is_otg_enabled(musb)) {
  			if (musb->gadget_driver) {
  				pm_runtime_get_sync(musb->controller);
+
+				val = musb_readl(musb->mregs, OTG_INTERFSEL);
+				if (data->interface_type ==
+							MUSB_INTERFACE_UTMI) {
+					val&= ~ULPI_12PIN;
+					val |= UTMI_8BIT;
+				} else {
+					val |= ULPI_12PIN;
+				}
+				musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
  				usb_phy_init(musb->xceiv);
  				omap2430_musb_set_vbus(musb, 1);
  			}
  		} else {
  			pm_runtime_get_sync(musb->controller);
+
+			val = musb_readl(musb->mregs, OTG_INTERFSEL);
+			if (data->interface_type == MUSB_INTERFACE_UTMI) {
+				val&= ~ULPI_12PIN;
+				val |= UTMI_8BIT;
+			} else {
+				val |= ULPI_12PIN;
+			}
+			musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
  			usb_phy_init(musb->xceiv);
  			omap2430_musb_set_vbus(musb, 1);
  		}
@@ -255,6 +277,16 @@ static int musb_otg_notifications(struct notifier_block *nb,
 
  		if (musb->gadget_driver)
  			pm_runtime_get_sync(musb->controller);
+
+		val = musb_readl(musb->mregs, OTG_INTERFSEL);

drivers/usb/musb/omap2430.c static int musb_otg_notifications(struct notifier_block *nb, · line 291

Quoted 10 lines
drivers/usb/musb/omap2430.c +8 -0
+		if (data->interface_type == MUSB_INTERFACE_UTMI) {
+			val&= ~ULPI_12PIN;
+			val |= UTMI_8BIT;
+		} else {
+			val |= ULPI_12PIN;
+		}
+		musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
  		usb_phy_init(musb->xceiv);
  		break;

Why repeat the same sequence 3 times. Couldn't you factor it out into a
subroutine?

Quoted 21 lines
drivers/usb/musb/omap2430.c +8 -1
@@ -272,6 +304,11 @@ static int musb_otg_notifications(struct notifier_block *nb,
  				otg_set_vbus(musb->xceiv->otg, 0);
  		}
  		usb_phy_shutdown(musb->xceiv);
+
+		val = musb_readl(musb->mregs, OTG_INTERFSEL);
+		val |= ULPI_12PIN;
+		musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
  		break;
  	default:
  		dev_dbg(musb->controller, "ID float\n");
@@ -304,16 +341,11 @@ static int omap2430_musb_init(struct musb *musb)
  		goto err1;
  	}
 
+	/* Set OTG_INTERFSEL to ULPI for correct charger detection.
+	 * This should be later set to UTMI.
+	 */
  	l = musb_readl(musb->mregs, OTG_INTERFSEL);
-

drivers/usb/musb/omap2430.c static int omap2430_musb_init(struct musb *musb) · line 349

Quoted 10 lines
drivers/usb/musb/omap2430.c +1 -8
-	if (data->interface_type == MUSB_INTERFACE_UTMI) {
-		/* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
-		l&= ~ULPI_12PIN;       /* Disable ULPI */
-		l |= UTMI_8BIT;         /* Enable UTMI  */
-	} else {
-		l |= ULPI_12PIN;
-	}
-
+	l |= ULPI_12PIN;
  	musb_writel(musb->mregs, OTG_INTERFSEL, l);

This also seems to be the same code repeated twice...

WBR, Sergei

#3 lore raw

Re: [RFC PATCH 1/6] usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection

Sergei,

Thanks for your comments.

Quoted 10 lines · Sergei Shtylyov

Hello.

Quoted 5 lines · Kishon Vijay Abraham I

Setting OTG_INTERFSEL to UTMI interferes with charger detection resulting in incorrect detection of charger type. Hence OTG_INTERFSEL is configured to
ULPI initially and changed to UTMI only after receiving USB_EVENT_ID or USB_EVENT_VBUS notification.

Quoted 4 lines
Quoted 2 lines

  AFAIK, full name is needed here.

is it not the prerogative of the person giving his signed-off by??

Quoted 7 lines
Quoted 5 lines

[[email protected]: The interface selection has to be done before the PHY
is activated and is not allowed to change when the PHY clock is already running]

  No signoff from him?

ok. will add his signoff.

Quoted 68 lines
Quoted 68 lines

---
 drivers/usb/musb/omap2430.c |   50
+++++++++++++++++++++++++++++++++++-------

 1 files changed, 41 insertions(+), 9 deletions(-)
drivers/usb/musb/omap2430.c +1 -0
index fc9377c..724450b 100644
@@ -228,6 +228,7 @@ static inline void omap2430_low_level_init(struct musb
 *musb)
  static int musb_otg_notifications(struct notifier_block *nb,
                unsigned long event, void *unused)
  {
+       u32 val;
        struct musb     *musb = container_of(nb, struct musb, nb);
        struct device *dev = musb->controller;

       struct musb_hdrc_platform_data *pdata = dev->platform_data;

drivers/usb/musb/omap2430.c +11 -0
@@ -240,11 +241,32 @@ static int musb_otg_notifications(struct
 notifier_block *nb,
                if (is_otg_enabled(musb)) {
                        if (musb->gadget_driver) {
                                pm_runtime_get_sync(musb->controller);
+
+                               val = musb_readl(musb->mregs,
 OTG_INTERFSEL);
+                               if (data->interface_type ==
+
 MUSB_INTERFACE_UTMI) {
+                                       val&= ~ULPI_12PIN;
+                                       val |= UTMI_8BIT;
+                               } else {
+                                       val |= ULPI_12PIN;
+                               }
+                               musb_writel(musb->mregs, OTG_INTERFSEL,
 val);
+
                                usb_phy_init(musb->xceiv);
                                omap2430_musb_set_vbus(musb, 1);
                        }
                } else {

                       pm_runtime_get_sync(musb->controller);

drivers/usb/musb/omap2430.c +10 -0
+
+                       val = musb_readl(musb->mregs, OTG_INTERFSEL);
+                       if (data->interface_type == MUSB_INTERFACE_UTMI) {
+                               val&= ~ULPI_12PIN;
+                               val |= UTMI_8BIT;
+                       } else {
+                               val |= ULPI_12PIN;
+                       }
+                       musb_writel(musb->mregs, OTG_INTERFSEL, val);
+

                       usb_phy_init(musb->xceiv); omap2430_musb_set_vbus(musb, 1); }

drivers/usb/musb/omap2430.c +7 -0
@@ -255,6 +277,16 @@ static int musb_otg_notifications(struct
 notifier_block *nb,
 
                if (musb->gadget_driver)
                        pm_runtime_get_sync(musb->controller);
+
+               val = musb_readl(musb->mregs, OTG_INTERFSEL);
+               if (data->interface_type == MUSB_INTERFACE_UTMI) {
+                       val&= ~ULPI_12PIN;
+                       val |= UTMI_8BIT;
+               } else {
+                       val |= ULPI_12PIN;
Quoted 8 lines

drivers/usb/musb/omap2430.c static int musb_otg_notifications(struct notifier_block *nb, · line 291

Quoted 5 lines
drivers/usb/musb/omap2430.c +3 -0
+               }
+               musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
                usb_phy_init(musb->xceiv);
                break;

  Why repeat the same sequence 3 times. Couldn't you factor it out into a subroutine?

I thought it will be unnecessary to to add a subroutine just for a single register modification.
Since you have pointed that out, I'll add a subroutine for it.

Quoted 28 lines
Quoted 28 lines
drivers/usb/musb/omap2430.c +5 -0
@@ -272,6 +304,11 @@ static int musb_otg_notifications(struct
 notifier_block *nb,
                                otg_set_vbus(musb->xceiv->otg, 0);
                }
                usb_phy_shutdown(musb->xceiv);
+
+               val = musb_readl(musb->mregs, OTG_INTERFSEL);
+               val |= ULPI_12PIN;
+               musb_writel(musb->mregs, OTG_INTERFSEL, val);
+
                break;

       default:
               dev_dbg(musb->controller, "ID float\n");

drivers/usb/musb/omap2430.c +3 -5
@@ -304,16 +341,11 @@ static int omap2430_musb_init(struct musb *musb)
                goto err1;
        }
 
+       /* Set OTG_INTERFSEL to ULPI for correct charger detection.
+        * This should be later set to UTMI.
+        */
        l = musb_readl(musb->mregs, OTG_INTERFSEL);
-
-       if (data->interface_type == MUSB_INTERFACE_UTMI) {
-               /* OMAP4 uses Internal PHY GS70 which uses UTMI interface
 */
-               l&= ~ULPI_12PIN;       /* Disable ULPI */
-               l |= UTMI_8BIT;         /* Enable UTMI  */
Quoted 8 lines

drivers/usb/musb/omap2430.c static int omap2430_musb_init(struct musb *musb) · line 349

Quoted 6 lines
drivers/usb/musb/omap2430.c +1 -4
-       } else {
-               l |= ULPI_12PIN;
-       }
-
+       l |= ULPI_12PIN;
        musb_writel(musb->mregs, OTG_INTERFSEL, l);

  This also seems to be the same code repeated twice...

Ok. So i'll create a new sub-routine which takes interface type as argument and set OTG_INTERFSEL to ULPI_12PIN or UTMI_8BIT based on the interface type.

Regards
Kishon

Quoted 3 lines

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [RFC PATCH 1/6] usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection

In reply to a message not in the archive
Quoted 15 lines · KISHON VIJAY

Sergei,

Thanks for your comments.

Quoted 10 lines · Sergei Shtylyov

Hello.

Quoted 5 lines · Kishon Vijay Abraham I

Setting OTG_INTERFSEL to UTMI interferes with charger detection resulting in incorrect detection of charger type. Hence OTG_INTERFSEL is configured to
ULPI initially and changed to UTMI only after receiving USB_EVENT_ID or USB_EVENT_VBUS notification.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

  AFAIK, full name is needed here.

is it not the prerogative of the person giving his signed-off by??

Not really.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

[[email protected]: The interface selection has to be done before the PHY
is activated and is not allowed to change when the PHY clock is already running]

  No signoff from him?

ok. will add his signoff.

You can NOT add someone else's sign-off to a patch, please go re-read Documentation/SubmittingPatches as to what this really means.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [RFC PATCH 1/6] usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection

Quoted 16 lines · Greg KH
Quoted 15 lines · KISHON VIJAY

Sergei,

Thanks for your comments.

Quoted 10 lines · Sergei Shtylyov

Hello.

Quoted 5 lines · Kishon Vijay Abraham I

Setting OTG_INTERFSEL to UTMI interferes with charger detection resulting in incorrect detection of charger type. Hence OTG_INTERFSEL is configured to
ULPI initially and changed to UTMI only after receiving USB_EVENT_ID or USB_EVENT_VBUS notification.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

  AFAIK, full name is needed here.

is it not the prerogative of the person giving his signed-off by??

Not really.

Certainly did not want to compete for long names :-) But Is Real Name + unique email id not sufficient. patches with this Signed-off .

Signature · 6 lines
Thanks and Regards,
Balaji T K
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

Re: [RFC PATCH 1/6] usb: musb: omap: Configure OTG_INTERFSEL for proper charger detection

Quoted 22 lines · Balaji
Quoted 21 lines · Greg KH
Quoted 20 lines · KISHON VIJAY

Sergei,

Thanks for your comments.

Quoted 14 lines · Sergei Shtylyov

Hello.

Quoted 8 lines · Kishon Vijay Abraham I

Setting OTG_INTERFSEL to UTMI interferes with charger detection resulting in incorrect detection of charger type. Hence OTG_INTERFSEL is configured to
ULPI initially and changed to UTMI only after receiving USB_EVENT_ID or USB_EVENT_VBUS notification.

  AFAIK, full name is needed here.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

is it not the prerogative of the person giving his signed-off by??

Not really.

Certainly did not want to compete for long names :-) But Is Real Name + unique email id not sufficient. patches with this Signed-off .

Real Name + unique email is sufficient. If "Balaji T K" is the real name here, then my sincere apologies at getting this incorrect. If it isn't, a few more letters might be sufficient, or even, native utf-8 characters for the name in the native language is also ok.

I know I get enough problems with my "odd" last name to be aware that there are lots of misconceptions about what is a real and not-real way to spell/handle a name, so again, if I am mistaken here, please let me know.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html