hd64461pcmcia.c revision 1.1 1 1.1 uch /* $NetBSD: hd64461pcmcia.c,v 1.1 2001/02/21 15:39:09 uch Exp $ */
2 1.1 uch
3 1.1 uch /*-
4 1.1 uch * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.1 uch * by UCHIYAMA Yasushi.
9 1.1 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 uch * notice, this list of conditions and the following disclaimer in the
17 1.1 uch * documentation and/or other materials provided with the distribution.
18 1.1 uch * 3. All advertising materials mentioning features or use of this software
19 1.1 uch * must display the following acknowledgement:
20 1.1 uch * This product includes software developed by the NetBSD
21 1.1 uch * Foundation, Inc. and its contributors.
22 1.1 uch * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 uch * contributors may be used to endorse or promote products derived
24 1.1 uch * from this software without specific prior written permission.
25 1.1 uch *
26 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 uch * POSSIBILITY OF SUCH DAMAGE.
37 1.1 uch */
38 1.1 uch #define HD64461PCMCIA_DEBUG
39 1.1 uch
40 1.1 uch #include <sys/param.h>
41 1.1 uch #include <sys/systm.h>
42 1.1 uch #include <sys/device.h>
43 1.1 uch #include <sys/malloc.h>
44 1.1 uch #include <sys/kthread.h>
45 1.1 uch #include <sys/boot_flag.h>
46 1.1 uch
47 1.1 uch #include <machine/bus.h>
48 1.1 uch #include <machine/intr.h>
49 1.1 uch
50 1.1 uch #ifdef DEBUG
51 1.1 uch #include <hpcsh/hpcsh/debug.h>
52 1.1 uch #endif
53 1.1 uch
54 1.1 uch #include <dev/pcmcia/pcmciareg.h>
55 1.1 uch #include <dev/pcmcia/pcmciavar.h>
56 1.1 uch #include <dev/pcmcia/pcmciachip.h>
57 1.1 uch
58 1.1 uch #include <sh3/bscreg.h>
59 1.1 uch
60 1.1 uch #include <hpcsh/dev/hd64461/hd64461reg.h>
61 1.1 uch #include <hpcsh/dev/hd64461/hd64461var.h>
62 1.1 uch #include <hpcsh/dev/hd64461/hd64461intcvar.h>
63 1.1 uch #include <hpcsh/dev/hd64461/hd64461gpioreg.h>
64 1.1 uch #include <hpcsh/dev/hd64461/hd64461pcmciareg.h>
65 1.1 uch
66 1.1 uch #ifdef HD64461PCMCIA_DEBUG
67 1.1 uch int hd64461pcmcia_debug = 1;
68 1.1 uch #define DPRINTF(fmt, args...) \
69 1.1 uch if (hd64461pcmcia_debug) \
70 1.1 uch printf("%s: " fmt, __FUNCTION__ , ##args)
71 1.1 uch #define DPRINTFN(n, arg) \
72 1.1 uch if (hd64461pcmcia_debug > (n)) \
73 1.1 uch printf("%s: " fmt, __FUNCTION__ , ##args)
74 1.1 uch #else
75 1.1 uch #define DPRINTF(arg...) ((void)0)
76 1.1 uch #define DPRINTFN(n, arg...) ((void)0)
77 1.1 uch #endif
78 1.1 uch
79 1.1 uch enum controller_channel {
80 1.1 uch CHANNEL_0 = 0,
81 1.1 uch CHANNEL_1 = 1,
82 1.1 uch CHANNEL_MAX = 2
83 1.1 uch };
84 1.1 uch
85 1.1 uch enum memory_window_mode {
86 1.1 uch MEMWIN_16M_MODE,
87 1.1 uch MEMWIN_32M_MODE
88 1.1 uch };
89 1.1 uch
90 1.1 uch enum memory_window_16 {
91 1.1 uch MEMWIN_16M_COMMON_0,
92 1.1 uch MEMWIN_16M_COMMON_1,
93 1.1 uch MEMWIN_16M_COMMON_2,
94 1.1 uch MEMWIN_16M_COMMON_3,
95 1.1 uch };
96 1.1 uch #define MEMWIN_16M_MAX 4
97 1.1 uch
98 1.1 uch enum memory_window_32 {
99 1.1 uch MEMWIN_32M_ATTR,
100 1.1 uch MEMWIN_32M_COMMON_0,
101 1.1 uch MEMWIN_32M_COMMON_1,
102 1.1 uch };
103 1.1 uch #define MEMWIN_32M_MAX 3
104 1.1 uch
105 1.1 uch enum hd64461pcmcia_event_type {
106 1.1 uch EVENT_NONE,
107 1.1 uch EVENT_INSERT,
108 1.1 uch EVENT_REMOVE,
109 1.1 uch };
110 1.1 uch #define EVENT_QUEUE_MAX 5
111 1.1 uch
112 1.1 uch struct hd64461pcmcia_softc; /* forward declaration */
113 1.1 uch
114 1.1 uch struct hd64461pcmcia_window_cookie {
115 1.1 uch bus_space_tag_t wc_tag;
116 1.1 uch bus_space_handle_t wc_handle;
117 1.1 uch int wc_size;
118 1.1 uch int wc_window;
119 1.1 uch };
120 1.1 uch
121 1.1 uch struct hd64461pcmcia_channel {
122 1.1 uch struct hd64461pcmcia_softc *ch_parent;
123 1.1 uch struct device *ch_pcmcia;
124 1.1 uch enum controller_channel ch_channel;
125 1.1 uch
126 1.1 uch /* memory space */
127 1.1 uch enum memory_window_mode ch_memory_window_mode;
128 1.1 uch bus_space_tag_t ch_memt;
129 1.1 uch bus_space_handle_t ch_memh;
130 1.1 uch bus_addr_t ch_membase_addr;
131 1.1 uch bus_size_t ch_memsize;
132 1.1 uch bus_space_tag_t ch_cmemt[MEMWIN_16M_MAX];
133 1.1 uch
134 1.1 uch /* I/O space */
135 1.1 uch bus_space_tag_t ch_iot;
136 1.1 uch bus_addr_t ch_iobase;
137 1.1 uch bus_size_t ch_iosize;
138 1.1 uch
139 1.1 uch /* card interrupt */
140 1.1 uch int (*ch_ih_card_func)(void *);
141 1.1 uch void *ch_ih_card_arg;
142 1.1 uch int ch_attached;
143 1.1 uch };
144 1.1 uch
145 1.1 uch struct hd64461pcmcia_event {
146 1.1 uch int __queued;
147 1.1 uch enum hd64461pcmcia_event_type pe_type;
148 1.1 uch struct hd64461pcmcia_channel *pe_ch;
149 1.1 uch SIMPLEQ_ENTRY(hd64461pcmcia_event) pe_link;
150 1.1 uch };
151 1.1 uch
152 1.1 uch struct hd64461pcmcia_softc {
153 1.1 uch struct device sc_dev;
154 1.1 uch enum hd64461_module_id sc_module_id;
155 1.1 uch int sc_shutdown;
156 1.1 uch
157 1.1 uch /* CSC event */
158 1.1 uch struct proc *sc_event_thread;
159 1.1 uch struct hd64461pcmcia_event sc_event_pool[EVENT_QUEUE_MAX];
160 1.1 uch SIMPLEQ_HEAD (, hd64461pcmcia_event) sc_event_head;
161 1.1 uch
162 1.1 uch struct hd64461pcmcia_channel sc_ch[CHANNEL_MAX];
163 1.1 uch };
164 1.1 uch
165 1.1 uch static int _chip_mem_alloc(pcmcia_chipset_handle_t, bus_size_t,
166 1.1 uch struct pcmcia_mem_handle *);
167 1.1 uch static void _chip_mem_free(pcmcia_chipset_handle_t,
168 1.1 uch struct pcmcia_mem_handle *);
169 1.1 uch static int _chip_mem_map(pcmcia_chipset_handle_t, int, bus_addr_t,
170 1.1 uch bus_size_t, struct pcmcia_mem_handle *,
171 1.1 uch bus_addr_t *, int *);
172 1.1 uch static void _chip_mem_unmap(pcmcia_chipset_handle_t, int);
173 1.1 uch static int _chip_io_alloc(pcmcia_chipset_handle_t, bus_addr_t,
174 1.1 uch bus_size_t, bus_size_t, struct pcmcia_io_handle *);
175 1.1 uch static void _chip_io_free(pcmcia_chipset_handle_t, struct pcmcia_io_handle *);
176 1.1 uch static int _chip_io_map(pcmcia_chipset_handle_t, int, bus_addr_t,
177 1.1 uch bus_size_t, struct pcmcia_io_handle *, int *);
178 1.1 uch static void _chip_io_unmap(pcmcia_chipset_handle_t, int);
179 1.1 uch static void _chip_socket_enable(pcmcia_chipset_handle_t);
180 1.1 uch static void _chip_socket_disable(pcmcia_chipset_handle_t);
181 1.1 uch static void *_chip_intr_establish(pcmcia_chipset_handle_t,
182 1.1 uch struct pcmcia_function *, int,
183 1.1 uch int (*)(void *), void *);
184 1.1 uch static void _chip_intr_disestablish(pcmcia_chipset_handle_t, void *);
185 1.1 uch
186 1.1 uch static struct pcmcia_chip_functions hd64461pcmcia_functions = {
187 1.1 uch _chip_mem_alloc,
188 1.1 uch _chip_mem_free,
189 1.1 uch _chip_mem_map,
190 1.1 uch _chip_mem_unmap,
191 1.1 uch _chip_io_alloc,
192 1.1 uch _chip_io_free,
193 1.1 uch _chip_io_map,
194 1.1 uch _chip_io_unmap,
195 1.1 uch _chip_intr_establish,
196 1.1 uch _chip_intr_disestablish,
197 1.1 uch _chip_socket_enable,
198 1.1 uch _chip_socket_disable,
199 1.1 uch };
200 1.1 uch
201 1.1 uch static int hd64461pcmcia_match(struct device *, struct cfdata *, void *);
202 1.1 uch static void hd64461pcmcia_attach(struct device *, struct device *, void *);
203 1.1 uch static int hd64461pcmcia_print(void *, const char *);
204 1.1 uch static int hd64461pcmcia_submatch(struct device *, struct cfdata *, void *);
205 1.1 uch
206 1.1 uch struct cfattach hd64461pcmcia_ca = {
207 1.1 uch sizeof(struct hd64461pcmcia_softc), hd64461pcmcia_match,
208 1.1 uch hd64461pcmcia_attach
209 1.1 uch };
210 1.1 uch
211 1.1 uch static void hd64461pcmcia_attach_channel(struct hd64461pcmcia_softc *,
212 1.1 uch enum controller_channel);
213 1.1 uch /* hot plug */
214 1.1 uch static void hd64461pcmcia_create_event_thread(void *);
215 1.1 uch static void hd64461pcmcia_event_thread(void *);
216 1.1 uch static void queue_event(struct hd64461pcmcia_channel *,
217 1.1 uch enum hd64461pcmcia_event_type);
218 1.1 uch /* interrupt handler */
219 1.1 uch static int hd64461pcmcia_channel0_intr(void *);
220 1.1 uch static int hd64461pcmcia_channel1_intr(void *);
221 1.1 uch /* card status */
222 1.1 uch static enum hd64461pcmcia_event_type detect_card(enum controller_channel);
223 1.1 uch static void power_off(enum controller_channel);
224 1.1 uch static void power_on(enum controller_channel);
225 1.1 uch /* memory window access ops */
226 1.1 uch static void memory_window_mode(enum controller_channel,
227 1.1 uch enum memory_window_mode);
228 1.1 uch static void memory_window_16(enum controller_channel, enum memory_window_16);
229 1.1 uch static void memory_window_32(enum controller_channel, enum memory_window_32)
230 1.1 uch __attribute__((__unused__));
231 1.1 uch #ifdef DEBUG
232 1.1 uch static void hd64461pcmcia_info(struct hd64461pcmcia_softc *);
233 1.1 uch #endif
234 1.1 uch #define __delay(x) delay((x) * 100) //XXX
235 1.1 uch
236 1.1 uch static int
237 1.1 uch hd64461pcmcia_match(struct device *parent, struct cfdata *cf, void *aux)
238 1.1 uch {
239 1.1 uch struct hd64461_attach_args *ha = aux;
240 1.1 uch
241 1.1 uch return (ha->ha_module_id == HD64461_MODULE_PCMCIA);
242 1.1 uch }
243 1.1 uch
244 1.1 uch static void
245 1.1 uch hd64461pcmcia_attach(struct device *parent, struct device *self, void *aux)
246 1.1 uch {
247 1.1 uch struct hd64461_attach_args *ha = aux;
248 1.1 uch struct hd64461pcmcia_softc *sc = (struct hd64461pcmcia_softc *)self;
249 1.1 uch
250 1.1 uch sc->sc_module_id = ha->ha_module_id;
251 1.1 uch
252 1.1 uch printf("\n");
253 1.1 uch
254 1.1 uch #ifdef DEBUG
255 1.1 uch if (bootverbose)
256 1.1 uch hd64461pcmcia_info(sc);
257 1.1 uch #endif
258 1.1 uch /* Channel 0/1 common CSC event queue */
259 1.1 uch SIMPLEQ_INIT (&sc->sc_event_head);
260 1.1 uch kthread_create(hd64461pcmcia_create_event_thread, sc);
261 1.1 uch
262 1.1 uch hd64461pcmcia_attach_channel(sc, CHANNEL_0);
263 1.1 uch hd64461pcmcia_attach_channel(sc, CHANNEL_1);
264 1.1 uch }
265 1.1 uch
266 1.1 uch static void
267 1.1 uch hd64461pcmcia_create_event_thread(void *arg)
268 1.1 uch {
269 1.1 uch struct hd64461pcmcia_softc *sc = arg;
270 1.1 uch int error;
271 1.1 uch
272 1.1 uch error = kthread_create1(hd64461pcmcia_event_thread, sc,
273 1.1 uch &sc->sc_event_thread, "%s",
274 1.1 uch sc->sc_dev.dv_xname);
275 1.1 uch KASSERT(error == 0);
276 1.1 uch }
277 1.1 uch
278 1.1 uch static void
279 1.1 uch hd64461pcmcia_event_thread(void *arg)
280 1.1 uch {
281 1.1 uch struct hd64461pcmcia_softc *sc = arg;
282 1.1 uch struct hd64461pcmcia_event *pe;
283 1.1 uch int s;
284 1.1 uch
285 1.1 uch while (!sc->sc_shutdown) {
286 1.1 uch tsleep(sc, PWAIT, "CSC wait", 0);
287 1.1 uch s = splhigh();
288 1.1 uch while ((pe = SIMPLEQ_FIRST(&sc->sc_event_head))) {
289 1.1 uch splx(s);
290 1.1 uch switch (pe->pe_type) {
291 1.1 uch default:
292 1.1 uch printf("%s: unknown event.\n", __FUNCTION__);
293 1.1 uch break;
294 1.1 uch case EVENT_INSERT:
295 1.1 uch DPRINTF("insert event.\n");
296 1.1 uch pcmcia_card_attach(pe->pe_ch->ch_pcmcia);
297 1.1 uch break;
298 1.1 uch case EVENT_REMOVE:
299 1.1 uch DPRINTF("remove event.\n");
300 1.1 uch pcmcia_card_detach(pe->pe_ch->ch_pcmcia,
301 1.1 uch DETACH_FORCE);
302 1.1 uch break;
303 1.1 uch }
304 1.1 uch s = splhigh();
305 1.1 uch SIMPLEQ_REMOVE_HEAD(&sc->sc_event_head, pe, pe_link);
306 1.1 uch pe->__queued = 0;
307 1.1 uch }
308 1.1 uch splx(s);
309 1.1 uch }
310 1.1 uch /* NOTREACHED */
311 1.1 uch }
312 1.1 uch
313 1.1 uch static int
314 1.1 uch hd64461pcmcia_print(void *arg, const char *pnp)
315 1.1 uch {
316 1.1 uch if (pnp)
317 1.1 uch printf("pcmcia at %s", pnp);
318 1.1 uch
319 1.1 uch return (UNCONF);
320 1.1 uch }
321 1.1 uch
322 1.1 uch static int
323 1.1 uch hd64461pcmcia_submatch(struct device *parent, struct cfdata *cf, void *aux)
324 1.1 uch {
325 1.1 uch struct pcmciabus_attach_args *paa = aux;
326 1.1 uch
327 1.1 uch paa->pct = (pcmcia_chipset_tag_t)&hd64461pcmcia_functions;
328 1.1 uch
329 1.1 uch return ((*cf->cf_attach->ca_match)(parent, cf, aux));
330 1.1 uch }
331 1.1 uch
332 1.1 uch static void
333 1.1 uch hd64461pcmcia_attach_channel(struct hd64461pcmcia_softc *sc,
334 1.1 uch enum controller_channel channel)
335 1.1 uch {
336 1.1 uch struct device *parent = (struct device *)sc;
337 1.1 uch struct hd64461pcmcia_channel *ch = &sc->sc_ch[channel];
338 1.1 uch struct pcmciabus_attach_args paa;
339 1.1 uch bus_addr_t membase;
340 1.1 uch int i;
341 1.1 uch
342 1.1 uch ch->ch_parent = sc;
343 1.1 uch ch->ch_channel = channel;
344 1.1 uch
345 1.1 uch /*
346 1.1 uch * Continuous 16-MB Area Mode
347 1.1 uch */
348 1.1 uch /* Attibute/Common memory extent */
349 1.1 uch membase = (channel == CHANNEL_0)
350 1.1 uch ? HD64461_PCC0_MEMBASE : HD64461_PCC1_MEMBASE;
351 1.1 uch ch->ch_memt = bus_space_create("PCMCIA attribute memory",
352 1.1 uch membase, 0x01000000); /* 16MB */
353 1.1 uch bus_space_alloc(ch->ch_memt, 0, 0x01000000, 0x01000000,
354 1.1 uch 0x01000000, 0x01000000, 0, &ch->ch_membase_addr,
355 1.1 uch &ch->ch_memh);
356 1.1 uch
357 1.1 uch /* Common memory space extent */
358 1.1 uch ch->ch_memsize = 0x01000000;
359 1.1 uch for (i = 0; i < MEMWIN_16M_MAX; i++) {
360 1.1 uch ch->ch_cmemt[i] = bus_space_create("PCMCIA common memory",
361 1.1 uch membase + 0x01000000,
362 1.1 uch ch->ch_memsize);
363 1.1 uch }
364 1.1 uch
365 1.1 uch /* I/O port extent and interrupt staff */
366 1.1 uch _chip_socket_disable(ch); /* enable CSC interrupt only */
367 1.1 uch
368 1.1 uch if (channel == CHANNEL_0) {
369 1.1 uch /* real I/O space */
370 1.1 uch ch->ch_iobase = 0;
371 1.1 uch ch->ch_iosize = HD64461_PCC0_IOSIZE;
372 1.1 uch ch->ch_iot = bus_space_create("PCMCIA I/O port",
373 1.1 uch HD64461_PCC0_IOBASE,
374 1.1 uch ch->ch_iosize);
375 1.1 uch
376 1.1 uch
377 1.1 uch hd64461_intr_establish(HD64461_IRQ_PCC0, IST_LEVEL, IPL_TTY,
378 1.1 uch hd64461pcmcia_channel0_intr, ch);
379 1.1 uch } else {
380 1.1 uch /* Compact Flash memory mapped mode (Common memory space) */
381 1.1 uch ch->ch_iobase = 0;
382 1.1 uch ch->ch_iosize = 0x10; /* 16byte (dont' use 0x400-0x7ff) */
383 1.1 uch ch->ch_iot = bus_space_create("PCMCIA memory mapped I/O port",
384 1.1 uch HD64461_PCC1_MEMBASE +
385 1.1 uch 0x01000000, ch->ch_iosize);
386 1.1 uch
387 1.1 uch hd64461_intr_establish(HD64461_IRQ_PCC1, IST_EDGE, IPL_TTY,
388 1.1 uch hd64461pcmcia_channel1_intr, ch);
389 1.1 uch }
390 1.1 uch
391 1.1 uch paa.paa_busname = "pcmcia";
392 1.1 uch paa.pch = (pcmcia_chipset_handle_t)ch;
393 1.1 uch paa.iobase = ch->ch_iobase;
394 1.1 uch paa.iosize = ch->ch_iosize;
395 1.1 uch
396 1.1 uch ch->ch_pcmcia = config_found_sm(parent, &paa, hd64461pcmcia_print,
397 1.1 uch hd64461pcmcia_submatch);
398 1.1 uch
399 1.1 uch if (ch->ch_pcmcia && (detect_card(ch->ch_channel) == EVENT_INSERT)) {
400 1.1 uch ch->ch_attached = 1;
401 1.1 uch pcmcia_card_attach(ch->ch_pcmcia);
402 1.1 uch }
403 1.1 uch }
404 1.1 uch
405 1.1 uch static int
406 1.1 uch hd64461pcmcia_channel0_intr(void *arg)
407 1.1 uch {
408 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)arg;
409 1.1 uch u_int8_t r;
410 1.1 uch int ret = 0;
411 1.1 uch
412 1.1 uch r = hd64461_reg_read_1(HD64461_PCC0CSCR_REG8);
413 1.1 uch /* clear interrtupt (edge source only) */
414 1.1 uch hd64461_reg_write_1(HD64461_PCC0CSCR_REG8, 0);
415 1.1 uch
416 1.1 uch if (r & HD64461_PCC0CSCR_P0IREQ) {
417 1.1 uch if (ch->ch_ih_card_func)
418 1.1 uch ret = (*ch->ch_ih_card_func)(ch->ch_ih_card_arg);
419 1.1 uch else
420 1.1 uch DPRINTF("spurious IREQ interrupt.\n");
421 1.1 uch }
422 1.1 uch
423 1.1 uch if (r & HD64461_PCC0CSCR_P0CDC)
424 1.1 uch queue_event(ch, detect_card(ch->ch_channel));
425 1.1 uch
426 1.1 uch return ret;
427 1.1 uch }
428 1.1 uch
429 1.1 uch static int
430 1.1 uch hd64461pcmcia_channel1_intr(void *arg)
431 1.1 uch {
432 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)arg;
433 1.1 uch u_int8_t r;
434 1.1 uch int ret = 0;
435 1.1 uch
436 1.1 uch r = hd64461_reg_read_1(HD64461_PCC1CSCR_REG8);
437 1.1 uch /* clear interrtupt */
438 1.1 uch hd64461_reg_write_1(HD64461_PCC1CSCR_REG8, 0);
439 1.1 uch
440 1.1 uch if (r & HD64461_PCC1CSCR_P1RC) {
441 1.1 uch if (ch->ch_ih_card_func)
442 1.1 uch ret = (*ch->ch_ih_card_func)(ch->ch_ih_card_arg);
443 1.1 uch else
444 1.1 uch DPRINTF("spurious READY interrupt.\n");
445 1.1 uch }
446 1.1 uch
447 1.1 uch if (r & HD64461_PCC1CSCR_P1CDC)
448 1.1 uch queue_event(ch, detect_card(ch->ch_channel));
449 1.1 uch
450 1.1 uch return ret;
451 1.1 uch }
452 1.1 uch
453 1.1 uch static void
454 1.1 uch queue_event(struct hd64461pcmcia_channel *ch,
455 1.1 uch enum hd64461pcmcia_event_type type)
456 1.1 uch {
457 1.1 uch struct hd64461pcmcia_event *pe, *pool;
458 1.1 uch struct hd64461pcmcia_softc *sc = ch->ch_parent;
459 1.1 uch int i;
460 1.1 uch int s = splhigh();
461 1.1 uch
462 1.1 uch if (type == EVENT_NONE)
463 1.1 uch goto out;
464 1.1 uch
465 1.1 uch pe = 0;
466 1.1 uch pool = sc->sc_event_pool;
467 1.1 uch for (i = 0; i < EVENT_QUEUE_MAX; i++) {
468 1.1 uch if (!pool[i].__queued) {
469 1.1 uch pe = &pool[i];
470 1.1 uch break;
471 1.1 uch }
472 1.1 uch }
473 1.1 uch
474 1.1 uch if (pe == 0) {
475 1.1 uch printf("%s: event FIFO overflow (max %d).\n", __FUNCTION__,
476 1.1 uch EVENT_QUEUE_MAX);
477 1.1 uch goto out;
478 1.1 uch }
479 1.1 uch
480 1.1 uch if ((ch->ch_attached && (type == EVENT_INSERT)) ||
481 1.1 uch (!ch->ch_attached && (type == EVENT_REMOVE))) {
482 1.1 uch DPRINTF("spurious CSC interrupt.\n");
483 1.1 uch goto out;
484 1.1 uch }
485 1.1 uch
486 1.1 uch ch->ch_attached = (type == EVENT_INSERT);
487 1.1 uch pe->__queued = 1;
488 1.1 uch pe->pe_type = type;
489 1.1 uch pe->pe_ch = ch;
490 1.1 uch SIMPLEQ_INSERT_TAIL(&sc->sc_event_head, pe, pe_link);
491 1.1 uch wakeup(sc);
492 1.1 uch out:
493 1.1 uch splx(s);
494 1.1 uch }
495 1.1 uch
496 1.1 uch /*
497 1.1 uch * interface for pcmcia driver.
498 1.1 uch */
499 1.1 uch static void *
500 1.1 uch _chip_intr_establish(pcmcia_chipset_handle_t pch, struct pcmcia_function *pf,
501 1.1 uch int ipl, int (*ih_func)(void *), void *ih_arg)
502 1.1 uch {
503 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
504 1.1 uch int channel = ch->ch_channel;
505 1.1 uch bus_addr_t cscier = HD64461_PCCCSCIER(channel);
506 1.1 uch int s = splhigh();
507 1.1 uch u_int8_t r;
508 1.1 uch
509 1.1 uch ch->ch_ih_card_func = ih_func;
510 1.1 uch ch->ch_ih_card_arg = ih_arg;
511 1.1 uch
512 1.1 uch /* enable card interrupt */
513 1.1 uch r = hd64461_reg_read_1(cscier);
514 1.1 uch if (channel == CHANNEL_0) {
515 1.1 uch /* set level mode */
516 1.1 uch r &= ~HD64461_PCC0CSCIER_P0IREQE_MASK;
517 1.1 uch r |= HD64461_PCC0CSCIER_P0IREQE_LEVEL;
518 1.1 uch } else {
519 1.1 uch /* READY-pin LOW to HIGH changes generates interrupt */
520 1.1 uch r |= HD64461_PCC1CSCIER_P1RE;
521 1.1 uch }
522 1.1 uch hd64461_reg_write_1(cscier, r);
523 1.1 uch
524 1.1 uch splx(s);
525 1.1 uch
526 1.1 uch return (void *)ih_func;
527 1.1 uch }
528 1.1 uch
529 1.1 uch static void
530 1.1 uch _chip_intr_disestablish(pcmcia_chipset_handle_t pch, void *ih)
531 1.1 uch {
532 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
533 1.1 uch int channel = ch->ch_channel;
534 1.1 uch bus_addr_t cscier = HD64461_PCCCSCIER(channel);
535 1.1 uch int s = splhigh();
536 1.1 uch u_int8_t r;
537 1.1 uch
538 1.1 uch /* disable card interrupt */
539 1.1 uch r = hd64461_reg_read_1(cscier);
540 1.1 uch if (channel == CHANNEL_0) {
541 1.1 uch r &= ~HD64461_PCC0CSCIER_P0IREQE_MASK;
542 1.1 uch r |= HD64461_PCC0CSCIER_P0IREQE_NONE;
543 1.1 uch } else {
544 1.1 uch r &= ~HD64461_PCC1CSCIER_P1RE;
545 1.1 uch }
546 1.1 uch hd64461_reg_write_1(cscier, r);
547 1.1 uch
548 1.1 uch ch->ch_ih_card_func = 0;
549 1.1 uch
550 1.1 uch splx(s);
551 1.1 uch }
552 1.1 uch
553 1.1 uch static int
554 1.1 uch _chip_mem_alloc(pcmcia_chipset_handle_t pch, bus_size_t size,
555 1.1 uch struct pcmcia_mem_handle *pcmhp)
556 1.1 uch {
557 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
558 1.1 uch
559 1.1 uch pcmhp->memt = ch->ch_memt;
560 1.1 uch pcmhp->addr = ch->ch_membase_addr;
561 1.1 uch pcmhp->memh = ch->ch_memh;
562 1.1 uch pcmhp->size = size;
563 1.1 uch pcmhp->realsize = size;
564 1.1 uch
565 1.1 uch return (0);
566 1.1 uch }
567 1.1 uch
568 1.1 uch static void
569 1.1 uch _chip_mem_free(pcmcia_chipset_handle_t pch, struct pcmcia_mem_handle *pcmhp)
570 1.1 uch {
571 1.1 uch /* nothing to do */
572 1.1 uch }
573 1.1 uch
574 1.1 uch static int
575 1.1 uch _chip_mem_map(pcmcia_chipset_handle_t pch, int kind, bus_addr_t card_addr,
576 1.1 uch bus_size_t size, struct pcmcia_mem_handle *pcmhp,
577 1.1 uch bus_addr_t *offsetp, int *windowp)
578 1.1 uch {
579 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
580 1.1 uch struct hd64461pcmcia_window_cookie *cookie;
581 1.1 uch
582 1.1 uch cookie = malloc(sizeof(struct hd64461pcmcia_window_cookie),
583 1.1 uch M_DEVBUF, M_NOWAIT);
584 1.1 uch KASSERT(cookie);
585 1.1 uch memset(cookie, 0, sizeof(struct hd64461pcmcia_window_cookie));
586 1.1 uch
587 1.1 uch if (kind == PCMCIA_MEM_ATTR) {
588 1.1 uch if (bus_space_subregion(ch->ch_memt, ch->ch_memh, card_addr,
589 1.1 uch size, &cookie->wc_handle) != 0)
590 1.1 uch goto bad;
591 1.1 uch
592 1.1 uch *offsetp = card_addr;
593 1.1 uch cookie->wc_window = -1;
594 1.1 uch } else {
595 1.1 uch int window = card_addr / ch->ch_memsize;
596 1.1 uch KASSERT(window < MEMWIN_16M_MAX);
597 1.1 uch
598 1.1 uch *offsetp = card_addr - window * ch->ch_memsize;
599 1.1 uch
600 1.1 uch if (bus_space_map(ch->ch_cmemt[window], *offsetp, size, 0,
601 1.1 uch &cookie->wc_handle) != 0)
602 1.1 uch goto bad;
603 1.1 uch
604 1.1 uch // XXX bogus. bus_space_tag should be vtbl...
605 1.1 uch memory_window_16(ch->ch_channel, window);
606 1.1 uch cookie->wc_window = window;
607 1.1 uch }
608 1.1 uch cookie->wc_size = size;
609 1.1 uch *windowp = (int)cookie;
610 1.1 uch
611 1.1 uch DPRINTF("%#lx-> %#lx+%#lx\n", card_addr, *offsetp, size);
612 1.1 uch
613 1.1 uch return (0);
614 1.1 uch bad:
615 1.1 uch DPRINTF("%#lx-%#lx map failed.\n", card_addr, size);
616 1.1 uch free(cookie, M_DEVBUF);
617 1.1 uch
618 1.1 uch return (1);
619 1.1 uch }
620 1.1 uch
621 1.1 uch static void
622 1.1 uch _chip_mem_unmap(pcmcia_chipset_handle_t pch, int window)
623 1.1 uch {
624 1.1 uch struct hd64461pcmcia_window_cookie *cookie = (void *)window;
625 1.1 uch
626 1.1 uch if (cookie->wc_window != -1)
627 1.1 uch bus_space_unmap(cookie->wc_tag, cookie->wc_handle,
628 1.1 uch cookie->wc_size);
629 1.1 uch free(cookie, M_DEVBUF);
630 1.1 uch }
631 1.1 uch
632 1.1 uch static int
633 1.1 uch _chip_io_alloc(pcmcia_chipset_handle_t pch, bus_addr_t start, bus_size_t size,
634 1.1 uch bus_size_t align, struct pcmcia_io_handle *pcihp)
635 1.1 uch {
636 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
637 1.1 uch
638 1.1 uch if (start) {
639 1.1 uch if (bus_space_map(ch->ch_iot, start, size, 0, &pcihp->ioh)) {
640 1.1 uch DPRINTF("couldn't map %#lx+%#lx\n", start, size);
641 1.1 uch return (1);
642 1.1 uch }
643 1.1 uch DPRINTF("map %#lx+%#lx\n", start, size);
644 1.1 uch } else {
645 1.1 uch if (bus_space_alloc(ch->ch_iot, ch->ch_iobase,
646 1.1 uch ch->ch_iobase + ch->ch_iosize,
647 1.1 uch size, align, 0, 0, &pcihp->addr,
648 1.1 uch &pcihp->ioh)) {
649 1.1 uch DPRINTF("couldn't allocate %#lx\n", size);
650 1.1 uch return (1);
651 1.1 uch }
652 1.1 uch pcihp->flags = PCMCIA_IO_ALLOCATED;
653 1.1 uch DPRINTF("%#lx from %#lx\n", size, pcihp->addr);
654 1.1 uch }
655 1.1 uch
656 1.1 uch pcihp->iot = ch->ch_iot;
657 1.1 uch pcihp->size = size;
658 1.1 uch
659 1.1 uch return (0);
660 1.1 uch }
661 1.1 uch
662 1.1 uch static int
663 1.1 uch _chip_io_map(pcmcia_chipset_handle_t pch, int width, bus_addr_t offset,
664 1.1 uch bus_size_t size, struct pcmcia_io_handle *pcihp, int *windowp)
665 1.1 uch {
666 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
667 1.1 uch #ifdef HD64461PCMCIA_DEBUG
668 1.1 uch static char *width_names[] = { "auto", "io8", "io16" };
669 1.1 uch #endif
670 1.1 uch u_int16_t r16;
671 1.1 uch
672 1.1 uch /* Set bus width */
673 1.1 uch r16 = SHREG_BCR2;
674 1.1 uch if (ch->ch_channel == CHANNEL_0) {
675 1.1 uch r16 &= ~((1 << 13)|(1 << 12));
676 1.1 uch r16 |= 1 << (width == PCMCIA_WIDTH_IO8 ? 12 : 13);
677 1.1 uch } else {
678 1.1 uch r16 &= ~((1 << 11)|(1 << 10));
679 1.1 uch r16 |= 1 << (width == PCMCIA_WIDTH_IO8 ? 10 : 11);
680 1.1 uch }
681 1.1 uch SHREG_BCR2 = r16;
682 1.1 uch
683 1.1 uch DPRINTF("%#lx:%#lx+%#lx %s\n", pcihp->ioh, offset, size,
684 1.1 uch width_names[width]);
685 1.1 uch
686 1.1 uch return (0);
687 1.1 uch }
688 1.1 uch
689 1.1 uch static void
690 1.1 uch _chip_io_free(pcmcia_chipset_handle_t pch, struct pcmcia_io_handle *pcihp)
691 1.1 uch {
692 1.1 uch if (pcihp->flags & PCMCIA_IO_ALLOCATED)
693 1.1 uch bus_space_free(pcihp->iot, pcihp->ioh, pcihp->size);
694 1.1 uch else
695 1.1 uch bus_space_unmap(pcihp->iot, pcihp->ioh, pcihp->size);
696 1.1 uch
697 1.1 uch DPRINTF("%#lx+%#lx\n", pcihp->ioh, pcihp->size);
698 1.1 uch }
699 1.1 uch
700 1.1 uch static void
701 1.1 uch _chip_io_unmap(pcmcia_chipset_handle_t pch, int window)
702 1.1 uch {
703 1.1 uch /* nothing to do */
704 1.1 uch }
705 1.1 uch
706 1.1 uch static void
707 1.1 uch _chip_socket_enable(pcmcia_chipset_handle_t pch)
708 1.1 uch {
709 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
710 1.1 uch int channel = ch->ch_channel;
711 1.1 uch bus_addr_t isr, gcr;
712 1.1 uch u_int8_t r;
713 1.1 uch int cardtype;
714 1.1 uch int i;
715 1.1 uch
716 1.1 uch DPRINTF("enable channel %d\n", channel);
717 1.1 uch isr = HD64461_PCCISR(channel);
718 1.1 uch gcr = HD64461_PCCGCR(channel);
719 1.1 uch
720 1.1 uch power_off(channel);
721 1.1 uch power_on(channel);
722 1.1 uch
723 1.1 uch /* assert reset */
724 1.1 uch r = hd64461_reg_read_1(gcr);
725 1.1 uch r |= HD64461_PCCGCR_PCCR;
726 1.1 uch hd64461_reg_write_1(gcr, r);
727 1.1 uch
728 1.1 uch /*
729 1.1 uch * hold RESET at least 10us.
730 1.1 uch */
731 1.1 uch __delay(20);
732 1.1 uch
733 1.1 uch /* clear the reset flag */
734 1.1 uch r &= ~HD64461_PCCGCR_PCCR;
735 1.1 uch hd64461_reg_write_1(gcr, r);
736 1.1 uch __delay(20000);
737 1.1 uch
738 1.1 uch /* wait for the chip to finish initializing */
739 1.1 uch for (i = 0; i < 10000; i++) {
740 1.1 uch if ((hd64461_reg_read_1(isr) & HD64461_PCCISR_READY))
741 1.1 uch goto reset_ok;
742 1.1 uch __delay(500);
743 1.1 uch
744 1.1 uch if ((i > 5000) && (i % 100 == 99))
745 1.1 uch printf(".");
746 1.1 uch }
747 1.1 uch printf("reset failed.\n");
748 1.1 uch power_off(channel);
749 1.1 uch return;
750 1.1 uch reset_ok:
751 1.1 uch
752 1.1 uch /* set Continuous 16-MB Area Mode */
753 1.1 uch ch->ch_memory_window_mode = MEMWIN_16M_MODE;
754 1.1 uch memory_window_mode(channel, ch->ch_memory_window_mode);
755 1.1 uch
756 1.1 uch /*
757 1.1 uch * set Common memory area.
758 1.1 uch */
759 1.1 uch memory_window_16(channel, MEMWIN_16M_COMMON_0);
760 1.1 uch
761 1.1 uch /* set the card type */
762 1.1 uch if (channel == CHANNEL_0) {
763 1.1 uch cardtype = pcmcia_card_gettype(ch->ch_pcmcia);
764 1.1 uch r = hd64461_reg_read_1(gcr);
765 1.1 uch if (cardtype == PCMCIA_IFTYPE_IO)
766 1.1 uch r |= HD64461_PCC0GCR_P0PCCT;
767 1.1 uch else
768 1.1 uch r &= ~HD64461_PCC0GCR_P0PCCT;
769 1.1 uch hd64461_reg_write_1(gcr, r);
770 1.1 uch }
771 1.1 uch
772 1.1 uch
773 1.1 uch DPRINTF("OK.\n");
774 1.1 uch }
775 1.1 uch
776 1.1 uch static void
777 1.1 uch _chip_socket_disable(pcmcia_chipset_handle_t pch)
778 1.1 uch {
779 1.1 uch struct hd64461pcmcia_channel *ch = (struct hd64461pcmcia_channel *)pch;
780 1.1 uch int channel = ch->ch_channel;
781 1.1 uch
782 1.1 uch /* dont' disable CSC interrupt */
783 1.1 uch hd64461_reg_write_1(HD64461_PCCCSCIER(channel), HD64461_PCCCSCIER_CDE);
784 1.1 uch hd64461_reg_write_1(HD64461_PCCCSCR(channel), 0);
785 1.1 uch
786 1.1 uch /* power down the socket */
787 1.1 uch power_off(channel);
788 1.1 uch }
789 1.1 uch
790 1.1 uch /*
791 1.1 uch * Card detect
792 1.1 uch */
793 1.1 uch static void
794 1.1 uch power_off(enum controller_channel channel)
795 1.1 uch {
796 1.1 uch u_int8_t r;
797 1.1 uch u_int16_t r16;
798 1.1 uch bus_addr_t scr, gcr;
799 1.1 uch
800 1.1 uch gcr = HD64461_PCCGCR(channel);
801 1.1 uch scr = HD64461_PCCSCR(channel);
802 1.1 uch
803 1.1 uch /* DRV (external buffer) high level */
804 1.1 uch r = hd64461_reg_read_1(gcr);
805 1.1 uch r &= ~HD64461_PCCGCR_DRVE;
806 1.1 uch hd64461_reg_write_1(gcr, r);
807 1.1 uch
808 1.1 uch /* stop power */
809 1.1 uch r = hd64461_reg_read_1(scr);
810 1.1 uch r |= HD64461_PCCSCR_VCC1; /* VCC1 high */
811 1.1 uch hd64461_reg_write_1(scr, r);
812 1.1 uch r = hd64461_reg_read_1(gcr);
813 1.1 uch r |= HD64461_PCCGCR_VCC0; /* VCC0 high */
814 1.1 uch hd64461_reg_write_1(gcr, r);
815 1.1 uch /*
816 1.1 uch * wait 300ms until power fails (Tpf). Then, wait 100ms since
817 1.1 uch * we are changing Vcc (Toff).
818 1.1 uch */
819 1.1 uch __delay(300 + 100);
820 1.1 uch
821 1.1 uch /* stop clock */
822 1.1 uch r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
823 1.1 uch r16 |= (channel == CHANNEL_0 ? HD64461_SYSSTBCR_SPC0ST :
824 1.1 uch HD64461_SYSSTBCR_SPC1ST);
825 1.1 uch hd64461_reg_write_2(HD64461_SYSSTBCR_REG16, r16);
826 1.1 uch
827 1.1 uch if (channel == CHANNEL_0) {
828 1.1 uch /* GPIO Port A XXX Jonanada690 specific? */
829 1.1 uch r16 = hd64461_reg_read_2(HD64461_GPADR_REG16);
830 1.1 uch r16 |= 0xf;
831 1.1 uch hd64461_reg_write_2(HD64461_GPADR_REG16, r16);
832 1.1 uch }
833 1.1 uch }
834 1.1 uch
835 1.1 uch static void
836 1.1 uch power_on(enum controller_channel channel)
837 1.1 uch {
838 1.1 uch u_int8_t r;
839 1.1 uch u_int16_t r16;
840 1.1 uch bus_addr_t scr, gcr, isr;
841 1.1 uch
842 1.1 uch isr = HD64461_PCCISR(channel);
843 1.1 uch gcr = HD64461_PCCGCR(channel);
844 1.1 uch scr = HD64461_PCCSCR(channel);
845 1.1 uch
846 1.1 uch if (channel == CHANNEL_0) {
847 1.1 uch /* GPIO Port A XXX Jonanada690 specific? */
848 1.1 uch r16 = hd64461_reg_read_2(HD64461_GPADR_REG16);
849 1.1 uch r16 &= ~0xf;
850 1.1 uch r16 |= 0x5;
851 1.1 uch hd64461_reg_write_2(HD64461_GPADR_REG16, r16);
852 1.1 uch }
853 1.1 uch
854 1.1 uch /* supply clock */
855 1.1 uch r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
856 1.1 uch r16 &= ~(channel == CHANNEL_0 ? HD64461_SYSSTBCR_SPC0ST :
857 1.1 uch HD64461_SYSSTBCR_SPC1ST);
858 1.1 uch hd64461_reg_write_2(HD64461_SYSSTBCR_REG16, r16);
859 1.1 uch __delay(2000);
860 1.1 uch
861 1.1 uch /* detect voltage and supply VCC */
862 1.1 uch r = hd64461_reg_read_1(isr);
863 1.1 uch switch (r & (HD64461_PCCISR_VS1 | HD64461_PCCISR_VS2)) {
864 1.1 uch case (HD64461_PCCISR_VS1 | HD64461_PCCISR_VS2):
865 1.1 uch DPRINTF("5V card\n");
866 1.1 uch r = hd64461_reg_read_1(gcr);
867 1.1 uch r &= ~HD64461_PCCGCR_VCC0;
868 1.1 uch hd64461_reg_write_1(gcr, r);
869 1.1 uch r = hd64461_reg_read_1(scr);
870 1.1 uch r &= ~HD64461_PCCSCR_VCC1;
871 1.1 uch hd64461_reg_write_1(scr, r);
872 1.1 uch break;
873 1.1 uch case HD64461_PCCISR_VS2:
874 1.1 uch DPRINTF("3.3V card\n");
875 1.1 uch if (channel == CHANNEL_1) {
876 1.1 uch r = hd64461_reg_read_1(gcr);
877 1.1 uch r &= ~HD64461_PCCGCR_VCC0;
878 1.1 uch hd64461_reg_write_1(gcr, r);
879 1.1 uch }
880 1.1 uch r = hd64461_reg_read_1(scr);
881 1.1 uch r &= ~HD64461_PCCSCR_VCC1;
882 1.1 uch hd64461_reg_write_1(scr, r);
883 1.1 uch break;
884 1.1 uch default:
885 1.1 uch printf("\nunknown Voltage. don't attach.\n");
886 1.1 uch return;
887 1.1 uch }
888 1.1 uch /*
889 1.1 uch * wait 100ms until power raise (Tpr) and 20ms to become
890 1.1 uch * stable (Tsu(Vcc)).
891 1.1 uch *
892 1.1 uch * some machines require some more time to be settled
893 1.1 uch * (300ms is added here).
894 1.1 uch */
895 1.1 uch __delay(100 + 20 + 300);
896 1.1 uch
897 1.1 uch /* DRV (external buffer) low level */
898 1.1 uch r = hd64461_reg_read_1(gcr);
899 1.1 uch r |= HD64461_PCCGCR_DRVE;
900 1.1 uch hd64461_reg_write_1(gcr, r);
901 1.1 uch
902 1.1 uch /* clear interrupt */
903 1.1 uch hd64461_reg_write_1(channel == CHANNEL_0 ? HD64461_PCC0CSCR_REG8 :
904 1.1 uch HD64461_PCC1CSCR_REG8, 0);
905 1.1 uch }
906 1.1 uch
907 1.1 uch static enum hd64461pcmcia_event_type
908 1.1 uch detect_card(enum controller_channel channel)
909 1.1 uch {
910 1.1 uch u_int8_t r;
911 1.1 uch
912 1.1 uch r = hd64461_reg_read_1(HD64461_PCCISR(channel)) &
913 1.1 uch (HD64461_PCCISR_CD2 | HD64461_PCCISR_CD1);
914 1.1 uch
915 1.1 uch if (r == (HD64461_PCCISR_CD2 | HD64461_PCCISR_CD1)) {
916 1.1 uch DPRINTF("remove\n");
917 1.1 uch return EVENT_REMOVE;
918 1.1 uch }
919 1.1 uch if (r == 0) {
920 1.1 uch DPRINTF("insert\n");
921 1.1 uch return EVENT_INSERT;
922 1.1 uch }
923 1.1 uch DPRINTF("transition\n");
924 1.1 uch
925 1.1 uch return EVENT_NONE;
926 1.1 uch }
927 1.1 uch
928 1.1 uch /*
929 1.1 uch * Memory window access ops.
930 1.1 uch */
931 1.1 uch static void
932 1.1 uch memory_window_mode(enum controller_channel channel,
933 1.1 uch enum memory_window_mode mode)
934 1.1 uch {
935 1.1 uch bus_addr_t a = HD64461_PCCGCR(channel);
936 1.1 uch u_int8_t r = hd64461_reg_read_1(a);
937 1.1 uch
938 1.1 uch r &= ~HD64461_PCCGCR_MMOD;
939 1.1 uch r |= (mode == MEMWIN_16M_MODE) ? HD64461_PCCGCR_MMOD_16M :
940 1.1 uch HD64461_PCCGCR_MMOD_32M;
941 1.1 uch hd64461_reg_write_1(a, r);
942 1.1 uch }
943 1.1 uch
944 1.1 uch static void
945 1.1 uch memory_window_16(enum controller_channel channel, enum memory_window_16 window)
946 1.1 uch {
947 1.1 uch bus_addr_t a = HD64461_PCCGCR(channel);
948 1.1 uch u_int8_t r;
949 1.1 uch
950 1.1 uch r = hd64461_reg_read_1(a);
951 1.1 uch r &= ~(HD64461_PCCGCR_PA25 | HD64461_PCCGCR_PA24);
952 1.1 uch
953 1.1 uch switch (window) {
954 1.1 uch case MEMWIN_16M_COMMON_0:
955 1.1 uch break;
956 1.1 uch case MEMWIN_16M_COMMON_1:
957 1.1 uch r |= HD64461_PCCGCR_PA24;
958 1.1 uch break;
959 1.1 uch case MEMWIN_16M_COMMON_2:
960 1.1 uch r |= HD64461_PCCGCR_PA25;
961 1.1 uch break;
962 1.1 uch case MEMWIN_16M_COMMON_3:
963 1.1 uch r |= (HD64461_PCCGCR_PA25 | HD64461_PCCGCR_PA24);
964 1.1 uch break;
965 1.1 uch }
966 1.1 uch
967 1.1 uch hd64461_reg_write_1(a, r);
968 1.1 uch }
969 1.1 uch
970 1.1 uch static void
971 1.1 uch memory_window_32(enum controller_channel channel, enum memory_window_32 window)
972 1.1 uch {
973 1.1 uch bus_addr_t a = HD64461_PCCGCR(channel);
974 1.1 uch u_int8_t r;
975 1.1 uch
976 1.1 uch r = hd64461_reg_read_1(a);
977 1.1 uch r &= ~(HD64461_PCCGCR_PA25 | HD64461_PCCGCR_PREG);
978 1.1 uch
979 1.1 uch switch (window) {
980 1.1 uch case MEMWIN_32M_ATTR:
981 1.1 uch break;
982 1.1 uch case MEMWIN_32M_COMMON_0:
983 1.1 uch r |= HD64461_PCCGCR_PREG;
984 1.1 uch break;
985 1.1 uch case MEMWIN_32M_COMMON_1:
986 1.1 uch r |= (HD64461_PCCGCR_PA25 | HD64461_PCCGCR_PREG);
987 1.1 uch break;
988 1.1 uch }
989 1.1 uch
990 1.1 uch hd64461_reg_write_1(a, r);
991 1.1 uch }
992 1.1 uch
993 1.1 uch #ifdef DEBUG
994 1.1 uch static void
995 1.1 uch hd64461pcmcia_info(struct hd64461pcmcia_softc *sc)
996 1.1 uch {
997 1.1 uch const char name[] = __FUNCTION__;
998 1.1 uch u_int8_t r8;
999 1.1 uch
1000 1.1 uch dbg_banner_start(name, sizeof name);
1001 1.1 uch /*
1002 1.1 uch * PCC0
1003 1.1 uch */
1004 1.1 uch printf("[PCC0 memory and I/O card (SH3 Area 6)]\n");
1005 1.1 uch printf("PCC0 Interface Status Register\n");
1006 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC0ISR_REG8);
1007 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC0ISR_##m, #m)
1008 1.1 uch DBG_BIT_PRINT(r8, P0READY);
1009 1.1 uch DBG_BIT_PRINT(r8, P0MWP);
1010 1.1 uch DBG_BIT_PRINT(r8, P0VS2);
1011 1.1 uch DBG_BIT_PRINT(r8, P0VS1);
1012 1.1 uch DBG_BIT_PRINT(r8, P0CD2);
1013 1.1 uch DBG_BIT_PRINT(r8, P0CD1);
1014 1.1 uch DBG_BIT_PRINT(r8, P0BVD2);
1015 1.1 uch DBG_BIT_PRINT(r8, P0BVD1);
1016 1.1 uch #undef DBG_BIT_PRINT
1017 1.1 uch printf("\n");
1018 1.1 uch
1019 1.1 uch printf("PCC0 General Control Register\n");
1020 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC0GCR_REG8);
1021 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC0GCR_##m, #m)
1022 1.1 uch DBG_BIT_PRINT(r8, P0DRVE);
1023 1.1 uch DBG_BIT_PRINT(r8, P0PCCR);
1024 1.1 uch DBG_BIT_PRINT(r8, P0PCCT);
1025 1.1 uch DBG_BIT_PRINT(r8, P0VCC0);
1026 1.1 uch DBG_BIT_PRINT(r8, P0MMOD);
1027 1.1 uch DBG_BIT_PRINT(r8, P0PA25);
1028 1.1 uch DBG_BIT_PRINT(r8, P0PA24);
1029 1.1 uch DBG_BIT_PRINT(r8, P0REG);
1030 1.1 uch #undef DBG_BIT_PRINT
1031 1.1 uch printf("\n");
1032 1.1 uch
1033 1.1 uch printf("PCC0 Card Status Change Register\n");
1034 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC0CSCR_REG8);
1035 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC0CSCR_##m, #m)
1036 1.1 uch DBG_BIT_PRINT(r8, P0SCDI);
1037 1.1 uch DBG_BIT_PRINT(r8, P0IREQ);
1038 1.1 uch DBG_BIT_PRINT(r8, P0SC);
1039 1.1 uch DBG_BIT_PRINT(r8, P0CDC);
1040 1.1 uch DBG_BIT_PRINT(r8, P0RC);
1041 1.1 uch DBG_BIT_PRINT(r8, P0BW);
1042 1.1 uch DBG_BIT_PRINT(r8, P0BD);
1043 1.1 uch #undef DBG_BIT_PRINT
1044 1.1 uch printf("\n");
1045 1.1 uch
1046 1.1 uch printf("PCC0 Card Status Change Interrupt Enable Register\n");
1047 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC0CSCIER_REG8);
1048 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC0CSCIER_##m, #m)
1049 1.1 uch DBG_BIT_PRINT(r8, P0CRE);
1050 1.1 uch DBG_BIT_PRINT(r8, P0SCE);
1051 1.1 uch DBG_BIT_PRINT(r8, P0CDE);
1052 1.1 uch DBG_BIT_PRINT(r8, P0RE);
1053 1.1 uch DBG_BIT_PRINT(r8, P0BWE);
1054 1.1 uch DBG_BIT_PRINT(r8, P0BDE);
1055 1.1 uch #undef DBG_BIT_PRINT
1056 1.1 uch printf("\ninterrupt type: ");
1057 1.1 uch switch (r8 & HD64461_PCC0CSCIER_P0IREQE_MASK) {
1058 1.1 uch case HD64461_PCC0CSCIER_P0IREQE_NONE:
1059 1.1 uch printf("none\n");
1060 1.1 uch break;
1061 1.1 uch case HD64461_PCC0CSCIER_P0IREQE_LEVEL:
1062 1.1 uch printf("level\n");
1063 1.1 uch break;
1064 1.1 uch case HD64461_PCC0CSCIER_P0IREQE_FEDGE:
1065 1.1 uch printf("falling edge\n");
1066 1.1 uch break;
1067 1.1 uch case HD64461_PCC0CSCIER_P0IREQE_REDGE:
1068 1.1 uch printf("rising edge\n");
1069 1.1 uch break;
1070 1.1 uch }
1071 1.1 uch
1072 1.1 uch printf("PCC0 Software Control Register\n");
1073 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC0SCR_REG8);
1074 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC0SCR_##m, #m)
1075 1.1 uch DBG_BIT_PRINT(r8, P0VCC1);
1076 1.1 uch DBG_BIT_PRINT(r8, P0SWP);
1077 1.1 uch #undef DBG_BIT_PRINT
1078 1.1 uch printf("\n");
1079 1.1 uch
1080 1.1 uch /*
1081 1.1 uch * PCC1
1082 1.1 uch */
1083 1.1 uch printf("[PCC1 memory card only (SH3 Area 5)]\n");
1084 1.1 uch printf("PCC1 Interface Status Register\n");
1085 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC1ISR_REG8);
1086 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC1ISR_##m, #m)
1087 1.1 uch DBG_BIT_PRINT(r8, P1READY);
1088 1.1 uch DBG_BIT_PRINT(r8, P1MWP);
1089 1.1 uch DBG_BIT_PRINT(r8, P1VS2);
1090 1.1 uch DBG_BIT_PRINT(r8, P1VS1);
1091 1.1 uch DBG_BIT_PRINT(r8, P1CD2);
1092 1.1 uch DBG_BIT_PRINT(r8, P1CD1);
1093 1.1 uch DBG_BIT_PRINT(r8, P1BVD2);
1094 1.1 uch DBG_BIT_PRINT(r8, P1BVD1);
1095 1.1 uch #undef DBG_BIT_PRINT
1096 1.1 uch printf("\n");
1097 1.1 uch
1098 1.1 uch printf("PCC1 General Contorol Register\n");
1099 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC1GCR_REG8);
1100 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC1GCR_##m, #m)
1101 1.1 uch DBG_BIT_PRINT(r8, P1DRVE);
1102 1.1 uch DBG_BIT_PRINT(r8, P1PCCR);
1103 1.1 uch DBG_BIT_PRINT(r8, P1VCC0);
1104 1.1 uch DBG_BIT_PRINT(r8, P1MMOD);
1105 1.1 uch DBG_BIT_PRINT(r8, P1PA25);
1106 1.1 uch DBG_BIT_PRINT(r8, P1PA24);
1107 1.1 uch DBG_BIT_PRINT(r8, P1REG);
1108 1.1 uch #undef DBG_BIT_PRINT
1109 1.1 uch printf("\n");
1110 1.1 uch
1111 1.1 uch printf("PCC1 Card Status Change Register\n");
1112 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC1CSCR_REG8);
1113 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC1CSCR_##m, #m)
1114 1.1 uch DBG_BIT_PRINT(r8, P1SCDI);
1115 1.1 uch DBG_BIT_PRINT(r8, P1CDC);
1116 1.1 uch DBG_BIT_PRINT(r8, P1RC);
1117 1.1 uch DBG_BIT_PRINT(r8, P1BW);
1118 1.1 uch DBG_BIT_PRINT(r8, P1BD);
1119 1.1 uch #undef DBG_BIT_PRINT
1120 1.1 uch printf("\n");
1121 1.1 uch
1122 1.1 uch printf("PCC1 Card Status Change Interrupt Enable Register\n");
1123 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC1CSCIER_REG8);
1124 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC1CSCIER_##m, #m)
1125 1.1 uch DBG_BIT_PRINT(r8, P1CRE);
1126 1.1 uch DBG_BIT_PRINT(r8, P1CDE);
1127 1.1 uch DBG_BIT_PRINT(r8, P1RE);
1128 1.1 uch DBG_BIT_PRINT(r8, P1BWE);
1129 1.1 uch DBG_BIT_PRINT(r8, P1BDE);
1130 1.1 uch #undef DBG_BIT_PRINT
1131 1.1 uch printf("\n");
1132 1.1 uch
1133 1.1 uch printf("PCC1 Software Control Register\n");
1134 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCC1SCR_REG8);
1135 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCC1SCR_##m, #m)
1136 1.1 uch DBG_BIT_PRINT(r8, P1VCC1);
1137 1.1 uch DBG_BIT_PRINT(r8, P1SWP);
1138 1.1 uch #undef DBG_BIT_PRINT
1139 1.1 uch printf("\n");
1140 1.1 uch
1141 1.1 uch /*
1142 1.1 uch * General Control
1143 1.1 uch */
1144 1.1 uch printf("[General Control]\n");
1145 1.1 uch printf("PCC0 Output pins Control Register\n");
1146 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCCP0OCR_REG8);
1147 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCCP0OCR_##m, #m)
1148 1.1 uch DBG_BIT_PRINT(r8, P0DEPLUP);
1149 1.1 uch DBG_BIT_PRINT(r8, P0AEPLUP);
1150 1.1 uch #undef DBG_BIT_PRINT
1151 1.1 uch printf("\n");
1152 1.1 uch
1153 1.1 uch printf("PCC1 Output pins Control Register\n");
1154 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCCP1OCR_REG8);
1155 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCCP1OCR_##m, #m)
1156 1.1 uch DBG_BIT_PRINT(r8, P1RST8MA);
1157 1.1 uch DBG_BIT_PRINT(r8, P1RST4MA);
1158 1.1 uch DBG_BIT_PRINT(r8, P1RAS8MA);
1159 1.1 uch DBG_BIT_PRINT(r8, P1RAS4MA);
1160 1.1 uch #undef DBG_BIT_PRINT
1161 1.1 uch printf("\n");
1162 1.1 uch
1163 1.1 uch printf("PC Card General Control Register\n");
1164 1.1 uch r8 = hd64461_reg_read_1(HD64461_PCCPGCR_REG8);
1165 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_PCCPGCR_##m, #m)
1166 1.1 uch DBG_BIT_PRINT(r8, PSSDIR);
1167 1.1 uch DBG_BIT_PRINT(r8, PSSRDWR);
1168 1.1 uch #undef DBG_BIT_PRINT
1169 1.1 uch printf("\n");
1170 1.1 uch
1171 1.1 uch dbg_banner_end();
1172 1.1 uch }
1173 1.1 uch #endif /* DEBUG */
1174 1.1 uch
1175