change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8830 / sprd_lcd.h
1 /* drivers/video/sc8810/sc8810_lcd.h
2  *
3  * Spreadtrum LCD abstraction
4  *
5  * Copyright (C) 2010 Spreadtrum.com
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 #ifndef _TIGER_LCD_H_
18 #define _TIGER_LCD_H_
19
20 #include <asm/arch/sci_types.h>
21
22 #include <linux/types.h>
23 #include <common.h>
24
25 #define LCD_DelayMS(ms)  udelay(1000*(ms))
26
27 /* LCD mode */
28 #define SPRDFB_I2C_WRITE_DELAY 0xffff
29
30
31 /* LCD mode */
32 #define LCD_MODE_MCU                    0
33 #define LCD_MODE_RGB                    1
34 #define LCD_MODE_DSI                    2
35 #define LCD_MODE_LVDS                   3
36
37 /* bus mode */
38 #define LCD_BUS_8080                    0
39 #define LCD_BUS_6800                    1
40 #define LCD_BUS_SPI                     2
41
42 /* lcd directions */
43 #define LCD_DIRECT_NORMAL               0
44 #define LCD_DIRECT_ROT_90               1
45 #define LCD_DIRECT_ROT_180              2
46 #define LCD_DIRECT_ROT_270              3
47 #define LCD_DIRECT_MIR_H                4
48 #define LCD_DIRECT_MIR_V                5
49 #define LCD_DIRECT_MIR_HV               6
50
51 #define PIN_PWM0_MOD_VALUE 0x20
52
53 #define SPRD_PWM_BASE                   0x88000000
54 #define SPRD_PWM_REG(off)               (SPRD_PWM_BASE + (off))
55 #define SPRD_PWM0_PRESCALE      SPRD_PWM_REG(0x0000)
56 #define SPRD_PWM0_CNT                   SPRD_PWM_REG(0x0004)
57 #define SPRD_PWM0_TONE_DIV      SPRD_PWM_REG(0x0008)
58 #define SPRD_PWM0_PAT_LOW       SPRD_PWM_REG(0x000C)
59 #define SPRD_PWM0_PAT_HIG       SPRD_PWM_REG(0x0010)
60
61 #define LCD_PWM_PRESCALE_VALUE  0x01
62 #define LCD_PWM_MOD_VALUE               0xFF
63 #define PWM_REG_MSK_VALUE                       0xFFFF
64
65 #define LCD_PWM0_EN BIT_8
66
67
68 /* panel property */
69 /* lcdc refresh, TE on, double timing, partial update*/
70 #define PANEL_CAP_NORMAL               0x0
71
72 /* only not support partial update*/
73 #define PANEL_CAP_NOT_PARTIAL_UPDATE   0x1
74
75 /* write register, grame have the same timing */
76 #define PANEL_CAP_UNIQUE_TIMING        0x2
77
78 /* lcd not support TE */
79 #define PANEL_CAP_NOT_TEAR_SYNC        0x4
80
81 /* only do command/data register, such as some mono oled display device */
82 #define PANEL_CAP_MANUAL_REFRESH       0x8
83
84 enum{
85         SPRDFB_PANEL_TYPE_MCU = 0,
86         SPRDFB_PANEL_TYPE_RGB,
87         SPRDFB_PANEL_TYPE_MIPI,
88         SPRDFB_PANEL_TYPE_LVDS,
89         SPRDFB_PANEL_TYPE_LIMIT
90 };
91
92 enum{
93         SPRDFB_POLARITY_POS = 0,
94         SPRDFB_POLARITY_NEG,
95         SPRDFB_POLARITY_LIMIT
96 };
97
98 enum{
99         SPRDFB_RGB_BUS_TYPE_I2C = 0,
100         SPRDFB_RGB_BUS_TYPE_SPI,
101         SPRDFB_RGB_BUS_TYPE_LVDS,
102         SPRDFB_RGB_BUG_TYPE_LIMIT
103 };
104
105 enum{
106         SPRDFB_MIPI_MODE_CMD = 0,
107         SPRDFB_MIPI_MODE_VIDEO,
108         SPRDFB_MIPI_MODE_LIMIT
109 };
110
111 struct panel_spec;
112
113 typedef int32_t (*send_cmd_t)(uint32_t data);
114 typedef int32_t (*send_data_t)(uint32_t data);
115 typedef int32_t (*send_cmd_data_t)(uint32_t cmd, uint32_t data);
116 typedef uint32_t (*read_data_t)(void);
117
118
119 typedef int32_t (*mipi_set_cmd_mode_t)(void);
120 typedef int32_t (*mipi_set_video_mode_t)(void);
121 typedef int32_t (*mipi_set_lp_mode_t)(void);//LiWei
122 typedef int32_t (*mipi_set_hs_mode_t)(void);//LiWei
123 typedef int32_t (*mipi_gen_write_t)(uint8_t *param, uint16_t param_length);
124 typedef int32_t (*mipi_gen_read_t)(uint8_t *param, uint16_t param_length, uint8_t bytes_to_read, uint8_t *read_buffer);
125 typedef int32_t (*mipi_dcs_write_t)(uint8_t *param, uint16_t param_length);
126 typedef int32_t (*mipi_dcs_read_t)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
127 typedef int32_t (*mipi_force_write_t)(uint8_t data_type, uint8_t *param, uint16_t param_length);        //add for LCD adapter
128 typedef int32_t (*mipi_force_read_t)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
129 typedef   int32_t (*mipi_eotp_set_t)(uint8_t rx_en, uint8_t tx_en);
130
131 typedef int32_t (*i2c_write_8bits_t)(uint8_t addr, uint8_t reg, uint8_t val);
132 typedef int32_t (*i2c_read_8bits_t)(uint8_t addr, uint8_t reg, uint8_t *val);
133 typedef int32_t (*i2c_write_16bits_t)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t val, BOOLEAN val_is_8bit);
134 typedef int32_t (*i2c_read_16bits_t)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t *val, BOOLEAN val_is_8bit);
135 typedef int32_t (*i2c_write_burst_t)(uint8_t addr, uint8_t* buf, int num);
136
137 typedef void (*spi_send_cmd_t)(uint32_t cmd);
138 typedef void (*spi_send_data_t)(uint32_t data);
139 typedef void (*spi_read_t)(uint32_t *data);
140
141 /* LCD operations */
142 struct panel_operations {
143         int32_t (*panel_init)(struct panel_spec *self);
144         int32_t (*panel_close)(struct panel_spec *self);
145         int32_t (*panel_reset)(struct panel_spec *self);
146         int32_t (*panel_enter_sleep)(struct panel_spec *self, uint8_t is_sleep);
147         int32_t (*panel_set_contrast)(struct panel_spec *self, uint16_t contrast);
148         int32_t (*panel_set_brightness)(struct panel_spec *self,
149                                 uint16_t brightness);
150         int32_t (*panel_set_window)(struct panel_spec *self,
151                                 uint16_t left, uint16_t top,
152                                 uint16_t right, uint16_t bottom);
153         int32_t (*panel_invalidate)(struct panel_spec *self);
154         int32_t (*panel_invalidate_rect)(struct panel_spec *self,
155                                 uint16_t left, uint16_t top,
156                                 uint16_t right, uint16_t bottom);
157         int32_t (*panel_rotate_invalidate_rect)(struct panel_spec *self,
158                                 uint16_t left, uint16_t top,
159                                 uint16_t right, uint16_t bottom,
160                                 uint16_t angle);
161         int32_t (*panel_set_direction)(struct panel_spec *self, uint16_t direction);
162         uint32_t (*panel_readid)(struct panel_spec *self);
163         int32_t (*panel_check_mtp)(struct panel_spec *self);
164         int32_t (*panel_check_elvss)(struct panel_spec *self);
165         int32_t (*panel_check_hbm)(struct panel_spec *self);
166 };
167
168 /* MCU LCD specific properties */
169 struct timing_mcu {
170         uint16_t rcss;
171         uint16_t rlpw;
172         uint16_t rhpw;
173         uint16_t wcss;
174         uint16_t wlpw;
175         uint16_t whpw;
176 };
177
178 /* RGB LCD specific properties */
179 struct timing_rgb {
180         uint16_t hfp;
181         uint16_t hbp;
182         uint16_t hsync;
183         uint16_t vfp;
184         uint16_t vbp;
185         uint16_t vsync;
186 };
187
188 struct ops_mcu {
189         int32_t (*send_cmd)(uint32_t cmd);
190         int32_t (*send_cmd_data)(uint32_t cmd, uint32_t data);
191         int32_t (*send_data)(uint32_t data);
192         uint32_t (*read_data)(void);
193 };
194
195 struct ops_i2c {
196         int32_t (*i2c_write_8bits)(uint8_t addr, uint8_t reg, uint8_t val);
197         int32_t (*i2c_read_8bits)(uint8_t addr, uint8_t reg, uint8_t *val);
198         int32_t (*i2c_write_16bits)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t val, BOOLEAN val_is_8bit);
199         int32_t (*i2c_read_16bits)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t *val, BOOLEAN val_is_8bit);
200         int32_t (*i2c_write_burst)(uint8_t addr, uint8_t* buf, int num);
201 };
202
203 struct ops_spi{
204         void (*spi_send_cmd)(uint32_t cmd);
205         void (*spi_send_data)(uint32_t data);
206         void (*spi_read)(uint32_t *data);
207 };
208
209 struct ops_mipi{
210         int32_t (*mipi_set_cmd_mode)(void);
211         int32_t (*mipi_set_video_mode)(void);
212         int32_t (*mipi_set_lp_mode)(void);
213         int32_t (*mipi_set_hs_mode)(void);
214         int32_t (*mipi_gen_write)(uint8_t *param, uint16_t param_length);
215         int32_t (*mipi_gen_read)(uint8_t *param, uint16_t param_length, uint8_t bytes_to_read, uint8_t *read_buffer);
216         int32_t (*mipi_dcs_write)(uint8_t *param, uint16_t param_length);
217         int32_t (*mipi_dcs_read)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
218         int32_t (*mipi_force_write)(uint8_t data_type, uint8_t *param, uint16_t param_length);                          //add for LCD adapter
219         int32_t (*mipi_force_read)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
220         int32_t (*mipi_eotp_set)(uint8_t rx_en, uint8_t tx_en);
221 };
222
223 struct i2c_info{
224         uint32_t i2c_addr;
225         struct ops_i2c *ops;
226 };
227
228 struct spi_info{
229         struct ops_spi *ops;
230 };
231
232 struct info_mipi {
233         uint16_t work_mode; /*command_mode, video_mode*/
234         uint16_t video_bus_width;
235         uint32_t lan_number;
236         uint32_t phy_feq;
237         uint16_t h_sync_pol;
238         uint16_t v_sync_pol;
239         uint16_t de_pol;
240         uint16_t te_pol; /*only for command_mode*/
241         uint16_t color_mode_pol;
242         uint16_t shut_down_pol;
243         struct timing_rgb *timing;
244         struct ops_mipi *ops;
245 };
246
247 struct info_rgb {
248         uint16_t cmd_bus_mode; /*spi, i2c*/
249         uint16_t video_bus_width;
250         uint16_t h_sync_pol;
251         uint16_t v_sync_pol;
252         uint16_t de_pol;
253         struct timing_rgb *timing;
254         union{
255                 struct i2c_info *i2c;
256                 struct spi_info *spi;
257         }bus_info;
258 };
259
260 struct info_mcu {
261         uint16_t bus_mode; /*8080, 6800*/
262         uint16_t bus_width;
263         uint16_t bpp;
264         uint16_t te_pol;
265         uint32_t te_sync_delay;
266         struct timing_mcu *timing;
267         struct ops_mcu *ops;
268 };
269
270
271 /* LCD abstraction */
272 struct panel_spec {
273         uint32_t cap;
274         uint16_t width;
275         uint16_t height;
276         uint32_t fps;
277         uint16_t type; /*mcu, rgb, mipi*/
278         uint16_t direction;
279         uint16_t is_need_reset;
280         union {
281                 struct info_mcu *mcu;
282                 struct info_rgb *rgb;
283                 struct info_mipi * mipi;
284         } info;
285         struct panel_operations *ops;
286 };
287
288 struct panel_cfg {
289         uint32_t lcd_id;
290         struct panel_spec *panel;
291 };
292
293 extern void LCD_SetBackLightBrightness( unsigned long  value);
294 #endif
295