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