Deleted Added
full compact
ixp425.c (167570) ixp425.c (169952)
1/* $NetBSD: ixp425.c,v 1.10 2005/12/11 12:16:51 christos Exp $ */
2
3/*
4 * Copyright (c) 2003
5 * Ichiro FUKUHARA <ichiro@ichiro.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <sys/cdefs.h>
1/* $NetBSD: ixp425.c,v 1.10 2005/12/11 12:16:51 christos Exp $ */
2
3/*
4 * Copyright (c) 2003
5 * Ichiro FUKUHARA <ichiro@ichiro.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/ixp425.c 167570 2007-03-14 19:03:07Z jhay $");
37__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/ixp425.c 169952 2007-05-24 16:25:49Z sam $");
38
39#define _ARM32_BUS_DMA_PRIVATE
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/bus.h>
43#include <sys/kernel.h>
44#include <sys/module.h>
45#include <sys/malloc.h>

--- 185 unchanged lines hidden (view full) ---

231 panic("ixp425_attach: failed to set up IRQ rman");
232
233 sc->sc_mem_rman.rm_type = RMAN_ARRAY;
234 sc->sc_mem_rman.rm_descr = "IXP425 Memory";
235 if (rman_init(&sc->sc_mem_rman) != 0 ||
236 rman_manage_region(&sc->sc_mem_rman, 0, ~0) != 0)
237 panic("ixp425_attach: failed to set up IRQ rman");
238
38
39#define _ARM32_BUS_DMA_PRIVATE
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/bus.h>
43#include <sys/kernel.h>
44#include <sys/module.h>
45#include <sys/malloc.h>

--- 185 unchanged lines hidden (view full) ---

231 panic("ixp425_attach: failed to set up IRQ rman");
232
233 sc->sc_mem_rman.rm_type = RMAN_ARRAY;
234 sc->sc_mem_rman.rm_descr = "IXP425 Memory";
235 if (rman_init(&sc->sc_mem_rman) != 0 ||
236 rman_manage_region(&sc->sc_mem_rman, 0, ~0) != 0)
237 panic("ixp425_attach: failed to set up IRQ rman");
238
239 device_add_child(dev, "pcib", 0);
240 device_add_child(dev, "ixpclk", 0);
241 device_add_child(dev, "ixpwdog", 0);
242 device_add_child(dev, "ixpiic", 0);
243 device_add_child(dev, "uart", 0);
244 /* XXX these are optional, what if they are not configured? */
245 device_add_child(dev, "ixpqmgr", 0);
246 device_add_child(dev, "npe", 0); /* NPE-B */
247 device_add_child(dev, "npe", 1); /* NPE-C */
248 device_add_child(dev, "ata_avila", 0); /* XXX */
249 device_add_child(dev, "led_avila", 0);
239 BUS_ADD_CHILD(dev, 0, "pcib", 0);
240 BUS_ADD_CHILD(dev, 0, "ixpclk", 0);
241 BUS_ADD_CHILD(dev, 0, "ixpiic", 0);
242 /* XXX move to hints? */
243 BUS_ADD_CHILD(dev, 0, "ixpwdog", 0);
250
244
245 /* attach wired devices via hints */
246 bus_enumerate_hinted_children(dev);
247
251 if (bus_space_map(sc->sc_iot, IXP425_GPIO_HWBASE, IXP425_GPIO_SIZE,
252 0, &sc->sc_gpio_ioh))
253 panic("ixp425_attach: unable to map GPIO registers");
254 if (bus_space_map(sc->sc_iot, IXP425_EXP_HWBASE, IXP425_EXP_SIZE,
255 0, &sc->sc_exp_ioh))
256 panic("ixp425_attach: unable to map Expansion Bus registers");
257
258 bus_generic_probe(dev);
259 bus_generic_attach(dev);
260
261 return (0);
262}
263
248 if (bus_space_map(sc->sc_iot, IXP425_GPIO_HWBASE, IXP425_GPIO_SIZE,
249 0, &sc->sc_gpio_ioh))
250 panic("ixp425_attach: unable to map GPIO registers");
251 if (bus_space_map(sc->sc_iot, IXP425_EXP_HWBASE, IXP425_EXP_SIZE,
252 0, &sc->sc_exp_ioh))
253 panic("ixp425_attach: unable to map Expansion Bus registers");
254
255 bus_generic_probe(dev);
256 bus_generic_attach(dev);
257
258 return (0);
259}
260
261static void
262ixp425_hinted_child(device_t bus, const char *dname, int dunit)
263{
264 device_t child;
265 struct ixp425_ivar *ivar;
266
267 child = BUS_ADD_CHILD(bus, 0, dname, dunit);
268 ivar = IXP425_IVAR(child);
269 resource_int_value(dname, dunit, "addr", &ivar->addr);
270 resource_int_value(dname, dunit, "irq", &ivar->irq);
271}
272
273static device_t
274ixp425_add_child(device_t dev, int order, const char *name, int unit)
275{
276 device_t child;
277 struct ixp425_ivar *ivar;
278
279 child = device_add_child_ordered(dev, order, name, unit);
280 if (child == NULL)
281 return NULL;
282 ivar = malloc(sizeof(struct ixp425_ivar), M_DEVBUF, M_NOWAIT);
283 if (ivar == NULL) {
284 device_delete_child(dev, child);
285 return NULL;
286 }
287 ivar->addr = 0;
288 ivar->irq = -1;
289 device_set_ivars(child, ivar);
290 return child;
291}
292
293static int
294ixp425_read_ivar(device_t bus, device_t child, int which, u_char *result)
295{
296 struct ixp425_ivar *ivar = IXP425_IVAR(child);
297
298 switch (which) {
299 case IXP425_IVAR_ADDR:
300 if (ivar->addr != 0) {
301 *(uint32_t *)result = ivar->addr;
302 return 0;
303 }
304 break;
305 case IXP425_IVAR_IRQ:
306 if (ivar->irq != -1) {
307 *(int *)result = ivar->irq;
308 return 0;
309 }
310 break;
311 }
312 return EINVAL;
313}
314
264static struct resource *
265ixp425_alloc_resource(device_t dev, device_t child, int type, int *rid,
266 u_long start, u_long end, u_long count, u_int flags)
267{
268 struct ixp425_softc *sc = device_get_softc(dev);
269 struct rman *rmanp;
270 struct resource *rv;
315static struct resource *
316ixp425_alloc_resource(device_t dev, device_t child, int type, int *rid,
317 u_long start, u_long end, u_long count, u_int flags)
318{
319 struct ixp425_softc *sc = device_get_softc(dev);
320 struct rman *rmanp;
321 struct resource *rv;
271 uint32_t vbase;
272 int isuart = (start == 0 && end == ~0); /* XXX how to do this right? */
322 uint32_t vbase, addr;
323 int irq;
273
324
274 rv = NULL;
275
276 switch (type) {
277 case SYS_RES_IRQ:
278 rmanp = &sc->sc_irq_rman;
325 switch (type) {
326 case SYS_RES_IRQ:
327 rmanp = &sc->sc_irq_rman;
279 if (isuart) {
280 if (device_get_unit(dev) == 0)
281 start = IXP425_INT_UART0;
282 else
283 start = IXP425_INT_UART1;
284 end = start;
285 }
328 /* override per hints */
329 if (BUS_READ_IVAR(dev, child, IXP425_IVAR_IRQ, &irq) == 0)
330 start = end = irq;
331 rv = rman_reserve_resource(rmanp, start, end, count,
332 flags, child);
333 if (rv != NULL)
334 rman_set_rid(rv, *rid);
286 break;
287
288 case SYS_RES_MEMORY:
289 rmanp = &sc->sc_mem_rman;
335 break;
336
337 case SYS_RES_MEMORY:
338 rmanp = &sc->sc_mem_rman;
290 if (isuart) {
291 if (device_get_unit(dev) == 0)
292 start = IXP425_UART0_HWBASE;
293 else
294 start = IXP425_UART1_HWBASE;
295 end = start + 0x1000;
339 /* override per hints */
340 if (BUS_READ_IVAR(dev, child, IXP425_IVAR_ADDR, &addr) == 0) {
341 start = addr;
342 end = start + 0x1000; /* XXX */
296 }
297 if (getvbase(start, end - start, &vbase))
343 }
344 if (getvbase(start, end - start, &vbase))
298 return (rv);
345 return NULL;
346 rv = rman_reserve_resource(rmanp, start, end, count,
347 flags, child);
348 if (rv != NULL) {
349 rman_set_rid(rv, *rid);
350 if (strcmp(device_get_name(child), "uart") == 0)
351 rman_set_bustag(rv, &ixp425_a4x_bs_tag);
352 else
353 rman_set_bustag(rv, sc->sc_iot);
354 rman_set_bushandle(rv, vbase);
355 }
299 break;
356 break;
300
301 default:
357 default:
302 return (rv);
358 rv = NULL;
359 break;
303 }
360 }
304
305 rv = rman_reserve_resource(rmanp, start, end, count, flags, child);
306 if (rv != NULL) {
307 rman_set_rid(rv, *rid);
308 if (type == SYS_RES_MEMORY) {
309 rman_set_bustag(rv,
310 isuart ? &ixp425_a4x_bs_tag : sc->sc_iot);
311 rman_set_bushandle(rv, vbase);
312 }
313 }
314
315 return (rv);
361 return rv;
316}
317
318static int
319ixp425_setup_intr(device_t dev, device_t child,
320 struct resource *ires, int flags, driver_filter_t *filt,
321 driver_intr_t *intr, void *arg, void **cookiep)
322{
323 uint32_t mask;
362}
363
364static int
365ixp425_setup_intr(device_t dev, device_t child,
366 struct resource *ires, int flags, driver_filter_t *filt,
367 driver_intr_t *intr, void *arg, void **cookiep)
368{
369 uint32_t mask;
324 int i;
370 int i, irq;
325
371
326 if (flags & INTR_TYPE_TTY) {
327 /* XXX: wrong. */
328 if (device_get_unit(dev) == 0)
329 rman_set_start(ires, IXP425_INT_UART0);
330 else
331 rman_set_start(ires, IXP425_INT_UART1);
372 if (BUS_READ_IVAR(dev, child, IXP425_IVAR_IRQ, &irq) == 0) {
373 rman_set_start(ires, irq);
332 rman_set_end(ires, rman_get_start(ires));
333 }
334 BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, filt, intr,
335 arg, cookiep);
336
337 mask = 0;
338 for (i = rman_get_start(ires); i <= rman_get_end(ires); i++)
339 mask |= 1 << i;

--- 21 unchanged lines hidden (view full) ---

361
362static device_method_t ixp425_methods[] = {
363 /* Device interface */
364 DEVMETHOD(device_probe, ixp425_probe),
365 DEVMETHOD(device_attach, ixp425_attach),
366 DEVMETHOD(device_identify, ixp425_identify),
367
368 /* Bus interface */
374 rman_set_end(ires, rman_get_start(ires));
375 }
376 BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, filt, intr,
377 arg, cookiep);
378
379 mask = 0;
380 for (i = rman_get_start(ires); i <= rman_get_end(ires); i++)
381 mask |= 1 << i;

--- 21 unchanged lines hidden (view full) ---

403
404static device_method_t ixp425_methods[] = {
405 /* Device interface */
406 DEVMETHOD(device_probe, ixp425_probe),
407 DEVMETHOD(device_attach, ixp425_attach),
408 DEVMETHOD(device_identify, ixp425_identify),
409
410 /* Bus interface */
411 DEVMETHOD(bus_add_child, ixp425_add_child),
412 DEVMETHOD(bus_hinted_child, ixp425_hinted_child),
413 DEVMETHOD(bus_read_ivar, ixp425_read_ivar),
414
369 DEVMETHOD(bus_alloc_resource, ixp425_alloc_resource),
370 DEVMETHOD(bus_setup_intr, ixp425_setup_intr),
371 DEVMETHOD(bus_teardown_intr, ixp425_teardown_intr),
372
373 {0, 0},
374};
375
376static driver_t ixp425_driver = {
377 "ixp",
378 ixp425_methods,
379 sizeof(struct ixp425_softc),
380};
381static devclass_t ixp425_devclass;
382
383DRIVER_MODULE(ixp, nexus, ixp425_driver, ixp425_devclass, 0, 0);
415 DEVMETHOD(bus_alloc_resource, ixp425_alloc_resource),
416 DEVMETHOD(bus_setup_intr, ixp425_setup_intr),
417 DEVMETHOD(bus_teardown_intr, ixp425_teardown_intr),
418
419 {0, 0},
420};
421
422static driver_t ixp425_driver = {
423 "ixp",
424 ixp425_methods,
425 sizeof(struct ixp425_softc),
426};
427static devclass_t ixp425_devclass;
428
429DRIVER_MODULE(ixp, nexus, ixp425_driver, ixp425_devclass, 0, 0);