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