Commit 74d4aa44 authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Felipe Balbi

usb: otg: twl4030: 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>
Reviewed-by: default avatarMarek Vasut <marek.vasut@gmail.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 41adf109
...@@ -144,7 +144,7 @@ ...@@ -144,7 +144,7 @@
#define GPIO_USB_4PIN_ULPI_2430C (3 << 0) #define GPIO_USB_4PIN_ULPI_2430C (3 << 0)
struct twl4030_usb { struct twl4030_usb {
struct usb_phy otg; struct usb_phy phy;
struct device *dev; struct device *dev;
/* TWL4030 internal USB regulator supplies */ /* TWL4030 internal USB regulator supplies */
...@@ -166,7 +166,7 @@ struct twl4030_usb { ...@@ -166,7 +166,7 @@ struct twl4030_usb {
}; };
/* internal define on top of container_of */ /* internal define on top of container_of */
#define xceiv_to_twl(x) container_of((x), struct twl4030_usb, otg) #define phy_to_twl(x) container_of((x), struct twl4030_usb, phy)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -250,6 +250,7 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl) ...@@ -250,6 +250,7 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
{ {
int status; int status;
int linkstat = USB_EVENT_NONE; int linkstat = USB_EVENT_NONE;
struct usb_otg *otg = twl->phy.otg;
twl->vbus_supplied = false; twl->vbus_supplied = false;
...@@ -281,7 +282,7 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl) ...@@ -281,7 +282,7 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
status, status, linkstat); status, status, linkstat);
twl->otg.last_event = linkstat; twl->phy.last_event = linkstat;
/* REVISIT this assumes host and peripheral controllers /* REVISIT this assumes host and peripheral controllers
* are registered, and that both are active... * are registered, and that both are active...
...@@ -290,11 +291,11 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl) ...@@ -290,11 +291,11 @@ static enum usb_phy_events twl4030_usb_linkstat(struct twl4030_usb *twl)
spin_lock_irq(&twl->lock); spin_lock_irq(&twl->lock);
twl->linkstat = linkstat; twl->linkstat = linkstat;
if (linkstat == USB_EVENT_ID) { if (linkstat == USB_EVENT_ID) {
twl->otg.default_a = true; otg->default_a = true;
twl->otg.state = OTG_STATE_A_IDLE; twl->phy.state = OTG_STATE_A_IDLE;
} else { } else {
twl->otg.default_a = false; otg->default_a = false;
twl->otg.state = OTG_STATE_B_IDLE; twl->phy.state = OTG_STATE_B_IDLE;
} }
spin_unlock_irq(&twl->lock); spin_unlock_irq(&twl->lock);
...@@ -520,8 +521,8 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) ...@@ -520,8 +521,8 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
else else
twl4030_phy_resume(twl); twl4030_phy_resume(twl);
atomic_notifier_call_chain(&twl->otg.notifier, status, atomic_notifier_call_chain(&twl->phy.notifier, status,
twl->otg.gadget); twl->phy.otg->gadget);
} }
sysfs_notify(&twl->dev->kobj, NULL, "vbus"); sysfs_notify(&twl->dev->kobj, NULL, "vbus");
...@@ -542,15 +543,15 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl) ...@@ -542,15 +543,15 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
twl->asleep = 0; twl->asleep = 0;
} }
atomic_notifier_call_chain(&twl->otg.notifier, status, atomic_notifier_call_chain(&twl->phy.notifier, status,
twl->otg.gadget); twl->phy.otg->gadget);
} }
sysfs_notify(&twl->dev->kobj, NULL, "vbus"); sysfs_notify(&twl->dev->kobj, NULL, "vbus");
} }
static int twl4030_set_suspend(struct usb_phy *x, int suspend) static int twl4030_set_suspend(struct usb_phy *x, int suspend)
{ {
struct twl4030_usb *twl = xceiv_to_twl(x); struct twl4030_usb *twl = phy_to_twl(x);
if (suspend) if (suspend)
twl4030_phy_suspend(twl, 1); twl4030_phy_suspend(twl, 1);
...@@ -560,33 +561,27 @@ static int twl4030_set_suspend(struct usb_phy *x, int suspend) ...@@ -560,33 +561,27 @@ static int twl4030_set_suspend(struct usb_phy *x, int suspend)
return 0; return 0;
} }
static int twl4030_set_peripheral(struct usb_phy *x, static int twl4030_set_peripheral(struct usb_otg *otg,
struct usb_gadget *gadget) struct usb_gadget *gadget)
{ {
struct twl4030_usb *twl; if (!otg)
if (!x)
return -ENODEV; return -ENODEV;
twl = xceiv_to_twl(x); otg->gadget = gadget;
twl->otg.gadget = gadget;
if (!gadget) if (!gadget)
twl->otg.state = OTG_STATE_UNDEFINED; otg->phy->state = OTG_STATE_UNDEFINED;
return 0; return 0;
} }
static int twl4030_set_host(struct usb_phy *x, struct usb_bus *host) static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
{ {
struct twl4030_usb *twl; if (!otg)
if (!x)
return -ENODEV; return -ENODEV;
twl = xceiv_to_twl(x); otg->host = host;
twl->otg.host = host;
if (!host) if (!host)
twl->otg.state = OTG_STATE_UNDEFINED; otg->phy->state = OTG_STATE_UNDEFINED;
return 0; return 0;
} }
...@@ -596,6 +591,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev) ...@@ -596,6 +591,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
struct twl4030_usb_data *pdata = pdev->dev.platform_data; struct twl4030_usb_data *pdata = pdev->dev.platform_data;
struct twl4030_usb *twl; struct twl4030_usb *twl;
int status, err; int status, err;
struct usb_otg *otg;
if (!pdata) { if (!pdata) {
dev_dbg(&pdev->dev, "platform_data not available\n"); dev_dbg(&pdev->dev, "platform_data not available\n");
...@@ -606,33 +602,44 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev) ...@@ -606,33 +602,44 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
if (!twl) if (!twl)
return -ENOMEM; return -ENOMEM;
otg = kzalloc(sizeof *otg, GFP_KERNEL);
if (!otg) {
kfree(twl);
return -ENOMEM;
}
twl->dev = &pdev->dev; twl->dev = &pdev->dev;
twl->irq = platform_get_irq(pdev, 0); twl->irq = platform_get_irq(pdev, 0);
twl->otg.dev = twl->dev;
twl->otg.label = "twl4030";
twl->otg.set_host = twl4030_set_host;
twl->otg.set_peripheral = twl4030_set_peripheral;
twl->otg.set_suspend = twl4030_set_suspend;
twl->usb_mode = pdata->usb_mode; twl->usb_mode = pdata->usb_mode;
twl->vbus_supplied = false; twl->vbus_supplied = false;
twl->asleep = 1; twl->asleep = 1;
twl->phy.dev = twl->dev;
twl->phy.label = "twl4030";
twl->phy.otg = otg;
twl->phy.set_suspend = twl4030_set_suspend;
otg->phy = &twl->phy;
otg->set_host = twl4030_set_host;
otg->set_peripheral = twl4030_set_peripheral;
/* init spinlock for workqueue */ /* init spinlock for workqueue */
spin_lock_init(&twl->lock); spin_lock_init(&twl->lock);
err = twl4030_usb_ldo_init(twl); err = twl4030_usb_ldo_init(twl);
if (err) { if (err) {
dev_err(&pdev->dev, "ldo init failed\n"); dev_err(&pdev->dev, "ldo init failed\n");
kfree(otg);
kfree(twl); kfree(twl);
return err; return err;
} }
otg_set_transceiver(&twl->otg); usb_set_transceiver(&twl->phy);
platform_set_drvdata(pdev, twl); platform_set_drvdata(pdev, twl);
if (device_create_file(&pdev->dev, &dev_attr_vbus)) if (device_create_file(&pdev->dev, &dev_attr_vbus))
dev_warn(&pdev->dev, "could not create sysfs file\n"); dev_warn(&pdev->dev, "could not create sysfs file\n");
ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier); ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
/* Our job is to use irqs and status from the power module /* Our job is to use irqs and status from the power module
* to keep the transceiver disabled when nothing's connected. * to keep the transceiver disabled when nothing's connected.
...@@ -649,6 +656,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev) ...@@ -649,6 +656,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
if (status < 0) { if (status < 0) {
dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
twl->irq, status); twl->irq, status);
kfree(otg);
kfree(twl); kfree(twl);
return status; return status;
} }
...@@ -693,6 +701,7 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev) ...@@ -693,6 +701,7 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
regulator_put(twl->usb1v8); regulator_put(twl->usb1v8);
regulator_put(twl->usb3v1); regulator_put(twl->usb3v1);
kfree(twl->phy.otg);
kfree(twl); kfree(twl);
return 0; return 0;
......
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