]> git.sur5r.net Git - u-boot/blob - drivers/usb/host/ehci-uniphier.c
dm: usb: Allow USB drivers to be declared and auto-probed
[u-boot] / drivers / usb / host / ehci-uniphier.c
1 /*
2  * Copyright (C) 2014 Panasonic Corporation
3  * Copyright (C) 2015 Socionext Inc.
4  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <linux/err.h>
11 #include <asm/io.h>
12 #include <usb.h>
13 #include <mach/mio-regs.h>
14 #include <fdtdec.h>
15 #include "ehci.h"
16
17 DECLARE_GLOBAL_DATA_PTR;
18
19 #define FDT             gd->fdt_blob
20 #define COMPAT          "socionext,uniphier-ehci"
21
22 static 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 }
39
40 static 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
52 int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
53                   struct ehci_hcor **hcor)
54 {
55         int ret;
56         struct ehci_hccr *cr;
57         struct ehci_hcor *or;
58
59         uniphier_ehci_reset(index, 0);
60
61         ret = get_uniphier_ehci_base(index, &cr);
62         if (ret < 0)
63                 return ret;
64         or = (void *)cr + HC_LENGTH(ehci_readl(&cr->cr_capbase));
65
66         *hccr = cr;
67         *hcor = or;
68
69         return 0;
70 }
71
72 int ehci_hcd_stop(int index)
73 {
74         uniphier_ehci_reset(index, 1);
75
76         return 0;
77 }