6 #define DUMP_REGISTERS 1
7 #define VERSION ((0<<8)|10)
14 #include <api_drv_video.h>
15 #include <lib/keyvalue.h>
16 #include <options.h> // ARM Arch
19 #define ABS(a) ((a)>0?(a):-(a))
23 int Tegra2Vid_Install(char **Arguments);
24 void Tegra2Vid_Uninstall();
27 size_t Tegra2Vid_Read(tVFS_Node *node, off_t off, size_t len, void *buffer);
28 size_t Tegra2Vid_Write(tVFS_Node *node, off_t off, size_t len, const void *buffer);
29 int Tegra2Vid_IOCtl(tVFS_Node *node, int id, void *data);
31 int Tegra2Vid_int_SetMode(int Mode);
34 MODULE_DEFINE(0, VERSION, Tegra2Vid, Tegra2Vid_Install, NULL, NULL);
35 tVFS_NodeType gTegra2Vid_NodeType = {
36 .Read = Tegra2Vid_Read,
37 .Write = Tegra2Vid_Write,
38 .IOCtl = Tegra2Vid_IOCtl
40 tDevFS_Driver gTegra2Vid_DriverStruct = {
42 {.Type = &gTegra2Vid_NodeType}
45 tPAddr gTegra2Vid_PhysBase = TEGRA2VID_BASE;
46 int gbTegra2Vid_IsVersatile = 1;
47 // -- KeyVal parse rules
48 const tKeyVal_ParseRules gTegra2Vid_KeyValueParser = {
51 {"Base", "P", &gTegra2Vid_PhysBase},
56 int giTegra2Vid_CurrentMode = 0;
57 int giTegra2Vid_BufferMode;
58 size_t giTegra2Vid_FramebufferSize;
59 Uint32 *gpTegra2Vid_IOMem;
60 tPAddr gTegra2Vid_FramebufferPhys;
61 void *gpTegra2Vid_Framebuffer;
62 void *gpTegra2Vid_Cursor;
64 tDrvUtil_Video_BufInfo gTegra2Vid_DrvUtil_BufInfo;
65 tVideo_IOCtl_Pos gTegra2Vid_CursorPos;
68 inline void _dumpreg(int i)
70 Log_Debug("Tegra2Vid", "[0x%03x] = 0x%08x (%s)", i, gpTegra2Vid_IOMem[i],
71 (csaTegra2Vid_RegisterNames[i] ? csaTegra2Vid_RegisterNames[i] : "-"));
74 void Tegra2Vid_int_DumpRegisters(void)
76 Log_Debug("Tegra2Vid", "Display CMD Registers");
77 for( int i = 0x000; i <= 0x01A; i ++ ) _dumpreg(i);
78 for( int i = 0x028; i <= 0x043; i ++ ) _dumpreg(i);
79 Log_Debug("Tegra2Vid", "Display COM Registers");
80 for( int i = 0x300; i <= 0x329; i ++ ) _dumpreg(i);
81 Log_Debug("Tegra2Vid", "Display DISP Registers");
82 for( int i = 0x400; i <= 0x446; i ++ ) _dumpreg(i);
83 for( int i = 0x480; i <= 0x484; i ++ ) _dumpreg(i);
84 for( int i = 0x4C0; i <= 0x4C1; i ++ ) _dumpreg(i);
85 Log_Debug("Tegra2Vid", "WINC_A Registers");
86 for( int i = 0x700; i <= 0x714; i ++ ) _dumpreg(i);
87 Log_Debug("Tegra2Vid", "WINBUF_A");
88 for( int i = 0x800; i <= 0x80A; i ++ ) _dumpreg(i);
93 int Tegra2Vid_Install(char **Arguments)
95 // return MODULE_ERR_NOTNEEDED;
96 // KeyVal_Parse(&gTegra2Vid_KeyValueParser, Arguments);
98 gpTegra2Vid_IOMem = (void*)MM_MapHWPages(gTegra2Vid_PhysBase, 256/4);
101 // Tegra2Vid_int_DumpRegisters();
107 int w = 1680, h = 1050;
108 gpTegra2Vid_IOMem[DC_DISP_DISP_ACTIVE_0] = (h << 16) | w;
109 gpTegra2Vid_IOMem[DC_WIN_A_SIZE_0] = (h << 16) | w;
110 gpTegra2Vid_IOMem[DC_WIN_A_PRESCALED_SIZE_0] = (h << 16) | w;
115 giTegra2Vid_FramebufferSize =
116 (gpTegra2Vid_IOMem[DC_WIN_A_SIZE_0]&0xFFFF)
117 *(gpTegra2Vid_IOMem[DC_WIN_A_SIZE_0]>>16)*4;
119 Log_Debug("Tegra2Vid", "giTegra2Vid_FramebufferSize = 0x%x", giTegra2Vid_FramebufferSize);
120 gpTegra2Vid_Framebuffer = (void*)MM_MapHWPages(
121 gpTegra2Vid_IOMem[DC_WINBUF_A_START_ADDR_0],
122 (giTegra2Vid_FramebufferSize+PAGE_SIZE-1)/PAGE_SIZE
124 Log_Debug("Tegra2Vid", "gpTegra2Vid_Framebuffer = %p", gpTegra2Vid_Framebuffer);
125 memset(gpTegra2Vid_Framebuffer, 0xFF, giTegra2Vid_FramebufferSize);
129 gpTegra2Vid_IOMem[DC_WIN_A_WIN_OPTIONS_0] = (1 << 30);
130 gpTegra2Vid_IOMem[DC_WIN_A_COLOR_DEPTH_0] = 12; // Could be 13 (BGR/RGB)
131 gpTegra2Vid_IOMem[DC_WIN_A_PRESCALED_SIZE_0] = gpTegra2Vid_IOMem[DC_WIN_A_SIZE_0];
132 gpTegra2Vid_IOMem[DC_WIN_A_LINE_STRIDE_0] =
133 gTegra2Vid_DrvUtil_BufInfo.Pitch =
135 gTegra2Vid_DrvUtil_BufInfo.Depth = 32;
136 gTegra2Vid_DrvUtil_BufInfo.Width = 1680;
137 gTegra2Vid_DrvUtil_BufInfo.Height = 1050;
138 gpTegra2Vid_IOMem[DC_CMD_STATE_CONTROL_0] = WIN_A_ACT_REQ;
140 gpTegra2Vid_IOMem[DC_WIN_A_COLOR_DEPTH_0] = 13; // Could be 13 (BGR/RGB)
141 gpTegra2Vid_IOMem[DC_WIN_A_LINE_STRIDE_0] =
142 gTegra2Vid_DrvUtil_BufInfo.Pitch = 1024*4;
143 gTegra2Vid_DrvUtil_BufInfo.Depth = 32;
144 gTegra2Vid_DrvUtil_BufInfo.Width = 1024;
145 gTegra2Vid_DrvUtil_BufInfo.Height = 768;
146 gTegra2Vid_DrvUtil_BufInfo.Framebuffer = gpTegra2Vid_Framebuffer;
147 gpTegra2Vid_IOMem[DC_CMD_STATE_CONTROL_0] = WIN_A_ACT_REQ;
150 gpTegra2Vid_Cursor = (void*)MM_AllocDMA(1, 26, NULL);
151 Log_Debug("Tegra2Vid", "gpTegra2Vid_Cursor = %p", gpTegra2Vid_Cursor);
153 Tegra2Vid_int_SetMode(0);
155 DevFS_AddDevice( &gTegra2Vid_DriverStruct );
161 * \brief Clean up resources for driver unloading
163 void Tegra2Vid_Uninstall()
168 * \brief Read from the framebuffer
170 size_t Tegra2Vid_Read(tVFS_Node *node, off_t off, size_t len, void *buffer)
176 * \brief Write to the framebuffer
178 size_t Tegra2Vid_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer)
180 gTegra2Vid_DrvUtil_BufInfo.BufferFormat = giTegra2Vid_BufferMode;
181 return DrvUtil_Video_WriteLFB(&gTegra2Vid_DrvUtil_BufInfo, Offset, Length, Buffer);
184 const char *csaTegra2Vid_IOCtls[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL};
187 * \brief Handle messages to the device
189 int Tegra2Vid_IOCtl(tVFS_Node *Node, int ID, void *Data)
192 ENTER("pNode iID pData", Node, ID, Data);
196 BASE_IOCTLS(DRV_TYPE_VIDEO, "PL110", VERSION, csaTegra2Vid_IOCtls);
198 case VIDEO_IOCTL_SETBUFFORMAT:
199 DrvUtil_Video_RemoveCursor( &gTegra2Vid_DrvUtil_BufInfo );
200 ret = giTegra2Vid_BufferMode;
201 if(Data) giTegra2Vid_BufferMode = *(int*)Data;
202 if(gTegra2Vid_DrvUtil_BufInfo.BufferFormat == VIDEO_BUFFMT_TEXT)
203 DrvUtil_Video_SetCursor( &gTegra2Vid_DrvUtil_BufInfo, &gDrvUtil_TextModeCursor );
206 case VIDEO_IOCTL_GETSETMODE:
211 if( !CheckMem(Data, sizeof(int)) )
214 newMode = *(int*)Data;
216 if(newMode < 0 || newMode >= ciTegra2Vid_ModeCount)
219 if(newMode != giTegra2Vid_CurrentMode)
221 giTegra2Vid_CurrentMode = newMode;
222 Tegra2Vid_int_SetMode( newMode );
225 ret = giTegra2Vid_CurrentMode;
228 case VIDEO_IOCTL_FINDMODE:
230 tVideo_IOCtl_Mode *mode = Data;
231 int closest=0, closestArea, reqArea = 0;
232 if(!Data || !CheckMem(Data, sizeof(tVideo_IOCtl_Mode)))
234 if( mode->bpp != 32 )
236 if( mode->flags != 0 )
240 mode->id = 1; mode->width = 1680; mode->height = 1050;
241 mode->id = 0; mode->width = 1024; mode->height = 768;
244 for( int i = 0x800; i <= 0x80A; i ++ ) _dumpreg(i);
249 for( int i = 0; i < ciTegra2Vid_ModeCount; i ++ )
252 if(mode->width == caTegra2Vid_Modes[i].W
253 && mode->height == caTegra2Vid_Modes[i].H) {
259 area = caTegra2Vid_Modes[i].W * caTegra2Vid_Modes[i].H;
261 reqArea = mode->width * mode->height;
265 else if( ABS(area - reqArea) < ABS(closestArea - reqArea) ) {
276 mode->width = caTegra2Vid_Modes[mode->id].W;
277 mode->height = caTegra2Vid_Modes[mode->id].H;
281 case VIDEO_IOCTL_MODEINFO:
283 tVideo_IOCtl_Mode *mode = Data;
284 if(!Data || !CheckMem(Data, sizeof(tVideo_IOCtl_Mode)))
286 if(mode->id < 0 || mode->id >= ciTegra2Vid_ModeCount)
292 mode->width = caTegra2Vid_Modes[mode->id].W;
293 mode->height = caTegra2Vid_Modes[mode->id].H;
299 case VIDEO_IOCTL_SETCURSOR:
300 if( !Data || !CheckMem(Data, sizeof(tVideo_IOCtl_Pos)) )
303 DrvUtil_Video_RemoveCursor( &gTegra2Vid_DrvUtil_BufInfo );
305 gTegra2Vid_CursorPos = *(tVideo_IOCtl_Pos*)Data;
306 // TODO: Set DC_DISP_CURSOR_POSITION_0
307 // TODO: Set DC_DISP_CURSOR_FOREGROUND_0 etc from image?
308 if(gTegra2Vid_DrvUtil_BufInfo.BufferFormat == VIDEO_BUFFMT_TEXT)
309 DrvUtil_Video_DrawCursor(
310 &gTegra2Vid_DrvUtil_BufInfo,
311 gTegra2Vid_CursorPos.x*giVT_CharWidth,
312 gTegra2Vid_CursorPos.y*giVT_CharHeight
315 DrvUtil_Video_DrawCursor(
316 &gTegra2Vid_DrvUtil_BufInfo,
317 gTegra2Vid_CursorPos.x,
318 gTegra2Vid_CursorPos.y
335 int Tegra2Vid_int_SetMode(int Mode)
337 const struct sTegra2_Disp_Mode *mode = &caTegra2Vid_Modes[Mode];
338 int w = mode->W, h = mode->H; // Horizontal/Vertical Active
339 gpTegra2Vid_IOMem[DC_DISP_REF_TO_SYNC_0] = (1 << 16) | 11; // TODO: <--
340 gpTegra2Vid_IOMem[DC_DISP_SYNC_WIDTH_0] = (mode->HS << 16) | mode->HS;
341 gpTegra2Vid_IOMem[DC_DISP_BACK_PORCH_0] = (mode->VBP << 16) | mode->HBP;
342 gpTegra2Vid_IOMem[DC_DISP_DISP_ACTIVE_0] = (mode->H << 16) | mode->W;
343 gpTegra2Vid_IOMem[DC_DISP_FRONT_PORCH_0] = (mode->VFP << 16) | mode->HFP;
345 gpTegra2Vid_IOMem[DC_DISP_DISP_COLOR_CONTROL_0] = 0x8; // BASE888 - TODO: useful?
346 gpTegra2Vid_IOMem[DC_WIN_A_POSITION_0] = 0;
347 gpTegra2Vid_IOMem[DC_WIN_A_SIZE_0] = (h << 16) | w;
348 gpTegra2Vid_IOMem[DC_WIN_A_COLOR_DEPTH_0] = 12; // Could be 13 (BGR/RGB)
349 gpTegra2Vid_IOMem[DC_WIN_A_PRESCALED_SIZE_0] = (h << 16) | w;
350 gpTegra2Vid_IOMem[DC_WIN_A_LINE_STRIDE_0] = w * 4;
351 gpTegra2Vid_IOMem[DC_WIN_A_DV_CONTROL_0] = 0;
353 gpTegra2Vid_IOMem[DC_DISP_BORDER_COLOR_0] = 0x70F010;
355 Log_Debug("Tegra2Vid", "Mode %i (%ix%i) selected", Mode, w, h);
357 if( !gpTegra2Vid_Framebuffer || w*h*4 != giTegra2Vid_FramebufferSize )
359 if( gpTegra2Vid_Framebuffer )
361 // TODO: Free framebuffer for reallocation
364 giTegra2Vid_FramebufferSize = w*h*4;
367 gpTegra2Vid_Framebuffer = (void*)MM_AllocDMA(
368 (giTegra2Vid_FramebufferSize + PAGE_SIZE-1) / PAGE_SIZE,
370 &gTegra2Vid_FramebufferPhys
372 if( !gpTegra2Vid_Framebuffer ) {
373 Log_Error("Tegra2Vid", "Can't allocate pages for 0x%x byte framebuffer",
374 giTegra2Vid_FramebufferSize);
377 Log_Debug("Tegra2Vid", "0x%x byte framebuffer at %p (%P phys)",
378 giTegra2Vid_FramebufferSize,
379 gpTegra2Vid_Framebuffer,
380 gTegra2Vid_FramebufferPhys
384 gpTegra2Vid_IOMem[DC_WINBUF_A_START_ADDR_0] = gTegra2Vid_FramebufferPhys;
385 gpTegra2Vid_IOMem[DC_WINBUF_A_ADDR_V_OFFSET_0] = 0; // Y offset
386 gpTegra2Vid_IOMem[DC_WINBUF_A_ADDR_H_OFFSET_0] = 0; // X offset
389 gpTegra2Vid_IOMem[DC_CMD_STATE_CONTROL_0] = WIN_A_ACT_REQ;
390 gpTegra2Vid_IOMem[DC_CMD_STATE_CONTROL_0] = GEN_ACT_REQ;
393 for( int i = 0x800; i <= 0x80A; i ++ ) _dumpreg(i);