summaryrefslogtreecommitdiffstats
path: root/drivers/video/fbcon-vga.c
blob: 05f843d257333b33615c469ad24ba3014e4e0cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 *  linux/drivers/video/fbcon-vga.c -- Low level frame buffer operations for
 *				       VGA characters/attributes
 *
 *	Created 28 Mar 1998 by Geert Uytterhoeven
 *	Monochrome attributes added May 1998 by Andrew Apted
 *
 *  This file is subject to the terms and conditions of the GNU General Public
 *  License.  See the file COPYING in the main directory of this archive for
 *  more details.
 */

#include <linux/module.h>
#include <linux/tty.h>
#include <linux/console.h>
#include <linux/string.h>
#include <linux/fb.h>

#include <asm/io.h>

#include <video/fbcon.h>
#include <video/fbcon-vga.h>


    /*
     *  VGA screen access
     */ 

static inline void vga_writew(u16 val, u16 *addr)
{
#ifdef __powerpc__
    st_le16(addr, val);
#else
    writew(val, (unsigned long)addr);
#endif /* !__powerpc__ */
}

static inline u16 vga_readw(u16 *addr)
{
#ifdef __powerpc__
    return ld_le16(addr);
#else
    return readw((unsigned long)addr);
#endif /* !__powerpc__ */	
}

static inline void vga_memsetw(void *s, u16 c, unsigned int count)
{
    u16 *addr = (u16 *)s;

    while (count) {
	count--;
	vga_writew(c, addr++);
    }
}

static inline void vga_memmovew(u16 *to, u16 *from, unsigned int count)
{
    if (to < from) {
	while (count) {
	    count--;
	    vga_writew(vga_readw(from++), to++);
	}
    } else {
	from += count;
	to += count;
	while (count) {
	    count--;
	    vga_writew(vga_readw(--from), --to);
	}
    }
}


    /*
     *  VGA characters/attributes
     */

static inline u16 fbcon_vga_attr(struct display *p,
				 unsigned short s)
{
        /* Underline and reverse-video are mutually exclusive on MDA.
         * Since reverse-video is used for cursors and selected areas, 
	 * it takes precedence.
         */

	return (attr_reverse(p, s) ? 0x7000 :
		(attr_underline(p, s) ? 0x0100 : 0x0700)) |
	       (attr_bold(p, s) ? 0x0800 : 0) |
	       (attr_blink(p, s) ? 0x8000 : 0);
}

void fbcon_vga_setup(struct display *p)
{
    p->next_line = p->line_length;
    p->next_plane = 0;
}

void fbcon_vga_bmove(struct display *p, int sy, int sx, int dy, int dx,
		     int height, int width)
{
    u16 *src, *dst;
    int rows;

    if (sx == 0 && dx == 0 && width == p->next_line/2) {
	src = (u16 *)(p->screen_base+sy*p->next_line);
	dst = (u16 *)(p->screen_base+dy*p->next_line);
	vga_memmovew(dst, src, height*width);
    } else if (dy < sy || (dy == sy && dx < sx)) {
	src = (u16 *)(p->screen_base+sy*p->next_line+sx*2);
	dst = (u16 *)(p->screen_base+dy*p->next_line+dx*2);
	for (rows = height; rows-- ;) {
	    vga_memmovew(dst, src, width);
	    src += p->next_line/2;
	    dst += p->next_line/2;
	}
    } else {
	src = (u16 *)(p->screen_base+(sy+height-1)*p->next_line+sx*2);
	dst = (u16 *)(p->screen_base+(dy+height-1)*p->next_line+dx*2);
	for (rows = height; rows-- ;) {
	    vga_memmovew(dst, src, width);
	    src -= p->next_line/2;
	    dst -= p->next_line/2;
	}
    }
}

void fbcon_vga_clear(struct vc_data *conp, struct display *p, int sy, int sx,
		     int height, int width)
{
    u16 *dest = (u16 *)(p->screen_base+sy*p->next_line+sx*2);
    int rows;

    if (sx == 0 && width*2 == p->next_line)      
	vga_memsetw(dest, conp->vc_video_erase_char, height*width);
    else
	for (rows = height; rows-- ; dest += p->next_line/2)
	    vga_memsetw(dest, conp->vc_video_erase_char, width);
}

void fbcon_vga_putc(struct vc_data *conp, struct display *p, int c, int y,
		    int x)
{
    u16 *dst = (u16 *)(p->screen_base+y*p->next_line+x*2);
    if (conp->vc_can_do_color)
    	vga_writew(c, dst);
    else
    	vga_writew(fbcon_vga_attr(p, c) | (c & 0xff), dst);
}

void fbcon_vga_putcs(struct vc_data *conp, struct display *p, 
		     const unsigned short *s, int count, int y, int x)
{
    u16 *dst = (u16 *)(p->screen_base+y*p->next_line+x*2);
    u16 sattr;
    if (conp->vc_can_do_color)
    	while (count--)
    	    vga_writew(scr_readw(s++), dst++);
    else {
        sattr = fbcon_vga_attr(p, scr_readw(s));
        while (count--)
	    vga_writew(sattr | ((int) (scr_readw(s++)) & 0xff), dst++);
    }
}

void fbcon_vga_revc(struct display *p, int x, int y)
{
    u16 *dst = (u16 *)(p->screen_base+y*p->next_line+x*2);
    u16 val = vga_readw(dst);
    val = (val & 0x88ff) | ((val<<4) & 0x7000) | ((val>>4) & 0x0700);
    vga_writew(val, dst);
}


    /*
     *  `switch' for the low level operations
     */

struct display_switch fbcon_vga = {
    fbcon_vga_setup, fbcon_vga_bmove, fbcon_vga_clear, fbcon_vga_putc,
    fbcon_vga_putcs, fbcon_vga_revc, NULL, NULL, NULL, FONTWIDTH(8)
};


#ifdef MODULE
int init_module(void)
{
    return 0;
}

void cleanup_module(void)
{}
#endif /* MODULE */


    /*
     *  Visible symbols for modules
     */

EXPORT_SYMBOL(fbcon_vga);
EXPORT_SYMBOL(fbcon_vga_setup);
EXPORT_SYMBOL(fbcon_vga_bmove);
EXPORT_SYMBOL(fbcon_vga_clear);
EXPORT_SYMBOL(fbcon_vga_putc);
EXPORT_SYMBOL(fbcon_vga_putcs);
EXPORT_SYMBOL(fbcon_vga_revc);