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