blob: 2190adba6777d849525efdf165ffed882cfd001a [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>
Masahiro Yamada8824cfc2016-09-21 11:29:02 +09009#include <reset.h>
Marek Vasut643cacb2016-01-23 21:04:46 +010010#include <asm/io.h>
Alexey Brodkin90fbb282015-12-02 12:32:02 +030011#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 */
19struct generic_ehci {
20 struct ehci_ctrl ctrl;
21};
22
23static int ehci_usb_probe(struct udevice *dev)
24{
Marek Vasut643cacb2016-01-23 21:04:46 +010025 struct ehci_hccr *hccr;
Alexey Brodkin90fbb282015-12-02 12:32:02 +030026 struct ehci_hcor *hcor;
Masahiro Yamada4feefdc2016-01-25 15:00:36 +090027 int i;
28
29 for (i = 0; ; i++) {
Stephen Warren135aa952016-06-17 09:44:00 -060030 struct clk clk;
31 int ret;
Masahiro Yamada4feefdc2016-01-25 15:00:36 +090032
Stephen Warren135aa952016-06-17 09:44:00 -060033 ret = clk_get_by_index(dev, i, &clk);
34 if (ret < 0)
Masahiro Yamada4feefdc2016-01-25 15:00:36 +090035 break;
Stephen Warren135aa952016-06-17 09:44:00 -060036 if (clk_enable(&clk))
37 printf("failed to enable clock %d\n", i);
38 clk_free(&clk);
Masahiro Yamada4feefdc2016-01-25 15:00:36 +090039 }
Alexey Brodkin90fbb282015-12-02 12:32:02 +030040
Masahiro Yamada8824cfc2016-09-21 11:29:02 +090041 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
Marek Vasut643cacb2016-01-23 21:04:46 +010053 hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE);
Alexey Brodkin90fbb282015-12-02 12:32:02 +030054 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
Alexey Brodkin90fbb282015-12-02 12:32:02 +030060static const struct udevice_id ehci_usb_ids[] = {
61 { .compatible = "generic-ehci" },
62 { }
63};
64
65U_BOOT_DRIVER(ehci_generic) = {
66 .name = "ehci_generic",
67 .id = UCLASS_USB,
68 .of_match = ehci_usb_ids,
69 .probe = ehci_usb_probe,
Masahiro Yamada40527342016-09-06 22:17:34 +090070 .remove = ehci_deregister,
Alexey Brodkin90fbb282015-12-02 12:32:02 +030071 .ops = &ehci_usb_ops,
72 .priv_auto_alloc_size = sizeof(struct generic_ehci),
73 .flags = DM_FLAG_ALLOC_PRIV_DMA,
74};