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