96190b21b5f2536b7136503daf64131432d5a95f
[pandora-kernel.git] / include / linux / omapfb.h
1 /*
2  * File: arch/arm/plat-omap/include/mach/omapfb.h
3  *
4  * Framebuffer driver for TI OMAP boards
5  *
6  * Copyright (C) 2004 Nokia Corporation
7  * Author: Imre Deak <imre.deak@nokia.com>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 #ifndef __OMAPFB_H
25 #define __OMAPFB_H
26
27 #include <asm/ioctl.h>
28 #include <asm/types.h>
29
30 /* IOCTL commands. */
31
32 #define OMAP_IOW(num, dtype)    _IOW('O', num, dtype)
33 #define OMAP_IOR(num, dtype)    _IOR('O', num, dtype)
34 #define OMAP_IOWR(num, dtype)   _IOWR('O', num, dtype)
35 #define OMAP_IO(num)            _IO('O', num)
36
37 #define OMAPFB_MIRROR           OMAP_IOW(31, int)
38 #define OMAPFB_SYNC_GFX         OMAP_IO(37)
39 #define OMAPFB_VSYNC            OMAP_IO(38)
40 #define OMAPFB_SET_UPDATE_MODE  OMAP_IOW(40, int)
41 #define OMAPFB_GET_CAPS         OMAP_IOR(42, struct omapfb_caps)
42 #define OMAPFB_GET_UPDATE_MODE  OMAP_IOW(43, int)
43 #define OMAPFB_LCD_TEST         OMAP_IOW(45, int)
44 #define OMAPFB_CTRL_TEST        OMAP_IOW(46, int)
45 #define OMAPFB_UPDATE_WINDOW_OLD OMAP_IOW(47, struct omapfb_update_window_old)
46 #define OMAPFB_SET_COLOR_KEY    OMAP_IOW(50, struct omapfb_color_key)
47 #define OMAPFB_GET_COLOR_KEY    OMAP_IOW(51, struct omapfb_color_key)
48 #define OMAPFB_SETUP_PLANE      OMAP_IOW(52, struct omapfb_plane_info)
49 #define OMAPFB_QUERY_PLANE      OMAP_IOW(53, struct omapfb_plane_info)
50 #define OMAPFB_UPDATE_WINDOW    OMAP_IOW(54, struct omapfb_update_window)
51 #define OMAPFB_SETUP_MEM        OMAP_IOW(55, struct omapfb_mem_info)
52 #define OMAPFB_QUERY_MEM        OMAP_IOW(56, struct omapfb_mem_info)
53 #define OMAPFB_WAITFORVSYNC     OMAP_IO(57)
54 #define OMAPFB_MEMORY_READ      OMAP_IOR(58, struct omapfb_memory_read)
55
56 #define OMAPFB_CAPS_GENERIC_MASK        0x00000fff
57 #define OMAPFB_CAPS_LCDC_MASK           0x00fff000
58 #define OMAPFB_CAPS_PANEL_MASK          0xff000000
59
60 #define OMAPFB_CAPS_MANUAL_UPDATE       0x00001000
61 #define OMAPFB_CAPS_TEARSYNC            0x00002000
62 #define OMAPFB_CAPS_PLANE_RELOCATE_MEM  0x00004000
63 #define OMAPFB_CAPS_PLANE_SCALE         0x00008000
64 #define OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE 0x00010000
65 #define OMAPFB_CAPS_WINDOW_SCALE        0x00020000
66 #define OMAPFB_CAPS_WINDOW_OVERLAY      0x00040000
67 #define OMAPFB_CAPS_WINDOW_ROTATE       0x00080000
68 #define OMAPFB_CAPS_SET_BACKLIGHT       0x01000000
69
70 /* Values from DSP must map to lower 16-bits */
71 #define OMAPFB_FORMAT_MASK              0x00ff
72 #define OMAPFB_FORMAT_FLAG_DOUBLE       0x0100
73 #define OMAPFB_FORMAT_FLAG_TEARSYNC     0x0200
74 #define OMAPFB_FORMAT_FLAG_FORCE_VSYNC  0x0400
75 #define OMAPFB_FORMAT_FLAG_ENABLE_OVERLAY       0x0800
76 #define OMAPFB_FORMAT_FLAG_DISABLE_OVERLAY      0x1000
77
78 #define OMAPFB_EVENT_READY      1
79 #define OMAPFB_EVENT_DISABLED   2
80
81 #define OMAPFB_MEMTYPE_SDRAM            0
82 #define OMAPFB_MEMTYPE_SRAM             1
83 #define OMAPFB_MEMTYPE_MAX              1
84
85 enum omapfb_color_format {
86         OMAPFB_COLOR_RGB565 = 0,
87         OMAPFB_COLOR_YUV422,
88         OMAPFB_COLOR_YUV420,
89         OMAPFB_COLOR_CLUT_8BPP,
90         OMAPFB_COLOR_CLUT_4BPP,
91         OMAPFB_COLOR_CLUT_2BPP,
92         OMAPFB_COLOR_CLUT_1BPP,
93         OMAPFB_COLOR_RGB444,
94         OMAPFB_COLOR_YUY422,
95
96         OMAPFB_COLOR_ARGB16,
97         OMAPFB_COLOR_RGB24U,    /* RGB24, 32-bit container */
98         OMAPFB_COLOR_RGB24P,    /* RGB24, 24-bit container */
99         OMAPFB_COLOR_ARGB32,
100         OMAPFB_COLOR_RGBA32,
101         OMAPFB_COLOR_RGBX32,
102 };
103
104 struct omapfb_update_window {
105         __u32 x, y;
106         __u32 width, height;
107         __u32 format;
108         __u32 out_x, out_y;
109         __u32 out_width, out_height;
110         __u32 reserved[8];
111 };
112
113 struct omapfb_update_window_old {
114         __u32 x, y;
115         __u32 width, height;
116         __u32 format;
117 };
118
119 enum omapfb_plane {
120         OMAPFB_PLANE_GFX = 0,
121         OMAPFB_PLANE_VID1,
122         OMAPFB_PLANE_VID2,
123 };
124
125 enum omapfb_channel_out {
126         OMAPFB_CHANNEL_OUT_LCD = 0,
127         OMAPFB_CHANNEL_OUT_DIGIT,
128 };
129
130 struct omapfb_plane_info {
131         __u32 pos_x;
132         __u32 pos_y;
133         __u8  enabled;
134         __u8  channel_out;
135         __u8  mirror;
136         __u8  reserved1;
137         __u32 out_width;
138         __u32 out_height;
139         __u32 reserved2[12];
140 };
141
142 struct omapfb_mem_info {
143         __u32 size;
144         __u8  type;
145         __u8  reserved[3];
146 };
147
148 struct omapfb_caps {
149         __u32 ctrl;
150         __u32 plane_color;
151         __u32 wnd_color;
152 };
153
154 enum omapfb_color_key_type {
155         OMAPFB_COLOR_KEY_DISABLED = 0,
156         OMAPFB_COLOR_KEY_GFX_DST,
157         OMAPFB_COLOR_KEY_VID_SRC,
158 };
159
160 struct omapfb_color_key {
161         __u8  channel_out;
162         __u32 background;
163         __u32 trans_key;
164         __u8  key_type;
165 };
166
167 enum omapfb_update_mode {
168         OMAPFB_UPDATE_DISABLED = 0,
169         OMAPFB_AUTO_UPDATE,
170         OMAPFB_MANUAL_UPDATE
171 };
172
173 struct omapfb_memory_read {
174         __u16 x;
175         __u16 y;
176         __u16 w;
177         __u16 h;
178         size_t buffer_size;
179         void __user *buffer;
180 };
181
182 #ifdef __KERNEL__
183
184 #include <linux/completion.h>
185 #include <linux/interrupt.h>
186 #include <linux/fb.h>
187 #include <linux/mutex.h>
188
189 #include <mach/board.h>
190
191 #define OMAP_LCDC_INV_VSYNC             0x0001
192 #define OMAP_LCDC_INV_HSYNC             0x0002
193 #define OMAP_LCDC_INV_PIX_CLOCK         0x0004
194 #define OMAP_LCDC_INV_OUTPUT_EN         0x0008
195 #define OMAP_LCDC_HSVS_RISING_EDGE      0x0010
196 #define OMAP_LCDC_HSVS_OPPOSITE         0x0020
197
198 #define OMAP_LCDC_SIGNAL_MASK           0x003f
199
200 #define OMAP_LCDC_PANEL_TFT             0x0100
201
202 #define OMAPFB_PLANE_XRES_MIN           8
203 #define OMAPFB_PLANE_YRES_MIN           8
204
205 #ifdef CONFIG_ARCH_OMAP1
206 #define OMAPFB_PLANE_NUM                1
207 #else
208 #define OMAPFB_PLANE_NUM                3
209 #endif
210
211 struct omapfb_device;
212
213 struct lcd_panel {
214         const char      *name;
215         int             config;         /* TFT/STN, signal inversion */
216         int             bpp;            /* Pixel format in fb mem */
217         int             data_lines;     /* Lines on LCD HW interface */
218
219         int             x_res, y_res;
220         int             pixel_clock;    /* In kHz */
221         int             hsw;            /* Horizontal synchronization
222                                            pulse width */
223         int             hfp;            /* Horizontal front porch */
224         int             hbp;            /* Horizontal back porch */
225         int             vsw;            /* Vertical synchronization
226                                            pulse width */
227         int             vfp;            /* Vertical front porch */
228         int             vbp;            /* Vertical back porch */
229         int             acb;            /* ac-bias pin frequency */
230         int             pcd;            /* pixel clock divider.
231                                            Obsolete use pixel_clock instead */
232
233         int             (*init)         (struct lcd_panel *panel,
234                                          struct omapfb_device *fbdev);
235         void            (*cleanup)      (struct lcd_panel *panel);
236         int             (*enable)       (struct lcd_panel *panel);
237         void            (*disable)      (struct lcd_panel *panel);
238         unsigned long   (*get_caps)     (struct lcd_panel *panel);
239         int             (*set_bklight_level)(struct lcd_panel *panel,
240                                              unsigned int level);
241         unsigned int    (*get_bklight_level)(struct lcd_panel *panel);
242         unsigned int    (*get_bklight_max)  (struct lcd_panel *panel);
243         int             (*run_test)     (struct lcd_panel *panel, int test_num);
244 };
245
246 struct extif_timings {
247         int cs_on_time;
248         int cs_off_time;
249         int we_on_time;
250         int we_off_time;
251         int re_on_time;
252         int re_off_time;
253         int we_cycle_time;
254         int re_cycle_time;
255         int cs_pulse_width;
256         int access_time;
257
258         int clk_div;
259
260         u32 tim[5];             /* set by extif->convert_timings */
261
262         int converted;
263 };
264
265 struct lcd_ctrl_extif {
266         int  (*init)            (struct omapfb_device *fbdev);
267         void (*cleanup)         (void);
268         void (*get_clk_info)    (u32 *clk_period, u32 *max_clk_div);
269         unsigned long (*get_max_tx_rate)(void);
270         int  (*convert_timings) (struct extif_timings *timings);
271         void (*set_timings)     (const struct extif_timings *timings);
272         void (*set_bits_per_cycle)(int bpc);
273         void (*write_command)   (const void *buf, unsigned int len);
274         void (*read_data)       (void *buf, unsigned int len);
275         void (*write_data)      (const void *buf, unsigned int len);
276         void (*transfer_area)   (int width, int height,
277                                  void (callback)(void * data), void *data);
278         int  (*setup_tearsync)  (unsigned pin_cnt,
279                                  unsigned hs_pulse_time, unsigned vs_pulse_time,
280                                  int hs_pol_inv, int vs_pol_inv, int div);
281         int  (*enable_tearsync) (int enable, unsigned line);
282
283         unsigned long           max_transmit_size;
284 };
285
286 struct omapfb_notifier_block {
287         struct notifier_block   nb;
288         void                    *data;
289         int                     plane_idx;
290 };
291
292 typedef int (*omapfb_notifier_callback_t)(struct notifier_block *,
293                                           unsigned long event,
294                                           void *fbi);
295
296 struct omapfb_mem_region {
297         u32             paddr;
298         void __iomem    *vaddr;
299         unsigned long   size;
300         u8              type;           /* OMAPFB_PLANE_MEM_* */
301         unsigned        alloc:1;        /* allocated by the driver */
302         unsigned        map:1;          /* kernel mapped by the driver */
303 };
304
305 struct omapfb_mem_desc {
306         int                             region_cnt;
307         struct omapfb_mem_region        region[OMAPFB_PLANE_NUM];
308 };
309
310 struct lcd_ctrl {
311         const char      *name;
312         void            *data;
313
314         int             (*init)           (struct omapfb_device *fbdev,
315                                            int ext_mode,
316                                            struct omapfb_mem_desc *req_md);
317         void            (*cleanup)        (void);
318         void            (*bind_client)    (struct omapfb_notifier_block *nb);
319         void            (*get_caps)       (int plane, struct omapfb_caps *caps);
320         int             (*set_update_mode)(enum omapfb_update_mode mode);
321         enum omapfb_update_mode (*get_update_mode)(void);
322         int             (*setup_plane)    (int plane, int channel_out,
323                                            unsigned long offset,
324                                            int screen_width,
325                                            int pos_x, int pos_y, int width,
326                                            int height, int color_mode);
327         int             (*set_rotate)     (int angle);
328         int             (*setup_mem)      (int plane, size_t size,
329                                            int mem_type, unsigned long *paddr);
330         int             (*mmap)           (struct fb_info *info,
331                                            struct vm_area_struct *vma);
332         int             (*set_scale)      (int plane,
333                                            int orig_width, int orig_height,
334                                            int out_width, int out_height);
335         int             (*enable_plane)   (int plane, int enable);
336         int             (*update_window)  (struct fb_info *fbi,
337                                            struct omapfb_update_window *win,
338                                            void (*callback)(void *),
339                                            void *callback_data);
340         void            (*sync)           (void);
341         void            (*suspend)        (void);
342         void            (*resume)         (void);
343         int             (*run_test)       (int test_num);
344         int             (*setcolreg)      (u_int regno, u16 red, u16 green,
345                                            u16 blue, u16 transp,
346                                            int update_hw_mem);
347         int             (*set_color_key)  (struct omapfb_color_key *ck);
348         int             (*get_color_key)  (struct omapfb_color_key *ck);
349 };
350
351 enum omapfb_state {
352         OMAPFB_DISABLED = 0,
353         OMAPFB_SUSPENDED= 99,
354         OMAPFB_ACTIVE   = 100
355 };
356
357 struct omapfb_plane_struct {
358         int                             idx;
359         struct omapfb_plane_info        info;
360         enum omapfb_color_format        color_mode;
361         struct omapfb_device            *fbdev;
362 };
363
364 struct omapfb_device {
365         int                     state;
366         int                     ext_lcdc;               /* Using external
367                                                            LCD controller */
368         struct mutex            rqueue_mutex;
369
370         int                     palette_size;
371         u32                     pseudo_palette[17];
372
373         struct lcd_panel        *panel;                 /* LCD panel */
374         const struct lcd_ctrl   *ctrl;                  /* LCD controller */
375         const struct lcd_ctrl   *int_ctrl;              /* internal LCD ctrl */
376         struct lcd_ctrl_extif   *ext_if;                /* LCD ctrl external
377                                                            interface */
378         struct device           *dev;
379         struct fb_var_screeninfo        new_var;        /* for mode changes */
380
381         struct omapfb_mem_desc          mem_desc;
382         struct fb_info                  *fb_info[OMAPFB_PLANE_NUM];
383 };
384
385 struct omapfb_platform_data {
386         struct omap_lcd_config          lcd;
387         struct omapfb_mem_desc          mem_desc;
388         void                            *ctrl_platform_data;
389 };
390
391 #ifdef CONFIG_ARCH_OMAP1
392 extern struct lcd_ctrl omap1_lcd_ctrl;
393 #else
394 extern struct lcd_ctrl omap2_disp_ctrl;
395 #endif
396
397 extern void omapfb_set_platform_data(struct omapfb_platform_data *data);
398
399 extern void omapfb_reserve_sdram(void);
400 extern void omapfb_register_panel(struct lcd_panel *panel);
401 extern void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval);
402 extern void omapfb_notify_clients(struct omapfb_device *fbdev,
403                                   unsigned long event);
404 extern int  omapfb_register_client(struct omapfb_notifier_block *nb,
405                                    omapfb_notifier_callback_t callback,
406                                    void *callback_data);
407 extern int  omapfb_unregister_client(struct omapfb_notifier_block *nb);
408 extern int  omapfb_update_window_async(struct fb_info *fbi,
409                                        struct omapfb_update_window *win,
410                                        void (*callback)(void *),
411                                        void *callback_data);
412
413 /* in arch/arm/plat-omap/fb.c */
414 extern void omapfb_set_ctrl_platform_data(void *pdata);
415
416 #endif /* __KERNEL__ */
417
418 #endif /* __OMAPFB_H */