1 /* $NetBSD: plum.c,v 1.6 2002/10/02 05:26:46 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 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/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 #include <sys/malloc.h> 43 44 #include <machine/bus.h> 45 #include <machine/intr.h> 46 47 #include <hpcmips/tx/tx39var.h> 48 #include <hpcmips/tx/txcsbusvar.h> 49 #include <hpcmips/dev/plumvar.h> 50 #include <hpcmips/dev/plumreg.h> 51 52 int plum_match(struct device *, struct cfdata *, void *); 53 void plum_attach(struct device *, struct device *, void *); 54 int plum_print(void *, const char *); 55 int plum_search(struct device *, struct cfdata *, void *); 56 57 struct plum_softc { 58 struct device sc_dev; 59 plum_chipset_tag_t sc_pc; 60 bus_space_tag_t sc_csregt; 61 bus_space_tag_t sc_csiot; 62 bus_space_tag_t sc_csmemt; 63 int sc_irq; 64 int sc_pri; 65 }; 66 67 CFATTACH_DECL(plum, sizeof(struct plum_softc), 68 plum_match, plum_attach, NULL, NULL); 69 70 plumreg_t plum_idcheck(bus_space_tag_t); 71 72 int 73 plum_match(struct device *parent, struct cfdata *cf, void *aux) 74 { 75 struct cs_attach_args *ca = aux; 76 77 switch (plum_idcheck(ca->ca_csreg.cstag)) { 78 default: 79 return (0); 80 case PLUM2_1: 81 case PLUM2_2: 82 } 83 84 return (1); 85 } 86 87 void 88 plum_attach(struct device *parent, struct device *self, void *aux) 89 { 90 struct cs_attach_args *ca = aux; 91 struct plum_softc *sc = (void*)self; 92 plumreg_t reg; 93 94 sc->sc_csregt = ca->ca_csreg.cstag; 95 sc->sc_csiot = ca->ca_csio.cstag; 96 sc->sc_csmemt = ca->ca_csmem.cstag; 97 sc->sc_irq = ca->ca_irq1; 98 99 switch (plum_idcheck(sc->sc_csregt)) { 100 default: 101 printf(": unknown revision %#x\n", reg); 102 return; 103 case PLUM2_1: 104 printf(": Plum2 #1\n"); 105 break; 106 case PLUM2_2: 107 printf(": Plum2 #2\n"); 108 break; 109 } 110 if (!(sc->sc_pc = malloc(sizeof(struct plum_chipset_tag), 111 M_DEVBUF, M_NOWAIT))) { 112 panic("no memory"); 113 } 114 memset(sc->sc_pc, 0, sizeof(struct plum_chipset_tag)); 115 sc->sc_pc->pc_tc = ca->ca_tc; 116 117 /* Attach Plum devices */ 118 /* 119 * interrupt, power/clock module is used by other plum module. 120 * attach first. 121 */ 122 sc->sc_pri = 2; 123 config_search(plum_search, self, plum_print); 124 /* 125 * Other plum module. 126 */ 127 sc->sc_pri = 1; 128 config_search(plum_search, self, plum_print); 129 } 130 131 plumreg_t 132 plum_idcheck(bus_space_tag_t regt) 133 { 134 bus_space_handle_t regh; 135 plumreg_t reg; 136 137 if (bus_space_map(regt, PLUM_ID_REGBASE, 138 PLUM_ID_REGSIZE, 0, ®h)) { 139 printf("ID register map failed\n"); 140 return (0); 141 } 142 reg = plum_conf_read(regt, regh, PLUM_ID_REG); 143 bus_space_unmap(regt, regh, PLUM_ID_REGSIZE); 144 145 return (reg); 146 } 147 148 int 149 plum_print(void *aux, const char *pnp) 150 { 151 152 return (pnp ? QUIET : UNCONF); 153 } 154 155 int 156 plum_search(struct device *parent, struct cfdata *cf, void *aux) 157 { 158 struct plum_softc *sc = (void*)parent; 159 struct plum_attach_args pa; 160 161 pa.pa_pc = sc->sc_pc; 162 pa.pa_regt = sc->sc_csregt; 163 pa.pa_iot = sc->sc_csiot; 164 pa.pa_memt = sc->sc_csmemt; 165 pa.pa_irq = sc->sc_irq; 166 167 if (config_match(parent, cf, &pa) == sc->sc_pri) { 168 config_attach(parent, cf, &pa, plum_print); 169 } 170 171 return 0; 172 } 173 174 plumreg_t 175 plum_conf_read(bus_space_tag_t t, bus_space_handle_t h, int o) 176 { 177 plumreg_t reg; 178 179 reg = bus_space_read_4(t, h, o); 180 181 return (reg); 182 } 183 184 void 185 plum_conf_write(bus_space_tag_t t, bus_space_handle_t h, int o, plumreg_t v) 186 { 187 188 bus_space_write_4(t, h, o, v); 189 } 190 191 void 192 plum_conf_register_intr(plum_chipset_tag_t t, void *intrt) 193 { 194 195 if (t->pc_intrt) { 196 panic("duplicate intrt"); 197 } 198 199 t->pc_intrt = intrt; 200 } 201 202 void 203 plum_conf_register_power(plum_chipset_tag_t t, void *powert) 204 { 205 206 if (t->pc_powert) { 207 panic("duplicate powert"); 208 } 209 210 t->pc_powert = powert; 211 } 212