blob: fb7846289372b0f8a0c67c0f7539ee8563afd424 [file] [log] [blame]
Alexey Brodkina6aff432015-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 Yamadafbb66bf2016-01-25 15:00:36 +09008#include <clk.h>
Masahiro Yamada8a5a1802016-09-21 11:29:02 +09009#include <reset.h>
Marek Vasut851fecc2016-01-23 21:04:46 +010010#include <asm/io.h>
Alexey Brodkina6aff432015-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 Vasut851fecc2016-01-23 21:04:46 +010025 struct ehci_hccr *hccr;
Alexey Brodkina6aff432015-12-02 12:32:02 +030026 struct ehci_hcor *hcor;
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090027 int i;
28
29 for (i = 0; ; i++) {
Stephen Warrena9622432016-06-17 09:44:00 -060030 struct clk clk;
31 int ret;
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090032
Stephen Warrena9622432016-06-17 09:44:00 -060033 ret = clk_get_by_index(dev, i, &clk);
34 if (ret < 0)
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090035 break;
Stephen Warrena9622432016-06-17 09:44:00 -060036 if (clk_enable(&clk))
37 printf("failed to enable clock %d\n", i);
38 clk_free(&clk);
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090039 }
Alexey Brodkina6aff432015-12-02 12:32:02 +030040
Masahiro Yamada8a5a1802016-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
Simon Glassba1dea42017-05-17 17:18:05 -060053 hccr = map_physmem(devfdt_get_addr(dev), 0x100, MAP_NOCACHE);
Alexey Brodkina6aff432015-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 Brodkina6aff432015-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 Yamadad41919b2016-09-06 22:17:34 +090070 .remove = ehci_deregister,
Alexey Brodkina6aff432015-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};