Commit 1d4c9293 authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Felipe Balbi

usb: otg: msm: Start using struct usb_otg

Use struct usb_otg members with OTG specific functions instead
of usb_phy members.
Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: default avatarPavankumar Kondeti <pkondeti@codeaurora.org>
Reviewed-by: default avatarMarek Vasut <marek.vasut@gmail.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 819d1c74
...@@ -69,9 +69,9 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) ...@@ -69,9 +69,9 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
int ret = 0; int ret = 0;
if (init) { if (init) {
hsusb_vddcx = regulator_get(motg->otg.dev, "HSUSB_VDDCX"); hsusb_vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
if (IS_ERR(hsusb_vddcx)) { if (IS_ERR(hsusb_vddcx)) {
dev_err(motg->otg.dev, "unable to get hsusb vddcx\n"); dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
return PTR_ERR(hsusb_vddcx); return PTR_ERR(hsusb_vddcx);
} }
...@@ -79,7 +79,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) ...@@ -79,7 +79,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
USB_PHY_VDD_DIG_VOL_MIN, USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX); USB_PHY_VDD_DIG_VOL_MAX);
if (ret) { if (ret) {
dev_err(motg->otg.dev, "unable to set the voltage " dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n"); "for hsusb vddcx\n");
regulator_put(hsusb_vddcx); regulator_put(hsusb_vddcx);
return ret; return ret;
...@@ -87,18 +87,18 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) ...@@ -87,18 +87,18 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
ret = regulator_enable(hsusb_vddcx); ret = regulator_enable(hsusb_vddcx);
if (ret) { if (ret) {
dev_err(motg->otg.dev, "unable to enable hsusb vddcx\n"); dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n");
regulator_put(hsusb_vddcx); regulator_put(hsusb_vddcx);
} }
} else { } else {
ret = regulator_set_voltage(hsusb_vddcx, 0, ret = regulator_set_voltage(hsusb_vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX); USB_PHY_VDD_DIG_VOL_MAX);
if (ret) if (ret)
dev_err(motg->otg.dev, "unable to set the voltage " dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n"); "for hsusb vddcx\n");
ret = regulator_disable(hsusb_vddcx); ret = regulator_disable(hsusb_vddcx);
if (ret) if (ret)
dev_err(motg->otg.dev, "unable to disable hsusb vddcx\n"); dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n");
regulator_put(hsusb_vddcx); regulator_put(hsusb_vddcx);
} }
...@@ -111,40 +111,40 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) ...@@ -111,40 +111,40 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init)
int rc = 0; int rc = 0;
if (init) { if (init) {
hsusb_3p3 = regulator_get(motg->otg.dev, "HSUSB_3p3"); hsusb_3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
if (IS_ERR(hsusb_3p3)) { if (IS_ERR(hsusb_3p3)) {
dev_err(motg->otg.dev, "unable to get hsusb 3p3\n"); dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
return PTR_ERR(hsusb_3p3); return PTR_ERR(hsusb_3p3);
} }
rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN, rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX); USB_PHY_3P3_VOL_MAX);
if (rc) { if (rc) {
dev_err(motg->otg.dev, "unable to set voltage level " dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 3p3\n"); "for hsusb 3p3\n");
goto put_3p3; goto put_3p3;
} }
rc = regulator_enable(hsusb_3p3); rc = regulator_enable(hsusb_3p3);
if (rc) { if (rc) {
dev_err(motg->otg.dev, "unable to enable the hsusb 3p3\n"); dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n");
goto put_3p3; goto put_3p3;
} }
hsusb_1p8 = regulator_get(motg->otg.dev, "HSUSB_1p8"); hsusb_1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
if (IS_ERR(hsusb_1p8)) { if (IS_ERR(hsusb_1p8)) {
dev_err(motg->otg.dev, "unable to get hsusb 1p8\n"); dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
rc = PTR_ERR(hsusb_1p8); rc = PTR_ERR(hsusb_1p8);
goto disable_3p3; goto disable_3p3;
} }
rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN, rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX); USB_PHY_1P8_VOL_MAX);
if (rc) { if (rc) {
dev_err(motg->otg.dev, "unable to set voltage level " dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 1p8\n"); "for hsusb 1p8\n");
goto put_1p8; goto put_1p8;
} }
rc = regulator_enable(hsusb_1p8); rc = regulator_enable(hsusb_1p8);
if (rc) { if (rc) {
dev_err(motg->otg.dev, "unable to enable the hsusb 1p8\n"); dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n");
goto put_1p8; goto put_1p8;
} }
...@@ -235,9 +235,9 @@ static int msm_hsusb_ldo_set_mode(int on) ...@@ -235,9 +235,9 @@ static int msm_hsusb_ldo_set_mode(int on)
return ret < 0 ? ret : 0; return ret < 0 ? ret : 0;
} }
static int ulpi_read(struct usb_phy *otg, u32 reg) static int ulpi_read(struct usb_phy *phy, u32 reg)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
int cnt = 0; int cnt = 0;
/* initiate read operation */ /* initiate read operation */
...@@ -253,16 +253,16 @@ static int ulpi_read(struct usb_phy *otg, u32 reg) ...@@ -253,16 +253,16 @@ static int ulpi_read(struct usb_phy *otg, u32 reg)
} }
if (cnt >= ULPI_IO_TIMEOUT_USEC) { if (cnt >= ULPI_IO_TIMEOUT_USEC) {
dev_err(otg->dev, "ulpi_read: timeout %08x\n", dev_err(phy->dev, "ulpi_read: timeout %08x\n",
readl(USB_ULPI_VIEWPORT)); readl(USB_ULPI_VIEWPORT));
return -ETIMEDOUT; return -ETIMEDOUT;
} }
return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT)); return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT));
} }
static int ulpi_write(struct usb_phy *otg, u32 val, u32 reg) static int ulpi_write(struct usb_phy *phy, u32 val, u32 reg)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
int cnt = 0; int cnt = 0;
/* initiate write operation */ /* initiate write operation */
...@@ -279,13 +279,13 @@ static int ulpi_write(struct usb_phy *otg, u32 val, u32 reg) ...@@ -279,13 +279,13 @@ static int ulpi_write(struct usb_phy *otg, u32 val, u32 reg)
} }
if (cnt >= ULPI_IO_TIMEOUT_USEC) { if (cnt >= ULPI_IO_TIMEOUT_USEC) {
dev_err(otg->dev, "ulpi_write: timeout\n"); dev_err(phy->dev, "ulpi_write: timeout\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
return 0; return 0;
} }
static struct otg_io_access_ops msm_otg_io_ops = { static struct usb_phy_io_ops msm_otg_io_ops = {
.read = ulpi_read, .read = ulpi_read,
.write = ulpi_write, .write = ulpi_write,
}; };
...@@ -299,9 +299,9 @@ static void ulpi_init(struct msm_otg *motg) ...@@ -299,9 +299,9 @@ static void ulpi_init(struct msm_otg *motg)
return; return;
while (seq[0] >= 0) { while (seq[0] >= 0) {
dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n", dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n",
seq[0], seq[1]); seq[0], seq[1]);
ulpi_write(&motg->otg, seq[0], seq[1]); ulpi_write(&motg->phy, seq[0], seq[1]);
seq += 2; seq += 2;
} }
} }
...@@ -313,11 +313,11 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) ...@@ -313,11 +313,11 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
if (assert) { if (assert) {
ret = clk_reset(motg->clk, CLK_RESET_ASSERT); ret = clk_reset(motg->clk, CLK_RESET_ASSERT);
if (ret) if (ret)
dev_err(motg->otg.dev, "usb hs_clk assert failed\n"); dev_err(motg->phy.dev, "usb hs_clk assert failed\n");
} else { } else {
ret = clk_reset(motg->clk, CLK_RESET_DEASSERT); ret = clk_reset(motg->clk, CLK_RESET_DEASSERT);
if (ret) if (ret)
dev_err(motg->otg.dev, "usb hs_clk deassert failed\n"); dev_err(motg->phy.dev, "usb hs_clk deassert failed\n");
} }
return ret; return ret;
} }
...@@ -328,13 +328,13 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg) ...@@ -328,13 +328,13 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg)
ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT); ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT);
if (ret) { if (ret) {
dev_err(motg->otg.dev, "usb phy clk assert failed\n"); dev_err(motg->phy.dev, "usb phy clk assert failed\n");
return ret; return ret;
} }
usleep_range(10000, 12000); usleep_range(10000, 12000);
ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT); ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT);
if (ret) if (ret)
dev_err(motg->otg.dev, "usb phy clk deassert failed\n"); dev_err(motg->phy.dev, "usb phy clk deassert failed\n");
return ret; return ret;
} }
...@@ -358,7 +358,7 @@ static int msm_otg_phy_reset(struct msm_otg *motg) ...@@ -358,7 +358,7 @@ static int msm_otg_phy_reset(struct msm_otg *motg)
writel(val | PORTSC_PTS_ULPI, USB_PORTSC); writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
for (retries = 3; retries > 0; retries--) { for (retries = 3; retries > 0; retries--) {
ret = ulpi_write(&motg->otg, ULPI_FUNC_CTRL_SUSPENDM, ret = ulpi_write(&motg->phy, ULPI_FUNC_CTRL_SUSPENDM,
ULPI_CLR(ULPI_FUNC_CTRL)); ULPI_CLR(ULPI_FUNC_CTRL));
if (!ret) if (!ret)
break; break;
...@@ -375,7 +375,7 @@ static int msm_otg_phy_reset(struct msm_otg *motg) ...@@ -375,7 +375,7 @@ static int msm_otg_phy_reset(struct msm_otg *motg)
return ret; return ret;
for (retries = 3; retries > 0; retries--) { for (retries = 3; retries > 0; retries--) {
ret = ulpi_read(&motg->otg, ULPI_DEBUG); ret = ulpi_read(&motg->phy, ULPI_DEBUG);
if (ret != -ETIMEDOUT) if (ret != -ETIMEDOUT)
break; break;
ret = msm_otg_phy_clk_reset(motg); ret = msm_otg_phy_clk_reset(motg);
...@@ -385,14 +385,14 @@ static int msm_otg_phy_reset(struct msm_otg *motg) ...@@ -385,14 +385,14 @@ static int msm_otg_phy_reset(struct msm_otg *motg)
if (!retries) if (!retries)
return -ETIMEDOUT; return -ETIMEDOUT;
dev_info(motg->otg.dev, "phy_reset: success\n"); dev_info(motg->phy.dev, "phy_reset: success\n");
return 0; return 0;
} }
#define LINK_RESET_TIMEOUT_USEC (250 * 1000) #define LINK_RESET_TIMEOUT_USEC (250 * 1000)
static int msm_otg_reset(struct usb_phy *otg) static int msm_otg_reset(struct usb_phy *phy)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
struct msm_otg_platform_data *pdata = motg->pdata; struct msm_otg_platform_data *pdata = motg->pdata;
int cnt = 0; int cnt = 0;
int ret; int ret;
...@@ -401,7 +401,7 @@ static int msm_otg_reset(struct usb_phy *otg) ...@@ -401,7 +401,7 @@ static int msm_otg_reset(struct usb_phy *otg)
ret = msm_otg_phy_reset(motg); ret = msm_otg_phy_reset(motg);
if (ret) { if (ret) {
dev_err(otg->dev, "phy_reset failed\n"); dev_err(phy->dev, "phy_reset failed\n");
return ret; return ret;
} }
...@@ -435,8 +435,8 @@ static int msm_otg_reset(struct usb_phy *otg) ...@@ -435,8 +435,8 @@ static int msm_otg_reset(struct usb_phy *otg)
val |= OTGSC_BSVIE; val |= OTGSC_BSVIE;
} }
writel(val, USB_OTGSC); writel(val, USB_OTGSC);
ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_RISE); ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_RISE);
ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_FALL); ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL);
} }
return 0; return 0;
...@@ -448,8 +448,8 @@ static int msm_otg_reset(struct usb_phy *otg) ...@@ -448,8 +448,8 @@ static int msm_otg_reset(struct usb_phy *otg)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int msm_otg_suspend(struct msm_otg *motg) static int msm_otg_suspend(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
struct usb_bus *bus = otg->host; struct usb_bus *bus = phy->otg->host;
struct msm_otg_platform_data *pdata = motg->pdata; struct msm_otg_platform_data *pdata = motg->pdata;
int cnt = 0; int cnt = 0;
...@@ -475,10 +475,10 @@ static int msm_otg_suspend(struct msm_otg *motg) ...@@ -475,10 +475,10 @@ static int msm_otg_suspend(struct msm_otg *motg)
*/ */
if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) { if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) {
ulpi_read(otg, 0x14); ulpi_read(phy, 0x14);
if (pdata->otg_control == OTG_PHY_CONTROL) if (pdata->otg_control == OTG_PHY_CONTROL)
ulpi_write(otg, 0x01, 0x30); ulpi_write(phy, 0x01, 0x30);
ulpi_write(otg, 0x08, 0x09); ulpi_write(phy, 0x08, 0x09);
} }
/* /*
...@@ -495,8 +495,8 @@ static int msm_otg_suspend(struct msm_otg *motg) ...@@ -495,8 +495,8 @@ static int msm_otg_suspend(struct msm_otg *motg)
} }
if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
dev_err(otg->dev, "Unable to suspend PHY\n"); dev_err(phy->dev, "Unable to suspend PHY\n");
msm_otg_reset(otg); msm_otg_reset(phy);
enable_irq(motg->irq); enable_irq(motg->irq);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -528,7 +528,7 @@ static int msm_otg_suspend(struct msm_otg *motg) ...@@ -528,7 +528,7 @@ static int msm_otg_suspend(struct msm_otg *motg)
msm_hsusb_config_vddcx(0); msm_hsusb_config_vddcx(0);
} }
if (device_may_wakeup(otg->dev)) if (device_may_wakeup(phy->dev))
enable_irq_wake(motg->irq); enable_irq_wake(motg->irq);
if (bus) if (bus)
clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
...@@ -536,15 +536,15 @@ static int msm_otg_suspend(struct msm_otg *motg) ...@@ -536,15 +536,15 @@ static int msm_otg_suspend(struct msm_otg *motg)
atomic_set(&motg->in_lpm, 1); atomic_set(&motg->in_lpm, 1);
enable_irq(motg->irq); enable_irq(motg->irq);
dev_info(otg->dev, "USB in low power mode\n"); dev_info(phy->dev, "USB in low power mode\n");
return 0; return 0;
} }
static int msm_otg_resume(struct msm_otg *motg) static int msm_otg_resume(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
struct usb_bus *bus = otg->host; struct usb_bus *bus = phy->otg->host;
int cnt = 0; int cnt = 0;
unsigned temp; unsigned temp;
...@@ -592,13 +592,13 @@ static int msm_otg_resume(struct msm_otg *motg) ...@@ -592,13 +592,13 @@ static int msm_otg_resume(struct msm_otg *motg)
* PHY. USB state can not be restored. Re-insertion * PHY. USB state can not be restored. Re-insertion
* of USB cable is the only way to get USB working. * of USB cable is the only way to get USB working.
*/ */
dev_err(otg->dev, "Unable to resume USB." dev_err(phy->dev, "Unable to resume USB."
"Re-plugin the cable\n"); "Re-plugin the cable\n");
msm_otg_reset(otg); msm_otg_reset(phy);
} }
skip_phy_resume: skip_phy_resume:
if (device_may_wakeup(otg->dev)) if (device_may_wakeup(phy->dev))
disable_irq_wake(motg->irq); disable_irq_wake(motg->irq);
if (bus) if (bus)
set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags);
...@@ -607,11 +607,11 @@ static int msm_otg_resume(struct msm_otg *motg) ...@@ -607,11 +607,11 @@ static int msm_otg_resume(struct msm_otg *motg)
if (motg->async_int) { if (motg->async_int) {
motg->async_int = 0; motg->async_int = 0;
pm_runtime_put(otg->dev); pm_runtime_put(phy->dev);
enable_irq(motg->irq); enable_irq(motg->irq);
} }
dev_info(otg->dev, "USB exited from low power mode\n"); dev_info(phy->dev, "USB exited from low power mode\n");
return 0; return 0;
} }
...@@ -623,13 +623,13 @@ static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA) ...@@ -623,13 +623,13 @@ static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA)
return; return;
/* TODO: Notify PMIC about available current */ /* TODO: Notify PMIC about available current */
dev_info(motg->otg.dev, "Avail curr from USB = %u\n", mA); dev_info(motg->phy.dev, "Avail curr from USB = %u\n", mA);
motg->cur_power = mA; motg->cur_power = mA;
} }
static int msm_otg_set_power(struct usb_phy *otg, unsigned mA) static int msm_otg_set_power(struct usb_phy *phy, unsigned mA)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
/* /*
* Gadget driver uses set_power method to notify about the * Gadget driver uses set_power method to notify about the
...@@ -644,19 +644,19 @@ static int msm_otg_set_power(struct usb_phy *otg, unsigned mA) ...@@ -644,19 +644,19 @@ static int msm_otg_set_power(struct usb_phy *otg, unsigned mA)
return 0; return 0;
} }
static void msm_otg_start_host(struct usb_phy *otg, int on) static void msm_otg_start_host(struct usb_phy *phy, int on)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
struct msm_otg_platform_data *pdata = motg->pdata; struct msm_otg_platform_data *pdata = motg->pdata;
struct usb_hcd *hcd; struct usb_hcd *hcd;
if (!otg->host) if (!phy->otg->host)
return; return;
hcd = bus_to_hcd(otg->host); hcd = bus_to_hcd(phy->otg->host);
if (on) { if (on) {
dev_dbg(otg->dev, "host on\n"); dev_dbg(phy->dev, "host on\n");
if (pdata->vbus_power) if (pdata->vbus_power)
pdata->vbus_power(1); pdata->vbus_power(1);
...@@ -671,7 +671,7 @@ static void msm_otg_start_host(struct usb_phy *otg, int on) ...@@ -671,7 +671,7 @@ static void msm_otg_start_host(struct usb_phy *otg, int on)
usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
#endif #endif
} else { } else {
dev_dbg(otg->dev, "host off\n"); dev_dbg(phy->dev, "host off\n");
#ifdef CONFIG_USB #ifdef CONFIG_USB
usb_remove_hcd(hcd); usb_remove_hcd(hcd);
...@@ -683,9 +683,9 @@ static void msm_otg_start_host(struct usb_phy *otg, int on) ...@@ -683,9 +683,9 @@ static void msm_otg_start_host(struct usb_phy *otg, int on)
} }
} }
static int msm_otg_set_host(struct usb_phy *otg, struct usb_bus *host) static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy);
struct usb_hcd *hcd; struct usb_hcd *hcd;
/* /*
...@@ -693,16 +693,16 @@ static int msm_otg_set_host(struct usb_phy *otg, struct usb_bus *host) ...@@ -693,16 +693,16 @@ static int msm_otg_set_host(struct usb_phy *otg, struct usb_bus *host)
* only peripheral configuration. * only peripheral configuration.
*/ */
if (motg->pdata->mode == USB_PERIPHERAL) { if (motg->pdata->mode == USB_PERIPHERAL) {
dev_info(otg->dev, "Host mode is not supported\n"); dev_info(otg->phy->dev, "Host mode is not supported\n");
return -ENODEV; return -ENODEV;
} }
if (!host) { if (!host) {
if (otg->state == OTG_STATE_A_HOST) { if (otg->phy->state == OTG_STATE_A_HOST) {
pm_runtime_get_sync(otg->dev); pm_runtime_get_sync(otg->phy->dev);
msm_otg_start_host(otg, 0); msm_otg_start_host(otg->phy, 0);
otg->host = NULL; otg->host = NULL;
otg->state = OTG_STATE_UNDEFINED; otg->phy->state = OTG_STATE_UNDEFINED;
schedule_work(&motg->sm_work); schedule_work(&motg->sm_work);
} else { } else {
otg->host = NULL; otg->host = NULL;
...@@ -715,30 +715,30 @@ static int msm_otg_set_host(struct usb_phy *otg, struct usb_bus *host) ...@@ -715,30 +715,30 @@ static int msm_otg_set_host(struct usb_phy *otg, struct usb_bus *host)
hcd->power_budget = motg->pdata->power_budget; hcd->power_budget = motg->pdata->power_budget;
otg->host = host; otg->host = host;
dev_dbg(otg->dev, "host driver registered w/ tranceiver\n"); dev_dbg(otg->phy->dev, "host driver registered w/ tranceiver\n");
/* /*
* Kick the state machine work, if peripheral is not supported * Kick the state machine work, if peripheral is not supported
* or peripheral is already registered with us. * or peripheral is already registered with us.
*/ */
if (motg->pdata->mode == USB_HOST || otg->gadget) { if (motg->pdata->mode == USB_HOST || otg->gadget) {
pm_runtime_get_sync(otg->dev); pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work); schedule_work(&motg->sm_work);
} }
return 0; return 0;
} }
static void msm_otg_start_peripheral(struct usb_phy *otg, int on) static void msm_otg_start_peripheral(struct usb_phy *phy, int on)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
struct msm_otg_platform_data *pdata = motg->pdata; struct msm_otg_platform_data *pdata = motg->pdata;
if (!otg->gadget) if (!phy->otg->gadget)
return; return;
if (on) { if (on) {
dev_dbg(otg->dev, "gadget on\n"); dev_dbg(phy->dev, "gadget on\n");
/* /*
* Some boards have a switch cotrolled by gpio * Some boards have a switch cotrolled by gpio
* to enable/disable internal HUB. Disable internal * to enable/disable internal HUB. Disable internal
...@@ -746,36 +746,36 @@ static void msm_otg_start_peripheral(struct usb_phy *otg, int on) ...@@ -746,36 +746,36 @@ static void msm_otg_start_peripheral(struct usb_phy *otg, int on)
*/ */
if (pdata->setup_gpio) if (pdata->setup_gpio)
pdata->setup_gpio(OTG_STATE_B_PERIPHERAL); pdata->setup_gpio(OTG_STATE_B_PERIPHERAL);
usb_gadget_vbus_connect(otg->gadget); usb_gadget_vbus_connect(phy->otg->gadget);
} else { } else {
dev_dbg(otg->dev, "gadget off\n"); dev_dbg(phy->dev, "gadget off\n");
usb_gadget_vbus_disconnect(otg->gadget); usb_gadget_vbus_disconnect(phy->otg->gadget);
if (pdata->setup_gpio) if (pdata->setup_gpio)
pdata->setup_gpio(OTG_STATE_UNDEFINED); pdata->setup_gpio(OTG_STATE_UNDEFINED);
} }
} }
static int msm_otg_set_peripheral(struct usb_phy *otg, static int msm_otg_set_peripheral(struct usb_otg *otg,
struct usb_gadget *gadget) struct usb_gadget *gadget)
{ {
struct msm_otg *motg = container_of(otg, struct msm_otg, otg); struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy);
/* /*
* Fail peripheral registration if this board can support * Fail peripheral registration if this board can support
* only host configuration. * only host configuration.
*/ */
if (motg->pdata->mode == USB_HOST) { if (motg->pdata->mode == USB_HOST) {
dev_info(otg->dev, "Peripheral mode is not supported\n"); dev_info(otg->phy->dev, "Peripheral mode is not supported\n");
return -ENODEV; return -ENODEV;
} }
if (!gadget) { if (!gadget) {
if (otg->state == OTG_STATE_B_PERIPHERAL) { if (otg->phy->state == OTG_STATE_B_PERIPHERAL) {
pm_runtime_get_sync(otg->dev); pm_runtime_get_sync(otg->phy->dev);
msm_otg_start_peripheral(otg, 0); msm_otg_start_peripheral(otg->phy, 0);
otg->gadget = NULL; otg->gadget = NULL;
otg->state = OTG_STATE_UNDEFINED; otg->phy->state = OTG_STATE_UNDEFINED;
schedule_work(&motg->sm_work); schedule_work(&motg->sm_work);
} else { } else {
otg->gadget = NULL; otg->gadget = NULL;
...@@ -784,14 +784,14 @@ static int msm_otg_set_peripheral(struct usb_phy *otg, ...@@ -784,14 +784,14 @@ static int msm_otg_set_peripheral(struct usb_phy *otg,
return 0; return 0;
} }
otg->gadget = gadget; otg->gadget = gadget;
dev_dbg(otg->dev, "peripheral driver registered w/ tranceiver\n"); dev_dbg(otg->phy->dev, "peripheral driver registered w/ tranceiver\n");
/* /*
* Kick the state machine work, if host is not supported * Kick the state machine work, if host is not supported
* or host is already registered with us. * or host is already registered with us.
*/ */
if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { if (motg->pdata->mode == USB_PERIPHERAL || otg->host) {
pm_runtime_get_sync(otg->dev); pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work); schedule_work(&motg->sm_work);
} }
...@@ -800,17 +800,17 @@ static int msm_otg_set_peripheral(struct usb_phy *otg, ...@@ -800,17 +800,17 @@ static int msm_otg_set_peripheral(struct usb_phy *otg,
static bool msm_chg_check_secondary_det(struct msm_otg *motg) static bool msm_chg_check_secondary_det(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 chg_det; u32 chg_det;
bool ret = false; bool ret = false;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
ret = chg_det & (1 << 4); ret = chg_det & (1 << 4);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x87); chg_det = ulpi_read(phy, 0x87);
ret = chg_det & 1; ret = chg_det & 1;
break; break;
default: default:
...@@ -821,38 +821,38 @@ static bool msm_chg_check_secondary_det(struct msm_otg *motg) ...@@ -821,38 +821,38 @@ static bool msm_chg_check_secondary_det(struct msm_otg *motg)
static void msm_chg_enable_secondary_det(struct msm_otg *motg) static void msm_chg_enable_secondary_det(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 chg_det; u32 chg_det;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
/* Turn off charger block */ /* Turn off charger block */
chg_det |= ~(1 << 1); chg_det |= ~(1 << 1);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
udelay(20); udelay(20);
/* control chg block via ULPI */ /* control chg block via ULPI */
chg_det &= ~(1 << 3); chg_det &= ~(1 << 3);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
/* put it in host mode for enabling D- source */ /* put it in host mode for enabling D- source */
chg_det &= ~(1 << 2); chg_det &= ~(1 << 2);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
/* Turn on chg detect block */ /* Turn on chg detect block */
chg_det &= ~(1 << 1); chg_det &= ~(1 << 1);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
udelay(20); udelay(20);
/* enable chg detection */ /* enable chg detection */
chg_det &= ~(1 << 0); chg_det &= ~(1 << 0);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
/* /*
* Configure DM as current source, DP as current sink * Configure DM as current source, DP as current sink
* and enable battery charging comparators. * and enable battery charging comparators.
*/ */
ulpi_write(otg, 0x8, 0x85); ulpi_write(phy, 0x8, 0x85);
ulpi_write(otg, 0x2, 0x85); ulpi_write(phy, 0x2, 0x85);
ulpi_write(otg, 0x1, 0x85); ulpi_write(phy, 0x1, 0x85);
break; break;
default: default:
break; break;
...@@ -861,17 +861,17 @@ static void msm_chg_enable_secondary_det(struct msm_otg *motg) ...@@ -861,17 +861,17 @@ static void msm_chg_enable_secondary_det(struct msm_otg *motg)
static bool msm_chg_check_primary_det(struct msm_otg *motg) static bool msm_chg_check_primary_det(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 chg_det; u32 chg_det;
bool ret = false; bool ret = false;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
ret = chg_det & (1 << 4); ret = chg_det & (1 << 4);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x87); chg_det = ulpi_read(phy, 0x87);
ret = chg_det & 1; ret = chg_det & 1;
break; break;
default: default:
...@@ -882,23 +882,23 @@ static bool msm_chg_check_primary_det(struct msm_otg *motg) ...@@ -882,23 +882,23 @@ static bool msm_chg_check_primary_det(struct msm_otg *motg)
static void msm_chg_enable_primary_det(struct msm_otg *motg) static void msm_chg_enable_primary_det(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 chg_det; u32 chg_det;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
/* enable chg detection */ /* enable chg detection */
chg_det &= ~(1 << 0); chg_det &= ~(1 << 0);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
/* /*
* Configure DP as current source, DM as current sink * Configure DP as current source, DM as current sink
* and enable battery charging comparators. * and enable battery charging comparators.
*/ */
ulpi_write(otg, 0x2, 0x85); ulpi_write(phy, 0x2, 0x85);
ulpi_write(otg, 0x1, 0x85); ulpi_write(phy, 0x1, 0x85);
break; break;
default: default:
break; break;
...@@ -907,17 +907,17 @@ static void msm_chg_enable_primary_det(struct msm_otg *motg) ...@@ -907,17 +907,17 @@ static void msm_chg_enable_primary_det(struct msm_otg *motg)
static bool msm_chg_check_dcd(struct msm_otg *motg) static bool msm_chg_check_dcd(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 line_state; u32 line_state;
bool ret = false; bool ret = false;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
line_state = ulpi_read(otg, 0x15); line_state = ulpi_read(phy, 0x15);
ret = !(line_state & 1); ret = !(line_state & 1);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
line_state = ulpi_read(otg, 0x87); line_state = ulpi_read(phy, 0x87);
ret = line_state & 2; ret = line_state & 2;
break; break;
default: default:
...@@ -928,17 +928,17 @@ static bool msm_chg_check_dcd(struct msm_otg *motg) ...@@ -928,17 +928,17 @@ static bool msm_chg_check_dcd(struct msm_otg *motg)
static void msm_chg_disable_dcd(struct msm_otg *motg) static void msm_chg_disable_dcd(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 chg_det; u32 chg_det;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
chg_det &= ~(1 << 5); chg_det &= ~(1 << 5);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
ulpi_write(otg, 0x10, 0x86); ulpi_write(phy, 0x10, 0x86);
break; break;
default: default:
break; break;
...@@ -947,19 +947,19 @@ static void msm_chg_disable_dcd(struct msm_otg *motg) ...@@ -947,19 +947,19 @@ static void msm_chg_disable_dcd(struct msm_otg *motg)
static void msm_chg_enable_dcd(struct msm_otg *motg) static void msm_chg_enable_dcd(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 chg_det; u32 chg_det;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
/* Turn on D+ current source */ /* Turn on D+ current source */
chg_det |= (1 << 5); chg_det |= (1 << 5);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
/* Data contact detection enable */ /* Data contact detection enable */
ulpi_write(otg, 0x10, 0x85); ulpi_write(phy, 0x10, 0x85);
break; break;
default: default:
break; break;
...@@ -968,32 +968,32 @@ static void msm_chg_enable_dcd(struct msm_otg *motg) ...@@ -968,32 +968,32 @@ static void msm_chg_enable_dcd(struct msm_otg *motg)
static void msm_chg_block_on(struct msm_otg *motg) static void msm_chg_block_on(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 func_ctrl, chg_det; u32 func_ctrl, chg_det;
/* put the controller in non-driving mode */ /* put the controller in non-driving mode */
func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL); func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL);
func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL); ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL);
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
/* control chg block via ULPI */ /* control chg block via ULPI */
chg_det &= ~(1 << 3); chg_det &= ~(1 << 3);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
/* Turn on chg detect block */ /* Turn on chg detect block */
chg_det &= ~(1 << 1); chg_det &= ~(1 << 1);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
udelay(20); udelay(20);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
/* Clear charger detecting control bits */ /* Clear charger detecting control bits */
ulpi_write(otg, 0x3F, 0x86); ulpi_write(phy, 0x3F, 0x86);
/* Clear alt interrupt latch and enable bits */ /* Clear alt interrupt latch and enable bits */
ulpi_write(otg, 0x1F, 0x92); ulpi_write(phy, 0x1F, 0x92);
ulpi_write(otg, 0x1F, 0x95); ulpi_write(phy, 0x1F, 0x95);
udelay(100); udelay(100);
break; break;
default: default:
...@@ -1003,32 +1003,32 @@ static void msm_chg_block_on(struct msm_otg *motg) ...@@ -1003,32 +1003,32 @@ static void msm_chg_block_on(struct msm_otg *motg)
static void msm_chg_block_off(struct msm_otg *motg) static void msm_chg_block_off(struct msm_otg *motg)
{ {
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 func_ctrl, chg_det; u32 func_ctrl, chg_det;
switch (motg->pdata->phy_type) { switch (motg->pdata->phy_type) {
case CI_45NM_INTEGRATED_PHY: case CI_45NM_INTEGRATED_PHY:
chg_det = ulpi_read(otg, 0x34); chg_det = ulpi_read(phy, 0x34);
/* Turn off charger block */ /* Turn off charger block */
chg_det |= ~(1 << 1); chg_det |= ~(1 << 1);
ulpi_write(otg, chg_det, 0x34); ulpi_write(phy, chg_det, 0x34);
break; break;
case SNPS_28NM_INTEGRATED_PHY: case SNPS_28NM_INTEGRATED_PHY:
/* Clear charger detecting control bits */ /* Clear charger detecting control bits */
ulpi_write(otg, 0x3F, 0x86); ulpi_write(phy, 0x3F, 0x86);
/* Clear alt interrupt latch and enable bits */ /* Clear alt interrupt latch and enable bits */
ulpi_write(otg, 0x1F, 0x92); ulpi_write(phy, 0x1F, 0x92);
ulpi_write(otg, 0x1F, 0x95); ulpi_write(phy, 0x1F, 0x95);
break; break;
default: default:
break; break;
} }
/* put the controller in normal mode */ /* put the controller in normal mode */
func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL); func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL);
func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL; func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL); ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL);
} }
#define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */ #define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */
...@@ -1038,14 +1038,14 @@ static void msm_chg_block_off(struct msm_otg *motg) ...@@ -1038,14 +1038,14 @@ static void msm_chg_block_off(struct msm_otg *motg)
static void msm_chg_detect_work(struct work_struct *w) static void msm_chg_detect_work(struct work_struct *w)
{ {
struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work); struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work);
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
bool is_dcd, tmout, vout; bool is_dcd, tmout, vout;
unsigned long delay; unsigned long delay;
dev_dbg(otg->dev, "chg detection work\n"); dev_dbg(phy->dev, "chg detection work\n");
switch (motg->chg_state) { switch (motg->chg_state) {
case USB_CHG_STATE_UNDEFINED: case USB_CHG_STATE_UNDEFINED:
pm_runtime_get_sync(otg->dev); pm_runtime_get_sync(phy->dev);
msm_chg_block_on(motg); msm_chg_block_on(motg);
msm_chg_enable_dcd(motg); msm_chg_enable_dcd(motg);
motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD;
...@@ -1088,7 +1088,7 @@ static void msm_chg_detect_work(struct work_struct *w) ...@@ -1088,7 +1088,7 @@ static void msm_chg_detect_work(struct work_struct *w)
motg->chg_state = USB_CHG_STATE_DETECTED; motg->chg_state = USB_CHG_STATE_DETECTED;
case USB_CHG_STATE_DETECTED: case USB_CHG_STATE_DETECTED:
msm_chg_block_off(motg); msm_chg_block_off(motg);
dev_dbg(otg->dev, "charger = %d\n", motg->chg_type); dev_dbg(phy->dev, "charger = %d\n", motg->chg_type);
schedule_work(&motg->sm_work); schedule_work(&motg->sm_work);
return; return;
default: default:
...@@ -1152,22 +1152,22 @@ static void msm_otg_init_sm(struct msm_otg *motg) ...@@ -1152,22 +1152,22 @@ static void msm_otg_init_sm(struct msm_otg *motg)
static void msm_otg_sm_work(struct work_struct *w) static void msm_otg_sm_work(struct work_struct *w)
{ {
struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); struct msm_otg *motg = container_of(w, struct msm_otg, sm_work);
struct usb_phy *otg = &motg->otg; struct usb_otg *otg = motg->phy.otg;
switch (otg->state) { switch (otg->phy->state) {
case OTG_STATE_UNDEFINED: case OTG_STATE_UNDEFINED:
dev_dbg(otg->dev, "OTG_STATE_UNDEFINED state\n"); dev_dbg(otg->phy->dev, "OTG_STATE_UNDEFINED state\n");
msm_otg_reset(otg); msm_otg_reset(otg->phy);
msm_otg_init_sm(motg); msm_otg_init_sm(motg);
otg->state = OTG_STATE_B_IDLE; otg->phy->state = OTG_STATE_B_IDLE;
/* FALL THROUGH */ /* FALL THROUGH */
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
dev_dbg(otg->dev, "OTG_STATE_B_IDLE state\n"); dev_dbg(otg->phy->dev, "OTG_STATE_B_IDLE state\n");
if (!test_bit(ID, &motg->inputs) && otg->host) { if (!test_bit(ID, &motg->inputs) && otg->host) {
/* disable BSV bit */ /* disable BSV bit */
writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC); writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC);
msm_otg_start_host(otg, 1); msm_otg_start_host(otg->phy, 1);
otg->state = OTG_STATE_A_HOST; otg->phy->state = OTG_STATE_A_HOST;
} else if (test_bit(B_SESS_VLD, &motg->inputs)) { } else if (test_bit(B_SESS_VLD, &motg->inputs)) {
switch (motg->chg_state) { switch (motg->chg_state) {
case USB_CHG_STATE_UNDEFINED: case USB_CHG_STATE_UNDEFINED:
...@@ -1182,13 +1182,15 @@ static void msm_otg_sm_work(struct work_struct *w) ...@@ -1182,13 +1182,15 @@ static void msm_otg_sm_work(struct work_struct *w)
case USB_CDP_CHARGER: case USB_CDP_CHARGER:
msm_otg_notify_charger(motg, msm_otg_notify_charger(motg,
IDEV_CHG_MAX); IDEV_CHG_MAX);
msm_otg_start_peripheral(otg, 1); msm_otg_start_peripheral(otg->phy, 1);
otg->state = OTG_STATE_B_PERIPHERAL; otg->phy->state
= OTG_STATE_B_PERIPHERAL;
break; break;
case USB_SDP_CHARGER: case USB_SDP_CHARGER:
msm_otg_notify_charger(motg, IUNIT); msm_otg_notify_charger(motg, IUNIT);
msm_otg_start_peripheral(otg, 1); msm_otg_start_peripheral(otg->phy, 1);
otg->state = OTG_STATE_B_PERIPHERAL; otg->phy->state
= OTG_STATE_B_PERIPHERAL;
break; break;
default: default:
break; break;
...@@ -1204,34 +1206,34 @@ static void msm_otg_sm_work(struct work_struct *w) ...@@ -1204,34 +1206,34 @@ static void msm_otg_sm_work(struct work_struct *w)
* is incremented in charger detection work. * is incremented in charger detection work.
*/ */
if (cancel_delayed_work_sync(&motg->chg_work)) { if (cancel_delayed_work_sync(&motg->chg_work)) {
pm_runtime_put_sync(otg->dev); pm_runtime_put_sync(otg->phy->dev);
msm_otg_reset(otg); msm_otg_reset(otg->phy);
} }
msm_otg_notify_charger(motg, 0); msm_otg_notify_charger(motg, 0);
motg->chg_state = USB_CHG_STATE_UNDEFINED; motg->chg_state = USB_CHG_STATE_UNDEFINED;
motg->chg_type = USB_INVALID_CHARGER; motg->chg_type = USB_INVALID_CHARGER;
} }
pm_runtime_put_sync(otg->dev); pm_runtime_put_sync(otg->phy->dev);
break; break;
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
dev_dbg(otg->dev, "OTG_STATE_B_PERIPHERAL state\n"); dev_dbg(otg->phy->dev, "OTG_STATE_B_PERIPHERAL state\n");
if (!test_bit(B_SESS_VLD, &motg->inputs) || if (!test_bit(B_SESS_VLD, &motg->inputs) ||
!test_bit(ID, &motg->inputs)) { !test_bit(ID, &motg->inputs)) {
msm_otg_notify_charger(motg, 0); msm_otg_notify_charger(motg, 0);
msm_otg_start_peripheral(otg, 0); msm_otg_start_peripheral(otg->phy, 0);
motg->chg_state = USB_CHG_STATE_UNDEFINED; motg->chg_state = USB_CHG_STATE_UNDEFINED;
motg->chg_type = USB_INVALID_CHARGER; motg->chg_type = USB_INVALID_CHARGER;
otg->state = OTG_STATE_B_IDLE; otg->phy->state = OTG_STATE_B_IDLE;
msm_otg_reset(otg); msm_otg_reset(otg->phy);
schedule_work(w); schedule_work(w);
} }
break; break;
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
dev_dbg(otg->dev, "OTG_STATE_A_HOST state\n"); dev_dbg(otg->phy->dev, "OTG_STATE_A_HOST state\n");
if (test_bit(ID, &motg->inputs)) { if (test_bit(ID, &motg->inputs)) {
msm_otg_start_host(otg, 0); msm_otg_start_host(otg->phy, 0);
otg->state = OTG_STATE_B_IDLE; otg->phy->state = OTG_STATE_B_IDLE;
msm_otg_reset(otg); msm_otg_reset(otg->phy);
schedule_work(w); schedule_work(w);
} }
break; break;
...@@ -1243,13 +1245,13 @@ static void msm_otg_sm_work(struct work_struct *w) ...@@ -1243,13 +1245,13 @@ static void msm_otg_sm_work(struct work_struct *w)
static irqreturn_t msm_otg_irq(int irq, void *data) static irqreturn_t msm_otg_irq(int irq, void *data)
{ {
struct msm_otg *motg = data; struct msm_otg *motg = data;
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
u32 otgsc = 0; u32 otgsc = 0;
if (atomic_read(&motg->in_lpm)) { if (atomic_read(&motg->in_lpm)) {
disable_irq_nosync(irq); disable_irq_nosync(irq);
motg->async_int = 1; motg->async_int = 1;
pm_runtime_get(otg->dev); pm_runtime_get(phy->dev);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -1262,15 +1264,15 @@ static irqreturn_t msm_otg_irq(int irq, void *data) ...@@ -1262,15 +1264,15 @@ static irqreturn_t msm_otg_irq(int irq, void *data)
set_bit(ID, &motg->inputs); set_bit(ID, &motg->inputs);
else else
clear_bit(ID, &motg->inputs); clear_bit(ID, &motg->inputs);
dev_dbg(otg->dev, "ID set/clear\n"); dev_dbg(phy->dev, "ID set/clear\n");
pm_runtime_get_noresume(otg->dev); pm_runtime_get_noresume(phy->dev);
} else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) { } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) {
if (otgsc & OTGSC_BSV) if (otgsc & OTGSC_BSV)
set_bit(B_SESS_VLD, &motg->inputs); set_bit(B_SESS_VLD, &motg->inputs);
else else
clear_bit(B_SESS_VLD, &motg->inputs); clear_bit(B_SESS_VLD, &motg->inputs);
dev_dbg(otg->dev, "BSV set/clear\n"); dev_dbg(phy->dev, "BSV set/clear\n");
pm_runtime_get_noresume(otg->dev); pm_runtime_get_noresume(phy->dev);
} }
writel(otgsc, USB_OTGSC); writel(otgsc, USB_OTGSC);
...@@ -1281,9 +1283,9 @@ static irqreturn_t msm_otg_irq(int irq, void *data) ...@@ -1281,9 +1283,9 @@ static irqreturn_t msm_otg_irq(int irq, void *data)
static int msm_otg_mode_show(struct seq_file *s, void *unused) static int msm_otg_mode_show(struct seq_file *s, void *unused)
{ {
struct msm_otg *motg = s->private; struct msm_otg *motg = s->private;
struct usb_phy *otg = &motg->otg; struct usb_otg *otg = motg->phy.otg;
switch (otg->state) { switch (otg->phy->state) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
seq_printf(s, "host\n"); seq_printf(s, "host\n");
break; break;
...@@ -1309,7 +1311,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, ...@@ -1309,7 +1311,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
struct seq_file *s = file->private_data; struct seq_file *s = file->private_data;
struct msm_otg *motg = s->private; struct msm_otg *motg = s->private;
char buf[16]; char buf[16];
struct usb_phy *otg = &motg->otg; struct usb_otg *otg = motg->phy.otg;
int status = count; int status = count;
enum usb_mode_type req_mode; enum usb_mode_type req_mode;
...@@ -1333,7 +1335,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, ...@@ -1333,7 +1335,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
switch (req_mode) { switch (req_mode) {
case USB_NONE: case USB_NONE:
switch (otg->state) { switch (otg->phy->state) {
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
set_bit(ID, &motg->inputs); set_bit(ID, &motg->inputs);
...@@ -1344,7 +1346,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, ...@@ -1344,7 +1346,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
} }
break; break;
case USB_PERIPHERAL: case USB_PERIPHERAL:
switch (otg->state) { switch (otg->phy->state) {
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
case OTG_STATE_A_HOST: case OTG_STATE_A_HOST:
set_bit(ID, &motg->inputs); set_bit(ID, &motg->inputs);
...@@ -1355,7 +1357,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, ...@@ -1355,7 +1357,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
} }
break; break;
case USB_HOST: case USB_HOST:
switch (otg->state) { switch (otg->phy->state) {
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
clear_bit(ID, &motg->inputs); clear_bit(ID, &motg->inputs);
...@@ -1368,7 +1370,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, ...@@ -1368,7 +1370,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf,
goto out; goto out;
} }
pm_runtime_get_sync(otg->dev); pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work); schedule_work(&motg->sm_work);
out: out:
return status; return status;
...@@ -1414,7 +1416,7 @@ static int __init msm_otg_probe(struct platform_device *pdev) ...@@ -1414,7 +1416,7 @@ static int __init msm_otg_probe(struct platform_device *pdev)
int ret = 0; int ret = 0;
struct resource *res; struct resource *res;
struct msm_otg *motg; struct msm_otg *motg;
struct usb_phy *otg; struct usb_phy *phy;
dev_info(&pdev->dev, "msm_otg probe\n"); dev_info(&pdev->dev, "msm_otg probe\n");
if (!pdev->dev.platform_data) { if (!pdev->dev.platform_data) {
...@@ -1428,9 +1430,15 @@ static int __init msm_otg_probe(struct platform_device *pdev) ...@@ -1428,9 +1430,15 @@ static int __init msm_otg_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
} }
motg->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL);
if (!motg->phy.otg) {
dev_err(&pdev->dev, "unable to allocate msm_otg\n");
return -ENOMEM;
}
motg->pdata = pdev->dev.platform_data; motg->pdata = pdev->dev.platform_data;
otg = &motg->otg; phy = &motg->phy;
otg->dev = &pdev->dev; phy->dev = &pdev->dev;
motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk"); motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk");
if (IS_ERR(motg->phy_reset_clk)) { if (IS_ERR(motg->phy_reset_clk)) {
...@@ -1538,16 +1546,18 @@ static int __init msm_otg_probe(struct platform_device *pdev) ...@@ -1538,16 +1546,18 @@ static int __init msm_otg_probe(struct platform_device *pdev)
goto disable_clks; goto disable_clks;
} }
otg->init = msm_otg_reset; phy->init = msm_otg_reset;
otg->set_host = msm_otg_set_host; phy->set_power = msm_otg_set_power;
otg->set_peripheral = msm_otg_set_peripheral;
otg->set_power = msm_otg_set_power; phy->io_ops = &msm_otg_io_ops;
otg->io_ops = &msm_otg_io_ops; phy->otg->phy = &motg->phy;
phy->otg->set_host = msm_otg_set_host;
phy->otg->set_peripheral = msm_otg_set_peripheral;
ret = otg_set_transceiver(&motg->otg); ret = usb_set_transceiver(&motg->phy);
if (ret) { if (ret) {
dev_err(&pdev->dev, "otg_set_transceiver failed\n"); dev_err(&pdev->dev, "usb_set_transceiver failed\n");
goto free_irq; goto free_irq;
} }
...@@ -1591,6 +1601,7 @@ static int __init msm_otg_probe(struct platform_device *pdev) ...@@ -1591,6 +1601,7 @@ static int __init msm_otg_probe(struct platform_device *pdev)
put_phy_reset_clk: put_phy_reset_clk:
clk_put(motg->phy_reset_clk); clk_put(motg->phy_reset_clk);
free_motg: free_motg:
kfree(motg->phy.otg);
kfree(motg); kfree(motg);
return ret; return ret;
} }
...@@ -1598,10 +1609,10 @@ static int __init msm_otg_probe(struct platform_device *pdev) ...@@ -1598,10 +1609,10 @@ static int __init msm_otg_probe(struct platform_device *pdev)
static int __devexit msm_otg_remove(struct platform_device *pdev) static int __devexit msm_otg_remove(struct platform_device *pdev)
{ {
struct msm_otg *motg = platform_get_drvdata(pdev); struct msm_otg *motg = platform_get_drvdata(pdev);
struct usb_phy *otg = &motg->otg; struct usb_phy *phy = &motg->phy;
int cnt = 0; int cnt = 0;
if (otg->host || otg->gadget) if (phy->otg->host || phy->otg->gadget)
return -EBUSY; return -EBUSY;
msm_otg_debugfs_cleanup(); msm_otg_debugfs_cleanup();
...@@ -1613,14 +1624,14 @@ static int __devexit msm_otg_remove(struct platform_device *pdev) ...@@ -1613,14 +1624,14 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 0); device_init_wakeup(&pdev->dev, 0);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
otg_set_transceiver(NULL); usb_set_transceiver(NULL);
free_irq(motg->irq, motg); free_irq(motg->irq, motg);
/* /*
* Put PHY in low power mode. * Put PHY in low power mode.
*/ */
ulpi_read(otg, 0x14); ulpi_read(phy, 0x14);
ulpi_write(otg, 0x08, 0x09); ulpi_write(phy, 0x08, 0x09);
writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC);
while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
...@@ -1630,7 +1641,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev) ...@@ -1630,7 +1641,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
cnt++; cnt++;
} }
if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) if (cnt >= PHY_SUSPEND_TIMEOUT_USEC)
dev_err(otg->dev, "Unable to suspend PHY\n"); dev_err(phy->dev, "Unable to suspend PHY\n");
clk_disable(motg->pclk); clk_disable(motg->pclk);
clk_disable(motg->clk); clk_disable(motg->clk);
...@@ -1651,6 +1662,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev) ...@@ -1651,6 +1662,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
if (motg->core_clk) if (motg->core_clk)
clk_put(motg->core_clk); clk_put(motg->core_clk);
kfree(motg->phy.otg);
kfree(motg); kfree(motg);
return 0; return 0;
...@@ -1660,7 +1672,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev) ...@@ -1660,7 +1672,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev)
static int msm_otg_runtime_idle(struct device *dev) static int msm_otg_runtime_idle(struct device *dev)
{ {
struct msm_otg *motg = dev_get_drvdata(dev); struct msm_otg *motg = dev_get_drvdata(dev);
struct usb_phy *otg = &motg->otg; struct usb_otg *otg = motg->phy.otg;
dev_dbg(dev, "OTG runtime idle\n"); dev_dbg(dev, "OTG runtime idle\n");
...@@ -1670,7 +1682,7 @@ static int msm_otg_runtime_idle(struct device *dev) ...@@ -1670,7 +1682,7 @@ static int msm_otg_runtime_idle(struct device *dev)
* This 1 sec delay also prevents entering into LPM immediately * This 1 sec delay also prevents entering into LPM immediately
* after asynchronous interrupt. * after asynchronous interrupt.
*/ */
if (otg->state != OTG_STATE_UNDEFINED) if (otg->phy->state != OTG_STATE_UNDEFINED)
pm_schedule_suspend(dev, 1000); pm_schedule_suspend(dev, 1000);
return -EAGAIN; return -EAGAIN;
......
...@@ -160,7 +160,7 @@ struct msm_otg_platform_data { ...@@ -160,7 +160,7 @@ struct msm_otg_platform_data {
* detection process. * detection process.
*/ */
struct msm_otg { struct msm_otg {
struct usb_phy otg; struct usb_phy phy;
struct msm_otg_platform_data *pdata; struct msm_otg_platform_data *pdata;
int irq; int irq;
struct clk *clk; struct clk *clk;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment