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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * All IO necessary to poke VGA registers.
22 #include <pc80/vga_io.h>
26 #define VGA_CR_INDEX 0x3D4
27 #define VGA_CR_VALUE 0x3D5
29 #define VGA_SR_INDEX 0x3C4
30 #define VGA_SR_VALUE 0x3C5
32 #define VGA_GR_INDEX 0x3CE
33 #define VGA_GR_VALUE 0x3CF
35 #define VGA_AR_INDEX 0x3C0
36 #define VGA_AR_VALUE_READ 0x3C1
37 #define VGA_AR_VALUE_WRITE VGA_AR_INDEX
39 #define VGA_MISC_WRITE 0x3C2
40 #define VGA_MISC_READ 0x3CC
42 #define VGA_ENABLE 0x3C3
43 #define VGA_STAT1 0x3DA
45 #define VGA_DAC_MASK 0x3C6
46 #define VGA_DAC_READ_ADDRESS 0x3C7
47 #define VGA_DAC_WRITE_ADDRESS 0x3C8
48 #define VGA_DAC_DATA 0x3C9
51 * VGA enable. Poke this to have the PCI IO enabled device accept VGA IO.
56 return inb(VGA_ENABLE);
60 vga_enable_write(unsigned char value)
62 outb(value, VGA_ENABLE);
66 vga_enable_mask(unsigned char value, unsigned char mask)
70 tmp = vga_enable_read();
72 tmp |= (value & mask);
73 vga_enable_write(tmp);
77 * Miscellaneous register.
82 return inb(VGA_MISC_READ);
86 vga_misc_write(unsigned char value)
88 outb(value, VGA_MISC_WRITE);
92 vga_misc_mask(unsigned char value, unsigned char mask)
96 tmp = vga_misc_read();
98 tmp |= (value & mask);
103 * Sequencer registers.
106 vga_sr_read(unsigned char index)
108 outb(index, VGA_SR_INDEX);
109 return (inb(VGA_SR_VALUE));
113 vga_sr_write(unsigned char index, unsigned char value)
115 outb(index, VGA_SR_INDEX);
116 outb(value, VGA_SR_VALUE);
120 vga_sr_mask(unsigned char index, unsigned char value, unsigned char mask)
124 tmp = vga_sr_read(index);
126 tmp |= (value & mask);
127 vga_sr_write(index, tmp);
134 vga_cr_read(unsigned char index)
136 outb(index, VGA_CR_INDEX);
137 return (inb(VGA_CR_VALUE));
141 vga_cr_write(unsigned char index, unsigned char value)
143 outb(index, VGA_CR_INDEX);
144 outb(value, VGA_CR_VALUE);
148 vga_cr_mask(unsigned char index, unsigned char value, unsigned char mask)
152 tmp = vga_cr_read(index);
154 tmp |= (value & mask);
155 vga_cr_write(index, tmp);
159 * Attribute registers.
162 vga_ar_read(unsigned char index)
166 (void) inb(VGA_STAT1);
167 outb(index, VGA_AR_INDEX);
168 ret = inb(VGA_AR_VALUE_READ);
169 (void) inb(VGA_STAT1);
175 vga_ar_write(unsigned char index, unsigned char value)
177 (void) inb(VGA_STAT1);
178 outb(index, VGA_AR_INDEX);
179 outb(value, VGA_AR_VALUE_WRITE);
180 (void) inb(VGA_STAT1);
184 vga_ar_mask(unsigned char index, unsigned char value, unsigned char mask)
188 tmp = vga_ar_read(index);
190 tmp |= (value & mask);
191 vga_ar_write(index, tmp);
195 * Graphics registers.
198 vga_gr_read(unsigned char index)
200 outb(index, VGA_GR_INDEX);
201 return (inb(VGA_GR_VALUE));
205 vga_gr_write(unsigned char index, unsigned char value)
207 outb(index, VGA_GR_INDEX);
208 outb(value, VGA_GR_VALUE);
212 vga_gr_mask(unsigned char index, unsigned char value, unsigned char mask)
216 tmp = vga_gr_read(index);
218 tmp |= (value & mask);
219 vga_gr_write(index, tmp);
226 vga_palette_enable(void)
228 (void) inb(VGA_STAT1);
229 outb(0x00, VGA_AR_INDEX);
230 (void) inb(VGA_STAT1);
234 vga_palette_disable(void)
236 (void) inb(VGA_STAT1);
237 outb(0x20, VGA_AR_INDEX);
238 (void) inb(VGA_STAT1);
242 vga_dac_mask_read(void)
244 return inb(VGA_DAC_MASK);
248 vga_dac_mask_write(unsigned char mask)
250 outb(mask, VGA_DAC_MASK);
254 vga_dac_read_address(unsigned char address)
256 outb(address, VGA_DAC_READ_ADDRESS);
260 vga_dac_write_address(unsigned char address)
262 outb(address, VGA_DAC_WRITE_ADDRESS);
266 vga_dac_data_read(void)
268 return inb(VGA_DAC_DATA);
272 vga_dac_data_write(unsigned char data)
274 outb(data, VGA_DAC_DATA);