1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
4 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
8 #include <linux/via-core.h>
11 void viafb_get_device_support_state(u32
*support_state
)
13 *support_state
= CRT_Device
;
15 if (viaparinfo
->chip_info
->tmds_chip_info
.tmds_chip_name
== VT1632_TMDS
)
16 *support_state
|= DVI_Device
;
18 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
== VT1631_LVDS
)
19 *support_state
|= LCD_Device
;
22 void viafb_get_device_connect_state(u32
*connect_state
)
26 *connect_state
= CRT_Device
;
28 if (viafb_dvi_sense())
29 *connect_state
|= DVI_Device
;
31 viafb_lcd_get_mobile_state(&mobile
);
33 *connect_state
|= LCD_Device
;
36 bool viafb_lcd_get_support_expand_state(u32 xres
, u32 yres
)
38 unsigned int support_state
= 0;
40 switch (viafb_lcd_panel_id
) {
41 case LCD_PANEL_ID0_640X480
:
42 if ((xres
< 640) && (yres
< 480))
46 case LCD_PANEL_ID1_800X600
:
47 if ((xres
< 800) && (yres
< 600))
51 case LCD_PANEL_ID2_1024X768
:
52 if ((xres
< 1024) && (yres
< 768))
56 case LCD_PANEL_ID3_1280X768
:
57 if ((xres
< 1280) && (yres
< 768))
61 case LCD_PANEL_ID4_1280X1024
:
62 if ((xres
< 1280) && (yres
< 1024))
66 case LCD_PANEL_ID5_1400X1050
:
67 if ((xres
< 1400) && (yres
< 1050))
71 case LCD_PANEL_ID6_1600X1200
:
72 if ((xres
< 1600) && (yres
< 1200))
76 case LCD_PANEL_ID7_1366X768
:
77 if ((xres
< 1366) && (yres
< 768))
81 case LCD_PANEL_ID8_1024X600
:
82 if ((xres
< 1024) && (yres
< 600))
86 case LCD_PANEL_ID9_1280X800
:
87 if ((xres
< 1280) && (yres
< 800))
91 case LCD_PANEL_IDA_800X480
:
92 if ((xres
< 800) && (yres
< 480))
96 case LCD_PANEL_IDB_1360X768
:
97 if ((xres
< 1360) && (yres
< 768))
101 case LCD_PANEL_IDC_480X640
:
102 if ((xres
< 480) && (yres
< 640))
103 support_state
= true;
107 support_state
= false;
111 return support_state
;
114 /*====================================================================*/
115 /* Gamma Function Implementation*/
116 /*====================================================================*/
118 void viafb_set_gamma_table(int bpp
, unsigned int *gamma_table
)
121 int active_device_amount
= 0;
122 int device_status
= viafb_DeviceStatus
;
124 for (i
= 0; i
< sizeof(viafb_DeviceStatus
) * 8; i
++) {
125 if (device_status
& 1)
126 active_device_amount
++;
130 /* 8 bpp mode can't adjust gamma */
135 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
136 case UNICHROME_CLE266
:
138 viafb_write_reg_mask(SR16
, VIASR
, 0x80, BIT7
);
142 case UNICHROME_PM800
:
143 case UNICHROME_CN700
:
144 case UNICHROME_CX700
:
145 case UNICHROME_K8M890
:
146 case UNICHROME_P4M890
:
147 case UNICHROME_P4M900
:
148 viafb_write_reg_mask(CR33
, VIACR
, 0x80, BIT7
);
151 sr1a
= (unsigned int)viafb_read_reg(VIASR
, SR1A
);
152 viafb_write_reg_mask(SR1A
, VIASR
, 0x0, BIT0
);
154 /* Fill IGA1 Gamma Table */
155 outb(0, LUT_INDEX_WRITE
);
156 for (i
= 0; i
< 256; i
++) {
157 outb(gamma_table
[i
] >> 16, LUT_DATA
);
158 outb(gamma_table
[i
] >> 8 & 0xFF, LUT_DATA
);
159 outb(gamma_table
[i
] & 0xFF, LUT_DATA
);
162 /* If adjust Gamma value in SAMM, fill IGA1,
163 IGA2 Gamma table simultaneous. */
164 /* Switch to IGA2 Gamma Table */
165 if ((active_device_amount
> 1) &&
166 !((viaparinfo
->chip_info
->gfx_chip_name
==
168 (viaparinfo
->chip_info
->gfx_chip_revision
< 15))) {
169 viafb_write_reg_mask(SR1A
, VIASR
, 0x01, BIT0
);
170 viafb_write_reg_mask(CR6A
, VIACR
, 0x02, BIT1
);
172 /* Fill IGA2 Gamma Table */
173 outb(0, LUT_INDEX_WRITE
);
174 for (i
= 0; i
< 256; i
++) {
175 outb(gamma_table
[i
] >> 16, LUT_DATA
);
176 outb(gamma_table
[i
] >> 8 & 0xFF, LUT_DATA
);
177 outb(gamma_table
[i
] & 0xFF, LUT_DATA
);
180 viafb_write_reg(SR1A
, VIASR
, sr1a
);
183 void viafb_get_gamma_table(unsigned int *gamma_table
)
185 unsigned char color_r
, color_g
, color_b
;
186 unsigned char sr1a
= 0;
190 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
191 case UNICHROME_CLE266
:
193 viafb_write_reg_mask(SR16
, VIASR
, 0x80, BIT7
);
197 case UNICHROME_PM800
:
198 case UNICHROME_CN700
:
199 case UNICHROME_CX700
:
200 case UNICHROME_K8M890
:
201 case UNICHROME_P4M890
:
202 case UNICHROME_P4M900
:
203 viafb_write_reg_mask(CR33
, VIACR
, 0x80, BIT7
);
206 sr1a
= viafb_read_reg(VIASR
, SR1A
);
207 viafb_write_reg_mask(SR1A
, VIASR
, 0x0, BIT0
);
209 /* Reading gamma table to get color value */
210 outb(0, LUT_INDEX_READ
);
211 for (i
= 0; i
< 256; i
++) {
212 color_r
= inb(LUT_DATA
);
213 color_g
= inb(LUT_DATA
);
214 color_b
= inb(LUT_DATA
);
216 ((((u32
) color_r
) << 16) |
217 (((u16
) color_g
) << 8)) | color_b
;
219 viafb_write_reg(SR1A
, VIASR
, sr1a
);
222 void viafb_get_gamma_support_state(int bpp
, unsigned int *support_state
)
225 *support_state
= None_Device
;
227 *support_state
= CRT_Device
| DVI_Device
| LCD_Device
;