]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/usb/host/ehci-uniphier.c
usb: ohci: enable cache support
[karo-tx-uboot.git] / drivers / usb / host / ehci-uniphier.c
1 /*
2  * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <linux/err.h>
9 #include <linux/io.h>
10 #include <usb.h>
11 #include <mach/mio-regs.h>
12 #include <fdtdec.h>
13 #include "ehci.h"
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 #define FDT             gd->fdt_blob
18 #define COMPAT          "socionext,uniphier-ehci"
19
20 static 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 }
37
38 static 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
50 int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
51                   struct ehci_hcor **hcor)
52 {
53         int ret;
54         struct ehci_hccr *cr;
55         struct ehci_hcor *or;
56
57         uniphier_ehci_reset(index, 0);
58
59         ret = get_uniphier_ehci_base(index, &cr);
60         if (ret < 0)
61                 return ret;
62         or = (void *)cr + HC_LENGTH(ehci_readl(&cr->cr_capbase));
63
64         *hccr = cr;
65         *hcor = or;
66
67         return 0;
68 }
69
70 int ehci_hcd_stop(int index)
71 {
72         uniphier_ehci_reset(index, 1);
73
74         return 0;
75 }