1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021, Adrian Chadd <adrian@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/interrupt.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/rman.h>
#include <sys/gpio.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_extern.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <dev/fdt/fdt_common.h>
#include <dev/fdt/fdt_pinctrl.h>
#include <dev/gpio/gpiobusvar.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/qcom_tcsr/qcom_tcsr_var.h>
#include <dev/qcom_tcsr/qcom_tcsr_reg.h>
/*
* The linux-msm branches that support IPQ4018 use "ipq,tcsr".
* The openwrt addons use qcom,tcsr. So for now support both.
*
* Also, it's not quite clear yet (since this is the first port!)
* whether these options and registers are specific to the QCA IPQ401x
* part or show up in different linux branches as different registers
* but with the same driver/naming here. Let's hope that doesn't
* happen.
*/
static struct ofw_compat_data compat_data[] = {
{ "qcom,tcsr", 1 },
{ "ipq,tcsr", 1 },
{ NULL, 0 }
};
static int
qcom_tcsr_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data)
return (ENXIO);
device_set_desc(dev, "Qualcomm Core Top Control and Status Driver");
return (BUS_PROBE_DEFAULT);
}
static int
qcom_tcsr_attach(device_t dev)
{
struct qcom_tcsr_softc *sc = device_get_softc(dev);
int rid, ret;
uint32_t val;
sc->sc_dev = dev;
/*
* Hardware version is stored in the ofw_compat_data table.
*/
sc->hw_version =
ofw_bus_search_compatible(dev, compat_data)->ocd_data;
mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
rid = 0;
sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
RF_ACTIVE);
if (!sc->sc_mem_res) {
device_printf(dev, "ERROR: Could not map memory\n");
ret = ENXIO;
goto error;
}
/*
* Parse out the open firmware entries to see which particular
* configurations we need to set here.
*/
/*
* USB control select.
*
* For linux-msm on the IPQ401x, it actually calls into the SCM
* to make the change. OpenWRT just does a register write.
* We'll do the register write for now.
*/
if (OF_getencprop(ofw_bus_get_node(dev), "qcom,usb-ctrl-select",
&val, sizeof(val)) > 0) {
if (bootverbose)
device_printf(sc->sc_dev,
"USB control select (val 0x%x)\n",
val);
QCOM_TCSR_WRITE_4(sc, QCOM_TCSR_USB_PORT_SEL, val);
}
/*
* USB high speed phy mode select.
*/
if (OF_getencprop(ofw_bus_get_node(dev), "qcom,usb-hsphy-mode-select",
&val, sizeof(val)) > 0) {
if (bootverbose)
device_printf(sc->sc_dev,
"USB high speed PHY mode select (val 0x%x)\n",
val);
QCOM_TCSR_WRITE_4(sc, QCOM_TCSR_USB_HSPHY_CONFIG, val);
}
/*
* Ethernet switch subsystem interface type select.
*/
if (OF_getencprop(ofw_bus_get_node(dev), "qcom,ess-interface-select",
&val, sizeof(val)) > 0) {
uint32_t reg;
if (bootverbose)
device_printf(sc->sc_dev,
"ESS external interface select (val 0x%x)\n",
val);
reg = QCOM_TCSR_READ_4(sc, QCOM_TCSR_ESS_INTERFACE_SEL_OFFSET);
reg &= ~QCOM_TCSR_ESS_INTERFACE_SEL_MASK;
reg |= (val & QCOM_TCSR_ESS_INTERFACE_SEL_MASK);
QCOM_TCSR_WRITE_4(sc, QCOM_TCSR_ESS_INTERFACE_SEL_OFFSET, reg);
}
/*
* WiFi GLB select.
*/
if (OF_getencprop(ofw_bus_get_node(dev), "qcom,wifi_glb_cfg",
&val, sizeof(val)) > 0) {
if (bootverbose)
device_printf(sc->sc_dev,
"WIFI GLB select (val 0x%x)\n",
val);
QCOM_TCSR_WRITE_4(sc, QCOM_TCSR_WIFI0_GLB_CFG_OFFSET, val);
QCOM_TCSR_WRITE_4(sc, QCOM_TCSR_WIFI1_GLB_CFG_OFFSET, val);
}
/*
* WiFi NOC interconnect memory type.
*/
if (OF_getencprop(ofw_bus_get_node(dev),
"qcom,wifi_noc_memtype_m0_m2",
&val, sizeof(val)) > 0) {
if (bootverbose)
device_printf(sc->sc_dev,
"WiFi NOC memory type (val 0x%x)\n",
val);
QCOM_TCSR_WRITE_4(sc, QCOM_TCSR_PNOC_SNOC_MEMTYPE_M0_M2, val);
}
return (0);
error:
if (sc->sc_mem_res)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
mtx_destroy(&sc->sc_mtx);
return (ret);
}
static int
qcom_tcsr_detach(device_t dev)
{
struct qcom_tcsr_softc *sc = device_get_softc(dev);
if (sc->sc_mem_res)
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
mtx_destroy(&sc->sc_mtx);
return (0);
}
static device_method_t qcom_tcsr_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, qcom_tcsr_probe),
DEVMETHOD(device_attach, qcom_tcsr_attach),
DEVMETHOD(device_detach, qcom_tcsr_detach),
DEVMETHOD_END
};
static driver_t qcom_tcsr_driver = {
"qcom_tcsr",
qcom_tcsr_methods,
sizeof(struct qcom_tcsr_softc),
};
/*
* This has to be run early, before the rest of the hardware is potentially
* probed/attached.
*/
EARLY_DRIVER_MODULE(qcom_tcsr, simplebus, qcom_tcsr_driver, 0, 0,
BUS_PASS_CPU + BUS_PASS_ORDER_EARLY);
SIMPLEBUS_PNP_INFO(compat_data);
|