2 * ti omap35 display subsystem (dss)
4 * can handle 2ⁿ bits per pixel for 0 < n ≤ 4, and 12 and 24 bits.
5 * can handle 1024×768 at 60 Hz with pixel clock of 63.5 MHz
6 * 1280×800 at 59.91 Hz with pixel clock of 71 MHz
7 * 1400×1050 lcd at 50 MHz with pixel clock of 75 MHz
8 * has 256 24-bit entries in RGB palette
11 #include "../port/lib.h"
17 #include "../port/error.h"
27 Tabstop = 4, /* should be 8 */
28 Scroll = 8, /* lines to scroll at one time */
30 * screen settings for Wid and Ht, should a bit more dynamic?
31 * http://www.epanorama.net/faq/vga2rgb/calc.html
32 * used to calculate settings.
35 // Hbp = (248-1) << 20,
51 EnableWakeup = 1 << 2,
73 // Lcden = 1 << 0, /* unused */
76 typedef struct Dispcregs Dispc;
77 typedef struct Dssregs Dss;
78 typedef struct Ioregs Ioregs;
80 struct Ioregs { /* common registers, 68 (0x44) bytes */
82 uchar _pad0[0x10-0x4];
98 struct Dssregs { /* display subsys at 0x48050000 */
102 uchar _pad3[0x5c-0x4c];
106 struct Dispcregs { /* display ctlr at 0x48050400 */
110 ulong defaultcolor[2];
122 ulong base[2]; /* should allocate both to avoid dithering */
132 ulong palette; /* gfx_table_ba */
133 uchar _pad5[0x5d4 - 0x4bc];
136 uchar _pad5[0x620 - 0x5e0];
145 Settings settings[] = {
146 [Res800x600] { 800, 600, 60, RGB16, 40000, 88, 40, 128, 23, 1, 5, },
147 [Res1024x768] { 1024, 768, 60, RGB16, 65000, 160, 24, 136, 29, 3, 7, },
148 [Res1280x1024] { 1280, 1024, 60, RGB16, 108000, 248, 48, 112, 38, 1, 4, },
149 [Res1400x1050] { 1400, 1050, 50, RGB16, 108000, 248, 48, 112, 38, 1, 4, }, // TODO
154 static Memdata xgdata;
156 static Memimage xgscreen =
158 { 0, 0, Wid, Ht }, /* r */
159 { 0, 0, Wid, Ht }, /* clipr */
166 Wid*(Depth/BI2BY)/BY2WD, /* width in words of a single scan line */
171 static Memimage *conscol;
172 static Memimage *back;
174 static Memsubfont *memdefont;
176 static Lock screenlock;
180 static int landscape = 0; /* screen orientation, default is 0: portrait */
181 static ushort *vscreen; /* virtual screen */
182 static Rectangle window;
184 static Dispc *dispc = (Dispc *)PHYSDISPC;
185 static Dss *dss = (Dss *)PHYSDSS;
187 static void omapscreenputs(char *s, int n);
188 static ulong rep(ulong, int);
189 static void screenputc(char *buf);
190 static void screenwin(void);
195 int swvisible; /* is the cursor visible? */
196 int swenabled; /* is the cursor supposed to be on the screen? */
197 Memimage* swback; /* screen under cursor */
198 Memimage* swimg; /* cursor image */
199 Memimage* swmask; /* cursor mask */
204 Rectangle swrect; /* screen rectangle in swback */
205 Point swpt; /* desired cursor location */
206 Point swvispt; /* actual cursor location */
207 int swvers; /* incremented each time cursor image changes */
208 int swvisvers; /* the version on the screen */
213 dispc->ctrl &= ~1; /* disable the lcd */
216 dispc->irqstat1 |= 1; /* set framedone */
219 /* the lcd never comes ready, so don't bother with this */
221 /* spin until the frame is complete, but not forever */
222 for(cnt = 50; !(dispc->irqstat1 & 1) && cnt-- > 0; )
225 delay(20); /* worst case for 1 frame, 50Hz */
231 /* should reset the dss system */
236 /* see spruf98i §15.6.7.4.2 */
242 sp = oscreen.settings;
243 dss->ctrl &= 0x78; /* choose dss clock */
244 dispc->sysconf = Midlemode | Sidlemode | EnableWakeup | Autoidle;
245 dispc->config = Loadmode;
249 dispc->defaultcolor[0] = 0; /* set background color to black? */
250 dispc->defaultcolor[1] = 0;
251 dispc->transcolor[0] = 0; /* set transparency to full */
252 dispc->transcolor[1] = 0;
254 dispc->timing_h = (sp->hbp-1) << 20 | (sp->hfp-1) << 8 |
256 dispc->timing_v = sp->vbp << 20 | sp->vfp << 8 |
259 dispc->pol_req = Ipc | Ihs | Ivs | Acb;
260 dispc->divisor = 1 << 16 | ((432000+sp->pixelclock-1)/sp->pixelclock);
262 dispc->lcdsize = (sp->ht - 1) << 16 | (sp->wid - 1);
265 dispc->base[0] = PADDR(framebuf->pixel);
266 dispc->base[1] = PADDR(framebuf->pixel);
268 dispc->pos = 0; /* place screen in the left corner */
269 /* use the whole screen */
270 dispc->size = (sp->ht - 1) << 16 | (sp->wid - 1);
272 /* what mode does plan 9 use for fb? */
273 dispc->attrib = Burstsize | Format | Gfxenable;
275 dispc->preload = Tft;
276 dispc->fifosize = Fifosize;
277 /* 1008 is max for our Burstsize */
278 dispc->fifothr = (Fifosize - 1) << 16 | (1008 - 1);
280 /* 1 byte is one pixel (not true, we use 2 bytes per pixel) */
283 dispc->winskip = 0; /* don't skip anything */
286 // dispc->palette = PADDR(framebuf->palette);
292 dispc->ctrl = Gpout1 | Gpout0 | Tftdata | Digital | Lcd | Stntft |
316 /* Paint the image data with blue pixels */
322 for (i = nelem(framebuf->pixel) - 1; i >= 0; i--)
323 framebuf->pixel[i] = 0x1f; /* blue */
324 // memset(framebuf->pixel, ~0, sizeof framebuf->pixel); /* white */
330 blankscreen(on == 0);
339 swcursordraw(mousexy());
354 /* called from devmouse */
356 setcursor(Cursor* curs)
358 oscreen.Cursor = *curs;
362 /* called from main and possibly later from devdss to change resolution */
366 static int first = 1;
369 iprint("screeninit...");
370 oscreen.settings = &settings[Res1280x1024];
375 /* mode is 16*32 = 512 */
376 framebuf = xspanalloc(sizeof *framebuf, 16*32, 0);
383 memdefont = getmemdefont();
388 xgdata.bdata = (uchar *)framebuf->pixel;
391 gscreen->r = Rect(0, 0, Wid, Ht);
392 gscreen->clipr = gscreen->r;
393 /* width, in words, of a single scan line */
394 gscreen->width = Wid * (Depth / BI2BY) / BY2WD;
395 flushmemscreen(gscreen->r);
398 iprint("on: blue for 3 seconds...");
402 screenwin(); /* draw border & top orange bar */
403 screenputs = omapscreenputs;
404 iprint("screen: frame buffer at %#p for %dx%d\n",
405 framebuf, oscreen.settings->wid, oscreen.settings->ht);
408 swcursorinit(); /* needs gscreen set */
415 /* flushmemscreen should change buffer? */
417 flushmemscreen(Rectangle r)
429 if (rectclip(&r, gscreen->r) == 0)
431 start = (ulong)&framebuf->pixel[r.min.y*Wid + r.min.x];
432 end = (ulong)&framebuf->pixel[(r.max.y - 1)*Wid + r.max.x -1];
433 cachedwbse((ulong *)start, end - start);
437 * export screen to devdraw
440 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
447 *chan = gscreen->chan;
448 *width = gscreen->width;
449 *softscreen = (landscape == 0);
451 gscreen->data->ref++;
452 return gscreen->data;
456 getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
462 setcolor(ulong p, ulong r, ulong g, ulong b)
469 blankscreen(int blank)
480 omapscreenputs(char *s, int n)
487 /* don't deadlock trying to print in interrupt */
488 if (!canlock(&screenlock))
489 return; /* discard s */
494 i = chartorune(&r, s);
517 memsetchan(gscreen, RGB16);
522 orange = allocmemimage(Rect(0, 0, 1, 1), RGB16);
523 orange->flags |= Frepl;
524 orange->clipr = gscreen->r;
525 orange->data->bdata[0] = 0x40; /* magic: colour? */
526 orange->data->bdata[1] = 0xfd; /* magic: colour? */
528 w = memdefont->info[' '].width;
529 h = memdefont->height;
531 r = insetrect(gscreen->r, 4);
533 memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP, S);
534 window = insetrect(r, 4);
535 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
537 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
538 window.max.x, window.min.y + h + 5 + 6), orange, ZP, nil, ZP, S);
539 freememimage(orange);
540 window = insetrect(window, 5);
542 greet = " Plan 9 Console ";
543 p = addpt(window.min, Pt(10, 0));
544 q = memsubfontwidth(memdefont, greet);
545 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
547 window.min.y += h + 6;
549 window.max.y = window.min.y + ((window.max.y - window.min.y) / h) * h;
559 /* move window contents up Scroll text lines */
561 r = Rpt(window.min, Pt(window.max.x, window.max.y - o));
562 p = Pt(window.min.x, window.min.y + o);
563 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
566 /* clear the bottom Scroll text lines */
567 r = Rpt(Pt(window.min.x, window.max.y - o), window.max);
568 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
575 screenputc(char *buf)
582 static int xbuf[256];
584 if (xp < xbuf || xp >= &xbuf[nelem(xbuf)])
589 if (curpos.y + h >= window.max.y)
596 curpos.x = window.min.x;
599 p = memsubfontwidth(memdefont, " ");
601 if (curpos.x >= window.max.x - Tabstop * w)
604 pos = (curpos.x - window.min.x) / w;
605 pos = Tabstop - pos % Tabstop;
607 r = Rect(curpos.x, curpos.y, curpos.x + pos * w, curpos.y + h);
608 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
616 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
617 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
624 p = memsubfontwidth(memdefont, buf);
627 if (curpos.x >= window.max.x - w)
631 r = Rect(curpos.x, curpos.y, curpos.x + w, curpos.y + h);
632 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
633 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);