Subversion Repositories HelenOS-historic

Rev

Rev 1628 | Rev 1702 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
982 decky 1
/*
2
 * Copyright (C) 2006 Martin Decky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include <arch/drivers/cuda.h>
30
#include <arch/asm.h>
987 decky 31
#include <console/console.h>
1628 decky 32
#include <console/chardev.h>
1480 palkovsky 33
#include <arch/drivers/pic.h>
1625 decky 34
#include <sysinfo/sysinfo.h>
1480 palkovsky 35
#include <interrupt.h>
1619 decky 36
#include <stdarg.h>
982 decky 37
 
1633 decky 38
#define SPECIAL		'?'
39
 
1619 decky 40
#define PACKET_ADB  0x00
41
#define PACKET_CUDA 0x01
42
 
982 decky 43
#define CUDA_POWERDOWN 0x0a
44
 
45
#define RS 0x200
46
#define B (0 * RS)
47
#define A (1 * RS)
48
#define SR (10 * RS)
49
#define ACR (11 * RS)
50
 
51
#define SR_OUT 0x10
52
#define TACK 0x10
53
#define TIP 0x20
54
 
55
 
1619 decky 56
static volatile __u8 *cuda = NULL;
982 decky 57
 
1606 decky 58
 
1619 decky 59
static char lchars[0x80] = {
1633 decky 60
	'a',
61
	's',
62
	'd',
63
	'f',
64
	'h',
65
	'g',
66
	'z',
67
	'x',
68
	'c',
69
	'v', 
70
	SPECIAL,
71
	'b',
72
	'q',
73
	'w',
74
	'e',
75
	'r',
76
	'y',
77
	't',
78
	'1',
79
	'2',
80
	'3',
81
	'4',
82
	'6',
83
	'5',
84
	'=',
85
	'9',
86
	'7',
87
	'-',
88
	'8',
89
	'0',
90
	']',
91
	'o',
92
	'u',
93
	'[',
94
	'i', 
95
	'p',
96
	'\n',    /* Enter */
97
	'l',
98
	'j',
99
	'\'',
100
	'k',
101
	';',
102
	'\\',
103
	',',
104
	'/',
105
	'n',
106
	'm',
107
	'.',
108
	'\t',    /* Tab */
109
	' ',
110
	'`',
111
	'\b',    /* Backspace */
112
	SPECIAL,
113
	SPECIAL, /* Escape */
114
	SPECIAL, /* Ctrl */
115
	SPECIAL, /* Alt */
116
	SPECIAL, /* Shift */
117
	SPECIAL, /* Caps-Lock */
118
	SPECIAL, /* RAlt */
119
	SPECIAL, /* Left */
120
	SPECIAL, /* Right */
121
	SPECIAL, /* Down */
122
	SPECIAL, /* Up */
123
	SPECIAL, 
124
	SPECIAL,
125
	'.',     /* Keypad . */
126
	SPECIAL, 
127
	'*',     /* Keypad * */
128
	SPECIAL,
129
	'+',     /* Keypad + */
130
	SPECIAL,
131
	SPECIAL, /* NumLock */
132
	SPECIAL,
133
	SPECIAL,
134
	SPECIAL,
135
	'/',     /* Keypad / */
136
	'\n',    /* Keypad Enter */
137
	SPECIAL,
138
	'-',     /* Keypad - */
139
	SPECIAL,
140
	SPECIAL,
141
	SPECIAL,
142
	'0',     /* Keypad 0 */
143
	'1',     /* Keypad 1 */
144
	'2',     /* Keypad 2 */
145
	'3',     /* Keypad 3 */
146
	'4',     /* Keypad 4 */
147
	'5',     /* Keypad 5 */
148
	'6',     /* Keypad 6 */
149
	'7',     /* Keypad 7 */
150
	SPECIAL,
151
	'8',     /* Keypad 8 */
152
	'9',     /* Keypad 9 */
153
	SPECIAL,
154
	SPECIAL,
155
	SPECIAL,
156
	SPECIAL, /* F5 */
157
	SPECIAL, /* F6 */
158
	SPECIAL, /* F7 */
159
	SPECIAL, /* F3 */
160
	SPECIAL, /* F8 */
161
	SPECIAL, /* F9 */
162
	SPECIAL,
163
	SPECIAL, /* F11 */
164
	SPECIAL,
165
	SPECIAL, /* F13 */
166
	SPECIAL,
167
	SPECIAL, /* ScrollLock */
168
	SPECIAL,
169
	SPECIAL, /* F10 */
