xref: /openbmc/u-boot/drivers/usb/host/ehci-generic.c (revision 730d2544)
1 /*
2  * Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <clk.h>
9 #include <reset.h>
10 #include <asm/io.h>
11 #include <dm.h>
12 #include "ehci.h"
13 
14 /*
15  * Even though here we don't explicitly use "struct ehci_ctrl"
16  * ehci_register() expects it to be the first thing that resides in
17  * device's private data.
18  */
19 struct generic_ehci {
20 	struct ehci_ctrl ctrl;
21 };
22 
23 static int ehci_usb_probe(struct udevice *dev)
24 {
25 	struct ehci_hccr *hccr;
26 	struct ehci_hcor *hcor;
27 	int i;
28 
29 	for (i = 0; ; i++) {
30 		struct clk clk;
31 		int ret;
32 
33 		ret = clk_get_by_index(dev, i, &clk);
34 		if (ret < 0)
35 			break;
36 		if (clk_enable(&clk))
37 			printf("failed to enable clock %d\n", i);
38 		clk_free(&clk);
39 	}
40 
41 	for (i = 0; ; i++) {
42 		struct reset_ctl reset;
43 		int ret;
44 
45 		ret = reset_get_by_index(dev, i, &reset);
46 		if (ret < 0)
47 			break;
48 		if (reset_deassert(&reset))
49 			printf("failed to deassert reset %d\n", i);
50 		reset_free(&reset);
51 	}
52 
53 	hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE);
54 	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
55 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
56 
57 	return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
58 }
59 
60 static const struct udevice_id ehci_usb_ids[] = {
61 	{ .compatible = "generic-ehci" },
62 	{ }
63 };
64 
65 U_BOOT_DRIVER(ehci_generic) = {
66 	.name	= "ehci_generic",
67 	.id	= UCLASS_USB,
68 	.of_match = ehci_usb_ids,
69 	.probe = ehci_usb_probe,
70 	.remove = ehci_deregister,
71 	.ops	= &ehci_usb_ops,
72 	.priv_auto_alloc_size = sizeof(struct generic_ehci),
73 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
74 };
75