blob: 9b4697add3130b4e482bc10483ff774ccc7a57de [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
44#endif /* Au1200 */
45
46extern int usb_disabled(void);
47
48/*-------------------------------------------------------------------------*/
49
50static void au1xxx_start_ehc(struct platform_device *dev)
51{
52 pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n");
53
54 /* write HW defaults again in case Yamon cleared them */
55 if (au_readl(USB_HOST_CONFIG) == 0) {
56 au_writel(0x00d02000, USB_HOST_CONFIG);
57 au_readl(USB_HOST_CONFIG);
58 udelay(1000);
59 }
60 /* enable host controller */
61 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
62 au_readl(USB_HOST_CONFIG);
63 udelay(1000);
64 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
65 USB_HOST_CONFIG);
66 au_readl(USB_HOST_CONFIG);
67 udelay(1000);
68
69 pr_debug(__FILE__ ": Clock to USB host has been enabled\n");
70}
71
72static void au1xxx_stop_ehc(struct platform_device *dev)
73{
74 pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n");
75
76 /* Disable mem */
77 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
78 udelay(1000);
79 /* Disable clock */
80 au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG),
81 USB_HOST_CONFIG);
82 au_readl(USB_HOST_CONFIG);
83}
84
85/*-------------------------------------------------------------------------*/
86
87/* configure so an HC device and id are always provided */
88/* always called with process context; sleeping is OK */
89
90/**
91 * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs
92 * Context: !in_interrupt()
93 *
94 * Allocates basic resources for this USB host controller, and
95 * then invokes the start() method for the HCD associated with it
96 * through the hotplug entry's driver_data.
97 *
98 */
99int usb_ehci_au1xxx_probe(const struct hc_driver *driver,
100 struct usb_hcd **hcd_out, struct platform_device *dev)
101{
102 int retval;
103 struct usb_hcd *hcd;
104 struct ehci_hcd *ehci;
105
106#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
107
108 /* Au1200 AB USB does not support coherent memory */
109 if (!(read_c0_prid() & 0xff)) {
110 pr_info("%s: this is chip revision AB!\n", dev->dev.name);
111 pr_info("%s: update your board or re-configure the kernel\n",
112 dev->dev.name);
113 return -ENODEV;
114 }
115#endif
116
117 au1xxx_start_ehc(dev);
118
119 if (dev->resource[1].flags != IORESOURCE_IRQ) {
120 pr_debug("resource[1] is not IORESOURCE_IRQ");
121 retval = -ENOMEM;
122 }
123 hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx");
124 if (!hcd)
125 return -ENOMEM;
126 hcd->rsrc_start = dev->resource[0].start;
127 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
128
129 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
130 pr_debug("request_mem_region failed");
131 retval = -EBUSY;
132 goto err1;
133 }
134
135 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
136 if (!hcd->regs) {
137 pr_debug("ioremap failed");
138 retval = -ENOMEM;
139 goto err2;
140 }
141
142 ehci = hcd_to_ehci(hcd);
143 ehci->caps = hcd->regs;
144 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
145 /* cache this readonly data; minimize chip reads */
146 ehci->hcs_params = readl(&ehci->caps->hcs_params);
147
148 /* ehci_hcd_init(hcd_to_ehci(hcd)); */
149
150 retval =
151 usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT | SA_SHIRQ);
152 if (retval == 0)
153 return retval;
154
155 au1xxx_stop_ehc(dev);
156 iounmap(hcd->regs);
157err2:
158 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
159err1:
160 usb_put_hcd(hcd);
161 return retval;
162}
163
164/* may be called without controller electrically present */
165/* may be called with controller, bus, and devices active */
166
167/**
168 * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
169 * @dev: USB Host Controller being removed
170 * Context: !in_interrupt()
171 *
172 * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
173 * the HCD's stop() method. It is always called from a thread
174 * context, normally "rmmod", "apmd", or something similar.
175 *
176 */
177void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
178{
179 usb_remove_hcd(hcd);
180 iounmap(hcd->regs);
181 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
182 usb_put_hcd(hcd);
183 au1xxx_stop_ehc(dev);
184}
185
186/*-------------------------------------------------------------------------*/
187
188static const struct hc_driver ehci_au1xxx_hc_driver = {
189 .description = hcd_name,
190 .product_desc = "Au1xxx EHCI",
191 .hcd_priv_size = sizeof(struct ehci_hcd),
192
193 /*
194 * generic hardware linkage
195 */
196 .irq = ehci_irq,
197 .flags = HCD_MEMORY | HCD_USB2,
198
199 /*
200 * basic lifecycle operations
201 */
202 .reset = ehci_init,
203 .start = ehci_run,
204 .stop = ehci_stop,
205
206 /*
207 * managing i/o requests and associated device resources
208 */
209 .urb_enqueue = ehci_urb_enqueue,
210 .urb_dequeue = ehci_urb_dequeue,
211 .endpoint_disable = ehci_endpoint_disable,
212
213 /*
214 * scheduling support
215 */
216 .get_frame_number = ehci_get_frame,
217
218 /*
219 * root hub support
220 */
221 .hub_status_data = ehci_hub_status_data,
222 .hub_control = ehci_hub_control,
223#ifdef CONFIG_PM
224 .hub_suspend = ehci_hub_suspend,
225 .hub_resume = ehci_hub_resume,
226#endif
227};
228
229/*-------------------------------------------------------------------------*/
230
231static int ehci_hcd_au1xxx_drv_probe(struct device *dev)
232{
233 struct platform_device *pdev = to_platform_device(dev);
234 struct usb_hcd *hcd = NULL;
235 int ret;
236
237 pr_debug("In ehci_hcd_au1xxx_drv_probe\n");
238
239 if (usb_disabled())
240 return -ENODEV;
241
242 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
243 return ret;
244}
245
246static int ehci_hcd_au1xxx_drv_remove(struct device *dev)
247{
248 struct platform_device *pdev = to_platform_device(dev);
249 struct usb_hcd *hcd = dev_get_drvdata(dev);
250
251 usb_ehci_au1xxx_remove(hcd, pdev);
252 return 0;
253}
254
255 /*TBD*/
256/*static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
257{
258 struct platform_device *pdev = to_platform_device(dev);
259 struct usb_hcd *hcd = dev_get_drvdata(dev);
260
261 return 0;
262}
263static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
264{
265 struct platform_device *pdev = to_platform_device(dev);
266 struct usb_hcd *hcd = dev_get_drvdata(dev);
267
268 return 0;
269}
270*/
Kumar Gala01cced22006-04-11 10:07:16 -0500271MODULE_ALIAS("au1xxx-ehci");
272/* FIXME use "struct platform_driver" */
Jordan Crouse76fa9a22006-01-20 14:06:09 -0800273static struct device_driver ehci_hcd_au1xxx_driver = {
274 .name = "au1xxx-ehci",
275 .bus = &platform_bus_type,
276 .probe = ehci_hcd_au1xxx_drv_probe,
277 .remove = ehci_hcd_au1xxx_drv_remove,
278 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
279 /*.resume = ehci_hcd_au1xxx_drv_resume, */
280};