xref: /openbmc/linux/drivers/video/console/sticon.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  linux/drivers/video/console/sticon.c - console driver using HP's STI firmware
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *	Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
57ff3f14dSHelge Deller  *	Copyright (C) 2002-2020 Helge Deller <deller@gmx.de>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *  Based on linux/drivers/video/vgacon.c and linux/drivers/video/fbcon.c,
81da177e4SLinus Torvalds  *  which were
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  *	Created 28 Sep 1997 by Geert Uytterhoeven
111da177e4SLinus Torvalds  *	Rewritten by Martin Mares <mj@ucw.cz>, July 1998
121da177e4SLinus Torvalds  *	Copyright (C) 1991, 1992  Linus Torvalds
131da177e4SLinus Torvalds  *			    1995  Jay Estabrook
141da177e4SLinus Torvalds  *	Copyright (C) 1995 Geert Uytterhoeven
151da177e4SLinus Torvalds  *	Copyright (C) 1993 Bjoern Brauel
161da177e4SLinus Torvalds  *			   Roman Hodek
171da177e4SLinus Torvalds  *	Copyright (C) 1993 Hamish Macdonald
181da177e4SLinus Torvalds  *			   Greg Harp
191da177e4SLinus Torvalds  *	Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  *	      with work by William Rucklidge (wjr@cs.cornell.edu)
221da177e4SLinus Torvalds  *			   Geert Uytterhoeven
231da177e4SLinus Torvalds  *			   Jes Sorensen (jds@kom.auc.dk)
241da177e4SLinus Torvalds  *			   Martin Apel
251da177e4SLinus Torvalds  *	      with work by Guenther Kelleter
261da177e4SLinus Torvalds  *			   Martin Schaller
271da177e4SLinus Torvalds  *			   Andreas Schwab
281da177e4SLinus Torvalds  *			   Emmanuel Marty (core@ggi-project.org)
291da177e4SLinus Torvalds  *			   Jakub Jelinek (jj@ultra.linux.cz)
301da177e4SLinus Torvalds  *			   Martin Mares <mj@ucw.cz>
311da177e4SLinus Torvalds  *
321da177e4SLinus Torvalds  *  This file is subject to the terms and conditions of the GNU General Public
331da177e4SLinus Torvalds  *  License.  See the file COPYING in the main directory of this archive for
341da177e4SLinus Torvalds  *  more details.
351da177e4SLinus Torvalds  *
361da177e4SLinus Torvalds  */
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #include <linux/init.h>
391da177e4SLinus Torvalds #include <linux/kernel.h>
401da177e4SLinus Torvalds #include <linux/console.h>
411da177e4SLinus Torvalds #include <linux/errno.h>
421da177e4SLinus Torvalds #include <linux/vt_kern.h>
431da177e4SLinus Torvalds #include <linux/kd.h>
441da177e4SLinus Torvalds #include <linux/selection.h>
451da177e4SLinus Torvalds #include <linux/module.h>
467ff3f14dSHelge Deller #include <linux/slab.h>
477ff3f14dSHelge Deller #include <linux/font.h>
487ff3f14dSHelge Deller #include <linux/crc32.h>
49b046f984SHelge Deller #include <linux/fb.h>
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #include <asm/io.h>
521da177e4SLinus Torvalds 
5374708497SThomas Zimmermann #include <video/sticore.h>
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /* switching to graphics mode */
561da177e4SLinus Torvalds #define BLANK 0
571da177e4SLinus Torvalds static int vga_is_gfx;
581da177e4SLinus Torvalds 
597ff3f14dSHelge Deller #define STI_DEF_FONT	sticon_sti->font
607ff3f14dSHelge Deller 
617ff3f14dSHelge Deller /* borrowed from fbcon.c */
627ff3f14dSHelge Deller #define FNTREFCOUNT(fd)	(fd->refcount)
637ff3f14dSHelge Deller #define FNTCRC(fd)	(fd->crc)
647ff3f14dSHelge Deller static struct sti_cooked_font *font_data[MAX_NR_CONSOLES];
657ff3f14dSHelge Deller 
661da177e4SLinus Torvalds /* this is the sti_struct used for this console */
671da177e4SLinus Torvalds static struct sti_struct *sticon_sti;
681da177e4SLinus Torvalds 
sticon_startup(void)69b877a964SAntonino A. Daplas static const char *sticon_startup(void)
701da177e4SLinus Torvalds {
711da177e4SLinus Torvalds     return "STI console";
721da177e4SLinus Torvalds }
731da177e4SLinus Torvalds 
sticon_putc(struct vc_data * conp,int c,int ypos,int xpos)741da177e4SLinus Torvalds static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos)
751da177e4SLinus Torvalds {
761da177e4SLinus Torvalds     if (vga_is_gfx || console_blanked)
771da177e4SLinus Torvalds 	    return;
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds     if (conp->vc_mode != KD_TEXT)
801da177e4SLinus Torvalds     	    return;
811da177e4SLinus Torvalds 
827ff3f14dSHelge Deller     sti_putc(sticon_sti, c, ypos, xpos, font_data[conp->vc_num]);
831da177e4SLinus Torvalds }
841da177e4SLinus Torvalds 
sticon_putcs(struct vc_data * conp,const unsigned short * s,int count,int ypos,int xpos)851da177e4SLinus Torvalds static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
861da177e4SLinus Torvalds 			 int count, int ypos, int xpos)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds     if (vga_is_gfx || console_blanked)
891da177e4SLinus Torvalds 	    return;
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds     if (conp->vc_mode != KD_TEXT)
921da177e4SLinus Torvalds     	    return;
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds     while (count--) {
957ff3f14dSHelge Deller 	sti_putc(sticon_sti, scr_readw(s++), ypos, xpos++,
967ff3f14dSHelge Deller 		 font_data[conp->vc_num]);
971da177e4SLinus Torvalds     }
981da177e4SLinus Torvalds }
991da177e4SLinus Torvalds 
sticon_cursor(struct vc_data * conp,int mode)1001da177e4SLinus Torvalds static void sticon_cursor(struct vc_data *conp, int mode)
1011da177e4SLinus Torvalds {
1021da177e4SLinus Torvalds     unsigned short car1;
1031da177e4SLinus Torvalds 
1047ff3f14dSHelge Deller     /* no cursor update if screen is blanked */
1057ff3f14dSHelge Deller     if (vga_is_gfx || console_blanked)
1067ff3f14dSHelge Deller 	return;
1077ff3f14dSHelge Deller 
10828bc24fcSJiri Slaby     car1 = conp->vc_screenbuf[conp->state.x + conp->state.y * conp->vc_cols];
1091da177e4SLinus Torvalds     switch (mode) {
1101da177e4SLinus Torvalds     case CM_ERASE:
1117ff3f14dSHelge Deller 	sti_putc(sticon_sti, car1, conp->state.y, conp->state.x,
1127ff3f14dSHelge Deller 		 font_data[conp->vc_num]);
1131da177e4SLinus Torvalds 	break;
1141da177e4SLinus Torvalds     case CM_MOVE:
1151da177e4SLinus Torvalds     case CM_DRAW:
116c0e4b3adSJiri Slaby 	switch (CUR_SIZE(conp->vc_cursor_type)) {
1171da177e4SLinus Torvalds 	case CUR_UNDERLINE:
1181da177e4SLinus Torvalds 	case CUR_LOWER_THIRD:
1191da177e4SLinus Torvalds 	case CUR_LOWER_HALF:
1201da177e4SLinus Torvalds 	case CUR_TWO_THIRDS:
1211da177e4SLinus Torvalds 	case CUR_BLOCK:
1221da177e4SLinus Torvalds 	    sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
1237ff3f14dSHelge Deller 		     conp->state.y, conp->state.x, font_data[conp->vc_num]);
1241da177e4SLinus Torvalds 	    break;
1251da177e4SLinus Torvalds 	}
1261da177e4SLinus Torvalds 	break;
1271da177e4SLinus Torvalds     }
1281da177e4SLinus Torvalds }
1291da177e4SLinus Torvalds 
sticon_scroll(struct vc_data * conp,unsigned int t,unsigned int b,enum con_scroll dir,unsigned int count)130d705ff38SJiri Slaby static bool sticon_scroll(struct vc_data *conp, unsigned int t,
131d705ff38SJiri Slaby 		unsigned int b, enum con_scroll dir, unsigned int count)
1321da177e4SLinus Torvalds {
1331da177e4SLinus Torvalds     struct sti_struct *sti = sticon_sti;
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds     if (vga_is_gfx)
136d705ff38SJiri Slaby         return false;
1371da177e4SLinus Torvalds 
1381da177e4SLinus Torvalds     sticon_cursor(conp, CM_ERASE);
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds     switch (dir) {
1411da177e4SLinus Torvalds     case SM_UP:
1427ff3f14dSHelge Deller 	sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols,
1437ff3f14dSHelge Deller 		  font_data[conp->vc_num]);
1447ff3f14dSHelge Deller 	sti_clear(sti, b - count, 0, count, conp->vc_cols,
1457ff3f14dSHelge Deller 		  conp->vc_video_erase_char, font_data[conp->vc_num]);
1461da177e4SLinus Torvalds 	break;
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds     case SM_DOWN:
1497ff3f14dSHelge Deller 	sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols,
1507ff3f14dSHelge Deller 		  font_data[conp->vc_num]);
1517ff3f14dSHelge Deller 	sti_clear(sti, t, 0, count, conp->vc_cols,
1527ff3f14dSHelge Deller 		  conp->vc_video_erase_char, font_data[conp->vc_num]);
1531da177e4SLinus Torvalds 	break;
1541da177e4SLinus Torvalds     }
1551da177e4SLinus Torvalds 
156d705ff38SJiri Slaby     return false;
1571da177e4SLinus Torvalds }
1581da177e4SLinus Torvalds 
sticon_set_def_font(int unit)159*4f2ba39aSJiri Slaby (SUSE) static void sticon_set_def_font(int unit)
1607ff3f14dSHelge Deller {
1617ff3f14dSHelge Deller 	if (font_data[unit] != STI_DEF_FONT) {
1627ff3f14dSHelge Deller 		if (--FNTREFCOUNT(font_data[unit]) == 0) {
1637ff3f14dSHelge Deller 			kfree(font_data[unit]->raw_ptr);
1647ff3f14dSHelge Deller 			kfree(font_data[unit]);
1657ff3f14dSHelge Deller 		}
1667ff3f14dSHelge Deller 		font_data[unit] = STI_DEF_FONT;
1677ff3f14dSHelge Deller 	}
1687ff3f14dSHelge Deller }
1697ff3f14dSHelge Deller 
sticon_set_font(struct vc_data * vc,struct console_font * op,unsigned int vpitch)170ffc1e089SSamuel Thibault static int sticon_set_font(struct vc_data *vc, struct console_font *op,
171ffc1e089SSamuel Thibault 			   unsigned int vpitch)
1727ff3f14dSHelge Deller {
1737ff3f14dSHelge Deller 	struct sti_struct *sti = sticon_sti;
1747ff3f14dSHelge Deller 	int vc_cols, vc_rows, vc_old_cols, vc_old_rows;
1757ff3f14dSHelge Deller 	int unit = vc->vc_num;
1767ff3f14dSHelge Deller 	int w = op->width;
1777ff3f14dSHelge Deller 	int h = op->height;
1787ff3f14dSHelge Deller 	int size, i, bpc, pitch;
1797ff3f14dSHelge Deller 	struct sti_rom_font *new_font;
1807ff3f14dSHelge Deller 	struct sti_cooked_font *cooked_font;
1817ff3f14dSHelge Deller 	unsigned char *data = op->data, *p;
1827ff3f14dSHelge Deller 
183ffc1e089SSamuel Thibault 	if ((w < 6) || (h < 6) || (w > 32) || (h > 32) || (vpitch != 32)
1847ff3f14dSHelge Deller 	    || (op->charcount != 256 && op->charcount != 512))
1857ff3f14dSHelge Deller 		return -EINVAL;
1867ff3f14dSHelge Deller 	pitch = ALIGN(w, 8) / 8;
1877ff3f14dSHelge Deller 	bpc = pitch * h;
1887ff3f14dSHelge Deller 	size = bpc * op->charcount;
1897ff3f14dSHelge Deller 
1907ff3f14dSHelge Deller 	new_font = kmalloc(sizeof(*new_font) + size, STI_LOWMEM);
1917ff3f14dSHelge Deller 	if (!new_font)
1927ff3f14dSHelge Deller 		return -ENOMEM;
1937ff3f14dSHelge Deller 
1947ff3f14dSHelge Deller 	new_font->first_char = 0;
1957ff3f14dSHelge Deller 	new_font->last_char = op->charcount - 1;
1967ff3f14dSHelge Deller 	new_font->width = w;
1977ff3f14dSHelge Deller 	new_font->height = h;
1987ff3f14dSHelge Deller 	new_font->font_type = STI_FONT_HPROMAN8;
1997ff3f14dSHelge Deller 	new_font->bytes_per_char = bpc;
2007ff3f14dSHelge Deller 	new_font->underline_height = 0;
2017ff3f14dSHelge Deller 	new_font->underline_pos = 0;
2027ff3f14dSHelge Deller 
2037ff3f14dSHelge Deller 	cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
2047ff3f14dSHelge Deller 	if (!cooked_font) {
2057ff3f14dSHelge Deller 		kfree(new_font);
2067ff3f14dSHelge Deller 		return -ENOMEM;
2077ff3f14dSHelge Deller 	}
2087ff3f14dSHelge Deller 	cooked_font->raw = new_font;
2097ff3f14dSHelge Deller 	cooked_font->raw_ptr = new_font;
2107ff3f14dSHelge Deller 	cooked_font->width = w;
2117ff3f14dSHelge Deller 	cooked_font->height = h;
2127ff3f14dSHelge Deller 	FNTREFCOUNT(cooked_font) = 0;	/* usage counter */
2137ff3f14dSHelge Deller 
2147ff3f14dSHelge Deller 	p = (unsigned char *) new_font;
2157ff3f14dSHelge Deller 	p += sizeof(*new_font);
2167ff3f14dSHelge Deller 	for (i = 0; i < op->charcount; i++) {
2177ff3f14dSHelge Deller 		memcpy(p, data, bpc);
2187ff3f14dSHelge Deller 		data += pitch*32;
2197ff3f14dSHelge Deller 		p += bpc;
2207ff3f14dSHelge Deller 	}
2217ff3f14dSHelge Deller 	FNTCRC(cooked_font) = crc32(0, new_font, size + sizeof(*new_font));
2227ff3f14dSHelge Deller 	sti_font_convert_bytemode(sti, cooked_font);
2237ff3f14dSHelge Deller 	new_font = cooked_font->raw_ptr;
2247ff3f14dSHelge Deller 
2257ff3f14dSHelge Deller 	/* check if font is already used by other console */
2267ff3f14dSHelge Deller 	for (i = 0; i < MAX_NR_CONSOLES; i++) {
2277ff3f14dSHelge Deller 		if (font_data[i] != STI_DEF_FONT
2287ff3f14dSHelge Deller 		    && (FNTCRC(font_data[i]) == FNTCRC(cooked_font))) {
2297ff3f14dSHelge Deller 			kfree(new_font);
2307ff3f14dSHelge Deller 			kfree(cooked_font);
2317ff3f14dSHelge Deller 			/* current font is the same as the new one */
2327ff3f14dSHelge Deller 			if (i == unit)
2337ff3f14dSHelge Deller 				return 0;
2347ff3f14dSHelge Deller 			cooked_font = font_data[i];
2357ff3f14dSHelge Deller 			new_font = cooked_font->raw_ptr;
2367ff3f14dSHelge Deller 			break;
2377ff3f14dSHelge Deller 		}
2387ff3f14dSHelge Deller 	}
2397ff3f14dSHelge Deller 
2407ff3f14dSHelge Deller 	/* clear screen with old font: we now may have less rows */
2417ff3f14dSHelge Deller 	vc_old_rows = vc->vc_rows;
2427ff3f14dSHelge Deller 	vc_old_cols = vc->vc_cols;
2437ff3f14dSHelge Deller 	sti_clear(sticon_sti, 0, 0, vc_old_rows, vc_old_cols,
2447ff3f14dSHelge Deller 		  vc->vc_video_erase_char, font_data[vc->vc_num]);
2457ff3f14dSHelge Deller 
2467ff3f14dSHelge Deller 	/* delete old font in case it is a user font */
247*4f2ba39aSJiri Slaby (SUSE) 	sticon_set_def_font(unit);
2487ff3f14dSHelge Deller 
2497ff3f14dSHelge Deller 	FNTREFCOUNT(cooked_font)++;
2507ff3f14dSHelge Deller 	font_data[unit] = cooked_font;
2517ff3f14dSHelge Deller 
2527ff3f14dSHelge Deller 	vc_cols = sti_onscreen_x(sti) / cooked_font->width;
2537ff3f14dSHelge Deller 	vc_rows = sti_onscreen_y(sti) / cooked_font->height;
2547ff3f14dSHelge Deller 	vc_resize(vc, vc_cols, vc_rows);
2557ff3f14dSHelge Deller 
2567ff3f14dSHelge Deller 	/* need to repaint screen if cols & rows are same as old font */
2577ff3f14dSHelge Deller 	if (vc_cols == vc_old_cols && vc_rows == vc_old_rows)
2587ff3f14dSHelge Deller 		update_screen(vc);
2597ff3f14dSHelge Deller 
2607ff3f14dSHelge Deller 	return 0;
2617ff3f14dSHelge Deller }
2627ff3f14dSHelge Deller 
sticon_font_default(struct vc_data * vc,struct console_font * op,char * name)2637ff3f14dSHelge Deller static int sticon_font_default(struct vc_data *vc, struct console_font *op, char *name)
2647ff3f14dSHelge Deller {
265*4f2ba39aSJiri Slaby (SUSE) 	sticon_set_def_font(vc->vc_num);
266*4f2ba39aSJiri Slaby (SUSE) 
267*4f2ba39aSJiri Slaby (SUSE) 	return 0;
2687ff3f14dSHelge Deller }
2697ff3f14dSHelge Deller 
sticon_font_set(struct vc_data * vc,struct console_font * font,unsigned int vpitch,unsigned int flags)2707ff3f14dSHelge Deller static int sticon_font_set(struct vc_data *vc, struct console_font *font,
271ffc1e089SSamuel Thibault 			   unsigned int vpitch, unsigned int flags)
2727ff3f14dSHelge Deller {
273ffc1e089SSamuel Thibault 	return sticon_set_font(vc, font, vpitch);
2747ff3f14dSHelge Deller }
2757ff3f14dSHelge Deller 
sticon_init(struct vc_data * c,int init)2761da177e4SLinus Torvalds static void sticon_init(struct vc_data *c, int init)
2771da177e4SLinus Torvalds {
2781da177e4SLinus Torvalds     struct sti_struct *sti = sticon_sti;
2791da177e4SLinus Torvalds     int vc_cols, vc_rows;
2801da177e4SLinus Torvalds 
2811da177e4SLinus Torvalds     sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0);
2827ff3f14dSHelge Deller     vc_cols = sti_onscreen_x(sti) / sti->font->width;
2837ff3f14dSHelge Deller     vc_rows = sti_onscreen_y(sti) / sti->font->height;
2841da177e4SLinus Torvalds     c->vc_can_do_color = 1;
2851da177e4SLinus Torvalds 
2861da177e4SLinus Torvalds     if (init) {
2871da177e4SLinus Torvalds 	c->vc_cols = vc_cols;
2881da177e4SLinus Torvalds 	c->vc_rows = vc_rows;
2891da177e4SLinus Torvalds     } else {
2901da177e4SLinus Torvalds 	vc_resize(c, vc_cols, vc_rows);
2911da177e4SLinus Torvalds     }
2921da177e4SLinus Torvalds }
2931da177e4SLinus Torvalds 
sticon_deinit(struct vc_data * c)2941da177e4SLinus Torvalds static void sticon_deinit(struct vc_data *c)
2951da177e4SLinus Torvalds {
2967ff3f14dSHelge Deller     int i;
2977ff3f14dSHelge Deller 
2987ff3f14dSHelge Deller     /* free memory used by user font */
2997ff3f14dSHelge Deller     for (i = 0; i < MAX_NR_CONSOLES; i++)
300*4f2ba39aSJiri Slaby (SUSE) 	sticon_set_def_font(i);
3011da177e4SLinus Torvalds }
3021da177e4SLinus Torvalds 
sticon_clear(struct vc_data * conp,int sy,int sx,int height,int width)3031da177e4SLinus Torvalds static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
3041da177e4SLinus Torvalds 			 int width)
3051da177e4SLinus Torvalds {
3061da177e4SLinus Torvalds     if (!height || !width)
3071da177e4SLinus Torvalds 	return;
3081da177e4SLinus Torvalds 
3097ff3f14dSHelge Deller     sti_clear(sticon_sti, sy, sx, height, width,
3107ff3f14dSHelge Deller 	      conp->vc_video_erase_char, font_data[conp->vc_num]);
3111da177e4SLinus Torvalds }
3121da177e4SLinus Torvalds 
sticon_switch(struct vc_data * conp)3131da177e4SLinus Torvalds static int sticon_switch(struct vc_data *conp)
3141da177e4SLinus Torvalds {
3151da177e4SLinus Torvalds     return 1;	/* needs refreshing */
3161da177e4SLinus Torvalds }
3171da177e4SLinus Torvalds 
sticon_blank(struct vc_data * c,int blank,int mode_switch)3181da177e4SLinus Torvalds static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
3191da177e4SLinus Torvalds {
3201da177e4SLinus Torvalds     if (blank == 0) {
3211da177e4SLinus Torvalds 	if (mode_switch)
3221da177e4SLinus Torvalds 	    vga_is_gfx = 0;
3231da177e4SLinus Torvalds 	return 1;
3241da177e4SLinus Torvalds     }
3257ff3f14dSHelge Deller     sti_clear(sticon_sti, 0, 0, c->vc_rows, c->vc_cols, BLANK,
3267ff3f14dSHelge Deller 	      font_data[c->vc_num]);
3271da177e4SLinus Torvalds     if (mode_switch)
3281da177e4SLinus Torvalds 	vga_is_gfx = 1;
3291da177e4SLinus Torvalds     return 1;
3301da177e4SLinus Torvalds }
3311da177e4SLinus Torvalds 
sticon_build_attr(struct vc_data * conp,u8 color,enum vc_intensity intens,bool blink,bool underline,bool reverse,bool italic)332b84ae3dcSJiri Slaby static u8 sticon_build_attr(struct vc_data *conp, u8 color,
333b84ae3dcSJiri Slaby 			    enum vc_intensity intens,
33477bc14f2SJiri Slaby 			    bool blink, bool underline, bool reverse,
33577bc14f2SJiri Slaby 			    bool italic)
3361da177e4SLinus Torvalds {
337bec05f33SSven Schnelle 	u8 fg = color & 7;
338bec05f33SSven Schnelle 	u8 bg = (color & 0x70) >> 4;
3391da177e4SLinus Torvalds 
340bec05f33SSven Schnelle 	if (reverse)
341bec05f33SSven Schnelle 		return (fg << 3) | bg;
342bec05f33SSven Schnelle 	else
343bec05f33SSven Schnelle 		return (bg << 3) | fg;
3441da177e4SLinus Torvalds }
3451da177e4SLinus Torvalds 
sticon_invert_region(struct vc_data * conp,u16 * p,int count)3461da177e4SLinus Torvalds static void sticon_invert_region(struct vc_data *conp, u16 *p, int count)
3471da177e4SLinus Torvalds {
3481da177e4SLinus Torvalds     int col = 1; /* vga_can_do_color; */
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds     while (count--) {
3511da177e4SLinus Torvalds 	u16 a = scr_readw(p);
3521da177e4SLinus Torvalds 
3531da177e4SLinus Torvalds 	if (col)
3541da177e4SLinus Torvalds 		a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
3551da177e4SLinus Torvalds 	else
3561da177e4SLinus Torvalds 		a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds 	scr_writew(a, p++);
3591da177e4SLinus Torvalds     }
3601da177e4SLinus Torvalds }
3611da177e4SLinus Torvalds 
362d95159cfSHelge Deller static const struct consw sti_con = {
3631da177e4SLinus Torvalds 	.owner			= THIS_MODULE,
3641da177e4SLinus Torvalds 	.con_startup		= sticon_startup,
3651da177e4SLinus Torvalds 	.con_init		= sticon_init,
3661da177e4SLinus Torvalds 	.con_deinit		= sticon_deinit,
3671da177e4SLinus Torvalds 	.con_clear		= sticon_clear,
3681da177e4SLinus Torvalds 	.con_putc		= sticon_putc,
3691da177e4SLinus Torvalds 	.con_putcs		= sticon_putcs,
3701da177e4SLinus Torvalds 	.con_cursor		= sticon_cursor,
3711da177e4SLinus Torvalds 	.con_scroll		= sticon_scroll,
3721da177e4SLinus Torvalds 	.con_switch		= sticon_switch,
3731da177e4SLinus Torvalds 	.con_blank		= sticon_blank,
3747ff3f14dSHelge Deller 	.con_font_set		= sticon_font_set,
3757ff3f14dSHelge Deller 	.con_font_default	= sticon_font_default,
3761da177e4SLinus Torvalds 	.con_build_attr		= sticon_build_attr,
3771da177e4SLinus Torvalds 	.con_invert_region	= sticon_invert_region,
3781da177e4SLinus Torvalds };
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds 
sticonsole_init(void)3823d1e412aSAdrian Bunk static int __init sticonsole_init(void)
3831da177e4SLinus Torvalds {
3847ff3f14dSHelge Deller     int err, i;
3857ff3f14dSHelge Deller 
3861da177e4SLinus Torvalds     /* already initialized ? */
3871da177e4SLinus Torvalds     if (sticon_sti)
3881da177e4SLinus Torvalds 	 return 0;
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds     sticon_sti = sti_get_rom(0);
3911da177e4SLinus Torvalds     if (!sticon_sti)
3921da177e4SLinus Torvalds 	return -ENODEV;
3931da177e4SLinus Torvalds 
3947ff3f14dSHelge Deller     for (i = 0; i < MAX_NR_CONSOLES; i++)
3957ff3f14dSHelge Deller 	font_data[i] = STI_DEF_FONT;
3967ff3f14dSHelge Deller 
397b046f984SHelge Deller     pr_info("sticon: Initializing STI text console on %s at [%s]\n",
398b046f984SHelge Deller 	sticon_sti->sti_data->inq_outptr.dev_name,
399b046f984SHelge Deller 	sticon_sti->pa_path);
400155957f5SWang YanQing     console_lock();
40158a5c67aSHelge Deller     err = do_take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1,
40258a5c67aSHelge Deller 		PAGE0->mem_cons.cl_class != CL_DUPLEX);
403155957f5SWang YanQing     console_unlock();
40458a5c67aSHelge Deller 
405155957f5SWang YanQing     return err;
4061da177e4SLinus Torvalds }
4071da177e4SLinus Torvalds 
4081da177e4SLinus Torvalds module_init(sticonsole_init);
4091da177e4SLinus Torvalds MODULE_LICENSE("GPL");
410