170
	SPECIAL,
171
	SPECIAL, /* F12 */
172
	SPECIAL,
173
	SPECIAL, /* Pause */
174
	SPECIAL, /* Insert */
175
	SPECIAL, /* Home */
176
	SPECIAL, /* PageUp */
177
	SPECIAL, /* Delete */
178
	SPECIAL, /* F4 */
179
	SPECIAL, /* End */
180
	SPECIAL, /* F2 */
181
	SPECIAL, /* PageDown */
182
	SPECIAL  /* F1 */
1619 decky 183
};
184
 
185
 
1628 decky 186
void send_packet(const __u8 kind, index_t count, ...);
1619 decky 187
 
188
 
189
static void receive_packet(__u8 *kind, index_t count, __u8 data[])
190
{
191
	cuda[B] = cuda[B] & ~TIP;
192
	*kind = cuda[SR];
193
 
194
	index_t i;
195
	for (i = 0; i < count; i++)
196
		data[i] = cuda[SR];
197
 
198
	cuda[B] = cuda[B] | TIP;
199
}
200
 
201
 
1606 decky 202
/* Called from getc(). */
203
static void cuda_resume(chardev_t *d)
204
{
205
}
206
 
207
 
208
/* Called from getc(). */
209
static void cuda_suspend(chardev_t *d)
210
{
211
}
212
 
213
 
214
static char key_read(chardev_t *d)
215
{
216
	char ch;
217
 
218
	ch = 0;
219
	return ch;
220
}
221
 
222
 
1628 decky 223
static chardev_t kbrd;
1606 decky 224
static chardev_operations_t ops = {
225
	.suspend = cuda_suspend,
226
	.resume = cuda_resume,
227
	.read = key_read
228
};
229
 
1619 decky 230
 
1633 decky 231
int cuda_get_scancode(void)
1480 palkovsky 232
{
1619 decky 233
	__u8 kind;
234
	__u8 data[4];
235
 
236
	receive_packet(&kind, 4, data);
237
 
1628 decky 238
	if ((kind == PACKET_ADB) && (data[0] == 0x40) && (data[1] == 0x2c))
239
		return data[2];
240
 
1633 decky 241
	return -1;
1480 palkovsky 242
}
982 decky 243
 
1628 decky 244
static void cuda_irq(int n, istate_t *istate)
245
{
1633 decky 246
	int scan_code = cuda_get_scancode();
1628 decky 247
 
1633 decky 248
	if (scan_code != -1) {
249
		__u8 scancode = (__u8) scan_code;
250
		if ((scancode & 0x80) != 0x80)
251
			chardev_push_character(&kbrd, lchars[scancode & 0x7f]);
252
	}
1628 decky 253
}
254
 
255
 
1619 decky 256
void cuda_init(__address base, size_t size)
990 decky 257
{
1619 decky 258
	cuda = (__u8 *) hw_map(base, size);
259
 
1480 palkovsky 260
	int_register(CUDA_IRQ, "cuda", cuda_irq);
261
	pic_enable_interrupt(CUDA_IRQ);
1606 decky 262
 
263
	chardev_initialize("cuda_kbd", &kbrd, &ops);
264
	stdin = &kbrd;
1625 decky 265
 
266
	sysinfo_set_item_val("cuda", NULL, true);
267
	sysinfo_set_item_val("cuda.irq", NULL, CUDA_IRQ);
990 decky 268
}
269
 
270
 
1628 decky 271
void send_packet(const __u8 kind, index_t count, ...)
272
{
273
	index_t i;
274
	va_list va;
275
 
276
	cuda[B] = cuda[B] | TIP;
277
	cuda[ACR] = cuda[ACR] | SR_OUT;
278
	cuda[SR] = kind;
279
	cuda[B] = cuda[B] & ~TIP;
280
 
281
	va_start(va, count);
282
 
283
	for (i = 0; i < count; i++) {
284
		cuda[ACR] = cuda[ACR] | SR_OUT;
285
		cuda[SR] = va_arg(va, int);
286
		cuda[B] = cuda[B] | TACK;
287
	}
288
 
289
	va_end(va);
290
 
291
	cuda[B] = cuda[B] | TIP;
292
}
293
 
294
 
982 decky 295
void cpu_halt(void) {
1004 decky 296
#ifdef CONFIG_POWEROFF
1619 decky 297
	send_packet(PACKET_CUDA, 1, CUDA_POWERDOWN);
298
#endif
1269 decky 299
	asm volatile (
300
		"b 0\n"
301
	);
982 decky 302
}