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.
22 #include <linux/via-core.h>
25 #include "via_clock.h"
27 static struct pll_limit cle266_pll_limits[] = {
58 static struct pll_limit k800_pll_limits[] = {
77 static struct pll_limit cx700_pll_limits[] = {
92 static struct pll_limit vx855_pll_limits[] = {
103 /* according to VIA Technologies these values are based on experiment */
104 static struct io_reg scaling_parameters[] = {
105 {VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
106 {VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
107 {VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
108 {VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
109 {VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
110 {VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
111 {VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
112 {VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
113 {VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
114 {VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
115 {VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
116 {VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
117 {VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
118 {VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
121 static struct io_reg common_vga[] = {
122 {VIACR, CR07, 0x10, 0x10}, /* [0] vertical total (bit 8)
123 [1] vertical display end (bit 8)
124 [2] vertical retrace start (bit 8)
125 [3] start vertical blanking (bit 8)
126 [4] line compare (bit 8)
127 [5] vertical total (bit 9)
128 [6] vertical display end (bit 9)
129 [7] vertical retrace start (bit 9) */
130 {VIACR, CR08, 0xFF, 0x00}, /* [0-4] preset row scan
131 [5-6] byte panning */
132 {VIACR, CR09, 0xDF, 0x40}, /* [0-4] max scan line
133 [5] start vertical blanking (bit 9)
134 [6] line compare (bit 9)
136 {VIACR, CR0A, 0xFF, 0x1E}, /* [0-4] cursor start
137 [5] cursor disable */
138 {VIACR, CR0B, 0xFF, 0x00}, /* [0-4] cursor end
140 {VIACR, CR0E, 0xFF, 0x00}, /* [0-7] cursor location (high) */
141 {VIACR, CR0F, 0xFF, 0x00}, /* [0-7] cursor location (low) */
142 {VIACR, CR11, 0xF0, 0x80}, /* [0-3] vertical retrace end
143 [6] memory refresh bandwidth
144 [7] CRTC register protect enable */
145 {VIACR, CR14, 0xFF, 0x00}, /* [0-4] underline location
146 [5] divide memory address clock by 4
147 [6] double word addressing */
148 {VIACR, CR17, 0xFF, 0x63}, /* [0-1] mapping of display address 13-14
149 [2] divide scan line clock by 2
150 [3] divide memory address clock by 2
154 {VIACR, CR18, 0xFF, 0xFF}, /* [0-7] line compare */
157 static struct fifo_depth_select display_fifo_depth_reg = {
158 /* IGA1 FIFO Depth_Select */
159 {IGA1_FIFO_DEPTH_SELECT_REG_NUM, {{SR17, 0, 7} } },
160 /* IGA2 FIFO Depth_Select */
161 {IGA2_FIFO_DEPTH_SELECT_REG_NUM,
162 {{CR68, 4, 7}, {CR94, 7, 7}, {CR95, 7, 7} } }
165 static struct fifo_threshold_select fifo_threshold_select_reg = {
166 /* IGA1 FIFO Threshold Select */
167 {IGA1_FIFO_THRESHOLD_REG_NUM, {{SR16, 0, 5}, {SR16, 7, 7} } },
168 /* IGA2 FIFO Threshold Select */
169 {IGA2_FIFO_THRESHOLD_REG_NUM, {{CR68, 0, 3}, {CR95, 4, 6} } }
172 static struct fifo_high_threshold_select fifo_high_threshold_select_reg = {
173 /* IGA1 FIFO High Threshold Select */
174 {IGA1_FIFO_HIGH_THRESHOLD_REG_NUM, {{SR18, 0, 5}, {SR18, 7, 7} } },
175 /* IGA2 FIFO High Threshold Select */
176 {IGA2_FIFO_HIGH_THRESHOLD_REG_NUM, {{CR92, 0, 3}, {CR95, 0, 2} } }
179 static struct display_queue_expire_num display_queue_expire_num_reg = {
180 /* IGA1 Display Queue Expire Num */
181 {IGA1_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM, {{SR22, 0, 4} } },
182 /* IGA2 Display Queue Expire Num */
183 {IGA2_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM, {{CR94, 0, 6} } }
186 /* Definition Fetch Count Registers*/
187 static struct fetch_count fetch_count_reg = {
188 /* IGA1 Fetch Count Register */
189 {IGA1_FETCH_COUNT_REG_NUM, {{SR1C, 0, 7}, {SR1D, 0, 1} } },
190 /* IGA2 Fetch Count Register */
191 {IGA2_FETCH_COUNT_REG_NUM, {{CR65, 0, 7}, {CR67, 2, 3} } }
194 static struct iga1_crtc_timing iga1_crtc_reg = {
195 /* IGA1 Horizontal Total */
196 {IGA1_HOR_TOTAL_REG_NUM, {{CR00, 0, 7}, {CR36, 3, 3} } },
197 /* IGA1 Horizontal Addressable Video */
198 {IGA1_HOR_ADDR_REG_NUM, {{CR01, 0, 7} } },
199 /* IGA1 Horizontal Blank Start */
200 {IGA1_HOR_BLANK_START_REG_NUM, {{CR02, 0, 7} } },
201 /* IGA1 Horizontal Blank End */
202 {IGA1_HOR_BLANK_END_REG_NUM,
203 {{CR03, 0, 4}, {CR05, 7, 7}, {CR33, 5, 5} } },
204 /* IGA1 Horizontal Sync Start */
205 {IGA1_HOR_SYNC_START_REG_NUM, {{CR04, 0, 7}, {CR33, 4, 4} } },
206 /* IGA1 Horizontal Sync End */
207 {IGA1_HOR_SYNC_END_REG_NUM, {{CR05, 0, 4} } },
208 /* IGA1 Vertical Total */
209 {IGA1_VER_TOTAL_REG_NUM,
210 {{CR06, 0, 7}, {CR07, 0, 0}, {CR07, 5, 5}, {CR35, 0, 0} } },
211 /* IGA1 Vertical Addressable Video */
212 {IGA1_VER_ADDR_REG_NUM,
213 {{CR12, 0, 7}, {CR07, 1, 1}, {CR07, 6, 6}, {CR35, 2, 2} } },
214 /* IGA1 Vertical Blank Start */
215 {IGA1_VER_BLANK_START_REG_NUM,
216 {{CR15, 0, 7}, {CR07, 3, 3}, {CR09, 5, 5}, {CR35, 3, 3} } },
217 /* IGA1 Vertical Blank End */
218 {IGA1_VER_BLANK_END_REG_NUM, {{CR16, 0, 7} } },
219 /* IGA1 Vertical Sync Start */
220 {IGA1_VER_SYNC_START_REG_NUM,
221 {{CR10, 0, 7}, {CR07, 2, 2}, {CR07, 7, 7}, {CR35, 1, 1} } },
222 /* IGA1 Vertical Sync End */
223 {IGA1_VER_SYNC_END_REG_NUM, {{CR11, 0, 3} } }
226 static struct iga2_crtc_timing iga2_crtc_reg = {
227 /* IGA2 Horizontal Total */
228 {IGA2_HOR_TOTAL_REG_NUM, {{CR50, 0, 7}, {CR55, 0, 3} } },
229 /* IGA2 Horizontal Addressable Video */
230 {IGA2_HOR_ADDR_REG_NUM, {{CR51, 0, 7}, {CR55, 4, 6} } },
231 /* IGA2 Horizontal Blank Start */
232 {IGA2_HOR_BLANK_START_REG_NUM, {{CR52, 0, 7}, {CR54, 0, 2} } },
233 /* IGA2 Horizontal Blank End */
234 {IGA2_HOR_BLANK_END_REG_NUM,
235 {{CR53, 0, 7}, {CR54, 3, 5}, {CR5D, 6, 6} } },
236 /* IGA2 Horizontal Sync Start */
237 {IGA2_HOR_SYNC_START_REG_NUM,
238 {{CR56, 0, 7}, {CR54, 6, 7}, {CR5C, 7, 7}, {CR5D, 7, 7} } },
239 /* IGA2 Horizontal Sync End */
240 {IGA2_HOR_SYNC_END_REG_NUM, {{CR57, 0, 7}, {CR5C, 6, 6} } },
241 /* IGA2 Vertical Total */
242 {IGA2_VER_TOTAL_REG_NUM, {{CR58, 0, 7}, {CR5D, 0, 2} } },
243 /* IGA2 Vertical Addressable Video */
244 {IGA2_VER_ADDR_REG_NUM, {{CR59, 0, 7}, {CR5D, 3, 5} } },
245 /* IGA2 Vertical Blank Start */
246 {IGA2_VER_BLANK_START_REG_NUM, {{CR5A, 0, 7}, {CR5C, 0, 2} } },
247 /* IGA2 Vertical Blank End */
248 {IGA2_VER_BLANK_END_REG_NUM, {{CR5B, 0, 7}, {CR5C, 3, 5} } },
249 /* IGA2 Vertical Sync Start */
250 {IGA2_VER_SYNC_START_REG_NUM, {{CR5E, 0, 7}, {CR5F, 5, 7} } },
251 /* IGA2 Vertical Sync End */
252 {IGA2_VER_SYNC_END_REG_NUM, {{CR5F, 0, 4} } }
255 static struct rgbLUT palLUT_table[] = {
257 /* Index 0x00~0x03 */
258 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x2A}, {0x00, 0x2A, 0x00}, {0x00,
261 /* Index 0x04~0x07 */
262 {0x2A, 0x00, 0x00}, {0x2A, 0x00, 0x2A}, {0x2A, 0x15, 0x00}, {0x2A,
265 /* Index 0x08~0x0B */
266 {0x15, 0x15, 0x15}, {0x15, 0x15, 0x3F}, {0x15, 0x3F, 0x15}, {0x15,
269 /* Index 0x0C~0x0F */
270 {0x3F, 0x15, 0x15}, {0x3F, 0x15, 0x3F}, {0x3F, 0x3F, 0x15}, {0x3F,
273 /* Index 0x10~0x13 */
274 {0x00, 0x00, 0x00}, {0x05, 0x05, 0x05}, {0x08, 0x08, 0x08}, {0x0B,
277 /* Index 0x14~0x17 */
278 {0x0E, 0x0E, 0x0E}, {0x11, 0x11, 0x11}, {0x14, 0x14, 0x14}, {0x18,
281 /* Index 0x18~0x1B */
282 {0x1C, 0x1C, 0x1C}, {0x20, 0x20, 0x20}, {0x24, 0x24, 0x24}, {0x28,
285 /* Index 0x1C~0x1F */
286 {0x2D, 0x2D, 0x2D}, {0x32, 0x32, 0x32}, {0x38, 0x38, 0x38}, {0x3F,
289 /* Index 0x20~0x23 */
290 {0x00, 0x00, 0x3F}, {0x10, 0x00, 0x3F}, {0x1F, 0x00, 0x3F}, {0x2F,
293 /* Index 0x24~0x27 */
294 {0x3F, 0x00, 0x3F}, {0x3F, 0x00, 0x2F}, {0x3F, 0x00, 0x1F}, {0x3F,
297 /* Index 0x28~0x2B */
298 {0x3F, 0x00, 0x00}, {0x3F, 0x10, 0x00}, {0x3F, 0x1F, 0x00}, {0x3F,
301 /* Index 0x2C~0x2F */
302 {0x3F, 0x3F, 0x00}, {0x2F, 0x3F, 0x00}, {0x1F, 0x3F, 0x00}, {0x10,
305 /* Index 0x30~0x33 */
306 {0x00, 0x3F, 0x00}, {0x00, 0x3F, 0x10}, {0x00, 0x3F, 0x1F}, {0x00,
309 /* Index 0x34~0x37 */
310 {0x00, 0x3F, 0x3F}, {0x00, 0x2F, 0x3F}, {0x00, 0x1F, 0x3F}, {0x00,
313 /* Index 0x38~0x3B */
314 {0x1F, 0x1F, 0x3F}, {0x27, 0x1F, 0x3F}, {0x2F, 0x1F, 0x3F}, {0x37,
317 /* Index 0x3C~0x3F */
318 {0x3F, 0x1F, 0x3F}, {0x3F, 0x1F, 0x37}, {0x3F, 0x1F, 0x2F}, {0x3F,
321 /* Index 0x40~0x43 */
322 {0x3F, 0x1F, 0x1F}, {0x3F, 0x27, 0x1F}, {0x3F, 0x2F, 0x1F}, {0x3F,
325 /* Index 0x44~0x47 */
326 {0x3F, 0x3F, 0x1F}, {0x37, 0x3F, 0x1F}, {0x2F, 0x3F, 0x1F}, {0x27,
329 /* Index 0x48~0x4B */
330 {0x1F, 0x3F, 0x1F}, {0x1F, 0x3F, 0x27}, {0x1F, 0x3F, 0x2F}, {0x1F,
333 /* Index 0x4C~0x4F */
334 {0x1F, 0x3F, 0x3F}, {0x1F, 0x37, 0x3F}, {0x1F, 0x2F, 0x3F}, {0x1F,
337 /* Index 0x50~0x53 */
338 {0x2D, 0x2D, 0x3F}, {0x31, 0x2D, 0x3F}, {0x36, 0x2D, 0x3F}, {0x3A,
341 /* Index 0x54~0x57 */
342 {0x3F, 0x2D, 0x3F}, {0x3F, 0x2D, 0x3A}, {0x3F, 0x2D, 0x36}, {0x3F,
345 /* Index 0x58~0x5B */
346 {0x3F, 0x2D, 0x2D}, {0x3F, 0x31, 0x2D}, {0x3F, 0x36, 0x2D}, {0x3F,
349 /* Index 0x5C~0x5F */
350 {0x3F, 0x3F, 0x2D}, {0x3A, 0x3F, 0x2D}, {0x36, 0x3F, 0x2D}, {0x31,
353 /* Index 0x60~0x63 */
354 {0x2D, 0x3F, 0x2D}, {0x2D, 0x3F, 0x31}, {0x2D, 0x3F, 0x36}, {0x2D,
357 /* Index 0x64~0x67 */
358 {0x2D, 0x3F, 0x3F}, {0x2D, 0x3A, 0x3F}, {0x2D, 0x36, 0x3F}, {0x2D,
361 /* Index 0x68~0x6B */
362 {0x00, 0x00, 0x1C}, {0x07, 0x00, 0x1C}, {0x0E, 0x00, 0x1C}, {0x15,
365 /* Index 0x6C~0x6F */
366 {0x1C, 0x00, 0x1C}, {0x1C, 0x00, 0x15}, {0x1C, 0x00, 0x0E}, {0x1C,
369 /* Index 0x70~0x73 */
370 {0x1C, 0x00, 0x00}, {0x1C, 0x07, 0x00}, {0x1C, 0x0E, 0x00}, {0x1C,
373 /* Index 0x74~0x77 */
374 {0x1C, 0x1C, 0x00}, {0x15, 0x1C, 0x00}, {0x0E, 0x1C, 0x00}, {0x07,
377 /* Index 0x78~0x7B */
378 {0x00, 0x1C, 0x00}, {0x00, 0x1C, 0x07}, {0x00, 0x1C, 0x0E}, {0x00,
381 /* Index 0x7C~0x7F */
382 {0x00, 0x1C, 0x1C}, {0x00, 0x15, 0x1C}, {0x00, 0x0E, 0x1C}, {0x00,
385 /* Index 0x80~0x83 */
386 {0x0E, 0x0E, 0x1C}, {0x11, 0x0E, 0x1C}, {0x15, 0x0E, 0x1C}, {0x18,
389 /* Index 0x84~0x87 */
390 {0x1C, 0x0E, 0x1C}, {0x1C, 0x0E, 0x18}, {0x1C, 0x0E, 0x15}, {0x1C,
393 /* Index 0x88~0x8B */
394 {0x1C, 0x0E, 0x0E}, {0x1C, 0x11, 0x0E}, {0x1C, 0x15, 0x0E}, {0x1C,
397 /* Index 0x8C~0x8F */
398 {0x1C, 0x1C, 0x0E}, {0x18, 0x1C, 0x0E}, {0x15, 0x1C, 0x0E}, {0x11,
401 /* Index 0x90~0x93 */
402 {0x0E, 0x1C, 0x0E}, {0x0E, 0x1C, 0x11}, {0x0E, 0x1C, 0x15}, {0x0E,
405 /* Index 0x94~0x97 */
406 {0x0E, 0x1C, 0x1C}, {0x0E, 0x18, 0x1C}, {0x0E, 0x15, 0x1C}, {0x0E,
409 /* Index 0x98~0x9B */
410 {0x14, 0x14, 0x1C}, {0x16, 0x14, 0x1C}, {0x18, 0x14, 0x1C}, {0x1A,
413 /* Index 0x9C~0x9F */
414 {0x1C, 0x14, 0x1C}, {0x1C, 0x14, 0x1A}, {0x1C, 0x14, 0x18}, {0x1C,
417 /* Index 0xA0~0xA3 */
418 {0x1C, 0x14, 0x14}, {0x1C, 0x16, 0x14}, {0x1C, 0x18, 0x14}, {0x1C,
421 /* Index 0xA4~0xA7 */
422 {0x1C, 0x1C, 0x14}, {0x1A, 0x1C, 0x14}, {0x18, 0x1C, 0x14}, {0x16,
425 /* Index 0xA8~0xAB */
426 {0x14, 0x1C, 0x14}, {0x14, 0x1C, 0x16}, {0x14, 0x1C, 0x18}, {0x14,
429 /* Index 0xAC~0xAF */
430 {0x14, 0x1C, 0x1C}, {0x14, 0x1A, 0x1C}, {0x14, 0x18, 0x1C}, {0x14,
433 /* Index 0xB0~0xB3 */
434 {0x00, 0x00, 0x10}, {0x04, 0x00, 0x10}, {0x08, 0x00, 0x10}, {0x0C,
437 /* Index 0xB4~0xB7 */
438 {0x10, 0x00, 0x10}, {0x10, 0x00, 0x0C}, {0x10, 0x00, 0x08}, {0x10,
441 /* Index 0xB8~0xBB */
442 {0x10, 0x00, 0x00}, {0x10, 0x04, 0x00}, {0x10, 0x08, 0x00}, {0x10,
445 /* Index 0xBC~0xBF */
446 {0x10, 0x10, 0x00}, {0x0C, 0x10, 0x00}, {0x08, 0x10, 0x00}, {0x04,
449 /* Index 0xC0~0xC3 */
450 {0x00, 0x10, 0x00}, {0x00, 0x10, 0x04}, {0x00, 0x10, 0x08}, {0x00,
453 /* Index 0xC4~0xC7 */
454 {0x00, 0x10, 0x10}, {0x00, 0x0C, 0x10}, {0x00, 0x08, 0x10}, {0x00,
457 /* Index 0xC8~0xCB */
458 {0x08, 0x08, 0x10}, {0x0A, 0x08, 0x10}, {0x0C, 0x08, 0x10}, {0x0E,
461 /* Index 0xCC~0xCF */
462 {0x10, 0x08, 0x10}, {0x10, 0x08, 0x0E}, {0x10, 0x08, 0x0C}, {0x10,
465 /* Index 0xD0~0xD3 */
466 {0x10, 0x08, 0x08}, {0x10, 0x0A, 0x08}, {0x10, 0x0C, 0x08}, {0x10,
469 /* Index 0xD4~0xD7 */
470 {0x10, 0x10, 0x08}, {0x0E, 0x10, 0x08}, {0x0C, 0x10, 0x08}, {0x0A,
473 /* Index 0xD8~0xDB */
474 {0x08, 0x10, 0x08}, {0x08, 0x10, 0x0A}, {0x08, 0x10, 0x0C}, {0x08,
477 /* Index 0xDC~0xDF */
478 {0x08, 0x10, 0x10}, {0x08, 0x0E, 0x10}, {0x08, 0x0C, 0x10}, {0x08,
481 /* Index 0xE0~0xE3 */
482 {0x0B, 0x0B, 0x10}, {0x0C, 0x0B, 0x10}, {0x0D, 0x0B, 0x10}, {0x0F,
485 /* Index 0xE4~0xE7 */
486 {0x10, 0x0B, 0x10}, {0x10, 0x0B, 0x0F}, {0x10, 0x0B, 0x0D}, {0x10,
489 /* Index 0xE8~0xEB */
490 {0x10, 0x0B, 0x0B}, {0x10, 0x0C, 0x0B}, {0x10, 0x0D, 0x0B}, {0x10,
493 /* Index 0xEC~0xEF */
494 {0x10, 0x10, 0x0B}, {0x0F, 0x10, 0x0B}, {0x0D, 0x10, 0x0B}, {0x0C,
497 /* Index 0xF0~0xF3 */
498 {0x0B, 0x10, 0x0B}, {0x0B, 0x10, 0x0C}, {0x0B, 0x10, 0x0D}, {0x0B,
501 /* Index 0xF4~0xF7 */
502 {0x0B, 0x10, 0x10}, {0x0B, 0x0F, 0x10}, {0x0B, 0x0D, 0x10}, {0x0B,
505 /* Index 0xF8~0xFB */
506 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
509 /* Index 0xFC~0xFF */
510 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
515 static struct via_device_mapping device_mapping[] = {
516 {VIA_LDVP0, "LDVP0"},
517 {VIA_LDVP1, "LDVP1"},
521 {VIA_LVDS1, "LVDS1"},
525 /* structure with function pointers to support clock control */
526 static struct via_clock clock;
528 static void load_fix_bit_crtc_reg(void);
529 static void __devinit init_gfx_chip_info(int chip_type);
530 static void __devinit init_tmds_chip_info(void);
531 static void __devinit init_lvds_chip_info(void);
532 static void device_screen_off(void);
533 static void device_screen_on(void);
534 static void set_display_channel(void);
535 static void device_off(void);
536 static void device_on(void);
537 static void enable_second_display_channel(void);
538 static void disable_second_display_channel(void);
540 void viafb_lock_crt(void)
542 viafb_write_reg_mask(CR11, VIACR, BIT7, BIT7);
545 void viafb_unlock_crt(void)
547 viafb_write_reg_mask(CR11, VIACR, 0, BIT7);
548 viafb_write_reg_mask(CR47, VIACR, 0, BIT0);
551 static void write_dac_reg(u8 index, u8 r, u8 g, u8 b)
553 outb(index, LUT_INDEX_WRITE);
559 static u32 get_dvi_devices(int output_interface)
561 switch (output_interface) {
563 return VIA_DVP0 | VIA_LDVP0;
566 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
571 case INTERFACE_DFP_HIGH:
572 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
575 return VIA_LVDS2 | VIA_DVP0;
577 case INTERFACE_DFP_LOW:
578 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
581 return VIA_DVP1 | VIA_LVDS1;
590 static u32 get_lcd_devices(int output_interface)
592 switch (output_interface) {
599 case INTERFACE_DFP_HIGH:
600 return VIA_LVDS2 | VIA_DVP0;
602 case INTERFACE_DFP_LOW:
603 return VIA_LVDS1 | VIA_DVP1;
606 return VIA_LVDS1 | VIA_LVDS2;
608 case INTERFACE_LVDS0:
609 case INTERFACE_LVDS0LVDS1:
612 case INTERFACE_LVDS1:
619 /*Set IGA path for each device*/
620 void viafb_set_iga_path(void)
622 int crt_iga_path = 0;
624 if (viafb_SAMM_ON == 1) {
626 if (viafb_primary_dev == CRT_Device)
633 if (viafb_primary_dev == DVI_Device)
634 viaparinfo->tmds_setting_info->iga_path = IGA1;
636 viaparinfo->tmds_setting_info->iga_path = IGA2;
640 if (viafb_primary_dev == LCD_Device) {
642 (viaparinfo->chip_info->gfx_chip_name ==
645 lvds_setting_info->iga_path = IGA2;
648 tmds_setting_info->iga_path = IGA1;
651 lvds_setting_info->iga_path = IGA1;
653 viaparinfo->lvds_setting_info->iga_path = IGA2;
657 if (LCD2_Device == viafb_primary_dev)
658 viaparinfo->lvds_setting_info2->iga_path = IGA1;
660 viaparinfo->lvds_setting_info2->iga_path = IGA2;
665 if (viafb_CRT_ON && viafb_LCD_ON) {
667 viaparinfo->lvds_setting_info->iga_path = IGA2;
668 } else if (viafb_CRT_ON && viafb_DVI_ON) {
670 viaparinfo->tmds_setting_info->iga_path = IGA2;
671 } else if (viafb_LCD_ON && viafb_DVI_ON) {
672 viaparinfo->tmds_setting_info->iga_path = IGA1;
673 viaparinfo->lvds_setting_info->iga_path = IGA2;
674 } else if (viafb_LCD_ON && viafb_LCD2_ON) {
675 viaparinfo->lvds_setting_info->iga_path = IGA2;
676 viaparinfo->lvds_setting_info2->iga_path = IGA2;
677 } else if (viafb_CRT_ON) {
679 } else if (viafb_LCD_ON) {
680 viaparinfo->lvds_setting_info->iga_path = IGA2;
681 } else if (viafb_DVI_ON) {
682 viaparinfo->tmds_setting_info->iga_path = IGA1;
686 viaparinfo->shared->iga1_devices = 0;
687 viaparinfo->shared->iga2_devices = 0;
689 if (crt_iga_path == IGA1)
690 viaparinfo->shared->iga1_devices |= VIA_CRT;
692 viaparinfo->shared->iga2_devices |= VIA_CRT;
696 if (viaparinfo->tmds_setting_info->iga_path == IGA1)
697 viaparinfo->shared->iga1_devices |= get_dvi_devices(
698 viaparinfo->chip_info->
699 tmds_chip_info.output_interface);
701 viaparinfo->shared->iga2_devices |= get_dvi_devices(
702 viaparinfo->chip_info->
703 tmds_chip_info.output_interface);
707 if (viaparinfo->lvds_setting_info->iga_path == IGA1)
708 viaparinfo->shared->iga1_devices |= get_lcd_devices(
709 viaparinfo->chip_info->
710 lvds_chip_info.output_interface);
712 viaparinfo->shared->iga2_devices |= get_lcd_devices(
713 viaparinfo->chip_info->
714 lvds_chip_info.output_interface);
718 if (viaparinfo->lvds_setting_info2->iga_path == IGA1)
719 viaparinfo->shared->iga1_devices |= get_lcd_devices(
720 viaparinfo->chip_info->
721 lvds_chip_info2.output_interface);
723 viaparinfo->shared->iga2_devices |= get_lcd_devices(
724 viaparinfo->chip_info->
725 lvds_chip_info2.output_interface);
728 /* looks like the OLPC has its display wired to DVP1 and LVDS2 */
729 if (machine_is_olpc())
730 viaparinfo->shared->iga2_devices = VIA_DVP1 | VIA_LVDS2;
733 static void set_color_register(u8 index, u8 red, u8 green, u8 blue)
735 outb(0xFF, 0x3C6); /* bit mask of palette */
742 void viafb_set_primary_color_register(u8 index, u8 red, u8 green, u8 blue)
744 viafb_write_reg_mask(0x1A, VIASR, 0x00, 0x01);
745 set_color_register(index, red, green, blue);
748 void viafb_set_secondary_color_register(u8 index, u8 red, u8 green, u8 blue)
750 viafb_write_reg_mask(0x1A, VIASR, 0x01, 0x01);
751 set_color_register(index, red, green, blue);
754 static void set_source_common(u8 index, u8 offset, u8 iga)
756 u8 value, mask = 1 << offset;
766 printk(KERN_WARNING "viafb: Unsupported source: %d\n", iga);
770 via_write_reg_mask(VIACR, index, value, mask);
773 static void set_crt_source(u8 iga)
785 printk(KERN_WARNING "viafb: Unsupported source: %d\n", iga);
789 via_write_reg_mask(VIASR, 0x16, value, 0x40);
792 static inline void set_ldvp0_source(u8 iga)
794 set_source_common(0x6C, 7, iga);
797 static inline void set_ldvp1_source(u8 iga)
799 set_source_common(0x93, 7, iga);
802 static inline void set_dvp0_source(u8 iga)
804 set_source_common(0x96, 4, iga);
807 static inline void set_dvp1_source(u8 iga)
809 set_source_common(0x9B, 4, iga);
812 static inline void set_lvds1_source(u8 iga)
814 set_source_common(0x99, 4, iga);
817 static inline void set_lvds2_source(u8 iga)
819 set_source_common(0x97, 4, iga);
822 void via_set_source(u32 devices, u8 iga)
824 if (devices & VIA_LDVP0)
825 set_ldvp0_source(iga);
826 if (devices & VIA_LDVP1)
827 set_ldvp1_source(iga);
828 if (devices & VIA_DVP0)
829 set_dvp0_source(iga);
830 if (devices & VIA_CRT)
832 if (devices & VIA_DVP1)
833 set_dvp1_source(iga);
834 if (devices & VIA_LVDS1)
835 set_lvds1_source(iga);
836 if (devices & VIA_LVDS2)
837 set_lvds2_source(iga);
840 static void set_crt_state(u8 state)
848 case VIA_STATE_STANDBY:
851 case VIA_STATE_SUSPEND:
861 via_write_reg_mask(VIACR, 0x36, value, 0x30);
864 static void set_dvp0_state(u8 state)
879 via_write_reg_mask(VIASR, 0x1E, value, 0xC0);
882 static void set_dvp1_state(u8 state)
897 via_write_reg_mask(VIASR, 0x1E, value, 0x30);
900 static void set_lvds1_state(u8 state)
915 via_write_reg_mask(VIASR, 0x2A, value, 0x03);
918 static void set_lvds2_state(u8 state)
933 via_write_reg_mask(VIASR, 0x2A, value, 0x0C);
936 void via_set_state(u32 devices, u8 state)
939 TODO: Can we enable/disable these devices? How?
940 if (devices & VIA_LDVP0)
941 if (devices & VIA_LDVP1)
943 if (devices & VIA_DVP0)
944 set_dvp0_state(state);
945 if (devices & VIA_CRT)
946 set_crt_state(state);
947 if (devices & VIA_DVP1)
948 set_dvp1_state(state);
949 if (devices & VIA_LVDS1)
950 set_lvds1_state(state);
951 if (devices & VIA_LVDS2)
952 set_lvds2_state(state);
955 void via_set_sync_polarity(u32 devices, u8 polarity)
957 if (polarity & ~(VIA_HSYNC_NEGATIVE | VIA_VSYNC_NEGATIVE)) {
958 printk(KERN_WARNING "viafb: Unsupported polarity: %d\n",
963 if (devices & VIA_CRT)
964 via_write_misc_reg_mask(polarity << 6, 0xC0);
965 if (devices & VIA_DVP1)
966 via_write_reg_mask(VIACR, 0x9B, polarity << 5, 0x60);
967 if (devices & VIA_LVDS1)
968 via_write_reg_mask(VIACR, 0x99, polarity << 5, 0x60);
969 if (devices & VIA_LVDS2)
970 via_write_reg_mask(VIACR, 0x97, polarity << 5, 0x60);
973 u32 via_parse_odev(char *input, char **end)
982 for (i = 0; i < ARRAY_SIZE(device_mapping); i++) {
983 len = strlen(device_mapping[i].name);
984 if (!strncmp(ptr, device_mapping[i].name, len)) {
985 odev |= device_mapping[i].device;
999 void via_odev_to_seq(struct seq_file *m, u32 odev)
1003 for (i = 0; i < ARRAY_SIZE(device_mapping); i++) {
1004 if (odev & device_mapping[i].device) {
1008 seq_puts(m, device_mapping[i].name);
1016 static void load_fix_bit_crtc_reg(void)
1020 /* always set to 1 */
1021 viafb_write_reg_mask(CR03, VIACR, 0x80, BIT7);
1022 /* line compare should set all bits = 1 (extend modes) */
1023 viafb_write_reg_mask(CR35, VIACR, 0x10, BIT4);
1024 /* line compare should set all bits = 1 (extend modes) */
1025 viafb_write_reg_mask(CR33, VIACR, 0x06, BIT0 + BIT1 + BIT2);
1026 /*viafb_write_reg_mask(CR32, VIACR, 0x01, BIT0); */
1030 /* If K8M800, enable Prefetch Mode. */
1031 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800)
1032 || (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890))
1033 viafb_write_reg_mask(CR33, VIACR, 0x08, BIT3);
1034 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
1035 && (viaparinfo->chip_info->gfx_chip_revision == CLE266_REVISION_AX))
1036 viafb_write_reg_mask(SR1A, VIASR, 0x02, BIT1);
1040 void viafb_load_reg(int timing_value, int viafb_load_reg_num,
1041 struct io_register *reg,
1049 int start_index, end_index, cr_index;
1052 for (i = 0; i < viafb_load_reg_num; i++) {
1055 start_index = reg[i].start_bit;
1056 end_index = reg[i].end_bit;
1057 cr_index = reg[i].io_addr;
1059 shift_next_reg = bit_num;
1060 for (j = start_index; j <= end_index; j++) {
1061 /*if (bit_num==8) timing_value = timing_value >>8; */
1062 reg_mask = reg_mask | (BIT0 << j);
1063 get_bit = (timing_value & (BIT0 << bit_num));
1065 data | ((get_bit >> shift_next_reg) << start_index);
1068 if (io_type == VIACR)
1069 viafb_write_reg_mask(cr_index, VIACR, data, reg_mask);
1071 viafb_write_reg_mask(cr_index, VIASR, data, reg_mask);
1076 /* Write Registers */
1077 void viafb_write_regx(struct io_reg RegTable[], int ItemNum)
1081 /*DEBUG_MSG(KERN_INFO "Table Size : %x!!\n",ItemNum ); */
1083 for (i = 0; i < ItemNum; i++)
1084 via_write_reg_mask(RegTable[i].port, RegTable[i].index,
1085 RegTable[i].value, RegTable[i].mask);
1088 void viafb_load_fetch_count_reg(int h_addr, int bpp_byte, int set_iga)
1091 int viafb_load_reg_num;
1092 struct io_register *reg = NULL;
1096 reg_value = IGA1_FETCH_COUNT_FORMULA(h_addr, bpp_byte);
1097 viafb_load_reg_num = fetch_count_reg.
1098 iga1_fetch_count_reg.reg_num;
1099 reg = fetch_count_reg.iga1_fetch_count_reg.reg;
1100 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1103 reg_value = IGA2_FETCH_COUNT_FORMULA(h_addr, bpp_byte);
1104 viafb_load_reg_num = fetch_count_reg.
1105 iga2_fetch_count_reg.reg_num;
1106 reg = fetch_count_reg.iga2_fetch_count_reg.reg;
1107 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1113 void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active)
1116 int viafb_load_reg_num;
1117 struct io_register *reg = NULL;
1118 int iga1_fifo_max_depth = 0, iga1_fifo_threshold =
1119 0, iga1_fifo_high_threshold = 0, iga1_display_queue_expire_num = 0;
1120 int iga2_fifo_max_depth = 0, iga2_fifo_threshold =
1121 0, iga2_fifo_high_threshold = 0, iga2_display_queue_expire_num = 0;
1123 if (set_iga == IGA1) {
1124 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
1125 iga1_fifo_max_depth = K800_IGA1_FIFO_MAX_DEPTH;
1126 iga1_fifo_threshold = K800_IGA1_FIFO_THRESHOLD;
1127 iga1_fifo_high_threshold =
1128 K800_IGA1_FIFO_HIGH_THRESHOLD;
1129 /* If resolution > 1280x1024, expire length = 64, else
1130 expire length = 128 */
1131 if ((hor_active > 1280) && (ver_active > 1024))
1132 iga1_display_queue_expire_num = 16;
1134 iga1_display_queue_expire_num =
1135 K800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1139 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_PM800) {
1140 iga1_fifo_max_depth = P880_IGA1_FIFO_MAX_DEPTH;
1141 iga1_fifo_threshold = P880_IGA1_FIFO_THRESHOLD;
1142 iga1_fifo_high_threshold =
1143 P880_IGA1_FIFO_HIGH_THRESHOLD;
1144 iga1_display_queue_expire_num =
1145 P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1147 /* If resolution > 1280x1024, expire length = 64, else
1148 expire length = 128 */
1149 if ((hor_active > 1280) && (ver_active > 1024))
1150 iga1_display_queue_expire_num = 16;
1152 iga1_display_queue_expire_num =
1153 P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1156 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CN700) {
1157 iga1_fifo_max_depth = CN700_IGA1_FIFO_MAX_DEPTH;
1158 iga1_fifo_threshold = CN700_IGA1_FIFO_THRESHOLD;
1159 iga1_fifo_high_threshold =
1160 CN700_IGA1_FIFO_HIGH_THRESHOLD;
1162 /* If resolution > 1280x1024, expire length = 64,
1163 else expire length = 128 */
1164 if ((hor_active > 1280) && (ver_active > 1024))
1165 iga1_display_queue_expire_num = 16;
1167 iga1_display_queue_expire_num =
1168 CN700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1171 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1172 iga1_fifo_max_depth = CX700_IGA1_FIFO_MAX_DEPTH;
1173 iga1_fifo_threshold = CX700_IGA1_FIFO_THRESHOLD;
1174 iga1_fifo_high_threshold =
1175 CX700_IGA1_FIFO_HIGH_THRESHOLD;
1176 iga1_display_queue_expire_num =
1177 CX700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1180 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890) {
1181 iga1_fifo_max_depth = K8M890_IGA1_FIFO_MAX_DEPTH;
1182 iga1_fifo_threshold = K8M890_IGA1_FIFO_THRESHOLD;
1183 iga1_fifo_high_threshold =
1184 K8M890_IGA1_FIFO_HIGH_THRESHOLD;
1185 iga1_display_queue_expire_num =
1186 K8M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1189 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M890) {
1190 iga1_fifo_max_depth = P4M890_IGA1_FIFO_MAX_DEPTH;
1191 iga1_fifo_threshold = P4M890_IGA1_FIFO_THRESHOLD;
1192 iga1_fifo_high_threshold =
1193 P4M890_IGA1_FIFO_HIGH_THRESHOLD;
1194 iga1_display_queue_expire_num =
1195 P4M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1198 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M900) {
1199 iga1_fifo_max_depth = P4M900_IGA1_FIFO_MAX_DEPTH;
1200 iga1_fifo_threshold = P4M900_IGA1_FIFO_THRESHOLD;
1201 iga1_fifo_high_threshold =
1202 P4M900_IGA1_FIFO_HIGH_THRESHOLD;
1203 iga1_display_queue_expire_num =
1204 P4M900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1207 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX800) {
1208 iga1_fifo_max_depth = VX800_IGA1_FIFO_MAX_DEPTH;
1209 iga1_fifo_threshold = VX800_IGA1_FIFO_THRESHOLD;
1210 iga1_fifo_high_threshold =
1211 VX800_IGA1_FIFO_HIGH_THRESHOLD;
1212 iga1_display_queue_expire_num =
1213 VX800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1216 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX855) {
1217 iga1_fifo_max_depth = VX855_IGA1_FIFO_MAX_DEPTH;
1218 iga1_fifo_threshold = VX855_IGA1_FIFO_THRESHOLD;
1219 iga1_fifo_high_threshold =
1220 VX855_IGA1_FIFO_HIGH_THRESHOLD;
1221 iga1_display_queue_expire_num =
1222 VX855_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1225 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX900) {
1226 iga1_fifo_max_depth = VX900_IGA1_FIFO_MAX_DEPTH;
1227 iga1_fifo_threshold = VX900_IGA1_FIFO_THRESHOLD;
1228 iga1_fifo_high_threshold =
1229 VX900_IGA1_FIFO_HIGH_THRESHOLD;
1230 iga1_display_queue_expire_num =
1231 VX900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1234 /* Set Display FIFO Depath Select */
1235 reg_value = IGA1_FIFO_DEPTH_SELECT_FORMULA(iga1_fifo_max_depth);
1236 viafb_load_reg_num =
1237 display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg_num;
1238 reg = display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg;
1239 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1241 /* Set Display FIFO Threshold Select */
1242 reg_value = IGA1_FIFO_THRESHOLD_FORMULA(iga1_fifo_threshold);
1243 viafb_load_reg_num =
1244 fifo_threshold_select_reg.
1245 iga1_fifo_threshold_select_reg.reg_num;
1247 fifo_threshold_select_reg.
1248 iga1_fifo_threshold_select_reg.reg;
1249 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1251 /* Set FIFO High Threshold Select */
1253 IGA1_FIFO_HIGH_THRESHOLD_FORMULA(iga1_fifo_high_threshold);
1254 viafb_load_reg_num =
1255 fifo_high_threshold_select_reg.
1256 iga1_fifo_high_threshold_select_reg.reg_num;
1258 fifo_high_threshold_select_reg.
1259 iga1_fifo_high_threshold_select_reg.reg;
1260 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1262 /* Set Display Queue Expire Num */
1264 IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
1265 (iga1_display_queue_expire_num);
1266 viafb_load_reg_num =
1267 display_queue_expire_num_reg.
1268 iga1_display_queue_expire_num_reg.reg_num;
1270 display_queue_expire_num_reg.
1271 iga1_display_queue_expire_num_reg.reg;
1272 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1275 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
1276 iga2_fifo_max_depth = K800_IGA2_FIFO_MAX_DEPTH;
1277 iga2_fifo_threshold = K800_IGA2_FIFO_THRESHOLD;
1278 iga2_fifo_high_threshold =
1279 K800_IGA2_FIFO_HIGH_THRESHOLD;
1281 /* If resolution > 1280x1024, expire length = 64,
1282 else expire length = 128 */
1283 if ((hor_active > 1280) && (ver_active > 1024))
1284 iga2_display_queue_expire_num = 16;
1286 iga2_display_queue_expire_num =
1287 K800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1290 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_PM800) {
1291 iga2_fifo_max_depth = P880_IGA2_FIFO_MAX_DEPTH;
1292 iga2_fifo_threshold = P880_IGA2_FIFO_THRESHOLD;
1293 iga2_fifo_high_threshold =
1294 P880_IGA2_FIFO_HIGH_THRESHOLD;
1296 /* If resolution > 1280x1024, expire length = 64,
1297 else expire length = 128 */
1298 if ((hor_active > 1280) && (ver_active > 1024))
1299 iga2_display_queue_expire_num = 16;
1301 iga2_display_queue_expire_num =
1302 P880_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1305 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CN700) {
1306 iga2_fifo_max_depth = CN700_IGA2_FIFO_MAX_DEPTH;
1307 iga2_fifo_threshold = CN700_IGA2_FIFO_THRESHOLD;
1308 iga2_fifo_high_threshold =
1309 CN700_IGA2_FIFO_HIGH_THRESHOLD;
1311 /* If resolution > 1280x1024, expire length = 64,
1312 else expire length = 128 */
1313 if ((hor_active > 1280) && (ver_active > 1024))
1314 iga2_display_queue_expire_num = 16;
1316 iga2_display_queue_expire_num =
1317 CN700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1320 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1321 iga2_fifo_max_depth = CX700_IGA2_FIFO_MAX_DEPTH;
1322 iga2_fifo_threshold = CX700_IGA2_FIFO_THRESHOLD;
1323 iga2_fifo_high_threshold =
1324 CX700_IGA2_FIFO_HIGH_THRESHOLD;
1325 iga2_display_queue_expire_num =
1326 CX700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1329 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890) {
1330 iga2_fifo_max_depth = K8M890_IGA2_FIFO_MAX_DEPTH;
1331 iga2_fifo_threshold = K8M890_IGA2_FIFO_THRESHOLD;
1332 iga2_fifo_high_threshold =
1333 K8M890_IGA2_FIFO_HIGH_THRESHOLD;
1334 iga2_display_queue_expire_num =
1335 K8M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1338 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M890) {
1339 iga2_fifo_max_depth = P4M890_IGA2_FIFO_MAX_DEPTH;
1340 iga2_fifo_threshold = P4M890_IGA2_FIFO_THRESHOLD;
1341 iga2_fifo_high_threshold =
1342 P4M890_IGA2_FIFO_HIGH_THRESHOLD;
1343 iga2_display_queue_expire_num =
1344 P4M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1347 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M900) {
1348 iga2_fifo_max_depth = P4M900_IGA2_FIFO_MAX_DEPTH;
1349 iga2_fifo_threshold = P4M900_IGA2_FIFO_THRESHOLD;
1350 iga2_fifo_high_threshold =
1351 P4M900_IGA2_FIFO_HIGH_THRESHOLD;
1352 iga2_display_queue_expire_num =
1353 P4M900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1356 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX800) {
1357 iga2_fifo_max_depth = VX800_IGA2_FIFO_MAX_DEPTH;
1358 iga2_fifo_threshold = VX800_IGA2_FIFO_THRESHOLD;
1359 iga2_fifo_high_threshold =
1360 VX800_IGA2_FIFO_HIGH_THRESHOLD;
1361 iga2_display_queue_expire_num =
1362 VX800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1365 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX855) {
1366 iga2_fifo_max_depth = VX855_IGA2_FIFO_MAX_DEPTH;
1367 iga2_fifo_threshold = VX855_IGA2_FIFO_THRESHOLD;
1368 iga2_fifo_high_threshold =
1369 VX855_IGA2_FIFO_HIGH_THRESHOLD;
1370 iga2_display_queue_expire_num =
1371 VX855_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1374 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX900) {
1375 iga2_fifo_max_depth = VX900_IGA2_FIFO_MAX_DEPTH;
1376 iga2_fifo_threshold = VX900_IGA2_FIFO_THRESHOLD;
1377 iga2_fifo_high_threshold =
1378 VX900_IGA2_FIFO_HIGH_THRESHOLD;
1379 iga2_display_queue_expire_num =
1380 VX900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1383 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
1384 /* Set Display FIFO Depath Select */
1386 IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth)
1388 /* Patch LCD in IGA2 case */
1389 viafb_load_reg_num =
1390 display_fifo_depth_reg.
1391 iga2_fifo_depth_select_reg.reg_num;
1393 display_fifo_depth_reg.
1394 iga2_fifo_depth_select_reg.reg;
1395 viafb_load_reg(reg_value,
1396 viafb_load_reg_num, reg, VIACR);
1399 /* Set Display FIFO Depath Select */
1401 IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth);
1402 viafb_load_reg_num =
1403 display_fifo_depth_reg.
1404 iga2_fifo_depth_select_reg.reg_num;
1406 display_fifo_depth_reg.
1407 iga2_fifo_depth_select_reg.reg;
1408 viafb_load_reg(reg_value,
1409 viafb_load_reg_num, reg, VIACR);
1412 /* Set Display FIFO Threshold Select */
1413 reg_value = IGA2_FIFO_THRESHOLD_FORMULA(iga2_fifo_threshold);
1414 viafb_load_reg_num =
1415 fifo_threshold_select_reg.
1416 iga2_fifo_threshold_select_reg.reg_num;
1418 fifo_threshold_select_reg.
1419 iga2_fifo_threshold_select_reg.reg;
1420 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1422 /* Set FIFO High Threshold Select */
1424 IGA2_FIFO_HIGH_THRESHOLD_FORMULA(iga2_fifo_high_threshold);
1425 viafb_load_reg_num =
1426 fifo_high_threshold_select_reg.
1427 iga2_fifo_high_threshold_select_reg.reg_num;
1429 fifo_high_threshold_select_reg.
1430 iga2_fifo_high_threshold_select_reg.reg;
1431 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1433 /* Set Display Queue Expire Num */
1435 IGA2_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
1436 (iga2_display_queue_expire_num);
1437 viafb_load_reg_num =
1438 display_queue_expire_num_reg.
1439 iga2_display_queue_expire_num_reg.reg_num;
1441 display_queue_expire_num_reg.
1442 iga2_display_queue_expire_num_reg.reg;
1443 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1449 static struct via_pll_config get_pll_config(struct pll_limit *limits, int size,
1452 struct via_pll_config cur, up, down, best = {0, 1, 0};
1453 const u32 f0 = 14318180; /* X1 frequency */
1456 for (i = 0; i < size; i++) {
1457 cur.rshift = limits[i].rshift;
1458 cur.divisor = limits[i].divisor;
1459 cur.multiplier = clk / ((f0 / cur.divisor)>>cur.rshift);
1460 f = abs(get_pll_output_frequency(f0, cur) - clk);
1464 if (abs(get_pll_output_frequency(f0, up) - clk) < f)
1466 else if (abs(get_pll_output_frequency(f0, down) - clk) < f)
1469 if (cur.multiplier < limits[i].multiplier_min)
1470 cur.multiplier = limits[i].multiplier_min;
1471 else if (cur.multiplier > limits[i].multiplier_max)
1472 cur.multiplier = limits[i].multiplier_max;
1474 f = abs(get_pll_output_frequency(f0, cur) - clk);
1475 if (f < abs(get_pll_output_frequency(f0, best) - clk))
1482 static struct via_pll_config get_best_pll_config(int clk)
1484 struct via_pll_config config;
1486 switch (viaparinfo->chip_info->gfx_chip_name) {
1487 case UNICHROME_CLE266:
1488 case UNICHROME_K400:
1489 config = get_pll_config(cle266_pll_limits,
1490 ARRAY_SIZE(cle266_pll_limits), clk);
1492 case UNICHROME_K800:
1493 case UNICHROME_PM800:
1494 case UNICHROME_CN700:
1495 config = get_pll_config(k800_pll_limits,
1496 ARRAY_SIZE(k800_pll_limits), clk);
1498 case UNICHROME_CX700:
1499 case UNICHROME_CN750:
1500 case UNICHROME_K8M890:
1501 case UNICHROME_P4M890:
1502 case UNICHROME_P4M900:
1503 case UNICHROME_VX800:
1504 config = get_pll_config(cx700_pll_limits,
1505 ARRAY_SIZE(cx700_pll_limits), clk);
1507 case UNICHROME_VX855:
1508 case UNICHROME_VX900:
1509 config = get_pll_config(vx855_pll_limits,
1510 ARRAY_SIZE(vx855_pll_limits), clk);
1518 void viafb_set_vclock(u32 clk, int set_iga)
1520 struct via_pll_config config = get_best_pll_config(clk);
1522 if (set_iga == IGA1)
1523 clock.set_primary_pll(config);
1524 if (set_iga == IGA2)
1525 clock.set_secondary_pll(config);
1528 via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
1531 void viafb_load_crtc_timing(struct display_timing device_timing,
1535 int viafb_load_reg_num = 0;
1537 struct io_register *reg = NULL;
1541 for (i = 0; i < 12; i++) {
1542 if (set_iga == IGA1) {
1546 IGA1_HOR_TOTAL_FORMULA(device_timing.
1548 viafb_load_reg_num =
1549 iga1_crtc_reg.hor_total.reg_num;
1550 reg = iga1_crtc_reg.hor_total.reg;
1554 IGA1_HOR_ADDR_FORMULA(device_timing.
1556 viafb_load_reg_num =
1557 iga1_crtc_reg.hor_addr.reg_num;
1558 reg = iga1_crtc_reg.hor_addr.reg;
1560 case H_BLANK_START_INDEX:
1562 IGA1_HOR_BLANK_START_FORMULA
1563 (device_timing.hor_blank_start);
1564 viafb_load_reg_num =
1565 iga1_crtc_reg.hor_blank_start.reg_num;
1566 reg = iga1_crtc_reg.hor_blank_start.reg;
1568 case H_BLANK_END_INDEX:
1570 IGA1_HOR_BLANK_END_FORMULA
1571 (device_timing.hor_blank_start,
1572 device_timing.hor_blank_end);
1573 viafb_load_reg_num =
1574 iga1_crtc_reg.hor_blank_end.reg_num;
1575 reg = iga1_crtc_reg.hor_blank_end.reg;
1577 case H_SYNC_START_INDEX:
1579 IGA1_HOR_SYNC_START_FORMULA
1580 (device_timing.hor_sync_start);
1581 viafb_load_reg_num =
1582 iga1_crtc_reg.hor_sync_start.reg_num;
1583 reg = iga1_crtc_reg.hor_sync_start.reg;
1585 case H_SYNC_END_INDEX:
1587 IGA1_HOR_SYNC_END_FORMULA
1588 (device_timing.hor_sync_start,
1589 device_timing.hor_sync_end);
1590 viafb_load_reg_num =
1591 iga1_crtc_reg.hor_sync_end.reg_num;
1592 reg = iga1_crtc_reg.hor_sync_end.reg;
1596 IGA1_VER_TOTAL_FORMULA(device_timing.
1598 viafb_load_reg_num =
1599 iga1_crtc_reg.ver_total.reg_num;
1600 reg = iga1_crtc_reg.ver_total.reg;
1604 IGA1_VER_ADDR_FORMULA(device_timing.
1606 viafb_load_reg_num =
1607 iga1_crtc_reg.ver_addr.reg_num;
1608 reg = iga1_crtc_reg.ver_addr.reg;
1610 case V_BLANK_START_INDEX:
1612 IGA1_VER_BLANK_START_FORMULA
1613 (device_timing.ver_blank_start);
1614 viafb_load_reg_num =
1615 iga1_crtc_reg.ver_blank_start.reg_num;
1616 reg = iga1_crtc_reg.ver_blank_start.reg;
1618 case V_BLANK_END_INDEX:
1620 IGA1_VER_BLANK_END_FORMULA
1621 (device_timing.ver_blank_start,
1622 device_timing.ver_blank_end);
1623 viafb_load_reg_num =
1624 iga1_crtc_reg.ver_blank_end.reg_num;
1625 reg = iga1_crtc_reg.ver_blank_end.reg;
1627 case V_SYNC_START_INDEX:
1629 IGA1_VER_SYNC_START_FORMULA
1630 (device_timing.ver_sync_start);
1631 viafb_load_reg_num =
1632 iga1_crtc_reg.ver_sync_start.reg_num;
1633 reg = iga1_crtc_reg.ver_sync_start.reg;
1635 case V_SYNC_END_INDEX:
1637 IGA1_VER_SYNC_END_FORMULA
1638 (device_timing.ver_sync_start,
1639 device_timing.ver_sync_end);
1640 viafb_load_reg_num =
1641 iga1_crtc_reg.ver_sync_end.reg_num;
1642 reg = iga1_crtc_reg.ver_sync_end.reg;
1648 if (set_iga == IGA2) {
1652 IGA2_HOR_TOTAL_FORMULA(device_timing.
1654 viafb_load_reg_num =
1655 iga2_crtc_reg.hor_total.reg_num;
1656 reg = iga2_crtc_reg.hor_total.reg;
1660 IGA2_HOR_ADDR_FORMULA(device_timing.
1662 viafb_load_reg_num =
1663 iga2_crtc_reg.hor_addr.reg_num;
1664 reg = iga2_crtc_reg.hor_addr.reg;
1666 case H_BLANK_START_INDEX:
1668 IGA2_HOR_BLANK_START_FORMULA
1669 (device_timing.hor_blank_start);
1670 viafb_load_reg_num =
1671 iga2_crtc_reg.hor_blank_start.reg_num;
1672 reg = iga2_crtc_reg.hor_blank_start.reg;
1674 case H_BLANK_END_INDEX:
1676 IGA2_HOR_BLANK_END_FORMULA
1677 (device_timing.hor_blank_start,
1678 device_timing.hor_blank_end);
1679 viafb_load_reg_num =
1680 iga2_crtc_reg.hor_blank_end.reg_num;
1681 reg = iga2_crtc_reg.hor_blank_end.reg;
1683 case H_SYNC_START_INDEX:
1685 IGA2_HOR_SYNC_START_FORMULA
1686 (device_timing.hor_sync_start);
1687 if (UNICHROME_CN700 <=
1688 viaparinfo->chip_info->gfx_chip_name)
1689 viafb_load_reg_num =
1690 iga2_crtc_reg.hor_sync_start.
1693 viafb_load_reg_num = 3;
1694 reg = iga2_crtc_reg.hor_sync_start.reg;
1696 case H_SYNC_END_INDEX:
1698 IGA2_HOR_SYNC_END_FORMULA
1699 (device_timing.hor_sync_start,
1700 device_timing.hor_sync_end);
1701 viafb_load_reg_num =
1702 iga2_crtc_reg.hor_sync_end.reg_num;
1703 reg = iga2_crtc_reg.hor_sync_end.reg;
1707 IGA2_VER_TOTAL_FORMULA(device_timing.
1709 viafb_load_reg_num =
1710 iga2_crtc_reg.ver_total.reg_num;
1711 reg = iga2_crtc_reg.ver_total.reg;
1715 IGA2_VER_ADDR_FORMULA(device_timing.
1717 viafb_load_reg_num =
1718 iga2_crtc_reg.ver_addr.reg_num;
1719 reg = iga2_crtc_reg.ver_addr.reg;
1721 case V_BLANK_START_INDEX:
1723 IGA2_VER_BLANK_START_FORMULA
1724 (device_timing.ver_blank_start);
1725 viafb_load_reg_num =
1726 iga2_crtc_reg.ver_blank_start.reg_num;
1727 reg = iga2_crtc_reg.ver_blank_start.reg;
1729 case V_BLANK_END_INDEX:
1731 IGA2_VER_BLANK_END_FORMULA
1732 (device_timing.ver_blank_start,
1733 device_timing.ver_blank_end);
1734 viafb_load_reg_num =
1735 iga2_crtc_reg.ver_blank_end.reg_num;
1736 reg = iga2_crtc_reg.ver_blank_end.reg;
1738 case V_SYNC_START_INDEX:
1740 IGA2_VER_SYNC_START_FORMULA
1741 (device_timing.ver_sync_start);
1742 viafb_load_reg_num =
1743 iga2_crtc_reg.ver_sync_start.reg_num;
1744 reg = iga2_crtc_reg.ver_sync_start.reg;
1746 case V_SYNC_END_INDEX:
1748 IGA2_VER_SYNC_END_FORMULA
1749 (device_timing.ver_sync_start,
1750 device_timing.ver_sync_end);
1751 viafb_load_reg_num =
1752 iga2_crtc_reg.ver_sync_end.reg_num;
1753 reg = iga2_crtc_reg.ver_sync_end.reg;
1758 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1764 void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
1765 struct VideoModeTable *video_mode, int bpp_byte, int set_iga)
1767 struct display_timing crt_reg;
1771 u32 clock, refresh = viafb_refresh;
1773 if (viafb_SAMM_ON && set_iga == IGA2)
1774 refresh = viafb_refresh1;
1776 for (i = 0; i < video_mode->mode_array; i++) {
1779 if (crt_table[i].refresh_rate == refresh)
1783 crt_reg = crt_table[index].crtc;
1785 /* Mode 640x480 has border, but LCD/DFP didn't have border. */
1786 /* So we would delete border. */
1787 if ((viafb_LCD_ON | viafb_DVI_ON)
1788 && video_mode->crtc[0].crtc.hor_addr == 640
1789 && video_mode->crtc[0].crtc.ver_addr == 480
1791 /* The border is 8 pixels. */
1792 crt_reg.hor_blank_start = crt_reg.hor_blank_start - 8;
1794 /* Blanking time should add left and right borders. */
1795 crt_reg.hor_blank_end = crt_reg.hor_blank_end + 16;
1798 h_addr = crt_reg.hor_addr;
1799 v_addr = crt_reg.ver_addr;
1800 if (set_iga == IGA1) {
1802 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
1807 viafb_load_crtc_timing(crt_reg, IGA1);
1810 viafb_load_crtc_timing(crt_reg, IGA2);
1815 viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
1816 viafb_load_fetch_count_reg(h_addr, bpp_byte, set_iga);
1819 if ((viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
1820 && (viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400))
1821 viafb_load_FIFO_reg(set_iga, h_addr, v_addr);
1823 clock = crt_reg.hor_total * crt_reg.ver_total
1824 * crt_table[index].refresh_rate;
1825 viafb_set_vclock(clock, set_iga);
1829 void __devinit viafb_init_chip_info(int chip_type)
1831 via_clock_init(&clock, chip_type);
1832 init_gfx_chip_info(chip_type);
1833 init_tmds_chip_info();
1834 init_lvds_chip_info();
1836 /*Set IGA path for each device */
1837 viafb_set_iga_path();
1839 viaparinfo->lvds_setting_info->display_method = viafb_lcd_dsp_method;
1840 viaparinfo->lvds_setting_info->lcd_mode = viafb_lcd_mode;
1841 viaparinfo->lvds_setting_info2->display_method =
1842 viaparinfo->lvds_setting_info->display_method;
1843 viaparinfo->lvds_setting_info2->lcd_mode =
1844 viaparinfo->lvds_setting_info->lcd_mode;
1847 void viafb_update_device_setting(int hres, int vres, int bpp, int flag)
1850 viaparinfo->tmds_setting_info->h_active = hres;
1851 viaparinfo->tmds_setting_info->v_active = vres;
1853 viaparinfo->lvds_setting_info->h_active = hres;
1854 viaparinfo->lvds_setting_info->v_active = vres;
1855 viaparinfo->lvds_setting_info->bpp = bpp;
1856 viaparinfo->lvds_setting_info2->h_active = hres;
1857 viaparinfo->lvds_setting_info2->v_active = vres;
1858 viaparinfo->lvds_setting_info2->bpp = bpp;
1861 if (viaparinfo->tmds_setting_info->iga_path == IGA2) {
1862 viaparinfo->tmds_setting_info->h_active = hres;
1863 viaparinfo->tmds_setting_info->v_active = vres;
1866 if (viaparinfo->lvds_setting_info->iga_path == IGA2) {
1867 viaparinfo->lvds_setting_info->h_active = hres;
1868 viaparinfo->lvds_setting_info->v_active = vres;
1869 viaparinfo->lvds_setting_info->bpp = bpp;
1871 if (IGA2 == viaparinfo->lvds_setting_info2->iga_path) {
1872 viaparinfo->lvds_setting_info2->h_active = hres;
1873 viaparinfo->lvds_setting_info2->v_active = vres;
1874 viaparinfo->lvds_setting_info2->bpp = bpp;
1879 static void __devinit init_gfx_chip_info(int chip_type)
1883 viaparinfo->chip_info->gfx_chip_name = chip_type;
1885 /* Check revision of CLE266 Chip */
1886 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
1887 /* CR4F only define in CLE266.CX chip */
1888 tmp = viafb_read_reg(VIACR, CR4F);
1889 viafb_write_reg(CR4F, VIACR, 0x55);
1890 if (viafb_read_reg(VIACR, CR4F) != 0x55)
1891 viaparinfo->chip_info->gfx_chip_revision =
1894 viaparinfo->chip_info->gfx_chip_revision =
1896 /* restore orignal CR4F value */
1897 viafb_write_reg(CR4F, VIACR, tmp);
1900 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1901 tmp = viafb_read_reg(VIASR, SR43);
1902 DEBUG_MSG(KERN_INFO "SR43:%X\n", tmp);
1904 viaparinfo->chip_info->gfx_chip_revision =
1905 CX700_REVISION_700M2;
1906 } else if (tmp & 0x40) {
1907 viaparinfo->chip_info->gfx_chip_revision =
1908 CX700_REVISION_700M;
1910 viaparinfo->chip_info->gfx_chip_revision =
1915 /* Determine which 2D engine we have */
1916 switch (viaparinfo->chip_info->gfx_chip_name) {
1917 case UNICHROME_VX800:
1918 case UNICHROME_VX855:
1919 case UNICHROME_VX900:
1920 viaparinfo->chip_info->twod_engine = VIA_2D_ENG_M1;
1922 case UNICHROME_K8M890:
1923 case UNICHROME_P4M900:
1924 viaparinfo->chip_info->twod_engine = VIA_2D_ENG_H5;
1927 viaparinfo->chip_info->twod_engine = VIA_2D_ENG_H2;
1932 static void __devinit init_tmds_chip_info(void)
1934 viafb_tmds_trasmitter_identify();
1936 if (INTERFACE_NONE == viaparinfo->chip_info->tmds_chip_info.
1938 switch (viaparinfo->chip_info->gfx_chip_name) {
1939 case UNICHROME_CX700:
1941 /* we should check support by hardware layout.*/
1942 if ((viafb_display_hardware_layout ==
1944 || (viafb_display_hardware_layout ==
1945 HW_LAYOUT_LCD_DVI)) {
1946 viaparinfo->chip_info->tmds_chip_info.
1947 output_interface = INTERFACE_TMDS;
1949 viaparinfo->chip_info->tmds_chip_info.
1955 case UNICHROME_K8M890:
1956 case UNICHROME_P4M900:
1957 case UNICHROME_P4M890:
1958 /* TMDS on PCIE, we set DFPLOW as default. */
1959 viaparinfo->chip_info->tmds_chip_info.output_interface =
1964 /* set DVP1 default for DVI */
1965 viaparinfo->chip_info->tmds_chip_info
1966 .output_interface = INTERFACE_DVP1;
1971 DEBUG_MSG(KERN_INFO "TMDS Chip = %d\n",
1972 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name);
1973 viafb_init_dvi_size(&viaparinfo->shared->chip_info.tmds_chip_info,
1974 &viaparinfo->shared->tmds_setting_info);
1977 static void __devinit init_lvds_chip_info(void)
1979 viafb_lvds_trasmitter_identify();
1980 viafb_init_lcd_size();
1981 viafb_init_lvds_output_interface(&viaparinfo->chip_info->lvds_chip_info,
1982 viaparinfo->lvds_setting_info);
1983 if (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1984 viafb_init_lvds_output_interface(&viaparinfo->chip_info->
1985 lvds_chip_info2, viaparinfo->lvds_setting_info2);
1987 /*If CX700,two singel LCD, we need to reassign
1988 LCD interface to different LVDS port */
1989 if ((UNICHROME_CX700 == viaparinfo->chip_info->gfx_chip_name)
1990 && (HW_LAYOUT_LCD1_LCD2 == viafb_display_hardware_layout)) {
1991 if ((INTEGRATED_LVDS == viaparinfo->chip_info->lvds_chip_info.
1992 lvds_chip_name) && (INTEGRATED_LVDS ==
1993 viaparinfo->chip_info->
1994 lvds_chip_info2.lvds_chip_name)) {
1995 viaparinfo->chip_info->lvds_chip_info.output_interface =
1997 viaparinfo->chip_info->lvds_chip_info2.
2003 DEBUG_MSG(KERN_INFO "LVDS Chip = %d\n",
2004 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
2005 DEBUG_MSG(KERN_INFO "LVDS1 output_interface = %d\n",
2006 viaparinfo->chip_info->lvds_chip_info.output_interface);
2007 DEBUG_MSG(KERN_INFO "LVDS2 output_interface = %d\n",
2008 viaparinfo->chip_info->lvds_chip_info.output_interface);
2011 void __devinit viafb_init_dac(int set_iga)
2016 if (set_iga == IGA1) {
2017 /* access Primary Display's LUT */
2018 viafb_write_reg_mask(SR1A, VIASR, 0x00, BIT0);
2020 viafb_write_reg_mask(SR1B, VIASR, 0x00, BIT7 + BIT6);
2021 for (i = 0; i < 256; i++) {
2022 write_dac_reg(i, palLUT_table[i].red,
2023 palLUT_table[i].green,
2024 palLUT_table[i].blue);
2027 viafb_write_reg_mask(SR1B, VIASR, 0xC0, BIT7 + BIT6);
2029 tmp = viafb_read_reg(VIACR, CR6A);
2030 /* access Secondary Display's LUT */
2031 viafb_write_reg_mask(CR6A, VIACR, 0x40, BIT6);
2032 viafb_write_reg_mask(SR1A, VIASR, 0x01, BIT0);
2033 for (i = 0; i < 256; i++) {
2034 write_dac_reg(i, palLUT_table[i].red,
2035 palLUT_table[i].green,
2036 palLUT_table[i].blue);
2038 /* set IGA1 DAC for default */
2039 viafb_write_reg_mask(SR1A, VIASR, 0x00, BIT0);
2040 viafb_write_reg(CR6A, VIACR, tmp);
2044 static void device_screen_off(void)
2046 /* turn off CRT screen (IGA1) */
2047 viafb_write_reg_mask(SR01, VIASR, 0x20, BIT5);
2050 static void device_screen_on(void)
2052 /* turn on CRT screen (IGA1) */
2053 viafb_write_reg_mask(SR01, VIASR, 0x00, BIT5);
2056 static void set_display_channel(void)
2058 /*If viafb_LCD2_ON, on cx700, internal lvds's information
2059 is keeped on lvds_setting_info2 */
2060 if (viafb_LCD2_ON &&
2061 viaparinfo->lvds_setting_info2->device_lcd_dualedge) {
2062 /* For dual channel LCD: */
2063 /* Set to Dual LVDS channel. */
2064 viafb_write_reg_mask(CRD2, VIACR, 0x20, BIT4 + BIT5);
2065 } else if (viafb_LCD_ON && viafb_DVI_ON) {
2067 /* Set to LVDS1 + TMDS channel. */
2068 viafb_write_reg_mask(CRD2, VIACR, 0x10, BIT4 + BIT5);
2069 } else if (viafb_DVI_ON) {
2070 /* Set to single TMDS channel. */
2071 viafb_write_reg_mask(CRD2, VIACR, 0x30, BIT4 + BIT5);
2072 } else if (viafb_LCD_ON) {
2073 if (viaparinfo->lvds_setting_info->device_lcd_dualedge) {
2074 /* For dual channel LCD: */
2075 /* Set to Dual LVDS channel. */
2076 viafb_write_reg_mask(CRD2, VIACR, 0x20, BIT4 + BIT5);
2078 /* Set to LVDS0 + LVDS1 channel. */
2079 viafb_write_reg_mask(CRD2, VIACR, 0x00, BIT4 + BIT5);
2084 static u8 get_sync(struct fb_info *info)
2088 if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
2089 polarity |= VIA_HSYNC_NEGATIVE;
2090 if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
2091 polarity |= VIA_VSYNC_NEGATIVE;
2095 int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
2096 struct VideoModeTable *vmode_tbl1, int video_bpp1)
2100 u32 devices = viaparinfo->shared->iga1_devices
2101 | viaparinfo->shared->iga2_devices;
2102 u8 value, index, mask;
2103 struct crt_mode_table *crt_timing;
2104 struct crt_mode_table *crt_timing1 = NULL;
2106 device_screen_off();
2107 crt_timing = vmode_tbl->crtc;
2109 if (viafb_SAMM_ON == 1) {
2110 crt_timing1 = vmode_tbl1->crtc;
2116 /* Write Common Setting for Video Mode */
2117 viafb_write_regx(common_vga, ARRAY_SIZE(common_vga));
2118 switch (viaparinfo->chip_info->gfx_chip_name) {
2119 case UNICHROME_CLE266:
2120 viafb_write_regx(CLE266_ModeXregs, NUM_TOTAL_CLE266_ModeXregs);
2123 case UNICHROME_K400:
2124 viafb_write_regx(KM400_ModeXregs, NUM_TOTAL_KM400_ModeXregs);
2127 case UNICHROME_K800:
2128 case UNICHROME_PM800:
2129 viafb_write_regx(CN400_ModeXregs, NUM_TOTAL_CN400_ModeXregs);
2132 case UNICHROME_CN700:
2133 case UNICHROME_K8M890:
2134 case UNICHROME_P4M890:
2135 case UNICHROME_P4M900:
2136 viafb_write_regx(CN700_ModeXregs, NUM_TOTAL_CN700_ModeXregs);
2139 case UNICHROME_CX700:
2140 case UNICHROME_VX800:
2141 viafb_write_regx(CX700_ModeXregs, NUM_TOTAL_CX700_ModeXregs);
2144 case UNICHROME_VX855:
2145 case UNICHROME_VX900:
2146 viafb_write_regx(VX855_ModeXregs, NUM_TOTAL_VX855_ModeXregs);
2150 viafb_write_regx(scaling_parameters, ARRAY_SIZE(scaling_parameters));
2152 via_set_state(devices, VIA_STATE_OFF);
2154 /* Fill VPIT Parameters */
2155 /* Write Misc Register */
2156 outb(VPIT.Misc, VIA_MISC_REG_WRITE);
2158 /* Write Sequencer */
2159 for (i = 1; i <= StdSR; i++)
2160 via_write_reg(VIASR, i, VPIT.SR[i - 1]);
2162 viafb_write_reg_mask(0x15, VIASR, 0xA2, 0xA2);
2164 /* Write Graphic Controller */
2165 for (i = 0; i < StdGR; i++)
2166 via_write_reg(VIAGR, i, VPIT.GR[i]);
2168 /* Write Attribute Controller */
2169 for (i = 0; i < StdAR; i++) {
2172 outb(VPIT.AR[i], VIAAR);
2178 /* Update Patch Register */
2180 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266
2181 || viaparinfo->chip_info->gfx_chip_name == UNICHROME_K400)
2182 && vmode_tbl->crtc[0].crtc.hor_addr == 1024
2183 && vmode_tbl->crtc[0].crtc.ver_addr == 768) {
2184 for (j = 0; j < res_patch_table[0].table_length; j++) {
2185 index = res_patch_table[0].io_reg_table[j].index;
2186 port = res_patch_table[0].io_reg_table[j].port;
2187 value = res_patch_table[0].io_reg_table[j].value;
2188 mask = res_patch_table[0].io_reg_table[j].mask;
2189 viafb_write_reg_mask(index, port, value, mask);
2193 load_fix_bit_crtc_reg();
2194 via_set_primary_pitch(viafbinfo->fix.line_length);
2195 via_set_secondary_pitch(viafb_dual_fb ? viafbinfo1->fix.line_length
2196 : viafbinfo->fix.line_length);
2197 via_set_primary_color_depth(viaparinfo->depth);
2198 via_set_secondary_color_depth(viafb_dual_fb ? viaparinfo1->depth
2199 : viaparinfo->depth);
2200 via_set_source(viaparinfo->shared->iga1_devices, IGA1);
2201 via_set_source(viaparinfo->shared->iga2_devices, IGA2);
2202 if (viaparinfo->shared->iga2_devices)
2203 enable_second_display_channel();
2205 disable_second_display_channel();
2207 /* Update Refresh Rate Setting */
2209 /* Clear On Screen */
2213 if (viafb_SAMM_ON &&
2214 viaparinfo->shared->iga2_devices & VIA_CRT) {
2215 viafb_fill_crtc_timing(crt_timing1, vmode_tbl1,
2216 video_bpp1 / 8, IGA2);
2218 viafb_fill_crtc_timing(crt_timing, vmode_tbl,
2220 (viaparinfo->shared->iga1_devices & VIA_CRT)
2224 /* Patch if set_hres is not 8 alignment (1366) to viafb_setmode
2225 to 8 alignment (1368),there is several pixels (2 pixels)
2226 on right side of screen. */
2227 if (vmode_tbl->crtc[0].crtc.hor_addr % 8) {
2229 viafb_write_reg(CR02, VIACR,
2230 viafb_read_reg(VIACR, CR02) - 1);
2236 if (viafb_SAMM_ON &&
2237 (viaparinfo->tmds_setting_info->iga_path == IGA2)) {
2238 viafb_dvi_set_mode(viafb_get_mode
2239 (viaparinfo->tmds_setting_info->h_active,
2240 viaparinfo->tmds_setting_info->
2242 video_bpp1, viaparinfo->
2243 tmds_setting_info->iga_path);
2245 viafb_dvi_set_mode(viafb_get_mode
2246 (viaparinfo->tmds_setting_info->h_active,
2248 tmds_setting_info->v_active),
2249 video_bpp, viaparinfo->
2250 tmds_setting_info->iga_path);
2255 if (viafb_SAMM_ON &&
2256 (viaparinfo->lvds_setting_info->iga_path == IGA2)) {
2257 viaparinfo->lvds_setting_info->bpp = video_bpp1;
2258 viafb_lcd_set_mode(crt_timing1, viaparinfo->
2260 &viaparinfo->chip_info->lvds_chip_info);
2262 /* IGA1 doesn't have LCD scaling, so set it center. */
2263 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
2264 viaparinfo->lvds_setting_info->display_method =
2267 viaparinfo->lvds_setting_info->bpp = video_bpp;
2268 viafb_lcd_set_mode(crt_timing, viaparinfo->
2270 &viaparinfo->chip_info->lvds_chip_info);
2273 if (viafb_LCD2_ON) {
2274 if (viafb_SAMM_ON &&
2275 (viaparinfo->lvds_setting_info2->iga_path == IGA2)) {
2276 viaparinfo->lvds_setting_info2->bpp = video_bpp1;
2277 viafb_lcd_set_mode(crt_timing1, viaparinfo->
2279 &viaparinfo->chip_info->lvds_chip_info2);
2281 /* IGA1 doesn't have LCD scaling, so set it center. */
2282 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
2283 viaparinfo->lvds_setting_info2->display_method =
2286 viaparinfo->lvds_setting_info2->bpp = video_bpp;
2287 viafb_lcd_set_mode(crt_timing, viaparinfo->
2289 &viaparinfo->chip_info->lvds_chip_info2);
2293 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700)
2294 && (viafb_LCD_ON || viafb_DVI_ON))
2295 set_display_channel();
2297 /* If set mode normally, save resolution information for hot-plug . */
2298 if (!viafb_hotplug) {
2299 viafb_hotplug_Xres = vmode_tbl->crtc[0].crtc.hor_addr;
2300 viafb_hotplug_Yres = vmode_tbl->crtc[0].crtc.ver_addr;
2301 viafb_hotplug_bpp = video_bpp;
2302 viafb_hotplug_refresh = viafb_refresh;
2305 viafb_DeviceStatus = DVI_Device;
2307 viafb_DeviceStatus = CRT_Device;
2311 via_set_sync_polarity(devices, get_sync(viafbinfo));
2313 via_set_sync_polarity(viaparinfo->shared->iga1_devices,
2314 get_sync(viafbinfo));
2315 via_set_sync_polarity(viaparinfo->shared->iga2_devices,
2316 get_sync(viafbinfo1));
2319 clock.set_engine_pll_state(VIA_STATE_ON);
2320 clock.set_primary_clock_source(VIA_CLKSRC_X1, true);
2321 clock.set_secondary_clock_source(VIA_CLKSRC_X1, true);
2323 #ifdef CONFIG_FB_VIA_X_COMPATIBILITY
2324 clock.set_primary_pll_state(VIA_STATE_ON);
2325 clock.set_primary_clock_state(VIA_STATE_ON);
2326 clock.set_secondary_pll_state(VIA_STATE_ON);
2327 clock.set_secondary_clock_state(VIA_STATE_ON);
2329 if (viaparinfo->shared->iga1_devices) {
2330 clock.set_primary_pll_state(VIA_STATE_ON);
2331 clock.set_primary_clock_state(VIA_STATE_ON);
2333 clock.set_primary_pll_state(VIA_STATE_OFF);
2334 clock.set_primary_clock_state(VIA_STATE_OFF);
2337 if (viaparinfo->shared->iga2_devices) {
2338 clock.set_secondary_pll_state(VIA_STATE_ON);
2339 clock.set_secondary_clock_state(VIA_STATE_ON);
2341 clock.set_secondary_pll_state(VIA_STATE_OFF);
2342 clock.set_secondary_clock_state(VIA_STATE_OFF);
2344 #endif /*CONFIG_FB_VIA_X_COMPATIBILITY*/
2346 via_set_state(devices, VIA_STATE_ON);
2351 int viafb_get_pixclock(int hres, int vres, int vmode_refresh)
2354 struct crt_mode_table *best;
2355 struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
2358 return RES_640X480_60HZ_PIXCLOCK;
2360 best = &vmode->crtc[0];
2361 for (i = 1; i < vmode->mode_array; i++) {
2362 if (abs(vmode->crtc[i].refresh_rate - vmode_refresh)
2363 < abs(best->refresh_rate - vmode_refresh))
2364 best = &vmode->crtc[i];
2367 return 1000000000 / (best->crtc.hor_total * best->crtc.ver_total)
2368 * 1000 / best->refresh_rate;
2371 int viafb_get_refresh(int hres, int vres, u32 long_refresh)
2374 struct crt_mode_table *best;
2375 struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
2380 best = &vmode->crtc[0];
2381 for (i = 1; i < vmode->mode_array; i++) {
2382 if (abs(vmode->crtc[i].refresh_rate - long_refresh)
2383 < abs(best->refresh_rate - long_refresh))
2384 best = &vmode->crtc[i];
2387 if (abs(best->refresh_rate - long_refresh) > 3) {
2388 if (hres == 1200 && vres == 900)
2389 return 49; /* OLPC DCON only supports 50 Hz */
2394 return best->refresh_rate;
2397 static void device_off(void)
2399 viafb_dvi_disable();
2400 viafb_lcd_disable();
2403 static void device_on(void)
2405 if (viafb_DVI_ON == 1)
2407 if (viafb_LCD_ON == 1)
2411 static void enable_second_display_channel(void)
2413 /* to enable second display channel. */
2414 viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT6);
2415 viafb_write_reg_mask(CR6A, VIACR, BIT7, BIT7);
2416 viafb_write_reg_mask(CR6A, VIACR, BIT6, BIT6);
2419 static void disable_second_display_channel(void)
2421 /* to disable second display channel. */
2422 viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT6);
2423 viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT7);
2424 viafb_write_reg_mask(CR6A, VIACR, BIT6, BIT6);
2427 void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
2430 switch (output_interface) {
2431 case INTERFACE_DVP0:
2433 /* DVP0 Clock Polarity and Adjust: */
2434 viafb_write_reg_mask(CR96, VIACR,
2435 p_gfx_dpa_setting->DVP0, 0x0F);
2437 /* DVP0 Clock and Data Pads Driving: */
2438 viafb_write_reg_mask(SR1E, VIASR,
2439 p_gfx_dpa_setting->DVP0ClockDri_S, BIT2);
2440 viafb_write_reg_mask(SR2A, VIASR,
2441 p_gfx_dpa_setting->DVP0ClockDri_S1,
2443 viafb_write_reg_mask(SR1B, VIASR,
2444 p_gfx_dpa_setting->DVP0DataDri_S, BIT1);
2445 viafb_write_reg_mask(SR2A, VIASR,
2446 p_gfx_dpa_setting->DVP0DataDri_S1, BIT5);
2450 case INTERFACE_DVP1:
2452 /* DVP1 Clock Polarity and Adjust: */
2453 viafb_write_reg_mask(CR9B, VIACR,
2454 p_gfx_dpa_setting->DVP1, 0x0F);
2456 /* DVP1 Clock and Data Pads Driving: */
2457 viafb_write_reg_mask(SR65, VIASR,
2458 p_gfx_dpa_setting->DVP1Driving, 0x0F);
2462 case INTERFACE_DFP_HIGH:
2464 viafb_write_reg_mask(CR97, VIACR,
2465 p_gfx_dpa_setting->DFPHigh, 0x0F);
2469 case INTERFACE_DFP_LOW:
2471 viafb_write_reg_mask(CR99, VIACR,
2472 p_gfx_dpa_setting->DFPLow, 0x0F);
2478 viafb_write_reg_mask(CR97, VIACR,
2479 p_gfx_dpa_setting->DFPHigh, 0x0F);
2480 viafb_write_reg_mask(CR99, VIACR,
2481 p_gfx_dpa_setting->DFPLow, 0x0F);
2487 /*According var's xres, yres fill var's other timing information*/
2488 void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
2489 struct VideoModeTable *vmode_tbl)
2491 struct crt_mode_table *crt_timing = NULL;
2492 struct display_timing crt_reg;
2493 int i = 0, index = 0;
2494 crt_timing = vmode_tbl->crtc;
2495 for (i = 0; i < vmode_tbl->mode_array; i++) {
2497 if (crt_timing[i].refresh_rate == refresh)
2501 crt_reg = crt_timing[index].crtc;
2502 var->pixclock = viafb_get_pixclock(var->xres, var->yres, refresh);
2504 crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end);
2505 var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr;
2506 var->hsync_len = crt_reg.hor_sync_end;
2508 crt_reg.ver_total - (crt_reg.ver_sync_start + crt_reg.ver_sync_end);
2509 var->lower_margin = crt_reg.ver_sync_start - crt_reg.ver_addr;
2510 var->vsync_len = crt_reg.ver_sync_end;
2512 if (crt_timing[index].h_sync_polarity == POSITIVE)
2513 var->sync |= FB_SYNC_HOR_HIGH_ACT;
2514 if (crt_timing[index].v_sync_polarity == POSITIVE)
2515 var->sync |= FB_SYNC_VERT_HIGH_ACT;