2 * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller
4 * GRUSBHC is typically found on LEON/GRLIB SoCs
6 * (c) Jan Andersson <jan@gaisler.com>
8 * Based on ehci-ppc-of.c which is:
9 * (c) Valentine Barshak <vbarshak@ru.mvista.com>
10 * and in turn based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
11 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/signal.h>
31 #include <linux/of_irq.h>
32 #include <linux/of_address.h>
33 #include <linux/of_platform.h>
35 #define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */
37 /* called during probe() after chip reset completes */
38 static int ehci_grlib_setup(struct usb_hcd
*hcd
)
40 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
43 retval
= ehci_halt(ehci
);
47 retval
= ehci_init(hcd
);
52 ehci_port_power(ehci
, 1);
54 return ehci_reset(ehci
);
58 static const struct hc_driver ehci_grlib_hc_driver
= {
59 .description
= hcd_name
,
60 .product_desc
= "GRLIB GRUSBHC EHCI",
61 .hcd_priv_size
= sizeof(struct ehci_hcd
),
64 * generic hardware linkage
67 .flags
= HCD_MEMORY
| HCD_USB2
,
70 * basic lifecycle operations
72 .reset
= ehci_grlib_setup
,
75 .shutdown
= ehci_shutdown
,
78 * managing i/o requests and associated device resources
80 .urb_enqueue
= ehci_urb_enqueue
,
81 .urb_dequeue
= ehci_urb_dequeue
,
82 .endpoint_disable
= ehci_endpoint_disable
,
83 .endpoint_reset
= ehci_endpoint_reset
,
88 .get_frame_number
= ehci_get_frame
,
93 .hub_status_data
= ehci_hub_status_data
,
94 .hub_control
= ehci_hub_control
,
96 .bus_suspend
= ehci_bus_suspend
,
97 .bus_resume
= ehci_bus_resume
,
99 .relinquish_port
= ehci_relinquish_port
,
100 .port_handed_over
= ehci_port_handed_over
,
102 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
106 static int __devinit
ehci_hcd_grlib_probe(struct platform_device
*op
)
108 struct device_node
*dn
= op
->dev
.of_node
;
110 struct ehci_hcd
*ehci
= NULL
;
119 dev_dbg(&op
->dev
, "initializing GRUSBHC EHCI USB Controller\n");
121 rv
= of_address_to_resource(dn
, 0, &res
);
125 /* usb_create_hcd requires dma_mask != NULL */
126 op
->dev
.dma_mask
= &op
->dev
.coherent_dma_mask
;
127 hcd
= usb_create_hcd(&ehci_grlib_hc_driver
, &op
->dev
,
132 hcd
->rsrc_start
= res
.start
;
133 hcd
->rsrc_len
= resource_size(&res
);
135 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, hcd_name
)) {
136 printk(KERN_ERR
"%s: request_mem_region failed\n", __FILE__
);
141 irq
= irq_of_parse_and_map(dn
, 0);
143 printk(KERN_ERR
"%s: irq_of_parse_and_map failed\n", __FILE__
);
148 hcd
->regs
= ioremap(hcd
->rsrc_start
, hcd
->rsrc_len
);
150 printk(KERN_ERR
"%s: ioremap failed\n", __FILE__
);
155 ehci
= hcd_to_ehci(hcd
);
157 ehci
->caps
= hcd
->regs
;
159 /* determine endianness of this implementation */
160 hc_capbase
= ehci_readl(ehci
, &ehci
->caps
->hc_capbase
);
161 if (HC_VERSION(ehci
, hc_capbase
) != GRUSBHC_HCIVERSION
) {
162 ehci
->big_endian_mmio
= 1;
163 ehci
->big_endian_desc
= 1;
164 ehci
->big_endian_capbase
= 1;
167 ehci
->regs
= hcd
->regs
+
168 HC_LENGTH(ehci
, ehci_readl(ehci
, &ehci
->caps
->hc_capbase
));
170 /* cache this readonly data; minimize chip reads */
171 ehci
->hcs_params
= ehci_readl(ehci
, &ehci
->caps
->hcs_params
);
173 rv
= usb_add_hcd(hcd
, irq
, 0);
182 irq_dispose_mapping(irq
);
184 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
192 static int ehci_hcd_grlib_remove(struct platform_device
*op
)
194 struct usb_hcd
*hcd
= dev_get_drvdata(&op
->dev
);
196 dev_set_drvdata(&op
->dev
, NULL
);
198 dev_dbg(&op
->dev
, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
203 irq_dispose_mapping(hcd
->irq
);
204 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
212 static void ehci_hcd_grlib_shutdown(struct platform_device
*op
)
214 struct usb_hcd
*hcd
= dev_get_drvdata(&op
->dev
);
216 if (hcd
->driver
->shutdown
)
217 hcd
->driver
->shutdown(hcd
);
221 static const struct of_device_id ehci_hcd_grlib_of_match
[] = {
223 .name
= "GAISLER_EHCI",
230 MODULE_DEVICE_TABLE(of
, ehci_hcd_grlib_of_match
);
233 static struct platform_driver ehci_grlib_driver
= {
234 .probe
= ehci_hcd_grlib_probe
,
235 .remove
= ehci_hcd_grlib_remove
,
236 .shutdown
= ehci_hcd_grlib_shutdown
,
238 .name
= "grlib-ehci",
239 .owner
= THIS_MODULE
,
240 .of_match_table
= ehci_hcd_grlib_of_match
,