]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/lcd.h
Unified codebase for TX28, TX48, TX51, TX53
[karo-tx-uboot.git] / include / lcd.h
1 /*
2  * Copyright (C) 2004-2010 Freescale Semiconductor, Inc.
3  *
4  * MPC823 and PXA LCD Controller
5  *
6  * Modeled after video interface by Paolo Scaffardi
7  *
8  *
9  * (C) Copyright 2001
10  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11  *
12  * See file CREDITS for list of people who contributed to this
13  * project.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License as
17  * published by the Free Software Foundation; either version 2 of
18  * the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28  * MA 02111-1307 USA
29  */
30
31 #ifndef _LCD_H_
32 #define _LCD_H_
33
34 extern char lcd_is_enabled;
35
36 extern int lcd_line_length;
37 extern int lcd_color_fg;
38 extern int lcd_color_bg;
39
40 /*
41  * Frame buffer memory information
42  */
43 extern void *lcd_base;          /* Start of framebuffer memory  */
44 extern void *lcd_console_address;       /* Start of console buffer      */
45
46 extern short console_col;
47 extern short console_row;
48 extern struct vidinfo panel_info;
49
50 extern void lcd_ctrl_init (void *lcdbase);
51 extern void lcd_enable (void);
52
53 /* setcolreg used in 8bpp/16bpp; initcolregs used in monochrome */
54 extern void lcd_setcolreg (ushort regno,
55                                 ushort red, ushort green, ushort blue);
56 extern void lcd_initcolregs (void);
57
58 /* gunzip_bmp used if CONFIG_VIDEO_BMP_GZIP */
59 extern struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp);
60
61 #if defined CONFIG_MPC823
62 /*
63  * LCD controller stucture for MPC823 CPU
64  */
65 typedef struct vidinfo {
66         ushort  vl_col;         /* Number of columns (i.e. 640) */
67         ushort  vl_row;         /* Number of rows (i.e. 480) */
68         ushort  vl_width;       /* Width of display area in millimeters */
69         ushort  vl_height;      /* Height of display area in millimeters */
70
71         /* LCD configuration register */
72         u_char  vl_clkp;        /* Clock polarity */
73         u_char  vl_oep;         /* Output Enable polarity */
74         u_char  vl_hsp;         /* Horizontal Sync polarity */
75         u_char  vl_vsp;         /* Vertical Sync polarity */
76         u_char  vl_dp;          /* Data polarity */
77         u_char  vl_bpix;        /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
78         u_char  vl_lbw;         /* LCD Bus width, 0 = 4, 1 = 8 */
79         u_char  vl_splt;        /* Split display, 0 = single-scan, 1 = dual-scan */
80         u_char  vl_clor;        /* Color, 0 = mono, 1 = color */
81         u_char  vl_tft;         /* 0 = passive, 1 = TFT */
82
83         /* Horizontal control register. Timing from data sheet */
84         ushort  vl_wbl;         /* Wait between lines */
85
86         /* Vertical control register */
87         u_char  vl_vpw;         /* Vertical sync pulse width */
88         u_char  vl_lcdac;       /* LCD AC timing */
89         u_char  vl_wbf;         /* Wait between frames */
90 } vidinfo_t;
91
92 #elif defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
93         defined CONFIG_CPU_MONAHANS
94 /*
95  * PXA LCD DMA descriptor
96  */
97 struct pxafb_dma_descriptor {
98         u_long  fdadr;          /* Frame descriptor address register */
99         u_long  fsadr;          /* Frame source address register */
100         u_long  fidr;           /* Frame ID register */
101         u_long  ldcmd;          /* Command register */
102 };
103
104 /*
105  * PXA LCD info
106  */
107 struct pxafb_info {
108
109         /* Misc registers */
110         u_long  reg_lccr3;
111         u_long  reg_lccr2;
112         u_long  reg_lccr1;
113         u_long  reg_lccr0;
114         u_long  fdadr0;
115         u_long  fdadr1;
116
117         /* DMA descriptors */
118         struct  pxafb_dma_descriptor *  dmadesc_fblow;
119         struct  pxafb_dma_descriptor *  dmadesc_fbhigh;
120         struct  pxafb_dma_descriptor *  dmadesc_palette;
121
122         u_long  screen;         /* physical address of frame buffer */
123         u_long  palette;        /* physical address of palette memory */
124         u_int   palette_size;
125 };
126
127 /*
128  * LCD controller stucture for PXA CPU
129  */
130 typedef struct vidinfo {
131         ushort  vl_col;         /* Number of columns (i.e. 640) */
132         ushort  vl_row;         /* Number of rows (i.e. 480) */
133         ushort  vl_width;       /* Width of display area in millimeters */
134         ushort  vl_height;      /* Height of display area in millimeters */
135
136         /* LCD configuration register */
137         u_char  vl_clkp;        /* Clock polarity */
138         u_char  vl_oep;         /* Output Enable polarity */
139         u_char  vl_hsp;         /* Horizontal Sync polarity */
140         u_char  vl_vsp;         /* Vertical Sync polarity */
141         u_char  vl_dp;          /* Data polarity */
142         u_char  vl_bpix;        /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16 */
143         u_char  vl_lbw;         /* LCD Bus width, 0 = 4, 1 = 8 */
144         u_char  vl_splt;        /* Split display, 0 = single-scan, 1 = dual-scan */
145         u_char  vl_clor;        /* Color, 0 = mono, 1 = color */
146         u_char  vl_tft;         /* 0 = passive, 1 = TFT */
147
148         /* Horizontal control register. Timing from data sheet */
149         ushort  vl_hpw;         /* Horz sync pulse width */
150         u_char  vl_blw;         /* Wait before of line */
151         u_char  vl_elw;         /* Wait end of line */
152
153         /* Vertical control register. */
154         u_char  vl_vpw;         /* Vertical sync pulse width */
155         u_char  vl_bfw;         /* Wait before of frame */
156         u_char  vl_efw;         /* Wait end of frame */
157
158         /* PXA LCD controller params */
159         struct  pxafb_info pxa;
160 } vidinfo_t;
161
162 #elif defined(CONFIG_ATMEL_LCD)
163
164 typedef struct vidinfo {
165         ushort vl_col;          /* Number of columns (i.e. 640) */
166         ushort vl_row;          /* Number of rows (i.e. 480) */
167         u_long vl_clk;  /* pixel clock in ps    */
168
169         /* LCD configuration register */
170         u_long vl_sync;         /* Horizontal / vertical sync */
171         u_long vl_bpix;         /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16 */
172         u_long vl_tft;          /* 0 = passive, 1 = TFT */
173         u_long vl_cont_pol_low; /* contrast polarity is low */
174
175         /* Horizontal control register. */
176         u_long vl_hsync_len;    /* Length of horizontal sync */
177         u_long vl_left_margin;  /* Time from sync to picture */
178         u_long vl_right_margin; /* Time from picture to sync */
179
180         /* Vertical control register. */
181         u_long vl_vsync_len;    /* Length of vertical sync */
182         u_long vl_upper_margin; /* Time from sync to picture */
183         u_long vl_lower_margin; /* Time from picture to sync */
184
185         u_long  mmio;           /* Memory mapped registers */
186 } vidinfo_t;
187
188 #elif defined(CONFIG_EXYNOS_FB)
189
190 enum {
191         FIMD_RGB_INTERFACE = 1,
192         FIMD_CPU_INTERFACE = 2,
193 };
194
195 typedef struct vidinfo {
196         ushort vl_col;          /* Number of columns (i.e. 640) */
197         ushort vl_row;          /* Number of rows (i.e. 480) */
198         ushort vl_width;        /* Width of display area in millimeters */
199         ushort vl_height;       /* Height of display area in millimeters */
200
201         /* LCD configuration register */
202         u_char vl_freq;         /* Frequency */
203         u_char vl_clkp;         /* Clock polarity */
204         u_char vl_oep;          /* Output Enable polarity */
205         u_char vl_hsp;          /* Horizontal Sync polarity */
206         u_char vl_vsp;          /* Vertical Sync polarity */
207         u_char vl_dp;           /* Data polarity */
208         u_char vl_bpix;         /* Bits per pixel */
209
210         /* Horizontal control register. Timing from data sheet */
211         u_char vl_hspw;         /* Horz sync pulse width */
212         u_char vl_hfpd;         /* Wait before of line */
213         u_char vl_hbpd;         /* Wait end of line */
214
215         /* Vertical control register. */
216         u_char  vl_vspw;        /* Vertical sync pulse width */
217         u_char  vl_vfpd;        /* Wait before of frame */
218         u_char  vl_vbpd;        /* Wait end of frame */
219         u_char  vl_cmd_allow_len; /* Wait end of frame */
220
221         void (*cfg_gpio)(void);
222         void (*backlight_on)(unsigned int onoff);
223         void (*reset_lcd)(void);
224         void (*lcd_power_on)(void);
225         void (*cfg_ldo)(void);
226         void (*enable_ldo)(unsigned int onoff);
227         void (*mipi_power)(void);
228         void (*backlight_reset)(void);
229
230         unsigned int win_id;
231         unsigned int init_delay;
232         unsigned int power_on_delay;
233         unsigned int reset_delay;
234         unsigned int interface_mode;
235         unsigned int mipi_enabled;
236         unsigned int cs_setup;
237         unsigned int wr_setup;
238         unsigned int wr_act;
239         unsigned int wr_hold;
240
241         /* parent clock name(MPLL, EPLL or VPLL) */
242         unsigned int pclk_name;
243         /* ratio value for source clock from parent clock. */
244         unsigned int sclk_div;
245
246         unsigned int dual_lcd_enabled;
247
248 } vidinfo_t;
249
250 void init_panel_info(vidinfo_t *vid);
251
252 #elif defined(CONFIG_MXC2_LCD)
253
254 typedef struct vidinfo {
255         u_long vl_refresh;      /* Refresh Rate Hz */
256         u_long vl_row;          /* resolution in x */
257         u_long vl_col;          /* resolution in y */
258         u_long vl_pixclock;     /* pixel clock in picoseconds */
259         u_long vl_left_margin;  /* Horizontal back porch */
260         u_long vl_right_margin; /* Horizontal front porch */
261         u_long vl_upper_margin; /* Vertical back porch */
262         u_long vl_lower_margin; /* Vertical front porch */
263         u_long vl_hsync;        /* Horizontal sync pulse length */
264         u_long vl_vsync;        /* Vertical sync pulse length */
265         u_long vl_sync;         /* Polarity on data enable */
266         u_long vl_mode;         /* Video Mode */
267         u_long vl_flag;
268         u_char  vl_bpix;
269         ushort  *cmap;
270 } vidinfo_t;
271
272 #elif defined(CONFIG_MXC_EPDC)
273
274 struct waveform_modes {
275         int mode_init;
276         int mode_du;
277         int mode_gc4;
278         int mode_gc8;
279         int mode_gc16;
280         int mode_gc32;
281 };
282
283 struct epdc_data_struct {
284         /* EPDC buffer pointers */
285         u_long working_buf_addr;
286         u_long waveform_buf_addr;
287
288         /* Waveform mode definitions */
289         struct waveform_modes wv_modes;
290 };
291
292 typedef struct vidinfo {
293         u_long vl_refresh;      /* Refresh Rate Hz */
294         u_long vl_row;          /* resolution in x */
295         u_long vl_col;          /* resolution in y */
296         u_long vl_pixclock;     /* pixel clock in picoseconds */
297         u_long vl_left_margin;  /* Horizontal back porch */
298         u_long vl_right_margin; /* Horizontal front porch */
299         u_long vl_upper_margin; /* Vertical back porch */
300         u_long vl_lower_margin; /* Vertical front porch */
301         u_long vl_hsync;        /* Horizontal sync pulse length */
302         u_long vl_vsync;        /* Vertical sync pulse length */
303         u_long vl_sync;         /* Polarity on data enable */
304         u_long vl_mode;         /* Video Mode */
305         u_long vl_flag;
306         u_char  vl_bpix;
307         ushort  *cmap;
308         struct epdc_data_struct epdc_data;
309 } vidinfo_t;
310
311 #else
312
313 typedef struct vidinfo {
314         ushort  vl_col;         /* Number of columns (i.e. 160) */
315         ushort  vl_row;         /* Number of rows (i.e. 100) */
316
317         u_char  vl_bpix;        /* Bits per pixel, 0 = 1 */
318
319         ushort  *cmap;          /* Pointer to the colormap */
320
321         void    *priv;          /* Pointer to driver-specific data */
322 } vidinfo_t;
323
324 #endif /* CONFIG_MPC823, CONFIG_CPU_PXA25X, CONFIG_MCC200, CONFIG_ATMEL_LCD */
325
326 extern vidinfo_t panel_info;
327
328 /* Video functions */
329
330 void    lcd_disable     (void);
331 void    lcd_panel_disable(void);
332
333 /* int  lcd_init        (void *lcdbase); */
334 void    lcd_putc        (const char c);
335 void    lcd_puts        (const char *s);
336 void    lcd_printf      (const char *fmt, ...);
337 void    lcd_clear(void);
338 int     lcd_display_bitmap(ulong bmp_image, int x, int y);
339
340 /* Allow boards to customize the information displayed */
341 void lcd_show_board_info(void);
342
343 /************************************************************************/
344 /* ** BITMAP DISPLAY SUPPORT                                            */
345 /************************************************************************/
346 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
347 # include <bmp_layout.h>
348 # include <asm/byteorder.h>
349 #endif
350
351 /*
352  *  Information about displays we are using. This is for configuring
353  *  the LCD controller and memory allocation. Someone has to know what
354  *  is connected, as we can't autodetect anything.
355  */
356 #define CONFIG_SYS_HIGH 0       /* Pins are active high                 */
357 #define CONFIG_SYS_LOW          1       /* Pins are active low                  */
358
359 #define LCD_MONOCHROME  0
360 #define LCD_COLOR2      1
361 #define LCD_COLOR4      2
362 #define LCD_COLOR8      3
363 #define LCD_COLOR16     4
364 #define LCD_COLOR24     5
365
366 /*----------------------------------------------------------------------*/
367 #if defined(CONFIG_LCD_INFO_BELOW_LOGO)
368 # define LCD_INFO_X             0
369 # define LCD_INFO_Y             (BMP_LOGO_HEIGHT + VIDEO_FONT_HEIGHT)
370 #elif defined(CONFIG_LCD_LOGO)
371 # define LCD_INFO_X             (BMP_LOGO_WIDTH + 4 * VIDEO_FONT_WIDTH)
372 # define LCD_INFO_Y             (VIDEO_FONT_HEIGHT)
373 #else
374 # define LCD_INFO_X             (VIDEO_FONT_WIDTH)
375 # define LCD_INFO_Y             (VIDEO_FONT_HEIGHT)
376 #endif
377
378 /* Default to 8bpp if bit depth not specified */
379 #ifndef LCD_BPP
380 # define LCD_BPP                        LCD_COLOR8
381 #endif
382 #ifndef LCD_DF
383 # define LCD_DF                 1
384 #endif
385
386 /* Calculate nr. of bits per pixel  and nr. of colors */
387 #define NBITS(bit_code)         (1 << (bit_code))
388 #define NCOLORS(bit_code)       (1 << NBITS(bit_code))
389
390 /************************************************************************/
391 /* ** CONSOLE CONSTANTS                                                 */
392 /************************************************************************/
393 #if LCD_BPP == LCD_MONOCHROME
394
395 /*
396  * Simple black/white definitions
397  */
398 # define CONSOLE_COLOR_BLACK    0
399 # define CONSOLE_COLOR_WHITE    1       /* Must remain last / highest   */
400
401 #elif LCD_BPP == LCD_COLOR8
402
403 /*
404  * 8bpp color definitions
405  */
406 # define CONSOLE_COLOR_BLACK    0
407 # define CONSOLE_COLOR_RED      1
408 # define CONSOLE_COLOR_GREEN    2
409 # define CONSOLE_COLOR_YELLOW   3
410 # define CONSOLE_COLOR_BLUE     4
411 # define CONSOLE_COLOR_MAGENTA  5
412 # define CONSOLE_COLOR_CYAN     6
413 # define CONSOLE_COLOR_GREY     14
414 # define CONSOLE_COLOR_WHITE    15      /* Must remain last / highest   */
415
416 #elif LCD_BPP == LCD_COLOR16
417
418 /*
419  * 16bpp color definitions
420  */
421 # define CONSOLE_COLOR_BLACK    0x0000
422 # define CONSOLE_COLOR_RED      0xf800
423 # define CONSOLE_COLOR_GREEN    0x07e0
424 # define CONSOLE_COLOR_YELLOW   0xffe0
425 # define CONSOLE_COLOR_BLUE     0x001f
426 # define CONSOLE_COLOR_MAGENTA  0xf81f
427 # define CONSOLE_COLOR_CYAN     0x07ff
428 # define CONSOLE_COLOR_GREY     0xcccc
429 # define CONSOLE_COLOR_WHITE    0xffff  /* Must remain last / highest   */
430
431 #elif LCD_BPP == LCD_COLOR24
432 /*
433  * 16bpp color definitions
434  */
435 # define CONSOLE_COLOR_BLACK    0x00000000
436 # define CONSOLE_COLOR_RED      0x00ff0000
437 # define CONSOLE_COLOR_GREEN    0x0000ff00
438 # define CONSOLE_COLOR_YELLOW   0x00ffff00
439 # define CONSOLE_COLOR_BLUE     0x000000ff
440 # define CONSOLE_COLOR_MAGENTA  0x00ff00ff
441 # define CONSOLE_COLOR_CYAN     0x0000ffff
442 # define CONSOLE_COLOR_GREY     0x00cccccc
443 # define CONSOLE_COLOR_WHITE    0x00ffffff      /* Must remain last / highest   */
444 #else
445 #error Invalid LCD_BPP setting
446 #endif /* color definitions */
447
448 /************************************************************************/
449 #ifndef PAGE_SIZE
450 # define PAGE_SIZE      4096
451 #endif
452
453 /************************************************************************/
454 /* ** CONSOLE DEFINITIONS & FUNCTIONS                                   */
455 /************************************************************************/
456 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
457 # define CONSOLE_ROWS           ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
458                                         / VIDEO_FONT_HEIGHT)
459 #else
460 # define CONSOLE_ROWS           (panel_info.vl_row / VIDEO_FONT_HEIGHT)
461 #endif
462
463 #define CONSOLE_COLS            (panel_info.vl_col / VIDEO_FONT_WIDTH)
464 #define CONSOLE_ROW_SIZE        (VIDEO_FONT_HEIGHT * lcd_line_length)
465 #define CONSOLE_ROW_FIRST       (lcd_console_address)
466 #define CONSOLE_ROW_SECOND      (lcd_console_address + CONSOLE_ROW_SIZE)
467 #define CONSOLE_ROW_LAST        (lcd_console_address + CONSOLE_SIZE \
468                                         - CONSOLE_ROW_SIZE)
469 #define CONSOLE_SIZE            (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
470 #define CONSOLE_SCROLL_SIZE     (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
471
472 #if LCD_BPP == LCD_MONOCHROME
473 # define COLOR_MASK(c)          ((c)      | (c) << 1 | (c) << 2 | (c) << 3 | \
474                                  (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
475 #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || (LCD_BPP == LCD_COLOR24)
476 # define COLOR_MASK(c)          (c)
477 #else
478 # error Unsupported LCD BPP.
479 #endif
480
481 /************************************************************************/
482
483 #endif  /* _LCD_H_ */