]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/usb/phy/phy-isp1301-omap.c
usb: move the OTG state from the USB PHY to the OTG structure
[karo-tx-linux.git] / drivers / usb / phy / phy-isp1301-omap.c
index 8eea56d3ded6deff1f361ed5fd3ac78208eb42d2..24f84cbbed574bbb286ce03b0ead222d383f44ad 100644 (file)
@@ -234,7 +234,7 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
 
 static inline const char *state_name(struct isp1301 *isp)
 {
-       return usb_otg_state_string(isp->phy.state);
+       return usb_otg_state_string(isp->phy.otg->state);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -249,7 +249,7 @@ static inline const char *state_name(struct isp1301 *isp)
 
 static void power_down(struct isp1301 *isp)
 {
-       isp->phy.state = OTG_STATE_UNDEFINED;
+       isp->phy.otg->state = OTG_STATE_UNDEFINED;
 
        // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
        isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
@@ -339,7 +339,7 @@ static void a_idle(struct isp1301 *isp, const char *tag)
 {
        u32 l;
 
-       if (isp->phy.state == OTG_STATE_A_IDLE)
+       if (isp->phy.otg->state == OTG_STATE_A_IDLE)
                return;
 
        isp->phy.otg->default_a = 1;
@@ -351,7 +351,7 @@ static void a_idle(struct isp1301 *isp, const char *tag)
                isp->phy.otg->gadget->is_a_peripheral = 1;
                gadget_suspend(isp);
        }
-       isp->phy.state = OTG_STATE_A_IDLE;
+       isp->phy.otg->state = OTG_STATE_A_IDLE;
        l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
        omap_writel(l, OTG_CTRL);
        isp->last_otg_ctrl = l;
@@ -363,7 +363,7 @@ static void b_idle(struct isp1301 *isp, const char *tag)
 {
        u32 l;
 
-       if (isp->phy.state == OTG_STATE_B_IDLE)
+       if (isp->phy.otg->state == OTG_STATE_B_IDLE)
                return;
 
        isp->phy.otg->default_a = 0;
@@ -375,7 +375,7 @@ static void b_idle(struct isp1301 *isp, const char *tag)
                isp->phy.otg->gadget->is_a_peripheral = 0;
                gadget_suspend(isp);
        }
-       isp->phy.state = OTG_STATE_B_IDLE;
+       isp->phy.otg->state = OTG_STATE_B_IDLE;
        l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
        omap_writel(l, OTG_CTRL);
        isp->last_otg_ctrl = l;
@@ -474,7 +474,7 @@ static void check_state(struct isp1301 *isp, const char *tag)
        default:
                break;
        }
-       if (isp->phy.state == state && !extra)
+       if (isp->phy.otg->state == state && !extra)
                return;
        pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
                usb_otg_state_string(state), fsm, state_name(isp),
@@ -498,23 +498,23 @@ static void update_otg1(struct isp1301 *isp, u8 int_src)
 
        if (int_src & INTR_SESS_VLD)
                otg_ctrl |= OTG_ASESSVLD;
-       else if (isp->phy.state == OTG_STATE_A_WAIT_VFALL) {
+       else if (isp->phy.otg->state == OTG_STATE_A_WAIT_VFALL) {
                a_idle(isp, "vfall");
                otg_ctrl &= ~OTG_CTRL_BITS;
        }
        if (int_src & INTR_VBUS_VLD)
                otg_ctrl |= OTG_VBUSVLD;
        if (int_src & INTR_ID_GND) {            /* default-A */
-               if (isp->phy.state == OTG_STATE_B_IDLE
-                               || isp->phy.state
+               if (isp->phy.otg->state == OTG_STATE_B_IDLE
+                               || isp->phy.otg->state
                                        == OTG_STATE_UNDEFINED) {
                        a_idle(isp, "init");
                        return;
                }
        } else {                                /* default-B */
                otg_ctrl |= OTG_ID;
-               if (isp->phy.state == OTG_STATE_A_IDLE
-                       || isp->phy.state == OTG_STATE_UNDEFINED) {
+               if (isp->phy.otg->state == OTG_STATE_A_IDLE
+                       || isp->phy.otg->state == OTG_STATE_UNDEFINED) {
                        b_idle(isp, "init");
                        return;
                }
@@ -548,14 +548,14 @@ static void otg_update_isp(struct isp1301 *isp)
        isp->last_otg_ctrl = otg_ctrl;
        otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
 
-       switch (isp->phy.state) {
+       switch (isp->phy.otg->state) {
        case OTG_STATE_B_IDLE:
        case OTG_STATE_B_PERIPHERAL:
        case OTG_STATE_B_SRP_INIT:
                if (!(otg_ctrl & OTG_PULLUP)) {
                        // if (otg_ctrl & OTG_B_HNPEN) {
                        if (isp->phy.otg->gadget->b_hnp_enable) {
-                               isp->phy.state = OTG_STATE_B_WAIT_ACON;
+                               isp->phy.otg->state = OTG_STATE_B_WAIT_ACON;
                                pr_debug("  --> b_wait_acon\n");
                        }
                        goto pulldown;
@@ -585,7 +585,7 @@ pulldown:
        if (!(isp->phy.otg->host))
                otg_ctrl &= ~OTG_DRV_VBUS;
 
-       switch (isp->phy.state) {
+       switch (isp->phy.otg->state) {
        case OTG_STATE_A_SUSPEND:
                if (otg_ctrl & OTG_DRV_VBUS) {
                        set |= OTG1_VBUS_DRV;
@@ -596,7 +596,7 @@ pulldown:
 
                /* FALLTHROUGH */
        case OTG_STATE_A_VBUS_ERR:
-               isp->phy.state = OTG_STATE_A_WAIT_VFALL;
+               isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL;
                pr_debug("  --> a_wait_vfall\n");
                /* FALLTHROUGH */
        case OTG_STATE_A_WAIT_VFALL:
@@ -605,7 +605,7 @@ pulldown:
                break;
        case OTG_STATE_A_IDLE:
                if (otg_ctrl & OTG_DRV_VBUS) {
-                       isp->phy.state = OTG_STATE_A_WAIT_VRISE;
+                       isp->phy.otg->state = OTG_STATE_A_WAIT_VRISE;
                        pr_debug("  --> a_wait_vrise\n");
                }
                /* FALLTHROUGH */
@@ -625,17 +625,17 @@ pulldown:
        if (otg_change & OTG_PULLUP) {
                u32 l;
 
-               switch (isp->phy.state) {
+               switch (isp->phy.otg->state) {
                case OTG_STATE_B_IDLE:
                        if (clr & OTG1_DP_PULLUP)
                                break;
-                       isp->phy.state = OTG_STATE_B_PERIPHERAL;
+                       isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
                        pr_debug("  --> b_peripheral\n");
                        break;
                case OTG_STATE_A_SUSPEND:
                        if (clr & OTG1_DP_PULLUP)
                                break;
-                       isp->phy.state = OTG_STATE_A_PERIPHERAL;
+                       isp->phy.otg->state = OTG_STATE_A_PERIPHERAL;
                        pr_debug("  --> a_peripheral\n");
                        break;
                default:
@@ -673,7 +673,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                 * remote wakeup (SRP, normal) using their own timer
                 * to give "check cable and A-device" messages.
                 */
-               if (isp->phy.state == OTG_STATE_B_SRP_INIT)
+               if (isp->phy.otg->state == OTG_STATE_B_SRP_INIT)
                        b_idle(isp, "srp_timeout");
 
                omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
@@ -691,7 +691,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                omap_writel(otg_ctrl, OTG_CTRL);
 
                /* subset of b_peripheral()... */
-               isp->phy.state = OTG_STATE_B_PERIPHERAL;
+               isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
                pr_debug("  --> b_peripheral\n");
 
                omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
@@ -703,7 +703,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                                state_name(isp), omap_readl(OTG_CTRL));
 
                isp1301_defer_work(isp, WORK_UPDATE_OTG);
-               switch (isp->phy.state) {
+               switch (isp->phy.otg->state) {
                case OTG_STATE_A_IDLE:
                        if (!otg->host)
                                break;
@@ -734,7 +734,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                otg_ctrl |= OTG_BUSDROP;
                otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
                omap_writel(otg_ctrl, OTG_CTRL);
-               isp->phy.state = OTG_STATE_A_WAIT_VFALL;
+               isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL;
 
                omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
@@ -748,7 +748,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                otg_ctrl |= OTG_BUSDROP;
                otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
                omap_writel(otg_ctrl, OTG_CTRL);
-               isp->phy.state = OTG_STATE_A_VBUS_ERR;
+               isp->phy.otg->state = OTG_STATE_A_VBUS_ERR;
 
                omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
                ret = IRQ_HANDLED;
@@ -769,7 +769,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
 
                /* role is peripheral */
                if (otg_ctrl & OTG_DRIVER_SEL) {
-                       switch (isp->phy.state) {
+                       switch (isp->phy.otg->state) {
                        case OTG_STATE_A_IDLE:
                                b_idle(isp, __func__);
                                break;
@@ -786,18 +786,18 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
                        }
 
                        if (otg->host) {
-                               switch (isp->phy.state) {
+                               switch (isp->phy.otg->state) {
                                case OTG_STATE_B_WAIT_ACON:
-                                       isp->phy.state = OTG_STATE_B_HOST;
+                                       isp->phy.otg->state = OTG_STATE_B_HOST;
                                        pr_debug("  --> b_host\n");
                                        kick = 1;
                                        break;
                                case OTG_STATE_A_WAIT_BCON:
-                                       isp->phy.state = OTG_STATE_A_HOST;
+                                       isp->phy.otg->state = OTG_STATE_A_HOST;
                                        pr_debug("  --> a_host\n");
                                        break;
                                case OTG_STATE_A_PERIPHERAL:
-                                       isp->phy.state = OTG_STATE_A_WAIT_BCON;
+                                       isp->phy.otg->state = OTG_STATE_A_WAIT_BCON;
                                        pr_debug("  --> a_wait_bcon\n");
                                        break;
                                default:
@@ -937,7 +937,7 @@ static void b_peripheral(struct isp1301 *isp)
        /* UDC driver just set OTG_BSESSVLD */
        isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
        isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
-       isp->phy.state = OTG_STATE_B_PERIPHERAL;
+       isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
        pr_debug("  --> b_peripheral\n");
        dump_regs(isp, "2periph");
 #endif
@@ -947,7 +947,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
 {
        struct usb_otg          *otg = isp->phy.otg;
        u8                      isp_stat, isp_bstat;
-       enum usb_otg_state      state = isp->phy.state;
+       enum usb_otg_state      state = isp->phy.otg->state;
 
        if (stat & INTR_BDIS_ACON)
                pr_debug("OTG:  BDIS_ACON, %s\n", state_name(isp));
@@ -970,7 +970,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                                 * when HNP is used.
                                 */
                                if (isp_stat & INTR_VBUS_VLD)
-                                       isp->phy.state = OTG_STATE_A_HOST;
+                                       isp->phy.otg->state = OTG_STATE_A_HOST;
                                break;
                        case OTG_STATE_A_WAIT_VFALL:
                                if (!(isp_stat & INTR_SESS_VLD))
@@ -978,7 +978,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                                break;
                        default:
                                if (!(isp_stat & INTR_VBUS_VLD))
-                                       isp->phy.state = OTG_STATE_A_VBUS_ERR;
+                                       isp->phy.otg->state = OTG_STATE_A_VBUS_ERR;
                                break;
                        }
                        isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
@@ -1007,7 +1007,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                if (otg->default_a) {
                        switch (state) {
                        default:
-                               isp->phy.state = OTG_STATE_A_WAIT_VFALL;
+                               isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL;
                                break;
                        case OTG_STATE_A_WAIT_VFALL:
                                state = OTG_STATE_A_IDLE;
@@ -1020,7 +1020,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                                host_suspend(isp);
                                isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
                                                MC1_BDIS_ACON_EN);
-                               isp->phy.state = OTG_STATE_B_IDLE;
+                               isp->phy.otg->state = OTG_STATE_B_IDLE;
                                l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
                                l &= ~OTG_CTRL_BITS;
                                omap_writel(l, OTG_CTRL);
@@ -1031,7 +1031,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                }
                isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
 
-               switch (isp->phy.state) {
+               switch (isp->phy.otg->state) {
                case OTG_STATE_B_PERIPHERAL:
                case OTG_STATE_B_WAIT_ACON:
                case OTG_STATE_B_HOST:
@@ -1071,7 +1071,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
                }
        }
 
-       if (state != isp->phy.state)
+       if (state != isp->phy.otg->state)
                pr_debug("  isp, %s -> %s\n",
                                usb_otg_state_string(state), state_name(isp));
 
@@ -1129,10 +1129,10 @@ isp1301_work(struct work_struct *work)
                         * skip A_WAIT_VRISE; hc transitions invisibly
                         * skip A_WAIT_BCON; same.
                         */
-                       switch (isp->phy.state) {
+                       switch (isp->phy.otg->state) {
                        case OTG_STATE_A_WAIT_BCON:
                        case OTG_STATE_A_WAIT_VRISE:
-                               isp->phy.state = OTG_STATE_A_HOST;
+                               isp->phy.otg->state = OTG_STATE_A_HOST;
                                pr_debug("  --> a_host\n");
                                otg_ctrl = omap_readl(OTG_CTRL);
                                otg_ctrl |= OTG_A_BUSREQ;
@@ -1141,7 +1141,7 @@ isp1301_work(struct work_struct *work)
                                omap_writel(otg_ctrl, OTG_CTRL);
                                break;
                        case OTG_STATE_B_WAIT_ACON:
-                               isp->phy.state = OTG_STATE_B_HOST;
+                               isp->phy.otg->state = OTG_STATE_B_HOST;
                                pr_debug("  --> b_host (acon)\n");
                                break;
                        case OTG_STATE_B_HOST:
@@ -1368,7 +1368,7 @@ isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
        }
 
        power_up(isp);
-       isp->phy.state = OTG_STATE_B_IDLE;
+       isp->phy.otg->state = OTG_STATE_B_IDLE;
 
        if (machine_is_omap_h2() || machine_is_omap_h3())
                isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
@@ -1403,7 +1403,7 @@ isp1301_set_power(struct usb_phy *dev, unsigned mA)
 {
        if (!the_transceiver)
                return -ENODEV;
-       if (dev->state == OTG_STATE_B_PERIPHERAL)
+       if (dev->otg->state == OTG_STATE_B_PERIPHERAL)
                enable_vbus_draw(the_transceiver, mA);
        return 0;
 }
@@ -1414,7 +1414,7 @@ isp1301_start_srp(struct usb_otg *otg)
        struct isp1301  *isp = container_of(otg->phy, struct isp1301, phy);
        u32             otg_ctrl;
 
-       if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE)
+       if (isp != the_transceiver || isp->phy.otg->state != OTG_STATE_B_IDLE)
                return -ENODEV;
 
        otg_ctrl = omap_readl(OTG_CTRL);
@@ -1424,7 +1424,7 @@ isp1301_start_srp(struct usb_otg *otg)
        otg_ctrl |= OTG_B_BUSREQ;
        otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
        omap_writel(otg_ctrl, OTG_CTRL);
-       isp->phy.state = OTG_STATE_B_SRP_INIT;
+       isp->phy.otg->state = OTG_STATE_B_SRP_INIT;
 
        pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
                        omap_readl(OTG_CTRL));
@@ -1452,9 +1452,9 @@ isp1301_start_hnp(struct usb_otg *otg)
        /* We want hardware to manage most HNP protocol timings.
         * So do this part as early as possible...
         */
-       switch (isp->phy.state) {
+       switch (isp->phy.otg->state) {
        case OTG_STATE_B_HOST:
-               isp->phy.state = OTG_STATE_B_PERIPHERAL;
+               isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
                /* caller will suspend next */
                break;
        case OTG_STATE_A_HOST: