Home | History | Annotate | Line # | Download | only in sbd
sbdio.c revision 1.2
      1 /*	$NetBSD: sbdio.c,v 1.2 2008/03/29 08:14:41 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: sbdio.c,v 1.2 2008/03/29 08:14:41 tsutsui Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 
     46 #include <machine/autoconf.h>
     47 #define _EWS4800MIPS_BUS_DMA_PRIVATE
     48 #include <machine/bus.h>
     49 #include <machine/sbdvar.h>
     50 #include <machine/sbdiovar.h>
     51 
     52 #include "ioconf.h"
     53 
     54 struct sbdio_softc {
     55 	device_t sc_dev;
     56 	struct ews4800mips_bus_space sc_bus_tag;
     57 	struct ews4800mips_bus_dma_tag sc_dma_tag;
     58 };
     59 
     60 static int sbdio_match(device_t, cfdata_t, void *);
     61 static void sbdio_attach(device_t, device_t, void *);
     62 static int sbdio_print(void *, const char *);
     63 
     64 CFATTACH_DECL_NEW(sbdio, sizeof(struct sbdio_softc),
     65     sbdio_match, sbdio_attach, NULL, NULL);
     66 
     67 static int sbdio_found;
     68 
     69 int
     70 sbdio_match(device_t parent, cfdata_t cf, void *aux)
     71 {
     72 	struct mainbus_attach_args *ma = aux;
     73 
     74 	if (sbdio_found != 0)
     75 		return 0;
     76 
     77 	if (strcmp(ma->ma_name, sbdio_cd.cd_name) != 0)
     78 		return 0;
     79 
     80 	if (platform.sbdiodevs == NULL)
     81 		return 0;
     82 
     83 	return 1;
     84 }
     85 
     86 void
     87 sbdio_attach(device_t parent, device_t self, void *aux)
     88 {
     89 	struct sbdio_softc *sc = device_private(self);
     90 	struct sbdio_attach_args sa;
     91 	const struct sbdiodevdesc *sd;
     92 
     93 	sbdio_found = 1;
     94 
     95 	sc->sc_dev = self;
     96 	aprint_normal("\n");
     97 
     98 	/* structure assignment */
     99 	sc->sc_dma_tag = ews4800mips_default_bus_dma_tag;
    100 
    101 	bus_space_create(&sc->sc_bus_tag, device_xname(sc->sc_dev),
    102 	    MIPS_KSEG1_START, MIPS_KSEG2_START - MIPS_KSEG1_START); /* XXX */
    103 
    104 	for (sd = platform.sbdiodevs; sd->sd_name != NULL; sd++) {
    105 		sa.sa_name  = sd->sd_name;
    106 		sa.sa_bust  = &sc->sc_bus_tag;
    107 		sa.sa_dmat  = &sc->sc_dma_tag;
    108 		sa.sa_addr1 = sd->sd_addr1;
    109 		sa.sa_addr2 = sd->sd_addr2;
    110 		sa.sa_irq   = sd->sd_irq;
    111 		sa.sa_flags = sd->sd_flags;
    112 		config_found(self, &sa, sbdio_print);
    113 	}
    114 }
    115 
    116 int
    117 sbdio_print(void *aux, const char *pnp)
    118 {
    119 	struct sbdio_attach_args *sa = aux;
    120 
    121 	if (sa->sa_addr1 != (paddr_t)-1) {
    122 		aprint_normal(" at 0x%lx", sa->sa_addr1);
    123 		if (sa->sa_addr2 != (paddr_t)-1)
    124 			aprint_normal(", 0x%lx", sa->sa_addr2);
    125 	}
    126 	if (sa->sa_irq != -1)
    127 		aprint_normal(" irq %d", sa->sa_irq);
    128 
    129 	return pnp ? QUIET : UNCONF;
    130 }
    131