mfp.c revision 1.3 1 /* $NetBSD: mfp.c,v 1.3 1999/03/18 12:27:59 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 void mfp_init __P((void));
58
59 struct cfattach mfp_ca = {
60 sizeof(struct mfp_softc), mfp_match, mfp_attach
61 };
62
63 extern int x68k_realconfig;
64 extern struct cfdriver mfp_cd;
65
66 static int
67 mfp_match(parent, cf, aux)
68 struct device *parent;
69 struct cfdata *cf;
70 void *aux;
71 {
72 struct intio_attach_args *ia = aux;
73
74 /* mfp0 */
75 if (strcmp (ia->ia_name, "mfp") != 0)
76 return 0;
77 if (cf->cf_unit != 0)
78 return (0);
79
80 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
81 ia->ia_addr = MFP_ADDR;
82 if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
83 ia->ia_addr = MFP_INTR;
84
85 /* fixed address */
86 if (ia->ia_addr != MFP_ADDR)
87 return (0);
88 if (ia->ia_intr != MFP_INTR)
89 return (0);
90
91 return (1);
92 }
93
94
95 static void
96 mfp_attach(parent, self, aux)
97 struct device *parent, *self;
98 void *aux;
99 {
100 struct mfp_softc *sc = (struct mfp_softc *)self;
101 struct intio_attach_args *ia = aux;
102
103 mfp_init ();
104
105 if (sc != NULL) {
106 /* realconfig */
107 int r;
108
109 printf ("\n");
110
111 sc->sc_bst = ia->ia_bst;
112 sc->sc_intr = ia->ia_intr;
113 ia->ia_size = 0x30;
114 r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
115 #ifdef DIAGNOSTIC
116 if (r)
117 panic ("IO map for MFP corruption??");
118 #endif
119 bus_space_map(ia->ia_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);
120 config_found (self, "kbd", NULL);
121 config_found (self, "clock", NULL);
122 config_found (self, "pow", NULL);
123 }
124 }
125
126 static void
127 mfp_init (void)
128 {
129 #if 0 /* done in x68k_init.c::intr_reset() */
130 mfp_set_vr(MFP_INTR);
131
132 /* stop all interrupts */
133 mfp_set_iera(0);
134 mfp_set_ierb(0);
135 #endif
136
137 /* Timer A settings */
138 mfp_set_tacr(MFP_TIMERA_RESET | MFP_TIMERA_STOP);
139
140 /* Timer B settings: used for USART clock */
141 mfp_set_tbcr(MFP_TIMERB_RESET | MFP_TIMERB_STOP);
142
143 /* Timer C/D settings */
144 mfp_set_tcdcr(0);
145 }
146
147 /*
148 * MFP utility functions
149 */
150
151 /*
152 * wait for built-in display hsync.
153 * should be called before writing to frame buffer.
154 * might be called before realconfig.
155 */
156 void
157 mfp_wait_for_hsync (void)
158 {
159 /* wait for CRT HSYNC */
160 while (mfp_get_gpip() & MFP_GPIP_HSYNC)
161 asm("nop");
162 while (!(mfp_get_gpip() & MFP_GPIP_HSYNC))
163 asm("nop");
164 }
165
166 /*
167 * send COMMAND to the MFP USART.
168 * USART is attached to the keyboard.
169 * might be called before realconfig.
170 */
171 int
172 mfp_send_usart (command)
173 int command;
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