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