tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8825 / tiger_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
36 /* bus mode */
37 #define LCD_BUS_8080                    0
38 #define LCD_BUS_6800                    1
39 #define LCD_BUS_SPI                     2
40
41 /* lcd directions */
42 #define LCD_DIRECT_NORMAL               0
43 #define LCD_DIRECT_ROT_90               1
44 #define LCD_DIRECT_ROT_180              2
45 #define LCD_DIRECT_ROT_270              3
46 #define LCD_DIRECT_MIR_H                4
47 #define LCD_DIRECT_MIR_V                5
48 #define LCD_DIRECT_MIR_HV               6
49
50 #define PIN_PWM0_MOD_VALUE 0x20
51
52 #define SPRD_PWM_BASE                   0x88000000
53 #define SPRD_PWM_REG(off)               (SPRD_PWM_BASE + (off))
54 #define SPRD_PWM0_PRESCALE      SPRD_PWM_REG(0x0000)
55 #define SPRD_PWM0_CNT                   SPRD_PWM_REG(0x0004)
56 #define SPRD_PWM0_TONE_DIV      SPRD_PWM_REG(0x0008)
57 #define SPRD_PWM0_PAT_LOW       SPRD_PWM_REG(0x000C)
58 #define SPRD_PWM0_PAT_HIG       SPRD_PWM_REG(0x0010)
59
60 #define LCD_PWM_PRESCALE_VALUE  0x01
61 #define LCD_PWM_MOD_VALUE               0xFF
62 #define PWM_REG_MSK_VALUE                       0xFFFF
63
64 #define LCD_PWM0_EN BIT_8
65
66
67 /* panel property */
68 /* lcdc refresh, TE on, double timing, partial update*/
69 #define PANEL_CAP_NORMAL               0x0
70
71 /* only not support partial update*/
72 #define PANEL_CAP_NOT_PARTIAL_UPDATE   0x1
73
74 /* write register, grame have the same timing */
75 #define PANEL_CAP_UNIQUE_TIMING        0x2
76
77 /* lcd not support TE */
78 #define PANEL_CAP_NOT_TEAR_SYNC        0x4
79
80 /* only do command/data register, such as some mono oled display device */
81 #define PANEL_CAP_MANUAL_REFRESH       0x8
82
83 enum{
84         SPRDFB_PANEL_TYPE_MCU = 0,
85         SPRDFB_PANEL_TYPE_RGB,
86         SPRDFB_PANEL_TYPE_MIPI,
87         SPRDFB_PANEL_TYPE_LIMIT
88 };
89
90 enum{
91         SPRDFB_POLARITY_POS = 0,
92         SPRDFB_POLARITY_NEG,
93         SPRDFB_POLARITY_LIMIT
94 };
95
96 enum{
97         SPRDFB_RGB_BUS_TYPE_I2C = 0,
98         SPRDFB_RGB_BUS_TYPE_SPI,
99         SPRDFB_RGB_BUG_TYPE_LIMIT
100 };
101
102 enum{
103         SPRDFB_MIPI_MODE_CMD = 0,
104         SPRDFB_MIPI_MODE_VIDEO,
105         SPRDFB_MIPI_MODE_LIMIT
106 };
107
108 struct panel_spec;
109
110 typedef int32_t (*send_cmd_t)(uint32_t data);
111 typedef int32_t (*send_data_t)(uint32_t data);
112 typedef int32_t (*send_cmd_data_t)(uint32_t cmd, uint32_t data);
113 typedef uint32_t (*read_data_t)(void);
114
115
116 typedef int32_t (*mipi_set_cmd_mode_t)(void);
117 typedef int32_t (*mipi_set_video_mode_t)(void);
118 typedef int32_t (*mipi_gen_write_t)(uint8_t *param, uint16_t param_length);
119 typedef int32_t (*mipi_gen_read_t)(uint8_t *param, uint16_t param_length, uint8_t bytes_to_read, uint8_t *read_buffer);
120 typedef int32_t (*mipi_dcs_write_t)(uint8_t *param, uint16_t param_length);
121 typedef int32_t (*mipi_dcs_read_t)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
122 typedef int32_t (*mipi_force_write_t)(uint8_t data_type, uint8_t *param, uint16_t param_length);        //add for LCD adapter
123 typedef int32_t (*mipi_force_read_t)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
124
125 typedef int32_t (*i2c_write_8bits_t)(uint8_t addr, uint8_t reg, uint8_t val);
126 typedef int32_t (*i2c_read_8bits_t)(uint8_t addr, uint8_t reg, uint8_t *val);
127 typedef int32_t (*i2c_write_16bits_t)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t val, BOOLEAN val_is_8bit);
128 typedef int32_t (*i2c_read_16bits_t)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t *val, BOOLEAN val_is_8bit);
129 typedef int32_t (*i2c_write_burst_t)(uint8_t addr, uint8_t* buf, int num);
130
131 typedef void (*spi_send_cmd_t)(uint32_t cmd);
132 typedef void (*spi_send_data_t)(uint32_t data);
133 typedef void (*spi_read_t)(uint32_t *data);
134
135 /* LCD operations */
136 struct panel_operations {
137         int32_t (*panel_init)(struct panel_spec *self);
138         int32_t (*panel_close)(struct panel_spec *self);
139         int32_t (*panel_reset)(struct panel_spec *self);
140         int32_t (*panel_enter_sleep)(struct panel_spec *self, uint8_t is_sleep);
141         int32_t (*panel_set_contrast)(struct panel_spec *self, uint16_t contrast);
142         int32_t (*panel_set_brightness)(struct panel_spec *self,
143                                 uint16_t brightness);
144         int32_t (*panel_set_window)(struct panel_spec *self,
145                                 uint16_t left, uint16_t top,
146                                 uint16_t right, uint16_t bottom);
147         int32_t (*panel_invalidate)(struct panel_spec *self);
148         int32_t (*panel_invalidate_rect)(struct panel_spec *self,
149                                 uint16_t left, uint16_t top,
150                                 uint16_t right, uint16_t bottom);
151         int32_t (*panel_rotate_invalidate_rect)(struct panel_spec *self,
152                                 uint16_t left, uint16_t top,
153                                 uint16_t right, uint16_t bottom,
154                                 uint16_t angle);
155         int32_t (*panel_set_direction)(struct panel_spec *self, uint16_t direction);
156         uint32_t (*panel_readid)(struct panel_spec *self);
157 };
158
159 /* MCU LCD specific properties */
160 struct timing_mcu {
161         uint16_t rcss;
162         uint16_t rlpw;
163         uint16_t rhpw;
164         uint16_t wcss;
165         uint16_t wlpw;
166         uint16_t whpw;
167 };
168
169 /* RGB LCD specific properties */
170 struct timing_rgb {
171         uint16_t hfp;
172         uint16_t hbp;
173         uint16_t hsync;
174         uint16_t vfp;
175         uint16_t vbp;
176         uint16_t vsync;
177 };
178
179 struct ops_mcu {
180         int32_t (*send_cmd)(uint32_t cmd);
181         int32_t (*send_cmd_data)(uint32_t cmd, uint32_t data);
182         int32_t (*send_data)(uint32_t data);
183         uint32_t (*read_data)(void);
184 };
185
186 struct ops_i2c {
187         int32_t (*i2c_write_8bits)(uint8_t addr, uint8_t reg, uint8_t val);
188         int32_t (*i2c_read_8bits)(uint8_t addr, uint8_t reg, uint8_t *val);
189         int32_t (*i2c_write_16bits)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t val, BOOLEAN val_is_8bit);
190         int32_t (*i2c_read_16bits)(uint8_t addr, uint16_t reg, BOOLEAN reg_is_8bit, uint16_t *val, BOOLEAN val_is_8bit);
191         int32_t (*i2c_write_burst)(uint8_t addr, uint8_t* buf, int num);
192 };
193
194 struct ops_spi{
195         void (*spi_send_cmd)(uint32_t cmd);
196         void (*spi_send_data)(uint32_t data);
197         void (*spi_read)(uint32_t *data);
198 };
199
200 struct ops_mipi{
201         int32_t (*mipi_set_cmd_mode)(void);
202         int32_t (*mipi_set_video_mode)(void);
203         int32_t (*mipi_gen_write)(uint8_t *param, uint16_t param_length);
204         int32_t (*mipi_gen_read)(uint8_t *param, uint16_t param_length, uint8_t bytes_to_read, uint8_t *read_buffer);
205         int32_t (*mipi_dcs_write)(uint8_t *param, uint16_t param_length);
206         int32_t (*mipi_dcs_read)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
207         int32_t (*mipi_force_write)(uint8_t data_type, uint8_t *param, uint16_t param_length);                          //add for LCD adapter
208         int32_t (*mipi_force_read)(uint8_t command, uint8_t bytes_to_read, uint8_t *read_buffer);
209 };
210
211 struct i2c_info{
212         uint32_t i2c_addr;
213         struct ops_i2c *ops;
214 };
215
216 struct spi_info{
217         struct ops_spi *ops;
218 };
219
220 struct info_mipi {
221         uint16_t work_mode; /*command_mode, video_mode*/
222         uint16_t video_bus_width;
223         uint32_t lan_number;
224         uint32_t phy_feq;
225         //uint16_t h_sync_pol;
226         //uint16_t v_sync_pol;
227         //uint16_t de_pol;
228         uint16_t te_pol; /*only for command_mode*/
229         //uint16_t color_mode_pol;
230         //uint16_t shut_down_pol;
231         struct timing_rgb *timing;
232         struct ops_mipi *ops;
233 };
234
235 struct info_rgb {
236         uint16_t cmd_bus_mode; /*spi, i2c*/
237         uint16_t video_bus_width;
238         uint16_t h_sync_pol;
239         uint16_t v_sync_pol;
240         uint16_t de_pol;
241         struct timing_rgb *timing;
242         union{
243                 struct i2c_info *i2c;
244                 struct spi_info *spi;
245         }bus_info;
246 };
247
248 struct info_mcu {
249         uint16_t bus_mode; /*8080, 6800*/
250         uint16_t bus_width;
251         uint16_t bpp;
252         uint16_t te_pol;
253         uint32_t te_sync_delay;
254         struct timing_mcu *timing;
255         struct ops_mcu *ops;
256 };
257
258
259 /* LCD abstraction */
260 struct panel_spec {
261         uint32_t cap;
262         uint16_t width;
263         uint16_t height;
264         uint32_t fps;
265         uint16_t type; /*mcu, rgb, mipi*/
266         uint16_t direction;
267         union {
268                 struct info_mcu *mcu;
269                 struct info_rgb *rgb;
270                 struct info_mipi * mipi;
271         } info;
272         struct panel_operations *ops;
273 };
274
275 struct panel_cfg {
276         uint32_t lcd_id;
277         struct panel_spec *panel;
278 };
279
280 extern void LCD_SetBackLightBrightness( unsigned long  value);
281 #endif
282