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