blob: c3f827ca0ae517ada98d3cb3e982beaae27b858b [file] [log] [blame]
Masahiro Yamada048899b2014-11-07 18:48:33 +09001/*
Masahiro Yamadaf6e7f072015-05-29 17:30:00 +09002 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada048899b2014-11-07 18:48:33 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada149c7512014-11-26 18:34:01 +09008#include <linux/err.h>
Masahiro Yamadaf6e7f072015-05-29 17:30:00 +09009#include <linux/io.h>
Masahiro Yamada048899b2014-11-07 18:48:33 +090010#include <usb.h>
Masahiro Yamada4c7d0252015-02-27 02:26:55 +090011#include <mach/mio-regs.h>
Masahiro Yamada44f597a2015-02-27 02:26:54 +090012#include <fdtdec.h>
Masahiro Yamada048899b2014-11-07 18:48:33 +090013#include "ehci.h"
14
Masahiro Yamada149c7512014-11-26 18:34:01 +090015DECLARE_GLOBAL_DATA_PTR;
16
17#define FDT gd->fdt_blob
Masahiro Yamada6462cde2015-03-11 15:54:46 +090018#define COMPAT "socionext,uniphier-ehci"
Masahiro Yamada149c7512014-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 Yamada149c7512014-11-26 18:34:01 +090037
Masahiro Yamada4c7d0252015-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 Yamada048899b2014-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 Yamada149c7512014-11-26 18:34:01 +090053 int ret;
Masahiro Yamada048899b2014-11-07 18:48:33 +090054 struct ehci_hccr *cr;
55 struct ehci_hcor *or;
56
57 uniphier_ehci_reset(index, 0);
58
Masahiro Yamada149c7512014-11-26 18:34:01 +090059 ret = get_uniphier_ehci_base(index, &cr);
60 if (ret < 0)
61 return ret;
Masahiro Yamada048899b2014-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}