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.
21 #include <linux/via-core.h>
22 #include <linux/via_i2c.h>
25 #define viafb_compact_res(x, y) (((x)<<16)|(y))
27 /* CLE266 Software Power Sequence */
28 /* {Mask}, {Data}, {Delay} */
29 static const int PowerSequenceOn
[3][3] = {
30 {0x10, 0x08, 0x06}, {0x10, 0x08, 0x06}, {0x19, 0x1FE, 0x01}
32 static const int PowerSequenceOff
[3][3] = {
33 {0x06, 0x08, 0x10}, {0x00, 0x00, 0x00}, {0xD2, 0x19, 0x01}
36 static struct _lcd_scaling_factor lcd_scaling_factor
= {
37 /* LCD Horizontal Scaling Factor Register */
38 {LCD_HOR_SCALING_FACTOR_REG_NUM
,
39 {{CR9F
, 0, 1}, {CR77
, 0, 7}, {CR79
, 4, 5} } },
40 /* LCD Vertical Scaling Factor Register */
41 {LCD_VER_SCALING_FACTOR_REG_NUM
,
42 {{CR79
, 3, 3}, {CR78
, 0, 7}, {CR79
, 6, 7} } }
44 static struct _lcd_scaling_factor lcd_scaling_factor_CLE
= {
45 /* LCD Horizontal Scaling Factor Register */
46 {LCD_HOR_SCALING_FACTOR_REG_NUM_CLE
, {{CR77
, 0, 7}, {CR79
, 4, 5} } },
47 /* LCD Vertical Scaling Factor Register */
48 {LCD_VER_SCALING_FACTOR_REG_NUM_CLE
, {{CR78
, 0, 7}, {CR79
, 6, 7} } }
51 static bool lvds_identify_integratedlvds(void);
52 static void fp_id_to_vindex(int panel_id
);
53 static int lvds_register_read(int index
);
54 static void load_lcd_scaling(int set_hres
, int set_vres
, int panel_hres
,
56 static void lcd_patch_skew_dvp0(struct lvds_setting_information
58 struct lvds_chip_information
*plvds_chip_info
);
59 static void lcd_patch_skew_dvp1(struct lvds_setting_information
61 struct lvds_chip_information
*plvds_chip_info
);
62 static void lcd_patch_skew(struct lvds_setting_information
63 *plvds_setting_info
, struct lvds_chip_information
*plvds_chip_info
);
65 static void integrated_lvds_disable(struct lvds_setting_information
67 struct lvds_chip_information
*plvds_chip_info
);
68 static void integrated_lvds_enable(struct lvds_setting_information
70 struct lvds_chip_information
*plvds_chip_info
);
71 static void lcd_powersequence_off(void);
72 static void lcd_powersequence_on(void);
73 static void fill_lcd_format(void);
74 static void check_diport_of_integrated_lvds(
75 struct lvds_chip_information
*plvds_chip_info
,
76 struct lvds_setting_information
79 static inline bool check_lvds_chip(int device_id_subaddr
, int device_id
)
81 return lvds_register_read(device_id_subaddr
) == device_id
;
84 void viafb_init_lcd_size(void)
86 DEBUG_MSG(KERN_INFO
"viafb_init_lcd_size()\n");
88 fp_id_to_vindex(viafb_lcd_panel_id
);
89 viaparinfo
->lvds_setting_info2
->lcd_panel_hres
=
90 viaparinfo
->lvds_setting_info
->lcd_panel_hres
;
91 viaparinfo
->lvds_setting_info2
->lcd_panel_vres
=
92 viaparinfo
->lvds_setting_info
->lcd_panel_vres
;
93 viaparinfo
->lvds_setting_info2
->device_lcd_dualedge
=
94 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
;
95 viaparinfo
->lvds_setting_info2
->LCDDithering
=
96 viaparinfo
->lvds_setting_info
->LCDDithering
;
99 static bool lvds_identify_integratedlvds(void)
101 if (viafb_display_hardware_layout
== HW_LAYOUT_LCD_EXTERNAL_LCD2
) {
102 /* Two dual channel LCD (Internal LVDS + External LVDS): */
103 /* If we have an external LVDS, such as VT1636, we should
104 have its chip ID already. */
105 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
106 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
=
108 DEBUG_MSG(KERN_INFO
"Support two dual channel LVDS! "
109 "(Internal LVDS + External LVDS)\n");
111 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
113 DEBUG_MSG(KERN_INFO
"Not found external LVDS, "
114 "so can't support two dual channel LVDS!\n");
116 } else if (viafb_display_hardware_layout
== HW_LAYOUT_LCD1_LCD2
) {
117 /* Two single channel LCD (Internal LVDS + Internal LVDS): */
118 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
120 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
=
122 DEBUG_MSG(KERN_INFO
"Support two single channel LVDS! "
123 "(Internal LVDS + Internal LVDS)\n");
124 } else if (viafb_display_hardware_layout
!= HW_LAYOUT_DVI_ONLY
) {
125 /* If we have found external LVDS, just use it,
126 otherwise, we will use internal LVDS as default. */
127 if (!viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
128 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
130 DEBUG_MSG(KERN_INFO
"Found Integrated LVDS!\n");
133 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
134 NON_LVDS_TRANSMITTER
;
135 DEBUG_MSG(KERN_INFO
"Do not support LVDS!\n");
142 bool viafb_lvds_trasmitter_identify(void)
144 if (viafb_lvds_identify_vt1636(VIA_PORT_31
)) {
145 viaparinfo
->chip_info
->lvds_chip_info
.i2c_port
= VIA_PORT_31
;
147 "Found VIA VT1636 LVDS on port i2c 0x31\n");
149 if (viafb_lvds_identify_vt1636(VIA_PORT_2C
)) {
150 viaparinfo
->chip_info
->lvds_chip_info
.i2c_port
=
153 "Found VIA VT1636 LVDS on port gpio 0x2c\n");
157 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
)
158 lvds_identify_integratedlvds();
160 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
162 /* Check for VT1631: */
163 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
= VT1631_LVDS
;
164 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
=
165 VT1631_LVDS_I2C_ADDR
;
167 if (check_lvds_chip(VT1631_DEVICE_ID_REG
, VT1631_DEVICE_ID
)) {
168 DEBUG_MSG(KERN_INFO
"\n VT1631 LVDS ! \n");
169 DEBUG_MSG(KERN_INFO
"\n %2d",
170 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
171 DEBUG_MSG(KERN_INFO
"\n %2d",
172 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
176 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
177 NON_LVDS_TRANSMITTER
;
178 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
=
179 VT1631_LVDS_I2C_ADDR
;
183 static void fp_id_to_vindex(int panel_id
)
185 DEBUG_MSG(KERN_INFO
"fp_get_panel_id()\n");
187 if (panel_id
> LCD_PANEL_ID_MAXIMUM
)
188 viafb_lcd_panel_id
= panel_id
=
189 viafb_read_reg(VIACR
, CR3F
) & 0x0F;
193 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 640;
194 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 480;
195 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
196 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
199 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
200 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
201 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
202 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
205 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
206 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
207 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
208 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
211 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
212 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
213 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
214 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
217 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
218 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1024;
219 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
220 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
223 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1400;
224 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1050;
225 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
226 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
229 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1600;
230 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1200;
231 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
232 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
235 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
236 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 480;
237 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
238 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
241 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
242 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
243 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
244 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
247 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
248 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
249 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
250 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
253 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
254 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
255 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
256 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
259 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
260 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
261 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
262 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
265 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
266 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1024;
267 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
268 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
271 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1400;
272 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1050;
273 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
274 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
277 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1600;
278 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1200;
279 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
280 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
283 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1366;
284 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
285 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
286 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
289 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
290 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
291 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
292 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
295 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
296 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
297 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
298 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
301 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
302 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 800;
303 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
304 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
307 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1360;
308 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
309 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
310 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
313 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
314 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
315 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
316 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
319 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 480;
320 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 640;
321 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
322 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
325 /* OLPC XO-1.5 panel */
326 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1200;
327 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 900;
328 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
329 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
332 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
333 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
334 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
335 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
339 static int lvds_register_read(int index
)
343 viafb_i2c_readbyte(VIA_PORT_2C
,
344 (u8
) viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
,
349 static void load_lcd_scaling(int set_hres
, int set_vres
, int panel_hres
,
353 int viafb_load_reg_num
;
354 struct io_register
*reg
= NULL
;
356 DEBUG_MSG(KERN_INFO
"load_lcd_scaling()!!\n");
358 /* LCD Scaling Enable */
359 viafb_write_reg_mask(CR79
, VIACR
, 0x07, BIT0
+ BIT1
+ BIT2
);
361 /* Check if expansion for horizontal */
362 if (set_hres
< panel_hres
) {
363 /* Load Horizontal Scaling Factor */
364 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
365 case UNICHROME_CLE266
:
368 CLE266_LCD_HOR_SCF_FORMULA(set_hres
, panel_hres
);
370 lcd_scaling_factor_CLE
.lcd_hor_scaling_factor
.
372 reg
= lcd_scaling_factor_CLE
.lcd_hor_scaling_factor
.reg
;
373 viafb_load_reg(reg_value
,
374 viafb_load_reg_num
, reg
, VIACR
);
377 case UNICHROME_PM800
:
378 case UNICHROME_CN700
:
379 case UNICHROME_CX700
:
380 case UNICHROME_K8M890
:
381 case UNICHROME_P4M890
:
382 case UNICHROME_P4M900
:
383 case UNICHROME_CN750
:
384 case UNICHROME_VX800
:
385 case UNICHROME_VX855
:
386 case UNICHROME_VX900
:
388 K800_LCD_HOR_SCF_FORMULA(set_hres
, panel_hres
);
389 /* Horizontal scaling enabled */
390 viafb_write_reg_mask(CRA2
, VIACR
, 0xC0, BIT7
+ BIT6
);
392 lcd_scaling_factor
.lcd_hor_scaling_factor
.reg_num
;
393 reg
= lcd_scaling_factor
.lcd_hor_scaling_factor
.reg
;
394 viafb_load_reg(reg_value
,
395 viafb_load_reg_num
, reg
, VIACR
);
399 DEBUG_MSG(KERN_INFO
"Horizontal Scaling value = %d", reg_value
);
401 /* Horizontal scaling disabled */
402 viafb_write_reg_mask(CRA2
, VIACR
, 0x00, BIT7
);
405 /* Check if expansion for vertical */
406 if (set_vres
< panel_vres
) {
407 /* Load Vertical Scaling Factor */
408 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
409 case UNICHROME_CLE266
:
412 CLE266_LCD_VER_SCF_FORMULA(set_vres
, panel_vres
);
414 lcd_scaling_factor_CLE
.lcd_ver_scaling_factor
.
416 reg
= lcd_scaling_factor_CLE
.lcd_ver_scaling_factor
.reg
;
417 viafb_load_reg(reg_value
,
418 viafb_load_reg_num
, reg
, VIACR
);
421 case UNICHROME_PM800
:
422 case UNICHROME_CN700
:
423 case UNICHROME_CX700
:
424 case UNICHROME_K8M890
:
425 case UNICHROME_P4M890
:
426 case UNICHROME_P4M900
:
427 case UNICHROME_CN750
:
428 case UNICHROME_VX800
:
429 case UNICHROME_VX855
:
430 case UNICHROME_VX900
:
432 K800_LCD_VER_SCF_FORMULA(set_vres
, panel_vres
);
433 /* Vertical scaling enabled */
434 viafb_write_reg_mask(CRA2
, VIACR
, 0x08, BIT3
);
436 lcd_scaling_factor
.lcd_ver_scaling_factor
.reg_num
;
437 reg
= lcd_scaling_factor
.lcd_ver_scaling_factor
.reg
;
438 viafb_load_reg(reg_value
,
439 viafb_load_reg_num
, reg
, VIACR
);
443 DEBUG_MSG(KERN_INFO
"Vertical Scaling value = %d", reg_value
);
445 /* Vertical scaling disabled */
446 viafb_write_reg_mask(CRA2
, VIACR
, 0x00, BIT3
);
450 static void via_pitch_alignment_patch_lcd(int iga_path
, int hres
, int bpp
)
452 unsigned char cr13
, cr35
, cr65
, cr66
, cr67
;
453 unsigned long dwScreenPitch
= 0;
454 unsigned long dwPitch
;
456 dwPitch
= hres
* (bpp
>> 3);
457 if (dwPitch
& 0x1F) {
458 dwScreenPitch
= ((dwPitch
+ 31) & ~31) >> 3;
459 if (iga_path
== IGA2
) {
461 cr66
= (unsigned char)(dwScreenPitch
& 0xFF);
462 viafb_write_reg(CR66
, VIACR
, cr66
);
463 cr67
= viafb_read_reg(VIACR
, CR67
) & 0xFC;
466 char)((dwScreenPitch
& 0x300) >> 8);
467 viafb_write_reg(CR67
, VIACR
, cr67
);
471 cr67
= viafb_read_reg(VIACR
, CR67
) & 0xF3;
472 cr67
|= (unsigned char)((dwScreenPitch
& 0x600) >> 7);
473 viafb_write_reg(CR67
, VIACR
, cr67
);
474 cr65
= (unsigned char)((dwScreenPitch
>> 1) & 0xFF);
476 viafb_write_reg(CR65
, VIACR
, cr65
);
479 cr13
= (unsigned char)(dwScreenPitch
& 0xFF);
480 viafb_write_reg(CR13
, VIACR
, cr13
);
481 cr35
= viafb_read_reg(VIACR
, CR35
) & 0x1F;
484 char)((dwScreenPitch
& 0x700) >> 3);
485 viafb_write_reg(CR35
, VIACR
, cr35
);
490 static void lcd_patch_skew_dvp0(struct lvds_setting_information
492 struct lvds_chip_information
*plvds_chip_info
)
494 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
) {
495 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
496 case UNICHROME_P4M900
:
497 viafb_vt1636_patch_skew_on_vt3364(plvds_setting_info
,
500 case UNICHROME_P4M890
:
501 viafb_vt1636_patch_skew_on_vt3327(plvds_setting_info
,
507 static void lcd_patch_skew_dvp1(struct lvds_setting_information
509 struct lvds_chip_information
*plvds_chip_info
)
511 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
) {
512 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
513 case UNICHROME_CX700
:
514 viafb_vt1636_patch_skew_on_vt3324(plvds_setting_info
,
520 static void lcd_patch_skew(struct lvds_setting_information
521 *plvds_setting_info
, struct lvds_chip_information
*plvds_chip_info
)
523 DEBUG_MSG(KERN_INFO
"lcd_patch_skew\n");
524 switch (plvds_chip_info
->output_interface
) {
526 lcd_patch_skew_dvp0(plvds_setting_info
, plvds_chip_info
);
529 lcd_patch_skew_dvp1(plvds_setting_info
, plvds_chip_info
);
531 case INTERFACE_DFP_LOW
:
532 if (UNICHROME_P4M900
== viaparinfo
->chip_info
->gfx_chip_name
) {
533 viafb_write_reg_mask(CR99
, VIACR
, 0x08,
534 BIT0
+ BIT1
+ BIT2
+ BIT3
);
541 void viafb_lcd_set_mode(const struct fb_var_screeninfo
*var
, u16 cxres
,
542 u16 cyres
, struct lvds_setting_information
*plvds_setting_info
,
543 struct lvds_chip_information
*plvds_chip_info
)
545 int set_iga
= plvds_setting_info
->iga_path
;
546 int mode_bpp
= var
->bits_per_pixel
;
547 int set_hres
= cxres
? cxres
: var
->xres
;
548 int set_vres
= cyres
? cyres
: var
->yres
;
549 int panel_hres
= plvds_setting_info
->lcd_panel_hres
;
550 int panel_vres
= plvds_setting_info
->lcd_panel_vres
;
552 struct via_display_timing timing
;
553 struct fb_var_screeninfo panel_var
;
554 const struct fb_videomode
*mode_crt_table
, *panel_crt_table
;
556 DEBUG_MSG(KERN_INFO
"viafb_lcd_set_mode!!\n");
558 mode_crt_table
= viafb_get_best_mode(set_hres
, set_vres
, 60);
559 /* Get panel table Pointer */
560 panel_crt_table
= viafb_get_best_mode(panel_hres
, panel_vres
, 60);
561 viafb_fill_var_timing_info(&panel_var
, panel_crt_table
);
562 DEBUG_MSG(KERN_INFO
"bellow viafb_lcd_set_mode!!\n");
563 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
)
564 viafb_init_lvds_vt1636(plvds_setting_info
, plvds_chip_info
);
565 clock
= PICOS2KHZ(panel_crt_table
->pixclock
) * 1000;
566 plvds_setting_info
->vclk
= clock
;
568 if (set_iga
== IGA2
&& (set_hres
< panel_hres
|| set_vres
< panel_vres
)
569 && plvds_setting_info
->display_method
== LCD_EXPANDSION
) {
570 timing
= var_to_timing(&panel_var
, panel_hres
, panel_vres
);
571 load_lcd_scaling(set_hres
, set_vres
, panel_hres
, panel_vres
);
573 timing
= var_to_timing(&panel_var
, set_hres
, set_vres
);
575 /* disable scaling */
576 via_write_reg_mask(VIACR
, 0x79, 0x00,
581 via_set_primary_timing(&timing
);
582 else if (set_iga
== IGA2
)
583 via_set_secondary_timing(&timing
);
585 /* Fetch count for IGA2 only */
586 viafb_load_fetch_count_reg(set_hres
, mode_bpp
/ 8, set_iga
);
588 if ((viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_CLE266
)
589 && (viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_K400
))
590 viafb_load_FIFO_reg(set_iga
, set_hres
, set_vres
);
593 viafb_set_vclock(clock
, set_iga
);
594 lcd_patch_skew(plvds_setting_info
, plvds_chip_info
);
596 /* If K8M800, enable LCD Prefetch Mode. */
597 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
)
598 || (UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
))
599 viafb_write_reg_mask(CR6A
, VIACR
, 0x01, BIT0
);
601 /* Patch for non 32bit alignment mode */
602 via_pitch_alignment_patch_lcd(plvds_setting_info
->iga_path
, set_hres
,
603 var
->bits_per_pixel
);
606 static void integrated_lvds_disable(struct lvds_setting_information
608 struct lvds_chip_information
*plvds_chip_info
)
610 bool turn_off_first_powersequence
= false;
611 bool turn_off_second_powersequence
= false;
612 if (INTERFACE_LVDS0LVDS1
== plvds_chip_info
->output_interface
)
613 turn_off_first_powersequence
= true;
614 if (INTERFACE_LVDS0
== plvds_chip_info
->output_interface
)
615 turn_off_first_powersequence
= true;
616 if (INTERFACE_LVDS1
== plvds_chip_info
->output_interface
)
617 turn_off_second_powersequence
= true;
618 if (turn_off_second_powersequence
) {
619 /* Use second power sequence control: */
621 /* Turn off power sequence. */
622 viafb_write_reg_mask(CRD4
, VIACR
, 0, BIT1
);
624 /* Turn off back light. */
625 viafb_write_reg_mask(CRD3
, VIACR
, 0xC0, BIT6
+ BIT7
);
627 if (turn_off_first_powersequence
) {
628 /* Use first power sequence control: */
630 /* Turn off power sequence. */
631 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT3
);
633 /* Turn off back light. */
634 viafb_write_reg_mask(CR91
, VIACR
, 0xC0, BIT6
+ BIT7
);
637 /* Power off LVDS channel. */
638 switch (plvds_chip_info
->output_interface
) {
639 case INTERFACE_LVDS0
:
641 viafb_write_reg_mask(CRD2
, VIACR
, 0x80, BIT7
);
645 case INTERFACE_LVDS1
:
647 viafb_write_reg_mask(CRD2
, VIACR
, 0x40, BIT6
);
651 case INTERFACE_LVDS0LVDS1
:
653 viafb_write_reg_mask(CRD2
, VIACR
, 0xC0, BIT6
+ BIT7
);
659 static void integrated_lvds_enable(struct lvds_setting_information
661 struct lvds_chip_information
*plvds_chip_info
)
663 DEBUG_MSG(KERN_INFO
"integrated_lvds_enable, out_interface:%d\n",
664 plvds_chip_info
->output_interface
);
665 if (plvds_setting_info
->lcd_mode
== LCD_SPWG
)
666 viafb_write_reg_mask(CRD2
, VIACR
, 0x00, BIT0
+ BIT1
);
668 viafb_write_reg_mask(CRD2
, VIACR
, 0x03, BIT0
+ BIT1
);
670 switch (plvds_chip_info
->output_interface
) {
671 case INTERFACE_LVDS0LVDS1
:
672 case INTERFACE_LVDS0
:
673 /* Use first power sequence control: */
674 /* Use hardware control power sequence. */
675 viafb_write_reg_mask(CR91
, VIACR
, 0, BIT0
);
676 /* Turn on back light. */
677 viafb_write_reg_mask(CR91
, VIACR
, 0, BIT6
+ BIT7
);
678 /* Turn on hardware power sequence. */
679 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
681 case INTERFACE_LVDS1
:
682 /* Use second power sequence control: */
683 /* Use hardware control power sequence. */
684 viafb_write_reg_mask(CRD3
, VIACR
, 0, BIT0
);
685 /* Turn on back light. */
686 viafb_write_reg_mask(CRD3
, VIACR
, 0, BIT6
+ BIT7
);
687 /* Turn on hardware power sequence. */
688 viafb_write_reg_mask(CRD4
, VIACR
, 0x02, BIT1
);
692 /* Power on LVDS channel. */
693 switch (plvds_chip_info
->output_interface
) {
694 case INTERFACE_LVDS0
:
696 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT7
);
700 case INTERFACE_LVDS1
:
702 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT6
);
706 case INTERFACE_LVDS0LVDS1
:
708 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT6
+ BIT7
);
714 void viafb_lcd_disable(void)
717 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
718 lcd_powersequence_off();
720 viafb_write_reg_mask(SR1E
, VIASR
, 0x00, 0x30);
721 } else if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
723 && (INTEGRATED_LVDS
==
724 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
))
725 integrated_lvds_disable(viaparinfo
->lvds_setting_info
,
726 &viaparinfo
->chip_info
->lvds_chip_info2
);
727 if (INTEGRATED_LVDS
==
728 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
729 integrated_lvds_disable(viaparinfo
->lvds_setting_info
,
730 &viaparinfo
->chip_info
->lvds_chip_info
);
731 if (VT1636_LVDS
== viaparinfo
->chip_info
->
732 lvds_chip_info
.lvds_chip_name
)
733 viafb_disable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
734 &viaparinfo
->chip_info
->lvds_chip_info
);
735 } else if (VT1636_LVDS
==
736 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
737 viafb_disable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
738 &viaparinfo
->chip_info
->lvds_chip_info
);
741 viafb_write_reg_mask(SR3D
, VIASR
, 0x00, 0x20);
742 /* 24 bit DI data paht off */
743 viafb_write_reg_mask(CR91
, VIACR
, 0x80, 0x80);
746 /* Disable expansion bit */
747 viafb_write_reg_mask(CR79
, VIACR
, 0x00, 0x01);
748 /* Simultaneout disabled */
749 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, 0x08);
752 static void set_lcd_output_path(int set_iga
, int output_interface
)
754 switch (output_interface
) {
756 if ((UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
)
757 || (UNICHROME_P4M890
==
758 viaparinfo
->chip_info
->gfx_chip_name
))
759 viafb_write_reg_mask(CR97
, VIACR
, 0x84,
760 BIT7
+ BIT2
+ BIT1
+ BIT0
);
763 case INTERFACE_DFP_HIGH
:
764 case INTERFACE_DFP_LOW
:
766 viafb_write_reg(CR91
, VIACR
, 0x00);
771 void viafb_lcd_enable(void)
773 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, BIT3
);
774 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
775 set_lcd_output_path(viaparinfo
->lvds_setting_info
->iga_path
,
776 viaparinfo
->chip_info
->lvds_chip_info
.output_interface
);
778 set_lcd_output_path(viaparinfo
->lvds_setting_info2
->iga_path
,
779 viaparinfo
->chip_info
->
780 lvds_chip_info2
.output_interface
);
782 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
784 viafb_write_reg_mask(SR1E
, VIASR
, 0x30, 0x30);
785 lcd_powersequence_on();
786 } else if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
787 if (viafb_LCD2_ON
&& (INTEGRATED_LVDS
==
788 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
))
789 integrated_lvds_enable(viaparinfo
->lvds_setting_info2
, \
790 &viaparinfo
->chip_info
->lvds_chip_info2
);
791 if (INTEGRATED_LVDS
==
792 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
793 integrated_lvds_enable(viaparinfo
->lvds_setting_info
,
794 &viaparinfo
->chip_info
->lvds_chip_info
);
795 if (VT1636_LVDS
== viaparinfo
->chip_info
->
796 lvds_chip_info
.lvds_chip_name
)
797 viafb_enable_lvds_vt1636(viaparinfo
->
798 lvds_setting_info
, &viaparinfo
->chip_info
->
800 } else if (VT1636_LVDS
==
801 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
802 viafb_enable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
803 &viaparinfo
->chip_info
->lvds_chip_info
);
806 viafb_write_reg_mask(SR3D
, VIASR
, 0x20, 0x20);
807 /* 24 bit DI data paht on */
808 viafb_write_reg_mask(CR91
, VIACR
, 0x00, 0x80);
810 viafb_write_reg_mask(CR6A
, VIACR
, 0x48, 0x48);
814 static void lcd_powersequence_off(void)
818 /* Software control power sequence */
819 viafb_write_reg_mask(CR91
, VIACR
, 0x11, 0x11);
821 for (i
= 0; i
< 3; i
++) {
822 mask
= PowerSequenceOff
[0][i
];
823 data
= PowerSequenceOff
[1][i
] & mask
;
824 viafb_write_reg_mask(CR91
, VIACR
, (u8
) data
, (u8
) mask
);
825 udelay(PowerSequenceOff
[2][i
]);
829 viafb_write_reg_mask(CR6A
, VIACR
, 0x00, 0x08);
832 static void lcd_powersequence_on(void)
836 /* Software control power sequence */
837 viafb_write_reg_mask(CR91
, VIACR
, 0x11, 0x11);
840 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, 0x08);
842 for (i
= 0; i
< 3; i
++) {
843 mask
= PowerSequenceOn
[0][i
];
844 data
= PowerSequenceOn
[1][i
] & mask
;
845 viafb_write_reg_mask(CR91
, VIACR
, (u8
) data
, (u8
) mask
);
846 udelay(PowerSequenceOn
[2][i
]);
852 static void fill_lcd_format(void)
854 u8 bdithering
= 0, bdual
= 0;
856 if (viaparinfo
->lvds_setting_info
->device_lcd_dualedge
)
858 if (viaparinfo
->lvds_setting_info
->LCDDithering
)
860 /* Dual & Dithering */
861 viafb_write_reg_mask(CR88
, VIACR
, (bdithering
| bdual
), BIT4
+ BIT0
);
864 static void check_diport_of_integrated_lvds(
865 struct lvds_chip_information
*plvds_chip_info
,
866 struct lvds_setting_information
869 /* Determine LCD DI Port by hardware layout. */
870 switch (viafb_display_hardware_layout
) {
871 case HW_LAYOUT_LCD_ONLY
:
873 if (plvds_setting_info
->device_lcd_dualedge
) {
874 plvds_chip_info
->output_interface
=
875 INTERFACE_LVDS0LVDS1
;
877 plvds_chip_info
->output_interface
=
884 case HW_LAYOUT_DVI_ONLY
:
886 plvds_chip_info
->output_interface
= INTERFACE_NONE
;
890 case HW_LAYOUT_LCD1_LCD2
:
891 case HW_LAYOUT_LCD_EXTERNAL_LCD2
:
893 plvds_chip_info
->output_interface
=
894 INTERFACE_LVDS0LVDS1
;
898 case HW_LAYOUT_LCD_DVI
:
900 plvds_chip_info
->output_interface
= INTERFACE_LVDS1
;
906 plvds_chip_info
->output_interface
= INTERFACE_LVDS1
;
912 "Display Hardware Layout: 0x%x, LCD DI Port: 0x%x\n",
913 viafb_display_hardware_layout
,
914 plvds_chip_info
->output_interface
);
917 void viafb_init_lvds_output_interface(struct lvds_chip_information
919 struct lvds_setting_information
922 if (INTERFACE_NONE
!= plvds_chip_info
->output_interface
) {
923 /*Do nothing, lcd port is specified by module parameter */
927 switch (plvds_chip_info
->lvds_chip_name
) {
930 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
931 case UNICHROME_CX700
:
932 plvds_chip_info
->output_interface
= INTERFACE_DVP1
;
934 case UNICHROME_CN700
:
935 plvds_chip_info
->output_interface
= INTERFACE_DFP_LOW
;
938 plvds_chip_info
->output_interface
= INTERFACE_DVP0
;
943 case INTEGRATED_LVDS
:
944 check_diport_of_integrated_lvds(plvds_chip_info
,
949 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
950 case UNICHROME_K8M890
:
951 case UNICHROME_P4M900
:
952 case UNICHROME_P4M890
:
953 plvds_chip_info
->output_interface
= INTERFACE_DFP_LOW
;
956 plvds_chip_info
->output_interface
= INTERFACE_DFP
;
963 bool viafb_lcd_get_mobile_state(bool *mobile
)
965 unsigned char __iomem
*romptr
, *tableptr
, *biosptr
;
968 const u32 romaddr
= 0x000C0000;
971 biosptr
= ioremap(romaddr
, 0x10000);
972 start_pattern
= readw(biosptr
);
974 /* Compare pattern */
975 if (start_pattern
== 0xAA55) {
976 /* Get the start of Table */
977 /* 0x1B means BIOS offset position */
978 romptr
= biosptr
+ 0x1B;
979 tableptr
= biosptr
+ readw(romptr
);
981 /* Get the start of biosver structure */
982 /* 18 means BIOS version position. */
983 romptr
= tableptr
+ 18;
984 romptr
= biosptr
+ readw(romptr
);
986 /* The offset should be 44, but the
987 actual image is less three char. */
991 core_base
= readb(romptr
);