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 #ifdef INCL_SISUSB_CON
75 #define sisusbcon_writew(val, addr) (*(addr) = (val))
76 #define sisusbcon_readw(addr) (*(addr))
77 #define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
78 #define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
80 /* vc_data -> sisusb conversion table */
81 static struct sisusb_usb_data
*mysisusbs
[MAX_NR_CONSOLES
];
83 /* Forward declaration */
84 static const struct consw sisusb_con
;
87 sisusbcon_memsetw(u16
*s
, u16 c
, unsigned int count
)
91 sisusbcon_writew(c
, s
++);
95 sisusb_initialize(struct sisusb_usb_data
*sisusb
)
97 /* Reset cursor and start address */
98 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0c, 0x00))
100 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0d, 0x00))
102 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, 0x00))
104 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, 0x00);
108 sisusbcon_set_start_address(struct sisusb_usb_data
*sisusb
, struct vc_data
*c
)
110 sisusb
->cur_start_addr
= (c
->vc_visible_origin
- sisusb
->scrbuf
) / 2;
112 sisusb_setidxreg(sisusb
, SISCR
, 0x0c, (sisusb
->cur_start_addr
>> 8));
113 sisusb_setidxreg(sisusb
, SISCR
, 0x0d, (sisusb
->cur_start_addr
& 0xff));
117 sisusb_set_cursor(struct sisusb_usb_data
*sisusb
, unsigned int location
)
119 if (sisusb
->sisusb_cursor_loc
== location
)
122 sisusb
->sisusb_cursor_loc
= location
;
124 /* Hardware bug: Text cursor appears twice or not at all
125 * at some positions. Work around it with the cursor skew
129 if ((location
& 0x0007) == 0x0007) {
130 sisusb
->bad_cursor_pos
= 1;
132 if (sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0x1f, 0x20))
134 } else if (sisusb
->bad_cursor_pos
) {
135 if (sisusb_setidxregand(sisusb
, SISCR
, 0x0b, 0x1f))
137 sisusb
->bad_cursor_pos
= 0;
140 if (sisusb_setidxreg(sisusb
, SISCR
, 0x0e, (location
>> 8)))
142 sisusb_setidxreg(sisusb
, SISCR
, 0x0f, (location
& 0xff));
145 static inline struct sisusb_usb_data
*
146 sisusb_get_sisusb(unsigned short console
)
148 return mysisusbs
[console
];
152 sisusb_sisusb_valid(struct sisusb_usb_data
*sisusb
)
154 if (!sisusb
->present
|| !sisusb
->ready
|| !sisusb
->sisusb_dev
)
160 static struct sisusb_usb_data
*
161 sisusb_get_sisusb_lock_and_check(unsigned short console
)
163 struct sisusb_usb_data
*sisusb
;
165 /* We can't handle console calls in non-schedulable
166 * context due to our locks and the USB transport.
167 * So we simply ignore them. This should only affect
168 * some calls to printk.
173 sisusb
= sisusb_get_sisusb(console
);
177 mutex_lock(&sisusb
->lock
);
179 if (!sisusb_sisusb_valid(sisusb
) ||
180 !sisusb
->havethisconsole
[console
]) {
181 mutex_unlock(&sisusb
->lock
);
189 sisusb_is_inactive(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
)
191 if (sisusb
->is_gfx
||
192 sisusb
->textmodedestroyed
||
193 c
->vc_mode
!= KD_TEXT
)
199 /* con_startup console interface routine */
201 sisusbcon_startup(void)
206 /* con_init console interface routine */
208 sisusbcon_init(struct vc_data
*c
, int init
)
210 struct sisusb_usb_data
*sisusb
;
213 /* This is called by do_take_over_console(),
214 * ie by us/under our control. It is
215 * only called after text mode and fonts
216 * are set up/restored.
219 sisusb
= sisusb_get_sisusb(c
->vc_num
);
223 mutex_lock(&sisusb
->lock
);
225 if (!sisusb_sisusb_valid(sisusb
)) {
226 mutex_unlock(&sisusb
->lock
);
230 c
->vc_can_do_color
= 1;
232 c
->vc_complement_mask
= 0x7700;
234 c
->vc_hi_font_mask
= sisusb
->current_font_512
? 0x0800 : 0;
236 sisusb
->haveconsole
= 1;
238 sisusb
->havethisconsole
[c
->vc_num
] = 1;
240 /* We only support 640x400 */
241 c
->vc_scan_lines
= 400;
243 c
->vc_font
.height
= sisusb
->current_font_height
;
245 /* We only support width = 8 */
247 rows
= c
->vc_scan_lines
/ c
->vc_font
.height
;
249 /* Increment usage count for our sisusb.
250 * Doing so saves us from upping/downing
251 * the disconnect semaphore; we can't
252 * lose our sisusb until this is undone
253 * in con_deinit. For all other console
254 * interface functions, it suffices to
255 * use sisusb->lock and do a quick check
256 * of sisusb for device disconnection.
258 kref_get(&sisusb
->kref
);
260 if (!*c
->vc_uni_pagedir_loc
)
261 con_set_default_unimap(c
);
263 mutex_unlock(&sisusb
->lock
);
269 vc_resize(c
, cols
, rows
);
272 /* con_deinit console interface routine */
274 sisusbcon_deinit(struct vc_data
*c
)
276 struct sisusb_usb_data
*sisusb
;
279 /* This is called by do_take_over_console()
280 * and others, ie not under our control.
283 sisusb
= sisusb_get_sisusb(c
->vc_num
);
287 mutex_lock(&sisusb
->lock
);
289 /* Clear ourselves in mysisusbs */
290 mysisusbs
[c
->vc_num
] = NULL
;
292 sisusb
->havethisconsole
[c
->vc_num
] = 0;
294 /* Free our font buffer if all consoles are gone */
295 if (sisusb
->font_backup
) {
296 for(i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
297 if (sisusb
->havethisconsole
[c
->vc_num
])
300 if (i
== MAX_NR_CONSOLES
) {
301 vfree(sisusb
->font_backup
);
302 sisusb
->font_backup
= NULL
;
306 mutex_unlock(&sisusb
->lock
);
308 /* decrement the usage count on our sisusb */
309 kref_put(&sisusb
->kref
, sisusb_delete
);
312 /* interface routine */
314 sisusbcon_build_attr(struct vc_data
*c
, u8 color
, u8 intensity
,
315 u8 blink
, u8 underline
, u8 reverse
, u8 unused
)
320 attr
= (attr
& 0xf0) | c
->vc_ulcolor
;
321 else if (intensity
== 0)
322 attr
= (attr
& 0xf0) | c
->vc_halfcolor
;
325 attr
= ((attr
) & 0x88) |
327 ((attr
) << 4)) & 0x77);
338 /* Interface routine */
340 sisusbcon_invert_region(struct vc_data
*vc
, u16
*p
, int count
)
342 /* Invert a region. This is called with a pointer
343 * to the console's internal screen buffer. So we
344 * simply do the inversion there and rely on
345 * a call to putc(s) to update the real screen.
349 u16 a
= sisusbcon_readw(p
);
352 (((a
) & 0x7000) >> 4) |
353 (((a
) & 0x0700) << 4);
355 sisusbcon_writew(a
, p
++);
359 #define SISUSB_VADDR(x,y) \
360 ((u16 *)c->vc_origin + \
361 (y) * sisusb->sisusb_num_columns + \
364 #define SISUSB_HADDR(x,y) \
365 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
366 (y) * sisusb->sisusb_num_columns + \
369 /* Interface routine */
371 sisusbcon_putc(struct vc_data
*c
, int ch
, int y
, int x
)
373 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);
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
;
401 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
405 /* sisusb->lock is down */
407 /* Need to put the characters into the buffer ourselves,
408 * because the vt does this AFTER calling us.
411 dest
= SISUSB_VADDR(x
, y
);
413 for (i
= count
; i
> 0; i
--)
414 sisusbcon_writew(sisusbcon_readw(s
++), dest
++);
416 if (sisusb_is_inactive(c
, sisusb
)) {
417 mutex_unlock(&sisusb
->lock
);
421 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(x
, y
),
422 (long)SISUSB_HADDR(x
, y
), count
* 2);
424 mutex_unlock(&sisusb
->lock
);
427 /* Interface routine */
429 sisusbcon_clear(struct vc_data
*c
, int y
, int x
, int height
, int width
)
431 struct sisusb_usb_data
*sisusb
;
432 u16 eattr
= c
->vc_video_erase_char
;
436 if (width
<= 0 || height
<= 0)
439 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
443 /* sisusb->lock is down */
445 /* Need to clear buffer ourselves, because the vt does
446 * this AFTER calling us.
449 dest
= SISUSB_VADDR(x
, y
);
451 cols
= sisusb
->sisusb_num_columns
;
456 if (x
== 0 && width
>= c
->vc_cols
) {
458 sisusbcon_memsetw(dest
, eattr
, height
* cols
* 2);
462 for (i
= height
; i
> 0; i
--, dest
+= cols
)
463 sisusbcon_memsetw(dest
, eattr
, width
* 2);
467 if (sisusb_is_inactive(c
, sisusb
)) {
468 mutex_unlock(&sisusb
->lock
);
472 length
= ((height
* cols
) - x
- (cols
- width
- x
)) * 2;
475 sisusb_copy_memory(sisusb
, (unsigned char *)SISUSB_VADDR(x
, y
),
476 (long)SISUSB_HADDR(x
, y
), length
);
478 mutex_unlock(&sisusb
->lock
);
481 /* interface routine */
483 sisusbcon_switch(struct vc_data
*c
)
485 struct sisusb_usb_data
*sisusb
;
488 /* Returnvalue 0 means we have fully restored screen,
489 * and vt doesn't need to call do_update_region().
490 * Returnvalue != 0 naturally means the opposite.
493 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
497 /* sisusb->lock is down */
499 /* Don't write to screen if in gfx mode */
500 if (sisusb_is_inactive(c
, sisusb
)) {
501 mutex_unlock(&sisusb
->lock
);
505 /* That really should not happen. It would mean we are
506 * being called while the vc is using its private buffer
509 if (c
->vc_origin
== (unsigned long)c
->vc_screenbuf
) {
510 mutex_unlock(&sisusb
->lock
);
511 dev_dbg(&sisusb
->sisusb_dev
->dev
, "ASSERT ORIGIN != SCREENBUF!\n");
515 /* Check that we don't copy too much */
516 length
= min((int)c
->vc_screenbuf_size
,
517 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
519 /* Restore the screen contents */
520 sisusbcon_memcpyw((u16
*)c
->vc_origin
, (u16
*)c
->vc_screenbuf
,
523 sisusb_copy_memory(sisusb
, (unsigned char *)c
->vc_origin
,
524 (long)SISUSB_HADDR(0, 0),
527 mutex_unlock(&sisusb
->lock
);
532 /* interface routine */
534 sisusbcon_save_screen(struct vc_data
*c
)
536 struct sisusb_usb_data
*sisusb
;
539 /* Save the current screen contents to vc's private
543 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
547 /* sisusb->lock is down */
549 if (sisusb_is_inactive(c
, sisusb
)) {
550 mutex_unlock(&sisusb
->lock
);
554 /* Check that we don't copy too much */
555 length
= min((int)c
->vc_screenbuf_size
,
556 (int)(sisusb
->scrbuf
+ sisusb
->scrbuf_size
- c
->vc_origin
));
558 /* Save the screen contents to vc's private buffer */
559 sisusbcon_memcpyw((u16
*)c
->vc_screenbuf
, (u16
*)c
->vc_origin
,
562 mutex_unlock(&sisusb
->lock
);
565 /* interface routine */
567 sisusbcon_set_palette(struct vc_data
*c
, const unsigned char *table
)
569 struct sisusb_usb_data
*sisusb
;
572 /* Return value not used by vt */
574 if (!con_is_visible(c
))
577 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
581 /* sisusb->lock is down */
583 if (sisusb_is_inactive(c
, sisusb
)) {
584 mutex_unlock(&sisusb
->lock
);
588 for (i
= j
= 0; i
< 16; i
++) {
589 if (sisusb_setreg(sisusb
, SISCOLIDX
, table
[i
]))
591 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
593 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
595 if (sisusb_setreg(sisusb
, SISCOLDATA
, c
->vc_palette
[j
++] >> 2))
599 mutex_unlock(&sisusb
->lock
);
602 /* interface routine */
604 sisusbcon_blank(struct vc_data
*c
, int blank
, int mode_switch
)
606 struct sisusb_usb_data
*sisusb
;
607 u8 sr1
, cr17
, pmreg
, cr63
;
610 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
614 /* sisusb->lock is down */
617 sisusb
->is_gfx
= blank
? 1 : 0;
619 if (sisusb_is_inactive(c
, sisusb
)) {
620 mutex_unlock(&sisusb
->lock
);
626 case 1: /* Normal blanking: Clear screen */
628 sisusbcon_memsetw((u16
*)c
->vc_origin
,
629 c
->vc_video_erase_char
,
630 c
->vc_screenbuf_size
);
631 sisusb_copy_memory(sisusb
,
632 (unsigned char *)c
->vc_origin
,
633 (u32
)(sisusb
->vrambase
+
634 (c
->vc_origin
- sisusb
->scrbuf
)),
635 c
->vc_screenbuf_size
);
636 sisusb
->con_blanked
= 1;
640 default: /* VESA blanking */
642 case 0: /* Unblank */
648 sisusb
->con_blanked
= 0;
650 case VESA_VSYNC_SUSPEND
+ 1:
656 case VESA_HSYNC_SUSPEND
+ 1:
662 case VESA_POWERDOWN
+ 1:
669 mutex_unlock(&sisusb
->lock
);
673 sisusb_setidxregandor(sisusb
, SISSR
, 0x01, ~0x20, sr1
);
674 sisusb_setidxregandor(sisusb
, SISCR
, 0x17, 0x7f, cr17
);
675 sisusb_setidxregandor(sisusb
, SISSR
, 0x1f, 0x3f, pmreg
);
676 sisusb_setidxregandor(sisusb
, SISCR
, 0x63, 0xbf, cr63
);
680 mutex_unlock(&sisusb
->lock
);
685 /* interface routine */
687 sisusbcon_scrolldelta(struct vc_data
*c
, int lines
)
689 struct sisusb_usb_data
*sisusb
;
691 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
695 /* sisusb->lock is down */
697 if (sisusb_is_inactive(c
, sisusb
)) {
698 mutex_unlock(&sisusb
->lock
);
702 vc_scrolldelta_helper(c
, lines
, sisusb
->con_rolled_over
,
703 (void *)sisusb
->scrbuf
, sisusb
->scrbuf_size
);
705 sisusbcon_set_start_address(sisusb
, c
);
707 mutex_unlock(&sisusb
->lock
);
710 /* Interface routine */
712 sisusbcon_cursor(struct vc_data
*c
, int mode
)
714 struct sisusb_usb_data
*sisusb
;
715 int from
, to
, baseline
;
717 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
721 /* sisusb->lock is down */
723 if (sisusb_is_inactive(c
, sisusb
)) {
724 mutex_unlock(&sisusb
->lock
);
728 if (c
->vc_origin
!= c
->vc_visible_origin
) {
729 c
->vc_visible_origin
= c
->vc_origin
;
730 sisusbcon_set_start_address(sisusb
, c
);
733 if (mode
== CM_ERASE
) {
734 sisusb_setidxregor(sisusb
, SISCR
, 0x0a, 0x20);
735 sisusb
->sisusb_cursor_size_to
= -1;
736 mutex_unlock(&sisusb
->lock
);
740 sisusb_set_cursor(sisusb
, (c
->vc_pos
- sisusb
->scrbuf
) / 2);
742 baseline
= c
->vc_font
.height
- (c
->vc_font
.height
< 10 ? 1 : 2);
744 switch (c
->vc_cursor_type
& 0x0f) {
745 case CUR_BLOCK
: from
= 1;
746 to
= c
->vc_font
.height
;
748 case CUR_TWO_THIRDS
: from
= c
->vc_font
.height
/ 3;
751 case CUR_LOWER_HALF
: from
= c
->vc_font
.height
/ 2;
754 case CUR_LOWER_THIRD
: from
= (c
->vc_font
.height
* 2) / 3;
757 case CUR_NONE
: from
= 31;
761 case CUR_UNDERLINE
: from
= baseline
- 1;
766 if (sisusb
->sisusb_cursor_size_from
!= from
||
767 sisusb
->sisusb_cursor_size_to
!= to
) {
769 sisusb_setidxreg(sisusb
, SISCR
, 0x0a, from
);
770 sisusb_setidxregandor(sisusb
, SISCR
, 0x0b, 0xe0, to
);
772 sisusb
->sisusb_cursor_size_from
= from
;
773 sisusb
->sisusb_cursor_size_to
= to
;
776 mutex_unlock(&sisusb
->lock
);
780 sisusbcon_scroll_area(struct vc_data
*c
, struct sisusb_usb_data
*sisusb
,
781 unsigned int t
, unsigned int b
, enum con_scroll dir
,
784 int cols
= sisusb
->sisusb_num_columns
;
785 int length
= ((b
- t
) * cols
) * 2;
786 u16 eattr
= c
->vc_video_erase_char
;
788 /* sisusb->lock is down */
790 /* Scroll an area which does not match the
791 * visible screen's dimensions. This needs
792 * to be done separately, as it does not
793 * use hardware panning.
799 sisusbcon_memmovew(SISUSB_VADDR(0, t
),
800 SISUSB_VADDR(0, t
+ lines
),
801 (b
- t
- lines
) * cols
* 2);
802 sisusbcon_memsetw(SISUSB_VADDR(0, b
- lines
), eattr
,
807 sisusbcon_memmovew(SISUSB_VADDR(0, t
+ lines
),
809 (b
- t
- lines
) * cols
* 2);
810 sisusbcon_memsetw(SISUSB_VADDR(0, t
), eattr
,
815 sisusb_copy_memory(sisusb
, (char *)SISUSB_VADDR(0, t
),
816 (long)SISUSB_HADDR(0, t
), length
);
818 mutex_unlock(&sisusb
->lock
);
823 /* Interface routine */
825 sisusbcon_scroll(struct vc_data
*c
, unsigned int t
, unsigned int b
,
826 enum con_scroll dir
, unsigned int lines
)
828 struct sisusb_usb_data
*sisusb
;
829 u16 eattr
= c
->vc_video_erase_char
;
831 unsigned long oldorigin
;
832 unsigned int delta
= lines
* c
->vc_size_row
;
835 /* Returning != 0 means we have done the scrolling successfully.
836 * Returning 0 makes vt do the scrolling on its own.
837 * Note that con_scroll is only called if the console is
838 * visible. In that case, the origin should be our buffer,
839 * not the vt's private one.
845 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
849 /* sisusb->lock is down */
851 if (sisusb_is_inactive(c
, sisusb
)) {
852 mutex_unlock(&sisusb
->lock
);
857 if (t
|| b
!= c
->vc_rows
)
858 return sisusbcon_scroll_area(c
, sisusb
, t
, b
, dir
, lines
);
860 if (c
->vc_origin
!= c
->vc_visible_origin
) {
861 c
->vc_visible_origin
= c
->vc_origin
;
862 sisusbcon_set_start_address(sisusb
, c
);
865 /* limit amount to maximum realistic size */
866 if (lines
> c
->vc_rows
)
869 oldorigin
= c
->vc_origin
;
875 if (c
->vc_scr_end
+ delta
>=
876 sisusb
->scrbuf
+ sisusb
->scrbuf_size
) {
877 sisusbcon_memcpyw((u16
*)sisusb
->scrbuf
,
878 (u16
*)(oldorigin
+ delta
),
879 c
->vc_screenbuf_size
- delta
);
880 c
->vc_origin
= sisusb
->scrbuf
;
881 sisusb
->con_rolled_over
= oldorigin
- sisusb
->scrbuf
;
884 c
->vc_origin
+= delta
;
887 (u16
*)(c
->vc_origin
+ c
->vc_screenbuf_size
- delta
),
894 if (oldorigin
- delta
< sisusb
->scrbuf
) {
895 sisusbcon_memmovew((u16
*)(sisusb
->scrbuf
+
896 sisusb
->scrbuf_size
-
897 c
->vc_screenbuf_size
+
900 c
->vc_screenbuf_size
- delta
);
901 c
->vc_origin
= sisusb
->scrbuf
+
902 sisusb
->scrbuf_size
-
903 c
->vc_screenbuf_size
;
904 sisusb
->con_rolled_over
= 0;
907 c
->vc_origin
-= delta
;
909 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
911 scr_memsetw((u16
*)(c
->vc_origin
), eattr
, delta
);
916 originoffset
= (u32
)(c
->vc_origin
- sisusb
->scrbuf
);
919 sisusb_copy_memory(sisusb
,
920 (char *)c
->vc_origin
,
921 (u32
)(sisusb
->vrambase
+ originoffset
),
922 c
->vc_screenbuf_size
);
923 else if (dir
== SM_UP
)
924 sisusb_copy_memory(sisusb
,
925 (char *)c
->vc_origin
+ c
->vc_screenbuf_size
- delta
,
926 (u32
)sisusb
->vrambase
+ originoffset
+
927 c
->vc_screenbuf_size
- delta
,
930 sisusb_copy_memory(sisusb
,
931 (char *)c
->vc_origin
,
932 (u32
)(sisusb
->vrambase
+ originoffset
),
935 c
->vc_scr_end
= c
->vc_origin
+ c
->vc_screenbuf_size
;
936 c
->vc_visible_origin
= c
->vc_origin
;
938 sisusbcon_set_start_address(sisusb
, c
);
940 c
->vc_pos
= c
->vc_pos
- oldorigin
+ c
->vc_origin
;
942 mutex_unlock(&sisusb
->lock
);
947 /* Interface routine */
949 sisusbcon_set_origin(struct vc_data
*c
)
951 struct sisusb_usb_data
*sisusb
;
953 /* Returning != 0 means we were successful.
954 * Returning 0 will vt make to use its own
955 * screenbuffer as the origin.
958 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
962 /* sisusb->lock is down */
964 if (sisusb_is_inactive(c
, sisusb
) || sisusb
->con_blanked
) {
965 mutex_unlock(&sisusb
->lock
);
969 c
->vc_origin
= c
->vc_visible_origin
= sisusb
->scrbuf
;
971 sisusbcon_set_start_address(sisusb
, c
);
973 sisusb
->con_rolled_over
= 0;
975 mutex_unlock(&sisusb
->lock
);
980 /* Interface routine */
982 sisusbcon_resize(struct vc_data
*c
, unsigned int newcols
, unsigned int newrows
,
985 struct sisusb_usb_data
*sisusb
;
988 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
992 fh
= sisusb
->current_font_height
;
994 mutex_unlock(&sisusb
->lock
);
996 /* We are quite unflexible as regards resizing. The vt code
997 * handles sizes where the line length isn't equal the pitch
998 * quite badly. As regards the rows, our panning tricks only
999 * work well if the number of rows equals the visible number
1003 if (newcols
!= 80 || c
->vc_scan_lines
/ fh
!= newrows
)
1010 sisusbcon_do_font_op(struct sisusb_usb_data
*sisusb
, int set
, int slot
,
1011 u8
*arg
, int cmapsz
, int ch512
, int dorecalc
,
1012 struct vc_data
*c
, int fh
, int uplock
)
1014 int font_select
= 0x00, i
, err
= 0;
1018 /* sisusb->lock is down */
1021 * The default font is kept in slot 0.
1022 * A user font is loaded in slot 2 (256 ch)
1026 if ((slot
!= 0 && slot
!= 2) || !fh
) {
1028 mutex_unlock(&sisusb
->lock
);
1033 sisusb
->font_slot
= slot
;
1035 /* Default font is always 256 */
1039 offset
= 4 * cmapsz
;
1041 font_select
= (slot
== 0) ? 0x00 : (ch512
? 0x0e : 0x0a);
1043 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1044 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x04); /* Write to plane 2 */
1045 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x07); /* Memory mode a0-bf */
1046 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset */
1051 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x03); /* Select plane read 2 */
1052 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x00); /* Disable odd/even */
1053 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x00); /* Address range a0-bf */
1060 for (i
= 0; i
< cmapsz
; i
++) {
1061 err
|= sisusb_writeb(sisusb
,
1062 sisusb
->vrambase
+ offset
+ i
,
1068 for (i
= 0; i
< cmapsz
; i
++) {
1069 err
|= sisusb_readb(sisusb
,
1070 sisusb
->vrambase
+ offset
+ i
,
1077 * In 512-character mode, the character map is not contiguous if
1078 * we want to remain EGA compatible -- which we do
1083 for (i
= 0; i
< cmapsz
; i
++) {
1084 err
|= sisusb_writeb(sisusb
,
1085 sisusb
->vrambase
+ offset
+
1092 for (i
= 0; i
< cmapsz
; i
++) {
1093 err
|= sisusb_readb(sisusb
,
1094 sisusb
->vrambase
+ offset
+
1106 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x01); /* Reset */
1107 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x02, 0x03); /* Write to planes 0+1 */
1108 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x04, 0x03); /* Memory mode a0-bf */
1110 sisusb_setidxreg(sisusb
, SISSR
, 0x03, font_select
);
1111 err
|= sisusb_setidxreg(sisusb
, SISSR
, 0x00, 0x03); /* Reset end */
1116 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x04, 0x00); /* Select plane read 0 */
1117 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x05, 0x10); /* Enable odd/even */
1118 err
|= sisusb_setidxreg(sisusb
, SISGR
, 0x06, 0x06); /* Address range b8-bf */
1123 if ((set
) && (ch512
!= sisusb
->current_font_512
)) {
1125 /* Font is shared among all our consoles.
1126 * And so is the hi_font_mask.
1128 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1129 struct vc_data
*d
= vc_cons
[i
].d
;
1130 if (d
&& d
->vc_sw
== &sisusb_con
)
1131 d
->vc_hi_font_mask
= ch512
? 0x0800 : 0;
1134 sisusb
->current_font_512
= ch512
;
1136 /* color plane enable register:
1137 256-char: enable intensity bit
1138 512-char: disable intensity bit */
1139 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1140 sisusb_setreg(sisusb
, SISAR
, 0x12);
1141 sisusb_setreg(sisusb
, SISAR
, ch512
? 0x07 : 0x0f);
1143 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1144 sisusb_setreg(sisusb
, SISAR
, 0x20);
1145 sisusb_getreg(sisusb
, SISINPSTAT
, &dummy
);
1151 * Adjust the screen to fit a font of a certain height
1154 unsigned char ovr
, vde
, fsr
;
1155 int rows
= 0, maxscan
= 0;
1159 /* Number of video rows */
1160 rows
= c
->vc_scan_lines
/ fh
;
1161 /* Scan lines to actually display-1 */
1162 maxscan
= rows
* fh
- 1;
1164 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1165 rows, maxscan, fh, c->vc_scan_lines);*/
1167 sisusb_getidxreg(sisusb
, SISCR
, 0x07, &ovr
);
1168 vde
= maxscan
& 0xff;
1169 ovr
= (ovr
& 0xbd) |
1170 ((maxscan
& 0x100) >> 7) |
1171 ((maxscan
& 0x200) >> 3);
1172 sisusb_setidxreg(sisusb
, SISCR
, 0x07, ovr
);
1173 sisusb_setidxreg(sisusb
, SISCR
, 0x12, vde
);
1177 sisusb_getidxreg(sisusb
, SISCR
, 0x09, &fsr
);
1178 fsr
= (fsr
& 0xe0) | (fh
- 1);
1179 sisusb_setidxreg(sisusb
, SISCR
, 0x09, fsr
);
1180 sisusb
->current_font_height
= fh
;
1182 sisusb
->sisusb_cursor_size_from
= -1;
1183 sisusb
->sisusb_cursor_size_to
= -1;
1188 mutex_unlock(&sisusb
->lock
);
1190 if (dorecalc
&& c
) {
1191 int rows
= c
->vc_scan_lines
/ fh
;
1193 /* Now adjust our consoles' size */
1195 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
1196 struct vc_data
*vc
= vc_cons
[i
].d
;
1198 if (vc
&& vc
->vc_sw
== &sisusb_con
) {
1199 if (con_is_visible(vc
)) {
1200 vc
->vc_sw
->con_cursor(vc
, CM_DRAW
);
1202 vc
->vc_font
.height
= fh
;
1203 vc_resize(vc
, 0, rows
);
1212 mutex_unlock(&sisusb
->lock
);
1217 /* Interface routine */
1219 sisusbcon_font_set(struct vc_data
*c
, struct console_font
*font
,
1222 struct sisusb_usb_data
*sisusb
;
1223 unsigned charcount
= font
->charcount
;
1225 if (font
->width
!= 8 || (charcount
!= 256 && charcount
!= 512))
1228 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1232 /* sisusb->lock is down */
1234 /* Save the user-provided font into a buffer. This
1235 * is used for restoring text mode after quitting
1236 * from X and for the con_getfont routine.
1238 if (sisusb
->font_backup
) {
1239 if (sisusb
->font_backup_size
< charcount
) {
1240 vfree(sisusb
->font_backup
);
1241 sisusb
->font_backup
= NULL
;
1245 if (!sisusb
->font_backup
)
1246 sisusb
->font_backup
= vmalloc(charcount
* 32);
1248 if (sisusb
->font_backup
) {
1249 memcpy(sisusb
->font_backup
, font
->data
, charcount
* 32);
1250 sisusb
->font_backup_size
= charcount
;
1251 sisusb
->font_backup_height
= font
->height
;
1252 sisusb
->font_backup_512
= (charcount
== 512) ? 1 : 0;
1255 /* do_font_op ups sisusb->lock */
1257 return sisusbcon_do_font_op(sisusb
, 1, 2, font
->data
,
1258 8192, (charcount
== 512),
1259 (!(flags
& KD_FONT_FLAG_DONT_RECALC
)) ? 1 : 0,
1260 c
, font
->height
, 1);
1263 /* Interface routine */
1265 sisusbcon_font_get(struct vc_data
*c
, struct console_font
*font
)
1267 struct sisusb_usb_data
*sisusb
;
1269 sisusb
= sisusb_get_sisusb_lock_and_check(c
->vc_num
);
1273 /* sisusb->lock is down */
1276 font
->height
= c
->vc_font
.height
;
1277 font
->charcount
= 256;
1280 mutex_unlock(&sisusb
->lock
);
1284 if (!sisusb
->font_backup
) {
1285 mutex_unlock(&sisusb
->lock
);
1289 /* Copy 256 chars only, like vgacon */
1290 memcpy(font
->data
, sisusb
->font_backup
, 256 * 32);
1292 mutex_unlock(&sisusb
->lock
);
1298 * The console `switch' structure for the sisusb console
1301 static const struct consw sisusb_con
= {
1302 .owner
= THIS_MODULE
,
1303 .con_startup
= sisusbcon_startup
,
1304 .con_init
= sisusbcon_init
,
1305 .con_deinit
= sisusbcon_deinit
,
1306 .con_clear
= sisusbcon_clear
,
1307 .con_putc
= sisusbcon_putc
,
1308 .con_putcs
= sisusbcon_putcs
,
1309 .con_cursor
= sisusbcon_cursor
,
1310 .con_scroll
= sisusbcon_scroll
,
1311 .con_switch
= sisusbcon_switch
,
1312 .con_blank
= sisusbcon_blank
,
1313 .con_font_set
= sisusbcon_font_set
,
1314 .con_font_get
= sisusbcon_font_get
,
1315 .con_set_palette
= sisusbcon_set_palette
,
1316 .con_scrolldelta
= sisusbcon_scrolldelta
,
1317 .con_build_attr
= sisusbcon_build_attr
,
1318 .con_invert_region
= sisusbcon_invert_region
,
1319 .con_set_origin
= sisusbcon_set_origin
,
1320 .con_save_screen
= sisusbcon_save_screen
,
1321 .con_resize
= sisusbcon_resize
,
1324 /* Our very own dummy console driver */
1326 static const char *sisusbdummycon_startup(void)
1328 return "SISUSBVGADUMMY";
1331 static void sisusbdummycon_init(struct vc_data
*vc
, int init
)
1333 vc
->vc_can_do_color
= 1;
1338 vc_resize(vc
, 80, 25);
1341 static int sisusbdummycon_dummy(void)
1346 #define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
1348 static const struct consw sisusb_dummy_con
= {
1349 .owner
= THIS_MODULE
,
1350 .con_startup
= sisusbdummycon_startup
,
1351 .con_init
= sisusbdummycon_init
,
1352 .con_deinit
= SISUSBCONDUMMY
,
1353 .con_clear
= SISUSBCONDUMMY
,
1354 .con_putc
= SISUSBCONDUMMY
,
1355 .con_putcs
= SISUSBCONDUMMY
,
1356 .con_cursor
= SISUSBCONDUMMY
,
1357 .con_scroll
= SISUSBCONDUMMY
,
1358 .con_switch
= SISUSBCONDUMMY
,
1359 .con_blank
= SISUSBCONDUMMY
,
1360 .con_font_set
= SISUSBCONDUMMY
,
1361 .con_font_get
= SISUSBCONDUMMY
,
1362 .con_font_default
= SISUSBCONDUMMY
,
1363 .con_font_copy
= SISUSBCONDUMMY
,
1367 sisusb_console_init(struct sisusb_usb_data
*sisusb
, int first
, int last
)
1371 mutex_lock(&sisusb
->lock
);
1373 /* Erm.. that should not happen */
1374 if (sisusb
->haveconsole
|| !sisusb
->SiS_Pr
) {
1375 mutex_unlock(&sisusb
->lock
);
1379 sisusb
->con_first
= first
;
1380 sisusb
->con_last
= last
;
1383 first
> MAX_NR_CONSOLES
||
1384 last
> MAX_NR_CONSOLES
) {
1385 mutex_unlock(&sisusb
->lock
);
1389 /* If gfxcore not initialized or no consoles given, quit graciously */
1390 if (!sisusb
->gfxinit
|| first
< 1 || last
< 1) {
1391 mutex_unlock(&sisusb
->lock
);
1395 sisusb
->sisusb_cursor_loc
= -1;
1396 sisusb
->sisusb_cursor_size_from
= -1;
1397 sisusb
->sisusb_cursor_size_to
= -1;
1399 /* Set up text mode (and upload default font) */
1400 if (sisusb_reset_text_mode(sisusb
, 1)) {
1401 mutex_unlock(&sisusb
->lock
);
1402 dev_err(&sisusb
->sisusb_dev
->dev
, "Failed to set up text mode\n");
1406 /* Initialize some gfx registers */
1407 sisusb_initialize(sisusb
);
1409 for (i
= first
- 1; i
<= last
- 1; i
++) {
1410 /* Save sisusb for our interface routines */
1411 mysisusbs
[i
] = sisusb
;
1414 /* Initial console setup */
1415 sisusb
->sisusb_num_columns
= 80;
1417 /* Use a 32K buffer (matches b8000-bffff area) */
1418 sisusb
->scrbuf_size
= 32 * 1024;
1420 /* Allocate screen buffer */
1421 if (!(sisusb
->scrbuf
= (unsigned long)vmalloc(sisusb
->scrbuf_size
))) {
1422 mutex_unlock(&sisusb
->lock
);
1423 dev_err(&sisusb
->sisusb_dev
->dev
, "Failed to allocate screen buffer\n");
1427 mutex_unlock(&sisusb
->lock
);
1429 /* Now grab the desired console(s) */
1431 ret
= do_take_over_console(&sisusb_con
, first
- 1, last
- 1, 0);
1434 sisusb
->haveconsole
= 1;
1436 for (i
= first
- 1; i
<= last
- 1; i
++)
1437 mysisusbs
[i
] = NULL
;
1444 sisusb_console_exit(struct sisusb_usb_data
*sisusb
)
1448 /* This is called if the device is disconnected
1449 * and while disconnect and lock semaphores
1450 * are up. This should be save because we
1451 * can't lose our sisusb any other way but by
1452 * disconnection (and hence, the disconnect
1453 * sema is for protecting all other access
1454 * functions from disconnection, not the
1458 /* Now what do we do in case of disconnection:
1459 * One alternative would be to simply call
1460 * give_up_console(). Nah, not a good idea.
1461 * give_up_console() is obviously buggy as it
1462 * only discards the consw pointer from the
1463 * driver_map, but doesn't adapt vc->vc_sw
1464 * of the affected consoles. Hence, the next
1465 * call to any of the console functions will
1466 * eventually take a trip to oops county.
1467 * Also, give_up_console for some reason
1468 * doesn't decrement our module refcount.
1469 * Instead, we switch our consoles to a private
1470 * dummy console. This, of course, keeps our
1471 * refcount up as well, but it works perfectly.
1474 if (sisusb
->haveconsole
) {
1475 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1476 if (sisusb
->havethisconsole
[i
]) {
1478 do_take_over_console(&sisusb_dummy_con
, i
, i
, 0);
1480 /* At this point, con_deinit for all our
1481 * consoles is executed by do_take_over_console().
1484 sisusb
->haveconsole
= 0;
1487 vfree((void *)sisusb
->scrbuf
);
1490 vfree(sisusb
->font_backup
);
1491 sisusb
->font_backup
= NULL
;
1494 void __init
sisusb_init_concode(void)
1498 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
1499 mysisusbs
[i
] = NULL
;
1502 #endif /* INCL_CON */