2 * Copyright (C) 2007-2009 Luc Verhaegen <libv@skynet.be>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * All IO necessary to poke VGA registers.
18 #include <pc80/vga_io.h>
22 #define VGA_CR_INDEX 0x3D4
23 #define VGA_CR_VALUE 0x3D5
25 #define VGA_SR_INDEX 0x3C4
26 #define VGA_SR_VALUE 0x3C5
28 #define VGA_GR_INDEX 0x3CE
29 #define VGA_GR_VALUE 0x3CF
31 #define VGA_AR_INDEX 0x3C0
32 #define VGA_AR_VALUE_READ 0x3C1
33 #define VGA_AR_VALUE_WRITE VGA_AR_INDEX
35 #define VGA_MISC_WRITE 0x3C2
36 #define VGA_MISC_READ 0x3CC
38 #define VGA_ENABLE 0x3C3
39 #define VGA_STAT1 0x3DA
41 #define VGA_DAC_MASK 0x3C6
42 #define VGA_DAC_READ_ADDRESS 0x3C7
43 #define VGA_DAC_WRITE_ADDRESS 0x3C8
44 #define VGA_DAC_DATA 0x3C9
47 * VGA enable. Poke this to have the PCI IO enabled device accept VGA IO.
52 return inb(VGA_ENABLE
);
56 vga_enable_write(unsigned char value
)
58 outb(value
, VGA_ENABLE
);
62 vga_enable_mask(unsigned char value
, unsigned char mask
)
66 tmp
= vga_enable_read();
68 tmp
|= (value
& mask
);
69 vga_enable_write(tmp
);
73 * Miscellaneous register.
78 return inb(VGA_MISC_READ
);
82 vga_misc_write(unsigned char value
)
84 outb(value
, VGA_MISC_WRITE
);
88 vga_misc_mask(unsigned char value
, unsigned char mask
)
92 tmp
= vga_misc_read();
94 tmp
|= (value
& mask
);
99 * Sequencer registers.
102 vga_sr_read(unsigned char index
)
104 outb(index
, VGA_SR_INDEX
);
105 return (inb(VGA_SR_VALUE
));
109 vga_sr_write(unsigned char index
, unsigned char value
)
111 outb(index
, VGA_SR_INDEX
);
112 outb(value
, VGA_SR_VALUE
);
116 vga_sr_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
120 tmp
= vga_sr_read(index
);
122 tmp
|= (value
& mask
);
123 vga_sr_write(index
, tmp
);
130 vga_cr_read(unsigned char index
)
132 outb(index
, VGA_CR_INDEX
);
133 return (inb(VGA_CR_VALUE
));
137 vga_cr_write(unsigned char index
, unsigned char value
)
139 outb(index
, VGA_CR_INDEX
);
140 outb(value
, VGA_CR_VALUE
);
144 vga_cr_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
148 tmp
= vga_cr_read(index
);
150 tmp
|= (value
& mask
);
151 vga_cr_write(index
, tmp
);
155 * Attribute registers.
158 vga_ar_read(unsigned char index
)
162 (void) inb(VGA_STAT1
);
163 outb(index
, VGA_AR_INDEX
);
164 ret
= inb(VGA_AR_VALUE_READ
);
165 (void) inb(VGA_STAT1
);
171 vga_ar_write(unsigned char index
, unsigned char value
)
173 (void) inb(VGA_STAT1
);
174 outb(index
, VGA_AR_INDEX
);
175 outb(value
, VGA_AR_VALUE_WRITE
);
176 (void) inb(VGA_STAT1
);
180 vga_ar_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
184 tmp
= vga_ar_read(index
);
186 tmp
|= (value
& mask
);
187 vga_ar_write(index
, tmp
);
191 * Graphics registers.
194 vga_gr_read(unsigned char index
)
196 outb(index
, VGA_GR_INDEX
);
197 return (inb(VGA_GR_VALUE
));
201 vga_gr_write(unsigned char index
, unsigned char value
)
203 outb(index
, VGA_GR_INDEX
);
204 outb(value
, VGA_GR_VALUE
);
208 vga_gr_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
212 tmp
= vga_gr_read(index
);
214 tmp
|= (value
& mask
);
215 vga_gr_write(index
, tmp
);
222 vga_palette_enable(void)
224 (void) inb(VGA_STAT1
);
225 outb(0x00, VGA_AR_INDEX
);
226 (void) inb(VGA_STAT1
);
230 vga_palette_disable(void)
232 (void) inb(VGA_STAT1
);
233 outb(0x20, VGA_AR_INDEX
);
234 (void) inb(VGA_STAT1
);
238 vga_dac_mask_read(void)
240 return inb(VGA_DAC_MASK
);
244 vga_dac_mask_write(unsigned char mask
)
246 outb(mask
, VGA_DAC_MASK
);
250 vga_dac_read_address(unsigned char address
)
252 outb(address
, VGA_DAC_READ_ADDRESS
);
256 vga_dac_write_address(unsigned char address
)
258 outb(address
, VGA_DAC_WRITE_ADDRESS
);
262 vga_dac_data_read(void)
264 return inb(VGA_DAC_DATA
);
268 vga_dac_data_write(unsigned char data
)
270 outb(data
, VGA_DAC_DATA
);