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