soc/intel/alderlake: Add ADL-P 4+4 with 28W TDP
[coreboot.git] / src / drivers / pc80 / vga / vga_io.c
blob2bf2af4fcc73cbf5d9017ee12a084776a60a0b24
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /*
4 * All IO necessary to poke VGA registers.
5 */
6 #include <pc80/vga_io.h>
8 #include <arch/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.
37 unsigned char
38 vga_enable_read(void)
40 return inb(VGA_ENABLE);
43 void
44 vga_enable_write(unsigned char value)
46 outb(value, VGA_ENABLE);
49 void
50 vga_enable_mask(unsigned char value, unsigned char mask)
52 unsigned char tmp;
54 tmp = vga_enable_read();
55 tmp &= ~mask;
56 tmp |= (value & mask);
57 vga_enable_write(tmp);
61 * Miscellaneous register.
63 unsigned char
64 vga_misc_read(void)
66 return inb(VGA_MISC_READ);
69 void
70 vga_misc_write(unsigned char value)
72 outb(value, VGA_MISC_WRITE);
75 void
76 vga_misc_mask(unsigned char value, unsigned char mask)
78 unsigned char tmp;
80 tmp = vga_misc_read();
81 tmp &= ~mask;
82 tmp |= (value & mask);
83 vga_misc_write(tmp);
87 * Sequencer registers.
89 unsigned char
90 vga_sr_read(unsigned char index)
92 outb(index, VGA_SR_INDEX);
93 return (inb(VGA_SR_VALUE));
96 void
97 vga_sr_write(unsigned char index, unsigned char value)
99 outb(index, VGA_SR_INDEX);
100 outb(value, VGA_SR_VALUE);
103 void
104 vga_sr_mask(unsigned char index, unsigned char value, unsigned char mask)
106 unsigned char tmp;
108 tmp = vga_sr_read(index);
109 tmp &= ~mask;
110 tmp |= (value & mask);
111 vga_sr_write(index, tmp);
115 * CRTC registers.
117 unsigned char
118 vga_cr_read(unsigned char index)
120 outb(index, VGA_CR_INDEX);
121 return (inb(VGA_CR_VALUE));
124 void
125 vga_cr_write(unsigned char index, unsigned char value)
127 outb(index, VGA_CR_INDEX);
128 outb(value, VGA_CR_VALUE);
131 void
132 vga_cr_mask(unsigned char index, unsigned char value, unsigned char mask)
134 unsigned char tmp;
136 tmp = vga_cr_read(index);
137 tmp &= ~mask;
138 tmp |= (value & mask);
139 vga_cr_write(index, tmp);
143 * Attribute registers.
145 unsigned char
146 vga_ar_read(unsigned char index)
148 unsigned char ret;
150 (void)inb(VGA_STAT1);
151 outb(index, VGA_AR_INDEX);
152 ret = inb(VGA_AR_VALUE_READ);
153 (void)inb(VGA_STAT1);
155 return ret;
158 void
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);
167 void
168 vga_ar_mask(unsigned char index, unsigned char value, unsigned char mask)
170 unsigned char tmp;
172 tmp = vga_ar_read(index);
173 tmp &= ~mask;
174 tmp |= (value & mask);
175 vga_ar_write(index, tmp);
179 * Graphics registers.
181 unsigned char
182 vga_gr_read(unsigned char index)
184 outb(index, VGA_GR_INDEX);
185 return (inb(VGA_GR_VALUE));
188 void
189 vga_gr_write(unsigned char index, unsigned char value)
191 outb(index, VGA_GR_INDEX);
192 outb(value, VGA_GR_VALUE);
195 void
196 vga_gr_mask(unsigned char index, unsigned char value, unsigned char mask)
198 unsigned char tmp;
200 tmp = vga_gr_read(index);
201 tmp &= ~mask;
202 tmp |= (value & mask);
203 vga_gr_write(index, tmp);
207 * DAC functions.
209 void
210 vga_palette_enable(void)
212 (void)inb(VGA_STAT1);
213 outb(0x00, VGA_AR_INDEX);
214 (void)inb(VGA_STAT1);
217 void
218 vga_palette_disable(void)
220 (void)inb(VGA_STAT1);
221 outb(0x20, VGA_AR_INDEX);
222 (void)inb(VGA_STAT1);
225 unsigned char
226 vga_dac_mask_read(void)
228 return inb(VGA_DAC_MASK);
231 void
232 vga_dac_mask_write(unsigned char mask)
234 outb(mask, VGA_DAC_MASK);
237 void
238 vga_dac_read_address(unsigned char address)
240 outb(address, VGA_DAC_READ_ADDRESS);
243 void
244 vga_dac_write_address(unsigned char address)
246 outb(address, VGA_DAC_WRITE_ADDRESS);
249 unsigned char
250 vga_dac_data_read(void)
252 return inb(VGA_DAC_DATA);
255 void
256 vga_dac_data_write(unsigned char data)
258 outb(data, VGA_DAC_DATA);