blob: 32a43752790d72ee1c7d0d18730c255d7a191dd7 [file] [log] [blame]
Masahiro Yamada048899b2014-11-07 18:48:33 +09001/*
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 Yamada149c7512014-11-26 18:34:01 +09009#include <linux/err.h>
Masahiro Yamada048899b2014-11-07 18:48:33 +090010#include <usb.h>
11#include <asm/arch/ehci-uniphier.h>
12#include "ehci.h"
13
Masahiro Yamada149c7512014-11-26 18:34:01 +090014#ifdef CONFIG_OF_CONTROL
15#include <fdtdec.h>
16DECLARE_GLOBAL_DATA_PTR;
17
18#define FDT gd->fdt_blob
19#define COMPAT "panasonic,uniphier-ehci"
20
21static 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}
38#else
39static int get_uniphier_ehci_base(int index, struct ehci_hccr **base)
40{
41 *base = (struct ehci_hccr *)uniphier_ehci_platdata[index].base;
42 return 0;
43}
44#endif
45
Masahiro Yamada048899b2014-11-07 18:48:33 +090046/*
47 * Create the appropriate control structures to manage
48 * a new EHCI host controller.
49 */
50int 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}