1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * All IO necessary to poke VGA registers.
6 #include <pc80/vga_io.h>
10 #define VGA_CR_INDEX 0x3D4
11 #define VGA_CR_VALUE 0x3D5
13 #define VGA_SR_INDEX 0x3C4
14 #define VGA_SR_VALUE 0x3C5
16 #define VGA_GR_INDEX 0x3CE
17 #define VGA_GR_VALUE 0x3CF
19 #define VGA_AR_INDEX 0x3C0
20 #define VGA_AR_VALUE_READ 0x3C1
21 #define VGA_AR_VALUE_WRITE VGA_AR_INDEX
23 #define VGA_MISC_WRITE 0x3C2
24 #define VGA_MISC_READ 0x3CC
26 #define VGA_ENABLE 0x3C3
27 #define VGA_STAT1 0x3DA
29 #define VGA_DAC_MASK 0x3C6
30 #define VGA_DAC_READ_ADDRESS 0x3C7
31 #define VGA_DAC_WRITE_ADDRESS 0x3C8
32 #define VGA_DAC_DATA 0x3C9
35 * VGA enable. Poke this to have the PCI IO enabled device accept VGA IO.
40 return inb(VGA_ENABLE
);
44 vga_enable_write(unsigned char value
)
46 outb(value
, VGA_ENABLE
);
50 vga_enable_mask(unsigned char value
, unsigned char mask
)
54 tmp
= vga_enable_read();
56 tmp
|= (value
& mask
);
57 vga_enable_write(tmp
);
61 * Miscellaneous register.
66 return inb(VGA_MISC_READ
);
70 vga_misc_write(unsigned char value
)
72 outb(value
, VGA_MISC_WRITE
);
76 vga_misc_mask(unsigned char value
, unsigned char mask
)
80 tmp
= vga_misc_read();
82 tmp
|= (value
& mask
);
87 * Sequencer registers.
90 vga_sr_read(unsigned char index
)
92 outb(index
, VGA_SR_INDEX
);
93 return (inb(VGA_SR_VALUE
));
97 vga_sr_write(unsigned char index
, unsigned char value
)
99 outb(index
, VGA_SR_INDEX
);
100 outb(value
, VGA_SR_VALUE
);
104 vga_sr_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
108 tmp
= vga_sr_read(index
);
110 tmp
|= (value
& mask
);
111 vga_sr_write(index
, tmp
);
118 vga_cr_read(unsigned char index
)
120 outb(index
, VGA_CR_INDEX
);
121 return (inb(VGA_CR_VALUE
));
125 vga_cr_write(unsigned char index
, unsigned char value
)
127 outb(index
, VGA_CR_INDEX
);
128 outb(value
, VGA_CR_VALUE
);
132 vga_cr_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
136 tmp
= vga_cr_read(index
);
138 tmp
|= (value
& mask
);
139 vga_cr_write(index
, tmp
);
143 * Attribute registers.
146 vga_ar_read(unsigned char index
)
150 (void)inb(VGA_STAT1
);
151 outb(index
, VGA_AR_INDEX
);
152 ret
= inb(VGA_AR_VALUE_READ
);
153 (void)inb(VGA_STAT1
);
159 vga_ar_write(unsigned char index
, unsigned char value
)
161 (void)inb(VGA_STAT1
);
162 outb(index
, VGA_AR_INDEX
);
163 outb(value
, VGA_AR_VALUE_WRITE
);
164 (void)inb(VGA_STAT1
);
168 vga_ar_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
172 tmp
= vga_ar_read(index
);
174 tmp
|= (value
& mask
);
175 vga_ar_write(index
, tmp
);
179 * Graphics registers.
182 vga_gr_read(unsigned char index
)
184 outb(index
, VGA_GR_INDEX
);
185 return (inb(VGA_GR_VALUE
));
189 vga_gr_write(unsigned char index
, unsigned char value
)
191 outb(index
, VGA_GR_INDEX
);
192 outb(value
, VGA_GR_VALUE
);
196 vga_gr_mask(unsigned char index
, unsigned char value
, unsigned char mask
)
200 tmp
= vga_gr_read(index
);
202 tmp
|= (value
& mask
);
203 vga_gr_write(index
, tmp
);
210 vga_palette_enable(void)
212 (void)inb(VGA_STAT1
);
213 outb(0x00, VGA_AR_INDEX
);
214 (void)inb(VGA_STAT1
);
218 vga_palette_disable(void)
220 (void)inb(VGA_STAT1
);
221 outb(0x20, VGA_AR_INDEX
);
222 (void)inb(VGA_STAT1
);
226 vga_dac_mask_read(void)
228 return inb(VGA_DAC_MASK
);
232 vga_dac_mask_write(unsigned char mask
)
234 outb(mask
, VGA_DAC_MASK
);
238 vga_dac_read_address(unsigned char address
)
240 outb(address
, VGA_DAC_READ_ADDRESS
);
244 vga_dac_write_address(unsigned char address
)
246 outb(address
, VGA_DAC_WRITE_ADDRESS
);
250 vga_dac_data_read(void)
252 return inb(VGA_DAC_DATA
);
256 vga_dac_data_write(unsigned char data
)
258 outb(data
, VGA_DAC_DATA
);