Alexey Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | fbb66bf | 2016-01-25 15:00:36 +0900 | [diff] [blame] | 8 | #include <clk.h> |
Masahiro Yamada | 8a5a180 | 2016-09-21 11:29:02 +0900 | [diff] [blame] | 9 | #include <reset.h> |
Marek Vasut | 851fecc | 2016-01-23 21:04:46 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
Alexey Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 11 | #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 | */ |
| 19 | struct generic_ehci { |
| 20 | struct ehci_ctrl ctrl; |
| 21 | }; |
| 22 | |
| 23 | static int ehci_usb_probe(struct udevice *dev) |
| 24 | { |
Marek Vasut | 851fecc | 2016-01-23 21:04:46 +0100 | [diff] [blame] | 25 | struct ehci_hccr *hccr; |
Alexey Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 26 | struct ehci_hcor *hcor; |
Masahiro Yamada | fbb66bf | 2016-01-25 15:00:36 +0900 | [diff] [blame] | 27 | int i; |
| 28 | |
| 29 | for (i = 0; ; i++) { |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 30 | struct clk clk; |
| 31 | int ret; |
Masahiro Yamada | fbb66bf | 2016-01-25 15:00:36 +0900 | [diff] [blame] | 32 | |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 33 | ret = clk_get_by_index(dev, i, &clk); |
| 34 | if (ret < 0) |
Masahiro Yamada | fbb66bf | 2016-01-25 15:00:36 +0900 | [diff] [blame] | 35 | break; |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 36 | if (clk_enable(&clk)) |
| 37 | printf("failed to enable clock %d\n", i); |
| 38 | clk_free(&clk); |
Masahiro Yamada | fbb66bf | 2016-01-25 15:00:36 +0900 | [diff] [blame] | 39 | } |
Alexey Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 40 | |
Masahiro Yamada | 8a5a180 | 2016-09-21 11:29:02 +0900 | [diff] [blame] | 41 | 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 Vasut | 851fecc | 2016-01-23 21:04:46 +0100 | [diff] [blame] | 53 | hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE); |
Alexey Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 54 | 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 Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 60 | static const struct udevice_id ehci_usb_ids[] = { |
| 61 | { .compatible = "generic-ehci" }, |
| 62 | { } |
| 63 | }; |
| 64 | |
| 65 | U_BOOT_DRIVER(ehci_generic) = { |
| 66 | .name = "ehci_generic", |
| 67 | .id = UCLASS_USB, |
| 68 | .of_match = ehci_usb_ids, |
| 69 | .probe = ehci_usb_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 70 | .remove = ehci_deregister, |
Alexey Brodkin | a6aff43 | 2015-12-02 12:32:02 +0300 | [diff] [blame] | 71 | .ops = &ehci_usb_ops, |
| 72 | .priv_auto_alloc_size = sizeof(struct generic_ehci), |
| 73 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 74 | }; |