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/config.h>
51 #include <linux/module.h>
52 #include <linux/kernel.h>
53 #include <linux/signal.h>
54 #include <linux/sched.h>
56 #include <linux/tty.h>
57 #include <linux/console.h>
58 #include <linux/string.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>
73 #ifdef INCL_SISUSB_CON
74 extern int sisusb_setreg(struct sisusb_usb_data
*, int, u8
);
75 extern int sisusb_getreg(struct sisusb_usb_data
*, int, u8
*);
76 extern int sisusb_setidxreg(struct sisusb_usb_data
*, int, u8
, u8
);
77 extern int sisusb_getidxreg(struct sisusb_usb_data
*, int, u8
, u8
*);
78 extern int sisusb_setidxregor(struct sisusb_usb_data
*, int, u8
, u8
);
79 extern int sisusb_setidxregand(struct sisusb_usb_data
*, int, u8
, u8
);
80 extern int sisusb_setidxregandor(struct sisusb_usb_data
*, int, u8
, u8
, u8
);
82 extern int sisusb_writeb(struct sisusb_usb_data
*sisusb
, u32 adr
, u8 data
);
83 extern int sisusb_readb(struct sisusb_usb_data
*sisusb
, u32 adr
, u8
*data
);
84 extern int sisusb_writew(struct sisusb_usb_data
*sisusb
, u32 adr
, u16 data
);
85 extern int sisusb_readw(struct sisusb_usb_data
*sisusb
, u32 adr
, u16
*data
);
86 extern int sisusb_copy_memory(struct sisusb_usb_data
*sisusb
, char *src
,
87 u32 dest
, int length
, size_t *bytes_written
);
89 extern void sisusb_delete(struct kref
*kref
);
90 extern int sisusb_reset_text_mode(struct sisusb_usb_data
*sisusb
, int init
);
92 extern int SiSUSBSetMode(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
);
94 #define sisusbcon_writew(val, addr) (*(addr) = (val))
95 #define sisusbcon_readw(addr) (*(addr))
96 #define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
97 #define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
99 /* vc_data -> sisusb conversion table */
100 static struct sisusb_usb_data
*mysisusbs
[MAX_NR_CONSOLES
];
102 /* Forward declaration */
103 static const struct consw sisusb_con
;
105 extern struct semaphore disconnect_sem
;
108 sisusbcon_memsetw(u16
*s
, u16 c
, unsigned int count
)
112 sisusbcon_writew(c
, s
++);
116 sisusb_initialize(struct sisusb_usb_data
*sisusb
)
118 /* Reset cursor and start address */
119 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0c, 0x00))
121 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0d, 0x00))
123 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, 0x00))
125 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, 0x00);
129 sisusbcon_set_start_address(struct sisusb_usb_data
*sisusb
, struct vc_data
*c
)
131 sisusb
->cur_start_addr
= (c
->vc_visible_origin
- sisusb
->scrbuf
) / 2;
133 sisusb_setidxreg(sisusb
, SISCR
, 0x0c, (sisusb
->cur_start_addr
>> 8));
134 sisusb_setidxreg(sisusb
, SISCR
, 0x0d, (sisusb
->cur_start_addr
& 0xff));
138 sisusb_set_cursor(struct sisusb_usb_data
*sisusb
, unsigned int location
)
140 if (sisusb
->sisusb_cursor_loc
== location
)
143 sisusb
->sisusb_cursor_loc
= location
;
145 /* Hardware bug: Text cursor appears twice or not at all
146 * at some positions. Work around it with the cursor skew
150 if ((location
& 0x0007) == 0x0007) {
151 sisusb
->bad_cursor_pos
= 1;
153 if (sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0x1f, 0x20))
155 } else if (sisusb
->bad_cursor_pos
) {
156 if (sisusb_setidxregand(sisusb
, SISCR
, 0x0b, 0x1f))
158 sisusb
->bad_cursor_pos
= 0;
161 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, (location
>> 8)))
163 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, (location
& 0xff));
166 static inline struct sisusb_usb_data
*
167 sisusb_get_sisusb(unsigned short console
)
169 return mysisusbs
[console
];
173 sisusb_sisusb_valid(struct sisusb_usb_data
*sisusb
)
175 if (!sisusb
->present
|| !sisusb
->ready
|| !sisusb
->sisusb_dev
)
181 static struct sisusb_usb_data
*
182 sisusb_get_sisusb_lock_and_check(unsigned short console
)
184 struct sisusb_usb_data
*sisusb
;
186 /* We can't handle console calls in non-schedulable
187 * context due to our locks and the USB transport.
188 * So we simply ignore them. This should only affect
189 * some calls to printk.
194 if (!(sisusb
= sisusb_get_sisusb(console
)))
199 if (!sisusb_sisusb_valid(sisusb
) ||
200 !sisusb
->havethisconsole
[console
]) {
209 sisusb_is_inactive(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
)
211 if (sisusb
->is_gfx
||
212 sisusb
->textmodedestroyed
||
213 c
->vc_mode
!= KD_TEXT
)
219 /* con_startup console interface routine */
221 sisusbcon_startup(void)
226 /* con_init console interface routine */
228 sisusbcon_init(struct vc_data
*c
, int init
)
230 struct sisusb_usb_data
*sisusb
;
233 /* This is called by take_over_console(),
234 * ie by us/under our control. It is
235 * only called after text mode and fonts
236 * are set up/restored.
239 down(&disconnect_sem
);
241 if (!(sisusb
= sisusb_get_sisusb(c
->vc_num
))) {
248 if (!sisusb_sisusb_valid(sisusb
)) {
254 c
->vc_can_do_color
= 1;
256 c
->vc_complement_mask
= 0x7700;
258 c
->vc_hi_font_mask
= sisusb
->current_font_512
? 0x0800 : 0;
260 sisusb
->haveconsole
= 1;
262 sisusb
->havethisconsole
[c
->vc_num
] = 1;
264 /* We only support 640x400 */
265 c
->vc_scan_lines
= 400;
267 c
->vc_font
.height
= sisusb
->current_font_height
;
269 /* We only support width = 8 */
271 rows
= c
->vc_scan_lines
/ c
->vc_font
.height
;
273 /* Increment usage count for our sisusb.
274 * Doing so saves us from upping/downing
275 * the disconnect semaphore; we can't
276 * lose our sisusb until this is undone
277 * in con_deinit. For all other console
278 * interface functions, it suffices to
279 * use sisusb->lock and do a quick check
280 * of sisusb for device disconnection.
282 kref_get(&sisusb
->kref
);
284 if (!*c
->vc_uni_pagedir_loc
)
285 con_set_default_unimap(c
);
295 vc_resize(c
, cols
, rows
);
298 /* con_deinit console interface routine */
300 sisusbcon_deinit(struct vc_data
*c
)
302 struct sisusb_usb_data
*sisusb
;
305 /* This is called by take_over_console()
306 * and others, ie not under our control.
309 down(&disconnect_sem
);
311 if (!(sisusb
= sisusb_get_sisusb(c
->vc_num
))) {
318 /* Clear ourselves in mysisusbs */
319 mysisusbs
[c
->vc_num
] = NULL
;
321 sisusb
->havethisconsole
[c
->vc_num
] = 0;
323 /* Free our font buffer if all consoles are gone */
324 if (sisusb
->font_backup
) {
325 for(i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
326 if (sisusb
->havethisconsole
[c
->vc_num
])
329 if (i
== MAX_NR_CONSOLES
) {
330 vfree(sisusb
->font_backup
);
331 sisusb
->font_backup
= NULL
;
337 /* decrement the usage count on our sisusb */
338 kref_put(&sisusb
->kref
, sisusb_delete
);
343 /* interface routine */
345 sisusbcon_build_attr(struct vc_data
*c
, u8 color
, u8 intensity
,
346 u8 blink
, u8 underline
, u8 reverse
)
351 attr
= (attr
& 0xf0) | c
->vc_ulcolor
;
352 else if (intensity
== 0)
353 attr
= (attr
& 0xf0) | c
->vc_halfcolor
;
356 attr
= ((attr
) & 0x88) |
358 ((attr
) << 4)) & 0x77);
369 /* Interface routine */
371 sisusbcon_invert_region(struct vc_data
*vc
, u16
*p
, int count
)
373 /* Invert a region. This is called with a pointer
374 * to the console's internal screen buffer. So we
375 * simply do the inversion there and rely on
376 * a call to putc(s) to update the real screen.
380 u16 a
= sisusbcon_readw(p
);
383 (((a
) & 0x7000) >> 4) |
384 (((a
) & 0x0700) << 4);
386 sisusbcon_writew(a
, p
++);
390 #define SISUSB_VADDR(x,y) \
391 ((u16 *)c->vc_origin + \
392 (y) * sisusb->sisusb_num_columns + \
395 #define SISUSB_HADDR(x,y) \
396 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
397 (y) * sisusb->sisusb_num_columns + \
400 /* Interface routine */
402 sisusbcon_putc(struct vc_data
*c
, int ch
, int y
, int x
)
404 struct sisusb_usb_data
*sisusb
;
407 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
410 /* sisusb->lock is down */
412 /* Don't need to put the character into buffer ourselves,
413 * because the vt does this BEFORE calling us.
416 sisusbcon_writew(ch
, SISUSB_VADDR(x
, y
));
419 if (sisusb_is_inactive(c
, sisusb
)) {
425 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(x
, y
),
426 (u32
)SISUSB_HADDR(x
, y
), 2, &written
);
431 /* Interface routine */
433 sisusbcon_putcs(struct vc_data
*c
, const unsigned short *s
,
434 int count
, int y
, int x
)
436 struct sisusb_usb_data
*sisusb
;
441 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
444 /* sisusb->lock is down */
446 /* Need to put the characters into the buffer ourselves,
447 * because the vt does this AFTER calling us.
450 dest
= SISUSB_VADDR(x
, y
);
452 for (i
= count
; i
> 0; i
--)
453 sisusbcon_writew(sisusbcon_readw(s
++), dest
++);
455 if (sisusb_is_inactive(c
, sisusb
)) {
460 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(x
, y
),
461 (u32
)SISUSB_HADDR(x
, y
), count
* 2, &written
);
466 /* Interface routine */
468 sisusbcon_clear(struct vc_data
*c
, int y
, int x
, int height
, int width
)
470 struct sisusb_usb_data
*sisusb
;
471 u16 eattr
= c
->vc_video_erase_char
;
476 if (width
<= 0 || height
<= 0)
479 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
482 /* sisusb->lock is down */
484 /* Need to clear buffer ourselves, because the vt does
485 * this AFTER calling us.
488 dest
= SISUSB_VADDR(x
, y
);
490 cols
= sisusb
->sisusb_num_columns
;
495 if (x
== 0 && width
>= c
->vc_cols
) {
497 sisusbcon_memsetw(dest
, eattr
, height
* cols
* 2);
501 for (i
= height
; i
> 0; i
--, dest
+= cols
)
502 sisusbcon_memsetw(dest
, eattr
, width
* 2);
506 if (sisusb_is_inactive(c
, sisusb
)) {
511 length
= ((height
* cols
) - x
- (cols
- width
- x
)) * 2;
514 sisusb_copy_memory(sisusb
, (unsigned char *)SISUSB_VADDR(x
, y
),
515 (u32
)SISUSB_HADDR(x
, y
), length
, &written
);
520 /* Interface routine */
522 sisusbcon_bmove(struct vc_data
*c
, int sy
, int sx
,
523 int dy
, int dx
, int height
, int width
)
525 struct sisusb_usb_data
*sisusb
;
533 if (width
<= 0 || height
<= 0)
536 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
539 /* sisusb->lock is down */
541 cols
= sisusb
->sisusb_num_columns
;
543 /* Don't need to move data outselves, because
544 * vt does this BEFORE calling us.
545 * This is only used by vt's insert/deletechar.
548 if (sx
== 0 && dx
== 0 && width
>= c
->vc_cols
&& width
<= cols
) {
550 sisusbcon_memmovew(SISUSB_VADDR(0, dy
), SISUSB_VADDR(0, sy
),
553 } else if (dy
< sy
|| (dy
== sy
&& dx
< sx
)) {
555 src
= SISUSB_VADDR(sx
, sy
);
556 dest
= SISUSB_VADDR(dx
, dy
);
558 for (i
= height
; i
> 0; i
--) {
559 sisusbcon_memmovew(dest
, src
, width
* 2);
566 src
= SISUSB_VADDR(sx
, sy
+ height
- 1);
567 dest
= SISUSB_VADDR(dx
, dy
+ height
- 1);
569 for (i
= height
; i
> 0; i
--) {
570 sisusbcon_memmovew(dest
, src
, width
* 2);
578 if (sisusb_is_inactive(c
, sisusb
)) {
583 length
= ((height
* cols
) - dx
- (cols
- width
- dx
)) * 2;
586 sisusb_copy_memory(sisusb
, (unsigned char *)SISUSB_VADDR(dx
, dy
),
587 (u32
)SISUSB_HADDR(dx
, dy
), length
, &written
);
592 /* interface routine */
594 sisusbcon_switch(struct vc_data
*c
)
596 struct sisusb_usb_data
*sisusb
;
600 /* Returnvalue 0 means we have fully restored screen,
601 * and vt doesn't need to call do_update_region().
602 * Returnvalue != 0 naturally means the opposite.
605 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
608 /* sisusb->lock is down */
610 /* Don't write to screen if in gfx mode */
611 if (sisusb_is_inactive(c
, sisusb
)) {
616 /* That really should not happen. It would mean we are
617 * being called while the vc is using its private buffer
620 if (c
->vc_origin
== (unsigned long)c
->vc_screenbuf
) {
622 printk(KERN_DEBUG
"sisusb: ASSERT ORIGIN != SCREENBUF!\n");
626 /* Check that we don't copy too much */
627 length
= min((int)c
->vc_screenbuf_size
,
628 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
630 /* Restore the screen contents */
631 sisusbcon_memcpyw((u16
*)c
->vc_origin
, (u16
*)c
->vc_screenbuf
,
634 sisusb_copy_memory(sisusb
, (unsigned char *)c
->vc_origin
,
635 (u32
)SISUSB_HADDR(0, 0),
643 /* interface routine */
645 sisusbcon_save_screen(struct vc_data
*c
)
647 struct sisusb_usb_data
*sisusb
;
650 /* Save the current screen contents to vc's private
654 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
657 /* sisusb->lock is down */
659 if (sisusb_is_inactive(c
, sisusb
)) {
664 /* Check that we don't copy too much */
665 length
= min((int)c
->vc_screenbuf_size
,
666 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
668 /* Save the screen contents to vc's private buffer */
669 sisusbcon_memcpyw((u16
*)c
->vc_screenbuf
, (u16
*)c
->vc_origin
,
675 /* interface routine */
677 sisusbcon_set_palette(struct vc_data
*c
, unsigned char *table
)
679 struct sisusb_usb_data
*sisusb
;
682 /* Return value not used by vt */
684 if (!CON_IS_VISIBLE(c
))
687 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
690 /* sisusb->lock is down */
692 if (sisusb_is_inactive(c
, sisusb
)) {
697 for (i
= j
= 0; i
< 16; i
++) {
698 if (sisusb_setreg(sisusb
, SISCOLIDX
, table
[i
]))
700 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
702 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
704 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
713 /* interface routine */
715 sisusbcon_blank(struct vc_data
*c
, int blank
, int mode_switch
)
717 struct sisusb_usb_data
*sisusb
;
718 u8 sr1
, cr17
, pmreg
, cr63
;
722 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
725 /* sisusb->lock is down */
728 sisusb
->is_gfx
= blank
? 1 : 0;
730 if (sisusb_is_inactive(c
, sisusb
)) {
737 case 1: /* Normal blanking: Clear screen */
739 sisusbcon_memsetw((u16
*)c
->vc_origin
,
740 c
->vc_video_erase_char
,
741 c
->vc_screenbuf_size
);
742 sisusb_copy_memory(sisusb
,
743 (unsigned char *)c
->vc_origin
,
744 (u32
)(sisusb
->vrambase
+
745 (c
->vc_origin
- sisusb
->scrbuf
)),
746 c
->vc_screenbuf_size
, &written
);
747 sisusb
->con_blanked
= 1;
751 default: /* VESA blanking */
753 case 0: /* Unblank */
759 sisusb
->con_blanked
= 0;
761 case VESA_VSYNC_SUSPEND
+ 1:
767 case VESA_HSYNC_SUSPEND
+ 1:
773 case VESA_POWERDOWN
+ 1:
784 sisusb_setidxregandor(sisusb
, SISSR
, 0x01, ~0x20, sr1
);
785 sisusb_setidxregandor(sisusb
, SISCR
, 0x17, 0x7f, cr17
);
786 sisusb_setidxregandor(sisusb
, SISSR
, 0x1f, 0x3f, pmreg
);
787 sisusb_setidxregandor(sisusb
, SISCR
, 0x63, 0xbf, cr63
);
796 /* interface routine */
798 sisusbcon_scrolldelta(struct vc_data
*c
, int lines
)
800 struct sisusb_usb_data
*sisusb
;
801 int margin
= c
->vc_size_row
* 4;
804 /* The return value does not seem to be used */
806 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
809 /* sisusb->lock is down */
811 if (sisusb_is_inactive(c
, sisusb
)) {
816 if (!lines
) /* Turn scrollback off */
817 c
->vc_visible_origin
= c
->vc_origin
;
820 if (sisusb
->con_rolled_over
>
821 (c
->vc_scr_end
- sisusb
->scrbuf
) + margin
) {
823 ul
= c
->vc_scr_end
- sisusb
->scrbuf
;
824 we
= sisusb
->con_rolled_over
+ c
->vc_size_row
;
829 we
= sisusb
->scrbuf_size
;
833 p
= (c
->vc_visible_origin
- sisusb
->scrbuf
- ul
+ we
) % we
+
834 lines
* c
->vc_size_row
;
836 st
= (c
->vc_origin
- sisusb
->scrbuf
- ul
+ we
) % we
;
847 c
->vc_visible_origin
= sisusb
->scrbuf
+ (p
+ ul
) % we
;
850 sisusbcon_set_start_address(sisusb
, c
);
857 /* Interface routine */
859 sisusbcon_cursor(struct vc_data
*c
, int mode
)
861 struct sisusb_usb_data
*sisusb
;
862 int from
, to
, baseline
;
864 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
867 /* sisusb->lock is down */
869 if (sisusb_is_inactive(c
, sisusb
)) {
874 if (c
->vc_origin
!= c
->vc_visible_origin
) {
875 c
->vc_visible_origin
= c
->vc_origin
;
876 sisusbcon_set_start_address(sisusb
, c
);
879 if (mode
== CM_ERASE
) {
880 sisusb_setidxregor(sisusb
, SISCR
, 0x0a, 0x20);
881 sisusb
->sisusb_cursor_size_to
= -1;
886 sisusb_set_cursor(sisusb
, (c
->vc_pos
- sisusb
->scrbuf
) / 2);
888 baseline
= c
->vc_font
.height
- (c
->vc_font
.height
< 10 ? 1 : 2);
890 switch (c
->vc_cursor_type
& 0x0f) {
891 case CUR_BLOCK
: from
= 1;
892 to
= c
->vc_font
.height
;
894 case CUR_TWO_THIRDS
: from
= c
->vc_font
.height
/ 3;
897 case CUR_LOWER_HALF
: from
= c
->vc_font
.height
/ 2;
900 case CUR_LOWER_THIRD
: from
= (c
->vc_font
.height
* 2) / 3;
903 case CUR_NONE
: from
= 31;
907 case CUR_UNDERLINE
: from
= baseline
- 1;
912 if (sisusb
->sisusb_cursor_size_from
!= from
||
913 sisusb
->sisusb_cursor_size_to
!= to
) {
915 sisusb_setidxreg(sisusb
, SISCR
, 0x0a, from
);
916 sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0xe0, to
);
918 sisusb
->sisusb_cursor_size_from
= from
;
919 sisusb
->sisusb_cursor_size_to
= to
;
926 sisusbcon_scroll_area(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
,
927 int t
, int b
, int dir
, int lines
)
929 int cols
= sisusb
->sisusb_num_columns
;
930 int length
= ((b
- t
) * cols
) * 2;
931 u16 eattr
= c
->vc_video_erase_char
;
934 /* sisusb->lock is down */
936 /* Scroll an area which does not match the
937 * visible screen's dimensions. This needs
938 * to be done separately, as it does not
939 * use hardware panning.
945 sisusbcon_memmovew(SISUSB_VADDR(0, t
),
946 SISUSB_VADDR(0, t
+ lines
),
947 (b
- t
- lines
) * cols
* 2);
948 sisusbcon_memsetw(SISUSB_VADDR(0, b
- lines
), eattr
,
953 sisusbcon_memmovew(SISUSB_VADDR(0, t
+ lines
),
955 (b
- t
- lines
) * cols
* 2);
956 sisusbcon_memsetw(SISUSB_VADDR(0, t
), eattr
,
961 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(0, t
),
962 (u32
)SISUSB_HADDR(0, t
), length
, &written
);
969 /* Interface routine */
971 sisusbcon_scroll(struct vc_data
*c
, int t
, int b
, int dir
, int lines
)
973 struct sisusb_usb_data
*sisusb
;
974 u16 eattr
= c
->vc_video_erase_char
;
977 unsigned long oldorigin
;
978 unsigned int delta
= lines
* c
->vc_size_row
;
981 /* Returning != 0 means we have done the scrolling successfully.
982 * Returning 0 makes vt do the scrolling on its own.
983 * Note that con_scroll is only called if the console is
984 * visible. In that case, the origin should be our buffer,
985 * not the vt's private one.
991 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
994 /* sisusb->lock is down */
996 if (sisusb_is_inactive(c
, sisusb
)) {
1002 if (t
|| b
!= c
->vc_rows
)
1003 return sisusbcon_scroll_area(c
, sisusb
, t
, b
, dir
, lines
);
1005 if (c
->vc_origin
!= c
->vc_visible_origin
) {
1006 c
->vc_visible_origin
= c
->vc_origin
;
1007 sisusbcon_set_start_address(sisusb
, c
);
1010 /* limit amount to maximum realistic size */
1011 if (lines
> c
->vc_rows
)
1014 oldorigin
= c
->vc_origin
;
1020 if (c
->vc_scr_end
+ delta
>=
1021 sisusb
->scrbuf
+ sisusb
->scrbuf_size
) {
1022 sisusbcon_memcpyw((u16
*)sisusb
->scrbuf
,
1023 (u16
*)(oldorigin
+ delta
),
1024 c
->vc_screenbuf_size
- delta
);
1025 c
->vc_origin
= sisusb
->scrbuf
;
1026 sisusb
->con_rolled_over
= oldorigin
- sisusb
->scrbuf
;
1029 c
->vc_origin
+= delta
;
1032 (u16
*)(c
->vc_origin
+ c
->vc_screenbuf_size
- delta
),
1039 if (oldorigin
- delta
< sisusb
->scrbuf
) {
1040 sisusbcon_memmovew((u16
*)(sisusb
->scrbuf
+
1041 sisusb
->scrbuf_size
-
1042 c
->vc_screenbuf_size
+
1045 c
->vc_screenbuf_size
- delta
);
1046 c
->vc_origin
= sisusb
->scrbuf
+
1047 sisusb
->scrbuf_size
-
1048 c
->vc_screenbuf_size
;
1049 sisusb
->con_rolled_over
= 0;
1052 c
->vc_origin
-= delta
;
1054 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
1056 scr_memsetw((u16
*)(c
->vc_origin
), eattr
, delta
);
1061 originoffset
= (u32
)(c
->vc_origin
- sisusb
->scrbuf
);
1064 sisusb_copy_memory(sisusb
,
1065 (char *)c
->vc_origin
,
1066 (u32
)(sisusb
->vrambase
+ originoffset
),
1067 c
->vc_screenbuf_size
, &written
);
1068 else if (dir
== SM_UP
)
1069 sisusb_copy_memory(sisusb
,
1070 (char *)c
->vc_origin
+ c
->vc_screenbuf_size
- delta
,
1071 (u32
)sisusb
->vrambase
+ originoffset
+
1072 c
->vc_screenbuf_size
- delta
,
1075 sisusb_copy_memory(sisusb
,
1076 (char *)c
->vc_origin
,
1077 (u32
)(sisusb
->vrambase
+ originoffset
),
1080 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
1081 c
->vc_visible_origin
= c
->vc_origin
;
1083 sisusbcon_set_start_address(sisusb
, c
);
1085 c
->vc_pos
= c
->vc_pos
- oldorigin
+ c
->vc_origin
;
1092 /* Interface routine */
1094 sisusbcon_set_origin(struct vc_data
*c
)
1096 struct sisusb_usb_data
*sisusb
;
1098 /* Returning != 0 means we were successful.
1099 * Returning 0 will vt make to use its own
1100 * screenbuffer as the origin.
1103 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
1106 /* sisusb->lock is down */
1108 if (sisusb_is_inactive(c
, sisusb
) || sisusb
->con_blanked
) {
1113 c
->vc_origin
= c
->vc_visible_origin
= sisusb
->scrbuf
;
1115 sisusbcon_set_start_address(sisusb
, c
);
1117 sisusb
->con_rolled_over
= 0;
1124 /* Interface routine */
1126 sisusbcon_resize(struct vc_data
*c
, unsigned int newcols
, unsigned int newrows
)
1128 struct sisusb_usb_data
*sisusb
;
1131 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
1134 fh
= sisusb
->current_font_height
;
1138 /* We are quite unflexible as regards resizing. The vt code
1139 * handles sizes where the line length isn't equal the pitch
1140 * quite badly. As regards the rows, our panning tricks only
1141 * work well if the number of rows equals the visible number
1145 if (newcols
!= 80 || c
->vc_scan_lines
/ fh
!= newrows
)
1152 sisusbcon_do_font_op(struct sisusb_usb_data
*sisusb
, int set
, int slot
,
1153 u8
*arg
, int cmapsz
, int ch512
, int dorecalc
,
1154 struct vc_data
*c
, int fh
, int uplock
)
1156 int font_select
= 0x00, i
, err
= 0;
1160 /* sisusb->lock is down */
1163 * The default font is kept in slot 0.
1164 * A user font is loaded in slot 2 (256 ch)
1168 if ((slot
!= 0 && slot
!= 2) || !fh
) {
1175 sisusb
->font_slot
= slot
;
1177 /* Default font is always 256 */
1181 offset
= 4 * cmapsz
;
1183 font_select
= (slot
== 0) ? 0x00 : (ch512
? 0x0e : 0x0a);
1185 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1186 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x04); /* Write to plane 2 */
1187 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x07); /* Memory mode a0-bf */
1188 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset */
1193 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x03); /* Select plane read 2 */
1194 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x00); /* Disable odd/even */
1195 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x00); /* Address range a0-bf */
1202 for (i
= 0; i
< cmapsz
; i
++) {
1203 err
|= sisusb_writeb(sisusb
,
1204 sisusb
->vrambase
+ offset
+ i
,
1210 for (i
= 0; i
< cmapsz
; i
++) {
1211 err
|= sisusb_readb(sisusb
,
1212 sisusb
->vrambase
+ offset
+ i
,
1219 * In 512-character mode, the character map is not contiguous if
1220 * we want to remain EGA compatible -- which we do
1225 for (i
= 0; i
< cmapsz
; i
++) {
1226 err
|= sisusb_writeb(sisusb
,
1227 sisusb
->vrambase
+ offset
+
1234 for (i
= 0; i
< cmapsz
; i
++) {
1235 err
|= sisusb_readb(sisusb
,
1236 sisusb
->vrambase
+ offset
+
1248 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1249 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x03); /* Write to planes 0+1 */
1250 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x03); /* Memory mode a0-bf */
1252 sisusb_setidxreg(sisusb
, SISSR
, 0x03, font_select
);
1253 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset end */
1258 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x00); /* Select plane read 0 */
1259 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x10); /* Enable odd/even */
1260 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x06); /* Address range b8-bf */
1265 if ((set
) && (ch512
!= sisusb
->current_font_512
)) {
1267 /* Font is shared among all our consoles.
1268 * And so is the hi_font_mask.
1270 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1271 struct vc_data
*c
= vc_cons
[i
].d
;
1272 if (c
&& c
->vc_sw
== &sisusb_con
)
1273 c
->vc_hi_font_mask
= ch512
? 0x0800 : 0;
1276 sisusb
->current_font_512
= ch512
;
1278 /* color plane enable register:
1279 256-char: enable intensity bit
1280 512-char: disable intensity bit */
1281 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1282 sisusb_setreg(sisusb
, SISAR
, 0x12);
1283 sisusb_setreg(sisusb
, SISAR
, ch512
? 0x07 : 0x0f);
1285 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1286 sisusb_setreg(sisusb
, SISAR
, 0x20);
1287 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1293 * Adjust the screen to fit a font of a certain height
1296 unsigned char ovr
, vde
, fsr
;
1297 int rows
= 0, maxscan
= 0;
1301 /* Number of video rows */
1302 rows
= c
->vc_scan_lines
/ fh
;
1303 /* Scan lines to actually display-1 */
1304 maxscan
= rows
* fh
- 1;
1306 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1307 rows, maxscan, fh, c->vc_scan_lines);*/
1309 sisusb_getidxreg(sisusb
, SISCR
, 0x07, &ovr
);
1310 vde
= maxscan
& 0xff;
1311 ovr
= (ovr
& 0xbd) |
1312 ((maxscan
& 0x100) >> 7) |
1313 ((maxscan
& 0x200) >> 3);
1314 sisusb_setidxreg(sisusb
, SISCR
, 0x07, ovr
);
1315 sisusb_setidxreg(sisusb
, SISCR
, 0x12, vde
);
1319 sisusb_getidxreg(sisusb
, SISCR
, 0x09, &fsr
);
1320 fsr
= (fsr
& 0xe0) | (fh
- 1);
1321 sisusb_setidxreg(sisusb
, SISCR
, 0x09, fsr
);
1322 sisusb
->current_font_height
= fh
;
1324 sisusb
->sisusb_cursor_size_from
= -1;
1325 sisusb
->sisusb_cursor_size_to
= -1;
1332 if (dorecalc
&& c
) {
1333 int i
, rows
= c
->vc_scan_lines
/ fh
;
1335 /* Now adjust our consoles' size */
1337 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1338 struct vc_data
*vc
= vc_cons
[i
].d
;
1340 if (vc
&& vc
->vc_sw
== &sisusb_con
) {
1341 if (CON_IS_VISIBLE(vc
)) {
1342 vc
->vc_sw
->con_cursor(vc
, CM_DRAW
);
1344 vc
->vc_font
.height
= fh
;
1345 vc_resize(vc
, 0, rows
);
1359 /* Interface routine */
1361 sisusbcon_font_set(struct vc_data
*c
, struct console_font
*font
,
1364 struct sisusb_usb_data
*sisusb
;
1365 unsigned charcount
= font
->charcount
;
1367 if (font
->width
!= 8 || (charcount
!= 256 && charcount
!= 512))
1370 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
1373 /* sisusb->lock is down */
1375 /* Save the user-provided font into a buffer. This
1376 * is used for restoring text mode after quitting
1377 * from X and for the con_getfont routine.
1379 if (sisusb
->font_backup
) {
1380 if (sisusb
->font_backup_size
< charcount
) {
1381 vfree(sisusb
->font_backup
);
1382 sisusb
->font_backup
= NULL
;
1386 if (!sisusb
->font_backup
)
1387 sisusb
->font_backup
= vmalloc(charcount
* 32);
1389 if (sisusb
->font_backup
) {
1390 memcpy(sisusb
->font_backup
, font
->data
, charcount
* 32);
1391 sisusb
->font_backup_size
= charcount
;
1392 sisusb
->font_backup_height
= font
->height
;
1393 sisusb
->font_backup_512
= (charcount
== 512) ? 1 : 0;
1396 /* do_font_op ups sisusb->lock */
1398 return sisusbcon_do_font_op(sisusb
, 1, 2, font
->data
,
1399 8192, (charcount
== 512),
1400 (!(flags
& KD_FONT_FLAG_DONT_RECALC
)) ? 1 : 0,
1401 c
, font
->height
, 1);
1404 /* Interface routine */
1406 sisusbcon_font_get(struct vc_data
*c
, struct console_font
*font
)
1408 struct sisusb_usb_data
*sisusb
;
1410 if (!(sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
)))
1413 /* sisusb->lock is down */
1416 font
->height
= c
->vc_font
.height
;
1417 font
->charcount
= 256;
1424 if (!sisusb
->font_backup
) {
1429 /* Copy 256 chars only, like vgacon */
1430 memcpy(font
->data
, sisusb
->font_backup
, 256 * 32);
1438 * The console `switch' structure for the sisusb console
1441 static const struct consw sisusb_con
= {
1442 .owner
= THIS_MODULE
,
1443 .con_startup
= sisusbcon_startup
,
1444 .con_init
= sisusbcon_init
,
1445 .con_deinit
= sisusbcon_deinit
,
1446 .con_clear
= sisusbcon_clear
,
1447 .con_putc
= sisusbcon_putc
,
1448 .con_putcs
= sisusbcon_putcs
,
1449 .con_cursor
= sisusbcon_cursor
,
1450 .con_scroll
= sisusbcon_scroll
,
1451 .con_bmove
= sisusbcon_bmove
,
1452 .con_switch
= sisusbcon_switch
,
1453 .con_blank
= sisusbcon_blank
,
1454 .con_font_set
= sisusbcon_font_set
,
1455 .con_font_get
= sisusbcon_font_get
,
1456 .con_set_palette
= sisusbcon_set_palette
,
1457 .con_scrolldelta
= sisusbcon_scrolldelta
,
1458 .con_build_attr
= sisusbcon_build_attr
,
1459 .con_invert_region
= sisusbcon_invert_region
,
1460 .con_set_origin
= sisusbcon_set_origin
,
1461 .con_save_screen
= sisusbcon_save_screen
,
1462 .con_resize
= sisusbcon_resize
,
1465 /* Our very own dummy console driver */
1467 static const char *sisusbdummycon_startup(void)
1469 return "SISUSBVGADUMMY";
1472 static void sisusbdummycon_init(struct vc_data
*vc
, int init
)
1474 vc
->vc_can_do_color
= 1;
1479 vc_resize(vc
, 80, 25);
1482 static int sisusbdummycon_dummy(void)
1487 #define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
1489 const struct consw sisusb_dummy_con
= {
1490 .owner
= THIS_MODULE
,
1491 .con_startup
= sisusbdummycon_startup
,
1492 .con_init
= sisusbdummycon_init
,
1493 .con_deinit
= SISUSBCONDUMMY
,
1494 .con_clear
= SISUSBCONDUMMY
,
1495 .con_putc
= SISUSBCONDUMMY
,
1496 .con_putcs
= SISUSBCONDUMMY
,
1497 .con_cursor
= SISUSBCONDUMMY
,
1498 .con_scroll
= SISUSBCONDUMMY
,
1499 .con_bmove
= SISUSBCONDUMMY
,
1500 .con_switch
= SISUSBCONDUMMY
,
1501 .con_blank
= SISUSBCONDUMMY
,
1502 .con_font_set
= SISUSBCONDUMMY
,
1503 .con_font_get
= SISUSBCONDUMMY
,
1504 .con_font_default
= SISUSBCONDUMMY
,
1505 .con_font_copy
= SISUSBCONDUMMY
,
1506 .con_set_palette
= SISUSBCONDUMMY
,
1507 .con_scrolldelta
= SISUSBCONDUMMY
,
1511 sisusb_console_init(struct sisusb_usb_data
*sisusb
, int first
, int last
)
1513 int i
, ret
, minor
= sisusb
->minor
;
1515 down(&disconnect_sem
);
1517 down(&sisusb
->lock
);
1519 /* Erm.. that should not happen */
1520 if (sisusb
->haveconsole
|| !sisusb
->SiS_Pr
) {
1522 up(&disconnect_sem
);
1526 sisusb
->con_first
= first
;
1527 sisusb
->con_last
= last
;
1530 first
> MAX_NR_CONSOLES
||
1531 last
> MAX_NR_CONSOLES
) {
1533 up(&disconnect_sem
);
1537 /* If gfxcore not initialized or no consoles given, quit graciously */
1538 if (!sisusb
->gfxinit
|| first
< 1 || last
< 1) {
1540 up(&disconnect_sem
);
1544 sisusb
->sisusb_cursor_loc
= -1;
1545 sisusb
->sisusb_cursor_size_from
= -1;
1546 sisusb
->sisusb_cursor_size_to
= -1;
1548 /* Set up text mode (and upload default font) */
1549 if (sisusb_reset_text_mode(sisusb
, 1)) {
1551 up(&disconnect_sem
);
1553 "sisusbvga[%d]: Failed to set up text mode\n",
1558 /* Initialize some gfx registers */
1559 sisusb_initialize(sisusb
);
1561 for (i
= first
- 1; i
<= last
- 1; i
++) {
1562 /* Save sisusb for our interface routines */
1563 mysisusbs
[i
] = sisusb
;
1566 /* Initial console setup */
1567 sisusb
->sisusb_num_columns
= 80;
1569 /* Use a 32K buffer (matches b8000-bffff area) */
1570 sisusb
->scrbuf_size
= 32 * 1024;
1572 /* Allocate screen buffer */
1573 if (!(sisusb
->scrbuf
= (unsigned long)vmalloc(sisusb
->scrbuf_size
))) {
1575 up(&disconnect_sem
);
1577 "sisusbvga[%d]: Failed to allocate screen buffer\n",
1583 up(&disconnect_sem
);
1585 /* Now grab the desired console(s) */
1586 ret
= take_over_console(&sisusb_con
, first
- 1, last
- 1, 0);
1589 sisusb
->haveconsole
= 1;
1591 for (i
= first
- 1; i
<= last
- 1; i
++)
1592 mysisusbs
[i
] = NULL
;
1599 sisusb_console_exit(struct sisusb_usb_data
*sisusb
)
1603 /* This is called if the device is disconnected
1604 * and while disconnect and lock semaphores
1605 * are up. This should be save because we
1606 * can't lose our sisusb any other way but by
1607 * disconnection (and hence, the disconnect
1608 * sema is for protecting all other access
1609 * functions from disconnection, not the
1613 /* Now what do we do in case of disconnection:
1614 * One alternative would be to simply call
1615 * give_up_console(). Nah, not a good idea.
1616 * give_up_console() is obviously buggy as it
1617 * only discards the consw pointer from the
1618 * driver_map, but doesn't adapt vc->vc_sw
1619 * of the affected consoles. Hence, the next
1620 * call to any of the console functions will
1621 * eventually take a trip to oops county.
1622 * Also, give_up_console for some reason
1623 * doesn't decrement our module refcount.
1624 * Instead, we switch our consoles to a private
1625 * dummy console. This, of course, keeps our
1626 * refcount up as well, but it works perfectly.
1629 if (sisusb
->haveconsole
) {
1630 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1631 if (sisusb
->havethisconsole
[i
])
1632 take_over_console(&sisusb_dummy_con
, i
, i
, 0);
1633 /* At this point, con_deinit for all our
1634 * consoles is executed by take_over_console().
1636 sisusb
->haveconsole
= 0;
1639 vfree((void *)sisusb
->scrbuf
);
1642 vfree(sisusb
->font_backup
);
1643 sisusb
->font_backup
= NULL
;
1646 void __init
sisusb_init_concode(void)
1650 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1651 mysisusbs
[i
] = NULL
;
1654 #endif /* INCL_CON */