usb: otg: twl6030: 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> Tested-by: Kishon Vijay Abraham I <kishon@ti.com> Reviewed-by: Marek Vasut <marek.vasut@gmail.com> Cc: Hema HK <hemahk@ti.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
parent
74d4aa4419
commit
46b8f6b0eb
1 changed files with 61 additions and 50 deletions
|
@ -87,7 +87,7 @@
|
||||||
#define VBUS_DET BIT(2)
|
#define VBUS_DET BIT(2)
|
||||||
|
|
||||||
struct twl6030_usb {
|
struct twl6030_usb {
|
||||||
struct usb_phy otg;
|
struct usb_phy phy;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
|
||||||
/* for vbus reporting with irqs disabled */
|
/* for vbus reporting with irqs disabled */
|
||||||
|
@ -107,7 +107,7 @@ struct twl6030_usb {
|
||||||
unsigned long features;
|
unsigned long features;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define xceiv_to_twl(x) container_of((x), struct twl6030_usb, otg)
|
#define phy_to_twl(x) container_of((x), struct twl6030_usb, phy)
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ static int twl6030_phy_init(struct usb_phy *x)
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
struct twl4030_usb_data *pdata;
|
struct twl4030_usb_data *pdata;
|
||||||
|
|
||||||
twl = xceiv_to_twl(x);
|
twl = phy_to_twl(x);
|
||||||
dev = twl->dev;
|
dev = twl->dev;
|
||||||
pdata = dev->platform_data;
|
pdata = dev->platform_data;
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ static void twl6030_phy_shutdown(struct usb_phy *x)
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
struct twl4030_usb_data *pdata;
|
struct twl4030_usb_data *pdata;
|
||||||
|
|
||||||
twl = xceiv_to_twl(x);
|
twl = phy_to_twl(x);
|
||||||
dev = twl->dev;
|
dev = twl->dev;
|
||||||
pdata = dev->platform_data;
|
pdata = dev->platform_data;
|
||||||
pdata->phy_power(twl->dev, 0, 0);
|
pdata->phy_power(twl->dev, 0, 0);
|
||||||
|
@ -169,7 +169,7 @@ static void twl6030_phy_shutdown(struct usb_phy *x)
|
||||||
|
|
||||||
static int twl6030_phy_suspend(struct usb_phy *x, int suspend)
|
static int twl6030_phy_suspend(struct usb_phy *x, int suspend)
|
||||||
{
|
{
|
||||||
struct twl6030_usb *twl = xceiv_to_twl(x);
|
struct twl6030_usb *twl = phy_to_twl(x);
|
||||||
struct device *dev = twl->dev;
|
struct device *dev = twl->dev;
|
||||||
struct twl4030_usb_data *pdata = dev->platform_data;
|
struct twl4030_usb_data *pdata = dev->platform_data;
|
||||||
|
|
||||||
|
@ -178,9 +178,9 @@ static int twl6030_phy_suspend(struct usb_phy *x, int suspend)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int twl6030_start_srp(struct usb_phy *x)
|
static int twl6030_start_srp(struct usb_otg *otg)
|
||||||
{
|
{
|
||||||
struct twl6030_usb *twl = xceiv_to_twl(x);
|
struct twl6030_usb *twl = phy_to_twl(otg->phy);
|
||||||
|
|
||||||
twl6030_writeb(twl, TWL_MODULE_USB, 0x24, USB_VBUS_CTRL_SET);
|
twl6030_writeb(twl, TWL_MODULE_USB, 0x24, USB_VBUS_CTRL_SET);
|
||||||
twl6030_writeb(twl, TWL_MODULE_USB, 0x84, USB_VBUS_CTRL_SET);
|
twl6030_writeb(twl, TWL_MODULE_USB, 0x84, USB_VBUS_CTRL_SET);
|
||||||
|
@ -256,6 +256,7 @@ static DEVICE_ATTR(vbus, 0444, twl6030_usb_vbus_show, NULL);
|
||||||
static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
|
static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
|
||||||
{
|
{
|
||||||
struct twl6030_usb *twl = _twl;
|
struct twl6030_usb *twl = _twl;
|
||||||
|
struct usb_otg *otg = twl->phy.otg;
|
||||||
int status;
|
int status;
|
||||||
u8 vbus_state, hw_state;
|
u8 vbus_state, hw_state;
|
||||||
|
|
||||||
|
@ -268,18 +269,18 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
|
||||||
regulator_enable(twl->usb3v3);
|
regulator_enable(twl->usb3v3);
|
||||||
twl->asleep = 1;
|
twl->asleep = 1;
|
||||||
status = USB_EVENT_VBUS;
|
status = USB_EVENT_VBUS;
|
||||||
twl->otg.default_a = false;
|
otg->default_a = false;
|
||||||
twl->otg.state = OTG_STATE_B_IDLE;
|
twl->phy.state = OTG_STATE_B_IDLE;
|
||||||
twl->linkstat = status;
|
twl->linkstat = status;
|
||||||
twl->otg.last_event = status;
|
twl->phy.last_event = status;
|
||||||
atomic_notifier_call_chain(&twl->otg.notifier,
|
atomic_notifier_call_chain(&twl->phy.notifier,
|
||||||
status, twl->otg.gadget);
|
status, otg->gadget);
|
||||||
} else {
|
} else {
|
||||||
status = USB_EVENT_NONE;
|
status = USB_EVENT_NONE;
|
||||||
twl->linkstat = status;
|
twl->linkstat = status;
|
||||||
twl->otg.last_event = status;
|
twl->phy.last_event = status;
|
||||||
atomic_notifier_call_chain(&twl->otg.notifier,
|
atomic_notifier_call_chain(&twl->phy.notifier,
|
||||||
status, twl->otg.gadget);
|
status, otg->gadget);
|
||||||
if (twl->asleep) {
|
if (twl->asleep) {
|
||||||
regulator_disable(twl->usb3v3);
|
regulator_disable(twl->usb3v3);
|
||||||
twl->asleep = 0;
|
twl->asleep = 0;
|
||||||
|
@ -294,6 +295,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
|
||||||
static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
|
static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
|
||||||
{
|
{
|
||||||
struct twl6030_usb *twl = _twl;
|
struct twl6030_usb *twl = _twl;
|
||||||
|
struct usb_otg *otg = twl->phy.otg;
|
||||||
int status = USB_EVENT_NONE;
|
int status = USB_EVENT_NONE;
|
||||||
u8 hw_state;
|
u8 hw_state;
|
||||||
|
|
||||||
|
@ -307,12 +309,12 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
|
||||||
twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET,
|
twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET,
|
||||||
0x10);
|
0x10);
|
||||||
status = USB_EVENT_ID;
|
status = 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;
|
||||||
twl->linkstat = status;
|
twl->linkstat = status;
|
||||||
twl->otg.last_event = status;
|
twl->phy.last_event = status;
|
||||||
atomic_notifier_call_chain(&twl->otg.notifier, status,
|
atomic_notifier_call_chain(&twl->phy.notifier, status,
|
||||||
twl->otg.gadget);
|
otg->gadget);
|
||||||
} else {
|
} else {
|
||||||
twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR,
|
twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR,
|
||||||
0x10);
|
0x10);
|
||||||
|
@ -324,25 +326,22 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int twl6030_set_peripheral(struct usb_phy *x,
|
static int twl6030_set_peripheral(struct usb_otg *otg,
|
||||||
struct usb_gadget *gadget)
|
struct usb_gadget *gadget)
|
||||||
{
|
{
|
||||||
struct twl6030_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 twl6030_enable_irq(struct usb_phy *x)
|
static int twl6030_enable_irq(struct usb_phy *x)
|
||||||
{
|
{
|
||||||
struct twl6030_usb *twl = xceiv_to_twl(x);
|
struct twl6030_usb *twl = phy_to_twl(x);
|
||||||
|
|
||||||
twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, 0x1);
|
twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, 0x1);
|
||||||
twl6030_interrupt_unmask(0x05, REG_INT_MSK_LINE_C);
|
twl6030_interrupt_unmask(0x05, REG_INT_MSK_LINE_C);
|
||||||
|
@ -376,9 +375,9 @@ static void otg_set_vbus_work(struct work_struct *data)
|
||||||
CHARGERUSB_CTRL1);
|
CHARGERUSB_CTRL1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int twl6030_set_vbus(struct usb_phy *x, bool enabled)
|
static int twl6030_set_vbus(struct usb_otg *otg, bool enabled)
|
||||||
{
|
{
|
||||||
struct twl6030_usb *twl = xceiv_to_twl(x);
|
struct twl6030_usb *twl = phy_to_twl(otg->phy);
|
||||||
|
|
||||||
twl->vbus_enable = enabled;
|
twl->vbus_enable = enabled;
|
||||||
schedule_work(&twl->set_vbus_work);
|
schedule_work(&twl->set_vbus_work);
|
||||||
|
@ -386,17 +385,14 @@ static int twl6030_set_vbus(struct usb_phy *x, bool enabled)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int twl6030_set_host(struct usb_phy *x, struct usb_bus *host)
|
static int twl6030_set_host(struct usb_otg *otg, struct usb_bus *host)
|
||||||
{
|
{
|
||||||
struct twl6030_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,6 +401,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
|
||||||
struct twl6030_usb *twl;
|
struct twl6030_usb *twl;
|
||||||
int status, err;
|
int status, err;
|
||||||
struct twl4030_usb_data *pdata;
|
struct twl4030_usb_data *pdata;
|
||||||
|
struct usb_otg *otg;
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
pdata = dev->platform_data;
|
pdata = dev->platform_data;
|
||||||
|
|
||||||
|
@ -412,19 +409,29 @@ static int __devinit twl6030_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->irq1 = platform_get_irq(pdev, 0);
|
twl->irq1 = platform_get_irq(pdev, 0);
|
||||||
twl->irq2 = platform_get_irq(pdev, 1);
|
twl->irq2 = platform_get_irq(pdev, 1);
|
||||||
twl->features = pdata->features;
|
twl->features = pdata->features;
|
||||||
twl->otg.dev = twl->dev;
|
|
||||||
twl->otg.label = "twl6030";
|
twl->phy.dev = twl->dev;
|
||||||
twl->otg.set_host = twl6030_set_host;
|
twl->phy.label = "twl6030";
|
||||||
twl->otg.set_peripheral = twl6030_set_peripheral;
|
twl->phy.otg = otg;
|
||||||
twl->otg.set_vbus = twl6030_set_vbus;
|
twl->phy.init = twl6030_phy_init;
|
||||||
twl->otg.init = twl6030_phy_init;
|
twl->phy.shutdown = twl6030_phy_shutdown;
|
||||||
twl->otg.shutdown = twl6030_phy_shutdown;
|
twl->phy.set_suspend = twl6030_phy_suspend;
|
||||||
twl->otg.set_suspend = twl6030_phy_suspend;
|
|
||||||
twl->otg.start_srp = twl6030_start_srp;
|
otg->phy = &twl->phy;
|
||||||
|
otg->set_host = twl6030_set_host;
|
||||||
|
otg->set_peripheral = twl6030_set_peripheral;
|
||||||
|
otg->set_vbus = twl6030_set_vbus;
|
||||||
|
otg->start_srp = twl6030_start_srp;
|
||||||
|
|
||||||
/* init spinlock for workqueue */
|
/* init spinlock for workqueue */
|
||||||
spin_lock_init(&twl->lock);
|
spin_lock_init(&twl->lock);
|
||||||
|
@ -432,16 +439,17 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
|
||||||
err = twl6030_usb_ldo_init(twl);
|
err = twl6030_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);
|
||||||
|
|
||||||
INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
|
INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
|
||||||
|
|
||||||
|
@ -453,6 +461,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
|
||||||
dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
|
dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
|
||||||
twl->irq1, status);
|
twl->irq1, status);
|
||||||
device_remove_file(twl->dev, &dev_attr_vbus);
|
device_remove_file(twl->dev, &dev_attr_vbus);
|
||||||
|
kfree(otg);
|
||||||
kfree(twl);
|
kfree(twl);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -465,14 +474,15 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
|
||||||
twl->irq2, status);
|
twl->irq2, status);
|
||||||
free_irq(twl->irq1, twl);
|
free_irq(twl->irq1, twl);
|
||||||
device_remove_file(twl->dev, &dev_attr_vbus);
|
device_remove_file(twl->dev, &dev_attr_vbus);
|
||||||
|
kfree(otg);
|
||||||
kfree(twl);
|
kfree(twl);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
twl->asleep = 0;
|
twl->asleep = 0;
|
||||||
pdata->phy_init(dev);
|
pdata->phy_init(dev);
|
||||||
twl6030_phy_suspend(&twl->otg, 0);
|
twl6030_phy_suspend(&twl->phy, 0);
|
||||||
twl6030_enable_irq(&twl->otg);
|
twl6030_enable_irq(&twl->phy);
|
||||||
dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
|
dev_info(&pdev->dev, "Initialized TWL6030 USB module\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -496,6 +506,7 @@ static int __exit twl6030_usb_remove(struct platform_device *pdev)
|
||||||
pdata->phy_exit(twl->dev);
|
pdata->phy_exit(twl->dev);
|
||||||
device_remove_file(twl->dev, &dev_attr_vbus);
|
device_remove_file(twl->dev, &dev_attr_vbus);
|
||||||
cancel_work_sync(&twl->set_vbus_work);
|
cancel_work_sync(&twl->set_vbus_work);
|
||||||
|
kfree(twl->phy.otg);
|
||||||
kfree(twl);
|
kfree(twl);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue