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