it8368.c revision 1.8.6.2 1 1.8.6.2 bouyer /* $NetBSD: it8368.c,v 1.8.6.2 2000/11/20 20:45:56 bouyer Exp $ */
2 1.8.6.2 bouyer
3 1.8.6.2 bouyer /*
4 1.8.6.2 bouyer * Copyright (c) 1999, 2000, by UCHIYAMA Yasushi
5 1.8.6.2 bouyer * All rights reserved.
6 1.8.6.2 bouyer *
7 1.8.6.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.8.6.2 bouyer * modification, are permitted provided that the following conditions
9 1.8.6.2 bouyer * are met:
10 1.8.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.8.6.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.8.6.2 bouyer * 2. The name of the developer may NOT be used to endorse or promote products
13 1.8.6.2 bouyer * derived from this software without specific prior written permission.
14 1.8.6.2 bouyer *
15 1.8.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.8.6.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.8.6.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.8.6.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.8.6.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.8.6.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.8.6.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.8.6.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.8.6.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.8.6.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.8.6.2 bouyer * SUCH DAMAGE.
26 1.8.6.2 bouyer *
27 1.8.6.2 bouyer */
28 1.8.6.2 bouyer #undef WINCE_DEFAULT_SETTING /* for debug */
29 1.8.6.2 bouyer #undef IT8368DEBUG
30 1.8.6.2 bouyer #include "opt_tx39_debug.h"
31 1.8.6.2 bouyer
32 1.8.6.2 bouyer #include <sys/param.h>
33 1.8.6.2 bouyer #include <sys/systm.h>
34 1.8.6.2 bouyer #include <sys/device.h>
35 1.8.6.2 bouyer
36 1.8.6.2 bouyer #include <machine/bus.h>
37 1.8.6.2 bouyer
38 1.8.6.2 bouyer #include <dev/pcmcia/pcmciareg.h>
39 1.8.6.2 bouyer #include <dev/pcmcia/pcmciavar.h>
40 1.8.6.2 bouyer #include <dev/pcmcia/pcmciachip.h>
41 1.8.6.2 bouyer
42 1.8.6.2 bouyer #include <hpcmips/tx/tx39var.h>
43 1.8.6.2 bouyer #include <hpcmips/tx/txcsbusvar.h>
44 1.8.6.2 bouyer #include <hpcmips/tx/tx39biureg.h> /* legacy mode requires BIU access */
45 1.8.6.2 bouyer #include <hpcmips/dev/it8368var.h>
46 1.8.6.2 bouyer #include <hpcmips/dev/it8368reg.h>
47 1.8.6.2 bouyer
48 1.8.6.2 bouyer #ifdef IT8368DEBUG
49 1.8.6.2 bouyer int it8368debug = 1;
50 1.8.6.2 bouyer #define DPRINTF(arg) if (it8368debug) printf arg;
51 1.8.6.2 bouyer #define DPRINTFN(n, arg) if (it8368debug > (n)) printf arg;
52 1.8.6.2 bouyer #else
53 1.8.6.2 bouyer #define DPRINTF(arg)
54 1.8.6.2 bouyer #define DPRINTFN(n, arg)
55 1.8.6.2 bouyer #endif
56 1.8.6.2 bouyer
57 1.8.6.2 bouyer int it8368e_match __P((struct device*, struct cfdata*, void*));
58 1.8.6.2 bouyer void it8368e_attach __P((struct device*, struct device*, void*));
59 1.8.6.2 bouyer int it8368_print __P((void*, const char*));
60 1.8.6.2 bouyer int it8368_submatch __P((struct device*, struct cfdata*, void*));
61 1.8.6.2 bouyer
62 1.8.6.2 bouyer #define IT8368_LASTSTATE_PRESENT 0x0002
63 1.8.6.2 bouyer #define IT8368_LASTSTATE_HALF 0x0001
64 1.8.6.2 bouyer #define IT8368_LASTSTATE_EMPTY 0x0000
65 1.8.6.2 bouyer
66 1.8.6.2 bouyer struct it8368e_softc {
67 1.8.6.2 bouyer struct device sc_dev;
68 1.8.6.2 bouyer struct device *sc_pcmcia;
69 1.8.6.2 bouyer tx_chipset_tag_t sc_tc;
70 1.8.6.2 bouyer
71 1.8.6.2 bouyer /* Register space */
72 1.8.6.2 bouyer bus_space_tag_t sc_csregt;
73 1.8.6.2 bouyer bus_space_handle_t sc_csregh;
74 1.8.6.2 bouyer /* I/O, attribute space */
75 1.8.6.2 bouyer bus_space_tag_t sc_csiot;
76 1.8.6.2 bouyer bus_addr_t sc_csiobase;
77 1.8.6.2 bouyer bus_size_t sc_csiosize;
78 1.8.6.2 bouyer /*
79 1.8.6.2 bouyer * XXX theses means attribute memory. not memory space.
80 1.8.6.2 bouyer * memory space is 0x64000000.
81 1.8.6.2 bouyer */
82 1.8.6.2 bouyer bus_space_tag_t sc_csmemt;
83 1.8.6.2 bouyer bus_addr_t sc_csmembase;
84 1.8.6.2 bouyer bus_size_t sc_csmemsize;
85 1.8.6.2 bouyer
86 1.8.6.2 bouyer /* Separate I/O and attribute space mode */
87 1.8.6.2 bouyer int sc_fixattr;
88 1.8.6.2 bouyer
89 1.8.6.2 bouyer /* Card interrupt handler */
90 1.8.6.2 bouyer int (*sc_card_fun) __P((void*));
91 1.8.6.2 bouyer void *sc_card_arg;
92 1.8.6.2 bouyer void *sc_card_ih;
93 1.8.6.2 bouyer int sc_card_irq;
94 1.8.6.2 bouyer
95 1.8.6.2 bouyer /* Card status change */
96 1.8.6.2 bouyer int sc_irq;
97 1.8.6.2 bouyer void *sc_ih;
98 1.8.6.2 bouyer int sc_laststate;
99 1.8.6.2 bouyer };
100 1.8.6.2 bouyer
101 1.8.6.2 bouyer void it8368_init_socket __P((struct it8368e_softc*));
102 1.8.6.2 bouyer void it8368_attach_socket __P((struct it8368e_softc*));
103 1.8.6.2 bouyer int it8368_intr __P((void*));
104 1.8.6.2 bouyer int it8368_chip_mem_alloc __P((pcmcia_chipset_handle_t, bus_size_t,
105 1.8.6.2 bouyer struct pcmcia_mem_handle*));
106 1.8.6.2 bouyer void it8368_chip_mem_free __P((pcmcia_chipset_handle_t,
107 1.8.6.2 bouyer struct pcmcia_mem_handle*));
108 1.8.6.2 bouyer int it8368_chip_mem_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
109 1.8.6.2 bouyer bus_size_t, struct pcmcia_mem_handle*,
110 1.8.6.2 bouyer bus_addr_t*, int*));
111 1.8.6.2 bouyer void it8368_chip_mem_unmap __P((pcmcia_chipset_handle_t, int));
112 1.8.6.2 bouyer int it8368_chip_io_alloc __P((pcmcia_chipset_handle_t, bus_addr_t,
113 1.8.6.2 bouyer bus_size_t, bus_size_t,
114 1.8.6.2 bouyer struct pcmcia_io_handle*));
115 1.8.6.2 bouyer void it8368_chip_io_free __P((pcmcia_chipset_handle_t,
116 1.8.6.2 bouyer struct pcmcia_io_handle*));
117 1.8.6.2 bouyer int it8368_chip_io_map __P((pcmcia_chipset_handle_t, int, bus_addr_t,
118 1.8.6.2 bouyer bus_size_t, struct pcmcia_io_handle*,
119 1.8.6.2 bouyer int*));
120 1.8.6.2 bouyer void it8368_chip_io_unmap __P((pcmcia_chipset_handle_t, int));
121 1.8.6.2 bouyer void it8368_chip_socket_enable __P((pcmcia_chipset_handle_t));
122 1.8.6.2 bouyer void it8368_chip_socket_disable __P((pcmcia_chipset_handle_t));
123 1.8.6.2 bouyer void *it8368_chip_intr_establish __P((pcmcia_chipset_handle_t,
124 1.8.6.2 bouyer struct pcmcia_function*, int,
125 1.8.6.2 bouyer int (*) (void*), void*));
126 1.8.6.2 bouyer void it8368_chip_intr_disestablish __P((pcmcia_chipset_handle_t, void*));
127 1.8.6.2 bouyer
128 1.8.6.2 bouyer #ifdef IT8368DEBUG
129 1.8.6.2 bouyer void it8368_dump __P((struct it8368e_softc*));
130 1.8.6.2 bouyer #endif
131 1.8.6.2 bouyer
132 1.8.6.2 bouyer static struct pcmcia_chip_functions it8368_functions = {
133 1.8.6.2 bouyer it8368_chip_mem_alloc,
134 1.8.6.2 bouyer it8368_chip_mem_free,
135 1.8.6.2 bouyer it8368_chip_mem_map,
136 1.8.6.2 bouyer it8368_chip_mem_unmap,
137 1.8.6.2 bouyer it8368_chip_io_alloc,
138 1.8.6.2 bouyer it8368_chip_io_free,
139 1.8.6.2 bouyer it8368_chip_io_map,
140 1.8.6.2 bouyer it8368_chip_io_unmap,
141 1.8.6.2 bouyer it8368_chip_intr_establish,
142 1.8.6.2 bouyer it8368_chip_intr_disestablish,
143 1.8.6.2 bouyer it8368_chip_socket_enable,
144 1.8.6.2 bouyer it8368_chip_socket_disable
145 1.8.6.2 bouyer };
146 1.8.6.2 bouyer
147 1.8.6.2 bouyer struct cfattach it8368e_ca = {
148 1.8.6.2 bouyer sizeof(struct it8368e_softc), it8368e_match, it8368e_attach
149 1.8.6.2 bouyer };
150 1.8.6.2 bouyer
151 1.8.6.2 bouyer /*
152 1.8.6.2 bouyer * IT8368 configuration register is big-endian.
153 1.8.6.2 bouyer */
154 1.8.6.2 bouyer __inline__ u_int16_t it8368_reg_read __P((bus_space_tag_t,
155 1.8.6.2 bouyer bus_space_handle_t, int));
156 1.8.6.2 bouyer __inline__ void it8368_reg_write __P((bus_space_tag_t,
157 1.8.6.2 bouyer bus_space_handle_t, int,
158 1.8.6.2 bouyer u_int16_t));
159 1.8.6.2 bouyer
160 1.8.6.2 bouyer #ifdef IT8368E_DESTRUCTIVE_CHECK
161 1.8.6.2 bouyer int it8368e_id_check __P((void *));
162 1.8.6.2 bouyer
163 1.8.6.2 bouyer /*
164 1.8.6.2 bouyer * IT8368E don't have identification method. this is destructive check.
165 1.8.6.2 bouyer */
166 1.8.6.2 bouyer int
167 1.8.6.2 bouyer it8368e_id_check(aux)
168 1.8.6.2 bouyer void *aux;
169 1.8.6.2 bouyer {
170 1.8.6.2 bouyer struct cs_attach_args *ca = aux;
171 1.8.6.2 bouyer tx_chipset_tag_t tc;
172 1.8.6.2 bouyer bus_space_tag_t csregt;
173 1.8.6.2 bouyer bus_space_handle_t csregh;
174 1.8.6.2 bouyer u_int16_t oreg, reg;
175 1.8.6.2 bouyer int match = 0;
176 1.8.6.2 bouyer
177 1.8.6.2 bouyer tc = ca->ca_tc;
178 1.8.6.2 bouyer csregt = ca->ca_csreg.cstag;
179 1.8.6.2 bouyer
180 1.8.6.2 bouyer bus_space_map(csregt, ca->ca_csreg.csbase, ca->ca_csreg.cssize,
181 1.8.6.2 bouyer 0, &csregh);
182 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
183 1.8.6.2 bouyer oreg = reg;
184 1.8.6.2 bouyer bitdisp(reg);
185 1.8.6.2 bouyer
186 1.8.6.2 bouyer reg &= ~IT8368_CTRL_BYTESWAP;
187 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
188 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
189 1.8.6.2 bouyer if (reg & IT8368_CTRL_BYTESWAP)
190 1.8.6.2 bouyer goto nomatch;
191 1.8.6.2 bouyer
192 1.8.6.2 bouyer reg |= IT8368_CTRL_BYTESWAP;
193 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
194 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
195 1.8.6.2 bouyer if (!(reg & IT8368_CTRL_BYTESWAP))
196 1.8.6.2 bouyer goto nomatch;
197 1.8.6.2 bouyer
198 1.8.6.2 bouyer match = 1;
199 1.8.6.2 bouyer nomatch:
200 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, oreg);
201 1.8.6.2 bouyer bus_space_unmap(csregt, csregh, ca->ca_csreg.cssize);
202 1.8.6.2 bouyer
203 1.8.6.2 bouyer return (match);
204 1.8.6.2 bouyer }
205 1.8.6.2 bouyer #endif /* IT8368E_DESTRUCTIVE_CHECK */
206 1.8.6.2 bouyer
207 1.8.6.2 bouyer int
208 1.8.6.2 bouyer it8368e_match(parent, cf, aux)
209 1.8.6.2 bouyer struct device *parent;
210 1.8.6.2 bouyer struct cfdata *cf;
211 1.8.6.2 bouyer void *aux;
212 1.8.6.2 bouyer {
213 1.8.6.2 bouyer #ifdef IT8368E_DESTRUCTIVE_CHECK
214 1.8.6.2 bouyer return (it8368e_id_check(aux));
215 1.8.6.2 bouyer #else
216 1.8.6.2 bouyer return (1);
217 1.8.6.2 bouyer #endif
218 1.8.6.2 bouyer }
219 1.8.6.2 bouyer
220 1.8.6.2 bouyer void
221 1.8.6.2 bouyer it8368e_attach(parent, self, aux)
222 1.8.6.2 bouyer struct device *parent;
223 1.8.6.2 bouyer struct device *self;
224 1.8.6.2 bouyer void *aux;
225 1.8.6.2 bouyer {
226 1.8.6.2 bouyer struct cs_attach_args *ca = aux;
227 1.8.6.2 bouyer struct it8368e_softc *sc = (void*)self;
228 1.8.6.2 bouyer tx_chipset_tag_t tc;
229 1.8.6.2 bouyer bus_space_tag_t csregt;
230 1.8.6.2 bouyer bus_space_handle_t csregh;
231 1.8.6.2 bouyer u_int16_t reg;
232 1.8.6.2 bouyer
233 1.8.6.2 bouyer sc->sc_tc = tc = ca->ca_tc;
234 1.8.6.2 bouyer sc->sc_csregt = csregt = ca->ca_csreg.cstag;
235 1.8.6.2 bouyer
236 1.8.6.2 bouyer bus_space_map(csregt, ca->ca_csreg.csbase, ca->ca_csreg.cssize,
237 1.8.6.2 bouyer 0, &sc->sc_csregh);
238 1.8.6.2 bouyer csregh = sc->sc_csregh;
239 1.8.6.2 bouyer sc->sc_csiot = ca->ca_csio.cstag;
240 1.8.6.2 bouyer sc->sc_csiobase = ca->ca_csio.csbase;
241 1.8.6.2 bouyer sc->sc_csiosize = ca->ca_csio.cssize;
242 1.8.6.2 bouyer
243 1.8.6.2 bouyer #ifdef IT8368DEBUG
244 1.8.6.2 bouyer printf("\n\t[Windows CE setting]\n");
245 1.8.6.2 bouyer it8368_dump(sc); /* print WindowsCE setting */
246 1.8.6.2 bouyer #endif
247 1.8.6.2 bouyer /* LHA[14:13] <= HA[14:13] */
248 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
249 1.8.6.2 bouyer reg &= ~IT8368_CTRL_ADDRSEL;
250 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
251 1.8.6.2 bouyer
252 1.8.6.2 bouyer /* Set all MFIO direction as LHA[23:13] output pins */
253 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_MFIODIR_REG);
254 1.8.6.2 bouyer reg |= IT8368_MFIODIR_MASK;
255 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_MFIODIR_REG, reg);
256 1.8.6.2 bouyer
257 1.8.6.2 bouyer /* Set all MFIO functions as LHA */
258 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_MFIOSEL_REG);
259 1.8.6.2 bouyer reg &= ~IT8368_MFIOSEL_MASK;
260 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_MFIOSEL_REG, reg);
261 1.8.6.2 bouyer
262 1.8.6.2 bouyer /* Disable MFIO interrupt */
263 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_MFIOPOSINTEN_REG);
264 1.8.6.2 bouyer reg &= ~IT8368_MFIOPOSINTEN_MASK;
265 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_MFIOPOSINTEN_REG, reg);
266 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_MFIONEGINTEN_REG);
267 1.8.6.2 bouyer reg &= ~IT8368_MFIONEGINTEN_MASK;
268 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_MFIONEGINTEN_REG, reg);
269 1.8.6.2 bouyer
270 1.8.6.2 bouyer /* Port direction */
271 1.8.6.2 bouyer reg = IT8368_PIN_CRDVCCON1 | IT8368_PIN_CRDVCCON0 |
272 1.8.6.2 bouyer IT8368_PIN_CRDVPPON1 | IT8368_PIN_CRDVPPON0 |
273 1.8.6.2 bouyer IT8368_PIN_BCRDRST;
274 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIODIR_REG, reg);
275 1.8.6.2 bouyer printf("\n");
276 1.8.6.2 bouyer
277 1.8.6.2 bouyer /*
278 1.8.6.2 bouyer * Separate I/O and attribute memory region
279 1.8.6.2 bouyer */
280 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
281 1.8.6.2 bouyer
282 1.8.6.2 bouyer reg |= IT8368_CTRL_FIXATTRIO;
283 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
284 1.8.6.2 bouyer
285 1.8.6.2 bouyer if (IT8368_CTRL_FIXATTRIO &
286 1.8.6.2 bouyer it8368_reg_read(csregt, csregh, IT8368_CTRL_REG)) {
287 1.8.6.2 bouyer sc->sc_fixattr = 1;
288 1.8.6.2 bouyer printf("%s: fix attr mode\n", sc->sc_dev.dv_xname);
289 1.8.6.2 bouyer } else {
290 1.8.6.2 bouyer sc->sc_fixattr = 0;
291 1.8.6.2 bouyer printf("%s: legacy attr mode\n", sc->sc_dev.dv_xname);
292 1.8.6.2 bouyer }
293 1.8.6.2 bouyer
294 1.8.6.2 bouyer sc->sc_csmemt = sc->sc_csiot;
295 1.8.6.2 bouyer sc->sc_csiosize /= 2;
296 1.8.6.2 bouyer sc->sc_csmemsize = sc->sc_csiosize;
297 1.8.6.2 bouyer sc->sc_csmembase = sc->sc_csiosize;
298 1.8.6.2 bouyer
299 1.8.6.2 bouyer #ifdef IT8368DEBUG
300 1.8.6.2 bouyer it8368_dump(sc);
301 1.8.6.2 bouyer #endif
302 1.8.6.2 bouyer /* Enable card and interrupt driving. */
303 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_CTRL_REG);
304 1.8.6.2 bouyer reg |= (IT8368_CTRL_GLOBALEN | IT8368_CTRL_CARDEN);
305 1.8.6.2 bouyer if (sc->sc_fixattr)
306 1.8.6.2 bouyer reg |= IT8368_CTRL_FIXATTRIO;
307 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_CTRL_REG, reg);
308 1.8.6.2 bouyer
309 1.8.6.2 bouyer sc->sc_irq = ca->ca_irq1;
310 1.8.6.2 bouyer sc->sc_card_irq = ca->ca_irq3;
311 1.8.6.2 bouyer
312 1.8.6.2 bouyer it8368_attach_socket(sc);
313 1.8.6.2 bouyer }
314 1.8.6.2 bouyer
315 1.8.6.2 bouyer __inline__ u_int16_t
316 1.8.6.2 bouyer it8368_reg_read(t, h, ofs)
317 1.8.6.2 bouyer bus_space_tag_t t;
318 1.8.6.2 bouyer bus_space_handle_t h;
319 1.8.6.2 bouyer int ofs;
320 1.8.6.2 bouyer {
321 1.8.6.2 bouyer u_int16_t val;
322 1.8.6.2 bouyer
323 1.8.6.2 bouyer val = bus_space_read_2(t, h, ofs);
324 1.8.6.2 bouyer return 0xffff & (((val >> 8) & 0xff)|((val << 8) & 0xff00));
325 1.8.6.2 bouyer }
326 1.8.6.2 bouyer
327 1.8.6.2 bouyer __inline__ void
328 1.8.6.2 bouyer it8368_reg_write(t, h, ofs, v)
329 1.8.6.2 bouyer bus_space_tag_t t;
330 1.8.6.2 bouyer bus_space_handle_t h;
331 1.8.6.2 bouyer int ofs;
332 1.8.6.2 bouyer u_int16_t v;
333 1.8.6.2 bouyer {
334 1.8.6.2 bouyer u_int16_t val;
335 1.8.6.2 bouyer
336 1.8.6.2 bouyer val = 0xffff & (((v >> 8) & 0xff)|((v << 8) & 0xff00));
337 1.8.6.2 bouyer bus_space_write_2(t, h, ofs, val);
338 1.8.6.2 bouyer }
339 1.8.6.2 bouyer
340 1.8.6.2 bouyer int
341 1.8.6.2 bouyer it8368_intr(arg)
342 1.8.6.2 bouyer void *arg;
343 1.8.6.2 bouyer {
344 1.8.6.2 bouyer struct it8368e_softc *sc = arg;
345 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
346 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
347 1.8.6.2 bouyer u_int16_t reg;
348 1.8.6.2 bouyer
349 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTSTAT_REG);
350 1.8.6.2 bouyer
351 1.8.6.2 bouyer if (reg & IT8368_PIN_BCRDRDY) {
352 1.8.6.2 bouyer if (sc->sc_card_fun) {
353 1.8.6.2 bouyer /* clear interrupt */
354 1.8.6.2 bouyer it8368_reg_write(csregt, csregh,
355 1.8.6.2 bouyer IT8368_GPIONEGINTSTAT_REG,
356 1.8.6.2 bouyer IT8368_PIN_BCRDRDY);
357 1.8.6.2 bouyer
358 1.8.6.2 bouyer /* Dispatch card interrupt handler */
359 1.8.6.2 bouyer (*sc->sc_card_fun)(sc->sc_card_arg);
360 1.8.6.2 bouyer }
361 1.8.6.2 bouyer } else if (reg & IT8368_PIN_CRDDET2) {
362 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTSTAT_REG,
363 1.8.6.2 bouyer IT8368_PIN_CRDDET2);
364 1.8.6.2 bouyer printf("[CSC]\n");
365 1.8.6.2 bouyer #ifdef IT8368DEBUG
366 1.8.6.2 bouyer it8368_dump(sc);
367 1.8.6.2 bouyer #endif
368 1.8.6.2 bouyer it8368_chip_socket_disable(sc);
369 1.8.6.2 bouyer } else {
370 1.8.6.2 bouyer #ifdef IT8368DEBUG
371 1.8.6.2 bouyer u_int16_t reg2;
372 1.8.6.2 bouyer reg2 = reg & ~(IT8368_PIN_BCRDRDY|IT8368_PIN_CRDDET2);
373 1.8.6.2 bouyer printf("unknown it8368 interrupt: ");
374 1.8.6.2 bouyer bitdisp(reg2);
375 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTSTAT_REG,
376 1.8.6.2 bouyer reg);
377 1.8.6.2 bouyer #endif
378 1.8.6.2 bouyer }
379 1.8.6.2 bouyer
380 1.8.6.2 bouyer return 0;
381 1.8.6.2 bouyer }
382 1.8.6.2 bouyer
383 1.8.6.2 bouyer int
384 1.8.6.2 bouyer it8368_print(arg, pnp)
385 1.8.6.2 bouyer void *arg;
386 1.8.6.2 bouyer const char *pnp;
387 1.8.6.2 bouyer {
388 1.8.6.2 bouyer if (pnp)
389 1.8.6.2 bouyer printf("pcmcia at %s", pnp);
390 1.8.6.2 bouyer
391 1.8.6.2 bouyer return UNCONF;
392 1.8.6.2 bouyer }
393 1.8.6.2 bouyer
394 1.8.6.2 bouyer int
395 1.8.6.2 bouyer it8368_submatch(parent, cf, aux)
396 1.8.6.2 bouyer struct device *parent;
397 1.8.6.2 bouyer struct cfdata *cf;
398 1.8.6.2 bouyer void *aux;
399 1.8.6.2 bouyer {
400 1.8.6.2 bouyer return ((*cf->cf_attach->ca_match)(parent, cf, aux));
401 1.8.6.2 bouyer }
402 1.8.6.2 bouyer
403 1.8.6.2 bouyer void
404 1.8.6.2 bouyer it8368_attach_socket(sc)
405 1.8.6.2 bouyer struct it8368e_softc *sc;
406 1.8.6.2 bouyer {
407 1.8.6.2 bouyer struct pcmciabus_attach_args paa;
408 1.8.6.2 bouyer
409 1.8.6.2 bouyer paa.paa_busname = "pcmcia";
410 1.8.6.2 bouyer paa.pct = (pcmcia_chipset_tag_t)&it8368_functions;
411 1.8.6.2 bouyer paa.pch = (pcmcia_chipset_handle_t)sc;
412 1.8.6.2 bouyer paa.iobase = 0; /* I don't use them */
413 1.8.6.2 bouyer paa.iosize = 0;
414 1.8.6.2 bouyer
415 1.8.6.2 bouyer if ((sc->sc_pcmcia = config_found_sm((void*)sc, &paa, it8368_print,
416 1.8.6.2 bouyer it8368_submatch))) {
417 1.8.6.2 bouyer
418 1.8.6.2 bouyer it8368_init_socket(sc);
419 1.8.6.2 bouyer }
420 1.8.6.2 bouyer }
421 1.8.6.2 bouyer
422 1.8.6.2 bouyer void
423 1.8.6.2 bouyer it8368_init_socket(sc)
424 1.8.6.2 bouyer struct it8368e_softc *sc;
425 1.8.6.2 bouyer {
426 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
427 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
428 1.8.6.2 bouyer u_int16_t reg;
429 1.8.6.2 bouyer
430 1.8.6.2 bouyer /*
431 1.8.6.2 bouyer * set up the card to interrupt on card detect
432 1.8.6.2 bouyer */
433 1.8.6.2 bouyer reg = IT8368_PIN_CRDDET2; /* CSC */
434 1.8.6.2 bouyer /* enable negative edge */
435 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
436 1.8.6.2 bouyer /* disable positive edge */
437 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIOPOSINTEN_REG, 0);
438 1.8.6.2 bouyer
439 1.8.6.2 bouyer sc->sc_ih = tx_intr_establish(sc->sc_tc, sc->sc_irq,
440 1.8.6.2 bouyer IST_EDGE, IPL_BIO, it8368_intr, sc);
441 1.8.6.2 bouyer if (sc->sc_ih == NULL) {
442 1.8.6.2 bouyer printf("%s: can't establish interrupt\n",
443 1.8.6.2 bouyer sc->sc_dev.dv_xname);
444 1.8.6.2 bouyer return;
445 1.8.6.2 bouyer }
446 1.8.6.2 bouyer
447 1.8.6.2 bouyer /*
448 1.8.6.2 bouyer * if there's a card there, then attach it.
449 1.8.6.2 bouyer */
450 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAIN_REG);
451 1.8.6.2 bouyer
452 1.8.6.2 bouyer if (reg & (IT8368_PIN_CRDDET2|IT8368_PIN_CRDDET1)) {
453 1.8.6.2 bouyer sc->sc_laststate = IT8368_LASTSTATE_EMPTY;
454 1.8.6.2 bouyer } else {
455 1.8.6.2 bouyer pcmcia_card_attach(sc->sc_pcmcia);
456 1.8.6.2 bouyer sc->sc_laststate = IT8368_LASTSTATE_PRESENT;
457 1.8.6.2 bouyer }
458 1.8.6.2 bouyer }
459 1.8.6.2 bouyer
460 1.8.6.2 bouyer void *
461 1.8.6.2 bouyer it8368_chip_intr_establish(pch, pf, ipl, ih_fun, ih_arg)
462 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
463 1.8.6.2 bouyer struct pcmcia_function *pf;
464 1.8.6.2 bouyer int ipl;
465 1.8.6.2 bouyer int (*ih_fun) __P((void *));
466 1.8.6.2 bouyer void *ih_arg;
467 1.8.6.2 bouyer {
468 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
469 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
470 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
471 1.8.6.2 bouyer u_int16_t reg;
472 1.8.6.2 bouyer
473 1.8.6.2 bouyer if (sc->sc_card_fun)
474 1.8.6.2 bouyer panic("it8368_chip_intr_establish: "
475 1.8.6.2 bouyer "duplicate card interrupt handler.");
476 1.8.6.2 bouyer
477 1.8.6.2 bouyer sc->sc_card_fun = ih_fun;
478 1.8.6.2 bouyer sc->sc_card_arg = ih_arg;
479 1.8.6.2 bouyer
480 1.8.6.2 bouyer sc->sc_card_ih = tx_intr_establish(sc->sc_tc, sc->sc_card_irq,
481 1.8.6.2 bouyer IST_EDGE, IPL_BIO, it8368_intr,
482 1.8.6.2 bouyer sc);
483 1.8.6.2 bouyer
484 1.8.6.2 bouyer /* enable card interrupt */
485 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTEN_REG);
486 1.8.6.2 bouyer reg |= IT8368_PIN_BCRDRDY;
487 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
488 1.8.6.2 bouyer
489 1.8.6.2 bouyer return sc->sc_card_ih;
490 1.8.6.2 bouyer }
491 1.8.6.2 bouyer
492 1.8.6.2 bouyer void
493 1.8.6.2 bouyer it8368_chip_intr_disestablish(pch, ih)
494 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
495 1.8.6.2 bouyer void *ih;
496 1.8.6.2 bouyer {
497 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
498 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
499 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
500 1.8.6.2 bouyer u_int16_t reg;
501 1.8.6.2 bouyer
502 1.8.6.2 bouyer if (!sc->sc_card_fun)
503 1.8.6.2 bouyer panic("it8368_chip_intr_disestablish:"
504 1.8.6.2 bouyer "no handler established.");
505 1.8.6.2 bouyer assert(ih == sc->sc_card_ih);
506 1.8.6.2 bouyer
507 1.8.6.2 bouyer sc->sc_card_fun = 0;
508 1.8.6.2 bouyer sc->sc_card_arg = 0;
509 1.8.6.2 bouyer
510 1.8.6.2 bouyer /* disable card interrupt */
511 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIONEGINTEN_REG);
512 1.8.6.2 bouyer reg &= ~IT8368_PIN_BCRDRDY;
513 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIONEGINTEN_REG, reg);
514 1.8.6.2 bouyer
515 1.8.6.2 bouyer tx_intr_disestablish(sc->sc_tc, ih);
516 1.8.6.2 bouyer }
517 1.8.6.2 bouyer
518 1.8.6.2 bouyer int
519 1.8.6.2 bouyer it8368_chip_mem_alloc(pch, size, pcmhp)
520 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
521 1.8.6.2 bouyer bus_size_t size;
522 1.8.6.2 bouyer struct pcmcia_mem_handle *pcmhp;
523 1.8.6.2 bouyer {
524 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
525 1.8.6.2 bouyer
526 1.8.6.2 bouyer if (bus_space_alloc(sc->sc_csmemt, sc->sc_csmembase,
527 1.8.6.2 bouyer sc->sc_csmembase + sc->sc_csmemsize, size,
528 1.8.6.2 bouyer size, 0, 0, 0, &pcmhp->memh)) {
529 1.8.6.2 bouyer DPRINTF(("it8368_chip_mem_alloc: failed\n"));
530 1.8.6.2 bouyer return 1;
531 1.8.6.2 bouyer }
532 1.8.6.2 bouyer
533 1.8.6.2 bouyer if (!sc->sc_fixattr) /* XXX IT8368 brain damaged spec */
534 1.8.6.2 bouyer pcmhp->memh -= sc->sc_csmembase;
535 1.8.6.2 bouyer
536 1.8.6.2 bouyer pcmhp->memt = sc->sc_csmemt;
537 1.8.6.2 bouyer pcmhp->addr = pcmhp->memh;
538 1.8.6.2 bouyer pcmhp->size = size;
539 1.8.6.2 bouyer pcmhp->realsize = size;
540 1.8.6.2 bouyer
541 1.8.6.2 bouyer DPRINTF(("it8368_chip_mem_alloc: %#x+%#x\n",
542 1.8.6.2 bouyer (unsigned)pcmhp->memh, (unsigned)size));
543 1.8.6.2 bouyer
544 1.8.6.2 bouyer return 0;
545 1.8.6.2 bouyer }
546 1.8.6.2 bouyer
547 1.8.6.2 bouyer void
548 1.8.6.2 bouyer it8368_chip_mem_free(pch, pcmhp)
549 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
550 1.8.6.2 bouyer struct pcmcia_mem_handle *pcmhp;
551 1.8.6.2 bouyer {
552 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
553 1.8.6.2 bouyer
554 1.8.6.2 bouyer DPRINTF(("it8368_chip_mem_free: %#x+%#x\n",
555 1.8.6.2 bouyer (unsigned)pcmhp->memh, (unsigned)pcmhp->size));
556 1.8.6.2 bouyer
557 1.8.6.2 bouyer if (!sc->sc_fixattr) /* XXX IT8368 brain damaged spec */
558 1.8.6.2 bouyer pcmhp->memh += sc->sc_csmembase;
559 1.8.6.2 bouyer
560 1.8.6.2 bouyer bus_space_unmap(pcmhp->memt, pcmhp->memh, pcmhp->size);
561 1.8.6.2 bouyer }
562 1.8.6.2 bouyer
563 1.8.6.2 bouyer int
564 1.8.6.2 bouyer it8368_chip_mem_map(pch, kind, card_addr, size, pcmhp, offsetp, windowp)
565 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
566 1.8.6.2 bouyer int kind;
567 1.8.6.2 bouyer bus_addr_t card_addr;
568 1.8.6.2 bouyer bus_size_t size;
569 1.8.6.2 bouyer struct pcmcia_mem_handle *pcmhp;
570 1.8.6.2 bouyer bus_addr_t *offsetp;
571 1.8.6.2 bouyer int *windowp;
572 1.8.6.2 bouyer {
573 1.8.6.2 bouyer /* attribute mode */
574 1.8.6.2 bouyer it8368_mode(pch, IT8368_ATTR_MODE, IT8368_WIDTH_16);
575 1.8.6.2 bouyer
576 1.8.6.2 bouyer *offsetp = card_addr;
577 1.8.6.2 bouyer DPRINTF(("it8368_chip_mem_map %#x+%#x\n",
578 1.8.6.2 bouyer (unsigned)pcmhp->memh, (unsigned)size));
579 1.8.6.2 bouyer
580 1.8.6.2 bouyer return 0;
581 1.8.6.2 bouyer }
582 1.8.6.2 bouyer
583 1.8.6.2 bouyer void
584 1.8.6.2 bouyer it8368_chip_mem_unmap(pch, window)
585 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
586 1.8.6.2 bouyer int window;
587 1.8.6.2 bouyer {
588 1.8.6.2 bouyer /* return to I/O mode */
589 1.8.6.2 bouyer it8368_mode(pch, IT8368_IO_MODE, IT8368_WIDTH_16);
590 1.8.6.2 bouyer }
591 1.8.6.2 bouyer
592 1.8.6.2 bouyer void
593 1.8.6.2 bouyer it8368_mode(pch, io, width)
594 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
595 1.8.6.2 bouyer int io;
596 1.8.6.2 bouyer int width;
597 1.8.6.2 bouyer {
598 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
599 1.8.6.2 bouyer txreg_t reg32;
600 1.8.6.2 bouyer
601 1.8.6.2 bouyer DPRINTF(("it8368_mode: change access space to "));
602 1.8.6.2 bouyer DPRINTF((io ? "I/O (%dbit)\n" : "attribute (%dbit)...\n",
603 1.8.6.2 bouyer width == IT8368_WIDTH_8 ? 8 : 16));
604 1.8.6.2 bouyer
605 1.8.6.2 bouyer reg32 = tx_conf_read(sc->sc_tc, TX39_MEMCONFIG3_REG);
606 1.8.6.2 bouyer
607 1.8.6.2 bouyer if (io) {
608 1.8.6.2 bouyer if (width == IT8368_WIDTH_8)
609 1.8.6.2 bouyer reg32 |= TX39_MEMCONFIG3_PORT8SEL;
610 1.8.6.2 bouyer else
611 1.8.6.2 bouyer reg32 &= ~TX39_MEMCONFIG3_PORT8SEL;
612 1.8.6.2 bouyer }
613 1.8.6.2 bouyer
614 1.8.6.2 bouyer if (!sc->sc_fixattr) {
615 1.8.6.2 bouyer if (io)
616 1.8.6.2 bouyer reg32 |= TX39_MEMCONFIG3_CARD1IOEN;
617 1.8.6.2 bouyer else
618 1.8.6.2 bouyer reg32 &= ~TX39_MEMCONFIG3_CARD1IOEN;
619 1.8.6.2 bouyer }
620 1.8.6.2 bouyer tx_conf_write(sc->sc_tc, TX39_MEMCONFIG3_REG, reg32);
621 1.8.6.2 bouyer
622 1.8.6.2 bouyer #ifdef IT8368DEBUG
623 1.8.6.2 bouyer if (sc->sc_fixattr)
624 1.8.6.2 bouyer return; /* No need to report BIU status */
625 1.8.6.2 bouyer
626 1.8.6.2 bouyer /* check BIU status */
627 1.8.6.2 bouyer reg32 = tx_conf_read(sc->sc_tc, TX39_MEMCONFIG3_REG);
628 1.8.6.2 bouyer if (reg32 & TX39_MEMCONFIG3_CARD1IOEN) {
629 1.8.6.2 bouyer DPRINTF(("it8368_mode: I/O space (%dbit) enabled\n",
630 1.8.6.2 bouyer reg32 & TX39_MEMCONFIG3_PORT8SEL ? 8 : 16));
631 1.8.6.2 bouyer } else {
632 1.8.6.2 bouyer DPRINTF(("it8368_mode: atttribute space enabled\n"));
633 1.8.6.2 bouyer }
634 1.8.6.2 bouyer #endif /* IT8368DEBUG */
635 1.8.6.2 bouyer }
636 1.8.6.2 bouyer
637 1.8.6.2 bouyer int
638 1.8.6.2 bouyer it8368_chip_io_alloc(pch, start, size, align, pcihp)
639 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
640 1.8.6.2 bouyer bus_addr_t start;
641 1.8.6.2 bouyer bus_size_t size;
642 1.8.6.2 bouyer bus_size_t align;
643 1.8.6.2 bouyer struct pcmcia_io_handle *pcihp;
644 1.8.6.2 bouyer {
645 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
646 1.8.6.2 bouyer
647 1.8.6.2 bouyer if (start) {
648 1.8.6.2 bouyer if (bus_space_map(sc->sc_csiot, start, size, 0,
649 1.8.6.2 bouyer &pcihp->ioh)) {
650 1.8.6.2 bouyer return 1;
651 1.8.6.2 bouyer }
652 1.8.6.2 bouyer DPRINTF(("it8368_chip_io_alloc map port %#x+%#x\n",
653 1.8.6.2 bouyer (unsigned)start, (unsigned)size));
654 1.8.6.2 bouyer } else {
655 1.8.6.2 bouyer if (bus_space_alloc(sc->sc_csiot, sc->sc_csiobase,
656 1.8.6.2 bouyer sc->sc_csiobase + sc->sc_csiosize,
657 1.8.6.2 bouyer size, align, 0, 0, &pcihp->addr,
658 1.8.6.2 bouyer &pcihp->ioh)) {
659 1.8.6.2 bouyer
660 1.8.6.2 bouyer return 1;
661 1.8.6.2 bouyer }
662 1.8.6.2 bouyer pcihp->flags = PCMCIA_IO_ALLOCATED;
663 1.8.6.2 bouyer DPRINTF(("it8368_chip_io_alloc alloc %#x from %#x\n",
664 1.8.6.2 bouyer (unsigned)size, (unsigned)pcihp->addr));
665 1.8.6.2 bouyer }
666 1.8.6.2 bouyer
667 1.8.6.2 bouyer pcihp->iot = sc->sc_csiot;
668 1.8.6.2 bouyer pcihp->size = size;
669 1.8.6.2 bouyer
670 1.8.6.2 bouyer return 0;
671 1.8.6.2 bouyer }
672 1.8.6.2 bouyer
673 1.8.6.2 bouyer int
674 1.8.6.2 bouyer it8368_chip_io_map(pch, width, offset, size, pcihp, windowp)
675 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
676 1.8.6.2 bouyer int width;
677 1.8.6.2 bouyer bus_addr_t offset;
678 1.8.6.2 bouyer bus_size_t size;
679 1.8.6.2 bouyer struct pcmcia_io_handle *pcihp;
680 1.8.6.2 bouyer int *windowp;
681 1.8.6.2 bouyer {
682 1.8.6.2 bouyer /* I/O mode */
683 1.8.6.2 bouyer it8368_mode(pch, IT8368_IO_MODE, IT8368_WIDTH_16);
684 1.8.6.2 bouyer
685 1.8.6.2 bouyer DPRINTF(("it8368_chip_io_map %#x:%#x+%#x\n",
686 1.8.6.2 bouyer (unsigned)pcihp->ioh, (unsigned)offset, (unsigned)size));
687 1.8.6.2 bouyer
688 1.8.6.2 bouyer return 0;
689 1.8.6.2 bouyer }
690 1.8.6.2 bouyer
691 1.8.6.2 bouyer void
692 1.8.6.2 bouyer it8368_chip_io_free(pch, pcihp)
693 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
694 1.8.6.2 bouyer struct pcmcia_io_handle *pcihp;
695 1.8.6.2 bouyer {
696 1.8.6.2 bouyer if (pcihp->flags & PCMCIA_IO_ALLOCATED)
697 1.8.6.2 bouyer bus_space_free(pcihp->iot, pcihp->ioh, pcihp->size);
698 1.8.6.2 bouyer else
699 1.8.6.2 bouyer bus_space_unmap(pcihp->iot, pcihp->ioh, pcihp->size);
700 1.8.6.2 bouyer
701 1.8.6.2 bouyer DPRINTF(("it8368_chip_io_free %#x+%#x\n",
702 1.8.6.2 bouyer (unsigned)pcihp->ioh, (unsigned)pcihp->size));
703 1.8.6.2 bouyer }
704 1.8.6.2 bouyer
705 1.8.6.2 bouyer void
706 1.8.6.2 bouyer it8368_chip_io_unmap(pch, window)
707 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
708 1.8.6.2 bouyer int window;
709 1.8.6.2 bouyer {
710 1.8.6.2 bouyer }
711 1.8.6.2 bouyer
712 1.8.6.2 bouyer void
713 1.8.6.2 bouyer it8368_chip_socket_enable(pch)
714 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
715 1.8.6.2 bouyer {
716 1.8.6.2 bouyer #ifndef WINCE_DEFAULT_SETTING
717 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*)pch;
718 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
719 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
720 1.8.6.2 bouyer volatile u_int16_t reg;
721 1.8.6.2 bouyer
722 1.8.6.2 bouyer /* Power off */
723 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
724 1.8.6.2 bouyer reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
725 1.8.6.2 bouyer reg |= (IT8368_PIN_CRDVCC_0V | IT8368_PIN_CRDVPP_0V);
726 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
727 1.8.6.2 bouyer delay(20000);
728 1.8.6.2 bouyer
729 1.8.6.2 bouyer /*
730 1.8.6.2 bouyer * wait 300ms until power fails (Tpf). Then, wait 100ms since
731 1.8.6.2 bouyer * we are changing Vcc (Toff).
732 1.8.6.2 bouyer */
733 1.8.6.2 bouyer delay((300 + 100) * 1000);
734 1.8.6.2 bouyer
735 1.8.6.2 bouyer /* Supply Vcc */
736 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
737 1.8.6.2 bouyer reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
738 1.8.6.2 bouyer reg |= IT8368_PIN_CRDVCC_5V; /* XXX */
739 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
740 1.8.6.2 bouyer
741 1.8.6.2 bouyer /*
742 1.8.6.2 bouyer * wait 100ms until power raise (Tpr) and 20ms to become
743 1.8.6.2 bouyer * stable (Tsu(Vcc)).
744 1.8.6.2 bouyer *
745 1.8.6.2 bouyer * some machines require some more time to be settled
746 1.8.6.2 bouyer * (300ms is added here).
747 1.8.6.2 bouyer */
748 1.8.6.2 bouyer delay((100 + 20 + 300) * 1000);
749 1.8.6.2 bouyer
750 1.8.6.2 bouyer /* Assert reset signal */
751 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
752 1.8.6.2 bouyer reg |= IT8368_PIN_BCRDRST;
753 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
754 1.8.6.2 bouyer
755 1.8.6.2 bouyer /*
756 1.8.6.2 bouyer * hold RESET at least 10us.
757 1.8.6.2 bouyer */
758 1.8.6.2 bouyer delay(10);
759 1.8.6.2 bouyer
760 1.8.6.2 bouyer /* deassert reset signal */
761 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
762 1.8.6.2 bouyer reg &= ~IT8368_PIN_BCRDRST;
763 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
764 1.8.6.2 bouyer delay(20000);
765 1.8.6.2 bouyer
766 1.8.6.2 bouyer DPRINTF(("it8368_chip_socket_enable: socket enabled\n"));
767 1.8.6.2 bouyer #endif /* !WINCE_DEFAULT_SETTING */
768 1.8.6.2 bouyer }
769 1.8.6.2 bouyer
770 1.8.6.2 bouyer void
771 1.8.6.2 bouyer it8368_chip_socket_disable(pch)
772 1.8.6.2 bouyer pcmcia_chipset_handle_t pch;
773 1.8.6.2 bouyer {
774 1.8.6.2 bouyer #ifndef WINCE_DEFAULT_SETTING
775 1.8.6.2 bouyer struct it8368e_softc *sc = (struct it8368e_softc*) pch;
776 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
777 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
778 1.8.6.2 bouyer u_int16_t reg;
779 1.8.6.2 bouyer
780 1.8.6.2 bouyer /* Power down */
781 1.8.6.2 bouyer reg = it8368_reg_read(csregt, csregh, IT8368_GPIODATAOUT_REG);
782 1.8.6.2 bouyer reg &= ~(IT8368_PIN_CRDVCCMASK | IT8368_PIN_CRDVPPMASK);
783 1.8.6.2 bouyer reg |= (IT8368_PIN_CRDVCC_0V | IT8368_PIN_CRDVPP_0V);
784 1.8.6.2 bouyer it8368_reg_write(csregt, csregh, IT8368_GPIODATAOUT_REG, reg);
785 1.8.6.2 bouyer delay(20000);
786 1.8.6.2 bouyer
787 1.8.6.2 bouyer /*
788 1.8.6.2 bouyer * wait 300ms until power fails (Tpf).
789 1.8.6.2 bouyer */
790 1.8.6.2 bouyer delay(300 * 1000);
791 1.8.6.2 bouyer
792 1.8.6.2 bouyer DPRINTF(("it8368_chip_socket_disable: socket disabled\n"));
793 1.8.6.2 bouyer #endif /* !WINCE_DEFAULT_SETTING */
794 1.8.6.2 bouyer }
795 1.8.6.2 bouyer
796 1.8.6.2 bouyer #ifdef IT8368DEBUG
797 1.8.6.2 bouyer #define PRINTGPIO(m) __bitdisp(it8368_reg_read(csregt, csregh, \
798 1.8.6.2 bouyer IT8368_GPIO##m##_REG), 0, IT8368_GPIO_MAX, #m, 1)
799 1.8.6.2 bouyer #define PRINTMFIO(m) __bitdisp(it8368_reg_read(csregt, csregh, \
800 1.8.6.2 bouyer IT8368_MFIO##m##_REG), 0, IT8368_MFIO_MAX, #m, 1)
801 1.8.6.2 bouyer void
802 1.8.6.2 bouyer it8368_dump(sc)
803 1.8.6.2 bouyer struct it8368e_softc *sc;
804 1.8.6.2 bouyer {
805 1.8.6.2 bouyer bus_space_tag_t csregt = sc->sc_csregt;
806 1.8.6.2 bouyer bus_space_handle_t csregh = sc->sc_csregh;
807 1.8.6.2 bouyer
808 1.8.6.2 bouyer printf("[GPIO]\n");
809 1.8.6.2 bouyer PRINTGPIO(DIR);
810 1.8.6.2 bouyer PRINTGPIO(DATAIN);
811 1.8.6.2 bouyer PRINTGPIO(DATAOUT);
812 1.8.6.2 bouyer PRINTGPIO(POSINTEN);
813 1.8.6.2 bouyer PRINTGPIO(NEGINTEN);
814 1.8.6.2 bouyer PRINTGPIO(POSINTSTAT);
815 1.8.6.2 bouyer PRINTGPIO(NEGINTSTAT);
816 1.8.6.2 bouyer printf("[MFIO]\n");
817 1.8.6.2 bouyer PRINTMFIO(SEL);
818 1.8.6.2 bouyer PRINTMFIO(DIR);
819 1.8.6.2 bouyer PRINTMFIO(DATAIN);
820 1.8.6.2 bouyer PRINTMFIO(DATAOUT);
821 1.8.6.2 bouyer PRINTMFIO(POSINTEN);
822 1.8.6.2 bouyer PRINTMFIO(NEGINTEN);
823 1.8.6.2 bouyer PRINTMFIO(POSINTSTAT);
824 1.8.6.2 bouyer PRINTMFIO(NEGINTSTAT);
825 1.8.6.2 bouyer __bitdisp(it8368_reg_read(csregt, csregh, IT8368_CTRL_REG), 0, 15,
826 1.8.6.2 bouyer "CTRL", 1);
827 1.8.6.2 bouyer __bitdisp(it8368_reg_read(csregt, csregh, IT8368_GPIODATAIN_REG),
828 1.8.6.2 bouyer 8, 11, "]CRDDET/SENSE[", 1);
829 1.8.6.2 bouyer }
830 1.8.6.2 bouyer #endif /* IT8368DEBUG */
831