blob: 49b220dc2f9b425a5dc97620aa4d2f0fbb76b533 [file] [log] [blame]
David Daney1643acc2010-10-08 14:47:52 -07001/*
2 * EHCI HCD glue for Cavium Octeon II SOCs.
3 *
4 * Loosely based on ehci-au1xxx.c
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 * Copyright (C) 2010 Cavium Networks
11 *
12 */
13
14#include <linux/platform_device.h>
15
16#include <asm/octeon/octeon.h>
17#include <asm/octeon/cvmx-uctlx-defs.h>
18
19#define OCTEON_OHCI_HCD_NAME "octeon-ohci"
20
21/* Common clock init code. */
22void octeon2_usb_clocks_start(void);
23void octeon2_usb_clocks_stop(void);
24
25static void ohci_octeon_hw_start(void)
26{
27 union cvmx_uctlx_ohci_ctl ohci_ctl;
28
29 octeon2_usb_clocks_start();
30
31 ohci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_OHCI_CTL(0));
32 ohci_ctl.s.l2c_addr_msb = 0;
33 ohci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
34 ohci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
35 cvmx_write_csr(CVMX_UCTLX_OHCI_CTL(0), ohci_ctl.u64);
36
37}
38
39static void ohci_octeon_hw_stop(void)
40{
41 /* Undo ohci_octeon_start() */
42 octeon2_usb_clocks_stop();
43}
44
Bill Pemberton41ac7b32012-11-19 13:21:48 -050045static int ohci_octeon_start(struct usb_hcd *hcd)
David Daney1643acc2010-10-08 14:47:52 -070046{
47 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
48 int ret;
49
50 ret = ohci_init(ohci);
51
52 if (ret < 0)
53 return ret;
54
55 ret = ohci_run(ohci);
56
57 if (ret < 0) {
58 ohci_err(ohci, "can't start %s", hcd->self.bus_name);
59 ohci_stop(hcd);
60 return ret;
61 }
62
63 return 0;
64}
65
66static const struct hc_driver ohci_octeon_hc_driver = {
67 .description = hcd_name,
68 .product_desc = "Octeon OHCI",
69 .hcd_priv_size = sizeof(struct ohci_hcd),
70
71 /*
72 * generic hardware linkage
73 */
74 .irq = ohci_irq,
75 .flags = HCD_USB11 | HCD_MEMORY,
76
77 /*
78 * basic lifecycle operations
79 */
80 .start = ohci_octeon_start,
81 .stop = ohci_stop,
82 .shutdown = ohci_shutdown,
83
84 /*
85 * managing i/o requests and associated device resources
86 */
87 .urb_enqueue = ohci_urb_enqueue,
88 .urb_dequeue = ohci_urb_dequeue,
89 .endpoint_disable = ohci_endpoint_disable,
90
91 /*
92 * scheduling support
93 */
94 .get_frame_number = ohci_get_frame,
95
96 /*
97 * root hub support
98 */
99 .hub_status_data = ohci_hub_status_data,
100 .hub_control = ohci_hub_control,
101
102 .start_port_reset = ohci_start_port_reset,
103};
104
105static int ohci_octeon_drv_probe(struct platform_device *pdev)
106{
107 struct usb_hcd *hcd;
108 struct ohci_hcd *ohci;
109 void *reg_base;
110 struct resource *res_mem;
111 int irq;
112 int ret;
113
114 if (usb_disabled())
115 return -ENODEV;
116
117 irq = platform_get_irq(pdev, 0);
118 if (irq < 0) {
119 dev_err(&pdev->dev, "No irq assigned\n");
120 return -ENODEV;
121 }
122
123 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 if (res_mem == NULL) {
125 dev_err(&pdev->dev, "No register space assigned\n");
126 return -ENODEV;
127 }
128
129 /* Ohci is a 32-bit device. */
Russell Kinge1fd7342013-06-27 12:36:37 +0100130 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Russell King22d9d8e2013-06-10 16:28:49 +0100131 if (ret)
132 return ret;
David Daney1643acc2010-10-08 14:47:52 -0700133
134 hcd = usb_create_hcd(&ohci_octeon_hc_driver, &pdev->dev, "octeon");
135 if (!hcd)
136 return -ENOMEM;
137
138 hcd->rsrc_start = res_mem->start;
Joe Perches28f65c112011-06-09 09:13:32 -0700139 hcd->rsrc_len = resource_size(res_mem);
David Daney1643acc2010-10-08 14:47:52 -0700140
141 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
142 OCTEON_OHCI_HCD_NAME)) {
143 dev_err(&pdev->dev, "request_mem_region failed\n");
144 ret = -EBUSY;
145 goto err1;
146 }
147
148 reg_base = ioremap(hcd->rsrc_start, hcd->rsrc_len);
149 if (!reg_base) {
150 dev_err(&pdev->dev, "ioremap failed\n");
151 ret = -ENOMEM;
152 goto err2;
153 }
154
155 ohci_octeon_hw_start();
156
157 hcd->regs = reg_base;
158
159 ohci = hcd_to_ohci(hcd);
160
161 /* Octeon OHCI matches CPU endianness. */
162#ifdef __BIG_ENDIAN
163 ohci->flags |= OHCI_QUIRK_BE_MMIO;
164#endif
165
166 ohci_hcd_init(ohci);
167
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800168 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
David Daney1643acc2010-10-08 14:47:52 -0700169 if (ret) {
170 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
171 goto err3;
172 }
173
Peter Chen3c9740a2013-11-05 10:46:02 +0800174 device_wakeup_enable(hcd->self.controller);
175
David Daney1643acc2010-10-08 14:47:52 -0700176 platform_set_drvdata(pdev, hcd);
177
178 return 0;
179
180err3:
181 ohci_octeon_hw_stop();
182
183 iounmap(hcd->regs);
184err2:
185 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
186err1:
187 usb_put_hcd(hcd);
188 return ret;
189}
190
191static int ohci_octeon_drv_remove(struct platform_device *pdev)
192{
193 struct usb_hcd *hcd = platform_get_drvdata(pdev);
194
195 usb_remove_hcd(hcd);
196
197 ohci_octeon_hw_stop();
198 iounmap(hcd->regs);
199 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
200 usb_put_hcd(hcd);
201
David Daney1643acc2010-10-08 14:47:52 -0700202 return 0;
203}
204
205static struct platform_driver ohci_octeon_driver = {
206 .probe = ohci_octeon_drv_probe,
207 .remove = ohci_octeon_drv_remove,
208 .shutdown = usb_hcd_platform_shutdown,
209 .driver = {
210 .name = OCTEON_OHCI_HCD_NAME,
211 .owner = THIS_MODULE,
212 }
213};
214
215MODULE_ALIAS("platform:" OCTEON_OHCI_HCD_NAME);