1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
5 * VGA text mode console part
7 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
9 * If distributed as part of the Linux kernel, this code is licensed under the
10 * terms of the GPL v2.
12 * Otherwise, the following license terms apply:
14 * * Redistribution and use in source and binary forms, with or without
15 * * modification, are permitted provided that the following conditions
17 * * 1) Redistributions of source code must retain the above copyright
18 * * notice, this list of conditions and the following disclaimer.
19 * * 2) Redistributions in binary form must reproduce the above copyright
20 * * notice, this list of conditions and the following disclaimer in the
21 * * documentation and/or other materials provided with the distribution.
22 * * 3) The name of the author may not be used to endorse or promote products
23 * * derived from this software without specific psisusbr written permission.
25 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
26 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Author: Thomas Winischhofer <thomas@winischhofer.net>
38 * Portions based on vgacon.c which are
39 * Created 28 Sep 1997 by Geert Uytterhoeven
40 * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
41 * based on code Copyright (C) 1991, 1992 Linus Torvalds
44 * A note on using in_atomic() in here: We can't handle console
45 * calls from non-schedulable context due to our USB-dependend
46 * nature. For now, this driver just ignores any calls if it
51 #include <linux/mutex.h>
52 #include <linux/module.h>
53 #include <linux/kernel.h>
54 #include <linux/signal.h>
56 #include <linux/usb.h>
57 #include <linux/tty.h>
58 #include <linux/console.h>
59 #include <linux/string.h>
61 #include <linux/init.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/ioport.h>
67 #include <linux/interrupt.h>
68 #include <linux/vmalloc.h>
71 #include "sisusb_init.h"
73 /* vc_data -> sisusb conversion table */
74 static struct sisusb_usb_data
*mysisusbs
[MAX_NR_CONSOLES
];
76 /* Forward declaration */
77 static const struct consw sisusb_con
;
80 sisusbcon_memsetw(u16
*s
, u16 c
, unsigned int count
)
82 memset16(s
, c
, count
/ 2);
86 sisusb_initialize(struct sisusb_usb_data
*sisusb
)
88 /* Reset cursor and start address */
89 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0c, 0x00))
91 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0d, 0x00))
93 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, 0x00))
95 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, 0x00);
99 sisusbcon_set_start_address(struct sisusb_usb_data
*sisusb
, struct vc_data
*c
)
101 sisusb
->cur_start_addr
= (c
->vc_visible_origin
- sisusb
->scrbuf
) / 2;
103 sisusb_setidxreg(sisusb
, SISCR
, 0x0c, (sisusb
->cur_start_addr
>> 8));
104 sisusb_setidxreg(sisusb
, SISCR
, 0x0d, (sisusb
->cur_start_addr
& 0xff));
108 sisusb_set_cursor(struct sisusb_usb_data
*sisusb
, unsigned int location
)
110 if (sisusb
->sisusb_cursor_loc
== location
)
113 sisusb
->sisusb_cursor_loc
= location
;
115 /* Hardware bug: Text cursor appears twice or not at all
116 * at some positions. Work around it with the cursor skew
120 if ((location
& 0x0007) == 0x0007) {
121 sisusb
->bad_cursor_pos
= 1;
123 if (sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0x1f, 0x20))
125 } else if (sisusb
->bad_cursor_pos
) {
126 if (sisusb_setidxregand(sisusb
, SISCR
, 0x0b, 0x1f))
128 sisusb
->bad_cursor_pos
= 0;
131 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, (location
>> 8)))
133 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, (location
& 0xff));
136 static inline struct sisusb_usb_data
*
137 sisusb_get_sisusb(unsigned short console
)
139 return mysisusbs
[console
];
143 sisusb_sisusb_valid(struct sisusb_usb_data
*sisusb
)
145 if (!sisusb
->present
|| !sisusb
->ready
|| !sisusb
->sisusb_dev
)
151 static struct sisusb_usb_data
*
152 sisusb_get_sisusb_lock_and_check(unsigned short console
)
154 struct sisusb_usb_data
*sisusb
;
156 /* We can't handle console calls in non-schedulable
157 * context due to our locks and the USB transport.
158 * So we simply ignore them. This should only affect
159 * some calls to printk.
164 sisusb
= sisusb_get_sisusb(console
);
168 mutex_lock(&sisusb
->lock
);
170 if (!sisusb_sisusb_valid(sisusb
) ||
171 !sisusb
->havethisconsole
[console
]) {
172 mutex_unlock(&sisusb
->lock
);
180 sisusb_is_inactive(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
)
182 if (sisusb
->is_gfx
||
183 sisusb
->textmodedestroyed
||
184 c
->vc_mode
!= KD_TEXT
)
190 /* con_startup console interface routine */
192 sisusbcon_startup(void)
197 /* con_init console interface routine */
199 sisusbcon_init(struct vc_data
*c
, int init
)
201 struct sisusb_usb_data
*sisusb
;
204 /* This is called by do_take_over_console(),
205 * ie by us/under our control. It is
206 * only called after text mode and fonts
207 * are set up/restored.
210 sisusb
= sisusb_get_sisusb(c
->vc_num
);
214 mutex_lock(&sisusb
->lock
);
216 if (!sisusb_sisusb_valid(sisusb
)) {
217 mutex_unlock(&sisusb
->lock
);
221 c
->vc_can_do_color
= 1;
223 c
->vc_complement_mask
= 0x7700;
225 c
->vc_hi_font_mask
= sisusb
->current_font_512
? 0x0800 : 0;
227 sisusb
->haveconsole
= 1;
229 sisusb
->havethisconsole
[c
->vc_num
] = 1;
231 /* We only support 640x400 */
232 c
->vc_scan_lines
= 400;
234 c
->vc_font
.height
= sisusb
->current_font_height
;
236 /* We only support width = 8 */
238 rows
= c
->vc_scan_lines
/ c
->vc_font
.height
;
240 /* Increment usage count for our sisusb.
241 * Doing so saves us from upping/downing
242 * the disconnect semaphore; we can't
243 * lose our sisusb until this is undone
244 * in con_deinit. For all other console
245 * interface functions, it suffices to
246 * use sisusb->lock and do a quick check
247 * of sisusb for device disconnection.
249 kref_get(&sisusb
->kref
);
251 if (!*c
->vc_uni_pagedir_loc
)
252 con_set_default_unimap(c
);
254 mutex_unlock(&sisusb
->lock
);
260 vc_resize(c
, cols
, rows
);
263 /* con_deinit console interface routine */
265 sisusbcon_deinit(struct vc_data
*c
)
267 struct sisusb_usb_data
*sisusb
;
270 /* This is called by do_take_over_console()
271 * and others, ie not under our control.
274 sisusb
= sisusb_get_sisusb(c
->vc_num
);
278 mutex_lock(&sisusb
->lock
);
280 /* Clear ourselves in mysisusbs */
281 mysisusbs
[c
->vc_num
] = NULL
;
283 sisusb
->havethisconsole
[c
->vc_num
] = 0;
285 /* Free our font buffer if all consoles are gone */
286 if (sisusb
->font_backup
) {
287 for(i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
288 if (sisusb
->havethisconsole
[c
->vc_num
])
291 if (i
== MAX_NR_CONSOLES
) {
292 vfree(sisusb
->font_backup
);
293 sisusb
->font_backup
= NULL
;
297 mutex_unlock(&sisusb
->lock
);
299 /* decrement the usage count on our sisusb */
300 kref_put(&sisusb
->kref
, sisusb_delete
);
303 /* interface routine */
305 sisusbcon_build_attr(struct vc_data
*c
, u8 color
, u8 intensity
,
306 u8 blink
, u8 underline
, u8 reverse
, u8 unused
)
311 attr
= (attr
& 0xf0) | c
->vc_ulcolor
;
312 else if (intensity
== 0)
313 attr
= (attr
& 0xf0) | c
->vc_halfcolor
;
316 attr
= ((attr
) & 0x88) |
318 ((attr
) << 4)) & 0x77);
329 /* Interface routine */
331 sisusbcon_invert_region(struct vc_data
*vc
, u16
*p
, int count
)
333 /* Invert a region. This is called with a pointer
334 * to the console's internal screen buffer. So we
335 * simply do the inversion there and rely on
336 * a call to putc(s) to update the real screen.
342 *p
++ = ((a
) & 0x88ff) |
343 (((a
) & 0x7000) >> 4) |
344 (((a
) & 0x0700) << 4);
348 static inline void *sisusb_vaddr(const struct sisusb_usb_data
*sisusb
,
349 const struct vc_data
*c
, unsigned int x
, unsigned int y
)
351 return (u16
*)c
->vc_origin
+ y
* sisusb
->sisusb_num_columns
+ x
;
354 static inline unsigned long sisusb_haddr(const struct sisusb_usb_data
*sisusb
,
355 const struct vc_data
*c
, unsigned int x
, unsigned int y
)
357 unsigned long offset
= c
->vc_origin
- sisusb
->scrbuf
;
359 /* 2 bytes per each character */
360 offset
+= 2 * (y
* sisusb
->sisusb_num_columns
+ x
);
362 return sisusb
->vrambase
+ offset
;
365 /* Interface routine */
367 sisusbcon_putc(struct vc_data
*c
, int ch
, int y
, int x
)
369 struct sisusb_usb_data
*sisusb
;
371 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
375 /* sisusb->lock is down */
376 if (sisusb_is_inactive(c
, sisusb
)) {
377 mutex_unlock(&sisusb
->lock
);
381 sisusb_copy_memory(sisusb
, sisusb_vaddr(sisusb
, c
, x
, y
),
382 sisusb_haddr(sisusb
, c
, x
, y
), 2);
384 mutex_unlock(&sisusb
->lock
);
387 /* Interface routine */
389 sisusbcon_putcs(struct vc_data
*c
, const unsigned short *s
,
390 int count
, int y
, int x
)
392 struct sisusb_usb_data
*sisusb
;
394 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
398 /* sisusb->lock is down */
400 /* Need to put the characters into the buffer ourselves,
401 * because the vt does this AFTER calling us.
404 memcpy(sisusb_vaddr(sisusb
, c
, x
, y
), s
, count
* 2);
406 if (sisusb_is_inactive(c
, sisusb
)) {
407 mutex_unlock(&sisusb
->lock
);
411 sisusb_copy_memory(sisusb
, sisusb_vaddr(sisusb
, c
, x
, y
),
412 sisusb_haddr(sisusb
, c
, x
, y
), count
* 2);
414 mutex_unlock(&sisusb
->lock
);
417 /* Interface routine */
419 sisusbcon_clear(struct vc_data
*c
, int y
, int x
, int height
, int width
)
421 struct sisusb_usb_data
*sisusb
;
422 u16 eattr
= c
->vc_video_erase_char
;
426 if (width
<= 0 || height
<= 0)
429 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
433 /* sisusb->lock is down */
435 /* Need to clear buffer ourselves, because the vt does
436 * this AFTER calling us.
439 dest
= sisusb_vaddr(sisusb
, c
, x
, y
);
441 cols
= sisusb
->sisusb_num_columns
;
446 if (x
== 0 && width
>= c
->vc_cols
) {
448 sisusbcon_memsetw(dest
, eattr
, height
* cols
* 2);
452 for (i
= height
; i
> 0; i
--, dest
+= cols
)
453 sisusbcon_memsetw(dest
, eattr
, width
* 2);
457 if (sisusb_is_inactive(c
, sisusb
)) {
458 mutex_unlock(&sisusb
->lock
);
462 length
= ((height
* cols
) - x
- (cols
- width
- x
)) * 2;
465 sisusb_copy_memory(sisusb
, sisusb_vaddr(sisusb
, c
, x
, y
),
466 sisusb_haddr(sisusb
, c
, x
, y
), length
);
468 mutex_unlock(&sisusb
->lock
);
471 /* interface routine */
473 sisusbcon_switch(struct vc_data
*c
)
475 struct sisusb_usb_data
*sisusb
;
478 /* Returnvalue 0 means we have fully restored screen,
479 * and vt doesn't need to call do_update_region().
480 * Returnvalue != 0 naturally means the opposite.
483 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
487 /* sisusb->lock is down */
489 /* Don't write to screen if in gfx mode */
490 if (sisusb_is_inactive(c
, sisusb
)) {
491 mutex_unlock(&sisusb
->lock
);
495 /* That really should not happen. It would mean we are
496 * being called while the vc is using its private buffer
499 if (c
->vc_origin
== (unsigned long)c
->vc_screenbuf
) {
500 mutex_unlock(&sisusb
->lock
);
501 dev_dbg(&sisusb
->sisusb_dev
->dev
, "ASSERT ORIGIN != SCREENBUF!\n");
505 /* Check that we don't copy too much */
506 length
= min((int)c
->vc_screenbuf_size
,
507 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
509 /* Restore the screen contents */
510 memcpy((u16
*)c
->vc_origin
, (u16
*)c
->vc_screenbuf
, length
);
512 sisusb_copy_memory(sisusb
, (char *)c
->vc_origin
,
513 sisusb_haddr(sisusb
, c
, 0, 0), length
);
515 mutex_unlock(&sisusb
->lock
);
520 /* interface routine */
522 sisusbcon_save_screen(struct vc_data
*c
)
524 struct sisusb_usb_data
*sisusb
;
527 /* Save the current screen contents to vc's private
531 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
535 /* sisusb->lock is down */
537 if (sisusb_is_inactive(c
, sisusb
)) {
538 mutex_unlock(&sisusb
->lock
);
542 /* Check that we don't copy too much */
543 length
= min((int)c
->vc_screenbuf_size
,
544 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
546 /* Save the screen contents to vc's private buffer */
547 memcpy((u16
*)c
->vc_screenbuf
, (u16
*)c
->vc_origin
, length
);
549 mutex_unlock(&sisusb
->lock
);
552 /* interface routine */
554 sisusbcon_set_palette(struct vc_data
*c
, const unsigned char *table
)
556 struct sisusb_usb_data
*sisusb
;
559 /* Return value not used by vt */
561 if (!con_is_visible(c
))
564 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
568 /* sisusb->lock is down */
570 if (sisusb_is_inactive(c
, sisusb
)) {
571 mutex_unlock(&sisusb
->lock
);
575 for (i
= j
= 0; i
< 16; i
++) {
576 if (sisusb_setreg(sisusb
, SISCOLIDX
, table
[i
]))
578 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
580 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
582 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
586 mutex_unlock(&sisusb
->lock
);
589 /* interface routine */
591 sisusbcon_blank(struct vc_data
*c
, int blank
, int mode_switch
)
593 struct sisusb_usb_data
*sisusb
;
594 u8 sr1
, cr17
, pmreg
, cr63
;
597 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
601 /* sisusb->lock is down */
604 sisusb
->is_gfx
= blank
? 1 : 0;
606 if (sisusb_is_inactive(c
, sisusb
)) {
607 mutex_unlock(&sisusb
->lock
);
613 case 1: /* Normal blanking: Clear screen */
615 sisusbcon_memsetw((u16
*)c
->vc_origin
,
616 c
->vc_video_erase_char
,
617 c
->vc_screenbuf_size
);
618 sisusb_copy_memory(sisusb
, (char *)c
->vc_origin
,
619 sisusb_haddr(sisusb
, c
, 0, 0),
620 c
->vc_screenbuf_size
);
621 sisusb
->con_blanked
= 1;
625 default: /* VESA blanking */
627 case 0: /* Unblank */
633 sisusb
->con_blanked
= 0;
635 case VESA_VSYNC_SUSPEND
+ 1:
641 case VESA_HSYNC_SUSPEND
+ 1:
647 case VESA_POWERDOWN
+ 1:
654 mutex_unlock(&sisusb
->lock
);
658 sisusb_setidxregandor(sisusb
, SISSR
, 0x01, ~0x20, sr1
);
659 sisusb_setidxregandor(sisusb
, SISCR
, 0x17, 0x7f, cr17
);
660 sisusb_setidxregandor(sisusb
, SISSR
, 0x1f, 0x3f, pmreg
);
661 sisusb_setidxregandor(sisusb
, SISCR
, 0x63, 0xbf, cr63
);
665 mutex_unlock(&sisusb
->lock
);
670 /* interface routine */
672 sisusbcon_scrolldelta(struct vc_data
*c
, int lines
)
674 struct sisusb_usb_data
*sisusb
;
676 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
680 /* sisusb->lock is down */
682 if (sisusb_is_inactive(c
, sisusb
)) {
683 mutex_unlock(&sisusb
->lock
);
687 vc_scrolldelta_helper(c
, lines
, sisusb
->con_rolled_over
,
688 (void *)sisusb
->scrbuf
, sisusb
->scrbuf_size
);
690 sisusbcon_set_start_address(sisusb
, c
);
692 mutex_unlock(&sisusb
->lock
);
695 /* Interface routine */
697 sisusbcon_cursor(struct vc_data
*c
, int mode
)
699 struct sisusb_usb_data
*sisusb
;
700 int from
, to
, baseline
;
702 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
706 /* sisusb->lock is down */
708 if (sisusb_is_inactive(c
, sisusb
)) {
709 mutex_unlock(&sisusb
->lock
);
713 if (c
->vc_origin
!= c
->vc_visible_origin
) {
714 c
->vc_visible_origin
= c
->vc_origin
;
715 sisusbcon_set_start_address(sisusb
, c
);
718 if (mode
== CM_ERASE
) {
719 sisusb_setidxregor(sisusb
, SISCR
, 0x0a, 0x20);
720 sisusb
->sisusb_cursor_size_to
= -1;
721 mutex_unlock(&sisusb
->lock
);
725 sisusb_set_cursor(sisusb
, (c
->vc_pos
- sisusb
->scrbuf
) / 2);
727 baseline
= c
->vc_font
.height
- (c
->vc_font
.height
< 10 ? 1 : 2);
729 switch (c
->vc_cursor_type
& 0x0f) {
730 case CUR_BLOCK
: from
= 1;
731 to
= c
->vc_font
.height
;
733 case CUR_TWO_THIRDS
: from
= c
->vc_font
.height
/ 3;
736 case CUR_LOWER_HALF
: from
= c
->vc_font
.height
/ 2;
739 case CUR_LOWER_THIRD
: from
= (c
->vc_font
.height
* 2) / 3;
742 case CUR_NONE
: from
= 31;
746 case CUR_UNDERLINE
: from
= baseline
- 1;
751 if (sisusb
->sisusb_cursor_size_from
!= from
||
752 sisusb
->sisusb_cursor_size_to
!= to
) {
754 sisusb_setidxreg(sisusb
, SISCR
, 0x0a, from
);
755 sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0xe0, to
);
757 sisusb
->sisusb_cursor_size_from
= from
;
758 sisusb
->sisusb_cursor_size_to
= to
;
761 mutex_unlock(&sisusb
->lock
);
765 sisusbcon_scroll_area(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
,
766 unsigned int t
, unsigned int b
, enum con_scroll dir
,
769 int cols
= sisusb
->sisusb_num_columns
;
770 int length
= ((b
- t
) * cols
) * 2;
771 u16 eattr
= c
->vc_video_erase_char
;
773 /* sisusb->lock is down */
775 /* Scroll an area which does not match the
776 * visible screen's dimensions. This needs
777 * to be done separately, as it does not
778 * use hardware panning.
784 memmove(sisusb_vaddr(sisusb
, c
, 0, t
),
785 sisusb_vaddr(sisusb
, c
, 0, t
+ lines
),
786 (b
- t
- lines
) * cols
* 2);
787 sisusbcon_memsetw(sisusb_vaddr(sisusb
, c
, 0, b
- lines
),
788 eattr
, lines
* cols
* 2);
792 memmove(sisusb_vaddr(sisusb
, c
, 0, t
+ lines
),
793 sisusb_vaddr(sisusb
, c
, 0, t
),
794 (b
- t
- lines
) * cols
* 2);
795 sisusbcon_memsetw(sisusb_vaddr(sisusb
, c
, 0, t
), eattr
,
800 sisusb_copy_memory(sisusb
, sisusb_vaddr(sisusb
, c
, 0, t
),
801 sisusb_haddr(sisusb
, c
, 0, t
), length
);
803 mutex_unlock(&sisusb
->lock
);
808 /* Interface routine */
810 sisusbcon_scroll(struct vc_data
*c
, unsigned int t
, unsigned int b
,
811 enum con_scroll dir
, unsigned int lines
)
813 struct sisusb_usb_data
*sisusb
;
814 u16 eattr
= c
->vc_video_erase_char
;
816 unsigned long oldorigin
;
817 unsigned int delta
= lines
* c
->vc_size_row
;
819 /* Returning != 0 means we have done the scrolling successfully.
820 * Returning 0 makes vt do the scrolling on its own.
821 * Note that con_scroll is only called if the console is
822 * visible. In that case, the origin should be our buffer,
823 * not the vt's private one.
829 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
833 /* sisusb->lock is down */
835 if (sisusb_is_inactive(c
, sisusb
)) {
836 mutex_unlock(&sisusb
->lock
);
841 if (t
|| b
!= c
->vc_rows
)
842 return sisusbcon_scroll_area(c
, sisusb
, t
, b
, dir
, lines
);
844 if (c
->vc_origin
!= c
->vc_visible_origin
) {
845 c
->vc_visible_origin
= c
->vc_origin
;
846 sisusbcon_set_start_address(sisusb
, c
);
849 /* limit amount to maximum realistic size */
850 if (lines
> c
->vc_rows
)
853 oldorigin
= c
->vc_origin
;
859 if (c
->vc_scr_end
+ delta
>=
860 sisusb
->scrbuf
+ sisusb
->scrbuf_size
) {
861 memcpy((u16
*)sisusb
->scrbuf
,
862 (u16
*)(oldorigin
+ delta
),
863 c
->vc_screenbuf_size
- delta
);
864 c
->vc_origin
= sisusb
->scrbuf
;
865 sisusb
->con_rolled_over
= oldorigin
- sisusb
->scrbuf
;
868 c
->vc_origin
+= delta
;
871 (u16
*)(c
->vc_origin
+ c
->vc_screenbuf_size
- delta
),
878 if (oldorigin
- delta
< sisusb
->scrbuf
) {
879 memmove((void *)sisusb
->scrbuf
+ sisusb
->scrbuf_size
-
880 c
->vc_screenbuf_size
+ delta
,
882 c
->vc_screenbuf_size
- delta
);
883 c
->vc_origin
= sisusb
->scrbuf
+
884 sisusb
->scrbuf_size
-
885 c
->vc_screenbuf_size
;
886 sisusb
->con_rolled_over
= 0;
889 c
->vc_origin
-= delta
;
891 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
893 scr_memsetw((u16
*)(c
->vc_origin
), eattr
, delta
);
899 sisusb_copy_memory(sisusb
,
900 (char *)c
->vc_origin
,
901 sisusb_haddr(sisusb
, c
, 0, 0),
902 c
->vc_screenbuf_size
);
903 else if (dir
== SM_UP
)
904 sisusb_copy_memory(sisusb
,
905 (char *)c
->vc_origin
+ c
->vc_screenbuf_size
- delta
,
906 sisusb_haddr(sisusb
, c
, 0, 0) +
907 c
->vc_screenbuf_size
- delta
,
910 sisusb_copy_memory(sisusb
,
911 (char *)c
->vc_origin
,
912 sisusb_haddr(sisusb
, c
, 0, 0),
915 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
916 c
->vc_visible_origin
= c
->vc_origin
;
918 sisusbcon_set_start_address(sisusb
, c
);
920 c
->vc_pos
= c
->vc_pos
- oldorigin
+ c
->vc_origin
;
922 mutex_unlock(&sisusb
->lock
);
927 /* Interface routine */
929 sisusbcon_set_origin(struct vc_data
*c
)
931 struct sisusb_usb_data
*sisusb
;
933 /* Returning != 0 means we were successful.
934 * Returning 0 will vt make to use its own
935 * screenbuffer as the origin.
938 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
942 /* sisusb->lock is down */
944 if (sisusb_is_inactive(c
, sisusb
) || sisusb
->con_blanked
) {
945 mutex_unlock(&sisusb
->lock
);
949 c
->vc_origin
= c
->vc_visible_origin
= sisusb
->scrbuf
;
951 sisusbcon_set_start_address(sisusb
, c
);
953 sisusb
->con_rolled_over
= 0;
955 mutex_unlock(&sisusb
->lock
);
960 /* Interface routine */
962 sisusbcon_resize(struct vc_data
*c
, unsigned int newcols
, unsigned int newrows
,
965 struct sisusb_usb_data
*sisusb
;
968 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
972 fh
= sisusb
->current_font_height
;
974 mutex_unlock(&sisusb
->lock
);
976 /* We are quite unflexible as regards resizing. The vt code
977 * handles sizes where the line length isn't equal the pitch
978 * quite badly. As regards the rows, our panning tricks only
979 * work well if the number of rows equals the visible number
983 if (newcols
!= 80 || c
->vc_scan_lines
/ fh
!= newrows
)
990 sisusbcon_do_font_op(struct sisusb_usb_data
*sisusb
, int set
, int slot
,
991 u8
*arg
, int cmapsz
, int ch512
, int dorecalc
,
992 struct vc_data
*c
, int fh
, int uplock
)
994 int font_select
= 0x00, i
, err
= 0;
998 /* sisusb->lock is down */
1001 * The default font is kept in slot 0.
1002 * A user font is loaded in slot 2 (256 ch)
1006 if ((slot
!= 0 && slot
!= 2) || !fh
) {
1008 mutex_unlock(&sisusb
->lock
);
1013 sisusb
->font_slot
= slot
;
1015 /* Default font is always 256 */
1019 offset
= 4 * cmapsz
;
1021 font_select
= (slot
== 0) ? 0x00 : (ch512
? 0x0e : 0x0a);
1023 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1024 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x04); /* Write to plane 2 */
1025 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x07); /* Memory mode a0-bf */
1026 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset */
1031 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x03); /* Select plane read 2 */
1032 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x00); /* Disable odd/even */
1033 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x00); /* Address range a0-bf */
1040 for (i
= 0; i
< cmapsz
; i
++) {
1041 err
|= sisusb_writeb(sisusb
,
1042 sisusb
->vrambase
+ offset
+ i
,
1048 for (i
= 0; i
< cmapsz
; i
++) {
1049 err
|= sisusb_readb(sisusb
,
1050 sisusb
->vrambase
+ offset
+ i
,
1057 * In 512-character mode, the character map is not contiguous if
1058 * we want to remain EGA compatible -- which we do
1063 for (i
= 0; i
< cmapsz
; i
++) {
1064 err
|= sisusb_writeb(sisusb
,
1065 sisusb
->vrambase
+ offset
+
1072 for (i
= 0; i
< cmapsz
; i
++) {
1073 err
|= sisusb_readb(sisusb
,
1074 sisusb
->vrambase
+ offset
+
1086 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1087 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x03); /* Write to planes 0+1 */
1088 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x03); /* Memory mode a0-bf */
1090 sisusb_setidxreg(sisusb
, SISSR
, 0x03, font_select
);
1091 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset end */
1096 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x00); /* Select plane read 0 */
1097 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x10); /* Enable odd/even */
1098 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x06); /* Address range b8-bf */
1103 if ((set
) && (ch512
!= sisusb
->current_font_512
)) {
1105 /* Font is shared among all our consoles.
1106 * And so is the hi_font_mask.
1108 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1109 struct vc_data
*d
= vc_cons
[i
].d
;
1110 if (d
&& d
->vc_sw
== &sisusb_con
)
1111 d
->vc_hi_font_mask
= ch512
? 0x0800 : 0;
1114 sisusb
->current_font_512
= ch512
;
1116 /* color plane enable register:
1117 256-char: enable intensity bit
1118 512-char: disable intensity bit */
1119 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1120 sisusb_setreg(sisusb
, SISAR
, 0x12);
1121 sisusb_setreg(sisusb
, SISAR
, ch512
? 0x07 : 0x0f);
1123 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1124 sisusb_setreg(sisusb
, SISAR
, 0x20);
1125 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1131 * Adjust the screen to fit a font of a certain height
1134 unsigned char ovr
, vde
, fsr
;
1135 int rows
= 0, maxscan
= 0;
1139 /* Number of video rows */
1140 rows
= c
->vc_scan_lines
/ fh
;
1141 /* Scan lines to actually display-1 */
1142 maxscan
= rows
* fh
- 1;
1144 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1145 rows, maxscan, fh, c->vc_scan_lines);*/
1147 sisusb_getidxreg(sisusb
, SISCR
, 0x07, &ovr
);
1148 vde
= maxscan
& 0xff;
1149 ovr
= (ovr
& 0xbd) |
1150 ((maxscan
& 0x100) >> 7) |
1151 ((maxscan
& 0x200) >> 3);
1152 sisusb_setidxreg(sisusb
, SISCR
, 0x07, ovr
);
1153 sisusb_setidxreg(sisusb
, SISCR
, 0x12, vde
);
1157 sisusb_getidxreg(sisusb
, SISCR
, 0x09, &fsr
);
1158 fsr
= (fsr
& 0xe0) | (fh
- 1);
1159 sisusb_setidxreg(sisusb
, SISCR
, 0x09, fsr
);
1160 sisusb
->current_font_height
= fh
;
1162 sisusb
->sisusb_cursor_size_from
= -1;
1163 sisusb
->sisusb_cursor_size_to
= -1;
1168 mutex_unlock(&sisusb
->lock
);
1170 if (dorecalc
&& c
) {
1171 int rows
= c
->vc_scan_lines
/ fh
;
1173 /* Now adjust our consoles' size */
1175 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1176 struct vc_data
*vc
= vc_cons
[i
].d
;
1178 if (vc
&& vc
->vc_sw
== &sisusb_con
) {
1179 if (con_is_visible(vc
)) {
1180 vc
->vc_sw
->con_cursor(vc
, CM_DRAW
);
1182 vc
->vc_font
.height
= fh
;
1183 vc_resize(vc
, 0, rows
);
1192 mutex_unlock(&sisusb
->lock
);
1197 /* Interface routine */
1199 sisusbcon_font_set(struct vc_data
*c
, struct console_font
*font
,
1202 struct sisusb_usb_data
*sisusb
;
1203 unsigned charcount
= font
->charcount
;
1205 if (font
->width
!= 8 || (charcount
!= 256 && charcount
!= 512))
1208 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1212 /* sisusb->lock is down */
1214 /* Save the user-provided font into a buffer. This
1215 * is used for restoring text mode after quitting
1216 * from X and for the con_getfont routine.
1218 if (sisusb
->font_backup
) {
1219 if (sisusb
->font_backup_size
< charcount
) {
1220 vfree(sisusb
->font_backup
);
1221 sisusb
->font_backup
= NULL
;
1225 if (!sisusb
->font_backup
)
1226 sisusb
->font_backup
= vmalloc(array_size(charcount
, 32));
1228 if (sisusb
->font_backup
) {
1229 memcpy(sisusb
->font_backup
, font
->data
, charcount
* 32);
1230 sisusb
->font_backup_size
= charcount
;
1231 sisusb
->font_backup_height
= font
->height
;
1232 sisusb
->font_backup_512
= (charcount
== 512) ? 1 : 0;
1235 /* do_font_op ups sisusb->lock */
1237 return sisusbcon_do_font_op(sisusb
, 1, 2, font
->data
,
1238 8192, (charcount
== 512),
1239 (!(flags
& KD_FONT_FLAG_DONT_RECALC
)) ? 1 : 0,
1240 c
, font
->height
, 1);
1243 /* Interface routine */
1245 sisusbcon_font_get(struct vc_data
*c
, struct console_font
*font
)
1247 struct sisusb_usb_data
*sisusb
;
1249 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1253 /* sisusb->lock is down */
1256 font
->height
= c
->vc_font
.height
;
1257 font
->charcount
= 256;
1260 mutex_unlock(&sisusb
->lock
);
1264 if (!sisusb
->font_backup
) {
1265 mutex_unlock(&sisusb
->lock
);
1269 /* Copy 256 chars only, like vgacon */
1270 memcpy(font
->data
, sisusb
->font_backup
, 256 * 32);
1272 mutex_unlock(&sisusb
->lock
);
1278 * The console `switch' structure for the sisusb console
1281 static const struct consw sisusb_con
= {
1282 .owner
= THIS_MODULE
,
1283 .con_startup
= sisusbcon_startup
,
1284 .con_init
= sisusbcon_init
,
1285 .con_deinit
= sisusbcon_deinit
,
1286 .con_clear
= sisusbcon_clear
,
1287 .con_putc
= sisusbcon_putc
,
1288 .con_putcs
= sisusbcon_putcs
,
1289 .con_cursor
= sisusbcon_cursor
,
1290 .con_scroll
= sisusbcon_scroll
,
1291 .con_switch
= sisusbcon_switch
,
1292 .con_blank
= sisusbcon_blank
,
1293 .con_font_set
= sisusbcon_font_set
,
1294 .con_font_get
= sisusbcon_font_get
,
1295 .con_set_palette
= sisusbcon_set_palette
,
1296 .con_scrolldelta
= sisusbcon_scrolldelta
,
1297 .con_build_attr
= sisusbcon_build_attr
,
1298 .con_invert_region
= sisusbcon_invert_region
,
1299 .con_set_origin
= sisusbcon_set_origin
,
1300 .con_save_screen
= sisusbcon_save_screen
,
1301 .con_resize
= sisusbcon_resize
,
1304 /* Our very own dummy console driver */
1306 static const char *sisusbdummycon_startup(void)
1308 return "SISUSBVGADUMMY";
1311 static void sisusbdummycon_init(struct vc_data
*vc
, int init
)
1313 vc
->vc_can_do_color
= 1;
1318 vc_resize(vc
, 80, 25);
1321 static void sisusbdummycon_deinit(struct vc_data
*vc
) { }
1322 static void sisusbdummycon_clear(struct vc_data
*vc
, int sy
, int sx
,
1323 int height
, int width
) { }
1324 static void sisusbdummycon_putc(struct vc_data
*vc
, int c
, int ypos
,
1326 static void sisusbdummycon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1327 int count
, int ypos
, int xpos
) { }
1328 static void sisusbdummycon_cursor(struct vc_data
*vc
, int mode
) { }
1330 static bool sisusbdummycon_scroll(struct vc_data
*vc
, unsigned int top
,
1331 unsigned int bottom
, enum con_scroll dir
,
1337 static int sisusbdummycon_switch(struct vc_data
*vc
)
1342 static int sisusbdummycon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
1347 static int sisusbdummycon_font_set(struct vc_data
*vc
,
1348 struct console_font
*font
,
1354 static int sisusbdummycon_font_default(struct vc_data
*vc
,
1355 struct console_font
*font
, char *name
)
1360 static int sisusbdummycon_font_copy(struct vc_data
*vc
, int con
)
1365 static const struct consw sisusb_dummy_con
= {
1366 .owner
= THIS_MODULE
,
1367 .con_startup
= sisusbdummycon_startup
,
1368 .con_init
= sisusbdummycon_init
,
1369 .con_deinit
= sisusbdummycon_deinit
,
1370 .con_clear
= sisusbdummycon_clear
,
1371 .con_putc
= sisusbdummycon_putc
,
1372 .con_putcs
= sisusbdummycon_putcs
,
1373 .con_cursor
= sisusbdummycon_cursor
,
1374 .con_scroll
= sisusbdummycon_scroll
,
1375 .con_switch
= sisusbdummycon_switch
,
1376 .con_blank
= sisusbdummycon_blank
,
1377 .con_font_set
= sisusbdummycon_font_set
,
1378 .con_font_default
= sisusbdummycon_font_default
,
1379 .con_font_copy
= sisusbdummycon_font_copy
,
1383 sisusb_console_init(struct sisusb_usb_data
*sisusb
, int first
, int last
)
1387 mutex_lock(&sisusb
->lock
);
1389 /* Erm.. that should not happen */
1390 if (sisusb
->haveconsole
|| !sisusb
->SiS_Pr
) {
1391 mutex_unlock(&sisusb
->lock
);
1395 sisusb
->con_first
= first
;
1396 sisusb
->con_last
= last
;
1399 first
> MAX_NR_CONSOLES
||
1400 last
> MAX_NR_CONSOLES
) {
1401 mutex_unlock(&sisusb
->lock
);
1405 /* If gfxcore not initialized or no consoles given, quit graciously */
1406 if (!sisusb
->gfxinit
|| first
< 1 || last
< 1) {
1407 mutex_unlock(&sisusb
->lock
);
1411 sisusb
->sisusb_cursor_loc
= -1;
1412 sisusb
->sisusb_cursor_size_from
= -1;
1413 sisusb
->sisusb_cursor_size_to
= -1;
1415 /* Set up text mode (and upload default font) */
1416 if (sisusb_reset_text_mode(sisusb
, 1)) {
1417 mutex_unlock(&sisusb
->lock
);
1418 dev_err(&sisusb
->sisusb_dev
->dev
, "Failed to set up text mode\n");
1422 /* Initialize some gfx registers */
1423 sisusb_initialize(sisusb
);
1425 for (i
= first
- 1; i
<= last
- 1; i
++) {
1426 /* Save sisusb for our interface routines */
1427 mysisusbs
[i
] = sisusb
;
1430 /* Initial console setup */
1431 sisusb
->sisusb_num_columns
= 80;
1433 /* Use a 32K buffer (matches b8000-bffff area) */
1434 sisusb
->scrbuf_size
= 32 * 1024;
1436 /* Allocate screen buffer */
1437 if (!(sisusb
->scrbuf
= (unsigned long)vmalloc(sisusb
->scrbuf_size
))) {
1438 mutex_unlock(&sisusb
->lock
);
1439 dev_err(&sisusb
->sisusb_dev
->dev
, "Failed to allocate screen buffer\n");
1443 mutex_unlock(&sisusb
->lock
);
1445 /* Now grab the desired console(s) */
1447 ret
= do_take_over_console(&sisusb_con
, first
- 1, last
- 1, 0);
1450 sisusb
->haveconsole
= 1;
1452 for (i
= first
- 1; i
<= last
- 1; i
++)
1453 mysisusbs
[i
] = NULL
;
1460 sisusb_console_exit(struct sisusb_usb_data
*sisusb
)
1464 /* This is called if the device is disconnected
1465 * and while disconnect and lock semaphores
1466 * are up. This should be save because we
1467 * can't lose our sisusb any other way but by
1468 * disconnection (and hence, the disconnect
1469 * sema is for protecting all other access
1470 * functions from disconnection, not the
1474 /* Now what do we do in case of disconnection:
1475 * One alternative would be to simply call
1476 * give_up_console(). Nah, not a good idea.
1477 * give_up_console() is obviously buggy as it
1478 * only discards the consw pointer from the
1479 * driver_map, but doesn't adapt vc->vc_sw
1480 * of the affected consoles. Hence, the next
1481 * call to any of the console functions will
1482 * eventually take a trip to oops county.
1483 * Also, give_up_console for some reason
1484 * doesn't decrement our module refcount.
1485 * Instead, we switch our consoles to a private
1486 * dummy console. This, of course, keeps our
1487 * refcount up as well, but it works perfectly.
1490 if (sisusb
->haveconsole
) {
1491 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1492 if (sisusb
->havethisconsole
[i
]) {
1494 do_take_over_console(&sisusb_dummy_con
, i
, i
, 0);
1496 /* At this point, con_deinit for all our
1497 * consoles is executed by do_take_over_console().
1500 sisusb
->haveconsole
= 0;
1503 vfree((void *)sisusb
->scrbuf
);
1506 vfree(sisusb
->font_backup
);
1507 sisusb
->font_backup
= NULL
;
1510 void __init
sisusb_init_concode(void)
1514 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1515 mysisusbs
[i
] = NULL
;