blob: 846bf509d67cded50bcf31f9b06510a89a8d3435 [file] [log] [blame]
Masahiro Yamada048899b2014-11-07 18:48:33 +09001/*
2 * Copyright (C) 2014 Panasonic Corporation
Masahiro Yamada6462cde2015-03-11 15:54:46 +09003 * Copyright (C) 2015 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada048899b2014-11-07 18:48:33 +09005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
Masahiro Yamada149c7512014-11-26 18:34:01 +090010#include <linux/err.h>
Masahiro Yamada4c7d0252015-02-27 02:26:55 +090011#include <asm/io.h>
Masahiro Yamada048899b2014-11-07 18:48:33 +090012#include <usb.h>
Masahiro Yamada4c7d0252015-02-27 02:26:55 +090013#include <mach/mio-regs.h>
Masahiro Yamada44f597a2015-02-27 02:26:54 +090014#include <fdtdec.h>
Masahiro Yamada048899b2014-11-07 18:48:33 +090015#include "ehci.h"
16
Masahiro Yamada149c7512014-11-26 18:34:01 +090017DECLARE_GLOBAL_DATA_PTR;
18
19#define FDT gd->fdt_blob
Masahiro Yamada6462cde2015-03-11 15:54:46 +090020#define COMPAT "socionext,uniphier-ehci"
Masahiro Yamada149c7512014-11-26 18:34:01 +090021
22static 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 Yamada149c7512014-11-26 18:34:01 +090039
Masahiro Yamada4c7d0252015-02-27 02:26:55 +090040static 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 Yamada048899b2014-11-07 18:48:33 +090052int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
53 struct ehci_hcor **hcor)
54{
Masahiro Yamada149c7512014-11-26 18:34:01 +090055 int ret;
Masahiro Yamada048899b2014-11-07 18:48:33 +090056 struct ehci_hccr *cr;
57 struct ehci_hcor *or;
58
59 uniphier_ehci_reset(index, 0);
60
Masahiro Yamada149c7512014-11-26 18:34:01 +090061 ret = get_uniphier_ehci_base(index, &cr);
62 if (ret < 0)
63 return ret;
Masahiro Yamada048899b2014-11-07 18:48:33 +090064 or = (void *)cr + HC_LENGTH(ehci_readl(&cr->cr_capbase));
65
66 *hccr = cr;
67 *hcor = or;
68
69 return 0;
70}
71
72int ehci_hcd_stop(int index)
73{
74 uniphier_ehci_reset(index, 1);
75
76 return 0;
77}