blob: 12c1a563c3f2a79be423a58b2581586a8de23bfb [file] [log] [blame]
Wan ZongShun586dfc82009-06-13 09:14:28 +08001/*
2 * linux/driver/usb/host/ehci-w90x900.c
3 *
4 * Copyright (c) 2008 Nuvoton technology corporation.
5 *
6 * Wan ZongShun <mcuos.com@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation;version 2 of the License.
11 *
12 */
13
Manjunath Goudara60f4f82013-09-21 16:44:42 +053014#include <linux/dma-mapping.h>
15#include <linux/io.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
Wan ZongShun586dfc82009-06-13 09:14:28 +080019#include <linux/platform_device.h>
Manjunath Goudara60f4f82013-09-21 16:44:42 +053020#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22
23#include "ehci.h"
Wan ZongShun586dfc82009-06-13 09:14:28 +080024
Justin P. Mattockbd066ee2012-10-23 07:45:01 -070025/* enable phy0 and phy1 for w90p910 */
Wan ZongShun586dfc82009-06-13 09:14:28 +080026#define ENPHY (0x01<<8)
27#define PHY0_CTR (0xA4)
28#define PHY1_CTR (0xA8)
29
Manjunath Goudara60f4f82013-09-21 16:44:42 +053030#define DRIVER_DESC "EHCI w90x900 driver"
31
32static const char hcd_name[] = "ehci-w90x900 ";
33
34static struct hc_driver __read_mostly ehci_w90x900_hc_driver;
35
Bill Pemberton41ac7b32012-11-19 13:21:48 -050036static int usb_w90x900_probe(const struct hc_driver *driver,
Wan ZongShun586dfc82009-06-13 09:14:28 +080037 struct platform_device *pdev)
38{
39 struct usb_hcd *hcd;
40 struct ehci_hcd *ehci;
41 struct resource *res;
42 int retval = 0, irq;
43 unsigned long val;
44
45
46 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
47 if (!res) {
48 retval = -ENXIO;
49 goto err1;
50 }
51
52 hcd = usb_create_hcd(driver, &pdev->dev, "w90x900 EHCI");
53 if (!hcd) {
54 retval = -ENOMEM;
55 goto err1;
56 }
57
58 hcd->rsrc_start = res->start;
Joe Perches28f65c112011-06-09 09:13:32 -070059 hcd->rsrc_len = resource_size(res);
Wan ZongShun586dfc82009-06-13 09:14:28 +080060
61 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
62 retval = -EBUSY;
63 goto err2;
64 }
65
66 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
67 if (hcd->regs == NULL) {
68 retval = -EFAULT;
69 goto err3;
70 }
71
72 ehci = hcd_to_ehci(hcd);
73 ehci->caps = hcd->regs;
74 ehci->regs = hcd->regs +
Jan Anderssonc4301312011-05-03 20:11:57 +020075 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Wan ZongShun586dfc82009-06-13 09:14:28 +080076
77 /* enable PHY 0,1,the regs only apply to w90p910
78 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
79 * w90p910 IC relative to ehci->regs.
80 */
81 val = __raw_readl(ehci->regs+PHY0_CTR);
82 val |= ENPHY;
83 __raw_writel(val, ehci->regs+PHY0_CTR);
84
85 val = __raw_readl(ehci->regs+PHY1_CTR);
86 val |= ENPHY;
87 __raw_writel(val, ehci->regs+PHY1_CTR);
88
Wan ZongShun586dfc82009-06-13 09:14:28 +080089 irq = platform_get_irq(pdev, 0);
90 if (irq < 0)
91 goto err4;
92
93 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
94 if (retval != 0)
95 goto err4;
96
Peter Chen3c9740a2013-11-05 10:46:02 +080097 device_wakeup_enable(hcd->self.controller);
Wan ZongShun586dfc82009-06-13 09:14:28 +080098 return retval;
99err4:
100 iounmap(hcd->regs);
101err3:
102 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
103err2:
104 usb_put_hcd(hcd);
105err1:
106 return retval;
107}
108
Manjunath Goudara60f4f82013-09-21 16:44:42 +0530109static void usb_w90x900_remove(struct usb_hcd *hcd,
110 struct platform_device *pdev)
Wan ZongShun586dfc82009-06-13 09:14:28 +0800111{
112 usb_remove_hcd(hcd);
113 iounmap(hcd->regs);
114 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
115 usb_put_hcd(hcd);
116}
117
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500118static int ehci_w90x900_probe(struct platform_device *pdev)
Wan ZongShun586dfc82009-06-13 09:14:28 +0800119{
120 if (usb_disabled())
121 return -ENODEV;
122
123 return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev);
124}
125
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500126static int ehci_w90x900_remove(struct platform_device *pdev)
Wan ZongShun586dfc82009-06-13 09:14:28 +0800127{
128 struct usb_hcd *hcd = platform_get_drvdata(pdev);
129
130 usb_w90x900_remove(hcd, pdev);
131
132 return 0;
133}
134
135static struct platform_driver ehci_hcd_w90x900_driver = {
136 .probe = ehci_w90x900_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500137 .remove = ehci_w90x900_remove,
Wan ZongShun586dfc82009-06-13 09:14:28 +0800138 .driver = {
139 .name = "w90x900-ehci",
140 .owner = THIS_MODULE,
141 },
142};
143
Manjunath Goudara60f4f82013-09-21 16:44:42 +0530144static int __init ehci_w90X900_init(void)
145{
146 if (usb_disabled())
147 return -ENODEV;
148
149 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
150
151 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
152 return platform_driver_register(&ehci_hcd_w90x900_driver);
153}
154module_init(ehci_w90X900_init);
155
156static void __exit ehci_w90X900_cleanup(void)
157{
158 platform_driver_unregister(&ehci_hcd_w90x900_driver);
159}
160module_exit(ehci_w90X900_cleanup);
161
162MODULE_DESCRIPTION(DRIVER_DESC);
Wan ZongShun586dfc82009-06-13 09:14:28 +0800163MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
Wan ZongShun586dfc82009-06-13 09:14:28 +0800164MODULE_ALIAS("platform:w90p910-ehci");
Manjunath Goudara60f4f82013-09-21 16:44:42 +0530165MODULE_LICENSE("GPL v2");