Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / drivers / usb / host / ehci-ppc-soc.c
bloba3249078c8085af2d7aa28be8fb739c2e8fcb788
1 /*
2 * EHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 2006-2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
6 * Bus Glue for PPC On-Chip EHCI driver
7 * Tested on AMCC 440EPx
9 * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
11 * This file is licenced under the GPL.
14 #include <linux/platform_device.h>
16 extern int usb_disabled(void);
18 /* called during probe() after chip reset completes */
19 static int ehci_ppc_soc_setup(struct usb_hcd *hcd)
21 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
22 int retval;
24 retval = ehci_halt(ehci);
25 if (retval)
26 return retval;
28 retval = ehci_init(hcd);
29 if (retval)
30 return retval;
32 ehci->sbrn = 0x20;
33 return ehci_reset(ehci);
36 /**
37 * usb_ehci_ppc_soc_probe - initialize PPC-SoC-based HCDs
38 * Context: !in_interrupt()
40 * Allocates basic resources for this USB host controller, and
41 * then invokes the start() method for the HCD associated with it
42 * through the hotplug entry's driver_data.
45 int usb_ehci_ppc_soc_probe(const struct hc_driver *driver,
46 struct usb_hcd **hcd_out,
47 struct platform_device *dev)
49 int retval;
50 struct usb_hcd *hcd;
51 struct ehci_hcd *ehci;
53 if (dev->resource[1].flags != IORESOURCE_IRQ) {
54 pr_debug("resource[1] is not IORESOURCE_IRQ");
55 retval = -ENOMEM;
57 hcd = usb_create_hcd(driver, &dev->dev, "PPC-SOC EHCI");
58 if (!hcd)
59 return -ENOMEM;
60 hcd->rsrc_start = dev->resource[0].start;
61 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
63 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
64 pr_debug("request_mem_region failed");
65 retval = -EBUSY;
66 goto err1;
69 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
70 if (!hcd->regs) {
71 pr_debug("ioremap failed");
72 retval = -ENOMEM;
73 goto err2;
76 ehci = hcd_to_ehci(hcd);
77 ehci->big_endian_mmio = 1;
78 ehci->big_endian_desc = 1;
79 ehci->caps = hcd->regs;
80 ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
82 /* cache this readonly data; minimize chip reads */
83 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
85 #if defined(CONFIG_440EPX)
87 * 440EPx Errata USBH_3
88 * Fix: Enable Break Memory Transfer (BMT) in INSNREG3
90 out_be32((void *)((ulong)(&ehci->regs->command) + 0x8c), (1 << 0));
91 ehci_dbg(ehci, "Break Memory Transfer (BMT) has beed enabled!\n");
92 #endif
94 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
95 if (retval == 0)
96 return retval;
98 iounmap(hcd->regs);
99 err2:
100 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
101 err1:
102 usb_put_hcd(hcd);
103 return retval;
106 /* may be called without controller electrically present */
107 /* may be called with controller, bus, and devices active */
110 * usb_ehci_hcd_ppc_soc_remove - shutdown processing for PPC-SoC-based HCDs
111 * @dev: USB Host Controller being removed
112 * Context: !in_interrupt()
114 * Reverses the effect of usb_ehci_hcd_ppc_soc_probe(), first invoking
115 * the HCD's stop() method. It is always called from a thread
116 * context, normally "rmmod", "apmd", or something similar.
119 void usb_ehci_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *dev)
121 usb_remove_hcd(hcd);
122 iounmap(hcd->regs);
123 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
124 usb_put_hcd(hcd);
127 static const struct hc_driver ehci_ppc_soc_hc_driver = {
128 .description = hcd_name,
129 .product_desc = "PPC-SOC EHCI",
130 .hcd_priv_size = sizeof(struct ehci_hcd),
133 * generic hardware linkage
135 .irq = ehci_irq,
136 .flags = HCD_MEMORY | HCD_USB2,
139 * basic lifecycle operations
141 .reset = ehci_ppc_soc_setup,
142 .start = ehci_run,
143 .stop = ehci_stop,
144 .shutdown = ehci_shutdown,
147 * managing i/o requests and associated device resources
149 .urb_enqueue = ehci_urb_enqueue,
150 .urb_dequeue = ehci_urb_dequeue,
151 .endpoint_disable = ehci_endpoint_disable,
154 * scheduling support
156 .get_frame_number = ehci_get_frame,
159 * root hub support
161 .hub_status_data = ehci_hub_status_data,
162 .hub_control = ehci_hub_control,
163 .bus_suspend = ehci_bus_suspend,
164 .bus_resume = ehci_bus_resume,
165 .relinquish_port = ehci_relinquish_port,
168 static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev)
170 struct usb_hcd *hcd = NULL;
171 int ret;
173 pr_debug("In ehci_hcd_ppc_soc_drv_probe\n");
175 if (usb_disabled())
176 return -ENODEV;
178 ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev);
179 return ret;
182 static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
184 struct usb_hcd *hcd = platform_get_drvdata(pdev);
186 usb_ehci_ppc_soc_remove(hcd, pdev);
187 return 0;
190 MODULE_ALIAS("ppc-soc-ehci");
191 static struct platform_driver ehci_ppc_soc_driver = {
192 .probe = ehci_hcd_ppc_soc_drv_probe,
193 .remove = ehci_hcd_ppc_soc_drv_remove,
194 .shutdown = usb_hcd_platform_shutdown,
195 .driver = {
196 .name = "ppc-soc-ehci",
197 .bus = &platform_bus_type