source: umon/ports/beagleboneblack/omap3530_lcd.c @ dee5246

Last change on this file since dee5246 was dee5246, checked in by Jarielle Catbagan <jcatbagan93@…>, on 06/19/15 at 18:53:54

Duplicated csb740 directory to beagleboneblack directory for BBB port

  • Property mode set to 100644
File size: 10.0 KB
Line 
1//==========================================================================
2//
3//      omap3530_lcd.c
4//
5// Author(s):   Luis Torrico - Cogent Computer Systems, Inc.
6// Date:        12-10-2008
7// Description: Init Code for TI OMAP3530 LCD Controller
8// NOTE                 Only 16-bit mode has been tested!
9//
10//==========================================================================
11
12#include "config.h"
13#include "cpuio.h"
14#include "stddefs.h"
15#include "genlib.h"
16#include "omap3530.h"
17#include "omap3530_lcd.h"
18#include "cpu_gpio.h"
19#include "vga_lookup.h"
20#include "font8x16.h"
21#include "fb_draw.h"
22#include "warmstart.h"
23
24#if INCLUDE_LCD
25
26//--------------------------------------------------------------------------
27// function prototypes and externs
28//
29void fbdev_init(void);
30
31extern void udelay(int);
32extern int GPIO_clr(int);
33extern int GPIO_set(int);
34extern int GPIO_tst(int);
35extern int GPIO_out(int);
36extern int GPIO_in(int);
37
38// ADDED FOR WRITING CHARACTERS TO THE DISPLAY
39void lcd_putchar(char c);
40void lcd_writechar(uchar c);
41void lcd_clr_row(int char_row);
42void lcd_clr_scr(void);
43void lcd_switch_buffer(void);
44
45// globals to keep track of foreground, background colors and x,y position
46int lcd_color_depth;            // 4, 8 or 16
47int lcd_fg_color;                       // 0 to 15, used as lookup into VGA color table
48int lcd_bg_color;                       // 0 to 15, used as lookup into VGA color table
49int lcd_col;                            // current column, 0 to COLS_PER_SCREEN - 1
50int lcd_row;                            // current row, 0 to (ROWS_PER_SCREEN * 2) - 1
51int lcd_tst_mode = 0;
52ulong lcd_fb_offset;            // current offset into frame buffer for lcd_putchar
53
54//#define LCD_DBG
55//--------------------------------------------------------------------------
56// fbdev_init
57//
58// This function sets up the OMAP3530 LCD Controller, to be used
59// as uMon's frame buffer device.
60//
61void
62fbdev_init(void)
63{
64        //ushort temp16;
65
66        if (StateOfMonitor != INITIALIZE)
67                return;
68
69        lcd_color_depth = 16;
70        lcd_fg_color = vga_lookup[LCD_FG_DEF];
71        lcd_bg_color = vga_lookup[LCD_BG_DEF];
72
73        // Select DSS1_ALWON_FCLK (96MHz) as source for DSI and DISPC
74    DSS_REG(DSS_CONTROL) = 0x30;
75
76    // apply a soft reset to the display subsystem
77    DISPC_REG(DISPC_SYSCONFIG) = 0x02;
78
79        udelay(1000);
80       
81        // Set interface and functional clock to on during wakeup
82        // and no standby or idle
83    DISPC_REG(DISPC_SYSCONFIG) |= 0x2015;
84
85        // Set up the DMA base address
86    DISPC_REG(DISPC_GFX_BA) = 0x80200000;
87 
88        // Set up RGB 16 and disable the DMA for now
89    DISPC_REG(DISPC_GFX_ATTR) = 0x0000000C;
90 
91        // Set preload based on equation in section 15.5.3.2 in RM
92    //DISPC_REG(DISPC_GFX_PRELOAD) = 0x60;
93 
94        // Set number of bytes to increment at end of row to 1 (default value)
95    DISPC_REG(DISPC_GFX_ROW_INC) = 0x0001;
96 
97        // Set number of bytes to increment between two pixels to 1 (default value)
98    DISPC_REG(DISPC_GFX_PIX_INC) = 0x0001;
99 
100        // Set FIFO thresholds to defaults (hi = 1023, lo = 960)
101    //DISPC_REG(DISPC_GFX_FIFO_TH) = 0x03FF03C0;
102    DISPC_REG(DISPC_GFX_FIFO_TH) = 0x03FC03BC;
103 
104        // Set start position to 0 (frame buffer and active display area are the same)
105    DISPC_REG(DISPC_GFX_POS) = 0x00000000;
106 
107        // Set frame buffer size, Y = PIXELS_PER_COL, X = PIXELS_PER_ROW
108    DISPC_REG(DISPC_GFX_SIZE) = (((PIXELS_PER_COL -1) << 16) | (PIXELS_PER_ROW - 1));
109 
110        // Set the control register keep bit 5 (GOLCD) and bit 28 (LCDENABLESIGNAL) low
111        // until shadow registers have all been written
112    DISPC_REG(DISPC_CONTROL) = 0x38019209;
113 
114    // Disable all gating, pixel clock always toggles, frame data only
115        // loaded every frame (palette/gamma table off)
116    DISPC_REG(DISPC_CONFIG) = 0x00000004;
117    //DISPC_REG(DISPC_CONFIG) = 0x00000000;
118 
119    // Disable all capabilities not used for LCD
120    DISPC_REG(DISPC_CAPABLE) = 0x00000000;
121 
122        // Set horizontal timing
123    DISPC_REG(DISPC_TIMING_H) = ((LCD_H_BACK << 20) | (LCD_H_FRONT << 8) | LCD_H_WIDTH);
124 
125        // Set vertical timing
126    DISPC_REG(DISPC_TIMING_V) = ((LCD_V_BACK << 20) | (LCD_V_FRONT << 8) | LCD_V_WIDTH);
127 
128        // Set syncs low true and DE to hi true
129    DISPC_REG(DISPC_POL_FREQ) = 0x00003000;
130       
131        // Set logic divisor to 1 and pixel divisor to 2
132    DISPC_REG(DISPC_DIVISOR) = 0x00020001;
133       
134        // Set LCD size, lines per panel is , pixels per line is
135    DISPC_REG(DISPC_SIZE_LCD) = (((PIXELS_PER_COL -1) << 16) | (PIXELS_PER_ROW - 1));
136       
137        // Enable the DMA
138    DISPC_REG(DISPC_GFX_ATTR) |= 0x00000001;
139 
140        // Set bit 5 (GOLCD) to enable LCD
141    DISPC_REG(DISPC_CONTROL) |= 0x00000020;
142
143        printf("OMAP3530 LCD Initialization Complete.\n");
144
145        return;
146}
147
148/* fbdev_setstart():
149 * Used by uMon's FBI interface to establish the starting address of
150 * the frame buffer memory.
151 */
152void
153fbdev_setstart(long offset)
154{
155        // Select DSS1_ALWON_FCLK (96MHz) as source for DSI and DISPC
156    DSS_REG(DSS_CONTROL) = 0x30;
157
158    // Set up the DMA base address
159    DISPC_REG(DISPC_GFX_BA) = offset;
160
161        // Enable the DMA
162    DISPC_REG(DISPC_GFX_ATTR) |= 0x00000001;
163 
164        // Set bit 5 (GOLCD) to enable LCD
165    DISPC_REG(DISPC_CONTROL) |= 0x00000020;
166
167        return;
168}
169
170char *lcd_tstHelp[] = {
171    "OMAP3530 LCD controller test",
172    "-[n,x,d[4,8,16]]",
173        "The user may set color depth to run the test at.",
174        "The frame buffer R/W test will test all of the frame ",
175        "buffer regardless of depth.",
176    "Options...",
177    "  -n    run test without keycheck - CAUTION: RESET SYSTEM TO STOP!",
178        "  -d4   run test, force a depth of 4-bits/pixel",
179        "  -d8   run test, force a depth of 8-bits/pixel",
180        "  -d16  run test, force a depth of 16-bits/pixel",
181        "  -x    init only, do not run frame buffer tests",
182        "",
183        "  No options, default to current mode and depth.",
184        0
185};
186
187int lcd_tst(int argc,char *argv[])
188{
189        volatile ushort wr16, rd16;
190        int i, x, opt;
191        int no_wait = 0;
192        int init_only = 0;
193        char c;
194
195        lcd_tst_mode = 1;
196
197    while ((opt=getopt(argc,argv,"clnsxd:4,8,16")) != -1) {
198        switch(opt) {
199                        case 'd':       // set the color depth
200                switch(*optarg) {
201                    case '4':
202                                lcd_color_depth = 4;
203                                                printf("Forcing 4bpp Mode!\n");
204                            break;
205                    case '8':
206                        lcd_color_depth = 8;
207                                                printf("Forcing 8bpp Mode!\n");
208                        break;
209                        default:        // test with 16bpp
210                            lcd_color_depth = 16;
211                                                printf("Forcing 16bpp Mode!\n");
212                                                break;
213                }
214                    break;
215                case 'n':   // no waiting for keypress - fastest operation
216                                no_wait = 1;
217                                printf("No Keypress Mode, Must Reset System to Stop!\n");
218                                break;
219                case 'x':   // init only
220                                no_wait = 1;
221                                printf("Initializing LCD, Skipping testsp!\n");
222                                init_only = 1;
223                                break;
224                        default:        // test with current mode
225                                break;
226                }
227        }
228
229        // get the new parameters into the LCD controller
230        fbdev_init();
231
232        if (init_only) return 0;
233
234        printf("Frame Buffer R/W...");
235        // do an address=data read/write test on the frame buffer
236        // PIXELS_PER_COL * PIXELS_PER_ROW is the highest pixel. 
237        // Multiply by bits_per_pixel (sed_color_depth), then
238        // divide by 8 to get the actual byte count.
239        for (i = 0; i < LCD_FB_SIZE(lcd_color_depth) + LCD_ROW_SIZE(lcd_color_depth); i += 2){ 
240                LCD_BUF(i) = i & 0xffff;
241                rd16 = LCD_BUF(i);
242                if(rd16 != (i & 0xffff)){
243                        printf("Fail at 0x%08x, WR 0x%08x, RD 0x%04lx!\n",LCD_BUF_ADD + i, i, (ulong)rd16);
244                        return -1;
245                }
246        }
247
248        printf("OK!, Press key to continue.\n");
249
250        c = getchar();
251
252        printf("Frame Buffer Start: 0x%08x, End 0x%08x\n",LCD_BUF_ADD,
253                        LCD_BUF_ADD + LCD_FB_SIZE(lcd_color_depth) + LCD_ROW_SIZE(lcd_color_depth));
254        if (no_wait)
255        {
256                printf("Begin Full Screen Color Test.\n");
257                while(1){
258                        // fill the frame buffer with incrementing color values
259                        for (x = 0; x < 16; x++){
260                                switch (lcd_color_depth){
261                                        case 4:  wr16 = x | x << 4 | x << 8 | x << 12; break;
262                                        case 8:  wr16 = x | x << 8; break;
263                                        default: wr16 = vga_lookup[x]; break;   // 16-bits bypasses the lookup table
264                                }
265                                for (i = 0; i < LCD_FB_SIZE(lcd_color_depth); i += 2){ 
266                                        LCD_BUF(i) = wr16;
267                                }
268                        } // for x
269                } // while
270        } // no_wait
271        else
272        {
273                printf("Begin Full Screen Color Test, Press any key to go to next color, \'x\' to end.\n");
274                while(1){
275                        // fill the frame buffer with incrementing color values
276                        for (x = 0; x < 16; x++){
277                                switch (lcd_color_depth){
278                                        case 4:  wr16 = x | x << 4 | x << 8 | x << 12; break;
279                                        case 8:  wr16 = x | x << 8; break;
280                                        default: wr16 = vga_lookup[x]; break;   // 16-bits bypasses the lookup table
281                                }
282                                for (i = 0; i < LCD_FB_SIZE(lcd_color_depth) + LCD_ROW_SIZE(lcd_color_depth); i += 2){ 
283                                        LCD_BUF(i) = wr16;
284                                }
285                                c = getchar();
286                                if (c == 'x') goto lcd_tst_next;
287                        } // for x
288                } // while
289        } // else no keycheck test
290
291        lcd_tst_next:
292
293        // write a one pixel border around the screen
294        lcd_fg_color = 15;      // VGA Bright White
295        fb_draw_line2(LEFT, TOP, RIGHT, TOP, lcd_fg_color);
296        fb_draw_line2(LEFT, TOP, LEFT, BOTTOM, lcd_fg_color);
297        fb_draw_line2(LEFT, BOTTOM, RIGHT, BOTTOM, lcd_fg_color);       // bottom left to bottom right
298        fb_draw_line2(RIGHT, TOP, RIGHT, BOTTOM, lcd_fg_color); // bottom right to top right
299        // draw an x
300        fb_draw_line2(LEFT, TOP, RIGHT, BOTTOM, lcd_fg_color);
301        fb_draw_line2(LEFT, BOTTOM, RIGHT, TOP, lcd_fg_color);
302        // draw 3 circles at the center of the screen, one inside the other
303        lcd_fg_color = 12;      // VGA Bright Red
304        fb_draw_circle2(CENTER_X, CENTER_Y, 100, lcd_fg_color);
305        lcd_fg_color = 10;      // VGA Bright Green
306        fb_draw_circle2(CENTER_X, CENTER_Y, 66, lcd_fg_color);
307        lcd_fg_color = 9;       // VGA Bright Blue
308        fb_draw_circle2(CENTER_X, CENTER_Y, 33, lcd_fg_color);
309
310        return 0;
311}
312
313// fb_set_pixel sets a pixel to the specified color.
314// This is target specific and is called from the generic
315// fb_draw.c functions
316void fb_set_pixel(ulong X, ulong Y, uchar color)
317{
318        // Make sure the specified pixel is valid.
319#if 0
320        if((X < 0) || (X >= PIXELS_PER_ROW) || (Y < 0) || (Y >= PIXELS_PER_COL))
321        {   
322                printf("fb_set_pixel() bad X (%ld) or Y (%ld)!\n", X, Y);
323                return;
324        }
325#else
326        if (X < 0)
327                X = 0;
328        else {
329                if (X >= PIXELS_PER_ROW)
330                        X = PIXELS_PER_ROW - 1;
331        }
332        if (Y < 0)
333                Y = 0;
334        else {
335                if (Y >= PIXELS_PER_COL)
336                        Y = PIXELS_PER_COL - 1;
337        }
338#endif
339
340        LCD_BUF(LCD_GET_PIXEL_ADD(X, Y)) = vga_lookup[color];
341}
342#endif
Note: See TracBrowser for help on using the repository browser.