xref: /openbmc/u-boot/drivers/usb/host/ehci-generic.c (revision dffceb4b)
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 <dm.h>
10 #include "ehci.h"
11 
12 /*
13  * Even though here we don't explicitly use "struct ehci_ctrl"
14  * ehci_register() expects it to be the first thing that resides in
15  * device's private data.
16  */
17 struct generic_ehci {
18 	struct ehci_ctrl ctrl;
19 };
20 
21 static int ehci_usb_probe(struct udevice *dev)
22 {
23 	struct ehci_hccr *hccr = (struct ehci_hccr *)dev_get_addr(dev);
24 	struct ehci_hcor *hcor;
25 	int i;
26 
27 	for (i = 0; ; i++) {
28 		struct udevice *clk_dev;
29 		int clk_id;
30 
31 		clk_id = clk_get_by_index(dev, i, &clk_dev);
32 		if (clk_id < 0)
33 			break;
34 		if (clk_enable(clk_dev, clk_id))
35 			printf("failed to enable clock (dev=%s, id=%d)\n",
36 			       clk_dev->name, clk_id);
37 	}
38 
39 	hcor = (struct ehci_hcor *)((uintptr_t)hccr +
40 				    HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
41 
42 	return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
43 }
44 
45 static int ehci_usb_remove(struct udevice *dev)
46 {
47 	return ehci_deregister(dev);
48 }
49 
50 static const struct udevice_id ehci_usb_ids[] = {
51 	{ .compatible = "generic-ehci" },
52 	{ }
53 };
54 
55 U_BOOT_DRIVER(ehci_generic) = {
56 	.name	= "ehci_generic",
57 	.id	= UCLASS_USB,
58 	.of_match = ehci_usb_ids,
59 	.probe = ehci_usb_probe,
60 	.remove = ehci_usb_remove,
61 	.ops	= &ehci_usb_ops,
62 	.priv_auto_alloc_size = sizeof(struct generic_ehci),
63 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
64 };
65