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