diff options
author | Heikki Krogerus <heikki.krogerus@linux.intel.com> | 2012-02-13 13:24:06 +0200 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2012-02-13 13:35:25 +0200 |
commit | 7e062c0f8888001d28cf74da0c3d16a651bd7489 (patch) | |
tree | 459a77a6f9eab6e4b0d584d744d5feb39832a21f | |
parent | 144713f34727801d55d8858e0f549118b9f691c4 (diff) |
usb: otg: fsl: Start using struct usb_otg
Use struct usb_otg members with OTG specific functions instead
of usb_phy members.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Li Yang <leoli@freescale.com>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/otg/fsl_otg.c | 113 | ||||
-rw-r--r-- | drivers/usb/otg/fsl_otg.h | 2 | ||||
-rw-r--r-- | drivers/usb/otg/otg_fsm.c | 22 | ||||
-rw-r--r-- | drivers/usb/otg/otg_fsm.h | 2 |
4 files changed, 75 insertions, 64 deletions
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/otg/fsl_otg.c index 66db2a11744..be4a63e8302 100644 --- a/drivers/usb/otg/fsl_otg.c +++ b/drivers/usb/otg/fsl_otg.c @@ -275,7 +275,7 @@ void b_srp_end(unsigned long foo) fsl_otg_dischrg_vbus(0); srp_wait_done = 1; - if ((fsl_otg_dev->otg.state == OTG_STATE_B_SRP_INIT) && + if ((fsl_otg_dev->phy.state == OTG_STATE_B_SRP_INIT) && fsl_otg_dev->fsm.b_sess_vld) fsl_otg_dev->fsm.b_srp_done = 1; } @@ -288,7 +288,7 @@ void b_srp_end(unsigned long foo) void a_wait_enum(unsigned long foo) { VDBG("a_wait_enum timeout\n"); - if (!fsl_otg_dev->otg.host->b_hnp_enable) + if (!fsl_otg_dev->phy.otg->host->b_hnp_enable) fsl_otg_add_timer(a_wait_enum_tmr); else otg_statemachine(&fsl_otg_dev->fsm); @@ -452,14 +452,14 @@ void otg_reset_controller(void) /* Call suspend/resume routines in host driver */ int fsl_otg_start_host(struct otg_fsm *fsm, int on) { - struct usb_phy *xceiv = fsm->transceiver; + struct usb_otg *otg = fsm->otg; struct device *dev; - struct fsl_otg *otg_dev = container_of(xceiv, struct fsl_otg, otg); + struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); u32 retval = 0; - if (!xceiv->host) + if (!otg->host) return -ENODEV; - dev = xceiv->host->controller; + dev = otg->host->controller; /* * Update a_vbus_vld state as a_vbus_vld int is disabled @@ -518,14 +518,14 @@ end: */ int fsl_otg_start_gadget(struct otg_fsm *fsm, int on) { - struct usb_phy *xceiv = fsm->transceiver; + struct usb_otg *otg = fsm->otg; struct device *dev; - if (!xceiv->gadget || !xceiv->gadget->dev.parent) + if (!otg->gadget || !otg->gadget->dev.parent) return -ENODEV; VDBG("gadget %s\n", on ? "on" : "off"); - dev = xceiv->gadget->dev.parent; + dev = otg->gadget->dev.parent; if (on) { if (dev->driver->resume) @@ -542,14 +542,14 @@ int fsl_otg_start_gadget(struct otg_fsm *fsm, int on) * Called by initialization code of host driver. Register host controller * to the OTG. Suspend host for OTG role detection. */ -static int fsl_otg_set_host(struct usb_phy *otg_p, struct usb_bus *host) +static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host) { - struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg); + struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); - if (!otg_p || otg_dev != fsl_otg_dev) + if (!otg || otg_dev != fsl_otg_dev) return -ENODEV; - otg_p->host = host; + otg->host = host; otg_dev->fsm.a_bus_drop = 0; otg_dev->fsm.a_bus_req = 1; @@ -557,8 +557,8 @@ static int fsl_otg_set_host(struct usb_phy *otg_p, struct usb_bus *host) if (host) { VDBG("host off......\n"); - otg_p->host->otg_port = fsl_otg_initdata.otg_port; - otg_p->host->is_b_host = otg_dev->fsm.id; + otg->host->otg_port = fsl_otg_initdata.otg_port; + otg->host->is_b_host = otg_dev->fsm.id; /* * must leave time for khubd to finish its thing * before yanking the host driver out from under it, @@ -574,7 +574,7 @@ static int fsl_otg_set_host(struct usb_phy *otg_p, struct usb_bus *host) /* Mini-A cable connected */ struct otg_fsm *fsm = &otg_dev->fsm; - otg_p->state = OTG_STATE_UNDEFINED; + otg->phy->state = OTG_STATE_UNDEFINED; fsm->protocol = PROTO_UNDEF; } } @@ -587,29 +587,29 @@ static int fsl_otg_set_host(struct usb_phy *otg_p, struct usb_bus *host) } /* Called by initialization code of udc. Register udc to OTG. */ -static int fsl_otg_set_peripheral(struct usb_phy *otg_p, - struct usb_gadget *gadget) +static int fsl_otg_set_peripheral(struct usb_otg *otg, + struct usb_gadget *gadget) { - struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg); + struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); VDBG("otg_dev 0x%x\n", (int)otg_dev); VDBG("fsl_otg_dev 0x%x\n", (int)fsl_otg_dev); - if (!otg_p || otg_dev != fsl_otg_dev) + if (!otg || otg_dev != fsl_otg_dev) return -ENODEV; if (!gadget) { - if (!otg_dev->otg.default_a) - otg_p->gadget->ops->vbus_draw(otg_p->gadget, 0); - usb_gadget_vbus_disconnect(otg_dev->otg.gadget); - otg_dev->otg.gadget = 0; + if (!otg->default_a) + otg->gadget->ops->vbus_draw(otg->gadget, 0); + usb_gadget_vbus_disconnect(otg->gadget); + otg->gadget = 0; otg_dev->fsm.b_bus_req = 0; otg_statemachine(&otg_dev->fsm); return 0; } - otg_p->gadget = gadget; - otg_p->gadget->is_a_peripheral = !otg_dev->fsm.id; + otg->gadget = gadget; + otg->gadget->is_a_peripheral = !otg_dev->fsm.id; otg_dev->fsm.b_bus_req = 1; @@ -625,11 +625,11 @@ static int fsl_otg_set_peripheral(struct usb_phy *otg_p, } /* Set OTG port power, only for B-device */ -static int fsl_otg_set_power(struct usb_phy *otg_p, unsigned mA) +static int fsl_otg_set_power(struct usb_phy *phy, unsigned mA) { if (!fsl_otg_dev) return -ENODEV; - if (otg_p->state == OTG_STATE_B_PERIPHERAL) + if (phy->state == OTG_STATE_B_PERIPHERAL) pr_info("FSL OTG: Draw %d mA\n", mA); return 0; @@ -658,12 +658,12 @@ static void fsl_otg_event(struct work_struct *work) } /* B-device start SRP */ -static int fsl_otg_start_srp(struct usb_phy *otg_p) +static int fsl_otg_start_srp(struct usb_otg *otg) { - struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg); + struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); - if (!otg_p || otg_dev != fsl_otg_dev - || otg_p->state != OTG_STATE_B_IDLE) + if (!otg || otg_dev != fsl_otg_dev + || otg->phy->state != OTG_STATE_B_IDLE) return -ENODEV; otg_dev->fsm.b_bus_req = 1; @@ -673,11 +673,11 @@ static int fsl_otg_start_srp(struct usb_phy *otg_p) } /* A_host suspend will call this function to start hnp */ -static int fsl_otg_start_hnp(struct usb_phy *otg_p) +static int fsl_otg_start_hnp(struct usb_otg *otg) { - struct fsl_otg *otg_dev = container_of(otg_p, struct fsl_otg, otg); + struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); - if (!otg_p || otg_dev != fsl_otg_dev) + if (!otg || otg_dev != fsl_otg_dev) return -ENODEV; DBG("start_hnp...n"); @@ -698,7 +698,7 @@ static int fsl_otg_start_hnp(struct usb_phy *otg_p) irqreturn_t fsl_otg_isr(int irq, void *dev_id) { struct otg_fsm *fsm = &((struct fsl_otg *)dev_id)->fsm; - struct usb_phy *otg = &((struct fsl_otg *)dev_id)->otg; + struct usb_otg *otg = ((struct fsl_otg *)dev_id)->phy.otg; u32 otg_int_src, otg_sc; otg_sc = fsl_readl(&usb_dr_regs->otgsc); @@ -774,6 +774,12 @@ static int fsl_otg_conf(struct platform_device *pdev) if (!fsl_otg_tc) return -ENOMEM; + fsl_otg_tc->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); + if (!fsl_otg_tc->phy.otg) { + kfree(fsl_otg_tc); + return -ENOMEM; + } + INIT_DELAYED_WORK(&fsl_otg_tc->otg_event, fsl_otg_event); INIT_LIST_HEAD(&active_timers); @@ -788,17 +794,19 @@ static int fsl_otg_conf(struct platform_device *pdev) fsl_otg_tc->fsm.ops = &fsl_otg_ops; /* initialize the otg structure */ - fsl_otg_tc->otg.label = DRIVER_DESC; - fsl_otg_tc->otg.set_host = fsl_otg_set_host; - fsl_otg_tc->otg.set_peripheral = fsl_otg_set_peripheral; - fsl_otg_tc->otg.set_power = fsl_otg_set_power; - fsl_otg_tc->otg.start_hnp = fsl_otg_start_hnp; - fsl_otg_tc->otg.start_srp = fsl_otg_start_srp; + fsl_otg_tc->phy.label = DRIVER_DESC; + fsl_otg_tc->phy.set_power = fsl_otg_set_power; + + fsl_otg_tc->phy.otg->phy = &fsl_otg_tc->phy; + fsl_otg_tc->phy.otg->set_host = fsl_otg_set_host; + fsl_otg_tc->phy.otg->set_peripheral = fsl_otg_set_peripheral; + fsl_otg_tc->phy.otg->start_hnp = fsl_otg_start_hnp; + fsl_otg_tc->phy.otg->start_srp = fsl_otg_start_srp; fsl_otg_dev = fsl_otg_tc; /* Store the otg transceiver */ - status = otg_set_transceiver(&fsl_otg_tc->otg); + status = usb_set_transceiver(&fsl_otg_tc->phy); if (status) { pr_warn(FSL_OTG_NAME ": unable to register OTG transceiver.\n"); goto err; @@ -807,6 +815,7 @@ static int fsl_otg_conf(struct platform_device *pdev) return 0; err: fsl_otg_uninit_timers(); + kfree(fsl_otg_tc->phy.otg); kfree(fsl_otg_tc); return status; } @@ -815,19 +824,19 @@ err: int usb_otg_start(struct platform_device *pdev) { struct fsl_otg *p_otg; - struct usb_phy *otg_trans = otg_get_transceiver(); + struct usb_phy *otg_trans = usb_get_transceiver(); struct otg_fsm *fsm; int status; struct resource *res; u32 temp; struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; - p_otg = container_of(otg_trans, struct fsl_otg, otg); + p_otg = container_of(otg_trans, struct fsl_otg, phy); fsm = &p_otg->fsm; /* Initialize the state machine structure with default values */ SET_OTG_STATE(otg_trans, OTG_STATE_UNDEFINED); - fsm->transceiver = &p_otg->otg; + fsm->otg = p_otg->phy.otg; /* We don't require predefined MEM/IRQ resource index */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -857,9 +866,10 @@ int usb_otg_start(struct platform_device *pdev) status = request_irq(p_otg->irq, fsl_otg_isr, IRQF_SHARED, driver_name, p_otg); if (status) { - dev_dbg(p_otg->otg.dev, "can't get IRQ %d, error %d\n", + dev_dbg(p_otg->phy.dev, "can't get IRQ %d, error %d\n", p_otg->irq, status); iounmap(p_otg->dr_mem_map); + kfree(p_otg->phy.otg); kfree(p_otg); return status; } @@ -919,10 +929,10 @@ int usb_otg_start(struct platform_device *pdev) * Also: record initial state of ID pin */ if (fsl_readl(&p_otg->dr_mem_map->otgsc) & OTGSC_STS_USB_ID) { - p_otg->otg.state = OTG_STATE_UNDEFINED; + p_otg->phy.state = OTG_STATE_UNDEFINED; p_otg->fsm.id = 1; } else { - p_otg->otg.state = OTG_STATE_A_IDLE; + p_otg->phy.state = OTG_STATE_A_IDLE; p_otg->fsm.id = 0; } @@ -978,7 +988,7 @@ static int show_fsl_usb2_otg_state(struct device *dev, /* State */ t = scnprintf(next, size, "OTG state: %s\n\n", - otg_state_string(fsl_otg_dev->otg.state)); + otg_state_string(fsl_otg_dev->phy.state)); size -= t; next += t; @@ -1124,12 +1134,13 @@ static int __devexit fsl_otg_remove(struct platform_device *pdev) { struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; - otg_set_transceiver(NULL); + usb_set_transceiver(NULL); free_irq(fsl_otg_dev->irq, fsl_otg_dev); iounmap((void *)usb_dr_regs); fsl_otg_uninit_timers(); + kfree(fsl_otg_dev->phy.otg); kfree(fsl_otg_dev); device_remove_file(&pdev->dev, &dev_attr_fsl_usb2_otg_state); diff --git a/drivers/usb/otg/fsl_otg.h b/drivers/usb/otg/fsl_otg.h index caec254ad81..ca266280895 100644 --- a/drivers/usb/otg/fsl_otg.h +++ b/drivers/usb/otg/fsl_otg.h @@ -369,7 +369,7 @@ inline struct fsl_otg_timer *otg_timer_initializer } struct fsl_otg { - struct usb_phy otg; + struct usb_phy phy; struct otg_fsm fsm; struct usb_dr_mmap *dr_mem_map; struct delayed_work otg_event; diff --git a/drivers/usb/otg/otg_fsm.c b/drivers/usb/otg/otg_fsm.c index 09117387d2a..ade131a8ae5 100644 --- a/drivers/usb/otg/otg_fsm.c +++ b/drivers/usb/otg/otg_fsm.c @@ -117,10 +117,10 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state) int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) { state_changed = 1; - if (fsm->transceiver->state == new_state) + if (fsm->otg->phy->state == new_state) return 0; VDBG("Set state: %s\n", otg_state_string(new_state)); - otg_leave_state(fsm, fsm->transceiver->state); + otg_leave_state(fsm, fsm->otg->phy->state); switch (new_state) { case OTG_STATE_B_IDLE: otg_drv_vbus(fsm, 0); @@ -155,8 +155,8 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) otg_loc_conn(fsm, 0); otg_loc_sof(fsm, 1); otg_set_protocol(fsm, PROTO_HOST); - usb_bus_start_enum(fsm->transceiver->host, - fsm->transceiver->host->otg_port); + usb_bus_start_enum(fsm->otg->host, + fsm->otg->host->otg_port); break; case OTG_STATE_A_IDLE: otg_drv_vbus(fsm, 0); @@ -221,7 +221,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state) break; } - fsm->transceiver->state = new_state; + fsm->otg->phy->state = new_state; return 0; } @@ -233,7 +233,7 @@ int otg_statemachine(struct otg_fsm *fsm) spin_lock_irqsave(&fsm->lock, flags); - state = fsm->transceiver->state; + state = fsm->otg->phy->state; state_changed = 0; /* State machine state change judgement */ @@ -248,7 +248,7 @@ int otg_statemachine(struct otg_fsm *fsm) case OTG_STATE_B_IDLE: if (!fsm->id) otg_set_state(fsm, OTG_STATE_A_IDLE); - else if (fsm->b_sess_vld && fsm->transceiver->gadget) + else if (fsm->b_sess_vld && fsm->otg->gadget) otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp) otg_set_state(fsm, OTG_STATE_B_SRP_INIT); @@ -260,7 +260,7 @@ int otg_statemachine(struct otg_fsm *fsm) case OTG_STATE_B_PERIPHERAL: if (!fsm->id || !fsm->b_sess_vld) otg_set_state(fsm, OTG_STATE_B_IDLE); - else if (fsm->b_bus_req && fsm->transceiver-> + else if (fsm->b_bus_req && fsm->otg-> gadget->b_hnp_enable && fsm->a_bus_suspend) otg_set_state(fsm, OTG_STATE_B_WAIT_ACON); break; @@ -302,7 +302,7 @@ int otg_statemachine(struct otg_fsm *fsm) break; case OTG_STATE_A_HOST: if ((!fsm->a_bus_req || fsm->a_suspend_req) && - fsm->transceiver->host->b_hnp_enable) + fsm->otg->host->b_hnp_enable) otg_set_state(fsm, OTG_STATE_A_SUSPEND); else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop) otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); @@ -310,9 +310,9 @@ int otg_statemachine(struct otg_fsm *fsm) otg_set_state(fsm, OTG_STATE_A_VBUS_ERR); break; case OTG_STATE_A_SUSPEND: - if (!fsm->b_conn && fsm->transceiver->host->b_hnp_enable) + if (!fsm->b_conn && fsm->otg->host->b_hnp_enable) otg_set_state(fsm, OTG_STATE_A_PERIPHERAL); - else if (!fsm->b_conn && !fsm->transceiver->host->b_hnp_enable) + else if (!fsm->b_conn && !fsm->otg->host->b_hnp_enable) otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); else if (fsm->a_bus_req || fsm->b_bus_resume) otg_set_state(fsm, OTG_STATE_A_HOST); diff --git a/drivers/usb/otg/otg_fsm.h b/drivers/usb/otg/otg_fsm.h index 5e589ae9a19..c30a2e1d9e4 100644 --- a/drivers/usb/otg/otg_fsm.h +++ b/drivers/usb/otg/otg_fsm.h @@ -82,7 +82,7 @@ struct otg_fsm { int loc_sof; struct otg_fsm_ops *ops; - struct usb_phy *transceiver; + struct usb_otg *otg; /* Current usb protocol used: 0:undefine; 1:host; 2:client */ int protocol; |