Merge 2.6.38-rc5 into staging-next
[deliverable/linux.git] / drivers / usb / host / ehci-au1xxx.c
CommitLineData
76fa9a24
JC
1/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
76fa9a24
JC
4 * Bus Glue for AMD Alchemy Au1xxx
5 *
6 * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
7 *
8 * Modified for AMD Alchemy Au1200 EHC
9 * by K.Boge <karsten.boge@amd.com>
10 *
11 * This file is licenced under the GPL.
12 */
13
14#include <linux/platform_device.h>
15#include <asm/mach-au1x00/au1000.h>
16
76fa9a24
JC
17#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
18#define USB_MCFG_PFEN (1<<31)
19#define USB_MCFG_RDCOMB (1<<30)
20#define USB_MCFG_SSDEN (1<<23)
21#define USB_MCFG_PHYPLLEN (1<<19)
53c81a34 22#define USB_MCFG_UCECLKEN (1<<18)
76fa9a24 23#define USB_MCFG_EHCCLKEN (1<<17)
53c81a34 24#ifdef CONFIG_DMA_COHERENT
76fa9a24 25#define USB_MCFG_UCAM (1<<7)
53c81a34
ML
26#else
27#define USB_MCFG_UCAM (0)
28#endif
76fa9a24
JC
29#define USB_MCFG_EBMEN (1<<3)
30#define USB_MCFG_EMEMEN (1<<2)
31
53c81a34
ML
32#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
33#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
34 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
35 USB_MCFG_UCAM | USB_MCFG_EBMEN | \
36 USB_MCFG_EMEMEN)
76fa9a24 37
76fa9a24
JC
38#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39
76fa9a24
JC
40extern int usb_disabled(void);
41
53c81a34 42static void au1xxx_start_ehc(void)
76fa9a24 43{
53c81a34
ML
44 /* enable clock to EHCI block and HS PHY PLL*/
45 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
46 au_sync();
76fa9a24
JC
47 udelay(1000);
48
53c81a34
ML
49 /* enable EHCI mmio */
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
76fa9a24
JC
53}
54
53c81a34 55static void au1xxx_stop_ehc(void)
76fa9a24 56{
53c81a34 57 unsigned long c;
76fa9a24
JC
58
59 /* Disable mem */
53c81a34
ML
60 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
76fa9a24 62 udelay(1000);
53c81a34
ML
63
64 /* Disable EHC clock. If the HS PHY is unused disable it too. */
65 c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
66 if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */
67 c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */
68 au_writel(c, USB_HOST_CONFIG);
69 au_sync();
76fa9a24
JC
70}
71
9757de38
ML
72static int au1xxx_ehci_setup(struct usb_hcd *hcd)
73{
74 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
75 int ret = ehci_init(hcd);
76
77 ehci->need_io_watchdog = 0;
78 return ret;
79}
80
53c81a34
ML
81static const struct hc_driver ehci_au1xxx_hc_driver = {
82 .description = hcd_name,
83 .product_desc = "Au1xxx EHCI",
84 .hcd_priv_size = sizeof(struct ehci_hcd),
76fa9a24 85
53c81a34
ML
86 /*
87 * generic hardware linkage
88 */
89 .irq = ehci_irq,
90 .flags = HCD_MEMORY | HCD_USB2,
76fa9a24 91
53c81a34
ML
92 /*
93 * basic lifecycle operations
94 *
95 * FIXME -- ehci_init() doesn't do enough here.
96 * See ehci-ppc-soc for a complete implementation.
97 */
9757de38 98 .reset = au1xxx_ehci_setup,
53c81a34
ML
99 .start = ehci_run,
100 .stop = ehci_stop,
101 .shutdown = ehci_shutdown,
102
103 /*
104 * managing i/o requests and associated device resources
105 */
106 .urb_enqueue = ehci_urb_enqueue,
107 .urb_dequeue = ehci_urb_dequeue,
108 .endpoint_disable = ehci_endpoint_disable,
b18ffd49 109 .endpoint_reset = ehci_endpoint_reset,
53c81a34
ML
110
111 /*
112 * scheduling support
113 */
114 .get_frame_number = ehci_get_frame,
115
116 /*
117 * root hub support
118 */
119 .hub_status_data = ehci_hub_status_data,
120 .hub_control = ehci_hub_control,
121 .bus_suspend = ehci_bus_suspend,
122 .bus_resume = ehci_bus_resume,
123 .relinquish_port = ehci_relinquish_port,
124 .port_handed_over = ehci_port_handed_over,
914b7012
AS
125
126 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
53c81a34
ML
127};
128
129static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
76fa9a24 130{
76fa9a24
JC
131 struct usb_hcd *hcd;
132 struct ehci_hcd *ehci;
1f141ca2 133 struct resource *res;
53c81a34 134 int ret;
76fa9a24 135
53c81a34
ML
136 if (usb_disabled())
137 return -ENODEV;
76fa9a24 138
53c81a34 139#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
76fa9a24
JC
140 /* Au1200 AB USB does not support coherent memory */
141 if (!(read_c0_prid() & 0xff)) {
53c81a34
ML
142 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
143 printk(KERN_INFO "%s: update your board or re-configure"
144 " the kernel\n", pdev->name);
76fa9a24
JC
145 return -ENODEV;
146 }
147#endif
148
53c81a34 149 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
76fa9a24 150 pr_debug("resource[1] is not IORESOURCE_IRQ");
53c81a34 151 return -ENOMEM;
76fa9a24 152 }
53c81a34 153 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
76fa9a24
JC
154 if (!hcd)
155 return -ENOMEM;
53c81a34 156
1f141ca2
HS
157 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
158 hcd->rsrc_start = res->start;
159 hcd->rsrc_len = resource_size(res);
76fa9a24
JC
160
161 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
162 pr_debug("request_mem_region failed");
53c81a34 163 ret = -EBUSY;
76fa9a24
JC
164 goto err1;
165 }
166
167 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
168 if (!hcd->regs) {
169 pr_debug("ioremap failed");
53c81a34 170 ret = -ENOMEM;
76fa9a24
JC
171 goto err2;
172 }
173
53c81a34
ML
174 au1xxx_start_ehc();
175
76fa9a24
JC
176 ehci = hcd_to_ehci(hcd);
177 ehci->caps = hcd->regs;
178 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
179 /* cache this readonly data; minimize chip reads */
180 ehci->hcs_params = readl(&ehci->caps->hcs_params);
181
53c81a34
ML
182 ret = usb_add_hcd(hcd, pdev->resource[1].start,
183 IRQF_DISABLED | IRQF_SHARED);
184 if (ret == 0) {
185 platform_set_drvdata(pdev, hcd);
186 return ret;
187 }
76fa9a24 188
53c81a34 189 au1xxx_stop_ehc();
76fa9a24
JC
190 iounmap(hcd->regs);
191err2:
192 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
193err1:
194 usb_put_hcd(hcd);
53c81a34 195 return ret;
76fa9a24
JC
196}
197
53c81a34 198static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
76fa9a24 199{
53c81a34
ML
200 struct usb_hcd *hcd = platform_get_drvdata(pdev);
201
76fa9a24
JC
202 usb_remove_hcd(hcd);
203 iounmap(hcd->regs);
204 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
205 usb_put_hcd(hcd);
53c81a34
ML
206 au1xxx_stop_ehc();
207 platform_set_drvdata(pdev, NULL);
76fa9a24 208
76fa9a24
JC
209 return 0;
210}
211
42bfc7b4 212#ifdef CONFIG_PM
807fcb5e 213static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
76fa9a24 214{
807fcb5e 215 struct usb_hcd *hcd = dev_get_drvdata(dev);
42bfc7b4
ML
216 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
217 unsigned long flags;
218 int rc;
76fa9a24
JC
219
220 return 0;
42bfc7b4
ML
221 rc = 0;
222
223 if (time_before(jiffies, ehci->next_statechange))
224 msleep(10);
225
226 /* Root hub was already suspended. Disable irq emission and
16032c4f
AS
227 * mark HW unaccessible. The PM and USB cores make sure that
228 * the root hub is either suspended or stopped.
42bfc7b4 229 */
4147200d 230 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
148fc55f 231 spin_lock_irqsave(&ehci->lock, flags);
42bfc7b4
ML
232 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
233 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
234
42bfc7b4
ML
235 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
236
237 au1xxx_stop_ehc();
42bfc7b4
ML
238 spin_unlock_irqrestore(&ehci->lock, flags);
239
240 // could save FLADJ in case of Vaux power loss
241 // ... we'd only use it to handle clock skew
242
243 return rc;
76fa9a24 244}
42bfc7b4 245
807fcb5e 246static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
76fa9a24 247{
807fcb5e 248 struct usb_hcd *hcd = dev_get_drvdata(dev);
42bfc7b4
ML
249 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
250
251 au1xxx_start_ehc();
252
253 // maybe restore FLADJ
254
255 if (time_before(jiffies, ehci->next_statechange))
256 msleep(100);
257
258 /* Mark hardware accessible again as we are out of D3 state by now */
259 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
260
261 /* If CF is still set, we maintained PCI Vaux power.
262 * Just undo the effect of ehci_pci_suspend().
263 */
264 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
265 int mask = INTR_MASK;
266
16032c4f 267 ehci_prepare_ports_for_controller_resume(ehci);
42bfc7b4
ML
268 if (!hcd->self.root_hub->do_remote_wakeup)
269 mask &= ~STS_PCD;
270 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
271 ehci_readl(ehci, &ehci->regs->intr_enable);
272 return 0;
273 }
274
275 ehci_dbg(ehci, "lost power, restarting\n");
276 usb_root_hub_lost_power(hcd->self.root_hub);
277
278 /* Else reset, to cope with power loss or flush-to-storage
279 * style "resume" having let BIOS kick in during reboot.
280 */
281 (void) ehci_halt(ehci);
282 (void) ehci_reset(ehci);
283
284 /* emptying the schedule aborts any urbs */
285 spin_lock_irq(&ehci->lock);
286 if (ehci->reclaim)
287 end_unlink_async(ehci);
288 ehci_work(ehci);
289 spin_unlock_irq(&ehci->lock);
290
291 ehci_writel(ehci, ehci->command, &ehci->regs->command);
292 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
293 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
294
295 /* here we "know" root ports should always stay powered */
296 ehci_port_power(ehci, 1);
297
298 hcd->state = HC_STATE_SUSPENDED;
76fa9a24
JC
299
300 return 0;
301}
42bfc7b4 302
47145210 303static const struct dev_pm_ops au1xxx_ehci_pmops = {
807fcb5e
ML
304 .suspend = ehci_hcd_au1xxx_drv_suspend,
305 .resume = ehci_hcd_au1xxx_drv_resume,
306};
307
308#define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
309
42bfc7b4 310#else
807fcb5e 311#define AU1XXX_EHCI_PMOPS NULL
42bfc7b4 312#endif
53c81a34 313
d14feb5e 314static struct platform_driver ehci_hcd_au1xxx_driver = {
53c81a34
ML
315 .probe = ehci_hcd_au1xxx_drv_probe,
316 .remove = ehci_hcd_au1xxx_drv_remove,
317 .shutdown = usb_hcd_platform_shutdown,
d14feb5e 318 .driver = {
53c81a34
ML
319 .name = "au1xxx-ehci",
320 .owner = THIS_MODULE,
807fcb5e 321 .pm = AU1XXX_EHCI_PMOPS,
d14feb5e 322 }
76fa9a24 323};
53c81a34
ML
324
325MODULE_ALIAS("platform:au1xxx-ehci");
This page took 0.723337 seconds and 5 git commands to generate.