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