d433baf4e9777292e864d20d9172b12b9dc3f445
[firefly-linux-kernel-4.4.55.git] / arch / arm / plat-omap / include / plat / display.h
1 /*
2  * linux/include/asm-arm/arch-omap/display.h
3  *
4  * Copyright (C) 2008 Nokia Corporation
5  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 as published by
9  * the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef __ASM_ARCH_OMAP_DISPLAY_H
21 #define __ASM_ARCH_OMAP_DISPLAY_H
22
23 #include <linux/list.h>
24 #include <linux/kobject.h>
25 #include <linux/device.h>
26 #include <asm/atomic.h>
27
28 #define DISPC_IRQ_FRAMEDONE             (1 << 0)
29 #define DISPC_IRQ_VSYNC                 (1 << 1)
30 #define DISPC_IRQ_EVSYNC_EVEN           (1 << 2)
31 #define DISPC_IRQ_EVSYNC_ODD            (1 << 3)
32 #define DISPC_IRQ_ACBIAS_COUNT_STAT     (1 << 4)
33 #define DISPC_IRQ_PROG_LINE_NUM         (1 << 5)
34 #define DISPC_IRQ_GFX_FIFO_UNDERFLOW    (1 << 6)
35 #define DISPC_IRQ_GFX_END_WIN           (1 << 7)
36 #define DISPC_IRQ_PAL_GAMMA_MASK        (1 << 8)
37 #define DISPC_IRQ_OCP_ERR               (1 << 9)
38 #define DISPC_IRQ_VID1_FIFO_UNDERFLOW   (1 << 10)
39 #define DISPC_IRQ_VID1_END_WIN          (1 << 11)
40 #define DISPC_IRQ_VID2_FIFO_UNDERFLOW   (1 << 12)
41 #define DISPC_IRQ_VID2_END_WIN          (1 << 13)
42 #define DISPC_IRQ_SYNC_LOST             (1 << 14)
43 #define DISPC_IRQ_SYNC_LOST_DIGIT       (1 << 15)
44 #define DISPC_IRQ_WAKEUP                (1 << 16)
45
46 struct omap_dss_device;
47 struct omap_overlay_manager;
48
49 enum omap_display_type {
50         OMAP_DISPLAY_TYPE_NONE          = 0,
51         OMAP_DISPLAY_TYPE_DPI           = 1 << 0,
52         OMAP_DISPLAY_TYPE_DBI           = 1 << 1,
53         OMAP_DISPLAY_TYPE_SDI           = 1 << 2,
54         OMAP_DISPLAY_TYPE_DSI           = 1 << 3,
55         OMAP_DISPLAY_TYPE_VENC          = 1 << 4,
56 };
57
58 enum omap_plane {
59         OMAP_DSS_GFX    = 0,
60         OMAP_DSS_VIDEO1 = 1,
61         OMAP_DSS_VIDEO2 = 2
62 };
63
64 enum omap_channel {
65         OMAP_DSS_CHANNEL_LCD    = 0,
66         OMAP_DSS_CHANNEL_DIGIT  = 1,
67 };
68
69 enum omap_color_mode {
70         OMAP_DSS_COLOR_CLUT1    = 1 << 0,  /* BITMAP 1 */
71         OMAP_DSS_COLOR_CLUT2    = 1 << 1,  /* BITMAP 2 */
72         OMAP_DSS_COLOR_CLUT4    = 1 << 2,  /* BITMAP 4 */
73         OMAP_DSS_COLOR_CLUT8    = 1 << 3,  /* BITMAP 8 */
74         OMAP_DSS_COLOR_RGB12U   = 1 << 4,  /* RGB12, 16-bit container */
75         OMAP_DSS_COLOR_ARGB16   = 1 << 5,  /* ARGB16 */
76         OMAP_DSS_COLOR_RGB16    = 1 << 6,  /* RGB16 */
77         OMAP_DSS_COLOR_RGB24U   = 1 << 7,  /* RGB24, 32-bit container */
78         OMAP_DSS_COLOR_RGB24P   = 1 << 8,  /* RGB24, 24-bit container */
79         OMAP_DSS_COLOR_YUV2     = 1 << 9,  /* YUV2 4:2:2 co-sited */
80         OMAP_DSS_COLOR_UYVY     = 1 << 10, /* UYVY 4:2:2 co-sited */
81         OMAP_DSS_COLOR_ARGB32   = 1 << 11, /* ARGB32 */
82         OMAP_DSS_COLOR_RGBA32   = 1 << 12, /* RGBA32 */
83         OMAP_DSS_COLOR_RGBX32   = 1 << 13, /* RGBx32 */
84 };
85
86 enum omap_lcd_display_type {
87         OMAP_DSS_LCD_DISPLAY_STN,
88         OMAP_DSS_LCD_DISPLAY_TFT,
89 };
90
91 enum omap_dss_load_mode {
92         OMAP_DSS_LOAD_CLUT_AND_FRAME    = 0,
93         OMAP_DSS_LOAD_CLUT_ONLY         = 1,
94         OMAP_DSS_LOAD_FRAME_ONLY        = 2,
95         OMAP_DSS_LOAD_CLUT_ONCE_FRAME   = 3,
96 };
97
98 enum omap_dss_trans_key_type {
99         OMAP_DSS_COLOR_KEY_GFX_DST = 0,
100         OMAP_DSS_COLOR_KEY_VID_SRC = 1,
101 };
102
103 enum omap_rfbi_te_mode {
104         OMAP_DSS_RFBI_TE_MODE_1 = 1,
105         OMAP_DSS_RFBI_TE_MODE_2 = 2,
106 };
107
108 enum omap_panel_config {
109         OMAP_DSS_LCD_IVS                = 1<<0,
110         OMAP_DSS_LCD_IHS                = 1<<1,
111         OMAP_DSS_LCD_IPC                = 1<<2,
112         OMAP_DSS_LCD_IEO                = 1<<3,
113         OMAP_DSS_LCD_RF                 = 1<<4,
114         OMAP_DSS_LCD_ONOFF              = 1<<5,
115
116         OMAP_DSS_LCD_TFT                = 1<<20,
117 };
118
119 enum omap_dss_venc_type {
120         OMAP_DSS_VENC_TYPE_COMPOSITE,
121         OMAP_DSS_VENC_TYPE_SVIDEO,
122 };
123
124 enum omap_display_caps {
125         OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE      = 1 << 0,
126         OMAP_DSS_DISPLAY_CAP_TEAR_ELIM          = 1 << 1,
127 };
128
129 enum omap_dss_update_mode {
130         OMAP_DSS_UPDATE_DISABLED = 0,
131         OMAP_DSS_UPDATE_AUTO,
132         OMAP_DSS_UPDATE_MANUAL,
133 };
134
135 enum omap_dss_display_state {
136         OMAP_DSS_DISPLAY_DISABLED = 0,
137         OMAP_DSS_DISPLAY_ACTIVE,
138         OMAP_DSS_DISPLAY_SUSPENDED,
139 };
140
141 /* XXX perhaps this should be removed */
142 enum omap_dss_overlay_managers {
143         OMAP_DSS_OVL_MGR_LCD,
144         OMAP_DSS_OVL_MGR_TV,
145 };
146
147 enum omap_dss_rotation_type {
148         OMAP_DSS_ROT_DMA = 0,
149         OMAP_DSS_ROT_VRFB = 1,
150 };
151
152 /* clockwise rotation angle */
153 enum omap_dss_rotation_angle {
154         OMAP_DSS_ROT_0   = 0,
155         OMAP_DSS_ROT_90  = 1,
156         OMAP_DSS_ROT_180 = 2,
157         OMAP_DSS_ROT_270 = 3,
158 };
159
160 enum omap_overlay_caps {
161         OMAP_DSS_OVL_CAP_SCALE = 1 << 0,
162         OMAP_DSS_OVL_CAP_DISPC = 1 << 1,
163 };
164
165 enum omap_overlay_manager_caps {
166         OMAP_DSS_OVL_MGR_CAP_DISPC = 1 << 0,
167 };
168
169 /* RFBI */
170
171 struct rfbi_timings {
172         int cs_on_time;
173         int cs_off_time;
174         int we_on_time;
175         int we_off_time;
176         int re_on_time;
177         int re_off_time;
178         int we_cycle_time;
179         int re_cycle_time;
180         int cs_pulse_width;
181         int access_time;
182
183         int clk_div;
184
185         u32 tim[5];             /* set by rfbi_convert_timings() */
186
187         int converted;
188 };
189
190 void omap_rfbi_write_command(const void *buf, u32 len);
191 void omap_rfbi_read_data(void *buf, u32 len);
192 void omap_rfbi_write_data(const void *buf, u32 len);
193 void omap_rfbi_write_pixels(const void __iomem *buf, int scr_width,
194                 u16 x, u16 y,
195                 u16 w, u16 h);
196 int omap_rfbi_enable_te(bool enable, unsigned line);
197 int omap_rfbi_setup_te(enum omap_rfbi_te_mode mode,
198                              unsigned hs_pulse_time, unsigned vs_pulse_time,
199                              int hs_pol_inv, int vs_pol_inv, int extif_div);
200
201 /* DSI */
202 void dsi_bus_lock(void);
203 void dsi_bus_unlock(void);
204 int dsi_vc_dcs_write(int channel, u8 *data, int len);
205 int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd);
206 int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param);
207 int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len);
208 int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen);
209 int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data);
210 int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2);
211 int dsi_vc_set_max_rx_packet_size(int channel, u16 len);
212 int dsi_vc_send_null(int channel);
213 int dsi_vc_send_bta_sync(int channel);
214
215 /* Board specific data */
216 struct omap_dss_board_info {
217         int (*get_last_off_on_transaction_id)(struct device *dev);
218         int num_devices;
219         struct omap_dss_device **devices;
220         struct omap_dss_device *default_device;
221 };
222
223 struct omap_video_timings {
224         /* Unit: pixels */
225         u16 x_res;
226         /* Unit: pixels */
227         u16 y_res;
228         /* Unit: KHz */
229         u32 pixel_clock;
230         /* Unit: pixel clocks */
231         u16 hsw;        /* Horizontal synchronization pulse width */
232         /* Unit: pixel clocks */
233         u16 hfp;        /* Horizontal front porch */
234         /* Unit: pixel clocks */
235         u16 hbp;        /* Horizontal back porch */
236         /* Unit: line clocks */
237         u16 vsw;        /* Vertical synchronization pulse width */
238         /* Unit: line clocks */
239         u16 vfp;        /* Vertical front porch */
240         /* Unit: line clocks */
241         u16 vbp;        /* Vertical back porch */
242 };
243
244 #ifdef CONFIG_OMAP2_DSS_VENC
245 /* Hardcoded timings for tv modes. Venc only uses these to
246  * identify the mode, and does not actually use the configs
247  * itself. However, the configs should be something that
248  * a normal monitor can also show */
249 extern const struct omap_video_timings omap_dss_pal_timings;
250 extern const struct omap_video_timings omap_dss_ntsc_timings;
251 #endif
252
253 struct omap_overlay_info {
254         bool enabled;
255
256         u32 paddr;
257         void __iomem *vaddr;
258         u16 screen_width;
259         u16 width;
260         u16 height;
261         enum omap_color_mode color_mode;
262         u8 rotation;
263         enum omap_dss_rotation_type rotation_type;
264         bool mirror;
265
266         u16 pos_x;
267         u16 pos_y;
268         u16 out_width;  /* if 0, out_width == width */
269         u16 out_height; /* if 0, out_height == height */
270         u8 global_alpha;
271         u8 pre_mult_alpha;
272 };
273
274 struct omap_overlay {
275         struct kobject kobj;
276         struct list_head list;
277
278         /* static fields */
279         const char *name;
280         int id;
281         enum omap_color_mode supported_modes;
282         enum omap_overlay_caps caps;
283
284         /* dynamic fields */
285         struct omap_overlay_manager *manager;
286         struct omap_overlay_info info;
287
288         /* if true, info has been changed, but not applied() yet */
289         bool info_dirty;
290
291         int (*set_manager)(struct omap_overlay *ovl,
292                 struct omap_overlay_manager *mgr);
293         int (*unset_manager)(struct omap_overlay *ovl);
294
295         int (*set_overlay_info)(struct omap_overlay *ovl,
296                         struct omap_overlay_info *info);
297         void (*get_overlay_info)(struct omap_overlay *ovl,
298                         struct omap_overlay_info *info);
299
300         int (*wait_for_go)(struct omap_overlay *ovl);
301 };
302
303 struct omap_overlay_manager_info {
304         u32 default_color;
305
306         enum omap_dss_trans_key_type trans_key_type;
307         u32 trans_key;
308         bool trans_enabled;
309
310         bool alpha_enabled;
311 };
312
313 struct omap_overlay_manager {
314         struct kobject kobj;
315         struct list_head list;
316
317         /* static fields */
318         const char *name;
319         int id;
320         enum omap_overlay_manager_caps caps;
321         int num_overlays;
322         struct omap_overlay **overlays;
323         enum omap_display_type supported_displays;
324
325         /* dynamic fields */
326         struct omap_dss_device *device;
327         struct omap_overlay_manager_info info;
328
329         bool device_changed;
330         /* if true, info has been changed but not applied() yet */
331         bool info_dirty;
332
333         int (*set_device)(struct omap_overlay_manager *mgr,
334                 struct omap_dss_device *dssdev);
335         int (*unset_device)(struct omap_overlay_manager *mgr);
336
337         int (*set_manager_info)(struct omap_overlay_manager *mgr,
338                         struct omap_overlay_manager_info *info);
339         void (*get_manager_info)(struct omap_overlay_manager *mgr,
340                         struct omap_overlay_manager_info *info);
341
342         int (*apply)(struct omap_overlay_manager *mgr);
343         int (*wait_for_go)(struct omap_overlay_manager *mgr);
344         int (*wait_for_vsync)(struct omap_overlay_manager *mgr);
345
346         int (*enable)(struct omap_overlay_manager *mgr);
347         int (*disable)(struct omap_overlay_manager *mgr);
348 };
349
350 struct omap_dss_device {
351         struct device dev;
352
353         enum omap_display_type type;
354
355         union {
356                 struct {
357                         u8 data_lines;
358                 } dpi;
359
360                 struct {
361                         u8 channel;
362                         u8 data_lines;
363                 } rfbi;
364
365                 struct {
366                         u8 datapairs;
367                 } sdi;
368
369                 struct {
370                         u8 clk_lane;
371                         u8 clk_pol;
372                         u8 data1_lane;
373                         u8 data1_pol;
374                         u8 data2_lane;
375                         u8 data2_pol;
376
377                         struct {
378                                 u16 regn;
379                                 u16 regm;
380                                 u16 regm3;
381                                 u16 regm4;
382
383                                 u16 lp_clk_div;
384
385                                 u16 lck_div;
386                                 u16 pck_div;
387                         } div;
388
389                         bool ext_te;
390                         u8 ext_te_gpio;
391                 } dsi;
392
393                 struct {
394                         enum omap_dss_venc_type type;
395                         bool invert_polarity;
396                 } venc;
397         } phy;
398
399         struct {
400                 struct omap_video_timings timings;
401
402                 int acbi;       /* ac-bias pin transitions per interrupt */
403                 /* Unit: line clocks */
404                 int acb;        /* ac-bias pin frequency */
405
406                 enum omap_panel_config config;
407         } panel;
408
409         struct {
410                 u8 pixel_size;
411                 struct rfbi_timings rfbi_timings;
412         } ctrl;
413
414         int reset_gpio;
415
416         int max_backlight_level;
417
418         const char *name;
419
420         /* used to match device to driver */
421         const char *driver_name;
422
423         void *data;
424
425         struct omap_dss_driver *driver;
426
427         /* helper variable for driver suspend/resume */
428         bool activate_after_resume;
429
430         enum omap_display_caps caps;
431
432         struct omap_overlay_manager *manager;
433
434         enum omap_dss_display_state state;
435
436         /* platform specific  */
437         int (*platform_enable)(struct omap_dss_device *dssdev);
438         void (*platform_disable)(struct omap_dss_device *dssdev);
439         int (*set_backlight)(struct omap_dss_device *dssdev, int level);
440         int (*get_backlight)(struct omap_dss_device *dssdev);
441 };
442
443 struct omap_dss_driver {
444         struct device_driver driver;
445
446         int (*probe)(struct omap_dss_device *);
447         void (*remove)(struct omap_dss_device *);
448
449         int (*enable)(struct omap_dss_device *display);
450         void (*disable)(struct omap_dss_device *display);
451         int (*suspend)(struct omap_dss_device *display);
452         int (*resume)(struct omap_dss_device *display);
453         int (*run_test)(struct omap_dss_device *display, int test);
454
455         int (*set_update_mode)(struct omap_dss_device *dssdev,
456                         enum omap_dss_update_mode);
457         enum omap_dss_update_mode (*get_update_mode)(
458                         struct omap_dss_device *dssdev);
459
460         int (*update)(struct omap_dss_device *dssdev,
461                                u16 x, u16 y, u16 w, u16 h);
462         int (*sync)(struct omap_dss_device *dssdev);
463
464         int (*enable_te)(struct omap_dss_device *dssdev, bool enable);
465         int (*get_te)(struct omap_dss_device *dssdev);
466
467         u8 (*get_rotate)(struct omap_dss_device *dssdev);
468         int (*set_rotate)(struct omap_dss_device *dssdev, u8 rotate);
469
470         bool (*get_mirror)(struct omap_dss_device *dssdev);
471         int (*set_mirror)(struct omap_dss_device *dssdev, bool enable);
472
473         int (*memory_read)(struct omap_dss_device *dssdev,
474                         void *buf, size_t size,
475                         u16 x, u16 y, u16 w, u16 h);
476
477         void (*get_resolution)(struct omap_dss_device *dssdev,
478                         u16 *xres, u16 *yres);
479         int (*get_recommended_bpp)(struct omap_dss_device *dssdev);
480
481         int (*check_timings)(struct omap_dss_device *dssdev,
482                         struct omap_video_timings *timings);
483         void (*set_timings)(struct omap_dss_device *dssdev,
484                         struct omap_video_timings *timings);
485         void (*get_timings)(struct omap_dss_device *dssdev,
486                         struct omap_video_timings *timings);
487
488         int (*set_wss)(struct omap_dss_device *dssdev, u32 wss);
489         u32 (*get_wss)(struct omap_dss_device *dssdev);
490 };
491
492 int omap_dss_register_driver(struct omap_dss_driver *);
493 void omap_dss_unregister_driver(struct omap_dss_driver *);
494
495 int omap_dss_register_device(struct omap_dss_device *);
496 void omap_dss_unregister_device(struct omap_dss_device *);
497
498 void omap_dss_get_device(struct omap_dss_device *dssdev);
499 void omap_dss_put_device(struct omap_dss_device *dssdev);
500 #define for_each_dss_dev(d) while ((d = omap_dss_get_next_device(d)) != NULL)
501 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from);
502 struct omap_dss_device *omap_dss_find_device(void *data,
503                 int (*match)(struct omap_dss_device *dssdev, void *data));
504
505 int omap_dss_start_device(struct omap_dss_device *dssdev);
506 void omap_dss_stop_device(struct omap_dss_device *dssdev);
507
508 int omap_dss_get_num_overlay_managers(void);
509 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num);
510
511 int omap_dss_get_num_overlays(void);
512 struct omap_overlay *omap_dss_get_overlay(int num);
513
514 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
515                 u16 *xres, u16 *yres);
516 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev);
517
518 typedef void (*omap_dispc_isr_t) (void *arg, u32 mask);
519 int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask);
520 int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask);
521
522 int omap_dispc_wait_for_irq_timeout(u32 irqmask, unsigned long timeout);
523 int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
524                 unsigned long timeout);
525
526 #define to_dss_driver(x) container_of((x), struct omap_dss_driver, driver)
527 #define to_dss_device(x) container_of((x), struct omap_dss_device, dev)
528
529 void omapdss_dsi_vc_enable_hs(int channel, bool enable);
530 int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable);
531
532 int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
533                                     u16 *x, u16 *y, u16 *w, u16 *h,
534                                     bool enlarge_update_area);
535 int omap_dsi_update(struct omap_dss_device *dssdev,
536                 int channel,
537                 u16 x, u16 y, u16 w, u16 h,
538                 void (*callback)(int, void *), void *data);
539
540 int omapdss_dsi_display_enable(struct omap_dss_device *dssdev);
541 void omapdss_dsi_display_disable(struct omap_dss_device *dssdev);
542
543 int omapdss_dpi_display_enable(struct omap_dss_device *dssdev);
544 void omapdss_dpi_display_disable(struct omap_dss_device *dssdev);
545 void dpi_set_timings(struct omap_dss_device *dssdev,
546                         struct omap_video_timings *timings);
547 int dpi_check_timings(struct omap_dss_device *dssdev,
548                         struct omap_video_timings *timings);
549
550 int omapdss_sdi_display_enable(struct omap_dss_device *dssdev);
551 void omapdss_sdi_display_disable(struct omap_dss_device *dssdev);
552
553 int omapdss_rfbi_display_enable(struct omap_dss_device *dssdev);
554 void omapdss_rfbi_display_disable(struct omap_dss_device *dssdev);
555 int omap_rfbi_prepare_update(struct omap_dss_device *dssdev,
556                 u16 *x, u16 *y, u16 *w, u16 *h);
557 int omap_rfbi_update(struct omap_dss_device *dssdev,
558                 u16 x, u16 y, u16 w, u16 h,
559                 void (*callback)(void *), void *data);
560
561 #endif