Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 2 | * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | 149c751 | 2014-11-26 18:34:01 +0900 | [diff] [blame] | 8 | #include <linux/err.h> |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 10 | #include <usb.h> |
Masahiro Yamada | 4c7d025 | 2015-02-27 02:26:55 +0900 | [diff] [blame] | 11 | #include <mach/mio-regs.h> |
Masahiro Yamada | 44f597a | 2015-02-27 02:26:54 +0900 | [diff] [blame] | 12 | #include <fdtdec.h> |
Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 13 | #include "ehci.h" |
| 14 | |
Masahiro Yamada | 149c751 | 2014-11-26 18:34:01 +0900 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | #define FDT gd->fdt_blob |
Masahiro Yamada | 6462cde | 2015-03-11 15:54:46 +0900 | [diff] [blame] | 18 | #define COMPAT "socionext,uniphier-ehci" |
Masahiro Yamada | 149c751 | 2014-11-26 18:34:01 +0900 | [diff] [blame] | 19 | |
| 20 | static int get_uniphier_ehci_base(int index, struct ehci_hccr **base) |
| 21 | { |
| 22 | int offset; |
| 23 | |
| 24 | for (offset = fdt_node_offset_by_compatible(FDT, 0, COMPAT); |
| 25 | offset >= 0; |
| 26 | offset = fdt_node_offset_by_compatible(FDT, offset, COMPAT)) { |
| 27 | if (index == 0) { |
| 28 | *base = (struct ehci_hccr *) |
| 29 | fdtdec_get_addr(FDT, offset, "reg"); |
| 30 | return 0; |
| 31 | } |
| 32 | index--; |
| 33 | } |
| 34 | |
| 35 | return -ENODEV; /* not found */ |
| 36 | } |
Masahiro Yamada | 149c751 | 2014-11-26 18:34:01 +0900 | [diff] [blame] | 37 | |
Masahiro Yamada | 4c7d025 | 2015-02-27 02:26:55 +0900 | [diff] [blame] | 38 | static void uniphier_ehci_reset(int index, int on) |
| 39 | { |
| 40 | u32 tmp; |
| 41 | |
| 42 | tmp = readl(MIO_USB_RSTCTRL(index)); |
| 43 | if (on) |
| 44 | tmp &= ~MIO_USB_RSTCTRL_XRST; |
| 45 | else |
| 46 | tmp |= MIO_USB_RSTCTRL_XRST; |
| 47 | writel(tmp, MIO_USB_RSTCTRL(index)); |
| 48 | } |
| 49 | |
Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 50 | int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, |
| 51 | struct ehci_hcor **hcor) |
| 52 | { |
Masahiro Yamada | 149c751 | 2014-11-26 18:34:01 +0900 | [diff] [blame] | 53 | int ret; |
Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 54 | struct ehci_hccr *cr; |
| 55 | struct ehci_hcor *or; |
| 56 | |
| 57 | uniphier_ehci_reset(index, 0); |
| 58 | |
Masahiro Yamada | 149c751 | 2014-11-26 18:34:01 +0900 | [diff] [blame] | 59 | ret = get_uniphier_ehci_base(index, &cr); |
| 60 | if (ret < 0) |
| 61 | return ret; |
Masahiro Yamada | 048899b | 2014-11-07 18:48:33 +0900 | [diff] [blame] | 62 | or = (void *)cr + HC_LENGTH(ehci_readl(&cr->cr_capbase)); |
| 63 | |
| 64 | *hccr = cr; |
| 65 | *hcor = or; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int ehci_hcd_stop(int index) |
| 71 | { |
| 72 | uniphier_ehci_reset(index, 1); |
| 73 | |
| 74 | return 0; |
| 75 | } |