Use struct usb_otg members with OTG specific functions instead of usb_phy members. Signed-off-by: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx> --- drivers/usb/otg/mv_otg.c | 110 ++++++++++++++++++++++++++-------------------- drivers/usb/otg/mv_otg.h | 2 +- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/otg/mv_otg.c index 1d2f7cb..1ce591a 100644 --- a/drivers/usb/otg/mv_otg.c +++ b/drivers/usb/otg/mv_otg.c @@ -55,16 +55,16 @@ static char *state_string[] = { "a_vbus_err" }; -static int mv_otg_set_vbus(struct usb_phy *otg, bool on) +static int mv_otg_set_vbus(struct usb_otg *otg, bool on) { - struct mv_otg *mvotg = container_of(otg, struct mv_otg, otg); + struct mv_otg *mvotg = container_of(otg->phy, struct mv_otg, phy); if (mvotg->pdata->set_vbus == NULL) return -ENODEV; return mvotg->pdata->set_vbus(on); } -static int mv_otg_set_host(struct usb_phy *otg, +static int mv_otg_set_host(struct usb_otg *otg, struct usb_bus *host) { otg->host = host; @@ -72,7 +72,7 @@ static int mv_otg_set_host(struct usb_phy *otg, return 0; } -static int mv_otg_set_peripheral(struct usb_phy *otg, +static int mv_otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) { otg->gadget = gadget; @@ -202,7 +202,7 @@ static void mv_otg_init_irq(struct mv_otg *mvotg) static void mv_otg_start_host(struct mv_otg *mvotg, int on) { - struct usb_phy *otg = &mvotg->otg; + struct usb_otg *otg = mvotg->phy.otg; struct usb_hcd *hcd; if (!otg->host) @@ -220,12 +220,12 @@ static void mv_otg_start_host(struct mv_otg *mvotg, int on) static void mv_otg_start_periphrals(struct mv_otg *mvotg, int on) { - struct usb_phy *otg = &mvotg->otg; + struct usb_otg *otg = mvotg->phy.otg; if (!otg->gadget) return; - dev_info(otg->dev, "gadget %s\n", on ? "on" : "off"); + dev_info(mvotg->phy.dev, "gadget %s\n", on ? "on" : "off"); if (on) usb_gadget_vbus_connect(otg->gadget); @@ -341,69 +341,69 @@ static void mv_otg_update_inputs(struct mv_otg *mvotg) static void mv_otg_update_state(struct mv_otg *mvotg) { struct mv_otg_ctrl *otg_ctrl = &mvotg->otg_ctrl; - struct usb_phy *otg = &mvotg->otg; - int old_state = otg->state; + struct usb_phy *phy = &mvotg->phy; + int old_state = phy->state; switch (old_state) { case OTG_STATE_UNDEFINED: - otg->state = OTG_STATE_B_IDLE; + phy->state = OTG_STATE_B_IDLE; /* FALL THROUGH */ case OTG_STATE_B_IDLE: if (otg_ctrl->id == 0) - otg->state = OTG_STATE_A_IDLE; + phy->state = OTG_STATE_A_IDLE; else if (otg_ctrl->b_sess_vld) - otg->state = OTG_STATE_B_PERIPHERAL; + phy->state = OTG_STATE_B_PERIPHERAL; break; case OTG_STATE_B_PERIPHERAL: if (!otg_ctrl->b_sess_vld || otg_ctrl->id == 0) - otg->state = OTG_STATE_B_IDLE; + phy->state = OTG_STATE_B_IDLE; break; case OTG_STATE_A_IDLE: if (otg_ctrl->id) - otg->state = OTG_STATE_B_IDLE; + phy->state = OTG_STATE_B_IDLE; else if (!(otg_ctrl->a_bus_drop) && (otg_ctrl->a_bus_req || otg_ctrl->a_srp_det)) - otg->state = OTG_STATE_A_WAIT_VRISE; + phy->state = OTG_STATE_A_WAIT_VRISE; break; case OTG_STATE_A_WAIT_VRISE: if (otg_ctrl->a_vbus_vld) - otg->state = OTG_STATE_A_WAIT_BCON; + phy->state = OTG_STATE_A_WAIT_BCON; break; case OTG_STATE_A_WAIT_BCON: if (otg_ctrl->id || otg_ctrl->a_bus_drop || otg_ctrl->a_wait_bcon_timeout) { mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); mvotg->otg_ctrl.a_wait_bcon_timeout = 0; - otg->state = OTG_STATE_A_WAIT_VFALL; + phy->state = OTG_STATE_A_WAIT_VFALL; otg_ctrl->a_bus_req = 0; } else if (!otg_ctrl->a_vbus_vld) { mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); mvotg->otg_ctrl.a_wait_bcon_timeout = 0; - otg->state = OTG_STATE_A_VBUS_ERR; + phy->state = OTG_STATE_A_VBUS_ERR; } else if (otg_ctrl->b_conn) { mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); mvotg->otg_ctrl.a_wait_bcon_timeout = 0; - otg->state = OTG_STATE_A_HOST; + phy->state = OTG_STATE_A_HOST; } break; case OTG_STATE_A_HOST: if (otg_ctrl->id || !otg_ctrl->b_conn || otg_ctrl->a_bus_drop) - otg->state = OTG_STATE_A_WAIT_BCON; + phy->state = OTG_STATE_A_WAIT_BCON; else if (!otg_ctrl->a_vbus_vld) - otg->state = OTG_STATE_A_VBUS_ERR; + phy->state = OTG_STATE_A_VBUS_ERR; break; case OTG_STATE_A_WAIT_VFALL: if (otg_ctrl->id || (!otg_ctrl->b_conn && otg_ctrl->a_sess_vld) || otg_ctrl->a_bus_req) - otg->state = OTG_STATE_A_IDLE; + phy->state = OTG_STATE_A_IDLE; break; case OTG_STATE_A_VBUS_ERR: if (otg_ctrl->id || otg_ctrl->a_clr_err || otg_ctrl->a_bus_drop) { otg_ctrl->a_clr_err = 0; - otg->state = OTG_STATE_A_WAIT_VFALL; + phy->state = OTG_STATE_A_WAIT_VFALL; } break; default: @@ -414,15 +414,17 @@ static void mv_otg_update_state(struct mv_otg *mvotg) static void mv_otg_work(struct work_struct *work) { struct mv_otg *mvotg; - struct usb_phy *otg; + struct usb_phy *phy; + struct usb_otg *otg; int old_state; mvotg = container_of((struct delayed_work *)work, struct mv_otg, work); run: /* work queue is single thread, or we need spin_lock to protect */ - otg = &mvotg->otg; - old_state = otg->state; + phy = &mvotg->phy; + otg = phy->otg; + old_state = phy->state; if (!mvotg->active) return; @@ -430,14 +432,14 @@ run: mv_otg_update_inputs(mvotg); mv_otg_update_state(mvotg); - if (old_state != otg->state) { + if (old_state != phy->state) { dev_info(&mvotg->pdev->dev, "change from state %s to %s\n", state_string[old_state], - state_string[otg->state]); + state_string[phy->state]); - switch (otg->state) { + switch (phy->state) { case OTG_STATE_B_IDLE: - mvotg->otg.default_a = 0; + otg->default_a = 0; if (old_state == OTG_STATE_B_PERIPHERAL) mv_otg_start_periphrals(mvotg, 0); mv_otg_reset(mvotg); @@ -448,14 +450,14 @@ run: mv_otg_start_periphrals(mvotg, 1); break; case OTG_STATE_A_IDLE: - mvotg->otg.default_a = 1; + otg->default_a = 1; mv_otg_enable(mvotg); if (old_state == OTG_STATE_A_WAIT_VFALL) mv_otg_start_host(mvotg, 0); mv_otg_reset(mvotg); break; case OTG_STATE_A_WAIT_VRISE: - mv_otg_set_vbus(&mvotg->otg, 1); + mv_otg_set_vbus(otg, 1); break; case OTG_STATE_A_WAIT_BCON: if (old_state != OTG_STATE_A_HOST) @@ -477,7 +479,7 @@ run: * here. In fact, it need host driver to notify us. */ mvotg->otg_ctrl.b_conn = 0; - mv_otg_set_vbus(&mvotg->otg, 0); + mv_otg_set_vbus(otg, 0); break; case OTG_STATE_A_VBUS_ERR: break; @@ -546,8 +548,8 @@ set_a_bus_req(struct device *dev, struct device_attribute *attr, return -1; /* We will use this interface to change to A device */ - if (mvotg->otg.state != OTG_STATE_B_IDLE - && mvotg->otg.state != OTG_STATE_A_IDLE) + if (mvotg->phy.state != OTG_STATE_B_IDLE + && mvotg->phy.state != OTG_STATE_A_IDLE) return -1; /* The clock may disabled and we need to set irq for ID detected */ @@ -577,7 +579,7 @@ set_a_clr_err(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct mv_otg *mvotg = dev_get_drvdata(dev); - if (!mvotg->otg.default_a) + if (!mvotg->phy.otg->default_a) return -1; if (count > 2) @@ -613,7 +615,7 @@ set_a_bus_drop(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct mv_otg *mvotg = dev_get_drvdata(dev); - if (!mvotg->otg.default_a) + if (!mvotg->phy.otg->default_a) return -1; if (count > 2) @@ -686,9 +688,10 @@ int mv_otg_remove(struct platform_device *pdev) for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++) clk_put(mvotg->clk[clk_i]); - otg_set_transceiver(NULL); + usb_set_transceiver(NULL); platform_set_drvdata(pdev, NULL); + kfree(mvotg->phy.otg); kfree(mvotg); return 0; @@ -698,6 +701,7 @@ static int mv_otg_probe(struct platform_device *pdev) { struct mv_usb_platform_data *pdata = pdev->dev.platform_data; struct mv_otg *mvotg; + struct usb_otg *otg; struct resource *r; int retval = 0, clk_i, i; size_t size; @@ -714,6 +718,12 @@ static int mv_otg_probe(struct platform_device *pdev) return -ENOMEM; } + otg = kzalloc(sizeof *otg, GFP_KERNEL); + if (!otg) { + kfree(mvotg); + return -ENOMEM; + } + platform_set_drvdata(pdev, mvotg); mvotg->pdev = pdev; @@ -739,12 +749,15 @@ static int mv_otg_probe(struct platform_device *pdev) /* OTG common part */ mvotg->pdev = pdev; - mvotg->otg.dev = &pdev->dev; - mvotg->otg.label = driver_name; - mvotg->otg.set_host = mv_otg_set_host; - mvotg->otg.set_peripheral = mv_otg_set_peripheral; - mvotg->otg.set_vbus = mv_otg_set_vbus; - mvotg->otg.state = OTG_STATE_UNDEFINED; + mvotg->phy.dev = &pdev->dev; + mvotg->phy.otg = otg; + mvotg->phy.label = driver_name; + mvotg->phy.state = OTG_STATE_UNDEFINED; + + otg->phy = &mvotg->phy; + otg->set_host = mv_otg_set_host; + otg->set_peripheral = mv_otg_set_peripheral; + otg->set_vbus = mv_otg_set_vbus; for (i = 0; i < OTG_TIMER_NUM; i++) init_timer(&mvotg->otg_ctrl.timer[i]); @@ -838,7 +851,7 @@ static int mv_otg_probe(struct platform_device *pdev) goto err_disable_clk; } - retval = otg_set_transceiver(&mvotg->otg); + retval = usb_set_transceiver(&mvotg->phy); if (retval < 0) { dev_err(&pdev->dev, "can't register transceiver, %d\n", retval); @@ -865,7 +878,7 @@ static int mv_otg_probe(struct platform_device *pdev) return 0; err_set_transceiver: - otg_set_transceiver(NULL); + usb_set_transceiver(NULL); err_free_irq: free_irq(mvotg->irq, mvotg); err_disable_clk: @@ -886,6 +899,7 @@ err_put_clk: clk_put(mvotg->clk[clk_i]); platform_set_drvdata(pdev, NULL); + kfree(otg); kfree(mvotg); return retval; @@ -896,10 +910,10 @@ static int mv_otg_suspend(struct platform_device *pdev, pm_message_t state) { struct mv_otg *mvotg = platform_get_drvdata(pdev); - if (mvotg->otg.state != OTG_STATE_B_IDLE) { + if (mvotg->phy.state != OTG_STATE_B_IDLE) { dev_info(&pdev->dev, "OTG state is not B_IDLE, it is %d!\n", - mvotg->otg.state); + mvotg->phy.state); return -EAGAIN; } diff --git a/drivers/usb/otg/mv_otg.h b/drivers/usb/otg/mv_otg.h index a74ee07..8a9e351 100644 --- a/drivers/usb/otg/mv_otg.h +++ b/drivers/usb/otg/mv_otg.h @@ -136,7 +136,7 @@ struct mv_otg_regs { }; struct mv_otg { - struct usb_phy otg; + struct usb_phy phy; struct mv_otg_ctrl otg_ctrl; /* base address */ -- 1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html