it8368.c revision 1.5 1 1.5 uch /* $NetBSD: it8368.c,v 1.5 2000/01/03 18:29:03 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.5 uch * Copyright (c) 1999, 2000, 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
36 1.1 uch #include <dev/pcmcia/pcmciareg.h>
37 1.1 uch #include <dev/pcmcia/pcmciavar.h>
38 1.1 uch #include <dev/pcmcia/pcmciachip.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/dev/it8368reg.h>
43 1.1 uch
44 1.1 uch #ifdef IT8368DEBUG
45 1.1 uch #define DPRINTF(arg) printf arg
46 1.1 uch #else
47 1.1 uch #define DPRINTF(arg)
48 1.1 uch #endif
49 1.1 uch
50 1.1 uch int it8368e_match __P((struct device*, struct cfdata*, void*));
51 1.1 uch void it8368e_attach __P((struct device*, struct device*, void*));
52 1.1 uch int it8368_print __P((void*, const char*));
53 1.1 uch int it8368_submatch __P((struct device*, struct cfdata*, void*));
54 1.1 uch
55 1.4 uch #define IT8368_LASTSTATE_PRESENT 0x0002
56 1.4 uch #define IT8368_LASTSTATE_HALF 0x0001
57 1.4 uch #define IT8368_LASTSTATE_EMPTY 0x0000
58 1.4 uch
59 1.1 uch struct it8368e_softc {
60 1.1 uch struct device sc_dev;
61 1.1 uch struct device *sc_pcmcia;
62 1.1 uch tx_chipset_tag_t sc_tc;
63 1.1 uch
64 1.1 uch /* Register space */
65 1.4 uch bus_space_tag_t sc_csregt;
66 1.4 uch bus_space_handle_t sc_csregh;
67 1.1 uch /* I/O, attribute space */
68 1.4 uch bus_space_tag_t sc_csiot;
69 1.4 uch bus_space_handle_t sc_csioh;
70 1.4 uch bus_addr_t sc_csiobase;
71 1.4 uch bus_size_t sc_csiosize;
72 1.3 uch /*
73 1.3 uch * XXX theses means attribute memory. not memory space.
74 1.3 uch * memory space is 0x64000000.
75 1.3 uch */
76 1.4 uch bus_space_tag_t sc_csmemt;
77 1.4 uch bus_space_handle_t sc_csmemh;
78 1.4 uch bus_addr_t sc_csmembase;
79 1.4 uch bus_size_t sc_csmemsize;
80 1.1 uch
81 1.1 uch /* Separate I/O and attribute space mode */
82 1.1 uch int sc_fixattr;
83 1.1 uch
84 1.1 uch /* Card interrupt handler */
85 1.4 uch int (*sc_card_fun) __P((void*));
86 1.4 uch void *sc_card_arg;
87 1.4 uch void *sc_card_ih;
88 1.4 uch int sc_card_irq;
89 1.4 uch
90 1.4 uch /* Card status change */
91 1.4 uch int sc_irq;
92 1.4 uch void *sc_ih;
93 1.4 uch int sc_laststate;
94 1.1 uch };
95 1.1 uch
96 1.4 uch void it8368_init_socket __P((struct it8368e_softc*));
97 1.1 uch void it8368_attach_socket __P((struct it8368e_softc*));
98 1.1 uch void it8368_access __P((struct it8368e_softc*, int, int));
99 1.1 uch int it8368_intr __P((void*));
100 1.4 uch
101 1.1 uch void it8368_dump __P((struct it8368e_softc*));
102 1.1 uch
103 1.3 uch int it8368_chip_mem_alloc __P((pcmcia_chipset_handle_t, bus_size_t,
104 1.3 uch struct pcmcia_mem_handle*));
105 1.3 uch void it8368_chip_mem_free __P((pcmcia_chipset_handle_t,
106 1.3 uch struct pcmcia_mem_handle*));
107 1.3 uch int it8368_chip_mem_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
108 1.3 uch bus_size_t, struct pcmcia_mem_handle*,
109 1.3 uch bus_addr_t*, int*));
110 1.1 uch void it8368_chip_mem_unmap __P((pcmcia_chipset_handle_t, int));
111 1.3 uch int it8368_chip_io_alloc __P((pcmcia_chipset_handle_t, bus_addr_t,
112 1.3 uch bus_size_t, bus_size_t,
113 1.3 uch struct pcmcia_io_handle*));
114 1.3 uch void it8368_chip_io_free __P((pcmcia_chipset_handle_t,
115 1.3 uch struct pcmcia_io_handle*));
116 1.3 uch int it8368_chip_io_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
117 1.3 uch bus_size_t, struct pcmcia_io_handle*,
118 1.3 uch int*));
119 1.1 uch void it8368_chip_io_unmap __P((pcmcia_chipset_handle_t, int));
120 1.1 uch void it8368_chip_socket_enable __P((pcmcia_chipset_handle_t));
121 1.1 uch void it8368_chip_socket_disable __P((pcmcia_chipset_handle_t));
122 1.3 uch void *it8368_chip_intr_establish __P((pcmcia_chipset_handle_t,
123 1.3 uch struct pcmcia_function*, int,
124 1.3 uch int (*) (void*), void*));
125 1.1 uch void it8368_chip_intr_disestablish __P((pcmcia_chipset_handle_t, void*));
126 1.1 uch
127 1.1 uch static struct pcmcia_chip_functions it8368_functions = {
128 1.1 uch it8368_chip_mem_alloc,
129 1.1 uch it8368_chip_mem_free,
130 1.1 uch it8368_chip_mem_map,
131 1.1 uch it8368_chip_mem_unmap,
132 1.1 uch it8368_chip_io_alloc,
133 1.1 uch it8368_chip_io_free,
134 1.1 uch it8368_chip_io_map,
135 1.1 uch it8368_chip_io_unmap,
136 1.1 uch it8368_chip_intr_establish,
137 1.1 uch it8368_chip_intr_disestablish,
138 1.1 uch it8368_chip_socket_enable,
139 1.1 uch it8368_chip_socket_disable
140 1.1 uch };
141 1.1 uch
142 1.1 uch struct cfattach it8368e_ca = {
143 1.1 uch sizeof(struct it8368e_softc), it8368e_match, it8368e_attach
144 1.1 uch };
145 1.1 uch
146 1.1 uch /*
147 1.1 uch * IT8368 configuration register is big-endian.
148 1.1 uch */
149 1.3 uch __inline u_int16_t it8368_reg_read __P((bus_space_tag_t,
150 1.3 uch bus_space_handle_t, int));
151 1.3 uch __inline void it8368_reg_write __P((bus_space_tag_t,
152 1.3 uch bus_space_handle_t, int,
153 1.3 uch u_int16_t));
154 1.1 uch
155 1.4 uch #define PRINTGPIO(m) __bitdisp(it8368_reg_read(csregt, csregh, \
156 1.4 uch IT8368_GPIO##m##_REG), 0, IT8368_GPIO_MAX, #m, 1)
157 1.4 uch #define PRINTMFIO(m) __bitdisp(it8368_reg_read(csregt, csregh, \
158 1.4 uch IT8368_MFIO##m##_REG), 0, IT8368_MFIO_MAX, #m, 1)
159 1.4 uch
160 1.1 uch int
161 1.1 uch it8368e_match(parent, cf, aux)
162 1.1 uch struct device *parent;
163 1.1 uch struct cfdata *cf;
164 1.1 uch void *aux;
165 1.1 uch {
166 1.1 uch return 1;
167 1.1 uch }
168 1.1 uch
169 1.1 uch void
170 1.1 uch it8368e_attach(parent, self, aux)
171 1.1 uch struct device *parent;
172 1.1 uch struct device *self;
173 1.1 uch void *aux;
174 1.1 uch {
175 1.1 uch struct cs_attach_args *ca = aux;
176 1.1 uch struct it8368e_softc *sc = (void*)self;
177 1.1 uch tx_chipset_tag_t tc;
178 1.1 uch bus_space_tag_t csregt;
179 1.1 uch bus_space_handle_t csregh;
180 1.1 uch u_int16_t reg;
181 1.1 uch
182 1.1 uch sc->sc_tc = tc = ca->ca_tc;
183 1.1 uch sc->sc_csregt = csregt = ca->ca_csreg.cstag;
184 1.1 uch
185 1.1 uch bus_space_map(csregt, ca->ca_csreg.csbase, ca->ca_csreg.cssize,
186 1.1 uch 0, &sc->sc_csregh);
187 1.1 uch csregh = sc->sc_csregh;
188 1.1 uch sc->sc_csiot = ca->ca_csio.cstag;
189 1.1 uch sc->sc_csiobase = ca->ca_csio.csbase;
190 1.1 uch sc->sc_csiosize = ca->ca_csio.cssize;
191 1.1 uch
192 1.3 uch #ifdef IT8368DEBUG
193 1.4 uch printf("\n\t[Windows CE setting]\n");
194 1.1 uch it8368_dump(sc); /* print WindowsCE setting */
195 1.3 uch #endif
196 1.1 uch /* LHA[14:13] <= HA[14:13] */
197 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
198 1.1 uch reg &= ~IT8368_CTRL_ADDRSEL;
199 1.1 uch it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
200 1.1 uch
201 1.1 uch /* Set all MFIO direction as LHA[23:13] output pins */
202 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_MFIODIR_REG);
203 1.1 uch reg |= IT8368_MFIODIR_MASK;
204 1.1 uch it8368_reg_write(csregt, csregh, IT8368_MFIODIR_REG, reg);
205 1.1 uch
206 1.1 uch /* Set all MFIO functions as LHA */
207 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_MFIOSEL_REG);
208 1.1 uch reg &= ~IT8368_MFIOSEL_MASK;
209 1.1 uch it8368_reg_write(csregt, csregh, IT8368_MFIOSEL_REG, reg);
210 1.1 uch
211 1.1 uch /* Disable MFIO interrupt */
212 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_MFIOPOSINTEN_REG);
213 1.1 uch reg &= ~IT8368_MFIOPOSINTEN_MASK;
214 1.1 uch it8368_reg_write(csregt, csregh, IT8368_MFIOPOSINTEN_REG, reg);
215 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_MFIONEGINTEN_REG);
216 1.1 uch reg &= ~IT8368_MFIONEGINTEN_MASK;
217 1.1 uch it8368_reg_write(csregt, csregh, IT8368_MFIONEGINTEN_REG, reg);
218 1.1 uch
219 1.1 uch /* Port direction */
220 1.1 uch reg = IT8368_PIN_CRDVCCON1 | IT8368_PIN_CRDVCCON0 |
221 1.1 uch IT8368_PIN_CRDVPPON1 | IT8368_PIN_CRDVPPON0 |
222 1.1 uch IT8368_PIN_BCRDRST;
223 1.1 uch it8368_reg_write(csregt, csregh, IT8368_GPIODIR_REG, reg);
224 1.1 uch
225 1.5 uch printf("\n");
226 1.5 uch
227 1.1 uch /*
228 1.1 uch * Separate I/O and attribute memory region
229 1.1 uch */
230 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
231 1.1 uch reg |= IT8368_CTRL_FIXATTRIO;
232 1.1 uch it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
233 1.1 uch
234 1.3 uch if (IT8368_CTRL_FIXATTRIO & it8368_reg_read(csregt, csregh,
235 1.3 uch IT8368_CTRL_REG)) {
236 1.1 uch sc->sc_fixattr = 1;
237 1.5 uch printf("%s: fix attr mode\n", sc->sc_dev.dv_xname);
238 1.1 uch sc->sc_csmemt = sc->sc_csiot;
239 1.1 uch sc->sc_csiosize /= 2;
240 1.1 uch sc->sc_csmemsize = sc->sc_csiosize;
241 1.1 uch sc->sc_csmembase = sc->sc_csiosize;
242 1.1 uch } else {
243 1.5 uch printf("%s: legacy attr mode", sc->sc_dev.dv_xname);
244 1.1 uch sc->sc_fixattr = 0;
245 1.1 uch sc->sc_csmemt = sc->sc_csiot;
246 1.1 uch sc->sc_csmemh = sc->sc_csmemh;
247 1.1 uch sc->sc_csmembase = sc->sc_csiobase;
248 1.1 uch sc->sc_csmemsize = sc->sc_csiosize;
249 1.1 uch }
250 1.1 uch it8368_dump(sc);
251 1.1 uch
252 1.4 uch /* Enable card and interrupt driving. */
253 1.4 uch reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
254 1.4 uch reg |= (IT8368_CTRL_GLOBALEN | IT8368_CTRL_CARDEN);
255 1.4 uch if (sc->sc_fixattr)
256 1.4 uch reg |= IT8368_CTRL_FIXATTRIO;
257 1.4 uch it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
258 1.4 uch
259 1.4 uch sc->sc_irq = ca->ca_irq1;
260 1.1 uch sc->sc_card_irq = ca->ca_irq3;
261 1.1 uch
262 1.5 uch
263 1.1 uch
264 1.1 uch it8368_attach_socket(sc);
265 1.1 uch }
266 1.1 uch
267 1.3 uch __inline u_int16_t
268 1.1 uch it8368_reg_read(t, h, ofs)
269 1.1 uch bus_space_tag_t t;
270 1.1 uch bus_space_handle_t h;
271 1.1 uch int ofs;
272 1.1 uch {
273 1.1 uch u_int16_t val;
274 1.1 uch
275 1.1 uch val = bus_space_read_2(t, h, ofs);
276 1.1 uch return 0xffff & (((val >> 8) & 0xff)|((val << 8) & 0xff00));
277 1.1 uch }
278 1.1 uch
279 1.3 uch __inline void
280 1.1 uch it8368_reg_write(t, h, ofs, v)
281 1.1 uch bus_space_tag_t t;
282 1.1 uch bus_space_handle_t h;
283 1.1 uch int ofs;
284 1.1 uch u_int16_t v;
285 1.1 uch {
286 1.1 uch u_int16_t val;
287 1.1 uch
288 1.1 uch val = 0xffff & (((v >> 8) & 0xff)|((v << 8) & 0xff00));
289 1.1 uch bus_space_write_2(t, h, ofs, val);
290 1.1 uch }
291 1.1 uch
292 1.1 uch int
293 1.1 uch it8368_intr(arg)
294 1.1 uch void *arg;
295 1.1 uch {
296 1.1 uch struct it8368e_softc *sc = arg;
297 1.4 uch bus_space_tag_t csregt = sc->sc_csregt;
298 1.4 uch bus_space_handle_t csregh = sc->sc_csregh;
299 1.4 uch u_int16_t reg;
300 1.3 uch
301 1.4 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTSTAT_REG);
302 1.3 uch
303 1.4 uch if (reg & IT8368_PIN_BCRDRDY) {
304 1.4 uch if (sc->sc_card_fun) {
305 1.4 uch /* clear interrupt */
306 1.4 uch it8368_reg_write(csregt, csregh,
307 1.4 uch IT8368_GPIONEGINTSTAT_REG,
308 1.4 uch IT8368_PIN_BCRDRDY);
309 1.4 uch
310 1.4 uch /* Dispatch card interrupt handler */
311 1.4 uch (*sc->sc_card_fun)(sc->sc_card_arg);
312 1.4 uch }
313 1.4 uch } else if (reg & IT8368_PIN_CRDDET2) {
314 1.4 uch it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTSTAT_REG,
315 1.4 uch IT8368_PIN_CRDDET2);
316 1.4 uch printf("[CSC]\n");
317 1.4 uch it8368_dump(sc);
318 1.4 uch it8368_chip_socket_disable(sc);
319 1.4 uch } else {
320 1.4 uch printf("unknown it8368 interrupt\n");
321 1.4 uch it8368_dump(sc);
322 1.1 uch }
323 1.4 uch
324 1.1 uch return 0;
325 1.1 uch }
326 1.1 uch
327 1.1 uch int
328 1.1 uch it8368_print(arg, pnp)
329 1.1 uch void *arg;
330 1.1 uch const char *pnp;
331 1.1 uch {
332 1.3 uch if (pnp)
333 1.1 uch printf("pcmcia at %s", pnp);
334 1.1 uch
335 1.1 uch return UNCONF;
336 1.1 uch }
337 1.1 uch
338 1.1 uch int
339 1.1 uch it8368_submatch(parent, cf, aux)
340 1.1 uch struct device *parent;
341 1.1 uch struct cfdata *cf;
342 1.1 uch void *aux;
343 1.1 uch {
344 1.1 uch return ((*cf->cf_attach->ca_match)(parent, cf, aux));
345 1.1 uch }
346 1.1 uch
347 1.1 uch void
348 1.1 uch it8368_attach_socket(sc)
349 1.1 uch struct it8368e_softc *sc;
350 1.1 uch {
351 1.1 uch struct pcmciabus_attach_args paa;
352 1.1 uch
353 1.1 uch paa.paa_busname = "pcmcia";
354 1.1 uch paa.pct = (pcmcia_chipset_tag_t)&it8368_functions;
355 1.1 uch paa.pch = (pcmcia_chipset_handle_t)sc;
356 1.1 uch paa.iobase = 0; /* I don't use them */
357 1.1 uch paa.iosize = 0;
358 1.1 uch
359 1.1 uch if ((sc->sc_pcmcia = config_found_sm((void*)sc, &paa, it8368_print,
360 1.1 uch it8368_submatch))) {
361 1.4 uch
362 1.4 uch it8368_init_socket(sc);
363 1.4 uch }
364 1.4 uch }
365 1.4 uch
366 1.4 uch void
367 1.4 uch it8368_init_socket(sc)
368 1.4 uch struct it8368e_softc *sc;
369 1.4 uch {
370 1.4 uch bus_space_tag_t csregt = sc->sc_csregt;
371 1.4 uch bus_space_handle_t csregh = sc->sc_csregh;
372 1.4 uch u_int16_t reg;
373 1.4 uch
374 1.4 uch /*
375 1.4 uch * set up the card to interrupt on card detect
376 1.4 uch */
377 1.4 uch reg = IT8368_PIN_CRDDET2; /* CSC */
378 1.4 uch /* enable negative edge */
379 1.4 uch it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
380 1.4 uch /* disable positive edge */
381 1.4 uch it8368_reg_write(csregt, csregh, IT8368_GPIOPOSINTEN_REG, 0);
382 1.4 uch
383 1.4 uch sc->sc_ih = tx_intr_establish(sc->sc_tc, sc->sc_irq,
384 1.4 uch IST_EDGE, IPL_BIO, it8368_intr, sc);
385 1.4 uch if (sc->sc_ih == NULL) {
386 1.4 uch printf("%s: can't establish interrupt\n",
387 1.4 uch sc->sc_dev.dv_xname);
388 1.4 uch return;
389 1.4 uch }
390 1.4 uch
391 1.4 uch /*
392 1.4 uch * if there's a card there, then attach it.
393 1.4 uch */
394 1.4 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAIN_REG);
395 1.4 uch
396 1.4 uch if (reg & (IT8368_PIN_CRDDET2|IT8368_PIN_CRDDET1)) {
397 1.4 uch sc->sc_laststate = IT8368_LASTSTATE_EMPTY;
398 1.4 uch } else {
399 1.4 uch pcmcia_card_attach(sc->sc_pcmcia);
400 1.4 uch sc->sc_laststate = IT8368_LASTSTATE_PRESENT;
401 1.1 uch }
402 1.1 uch }
403 1.1 uch
404 1.1 uch void *
405 1.1 uch it8368_chip_intr_establish(pch, pf, ipl, ih_fun, ih_arg)
406 1.1 uch pcmcia_chipset_handle_t pch;
407 1.1 uch struct pcmcia_function *pf;
408 1.1 uch int ipl;
409 1.1 uch int (*ih_fun) __P((void *));
410 1.1 uch void *ih_arg;
411 1.1 uch {
412 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
413 1.4 uch bus_space_tag_t csregt = sc->sc_csregt;
414 1.4 uch bus_space_handle_t csregh = sc->sc_csregh;
415 1.4 uch u_int16_t reg;
416 1.1 uch
417 1.4 uch if (sc->sc_card_fun)
418 1.3 uch panic("it8368_chip_intr_establish: "
419 1.3 uch "duplicate card interrupt handler.");
420 1.4 uch
421 1.1 uch sc->sc_card_fun = ih_fun;
422 1.1 uch sc->sc_card_arg = ih_arg;
423 1.1 uch
424 1.4 uch sc->sc_card_ih = tx_intr_establish(sc->sc_tc, sc->sc_card_irq,
425 1.4 uch IST_EDGE, IPL_BIO, it8368_intr,
426 1.4 uch sc);
427 1.4 uch
428 1.4 uch /* enable card interrupt */
429 1.4 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTEN_REG);
430 1.4 uch reg |= IT8368_PIN_BCRDRDY;
431 1.4 uch it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
432 1.4 uch
433 1.1 uch return sc->sc_card_ih;
434 1.1 uch }
435 1.1 uch
436 1.1 uch void
437 1.1 uch it8368_chip_intr_disestablish(pch, ih)
438 1.1 uch pcmcia_chipset_handle_t pch;
439 1.1 uch void *ih;
440 1.1 uch {
441 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
442 1.4 uch bus_space_tag_t csregt = sc->sc_csregt;
443 1.4 uch bus_space_handle_t csregh = sc->sc_csregh;
444 1.4 uch u_int16_t reg;
445 1.1 uch
446 1.4 uch if (!sc->sc_card_fun)
447 1.3 uch panic("it8368_chip_intr_disestablish:"
448 1.3 uch "no handler established.");
449 1.4 uch assert(ih == sc->sc_card_ih);
450 1.4 uch
451 1.1 uch sc->sc_card_fun = 0;
452 1.1 uch sc->sc_card_arg = 0;
453 1.1 uch
454 1.4 uch /* disable card interrupt */
455 1.4 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTEN_REG);
456 1.4 uch reg &= ~IT8368_PIN_BCRDRDY;
457 1.4 uch it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
458 1.4 uch
459 1.1 uch tx_intr_disestablish(sc->sc_tc, ih);
460 1.1 uch }
461 1.1 uch
462 1.1 uch int
463 1.1 uch it8368_chip_mem_alloc(pch, size, pcmhp)
464 1.1 uch pcmcia_chipset_handle_t pch;
465 1.1 uch bus_size_t size;
466 1.1 uch struct pcmcia_mem_handle *pcmhp;
467 1.1 uch {
468 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
469 1.1 uch it8368_access(sc, 0, 0);
470 1.1 uch
471 1.1 uch pcmhp->memt = sc->sc_csmemt;
472 1.1 uch
473 1.1 uch if (bus_space_map(sc->sc_csmemt, sc->sc_csmembase, size, 0,
474 1.1 uch &pcmhp->memh)) {
475 1.1 uch return 1;
476 1.1 uch }
477 1.3 uch
478 1.1 uch pcmhp->addr = pcmhp->memh;
479 1.1 uch pcmhp->size = size;
480 1.1 uch pcmhp->realsize = size;
481 1.3 uch
482 1.1 uch DPRINTF(("it8368_chip_mem_alloc %#x+%#x\n", pcmhp->memh, size));
483 1.1 uch
484 1.1 uch return 0;
485 1.1 uch }
486 1.1 uch
487 1.1 uch void
488 1.1 uch it8368_chip_mem_free(pch, pcmhp)
489 1.1 uch pcmcia_chipset_handle_t pch;
490 1.1 uch struct pcmcia_mem_handle *pcmhp;
491 1.1 uch {
492 1.1 uch bus_space_unmap(pcmhp->memt, pcmhp->memh, pcmhp->size);
493 1.1 uch }
494 1.1 uch
495 1.1 uch int
496 1.1 uch it8368_chip_mem_map(pch, kind, card_addr, size, pcmhp, offsetp, windowp)
497 1.1 uch pcmcia_chipset_handle_t pch;
498 1.1 uch int kind;
499 1.1 uch bus_addr_t card_addr;
500 1.1 uch bus_size_t size;
501 1.1 uch struct pcmcia_mem_handle *pcmhp;
502 1.1 uch bus_addr_t *offsetp;
503 1.1 uch int *windowp;
504 1.1 uch {
505 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
506 1.1 uch
507 1.1 uch it8368_access(sc, 0, 0);
508 1.1 uch
509 1.3 uch *offsetp = card_addr;
510 1.1 uch DPRINTF(("it8368_chip_mem_map %#x+%#x\n", pcmhp->memh, size));
511 1.3 uch
512 1.1 uch return 0;
513 1.1 uch }
514 1.1 uch
515 1.1 uch void
516 1.1 uch it8368_chip_mem_unmap(pch, window)
517 1.1 uch pcmcia_chipset_handle_t pch;
518 1.1 uch int window;
519 1.1 uch {
520 1.1 uch }
521 1.1 uch
522 1.1 uch void
523 1.1 uch it8368_access(sc, io, width)
524 1.1 uch struct it8368e_softc *sc;
525 1.1 uch int io;
526 1.1 uch int width;
527 1.1 uch {
528 1.1 uch #if not_required_yet
529 1.1 uch txreg_t reg32;
530 1.1 uch
531 1.1 uch reg32 = tx_conf_read(sc->sc_tc, TX39_MEMCONFIG3_REG);
532 1.1 uch if (io && width == 1) {
533 1.1 uch reg32 |= TX39_MEMCONFIG3_PORT8SEL;
534 1.1 uch } else {
535 1.1 uch reg32 &= ~TX39_MEMCONFIG3_PORT8SEL;
536 1.1 uch }
537 1.1 uch if (!sc->sc_fixattr) {
538 1.1 uch if (io) {
539 1.1 uch reg32 |= TX39_MEMCONFIG3_CARD1IOEN;
540 1.1 uch } else {
541 1.1 uch reg32 &= ~TX39_MEMCONFIG3_CARD1IOEN;
542 1.1 uch }
543 1.1 uch }
544 1.1 uch tx_conf_write(sc->sc_tc, TX39_MEMCONFIG3_REG, reg32);
545 1.1 uch
546 1.1 uch reg32 = tx_conf_read(sc->sc_tc, TX39_MEMCONFIG3_REG);
547 1.1 uch if (!(reg32 & TX39_MEMCONFIG3_CARD1IOEN))
548 1.1 uch printf("CARDIOEN failed\n");
549 1.1 uch if (!(reg32 & TX39_MEMCONFIG3_PORT8SEL))
550 1.1 uch printf("PORT8SEL failed\n");
551 1.1 uch
552 1.1 uch delay(20);
553 1.1 uch #endif
554 1.1 uch }
555 1.1 uch
556 1.1 uch int
557 1.1 uch it8368_chip_io_alloc(pch, start, size, align, pcihp)
558 1.1 uch pcmcia_chipset_handle_t pch;
559 1.1 uch bus_addr_t start;
560 1.1 uch bus_size_t size;
561 1.1 uch bus_size_t align;
562 1.1 uch struct pcmcia_io_handle *pcihp;
563 1.1 uch {
564 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
565 1.1 uch
566 1.1 uch it8368_access(sc, 1, 0);
567 1.1 uch
568 1.1 uch if (start) {
569 1.3 uch if (bus_space_map(sc->sc_csiot, start, size, 0,
570 1.3 uch &pcihp->ioh)) {
571 1.1 uch return 1;
572 1.1 uch }
573 1.1 uch DPRINTF(("it8368_chip_io_alloc map port %#x+%#x\n",
574 1.1 uch start, size));
575 1.1 uch } else {
576 1.1 uch if (bus_space_alloc(sc->sc_csiot, sc->sc_csiobase,
577 1.3 uch sc->sc_csiobase + sc->sc_csiosize,
578 1.3 uch size, align, 0, 0, &pcihp->addr,
579 1.3 uch &pcihp->ioh)) {
580 1.3 uch
581 1.1 uch return 1;
582 1.1 uch }
583 1.1 uch pcihp->flags = PCMCIA_IO_ALLOCATED;
584 1.1 uch DPRINTF(("it8368_chip_io_alloc alloc %#x from %#x\n",
585 1.1 uch size, pcihp->addr));
586 1.2 uch }
587 1.1 uch
588 1.1 uch pcihp->iot = sc->sc_csiot;
589 1.1 uch pcihp->size = size;
590 1.1 uch
591 1.1 uch return 0;
592 1.1 uch }
593 1.1 uch
594 1.1 uch int
595 1.1 uch it8368_chip_io_map(pch, width, offset, size, pcihp, windowp)
596 1.1 uch pcmcia_chipset_handle_t pch;
597 1.1 uch int width;
598 1.1 uch bus_addr_t offset;
599 1.1 uch bus_size_t size;
600 1.1 uch struct pcmcia_io_handle *pcihp;
601 1.1 uch int *windowp;
602 1.1 uch {
603 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
604 1.1 uch
605 1.1 uch it8368_access(sc, 1, 0);
606 1.1 uch
607 1.3 uch DPRINTF(("it8368_chip_io_map %#x:%#x+%#x\n", pcihp->ioh, offset,
608 1.3 uch size));
609 1.1 uch
610 1.1 uch return 0;
611 1.1 uch }
612 1.1 uch
613 1.1 uch void
614 1.1 uch it8368_chip_io_free(pch, pcihp)
615 1.1 uch pcmcia_chipset_handle_t pch;
616 1.1 uch struct pcmcia_io_handle *pcihp;
617 1.1 uch {
618 1.1 uch if (pcihp->flags & PCMCIA_IO_ALLOCATED) {
619 1.1 uch bus_space_free(pcihp->iot, pcihp->ioh, pcihp->size);
620 1.1 uch } else {
621 1.1 uch bus_space_unmap(pcihp->iot, pcihp->ioh, pcihp->size);
622 1.1 uch }
623 1.1 uch DPRINTF(("it8368_chip_io_free %#x+%#x\n", pcihp->ioh, pcihp->size));
624 1.1 uch }
625 1.1 uch
626 1.1 uch void
627 1.1 uch it8368_chip_io_unmap(pch, window)
628 1.1 uch pcmcia_chipset_handle_t pch;
629 1.1 uch int window;
630 1.1 uch {
631 1.1 uch }
632 1.1 uch
633 1.1 uch void
634 1.1 uch it8368_chip_socket_enable(pch)
635 1.1 uch pcmcia_chipset_handle_t pch;
636 1.1 uch {
637 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*)pch;
638 1.1 uch bus_space_tag_t csregt = sc->sc_csregt;
639 1.1 uch bus_space_handle_t csregh = sc->sc_csregh;
640 1.1 uch volatile u_int16_t reg;
641 1.3 uch
642 1.1 uch /* Power off */
643 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
644 1.1 uch reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
645 1.1 uch reg |= (IT8368_PIN_CRDVCC_0V | IT8368_PIN_CRDVPP_0V);
646 1.1 uch it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
647 1.1 uch delay(20000);
648 1.1 uch
649 1.1 uch /*
650 1.1 uch * wait 300ms until power fails (Tpf). Then, wait 100ms since
651 1.1 uch * we are changing Vcc (Toff).
652 1.1 uch */
653 1.1 uch delay((300 + 100) * 1000);
654 1.1 uch
655 1.1 uch /* Supply Vcc */
656 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
657 1.1 uch reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
658 1.1 uch reg |= IT8368_PIN_CRDVCC_5V; /* XXX */
659 1.1 uch it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
660 1.1 uch
661 1.1 uch /*
662 1.1 uch * wait 100ms until power raise (Tpr) and 20ms to become
663 1.1 uch * stable (Tsu(Vcc)).
664 1.1 uch *
665 1.1 uch * some machines require some more time to be settled
666 1.1 uch * (300ms is added here).
667 1.1 uch */
668 1.1 uch delay((100 + 20 + 300) * 1000);
669 1.1 uch
670 1.1 uch /* Assert reset signal */
671 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
672 1.1 uch reg |= IT8368_PIN_BCRDRST;
673 1.1 uch it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
674 1.4 uch
675 1.1 uch /*
676 1.1 uch * hold RESET at least 10us.
677 1.1 uch */
678 1.1 uch delay(10);
679 1.4 uch
680 1.1 uch /* Dessert reset signal */
681 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
682 1.1 uch reg &= ~IT8368_PIN_BCRDRST;
683 1.1 uch it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
684 1.1 uch delay(20000);
685 1.1 uch
686 1.1 uch DPRINTF(("socket enabled\n"));
687 1.1 uch }
688 1.1 uch
689 1.1 uch void
690 1.1 uch it8368_chip_socket_disable(pch)
691 1.1 uch pcmcia_chipset_handle_t pch;
692 1.1 uch {
693 1.1 uch struct it8368e_softc *sc = (struct it8368e_softc*) pch;
694 1.1 uch bus_space_tag_t csregt = sc->sc_csregt;
695 1.1 uch bus_space_handle_t csregh = sc->sc_csregh;
696 1.1 uch u_int16_t reg;
697 1.1 uch
698 1.1 uch /* Power down */
699 1.1 uch reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
700 1.1 uch reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
701 1.1 uch reg |= (IT8368_PIN_CRDVCC_0V | IT8368_PIN_CRDVPP_0V);
702 1.1 uch it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
703 1.1 uch delay(20000);
704 1.1 uch
705 1.1 uch /*
706 1.1 uch * wait 300ms until power fails (Tpf).
707 1.1 uch */
708 1.1 uch delay(300 * 1000);
709 1.4 uch
710 1.1 uch DPRINTF(("socket disabled\n"));
711 1.1 uch }
712 1.1 uch
713 1.1 uch void
714 1.1 uch it8368_dump(sc)
715 1.1 uch struct it8368e_softc *sc;
716 1.1 uch {
717 1.1 uch #ifdef IT8368DEBUG
718 1.1 uch bus_space_tag_t csregt = sc->sc_csregt;
719 1.1 uch bus_space_handle_t csregh = sc->sc_csregh;
720 1.1 uch
721 1.1 uch printf("[GPIO]\n");
722 1.1 uch PRINTGPIO(DIR);
723 1.1 uch PRINTGPIO(DATAIN);
724 1.1 uch PRINTGPIO(DATAOUT);
725 1.1 uch PRINTGPIO(POSINTEN);
726 1.1 uch PRINTGPIO(NEGINTEN);
727 1.1 uch PRINTGPIO(POSINTSTAT);
728 1.1 uch PRINTGPIO(NEGINTSTAT);
729 1.1 uch printf("[MFIO]\n");
730 1.1 uch PRINTMFIO(SEL);
731 1.1 uch PRINTMFIO(DIR);
732 1.1 uch PRINTMFIO(DATAIN);
733 1.1 uch PRINTMFIO(DATAOUT);
734 1.1 uch PRINTMFIO(POSINTEN);
735 1.1 uch PRINTMFIO(NEGINTEN);
736 1.1 uch PRINTMFIO(POSINTSTAT);
737 1.1 uch PRINTMFIO(NEGINTSTAT);
738 1.3 uch __bitdisp(it8368_reg_read(csregt, csregh, IT8368_CTRL_REG), 0, 15,
739 1.3 uch "CTRL", 1);
740 1.3 uch __bitdisp(it8368_reg_read(csregt, csregh, IT8368_GPIODATAIN_REG),
741 1.3 uch 8, 11, "]CRDDET/SENSE[", 1);
742 1.1 uch #endif
743 1.1 uch }
744