1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/* $NetBSD: mfp.c,v 1.29 2021/08/07 16:19:07 thorpej Exp $ */
/*-
* Copyright (c) 1998 NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* MC68901 MFP (multi function periferal) driver for NetBSD/x68k
*/
/*
* MFP is used as keyboard controller, which may be used before
* ordinary initialization.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mfp.c,v 1.29 2021/08/07 16:19:07 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/autoconf.h>
#include <arch/x68k/dev/intiovar.h>
#include <arch/x68k/dev/mfp.h>
static int mfp_match(device_t, cfdata_t, void *);
static void mfp_attach(device_t, device_t, void *);
static int mfp_search(device_t, cfdata_t, const int *, void *);
static void mfp_init(void);
static void mfp_calibrate_delay(void);
CFATTACH_DECL_NEW(mfp, sizeof(struct mfp_softc),
mfp_match, mfp_attach, NULL, NULL);
static int mfp_attached;
static int
mfp_match(device_t parent, cfdata_t cf, void *aux)
{
struct intio_attach_args *ia = aux;
/* mfp0 */
if (strcmp(ia->ia_name, "mfp") != 0)
return 0;
if (mfp_attached)
return (0);
if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
ia->ia_addr = MFP_ADDR;
if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
ia->ia_addr = MFP_INTR;
/* fixed address */
if (ia->ia_addr != MFP_ADDR)
return (0);
if (ia->ia_intr != MFP_INTR)
return (0);
return (1);
}
static void
mfp_attach(device_t parent, device_t self, void *aux)
{
struct mfp_softc *sc = device_private(self);
struct intio_attach_args *ia = aux;
int r __diagused;
aprint_normal("\n");
mfp_attached = 1;
/* mfp_init() is already called via early config_console() */
sc->sc_bst = ia->ia_bst;
sc->sc_intr = ia->ia_intr;
ia->ia_size = 0x30;
r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
#ifdef DIAGNOSTIC
if (r)
panic("IO map for MFP corruption??");
#endif
bus_space_map(ia->ia_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);
config_search(self, NULL,
CFARGS(.search = mfp_search));
}
static int
mfp_search(device_t parent, cfdata_t cf, const int *loc, void *aux)
{
if (config_probe(parent, cf, __UNCONST(cf->cf_name)))
config_attach(parent, cf, __UNCONST(cf->cf_name), NULL,
CFARGS_NONE);
return 0;
}
void
mfp_config_console(void)
{
mfp_init();
mfp_calibrate_delay();
}
static void
mfp_init(void)
{
mfp_set_vr(MFP_INTR);
/* stop all interrupts */
mfp_set_iera(0);
mfp_set_ierb(0);
/* make MSCTRL 'High', XXX where should I do it? */
mfp_send_usart(0x41);
/* Timer A settings */
mfp_set_tacr(MFP_TIMERA_RESET | MFP_TIMERA_STOP);
/* Timer B settings: used for USART clock */
mfp_set_tbcr(MFP_TIMERB_RESET | MFP_TIMERB_STOP);
/* Timer C/D settings */
mfp_set_tcdcr(0);
}
extern int delay_divisor;
void _delay(u_int);
static void
mfp_calibrate_delay(void)
{
/*
* Stolen from mvme68k.
*/
/*
* X68k provides 4MHz clock (= 0.25usec) for MFP timer C.
* 10000usec = 0.25usec * 200 * 200
* Our slowest clock is 20MHz (?). Its delay_divisor value
* should be about 102. Start from 140 here.
*/
for (delay_divisor = 140; delay_divisor > 0; delay_divisor--) {
mfp_set_tcdr(255-0);
mfp_set_tcdcr(0x70); /* 1/200 delay mode */
_delay(10000 << 8);
mfp_set_tcdcr(0); /* stop timer */
if ((255 - mfp_get_tcdr()) > 200)
break; /* got it! */
/* retry! */
}
}
/*
* MFP utility functions
*/
/*
* wait for built-in display hsync.
* should be called before writing to frame buffer.
* might be called before realconfig.
*/
void
mfp_wait_for_hsync(void)
{
/* wait for CRT HSYNC */
while (mfp_get_gpip() & MFP_GPIP_HSYNC)
__asm("nop");
while (!(mfp_get_gpip() & MFP_GPIP_HSYNC))
__asm("nop");
}
/*
* send COMMAND to the MFP USART.
* USART is attached to the keyboard.
* might be called before realconfig.
*/
int
mfp_send_usart(int command)
{
while (!(mfp_get_tsr() & MFP_TSR_BE));
mfp_set_udr(command);
return 0;
}
int
mfp_receive_usart(void)
{
while (!(mfp_get_rsr() & MFP_RSR_BF))
__asm("nop");
return mfp_get_udr();
}
|