blob: 9051439039a704733e08ea6dba20eefeeb9da430 [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_EHCI_HCD_NAME "octeon-ehci"
20
21/* Common clock init code. */
22void octeon2_usb_clocks_start(void);
23void octeon2_usb_clocks_stop(void);
24
25static void ehci_octeon_start(void)
26{
27 union cvmx_uctlx_ehci_ctl ehci_ctl;
28
29 octeon2_usb_clocks_start();
30
31 ehci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_EHCI_CTL(0));
32 /* Use 64-bit addressing. */
33 ehci_ctl.s.ehci_64b_addr_en = 1;
34 ehci_ctl.s.l2c_addr_msb = 0;
35 ehci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
36 ehci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
37 cvmx_write_csr(CVMX_UCTLX_EHCI_CTL(0), ehci_ctl.u64);
38}
39
40static void ehci_octeon_stop(void)
41{
42 octeon2_usb_clocks_stop();
43}
44
45static const struct hc_driver ehci_octeon_hc_driver = {
46 .description = hcd_name,
47 .product_desc = "Octeon EHCI",
48 .hcd_priv_size = sizeof(struct ehci_hcd),
49
50 /*
51 * generic hardware linkage
52 */
53 .irq = ehci_irq,
Ming Lei428aac82013-07-03 22:53:11 +080054 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
David Daney1643acc2010-10-08 14:47:52 -070055
56 /*
57 * basic lifecycle operations
58 */
Alan Stern1a49e2a2012-07-09 15:55:14 -040059 .reset = ehci_setup,
David Daney1643acc2010-10-08 14:47:52 -070060 .start = ehci_run,
61 .stop = ehci_stop,
62 .shutdown = ehci_shutdown,
63
64 /*
65 * managing i/o requests and associated device resources
66 */
67 .urb_enqueue = ehci_urb_enqueue,
68 .urb_dequeue = ehci_urb_dequeue,
69 .endpoint_disable = ehci_endpoint_disable,
70 .endpoint_reset = ehci_endpoint_reset,
71
72 /*
73 * scheduling support
74 */
75 .get_frame_number = ehci_get_frame,
76
77 /*
78 * root hub support
79 */
80 .hub_status_data = ehci_hub_status_data,
81 .hub_control = ehci_hub_control,
82 .bus_suspend = ehci_bus_suspend,
83 .bus_resume = ehci_bus_resume,
84 .relinquish_port = ehci_relinquish_port,
85 .port_handed_over = ehci_port_handed_over,
86
87 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
88};
89
90static u64 ehci_octeon_dma_mask = DMA_BIT_MASK(64);
91
92static int ehci_octeon_drv_probe(struct platform_device *pdev)
93{
94 struct usb_hcd *hcd;
95 struct ehci_hcd *ehci;
96 struct resource *res_mem;
97 int irq;
98 int ret;
99
100 if (usb_disabled())
101 return -ENODEV;
102
103 irq = platform_get_irq(pdev, 0);
104 if (irq < 0) {
105 dev_err(&pdev->dev, "No irq assigned\n");
106 return -ENODEV;
107 }
108
109 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
110 if (res_mem == NULL) {
111 dev_err(&pdev->dev, "No register space assigned\n");
112 return -ENODEV;
113 }
114
115 /*
116 * We can DMA from anywhere. But the descriptors must be in
117 * the lower 4GB.
118 */
David Daney1643acc2010-10-08 14:47:52 -0700119 pdev->dev.dma_mask = &ehci_octeon_dma_mask;
Russell King22d9d8e2013-06-10 16:28:49 +0100120 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
121 if (ret)
122 return ret;
David Daney1643acc2010-10-08 14:47:52 -0700123
124 hcd = usb_create_hcd(&ehci_octeon_hc_driver, &pdev->dev, "octeon");
125 if (!hcd)
126 return -ENOMEM;
127
128 hcd->rsrc_start = res_mem->start;
Joe Perches28f65c112011-06-09 09:13:32 -0700129 hcd->rsrc_len = resource_size(res_mem);
David Daney1643acc2010-10-08 14:47:52 -0700130
Jingoo Han49aa57b2013-12-11 16:20:06 +0900131 hcd->regs = devm_ioremap_resource(&pdev->dev, res_mem);
132 if (IS_ERR(hcd->regs)) {
133 ret = PTR_ERR(hcd->regs);
David Daney1643acc2010-10-08 14:47:52 -0700134 goto err1;
135 }
136
David Daney1643acc2010-10-08 14:47:52 -0700137 ehci_octeon_start();
138
139 ehci = hcd_to_ehci(hcd);
140
141 /* Octeon EHCI matches CPU endianness. */
142#ifdef __BIG_ENDIAN
143 ehci->big_endian_mmio = 1;
144#endif
145
146 ehci->caps = hcd->regs;
Geoff Levand876e0df2011-11-22 18:04:45 -0800147
Yong Zhangb5dd18d2011-09-07 16:10:52 +0800148 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
David Daney1643acc2010-10-08 14:47:52 -0700149 if (ret) {
150 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
Jingoo Han49aa57b2013-12-11 16:20:06 +0900151 goto err2;
David Daney1643acc2010-10-08 14:47:52 -0700152 }
Peter Chen3c9740a2013-11-05 10:46:02 +0800153 device_wakeup_enable(hcd->self.controller);
David Daney1643acc2010-10-08 14:47:52 -0700154
155 platform_set_drvdata(pdev, hcd);
156
David Daney1643acc2010-10-08 14:47:52 -0700157 return 0;
Jingoo Han49aa57b2013-12-11 16:20:06 +0900158err2:
David Daney1643acc2010-10-08 14:47:52 -0700159 ehci_octeon_stop();
160
David Daney1643acc2010-10-08 14:47:52 -0700161err1:
162 usb_put_hcd(hcd);
163 return ret;
164}
165
166static int ehci_octeon_drv_remove(struct platform_device *pdev)
167{
168 struct usb_hcd *hcd = platform_get_drvdata(pdev);
169
170 usb_remove_hcd(hcd);
171
172 ehci_octeon_stop();
David Daney1643acc2010-10-08 14:47:52 -0700173 usb_put_hcd(hcd);
174
David Daney1643acc2010-10-08 14:47:52 -0700175 return 0;
176}
177
178static struct platform_driver ehci_octeon_driver = {
179 .probe = ehci_octeon_drv_probe,
180 .remove = ehci_octeon_drv_remove,
181 .shutdown = usb_hcd_platform_shutdown,
182 .driver = {
183 .name = OCTEON_EHCI_HCD_NAME,
184 .owner = THIS_MODULE,
185 }
186};
187
188MODULE_ALIAS("platform:" OCTEON_EHCI_HCD_NAME);