mfp.c revision 1.2 1 /* $NetBSD: mfp.c,v 1.2 1999/03/16 16:30:19 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 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
82 ia->ia_addr = MFP_ADDR;
83 if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
84 ia->ia_addr = MFP_INTR;
85
86 /* fixed address */
87 if (ia->ia_addr != MFP_ADDR)
88 return (0);
89 if (ia->ia_intr != MFP_INTR)
90 return (0);
91
92 return (1);
93 }
94
95
96 static void
97 mfp_attach(parent, self, aux)
98 struct device *parent, *self;
99 void *aux;
100 {
101 struct mfp_softc *sc = (struct mfp_softc *)self;
102 struct intio_attach_args *ia = aux;
103
104 mfp_init ();
105
106 if (sc != NULL) {
107 /* realconfig */
108 int r;
109
110 printf ("\n");
111
112 sc->sc_bst = ia->ia_bst;
113 sc->sc_intr = ia->ia_intr;
114 ia->ia_size = 0x30;
115 r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
116 #ifdef DIAGNOSTIC
117 if (r)
118 panic ("IO map for MFP corruption??");
119 #endif
120 bus_space_map(ia->ia_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);
121 config_found (self, "kbd", NULL);
122 config_found (self, "clock", NULL);
123 config_found (self, "pow", NULL);
124 }
125 }
126
127 static void
128 mfp_init (void)
129 {
130 #if 0 /* done in x68k_init.c::intr_reset() */
131 mfp_set_vr(MFP_INTR);
132
133 /* stop all interrupts */
134 mfp_set_iera(0);
135 mfp_set_ierb(0);
136 #endif
137
138 /* Timer A settings */
139 mfp_set_tacr(MFP_TIMERA_RESET | MFP_TIMERA_STOP);
140
141 /* Timer B settings: used for USART clock */
142 mfp_set_tbcr(MFP_TIMERB_RESET | MFP_TIMERB_STOP);
143
144 /* Timer C/D settings */
145 mfp_set_tcdcr(0);
146 }
147
148 /*
149 * MFP utility functions
150 */
151
152 /*
153 * wait for built-in display hsync.
154 * should be called before writing to frame buffer.
155 * might be called before realconfig.
156 */
157 void
158 mfp_wait_for_hsync (void)
159 {
160 struct mfp_softc *sc = mfp_cd.cd_devs[0]; /* XXX */
161
162 /* wait for CRT HSYNC */
163 while (mfp_get_gpip() & MFP_GPIP_HSYNC)
164 asm("nop");
165 while (!(mfp_get_gpip() & MFP_GPIP_HSYNC))
166 asm("nop");
167 }
168
169 /*
170 * send COMMAND to the MFP USART.
171 * USART is attached to the keyboard.
172 * might be called before realconfig.
173 */
174 int
175 mfp_send_usart (command)
176 int command;
177 {
178 struct mfp_softc *sc = mfp_cd.cd_devs[0]; /* XXX */
179
180 while (!(mfp_get_tsr() & MFP_TSR_BE));
181 mfp_set_udr(command);
182
183 return 0;
184 }
185
186 int
187 mfp_recieve_usart(void)
188 {
189 while (!(mfp_get_rsr() & MFP_RSR_BF))
190 asm("nop");
191 return mfp_get_udr();
192 }
193