]>
Commit | Line | Data |
---|---|---|
586dfc8c WZ |
1 | /* |
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 | ||
a60f4f81 MG |
14 | #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> | |
586dfc8c | 19 | #include <linux/platform_device.h> |
a60f4f81 MG |
20 | #include <linux/usb.h> |
21 | #include <linux/usb/hcd.h> | |
22 | ||
23 | #include "ehci.h" | |
586dfc8c | 24 | |
bd066eef | 25 | /* enable phy0 and phy1 for w90p910 */ |
586dfc8c WZ |
26 | #define ENPHY (0x01<<8) |
27 | #define PHY0_CTR (0xA4) | |
28 | #define PHY1_CTR (0xA8) | |
29 | ||
a60f4f81 MG |
30 | #define DRIVER_DESC "EHCI w90x900 driver" |
31 | ||
32 | static const char hcd_name[] = "ehci-w90x900 "; | |
33 | ||
34 | static struct hc_driver __read_mostly ehci_w90x900_hc_driver; | |
35 | ||
41ac7b3a | 36 | static int usb_w90x900_probe(const struct hc_driver *driver, |
586dfc8c WZ |
37 | 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; | |
28f65c11 | 59 | hcd->rsrc_len = resource_size(res); |
586dfc8c WZ |
60 | |
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 + | |
c430131a | 75 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
586dfc8c WZ |
76 | |
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 | ||
586dfc8c WZ |
89 | 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 | ||
586dfc8c WZ |
97 | return retval; |
98 | err4: | |
99 | iounmap(hcd->regs); | |
100 | err3: | |
101 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
102 | err2: | |
103 | usb_put_hcd(hcd); | |
104 | err1: | |
105 | return retval; | |
106 | } | |
107 | ||
a60f4f81 MG |
108 | static void usb_w90x900_remove(struct usb_hcd *hcd, |
109 | struct platform_device *pdev) | |
586dfc8c WZ |
110 | { |
111 | usb_remove_hcd(hcd); | |
112 | iounmap(hcd->regs); | |
113 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
114 | usb_put_hcd(hcd); | |
115 | } | |
116 | ||
41ac7b3a | 117 | static int ehci_w90x900_probe(struct platform_device *pdev) |
586dfc8c WZ |
118 | { |
119 | if (usb_disabled()) | |
120 | return -ENODEV; | |
121 | ||
122 | return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev); | |
123 | } | |
124 | ||
fb4e98ab | 125 | static int ehci_w90x900_remove(struct platform_device *pdev) |
586dfc8c WZ |
126 | { |
127 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
128 | ||
129 | usb_w90x900_remove(hcd, pdev); | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | static struct platform_driver ehci_hcd_w90x900_driver = { | |
135 | .probe = ehci_w90x900_probe, | |
7690417d | 136 | .remove = ehci_w90x900_remove, |
586dfc8c WZ |
137 | .driver = { |
138 | .name = "w90x900-ehci", | |
139 | .owner = THIS_MODULE, | |
140 | }, | |
141 | }; | |
142 | ||
a60f4f81 MG |
143 | static int __init ehci_w90X900_init(void) |
144 | { | |
145 | if (usb_disabled()) | |
146 | return -ENODEV; | |
147 | ||
148 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | |
149 | ||
150 | ehci_init_driver(&ehci_w90x900_hc_driver, NULL); | |
151 | return platform_driver_register(&ehci_hcd_w90x900_driver); | |
152 | } | |
153 | module_init(ehci_w90X900_init); | |
154 | ||
155 | static void __exit ehci_w90X900_cleanup(void) | |
156 | { | |
157 | platform_driver_unregister(&ehci_hcd_w90x900_driver); | |
158 | } | |
159 | module_exit(ehci_w90X900_cleanup); | |
160 | ||
161 | MODULE_DESCRIPTION(DRIVER_DESC); | |
586dfc8c | 162 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); |
586dfc8c | 163 | MODULE_ALIAS("platform:w90p910-ehci"); |
a60f4f81 | 164 | MODULE_LICENSE("GPL v2"); |