2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 static const struct pci_device_id_info pciidlist
[] = {
25 {PCI_VIA_VENDOR_ID
, UNICHROME_CLE266_DID
, UNICHROME_CLE266
},
26 {PCI_VIA_VENDOR_ID
, UNICHROME_PM800_DID
, UNICHROME_PM800
},
27 {PCI_VIA_VENDOR_ID
, UNICHROME_K400_DID
, UNICHROME_K400
},
28 {PCI_VIA_VENDOR_ID
, UNICHROME_K800_DID
, UNICHROME_K800
},
29 {PCI_VIA_VENDOR_ID
, UNICHROME_CN700_DID
, UNICHROME_CN700
},
30 {PCI_VIA_VENDOR_ID
, UNICHROME_P4M890_DID
, UNICHROME_P4M890
},
31 {PCI_VIA_VENDOR_ID
, UNICHROME_K8M890_DID
, UNICHROME_K8M890
},
32 {PCI_VIA_VENDOR_ID
, UNICHROME_CX700_DID
, UNICHROME_CX700
},
33 {PCI_VIA_VENDOR_ID
, UNICHROME_P4M900_DID
, UNICHROME_P4M900
},
34 {PCI_VIA_VENDOR_ID
, UNICHROME_CN750_DID
, UNICHROME_CN750
},
35 {PCI_VIA_VENDOR_ID
, UNICHROME_VX800_DID
, UNICHROME_VX800
},
39 struct offset offset_reg
= {
40 /* IGA1 Offset Register */
41 {IGA1_OFFSET_REG_NUM
, {{CR13
, 0, 7}, {CR35
, 5, 7} } },
42 /* IGA2 Offset Register */
43 {IGA2_OFFSET_REG_NUM
, {{CR66
, 0, 7}, {CR67
, 0, 1} } }
46 static struct pll_map pll_value
[] = {
47 {CLK_25_175M
, CLE266_PLL_25_175M
, K800_PLL_25_175M
, CX700_25_175M
},
48 {CLK_29_581M
, CLE266_PLL_29_581M
, K800_PLL_29_581M
, CX700_29_581M
},
49 {CLK_26_880M
, CLE266_PLL_26_880M
, K800_PLL_26_880M
, CX700_26_880M
},
50 {CLK_31_490M
, CLE266_PLL_31_490M
, K800_PLL_31_490M
, CX700_31_490M
},
51 {CLK_31_500M
, CLE266_PLL_31_500M
, K800_PLL_31_500M
, CX700_31_500M
},
52 {CLK_31_728M
, CLE266_PLL_31_728M
, K800_PLL_31_728M
, CX700_31_728M
},
53 {CLK_32_668M
, CLE266_PLL_32_668M
, K800_PLL_32_668M
, CX700_32_668M
},
54 {CLK_36_000M
, CLE266_PLL_36_000M
, K800_PLL_36_000M
, CX700_36_000M
},
55 {CLK_40_000M
, CLE266_PLL_40_000M
, K800_PLL_40_000M
, CX700_40_000M
},
56 {CLK_41_291M
, CLE266_PLL_41_291M
, K800_PLL_41_291M
, CX700_41_291M
},
57 {CLK_43_163M
, CLE266_PLL_43_163M
, K800_PLL_43_163M
, CX700_43_163M
},
58 {CLK_45_250M
, CLE266_PLL_45_250M
, K800_PLL_45_250M
, CX700_45_250M
},
59 {CLK_46_000M
, CLE266_PLL_46_000M
, K800_PLL_46_000M
, CX700_46_000M
},
60 {CLK_46_996M
, CLE266_PLL_46_996M
, K800_PLL_46_996M
, CX700_46_996M
},
61 {CLK_48_000M
, CLE266_PLL_48_000M
, K800_PLL_48_000M
, CX700_48_000M
},
62 {CLK_48_875M
, CLE266_PLL_48_875M
, K800_PLL_48_875M
, CX700_48_875M
},
63 {CLK_49_500M
, CLE266_PLL_49_500M
, K800_PLL_49_500M
, CX700_49_500M
},
64 {CLK_52_406M
, CLE266_PLL_52_406M
, K800_PLL_52_406M
, CX700_52_406M
},
65 {CLK_52_977M
, CLE266_PLL_52_977M
, K800_PLL_52_977M
, CX700_52_977M
},
66 {CLK_56_250M
, CLE266_PLL_56_250M
, K800_PLL_56_250M
, CX700_56_250M
},
67 {CLK_60_466M
, CLE266_PLL_60_466M
, K800_PLL_60_466M
, CX700_60_466M
},
68 {CLK_61_500M
, CLE266_PLL_61_500M
, K800_PLL_61_500M
, CX700_61_500M
},
69 {CLK_65_000M
, CLE266_PLL_65_000M
, K800_PLL_65_000M
, CX700_65_000M
},
70 {CLK_65_178M
, CLE266_PLL_65_178M
, K800_PLL_65_178M
, CX700_65_178M
},
71 {CLK_66_750M
, CLE266_PLL_66_750M
, K800_PLL_66_750M
, CX700_66_750M
},
72 {CLK_68_179M
, CLE266_PLL_68_179M
, K800_PLL_68_179M
, CX700_68_179M
},
73 {CLK_69_924M
, CLE266_PLL_69_924M
, K800_PLL_69_924M
, CX700_69_924M
},
74 {CLK_70_159M
, CLE266_PLL_70_159M
, K800_PLL_70_159M
, CX700_70_159M
},
75 {CLK_72_000M
, CLE266_PLL_72_000M
, K800_PLL_72_000M
, CX700_72_000M
},
76 {CLK_78_750M
, CLE266_PLL_78_750M
, K800_PLL_78_750M
, CX700_78_750M
},
77 {CLK_80_136M
, CLE266_PLL_80_136M
, K800_PLL_80_136M
, CX700_80_136M
},
78 {CLK_83_375M
, CLE266_PLL_83_375M
, K800_PLL_83_375M
, CX700_83_375M
},
79 {CLK_83_950M
, CLE266_PLL_83_950M
, K800_PLL_83_950M
, CX700_83_950M
},
80 {CLK_84_750M
, CLE266_PLL_84_750M
, K800_PLL_84_750M
, CX700_84_750M
},
81 {CLK_85_860M
, CLE266_PLL_85_860M
, K800_PLL_85_860M
, CX700_85_860M
},
82 {CLK_88_750M
, CLE266_PLL_88_750M
, K800_PLL_88_750M
, CX700_88_750M
},
83 {CLK_94_500M
, CLE266_PLL_94_500M
, K800_PLL_94_500M
, CX700_94_500M
},
84 {CLK_97_750M
, CLE266_PLL_97_750M
, K800_PLL_97_750M
, CX700_97_750M
},
85 {CLK_101_000M
, CLE266_PLL_101_000M
, K800_PLL_101_000M
,
87 {CLK_106_500M
, CLE266_PLL_106_500M
, K800_PLL_106_500M
,
89 {CLK_108_000M
, CLE266_PLL_108_000M
, K800_PLL_108_000M
,
91 {CLK_113_309M
, CLE266_PLL_113_309M
, K800_PLL_113_309M
,
93 {CLK_118_840M
, CLE266_PLL_118_840M
, K800_PLL_118_840M
,
95 {CLK_119_000M
, CLE266_PLL_119_000M
, K800_PLL_119_000M
,
97 {CLK_121_750M
, CLE266_PLL_121_750M
, K800_PLL_121_750M
,
99 {CLK_125_104M
, CLE266_PLL_125_104M
, K800_PLL_125_104M
,
101 {CLK_133_308M
, CLE266_PLL_133_308M
, K800_PLL_133_308M
,
103 {CLK_135_000M
, CLE266_PLL_135_000M
, K800_PLL_135_000M
,
105 {CLK_136_700M
, CLE266_PLL_136_700M
, K800_PLL_136_700M
,
107 {CLK_138_400M
, CLE266_PLL_138_400M
, K800_PLL_138_400M
,
109 {CLK_146_760M
, CLE266_PLL_146_760M
, K800_PLL_146_760M
,
111 {CLK_153_920M
, CLE266_PLL_153_920M
, K800_PLL_153_920M
,
113 {CLK_156_000M
, CLE266_PLL_156_000M
, K800_PLL_156_000M
,
115 {CLK_157_500M
, CLE266_PLL_157_500M
, K800_PLL_157_500M
,
117 {CLK_162_000M
, CLE266_PLL_162_000M
, K800_PLL_162_000M
,
119 {CLK_187_000M
, CLE266_PLL_187_000M
, K800_PLL_187_000M
,
121 {CLK_193_295M
, CLE266_PLL_193_295M
, K800_PLL_193_295M
,
123 {CLK_202_500M
, CLE266_PLL_202_500M
, K800_PLL_202_500M
,
125 {CLK_204_000M
, CLE266_PLL_204_000M
, K800_PLL_204_000M
,
127 {CLK_218_500M
, CLE266_PLL_218_500M
, K800_PLL_218_500M
,
129 {CLK_234_000M
, CLE266_PLL_234_000M
, K800_PLL_234_000M
,
131 {CLK_267_250M
, CLE266_PLL_267_250M
, K800_PLL_267_250M
,
133 {CLK_297_500M
, CLE266_PLL_297_500M
, K800_PLL_297_500M
,
135 {CLK_74_481M
, CLE266_PLL_74_481M
, K800_PLL_74_481M
, CX700_74_481M
},
136 {CLK_172_798M
, CLE266_PLL_172_798M
, K800_PLL_172_798M
,
138 {CLK_122_614M
, CLE266_PLL_122_614M
, K800_PLL_122_614M
,
140 {CLK_74_270M
, CLE266_PLL_74_270M
, K800_PLL_74_270M
, CX700_74_270M
},
141 {CLK_148_500M
, CLE266_PLL_148_500M
, K800_PLL_148_500M
,
145 static struct fifo_depth_select display_fifo_depth_reg
= {
146 /* IGA1 FIFO Depth_Select */
147 {IGA1_FIFO_DEPTH_SELECT_REG_NUM
, {{SR17
, 0, 7} } },
148 /* IGA2 FIFO Depth_Select */
149 {IGA2_FIFO_DEPTH_SELECT_REG_NUM
,
150 {{CR68
, 4, 7}, {CR94
, 7, 7}, {CR95
, 7, 7} } }
153 static struct fifo_threshold_select fifo_threshold_select_reg
= {
154 /* IGA1 FIFO Threshold Select */
155 {IGA1_FIFO_THRESHOLD_REG_NUM
, {{SR16
, 0, 5}, {SR16
, 7, 7} } },
156 /* IGA2 FIFO Threshold Select */
157 {IGA2_FIFO_THRESHOLD_REG_NUM
, {{CR68
, 0, 3}, {CR95
, 4, 6} } }
160 static struct fifo_high_threshold_select fifo_high_threshold_select_reg
= {
161 /* IGA1 FIFO High Threshold Select */
162 {IGA1_FIFO_HIGH_THRESHOLD_REG_NUM
, {{SR18
, 0, 5}, {SR18
, 7, 7} } },
163 /* IGA2 FIFO High Threshold Select */
164 {IGA2_FIFO_HIGH_THRESHOLD_REG_NUM
, {{CR92
, 0, 3}, {CR95
, 0, 2} } }
167 static struct display_queue_expire_num display_queue_expire_num_reg
= {
168 /* IGA1 Display Queue Expire Num */
169 {IGA1_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM
, {{SR22
, 0, 4} } },
170 /* IGA2 Display Queue Expire Num */
171 {IGA2_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM
, {{CR94
, 0, 6} } }
174 /* Definition Fetch Count Registers*/
175 static struct fetch_count fetch_count_reg
= {
176 /* IGA1 Fetch Count Register */
177 {IGA1_FETCH_COUNT_REG_NUM
, {{SR1C
, 0, 7}, {SR1D
, 0, 1} } },
178 /* IGA2 Fetch Count Register */
179 {IGA2_FETCH_COUNT_REG_NUM
, {{CR65
, 0, 7}, {CR67
, 2, 3} } }
182 static struct iga1_crtc_timing iga1_crtc_reg
= {
183 /* IGA1 Horizontal Total */
184 {IGA1_HOR_TOTAL_REG_NUM
, {{CR00
, 0, 7}, {CR36
, 3, 3} } },
185 /* IGA1 Horizontal Addressable Video */
186 {IGA1_HOR_ADDR_REG_NUM
, {{CR01
, 0, 7} } },
187 /* IGA1 Horizontal Blank Start */
188 {IGA1_HOR_BLANK_START_REG_NUM
, {{CR02
, 0, 7} } },
189 /* IGA1 Horizontal Blank End */
190 {IGA1_HOR_BLANK_END_REG_NUM
,
191 {{CR03
, 0, 4}, {CR05
, 7, 7}, {CR33
, 5, 5} } },
192 /* IGA1 Horizontal Sync Start */
193 {IGA1_HOR_SYNC_START_REG_NUM
, {{CR04
, 0, 7}, {CR33
, 4, 4} } },
194 /* IGA1 Horizontal Sync End */
195 {IGA1_HOR_SYNC_END_REG_NUM
, {{CR05
, 0, 4} } },
196 /* IGA1 Vertical Total */
197 {IGA1_VER_TOTAL_REG_NUM
,
198 {{CR06
, 0, 7}, {CR07
, 0, 0}, {CR07
, 5, 5}, {CR35
, 0, 0} } },
199 /* IGA1 Vertical Addressable Video */
200 {IGA1_VER_ADDR_REG_NUM
,
201 {{CR12
, 0, 7}, {CR07
, 1, 1}, {CR07
, 6, 6}, {CR35
, 2, 2} } },
202 /* IGA1 Vertical Blank Start */
203 {IGA1_VER_BLANK_START_REG_NUM
,
204 {{CR15
, 0, 7}, {CR07
, 3, 3}, {CR09
, 5, 5}, {CR35
, 3, 3} } },
205 /* IGA1 Vertical Blank End */
206 {IGA1_VER_BLANK_END_REG_NUM
, {{CR16
, 0, 7} } },
207 /* IGA1 Vertical Sync Start */
208 {IGA1_VER_SYNC_START_REG_NUM
,
209 {{CR10
, 0, 7}, {CR07
, 2, 2}, {CR07
, 7, 7}, {CR35
, 1, 1} } },
210 /* IGA1 Vertical Sync End */
211 {IGA1_VER_SYNC_END_REG_NUM
, {{CR11
, 0, 3} } }
214 static struct iga2_crtc_timing iga2_crtc_reg
= {
215 /* IGA2 Horizontal Total */
216 {IGA2_HOR_TOTAL_REG_NUM
, {{CR50
, 0, 7}, {CR55
, 0, 3} } },
217 /* IGA2 Horizontal Addressable Video */
218 {IGA2_HOR_ADDR_REG_NUM
, {{CR51
, 0, 7}, {CR55
, 4, 6} } },
219 /* IGA2 Horizontal Blank Start */
220 {IGA2_HOR_BLANK_START_REG_NUM
, {{CR52
, 0, 7}, {CR54
, 0, 2} } },
221 /* IGA2 Horizontal Blank End */
222 {IGA2_HOR_BLANK_END_REG_NUM
,
223 {{CR53
, 0, 7}, {CR54
, 3, 5}, {CR5D
, 6, 6} } },
224 /* IGA2 Horizontal Sync Start */
225 {IGA2_HOR_SYNC_START_REG_NUM
,
226 {{CR56
, 0, 7}, {CR54
, 6, 7}, {CR5C
, 7, 7}, {CR5D
, 7, 7} } },
227 /* IGA2 Horizontal Sync End */
228 {IGA2_HOR_SYNC_END_REG_NUM
, {{CR57
, 0, 7}, {CR5C
, 6, 6} } },
229 /* IGA2 Vertical Total */
230 {IGA2_VER_TOTAL_REG_NUM
, {{CR58
, 0, 7}, {CR5D
, 0, 2} } },
231 /* IGA2 Vertical Addressable Video */
232 {IGA2_VER_ADDR_REG_NUM
, {{CR59
, 0, 7}, {CR5D
, 3, 5} } },
233 /* IGA2 Vertical Blank Start */
234 {IGA2_VER_BLANK_START_REG_NUM
, {{CR5A
, 0, 7}, {CR5C
, 0, 2} } },
235 /* IGA2 Vertical Blank End */
236 {IGA2_VER_BLANK_END_REG_NUM
, {{CR5B
, 0, 7}, {CR5C
, 3, 5} } },
237 /* IGA2 Vertical Sync Start */
238 {IGA2_VER_SYNC_START_REG_NUM
, {{CR5E
, 0, 7}, {CR5F
, 5, 7} } },
239 /* IGA2 Vertical Sync End */
240 {IGA2_VER_SYNC_END_REG_NUM
, {{CR5F
, 0, 4} } }
243 static struct rgbLUT palLUT_table
[] = {
245 /* Index 0x00~0x03 */
246 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x2A}, {0x00, 0x2A, 0x00}, {0x00,
249 /* Index 0x04~0x07 */
250 {0x2A, 0x00, 0x00}, {0x2A, 0x00, 0x2A}, {0x2A, 0x15, 0x00}, {0x2A,
253 /* Index 0x08~0x0B */
254 {0x15, 0x15, 0x15}, {0x15, 0x15, 0x3F}, {0x15, 0x3F, 0x15}, {0x15,
257 /* Index 0x0C~0x0F */
258 {0x3F, 0x15, 0x15}, {0x3F, 0x15, 0x3F}, {0x3F, 0x3F, 0x15}, {0x3F,
261 /* Index 0x10~0x13 */
262 {0x00, 0x00, 0x00}, {0x05, 0x05, 0x05}, {0x08, 0x08, 0x08}, {0x0B,
265 /* Index 0x14~0x17 */
266 {0x0E, 0x0E, 0x0E}, {0x11, 0x11, 0x11}, {0x14, 0x14, 0x14}, {0x18,
269 /* Index 0x18~0x1B */
270 {0x1C, 0x1C, 0x1C}, {0x20, 0x20, 0x20}, {0x24, 0x24, 0x24}, {0x28,
273 /* Index 0x1C~0x1F */
274 {0x2D, 0x2D, 0x2D}, {0x32, 0x32, 0x32}, {0x38, 0x38, 0x38}, {0x3F,
277 /* Index 0x20~0x23 */
278 {0x00, 0x00, 0x3F}, {0x10, 0x00, 0x3F}, {0x1F, 0x00, 0x3F}, {0x2F,
281 /* Index 0x24~0x27 */
282 {0x3F, 0x00, 0x3F}, {0x3F, 0x00, 0x2F}, {0x3F, 0x00, 0x1F}, {0x3F,
285 /* Index 0x28~0x2B */
286 {0x3F, 0x00, 0x00}, {0x3F, 0x10, 0x00}, {0x3F, 0x1F, 0x00}, {0x3F,
289 /* Index 0x2C~0x2F */
290 {0x3F, 0x3F, 0x00}, {0x2F, 0x3F, 0x00}, {0x1F, 0x3F, 0x00}, {0x10,
293 /* Index 0x30~0x33 */
294 {0x00, 0x3F, 0x00}, {0x00, 0x3F, 0x10}, {0x00, 0x3F, 0x1F}, {0x00,
297 /* Index 0x34~0x37 */
298 {0x00, 0x3F, 0x3F}, {0x00, 0x2F, 0x3F}, {0x00, 0x1F, 0x3F}, {0x00,
301 /* Index 0x38~0x3B */
302 {0x1F, 0x1F, 0x3F}, {0x27, 0x1F, 0x3F}, {0x2F, 0x1F, 0x3F}, {0x37,
305 /* Index 0x3C~0x3F */
306 {0x3F, 0x1F, 0x3F}, {0x3F, 0x1F, 0x37}, {0x3F, 0x1F, 0x2F}, {0x3F,
309 /* Index 0x40~0x43 */
310 {0x3F, 0x1F, 0x1F}, {0x3F, 0x27, 0x1F}, {0x3F, 0x2F, 0x1F}, {0x3F,
313 /* Index 0x44~0x47 */
314 {0x3F, 0x3F, 0x1F}, {0x37, 0x3F, 0x1F}, {0x2F, 0x3F, 0x1F}, {0x27,
317 /* Index 0x48~0x4B */
318 {0x1F, 0x3F, 0x1F}, {0x1F, 0x3F, 0x27}, {0x1F, 0x3F, 0x2F}, {0x1F,
321 /* Index 0x4C~0x4F */
322 {0x1F, 0x3F, 0x3F}, {0x1F, 0x37, 0x3F}, {0x1F, 0x2F, 0x3F}, {0x1F,
325 /* Index 0x50~0x53 */
326 {0x2D, 0x2D, 0x3F}, {0x31, 0x2D, 0x3F}, {0x36, 0x2D, 0x3F}, {0x3A,
329 /* Index 0x54~0x57 */
330 {0x3F, 0x2D, 0x3F}, {0x3F, 0x2D, 0x3A}, {0x3F, 0x2D, 0x36}, {0x3F,
333 /* Index 0x58~0x5B */
334 {0x3F, 0x2D, 0x2D}, {0x3F, 0x31, 0x2D}, {0x3F, 0x36, 0x2D}, {0x3F,
337 /* Index 0x5C~0x5F */
338 {0x3F, 0x3F, 0x2D}, {0x3A, 0x3F, 0x2D}, {0x36, 0x3F, 0x2D}, {0x31,
341 /* Index 0x60~0x63 */
342 {0x2D, 0x3F, 0x2D}, {0x2D, 0x3F, 0x31}, {0x2D, 0x3F, 0x36}, {0x2D,
345 /* Index 0x64~0x67 */
346 {0x2D, 0x3F, 0x3F}, {0x2D, 0x3A, 0x3F}, {0x2D, 0x36, 0x3F}, {0x2D,
349 /* Index 0x68~0x6B */
350 {0x00, 0x00, 0x1C}, {0x07, 0x00, 0x1C}, {0x0E, 0x00, 0x1C}, {0x15,
353 /* Index 0x6C~0x6F */
354 {0x1C, 0x00, 0x1C}, {0x1C, 0x00, 0x15}, {0x1C, 0x00, 0x0E}, {0x1C,
357 /* Index 0x70~0x73 */
358 {0x1C, 0x00, 0x00}, {0x1C, 0x07, 0x00}, {0x1C, 0x0E, 0x00}, {0x1C,
361 /* Index 0x74~0x77 */
362 {0x1C, 0x1C, 0x00}, {0x15, 0x1C, 0x00}, {0x0E, 0x1C, 0x00}, {0x07,
365 /* Index 0x78~0x7B */
366 {0x00, 0x1C, 0x00}, {0x00, 0x1C, 0x07}, {0x00, 0x1C, 0x0E}, {0x00,
369 /* Index 0x7C~0x7F */
370 {0x00, 0x1C, 0x1C}, {0x00, 0x15, 0x1C}, {0x00, 0x0E, 0x1C}, {0x00,
373 /* Index 0x80~0x83 */
374 {0x0E, 0x0E, 0x1C}, {0x11, 0x0E, 0x1C}, {0x15, 0x0E, 0x1C}, {0x18,
377 /* Index 0x84~0x87 */
378 {0x1C, 0x0E, 0x1C}, {0x1C, 0x0E, 0x18}, {0x1C, 0x0E, 0x15}, {0x1C,
381 /* Index 0x88~0x8B */
382 {0x1C, 0x0E, 0x0E}, {0x1C, 0x11, 0x0E}, {0x1C, 0x15, 0x0E}, {0x1C,
385 /* Index 0x8C~0x8F */
386 {0x1C, 0x1C, 0x0E}, {0x18, 0x1C, 0x0E}, {0x15, 0x1C, 0x0E}, {0x11,
389 /* Index 0x90~0x93 */
390 {0x0E, 0x1C, 0x0E}, {0x0E, 0x1C, 0x11}, {0x0E, 0x1C, 0x15}, {0x0E,
393 /* Index 0x94~0x97 */
394 {0x0E, 0x1C, 0x1C}, {0x0E, 0x18, 0x1C}, {0x0E, 0x15, 0x1C}, {0x0E,
397 /* Index 0x98~0x9B */
398 {0x14, 0x14, 0x1C}, {0x16, 0x14, 0x1C}, {0x18, 0x14, 0x1C}, {0x1A,
401 /* Index 0x9C~0x9F */
402 {0x1C, 0x14, 0x1C}, {0x1C, 0x14, 0x1A}, {0x1C, 0x14, 0x18}, {0x1C,
405 /* Index 0xA0~0xA3 */
406 {0x1C, 0x14, 0x14}, {0x1C, 0x16, 0x14}, {0x1C, 0x18, 0x14}, {0x1C,
409 /* Index 0xA4~0xA7 */
410 {0x1C, 0x1C, 0x14}, {0x1A, 0x1C, 0x14}, {0x18, 0x1C, 0x14}, {0x16,
413 /* Index 0xA8~0xAB */
414 {0x14, 0x1C, 0x14}, {0x14, 0x1C, 0x16}, {0x14, 0x1C, 0x18}, {0x14,
417 /* Index 0xAC~0xAF */
418 {0x14, 0x1C, 0x1C}, {0x14, 0x1A, 0x1C}, {0x14, 0x18, 0x1C}, {0x14,
421 /* Index 0xB0~0xB3 */
422 {0x00, 0x00, 0x10}, {0x04, 0x00, 0x10}, {0x08, 0x00, 0x10}, {0x0C,
425 /* Index 0xB4~0xB7 */
426 {0x10, 0x00, 0x10}, {0x10, 0x00, 0x0C}, {0x10, 0x00, 0x08}, {0x10,
429 /* Index 0xB8~0xBB */
430 {0x10, 0x00, 0x00}, {0x10, 0x04, 0x00}, {0x10, 0x08, 0x00}, {0x10,
433 /* Index 0xBC~0xBF */
434 {0x10, 0x10, 0x00}, {0x0C, 0x10, 0x00}, {0x08, 0x10, 0x00}, {0x04,
437 /* Index 0xC0~0xC3 */
438 {0x00, 0x10, 0x00}, {0x00, 0x10, 0x04}, {0x00, 0x10, 0x08}, {0x00,
441 /* Index 0xC4~0xC7 */
442 {0x00, 0x10, 0x10}, {0x00, 0x0C, 0x10}, {0x00, 0x08, 0x10}, {0x00,
445 /* Index 0xC8~0xCB */
446 {0x08, 0x08, 0x10}, {0x0A, 0x08, 0x10}, {0x0C, 0x08, 0x10}, {0x0E,
449 /* Index 0xCC~0xCF */
450 {0x10, 0x08, 0x10}, {0x10, 0x08, 0x0E}, {0x10, 0x08, 0x0C}, {0x10,
453 /* Index 0xD0~0xD3 */
454 {0x10, 0x08, 0x08}, {0x10, 0x0A, 0x08}, {0x10, 0x0C, 0x08}, {0x10,
457 /* Index 0xD4~0xD7 */
458 {0x10, 0x10, 0x08}, {0x0E, 0x10, 0x08}, {0x0C, 0x10, 0x08}, {0x0A,
461 /* Index 0xD8~0xDB */
462 {0x08, 0x10, 0x08}, {0x08, 0x10, 0x0A}, {0x08, 0x10, 0x0C}, {0x08,
465 /* Index 0xDC~0xDF */
466 {0x08, 0x10, 0x10}, {0x08, 0x0E, 0x10}, {0x08, 0x0C, 0x10}, {0x08,
469 /* Index 0xE0~0xE3 */
470 {0x0B, 0x0B, 0x10}, {0x0C, 0x0B, 0x10}, {0x0D, 0x0B, 0x10}, {0x0F,
473 /* Index 0xE4~0xE7 */
474 {0x10, 0x0B, 0x10}, {0x10, 0x0B, 0x0F}, {0x10, 0x0B, 0x0D}, {0x10,
477 /* Index 0xE8~0xEB */
478 {0x10, 0x0B, 0x0B}, {0x10, 0x0C, 0x0B}, {0x10, 0x0D, 0x0B}, {0x10,
481 /* Index 0xEC~0xEF */
482 {0x10, 0x10, 0x0B}, {0x0F, 0x10, 0x0B}, {0x0D, 0x10, 0x0B}, {0x0C,
485 /* Index 0xF0~0xF3 */
486 {0x0B, 0x10, 0x0B}, {0x0B, 0x10, 0x0C}, {0x0B, 0x10, 0x0D}, {0x0B,
489 /* Index 0xF4~0xF7 */
490 {0x0B, 0x10, 0x10}, {0x0B, 0x0F, 0x10}, {0x0B, 0x0D, 0x10}, {0x0B,
493 /* Index 0xF8~0xFB */
494 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
497 /* Index 0xFC~0xFF */
498 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
503 static void set_crt_output_path(int set_iga
);
504 static void dvi_patch_skew_dvp0(void);
505 static void dvi_patch_skew_dvp1(void);
506 static void dvi_patch_skew_dvp_low(void);
507 static void set_dvi_output_path(int set_iga
, int output_interface
);
508 static void set_lcd_output_path(int set_iga
, int output_interface
);
509 static int search_mode_setting(int ModeInfoIndex
);
510 static void load_fix_bit_crtc_reg(void);
511 static void init_gfx_chip_info(void);
512 static void init_tmds_chip_info(void);
513 static void init_lvds_chip_info(void);
514 static void device_screen_off(void);
515 static void device_screen_on(void);
516 static void set_display_channel(void);
517 static void device_off(void);
518 static void device_on(void);
519 static void enable_second_display_channel(void);
520 static void disable_second_display_channel(void);
521 static int get_fb_size_from_pci(void);
523 void viafb_write_reg(u8 index
, u16 io_port
, u8 data
)
525 outb(index
, io_port
);
526 outb(data
, io_port
+ 1);
527 /*DEBUG_MSG(KERN_INFO "\nIndex=%2d Value=%2d", index, data); */
529 u8
viafb_read_reg(int io_port
, u8 index
)
531 outb(index
, io_port
);
532 return inb(io_port
+ 1);
535 void viafb_lock_crt(void)
537 viafb_write_reg_mask(CR11
, VIACR
, BIT7
, BIT7
);
540 void viafb_unlock_crt(void)
542 viafb_write_reg_mask(CR11
, VIACR
, 0, BIT7
);
543 viafb_write_reg_mask(CR47
, VIACR
, 0, BIT0
);
546 void viafb_write_reg_mask(u8 index
, int io_port
, u8 data
, u8 mask
)
550 outb(index
, io_port
);
551 tmp
= inb(io_port
+ 1);
552 outb((data
& mask
) | (tmp
& (~mask
)), io_port
+ 1);
553 /*DEBUG_MSG(KERN_INFO "\nIndex=%2d Value=%2d", index, tmp); */
556 void write_dac_reg(u8 index
, u8 r
, u8 g
, u8 b
)
558 outb(index
, LUT_INDEX_WRITE
);
564 /*Set IGA path for each device*/
565 void viafb_set_iga_path(void)
568 if (viafb_SAMM_ON
== 1) {
570 if (viafb_primary_dev
== CRT_Device
)
571 viaparinfo
->crt_setting_info
->iga_path
= IGA1
;
573 viaparinfo
->crt_setting_info
->iga_path
= IGA2
;
577 if (viafb_primary_dev
== DVI_Device
)
578 viaparinfo
->tmds_setting_info
->iga_path
= IGA1
;
580 viaparinfo
->tmds_setting_info
->iga_path
= IGA2
;
584 if (viafb_primary_dev
== LCD_Device
) {
586 (viaparinfo
->chip_info
->gfx_chip_name
==
589 lvds_setting_info
->iga_path
= IGA2
;
591 crt_setting_info
->iga_path
= IGA1
;
593 tmds_setting_info
->iga_path
= IGA1
;
596 lvds_setting_info
->iga_path
= IGA1
;
598 viaparinfo
->lvds_setting_info
->iga_path
= IGA2
;
602 if (LCD2_Device
== viafb_primary_dev
)
603 viaparinfo
->lvds_setting_info2
->iga_path
= IGA1
;
605 viaparinfo
->lvds_setting_info2
->iga_path
= IGA2
;
610 if (viafb_CRT_ON
&& viafb_LCD_ON
) {
611 viaparinfo
->crt_setting_info
->iga_path
= IGA1
;
612 viaparinfo
->lvds_setting_info
->iga_path
= IGA2
;
613 } else if (viafb_CRT_ON
&& viafb_DVI_ON
) {
614 viaparinfo
->crt_setting_info
->iga_path
= IGA1
;
615 viaparinfo
->tmds_setting_info
->iga_path
= IGA2
;
616 } else if (viafb_LCD_ON
&& viafb_DVI_ON
) {
617 viaparinfo
->tmds_setting_info
->iga_path
= IGA1
;
618 viaparinfo
->lvds_setting_info
->iga_path
= IGA2
;
619 } else if (viafb_LCD_ON
&& viafb_LCD2_ON
) {
620 viaparinfo
->lvds_setting_info
->iga_path
= IGA2
;
621 viaparinfo
->lvds_setting_info2
->iga_path
= IGA2
;
622 } else if (viafb_CRT_ON
) {
623 viaparinfo
->crt_setting_info
->iga_path
= IGA1
;
624 } else if (viafb_LCD_ON
) {
625 viaparinfo
->lvds_setting_info
->iga_path
= IGA2
;
626 } else if (viafb_DVI_ON
) {
627 viaparinfo
->tmds_setting_info
->iga_path
= IGA1
;
632 void viafb_set_start_addr(void)
634 unsigned long offset
= 0, tmp
= 0, size
= 0;
635 unsigned long length
;
637 DEBUG_MSG(KERN_INFO
"viafb_set_start_addr!\n");
639 /* update starting address of IGA1 */
640 viafb_write_reg(CR0C
, VIACR
, 0x00); /*initial starting address */
641 viafb_write_reg(CR0D
, VIACR
, 0x00);
642 viafb_write_reg(CR34
, VIACR
, 0x00);
643 viafb_write_reg_mask(CR48
, VIACR
, 0x00, 0x1F);
646 viaparinfo
->iga_path
= IGA1
;
647 viaparinfo1
->iga_path
= IGA2
;
650 if (viafb_SAMM_ON
== 1) {
651 if (!viafb_dual_fb
) {
652 if (viafb_second_size
)
653 size
= viafb_second_size
* 1024 * 1024;
655 size
= 8 * 1024 * 1024;
658 size
= viaparinfo1
->memsize
;
660 offset
= viafb_second_offset
;
662 "viafb_second_size=%lx, second start_adddress=%lx\n",
665 if (viafb_SAMM_ON
== 1) {
666 offset
= offset
>> 3;
668 tmp
= viafb_read_reg(VIACR
, 0x62) & 0x01;
669 tmp
|= (offset
& 0x7F) << 1;
670 viafb_write_reg(CR62
, VIACR
, tmp
);
671 viafb_write_reg(CR63
, VIACR
, ((offset
& 0x7F80) >> 7));
672 viafb_write_reg(CR64
, VIACR
, ((offset
& 0x7F8000) >> 15));
673 viafb_write_reg(CRA3
, VIACR
, ((offset
& 0x3800000) >> 23));
675 /* update starting address */
676 viafb_write_reg(CR62
, VIACR
, 0x00);
677 viafb_write_reg(CR63
, VIACR
, 0x00);
678 viafb_write_reg(CR64
, VIACR
, 0x00);
679 viafb_write_reg(CRA3
, VIACR
, 0x00);
682 if (viafb_SAMM_ON
== 1) {
685 length
= size
- viaparinfo
->fbmem_used
;
687 length
= size
- viaparinfo1
->fbmem_used
;
690 offset
= (unsigned long)(void *)viafb_FB_MM
+
692 memset((void *)offset
, 0, length
);
698 void viafb_set_output_path(int device
, int set_iga
, int output_interface
)
702 set_crt_output_path(set_iga
);
705 set_dvi_output_path(set_iga
, output_interface
);
708 set_lcd_output_path(set_iga
, output_interface
);
713 static void set_crt_output_path(int set_iga
)
715 viafb_write_reg_mask(CR36
, VIACR
, 0x00, BIT4
+ BIT5
);
719 viafb_write_reg_mask(SR16
, VIASR
, 0x00, BIT6
);
723 viafb_write_reg_mask(CR6A
, VIACR
, 0xC0, BIT6
+ BIT7
);
724 viafb_write_reg_mask(SR16
, VIASR
, 0x40, BIT6
);
725 if (set_iga
== IGA1_IGA2
)
726 viafb_write_reg_mask(CR6B
, VIACR
, 0x08, BIT3
);
731 static void dvi_patch_skew_dvp0(void)
733 /* Reset data driving first: */
734 viafb_write_reg_mask(SR1B
, VIASR
, 0, BIT1
);
735 viafb_write_reg_mask(SR2A
, VIASR
, 0, BIT4
);
737 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
738 case UNICHROME_P4M890
:
740 if ((viaparinfo
->tmds_setting_info
->h_active
== 1600) &&
741 (viaparinfo
->tmds_setting_info
->v_active
==
743 viafb_write_reg_mask(CR96
, VIACR
, 0x03,
746 viafb_write_reg_mask(CR96
, VIACR
, 0x07,
751 case UNICHROME_P4M900
:
753 viafb_write_reg_mask(CR96
, VIACR
, 0x07,
754 BIT0
+ BIT1
+ BIT2
+ BIT3
);
755 viafb_write_reg_mask(SR1B
, VIASR
, 0x02, BIT1
);
756 viafb_write_reg_mask(SR2A
, VIASR
, 0x10, BIT4
);
767 static void dvi_patch_skew_dvp1(void)
769 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
770 case UNICHROME_CX700
:
782 static void dvi_patch_skew_dvp_low(void)
784 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
785 case UNICHROME_K8M890
:
787 viafb_write_reg_mask(CR99
, VIACR
, 0x03, BIT0
+ BIT1
);
791 case UNICHROME_P4M900
:
793 viafb_write_reg_mask(CR99
, VIACR
, 0x08,
794 BIT0
+ BIT1
+ BIT2
+ BIT3
);
798 case UNICHROME_P4M890
:
800 viafb_write_reg_mask(CR99
, VIACR
, 0x0F,
801 BIT0
+ BIT1
+ BIT2
+ BIT3
);
812 static void set_dvi_output_path(int set_iga
, int output_interface
)
814 switch (output_interface
) {
816 viafb_write_reg_mask(CR6B
, VIACR
, 0x01, BIT0
);
818 if (set_iga
== IGA1
) {
819 viafb_write_reg_mask(CR96
, VIACR
, 0x00, BIT4
);
820 viafb_write_reg_mask(CR6C
, VIACR
, 0x21, BIT0
+
823 viafb_write_reg_mask(CR96
, VIACR
, 0x10, BIT4
);
824 viafb_write_reg_mask(CR6C
, VIACR
, 0xA1, BIT0
+
828 viafb_write_reg_mask(SR1E
, VIASR
, 0xC0, BIT7
+ BIT6
);
830 dvi_patch_skew_dvp0();
834 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
836 viafb_write_reg_mask(CR93
, VIACR
, 0x21,
839 viafb_write_reg_mask(CR93
, VIACR
, 0xA1,
843 viafb_write_reg_mask(CR9B
, VIACR
, 0x00, BIT4
);
845 viafb_write_reg_mask(CR9B
, VIACR
, 0x10, BIT4
);
848 viafb_write_reg_mask(SR1E
, VIASR
, 0x30, BIT4
+ BIT5
);
849 dvi_patch_skew_dvp1();
851 case INTERFACE_DFP_HIGH
:
852 if (viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_CLE266
) {
853 if (set_iga
== IGA1
) {
854 viafb_write_reg_mask(CR96
, VIACR
, 0x00, BIT4
);
855 viafb_write_reg_mask(CR97
, VIACR
, 0x03,
858 viafb_write_reg_mask(CR96
, VIACR
, 0x10, BIT4
);
859 viafb_write_reg_mask(CR97
, VIACR
, 0x13,
863 viafb_write_reg_mask(SR2A
, VIASR
, 0x0C, BIT2
+ BIT3
);
866 case INTERFACE_DFP_LOW
:
867 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)
870 if (set_iga
== IGA1
) {
871 viafb_write_reg_mask(CR99
, VIACR
, 0x00, BIT4
);
872 viafb_write_reg_mask(CR9B
, VIACR
, 0x00, BIT4
);
874 viafb_write_reg_mask(CR99
, VIACR
, 0x10, BIT4
);
875 viafb_write_reg_mask(CR9B
, VIACR
, 0x10, BIT4
);
878 viafb_write_reg_mask(SR2A
, VIASR
, 0x03, BIT0
+ BIT1
);
879 dvi_patch_skew_dvp_low();
884 viafb_write_reg_mask(CR99
, VIACR
, 0x00, BIT4
);
886 viafb_write_reg_mask(CR99
, VIACR
, 0x10, BIT4
);
890 if (set_iga
== IGA2
) {
891 enable_second_display_channel();
892 /* Disable LCD Scaling */
893 viafb_write_reg_mask(CR79
, VIACR
, 0x00, BIT0
);
897 static void set_lcd_output_path(int set_iga
, int output_interface
)
900 "set_lcd_output_path, iga:%d,out_interface:%d\n",
901 set_iga
, output_interface
);
904 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, BIT3
);
905 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
907 disable_second_display_channel();
911 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, BIT3
);
912 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
914 enable_second_display_channel();
918 viafb_write_reg_mask(CR6B
, VIACR
, 0x08, BIT3
);
919 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
921 disable_second_display_channel();
925 switch (output_interface
) {
927 if (set_iga
== IGA1
) {
928 viafb_write_reg_mask(CR96
, VIACR
, 0x00, BIT4
);
930 viafb_write_reg(CR91
, VIACR
, 0x00);
931 viafb_write_reg_mask(CR96
, VIACR
, 0x10, BIT4
);
937 viafb_write_reg_mask(CR9B
, VIACR
, 0x00, BIT4
);
939 viafb_write_reg(CR91
, VIACR
, 0x00);
940 viafb_write_reg_mask(CR9B
, VIACR
, 0x10, BIT4
);
944 case INTERFACE_DFP_HIGH
:
946 viafb_write_reg_mask(CR97
, VIACR
, 0x00, BIT4
);
948 viafb_write_reg(CR91
, VIACR
, 0x00);
949 viafb_write_reg_mask(CR97
, VIACR
, 0x10, BIT4
);
950 viafb_write_reg_mask(CR96
, VIACR
, 0x10, BIT4
);
954 case INTERFACE_DFP_LOW
:
956 viafb_write_reg_mask(CR99
, VIACR
, 0x00, BIT4
);
958 viafb_write_reg(CR91
, VIACR
, 0x00);
959 viafb_write_reg_mask(CR99
, VIACR
, 0x10, BIT4
);
960 viafb_write_reg_mask(CR9B
, VIACR
, 0x10, BIT4
);
966 if ((UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
)
967 || (UNICHROME_P4M890
==
968 viaparinfo
->chip_info
->gfx_chip_name
))
969 viafb_write_reg_mask(CR97
, VIACR
, 0x84,
970 BIT7
+ BIT2
+ BIT1
+ BIT0
);
971 if (set_iga
== IGA1
) {
972 viafb_write_reg_mask(CR97
, VIACR
, 0x00, BIT4
);
973 viafb_write_reg_mask(CR99
, VIACR
, 0x00, BIT4
);
975 viafb_write_reg(CR91
, VIACR
, 0x00);
976 viafb_write_reg_mask(CR97
, VIACR
, 0x10, BIT4
);
977 viafb_write_reg_mask(CR99
, VIACR
, 0x10, BIT4
);
981 case INTERFACE_LVDS0
:
982 case INTERFACE_LVDS0LVDS1
:
984 viafb_write_reg_mask(CR99
, VIACR
, 0x00, BIT4
);
986 viafb_write_reg_mask(CR99
, VIACR
, 0x10, BIT4
);
990 case INTERFACE_LVDS1
:
992 viafb_write_reg_mask(CR97
, VIACR
, 0x00, BIT4
);
994 viafb_write_reg_mask(CR97
, VIACR
, 0x10, BIT4
);
999 /* Search Mode Index */
1000 static int search_mode_setting(int ModeInfoIndex
)
1004 while ((i
< NUM_TOTAL_MODETABLE
) &&
1005 (ModeInfoIndex
!= CLE266Modes
[i
].ModeIndex
))
1007 if (i
>= NUM_TOTAL_MODETABLE
)
1013 struct VideoModeTable
*viafb_get_modetbl_pointer(int Index
)
1015 struct VideoModeTable
*TmpTbl
= NULL
;
1016 TmpTbl
= &CLE266Modes
[search_mode_setting(Index
)];
1020 struct VideoModeTable
*viafb_get_cea_mode_tbl_pointer(int Index
)
1022 struct VideoModeTable
*TmpTbl
= NULL
;
1024 while ((i
< NUM_TOTAL_CEA_MODES
) &&
1025 (Index
!= CEA_HDMI_Modes
[i
].ModeIndex
))
1027 if ((i
< NUM_TOTAL_CEA_MODES
))
1028 TmpTbl
= &CEA_HDMI_Modes
[i
];
1030 /*Still use general timing if don't find CEA timing */
1032 while ((i
< NUM_TOTAL_MODETABLE
) &&
1033 (Index
!= CLE266Modes
[i
].ModeIndex
))
1035 if (i
>= NUM_TOTAL_MODETABLE
)
1037 TmpTbl
= &CLE266Modes
[i
];
1042 static void load_fix_bit_crtc_reg(void)
1044 /* always set to 1 */
1045 viafb_write_reg_mask(CR03
, VIACR
, 0x80, BIT7
);
1046 /* line compare should set all bits = 1 (extend modes) */
1047 viafb_write_reg(CR18
, VIACR
, 0xff);
1048 /* line compare should set all bits = 1 (extend modes) */
1049 viafb_write_reg_mask(CR07
, VIACR
, 0x10, BIT4
);
1050 /* line compare should set all bits = 1 (extend modes) */
1051 viafb_write_reg_mask(CR09
, VIACR
, 0x40, BIT6
);
1052 /* line compare should set all bits = 1 (extend modes) */
1053 viafb_write_reg_mask(CR35
, VIACR
, 0x10, BIT4
);
1054 /* line compare should set all bits = 1 (extend modes) */
1055 viafb_write_reg_mask(CR33
, VIACR
, 0x06, BIT0
+ BIT1
+ BIT2
);
1056 /*viafb_write_reg_mask(CR32, VIACR, 0x01, BIT0); */
1057 /* extend mode always set to e3h */
1058 viafb_write_reg(CR17
, VIACR
, 0xe3);
1059 /* extend mode always set to 0h */
1060 viafb_write_reg(CR08
, VIACR
, 0x00);
1061 /* extend mode always set to 0h */
1062 viafb_write_reg(CR14
, VIACR
, 0x00);
1064 /* If K8M800, enable Prefetch Mode. */
1065 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
)
1066 || (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K8M890
))
1067 viafb_write_reg_mask(CR33
, VIACR
, 0x08, BIT3
);
1068 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)
1069 && (viaparinfo
->chip_info
->gfx_chip_revision
== CLE266_REVISION_AX
))
1070 viafb_write_reg_mask(SR1A
, VIASR
, 0x02, BIT1
);
1074 void viafb_load_reg(int timing_value
, int viafb_load_reg_num
,
1075 struct io_register
*reg
,
1083 int start_index
, end_index
, cr_index
;
1086 for (i
= 0; i
< viafb_load_reg_num
; i
++) {
1089 start_index
= reg
[i
].start_bit
;
1090 end_index
= reg
[i
].end_bit
;
1091 cr_index
= reg
[i
].io_addr
;
1093 shift_next_reg
= bit_num
;
1094 for (j
= start_index
; j
<= end_index
; j
++) {
1095 /*if (bit_num==8) timing_value = timing_value >>8; */
1096 reg_mask
= reg_mask
| (BIT0
<< j
);
1097 get_bit
= (timing_value
& (BIT0
<< bit_num
));
1099 data
| ((get_bit
>> shift_next_reg
) << start_index
);
1102 if (io_type
== VIACR
)
1103 viafb_write_reg_mask(cr_index
, VIACR
, data
, reg_mask
);
1105 viafb_write_reg_mask(cr_index
, VIASR
, data
, reg_mask
);
1110 /* Write Registers */
1111 void viafb_write_regx(struct io_reg RegTable
[], int ItemNum
)
1114 unsigned char RegTemp
;
1116 /*DEBUG_MSG(KERN_INFO "Table Size : %x!!\n",ItemNum ); */
1118 for (i
= 0; i
< ItemNum
; i
++) {
1119 outb(RegTable
[i
].index
, RegTable
[i
].port
);
1120 RegTemp
= inb(RegTable
[i
].port
+ 1);
1121 RegTemp
= (RegTemp
& (~RegTable
[i
].mask
)) | RegTable
[i
].value
;
1122 outb(RegTemp
, RegTable
[i
].port
+ 1);
1126 void viafb_load_offset_reg(int h_addr
, int bpp_byte
, int set_iga
)
1129 int viafb_load_reg_num
;
1130 struct io_register
*reg
;
1135 reg_value
= IGA1_OFFSET_FORMULA(h_addr
, bpp_byte
);
1136 viafb_load_reg_num
= offset_reg
.iga1_offset_reg
.reg_num
;
1137 reg
= offset_reg
.iga1_offset_reg
.reg
;
1138 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1139 if (set_iga
== IGA1
)
1142 reg_value
= IGA2_OFFSET_FORMULA(h_addr
, bpp_byte
);
1143 viafb_load_reg_num
= offset_reg
.iga2_offset_reg
.reg_num
;
1144 reg
= offset_reg
.iga2_offset_reg
.reg
;
1145 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1150 void viafb_load_fetch_count_reg(int h_addr
, int bpp_byte
, int set_iga
)
1153 int viafb_load_reg_num
;
1154 struct io_register
*reg
= NULL
;
1159 reg_value
= IGA1_FETCH_COUNT_FORMULA(h_addr
, bpp_byte
);
1160 viafb_load_reg_num
= fetch_count_reg
.
1161 iga1_fetch_count_reg
.reg_num
;
1162 reg
= fetch_count_reg
.iga1_fetch_count_reg
.reg
;
1163 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIASR
);
1164 if (set_iga
== IGA1
)
1167 reg_value
= IGA2_FETCH_COUNT_FORMULA(h_addr
, bpp_byte
);
1168 viafb_load_reg_num
= fetch_count_reg
.
1169 iga2_fetch_count_reg
.reg_num
;
1170 reg
= fetch_count_reg
.iga2_fetch_count_reg
.reg
;
1171 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1177 void viafb_load_FIFO_reg(int set_iga
, int hor_active
, int ver_active
)
1180 int viafb_load_reg_num
;
1181 struct io_register
*reg
= NULL
;
1182 int iga1_fifo_max_depth
= 0, iga1_fifo_threshold
=
1183 0, iga1_fifo_high_threshold
= 0, iga1_display_queue_expire_num
= 0;
1184 int iga2_fifo_max_depth
= 0, iga2_fifo_threshold
=
1185 0, iga2_fifo_high_threshold
= 0, iga2_display_queue_expire_num
= 0;
1187 if (set_iga
== IGA1
) {
1188 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
) {
1189 iga1_fifo_max_depth
= K800_IGA1_FIFO_MAX_DEPTH
;
1190 iga1_fifo_threshold
= K800_IGA1_FIFO_THRESHOLD
;
1191 iga1_fifo_high_threshold
=
1192 K800_IGA1_FIFO_HIGH_THRESHOLD
;
1193 /* If resolution > 1280x1024, expire length = 64, else
1194 expire length = 128 */
1195 if ((hor_active
> 1280) && (ver_active
> 1024))
1196 iga1_display_queue_expire_num
= 16;
1198 iga1_display_queue_expire_num
=
1199 K800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1203 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_PM800
) {
1204 iga1_fifo_max_depth
= P880_IGA1_FIFO_MAX_DEPTH
;
1205 iga1_fifo_threshold
= P880_IGA1_FIFO_THRESHOLD
;
1206 iga1_fifo_high_threshold
=
1207 P880_IGA1_FIFO_HIGH_THRESHOLD
;
1208 iga1_display_queue_expire_num
=
1209 P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1211 /* If resolution > 1280x1024, expire length = 64, else
1212 expire length = 128 */
1213 if ((hor_active
> 1280) && (ver_active
> 1024))
1214 iga1_display_queue_expire_num
= 16;
1216 iga1_display_queue_expire_num
=
1217 P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1220 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CN700
) {
1221 iga1_fifo_max_depth
= CN700_IGA1_FIFO_MAX_DEPTH
;
1222 iga1_fifo_threshold
= CN700_IGA1_FIFO_THRESHOLD
;
1223 iga1_fifo_high_threshold
=
1224 CN700_IGA1_FIFO_HIGH_THRESHOLD
;
1226 /* If resolution > 1280x1024, expire length = 64,
1227 else expire length = 128 */
1228 if ((hor_active
> 1280) && (ver_active
> 1024))
1229 iga1_display_queue_expire_num
= 16;
1231 iga1_display_queue_expire_num
=
1232 CN700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1235 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
1236 iga1_fifo_max_depth
= CX700_IGA1_FIFO_MAX_DEPTH
;
1237 iga1_fifo_threshold
= CX700_IGA1_FIFO_THRESHOLD
;
1238 iga1_fifo_high_threshold
=
1239 CX700_IGA1_FIFO_HIGH_THRESHOLD
;
1240 iga1_display_queue_expire_num
=
1241 CX700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1244 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K8M890
) {
1245 iga1_fifo_max_depth
= K8M890_IGA1_FIFO_MAX_DEPTH
;
1246 iga1_fifo_threshold
= K8M890_IGA1_FIFO_THRESHOLD
;
1247 iga1_fifo_high_threshold
=
1248 K8M890_IGA1_FIFO_HIGH_THRESHOLD
;
1249 iga1_display_queue_expire_num
=
1250 K8M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1253 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_P4M890
) {
1254 iga1_fifo_max_depth
= P4M890_IGA1_FIFO_MAX_DEPTH
;
1255 iga1_fifo_threshold
= P4M890_IGA1_FIFO_THRESHOLD
;
1256 iga1_fifo_high_threshold
=
1257 P4M890_IGA1_FIFO_HIGH_THRESHOLD
;
1258 iga1_display_queue_expire_num
=
1259 P4M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1262 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_P4M900
) {
1263 iga1_fifo_max_depth
= P4M900_IGA1_FIFO_MAX_DEPTH
;
1264 iga1_fifo_threshold
= P4M900_IGA1_FIFO_THRESHOLD
;
1265 iga1_fifo_high_threshold
=
1266 P4M900_IGA1_FIFO_HIGH_THRESHOLD
;
1267 iga1_display_queue_expire_num
=
1268 P4M900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1271 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_VX800
) {
1272 iga1_fifo_max_depth
= VX800_IGA1_FIFO_MAX_DEPTH
;
1273 iga1_fifo_threshold
= VX800_IGA1_FIFO_THRESHOLD
;
1274 iga1_fifo_high_threshold
=
1275 VX800_IGA1_FIFO_HIGH_THRESHOLD
;
1276 iga1_display_queue_expire_num
=
1277 VX800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1280 /* Set Display FIFO Depath Select */
1281 reg_value
= IGA1_FIFO_DEPTH_SELECT_FORMULA(iga1_fifo_max_depth
);
1282 viafb_load_reg_num
=
1283 display_fifo_depth_reg
.iga1_fifo_depth_select_reg
.reg_num
;
1284 reg
= display_fifo_depth_reg
.iga1_fifo_depth_select_reg
.reg
;
1285 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIASR
);
1287 /* Set Display FIFO Threshold Select */
1288 reg_value
= IGA1_FIFO_THRESHOLD_FORMULA(iga1_fifo_threshold
);
1289 viafb_load_reg_num
=
1290 fifo_threshold_select_reg
.
1291 iga1_fifo_threshold_select_reg
.reg_num
;
1293 fifo_threshold_select_reg
.
1294 iga1_fifo_threshold_select_reg
.reg
;
1295 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIASR
);
1297 /* Set FIFO High Threshold Select */
1299 IGA1_FIFO_HIGH_THRESHOLD_FORMULA(iga1_fifo_high_threshold
);
1300 viafb_load_reg_num
=
1301 fifo_high_threshold_select_reg
.
1302 iga1_fifo_high_threshold_select_reg
.reg_num
;
1304 fifo_high_threshold_select_reg
.
1305 iga1_fifo_high_threshold_select_reg
.reg
;
1306 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIASR
);
1308 /* Set Display Queue Expire Num */
1310 IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
1311 (iga1_display_queue_expire_num
);
1312 viafb_load_reg_num
=
1313 display_queue_expire_num_reg
.
1314 iga1_display_queue_expire_num_reg
.reg_num
;
1316 display_queue_expire_num_reg
.
1317 iga1_display_queue_expire_num_reg
.reg
;
1318 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIASR
);
1321 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
) {
1322 iga2_fifo_max_depth
= K800_IGA2_FIFO_MAX_DEPTH
;
1323 iga2_fifo_threshold
= K800_IGA2_FIFO_THRESHOLD
;
1324 iga2_fifo_high_threshold
=
1325 K800_IGA2_FIFO_HIGH_THRESHOLD
;
1327 /* If resolution > 1280x1024, expire length = 64,
1328 else expire length = 128 */
1329 if ((hor_active
> 1280) && (ver_active
> 1024))
1330 iga2_display_queue_expire_num
= 16;
1332 iga2_display_queue_expire_num
=
1333 K800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1336 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_PM800
) {
1337 iga2_fifo_max_depth
= P880_IGA2_FIFO_MAX_DEPTH
;
1338 iga2_fifo_threshold
= P880_IGA2_FIFO_THRESHOLD
;
1339 iga2_fifo_high_threshold
=
1340 P880_IGA2_FIFO_HIGH_THRESHOLD
;
1342 /* If resolution > 1280x1024, expire length = 64,
1343 else expire length = 128 */
1344 if ((hor_active
> 1280) && (ver_active
> 1024))
1345 iga2_display_queue_expire_num
= 16;
1347 iga2_display_queue_expire_num
=
1348 P880_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1351 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CN700
) {
1352 iga2_fifo_max_depth
= CN700_IGA2_FIFO_MAX_DEPTH
;
1353 iga2_fifo_threshold
= CN700_IGA2_FIFO_THRESHOLD
;
1354 iga2_fifo_high_threshold
=
1355 CN700_IGA2_FIFO_HIGH_THRESHOLD
;
1357 /* If resolution > 1280x1024, expire length = 64,
1358 else expire length = 128 */
1359 if ((hor_active
> 1280) && (ver_active
> 1024))
1360 iga2_display_queue_expire_num
= 16;
1362 iga2_display_queue_expire_num
=
1363 CN700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1366 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
1367 iga2_fifo_max_depth
= CX700_IGA2_FIFO_MAX_DEPTH
;
1368 iga2_fifo_threshold
= CX700_IGA2_FIFO_THRESHOLD
;
1369 iga2_fifo_high_threshold
=
1370 CX700_IGA2_FIFO_HIGH_THRESHOLD
;
1371 iga2_display_queue_expire_num
=
1372 CX700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1375 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K8M890
) {
1376 iga2_fifo_max_depth
= K8M890_IGA2_FIFO_MAX_DEPTH
;
1377 iga2_fifo_threshold
= K8M890_IGA2_FIFO_THRESHOLD
;
1378 iga2_fifo_high_threshold
=
1379 K8M890_IGA2_FIFO_HIGH_THRESHOLD
;
1380 iga2_display_queue_expire_num
=
1381 K8M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1384 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_P4M890
) {
1385 iga2_fifo_max_depth
= P4M890_IGA2_FIFO_MAX_DEPTH
;
1386 iga2_fifo_threshold
= P4M890_IGA2_FIFO_THRESHOLD
;
1387 iga2_fifo_high_threshold
=
1388 P4M890_IGA2_FIFO_HIGH_THRESHOLD
;
1389 iga2_display_queue_expire_num
=
1390 P4M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1393 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_P4M900
) {
1394 iga2_fifo_max_depth
= P4M900_IGA2_FIFO_MAX_DEPTH
;
1395 iga2_fifo_threshold
= P4M900_IGA2_FIFO_THRESHOLD
;
1396 iga2_fifo_high_threshold
=
1397 P4M900_IGA2_FIFO_HIGH_THRESHOLD
;
1398 iga2_display_queue_expire_num
=
1399 P4M900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1402 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_VX800
) {
1403 iga2_fifo_max_depth
= VX800_IGA2_FIFO_MAX_DEPTH
;
1404 iga2_fifo_threshold
= VX800_IGA2_FIFO_THRESHOLD
;
1405 iga2_fifo_high_threshold
=
1406 VX800_IGA2_FIFO_HIGH_THRESHOLD
;
1407 iga2_display_queue_expire_num
=
1408 VX800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM
;
1411 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
) {
1412 /* Set Display FIFO Depath Select */
1414 IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth
)
1416 /* Patch LCD in IGA2 case */
1417 viafb_load_reg_num
=
1418 display_fifo_depth_reg
.
1419 iga2_fifo_depth_select_reg
.reg_num
;
1421 display_fifo_depth_reg
.
1422 iga2_fifo_depth_select_reg
.reg
;
1423 viafb_load_reg(reg_value
,
1424 viafb_load_reg_num
, reg
, VIACR
);
1427 /* Set Display FIFO Depath Select */
1429 IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth
);
1430 viafb_load_reg_num
=
1431 display_fifo_depth_reg
.
1432 iga2_fifo_depth_select_reg
.reg_num
;
1434 display_fifo_depth_reg
.
1435 iga2_fifo_depth_select_reg
.reg
;
1436 viafb_load_reg(reg_value
,
1437 viafb_load_reg_num
, reg
, VIACR
);
1440 /* Set Display FIFO Threshold Select */
1441 reg_value
= IGA2_FIFO_THRESHOLD_FORMULA(iga2_fifo_threshold
);
1442 viafb_load_reg_num
=
1443 fifo_threshold_select_reg
.
1444 iga2_fifo_threshold_select_reg
.reg_num
;
1446 fifo_threshold_select_reg
.
1447 iga2_fifo_threshold_select_reg
.reg
;
1448 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1450 /* Set FIFO High Threshold Select */
1452 IGA2_FIFO_HIGH_THRESHOLD_FORMULA(iga2_fifo_high_threshold
);
1453 viafb_load_reg_num
=
1454 fifo_high_threshold_select_reg
.
1455 iga2_fifo_high_threshold_select_reg
.reg_num
;
1457 fifo_high_threshold_select_reg
.
1458 iga2_fifo_high_threshold_select_reg
.reg
;
1459 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1461 /* Set Display Queue Expire Num */
1463 IGA2_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
1464 (iga2_display_queue_expire_num
);
1465 viafb_load_reg_num
=
1466 display_queue_expire_num_reg
.
1467 iga2_display_queue_expire_num_reg
.reg_num
;
1469 display_queue_expire_num_reg
.
1470 iga2_display_queue_expire_num_reg
.reg
;
1471 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1477 u32
viafb_get_clk_value(int clk
)
1481 for (i
= 0; i
< NUM_TOTAL_PLL_TABLE
; i
++) {
1482 if (clk
== pll_value
[i
].clk
) {
1483 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
1484 case UNICHROME_CLE266
:
1485 case UNICHROME_K400
:
1486 return pll_value
[i
].cle266_pll
;
1488 case UNICHROME_K800
:
1489 case UNICHROME_PM800
:
1490 case UNICHROME_CN700
:
1491 return pll_value
[i
].k800_pll
;
1493 case UNICHROME_CX700
:
1494 case UNICHROME_K8M890
:
1495 case UNICHROME_P4M890
:
1496 case UNICHROME_P4M900
:
1497 case UNICHROME_VX800
:
1498 return pll_value
[i
].cx700_pll
;
1503 DEBUG_MSG(KERN_INFO
"Can't find match PLL value\n\n");
1508 void viafb_set_vclock(u32 CLK
, int set_iga
)
1510 unsigned char RegTemp
;
1512 /* H.W. Reset : ON */
1513 viafb_write_reg_mask(CR17
, VIACR
, 0x00, BIT7
);
1515 if ((set_iga
== IGA1
) || (set_iga
== IGA1_IGA2
)) {
1516 /* Change D,N FOR VCLK */
1517 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
1518 case UNICHROME_CLE266
:
1519 case UNICHROME_K400
:
1520 viafb_write_reg(SR46
, VIASR
, CLK
/ 0x100);
1521 viafb_write_reg(SR47
, VIASR
, CLK
% 0x100);
1524 case UNICHROME_K800
:
1525 case UNICHROME_PM800
:
1526 case UNICHROME_CN700
:
1527 case UNICHROME_CX700
:
1528 case UNICHROME_K8M890
:
1529 case UNICHROME_P4M890
:
1530 case UNICHROME_P4M900
:
1531 case UNICHROME_VX800
:
1532 viafb_write_reg(SR44
, VIASR
, CLK
/ 0x10000);
1533 DEBUG_MSG(KERN_INFO
"\nSR44=%x", CLK
/ 0x10000);
1534 viafb_write_reg(SR45
, VIASR
, (CLK
& 0xFFFF) / 0x100);
1535 DEBUG_MSG(KERN_INFO
"\nSR45=%x",
1536 (CLK
& 0xFFFF) / 0x100);
1537 viafb_write_reg(SR46
, VIASR
, CLK
% 0x100);
1538 DEBUG_MSG(KERN_INFO
"\nSR46=%x", CLK
% 0x100);
1543 if ((set_iga
== IGA2
) || (set_iga
== IGA1_IGA2
)) {
1544 /* Change D,N FOR LCK */
1545 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
1546 case UNICHROME_CLE266
:
1547 case UNICHROME_K400
:
1548 viafb_write_reg(SR44
, VIASR
, CLK
/ 0x100);
1549 viafb_write_reg(SR45
, VIASR
, CLK
% 0x100);
1552 case UNICHROME_K800
:
1553 case UNICHROME_PM800
:
1554 case UNICHROME_CN700
:
1555 case UNICHROME_CX700
:
1556 case UNICHROME_K8M890
:
1557 case UNICHROME_P4M890
:
1558 case UNICHROME_P4M900
:
1559 case UNICHROME_VX800
:
1560 viafb_write_reg(SR4A
, VIASR
, CLK
/ 0x10000);
1561 viafb_write_reg(SR4B
, VIASR
, (CLK
& 0xFFFF) / 0x100);
1562 viafb_write_reg(SR4C
, VIASR
, CLK
% 0x100);
1567 /* H.W. Reset : OFF */
1568 viafb_write_reg_mask(CR17
, VIACR
, 0x80, BIT7
);
1571 if ((set_iga
== IGA1
) || (set_iga
== IGA1_IGA2
)) {
1572 viafb_write_reg_mask(SR40
, VIASR
, 0x02, BIT1
);
1573 viafb_write_reg_mask(SR40
, VIASR
, 0x00, BIT1
);
1576 if ((set_iga
== IGA2
) || (set_iga
== IGA1_IGA2
)) {
1577 viafb_write_reg_mask(SR40
, VIASR
, 0x01, BIT0
);
1578 viafb_write_reg_mask(SR40
, VIASR
, 0x00, BIT0
);
1582 RegTemp
= inb(VIARMisc
);
1583 outb(RegTemp
| (BIT2
+ BIT3
), VIAWMisc
);
1586 void viafb_load_crtc_timing(struct display_timing device_timing
,
1590 int viafb_load_reg_num
= 0;
1592 struct io_register
*reg
= NULL
;
1596 for (i
= 0; i
< 12; i
++) {
1597 if (set_iga
== IGA1
) {
1601 IGA1_HOR_TOTAL_FORMULA(device_timing
.
1603 viafb_load_reg_num
=
1604 iga1_crtc_reg
.hor_total
.reg_num
;
1605 reg
= iga1_crtc_reg
.hor_total
.reg
;
1609 IGA1_HOR_ADDR_FORMULA(device_timing
.
1611 viafb_load_reg_num
=
1612 iga1_crtc_reg
.hor_addr
.reg_num
;
1613 reg
= iga1_crtc_reg
.hor_addr
.reg
;
1615 case H_BLANK_START_INDEX
:
1617 IGA1_HOR_BLANK_START_FORMULA
1618 (device_timing
.hor_blank_start
);
1619 viafb_load_reg_num
=
1620 iga1_crtc_reg
.hor_blank_start
.reg_num
;
1621 reg
= iga1_crtc_reg
.hor_blank_start
.reg
;
1623 case H_BLANK_END_INDEX
:
1625 IGA1_HOR_BLANK_END_FORMULA
1626 (device_timing
.hor_blank_start
,
1627 device_timing
.hor_blank_end
);
1628 viafb_load_reg_num
=
1629 iga1_crtc_reg
.hor_blank_end
.reg_num
;
1630 reg
= iga1_crtc_reg
.hor_blank_end
.reg
;
1632 case H_SYNC_START_INDEX
:
1634 IGA1_HOR_SYNC_START_FORMULA
1635 (device_timing
.hor_sync_start
);
1636 viafb_load_reg_num
=
1637 iga1_crtc_reg
.hor_sync_start
.reg_num
;
1638 reg
= iga1_crtc_reg
.hor_sync_start
.reg
;
1640 case H_SYNC_END_INDEX
:
1642 IGA1_HOR_SYNC_END_FORMULA
1643 (device_timing
.hor_sync_start
,
1644 device_timing
.hor_sync_end
);
1645 viafb_load_reg_num
=
1646 iga1_crtc_reg
.hor_sync_end
.reg_num
;
1647 reg
= iga1_crtc_reg
.hor_sync_end
.reg
;
1651 IGA1_VER_TOTAL_FORMULA(device_timing
.
1653 viafb_load_reg_num
=
1654 iga1_crtc_reg
.ver_total
.reg_num
;
1655 reg
= iga1_crtc_reg
.ver_total
.reg
;
1659 IGA1_VER_ADDR_FORMULA(device_timing
.
1661 viafb_load_reg_num
=
1662 iga1_crtc_reg
.ver_addr
.reg_num
;
1663 reg
= iga1_crtc_reg
.ver_addr
.reg
;
1665 case V_BLANK_START_INDEX
:
1667 IGA1_VER_BLANK_START_FORMULA
1668 (device_timing
.ver_blank_start
);
1669 viafb_load_reg_num
=
1670 iga1_crtc_reg
.ver_blank_start
.reg_num
;
1671 reg
= iga1_crtc_reg
.ver_blank_start
.reg
;
1673 case V_BLANK_END_INDEX
:
1675 IGA1_VER_BLANK_END_FORMULA
1676 (device_timing
.ver_blank_start
,
1677 device_timing
.ver_blank_end
);
1678 viafb_load_reg_num
=
1679 iga1_crtc_reg
.ver_blank_end
.reg_num
;
1680 reg
= iga1_crtc_reg
.ver_blank_end
.reg
;
1682 case V_SYNC_START_INDEX
:
1684 IGA1_VER_SYNC_START_FORMULA
1685 (device_timing
.ver_sync_start
);
1686 viafb_load_reg_num
=
1687 iga1_crtc_reg
.ver_sync_start
.reg_num
;
1688 reg
= iga1_crtc_reg
.ver_sync_start
.reg
;
1690 case V_SYNC_END_INDEX
:
1692 IGA1_VER_SYNC_END_FORMULA
1693 (device_timing
.ver_sync_start
,
1694 device_timing
.ver_sync_end
);
1695 viafb_load_reg_num
=
1696 iga1_crtc_reg
.ver_sync_end
.reg_num
;
1697 reg
= iga1_crtc_reg
.ver_sync_end
.reg
;
1703 if (set_iga
== IGA2
) {
1707 IGA2_HOR_TOTAL_FORMULA(device_timing
.
1709 viafb_load_reg_num
=
1710 iga2_crtc_reg
.hor_total
.reg_num
;
1711 reg
= iga2_crtc_reg
.hor_total
.reg
;
1715 IGA2_HOR_ADDR_FORMULA(device_timing
.
1717 viafb_load_reg_num
=
1718 iga2_crtc_reg
.hor_addr
.reg_num
;
1719 reg
= iga2_crtc_reg
.hor_addr
.reg
;
1721 case H_BLANK_START_INDEX
:
1723 IGA2_HOR_BLANK_START_FORMULA
1724 (device_timing
.hor_blank_start
);
1725 viafb_load_reg_num
=
1726 iga2_crtc_reg
.hor_blank_start
.reg_num
;
1727 reg
= iga2_crtc_reg
.hor_blank_start
.reg
;
1729 case H_BLANK_END_INDEX
:
1731 IGA2_HOR_BLANK_END_FORMULA
1732 (device_timing
.hor_blank_start
,
1733 device_timing
.hor_blank_end
);
1734 viafb_load_reg_num
=
1735 iga2_crtc_reg
.hor_blank_end
.reg_num
;
1736 reg
= iga2_crtc_reg
.hor_blank_end
.reg
;
1738 case H_SYNC_START_INDEX
:
1740 IGA2_HOR_SYNC_START_FORMULA
1741 (device_timing
.hor_sync_start
);
1742 if (UNICHROME_CN700
<=
1743 viaparinfo
->chip_info
->gfx_chip_name
)
1744 viafb_load_reg_num
=
1745 iga2_crtc_reg
.hor_sync_start
.
1748 viafb_load_reg_num
= 3;
1749 reg
= iga2_crtc_reg
.hor_sync_start
.reg
;
1751 case H_SYNC_END_INDEX
:
1753 IGA2_HOR_SYNC_END_FORMULA
1754 (device_timing
.hor_sync_start
,
1755 device_timing
.hor_sync_end
);
1756 viafb_load_reg_num
=
1757 iga2_crtc_reg
.hor_sync_end
.reg_num
;
1758 reg
= iga2_crtc_reg
.hor_sync_end
.reg
;
1762 IGA2_VER_TOTAL_FORMULA(device_timing
.
1764 viafb_load_reg_num
=
1765 iga2_crtc_reg
.ver_total
.reg_num
;
1766 reg
= iga2_crtc_reg
.ver_total
.reg
;
1770 IGA2_VER_ADDR_FORMULA(device_timing
.
1772 viafb_load_reg_num
=
1773 iga2_crtc_reg
.ver_addr
.reg_num
;
1774 reg
= iga2_crtc_reg
.ver_addr
.reg
;
1776 case V_BLANK_START_INDEX
:
1778 IGA2_VER_BLANK_START_FORMULA
1779 (device_timing
.ver_blank_start
);
1780 viafb_load_reg_num
=
1781 iga2_crtc_reg
.ver_blank_start
.reg_num
;
1782 reg
= iga2_crtc_reg
.ver_blank_start
.reg
;
1784 case V_BLANK_END_INDEX
:
1786 IGA2_VER_BLANK_END_FORMULA
1787 (device_timing
.ver_blank_start
,
1788 device_timing
.ver_blank_end
);
1789 viafb_load_reg_num
=
1790 iga2_crtc_reg
.ver_blank_end
.reg_num
;
1791 reg
= iga2_crtc_reg
.ver_blank_end
.reg
;
1793 case V_SYNC_START_INDEX
:
1795 IGA2_VER_SYNC_START_FORMULA
1796 (device_timing
.ver_sync_start
);
1797 viafb_load_reg_num
=
1798 iga2_crtc_reg
.ver_sync_start
.reg_num
;
1799 reg
= iga2_crtc_reg
.ver_sync_start
.reg
;
1801 case V_SYNC_END_INDEX
:
1803 IGA2_VER_SYNC_END_FORMULA
1804 (device_timing
.ver_sync_start
,
1805 device_timing
.ver_sync_end
);
1806 viafb_load_reg_num
=
1807 iga2_crtc_reg
.ver_sync_end
.reg_num
;
1808 reg
= iga2_crtc_reg
.ver_sync_end
.reg
;
1813 viafb_load_reg(reg_value
, viafb_load_reg_num
, reg
, VIACR
);
1819 void viafb_set_color_depth(int bpp_byte
, int set_iga
)
1821 if (set_iga
== IGA1
) {
1824 viafb_write_reg_mask(SR15
, VIASR
, 0x22, 0x7E);
1827 viafb_write_reg_mask(SR15
, VIASR
, 0xB6, 0xFE);
1830 viafb_write_reg_mask(SR15
, VIASR
, 0xAE, 0xFE);
1836 viafb_write_reg_mask(CR67
, VIACR
, 0x00, BIT6
+ BIT7
);
1839 viafb_write_reg_mask(CR67
, VIACR
, 0x40, BIT6
+ BIT7
);
1842 viafb_write_reg_mask(CR67
, VIACR
, 0xC0, BIT6
+ BIT7
);
1848 void viafb_fill_crtc_timing(struct crt_mode_table
*crt_table
,
1849 int mode_index
, int bpp_byte
, int set_iga
)
1851 struct VideoModeTable
*video_mode
;
1852 struct display_timing crt_reg
;
1858 video_mode
= &CLE266Modes
[search_mode_setting(mode_index
)];
1860 for (i
= 0; i
< video_mode
->mode_array
; i
++) {
1863 if (crt_table
[i
].refresh_rate
== viaparinfo
->
1864 crt_setting_info
->refresh_rate
)
1868 crt_reg
= crt_table
[index
].crtc
;
1870 /* Mode 640x480 has border, but LCD/DFP didn't have border. */
1871 /* So we would delete border. */
1872 if ((viafb_LCD_ON
| viafb_DVI_ON
) && (mode_index
== VIA_RES_640X480
)
1873 && (viaparinfo
->crt_setting_info
->refresh_rate
== 60)) {
1874 /* The border is 8 pixels. */
1875 crt_reg
.hor_blank_start
= crt_reg
.hor_blank_start
- 8;
1877 /* Blanking time should add left and right borders. */
1878 crt_reg
.hor_blank_end
= crt_reg
.hor_blank_end
+ 16;
1881 h_addr
= crt_reg
.hor_addr
;
1882 v_addr
= crt_reg
.ver_addr
;
1884 /* update polarity for CRT timing */
1885 if (crt_table
[index
].h_sync_polarity
== NEGATIVE
) {
1886 if (crt_table
[index
].v_sync_polarity
== NEGATIVE
)
1887 outb((inb(VIARMisc
) & (~(BIT6
+ BIT7
))) |
1888 (BIT6
+ BIT7
), VIAWMisc
);
1890 outb((inb(VIARMisc
) & (~(BIT6
+ BIT7
))) | (BIT6
),
1893 if (crt_table
[index
].v_sync_polarity
== NEGATIVE
)
1894 outb((inb(VIARMisc
) & (~(BIT6
+ BIT7
))) | (BIT7
),
1897 outb((inb(VIARMisc
) & (~(BIT6
+ BIT7
))), VIAWMisc
);
1900 if (set_iga
== IGA1
) {
1902 viafb_write_reg(CR09
, VIACR
, 0x00); /*initial CR09=0 */
1903 viafb_write_reg_mask(CR11
, VIACR
, 0x00, BIT4
+ BIT5
+ BIT6
);
1904 viafb_write_reg_mask(CR17
, VIACR
, 0x00, BIT7
);
1909 viafb_load_crtc_timing(crt_reg
, IGA1
);
1912 viafb_load_crtc_timing(crt_reg
, IGA2
);
1916 load_fix_bit_crtc_reg();
1918 viafb_write_reg_mask(CR17
, VIACR
, 0x80, BIT7
);
1919 viafb_load_offset_reg(h_addr
, bpp_byte
, set_iga
);
1920 viafb_load_fetch_count_reg(h_addr
, bpp_byte
, set_iga
);
1923 if ((viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_CLE266
)
1924 && (viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_K400
))
1925 viafb_load_FIFO_reg(set_iga
, h_addr
, v_addr
);
1927 /* load SR Register About Memory and Color part */
1928 viafb_set_color_depth(bpp_byte
, set_iga
);
1930 pll_D_N
= viafb_get_clk_value(crt_table
[index
].clk
);
1931 DEBUG_MSG(KERN_INFO
"PLL=%x", pll_D_N
);
1932 viafb_set_vclock(pll_D_N
, set_iga
);
1936 void viafb_init_chip_info(void)
1938 init_gfx_chip_info();
1939 init_tmds_chip_info();
1940 init_lvds_chip_info();
1942 viaparinfo
->crt_setting_info
->iga_path
= IGA1
;
1943 viaparinfo
->crt_setting_info
->refresh_rate
= viafb_refresh
;
1945 /*Set IGA path for each device */
1946 viafb_set_iga_path();
1948 viaparinfo
->lvds_setting_info
->display_method
= viafb_lcd_dsp_method
;
1949 viaparinfo
->lvds_setting_info
->get_lcd_size_method
=
1950 GET_LCD_SIZE_BY_USER_SETTING
;
1951 viaparinfo
->lvds_setting_info
->lcd_mode
= viafb_lcd_mode
;
1952 viaparinfo
->lvds_setting_info2
->display_method
=
1953 viaparinfo
->lvds_setting_info
->display_method
;
1954 viaparinfo
->lvds_setting_info2
->lcd_mode
=
1955 viaparinfo
->lvds_setting_info
->lcd_mode
;
1958 void viafb_update_device_setting(int hres
, int vres
,
1959 int bpp
, int vmode_refresh
, int flag
)
1962 viaparinfo
->crt_setting_info
->h_active
= hres
;
1963 viaparinfo
->crt_setting_info
->v_active
= vres
;
1964 viaparinfo
->crt_setting_info
->bpp
= bpp
;
1965 viaparinfo
->crt_setting_info
->refresh_rate
=
1968 viaparinfo
->tmds_setting_info
->h_active
= hres
;
1969 viaparinfo
->tmds_setting_info
->v_active
= vres
;
1970 viaparinfo
->tmds_setting_info
->bpp
= bpp
;
1971 viaparinfo
->tmds_setting_info
->refresh_rate
=
1974 viaparinfo
->lvds_setting_info
->h_active
= hres
;
1975 viaparinfo
->lvds_setting_info
->v_active
= vres
;
1976 viaparinfo
->lvds_setting_info
->bpp
= bpp
;
1977 viaparinfo
->lvds_setting_info
->refresh_rate
=
1979 viaparinfo
->lvds_setting_info2
->h_active
= hres
;
1980 viaparinfo
->lvds_setting_info2
->v_active
= vres
;
1981 viaparinfo
->lvds_setting_info2
->bpp
= bpp
;
1982 viaparinfo
->lvds_setting_info2
->refresh_rate
=
1986 if (viaparinfo
->tmds_setting_info
->iga_path
== IGA2
) {
1987 viaparinfo
->tmds_setting_info
->h_active
= hres
;
1988 viaparinfo
->tmds_setting_info
->v_active
= vres
;
1989 viaparinfo
->tmds_setting_info
->bpp
= bpp
;
1990 viaparinfo
->tmds_setting_info
->refresh_rate
=
1994 if (viaparinfo
->lvds_setting_info
->iga_path
== IGA2
) {
1995 viaparinfo
->lvds_setting_info
->h_active
= hres
;
1996 viaparinfo
->lvds_setting_info
->v_active
= vres
;
1997 viaparinfo
->lvds_setting_info
->bpp
= bpp
;
1998 viaparinfo
->lvds_setting_info
->refresh_rate
=
2001 if (IGA2
== viaparinfo
->lvds_setting_info2
->iga_path
) {
2002 viaparinfo
->lvds_setting_info2
->h_active
= hres
;
2003 viaparinfo
->lvds_setting_info2
->v_active
= vres
;
2004 viaparinfo
->lvds_setting_info2
->bpp
= bpp
;
2005 viaparinfo
->lvds_setting_info2
->refresh_rate
=
2011 static void init_gfx_chip_info(void)
2013 struct pci_dev
*pdev
= NULL
;
2017 /* Indentify GFX Chip Name */
2018 for (i
= 0; pciidlist
[i
].vendor
!= 0; i
++) {
2019 pdev
= pci_get_device(pciidlist
[i
].vendor
,
2020 pciidlist
[i
].device
, 0);
2025 if (!pciidlist
[i
].vendor
)
2028 viaparinfo
->chip_info
->gfx_chip_name
= pciidlist
[i
].chip_index
;
2030 /* Check revision of CLE266 Chip */
2031 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
2032 /* CR4F only define in CLE266.CX chip */
2033 tmp
= viafb_read_reg(VIACR
, CR4F
);
2034 viafb_write_reg(CR4F
, VIACR
, 0x55);
2035 if (viafb_read_reg(VIACR
, CR4F
) != 0x55)
2036 viaparinfo
->chip_info
->gfx_chip_revision
=
2039 viaparinfo
->chip_info
->gfx_chip_revision
=
2041 /* restore orignal CR4F value */
2042 viafb_write_reg(CR4F
, VIACR
, tmp
);
2045 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
2046 tmp
= viafb_read_reg(VIASR
, SR43
);
2047 DEBUG_MSG(KERN_INFO
"SR43:%X\n", tmp
);
2049 viaparinfo
->chip_info
->gfx_chip_revision
=
2050 CX700_REVISION_700M2
;
2051 } else if (tmp
& 0x40) {
2052 viaparinfo
->chip_info
->gfx_chip_revision
=
2053 CX700_REVISION_700M
;
2055 viaparinfo
->chip_info
->gfx_chip_revision
=
2063 static void init_tmds_chip_info(void)
2065 viafb_tmds_trasmitter_identify();
2067 if (INTERFACE_NONE
== viaparinfo
->chip_info
->tmds_chip_info
.
2069 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
2070 case UNICHROME_CX700
:
2072 /* we should check support by hardware layout.*/
2073 if ((viafb_display_hardware_layout
==
2075 || (viafb_display_hardware_layout
==
2076 HW_LAYOUT_LCD_DVI
)) {
2077 viaparinfo
->chip_info
->tmds_chip_info
.
2078 output_interface
= INTERFACE_TMDS
;
2080 viaparinfo
->chip_info
->tmds_chip_info
.
2086 case UNICHROME_K8M890
:
2087 case UNICHROME_P4M900
:
2088 case UNICHROME_P4M890
:
2089 /* TMDS on PCIE, we set DFPLOW as default. */
2090 viaparinfo
->chip_info
->tmds_chip_info
.output_interface
=
2095 /* set DVP1 default for DVI */
2096 viaparinfo
->chip_info
->tmds_chip_info
2097 .output_interface
= INTERFACE_DVP1
;
2102 DEBUG_MSG(KERN_INFO
"TMDS Chip = %d\n",
2103 viaparinfo
->chip_info
->tmds_chip_info
.tmds_chip_name
);
2104 viaparinfo
->tmds_setting_info
->get_dvi_size_method
=
2105 GET_DVI_SIZE_BY_VGA_BIOS
;
2106 viafb_init_dvi_size();
2109 static void init_lvds_chip_info(void)
2111 if (viafb_lcd_panel_id
> LCD_PANEL_ID_MAXIMUM
)
2112 viaparinfo
->lvds_setting_info
->get_lcd_size_method
=
2113 GET_LCD_SIZE_BY_VGA_BIOS
;
2115 viaparinfo
->lvds_setting_info
->get_lcd_size_method
=
2116 GET_LCD_SIZE_BY_USER_SETTING
;
2118 viafb_lvds_trasmitter_identify();
2119 viafb_init_lcd_size();
2120 viafb_init_lvds_output_interface(&viaparinfo
->chip_info
->lvds_chip_info
,
2121 viaparinfo
->lvds_setting_info
);
2122 if (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
2123 viafb_init_lvds_output_interface(&viaparinfo
->chip_info
->
2124 lvds_chip_info2
, viaparinfo
->lvds_setting_info2
);
2126 /*If CX700,two singel LCD, we need to reassign
2127 LCD interface to different LVDS port */
2128 if ((UNICHROME_CX700
== viaparinfo
->chip_info
->gfx_chip_name
)
2129 && (HW_LAYOUT_LCD1_LCD2
== viafb_display_hardware_layout
)) {
2130 if ((INTEGRATED_LVDS
== viaparinfo
->chip_info
->lvds_chip_info
.
2131 lvds_chip_name
) && (INTEGRATED_LVDS
==
2132 viaparinfo
->chip_info
->
2133 lvds_chip_info2
.lvds_chip_name
)) {
2134 viaparinfo
->chip_info
->lvds_chip_info
.output_interface
=
2136 viaparinfo
->chip_info
->lvds_chip_info2
.
2142 DEBUG_MSG(KERN_INFO
"LVDS Chip = %d\n",
2143 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
2144 DEBUG_MSG(KERN_INFO
"LVDS1 output_interface = %d\n",
2145 viaparinfo
->chip_info
->lvds_chip_info
.output_interface
);
2146 DEBUG_MSG(KERN_INFO
"LVDS2 output_interface = %d\n",
2147 viaparinfo
->chip_info
->lvds_chip_info
.output_interface
);
2150 void viafb_init_dac(int set_iga
)
2155 if (set_iga
== IGA1
) {
2156 /* access Primary Display's LUT */
2157 viafb_write_reg_mask(SR1A
, VIASR
, 0x00, BIT0
);
2159 viafb_write_reg_mask(SR1B
, VIASR
, 0x00, BIT7
+ BIT6
);
2160 for (i
= 0; i
< 256; i
++) {
2161 write_dac_reg(i
, palLUT_table
[i
].red
,
2162 palLUT_table
[i
].green
,
2163 palLUT_table
[i
].blue
);
2166 viafb_write_reg_mask(SR1B
, VIASR
, 0xC0, BIT7
+ BIT6
);
2168 tmp
= viafb_read_reg(VIACR
, CR6A
);
2169 /* access Secondary Display's LUT */
2170 viafb_write_reg_mask(CR6A
, VIACR
, 0x40, BIT6
);
2171 viafb_write_reg_mask(SR1A
, VIASR
, 0x01, BIT0
);
2172 for (i
= 0; i
< 256; i
++) {
2173 write_dac_reg(i
, palLUT_table
[i
].red
,
2174 palLUT_table
[i
].green
,
2175 palLUT_table
[i
].blue
);
2177 /* set IGA1 DAC for default */
2178 viafb_write_reg_mask(SR1A
, VIASR
, 0x00, BIT0
);
2179 viafb_write_reg(CR6A
, VIACR
, tmp
);
2183 static void device_screen_off(void)
2185 /* turn off CRT screen (IGA1) */
2186 viafb_write_reg_mask(SR01
, VIASR
, 0x20, BIT5
);
2189 static void device_screen_on(void)
2191 /* turn on CRT screen (IGA1) */
2192 viafb_write_reg_mask(SR01
, VIASR
, 0x00, BIT5
);
2195 static void set_display_channel(void)
2197 /*If viafb_LCD2_ON, on cx700, internal lvds's information
2198 is keeped on lvds_setting_info2 */
2199 if (viafb_LCD2_ON
&&
2200 viaparinfo
->lvds_setting_info2
->device_lcd_dualedge
) {
2201 /* For dual channel LCD: */
2202 /* Set to Dual LVDS channel. */
2203 viafb_write_reg_mask(CRD2
, VIACR
, 0x20, BIT4
+ BIT5
);
2204 } else if (viafb_LCD_ON
&& viafb_DVI_ON
) {
2206 /* Set to LVDS1 + TMDS channel. */
2207 viafb_write_reg_mask(CRD2
, VIACR
, 0x10, BIT4
+ BIT5
);
2208 } else if (viafb_DVI_ON
) {
2209 /* Set to single TMDS channel. */
2210 viafb_write_reg_mask(CRD2
, VIACR
, 0x30, BIT4
+ BIT5
);
2211 } else if (viafb_LCD_ON
) {
2212 if (viaparinfo
->lvds_setting_info
->device_lcd_dualedge
) {
2213 /* For dual channel LCD: */
2214 /* Set to Dual LVDS channel. */
2215 viafb_write_reg_mask(CRD2
, VIACR
, 0x20, BIT4
+ BIT5
);
2217 /* Set to LVDS0 + LVDS1 channel. */
2218 viafb_write_reg_mask(CRD2
, VIACR
, 0x00, BIT4
+ BIT5
);
2223 int viafb_setmode(int vmode_index
, int hor_res
, int ver_res
, int video_bpp
,
2224 int vmode_index1
, int hor_res1
, int ver_res1
, int video_bpp1
)
2228 u8 value
, index
, mask
;
2229 struct VideoModeTable
*vmode_tbl
;
2230 struct crt_mode_table
*crt_timing
;
2231 struct VideoModeTable
*vmode_tbl1
= NULL
;
2232 struct crt_mode_table
*crt_timing1
= NULL
;
2234 DEBUG_MSG(KERN_INFO
"Set Mode!!\n");
2236 "vmode_index=%d hor_res=%d ver_res=%d video_bpp=%d\n",
2237 vmode_index
, hor_res
, ver_res
, video_bpp
);
2239 device_screen_off();
2240 vmode_tbl
= &CLE266Modes
[search_mode_setting(vmode_index
)];
2241 crt_timing
= vmode_tbl
->crtc
;
2243 if (viafb_SAMM_ON
== 1) {
2244 vmode_tbl1
= &CLE266Modes
[search_mode_setting(vmode_index1
)];
2245 crt_timing1
= vmode_tbl1
->crtc
;
2251 /* Write Common Setting for Video Mode */
2252 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
2253 case UNICHROME_CLE266
:
2254 viafb_write_regx(CLE266_ModeXregs
, NUM_TOTAL_CLE266_ModeXregs
);
2257 case UNICHROME_K400
:
2258 viafb_write_regx(KM400_ModeXregs
, NUM_TOTAL_KM400_ModeXregs
);
2261 case UNICHROME_K800
:
2262 case UNICHROME_PM800
:
2263 viafb_write_regx(CN400_ModeXregs
, NUM_TOTAL_CN400_ModeXregs
);
2266 case UNICHROME_CN700
:
2267 case UNICHROME_K8M890
:
2268 case UNICHROME_P4M890
:
2269 case UNICHROME_P4M900
:
2270 viafb_write_regx(CN700_ModeXregs
, NUM_TOTAL_CN700_ModeXregs
);
2273 case UNICHROME_CX700
:
2274 viafb_write_regx(CX700_ModeXregs
, NUM_TOTAL_CX700_ModeXregs
);
2276 case UNICHROME_VX800
:
2277 viafb_write_regx(VX800_ModeXregs
, NUM_TOTAL_VX800_ModeXregs
);
2284 /* Fill VPIT Parameters */
2285 /* Write Misc Register */
2286 outb(VPIT
.Misc
, VIAWMisc
);
2288 /* Write Sequencer */
2289 for (i
= 1; i
<= StdSR
; i
++) {
2291 outb(VPIT
.SR
[i
- 1], VIASR
+ 1);
2294 viafb_set_start_addr();
2295 viafb_set_iga_path();
2298 viafb_fill_crtc_timing(crt_timing
, vmode_index
, video_bpp
/ 8, IGA1
);
2300 /* Write Graphic Controller */
2301 for (i
= 0; i
< StdGR
; i
++) {
2303 outb(VPIT
.GR
[i
], VIAGR
+ 1);
2306 /* Write Attribute Controller */
2307 for (i
= 0; i
< StdAR
; i
++) {
2310 outb(VPIT
.AR
[i
], VIAAR
);
2316 /* Update Patch Register */
2318 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)
2319 || (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K400
)) {
2320 for (i
= 0; i
< NUM_TOTAL_PATCH_MODE
; i
++) {
2321 if (res_patch_table
[i
].mode_index
== vmode_index
) {
2323 j
< res_patch_table
[i
].table_length
; j
++) {
2326 io_reg_table
[j
].index
;
2329 io_reg_table
[j
].port
;
2332 io_reg_table
[j
].value
;
2335 io_reg_table
[j
].mask
;
2336 viafb_write_reg_mask(index
, port
, value
,
2343 if (viafb_SAMM_ON
== 1) {
2344 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)
2345 || (viaparinfo
->chip_info
->gfx_chip_name
==
2347 for (i
= 0; i
< NUM_TOTAL_PATCH_MODE
; i
++) {
2348 if (res_patch_table
[i
].mode_index
==
2353 table_length
; j
++) {
2356 io_reg_table
[j
].index
;
2359 io_reg_table
[j
].port
;
2362 io_reg_table
[j
].value
;
2365 io_reg_table
[j
].mask
;
2366 viafb_write_reg_mask(index
,
2374 /* Update Refresh Rate Setting */
2376 /* Clear On Screen */
2380 if (viafb_SAMM_ON
&& (viaparinfo
->crt_setting_info
->iga_path
==
2382 viafb_fill_crtc_timing(crt_timing1
, vmode_index1
,
2384 viaparinfo
->crt_setting_info
->iga_path
);
2386 viafb_fill_crtc_timing(crt_timing
, vmode_index
,
2388 viaparinfo
->crt_setting_info
->iga_path
);
2391 set_crt_output_path(viaparinfo
->crt_setting_info
->iga_path
);
2393 /* Patch if set_hres is not 8 alignment (1366) to viafb_setmode
2394 to 8 alignment (1368),there is several pixels (2 pixels)
2395 on right side of screen. */
2398 viafb_write_reg(CR02
, VIACR
,
2399 viafb_read_reg(VIACR
, CR02
) - 1);
2405 if (viafb_SAMM_ON
&&
2406 (viaparinfo
->tmds_setting_info
->iga_path
== IGA2
)) {
2407 viafb_dvi_set_mode(viafb_get_mode_index
2408 (viaparinfo
->tmds_setting_info
->h_active
,
2409 viaparinfo
->tmds_setting_info
->
2411 video_bpp1
, viaparinfo
->
2412 tmds_setting_info
->iga_path
);
2414 viafb_dvi_set_mode(viafb_get_mode_index
2415 (viaparinfo
->tmds_setting_info
->h_active
,
2417 tmds_setting_info
->v_active
, 0),
2418 video_bpp
, viaparinfo
->
2419 tmds_setting_info
->iga_path
);
2424 if (viafb_SAMM_ON
&&
2425 (viaparinfo
->lvds_setting_info
->iga_path
== IGA2
)) {
2426 viaparinfo
->lvds_setting_info
->bpp
= video_bpp1
;
2427 viafb_lcd_set_mode(crt_timing1
, viaparinfo
->
2429 &viaparinfo
->chip_info
->lvds_chip_info
);
2431 /* IGA1 doesn't have LCD scaling, so set it center. */
2432 if (viaparinfo
->lvds_setting_info
->iga_path
== IGA1
) {
2433 viaparinfo
->lvds_setting_info
->display_method
=
2436 viaparinfo
->lvds_setting_info
->bpp
= video_bpp
;
2437 viafb_lcd_set_mode(crt_timing
, viaparinfo
->
2439 &viaparinfo
->chip_info
->lvds_chip_info
);
2442 if (viafb_LCD2_ON
) {
2443 if (viafb_SAMM_ON
&&
2444 (viaparinfo
->lvds_setting_info2
->iga_path
== IGA2
)) {
2445 viaparinfo
->lvds_setting_info2
->bpp
= video_bpp1
;
2446 viafb_lcd_set_mode(crt_timing1
, viaparinfo
->
2448 &viaparinfo
->chip_info
->lvds_chip_info2
);
2450 /* IGA1 doesn't have LCD scaling, so set it center. */
2451 if (viaparinfo
->lvds_setting_info2
->iga_path
== IGA1
) {
2452 viaparinfo
->lvds_setting_info2
->display_method
=
2455 viaparinfo
->lvds_setting_info2
->bpp
= video_bpp
;
2456 viafb_lcd_set_mode(crt_timing
, viaparinfo
->
2458 &viaparinfo
->chip_info
->lvds_chip_info2
);
2462 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
)
2463 && (viafb_LCD_ON
|| viafb_DVI_ON
))
2464 set_display_channel();
2466 /* If set mode normally, save resolution information for hot-plug . */
2467 if (!viafb_hotplug
) {
2468 viafb_hotplug_Xres
= hor_res
;
2469 viafb_hotplug_Yres
= ver_res
;
2470 viafb_hotplug_bpp
= video_bpp
;
2471 viafb_hotplug_refresh
= viafb_refresh
;
2474 viafb_DeviceStatus
= DVI_Device
;
2476 viafb_DeviceStatus
= CRT_Device
;
2480 if (viafb_SAMM_ON
== 1)
2481 viafb_write_reg_mask(CR6A
, VIACR
, 0xC0, BIT6
+ BIT7
);
2487 int viafb_get_pixclock(int hres
, int vres
, int vmode_refresh
)
2491 for (i
= 0; i
< NUM_TOTAL_RES_MAP_REFRESH
; i
++) {
2492 if ((hres
== res_map_refresh_tbl
[i
].hres
)
2493 && (vres
== res_map_refresh_tbl
[i
].vres
)
2494 && (vmode_refresh
== res_map_refresh_tbl
[i
].vmode_refresh
))
2495 return res_map_refresh_tbl
[i
].pixclock
;
2497 return RES_640X480_60HZ_PIXCLOCK
;
2501 int viafb_get_refresh(int hres
, int vres
, u32 long_refresh
)
2503 #define REFRESH_TOLERANCE 3
2504 int i
, nearest
= -1, diff
= REFRESH_TOLERANCE
;
2505 for (i
= 0; i
< NUM_TOTAL_RES_MAP_REFRESH
; i
++) {
2506 if ((hres
== res_map_refresh_tbl
[i
].hres
)
2507 && (vres
== res_map_refresh_tbl
[i
].vres
)
2508 && (diff
> (abs(long_refresh
-
2509 res_map_refresh_tbl
[i
].vmode_refresh
)))) {
2510 diff
= abs(long_refresh
- res_map_refresh_tbl
[i
].
2515 #undef REFRESH_TOLERANCE
2517 return res_map_refresh_tbl
[nearest
].vmode_refresh
;
2521 static void device_off(void)
2523 viafb_crt_disable();
2524 viafb_dvi_disable();
2525 viafb_lcd_disable();
2528 static void device_on(void)
2530 if (viafb_CRT_ON
== 1)
2532 if (viafb_DVI_ON
== 1)
2534 if (viafb_LCD_ON
== 1)
2538 void viafb_crt_disable(void)
2540 viafb_write_reg_mask(CR36
, VIACR
, BIT5
+ BIT4
, BIT5
+ BIT4
);
2543 void viafb_crt_enable(void)
2545 viafb_write_reg_mask(CR36
, VIACR
, 0x0, BIT5
+ BIT4
);
2548 void viafb_get_mmio_info(unsigned long *mmio_base
,
2549 unsigned long *mmio_len
)
2551 struct pci_dev
*pdev
= NULL
;
2555 for (i
= 0; pciidlist
[i
].vendor
!= 0; i
++)
2556 if (viaparinfo
->chip_info
->gfx_chip_name
==
2557 pciidlist
[i
].chip_index
)
2560 if (!pciidlist
[i
].vendor
)
2563 vendor
= pciidlist
[i
].vendor
;
2564 device
= pciidlist
[i
].device
;
2566 pdev
= pci_get_device(vendor
, device
, NULL
);
2574 *mmio_base
= pci_resource_start(pdev
, 1);
2575 *mmio_len
= pci_resource_len(pdev
, 1);
2580 static void enable_second_display_channel(void)
2582 /* to enable second display channel. */
2583 viafb_write_reg_mask(CR6A
, VIACR
, 0x00, BIT6
);
2584 viafb_write_reg_mask(CR6A
, VIACR
, BIT7
, BIT7
);
2585 viafb_write_reg_mask(CR6A
, VIACR
, BIT6
, BIT6
);
2588 static void disable_second_display_channel(void)
2590 /* to disable second display channel. */
2591 viafb_write_reg_mask(CR6A
, VIACR
, 0x00, BIT6
);
2592 viafb_write_reg_mask(CR6A
, VIACR
, 0x00, BIT7
);
2593 viafb_write_reg_mask(CR6A
, VIACR
, BIT6
, BIT6
);
2596 void viafb_get_fb_info(unsigned int *fb_base
, unsigned int *fb_len
)
2598 struct pci_dev
*pdev
= NULL
;
2602 for (i
= 0; pciidlist
[i
].vendor
!= 0; i
++)
2603 if (viaparinfo
->chip_info
->gfx_chip_name
==
2604 pciidlist
[i
].chip_index
)
2607 if (!pciidlist
[i
].vendor
)
2610 vendor
= pciidlist
[i
].vendor
;
2611 device
= pciidlist
[i
].device
;
2613 pdev
= pci_get_device(vendor
, device
, NULL
);
2616 *fb_base
= viafb_read_reg(VIASR
, SR30
) << 24;
2617 *fb_len
= viafb_get_memsize();
2618 DEBUG_MSG(KERN_INFO
"Get FB info from SR30!\n");
2619 DEBUG_MSG(KERN_INFO
"fb_base = %08x\n", *fb_base
);
2620 DEBUG_MSG(KERN_INFO
"fb_len = %08x\n", *fb_len
);
2624 *fb_base
= (unsigned int)pci_resource_start(pdev
, 0);
2625 *fb_len
= get_fb_size_from_pci();
2626 DEBUG_MSG(KERN_INFO
"Get FB info from PCI system!\n");
2627 DEBUG_MSG(KERN_INFO
"fb_base = %08x\n", *fb_base
);
2628 DEBUG_MSG(KERN_INFO
"fb_len = %08x\n", *fb_len
);
2633 static int get_fb_size_from_pci(void)
2635 unsigned long configid
, deviceid
, FBSize
= 0;
2637 int DeviceFound
= false;
2639 for (configid
= 0x80000000; configid
< 0x80010800; configid
+= 0x100) {
2640 outl(configid
, (unsigned long)0xCF8);
2641 deviceid
= (inl((unsigned long)0xCFC) >> 16) & 0xffff;
2646 outl(configid
+ 0xE0, (unsigned long)0xCF8);
2647 FBSize
= inl((unsigned long)0xCFC);
2648 DeviceFound
= true; /* Found device id */
2651 case CN400_FUNCTION3
:
2652 case CN700_FUNCTION3
:
2653 case CX700_FUNCTION3
:
2654 case KM800_FUNCTION3
:
2655 case KM890_FUNCTION3
:
2656 case P4M890_FUNCTION3
:
2657 case P4M900_FUNCTION3
:
2658 case VX800_FUNCTION3
:
2659 /*case CN750_FUNCTION3: */
2660 outl(configid
+ 0xA0, (unsigned long)0xCF8);
2661 FBSize
= inl((unsigned long)0xCFC);
2662 DeviceFound
= true; /* Found device id */
2673 DEBUG_MSG(KERN_INFO
"Device ID = %lx\n", deviceid
);
2675 FBSize
= FBSize
& 0x00007000;
2676 DEBUG_MSG(KERN_INFO
"FB Size = %x\n", FBSize
);
2678 if (viaparinfo
->chip_info
->gfx_chip_name
< UNICHROME_CX700
) {
2681 VideoMemSize
= (16 << 20); /*16M */
2685 VideoMemSize
= (32 << 20); /*32M */
2689 VideoMemSize
= (64 << 20); /*64M */
2693 VideoMemSize
= (32 << 20); /*32M */
2699 VideoMemSize
= (8 << 20); /*8M */
2703 VideoMemSize
= (16 << 20); /*16M */
2707 VideoMemSize
= (32 << 20); /*32M */
2711 VideoMemSize
= (64 << 20); /*64M */
2715 VideoMemSize
= (128 << 20); /*128M */
2719 VideoMemSize
= (256 << 20); /*256M */
2723 VideoMemSize
= (32 << 20); /*32M */
2728 return VideoMemSize
;
2731 void viafb_set_dpa_gfx(int output_interface
, struct GFX_DPA_SETTING\
2734 switch (output_interface
) {
2735 case INTERFACE_DVP0
:
2737 /* DVP0 Clock Polarity and Adjust: */
2738 viafb_write_reg_mask(CR96
, VIACR
,
2739 p_gfx_dpa_setting
->DVP0
, 0x0F);
2741 /* DVP0 Clock and Data Pads Driving: */
2742 viafb_write_reg_mask(SR1E
, VIASR
,
2743 p_gfx_dpa_setting
->DVP0ClockDri_S
, BIT2
);
2744 viafb_write_reg_mask(SR2A
, VIASR
,
2745 p_gfx_dpa_setting
->DVP0ClockDri_S1
,
2747 viafb_write_reg_mask(SR1B
, VIASR
,
2748 p_gfx_dpa_setting
->DVP0DataDri_S
, BIT1
);
2749 viafb_write_reg_mask(SR2A
, VIASR
,
2750 p_gfx_dpa_setting
->DVP0DataDri_S1
, BIT5
);
2754 case INTERFACE_DVP1
:
2756 /* DVP1 Clock Polarity and Adjust: */
2757 viafb_write_reg_mask(CR9B
, VIACR
,
2758 p_gfx_dpa_setting
->DVP1
, 0x0F);
2760 /* DVP1 Clock and Data Pads Driving: */
2761 viafb_write_reg_mask(SR65
, VIASR
,
2762 p_gfx_dpa_setting
->DVP1Driving
, 0x0F);
2766 case INTERFACE_DFP_HIGH
:
2768 viafb_write_reg_mask(CR97
, VIACR
,
2769 p_gfx_dpa_setting
->DFPHigh
, 0x0F);
2773 case INTERFACE_DFP_LOW
:
2775 viafb_write_reg_mask(CR99
, VIACR
,
2776 p_gfx_dpa_setting
->DFPLow
, 0x0F);
2782 viafb_write_reg_mask(CR97
, VIACR
,
2783 p_gfx_dpa_setting
->DFPHigh
, 0x0F);
2784 viafb_write_reg_mask(CR99
, VIACR
,
2785 p_gfx_dpa_setting
->DFPLow
, 0x0F);
2791 void viafb_memory_pitch_patch(struct fb_info
*info
)
2793 if (info
->var
.xres
!= info
->var
.xres_virtual
) {
2794 viafb_load_offset_reg(info
->var
.xres_virtual
,
2795 info
->var
.bits_per_pixel
>> 3, IGA1
);
2797 if (viafb_SAMM_ON
) {
2798 viafb_load_offset_reg(viafb_second_virtual_xres
,
2802 viafb_load_offset_reg(info
->var
.xres_virtual
,
2803 info
->var
.bits_per_pixel
>> 3, IGA2
);
2809 /*According var's xres, yres fill var's other timing information*/
2810 void viafb_fill_var_timing_info(struct fb_var_screeninfo
*var
, int refresh
,
2813 struct VideoModeTable
*vmode_tbl
= NULL
;
2814 struct crt_mode_table
*crt_timing
= NULL
;
2815 struct display_timing crt_reg
;
2816 int i
= 0, index
= 0;
2817 vmode_tbl
= &CLE266Modes
[search_mode_setting(mode_index
)];
2818 crt_timing
= vmode_tbl
->crtc
;
2819 for (i
= 0; i
< vmode_tbl
->mode_array
; i
++) {
2821 if (crt_timing
[i
].refresh_rate
== refresh
)
2825 crt_reg
= crt_timing
[index
].crtc
;
2826 switch (var
->bits_per_pixel
) {
2828 var
->red
.offset
= 0;
2829 var
->green
.offset
= 0;
2830 var
->blue
.offset
= 0;
2831 var
->red
.length
= 6;
2832 var
->green
.length
= 6;
2833 var
->blue
.length
= 6;
2836 var
->red
.offset
= 11;
2837 var
->green
.offset
= 5;
2838 var
->blue
.offset
= 0;
2839 var
->red
.length
= 5;
2840 var
->green
.length
= 6;
2841 var
->blue
.length
= 5;
2844 var
->red
.offset
= 16;
2845 var
->green
.offset
= 8;
2846 var
->blue
.offset
= 0;
2847 var
->red
.length
= 8;
2848 var
->green
.length
= 8;
2849 var
->blue
.length
= 8;
2852 /* never happed, put here to keep consistent */
2856 var
->pixclock
= viafb_get_pixclock(var
->xres
, var
->yres
, refresh
);
2858 crt_reg
.hor_total
- (crt_reg
.hor_sync_start
+ crt_reg
.hor_sync_end
);
2859 var
->right_margin
= crt_reg
.hor_sync_start
- crt_reg
.hor_addr
;
2860 var
->hsync_len
= crt_reg
.hor_sync_end
;
2862 crt_reg
.ver_total
- (crt_reg
.ver_sync_start
+ crt_reg
.ver_sync_end
);
2863 var
->lower_margin
= crt_reg
.ver_sync_start
- crt_reg
.ver_addr
;
2864 var
->vsync_len
= crt_reg
.ver_sync_end
;