Home | History | Annotate | Line # | Download | only in dev
mfp.c revision 1.1.2.3
      1 /*	$NetBSD: mfp.c,v 1.1.2.3 1998/12/27 15:14:31 minoura Exp $	*/
      2 
      3 /*
      4  *
      5  * Copyright (c) 1998 NetBSD Foundation, Inc.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by Charles D. Cranor and
     19  *      Washington University.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * MC68901 MFP (multi function periferal) driver for NetBSD/x68k
     37  */
     38 
     39 /*
     40  * MFP is used as keyboard controler, which may be used before
     41  * ordinary initialization.
     42  */
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/device.h>
     47 #include <sys/malloc.h>
     48 
     49 #include <machine/bus.h>
     50 #include <machine/cpu.h>
     51 
     52 #include <arch/x68k/dev/intiovar.h>
     53 #include <arch/x68k/dev/mfp.h>
     54 
     55 static int mfp_match __P((struct device *, struct cfdata *, void *));
     56 static void mfp_attach __P((struct device *, struct device *, void *));
     57 static int mfp_search __P((struct device *, struct cfdata *cf, void *));
     58 static void mfp_init __P((void));
     59 
     60 struct cfattach mfp_ca = {
     61 	sizeof(struct mfp_softc), mfp_match, mfp_attach
     62 };
     63 
     64 extern int x68k_realconfig;
     65 extern struct cfdriver mfp_cd;
     66 
     67 static int
     68 mfp_match(parent, cf, aux)
     69 	struct device *parent;
     70 	struct cfdata *cf;
     71 	void *aux;
     72 {
     73 	struct intio_attach_args *ia = aux;
     74 
     75 	/* mfp0 */
     76 	if (strcmp (ia->ia_name, "mfp") != 0)
     77 		return 0;
     78 	if (cf->cf_unit != 0)
     79 		return (0);
     80 
     81 	/* fixed address */
     82 	if (ia->ia_addr != MFP_ADDR)
     83 		return (0);
     84 	if (ia->ia_intr != MFP_INTR)
     85 		return (0);
     86 
     87 	return (1);
     88 }
     89 
     90 
     91 static void
     92 mfp_attach(parent, self, aux)
     93 	struct device *parent, *self;
     94 	void *aux;
     95 {
     96 	struct mfp_softc *sc = (struct mfp_softc *)self;
     97 	struct intio_attach_args *ia = aux;
     98 
     99 	mfp_init ();
    100 
    101 	if (sc != NULL) {
    102 		/* realconfig */
    103 		int r;
    104 
    105 		printf ("\n");
    106 
    107 		sc->sc_bst = ia->ia_bst;
    108 		sc->sc_intr = ia->ia_intr;
    109 		ia->ia_size = 0x30;
    110 		r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    111 #ifdef DIAGNOSTIC
    112 		if (r)
    113 			panic ("IO map for MFP corruption??");
    114 #endif
    115 		bus_space_map(ia->ia_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);
    116 		config_found (self, "kbd", NULL);
    117 		config_found (self, "clock", NULL);
    118 		config_found (self, "pow", NULL);
    119 	}
    120 }
    121 
    122 static void
    123 mfp_init (void)
    124 {
    125 #if 0				/* done in x68k_init.c::intr_reset() */
    126 	mfp_set_vr(MFP_INTR);
    127 
    128 	/* stop all interrupts */
    129 	mfp_set_iera(0);
    130 	mfp_set_ierb(0);
    131 #endif
    132 
    133 	/* Timer A settings */
    134 	mfp_set_tacr(MFP_TIMERA_RESET | MFP_TIMERA_STOP);
    135 
    136 	/* Timer B settings: used for USART clock */
    137 	mfp_set_tbcr(MFP_TIMERB_RESET | MFP_TIMERB_STOP);
    138 
    139 	/* Timer C/D settings */
    140 	mfp_set_tcdcr(0);
    141 }
    142 
    143 /*
    144  * MFP utility functions
    145  */
    146 
    147 /*
    148  * wait for built-in display hsync.
    149  * should be called before writing to frame buffer.
    150  * might be called before realconfig.
    151  */
    152 void
    153 mfp_wait_for_hsync (void)
    154 {
    155 	struct mfp_softc *sc = mfp_cd.cd_devs[0]; /* XXX */
    156 
    157 	/* wait for CRT HSYNC */
    158 	while (mfp_get_gpip() & MFP_GPIP_HSYNC)
    159 		asm("nop");
    160 	while (!(mfp_get_gpip() & MFP_GPIP_HSYNC))
    161 		asm("nop");
    162 }
    163 
    164 /*
    165  * send COMMAND to the MFP USART.
    166  * USART is attached to the keyboard.
    167  * might be called before realconfig.
    168  */
    169 int
    170 mfp_send_usart (command)
    171 	int command;
    172 {
    173 	struct mfp_softc *sc = mfp_cd.cd_devs[0]; /* XXX */
    174 
    175 	while (!(mfp_get_tsr() & MFP_TSR_BE));
    176 	mfp_set_udr(command);
    177 
    178 	return 0;
    179 }
    180 
    181 int
    182 mfp_recieve_usart(void)
    183 {
    184 	while (!(mfp_get_rsr() & MFP_RSR_BF))
    185 		asm("nop");
    186 	return mfp_get_udr();
    187 }
    188