DSS2: HACK: Add DSS2 support for N800
[pandora-kernel.git] / drivers / video / omap2 / displays / ctrl-blizzard.c
1
2 //#define DEBUG
3
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/clk.h>
7 #include <linux/delay.h>
8 #include <linux/err.h>
9
10 #include <mach/display.h>
11 #include <mach/dma.h>
12
13 #ifdef DEBUG
14 #define DBG(format, ...) printk(KERN_DEBUG "Blizzard: " format, ## __VA_ARGS__)
15 #else
16 #define DBG(format, ...)
17 #endif
18
19 #define BLIZZARD_REV_CODE                       0x00
20 #define BLIZZARD_CONFIG                         0x02
21 #define BLIZZARD_PLL_DIV                        0x04
22 #define BLIZZARD_PLL_LOCK_RANGE                 0x06
23 #define BLIZZARD_PLL_CLOCK_SYNTH_0              0x08
24 #define BLIZZARD_PLL_CLOCK_SYNTH_1              0x0a
25 #define BLIZZARD_PLL_MODE                       0x0c
26 #define BLIZZARD_CLK_SRC                        0x0e
27 #define BLIZZARD_MEM_BANK0_ACTIVATE             0x10
28 #define BLIZZARD_MEM_BANK0_STATUS               0x14
29 #define BLIZZARD_PANEL_CONFIGURATION            0x28
30 #define BLIZZARD_HDISP                          0x2a
31 #define BLIZZARD_HNDP                           0x2c
32 #define BLIZZARD_VDISP0                         0x2e
33 #define BLIZZARD_VDISP1                         0x30
34 #define BLIZZARD_VNDP                           0x32
35 #define BLIZZARD_HSW                            0x34
36 #define BLIZZARD_VSW                            0x38
37 #define BLIZZARD_DISPLAY_MODE                   0x68
38 #define BLIZZARD_INPUT_WIN_X_START_0            0x6c
39 #define BLIZZARD_DATA_SOURCE_SELECT             0x8e
40 #define BLIZZARD_DISP_MEM_DATA_PORT             0x90
41 #define BLIZZARD_DISP_MEM_READ_ADDR0            0x92
42 #define BLIZZARD_POWER_SAVE                     0xE6
43 #define BLIZZARD_NDISP_CTRL_STATUS              0xE8
44
45 /* Data source select */
46 /* For S1D13745 */
47 #define BLIZZARD_SRC_WRITE_LCD_BACKGROUND       0x00
48 #define BLIZZARD_SRC_WRITE_LCD_DESTRUCTIVE      0x01
49 #define BLIZZARD_SRC_WRITE_OVERLAY_ENABLE       0x04
50 #define BLIZZARD_SRC_DISABLE_OVERLAY            0x05
51 /* For S1D13744 */
52 #define BLIZZARD_SRC_WRITE_LCD                  0x00
53 #define BLIZZARD_SRC_BLT_LCD                    0x06
54
55 #define BLIZZARD_COLOR_RGB565                   0x01
56 #define BLIZZARD_COLOR_YUV420                   0x09
57
58 #define BLIZZARD_VERSION_S1D13745               0x01    /* Hailstorm */
59 #define BLIZZARD_VERSION_S1D13744               0x02    /* Blizzard */
60
61 #define BLIZZARD_AUTO_UPDATE_TIME               (HZ / 20)
62
63
64
65 static struct {
66         int                     version;
67 } blizzard;
68
69
70 static inline void blizzard_cmd(u8 cmd)
71 {
72         omap_rfbi_write_command(&cmd, 1);
73 }
74
75 static inline void blizzard_write(u8 cmd, const u8 *buf, int len)
76 {
77         omap_rfbi_write_command(&cmd, 1);
78         omap_rfbi_write_data(buf, len);
79 }
80
81 static inline void blizzard_read(u8 cmd, u8 *buf, int len)
82 {
83         omap_rfbi_write_command(&cmd, 1);
84         omap_rfbi_read_data(buf, len);
85 }
86
87 static u8 blizzard_read_reg(u8 cmd)
88 {
89         u8 data;
90         blizzard_read(cmd, &data, 1);
91         return data;
92 }
93
94 static int blizzard_ctrl_init(struct omap_display *display)
95 {
96         DBG("blizzard_ctrl_init\n");
97
98         return 0;
99 }
100
101
102 static int blizzard_ctrl_enable(struct omap_display *display)
103 {
104         int r = 0;
105         u8 rev, conf;
106
107         DBG("blizzard_ctrl_enable\n");
108
109         if (display->hw_config.ctrl_enable) {
110                 r = display->hw_config.ctrl_enable(display);
111                 if (r)
112                         return r;
113         }
114
115         msleep(100);
116
117         rev = blizzard_read_reg(BLIZZARD_CLK_SRC);
118         printk("CLK_SRC %x\n", rev);
119
120         rev = blizzard_read_reg(BLIZZARD_PLL_DIV);
121         printk("PLLDIV %x\n", rev);
122
123         rev = blizzard_read_reg(BLIZZARD_REV_CODE);
124         conf = blizzard_read_reg(BLIZZARD_CONFIG);
125
126         printk("rev %x, conf %x\n", rev, conf);
127
128         switch (rev & 0xfc) {
129         case 0x9c:
130                 blizzard.version = BLIZZARD_VERSION_S1D13744;
131                 pr_info("omapfb: s1d13744 LCD controller rev %d "
132                         "initialized (CNF pins %x)\n", rev & 0x03, conf & 0x07);
133                 break;
134         case 0xa4:
135                 blizzard.version = BLIZZARD_VERSION_S1D13745;
136                 pr_info("omapfb: s1d13745 LCD controller rev %d "
137                         "initialized (CNF pins %x)\n", rev & 0x03, conf & 0x07);
138                 break;
139         default:
140                 printk("invalid s1d1374x revision %02x\n",
141                         rev);
142                 r = -ENODEV;
143         }
144
145         return r;
146 }
147
148 static void blizzard_ctrl_disable(struct omap_display *display)
149 {
150         DBG("blizzard_ctrl_disable\n");
151
152         if (display->hw_config.ctrl_disable)
153                 display->hw_config.ctrl_disable(display);
154 }
155
156 int rfbi_configure(int rfbi_module, int bpp, int lines);
157
158 static void blizzard_ctrl_setup_update(struct omap_display *display,
159                                     u16 x, u16 y, u16 w, u16 h)
160 {
161         u8 tmp[18];
162         int x_end, y_end;
163
164         DBG("blizzard_ctrl_setup_update\n");
165
166         x_end = x + w - 1;
167         y_end = y + h - 1;
168
169         tmp[0] = x;
170         tmp[1] = x >> 8;
171         tmp[2] = y;
172         tmp[3] = y >> 8;
173         tmp[4] = x_end;
174         tmp[5] = x_end >> 8;
175         tmp[6] = y_end;
176         tmp[7] = y_end >> 8;
177
178         /* scaling? */
179         tmp[8] = x;
180         tmp[9] = x >> 8;
181         tmp[10] = y;
182         tmp[11] = y >> 8;
183         tmp[12] = x_end;
184         tmp[13] = x_end >> 8;
185         tmp[14] = y_end;
186         tmp[15] = y_end >> 8;
187
188         tmp[16] = BLIZZARD_COLOR_RGB565; //color_mode;
189
190         if (blizzard.version == BLIZZARD_VERSION_S1D13745)
191                 tmp[17] = BLIZZARD_SRC_WRITE_LCD_BACKGROUND;
192         else
193                 tmp[17] = blizzard.version == BLIZZARD_VERSION_S1D13744 ?
194                                 BLIZZARD_SRC_WRITE_LCD :
195                                 BLIZZARD_SRC_WRITE_LCD_DESTRUCTIVE;
196
197         rfbi_configure(display->hw_config.u.rfbi.channel,
198                        16,
199                        8);
200
201         blizzard_write(BLIZZARD_INPUT_WIN_X_START_0, tmp, 18);
202
203         rfbi_configure(display->hw_config.u.rfbi.channel,
204                        16,
205                        16);
206 }
207
208 static int blizzard_ctrl_enable_te(struct omap_display *display, bool enable)
209 {
210         return 0;
211 }
212
213 static int blizzard_ctrl_rotate(struct omap_display *display, u8 rotate)
214 {
215         return 0;
216 }
217
218 static int blizzard_ctrl_mirror(struct omap_display *display, bool enable)
219 {
220         return 0;
221 }
222
223 static int blizzard_run_test(struct omap_display *display, int test_num)
224 {
225         return 0;
226 }
227
228 static struct omap_ctrl blizzard_ctrl = {
229         .owner = THIS_MODULE,
230         .name = "ctrl-blizzard",
231         .init = blizzard_ctrl_init,
232         .enable = blizzard_ctrl_enable,
233         .disable = blizzard_ctrl_disable,
234         .setup_update = blizzard_ctrl_setup_update,
235         .enable_te = blizzard_ctrl_enable_te,
236         .set_rotate = blizzard_ctrl_rotate,
237         .set_mirror = blizzard_ctrl_mirror,
238         .run_test = blizzard_run_test,
239         .pixel_size = 16,
240
241         .timings = {
242                 .cs_on_time     = 0,
243
244                 .we_on_time     = 9000,
245                 .we_off_time    = 18000,
246                 .we_cycle_time  = 36000,
247
248                 .re_on_time     = 9000,
249                 .re_off_time    = 27000,
250                 .re_cycle_time  = 36000,
251
252                 .access_time    = 27000,
253                 .cs_off_time    = 36000,
254
255                 .cs_pulse_width = 0,
256         },
257 };
258
259
260 static int __init blizzard_init(void)
261 {
262         DBG("blizzard_init\n");
263         omap_dss_register_ctrl(&blizzard_ctrl);
264         return 0;
265 }
266
267 static void __exit blizzard_exit(void)
268 {
269         DBG("blizzard_exit\n");
270
271         omap_dss_unregister_ctrl(&blizzard_ctrl);
272 }
273
274 module_init(blizzard_init);
275 module_exit(blizzard_exit);
276
277 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
278 MODULE_DESCRIPTION("Blizzard Driver");
279 MODULE_LICENSE("GPL");