1
0
Fork 0

usb: otg: ab8500: 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: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
hifive-unleashed-5.1
Heikki Krogerus 2012-02-13 13:24:05 +02:00 committed by Felipe Balbi
parent 7a8a3a9bec
commit 144713f347
1 changed files with 51 additions and 40 deletions

View File

@ -68,7 +68,7 @@ enum ab8500_usb_link_status {
}; };
struct ab8500_usb { struct ab8500_usb {
struct usb_phy otg; struct usb_phy phy;
struct device *dev; struct device *dev;
int irq_num_id_rise; int irq_num_id_rise;
int irq_num_id_fall; int irq_num_id_fall;
@ -82,9 +82,9 @@ struct ab8500_usb {
int rev; int rev;
}; };
static inline struct ab8500_usb *xceiv_to_ab(struct usb_phy *x) static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
{ {
return container_of(x, struct ab8500_usb, otg); return container_of(x, struct ab8500_usb, phy);
} }
static void ab8500_usb_wd_workaround(struct ab8500_usb *ab) static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
@ -169,8 +169,8 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
/* TODO: Disable regulators. */ /* TODO: Disable regulators. */
ab8500_usb_host_phy_dis(ab); ab8500_usb_host_phy_dis(ab);
ab8500_usb_peri_phy_dis(ab); ab8500_usb_peri_phy_dis(ab);
ab->otg.state = OTG_STATE_B_IDLE; ab->phy.state = OTG_STATE_B_IDLE;
ab->otg.default_a = false; ab->phy.otg->default_a = false;
ab->vbus_draw = 0; ab->vbus_draw = 0;
event = USB_EVENT_NONE; event = USB_EVENT_NONE;
break; break;
@ -181,22 +181,22 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
case USB_LINK_HOST_CHG_NM: case USB_LINK_HOST_CHG_NM:
case USB_LINK_HOST_CHG_HS: case USB_LINK_HOST_CHG_HS:
case USB_LINK_HOST_CHG_HS_CHIRP: case USB_LINK_HOST_CHG_HS_CHIRP:
if (ab->otg.gadget) { if (ab->phy.otg->gadget) {
/* TODO: Enable regulators. */ /* TODO: Enable regulators. */
ab8500_usb_peri_phy_en(ab); ab8500_usb_peri_phy_en(ab);
v = ab->otg.gadget; v = ab->phy.otg->gadget;
} }
event = USB_EVENT_VBUS; event = USB_EVENT_VBUS;
break; break;
case USB_LINK_HM_IDGND: case USB_LINK_HM_IDGND:
if (ab->otg.host) { if (ab->phy.otg->host) {
/* TODO: Enable regulators. */ /* TODO: Enable regulators. */
ab8500_usb_host_phy_en(ab); ab8500_usb_host_phy_en(ab);
v = ab->otg.host; v = ab->phy.otg->host;
} }
ab->otg.state = OTG_STATE_A_IDLE; ab->phy.state = OTG_STATE_A_IDLE;
ab->otg.default_a = true; ab->phy.otg->default_a = true;
event = USB_EVENT_ID; event = USB_EVENT_ID;
break; break;
@ -212,7 +212,7 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
break; break;
} }
atomic_notifier_call_chain(&ab->otg.notifier, event, v); atomic_notifier_call_chain(&ab->phy.notifier, event, v);
return 0; return 0;
} }
@ -262,27 +262,27 @@ static void ab8500_usb_phy_disable_work(struct work_struct *work)
struct ab8500_usb *ab = container_of(work, struct ab8500_usb, struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
phy_dis_work); phy_dis_work);
if (!ab->otg.host) if (!ab->phy.otg->host)
ab8500_usb_host_phy_dis(ab); ab8500_usb_host_phy_dis(ab);
if (!ab->otg.gadget) if (!ab->phy.otg->gadget)
ab8500_usb_peri_phy_dis(ab); ab8500_usb_peri_phy_dis(ab);
} }
static int ab8500_usb_set_power(struct usb_phy *otg, unsigned mA) static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
{ {
struct ab8500_usb *ab; struct ab8500_usb *ab;
if (!otg) if (!phy)
return -ENODEV; return -ENODEV;
ab = xceiv_to_ab(otg); ab = phy_to_ab(phy);
ab->vbus_draw = mA; ab->vbus_draw = mA;
if (mA) if (mA)
atomic_notifier_call_chain(&ab->otg.notifier, atomic_notifier_call_chain(&ab->phy.notifier,
USB_EVENT_ENUMERATED, ab->otg.gadget); USB_EVENT_ENUMERATED, ab->phy.otg->gadget);
return 0; return 0;
} }
@ -296,15 +296,15 @@ static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
return 0; return 0;
} }
static int ab8500_usb_set_peripheral(struct usb_phy *otg, static int ab8500_usb_set_peripheral(struct usb_otg *otg,
struct usb_gadget *gadget) struct usb_gadget *gadget)
{ {
struct ab8500_usb *ab; struct ab8500_usb *ab;
if (!otg) if (!otg)
return -ENODEV; return -ENODEV;
ab = xceiv_to_ab(otg); ab = phy_to_ab(otg->phy);
/* Some drivers call this function in atomic context. /* Some drivers call this function in atomic context.
* Do not update ab8500 registers directly till this * Do not update ab8500 registers directly till this
@ -313,11 +313,11 @@ static int ab8500_usb_set_peripheral(struct usb_phy *otg,
if (!gadget) { if (!gadget) {
/* TODO: Disable regulators. */ /* TODO: Disable regulators. */
ab->otg.gadget = NULL; otg->gadget = NULL;
schedule_work(&ab->phy_dis_work); schedule_work(&ab->phy_dis_work);
} else { } else {
ab->otg.gadget = gadget; otg->gadget = gadget;
ab->otg.state = OTG_STATE_B_IDLE; otg->phy->state = OTG_STATE_B_IDLE;
/* Phy will not be enabled if cable is already /* Phy will not be enabled if cable is already
* plugged-in. Schedule to enable phy. * plugged-in. Schedule to enable phy.
@ -329,15 +329,14 @@ static int ab8500_usb_set_peripheral(struct usb_phy *otg,
return 0; return 0;
} }
static int ab8500_usb_set_host(struct usb_phy *otg, static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
struct usb_bus *host)
{ {
struct ab8500_usb *ab; struct ab8500_usb *ab;
if (!otg) if (!otg)
return -ENODEV; return -ENODEV;
ab = xceiv_to_ab(otg); ab = phy_to_ab(otg->phy);
/* Some drivers call this function in atomic context. /* Some drivers call this function in atomic context.
* Do not update ab8500 registers directly till this * Do not update ab8500 registers directly till this
@ -346,10 +345,10 @@ static int ab8500_usb_set_host(struct usb_phy *otg,
if (!host) { if (!host) {
/* TODO: Disable regulators. */ /* TODO: Disable regulators. */
ab->otg.host = NULL; otg->host = NULL;
schedule_work(&ab->phy_dis_work); schedule_work(&ab->phy_dis_work);
} else { } else {
ab->otg.host = host; otg->host = host;
/* Phy will not be enabled if cable is already /* Phy will not be enabled if cable is already
* plugged-in. Schedule to enable phy. * plugged-in. Schedule to enable phy.
* Use same delay to avoid any race condition. * Use same delay to avoid any race condition.
@ -472,6 +471,7 @@ static int ab8500_usb_v2_res_setup(struct platform_device *pdev,
static int __devinit ab8500_usb_probe(struct platform_device *pdev) static int __devinit ab8500_usb_probe(struct platform_device *pdev)
{ {
struct ab8500_usb *ab; struct ab8500_usb *ab;
struct usb_otg *otg;
int err; int err;
int rev; int rev;
@ -488,19 +488,28 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
if (!ab) if (!ab)
return -ENOMEM; return -ENOMEM;
otg = kzalloc(sizeof *otg, GFP_KERNEL);
if (!ab->phy.otg) {
kfree(ab);
return -ENOMEM;
}
ab->dev = &pdev->dev; ab->dev = &pdev->dev;
ab->rev = rev; ab->rev = rev;
ab->otg.dev = ab->dev; ab->phy.dev = ab->dev;
ab->otg.label = "ab8500"; ab->phy.otg = otg;
ab->otg.state = OTG_STATE_UNDEFINED; ab->phy.label = "ab8500";
ab->otg.set_host = ab8500_usb_set_host; ab->phy.set_suspend = ab8500_usb_set_suspend;
ab->otg.set_peripheral = ab8500_usb_set_peripheral; ab->phy.set_power = ab8500_usb_set_power;
ab->otg.set_suspend = ab8500_usb_set_suspend; ab->phy.state = OTG_STATE_UNDEFINED;
ab->otg.set_power = ab8500_usb_set_power;
otg->phy = &ab->phy;
otg->set_host = ab8500_usb_set_host;
otg->set_peripheral = ab8500_usb_set_peripheral;
platform_set_drvdata(pdev, ab); platform_set_drvdata(pdev, ab);
ATOMIC_INIT_NOTIFIER_HEAD(&ab->otg.notifier); ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
/* v1: Wait for link status to become stable. /* v1: Wait for link status to become stable.
* all: Updates form set_host and set_peripheral as they are atomic. * all: Updates form set_host and set_peripheral as they are atomic.
@ -520,7 +529,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
goto fail0; goto fail0;
err = otg_set_transceiver(&ab->otg); err = usb_set_transceiver(&ab->phy);
if (err) { if (err) {
dev_err(&pdev->dev, "Can't register transceiver\n"); dev_err(&pdev->dev, "Can't register transceiver\n");
goto fail1; goto fail1;
@ -532,6 +541,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev)
fail1: fail1:
ab8500_usb_irq_free(ab); ab8500_usb_irq_free(ab);
fail0: fail0:
kfree(otg);
kfree(ab); kfree(ab);
return err; return err;
} }
@ -546,13 +556,14 @@ static int __devexit ab8500_usb_remove(struct platform_device *pdev)
cancel_work_sync(&ab->phy_dis_work); cancel_work_sync(&ab->phy_dis_work);
otg_set_transceiver(NULL); usb_set_transceiver(NULL);
ab8500_usb_host_phy_dis(ab); ab8500_usb_host_phy_dis(ab);
ab8500_usb_peri_phy_dis(ab); ab8500_usb_peri_phy_dis(ab);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
kfree(ab->phy.otg);
kfree(ab); kfree(ab);
return 0; return 0;