dwctwo_plb.c revision 1.2.10.3 1 1.2.10.2 tls /* $NetBSD: dwctwo_plb.c,v 1.2.10.3 2017/12/03 11:36:36 jdolecek Exp $ */
2 1.2.10.2 tls /*
3 1.2.10.2 tls * Copyright (c) 2013 KIYOHARA Takashi
4 1.2.10.2 tls * All rights reserved.
5 1.2.10.2 tls *
6 1.2.10.2 tls * Redistribution and use in source and binary forms, with or without
7 1.2.10.2 tls * modification, are permitted provided that the following conditions
8 1.2.10.2 tls * are met:
9 1.2.10.2 tls * 1. Redistributions of source code must retain the above copyright
10 1.2.10.2 tls * notice, this list of conditions and the following disclaimer.
11 1.2.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
12 1.2.10.2 tls * notice, this list of conditions and the following disclaimer in the
13 1.2.10.2 tls * documentation and/or other materials provided with the distribution.
14 1.2.10.2 tls *
15 1.2.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.2.10.2 tls * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.2.10.2 tls * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.2.10.2 tls * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.2.10.2 tls * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.2.10.2 tls * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.2.10.2 tls * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.2.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.2.10.2 tls * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.2.10.2 tls * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.2.10.2 tls * POSSIBILITY OF SUCH DAMAGE.
26 1.2.10.2 tls */
27 1.2.10.2 tls
28 1.2.10.2 tls #include <sys/cdefs.h>
29 1.2.10.2 tls __KERNEL_RCSID(0, "$NetBSD: dwctwo_plb.c,v 1.2.10.3 2017/12/03 11:36:36 jdolecek Exp $");
30 1.2.10.2 tls
31 1.2.10.2 tls #include <sys/param.h>
32 1.2.10.2 tls #include <sys/bus.h>
33 1.2.10.2 tls #include <sys/device.h>
34 1.2.10.2 tls #include <sys/errno.h>
35 1.2.10.2 tls #include <sys/extent.h>
36 1.2.10.2 tls
37 1.2.10.2 tls #include <powerpc/ibm4xx/cpu.h>
38 1.2.10.2 tls #include <powerpc/ibm4xx/dev/plbvar.h>
39 1.2.10.2 tls
40 1.2.10.2 tls #include <dev/usb/usb.h>
41 1.2.10.2 tls #include <dev/usb/usbdi.h>
42 1.2.10.2 tls #include <dev/usb/usbdivar.h>
43 1.2.10.2 tls #include <dev/usb/usb_mem.h>
44 1.2.10.2 tls
45 1.2.10.2 tls #include <dwc2/dwc2.h>
46 1.2.10.2 tls #include <dwc2/dwc2var.h>
47 1.2.10.2 tls #include "dwc2_core.h"
48 1.2.10.2 tls
49 1.2.10.2 tls #include "locators.h"
50 1.2.10.2 tls
51 1.2.10.2 tls #define DWCTWO_SIZE 0x40000
52 1.2.10.2 tls
53 1.2.10.2 tls static int dwctwo_plb_match(device_t, cfdata_t, void *);
54 1.2.10.2 tls static void dwctwo_plb_attach(device_t, device_t, void *);
55 1.2.10.2 tls
56 1.2.10.2 tls static void dwctwo_plb_deferred(device_t);
57 1.2.10.2 tls
58 1.2.10.2 tls CFATTACH_DECL_NEW(dwctwo_plb, sizeof(struct dwc2_softc),
59 1.2.10.2 tls dwctwo_plb_match, dwctwo_plb_attach, NULL, NULL);
60 1.2.10.2 tls
61 1.2.10.2 tls static struct powerpc_bus_space dwctwo_tag = {
62 1.2.10.2 tls _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
63 1.2.10.2 tls 0x00000000,
64 1.2.10.2 tls 0x00000000,
65 1.2.10.2 tls DWCTWO_SIZE
66 1.2.10.2 tls };
67 1.2.10.2 tls static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
68 1.2.10.2 tls __attribute__((aligned(8)));
69 1.2.10.2 tls
70 1.2.10.2 tls
71 1.2.10.2 tls static int
72 1.2.10.2 tls dwctwo_plb_match(device_t parent, cfdata_t match, void *aux)
73 1.2.10.2 tls {
74 1.2.10.2 tls struct plb_attach_args *paa = aux;
75 1.2.10.2 tls
76 1.2.10.2 tls if (strcmp(paa->plb_name, match->cf_name) != 0)
77 1.2.10.2 tls return 0;
78 1.2.10.2 tls
79 1.2.10.2 tls if (match->cf_loc[PLBCF_ADDR] == PLBCF_ADDR_DEFAULT)
80 1.2.10.2 tls panic("dwctwo_plb_match: wildcard addr not allowed");
81 1.2.10.2 tls if (match->cf_loc[PLBCF_IRQ] == PLBCF_IRQ_DEFAULT)
82 1.2.10.2 tls panic("dwctwo_plb_match: wildcard IRQ not allowed");
83 1.2.10.2 tls
84 1.2.10.2 tls paa->plb_addr = match->cf_loc[PLBCF_ADDR];
85 1.2.10.2 tls paa->plb_irq = match->cf_loc[PLBCF_IRQ];
86 1.2.10.2 tls return 1;
87 1.2.10.2 tls }
88 1.2.10.2 tls
89 1.2.10.2 tls static void
90 1.2.10.2 tls dwctwo_plb_attach(device_t parent, device_t self, void *aux)
91 1.2.10.2 tls {
92 1.2.10.2 tls struct dwc2_softc *sc = device_private(self);
93 1.2.10.2 tls struct plb_attach_args *paa = aux;
94 1.2.10.2 tls prop_dictionary_t dict = device_properties(self);
95 1.2.10.2 tls uint32_t srst0;
96 1.2.10.2 tls
97 1.2.10.2 tls sc->sc_dev = self;
98 1.2.10.2 tls
99 1.2.10.2 tls /* get core parameters */
100 1.2.10.2 tls if (!prop_dictionary_get_uint32(dict, "params",
101 1.2.10.2 tls (uint32_t *)&sc->sc_params)) {
102 1.2.10.2 tls aprint_error("struct dwc2_core_params not found\n");
103 1.2.10.2 tls return;
104 1.2.10.2 tls }
105 1.2.10.2 tls
106 1.2.10.2 tls dwctwo_tag.pbs_base = paa->plb_addr;
107 1.2.10.2 tls dwctwo_tag.pbs_limit += paa->plb_addr;
108 1.2.10.2 tls if (bus_space_init(&dwctwo_tag, "dwctwotag", ex_storage,
109 1.2.10.2 tls sizeof(ex_storage)))
110 1.2.10.2 tls panic("dwctwo_attach: Failed to initialise opb_tag");
111 1.2.10.2 tls sc->sc_iot = &dwctwo_tag;
112 1.2.10.2 tls bus_space_map(sc->sc_iot, paa->plb_addr, DWCTWO_SIZE, 0, &sc->sc_ioh);
113 1.2.10.3 jdolecek sc->sc_bus.ub_dmatag = paa->plb_dmat;
114 1.2.10.2 tls
115 1.2.10.3 jdolecek intr_establish(paa->plb_irq, IST_LEVEL, IPL_VM, dwc2_intr, sc);
116 1.2.10.2 tls
117 1.2.10.2 tls /* Enable the USB interface. */
118 1.2.10.2 tls mtsdr(DCR_SDR0_PFC1, mfsdr(DCR_SDR0_PFC1) | SDR0_PFC1_USBEN);
119 1.2.10.2 tls srst0 = mfsdr(DCR_SDR0_SRST0);
120 1.2.10.2 tls mtsdr(DCR_SDR0_SRST0, srst0 | SDR0_SRST0_UPRST | SDR0_SRST0_AHB);
121 1.2.10.2 tls delay(200 * 1000); /* XXXX */
122 1.2.10.2 tls mtsdr(DCR_SDR0_SRST0, srst0);
123 1.2.10.2 tls
124 1.2.10.2 tls config_defer(self, dwctwo_plb_deferred);
125 1.2.10.2 tls }
126 1.2.10.2 tls
127 1.2.10.2 tls static void
128 1.2.10.2 tls dwctwo_plb_deferred(device_t self)
129 1.2.10.2 tls {
130 1.2.10.2 tls struct dwc2_softc *sc = device_private(self);
131 1.2.10.2 tls int error;
132 1.2.10.2 tls
133 1.2.10.2 tls error = dwc2_init(sc);
134 1.2.10.2 tls if (error != 0) {
135 1.2.10.2 tls aprint_error_dev(self, "couldn't initialize host, error=%d\n",
136 1.2.10.2 tls error);
137 1.2.10.2 tls return;
138 1.2.10.2 tls }
139 1.2.10.2 tls sc->sc_child = config_found(sc->sc_dev, &sc->sc_bus, usbctlprint);
140 1.2.10.2 tls }
141