blob: c3f827ca0ae517ada98d3cb3e982beaae27b858b [file] [log] [blame]
Masahiro Yamada21b88902014-11-07 18:48:33 +09001/*
Masahiro Yamada663a23f2015-05-29 17:30:00 +09002 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada21b88902014-11-07 18:48:33 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada9a724622014-11-26 18:34:01 +09008#include <linux/err.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +09009#include <linux/io.h>
Masahiro Yamada21b88902014-11-07 18:48:33 +090010#include <usb.h>
Masahiro Yamadab2584c52015-02-27 02:26:55 +090011#include <mach/mio-regs.h>
Masahiro Yamada9a1dff52015-02-27 02:26:54 +090012#include <fdtdec.h>
Masahiro Yamada21b88902014-11-07 18:48:33 +090013#include "ehci.h"
14
Masahiro Yamada9a724622014-11-26 18:34:01 +090015DECLARE_GLOBAL_DATA_PTR;
16
17#define FDT gd->fdt_blob
Masahiro Yamadad5f83a42015-03-11 15:54:46 +090018#define COMPAT "socionext,uniphier-ehci"
Masahiro Yamada9a724622014-11-26 18:34:01 +090019
20static 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 Yamada9a724622014-11-26 18:34:01 +090037
Masahiro Yamadab2584c52015-02-27 02:26:55 +090038static 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 Yamada21b88902014-11-07 18:48:33 +090050int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
51 struct ehci_hcor **hcor)
52{
Masahiro Yamada9a724622014-11-26 18:34:01 +090053 int ret;
Masahiro Yamada21b88902014-11-07 18:48:33 +090054 struct ehci_hccr *cr;
55 struct ehci_hcor *or;
56
57 uniphier_ehci_reset(index, 0);
58
Masahiro Yamada9a724622014-11-26 18:34:01 +090059 ret = get_uniphier_ehci_base(index, &cr);
60 if (ret < 0)
61 return ret;
Masahiro Yamada21b88902014-11-07 18:48:33 +090062 or = (void *)cr + HC_LENGTH(ehci_readl(&cr->cr_capbase));
63
64 *hccr = cr;
65 *hcor = or;
66
67 return 0;
68}
69
70int ehci_hcd_stop(int index)
71{
72 uniphier_ehci_reset(index, 1);
73
74 return 0;
75}