blob: 6291ed230bf66040090be1df1f3874a4cfbc61af [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>
Marek Vasut851fecc2016-01-23 21:04:46 +01009#include <asm/io.h>
Alexey Brodkina6aff432015-12-02 12:32:02 +030010#include <dm.h>
11#include "ehci.h"
12
13/*
14 * Even though here we don't explicitly use "struct ehci_ctrl"
15 * ehci_register() expects it to be the first thing that resides in
16 * device's private data.
17 */
18struct generic_ehci {
19 struct ehci_ctrl ctrl;
20};
21
22static int ehci_usb_probe(struct udevice *dev)
23{
Marek Vasut851fecc2016-01-23 21:04:46 +010024 struct ehci_hccr *hccr;
Alexey Brodkina6aff432015-12-02 12:32:02 +030025 struct ehci_hcor *hcor;
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090026 int i;
27
28 for (i = 0; ; i++) {
Stephen Warrena9622432016-06-17 09:44:00 -060029 struct clk clk;
30 int ret;
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090031
Stephen Warrena9622432016-06-17 09:44:00 -060032 ret = clk_get_by_index(dev, i, &clk);
33 if (ret < 0)
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090034 break;
Stephen Warrena9622432016-06-17 09:44:00 -060035 if (clk_enable(&clk))
36 printf("failed to enable clock %d\n", i);
37 clk_free(&clk);
Masahiro Yamadafbb66bf2016-01-25 15:00:36 +090038 }
Alexey Brodkina6aff432015-12-02 12:32:02 +030039
Marek Vasut851fecc2016-01-23 21:04:46 +010040 hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE);
Alexey Brodkina6aff432015-12-02 12:32:02 +030041 hcor = (struct ehci_hcor *)((uintptr_t)hccr +
42 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
43
44 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
45}
46
Alexey Brodkina6aff432015-12-02 12:32:02 +030047static const struct udevice_id ehci_usb_ids[] = {
48 { .compatible = "generic-ehci" },
49 { }
50};
51
52U_BOOT_DRIVER(ehci_generic) = {
53 .name = "ehci_generic",
54 .id = UCLASS_USB,
55 .of_match = ehci_usb_ids,
56 .probe = ehci_usb_probe,
Masahiro Yamadad41919b2016-09-06 22:17:34 +090057 .remove = ehci_deregister,
Alexey Brodkina6aff432015-12-02 12:32:02 +030058 .ops = &ehci_usb_ops,
59 .priv_auto_alloc_size = sizeof(struct generic_ehci),
60 .flags = DM_FLAG_ALLOC_PRIV_DMA,
61};