usb: msm: 8x60: use PHY ID circuit for ID_GND to ID_A transistions.
As PMIC can't generate ID_GND to ID_A transistions use PHY
ID circuit for ID_GND to ID_A and ID_A to ID_GND transistions.
As both PMIC ID pullup and PHY ID pullup can't be enabled at the same
time decouple enabling the PMIC MPP2(which will close FET for HSUSB PHY
ID detection) from configuring the PMIC ID IRQ.
Configure the PMIC ID IRQ upon cable disconnect and disable PHY ID
circuit.
Upon cable connect, unconfigure the PMIC ID IRQ and enable PHY ID
circuit.
Change-Id: Idabee8541580dd1b7e6b156c1330e3d7d12aa18a
CRs-fixed: 312423
Signed-off-by: Anji jonnala <anjir@codeaurora.org>
diff --git a/arch/arm/mach-msm/board-msm8x60.c b/arch/arm/mach-msm/board-msm8x60.c
index b217b41..b394710 100644
--- a/arch/arm/mach-msm/board-msm8x60.c
+++ b/arch/arm/mach-msm/board-msm8x60.c
@@ -993,6 +993,7 @@
static struct regulator *ldo7_1p8;
static struct regulator *vdd_cx;
#define PMICID_INT PM8058_GPIO_IRQ(PM8058_IRQ_BASE, 36)
+#define PMIC_ID_GPIO 36
notify_vbus_state notify_vbus_state_func_ptr;
static int usb_phy_susp_dig_vol = 750000;
static int pmic_id_notif_supported;
@@ -1031,10 +1032,42 @@
return IRQ_HANDLED;
}
+static int msm_hsusb_phy_id_setup_init(int init)
+{
+ unsigned ret;
+
+ if (init) {
+ ret = pm8901_mpp_config_digital_out(1,
+ PM8901_MPP_DIG_LEVEL_L5, 1);
+ if (ret < 0)
+ pr_err("%s:MPP2 configuration failed\n", __func__);
+ } else {
+ ret = pm8901_mpp_config_digital_out(1,
+ PM8901_MPP_DIG_LEVEL_L5, 0);
+ if (ret < 0)
+ pr_err("%s:MPP2 un config failed\n", __func__);
+ }
+ return ret;
+}
+
static int msm_hsusb_pmic_id_notif_init(void (*callback)(int online), int init)
{
unsigned ret = -ENODEV;
+ struct pm8058_gpio pmic_id_cfg = {
+ .direction = PM_GPIO_DIR_IN,
+ .pull = PM_GPIO_PULL_UP_1P5,
+ .function = PM_GPIO_FUNC_NORMAL,
+ .vin_sel = 2,
+ .inv_int_pol = 0,
+ };
+ struct pm8058_gpio pmic_id_uncfg = {
+ .direction = PM_GPIO_DIR_IN,
+ .pull = PM_GPIO_PULL_NO,
+ .function = PM_GPIO_FUNC_NORMAL,
+ .vin_sel = 2,
+ .inv_int_pol = 0,
+ };
if (!callback)
return -EINVAL;
@@ -1058,37 +1091,34 @@
if (init) {
notify_vbus_state_func_ptr = callback;
- ret = pm8901_mpp_config_digital_out(1,
- PM8901_MPP_DIG_LEVEL_L5, 1);
- if (ret) {
- pr_err("%s: MPP2 configuration failed\n", __func__);
- return -ENODEV;
- }
INIT_DELAYED_WORK(&pmic_id_det, pmic_id_detect);
+ ret = pm8058_gpio_config(PMIC_ID_GPIO, &pmic_id_cfg);
+ if (ret) {
+ pr_err("%s:return val of pm8058_gpio_config: %d\n",
+ __func__, ret);
+ return ret;
+ }
ret = request_threaded_irq(PMICID_INT, NULL, pmic_id_on_irq,
(IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING),
"msm_otg_id", NULL);
if (ret) {
- pm8901_mpp_config_digital_out(1,
- PM8901_MPP_DIG_LEVEL_L5, 0);
pr_err("%s:pmic_usb_id interrupt registration failed",
__func__);
return ret;
}
- /* Notify the initial Id status */
- pmic_id_detect(&pmic_id_det.work);
msm_otg_pdata.pmic_id_irq = PMICID_INT;
} else {
+ usb_phy_susp_dig_vol = 750000;
free_irq(PMICID_INT, 0);
+ ret = pm8058_gpio_config(PMIC_ID_GPIO, &pmic_id_uncfg);
+ if (ret) {
+ pr_err("%s: return val of pm8058_gpio_config: %d\n",
+ __func__, ret);
+ return ret;
+ }
msm_otg_pdata.pmic_id_irq = 0;
cancel_delayed_work_sync(&pmic_id_det);
notify_vbus_state_func_ptr = NULL;
- ret = pm8901_mpp_config_digital_out(1,
- PM8901_MPP_DIG_LEVEL_L5, 0);
- if (ret) {
- pr_err("%s:MPP2 configuration failed\n", __func__);
- return -ENODEV;
- }
}
return 0;
}
@@ -1393,6 +1423,7 @@
.bam_disable = 1,
#ifdef CONFIG_USB_EHCI_MSM_72K
.pmic_id_notif_init = msm_hsusb_pmic_id_notif_init,
+ .phy_id_setup_init = msm_hsusb_phy_id_setup_init,
#endif
#ifdef CONFIG_USB_EHCI_MSM_72K
.vbus_power = msm_hsusb_vbus_power,
@@ -5429,7 +5460,7 @@
36,
{
.direction = PM_GPIO_DIR_IN,
- .pull = PM_GPIO_PULL_UP_1P5,
+ .pull = PM_GPIO_PULL_NO,
.function = PM_GPIO_FUNC_NORMAL,
.vin_sel = 2,
.inv_int_pol = 0,
diff --git a/arch/arm/mach-msm/include/mach/msm72k_otg.h b/arch/arm/mach-msm/include/mach/msm72k_otg.h
index 43f487a..4509dad 100644
--- a/arch/arm/mach-msm/include/mach/msm72k_otg.h
+++ b/arch/arm/mach-msm/include/mach/msm72k_otg.h
@@ -25,6 +25,7 @@
#define OTGSC_BSVIE (1 << 27)
#define OTGSC_IDIE (1 << 24)
+#define OTGSC_IDPU (1 << 5)
#define OTGSC_BSVIS (1 << 19)
#define OTGSC_ID (1 << 8)
#define OTGSC_IDIS (1 << 16)
@@ -148,7 +149,6 @@
struct wake_lock wlock;
unsigned long b_last_se0_sess; /* SRP initial condition check */
unsigned long inputs;
- int pmic_id_status;
unsigned long tmouts;
u8 active_tmout;
struct hrtimer timer;
diff --git a/arch/arm/mach-msm/include/mach/msm_hsusb.h b/arch/arm/mach-msm/include/mach/msm_hsusb.h
index 26f1cdd..3e8ab55 100644
--- a/arch/arm/mach-msm/include/mach/msm_hsusb.h
+++ b/arch/arm/mach-msm/include/mach/msm_hsusb.h
@@ -158,6 +158,7 @@
/* pmic notfications apis */
int (*pmic_vbus_notif_init) (void (*callback)(int online), int init);
int (*pmic_id_notif_init) (void (*callback)(int online), int init);
+ int (*phy_id_setup_init) (int init);
int (*pmic_register_vbus_sn) (void (*callback)(int online));
void (*pmic_unregister_vbus_sn) (void (*callback)(int online));
int (*pmic_enable_ldo) (int);
diff --git a/drivers/usb/otg/msm72k_otg.c b/drivers/usb/otg/msm72k_otg.c
index fccd357..714099a 100644
--- a/drivers/usb/otg/msm72k_otg.c
+++ b/drivers/usb/otg/msm72k_otg.c
@@ -37,7 +37,13 @@
#define DRIVER_NAME "msm_otg"
static void otg_reset(struct otg_transceiver *xceiv, int phy_reset);
static void msm_otg_set_vbus_state(int online);
-static void msm_otg_set_id_state(int online);
+#ifdef CONFIG_USB_EHCI_MSM_72K
+static void msm_otg_set_id_state(int id);
+#else
+static void msm_otg_set_id_state(int id)
+{
+}
+#endif
struct msm_otg *the_msm_otg;
@@ -45,9 +51,7 @@
{
struct msm_otg *dev = the_msm_otg;
- if (dev->pmic_id_notif_supp)
- return dev->pmic_id_status ? 0 : 1;
- else if (dev->pdata->otg_mode == OTG_ID)
+ if (dev->pdata->otg_mode == OTG_ID)
return (OTGSC_ID & readl(USB_OTGSC)) ? 0 : 1;
else
return !test_bit(ID, &dev->inputs);
@@ -135,24 +139,38 @@
#ifdef CONFIG_USB_EHCI_MSM_72K
static void enable_idgnd(struct msm_otg *dev)
{
+ unsigned temp;
+
/* Do nothing if instead of ID pin, USER controls mode switch */
if (dev->pdata->otg_mode == OTG_USER_CONTROL)
return;
ulpi_write(dev, (1<<4), 0x0E);
ulpi_write(dev, (1<<4), 0x11);
- writel_relaxed(readl_relaxed(USB_OTGSC) | OTGSC_IDIE, USB_OTGSC);
+ ulpi_write(dev, (1<<0), 0x0B);
+ temp = OTGSC_IDIE | OTGSC_IDPU;
+ writel_relaxed(readl_relaxed(USB_OTGSC) | temp, USB_OTGSC);
}
static void disable_idgnd(struct msm_otg *dev)
{
+ unsigned temp;
+
/* Do nothing if instead of ID pin, USER controls mode switch */
if (dev->pdata->otg_mode == OTG_USER_CONTROL)
return;
-
+ temp = OTGSC_IDIE | OTGSC_IDPU;
+ writel_relaxed(readl_relaxed(USB_OTGSC) & ~temp, USB_OTGSC);
ulpi_write(dev, (1<<4), 0x0F);
ulpi_write(dev, (1<<4), 0x12);
- writel_relaxed(readl_relaxed(USB_OTGSC) & ~OTGSC_IDIE, USB_OTGSC);
+ ulpi_write(dev, (1<<0), 0x0C);
+}
+#else
+static void enable_idgnd(struct msm_otg *dev)
+{
+}
+static void disable_idgnd(struct msm_otg *dev)
+{
}
#endif
@@ -224,6 +242,9 @@
#define get_aca_bmaxpower(dev) (dev->b_max_power)
#define set_aca_bmaxpower(dev, power) (dev->b_max_power = power)
#else
+static void set_aca_id_inputs(struct msm_otg *dev)
+{
+}
#define get_aca_bmaxpower(dev) 0
#define set_aca_bmaxpower(dev, power)
#endif
@@ -692,6 +713,31 @@
* 4. peripheral is supported, but, vbus is not routed to pmic
*/
host_bus_suspend = dev->otg.host && is_host();
+
+ /*
+ * Configure the PMIC ID only in case of cable disconnect.
+ * PMIC doesn't generate interrupt for ID_GND to ID_A
+ * transistion. hence use the PHY ID cricuit.
+ */
+ if (dev->pdata->pmic_id_notif_init && !host_bus_suspend &&
+ !test_bit(ID_A, &dev->inputs)) {
+ disable_idgnd(dev);
+ ret = dev->pdata->pmic_id_notif_init(
+ &msm_otg_set_id_state, 1);
+ if (!ret) {
+ dev->pmic_id_notif_supp = 1;
+ if (dev->pdata->pmic_id_irq)
+ dev->id_irq = dev->pdata->pmic_id_irq;
+ } else if (ret == -ENOTSUPP) {
+ pr_debug("%s:USB ID is not routed to pmic",
+ __func__);
+ enable_idgnd(dev);
+ } else {
+ pr_err("%s: pmic_id_ notif_init failed err:%d",
+ __func__, ret);
+ }
+ }
+
if ((dev->otg.gadget && chg_type == USB_CHG_TYPE__WALLCHARGER) ||
host_bus_suspend ||
(dev->otg.host && !dev->pmic_id_notif_supp) ||
@@ -760,7 +806,8 @@
* that there is no harm with this. Till hw folks confirms this
* put regulators in lpm.
*/
- if (!host_bus_suspend && dev->pmic_vbus_notif_supp) {
+ if (!host_bus_suspend && dev->pmic_vbus_notif_supp &&
+ !test_bit(ID_A, &dev->inputs)) {
pr_debug("phy can power collapse: (%d)\n",
can_phy_power_collapse(dev));
if (can_phy_power_collapse(dev) && dev->pdata->ldo_enable) {
@@ -881,9 +928,35 @@
}
phy_resumed:
+ /*
+ * It is observed that BSVIS may get set immediatly
+ * after PHY becomes active upon micro-B cable connect.
+ * But BSVIS might get cleared by below enable_idgnd
+ * function which causes hw to not generate the BSV interrupt.
+ * Hence check for BSV interrupt explictly and schedule the
+ * work.
+ */
+ if (readl_relaxed(USB_OTGSC) & OTGSC_BSVIS) {
+ set_bit(B_SESS_VLD, &dev->inputs);
+ queue_work(dev->wq, &dev->sm_work);
+ }
+ if (dev->pmic_id_notif_supp) {
+ dev->pdata->pmic_id_notif_init(&msm_otg_set_id_state, 0);
+ dev->pmic_id_notif_supp = 0;
+ enable_idgnd(dev);
+ }
+
/* Enable Idabc interrupts as these were disabled before entering LPM */
enable_idabc(dev);
+ /*
+ * There is corner case where host won't be resumed
+ * while transitioning from ID_GND to ID_A. In that
+ * IDGND might have cleared and ID_A might not have updated
+ * yet. Hence update the ACA states explicitly.
+ */
+ set_aca_id_inputs(dev);
+
/* If resume signalling finishes before lpm exit, PCD is not set in
* USBSTS register. Drive resume signal to the downstream device now
* so that host driver can process the upcoming port change interrupt.*/
@@ -996,6 +1069,12 @@
}
udelay(10);
}
+ if (dev->pmic_id_notif_supp) {
+ dev->pdata->pmic_id_notif_init(
+ &msm_otg_set_id_state, 0);
+ dev->pmic_id_notif_supp = 0;
+ enable_idgnd(dev);
+ }
out:
enable_idabc(dev);
enable_irq(dev->irq);
@@ -1119,23 +1198,20 @@
#endif
return 0;
}
-#endif
-void msm_otg_set_id_state(int id)
+static void msm_otg_set_id_state(int id)
{
struct msm_otg *dev = the_msm_otg;
unsigned long flags;
- if (id == dev->pmic_id_status)
+ if (!atomic_read(&dev->in_lpm))
return;
if (id) {
set_bit(ID, &dev->inputs);
- dev->pmic_id_status = 1;
} else {
clear_bit(ID, &dev->inputs);
set_bit(A_BUS_REQ, &dev->inputs);
- dev->pmic_id_status = 0;
}
spin_lock_irqsave(&dev->lock, flags);
if (dev->otg.state != OTG_STATE_UNDEFINED) {
@@ -1144,6 +1220,7 @@
}
spin_unlock_irqrestore(&dev->lock, flags);
}
+#endif
void msm_otg_set_vbus_state(int online)
{
@@ -1973,6 +2050,7 @@
} else if (test_bit(ID_A, &dev->inputs)) {
dev->pdata->vbus_power(USB_PHY_INTEGRATED, 0);
} else if (!test_bit(ID, &dev->inputs)) {
+ msm_otg_set_power(&dev->otg, 0);
dev->pdata->vbus_power(USB_PHY_INTEGRATED, 1);
}
break;
@@ -2687,12 +2765,10 @@
}
}
- if (dev->pdata->pmic_id_notif_init) {
- ret = dev->pdata->pmic_id_notif_init(&msm_otg_set_id_state, 1);
- if (!ret) {
- dev->pmic_id_notif_supp = 1;
- } else if (ret != -ENOTSUPP) {
- pr_err("%s: pmic_id_ notif_init failed err:%d",
+ if (dev->pdata->phy_id_setup_init) {
+ ret = dev->pdata->phy_id_setup_init(1);
+ if (ret) {
+ pr_err("%s: phy_id_setup_init failed err:%d",
__func__, ret);
goto free_pmic_vbus_notif;
}
@@ -2700,8 +2776,6 @@
if (dev->pdata->pmic_vbus_irq)
dev->vbus_on_irq = dev->pdata->pmic_vbus_irq;
- if (dev->pdata->pmic_id_irq)
- dev->id_irq = dev->pdata->pmic_id_irq;
/* vote for vddcx, as PHY cannot tolerate vddcx below 1.0V */
if (dev->pdata->init_vddcx) {
@@ -2709,7 +2783,7 @@
if (ret) {
pr_err("%s: unable to enable vddcx digital core:%d\n",
__func__, ret);
- goto free_pmic_id_notif;
+ goto free_phy_id_setup;
}
}
@@ -2819,9 +2893,9 @@
free_config_vddcx:
if (dev->pdata->init_vddcx)
dev->pdata->init_vddcx(0);
-free_pmic_id_notif:
- if (dev->pdata->pmic_id_notif_init && dev->pmic_id_notif_supp)
- dev->pdata->pmic_id_notif_init(&msm_otg_set_id_state, 0);
+free_phy_id_setup:
+ if (dev->pdata->phy_id_setup_init)
+ dev->pdata->phy_id_setup_init(0);
free_pmic_vbus_notif:
if (dev->pdata->pmic_vbus_notif_init && dev->pmic_vbus_notif_supp)
dev->pdata->pmic_vbus_notif_init(&msm_otg_set_vbus_state, 0);
@@ -2890,6 +2964,9 @@
if (dev->pmic_vbus_notif_supp)
dev->pdata->pmic_vbus_notif_init(&msm_otg_set_vbus_state, 0);
+ if (dev->pdata->phy_id_setup_init)
+ dev->pdata->phy_id_setup_init(0);
+
if (dev->pmic_id_notif_supp)
dev->pdata->pmic_id_notif_init(&msm_otg_set_id_state, 0);