txcsbus.c revision 1.2 1 1.2 uch /* $NetBSD: txcsbus.c,v 1.2 1999/12/03 18:15:41 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.1 uch * Copyright (c) 1999, by UCHIYAMA Yasushi
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * Redistribution and use in source and binary forms, with or without
8 1.1 uch * modification, are permitted provided that the following conditions
9 1.1 uch * are met:
10 1.1 uch * 1. Redistributions of source code must retain the above copyright
11 1.1 uch * notice, this list of conditions and the following disclaimer.
12 1.1 uch * 2. The name of the developer may NOT be used to endorse or promote products
13 1.1 uch * derived from this software without specific prior written permission.
14 1.1 uch *
15 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 uch * SUCH DAMAGE.
26 1.1 uch *
27 1.1 uch */
28 1.1 uch #include "opt_tx39_debug.h"
29 1.1 uch
30 1.1 uch #include <sys/param.h>
31 1.1 uch #include <sys/systm.h>
32 1.1 uch #include <sys/device.h>
33 1.1 uch
34 1.1 uch #include <machine/bus.h>
35 1.1 uch #include <machine/intr.h>
36 1.1 uch
37 1.1 uch #include <machine/platid.h>
38 1.1 uch #include <machine/platid_mask.h>
39 1.1 uch
40 1.1 uch #include <hpcmips/tx/tx39var.h>
41 1.1 uch #include <hpcmips/tx/txcsbusvar.h>
42 1.1 uch #include <hpcmips/tx/tx39biuvar.h>
43 1.1 uch #include <hpcmips/tx/tx39biureg.h>
44 1.1 uch
45 1.1 uch #include "locators.h"
46 1.1 uch
47 1.1 uch int txcsbus_match __P((struct device*, struct cfdata*, void*));
48 1.1 uch void txcsbus_attach __P((struct device*, struct device*, void*));
49 1.1 uch int txcsbus_print __P((void*, const char*));
50 1.1 uch int txcsbus_search __P((struct device*, struct cfdata*, void*));
51 1.1 uch
52 1.1 uch struct txcsbus_softc {
53 1.1 uch struct device sc_dev;
54 1.1 uch tx_chipset_tag_t sc_tc;
55 1.1 uch /* chip select space tag */
56 1.1 uch bus_space_tag_t sc_cst[TX39_MAXCS];
57 1.1 uch };
58 1.1 uch
59 1.1 uch struct cfattach txcsbus_ca = {
60 1.1 uch sizeof(struct txcsbus_softc), txcsbus_match, txcsbus_attach
61 1.1 uch };
62 1.1 uch
63 1.2 uch bus_space_tag_t __txcsbus_alloc_cstag __P((struct txcsbus_softc*,
64 1.2 uch struct cs_handle*));
65 1.1 uch
66 1.1 uch int
67 1.1 uch txcsbus_match(parent, cf, aux)
68 1.1 uch struct device *parent;
69 1.1 uch struct cfdata *cf;
70 1.1 uch void *aux;
71 1.1 uch {
72 1.1 uch struct csbus_attach_args *cba = aux;
73 1.1 uch platid_mask_t mask;
74 1.1 uch
75 1.2 uch if (strcmp(cba->cba_busname, cf->cf_driver->cd_name)) {
76 1.1 uch return 0;
77 1.2 uch }
78 1.1 uch
79 1.2 uch if (cf->cf_loc[TXCSBUSIFCF_PLATFORM] ==
80 1.2 uch TXCSBUSIFCF_PLATFORM_DEFAULT) {
81 1.1 uch return 1;
82 1.2 uch }
83 1.1 uch
84 1.1 uch mask = PLATID_DEREF(cf->cf_loc[TXCSBUSIFCF_PLATFORM]);
85 1.2 uch if (platid_match(&platid, &mask)) {
86 1.1 uch return 2;
87 1.2 uch }
88 1.1 uch
89 1.1 uch return 0;
90 1.1 uch }
91 1.1 uch
92 1.1 uch void
93 1.1 uch txcsbus_attach(parent, self, aux)
94 1.1 uch struct device *parent;
95 1.1 uch struct device *self;
96 1.1 uch void *aux;
97 1.1 uch {
98 1.1 uch struct csbus_attach_args *cba = aux;
99 1.1 uch struct txcsbus_softc *sc = (void*)self;
100 1.1 uch
101 1.1 uch sc->sc_tc = cba->cba_tc;
102 1.1 uch printf("\n");
103 1.1 uch
104 1.1 uch /*
105 1.1 uch * Attach external chip.
106 1.1 uch */
107 1.1 uch config_search(txcsbus_search, self, txcsbus_print);
108 1.1 uch }
109 1.1 uch
110 1.1 uch int
111 1.1 uch txcsbus_print(aux, pnp)
112 1.1 uch void *aux;
113 1.1 uch const char *pnp;
114 1.1 uch {
115 1.1 uch return pnp ? QUIET : UNCONF;
116 1.1 uch }
117 1.1 uch
118 1.1 uch int
119 1.1 uch txcsbus_search(parent, cf, aux)
120 1.1 uch struct device *parent;
121 1.1 uch struct cfdata *cf;
122 1.1 uch void *aux;
123 1.1 uch {
124 1.1 uch struct txcsbus_softc *sc = (void*)parent;
125 1.1 uch struct cs_attach_args ca;
126 1.1 uch
127 1.1 uch ca.ca_tc = sc->sc_tc;
128 1.1 uch
129 1.1 uch ca.ca_csreg.cs = cf->cf_loc[TXCSBUSCF_REGCS];
130 1.1 uch ca.ca_csreg.csbase = cf->cf_loc[TXCSBUSCF_REGCSBASE];
131 1.1 uch ca.ca_csreg.cssize = cf->cf_loc[TXCSBUSCF_REGCSSIZE];
132 1.1 uch ca.ca_csreg.cswidth = cf->cf_loc[TXCSBUSCF_REGCSWIDTH];
133 1.2 uch
134 1.1 uch if (ca.ca_csreg.cs != TXCSBUSCF_REGCS_DEFAULT) {
135 1.2 uch ca.ca_csreg.cstag = __txcsbus_alloc_cstag(sc, &ca.ca_csreg);
136 1.1 uch }
137 1.1 uch
138 1.1 uch ca.ca_csio.cs = cf->cf_loc[TXCSBUSCF_IOCS];
139 1.1 uch ca.ca_csio.csbase = cf->cf_loc[TXCSBUSCF_IOCSBASE];
140 1.1 uch ca.ca_csio.cssize = cf->cf_loc[TXCSBUSCF_IOCSSIZE];
141 1.1 uch ca.ca_csio.cswidth = cf->cf_loc[TXCSBUSCF_IOCSWIDTH];
142 1.2 uch
143 1.1 uch if (ca.ca_csio.cs != TXCSBUSCF_IOCS_DEFAULT) {
144 1.2 uch ca.ca_csio.cstag = __txcsbus_alloc_cstag(sc, &ca.ca_csio);
145 1.1 uch }
146 1.2 uch
147 1.1 uch ca.ca_csmem.cs = cf->cf_loc[TXCSBUSCF_MEMCS];
148 1.1 uch ca.ca_csmem.csbase = cf->cf_loc[TXCSBUSCF_MEMCSBASE];
149 1.1 uch ca.ca_csmem.cssize = cf->cf_loc[TXCSBUSCF_MEMCSSIZE];
150 1.1 uch ca.ca_csmem.cswidth = cf->cf_loc[TXCSBUSCF_MEMCSWIDTH];
151 1.2 uch
152 1.1 uch if (ca.ca_csmem.cs != TXCSBUSCF_MEMCS_DEFAULT) {
153 1.2 uch ca.ca_csmem.cstag = __txcsbus_alloc_cstag(sc, &ca.ca_csmem);
154 1.1 uch }
155 1.1 uch
156 1.1 uch ca.ca_irq1 = cf->cf_loc[TXCSBUSCF_IRQ1];
157 1.1 uch ca.ca_irq2 = cf->cf_loc[TXCSBUSCF_IRQ2];
158 1.1 uch ca.ca_irq3 = cf->cf_loc[TXCSBUSCF_IRQ3];
159 1.1 uch
160 1.1 uch if ((*cf->cf_attach->ca_match)(parent, cf, &ca)) {
161 1.1 uch config_attach(parent, cf, &ca, txcsbus_print);
162 1.1 uch }
163 1.1 uch
164 1.1 uch return 0;
165 1.1 uch }
166 1.1 uch
167 1.1 uch bus_space_tag_t
168 1.1 uch __txcsbus_alloc_cstag(sc, csh)
169 1.1 uch struct txcsbus_softc *sc;
170 1.1 uch struct cs_handle *csh;
171 1.1 uch {
172 1.1 uch /* TX39 CS mapping. (nonconfigurationable) */
173 1.1 uch struct csmap {
174 1.1 uch char *cs_name;
175 1.1 uch paddr_t cs_addr;
176 1.1 uch psize_t cs_size;
177 1.1 uch } __csmap[] = {
178 1.2 uch [TX39_CS0] = {"CS0(ROM)" , TX39_SYSADDR_CS0 ,
179 1.2 uch TX39_SYSADDR_CS_SIZE},
180 1.2 uch [TX39_CS1] = {"CS1" , TX39_SYSADDR_CS1 ,
181 1.2 uch TX39_SYSADDR_CS_SIZE},
182 1.2 uch [TX39_CS2] = {"CS2" , TX39_SYSADDR_CS2 ,
183 1.2 uch TX39_SYSADDR_CS_SIZE},
184 1.2 uch [TX39_CS3] = {"CS3" , TX39_SYSADDR_CS3 ,
185 1.2 uch TX39_SYSADDR_CS_SIZE},
186 1.2 uch [TX39_MCS0] = {"MCS0" , TX39_SYSADDR_MCS0 ,
187 1.2 uch TX39_SYSADDR_MCS_SIZE},
188 1.2 uch [TX39_MCS1] = {"MCS1" , TX39_SYSADDR_MCS1 ,
189 1.2 uch TX39_SYSADDR_MCS_SIZE},
190 1.1 uch #ifdef TX391X
191 1.2 uch [TX39_MCS2] = {"MCS2" , TX39_SYSADDR_MCS2 ,
192 1.2 uch TX39_SYSADDR_MCS_SIZE},
193 1.2 uch [TX39_MCS3] = {"MCS3" , TX39_SYSADDR_MCS3 ,
194 1.2 uch TX39_SYSADDR_MCS_SIZE},
195 1.1 uch #endif /* TX391X */
196 1.2 uch [TX39_CARD1] = {"CARD1(io/attr)", TX39_SYSADDR_CARD1 ,
197 1.2 uch TX39_SYSADDR_CARD_SIZE},
198 1.2 uch [TX39_CARD2] = {"CARD2(io/attr)", TX39_SYSADDR_CARD2 ,
199 1.2 uch TX39_SYSADDR_CARD_SIZE},
200 1.2 uch [TX39_CARD1MEM] = {"CARD1(mem)" , TX39_SYSADDR_CARD1MEM ,
201 1.2 uch TX39_SYSADDR_CARD_SIZE},
202 1.2 uch [TX39_CARD2MEM] = {"CARD2(mem)" , TX39_SYSADDR_CARD2MEM ,
203 1.2 uch TX39_SYSADDR_CARD_SIZE},
204 1.1 uch };
205 1.1 uch
206 1.1 uch tx_chipset_tag_t tc = sc->sc_tc;
207 1.1 uch int cs = csh->cs;
208 1.1 uch int width = csh->cswidth;
209 1.1 uch bus_space_tag_t iot;
210 1.1 uch txreg_t reg;
211 1.1 uch
212 1.1 uch if (!TX39_ISCS(cs) && !TX39_ISMCS(cs) && !TX39_ISCARD(cs)) {
213 1.1 uch panic("txcsbus_alloc_tag: bogus chip select %d\n", cs);
214 1.1 uch }
215 1.1 uch
216 1.1 uch printf("(%s)", __csmap[cs].cs_name);
217 1.1 uch /* Already setuped chip select */
218 1.1 uch if (sc->sc_cst[cs]) {
219 1.1 uch return sc->sc_cst[cs];
220 1.1 uch }
221 1.1 uch
222 1.1 uch iot = hpcmips_alloc_bus_space_tag();
223 1.1 uch sc->sc_cst[cs] = iot;
224 1.1 uch
225 1.1 uch iot->t_base = __csmap[cs].cs_addr;
226 1.1 uch iot->t_size = __csmap[cs].cs_size;
227 1.1 uch strcpy(iot->t_name , __csmap[cs].cs_name);
228 1.1 uch
229 1.1 uch /* CS bus-width (configurationable) */
230 1.1 uch switch (width) {
231 1.1 uch default:
232 1.1 uch panic("txcsbus_alloc_tag: bogus bus width %d\n", width);
233 1.2 uch
234 1.1 uch case 32:
235 1.1 uch if (TX39_ISCS(cs)) {
236 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
237 1.1 uch reg |= (1 << cs);
238 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG0_REG, reg);
239 1.2 uch } else if(TX39_ISMCS(cs)) {
240 1.1 uch #ifdef TX391X
241 1.1 uch panic("txcsbus_alloc_tag: MCS is 16bit only");
242 1.2 uch #endif /* TX391X */
243 1.2 uch #ifdef TX392X
244 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG1_REG);
245 1.2 uch reg |= ((cs == TX39_MCS0) ?
246 1.2 uch TX39_MEMCONFIG1_MCS0_32 :
247 1.1 uch TX39_MEMCONFIG1_MCS1_32);
248 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG1_REG, reg);
249 1.2 uch #endif /* TX392X */
250 1.1 uch }
251 1.1 uch break;
252 1.2 uch
253 1.1 uch case 16:
254 1.1 uch if (TX39_ISCS(cs)) {
255 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
256 1.1 uch reg &= ~(1 << cs);
257 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG0_REG, reg);
258 1.2 uch } else if(TX39_ISMCS(cs)) {
259 1.2 uch /* TX391X always 16bit port */
260 1.1 uch #ifdef TX392X
261 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG1_REG);
262 1.2 uch reg &= ~((cs == TX39_MCS0) ?
263 1.2 uch TX39_MEMCONFIG1_MCS0_32 :
264 1.1 uch TX39_MEMCONFIG1_MCS1_32);
265 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG1_REG, reg);
266 1.2 uch #endif /* TX392X */
267 1.2 uch } else {
268 1.2 uch /* CARD io/attr or mem */
269 1.2 uch reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
270 1.2 uch
271 1.2 uch /* enable I/O access */
272 1.2 uch reg |= (cs == TX39_CARD1) ?
273 1.2 uch TX39_MEMCONFIG3_CARD1IOEN :
274 1.2 uch TX39_MEMCONFIG3_CARD2IOEN;
275 1.2 uch /* disable 8bit access */
276 1.2 uch #ifdef TX392X
277 1.2 uch reg &= ~((cs == TX39_CARD1) ?
278 1.2 uch TX39_MEMCONFIG3_CARD1_8SEL :
279 1.2 uch TX39_MEMCONFIG3_CARD2_8SEL);
280 1.2 uch #endif /* TX392X */
281 1.2 uch #ifdef TX391X
282 1.2 uch reg &= ~TX39_MEMCONFIG3_PORT8SEL;
283 1.2 uch #endif /* TX391X */
284 1.2 uch tx_conf_write(tc, TX39_MEMCONFIG3_REG, reg);
285 1.1 uch }
286 1.1 uch break;
287 1.2 uch
288 1.2 uch case 8:
289 1.2 uch if (TX39_ISCARD(cs)) {
290 1.2 uch reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
291 1.2 uch
292 1.2 uch /* enable I/O access */
293 1.2 uch reg |= (cs == TX39_CARD1) ?
294 1.2 uch TX39_MEMCONFIG3_CARD1IOEN :
295 1.2 uch TX39_MEMCONFIG3_CARD2IOEN;
296 1.2 uch /* disable 8bit access */
297 1.2 uch #ifdef TX392X
298 1.2 uch reg |= (cs == TX39_CARD1) ?
299 1.2 uch TX39_MEMCONFIG3_CARD1_8SEL :
300 1.2 uch TX39_MEMCONFIG3_CARD2_8SEL;
301 1.2 uch #endif /* TX392X */
302 1.2 uch #ifdef TX391X
303 1.2 uch reg |= TX39_MEMCONFIG3_PORT8SEL;
304 1.2 uch #endif /* TX391X */
305 1.2 uch tx_conf_write(tc, TX39_MEMCONFIG3_REG, reg);
306 1.2 uch
307 1.2 uch } else {
308 1.2 uch panic("__txcsbus_alloc_cstag: CS%d 8bit mode is"
309 1.2 uch "not allowed");
310 1.2 uch }
311 1.1 uch }
312 1.1 uch
313 1.1 uch hpcmips_init_bus_space_extent(iot);
314 1.1 uch printf("\n");
315 1.1 uch
316 1.1 uch return iot;
317 1.1 uch }
318