blob: 5d1b12aad7766acc39d338c9200dfc4ca6b86601 [file] [log] [blame]
Jordan Crouse76fa9a22006-01-20 14:06:09 -08001/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
5 *
6 * Bus Glue for AMD Alchemy Au1xxx
7 *
8 * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
9 *
10 * Modified for AMD Alchemy Au1200 EHC
11 * by K.Boge <karsten.boge@amd.com>
12 *
13 * This file is licenced under the GPL.
14 */
15
16#include <linux/platform_device.h>
17#include <asm/mach-au1x00/au1000.h>
18
Jordan Crouse76fa9a22006-01-20 14:06:09 -080019#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
20#define USB_MCFG_PFEN (1<<31)
21#define USB_MCFG_RDCOMB (1<<30)
22#define USB_MCFG_SSDEN (1<<23)
23#define USB_MCFG_PHYPLLEN (1<<19)
24#define USB_MCFG_EHCCLKEN (1<<17)
25#define USB_MCFG_UCAM (1<<7)
26#define USB_MCFG_EBMEN (1<<3)
27#define USB_MCFG_EMEMEN (1<<2)
28
29#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
30
31#ifdef CONFIG_DMA_COHERENT
32#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
33 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
34 | USB_MCFG_SSDEN | USB_MCFG_UCAM \
35 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
36#else
37#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
38 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
39 | USB_MCFG_SSDEN \
40 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
41#endif
42#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
43
Jordan Crouse76fa9a22006-01-20 14:06:09 -080044extern int usb_disabled(void);
45
46/*-------------------------------------------------------------------------*/
47
48static void au1xxx_start_ehc(struct platform_device *dev)
49{
50 pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n");
51
52 /* write HW defaults again in case Yamon cleared them */
53 if (au_readl(USB_HOST_CONFIG) == 0) {
54 au_writel(0x00d02000, USB_HOST_CONFIG);
55 au_readl(USB_HOST_CONFIG);
56 udelay(1000);
57 }
58 /* enable host controller */
59 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
60 au_readl(USB_HOST_CONFIG);
61 udelay(1000);
62 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
63 USB_HOST_CONFIG);
64 au_readl(USB_HOST_CONFIG);
65 udelay(1000);
66
67 pr_debug(__FILE__ ": Clock to USB host has been enabled\n");
68}
69
70static void au1xxx_stop_ehc(struct platform_device *dev)
71{
72 pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n");
73
74 /* Disable mem */
75 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
76 udelay(1000);
77 /* Disable clock */
78 au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG),
79 USB_HOST_CONFIG);
80 au_readl(USB_HOST_CONFIG);
81}
82
83/*-------------------------------------------------------------------------*/
84
85/* configure so an HC device and id are always provided */
86/* always called with process context; sleeping is OK */
87
88/**
89 * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs
90 * Context: !in_interrupt()
91 *
92 * Allocates basic resources for this USB host controller, and
93 * then invokes the start() method for the HCD associated with it
94 * through the hotplug entry's driver_data.
95 *
96 */
97int usb_ehci_au1xxx_probe(const struct hc_driver *driver,
98 struct usb_hcd **hcd_out, struct platform_device *dev)
99{
100 int retval;
101 struct usb_hcd *hcd;
102 struct ehci_hcd *ehci;
103
104#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
105
106 /* Au1200 AB USB does not support coherent memory */
107 if (!(read_c0_prid() & 0xff)) {
Daniel Mackd14feb52006-06-23 21:36:07 +0100108 pr_info("%s: this is chip revision AB!\n", dev->name);
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800109 pr_info("%s: update your board or re-configure the kernel\n",
Daniel Mackd14feb52006-06-23 21:36:07 +0100110 dev->name);
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800111 return -ENODEV;
112 }
113#endif
114
115 au1xxx_start_ehc(dev);
116
117 if (dev->resource[1].flags != IORESOURCE_IRQ) {
118 pr_debug("resource[1] is not IORESOURCE_IRQ");
119 retval = -ENOMEM;
120 }
121 hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx");
122 if (!hcd)
123 return -ENOMEM;
124 hcd->rsrc_start = dev->resource[0].start;
125 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
126
127 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
128 pr_debug("request_mem_region failed");
129 retval = -EBUSY;
130 goto err1;
131 }
132
133 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
134 if (!hcd->regs) {
135 pr_debug("ioremap failed");
136 retval = -ENOMEM;
137 goto err2;
138 }
139
140 ehci = hcd_to_ehci(hcd);
141 ehci->caps = hcd->regs;
142 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
143 /* cache this readonly data; minimize chip reads */
144 ehci->hcs_params = readl(&ehci->caps->hcs_params);
145
146 /* ehci_hcd_init(hcd_to_ehci(hcd)); */
147
148 retval =
Thomas Gleixnerd54b5ca2006-07-01 19:29:44 -0700149 usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED);
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800150 if (retval == 0)
151 return retval;
152
153 au1xxx_stop_ehc(dev);
154 iounmap(hcd->regs);
155err2:
156 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
157err1:
158 usb_put_hcd(hcd);
159 return retval;
160}
161
162/* may be called without controller electrically present */
163/* may be called with controller, bus, and devices active */
164
165/**
166 * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
167 * @dev: USB Host Controller being removed
168 * Context: !in_interrupt()
169 *
170 * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
171 * the HCD's stop() method. It is always called from a thread
172 * context, normally "rmmod", "apmd", or something similar.
173 *
174 */
175void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
176{
177 usb_remove_hcd(hcd);
178 iounmap(hcd->regs);
179 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
180 usb_put_hcd(hcd);
181 au1xxx_stop_ehc(dev);
182}
183
184/*-------------------------------------------------------------------------*/
185
186static const struct hc_driver ehci_au1xxx_hc_driver = {
187 .description = hcd_name,
188 .product_desc = "Au1xxx EHCI",
189 .hcd_priv_size = sizeof(struct ehci_hcd),
190
191 /*
192 * generic hardware linkage
193 */
194 .irq = ehci_irq,
195 .flags = HCD_MEMORY | HCD_USB2,
196
197 /*
198 * basic lifecycle operations
199 */
200 .reset = ehci_init,
201 .start = ehci_run,
202 .stop = ehci_stop,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700203 .shutdown = ehci_shutdown,
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800204
205 /*
206 * managing i/o requests and associated device resources
207 */
208 .urb_enqueue = ehci_urb_enqueue,
209 .urb_dequeue = ehci_urb_dequeue,
210 .endpoint_disable = ehci_endpoint_disable,
211
212 /*
213 * scheduling support
214 */
215 .get_frame_number = ehci_get_frame,
216
217 /*
218 * root hub support
219 */
220 .hub_status_data = ehci_hub_status_data,
221 .hub_control = ehci_hub_control,
222#ifdef CONFIG_PM
223 .hub_suspend = ehci_hub_suspend,
224 .hub_resume = ehci_hub_resume,
225#endif
226};
227
228/*-------------------------------------------------------------------------*/
229
Daniel Mackd14feb52006-06-23 21:36:07 +0100230static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800231{
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800232 struct usb_hcd *hcd = NULL;
233 int ret;
234
235 pr_debug("In ehci_hcd_au1xxx_drv_probe\n");
236
237 if (usb_disabled())
238 return -ENODEV;
239
240 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
241 return ret;
242}
243
Daniel Mackd14feb52006-06-23 21:36:07 +0100244static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800245{
Daniel Mackd14feb52006-06-23 21:36:07 +0100246 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800247
248 usb_ehci_au1xxx_remove(hcd, pdev);
249 return 0;
250}
251
252 /*TBD*/
253/*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
254{
255 struct platform_device *pdev = to_platform_device(dev);
256 struct usb_hcd *hcd = dev_get_drvdata(dev);
257
258 return 0;
259}
260static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
261{
262 struct platform_device *pdev = to_platform_device(dev);
263 struct usb_hcd *hcd = dev_get_drvdata(dev);
264
265 return 0;
266}
267*/
Kumar Gala01cced22006-04-11 10:07:16 -0500268MODULE_ALIAS("au1xxx-ehci");
Daniel Mackd14feb52006-06-23 21:36:07 +0100269static struct platform_driver ehci_hcd_au1xxx_driver = {
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800270 .probe = ehci_hcd_au1xxx_drv_probe,
271 .remove = ehci_hcd_au1xxx_drv_remove,
Aleksey Gorelov64a21d02006-08-08 17:24:08 -0700272 .shutdown = usb_hcd_platform_shutdown,
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800273 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
274 /*.resume = ehci_hcd_au1xxx_drv_resume, */
Daniel Mackd14feb52006-06-23 21:36:07 +0100275 .driver = {
276 .name = "au1xxx-ehci",
277 .bus = &platform_bus_type
278 }
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800279};