blob: 84114c5df9847e4ad0fbadc98c3d04d57f0ac08f [file] [log] [blame]
Alexey Brodkin90fbb282015-12-02 12:32:02 +03001/*
2 * Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada4feefdc2016-01-25 15:00:36 +09008#include <clk.h>
Alexey Brodkin90fbb282015-12-02 12:32:02 +03009#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 */
17struct generic_ehci {
18 struct ehci_ctrl ctrl;
19};
20
21static 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;
Masahiro Yamada4feefdc2016-01-25 15:00:36 +090025 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 }
Alexey Brodkin90fbb282015-12-02 12:32:02 +030038
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
45static int ehci_usb_remove(struct udevice *dev)
46{
47 return ehci_deregister(dev);
48}
49
50static const struct udevice_id ehci_usb_ids[] = {
51 { .compatible = "generic-ehci" },
52 { }
53};
54
55U_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};