Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / video / fbdev / via / vt1636.c
blob8d8cfdb05618fa10b1cb4ebe61443e28c6db9df8
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
4 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
6 */
8 #include <linux/via-core.h>
9 #include <linux/via_i2c.h>
10 #include "global.h"
12 static const struct IODATA common_init_data[] = {
13 /* Index, Mask, Value */
14 /* Set panel power sequence timing */
15 {0x10, 0xC0, 0x00},
16 /* T1: VDD on - Data on. Each increment is 1 ms. (50ms = 031h) */
17 {0x0B, 0xFF, 0x40},
18 /* T2: Data on - Backlight on. Each increment is 2 ms. (210ms = 068h) */
19 {0x0C, 0xFF, 0x31},
20 /* T3: Backlight off -Data off. Each increment is 2 ms. (210ms = 068h)*/
21 {0x0D, 0xFF, 0x31},
22 /* T4: Data off - VDD off. Each increment is 1 ms. (50ms = 031h) */
23 {0x0E, 0xFF, 0x68},
24 /* T5: VDD off - VDD on. Each increment is 100 ms. (500ms = 04h) */
25 {0x0F, 0xFF, 0x68},
26 /* LVDS output power up */
27 {0x09, 0xA0, 0xA0},
28 /* turn on back light */
29 {0x10, 0x33, 0x13}
32 /* Index, Mask, Value */
33 static const struct IODATA dual_channel_enable_data = {0x08, 0xF0, 0xE0};
34 static const struct IODATA single_channel_enable_data = {0x08, 0xF0, 0x00};
35 static const struct IODATA dithering_enable_data = {0x0A, 0x70, 0x50};
36 static const struct IODATA dithering_disable_data = {0x0A, 0x70, 0x00};
37 static const struct IODATA vdd_on_data = {0x10, 0x20, 0x20};
38 static const struct IODATA vdd_off_data = {0x10, 0x20, 0x00};
40 u8 viafb_gpio_i2c_read_lvds(struct lvds_setting_information
41 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
42 u8 index)
44 u8 data;
46 viafb_i2c_readbyte(plvds_chip_info->i2c_port,
47 plvds_chip_info->lvds_chip_slave_addr, index, &data);
48 return data;
51 void viafb_gpio_i2c_write_mask_lvds(struct lvds_setting_information
52 *plvds_setting_info, struct lvds_chip_information
53 *plvds_chip_info, struct IODATA io_data)
55 int index, data;
57 index = io_data.Index;
58 data = viafb_gpio_i2c_read_lvds(plvds_setting_info, plvds_chip_info,
59 index);
60 data = (data & (~io_data.Mask)) | io_data.Data;
62 viafb_i2c_writebyte(plvds_chip_info->i2c_port,
63 plvds_chip_info->lvds_chip_slave_addr, index, data);
66 void viafb_init_lvds_vt1636(struct lvds_setting_information
67 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info)
69 int reg_num, i;
71 /* Common settings: */
72 reg_num = ARRAY_SIZE(common_init_data);
73 for (i = 0; i < reg_num; i++)
74 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
75 plvds_chip_info, common_init_data[i]);
77 /* Input Data Mode Select */
78 if (plvds_setting_info->device_lcd_dualedge)
79 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
80 plvds_chip_info, dual_channel_enable_data);
81 else
82 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
83 plvds_chip_info, single_channel_enable_data);
85 if (plvds_setting_info->LCDDithering)
86 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
87 plvds_chip_info, dithering_enable_data);
88 else
89 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
90 plvds_chip_info, dithering_disable_data);
93 void viafb_enable_lvds_vt1636(struct lvds_setting_information
94 *plvds_setting_info,
95 struct lvds_chip_information *plvds_chip_info)
97 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
98 vdd_on_data);
101 void viafb_disable_lvds_vt1636(struct lvds_setting_information
102 *plvds_setting_info,
103 struct lvds_chip_information *plvds_chip_info)
105 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
106 vdd_off_data);
109 bool viafb_lvds_identify_vt1636(u8 i2c_adapter)
111 u8 Buffer[2];
113 DEBUG_MSG(KERN_INFO "viafb_lvds_identify_vt1636.\n");
115 /* Sense VT1636 LVDS Transmiter */
116 viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
117 VT1636_LVDS_I2C_ADDR;
119 /* Check vendor ID first: */
120 if (viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR,
121 0x00, &Buffer[0]))
122 return false;
123 viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x01, &Buffer[1]);
125 if (!((Buffer[0] == 0x06) && (Buffer[1] == 0x11)))
126 return false;
128 /* Check Chip ID: */
129 viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x02, &Buffer[0]);
130 viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x03, &Buffer[1]);
131 if ((Buffer[0] == 0x45) && (Buffer[1] == 0x33)) {
132 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
133 VT1636_LVDS;
134 return true;
137 return false;
140 static int get_clk_range_index(u32 Clk)
142 if (Clk < DPA_CLK_30M)
143 return DPA_CLK_RANGE_30M;
144 else if (Clk < DPA_CLK_50M)
145 return DPA_CLK_RANGE_30_50M;
146 else if (Clk < DPA_CLK_70M)
147 return DPA_CLK_RANGE_50_70M;
148 else if (Clk < DPA_CLK_100M)
149 return DPA_CLK_RANGE_70_100M;
150 else if (Clk < DPA_CLK_150M)
151 return DPA_CLK_RANGE_100_150M;
152 else
153 return DPA_CLK_RANGE_150M;
156 static void set_dpa_vt1636(struct lvds_setting_information
157 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
158 struct VT1636_DPA_SETTING *p_vt1636_dpa_setting)
160 struct IODATA io_data;
162 io_data.Index = 0x09;
163 io_data.Mask = 0x1F;
164 io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST1;
165 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
166 plvds_chip_info, io_data);
168 io_data.Index = 0x08;
169 io_data.Mask = 0x0F;
170 io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST2;
171 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
172 io_data);
175 void viafb_vt1636_patch_skew_on_vt3324(
176 struct lvds_setting_information *plvds_setting_info,
177 struct lvds_chip_information *plvds_chip_info)
179 struct VT1636_DPA_SETTING dpa = {0x00, 0x00}, dpa_16x12 = {0x0B, 0x03},
180 *pdpa;
181 int index;
183 DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3324.\n");
185 /* Graphics DPA settings: */
186 index = get_clk_range_index(plvds_setting_info->vclk);
187 viafb_set_dpa_gfx(plvds_chip_info->output_interface,
188 &GFX_DPA_SETTING_TBL_VT3324[index]);
190 /* LVDS Transmitter DPA settings: */
191 if (plvds_setting_info->lcd_panel_hres == 1600 &&
192 plvds_setting_info->lcd_panel_vres == 1200)
193 pdpa = &dpa_16x12;
194 else
195 pdpa = &dpa;
197 set_dpa_vt1636(plvds_setting_info, plvds_chip_info, pdpa);
200 void viafb_vt1636_patch_skew_on_vt3327(
201 struct lvds_setting_information *plvds_setting_info,
202 struct lvds_chip_information *plvds_chip_info)
204 struct VT1636_DPA_SETTING dpa = {0x00, 0x00};
205 int index;
207 DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3327.\n");
209 /* Graphics DPA settings: */
210 index = get_clk_range_index(plvds_setting_info->vclk);
211 viafb_set_dpa_gfx(plvds_chip_info->output_interface,
212 &GFX_DPA_SETTING_TBL_VT3327[index]);
214 /* LVDS Transmitter DPA settings: */
215 set_dpa_vt1636(plvds_setting_info, plvds_chip_info, &dpa);
218 void viafb_vt1636_patch_skew_on_vt3364(
219 struct lvds_setting_information *plvds_setting_info,
220 struct lvds_chip_information *plvds_chip_info)
222 int index;
224 DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3364.\n");
226 /* Graphics DPA settings: */
227 index = get_clk_range_index(plvds_setting_info->vclk);
228 viafb_set_dpa_gfx(plvds_chip_info->output_interface,
229 &GFX_DPA_SETTING_TBL_VT3364[index]);