1 /* $NetBSD: sbdio.c,v 1.3 2008/04/28 20:23:18 martin 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: sbdio.c,v 1.3 2008/04/28 20:23:18 martin Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <machine/autoconf.h> 40 #define _EWS4800MIPS_BUS_DMA_PRIVATE 41 #include <machine/bus.h> 42 #include <machine/sbdvar.h> 43 #include <machine/sbdiovar.h> 44 45 #include "ioconf.h" 46 47 struct sbdio_softc { 48 device_t sc_dev; 49 struct ews4800mips_bus_space sc_bus_tag; 50 struct ews4800mips_bus_dma_tag sc_dma_tag; 51 }; 52 53 static int sbdio_match(device_t, cfdata_t, void *); 54 static void sbdio_attach(device_t, device_t, void *); 55 static int sbdio_print(void *, const char *); 56 57 CFATTACH_DECL_NEW(sbdio, sizeof(struct sbdio_softc), 58 sbdio_match, sbdio_attach, NULL, NULL); 59 60 static int sbdio_found; 61 62 int 63 sbdio_match(device_t parent, cfdata_t cf, void *aux) 64 { 65 struct mainbus_attach_args *ma = aux; 66 67 if (sbdio_found != 0) 68 return 0; 69 70 if (strcmp(ma->ma_name, sbdio_cd.cd_name) != 0) 71 return 0; 72 73 if (platform.sbdiodevs == NULL) 74 return 0; 75 76 return 1; 77 } 78 79 void 80 sbdio_attach(device_t parent, device_t self, void *aux) 81 { 82 struct sbdio_softc *sc = device_private(self); 83 struct sbdio_attach_args sa; 84 const struct sbdiodevdesc *sd; 85 86 sbdio_found = 1; 87 88 sc->sc_dev = self; 89 aprint_normal("\n"); 90 91 /* structure assignment */ 92 sc->sc_dma_tag = ews4800mips_default_bus_dma_tag; 93 94 bus_space_create(&sc->sc_bus_tag, device_xname(sc->sc_dev), 95 MIPS_KSEG1_START, MIPS_KSEG2_START - MIPS_KSEG1_START); /* XXX */ 96 97 for (sd = platform.sbdiodevs; sd->sd_name != NULL; sd++) { 98 sa.sa_name = sd->sd_name; 99 sa.sa_bust = &sc->sc_bus_tag; 100 sa.sa_dmat = &sc->sc_dma_tag; 101 sa.sa_addr1 = sd->sd_addr1; 102 sa.sa_addr2 = sd->sd_addr2; 103 sa.sa_irq = sd->sd_irq; 104 sa.sa_flags = sd->sd_flags; 105 config_found(self, &sa, sbdio_print); 106 } 107 } 108 109 int 110 sbdio_print(void *aux, const char *pnp) 111 { 112 struct sbdio_attach_args *sa = aux; 113 114 if (sa->sa_addr1 != (paddr_t)-1) { 115 aprint_normal(" at 0x%lx", sa->sa_addr1); 116 if (sa->sa_addr2 != (paddr_t)-1) 117 aprint_normal(", 0x%lx", sa->sa_addr2); 118 } 119 if (sa->sa_irq != -1) 120 aprint_normal(" irq %d", sa->sa_irq); 121 122 return pnp ? QUIET : UNCONF; 123 } 124