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