Lines 43-53
Link Here
|
43 |
|
43 |
|
44 |
#include "clkdev_if.h" |
44 |
#include "clkdev_if.h" |
45 |
|
45 |
|
|
|
46 |
static struct resource_spec armada38x_gateclk_specs[] = { |
47 |
{ SYS_RES_MEMORY, 0, RF_ACTIVE }, |
48 |
{ -1, 0 } |
49 |
}; |
50 |
|
51 |
#define RD4(_sc, addr) bus_read_4(_sc->res, addr) |
52 |
#define WR4(_sc, addr, val) bus_write_4(_sc->res, addr, val) |
53 |
|
46 |
struct armada38x_gateclk_softc |
54 |
struct armada38x_gateclk_softc |
47 |
{ |
55 |
{ |
48 |
struct clkdom *clkdom; |
56 |
struct resource *res; |
49 |
struct mtx mtx; |
57 |
struct clkdom *clkdom; |
50 |
const char* parent; |
58 |
struct mtx mtx; |
|
|
59 |
const char* parent; |
51 |
}; |
60 |
}; |
52 |
|
61 |
|
53 |
static struct clk_gate_def gateclk_nodes[] = |
62 |
static struct clk_gate_def gateclk_nodes[] = |
Lines 219-228
static struct clk_gate_def gateclk_nodes[] =
Link Here
|
219 |
static int armada38x_gateclk_probe(device_t dev); |
228 |
static int armada38x_gateclk_probe(device_t dev); |
220 |
static int armada38x_gateclk_attach(device_t dev); |
229 |
static int armada38x_gateclk_attach(device_t dev); |
221 |
|
230 |
|
|
|
231 |
static int |
232 |
armada38x_gateclk_write_4(device_t dev, bus_addr_t addr, uint32_t val) |
233 |
{ |
234 |
struct armada38x_gateclk_softc *sc = device_get_softc(dev); |
235 |
|
236 |
WR4(sc, addr, val); |
237 |
return (0); |
238 |
} |
239 |
|
240 |
static int |
241 |
armada38x_gateclk_read_4(device_t dev, bus_addr_t addr, uint32_t *val) |
242 |
{ |
243 |
struct armada38x_gateclk_softc *sc = device_get_softc(dev); |
244 |
|
245 |
*val = RD4(sc, addr); |
246 |
return (0); |
247 |
} |
248 |
|
249 |
static int |
250 |
armada38x_gateclk_modify_4(device_t dev, bus_addr_t addr, uint32_t clr, |
251 |
uint32_t set) |
252 |
{ |
253 |
struct armada38x_gateclk_softc *sc = device_get_softc(dev); |
254 |
uint32_t reg; |
255 |
|
256 |
reg = RD4(sc, addr); |
257 |
reg &= ~clr; |
258 |
reg |= set; |
259 |
WR4(sc, addr, reg); |
260 |
|
261 |
return (0); |
262 |
} |
263 |
|
264 |
static void |
265 |
armada38x_gateclk_device_lock(device_t dev) |
266 |
{ |
267 |
struct armada38x_gateclk_softc *sc = device_get_softc(dev); |
268 |
|
269 |
mtx_lock(&sc->mtx); |
270 |
} |
271 |
|
272 |
static void |
273 |
armada38x_gateclk_device_unlock(device_t dev) |
274 |
{ |
275 |
struct armada38x_gateclk_softc *sc = device_get_softc(dev); |
276 |
|
277 |
mtx_unlock(&sc->mtx); |
278 |
} |
279 |
|
222 |
static device_method_t armada38x_gateclk_methods[] = { |
280 |
static device_method_t armada38x_gateclk_methods[] = { |
223 |
DEVMETHOD(device_probe, armada38x_gateclk_probe), |
281 |
DEVMETHOD(device_probe, armada38x_gateclk_probe), |
224 |
DEVMETHOD(device_attach, armada38x_gateclk_attach), |
282 |
DEVMETHOD(device_attach, armada38x_gateclk_attach), |
225 |
|
283 |
|
|
|
284 |
/* clkdev interface */ |
285 |
DEVMETHOD(clkdev_write_4, armada38x_gateclk_write_4), |
286 |
DEVMETHOD(clkdev_read_4, armada38x_gateclk_read_4), |
287 |
DEVMETHOD(clkdev_modify_4, armada38x_gateclk_modify_4), |
288 |
DEVMETHOD(clkdev_device_lock, armada38x_gateclk_device_lock), |
289 |
DEVMETHOD(clkdev_device_unlock, armada38x_gateclk_device_unlock), |
290 |
|
226 |
DEVMETHOD_END |
291 |
DEVMETHOD_END |
227 |
}; |
292 |
}; |
228 |
|
293 |
|
Lines 254-259
static int
Link Here
|
254 |
armada38x_gateclk_attach(device_t dev) |
319 |
armada38x_gateclk_attach(device_t dev) |
255 |
{ |
320 |
{ |
256 |
struct armada38x_gateclk_softc *sc; |
321 |
struct armada38x_gateclk_softc *sc; |
|
|
322 |
struct clk_gate_def *defp; |
257 |
phandle_t node; |
323 |
phandle_t node; |
258 |
int i, error; |
324 |
int i, error; |
259 |
clk_t clock; |
325 |
clk_t clock; |
Lines 261-266
armada38x_gateclk_attach(device_t dev)
Link Here
|
261 |
sc = device_get_softc(dev); |
327 |
sc = device_get_softc(dev); |
262 |
node = ofw_bus_get_node(dev); |
328 |
node = ofw_bus_get_node(dev); |
263 |
|
329 |
|
|
|
330 |
if (bus_alloc_resources(dev, armada38x_gateclk_specs, &sc->res) != 0) { |
331 |
device_printf(dev, "Cannot allocate resources.\n"); |
332 |
return (ENXIO); |
333 |
} |
334 |
|
264 |
mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); |
335 |
mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); |
265 |
|
336 |
|
266 |
sc->clkdom = clkdom_create(dev); |
337 |
sc->clkdom = clkdom_create(dev); |
Lines 276-283
armada38x_gateclk_attach(device_t dev)
Link Here
|
276 |
sc->parent = clk_get_name(clock); |
347 |
sc->parent = clk_get_name(clock); |
277 |
|
348 |
|
278 |
for (i = 0; i < nitems(gateclk_nodes); ++i) { |
349 |
for (i = 0; i < nitems(gateclk_nodes); ++i) { |
279 |
gateclk_nodes[i].clkdef.parent_names = &sc->parent; |
350 |
/* Fill clk_gate fields. */ |
280 |
error = clknode_gate_register(sc->clkdom, &gateclk_nodes[i]); |
351 |
defp = &gateclk_nodes[i]; |
|
|
352 |
defp->clkdef.parent_names = &sc->parent; |
353 |
defp->offset = 0; |
354 |
defp->mask = 0x1; |
355 |
defp->on_value = 1; |
356 |
defp->off_value = 0; |
357 |
|
358 |
error = clknode_gate_register(sc->clkdom, defp); |
281 |
if (error != 0) { |
359 |
if (error != 0) { |
282 |
device_printf(dev, "Cannot create gate nodes\n"); |
360 |
device_printf(dev, "Cannot create gate nodes\n"); |
283 |
return (error); |
361 |
return (error); |