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
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
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.
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
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
50 #include <linux/mutex.h>
51 #include <linux/module.h>
52 #include <linux/kernel.h>
53 #include <linux/signal.h>
55 #include <linux/usb.h>
56 #include <linux/tty.h>
57 #include <linux/console.h>
58 #include <linux/string.h>
60 #include <linux/init.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>
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
;
86 sisusbcon_memsetw(u16
*s
, u16 c
, unsigned int count
)
90 sisusbcon_writew(c
, s
++);
94 sisusb_initialize(struct sisusb_usb_data
*sisusb
)
96 /* Reset cursor and start address */
97 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0c, 0x00))
99 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0d, 0x00))
101 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, 0x00))
103 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, 0x00);
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));
116 sisusb_set_cursor(struct sisusb_usb_data
*sisusb
, unsigned int location
)
118 if (sisusb
->sisusb_cursor_loc
== location
)
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
128 if ((location
& 0x0007) == 0x0007) {
129 sisusb
->bad_cursor_pos
= 1;
131 if (sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0x1f, 0x20))
133 } else if (sisusb
->bad_cursor_pos
) {
134 if (sisusb_setidxregand(sisusb
, SISCR
, 0x0b, 0x1f))
136 sisusb
->bad_cursor_pos
= 0;
139 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, (location
>> 8)))
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
];
151 sisusb_sisusb_valid(struct sisusb_usb_data
*sisusb
)
153 if (!sisusb
->present
|| !sisusb
->ready
|| !sisusb
->sisusb_dev
)
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.
172 sisusb
= sisusb_get_sisusb(console
);
176 mutex_lock(&sisusb
->lock
);
178 if (!sisusb_sisusb_valid(sisusb
) ||
179 !sisusb
->havethisconsole
[console
]) {
180 mutex_unlock(&sisusb
->lock
);
188 sisusb_is_inactive(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
)
190 if (sisusb
->is_gfx
||
191 sisusb
->textmodedestroyed
||
192 c
->vc_mode
!= KD_TEXT
)
198 /* con_startup console interface routine */
200 sisusbcon_startup(void)
205 /* con_init console interface routine */
207 sisusbcon_init(struct vc_data
*c
, int init
)
209 struct sisusb_usb_data
*sisusb
;
212 /* This is called by do_take_over_console(),
213 * ie by us/under our control. It is
214 * only called after text mode and fonts
215 * are set up/restored.
218 sisusb
= sisusb_get_sisusb(c
->vc_num
);
222 mutex_lock(&sisusb
->lock
);
224 if (!sisusb_sisusb_valid(sisusb
)) {
225 mutex_unlock(&sisusb
->lock
);
229 c
->vc_can_do_color
= 1;
231 c
->vc_complement_mask
= 0x7700;
233 c
->vc_hi_font_mask
= sisusb
->current_font_512
? 0x0800 : 0;
235 sisusb
->haveconsole
= 1;
237 sisusb
->havethisconsole
[c
->vc_num
] = 1;
239 /* We only support 640x400 */
240 c
->vc_scan_lines
= 400;
242 c
->vc_font
.height
= sisusb
->current_font_height
;
244 /* We only support width = 8 */
246 rows
= c
->vc_scan_lines
/ c
->vc_font
.height
;
248 /* Increment usage count for our sisusb.
249 * Doing so saves us from upping/downing
250 * the disconnect semaphore; we can't
251 * lose our sisusb until this is undone
252 * in con_deinit. For all other console
253 * interface functions, it suffices to
254 * use sisusb->lock and do a quick check
255 * of sisusb for device disconnection.
257 kref_get(&sisusb
->kref
);
259 if (!*c
->vc_uni_pagedir_loc
)
260 con_set_default_unimap(c
);
262 mutex_unlock(&sisusb
->lock
);
268 vc_resize(c
, cols
, rows
);
271 /* con_deinit console interface routine */
273 sisusbcon_deinit(struct vc_data
*c
)
275 struct sisusb_usb_data
*sisusb
;
278 /* This is called by do_take_over_console()
279 * and others, ie not under our control.
282 sisusb
= sisusb_get_sisusb(c
->vc_num
);
286 mutex_lock(&sisusb
->lock
);
288 /* Clear ourselves in mysisusbs */
289 mysisusbs
[c
->vc_num
] = NULL
;
291 sisusb
->havethisconsole
[c
->vc_num
] = 0;
293 /* Free our font buffer if all consoles are gone */
294 if (sisusb
->font_backup
) {
295 for(i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
296 if (sisusb
->havethisconsole
[c
->vc_num
])
299 if (i
== MAX_NR_CONSOLES
) {
300 vfree(sisusb
->font_backup
);
301 sisusb
->font_backup
= NULL
;
305 mutex_unlock(&sisusb
->lock
);
307 /* decrement the usage count on our sisusb */
308 kref_put(&sisusb
->kref
, sisusb_delete
);
311 /* interface routine */
313 sisusbcon_build_attr(struct vc_data
*c
, u8 color
, u8 intensity
,
314 u8 blink
, u8 underline
, u8 reverse
, u8 unused
)
319 attr
= (attr
& 0xf0) | c
->vc_ulcolor
;
320 else if (intensity
== 0)
321 attr
= (attr
& 0xf0) | c
->vc_halfcolor
;
324 attr
= ((attr
) & 0x88) |
326 ((attr
) << 4)) & 0x77);
337 /* Interface routine */
339 sisusbcon_invert_region(struct vc_data
*vc
, u16
*p
, int count
)
341 /* Invert a region. This is called with a pointer
342 * to the console's internal screen buffer. So we
343 * simply do the inversion there and rely on
344 * a call to putc(s) to update the real screen.
348 u16 a
= sisusbcon_readw(p
);
351 (((a
) & 0x7000) >> 4) |
352 (((a
) & 0x0700) << 4);
354 sisusbcon_writew(a
, p
++);
358 #define SISUSB_VADDR(x,y) \
359 ((u16 *)c->vc_origin + \
360 (y) * sisusb->sisusb_num_columns + \
363 #define SISUSB_HADDR(x,y) \
364 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
365 (y) * sisusb->sisusb_num_columns + \
368 /* Interface routine */
370 sisusbcon_putc(struct vc_data
*c
, int ch
, int y
, int x
)
372 struct sisusb_usb_data
*sisusb
;
375 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
379 /* sisusb->lock is down */
380 if (sisusb_is_inactive(c
, sisusb
)) {
381 mutex_unlock(&sisusb
->lock
);
386 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(x
, y
),
387 (long)SISUSB_HADDR(x
, y
), 2, &written
);
389 mutex_unlock(&sisusb
->lock
);
392 /* Interface routine */
394 sisusbcon_putcs(struct vc_data
*c
, const unsigned short *s
,
395 int count
, int y
, int x
)
397 struct sisusb_usb_data
*sisusb
;
402 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
406 /* sisusb->lock is down */
408 /* Need to put the characters into the buffer ourselves,
409 * because the vt does this AFTER calling us.
412 dest
= SISUSB_VADDR(x
, y
);
414 for (i
= count
; i
> 0; i
--)
415 sisusbcon_writew(sisusbcon_readw(s
++), dest
++);
417 if (sisusb_is_inactive(c
, sisusb
)) {
418 mutex_unlock(&sisusb
->lock
);
422 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(x
, y
),
423 (long)SISUSB_HADDR(x
, y
), count
* 2, &written
);
425 mutex_unlock(&sisusb
->lock
);
428 /* Interface routine */
430 sisusbcon_clear(struct vc_data
*c
, int y
, int x
, int height
, int width
)
432 struct sisusb_usb_data
*sisusb
;
433 u16 eattr
= c
->vc_video_erase_char
;
438 if (width
<= 0 || height
<= 0)
441 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
445 /* sisusb->lock is down */
447 /* Need to clear buffer ourselves, because the vt does
448 * this AFTER calling us.
451 dest
= SISUSB_VADDR(x
, y
);
453 cols
= sisusb
->sisusb_num_columns
;
458 if (x
== 0 && width
>= c
->vc_cols
) {
460 sisusbcon_memsetw(dest
, eattr
, height
* cols
* 2);
464 for (i
= height
; i
> 0; i
--, dest
+= cols
)
465 sisusbcon_memsetw(dest
, eattr
, width
* 2);
469 if (sisusb_is_inactive(c
, sisusb
)) {
470 mutex_unlock(&sisusb
->lock
);
474 length
= ((height
* cols
) - x
- (cols
- width
- x
)) * 2;
477 sisusb_copy_memory(sisusb
, (unsigned char *)SISUSB_VADDR(x
, y
),
478 (long)SISUSB_HADDR(x
, y
), length
, &written
);
480 mutex_unlock(&sisusb
->lock
);
483 /* Interface routine */
485 sisusbcon_bmove(struct vc_data
*c
, int sy
, int sx
,
486 int dy
, int dx
, int height
, int width
)
488 struct sisusb_usb_data
*sisusb
;
492 if (width
<= 0 || height
<= 0)
495 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
499 /* sisusb->lock is down */
501 cols
= sisusb
->sisusb_num_columns
;
503 if (sisusb_is_inactive(c
, sisusb
)) {
504 mutex_unlock(&sisusb
->lock
);
508 length
= ((height
* cols
) - dx
- (cols
- width
- dx
)) * 2;
511 sisusb_copy_memory(sisusb
, (unsigned char *)SISUSB_VADDR(dx
, dy
),
512 (long)SISUSB_HADDR(dx
, dy
), length
, &written
);
514 mutex_unlock(&sisusb
->lock
);
517 /* interface routine */
519 sisusbcon_switch(struct vc_data
*c
)
521 struct sisusb_usb_data
*sisusb
;
525 /* Returnvalue 0 means we have fully restored screen,
526 * and vt doesn't need to call do_update_region().
527 * Returnvalue != 0 naturally means the opposite.
530 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
534 /* sisusb->lock is down */
536 /* Don't write to screen if in gfx mode */
537 if (sisusb_is_inactive(c
, sisusb
)) {
538 mutex_unlock(&sisusb
->lock
);
542 /* That really should not happen. It would mean we are
543 * being called while the vc is using its private buffer
546 if (c
->vc_origin
== (unsigned long)c
->vc_screenbuf
) {
547 mutex_unlock(&sisusb
->lock
);
548 dev_dbg(&sisusb
->sisusb_dev
->dev
, "ASSERT ORIGIN != SCREENBUF!\n");
552 /* Check that we don't copy too much */
553 length
= min((int)c
->vc_screenbuf_size
,
554 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
556 /* Restore the screen contents */
557 sisusbcon_memcpyw((u16
*)c
->vc_origin
, (u16
*)c
->vc_screenbuf
,
560 sisusb_copy_memory(sisusb
, (unsigned char *)c
->vc_origin
,
561 (long)SISUSB_HADDR(0, 0),
564 mutex_unlock(&sisusb
->lock
);
569 /* interface routine */
571 sisusbcon_save_screen(struct vc_data
*c
)
573 struct sisusb_usb_data
*sisusb
;
576 /* Save the current screen contents to vc's private
580 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
584 /* sisusb->lock is down */
586 if (sisusb_is_inactive(c
, sisusb
)) {
587 mutex_unlock(&sisusb
->lock
);
591 /* Check that we don't copy too much */
592 length
= min((int)c
->vc_screenbuf_size
,
593 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
595 /* Save the screen contents to vc's private buffer */
596 sisusbcon_memcpyw((u16
*)c
->vc_screenbuf
, (u16
*)c
->vc_origin
,
599 mutex_unlock(&sisusb
->lock
);
602 /* interface routine */
604 sisusbcon_set_palette(struct vc_data
*c
, unsigned char *table
)
606 struct sisusb_usb_data
*sisusb
;
609 /* Return value not used by vt */
611 if (!CON_IS_VISIBLE(c
))
614 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
618 /* sisusb->lock is down */
620 if (sisusb_is_inactive(c
, sisusb
)) {
621 mutex_unlock(&sisusb
->lock
);
625 for (i
= j
= 0; i
< 16; i
++) {
626 if (sisusb_setreg(sisusb
, SISCOLIDX
, table
[i
]))
628 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
630 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
632 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
636 mutex_unlock(&sisusb
->lock
);
641 /* interface routine */
643 sisusbcon_blank(struct vc_data
*c
, int blank
, int mode_switch
)
645 struct sisusb_usb_data
*sisusb
;
646 u8 sr1
, cr17
, pmreg
, cr63
;
650 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
654 /* sisusb->lock is down */
657 sisusb
->is_gfx
= blank
? 1 : 0;
659 if (sisusb_is_inactive(c
, sisusb
)) {
660 mutex_unlock(&sisusb
->lock
);
666 case 1: /* Normal blanking: Clear screen */
668 sisusbcon_memsetw((u16
*)c
->vc_origin
,
669 c
->vc_video_erase_char
,
670 c
->vc_screenbuf_size
);
671 sisusb_copy_memory(sisusb
,
672 (unsigned char *)c
->vc_origin
,
673 (u32
)(sisusb
->vrambase
+
674 (c
->vc_origin
- sisusb
->scrbuf
)),
675 c
->vc_screenbuf_size
, &written
);
676 sisusb
->con_blanked
= 1;
680 default: /* VESA blanking */
682 case 0: /* Unblank */
688 sisusb
->con_blanked
= 0;
690 case VESA_VSYNC_SUSPEND
+ 1:
696 case VESA_HSYNC_SUSPEND
+ 1:
702 case VESA_POWERDOWN
+ 1:
709 mutex_unlock(&sisusb
->lock
);
713 sisusb_setidxregandor(sisusb
, SISSR
, 0x01, ~0x20, sr1
);
714 sisusb_setidxregandor(sisusb
, SISCR
, 0x17, 0x7f, cr17
);
715 sisusb_setidxregandor(sisusb
, SISSR
, 0x1f, 0x3f, pmreg
);
716 sisusb_setidxregandor(sisusb
, SISCR
, 0x63, 0xbf, cr63
);
720 mutex_unlock(&sisusb
->lock
);
725 /* interface routine */
727 sisusbcon_scrolldelta(struct vc_data
*c
, int lines
)
729 struct sisusb_usb_data
*sisusb
;
730 int margin
= c
->vc_size_row
* 4;
733 /* The return value does not seem to be used */
735 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
739 /* sisusb->lock is down */
741 if (sisusb_is_inactive(c
, sisusb
)) {
742 mutex_unlock(&sisusb
->lock
);
746 if (!lines
) /* Turn scrollback off */
747 c
->vc_visible_origin
= c
->vc_origin
;
750 if (sisusb
->con_rolled_over
>
751 (c
->vc_scr_end
- sisusb
->scrbuf
) + margin
) {
753 ul
= c
->vc_scr_end
- sisusb
->scrbuf
;
754 we
= sisusb
->con_rolled_over
+ c
->vc_size_row
;
759 we
= sisusb
->scrbuf_size
;
763 p
= (c
->vc_visible_origin
- sisusb
->scrbuf
- ul
+ we
) % we
+
764 lines
* c
->vc_size_row
;
766 st
= (c
->vc_origin
- sisusb
->scrbuf
- ul
+ we
) % we
;
777 c
->vc_visible_origin
= sisusb
->scrbuf
+ (p
+ ul
) % we
;
780 sisusbcon_set_start_address(sisusb
, c
);
782 mutex_unlock(&sisusb
->lock
);
787 /* Interface routine */
789 sisusbcon_cursor(struct vc_data
*c
, int mode
)
791 struct sisusb_usb_data
*sisusb
;
792 int from
, to
, baseline
;
794 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
798 /* sisusb->lock is down */
800 if (sisusb_is_inactive(c
, sisusb
)) {
801 mutex_unlock(&sisusb
->lock
);
805 if (c
->vc_origin
!= c
->vc_visible_origin
) {
806 c
->vc_visible_origin
= c
->vc_origin
;
807 sisusbcon_set_start_address(sisusb
, c
);
810 if (mode
== CM_ERASE
) {
811 sisusb_setidxregor(sisusb
, SISCR
, 0x0a, 0x20);
812 sisusb
->sisusb_cursor_size_to
= -1;
813 mutex_unlock(&sisusb
->lock
);
817 sisusb_set_cursor(sisusb
, (c
->vc_pos
- sisusb
->scrbuf
) / 2);
819 baseline
= c
->vc_font
.height
- (c
->vc_font
.height
< 10 ? 1 : 2);
821 switch (c
->vc_cursor_type
& 0x0f) {
822 case CUR_BLOCK
: from
= 1;
823 to
= c
->vc_font
.height
;
825 case CUR_TWO_THIRDS
: from
= c
->vc_font
.height
/ 3;
828 case CUR_LOWER_HALF
: from
= c
->vc_font
.height
/ 2;
831 case CUR_LOWER_THIRD
: from
= (c
->vc_font
.height
* 2) / 3;
834 case CUR_NONE
: from
= 31;
838 case CUR_UNDERLINE
: from
= baseline
- 1;
843 if (sisusb
->sisusb_cursor_size_from
!= from
||
844 sisusb
->sisusb_cursor_size_to
!= to
) {
846 sisusb_setidxreg(sisusb
, SISCR
, 0x0a, from
);
847 sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0xe0, to
);
849 sisusb
->sisusb_cursor_size_from
= from
;
850 sisusb
->sisusb_cursor_size_to
= to
;
853 mutex_unlock(&sisusb
->lock
);
857 sisusbcon_scroll_area(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
,
858 int t
, int b
, int dir
, int lines
)
860 int cols
= sisusb
->sisusb_num_columns
;
861 int length
= ((b
- t
) * cols
) * 2;
862 u16 eattr
= c
->vc_video_erase_char
;
865 /* sisusb->lock is down */
867 /* Scroll an area which does not match the
868 * visible screen's dimensions. This needs
869 * to be done separately, as it does not
870 * use hardware panning.
876 sisusbcon_memmovew(SISUSB_VADDR(0, t
),
877 SISUSB_VADDR(0, t
+ lines
),
878 (b
- t
- lines
) * cols
* 2);
879 sisusbcon_memsetw(SISUSB_VADDR(0, b
- lines
), eattr
,
884 sisusbcon_memmovew(SISUSB_VADDR(0, t
+ lines
),
886 (b
- t
- lines
) * cols
* 2);
887 sisusbcon_memsetw(SISUSB_VADDR(0, t
), eattr
,
892 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(0, t
),
893 (long)SISUSB_HADDR(0, t
), length
, &written
);
895 mutex_unlock(&sisusb
->lock
);
900 /* Interface routine */
902 sisusbcon_scroll(struct vc_data
*c
, int t
, int b
, int dir
, int lines
)
904 struct sisusb_usb_data
*sisusb
;
905 u16 eattr
= c
->vc_video_erase_char
;
908 unsigned long oldorigin
;
909 unsigned int delta
= lines
* c
->vc_size_row
;
912 /* Returning != 0 means we have done the scrolling successfully.
913 * Returning 0 makes vt do the scrolling on its own.
914 * Note that con_scroll is only called if the console is
915 * visible. In that case, the origin should be our buffer,
916 * not the vt's private one.
922 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
926 /* sisusb->lock is down */
928 if (sisusb_is_inactive(c
, sisusb
)) {
929 mutex_unlock(&sisusb
->lock
);
934 if (t
|| b
!= c
->vc_rows
)
935 return sisusbcon_scroll_area(c
, sisusb
, t
, b
, dir
, lines
);
937 if (c
->vc_origin
!= c
->vc_visible_origin
) {
938 c
->vc_visible_origin
= c
->vc_origin
;
939 sisusbcon_set_start_address(sisusb
, c
);
942 /* limit amount to maximum realistic size */
943 if (lines
> c
->vc_rows
)
946 oldorigin
= c
->vc_origin
;
952 if (c
->vc_scr_end
+ delta
>=
953 sisusb
->scrbuf
+ sisusb
->scrbuf_size
) {
954 sisusbcon_memcpyw((u16
*)sisusb
->scrbuf
,
955 (u16
*)(oldorigin
+ delta
),
956 c
->vc_screenbuf_size
- delta
);
957 c
->vc_origin
= sisusb
->scrbuf
;
958 sisusb
->con_rolled_over
= oldorigin
- sisusb
->scrbuf
;
961 c
->vc_origin
+= delta
;
964 (u16
*)(c
->vc_origin
+ c
->vc_screenbuf_size
- delta
),
971 if (oldorigin
- delta
< sisusb
->scrbuf
) {
972 sisusbcon_memmovew((u16
*)(sisusb
->scrbuf
+
973 sisusb
->scrbuf_size
-
974 c
->vc_screenbuf_size
+
977 c
->vc_screenbuf_size
- delta
);
978 c
->vc_origin
= sisusb
->scrbuf
+
979 sisusb
->scrbuf_size
-
980 c
->vc_screenbuf_size
;
981 sisusb
->con_rolled_over
= 0;
984 c
->vc_origin
-= delta
;
986 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
988 scr_memsetw((u16
*)(c
->vc_origin
), eattr
, delta
);
993 originoffset
= (u32
)(c
->vc_origin
- sisusb
->scrbuf
);
996 sisusb_copy_memory(sisusb
,
997 (char *)c
->vc_origin
,
998 (u32
)(sisusb
->vrambase
+ originoffset
),
999 c
->vc_screenbuf_size
, &written
);
1000 else if (dir
== SM_UP
)
1001 sisusb_copy_memory(sisusb
,
1002 (char *)c
->vc_origin
+ c
->vc_screenbuf_size
- delta
,
1003 (u32
)sisusb
->vrambase
+ originoffset
+
1004 c
->vc_screenbuf_size
- delta
,
1007 sisusb_copy_memory(sisusb
,
1008 (char *)c
->vc_origin
,
1009 (u32
)(sisusb
->vrambase
+ originoffset
),
1012 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
1013 c
->vc_visible_origin
= c
->vc_origin
;
1015 sisusbcon_set_start_address(sisusb
, c
);
1017 c
->vc_pos
= c
->vc_pos
- oldorigin
+ c
->vc_origin
;
1019 mutex_unlock(&sisusb
->lock
);
1024 /* Interface routine */
1026 sisusbcon_set_origin(struct vc_data
*c
)
1028 struct sisusb_usb_data
*sisusb
;
1030 /* Returning != 0 means we were successful.
1031 * Returning 0 will vt make to use its own
1032 * screenbuffer as the origin.
1035 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1039 /* sisusb->lock is down */
1041 if (sisusb_is_inactive(c
, sisusb
) || sisusb
->con_blanked
) {
1042 mutex_unlock(&sisusb
->lock
);
1046 c
->vc_origin
= c
->vc_visible_origin
= sisusb
->scrbuf
;
1048 sisusbcon_set_start_address(sisusb
, c
);
1050 sisusb
->con_rolled_over
= 0;
1052 mutex_unlock(&sisusb
->lock
);
1057 /* Interface routine */
1059 sisusbcon_resize(struct vc_data
*c
, unsigned int newcols
, unsigned int newrows
,
1062 struct sisusb_usb_data
*sisusb
;
1065 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1069 fh
= sisusb
->current_font_height
;
1071 mutex_unlock(&sisusb
->lock
);
1073 /* We are quite unflexible as regards resizing. The vt code
1074 * handles sizes where the line length isn't equal the pitch
1075 * quite badly. As regards the rows, our panning tricks only
1076 * work well if the number of rows equals the visible number
1080 if (newcols
!= 80 || c
->vc_scan_lines
/ fh
!= newrows
)
1087 sisusbcon_do_font_op(struct sisusb_usb_data
*sisusb
, int set
, int slot
,
1088 u8
*arg
, int cmapsz
, int ch512
, int dorecalc
,
1089 struct vc_data
*c
, int fh
, int uplock
)
1091 int font_select
= 0x00, i
, err
= 0;
1095 /* sisusb->lock is down */
1098 * The default font is kept in slot 0.
1099 * A user font is loaded in slot 2 (256 ch)
1103 if ((slot
!= 0 && slot
!= 2) || !fh
) {
1105 mutex_unlock(&sisusb
->lock
);
1110 sisusb
->font_slot
= slot
;
1112 /* Default font is always 256 */
1116 offset
= 4 * cmapsz
;
1118 font_select
= (slot
== 0) ? 0x00 : (ch512
? 0x0e : 0x0a);
1120 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1121 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x04); /* Write to plane 2 */
1122 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x07); /* Memory mode a0-bf */
1123 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset */
1128 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x03); /* Select plane read 2 */
1129 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x00); /* Disable odd/even */
1130 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x00); /* Address range a0-bf */
1137 for (i
= 0; i
< cmapsz
; i
++) {
1138 err
|= sisusb_writeb(sisusb
,
1139 sisusb
->vrambase
+ offset
+ i
,
1145 for (i
= 0; i
< cmapsz
; i
++) {
1146 err
|= sisusb_readb(sisusb
,
1147 sisusb
->vrambase
+ offset
+ i
,
1154 * In 512-character mode, the character map is not contiguous if
1155 * we want to remain EGA compatible -- which we do
1160 for (i
= 0; i
< cmapsz
; i
++) {
1161 err
|= sisusb_writeb(sisusb
,
1162 sisusb
->vrambase
+ offset
+
1169 for (i
= 0; i
< cmapsz
; i
++) {
1170 err
|= sisusb_readb(sisusb
,
1171 sisusb
->vrambase
+ offset
+
1183 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1184 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x03); /* Write to planes 0+1 */
1185 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x03); /* Memory mode a0-bf */
1187 sisusb_setidxreg(sisusb
, SISSR
, 0x03, font_select
);
1188 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset end */
1193 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x00); /* Select plane read 0 */
1194 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x10); /* Enable odd/even */
1195 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x06); /* Address range b8-bf */
1200 if ((set
) && (ch512
!= sisusb
->current_font_512
)) {
1202 /* Font is shared among all our consoles.
1203 * And so is the hi_font_mask.
1205 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1206 struct vc_data
*d
= vc_cons
[i
].d
;
1207 if (d
&& d
->vc_sw
== &sisusb_con
)
1208 d
->vc_hi_font_mask
= ch512
? 0x0800 : 0;
1211 sisusb
->current_font_512
= ch512
;
1213 /* color plane enable register:
1214 256-char: enable intensity bit
1215 512-char: disable intensity bit */
1216 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1217 sisusb_setreg(sisusb
, SISAR
, 0x12);
1218 sisusb_setreg(sisusb
, SISAR
, ch512
? 0x07 : 0x0f);
1220 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1221 sisusb_setreg(sisusb
, SISAR
, 0x20);
1222 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1228 * Adjust the screen to fit a font of a certain height
1231 unsigned char ovr
, vde
, fsr
;
1232 int rows
= 0, maxscan
= 0;
1236 /* Number of video rows */
1237 rows
= c
->vc_scan_lines
/ fh
;
1238 /* Scan lines to actually display-1 */
1239 maxscan
= rows
* fh
- 1;
1241 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1242 rows, maxscan, fh, c->vc_scan_lines);*/
1244 sisusb_getidxreg(sisusb
, SISCR
, 0x07, &ovr
);
1245 vde
= maxscan
& 0xff;
1246 ovr
= (ovr
& 0xbd) |
1247 ((maxscan
& 0x100) >> 7) |
1248 ((maxscan
& 0x200) >> 3);
1249 sisusb_setidxreg(sisusb
, SISCR
, 0x07, ovr
);
1250 sisusb_setidxreg(sisusb
, SISCR
, 0x12, vde
);
1254 sisusb_getidxreg(sisusb
, SISCR
, 0x09, &fsr
);
1255 fsr
= (fsr
& 0xe0) | (fh
- 1);
1256 sisusb_setidxreg(sisusb
, SISCR
, 0x09, fsr
);
1257 sisusb
->current_font_height
= fh
;
1259 sisusb
->sisusb_cursor_size_from
= -1;
1260 sisusb
->sisusb_cursor_size_to
= -1;
1265 mutex_unlock(&sisusb
->lock
);
1267 if (dorecalc
&& c
) {
1268 int rows
= c
->vc_scan_lines
/ fh
;
1270 /* Now adjust our consoles' size */
1272 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1273 struct vc_data
*vc
= vc_cons
[i
].d
;
1275 if (vc
&& vc
->vc_sw
== &sisusb_con
) {
1276 if (CON_IS_VISIBLE(vc
)) {
1277 vc
->vc_sw
->con_cursor(vc
, CM_DRAW
);
1279 vc
->vc_font
.height
= fh
;
1280 vc_resize(vc
, 0, rows
);
1289 mutex_unlock(&sisusb
->lock
);
1294 /* Interface routine */
1296 sisusbcon_font_set(struct vc_data
*c
, struct console_font
*font
,
1299 struct sisusb_usb_data
*sisusb
;
1300 unsigned charcount
= font
->charcount
;
1302 if (font
->width
!= 8 || (charcount
!= 256 && charcount
!= 512))
1305 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1309 /* sisusb->lock is down */
1311 /* Save the user-provided font into a buffer. This
1312 * is used for restoring text mode after quitting
1313 * from X and for the con_getfont routine.
1315 if (sisusb
->font_backup
) {
1316 if (sisusb
->font_backup_size
< charcount
) {
1317 vfree(sisusb
->font_backup
);
1318 sisusb
->font_backup
= NULL
;
1322 if (!sisusb
->font_backup
)
1323 sisusb
->font_backup
= vmalloc(charcount
* 32);
1325 if (sisusb
->font_backup
) {
1326 memcpy(sisusb
->font_backup
, font
->data
, charcount
* 32);
1327 sisusb
->font_backup_size
= charcount
;
1328 sisusb
->font_backup_height
= font
->height
;
1329 sisusb
->font_backup_512
= (charcount
== 512) ? 1 : 0;
1332 /* do_font_op ups sisusb->lock */
1334 return sisusbcon_do_font_op(sisusb
, 1, 2, font
->data
,
1335 8192, (charcount
== 512),
1336 (!(flags
& KD_FONT_FLAG_DONT_RECALC
)) ? 1 : 0,
1337 c
, font
->height
, 1);
1340 /* Interface routine */
1342 sisusbcon_font_get(struct vc_data
*c
, struct console_font
*font
)
1344 struct sisusb_usb_data
*sisusb
;
1346 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1350 /* sisusb->lock is down */
1353 font
->height
= c
->vc_font
.height
;
1354 font
->charcount
= 256;
1357 mutex_unlock(&sisusb
->lock
);
1361 if (!sisusb
->font_backup
) {
1362 mutex_unlock(&sisusb
->lock
);
1366 /* Copy 256 chars only, like vgacon */
1367 memcpy(font
->data
, sisusb
->font_backup
, 256 * 32);
1369 mutex_unlock(&sisusb
->lock
);
1375 * The console `switch' structure for the sisusb console
1378 static const struct consw sisusb_con
= {
1379 .owner
= THIS_MODULE
,
1380 .con_startup
= sisusbcon_startup
,
1381 .con_init
= sisusbcon_init
,
1382 .con_deinit
= sisusbcon_deinit
,
1383 .con_clear
= sisusbcon_clear
,
1384 .con_putc
= sisusbcon_putc
,
1385 .con_putcs
= sisusbcon_putcs
,
1386 .con_cursor
= sisusbcon_cursor
,
1387 .con_scroll
= sisusbcon_scroll
,
1388 .con_bmove
= sisusbcon_bmove
,
1389 .con_switch
= sisusbcon_switch
,
1390 .con_blank
= sisusbcon_blank
,
1391 .con_font_set
= sisusbcon_font_set
,
1392 .con_font_get
= sisusbcon_font_get
,
1393 .con_set_palette
= sisusbcon_set_palette
,
1394 .con_scrolldelta
= sisusbcon_scrolldelta
,
1395 .con_build_attr
= sisusbcon_build_attr
,
1396 .con_invert_region
= sisusbcon_invert_region
,
1397 .con_set_origin
= sisusbcon_set_origin
,
1398 .con_save_screen
= sisusbcon_save_screen
,
1399 .con_resize
= sisusbcon_resize
,
1402 /* Our very own dummy console driver */
1404 static const char *sisusbdummycon_startup(void)
1406 return "SISUSBVGADUMMY";
1409 static void sisusbdummycon_init(struct vc_data
*vc
, int init
)
1411 vc
->vc_can_do_color
= 1;
1416 vc_resize(vc
, 80, 25);
1419 static int sisusbdummycon_dummy(void)
1424 #define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
1426 static const struct consw sisusb_dummy_con
= {
1427 .owner
= THIS_MODULE
,
1428 .con_startup
= sisusbdummycon_startup
,
1429 .con_init
= sisusbdummycon_init
,
1430 .con_deinit
= SISUSBCONDUMMY
,
1431 .con_clear
= SISUSBCONDUMMY
,
1432 .con_putc
= SISUSBCONDUMMY
,
1433 .con_putcs
= SISUSBCONDUMMY
,
1434 .con_cursor
= SISUSBCONDUMMY
,
1435 .con_scroll
= SISUSBCONDUMMY
,
1436 .con_bmove
= SISUSBCONDUMMY
,
1437 .con_switch
= SISUSBCONDUMMY
,
1438 .con_blank
= SISUSBCONDUMMY
,
1439 .con_font_set
= SISUSBCONDUMMY
,
1440 .con_font_get
= SISUSBCONDUMMY
,
1441 .con_font_default
= SISUSBCONDUMMY
,
1442 .con_font_copy
= SISUSBCONDUMMY
,
1443 .con_set_palette
= SISUSBCONDUMMY
,
1444 .con_scrolldelta
= SISUSBCONDUMMY
,
1448 sisusb_console_init(struct sisusb_usb_data
*sisusb
, int first
, int last
)
1452 mutex_lock(&sisusb
->lock
);
1454 /* Erm.. that should not happen */
1455 if (sisusb
->haveconsole
|| !sisusb
->SiS_Pr
) {
1456 mutex_unlock(&sisusb
->lock
);
1460 sisusb
->con_first
= first
;
1461 sisusb
->con_last
= last
;
1464 first
> MAX_NR_CONSOLES
||
1465 last
> MAX_NR_CONSOLES
) {
1466 mutex_unlock(&sisusb
->lock
);
1470 /* If gfxcore not initialized or no consoles given, quit graciously */
1471 if (!sisusb
->gfxinit
|| first
< 1 || last
< 1) {
1472 mutex_unlock(&sisusb
->lock
);
1476 sisusb
->sisusb_cursor_loc
= -1;
1477 sisusb
->sisusb_cursor_size_from
= -1;
1478 sisusb
->sisusb_cursor_size_to
= -1;
1480 /* Set up text mode (and upload default font) */
1481 if (sisusb_reset_text_mode(sisusb
, 1)) {
1482 mutex_unlock(&sisusb
->lock
);
1483 dev_err(&sisusb
->sisusb_dev
->dev
, "Failed to set up text mode\n");
1487 /* Initialize some gfx registers */
1488 sisusb_initialize(sisusb
);
1490 for (i
= first
- 1; i
<= last
- 1; i
++) {
1491 /* Save sisusb for our interface routines */
1492 mysisusbs
[i
] = sisusb
;
1495 /* Initial console setup */
1496 sisusb
->sisusb_num_columns
= 80;
1498 /* Use a 32K buffer (matches b8000-bffff area) */
1499 sisusb
->scrbuf_size
= 32 * 1024;
1501 /* Allocate screen buffer */
1502 if (!(sisusb
->scrbuf
= (unsigned long)vmalloc(sisusb
->scrbuf_size
))) {
1503 mutex_unlock(&sisusb
->lock
);
1504 dev_err(&sisusb
->sisusb_dev
->dev
, "Failed to allocate screen buffer\n");
1508 mutex_unlock(&sisusb
->lock
);
1510 /* Now grab the desired console(s) */
1512 ret
= do_take_over_console(&sisusb_con
, first
- 1, last
- 1, 0);
1515 sisusb
->haveconsole
= 1;
1517 for (i
= first
- 1; i
<= last
- 1; i
++)
1518 mysisusbs
[i
] = NULL
;
1525 sisusb_console_exit(struct sisusb_usb_data
*sisusb
)
1529 /* This is called if the device is disconnected
1530 * and while disconnect and lock semaphores
1531 * are up. This should be save because we
1532 * can't lose our sisusb any other way but by
1533 * disconnection (and hence, the disconnect
1534 * sema is for protecting all other access
1535 * functions from disconnection, not the
1539 /* Now what do we do in case of disconnection:
1540 * One alternative would be to simply call
1541 * give_up_console(). Nah, not a good idea.
1542 * give_up_console() is obviously buggy as it
1543 * only discards the consw pointer from the
1544 * driver_map, but doesn't adapt vc->vc_sw
1545 * of the affected consoles. Hence, the next
1546 * call to any of the console functions will
1547 * eventually take a trip to oops county.
1548 * Also, give_up_console for some reason
1549 * doesn't decrement our module refcount.
1550 * Instead, we switch our consoles to a private
1551 * dummy console. This, of course, keeps our
1552 * refcount up as well, but it works perfectly.
1555 if (sisusb
->haveconsole
) {
1556 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1557 if (sisusb
->havethisconsole
[i
]) {
1559 do_take_over_console(&sisusb_dummy_con
, i
, i
, 0);
1561 /* At this point, con_deinit for all our
1562 * consoles is executed by do_take_over_console().
1565 sisusb
->haveconsole
= 0;
1568 vfree((void *)sisusb
->scrbuf
);
1571 vfree(sisusb
->font_backup
);
1572 sisusb
->font_backup
= NULL
;
1575 void __init
sisusb_init_concode(void)
1579 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1580 mysisusbs
[i
] = NULL
;
1583 #endif /* INCL_CON */