0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <linux/kernel.h>
0021 #include <linux/module.h>
0022 #include <linux/io.h>
0023 #include <linux/platform_device.h>
0024 #include <linux/slab.h>
0025 #include <linux/usb/ulpi.h>
0026 #include <linux/pm_runtime.h>
0027 #include <linux/clk.h>
0028 #include <linux/usb.h>
0029 #include <linux/usb/hcd.h>
0030 #include <linux/of.h>
0031 #include <linux/dma-mapping.h>
0032
0033 #include "ehci.h"
0034
0035 #include <linux/platform_data/usb-omap.h>
0036
0037
0038 #define EHCI_INSNREG04 (0xA0)
0039 #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
0040 #define EHCI_INSNREG05_ULPI (0xA4)
0041 #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
0042 #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
0043 #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
0044 #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
0045 #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
0046 #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
0047
0048 #define DRIVER_DESC "OMAP-EHCI Host Controller driver"
0049
0050 static const char hcd_name[] = "ehci-omap";
0051
0052
0053
0054 struct omap_hcd {
0055 struct usb_phy *phy[OMAP3_HS_USB_PORTS];
0056 int nports;
0057 };
0058
0059 static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
0060 {
0061 __raw_writel(val, base + reg);
0062 }
0063
0064
0065
0066
0067 static struct hc_driver __read_mostly ehci_omap_hc_driver;
0068
0069 static const struct ehci_driver_overrides ehci_omap_overrides __initconst = {
0070 .extra_priv_size = sizeof(struct omap_hcd),
0071 };
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 static int ehci_hcd_omap_probe(struct platform_device *pdev)
0082 {
0083 struct device *dev = &pdev->dev;
0084 struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
0085 struct resource *res;
0086 struct usb_hcd *hcd;
0087 void __iomem *regs;
0088 int ret;
0089 int irq;
0090 int i;
0091 struct omap_hcd *omap;
0092
0093 if (usb_disabled())
0094 return -ENODEV;
0095
0096 if (!dev->parent) {
0097 dev_err(dev, "Missing parent device\n");
0098 return -ENODEV;
0099 }
0100
0101
0102 if (dev->of_node) {
0103 pdata = dev_get_platdata(dev->parent);
0104 dev->platform_data = pdata;
0105 }
0106
0107 if (!pdata) {
0108 dev_err(dev, "Missing platform data\n");
0109 return -ENODEV;
0110 }
0111
0112 irq = platform_get_irq(pdev, 0);
0113 if (irq < 0)
0114 return irq;
0115
0116 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0117 regs = devm_ioremap_resource(dev, res);
0118 if (IS_ERR(regs))
0119 return PTR_ERR(regs);
0120
0121
0122
0123
0124
0125
0126 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
0127 if (ret)
0128 return ret;
0129
0130 ret = -ENODEV;
0131 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
0132 dev_name(dev));
0133 if (!hcd) {
0134 dev_err(dev, "Failed to create HCD\n");
0135 return -ENOMEM;
0136 }
0137
0138 hcd->rsrc_start = res->start;
0139 hcd->rsrc_len = resource_size(res);
0140 hcd->regs = regs;
0141 hcd_to_ehci(hcd)->caps = regs;
0142
0143 omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
0144 omap->nports = pdata->nports;
0145
0146 platform_set_drvdata(pdev, hcd);
0147
0148
0149 for (i = 0 ; i < omap->nports ; i++) {
0150 struct usb_phy *phy;
0151
0152
0153 phy = devm_usb_get_phy_by_phandle(dev, "phys", i);
0154 if (IS_ERR(phy)) {
0155 ret = PTR_ERR(phy);
0156 if (ret == -ENODEV) {
0157 phy = NULL;
0158 continue;
0159 }
0160
0161 if (ret != -EPROBE_DEFER)
0162 dev_err(dev, "Can't get PHY for port %d: %d\n",
0163 i, ret);
0164 goto err_phy;
0165 }
0166
0167 omap->phy[i] = phy;
0168
0169 if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY) {
0170 usb_phy_init(omap->phy[i]);
0171
0172 usb_phy_set_suspend(omap->phy[i], 0);
0173 }
0174 }
0175
0176 pm_runtime_enable(dev);
0177 pm_runtime_get_sync(dev);
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 ehci_write(regs, EHCI_INSNREG04,
0189 EHCI_INSNREG04_DISABLE_UNSUSPEND);
0190
0191 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
0192 if (ret) {
0193 dev_err(dev, "failed to add hcd with err %d\n", ret);
0194 goto err_pm_runtime;
0195 }
0196 device_wakeup_enable(hcd->self.controller);
0197
0198
0199
0200
0201
0202
0203
0204 for (i = 0; i < omap->nports; i++) {
0205 if (!omap->phy[i] ||
0206 pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY)
0207 continue;
0208
0209 usb_phy_init(omap->phy[i]);
0210
0211 usb_phy_set_suspend(omap->phy[i], 0);
0212 }
0213
0214 return 0;
0215
0216 err_pm_runtime:
0217 pm_runtime_put_sync(dev);
0218 pm_runtime_disable(dev);
0219
0220 err_phy:
0221 for (i = 0; i < omap->nports; i++) {
0222 if (omap->phy[i])
0223 usb_phy_shutdown(omap->phy[i]);
0224 }
0225
0226 usb_put_hcd(hcd);
0227
0228 return ret;
0229 }
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 static int ehci_hcd_omap_remove(struct platform_device *pdev)
0241 {
0242 struct device *dev = &pdev->dev;
0243 struct usb_hcd *hcd = dev_get_drvdata(dev);
0244 struct omap_hcd *omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
0245 int i;
0246
0247 usb_remove_hcd(hcd);
0248
0249 for (i = 0; i < omap->nports; i++) {
0250 if (omap->phy[i])
0251 usb_phy_shutdown(omap->phy[i]);
0252 }
0253
0254 usb_put_hcd(hcd);
0255 pm_runtime_put_sync(dev);
0256 pm_runtime_disable(dev);
0257
0258 return 0;
0259 }
0260
0261 static const struct of_device_id omap_ehci_dt_ids[] = {
0262 { .compatible = "ti,ehci-omap" },
0263 { }
0264 };
0265
0266 MODULE_DEVICE_TABLE(of, omap_ehci_dt_ids);
0267
0268 static struct platform_driver ehci_hcd_omap_driver = {
0269 .probe = ehci_hcd_omap_probe,
0270 .remove = ehci_hcd_omap_remove,
0271 .shutdown = usb_hcd_platform_shutdown,
0272
0273
0274 .driver = {
0275 .name = hcd_name,
0276 .of_match_table = omap_ehci_dt_ids,
0277 }
0278 };
0279
0280
0281
0282 static int __init ehci_omap_init(void)
0283 {
0284 if (usb_disabled())
0285 return -ENODEV;
0286
0287 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
0288
0289 ehci_init_driver(&ehci_omap_hc_driver, &ehci_omap_overrides);
0290 return platform_driver_register(&ehci_hcd_omap_driver);
0291 }
0292 module_init(ehci_omap_init);
0293
0294 static void __exit ehci_omap_cleanup(void)
0295 {
0296 platform_driver_unregister(&ehci_hcd_omap_driver);
0297 }
0298 module_exit(ehci_omap_cleanup);
0299
0300 MODULE_ALIAS("platform:ehci-omap");
0301 MODULE_AUTHOR("Texas Instruments, Inc.");
0302 MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
0303 MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
0304
0305 MODULE_DESCRIPTION(DRIVER_DESC);
0306 MODULE_LICENSE("GPL");