Commit | Line | Data |
---|---|---|
23106343 J |
1 | /* |
2 | * EHCI HCD for Netlogic XLS processors. | |
3 | * | |
4 | * (C) Copyright 2011 Netlogic Microsystems Inc. | |
5 | * | |
6 | * Based on various ehci-*.c drivers | |
7 | * | |
8 | * This file is subject to the terms and conditions of the GNU General Public | |
9 | * License. See the file COPYING in the main directory of this archive for | |
10 | * more details. | |
11 | */ | |
12 | ||
13 | #include <linux/platform_device.h> | |
14 | ||
15 | static int ehci_xls_setup(struct usb_hcd *hcd) | |
16 | { | |
17 | int retval; | |
18 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | |
19 | ||
20 | ehci->caps = hcd->regs; | |
21 | ehci->regs = hcd->regs + | |
22 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | |
23 | dbg_hcs_params(ehci, "reset"); | |
24 | dbg_hcc_params(ehci, "reset"); | |
25 | ||
26 | /* cache this readonly data; minimize chip reads */ | |
27 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | |
28 | ||
29 | retval = ehci_halt(ehci); | |
30 | if (retval) | |
31 | return retval; | |
32 | ||
33 | /* data structure init */ | |
34 | retval = ehci_init(hcd); | |
35 | if (retval) | |
36 | return retval; | |
37 | ||
38 | ehci_reset(ehci); | |
39 | ||
40 | return retval; | |
41 | } | |
42 | ||
43 | int ehci_xls_probe_internal(const struct hc_driver *driver, | |
44 | struct platform_device *pdev) | |
45 | { | |
46 | struct usb_hcd *hcd; | |
47 | struct resource *res; | |
48 | int retval, irq; | |
49 | ||
50 | /* Get our IRQ from an earlier registered Platform Resource */ | |
51 | irq = platform_get_irq(pdev, 0); | |
52 | if (irq < 0) { | |
53 | dev_err(&pdev->dev, "Found HC with no IRQ. Check %s setup!\n", | |
54 | dev_name(&pdev->dev)); | |
55 | return -ENODEV; | |
56 | } | |
57 | ||
58 | /* Get our Memory Handle */ | |
59 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
60 | if (!res) { | |
61 | dev_err(&pdev->dev, "Error: MMIO Handle %s setup!\n", | |
62 | dev_name(&pdev->dev)); | |
63 | return -ENODEV; | |
64 | } | |
65 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); | |
66 | if (!hcd) { | |
67 | retval = -ENOMEM; | |
68 | goto err1; | |
69 | } | |
70 | ||
71 | hcd->rsrc_start = res->start; | |
72 | hcd->rsrc_len = res->end - res->start + 1; | |
73 | ||
74 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | |
75 | driver->description)) { | |
76 | dev_dbg(&pdev->dev, "controller already in use\n"); | |
77 | retval = -EBUSY; | |
78 | goto err2; | |
79 | } | |
80 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | |
81 | ||
82 | if (hcd->regs == NULL) { | |
83 | dev_dbg(&pdev->dev, "error mapping memory\n"); | |
84 | retval = -EFAULT; | |
85 | goto err3; | |
86 | } | |
87 | ||
88 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | |
89 | if (retval != 0) | |
90 | goto err4; | |
91 | return retval; | |
92 | ||
93 | err4: | |
94 | iounmap(hcd->regs); | |
95 | err3: | |
96 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
97 | err2: | |
98 | usb_put_hcd(hcd); | |
99 | err1: | |
100 | dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), | |
101 | retval); | |
102 | return retval; | |
103 | } | |
104 | ||
105 | static struct hc_driver ehci_xls_hc_driver = { | |
106 | .description = hcd_name, | |
107 | .product_desc = "XLS EHCI Host Controller", | |
108 | .hcd_priv_size = sizeof(struct ehci_hcd), | |
109 | .irq = ehci_irq, | |
110 | .flags = HCD_USB2 | HCD_MEMORY, | |
111 | .reset = ehci_xls_setup, | |
112 | .start = ehci_run, | |
113 | .stop = ehci_stop, | |
114 | .shutdown = ehci_shutdown, | |
115 | ||
116 | .urb_enqueue = ehci_urb_enqueue, | |
117 | .urb_dequeue = ehci_urb_dequeue, | |
118 | .endpoint_disable = ehci_endpoint_disable, | |
119 | .endpoint_reset = ehci_endpoint_reset, | |
120 | ||
121 | .get_frame_number = ehci_get_frame, | |
122 | ||
123 | .hub_status_data = ehci_hub_status_data, | |
124 | .hub_control = ehci_hub_control, | |
125 | .bus_suspend = ehci_bus_suspend, | |
126 | .bus_resume = ehci_bus_resume, | |
127 | .relinquish_port = ehci_relinquish_port, | |
128 | .port_handed_over = ehci_port_handed_over, | |
129 | ||
130 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | |
131 | }; | |
132 | ||
133 | static int ehci_xls_probe(struct platform_device *pdev) | |
134 | { | |
135 | if (usb_disabled()) | |
136 | return -ENODEV; | |
137 | ||
138 | return ehci_xls_probe_internal(&ehci_xls_hc_driver, pdev); | |
139 | } | |
140 | ||
141 | static int ehci_xls_remove(struct platform_device *pdev) | |
142 | { | |
143 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | |
144 | ||
145 | usb_remove_hcd(hcd); | |
146 | iounmap(hcd->regs); | |
147 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | |
148 | usb_put_hcd(hcd); | |
149 | return 0; | |
150 | } | |
151 | ||
152 | MODULE_ALIAS("ehci-xls"); | |
153 | ||
154 | static struct platform_driver ehci_xls_driver = { | |
155 | .probe = ehci_xls_probe, | |
156 | .remove = ehci_xls_remove, | |
157 | .shutdown = usb_hcd_platform_shutdown, | |
158 | .driver = { | |
159 | .name = "ehci-xls", | |
160 | }, | |
161 | }; |