header cleaning: don't include smp_lock.h when not used
[usb.git] / drivers / usb / misc / sisusbvga / sisusb_con.c
blobef6c727ef5ef70fcd8b05cb681ffc54583378347
1 /*
2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
4 * VGA text mode console part
6 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
8 * If distributed as part of the Linux kernel, this code is licensed under the
9 * terms of the GPL v2.
11 * Otherwise, the following license terms apply:
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.
35 * Author: Thomas Winischhofer <thomas@winischhofer.net>
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
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.
50 #include <linux/mutex.h>
51 #include <linux/module.h>
52 #include <linux/kernel.h>
53 #include <linux/signal.h>
54 #include <linux/fs.h>
55 #include <linux/tty.h>
56 #include <linux/console.h>
57 #include <linux/string.h>
58 #include <linux/kd.h>
59 #include <linux/init.h>
60 #include <linux/slab.h>
61 #include <linux/vt_kern.h>
62 #include <linux/selection.h>
63 #include <linux/spinlock.h>
64 #include <linux/kref.h>
65 #include <linux/ioport.h>
66 #include <linux/interrupt.h>
67 #include <linux/vmalloc.h>
69 #include "sisusb.h"
70 #include "sisusb_init.h"
72 #ifdef INCL_SISUSB_CON
74 #define sisusbcon_writew(val, addr) (*(addr) = (val))
75 #define sisusbcon_readw(addr) (*(addr))
76 #define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
77 #define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
79 /* vc_data -> sisusb conversion table */
80 static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
82 /* Forward declaration */
83 static const struct consw sisusb_con;
85 static inline void
86 sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
88 count /= 2;
89 while (count--)
90 sisusbcon_writew(c, s++);
93 static inline void
94 sisusb_initialize(struct sisusb_usb_data *sisusb)
96 /* Reset cursor and start address */
97 if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
98 return;
99 if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
100 return;
101 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
102 return;
103 sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
106 static inline void
107 sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
109 sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
111 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
112 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
115 void
116 sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
118 if (sisusb->sisusb_cursor_loc == location)
119 return;
121 sisusb->sisusb_cursor_loc = location;
123 /* Hardware bug: Text cursor appears twice or not at all
124 * at some positions. Work around it with the cursor skew
125 * bits.
128 if ((location & 0x0007) == 0x0007) {
129 sisusb->bad_cursor_pos = 1;
130 location--;
131 if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
132 return;
133 } else if (sisusb->bad_cursor_pos) {
134 if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
135 return;
136 sisusb->bad_cursor_pos = 0;
139 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
140 return;
141 sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
144 static inline struct sisusb_usb_data *
145 sisusb_get_sisusb(unsigned short console)
147 return mysisusbs[console];
150 static inline int
151 sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
153 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
154 return 0;
156 return 1;
159 static struct sisusb_usb_data *
160 sisusb_get_sisusb_lock_and_check(unsigned short console)
162 struct sisusb_usb_data *sisusb;
164 /* We can't handle console calls in non-schedulable
165 * context due to our locks and the USB transport.
166 * So we simply ignore them. This should only affect
167 * some calls to printk.
169 if (in_atomic())
170 return NULL;
172 if (!(sisusb = sisusb_get_sisusb(console)))
173 return NULL;
175 mutex_lock(&sisusb->lock);
177 if (!sisusb_sisusb_valid(sisusb) ||
178 !sisusb->havethisconsole[console]) {
179 mutex_unlock(&sisusb->lock);
180 return NULL;
183 return sisusb;
186 static int
187 sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
189 if (sisusb->is_gfx ||
190 sisusb->textmodedestroyed ||
191 c->vc_mode != KD_TEXT)
192 return 1;
194 return 0;
197 /* con_startup console interface routine */
198 static const char *
199 sisusbcon_startup(void)
201 return "SISUSBCON";
204 /* con_init console interface routine */
205 static void
206 sisusbcon_init(struct vc_data *c, int init)
208 struct sisusb_usb_data *sisusb;
209 int cols, rows;
211 /* This is called by take_over_console(),
212 * ie by us/under our control. It is
213 * only called after text mode and fonts
214 * are set up/restored.
217 mutex_lock(&disconnect_mutex);
219 if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
220 mutex_unlock(&disconnect_mutex);
221 return;
224 mutex_lock(&sisusb->lock);
226 if (!sisusb_sisusb_valid(sisusb)) {
227 mutex_unlock(&sisusb->lock);
228 mutex_unlock(&disconnect_mutex);
229 return;
232 c->vc_can_do_color = 1;
234 c->vc_complement_mask = 0x7700;
236 c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
238 sisusb->haveconsole = 1;
240 sisusb->havethisconsole[c->vc_num] = 1;
242 /* We only support 640x400 */
243 c->vc_scan_lines = 400;
245 c->vc_font.height = sisusb->current_font_height;
247 /* We only support width = 8 */
248 cols = 80;
249 rows = c->vc_scan_lines / c->vc_font.height;
251 /* Increment usage count for our sisusb.
252 * Doing so saves us from upping/downing
253 * the disconnect semaphore; we can't
254 * lose our sisusb until this is undone
255 * in con_deinit. For all other console
256 * interface functions, it suffices to
257 * use sisusb->lock and do a quick check
258 * of sisusb for device disconnection.
260 kref_get(&sisusb->kref);
262 if (!*c->vc_uni_pagedir_loc)
263 con_set_default_unimap(c);
265 mutex_unlock(&sisusb->lock);
267 mutex_unlock(&disconnect_mutex);
269 if (init) {
270 c->vc_cols = cols;
271 c->vc_rows = rows;
272 } else
273 vc_resize(c, cols, rows);
276 /* con_deinit console interface routine */
277 static void
278 sisusbcon_deinit(struct vc_data *c)
280 struct sisusb_usb_data *sisusb;
281 int i;
283 /* This is called by take_over_console()
284 * and others, ie not under our control.
287 mutex_lock(&disconnect_mutex);
289 if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
290 mutex_unlock(&disconnect_mutex);
291 return;
294 mutex_lock(&sisusb->lock);
296 /* Clear ourselves in mysisusbs */
297 mysisusbs[c->vc_num] = NULL;
299 sisusb->havethisconsole[c->vc_num] = 0;
301 /* Free our font buffer if all consoles are gone */
302 if (sisusb->font_backup) {
303 for(i = 0; i < MAX_NR_CONSOLES; i++) {
304 if (sisusb->havethisconsole[c->vc_num])
305 break;
307 if (i == MAX_NR_CONSOLES) {
308 vfree(sisusb->font_backup);
309 sisusb->font_backup = NULL;
313 mutex_unlock(&sisusb->lock);
315 /* decrement the usage count on our sisusb */
316 kref_put(&sisusb->kref, sisusb_delete);
318 mutex_unlock(&disconnect_mutex);
321 /* interface routine */
322 static u8
323 sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
324 u8 blink, u8 underline, u8 reverse)
326 u8 attr = color;
328 if (underline)
329 attr = (attr & 0xf0) | c->vc_ulcolor;
330 else if (intensity == 0)
331 attr = (attr & 0xf0) | c->vc_halfcolor;
333 if (reverse)
334 attr = ((attr) & 0x88) |
335 ((((attr) >> 4) |
336 ((attr) << 4)) & 0x77);
338 if (blink)
339 attr ^= 0x80;
341 if (intensity == 2)
342 attr ^= 0x08;
344 return attr;
347 /* Interface routine */
348 static void
349 sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
351 /* Invert a region. This is called with a pointer
352 * to the console's internal screen buffer. So we
353 * simply do the inversion there and rely on
354 * a call to putc(s) to update the real screen.
357 while (count--) {
358 u16 a = sisusbcon_readw(p);
360 a = ((a) & 0x88ff) |
361 (((a) & 0x7000) >> 4) |
362 (((a) & 0x0700) << 4);
364 sisusbcon_writew(a, p++);
368 #define SISUSB_VADDR(x,y) \
369 ((u16 *)c->vc_origin + \
370 (y) * sisusb->sisusb_num_columns + \
371 (x))
373 #define SISUSB_HADDR(x,y) \
374 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
375 (y) * sisusb->sisusb_num_columns + \
376 (x))
378 /* Interface routine */
379 static void
380 sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
382 struct sisusb_usb_data *sisusb;
383 ssize_t written;
385 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
386 return;
388 /* sisusb->lock is down */
390 /* Don't need to put the character into buffer ourselves,
391 * because the vt does this BEFORE calling us.
393 #if 0
394 sisusbcon_writew(ch, SISUSB_VADDR(x, y));
395 #endif
397 if (sisusb_is_inactive(c, sisusb)) {
398 mutex_unlock(&sisusb->lock);
399 return;
403 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
404 (long)SISUSB_HADDR(x, y), 2, &written);
406 mutex_unlock(&sisusb->lock);
409 /* Interface routine */
410 static void
411 sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
412 int count, int y, int x)
414 struct sisusb_usb_data *sisusb;
415 ssize_t written;
416 u16 *dest;
417 int i;
419 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
420 return;
422 /* sisusb->lock is down */
424 /* Need to put the characters into the buffer ourselves,
425 * because the vt does this AFTER calling us.
428 dest = SISUSB_VADDR(x, y);
430 for (i = count; i > 0; i--)
431 sisusbcon_writew(sisusbcon_readw(s++), dest++);
433 if (sisusb_is_inactive(c, sisusb)) {
434 mutex_unlock(&sisusb->lock);
435 return;
438 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
439 (long)SISUSB_HADDR(x, y), count * 2, &written);
441 mutex_unlock(&sisusb->lock);
444 /* Interface routine */
445 static void
446 sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
448 struct sisusb_usb_data *sisusb;
449 u16 eattr = c->vc_video_erase_char;
450 ssize_t written;
451 int i, length, cols;
452 u16 *dest;
454 if (width <= 0 || height <= 0)
455 return;
457 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
458 return;
460 /* sisusb->lock is down */
462 /* Need to clear buffer ourselves, because the vt does
463 * this AFTER calling us.
466 dest = SISUSB_VADDR(x, y);
468 cols = sisusb->sisusb_num_columns;
470 if (width > cols)
471 width = cols;
473 if (x == 0 && width >= c->vc_cols) {
475 sisusbcon_memsetw(dest, eattr, height * cols * 2);
477 } else {
479 for (i = height; i > 0; i--, dest += cols)
480 sisusbcon_memsetw(dest, eattr, width * 2);
484 if (sisusb_is_inactive(c, sisusb)) {
485 mutex_unlock(&sisusb->lock);
486 return;
489 length = ((height * cols) - x - (cols - width - x)) * 2;
492 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
493 (long)SISUSB_HADDR(x, y), length, &written);
495 mutex_unlock(&sisusb->lock);
498 /* Interface routine */
499 static void
500 sisusbcon_bmove(struct vc_data *c, int sy, int sx,
501 int dy, int dx, int height, int width)
503 struct sisusb_usb_data *sisusb;
504 ssize_t written;
505 int cols, length;
506 #if 0
507 u16 *src, *dest;
508 int i;
509 #endif
511 if (width <= 0 || height <= 0)
512 return;
514 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
515 return;
517 /* sisusb->lock is down */
519 cols = sisusb->sisusb_num_columns;
521 /* Don't need to move data outselves, because
522 * vt does this BEFORE calling us.
523 * This is only used by vt's insert/deletechar.
525 #if 0
526 if (sx == 0 && dx == 0 && width >= c->vc_cols && width <= cols) {
528 sisusbcon_memmovew(SISUSB_VADDR(0, dy), SISUSB_VADDR(0, sy),
529 height * width * 2);
531 } else if (dy < sy || (dy == sy && dx < sx)) {
533 src = SISUSB_VADDR(sx, sy);
534 dest = SISUSB_VADDR(dx, dy);
536 for (i = height; i > 0; i--) {
537 sisusbcon_memmovew(dest, src, width * 2);
538 src += cols;
539 dest += cols;
542 } else {
544 src = SISUSB_VADDR(sx, sy + height - 1);
545 dest = SISUSB_VADDR(dx, dy + height - 1);
547 for (i = height; i > 0; i--) {
548 sisusbcon_memmovew(dest, src, width * 2);
549 src -= cols;
550 dest -= cols;
554 #endif
556 if (sisusb_is_inactive(c, sisusb)) {
557 mutex_unlock(&sisusb->lock);
558 return;
561 length = ((height * cols) - dx - (cols - width - dx)) * 2;
564 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy),
565 (long)SISUSB_HADDR(dx, dy), length, &written);
567 mutex_unlock(&sisusb->lock);
570 /* interface routine */
571 static int
572 sisusbcon_switch(struct vc_data *c)
574 struct sisusb_usb_data *sisusb;
575 ssize_t written;
576 int length;
578 /* Returnvalue 0 means we have fully restored screen,
579 * and vt doesn't need to call do_update_region().
580 * Returnvalue != 0 naturally means the opposite.
583 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
584 return 0;
586 /* sisusb->lock is down */
588 /* Don't write to screen if in gfx mode */
589 if (sisusb_is_inactive(c, sisusb)) {
590 mutex_unlock(&sisusb->lock);
591 return 0;
594 /* That really should not happen. It would mean we are
595 * being called while the vc is using its private buffer
596 * as origin.
598 if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
599 mutex_unlock(&sisusb->lock);
600 printk(KERN_DEBUG "sisusb: ASSERT ORIGIN != SCREENBUF!\n");
601 return 0;
604 /* Check that we don't copy too much */
605 length = min((int)c->vc_screenbuf_size,
606 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
608 /* Restore the screen contents */
609 sisusbcon_memcpyw((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf,
610 length);
612 sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
613 (long)SISUSB_HADDR(0, 0),
614 length, &written);
616 mutex_unlock(&sisusb->lock);
618 return 0;
621 /* interface routine */
622 static void
623 sisusbcon_save_screen(struct vc_data *c)
625 struct sisusb_usb_data *sisusb;
626 int length;
628 /* Save the current screen contents to vc's private
629 * buffer.
632 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
633 return;
635 /* sisusb->lock is down */
637 if (sisusb_is_inactive(c, sisusb)) {
638 mutex_unlock(&sisusb->lock);
639 return;
642 /* Check that we don't copy too much */
643 length = min((int)c->vc_screenbuf_size,
644 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
646 /* Save the screen contents to vc's private buffer */
647 sisusbcon_memcpyw((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin,
648 length);
650 mutex_unlock(&sisusb->lock);
653 /* interface routine */
654 static int
655 sisusbcon_set_palette(struct vc_data *c, unsigned char *table)
657 struct sisusb_usb_data *sisusb;
658 int i, j;
660 /* Return value not used by vt */
662 if (!CON_IS_VISIBLE(c))
663 return -EINVAL;
665 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
666 return -EINVAL;
668 /* sisusb->lock is down */
670 if (sisusb_is_inactive(c, sisusb)) {
671 mutex_unlock(&sisusb->lock);
672 return -EINVAL;
675 for (i = j = 0; i < 16; i++) {
676 if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
677 break;
678 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
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;
686 mutex_unlock(&sisusb->lock);
688 return 0;
691 /* interface routine */
692 static int
693 sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
695 struct sisusb_usb_data *sisusb;
696 u8 sr1, cr17, pmreg, cr63;
697 ssize_t written;
698 int ret = 0;
700 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
701 return 0;
703 /* sisusb->lock is down */
705 if (mode_switch)
706 sisusb->is_gfx = blank ? 1 : 0;
708 if (sisusb_is_inactive(c, sisusb)) {
709 mutex_unlock(&sisusb->lock);
710 return 0;
713 switch (blank) {
715 case 1: /* Normal blanking: Clear screen */
716 case -1:
717 sisusbcon_memsetw((u16 *)c->vc_origin,
718 c->vc_video_erase_char,
719 c->vc_screenbuf_size);
720 sisusb_copy_memory(sisusb,
721 (unsigned char *)c->vc_origin,
722 (u32)(sisusb->vrambase +
723 (c->vc_origin - sisusb->scrbuf)),
724 c->vc_screenbuf_size, &written);
725 sisusb->con_blanked = 1;
726 ret = 1;
727 break;
729 default: /* VESA blanking */
730 switch (blank) {
731 case 0: /* Unblank */
732 sr1 = 0x00;
733 cr17 = 0x80;
734 pmreg = 0x00;
735 cr63 = 0x00;
736 ret = 1;
737 sisusb->con_blanked = 0;
738 break;
739 case VESA_VSYNC_SUSPEND + 1:
740 sr1 = 0x20;
741 cr17 = 0x80;
742 pmreg = 0x80;
743 cr63 = 0x40;
744 break;
745 case VESA_HSYNC_SUSPEND + 1:
746 sr1 = 0x20;
747 cr17 = 0x80;
748 pmreg = 0x40;
749 cr63 = 0x40;
750 break;
751 case VESA_POWERDOWN + 1:
752 sr1 = 0x20;
753 cr17 = 0x00;
754 pmreg = 0xc0;
755 cr63 = 0x40;
756 break;
757 default:
758 mutex_unlock(&sisusb->lock);
759 return -EINVAL;
762 sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
763 sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
764 sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
765 sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
769 mutex_unlock(&sisusb->lock);
771 return ret;
774 /* interface routine */
775 static int
776 sisusbcon_scrolldelta(struct vc_data *c, int lines)
778 struct sisusb_usb_data *sisusb;
779 int margin = c->vc_size_row * 4;
780 int ul, we, p, st;
782 /* The return value does not seem to be used */
784 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
785 return 0;
787 /* sisusb->lock is down */
789 if (sisusb_is_inactive(c, sisusb)) {
790 mutex_unlock(&sisusb->lock);
791 return 0;
794 if (!lines) /* Turn scrollback off */
795 c->vc_visible_origin = c->vc_origin;
796 else {
798 if (sisusb->con_rolled_over >
799 (c->vc_scr_end - sisusb->scrbuf) + margin) {
801 ul = c->vc_scr_end - sisusb->scrbuf;
802 we = sisusb->con_rolled_over + c->vc_size_row;
804 } else {
806 ul = 0;
807 we = sisusb->scrbuf_size;
811 p = (c->vc_visible_origin - sisusb->scrbuf - ul + we) % we +
812 lines * c->vc_size_row;
814 st = (c->vc_origin - sisusb->scrbuf - ul + we) % we;
816 if (st < 2 * margin)
817 margin = 0;
819 if (p < margin)
820 p = 0;
822 if (p > st - margin)
823 p = st;
825 c->vc_visible_origin = sisusb->scrbuf + (p + ul) % we;
828 sisusbcon_set_start_address(sisusb, c);
830 mutex_unlock(&sisusb->lock);
832 return 1;
835 /* Interface routine */
836 static void
837 sisusbcon_cursor(struct vc_data *c, int mode)
839 struct sisusb_usb_data *sisusb;
840 int from, to, baseline;
842 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
843 return;
845 /* sisusb->lock is down */
847 if (sisusb_is_inactive(c, sisusb)) {
848 mutex_unlock(&sisusb->lock);
849 return;
852 if (c->vc_origin != c->vc_visible_origin) {
853 c->vc_visible_origin = c->vc_origin;
854 sisusbcon_set_start_address(sisusb, c);
857 if (mode == CM_ERASE) {
858 sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
859 sisusb->sisusb_cursor_size_to = -1;
860 mutex_unlock(&sisusb->lock);
861 return;
864 sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
866 baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
868 switch (c->vc_cursor_type & 0x0f) {
869 case CUR_BLOCK: from = 1;
870 to = c->vc_font.height;
871 break;
872 case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
873 to = baseline;
874 break;
875 case CUR_LOWER_HALF: from = c->vc_font.height / 2;
876 to = baseline;
877 break;
878 case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
879 to = baseline;
880 break;
881 case CUR_NONE: from = 31;
882 to = 30;
883 break;
884 default:
885 case CUR_UNDERLINE: from = baseline - 1;
886 to = baseline;
887 break;
890 if (sisusb->sisusb_cursor_size_from != from ||
891 sisusb->sisusb_cursor_size_to != to) {
893 sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
894 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
896 sisusb->sisusb_cursor_size_from = from;
897 sisusb->sisusb_cursor_size_to = to;
900 mutex_unlock(&sisusb->lock);
903 static int
904 sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
905 int t, int b, int dir, int lines)
907 int cols = sisusb->sisusb_num_columns;
908 int length = ((b - t) * cols) * 2;
909 u16 eattr = c->vc_video_erase_char;
910 ssize_t written;
912 /* sisusb->lock is down */
914 /* Scroll an area which does not match the
915 * visible screen's dimensions. This needs
916 * to be done separately, as it does not
917 * use hardware panning.
920 switch (dir) {
922 case SM_UP:
923 sisusbcon_memmovew(SISUSB_VADDR(0, t),
924 SISUSB_VADDR(0, t + lines),
925 (b - t - lines) * cols * 2);
926 sisusbcon_memsetw(SISUSB_VADDR(0, b - lines), eattr,
927 lines * cols * 2);
928 break;
930 case SM_DOWN:
931 sisusbcon_memmovew(SISUSB_VADDR(0, t + lines),
932 SISUSB_VADDR(0, t),
933 (b - t - lines) * cols * 2);
934 sisusbcon_memsetw(SISUSB_VADDR(0, t), eattr,
935 lines * cols * 2);
936 break;
939 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
940 (long)SISUSB_HADDR(0, t), length, &written);
942 mutex_unlock(&sisusb->lock);
944 return 1;
947 /* Interface routine */
948 static int
949 sisusbcon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
951 struct sisusb_usb_data *sisusb;
952 u16 eattr = c->vc_video_erase_char;
953 ssize_t written;
954 int copyall = 0;
955 unsigned long oldorigin;
956 unsigned int delta = lines * c->vc_size_row;
957 u32 originoffset;
959 /* Returning != 0 means we have done the scrolling successfully.
960 * Returning 0 makes vt do the scrolling on its own.
961 * Note that con_scroll is only called if the console is
962 * visible. In that case, the origin should be our buffer,
963 * not the vt's private one.
966 if (!lines)
967 return 1;
969 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
970 return 0;
972 /* sisusb->lock is down */
974 if (sisusb_is_inactive(c, sisusb)) {
975 mutex_unlock(&sisusb->lock);
976 return 0;
979 /* Special case */
980 if (t || b != c->vc_rows)
981 return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
983 if (c->vc_origin != c->vc_visible_origin) {
984 c->vc_visible_origin = c->vc_origin;
985 sisusbcon_set_start_address(sisusb, c);
988 /* limit amount to maximum realistic size */
989 if (lines > c->vc_rows)
990 lines = c->vc_rows;
992 oldorigin = c->vc_origin;
994 switch (dir) {
996 case SM_UP:
998 if (c->vc_scr_end + delta >=
999 sisusb->scrbuf + sisusb->scrbuf_size) {
1000 sisusbcon_memcpyw((u16 *)sisusb->scrbuf,
1001 (u16 *)(oldorigin + delta),
1002 c->vc_screenbuf_size - delta);
1003 c->vc_origin = sisusb->scrbuf;
1004 sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
1005 copyall = 1;
1006 } else
1007 c->vc_origin += delta;
1009 sisusbcon_memsetw(
1010 (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
1011 eattr, delta);
1013 break;
1015 case SM_DOWN:
1017 if (oldorigin - delta < sisusb->scrbuf) {
1018 sisusbcon_memmovew((u16 *)(sisusb->scrbuf +
1019 sisusb->scrbuf_size -
1020 c->vc_screenbuf_size +
1021 delta),
1022 (u16 *)oldorigin,
1023 c->vc_screenbuf_size - delta);
1024 c->vc_origin = sisusb->scrbuf +
1025 sisusb->scrbuf_size -
1026 c->vc_screenbuf_size;
1027 sisusb->con_rolled_over = 0;
1028 copyall = 1;
1029 } else
1030 c->vc_origin -= delta;
1032 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1034 scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
1036 break;
1039 originoffset = (u32)(c->vc_origin - sisusb->scrbuf);
1041 if (copyall)
1042 sisusb_copy_memory(sisusb,
1043 (char *)c->vc_origin,
1044 (u32)(sisusb->vrambase + originoffset),
1045 c->vc_screenbuf_size, &written);
1046 else if (dir == SM_UP)
1047 sisusb_copy_memory(sisusb,
1048 (char *)c->vc_origin + c->vc_screenbuf_size - delta,
1049 (u32)sisusb->vrambase + originoffset +
1050 c->vc_screenbuf_size - delta,
1051 delta, &written);
1052 else
1053 sisusb_copy_memory(sisusb,
1054 (char *)c->vc_origin,
1055 (u32)(sisusb->vrambase + originoffset),
1056 delta, &written);
1058 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1059 c->vc_visible_origin = c->vc_origin;
1061 sisusbcon_set_start_address(sisusb, c);
1063 c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
1065 mutex_unlock(&sisusb->lock);
1067 return 1;
1070 /* Interface routine */
1071 static int
1072 sisusbcon_set_origin(struct vc_data *c)
1074 struct sisusb_usb_data *sisusb;
1076 /* Returning != 0 means we were successful.
1077 * Returning 0 will vt make to use its own
1078 * screenbuffer as the origin.
1081 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1082 return 0;
1084 /* sisusb->lock is down */
1086 if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
1087 mutex_unlock(&sisusb->lock);
1088 return 0;
1091 c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
1093 sisusbcon_set_start_address(sisusb, c);
1095 sisusb->con_rolled_over = 0;
1097 mutex_unlock(&sisusb->lock);
1099 return 1;
1102 /* Interface routine */
1103 static int
1104 sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows)
1106 struct sisusb_usb_data *sisusb;
1107 int fh;
1109 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1110 return -ENODEV;
1112 fh = sisusb->current_font_height;
1114 mutex_unlock(&sisusb->lock);
1116 /* We are quite unflexible as regards resizing. The vt code
1117 * handles sizes where the line length isn't equal the pitch
1118 * quite badly. As regards the rows, our panning tricks only
1119 * work well if the number of rows equals the visible number
1120 * of rows.
1123 if (newcols != 80 || c->vc_scan_lines / fh != newrows)
1124 return -EINVAL;
1126 return 0;
1130 sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
1131 u8 *arg, int cmapsz, int ch512, int dorecalc,
1132 struct vc_data *c, int fh, int uplock)
1134 int font_select = 0x00, i, err = 0;
1135 u32 offset = 0;
1136 u8 dummy;
1138 /* sisusb->lock is down */
1141 * The default font is kept in slot 0.
1142 * A user font is loaded in slot 2 (256 ch)
1143 * or 2+3 (512 ch).
1146 if ((slot != 0 && slot != 2) || !fh) {
1147 if (uplock)
1148 mutex_unlock(&sisusb->lock);
1149 return -EINVAL;
1152 if (set)
1153 sisusb->font_slot = slot;
1155 /* Default font is always 256 */
1156 if (slot == 0)
1157 ch512 = 0;
1158 else
1159 offset = 4 * cmapsz;
1161 font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
1163 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1164 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */
1165 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */
1166 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */
1168 if (err)
1169 goto font_op_error;
1171 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */
1172 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */
1173 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */
1175 if (err)
1176 goto font_op_error;
1178 if (arg) {
1179 if (set)
1180 for (i = 0; i < cmapsz; i++) {
1181 err |= sisusb_writeb(sisusb,
1182 sisusb->vrambase + offset + i,
1183 arg[i]);
1184 if (err)
1185 break;
1187 else
1188 for (i = 0; i < cmapsz; i++) {
1189 err |= sisusb_readb(sisusb,
1190 sisusb->vrambase + offset + i,
1191 &arg[i]);
1192 if (err)
1193 break;
1197 * In 512-character mode, the character map is not contiguous if
1198 * we want to remain EGA compatible -- which we do
1201 if (ch512) {
1202 if (set)
1203 for (i = 0; i < cmapsz; i++) {
1204 err |= sisusb_writeb(sisusb,
1205 sisusb->vrambase + offset +
1206 (2 * cmapsz) + i,
1207 arg[cmapsz + i]);
1208 if (err)
1209 break;
1211 else
1212 for (i = 0; i < cmapsz; i++) {
1213 err |= sisusb_readb(sisusb,
1214 sisusb->vrambase + offset +
1215 (2 * cmapsz) + i,
1216 &arg[cmapsz + i]);
1217 if (err)
1218 break;
1223 if (err)
1224 goto font_op_error;
1226 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1227 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */
1228 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */
1229 if (set)
1230 sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
1231 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */
1233 if (err)
1234 goto font_op_error;
1236 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */
1237 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */
1238 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */
1240 if (err)
1241 goto font_op_error;
1243 if ((set) && (ch512 != sisusb->current_font_512)) {
1245 /* Font is shared among all our consoles.
1246 * And so is the hi_font_mask.
1248 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1249 struct vc_data *c = vc_cons[i].d;
1250 if (c && c->vc_sw == &sisusb_con)
1251 c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
1254 sisusb->current_font_512 = ch512;
1256 /* color plane enable register:
1257 256-char: enable intensity bit
1258 512-char: disable intensity bit */
1259 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1260 sisusb_setreg(sisusb, SISAR, 0x12);
1261 sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
1263 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1264 sisusb_setreg(sisusb, SISAR, 0x20);
1265 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1268 if (dorecalc) {
1271 * Adjust the screen to fit a font of a certain height
1274 unsigned char ovr, vde, fsr;
1275 int rows = 0, maxscan = 0;
1277 if (c) {
1279 /* Number of video rows */
1280 rows = c->vc_scan_lines / fh;
1281 /* Scan lines to actually display-1 */
1282 maxscan = rows * fh - 1;
1284 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1285 rows, maxscan, fh, c->vc_scan_lines);*/
1287 sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
1288 vde = maxscan & 0xff;
1289 ovr = (ovr & 0xbd) |
1290 ((maxscan & 0x100) >> 7) |
1291 ((maxscan & 0x200) >> 3);
1292 sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
1293 sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
1297 sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
1298 fsr = (fsr & 0xe0) | (fh - 1);
1299 sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
1300 sisusb->current_font_height = fh;
1302 sisusb->sisusb_cursor_size_from = -1;
1303 sisusb->sisusb_cursor_size_to = -1;
1307 if (uplock)
1308 mutex_unlock(&sisusb->lock);
1310 if (dorecalc && c) {
1311 int i, rows = c->vc_scan_lines / fh;
1313 /* Now adjust our consoles' size */
1315 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1316 struct vc_data *vc = vc_cons[i].d;
1318 if (vc && vc->vc_sw == &sisusb_con) {
1319 if (CON_IS_VISIBLE(vc)) {
1320 vc->vc_sw->con_cursor(vc, CM_DRAW);
1322 vc->vc_font.height = fh;
1323 vc_resize(vc, 0, rows);
1328 return 0;
1330 font_op_error:
1331 if (uplock)
1332 mutex_unlock(&sisusb->lock);
1334 return -EIO;
1337 /* Interface routine */
1338 static int
1339 sisusbcon_font_set(struct vc_data *c, struct console_font *font,
1340 unsigned flags)
1342 struct sisusb_usb_data *sisusb;
1343 unsigned charcount = font->charcount;
1345 if (font->width != 8 || (charcount != 256 && charcount != 512))
1346 return -EINVAL;
1348 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1349 return -ENODEV;
1351 /* sisusb->lock is down */
1353 /* Save the user-provided font into a buffer. This
1354 * is used for restoring text mode after quitting
1355 * from X and for the con_getfont routine.
1357 if (sisusb->font_backup) {
1358 if (sisusb->font_backup_size < charcount) {
1359 vfree(sisusb->font_backup);
1360 sisusb->font_backup = NULL;
1364 if (!sisusb->font_backup)
1365 sisusb->font_backup = vmalloc(charcount * 32);
1367 if (sisusb->font_backup) {
1368 memcpy(sisusb->font_backup, font->data, charcount * 32);
1369 sisusb->font_backup_size = charcount;
1370 sisusb->font_backup_height = font->height;
1371 sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
1374 /* do_font_op ups sisusb->lock */
1376 return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
1377 8192, (charcount == 512),
1378 (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
1379 c, font->height, 1);
1382 /* Interface routine */
1383 static int
1384 sisusbcon_font_get(struct vc_data *c, struct console_font *font)
1386 struct sisusb_usb_data *sisusb;
1388 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1389 return -ENODEV;
1391 /* sisusb->lock is down */
1393 font->width = 8;
1394 font->height = c->vc_font.height;
1395 font->charcount = 256;
1397 if (!font->data) {
1398 mutex_unlock(&sisusb->lock);
1399 return 0;
1402 if (!sisusb->font_backup) {
1403 mutex_unlock(&sisusb->lock);
1404 return -ENODEV;
1407 /* Copy 256 chars only, like vgacon */
1408 memcpy(font->data, sisusb->font_backup, 256 * 32);
1410 mutex_unlock(&sisusb->lock);
1412 return 0;
1416 * The console `switch' structure for the sisusb console
1419 static const struct consw sisusb_con = {
1420 .owner = THIS_MODULE,
1421 .con_startup = sisusbcon_startup,
1422 .con_init = sisusbcon_init,
1423 .con_deinit = sisusbcon_deinit,
1424 .con_clear = sisusbcon_clear,
1425 .con_putc = sisusbcon_putc,
1426 .con_putcs = sisusbcon_putcs,
1427 .con_cursor = sisusbcon_cursor,
1428 .con_scroll = sisusbcon_scroll,
1429 .con_bmove = sisusbcon_bmove,
1430 .con_switch = sisusbcon_switch,
1431 .con_blank = sisusbcon_blank,
1432 .con_font_set = sisusbcon_font_set,
1433 .con_font_get = sisusbcon_font_get,
1434 .con_set_palette = sisusbcon_set_palette,
1435 .con_scrolldelta = sisusbcon_scrolldelta,
1436 .con_build_attr = sisusbcon_build_attr,
1437 .con_invert_region = sisusbcon_invert_region,
1438 .con_set_origin = sisusbcon_set_origin,
1439 .con_save_screen = sisusbcon_save_screen,
1440 .con_resize = sisusbcon_resize,
1443 /* Our very own dummy console driver */
1445 static const char *sisusbdummycon_startup(void)
1447 return "SISUSBVGADUMMY";
1450 static void sisusbdummycon_init(struct vc_data *vc, int init)
1452 vc->vc_can_do_color = 1;
1453 if (init) {
1454 vc->vc_cols = 80;
1455 vc->vc_rows = 25;
1456 } else
1457 vc_resize(vc, 80, 25);
1460 static int sisusbdummycon_dummy(void)
1462 return 0;
1465 #define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
1467 static const struct consw sisusb_dummy_con = {
1468 .owner = THIS_MODULE,
1469 .con_startup = sisusbdummycon_startup,
1470 .con_init = sisusbdummycon_init,
1471 .con_deinit = SISUSBCONDUMMY,
1472 .con_clear = SISUSBCONDUMMY,
1473 .con_putc = SISUSBCONDUMMY,
1474 .con_putcs = SISUSBCONDUMMY,
1475 .con_cursor = SISUSBCONDUMMY,
1476 .con_scroll = SISUSBCONDUMMY,
1477 .con_bmove = SISUSBCONDUMMY,
1478 .con_switch = SISUSBCONDUMMY,
1479 .con_blank = SISUSBCONDUMMY,
1480 .con_font_set = SISUSBCONDUMMY,
1481 .con_font_get = SISUSBCONDUMMY,
1482 .con_font_default = SISUSBCONDUMMY,
1483 .con_font_copy = SISUSBCONDUMMY,
1484 .con_set_palette = SISUSBCONDUMMY,
1485 .con_scrolldelta = SISUSBCONDUMMY,
1489 sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
1491 int i, ret, minor = sisusb->minor;
1493 mutex_lock(&disconnect_mutex);
1495 mutex_lock(&sisusb->lock);
1497 /* Erm.. that should not happen */
1498 if (sisusb->haveconsole || !sisusb->SiS_Pr) {
1499 mutex_unlock(&sisusb->lock);
1500 mutex_unlock(&disconnect_mutex);
1501 return 1;
1504 sisusb->con_first = first;
1505 sisusb->con_last = last;
1507 if (first > last ||
1508 first > MAX_NR_CONSOLES ||
1509 last > MAX_NR_CONSOLES) {
1510 mutex_unlock(&sisusb->lock);
1511 mutex_unlock(&disconnect_mutex);
1512 return 1;
1515 /* If gfxcore not initialized or no consoles given, quit graciously */
1516 if (!sisusb->gfxinit || first < 1 || last < 1) {
1517 mutex_unlock(&sisusb->lock);
1518 mutex_unlock(&disconnect_mutex);
1519 return 0;
1522 sisusb->sisusb_cursor_loc = -1;
1523 sisusb->sisusb_cursor_size_from = -1;
1524 sisusb->sisusb_cursor_size_to = -1;
1526 /* Set up text mode (and upload default font) */
1527 if (sisusb_reset_text_mode(sisusb, 1)) {
1528 mutex_unlock(&sisusb->lock);
1529 mutex_unlock(&disconnect_mutex);
1530 printk(KERN_ERR
1531 "sisusbvga[%d]: Failed to set up text mode\n",
1532 minor);
1533 return 1;
1536 /* Initialize some gfx registers */
1537 sisusb_initialize(sisusb);
1539 for (i = first - 1; i <= last - 1; i++) {
1540 /* Save sisusb for our interface routines */
1541 mysisusbs[i] = sisusb;
1544 /* Initial console setup */
1545 sisusb->sisusb_num_columns = 80;
1547 /* Use a 32K buffer (matches b8000-bffff area) */
1548 sisusb->scrbuf_size = 32 * 1024;
1550 /* Allocate screen buffer */
1551 if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
1552 mutex_unlock(&sisusb->lock);
1553 mutex_unlock(&disconnect_mutex);
1554 printk(KERN_ERR
1555 "sisusbvga[%d]: Failed to allocate screen buffer\n",
1556 minor);
1557 return 1;
1560 mutex_unlock(&sisusb->lock);
1561 mutex_unlock(&disconnect_mutex);
1563 /* Now grab the desired console(s) */
1564 ret = take_over_console(&sisusb_con, first - 1, last - 1, 0);
1566 if (!ret)
1567 sisusb->haveconsole = 1;
1568 else {
1569 for (i = first - 1; i <= last - 1; i++)
1570 mysisusbs[i] = NULL;
1573 return ret;
1576 void
1577 sisusb_console_exit(struct sisusb_usb_data *sisusb)
1579 int i;
1581 /* This is called if the device is disconnected
1582 * and while disconnect and lock semaphores
1583 * are up. This should be save because we
1584 * can't lose our sisusb any other way but by
1585 * disconnection (and hence, the disconnect
1586 * sema is for protecting all other access
1587 * functions from disconnection, not the
1588 * other way round).
1591 /* Now what do we do in case of disconnection:
1592 * One alternative would be to simply call
1593 * give_up_console(). Nah, not a good idea.
1594 * give_up_console() is obviously buggy as it
1595 * only discards the consw pointer from the
1596 * driver_map, but doesn't adapt vc->vc_sw
1597 * of the affected consoles. Hence, the next
1598 * call to any of the console functions will
1599 * eventually take a trip to oops county.
1600 * Also, give_up_console for some reason
1601 * doesn't decrement our module refcount.
1602 * Instead, we switch our consoles to a private
1603 * dummy console. This, of course, keeps our
1604 * refcount up as well, but it works perfectly.
1607 if (sisusb->haveconsole) {
1608 for (i = 0; i < MAX_NR_CONSOLES; i++)
1609 if (sisusb->havethisconsole[i])
1610 take_over_console(&sisusb_dummy_con, i, i, 0);
1611 /* At this point, con_deinit for all our
1612 * consoles is executed by take_over_console().
1614 sisusb->haveconsole = 0;
1617 vfree((void *)sisusb->scrbuf);
1618 sisusb->scrbuf = 0;
1620 vfree(sisusb->font_backup);
1621 sisusb->font_backup = NULL;
1624 void __init sisusb_init_concode(void)
1626 int i;
1628 for (i = 0; i < MAX_NR_CONSOLES; i++)
1629 mysisusbs[i] = NULL;
1632 #endif /* INCL_CON */