blob: bf26c3c56990f2ee36c9216b00fa430fc8662d22 [file] [log] [blame]
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001/*
2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
3 *
4 * VGA text mode console part
5 *
6 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
7 *
8 * If distributed as part of the Linux kernel, this code is licensed under the
9 * terms of the GPL v2.
10 *
11 * Otherwise, the following license terms apply:
12 *
13 * * Redistribution and use in source and binary forms, with or without
14 * * modification, are permitted provided that the following conditions
15 * * are met:
16 * * 1) Redistributions of source code must retain the above copyright
17 * * notice, this list of conditions and the following disclaimer.
18 * * 2) Redistributions in binary form must reproduce the above copyright
19 * * notice, this list of conditions and the following disclaimer in the
20 * * documentation and/or other materials provided with the distribution.
21 * * 3) The name of the author may not be used to endorse or promote products
22 * * derived from this software without specific psisusbr written permission.
23 * *
24 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
25 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Thomas Winischhofer <thomas@winischhofer.net>
36 *
37 * Portions based on vgacon.c which are
38 * Created 28 Sep 1997 by Geert Uytterhoeven
39 * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
40 * based on code Copyright (C) 1991, 1992 Linus Torvalds
41 * 1995 Jay Estabrook
42 *
43 * A note on using in_atomic() in here: We can't handle console
44 * calls from non-schedulable context due to our USB-dependend
45 * nature. For now, this driver just ignores any calls if it
46 * detects this state.
47 *
48 */
49
Arjan van de Ven2682d272006-03-28 01:00:21 -080050#include <linux/mutex.h>
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +020051#include <linux/module.h>
52#include <linux/kernel.h>
53#include <linux/signal.h>
54#include <linux/sched.h>
55#include <linux/fs.h>
56#include <linux/tty.h>
57#include <linux/console.h>
58#include <linux/string.h>
59#include <linux/kd.h>
60#include <linux/init.h>
61#include <linux/slab.h>
62#include <linux/vt_kern.h>
63#include <linux/selection.h>
64#include <linux/spinlock.h>
65#include <linux/kref.h>
66#include <linux/smp_lock.h>
67#include <linux/ioport.h>
68#include <linux/interrupt.h>
69#include <linux/vmalloc.h>
70
71#include "sisusb.h"
Adrian Bunkdf47e532006-04-15 11:17:27 +020072#include "sisusb_init.h"
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +020073
74#ifdef INCL_SISUSB_CON
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +020075
76#define sisusbcon_writew(val, addr) (*(addr) = (val))
77#define sisusbcon_readw(addr) (*(addr))
78#define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
79#define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
80
81/* vc_data -> sisusb conversion table */
82static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
83
84/* Forward declaration */
85static const struct consw sisusb_con;
86
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +020087static inline void
88sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
89{
90 count /= 2;
91 while (count--)
92 sisusbcon_writew(c, s++);
93}
94
95static inline void
96sisusb_initialize(struct sisusb_usb_data *sisusb)
97{
98 /* Reset cursor and start address */
99 if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
100 return;
101 if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
102 return;
103 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
104 return;
105 sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
106}
107
108static inline void
109sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
110{
111 sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
112
113 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
114 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
115}
116
117void
118sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
119{
120 if (sisusb->sisusb_cursor_loc == location)
121 return;
122
123 sisusb->sisusb_cursor_loc = location;
124
125 /* Hardware bug: Text cursor appears twice or not at all
126 * at some positions. Work around it with the cursor skew
127 * bits.
128 */
129
130 if ((location & 0x0007) == 0x0007) {
131 sisusb->bad_cursor_pos = 1;
132 location--;
133 if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
134 return;
135 } else if (sisusb->bad_cursor_pos) {
136 if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
137 return;
138 sisusb->bad_cursor_pos = 0;
139 }
140
141 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
142 return;
143 sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
144}
145
146static inline struct sisusb_usb_data *
147sisusb_get_sisusb(unsigned short console)
148{
149 return mysisusbs[console];
150}
151
152static inline int
153sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
154{
155 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
156 return 0;
157
158 return 1;
159}
160
161static struct sisusb_usb_data *
162sisusb_get_sisusb_lock_and_check(unsigned short console)
163{
164 struct sisusb_usb_data *sisusb;
165
166 /* We can't handle console calls in non-schedulable
167 * context due to our locks and the USB transport.
168 * So we simply ignore them. This should only affect
169 * some calls to printk.
170 */
171 if (in_atomic())
172 return NULL;
173
174 if (!(sisusb = sisusb_get_sisusb(console)))
175 return NULL;
176
Arjan van de Ven2682d272006-03-28 01:00:21 -0800177 mutex_lock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200178
179 if (!sisusb_sisusb_valid(sisusb) ||
180 !sisusb->havethisconsole[console]) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800181 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200182 return NULL;
183 }
184
185 return sisusb;
186}
187
188static int
189sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
190{
191 if (sisusb->is_gfx ||
192 sisusb->textmodedestroyed ||
193 c->vc_mode != KD_TEXT)
194 return 1;
195
196 return 0;
197}
198
199/* con_startup console interface routine */
200static const char *
201sisusbcon_startup(void)
202{
203 return "SISUSBCON";
204}
205
206/* con_init console interface routine */
207static void
208sisusbcon_init(struct vc_data *c, int init)
209{
210 struct sisusb_usb_data *sisusb;
211 int cols, rows;
212
213 /* This is called by take_over_console(),
214 * ie by us/under our control. It is
215 * only called after text mode and fonts
216 * are set up/restored.
217 */
218
Arjan van de Ven2682d272006-03-28 01:00:21 -0800219 mutex_lock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200220
221 if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800222 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200223 return;
224 }
225
Arjan van de Ven2682d272006-03-28 01:00:21 -0800226 mutex_lock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200227
228 if (!sisusb_sisusb_valid(sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800229 mutex_unlock(&sisusb->lock);
230 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200231 return;
232 }
233
234 c->vc_can_do_color = 1;
235
236 c->vc_complement_mask = 0x7700;
237
238 c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
239
240 sisusb->haveconsole = 1;
241
242 sisusb->havethisconsole[c->vc_num] = 1;
243
244 /* We only support 640x400 */
245 c->vc_scan_lines = 400;
246
247 c->vc_font.height = sisusb->current_font_height;
248
249 /* We only support width = 8 */
250 cols = 80;
251 rows = c->vc_scan_lines / c->vc_font.height;
252
253 /* Increment usage count for our sisusb.
254 * Doing so saves us from upping/downing
255 * the disconnect semaphore; we can't
256 * lose our sisusb until this is undone
257 * in con_deinit. For all other console
258 * interface functions, it suffices to
259 * use sisusb->lock and do a quick check
260 * of sisusb for device disconnection.
261 */
262 kref_get(&sisusb->kref);
263
264 if (!*c->vc_uni_pagedir_loc)
265 con_set_default_unimap(c);
266
Arjan van de Ven2682d272006-03-28 01:00:21 -0800267 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200268
Arjan van de Ven2682d272006-03-28 01:00:21 -0800269 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200270
271 if (init) {
272 c->vc_cols = cols;
273 c->vc_rows = rows;
274 } else
275 vc_resize(c, cols, rows);
276}
277
278/* con_deinit console interface routine */
279static void
280sisusbcon_deinit(struct vc_data *c)
281{
282 struct sisusb_usb_data *sisusb;
283 int i;
284
285 /* This is called by take_over_console()
286 * and others, ie not under our control.
287 */
288
Arjan van de Ven2682d272006-03-28 01:00:21 -0800289 mutex_lock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200290
291 if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800292 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200293 return;
294 }
295
Arjan van de Ven2682d272006-03-28 01:00:21 -0800296 mutex_lock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200297
298 /* Clear ourselves in mysisusbs */
299 mysisusbs[c->vc_num] = NULL;
300
301 sisusb->havethisconsole[c->vc_num] = 0;
302
303 /* Free our font buffer if all consoles are gone */
304 if (sisusb->font_backup) {
305 for(i = 0; i < MAX_NR_CONSOLES; i++) {
306 if (sisusb->havethisconsole[c->vc_num])
307 break;
308 }
309 if (i == MAX_NR_CONSOLES) {
310 vfree(sisusb->font_backup);
311 sisusb->font_backup = NULL;
312 }
313 }
314
Arjan van de Ven2682d272006-03-28 01:00:21 -0800315 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200316
317 /* decrement the usage count on our sisusb */
318 kref_put(&sisusb->kref, sisusb_delete);
319
Arjan van de Ven2682d272006-03-28 01:00:21 -0800320 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200321}
322
323/* interface routine */
324static u8
325sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
326 u8 blink, u8 underline, u8 reverse)
327{
328 u8 attr = color;
329
330 if (underline)
331 attr = (attr & 0xf0) | c->vc_ulcolor;
332 else if (intensity == 0)
333 attr = (attr & 0xf0) | c->vc_halfcolor;
334
335 if (reverse)
336 attr = ((attr) & 0x88) |
337 ((((attr) >> 4) |
338 ((attr) << 4)) & 0x77);
339
340 if (blink)
341 attr ^= 0x80;
342
343 if (intensity == 2)
344 attr ^= 0x08;
345
346 return attr;
347}
348
349/* Interface routine */
350static void
351sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
352{
353 /* Invert a region. This is called with a pointer
354 * to the console's internal screen buffer. So we
355 * simply do the inversion there and rely on
356 * a call to putc(s) to update the real screen.
357 */
358
359 while (count--) {
360 u16 a = sisusbcon_readw(p);
361
362 a = ((a) & 0x88ff) |
363 (((a) & 0x7000) >> 4) |
364 (((a) & 0x0700) << 4);
365
366 sisusbcon_writew(a, p++);
367 }
368}
369
370#define SISUSB_VADDR(x,y) \
371 ((u16 *)c->vc_origin + \
372 (y) * sisusb->sisusb_num_columns + \
373 (x))
374
375#define SISUSB_HADDR(x,y) \
376 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
377 (y) * sisusb->sisusb_num_columns + \
378 (x))
379
380/* Interface routine */
381static void
382sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
383{
384 struct sisusb_usb_data *sisusb;
385 ssize_t written;
386
387 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
388 return;
389
390 /* sisusb->lock is down */
391
392 /* Don't need to put the character into buffer ourselves,
393 * because the vt does this BEFORE calling us.
394 */
395#if 0
396 sisusbcon_writew(ch, SISUSB_VADDR(x, y));
397#endif
398
399 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800400 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200401 return;
402 }
403
404
405 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
406 (u32)SISUSB_HADDR(x, y), 2, &written);
407
Arjan van de Ven2682d272006-03-28 01:00:21 -0800408 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200409}
410
411/* Interface routine */
412static void
413sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
414 int count, int y, int x)
415{
416 struct sisusb_usb_data *sisusb;
417 ssize_t written;
418 u16 *dest;
419 int i;
420
421 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
422 return;
423
424 /* sisusb->lock is down */
425
426 /* Need to put the characters into the buffer ourselves,
427 * because the vt does this AFTER calling us.
428 */
429
430 dest = SISUSB_VADDR(x, y);
431
432 for (i = count; i > 0; i--)
433 sisusbcon_writew(sisusbcon_readw(s++), dest++);
434
435 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800436 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200437 return;
438 }
439
440 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
441 (u32)SISUSB_HADDR(x, y), count * 2, &written);
442
Arjan van de Ven2682d272006-03-28 01:00:21 -0800443 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200444}
445
446/* Interface routine */
447static void
448sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
449{
450 struct sisusb_usb_data *sisusb;
451 u16 eattr = c->vc_video_erase_char;
452 ssize_t written;
453 int i, length, cols;
454 u16 *dest;
455
456 if (width <= 0 || height <= 0)
457 return;
458
459 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
460 return;
461
462 /* sisusb->lock is down */
463
464 /* Need to clear buffer ourselves, because the vt does
465 * this AFTER calling us.
466 */
467
468 dest = SISUSB_VADDR(x, y);
469
470 cols = sisusb->sisusb_num_columns;
471
472 if (width > cols)
473 width = cols;
474
475 if (x == 0 && width >= c->vc_cols) {
476
477 sisusbcon_memsetw(dest, eattr, height * cols * 2);
478
479 } else {
480
481 for (i = height; i > 0; i--, dest += cols)
482 sisusbcon_memsetw(dest, eattr, width * 2);
483
484 }
485
486 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800487 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200488 return;
489 }
490
491 length = ((height * cols) - x - (cols - width - x)) * 2;
492
493
494 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
495 (u32)SISUSB_HADDR(x, y), length, &written);
496
Arjan van de Ven2682d272006-03-28 01:00:21 -0800497 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200498}
499
500/* Interface routine */
501static void
502sisusbcon_bmove(struct vc_data *c, int sy, int sx,
503 int dy, int dx, int height, int width)
504{
505 struct sisusb_usb_data *sisusb;
506 ssize_t written;
507 int cols, length;
508#if 0
509 u16 *src, *dest;
510 int i;
511#endif
512
513 if (width <= 0 || height <= 0)
514 return;
515
516 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
517 return;
518
519 /* sisusb->lock is down */
520
521 cols = sisusb->sisusb_num_columns;
522
523 /* Don't need to move data outselves, because
524 * vt does this BEFORE calling us.
525 * This is only used by vt's insert/deletechar.
526 */
527#if 0
528 if (sx == 0 && dx == 0 && width >= c->vc_cols && width <= cols) {
529
530 sisusbcon_memmovew(SISUSB_VADDR(0, dy), SISUSB_VADDR(0, sy),
531 height * width * 2);
532
533 } else if (dy < sy || (dy == sy && dx < sx)) {
534
535 src = SISUSB_VADDR(sx, sy);
536 dest = SISUSB_VADDR(dx, dy);
537
538 for (i = height; i > 0; i--) {
539 sisusbcon_memmovew(dest, src, width * 2);
540 src += cols;
541 dest += cols;
542 }
543
544 } else {
545
546 src = SISUSB_VADDR(sx, sy + height - 1);
547 dest = SISUSB_VADDR(dx, dy + height - 1);
548
549 for (i = height; i > 0; i--) {
550 sisusbcon_memmovew(dest, src, width * 2);
551 src -= cols;
552 dest -= cols;
553 }
554
555 }
556#endif
557
558 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800559 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200560 return;
561 }
562
563 length = ((height * cols) - dx - (cols - width - dx)) * 2;
564
565
566 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy),
567 (u32)SISUSB_HADDR(dx, dy), length, &written);
568
Arjan van de Ven2682d272006-03-28 01:00:21 -0800569 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200570}
571
572/* interface routine */
573static int
574sisusbcon_switch(struct vc_data *c)
575{
576 struct sisusb_usb_data *sisusb;
577 ssize_t written;
578 int length;
579
580 /* Returnvalue 0 means we have fully restored screen,
581 * and vt doesn't need to call do_update_region().
582 * Returnvalue != 0 naturally means the opposite.
583 */
584
585 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
586 return 0;
587
588 /* sisusb->lock is down */
589
590 /* Don't write to screen if in gfx mode */
591 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800592 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200593 return 0;
594 }
595
596 /* That really should not happen. It would mean we are
597 * being called while the vc is using its private buffer
598 * as origin.
599 */
600 if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800601 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200602 printk(KERN_DEBUG "sisusb: ASSERT ORIGIN != SCREENBUF!\n");
603 return 0;
604 }
605
606 /* Check that we don't copy too much */
607 length = min((int)c->vc_screenbuf_size,
608 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
609
610 /* Restore the screen contents */
611 sisusbcon_memcpyw((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf,
612 length);
613
614 sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
615 (u32)SISUSB_HADDR(0, 0),
616 length, &written);
617
Arjan van de Ven2682d272006-03-28 01:00:21 -0800618 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200619
620 return 0;
621}
622
623/* interface routine */
624static void
625sisusbcon_save_screen(struct vc_data *c)
626{
627 struct sisusb_usb_data *sisusb;
628 int length;
629
630 /* Save the current screen contents to vc's private
631 * buffer.
632 */
633
634 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
635 return;
636
637 /* sisusb->lock is down */
638
639 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800640 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200641 return;
642 }
643
644 /* Check that we don't copy too much */
645 length = min((int)c->vc_screenbuf_size,
646 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
647
648 /* Save the screen contents to vc's private buffer */
649 sisusbcon_memcpyw((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin,
650 length);
651
Arjan van de Ven2682d272006-03-28 01:00:21 -0800652 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200653}
654
655/* interface routine */
656static int
657sisusbcon_set_palette(struct vc_data *c, unsigned char *table)
658{
659 struct sisusb_usb_data *sisusb;
660 int i, j;
661
662 /* Return value not used by vt */
663
664 if (!CON_IS_VISIBLE(c))
665 return -EINVAL;
666
667 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
668 return -EINVAL;
669
670 /* sisusb->lock is down */
671
672 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800673 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200674 return -EINVAL;
675 }
676
677 for (i = j = 0; i < 16; i++) {
678 if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
679 break;
680 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
681 break;
682 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
683 break;
684 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
685 break;
686 }
687
Arjan van de Ven2682d272006-03-28 01:00:21 -0800688 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200689
690 return 0;
691}
692
693/* interface routine */
694static int
695sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
696{
697 struct sisusb_usb_data *sisusb;
698 u8 sr1, cr17, pmreg, cr63;
699 ssize_t written;
700 int ret = 0;
701
702 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
703 return 0;
704
705 /* sisusb->lock is down */
706
707 if (mode_switch)
708 sisusb->is_gfx = blank ? 1 : 0;
709
710 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800711 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200712 return 0;
713 }
714
715 switch (blank) {
716
717 case 1: /* Normal blanking: Clear screen */
718 case -1:
719 sisusbcon_memsetw((u16 *)c->vc_origin,
720 c->vc_video_erase_char,
721 c->vc_screenbuf_size);
722 sisusb_copy_memory(sisusb,
723 (unsigned char *)c->vc_origin,
724 (u32)(sisusb->vrambase +
725 (c->vc_origin - sisusb->scrbuf)),
726 c->vc_screenbuf_size, &written);
727 sisusb->con_blanked = 1;
728 ret = 1;
729 break;
730
731 default: /* VESA blanking */
732 switch (blank) {
733 case 0: /* Unblank */
734 sr1 = 0x00;
735 cr17 = 0x80;
736 pmreg = 0x00;
737 cr63 = 0x00;
738 ret = 1;
739 sisusb->con_blanked = 0;
740 break;
741 case VESA_VSYNC_SUSPEND + 1:
742 sr1 = 0x20;
743 cr17 = 0x80;
744 pmreg = 0x80;
745 cr63 = 0x40;
746 break;
747 case VESA_HSYNC_SUSPEND + 1:
748 sr1 = 0x20;
749 cr17 = 0x80;
750 pmreg = 0x40;
751 cr63 = 0x40;
752 break;
753 case VESA_POWERDOWN + 1:
754 sr1 = 0x20;
755 cr17 = 0x00;
756 pmreg = 0xc0;
757 cr63 = 0x40;
758 break;
759 default:
Arjan van de Ven2682d272006-03-28 01:00:21 -0800760 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200761 return -EINVAL;
762 }
763
764 sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
765 sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
766 sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
767 sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
768
769 }
770
Arjan van de Ven2682d272006-03-28 01:00:21 -0800771 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200772
773 return ret;
774}
775
776/* interface routine */
777static int
778sisusbcon_scrolldelta(struct vc_data *c, int lines)
779{
780 struct sisusb_usb_data *sisusb;
781 int margin = c->vc_size_row * 4;
782 int ul, we, p, st;
783
784 /* The return value does not seem to be used */
785
786 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
787 return 0;
788
789 /* sisusb->lock is down */
790
791 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800792 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200793 return 0;
794 }
795
796 if (!lines) /* Turn scrollback off */
797 c->vc_visible_origin = c->vc_origin;
798 else {
799
800 if (sisusb->con_rolled_over >
801 (c->vc_scr_end - sisusb->scrbuf) + margin) {
802
803 ul = c->vc_scr_end - sisusb->scrbuf;
804 we = sisusb->con_rolled_over + c->vc_size_row;
805
806 } else {
807
808 ul = 0;
809 we = sisusb->scrbuf_size;
810
811 }
812
813 p = (c->vc_visible_origin - sisusb->scrbuf - ul + we) % we +
814 lines * c->vc_size_row;
815
816 st = (c->vc_origin - sisusb->scrbuf - ul + we) % we;
817
818 if (st < 2 * margin)
819 margin = 0;
820
821 if (p < margin)
822 p = 0;
823
824 if (p > st - margin)
825 p = st;
826
827 c->vc_visible_origin = sisusb->scrbuf + (p + ul) % we;
828 }
829
830 sisusbcon_set_start_address(sisusb, c);
831
Arjan van de Ven2682d272006-03-28 01:00:21 -0800832 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200833
834 return 1;
835}
836
837/* Interface routine */
838static void
839sisusbcon_cursor(struct vc_data *c, int mode)
840{
841 struct sisusb_usb_data *sisusb;
842 int from, to, baseline;
843
844 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
845 return;
846
847 /* sisusb->lock is down */
848
849 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800850 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200851 return;
852 }
853
854 if (c->vc_origin != c->vc_visible_origin) {
855 c->vc_visible_origin = c->vc_origin;
856 sisusbcon_set_start_address(sisusb, c);
857 }
858
859 if (mode == CM_ERASE) {
860 sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
861 sisusb->sisusb_cursor_size_to = -1;
Arjan van de Ven2682d272006-03-28 01:00:21 -0800862 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200863 return;
864 }
865
866 sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
867
868 baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
869
870 switch (c->vc_cursor_type & 0x0f) {
871 case CUR_BLOCK: from = 1;
872 to = c->vc_font.height;
873 break;
874 case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
875 to = baseline;
876 break;
877 case CUR_LOWER_HALF: from = c->vc_font.height / 2;
878 to = baseline;
879 break;
880 case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
881 to = baseline;
882 break;
883 case CUR_NONE: from = 31;
884 to = 30;
885 break;
886 default:
887 case CUR_UNDERLINE: from = baseline - 1;
888 to = baseline;
889 break;
890 }
891
892 if (sisusb->sisusb_cursor_size_from != from ||
893 sisusb->sisusb_cursor_size_to != to) {
894
895 sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
896 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
897
898 sisusb->sisusb_cursor_size_from = from;
899 sisusb->sisusb_cursor_size_to = to;
900 }
901
Arjan van de Ven2682d272006-03-28 01:00:21 -0800902 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200903}
904
905static int
906sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
907 int t, int b, int dir, int lines)
908{
909 int cols = sisusb->sisusb_num_columns;
910 int length = ((b - t) * cols) * 2;
911 u16 eattr = c->vc_video_erase_char;
912 ssize_t written;
913
914 /* sisusb->lock is down */
915
916 /* Scroll an area which does not match the
917 * visible screen's dimensions. This needs
918 * to be done separately, as it does not
919 * use hardware panning.
920 */
921
922 switch (dir) {
923
924 case SM_UP:
925 sisusbcon_memmovew(SISUSB_VADDR(0, t),
926 SISUSB_VADDR(0, t + lines),
927 (b - t - lines) * cols * 2);
928 sisusbcon_memsetw(SISUSB_VADDR(0, b - lines), eattr,
929 lines * cols * 2);
930 break;
931
932 case SM_DOWN:
933 sisusbcon_memmovew(SISUSB_VADDR(0, t + lines),
934 SISUSB_VADDR(0, t),
935 (b - t - lines) * cols * 2);
936 sisusbcon_memsetw(SISUSB_VADDR(0, t), eattr,
937 lines * cols * 2);
938 break;
939 }
940
941 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
942 (u32)SISUSB_HADDR(0, t), length, &written);
943
Arjan van de Ven2682d272006-03-28 01:00:21 -0800944 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200945
946 return 1;
947}
948
949/* Interface routine */
950static int
951sisusbcon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
952{
953 struct sisusb_usb_data *sisusb;
954 u16 eattr = c->vc_video_erase_char;
955 ssize_t written;
956 int copyall = 0;
957 unsigned long oldorigin;
958 unsigned int delta = lines * c->vc_size_row;
959 u32 originoffset;
960
961 /* Returning != 0 means we have done the scrolling successfully.
962 * Returning 0 makes vt do the scrolling on its own.
963 * Note that con_scroll is only called if the console is
964 * visible. In that case, the origin should be our buffer,
965 * not the vt's private one.
966 */
967
968 if (!lines)
969 return 1;
970
971 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
972 return 0;
973
974 /* sisusb->lock is down */
975
976 if (sisusb_is_inactive(c, sisusb)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -0800977 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +0200978 return 0;
979 }
980
981 /* Special case */
982 if (t || b != c->vc_rows)
983 return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
984
985 if (c->vc_origin != c->vc_visible_origin) {
986 c->vc_visible_origin = c->vc_origin;
987 sisusbcon_set_start_address(sisusb, c);
988 }
989
990 /* limit amount to maximum realistic size */
991 if (lines > c->vc_rows)
992 lines = c->vc_rows;
993
994 oldorigin = c->vc_origin;
995
996 switch (dir) {
997
998 case SM_UP:
999
1000 if (c->vc_scr_end + delta >=
1001 sisusb->scrbuf + sisusb->scrbuf_size) {
1002 sisusbcon_memcpyw((u16 *)sisusb->scrbuf,
1003 (u16 *)(oldorigin + delta),
1004 c->vc_screenbuf_size - delta);
1005 c->vc_origin = sisusb->scrbuf;
1006 sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
1007 copyall = 1;
1008 } else
1009 c->vc_origin += delta;
1010
1011 sisusbcon_memsetw(
1012 (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
1013 eattr, delta);
1014
1015 break;
1016
1017 case SM_DOWN:
1018
1019 if (oldorigin - delta < sisusb->scrbuf) {
1020 sisusbcon_memmovew((u16 *)(sisusb->scrbuf +
1021 sisusb->scrbuf_size -
1022 c->vc_screenbuf_size +
1023 delta),
1024 (u16 *)oldorigin,
1025 c->vc_screenbuf_size - delta);
1026 c->vc_origin = sisusb->scrbuf +
1027 sisusb->scrbuf_size -
1028 c->vc_screenbuf_size;
1029 sisusb->con_rolled_over = 0;
1030 copyall = 1;
1031 } else
1032 c->vc_origin -= delta;
1033
1034 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1035
1036 scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
1037
1038 break;
1039 }
1040
1041 originoffset = (u32)(c->vc_origin - sisusb->scrbuf);
1042
1043 if (copyall)
1044 sisusb_copy_memory(sisusb,
1045 (char *)c->vc_origin,
1046 (u32)(sisusb->vrambase + originoffset),
1047 c->vc_screenbuf_size, &written);
1048 else if (dir == SM_UP)
1049 sisusb_copy_memory(sisusb,
1050 (char *)c->vc_origin + c->vc_screenbuf_size - delta,
1051 (u32)sisusb->vrambase + originoffset +
1052 c->vc_screenbuf_size - delta,
1053 delta, &written);
1054 else
1055 sisusb_copy_memory(sisusb,
1056 (char *)c->vc_origin,
1057 (u32)(sisusb->vrambase + originoffset),
1058 delta, &written);
1059
1060 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1061 c->vc_visible_origin = c->vc_origin;
1062
1063 sisusbcon_set_start_address(sisusb, c);
1064
1065 c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
1066
Arjan van de Ven2682d272006-03-28 01:00:21 -08001067 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001068
1069 return 1;
1070}
1071
1072/* Interface routine */
1073static int
1074sisusbcon_set_origin(struct vc_data *c)
1075{
1076 struct sisusb_usb_data *sisusb;
1077
1078 /* Returning != 0 means we were successful.
1079 * Returning 0 will vt make to use its own
1080 * screenbuffer as the origin.
1081 */
1082
1083 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1084 return 0;
1085
1086 /* sisusb->lock is down */
1087
1088 if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001089 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001090 return 0;
1091 }
1092
1093 c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
1094
1095 sisusbcon_set_start_address(sisusb, c);
1096
1097 sisusb->con_rolled_over = 0;
1098
Arjan van de Ven2682d272006-03-28 01:00:21 -08001099 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001100
1101 return 1;
1102}
1103
1104/* Interface routine */
1105static int
1106sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows)
1107{
1108 struct sisusb_usb_data *sisusb;
1109 int fh;
1110
1111 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1112 return -ENODEV;
1113
1114 fh = sisusb->current_font_height;
1115
Arjan van de Ven2682d272006-03-28 01:00:21 -08001116 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001117
1118 /* We are quite unflexible as regards resizing. The vt code
1119 * handles sizes where the line length isn't equal the pitch
1120 * quite badly. As regards the rows, our panning tricks only
1121 * work well if the number of rows equals the visible number
1122 * of rows.
1123 */
1124
1125 if (newcols != 80 || c->vc_scan_lines / fh != newrows)
1126 return -EINVAL;
1127
1128 return 0;
1129}
1130
1131int
1132sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
1133 u8 *arg, int cmapsz, int ch512, int dorecalc,
1134 struct vc_data *c, int fh, int uplock)
1135{
1136 int font_select = 0x00, i, err = 0;
1137 u32 offset = 0;
1138 u8 dummy;
1139
1140 /* sisusb->lock is down */
1141
1142 /*
1143 * The default font is kept in slot 0.
1144 * A user font is loaded in slot 2 (256 ch)
1145 * or 2+3 (512 ch).
1146 */
1147
1148 if ((slot != 0 && slot != 2) || !fh) {
1149 if (uplock)
Arjan van de Ven2682d272006-03-28 01:00:21 -08001150 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001151 return -EINVAL;
1152 }
1153
1154 if (set)
1155 sisusb->font_slot = slot;
1156
1157 /* Default font is always 256 */
1158 if (slot == 0)
1159 ch512 = 0;
1160 else
1161 offset = 4 * cmapsz;
1162
1163 font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
1164
1165 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1166 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */
1167 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */
1168 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */
1169
1170 if (err)
1171 goto font_op_error;
1172
1173 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */
1174 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */
1175 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */
1176
1177 if (err)
1178 goto font_op_error;
1179
1180 if (arg) {
1181 if (set)
1182 for (i = 0; i < cmapsz; i++) {
1183 err |= sisusb_writeb(sisusb,
1184 sisusb->vrambase + offset + i,
1185 arg[i]);
1186 if (err)
1187 break;
1188 }
1189 else
1190 for (i = 0; i < cmapsz; i++) {
1191 err |= sisusb_readb(sisusb,
1192 sisusb->vrambase + offset + i,
1193 &arg[i]);
1194 if (err)
1195 break;
1196 }
1197
1198 /*
1199 * In 512-character mode, the character map is not contiguous if
1200 * we want to remain EGA compatible -- which we do
1201 */
1202
1203 if (ch512) {
1204 if (set)
1205 for (i = 0; i < cmapsz; i++) {
1206 err |= sisusb_writeb(sisusb,
1207 sisusb->vrambase + offset +
1208 (2 * cmapsz) + i,
1209 arg[cmapsz + i]);
1210 if (err)
1211 break;
1212 }
1213 else
1214 for (i = 0; i < cmapsz; i++) {
1215 err |= sisusb_readb(sisusb,
1216 sisusb->vrambase + offset +
1217 (2 * cmapsz) + i,
1218 &arg[cmapsz + i]);
1219 if (err)
1220 break;
1221 }
1222 }
1223 }
1224
1225 if (err)
1226 goto font_op_error;
1227
1228 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1229 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */
1230 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */
1231 if (set)
1232 sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
1233 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */
1234
1235 if (err)
1236 goto font_op_error;
1237
1238 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */
1239 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */
1240 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */
1241
1242 if (err)
1243 goto font_op_error;
1244
1245 if ((set) && (ch512 != sisusb->current_font_512)) {
1246
1247 /* Font is shared among all our consoles.
1248 * And so is the hi_font_mask.
1249 */
1250 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1251 struct vc_data *c = vc_cons[i].d;
1252 if (c && c->vc_sw == &sisusb_con)
1253 c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
1254 }
1255
1256 sisusb->current_font_512 = ch512;
1257
1258 /* color plane enable register:
1259 256-char: enable intensity bit
1260 512-char: disable intensity bit */
1261 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1262 sisusb_setreg(sisusb, SISAR, 0x12);
1263 sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
1264
1265 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1266 sisusb_setreg(sisusb, SISAR, 0x20);
1267 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1268 }
1269
1270 if (dorecalc) {
1271
1272 /*
1273 * Adjust the screen to fit a font of a certain height
1274 */
1275
1276 unsigned char ovr, vde, fsr;
1277 int rows = 0, maxscan = 0;
1278
1279 if (c) {
1280
1281 /* Number of video rows */
1282 rows = c->vc_scan_lines / fh;
1283 /* Scan lines to actually display-1 */
1284 maxscan = rows * fh - 1;
1285
1286 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1287 rows, maxscan, fh, c->vc_scan_lines);*/
1288
1289 sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
1290 vde = maxscan & 0xff;
1291 ovr = (ovr & 0xbd) |
1292 ((maxscan & 0x100) >> 7) |
1293 ((maxscan & 0x200) >> 3);
1294 sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
1295 sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
1296
1297 }
1298
1299 sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
1300 fsr = (fsr & 0xe0) | (fh - 1);
1301 sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
1302 sisusb->current_font_height = fh;
1303
1304 sisusb->sisusb_cursor_size_from = -1;
1305 sisusb->sisusb_cursor_size_to = -1;
1306
1307 }
1308
1309 if (uplock)
Arjan van de Ven2682d272006-03-28 01:00:21 -08001310 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001311
1312 if (dorecalc && c) {
1313 int i, rows = c->vc_scan_lines / fh;
1314
1315 /* Now adjust our consoles' size */
1316
1317 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1318 struct vc_data *vc = vc_cons[i].d;
1319
1320 if (vc && vc->vc_sw == &sisusb_con) {
1321 if (CON_IS_VISIBLE(vc)) {
1322 vc->vc_sw->con_cursor(vc, CM_DRAW);
1323 }
1324 vc->vc_font.height = fh;
1325 vc_resize(vc, 0, rows);
1326 }
1327 }
1328 }
1329
1330 return 0;
1331
1332font_op_error:
1333 if (uplock)
Arjan van de Ven2682d272006-03-28 01:00:21 -08001334 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001335
1336 return -EIO;
1337}
1338
1339/* Interface routine */
1340static int
1341sisusbcon_font_set(struct vc_data *c, struct console_font *font,
1342 unsigned flags)
1343{
1344 struct sisusb_usb_data *sisusb;
1345 unsigned charcount = font->charcount;
1346
1347 if (font->width != 8 || (charcount != 256 && charcount != 512))
1348 return -EINVAL;
1349
1350 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1351 return -ENODEV;
1352
1353 /* sisusb->lock is down */
1354
1355 /* Save the user-provided font into a buffer. This
1356 * is used for restoring text mode after quitting
1357 * from X and for the con_getfont routine.
1358 */
1359 if (sisusb->font_backup) {
1360 if (sisusb->font_backup_size < charcount) {
1361 vfree(sisusb->font_backup);
1362 sisusb->font_backup = NULL;
1363 }
1364 }
1365
1366 if (!sisusb->font_backup)
1367 sisusb->font_backup = vmalloc(charcount * 32);
1368
1369 if (sisusb->font_backup) {
1370 memcpy(sisusb->font_backup, font->data, charcount * 32);
1371 sisusb->font_backup_size = charcount;
1372 sisusb->font_backup_height = font->height;
1373 sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
1374 }
1375
1376 /* do_font_op ups sisusb->lock */
1377
1378 return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
1379 8192, (charcount == 512),
1380 (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
1381 c, font->height, 1);
1382}
1383
1384/* Interface routine */
1385static int
1386sisusbcon_font_get(struct vc_data *c, struct console_font *font)
1387{
1388 struct sisusb_usb_data *sisusb;
1389
1390 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1391 return -ENODEV;
1392
1393 /* sisusb->lock is down */
1394
1395 font->width = 8;
1396 font->height = c->vc_font.height;
1397 font->charcount = 256;
1398
1399 if (!font->data) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001400 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001401 return 0;
1402 }
1403
1404 if (!sisusb->font_backup) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001405 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001406 return -ENODEV;
1407 }
1408
1409 /* Copy 256 chars only, like vgacon */
1410 memcpy(font->data, sisusb->font_backup, 256 * 32);
1411
Arjan van de Ven2682d272006-03-28 01:00:21 -08001412 mutex_unlock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001413
1414 return 0;
1415}
1416
1417/*
1418 * The console `switch' structure for the sisusb console
1419 */
1420
1421static const struct consw sisusb_con = {
1422 .owner = THIS_MODULE,
1423 .con_startup = sisusbcon_startup,
1424 .con_init = sisusbcon_init,
1425 .con_deinit = sisusbcon_deinit,
1426 .con_clear = sisusbcon_clear,
1427 .con_putc = sisusbcon_putc,
1428 .con_putcs = sisusbcon_putcs,
1429 .con_cursor = sisusbcon_cursor,
1430 .con_scroll = sisusbcon_scroll,
1431 .con_bmove = sisusbcon_bmove,
1432 .con_switch = sisusbcon_switch,
1433 .con_blank = sisusbcon_blank,
1434 .con_font_set = sisusbcon_font_set,
1435 .con_font_get = sisusbcon_font_get,
1436 .con_set_palette = sisusbcon_set_palette,
1437 .con_scrolldelta = sisusbcon_scrolldelta,
1438 .con_build_attr = sisusbcon_build_attr,
1439 .con_invert_region = sisusbcon_invert_region,
1440 .con_set_origin = sisusbcon_set_origin,
1441 .con_save_screen = sisusbcon_save_screen,
1442 .con_resize = sisusbcon_resize,
1443};
1444
1445/* Our very own dummy console driver */
1446
1447static const char *sisusbdummycon_startup(void)
1448{
1449 return "SISUSBVGADUMMY";
1450}
1451
1452static void sisusbdummycon_init(struct vc_data *vc, int init)
1453{
1454 vc->vc_can_do_color = 1;
1455 if (init) {
1456 vc->vc_cols = 80;
1457 vc->vc_rows = 25;
1458 } else
1459 vc_resize(vc, 80, 25);
1460}
1461
1462static int sisusbdummycon_dummy(void)
1463{
1464 return 0;
1465}
1466
1467#define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
1468
Adrian Bunkdf47e532006-04-15 11:17:27 +02001469static const struct consw sisusb_dummy_con = {
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001470 .owner = THIS_MODULE,
1471 .con_startup = sisusbdummycon_startup,
1472 .con_init = sisusbdummycon_init,
1473 .con_deinit = SISUSBCONDUMMY,
1474 .con_clear = SISUSBCONDUMMY,
1475 .con_putc = SISUSBCONDUMMY,
1476 .con_putcs = SISUSBCONDUMMY,
1477 .con_cursor = SISUSBCONDUMMY,
1478 .con_scroll = SISUSBCONDUMMY,
1479 .con_bmove = SISUSBCONDUMMY,
1480 .con_switch = SISUSBCONDUMMY,
1481 .con_blank = SISUSBCONDUMMY,
1482 .con_font_set = SISUSBCONDUMMY,
1483 .con_font_get = SISUSBCONDUMMY,
1484 .con_font_default = SISUSBCONDUMMY,
1485 .con_font_copy = SISUSBCONDUMMY,
1486 .con_set_palette = SISUSBCONDUMMY,
1487 .con_scrolldelta = SISUSBCONDUMMY,
1488};
1489
1490int
1491sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
1492{
1493 int i, ret, minor = sisusb->minor;
1494
Arjan van de Ven2682d272006-03-28 01:00:21 -08001495 mutex_lock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001496
Arjan van de Ven2682d272006-03-28 01:00:21 -08001497 mutex_lock(&sisusb->lock);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001498
1499 /* Erm.. that should not happen */
1500 if (sisusb->haveconsole || !sisusb->SiS_Pr) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001501 mutex_unlock(&sisusb->lock);
1502 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001503 return 1;
1504 }
1505
1506 sisusb->con_first = first;
1507 sisusb->con_last = last;
1508
1509 if (first > last ||
1510 first > MAX_NR_CONSOLES ||
1511 last > MAX_NR_CONSOLES) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001512 mutex_unlock(&sisusb->lock);
1513 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001514 return 1;
1515 }
1516
1517 /* If gfxcore not initialized or no consoles given, quit graciously */
1518 if (!sisusb->gfxinit || first < 1 || last < 1) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001519 mutex_unlock(&sisusb->lock);
1520 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001521 return 0;
1522 }
1523
1524 sisusb->sisusb_cursor_loc = -1;
1525 sisusb->sisusb_cursor_size_from = -1;
1526 sisusb->sisusb_cursor_size_to = -1;
1527
1528 /* Set up text mode (and upload default font) */
1529 if (sisusb_reset_text_mode(sisusb, 1)) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001530 mutex_unlock(&sisusb->lock);
1531 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001532 printk(KERN_ERR
1533 "sisusbvga[%d]: Failed to set up text mode\n",
1534 minor);
1535 return 1;
1536 }
1537
1538 /* Initialize some gfx registers */
1539 sisusb_initialize(sisusb);
1540
1541 for (i = first - 1; i <= last - 1; i++) {
1542 /* Save sisusb for our interface routines */
1543 mysisusbs[i] = sisusb;
1544 }
1545
1546 /* Initial console setup */
1547 sisusb->sisusb_num_columns = 80;
1548
1549 /* Use a 32K buffer (matches b8000-bffff area) */
1550 sisusb->scrbuf_size = 32 * 1024;
1551
1552 /* Allocate screen buffer */
1553 if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
Arjan van de Ven2682d272006-03-28 01:00:21 -08001554 mutex_unlock(&sisusb->lock);
1555 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001556 printk(KERN_ERR
1557 "sisusbvga[%d]: Failed to allocate screen buffer\n",
1558 minor);
1559 return 1;
1560 }
1561
Arjan van de Ven2682d272006-03-28 01:00:21 -08001562 mutex_unlock(&sisusb->lock);
1563 mutex_unlock(&disconnect_mutex);
Thomas Winischhofer1bbb4f22005-08-29 17:01:16 +02001564
1565 /* Now grab the desired console(s) */
1566 ret = take_over_console(&sisusb_con, first - 1, last - 1, 0);
1567
1568 if (!ret)
1569 sisusb->haveconsole = 1;
1570 else {
1571 for (i = first - 1; i <= last - 1; i++)
1572 mysisusbs[i] = NULL;
1573 }
1574
1575 return ret;
1576}
1577
1578void
1579sisusb_console_exit(struct sisusb_usb_data *sisusb)
1580{
1581 int i;
1582
1583 /* This is called if the device is disconnected
1584 * and while disconnect and lock semaphores
1585 * are up. This should be save because we
1586 * can't lose our sisusb any other way but by
1587 * disconnection (and hence, the disconnect
1588 * sema is for protecting all other access
1589 * functions from disconnection, not the
1590 * other way round).
1591 */
1592
1593 /* Now what do we do in case of disconnection:
1594 * One alternative would be to simply call
1595 * give_up_console(). Nah, not a good idea.
1596 * give_up_console() is obviously buggy as it
1597 * only discards the consw pointer from the
1598 * driver_map, but doesn't adapt vc->vc_sw
1599 * of the affected consoles. Hence, the next
1600 * call to any of the console functions will
1601 * eventually take a trip to oops county.
1602 * Also, give_up_console for some reason
1603 * doesn't decrement our module refcount.
1604 * Instead, we switch our consoles to a private
1605 * dummy console. This, of course, keeps our
1606 * refcount up as well, but it works perfectly.
1607 */
1608
1609 if (sisusb->haveconsole) {
1610 for (i = 0; i < MAX_NR_CONSOLES; i++)
1611 if (sisusb->havethisconsole[i])
1612 take_over_console(&sisusb_dummy_con, i, i, 0);
1613 /* At this point, con_deinit for all our
1614 * consoles is executed by take_over_console().
1615 */
1616 sisusb->haveconsole = 0;
1617 }
1618
1619 vfree((void *)sisusb->scrbuf);
1620 sisusb->scrbuf = 0;
1621
1622 vfree(sisusb->font_backup);
1623 sisusb->font_backup = NULL;
1624}
1625
1626void __init sisusb_init_concode(void)
1627{
1628 int i;
1629
1630 for (i = 0; i < MAX_NR_CONSOLES; i++)
1631 mysisusbs[i] = NULL;
1632}
1633
1634#endif /* INCL_CON */
1635
1636
1637