video.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. video.c
  5. Abstract:
  6. This module implements support for the Texas Instruments OMAP4
  7. DSS/DISPC display controller.
  8. Author:
  9. Evan Green 25-Mar-2014
  10. Environment:
  11. Firmware
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <uefifw.h>
  17. #include <minoca/uefi/protocol/graphout.h>
  18. #include "pandafw.h"
  19. //
  20. // --------------------------------------------------------------------- Macros
  21. //
  22. //
  23. // These macros read from and write to a display controller register.
  24. //
  25. #define READ_DISPLAY_REGISTER(_Register) \
  26. *(volatile UINT32 *)((UINT8 *)EfiOmap4DispcAddress + (_Register))
  27. #define WRITE_DISPLAY_REGISTER(_Register, _Value) \
  28. *((volatile UINT32 *)((UINT8 *)EfiOmap4DispcAddress + (_Register))) = \
  29. (_Value)
  30. //
  31. // These macros read from and write to the display subsystem.
  32. //
  33. #define READ_DISPLAY_SUBSYSTEM_REGISTER(_Register) \
  34. *(volatile UINT32 *)((UINT8 *)EfiOmap4DssAddress + (_Register))
  35. #define WRITE_DISPLAY_SUBSYSTEM_REGISTER(_Register, _Value) \
  36. *((volatile UINT32 *)((UINT8 *)EfiOmap4DssAddress + (_Register))) = (_Value)
  37. //
  38. // These macros read from and write to the DSS PRM (Power and Reset Manager).
  39. //
  40. #define READ_DSS_PRM_REGISTER(_Register) \
  41. *(volatile UINT32 *)((UINT8 *)EfiOmap4DssPrmAddress + (_Register))
  42. #define WRITE_DSS_PRM_REGISTER(_Register, _Value) \
  43. *((volatile UINT32 *)((UINT8 *)EfiOmap4DssPrmAddress + (_Register))) = \
  44. (_Value)
  45. //
  46. // These macros read from and write to the DSS CM (Clock Manager).
  47. //
  48. #define READ_DSS_CM_REGISTER(_Register) \
  49. *(volatile UINT32 *)((UINT8 *)EfiOmap4DssCm2Address + (_Register))
  50. #define WRITE_DSS_CM_REGISTER(_Register, _Value) \
  51. *((volatile UINT32 *)((UINT8 *)EfiOmap4DssCm2Address + (_Register))) = \
  52. (_Value)
  53. //
  54. // ---------------------------------------------------------------- Definitions
  55. //
  56. #define EFI_OMAP4_VIDEO_DEVICE_GUID \
  57. { \
  58. 0x19EEE1EB, 0x8F2A, 0x4DFA, \
  59. {0xB0, 0xF9, 0xB1, 0x0B, 0xD5, 0xB8, 0x71, 0x04} \
  60. }
  61. #define EFI_OMAP4_VIDEO_DEVICE_MAGIC 0x6469564F // 'diVO'
  62. //
  63. // Define the default mode to initialize in.
  64. //
  65. #define EFI_OMAP4_VIDEO_DEFAULT_MODE 1
  66. #define EFI_OMAP4_VIDEO_MODE_COUNT \
  67. (sizeof(EfiOmap4VideoModes) / sizeof(EfiOmap4VideoModes[0]))
  68. //
  69. // Define the size of the frame buffer to allocate, which should be large
  70. // enough to support the largest resolution.
  71. //
  72. #define EFI_OMAP4_FRAME_BUFFER_SIZE (1024 * 768 * sizeof(UINT32))
  73. //
  74. // Define the default physical address of the DISPC module on OMAP4 chips.
  75. //
  76. #define OMAP4_DISPC_BASE 0x58001000
  77. //
  78. // Define the default physical address of the DSS module on OMAP4 chips.
  79. //
  80. #define OMAP4_DSS_BASE 0x48040000
  81. //
  82. // Define the default physical address of the DSS Power and Reset Manager (PRM).
  83. //
  84. #define OMAP4_DSS_PRM_BASE 0x4A307100
  85. //
  86. // Define the default physical address of the DSS Clock Manager (CM).
  87. //
  88. #define OMAP4_DSS_CM2_BASE 0x4A009100
  89. //
  90. // Define the timing parameters to use.
  91. //
  92. #define OMAP4_DISPLAY_SUBSYSTEM_DIVISOR 1
  93. #define OMAP4_HORIZONTAL_BACK_PORCH 47
  94. #define OMAP4_HORIZONTAL_FRONT_PORCH 15
  95. #define OMAP4_VERTICAL_BACK_PORCH 32
  96. #define OMAP4_VERTICAL_FRONT_PORCH 9
  97. #define OMAP4_HORIZONTAL_SYNC_PULSE_WIDTH 95
  98. #define OMAP4_VERTICAL_SYNC_PULSE_WIDTH 2
  99. #define OMAP4_DISPLAY_SUBSYSTEM_DIVISOR 1
  100. //
  101. // Define the number of 128-bit words to pre-load into the video DMA pipeline.
  102. //
  103. #define OMAP4_VIDEO_PRELOAD_VALUE 0x100
  104. //
  105. // Define DMA buffer attributes.
  106. //
  107. #define OMAP_VIDEO_BUFFER_LOW_THRESHOLD 0x00C0
  108. #define OMAP_VIDEO_BUFFER_HIGH_THRESHOLD 0x00FC
  109. #define OMAP_VIDEO_BUFFER_SIZE 0x00000400
  110. //
  111. // Define register bit definitions for the DSS control register.
  112. //
  113. //
  114. // Set this bit to select the HDMI encoder.
  115. //
  116. #define OMAP_DSS_CONTROL_SELECT_HDMI (1 << 15)
  117. //
  118. // Define register bit definitions for the system configuration register.
  119. //
  120. //
  121. // Set this bit to allow auto idling.
  122. //
  123. #define OMAP_VIDEO_SYSTEM_CONFIGURATION_AUTO_IDLE (1 << 0)
  124. //
  125. // Set this bit to enable the wakeup feature.
  126. //
  127. #define OMAP_VIDEO_SYSTEM_CONFIGURATION_ENABLE_WAKEUP (1 << 2)
  128. //
  129. // Set this bit to tell the controller to never idle out.
  130. //
  131. #define OMAP_VIDEO_SYSTEM_CONFIGURATION_NO_IDLE (1 << 3)
  132. //
  133. // Set these bits to enable smart idle.
  134. //
  135. #define OMAP_VIDEO_SYSTEM_CONFIGURATION_SMART_IDLE (2 << 3)
  136. //
  137. // Set this bit to tell the controller never to assert standby.
  138. //
  139. #define OMAP_VIDEO_SYSTEM_CONIGURATION_NO_STANDBY (1 << 12)
  140. //
  141. // Set this bit to enable smart standby.
  142. //
  143. #define OMAP_VIDEO_SYSTEM_CONFIGURATION_SMART_STANDBY (2 << 12)
  144. //
  145. // Define register bit definitions for the attributes register.
  146. //
  147. //
  148. // Set this bit to enable the given video pipeline.
  149. //
  150. #define OMAP_VIDEO_ATTRIBUTES_ENABLED (1 << 0)
  151. //
  152. // This format sets the frame buffer to be in ARGB32-8888 mode.
  153. //
  154. #define OMAP_VIDEO_ATTRIBUTES_FORMAT_ARGB32_8888 (0xC << 1)
  155. //
  156. // This format sets the frame buffer to be in xRGB24-8888 mode
  157. // (32-bit container).
  158. //
  159. #define OMAP_VIDEO_ATTRIBUTES_FORMAT_XRGB24_8888 (0x8 << 1)
  160. //
  161. // Set this bit to enable a DMA burst size of 8x128 bits.
  162. //
  163. #define OMAP_VIDEO_ATTRIBUTES_BURST_8X128_BITS (0x2 << 6)
  164. //
  165. // Set this bit to make this video pipeline high priority in the DMA arbiter.
  166. //
  167. #define OMAP_VIDEO_ATTRIBUTES_ARBITRATION (1 << 14)
  168. //
  169. // Set this bit to select the TV out over the LCD0, LCD1, or WB pipelines.
  170. //
  171. #define OMAP_VIDEO_ATTRIBUTES_TV_OUTPUT (1 << 16)
  172. //
  173. // Set this bit to cause the video pipeline to fetch from teh DMA buffer.
  174. //
  175. #define OMAP_VIDEO_ATTRIBUTES_SELF_REFRESH (1 << 24)
  176. //
  177. // Set this bit to send the output to the secondary LCD.
  178. //
  179. #define OMAP_VIDEO_ATTRIBUTES_LCD2_OUTPUT (1 << 30)
  180. //
  181. // Define register bit definitions for the picture size register.
  182. //
  183. //
  184. // Define the shift amounts for picture size fields.
  185. //
  186. #define OMAP_VIDEO_PICTURE_SIZE_X_SHIFT 0
  187. #define OMAP_VIDEO_PICTURE_SIZE_Y_SHIFT 16
  188. //
  189. // Define register bit definitions for the size register.
  190. //
  191. //
  192. // Define the shift amounts for the size fields.
  193. //
  194. #define OMAP_VIDEO_SIZE_X_SHIFT 0
  195. #define OMAP_VIDEO_SIZE_Y_SHIFT 16
  196. //
  197. // Define register bit definitions for the TV size register.
  198. //
  199. //
  200. // Define the shift amounts for the size fields.
  201. //
  202. #define OMAP_VIDEO_TV_SIZE_X_SHIFT 0
  203. #define OMAP_VIDEO_TV_SIZE_Y_SHIFT 16
  204. //
  205. // Define register bit definitions for the LCD size registers.
  206. //
  207. //
  208. // Define the shift amounts for the size fields.
  209. //
  210. #define OMAP_VIDEO_LCD_SIZE_X_SHIFT 0
  211. #define OMAP_VIDEO_LCD_SIZE_Y_SHIFT 16
  212. //
  213. // Define the buffer threshold register.
  214. //
  215. #define OMAP_VIDEO_BUFFER_THRESHOLD_HIGH_SHIFT 16
  216. //
  217. // Define register bit definitions for the control 1 register.
  218. //
  219. //
  220. // Set this bit to enable TV output.
  221. //
  222. #define OMAP_VIDEO_CONTROL1_TV_ENABLED (1 << 1)
  223. //
  224. // Set this bit for Active matrix (TFT) displays.
  225. //
  226. #define OMAP_VIDEO_CONTROL1_ACTIVE_TFT (1 << 3)
  227. //
  228. // Set this bit to snap all configured shadow registers into service at the
  229. // next VSYNC.
  230. //
  231. #define OMAP_VIDEO_CONTROL1_GO_TV (1 << 6)
  232. //
  233. // Set this bit to set the first GPIO line to high.
  234. //
  235. #define OMAP_VIDEO_CONTROL1_GPIO0_SET (1 << 15)
  236. //
  237. // Set this bit to set the second GPIO line to high.
  238. //
  239. #define OMAP_VIDEO_CONTROL1_GPIO1_SET (1 << 16)
  240. //
  241. // Define register bit definitions for the configuration 1 register.
  242. //
  243. #define OMAP_VIDEO_CONFIGURATION1_LOAD_ONLY_FRAME_DATA (2 << 1)
  244. //
  245. // Define register bit definitions for the control 2 register.
  246. //
  247. //
  248. // Set this bit to enable LCD2.
  249. //
  250. #define OMAP_VIDEO_CONTROL2_LCD2_ENABLED (1 << 0)
  251. //
  252. // Set this bit for Active matrix (TFT) displays.
  253. //
  254. #define OMAP_VIDEO_CONTROL2_ACTIVE_TFT (1 << 3)
  255. //
  256. // Set this bit to pull the configured pipeline values into service.
  257. //
  258. #define OMAP_VIDEO_CONTROL2_GO_LCD2 (1 << 5)
  259. //
  260. // Set these bits to output 24-bits of data aligned on the LSB of the pixel
  261. // data interface.
  262. //
  263. #define OMAP_VIDEO_CONTROL2_24_BIT_TFT_DATA (3 << 8)
  264. //
  265. // Define the register definitions for the horizontal timing registers.
  266. //
  267. //
  268. // Define the shifts for the horizontal back porch and horizontal front porch.
  269. //
  270. #define OMAP_VIDEO_TIMING_HORIZONTAL_BACK_PORCH_SHIFT 20
  271. #define OMAP_VIDEO_TIMING_HORIZONTAL_FRONT_PORCH_SHIFT 8
  272. //
  273. // Define the register definitions for the vertical timing registers.
  274. //
  275. //
  276. // Define the shifts for the vertical back porch, and veritical front porch.
  277. //
  278. #define OMAP_VIDEO_TIMING_VERTICAL_BACK_PORCH_SHIFT 20
  279. #define OMAP_VIDEO_TIMING_VERTICAL_FRONT_PORCH_SHIFT 8
  280. //
  281. // Define the register definitions for the divisor registers.
  282. //
  283. //
  284. // Define the shifts for the display subsystem divisor.
  285. //
  286. #define OMAP_VIDEO_DIVISOR_DISPLAY_SUBSYSTEM_DIVISOR_SHIFT 16
  287. //
  288. // Define register definitions for the DSS PRM Power state control register.
  289. //
  290. //
  291. // Set these bits to enable power to the DSS subsystem.
  292. //
  293. #define OMAP_DSS_PRM_POWER_CONTROL_POWER_ON (0x3 << 0)
  294. //
  295. // Define register definitions for the DSS CM Clock state control register.
  296. //
  297. //
  298. // Set this bit to force a software wakeup of the DSS clock domain.
  299. //
  300. #define OMAP_DSS_CM_CLOCK_STATE_CONTROL_SOFTWARE_WAKEUP (0x2 << 0)
  301. //
  302. // Define register definitions for the DSS CM Clock control register.
  303. //
  304. //
  305. // These bits define the idle state mask.
  306. //
  307. #define OMAP_DSS_CM_CLOCK_CONTROL_IDLE_STATE_MASK (0x3 << 16)
  308. //
  309. // This bit is set if the module is in standby.
  310. //
  311. #define OMAP_DSS_CM_CLOCK_CONTROL_STANDBY (1 << 18)
  312. //
  313. // Set these bits to enable various optional clocks.
  314. //
  315. #define OMAP_DSS_CM_CLOCK_CONTROL_TV_CLOCK_ENABLED (1 << 11)
  316. #define OMAP_DSS_CM_CLOCK_CONTROL_SYSTEM_CLOCK_ENABLED (1 << 10)
  317. #define OMAP_DSS_CM_CLOCK_CONTROL_48MHZ_CLOCK_ENABLED (1 << 9)
  318. #define OMAP_DSS_CM_CLOCK_CONTROL_DSS_CLOCK_ENABLED (1 << 8)
  319. //
  320. // Set this bit to explicitly enable the functional clock.
  321. //
  322. #define OMAP_DSS_CM_CLOCK_CONTROL_ENABLE (0x2 << 0)
  323. //
  324. // ------------------------------------------------------ Data Type Definitions
  325. //
  326. //
  327. // Define register offsets in the DISPC Display controller. All offsets are in
  328. // bytes.
  329. //
  330. typedef enum _OMAP_DISPLAY_CONTROLLER_REGISTER {
  331. OmapDisplaySystemConfiguration = 0x010, // DISPC_SYSCONFIG
  332. OmapDisplayInterruptStatus = 0x018, // DISPC_IRQSTATUS
  333. OmapDisplayControl1 = 0x040, // DISPC_CONTROL1
  334. OmapDisplayConfiguration1 = 0x044, // DISPC_CONFIG1
  335. OmapDisplayDefaultColor0 = 0x04C, // DISPC_DEFAULT_COLOR0
  336. OmapDisplayDefaultColor1 = 0x050, // DISPC_DEFAULT_COLOR1
  337. OmapDisplayDivisor1 = 0x070, // DISPC_DIVISOR1
  338. OmapDisplayGlobalAlpha = 0x074, // DISPC_GLOBAL_ALPHA
  339. OmapDisplayTvSize = 0x078, // DISPC_SIZE_TV
  340. OmapDisplayGraphicsFrameBufferAddress0 = 0x080, // DISPC_GFX_BA_0
  341. OmapDisplayGraphicsFrameBufferAddress1 = 0x084, // DISPC_GFX_BA_1
  342. OmapDisplayGraphicsPosition = 0x088, // DISPC_GFX_POSITION
  343. OmapDisplayGraphicsSize = 0x08C, // DISPC_GFX_SIZE
  344. OmapDisplayGraphicsAttributes = 0x0A0, // DISPC_GFX_ATTRIBUTES
  345. OmapDisplayGraphicsBufferThreshold = 0x0A4, // DISPC_GFX_BUF_THRESHOLD
  346. OmapDisplayGraphicsBufferSize = 0x0A8, // DISPC_GFX_BUF_SIZE_STATUS
  347. OmapDisplayGraphicsRowIncrement = 0x0AC, // DISPC_GFX_ROW_INC
  348. OmapDisplayGraphicsPixelIncrement = 0x0B0, // DISPC_GFX_PIXEL_INC
  349. OmapDisplayGraphicsWindowSkip = 0x0B4, // DISPC_GFX_WINDOW_SKIP
  350. OmapDisplayVideo1FrameBufferAddress0 = 0x0BC, // DISPC_VID1_BA_0
  351. OmapDisplayVideo1FrameBufferAddress1 = 0x0C0, // DISPC_VID1_BA_1
  352. OmapDisplayVideo1Position = 0x0C4, // DISPC_VID1_POSITION
  353. OmapDisplayVideo1Size = 0x0C8, // DISPC_VID1_SIZE
  354. OmapDisplayVideo1Attributes = 0x0CC, // DISPC_VID1_ATTRIBUTES
  355. OmapDisplayVideo1PictureSize = 0x0E4, // DISPC_VID1_PICTURE_SIZE
  356. OmapDisplayGraphicsDmaPreload = 0x22C, // DISPC_GFX_PRELOAD
  357. OmapDisplayVideo1DmaPreload = 0x230, // DISPC_VID1_PRELOAD
  358. OmapDisplayControl2 = 0x238, // DISPC_CONTROL2
  359. OmapDisplayDefaultColor2 = 0x3AC, // DISPC_DEFAULT_COLOR2
  360. OmapDisplayData2Cycle1 = 0x3C0, // DISPC_DATA2_CYCLE1
  361. OmapDisplayLcd2Size = 0x3CC, // DISPC_SIZE_LCD2
  362. OmapDisplayHorizontalTiming2 = 0x400, // DISPC_TIMING_H2
  363. OmapDisplayVerticalTiming2 = 0x404, // DISPC_TIMING_V2
  364. OmapDisplayPolarity2 = 0x408, // DISPC_POL_FREQ2
  365. OmapDisplayDivisor2 = 0x40C, // DISPC_DIVISOR2
  366. OmapDisplayConfiguration2 = 0x620, // DISPC_CONFIG2
  367. OmapDisplayVideo1Attributes2 = 0x624, // DISPC_VID1_ATTRIBUTES2
  368. } OMAP_DISPLAY_CONTROLLER_REGISTER, *POMAP_DISPLAY_CONTROLLER_REGISTER;
  369. //
  370. // Define register offsets in the DSS (Display Subsystem) module. All offsets
  371. // are in bytes.
  372. //
  373. typedef enum _OMAP_DISPLAY_SUBSYSTEM_REGISTER {
  374. OmapDisplaySubsystemControl = 0x040, // DSS_CTRL
  375. } OMAP_DISPLAY_SUBSYSTEM_REGISTER, *POMAP_DISPLAY_SUBSYSTEM_REGISTER;
  376. //
  377. // Define register offsets for the DSS PRM. All offsets are in bytes.
  378. //
  379. typedef enum _DSS_PRM_REGISTER {
  380. OmapDssPrmPowerStateControl = 0x0
  381. } DSS_PRM_REGISTER, *PDSS_PRM_REGISTER;
  382. //
  383. // Define register offsets for the DSS CM. All offsets are in bytes.
  384. //
  385. typedef enum _DSS_CM2_REGISTER {
  386. OmapDssCmClockStateControl = 0x00, // CM_DSS_CLKSTCTRL
  387. OmapDssCmClockControl = 0x20, // CM_DSS_DSS_CLKCTRL
  388. } DSS_CM2_REGISTER, *PDSS_CM2_REGISTER;
  389. /*++
  390. Structure Description:
  391. This structure stores the OMAP4 graphics output mode information.
  392. Members:
  393. Information - Stores the information structure.
  394. PixelClockDivisor - Stores the pixel clock divisor to set for that mode.
  395. --*/
  396. typedef struct _EFI_OMAP4_VIDEO_MODE {
  397. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION Information;
  398. UINT32 PixelClockDivisor;
  399. } EFI_OMAP4_VIDEO_MODE, *PEFI_OMAP4_VIDEO_MODE;
  400. /*++
  401. Structure Description:
  402. This structure stores the structure of an OMAP4 video device path.
  403. Members:
  404. VendorPath - Stores the vendor path portion of the device path.
  405. End - Stores the end device path node.
  406. --*/
  407. typedef struct _EFI_OMAP4_VIDEO_DEVICE_PATH {
  408. VENDOR_DEVICE_PATH VendorPath;
  409. EFI_DEVICE_PATH_PROTOCOL End;
  410. } EFI_OMAP4_VIDEO_DEVICE_PATH, *PEFI_OMAP4_VIDEO_DEVICE_PATH;
  411. /*++
  412. Structure Description:
  413. This structure stores the internal context for an OMAP4 video device.
  414. Members:
  415. Magic - Stores the constant magic value EFI_OMAP4_VIDEO_DEVICE_MAGIC.
  416. Handle - Stores the graphics out handle.
  417. GraphicsOut - Stores the graphics output protocol.
  418. GraphicsOutMode - Stores the graphics output protocol mode.
  419. --*/
  420. typedef struct _EFI_OMAP4_VIDEO_DEVICE {
  421. UINT32 Magic;
  422. EFI_HANDLE Handle;
  423. EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOut;
  424. EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GraphicsOutMode;
  425. } EFI_OMAP4_VIDEO_DEVICE, *PEFI_OMAP4_VIDEO_DEVICE;
  426. //
  427. // ----------------------------------------------- Internal Function Prototypes
  428. //
  429. EFIAPI
  430. EFI_STATUS
  431. EfipOmap4GraphicsQueryMode (
  432. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  433. UINT32 ModeNumber,
  434. UINTN *SizeOfInfo,
  435. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
  436. );
  437. EFIAPI
  438. EFI_STATUS
  439. EfipOmap4GraphicsSetMode (
  440. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  441. UINT32 ModeNumber
  442. );
  443. EFIAPI
  444. EFI_STATUS
  445. EfipOmap4GraphicsBlt (
  446. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  447. EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  448. EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  449. UINTN SourceX,
  450. UINTN SourceY,
  451. UINTN DestinationX,
  452. UINTN DestinationY,
  453. UINTN Width,
  454. UINTN Height,
  455. UINTN Delta
  456. );
  457. VOID
  458. EfipOmap4VideoInitialize (
  459. EFI_PHYSICAL_ADDRESS FrameBufferBase,
  460. UINT32 FrameBufferWidth,
  461. UINT32 FrameBufferHeight,
  462. UINT32 PixelClockDivisor
  463. );
  464. //
  465. // -------------------------------------------------------------------- Globals
  466. //
  467. //
  468. // Store a pointer to the DISPC module.
  469. //
  470. VOID *EfiOmap4DispcAddress = (VOID *)OMAP4_DISPC_BASE;
  471. //
  472. // Store a pointer to the more global DSS (Display Subsystem) module.
  473. //
  474. VOID *EfiOmap4DssAddress = (VOID *)OMAP4_DSS_BASE;
  475. //
  476. // Store a pointer to the DSS Power and Reset Manager (PRM).
  477. //
  478. VOID *EfiOmap4DssPrmAddress = (VOID *)OMAP4_DSS_PRM_BASE;
  479. //
  480. // Store a pointer to the DSS Clock Manager (CM).
  481. //
  482. VOID *EfiOmap4DssCm2Address = (VOID *)OMAP4_DSS_CM2_BASE;
  483. //
  484. // Store the device path of the video controller.
  485. //
  486. EFI_OMAP4_VIDEO_DEVICE_PATH EfiOmap4VideoDevicePathTemplate = {
  487. {
  488. {
  489. HARDWARE_DEVICE_PATH,
  490. HW_VENDOR_DP,
  491. sizeof(VENDOR_DEVICE_PATH)
  492. },
  493. EFI_OMAP4_VIDEO_DEVICE_GUID,
  494. },
  495. {
  496. END_DEVICE_PATH_TYPE,
  497. END_ENTIRE_DEVICE_PATH_SUBTYPE,
  498. END_DEVICE_PATH_LENGTH
  499. }
  500. };
  501. //
  502. // Define the supported video modes.
  503. //
  504. EFI_OMAP4_VIDEO_MODE EfiOmap4VideoModes[] = {
  505. {
  506. {
  507. 0,
  508. 1024,
  509. 600,
  510. PixelBitMask,
  511. {
  512. 0x00FF0000,
  513. 0x0000FF00,
  514. 0x000000FF,
  515. 0xFF000000
  516. },
  517. 1024
  518. },
  519. 18
  520. },
  521. {
  522. {
  523. 0,
  524. 1024,
  525. 768,
  526. PixelBitMask,
  527. {
  528. 0x00FF0000,
  529. 0x0000FF00,
  530. 0x000000FF,
  531. 0xFF000000
  532. },
  533. 1024
  534. },
  535. 13
  536. },
  537. };
  538. //
  539. // ------------------------------------------------------------------ Functions
  540. //
  541. EFI_STATUS
  542. EfipPandaEnumerateVideo (
  543. VOID
  544. )
  545. /*++
  546. Routine Description:
  547. This routine enumerates the display on the PandaBoard.
  548. Arguments:
  549. None.
  550. Return Value:
  551. EFI status code.
  552. --*/
  553. {
  554. PEFI_OMAP4_VIDEO_DEVICE Device;
  555. EFI_PHYSICAL_ADDRESS FrameBufferBase;
  556. PEFI_OMAP4_VIDEO_MODE Mode;
  557. EFI_STATUS Status;
  558. FrameBufferBase = -1;
  559. Device = NULL;
  560. Mode = &(EfiOmap4VideoModes[EFI_OMAP4_VIDEO_DEFAULT_MODE]);
  561. //
  562. // Allocate space for the frame buffer.
  563. //
  564. Status = EfiAllocatePages(AllocateAnyPages,
  565. EfiMemoryMappedIO,
  566. EFI_SIZE_TO_PAGES(EFI_OMAP4_FRAME_BUFFER_SIZE),
  567. &FrameBufferBase);
  568. if (EFI_ERROR(Status)) {
  569. return Status;
  570. }
  571. //
  572. // Initialize the video to the default mode.
  573. //
  574. EfipOmap4VideoInitialize(FrameBufferBase,
  575. Mode->Information.HorizontalResolution,
  576. Mode->Information.VerticalResolution,
  577. Mode->PixelClockDivisor);
  578. //
  579. // Everything's all set up, create the graphics output protocol.
  580. //
  581. Status = EfiAllocatePool(EfiBootServicesData,
  582. sizeof(EFI_OMAP4_VIDEO_DEVICE),
  583. (VOID **)&Device);
  584. if (EFI_ERROR(Status)) {
  585. goto EnumerateVideoEnd;
  586. }
  587. EfiSetMem(Device, sizeof(EFI_OMAP4_VIDEO_DEVICE), 0);
  588. Device->Magic = EFI_OMAP4_VIDEO_DEVICE_MAGIC;
  589. Device->GraphicsOut.QueryMode = EfipOmap4GraphicsQueryMode;
  590. Device->GraphicsOut.SetMode = EfipOmap4GraphicsSetMode;
  591. Device->GraphicsOut.Blt = EfipOmap4GraphicsBlt;
  592. Device->GraphicsOut.Mode = &(Device->GraphicsOutMode);
  593. Device->GraphicsOutMode.MaxMode = EFI_OMAP4_VIDEO_MODE_COUNT;
  594. Device->GraphicsOutMode.Mode = EFI_OMAP4_VIDEO_DEFAULT_MODE;
  595. Device->GraphicsOutMode.Info = &(Mode->Information);
  596. Device->GraphicsOutMode.SizeOfInfo =
  597. sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
  598. Device->GraphicsOutMode.FrameBufferBase = FrameBufferBase;
  599. Device->GraphicsOutMode.FrameBufferSize = EFI_OMAP4_FRAME_BUFFER_SIZE;
  600. Status = EfiInstallMultipleProtocolInterfaces(
  601. &(Device->Handle),
  602. &EfiGraphicsOutputProtocolGuid,
  603. &(Device->GraphicsOut),
  604. &EfiDevicePathProtocolGuid,
  605. &EfiOmap4VideoDevicePathTemplate,
  606. NULL);
  607. if (EFI_ERROR(Status)) {
  608. goto EnumerateVideoEnd;
  609. }
  610. EnumerateVideoEnd:
  611. if (EFI_ERROR(Status)) {
  612. if (FrameBufferBase != -1) {
  613. EfiFreePages(FrameBufferBase,
  614. EFI_SIZE_TO_PAGES(EFI_OMAP4_FRAME_BUFFER_SIZE));
  615. }
  616. if (Device != NULL) {
  617. EfiFreePool(Device);
  618. }
  619. }
  620. return Status;
  621. }
  622. //
  623. // --------------------------------------------------------- Internal Functions
  624. //
  625. EFIAPI
  626. EFI_STATUS
  627. EfipOmap4GraphicsQueryMode (
  628. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  629. UINT32 ModeNumber,
  630. UINTN *SizeOfInfo,
  631. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
  632. )
  633. /*++
  634. Routine Description:
  635. This routine returns information about available graphics modes that the
  636. graphics device and set of active video output devices support.
  637. Arguments:
  638. This - Supplies a pointer to the protocol instance.
  639. ModeNumber - Supplies the mode number to return information about.
  640. SizeOfInfo - Supplies a pointer that on input contains the size in bytes of
  641. the information buffer.
  642. Info - Supplies a pointer where a callee-allocated buffer will be returned
  643. containing information about the mode. The caller is responsible for
  644. calling FreePool to free this data.
  645. Return Value:
  646. EFI_SUCCESS on success.
  647. EFI_DEVICE_ERROR if a hardware error occurred trying to retrieve the video
  648. mode.
  649. EFI_INVALID_PARAMETER if the mode number is not valid.
  650. --*/
  651. {
  652. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Information;
  653. EFI_STATUS Status;
  654. if ((ModeNumber >= EFI_OMAP4_VIDEO_MODE_COUNT) || (SizeOfInfo == NULL)) {
  655. return EFI_INVALID_PARAMETER;
  656. }
  657. Status = EfiAllocatePool(EfiBootServicesData,
  658. sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
  659. (VOID **)&Information);
  660. if (EFI_ERROR(Status)) {
  661. return Status;
  662. }
  663. EfiCopyMem(Information,
  664. &(EfiOmap4VideoModes[ModeNumber].Information),
  665. sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
  666. *Info = Information;
  667. *SizeOfInfo = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
  668. return EFI_SUCCESS;
  669. }
  670. EFIAPI
  671. EFI_STATUS
  672. EfipOmap4GraphicsSetMode (
  673. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  674. UINT32 ModeNumber
  675. )
  676. /*++
  677. Routine Description:
  678. This routine sets the video device into the specified mode and clears the
  679. visible portions of the output display to black.
  680. Arguments:
  681. This - Supplies a pointer to the protocol instance.
  682. ModeNumber - Supplies the mode number to set.
  683. Return Value:
  684. EFI_SUCCESS on success.
  685. EFI_DEVICE_ERROR if a hardware error occurred trying to set the video mode.
  686. EFI_UNSUPPORTED if the mode number is not supported by this device.
  687. --*/
  688. {
  689. PEFI_OMAP4_VIDEO_MODE Mode;
  690. EFI_STATUS Status;
  691. if (ModeNumber >= EFI_OMAP4_VIDEO_MODE_COUNT) {
  692. return EFI_UNSUPPORTED;
  693. }
  694. Mode = &(EfiOmap4VideoModes[ModeNumber]);
  695. EfipOmap4VideoInitialize(This->Mode->FrameBufferBase,
  696. Mode->Information.HorizontalResolution,
  697. Mode->Information.VerticalResolution,
  698. Mode->PixelClockDivisor);
  699. This->Mode->Info = &(Mode->Information);
  700. This->Mode->Mode = ModeNumber;
  701. This->Mode->SizeOfInfo = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
  702. return Status;
  703. }
  704. EFIAPI
  705. EFI_STATUS
  706. EfipOmap4GraphicsBlt (
  707. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  708. EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  709. EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  710. UINTN SourceX,
  711. UINTN SourceY,
  712. UINTN DestinationX,
  713. UINTN DestinationY,
  714. UINTN Width,
  715. UINTN Height,
  716. UINTN Delta
  717. )
  718. /*++
  719. Routine Description:
  720. This routine performs a Blt (copy) operation of pixels on the graphics
  721. screen. Blt stands for Block Transfer for those not up on their video lingo.
  722. Arguments:
  723. This - Supplies a pointer to the protocol instance.
  724. BltBuffer - Supplies an optional pointer to the data to transfer to the
  725. graphics screen. The size must be at least width * height *
  726. sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL).
  727. BltOperation - Supplies the operation to perform when copying the buffer to
  728. the screen.
  729. SourceX - Supplies the X coordinate of the source of the operation.
  730. SourceY - Supplies the Y coordinate of the source of the operation.
  731. DestinationX - Supplies the X coordinate of the destination of the
  732. operation.
  733. DestinationY - Supplies the Y coordinate of the destination of the
  734. operation.
  735. Width - Supplies the width of the rectangle in pixels.
  736. Height - Supplies the height of the rectangle in pixels.
  737. Delta - Supplies an optional number of bytes in a row of the given buffer.
  738. If a delta of zero is used, the entire buffer is being operated on.
  739. This is not used for EfiBltVideoFill or EfiBltVideoToVideo operations.
  740. Return Value:
  741. EFI_SUCCESS on success.
  742. EFI_INVALID_PARAMETER if the operation was not valid.
  743. EFI_DEVICE_ERROR if a hardware error occurred and the request could not be
  744. completed.
  745. --*/
  746. {
  747. return EFI_UNSUPPORTED;
  748. }
  749. VOID
  750. EfipOmap4VideoInitialize (
  751. EFI_PHYSICAL_ADDRESS FrameBufferBase,
  752. UINT32 FrameBufferWidth,
  753. UINT32 FrameBufferHeight,
  754. UINT32 PixelClockDivisor
  755. )
  756. /*++
  757. Routine Description:
  758. This routine initialize the video subsystem on the TI OMAP4.
  759. Arguments:
  760. FrameBufferBase - Supplies the physical address where the frame buffer is
  761. located.
  762. FrameBufferWidth - Supplies the width of the frame buffer in pixels.
  763. FrameBufferHeight - Supplies the height of the frame buffer in pixels.
  764. PixelClockDivisor - Supplies the pixel clock divisor to set.
  765. Return Value:
  766. None.
  767. --*/
  768. {
  769. UINT32 Value;
  770. //
  771. // Set GPIO0 to HI to enable the TFP410PAP. For the output enable register,
  772. // when a bit is 0, then the GPIO is in output mode.
  773. //
  774. Value = READ_GPIO1_REGISTER(OmapGpioOutputEnable);
  775. WRITE_GPIO1_REGISTER(OmapGpioOutputEnable, Value & ~(1 << 0));
  776. WRITE_GPIO1_REGISTER(OmapGpioOutputSet, (1 << 0));
  777. //
  778. // Enable clocks and power for the Display Subsystem.
  779. //
  780. WRITE_DSS_PRM_REGISTER(OmapDssPrmPowerStateControl,
  781. OMAP_DSS_PRM_POWER_CONTROL_POWER_ON);
  782. WRITE_DSS_CM_REGISTER(OmapDssCmClockStateControl,
  783. OMAP_DSS_CM_CLOCK_STATE_CONTROL_SOFTWARE_WAKEUP);
  784. Value = OMAP_DSS_CM_CLOCK_CONTROL_DSS_CLOCK_ENABLED |
  785. OMAP_DSS_CM_CLOCK_CONTROL_ENABLE;
  786. WRITE_DSS_CM_REGISTER(OmapDssCmClockControl, Value);
  787. //
  788. // Wait for the module to exit an idle state before attempting to access it.
  789. //
  790. while (TRUE) {
  791. if ((READ_DSS_CM_REGISTER(OmapDssCmClockControl) &
  792. OMAP_DSS_CM_CLOCK_CONTROL_IDLE_STATE_MASK) == 0) {
  793. break;
  794. }
  795. }
  796. //
  797. // Reset DSS control to its default value.
  798. //
  799. WRITE_DISPLAY_SUBSYSTEM_REGISTER(OmapDisplaySubsystemControl, 0);
  800. //
  801. // Set up smart auto-idling.
  802. //
  803. Value = OMAP_VIDEO_SYSTEM_CONFIGURATION_SMART_STANDBY |
  804. OMAP_VIDEO_SYSTEM_CONFIGURATION_SMART_IDLE |
  805. OMAP_VIDEO_SYSTEM_CONFIGURATION_ENABLE_WAKEUP |
  806. OMAP_VIDEO_SYSTEM_CONFIGURATION_AUTO_IDLE;
  807. WRITE_DISPLAY_REGISTER(OmapDisplaySystemConfiguration, Value);
  808. //
  809. // Set up the configuration register to only load frame data (and not
  810. // palette/gamma tables) every frame.
  811. //
  812. WRITE_DISPLAY_REGISTER(OmapDisplayConfiguration1,
  813. OMAP_VIDEO_CONFIGURATION1_LOAD_ONLY_FRAME_DATA);
  814. //
  815. // Set up the divisor.
  816. //
  817. Value = (OMAP4_DISPLAY_SUBSYSTEM_DIVISOR <<
  818. OMAP_VIDEO_DIVISOR_DISPLAY_SUBSYSTEM_DIVISOR_SHIFT) |
  819. PixelClockDivisor;
  820. WRITE_DISPLAY_REGISTER(OmapDisplayDivisor2, Value);
  821. //
  822. // Disable the global alpha channel on all video pipelines.
  823. //
  824. WRITE_DISPLAY_REGISTER(OmapDisplayGlobalAlpha, 0xFFFFFFFF);
  825. //
  826. // Set the address of the frame buffer.
  827. //
  828. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsFrameBufferAddress0,
  829. (UINT32)FrameBufferBase);
  830. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsFrameBufferAddress1,
  831. (UINT32)FrameBufferBase);
  832. //
  833. // Set the position of this frame buffer in the overlay manager. This is
  834. // the only frame buffer, so set it to the top left.
  835. //
  836. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsPosition, 0);
  837. //
  838. // Set up the dimensions of the frame buffer itself.
  839. //
  840. Value = ((FrameBufferWidth - 1) << OMAP_VIDEO_SIZE_X_SHIFT) |
  841. ((FrameBufferHeight - 1) << OMAP_VIDEO_SIZE_Y_SHIFT);
  842. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsSize, Value);
  843. //
  844. // Set up the attributes register, which sets up the pixel format, enables
  845. // the pipeline, and sets LCD2 as the destination.
  846. //
  847. Value = OMAP_VIDEO_ATTRIBUTES_LCD2_OUTPUT |
  848. OMAP_VIDEO_ATTRIBUTES_BURST_8X128_BITS |
  849. OMAP_VIDEO_ATTRIBUTES_FORMAT_XRGB24_8888 |
  850. OMAP_VIDEO_ATTRIBUTES_ENABLED;
  851. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsAttributes, Value);
  852. Value = (OMAP_VIDEO_BUFFER_HIGH_THRESHOLD <<
  853. OMAP_VIDEO_BUFFER_THRESHOLD_HIGH_SHIFT) |
  854. OMAP_VIDEO_BUFFER_LOW_THRESHOLD;
  855. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsBufferThreshold, Value);
  856. Value = OMAP_VIDEO_BUFFER_SIZE;
  857. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsBufferSize, Value);
  858. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsWindowSkip, 0);
  859. //
  860. // Set up the row and pixel increments to nothing fancy.
  861. //
  862. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsRowIncrement, 1);
  863. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsPixelIncrement, 1);
  864. //
  865. // Set the preload value to its default.
  866. //
  867. WRITE_DISPLAY_REGISTER(OmapDisplayGraphicsDmaPreload,
  868. OMAP4_VIDEO_PRELOAD_VALUE);
  869. //
  870. // Set the default color to red.
  871. //
  872. WRITE_DISPLAY_REGISTER(OmapDisplayDefaultColor0, 0x00FF0000);
  873. WRITE_DISPLAY_REGISTER(OmapDisplayDefaultColor1, 0x00FF0000);
  874. WRITE_DISPLAY_REGISTER(OmapDisplayDefaultColor2, 0x00FF0000);
  875. //
  876. // Configure all the pin polarities to their normal values.
  877. //
  878. WRITE_DISPLAY_REGISTER(OmapDisplayPolarity2, 0);
  879. //
  880. // Set up the dimensions to output to LCD2.
  881. //
  882. Value = ((FrameBufferWidth - 1) << OMAP_VIDEO_LCD_SIZE_X_SHIFT) |
  883. ((FrameBufferHeight - 1) << OMAP_VIDEO_LCD_SIZE_Y_SHIFT);
  884. WRITE_DISPLAY_REGISTER(OmapDisplayLcd2Size, Value);
  885. //
  886. // Set up the timing parameters.
  887. //
  888. Value = (OMAP4_HORIZONTAL_BACK_PORCH <<
  889. OMAP_VIDEO_TIMING_HORIZONTAL_BACK_PORCH_SHIFT) |
  890. (OMAP4_HORIZONTAL_FRONT_PORCH <<
  891. OMAP_VIDEO_TIMING_HORIZONTAL_FRONT_PORCH_SHIFT) |
  892. OMAP4_HORIZONTAL_SYNC_PULSE_WIDTH;
  893. WRITE_DISPLAY_REGISTER(OmapDisplayHorizontalTiming2, Value);
  894. Value = (OMAP4_VERTICAL_BACK_PORCH <<
  895. OMAP_VIDEO_TIMING_VERTICAL_BACK_PORCH_SHIFT) |
  896. (OMAP4_VERTICAL_FRONT_PORCH <<
  897. OMAP_VIDEO_TIMING_HORIZONTAL_FRONT_PORCH_SHIFT) |
  898. OMAP4_VERTICAL_SYNC_PULSE_WIDTH;
  899. WRITE_DISPLAY_REGISTER(OmapDisplayVerticalTiming2, Value);
  900. //
  901. // Set up the control 2 register to turn on LCD2.
  902. //
  903. Value = OMAP_VIDEO_CONTROL2_24_BIT_TFT_DATA |
  904. OMAP_VIDEO_CONTROL2_ACTIVE_TFT |
  905. OMAP_VIDEO_CONTROL2_LCD2_ENABLED;
  906. WRITE_DISPLAY_REGISTER(OmapDisplayControl2, Value);
  907. WRITE_DISPLAY_REGISTER(OmapDisplayControl2,
  908. Value | OMAP_VIDEO_CONTROL2_GO_LCD2);
  909. //
  910. // Wait for the pipeline to suck up the new parameters.
  911. //
  912. while (TRUE) {
  913. if ((READ_DISPLAY_REGISTER(OmapDisplayControl2) &
  914. OMAP_VIDEO_CONTROL2_GO_LCD2) == 0) {
  915. break;
  916. }
  917. }
  918. //
  919. // Clear any pending interrupts.
  920. //
  921. WRITE_DISPLAY_REGISTER(OmapDisplayInterruptStatus, 0xFFFFFFFF);
  922. return;
  923. }