]> git.openfabrics.org - ~shefty/rdma-dev.git/blob - drivers/video/via/vt1636.c
viafb: introduce per output device power management
[~shefty/rdma-dev.git] / drivers / video / via / vt1636.c
1 /*
2  * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3  * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
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.
9
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
14  * for more details.
15
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
18  * Foundation, Inc.,
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #include <linux/via-core.h>
23 #include <linux/via_i2c.h>
24 #include "global.h"
25
26 u8 viafb_gpio_i2c_read_lvds(struct lvds_setting_information
27         *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
28         u8 index)
29 {
30         u8 data;
31
32         viafb_i2c_readbyte(plvds_chip_info->i2c_port,
33                            plvds_chip_info->lvds_chip_slave_addr, index, &data);
34         return data;
35 }
36
37 void viafb_gpio_i2c_write_mask_lvds(struct lvds_setting_information
38                               *plvds_setting_info, struct lvds_chip_information
39                               *plvds_chip_info, struct IODATA io_data)
40 {
41         int index, data;
42
43         index = io_data.Index;
44         data = viafb_gpio_i2c_read_lvds(plvds_setting_info, plvds_chip_info,
45                 index);
46         data = (data & (~io_data.Mask)) | io_data.Data;
47
48         viafb_i2c_writebyte(plvds_chip_info->i2c_port,
49                             plvds_chip_info->lvds_chip_slave_addr, index, data);
50 }
51
52 void viafb_init_lvds_vt1636(struct lvds_setting_information
53         *plvds_setting_info, struct lvds_chip_information *plvds_chip_info)
54 {
55         int reg_num, i;
56
57         /* Common settings: */
58         reg_num = ARRAY_SIZE(COMMON_INIT_TBL_VT1636);
59
60         for (i = 0; i < reg_num; i++) {
61                 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
62                                          plvds_chip_info,
63                                          COMMON_INIT_TBL_VT1636[i]);
64         }
65
66         /* Input Data Mode Select */
67         if (plvds_setting_info->device_lcd_dualedge) {
68                 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
69                                          plvds_chip_info,
70                                          DUAL_CHANNEL_ENABLE_TBL_VT1636[0]);
71         } else {
72                 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
73                                          plvds_chip_info,
74                                          SINGLE_CHANNEL_ENABLE_TBL_VT1636[0]);
75         }
76
77         if (plvds_setting_info->LCDDithering) {
78                 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
79                                          plvds_chip_info,
80                                          DITHERING_ENABLE_TBL_VT1636[0]);
81         } else {
82                 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
83                                          plvds_chip_info,
84                                          DITHERING_DISABLE_TBL_VT1636[0]);
85         }
86 }
87
88 void viafb_enable_lvds_vt1636(struct lvds_setting_information
89                         *plvds_setting_info,
90                         struct lvds_chip_information *plvds_chip_info)
91 {
92
93         viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
94                                  VDD_ON_TBL_VT1636[0]);
95 }
96
97 void viafb_disable_lvds_vt1636(struct lvds_setting_information
98                          *plvds_setting_info,
99                          struct lvds_chip_information *plvds_chip_info)
100 {
101
102         viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
103                                  VDD_OFF_TBL_VT1636[0]);
104 }
105
106 bool viafb_lvds_identify_vt1636(u8 i2c_adapter)
107 {
108         u8 Buffer[2];
109
110         DEBUG_MSG(KERN_INFO "viafb_lvds_identify_vt1636.\n");
111
112         /* Sense VT1636 LVDS Transmiter */
113         viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
114                 VT1636_LVDS_I2C_ADDR;
115
116         /* Check vendor ID first: */
117         if (viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR,
118                                         0x00, &Buffer[0]))
119                 return false;
120         viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x01, &Buffer[1]);
121
122         if (!((Buffer[0] == 0x06) && (Buffer[1] == 0x11)))
123                 return false;
124
125         /* Check Chip ID: */
126         viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x02, &Buffer[0]);
127         viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x03, &Buffer[1]);
128         if ((Buffer[0] == 0x45) && (Buffer[1] == 0x33)) {
129                 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
130                         VT1636_LVDS;
131                 return true;
132         }
133
134         return false;
135 }
136
137 static int get_clk_range_index(u32 Clk)
138 {
139         if (Clk < DPA_CLK_30M)
140                 return DPA_CLK_RANGE_30M;
141         else if (Clk < DPA_CLK_50M)
142                 return DPA_CLK_RANGE_30_50M;
143         else if (Clk < DPA_CLK_70M)
144                 return DPA_CLK_RANGE_50_70M;
145         else if (Clk < DPA_CLK_100M)
146                 return DPA_CLK_RANGE_70_100M;
147         else if (Clk < DPA_CLK_150M)
148                 return DPA_CLK_RANGE_100_150M;
149         else
150                 return DPA_CLK_RANGE_150M;
151 }
152
153 static int get_lvds_dpa_setting_index(int panel_size_id,
154                              struct VT1636_DPA_SETTING *p_vt1636_dpasetting_tbl,
155                                int tbl_size)
156 {
157         int i;
158
159         for (i = 0; i < tbl_size; i++) {
160                 if (panel_size_id == p_vt1636_dpasetting_tbl->PanelSizeID)
161                         return i;
162
163                 p_vt1636_dpasetting_tbl++;
164         }
165
166         return 0;
167 }
168
169 static void set_dpa_vt1636(struct lvds_setting_information
170         *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
171                     struct VT1636_DPA_SETTING *p_vt1636_dpa_setting)
172 {
173         struct IODATA io_data;
174
175         io_data.Index = 0x09;
176         io_data.Mask = 0x1F;
177         io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST1;
178         viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
179                 plvds_chip_info, io_data);
180
181         io_data.Index = 0x08;
182         io_data.Mask = 0x0F;
183         io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST2;
184         viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
185                 io_data);
186 }
187
188 void viafb_vt1636_patch_skew_on_vt3324(
189         struct lvds_setting_information *plvds_setting_info,
190         struct lvds_chip_information *plvds_chip_info)
191 {
192         int index, size;
193
194         DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3324.\n");
195
196         /* Graphics DPA settings: */
197         index = get_clk_range_index(plvds_setting_info->vclk);
198         viafb_set_dpa_gfx(plvds_chip_info->output_interface,
199                     &GFX_DPA_SETTING_TBL_VT3324[index]);
200
201         /* LVDS Transmitter DPA settings: */
202         size = ARRAY_SIZE(VT1636_DPA_SETTING_TBL_VT3324);
203         index =
204             get_lvds_dpa_setting_index(plvds_setting_info->lcd_panel_id,
205                                        VT1636_DPA_SETTING_TBL_VT3324, size);
206         set_dpa_vt1636(plvds_setting_info, plvds_chip_info,
207                        &VT1636_DPA_SETTING_TBL_VT3324[index]);
208 }
209
210 void viafb_vt1636_patch_skew_on_vt3327(
211         struct lvds_setting_information *plvds_setting_info,
212         struct lvds_chip_information *plvds_chip_info)
213 {
214         int index, size;
215
216         DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3327.\n");
217
218         /* Graphics DPA settings: */
219         index = get_clk_range_index(plvds_setting_info->vclk);
220         viafb_set_dpa_gfx(plvds_chip_info->output_interface,
221                     &GFX_DPA_SETTING_TBL_VT3327[index]);
222
223         /* LVDS Transmitter DPA settings: */
224         size = ARRAY_SIZE(VT1636_DPA_SETTING_TBL_VT3327);
225         index =
226             get_lvds_dpa_setting_index(plvds_setting_info->lcd_panel_id,
227                                        VT1636_DPA_SETTING_TBL_VT3327, size);
228         set_dpa_vt1636(plvds_setting_info, plvds_chip_info,
229                        &VT1636_DPA_SETTING_TBL_VT3327[index]);
230 }
231
232 void viafb_vt1636_patch_skew_on_vt3364(
233         struct lvds_setting_information *plvds_setting_info,
234         struct lvds_chip_information *plvds_chip_info)
235 {
236         int index;
237
238         DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3364.\n");
239
240         /* Graphics DPA settings: */
241         index = get_clk_range_index(plvds_setting_info->vclk);
242         viafb_set_dpa_gfx(plvds_chip_info->output_interface,
243                     &GFX_DPA_SETTING_TBL_VT3364[index]);
244 }