mvebu_lcd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Video driver for Marvell Armada XP SoC
  4. *
  5. * Initialization of LCD interface and setup of SPLASH screen image
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <part.h>
  10. #include <video.h>
  11. #include <asm/cache.h>
  12. #include <dm/device_compat.h>
  13. #include <linux/mbus.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/soc.h>
  17. #define MVEBU_LCD_WIN_CONTROL(w) (0xf000 + ((w) << 4))
  18. #define MVEBU_LCD_WIN_BASE(w) (0xf004 + ((w) << 4))
  19. #define MVEBU_LCD_WIN_REMAP(w) (0xf00c + ((w) << 4))
  20. #define MVEBU_LCD_CFG_DMA_START_ADDR_0 0x00cc
  21. #define MVEBU_LCD_CFG_DMA_START_ADDR_1 0x00dc
  22. #define MVEBU_LCD_CFG_GRA_START_ADDR0 0x00f4
  23. #define MVEBU_LCD_CFG_GRA_START_ADDR1 0x00f8
  24. #define MVEBU_LCD_CFG_GRA_PITCH 0x00fc
  25. #define MVEBU_LCD_SPU_GRA_OVSA_HPXL_VLN 0x0100
  26. #define MVEBU_LCD_SPU_GRA_HPXL_VLN 0x0104
  27. #define MVEBU_LCD_SPU_GZM_HPXL_VLN 0x0108
  28. #define MVEBU_LCD_SPU_HWC_OVSA_HPXL_VLN 0x010c
  29. #define MVEBU_LCD_SPU_HWC_HPXL_VLN 0x0110
  30. #define MVEBU_LCD_SPUT_V_H_TOTAL 0x0114
  31. #define MVEBU_LCD_SPU_V_H_ACTIVE 0x0118
  32. #define MVEBU_LCD_SPU_H_PORCH 0x011c
  33. #define MVEBU_LCD_SPU_V_PORCH 0x0120
  34. #define MVEBU_LCD_SPU_BLANKCOLOR 0x0124
  35. #define MVEBU_LCD_SPU_ALPHA_COLOR1 0x0128
  36. #define MVEBU_LCD_SPU_ALPHA_COLOR2 0x012c
  37. #define MVEBU_LCD_SPU_COLORKEY_Y 0x0130
  38. #define MVEBU_LCD_SPU_COLORKEY_U 0x0134
  39. #define MVEBU_LCD_SPU_COLORKEY_V 0x0138
  40. #define MVEBU_LCD_CFG_RDREG4F 0x013c
  41. #define MVEBU_LCD_SPU_SPI_RXDATA 0x0140
  42. #define MVEBU_LCD_SPU_ISA_RXDATA 0x0144
  43. #define MVEBU_LCD_SPU_DBG_ISA 0x0148
  44. #define MVEBU_LCD_SPU_HWC_RDDAT 0x0158
  45. #define MVEBU_LCD_SPU_GAMMA_RDDAT 0x015c
  46. #define MVEBU_LCD_SPU_PALETTE_RDDAT 0x0160
  47. #define MVEBU_LCD_SPU_IOPAD_IN 0x0178
  48. #define MVEBU_LCD_FRAME_COUNT 0x017c
  49. #define MVEBU_LCD_SPU_DMA_CTRL0 0x0190
  50. #define MVEBU_LCD_SPU_DMA_CTRL1 0x0194
  51. #define MVEBU_LCD_SPU_SRAM_CTRL 0x0198
  52. #define MVEBU_LCD_SPU_SRAM_WRDAT 0x019c
  53. #define MVEBU_LCD_SPU_SRAM_PARA0 0x01a0
  54. #define MVEBU_LCD_SPU_SRAM_PARA1 0x01a4
  55. #define MVEBU_LCD_CFG_SCLK_DIV 0x01a8
  56. #define MVEBU_LCD_SPU_CONTRAST 0x01ac
  57. #define MVEBU_LCD_SPU_SATURATION 0x01b0
  58. #define MVEBU_LCD_SPU_CBSH_HUE 0x01b4
  59. #define MVEBU_LCD_SPU_DUMB_CTRL 0x01b8
  60. #define MVEBU_LCD_SPU_IOPAD_CONTROL 0x01bc
  61. #define MVEBU_LCD_SPU_IRQ_ENA_2 0x01d8
  62. #define MVEBU_LCD_SPU_IRQ_ISR_2 0x01dc
  63. #define MVEBU_LCD_SPU_IRQ_ENA 0x01c0
  64. #define MVEBU_LCD_SPU_IRQ_ISR 0x01c4
  65. #define MVEBU_LCD_ADLL_CTRL 0x01c8
  66. #define MVEBU_LCD_CLK_DIS 0x01cc
  67. #define MVEBU_LCD_VGA_HVSYNC_DELAY 0x01d4
  68. #define MVEBU_LCD_CLK_CFG_0 0xf0a0
  69. #define MVEBU_LCD_CLK_CFG_1 0xf0a4
  70. #define MVEBU_LCD_LVDS_CLK_CFG 0xf0ac
  71. #define MVEBU_LVDS_PADS_REG (MVEBU_SYSTEM_REG_BASE + 0xf0)
  72. enum {
  73. /* Maximum LCD size we support */
  74. LCD_MAX_WIDTH = 640,
  75. LCD_MAX_HEIGHT = 480,
  76. LCD_MAX_LOG2_BPP = VIDEO_BPP16,
  77. };
  78. struct mvebu_lcd_info {
  79. u32 fb_base;
  80. int x_res;
  81. int y_res;
  82. int x_fp;
  83. int y_fp;
  84. int x_bp;
  85. int y_bp;
  86. };
  87. struct mvebu_video_priv {
  88. uintptr_t regs;
  89. };
  90. /* Setup Mbus Bridge Windows for LCD */
  91. static void mvebu_lcd_conf_mbus_registers(uintptr_t regs)
  92. {
  93. const struct mbus_dram_target_info *dram;
  94. int i;
  95. dram = mvebu_mbus_dram_info();
  96. /* Disable windows, set size/base/remap to 0 */
  97. for (i = 0; i < 6; i++) {
  98. writel(0, regs + MVEBU_LCD_WIN_CONTROL(i));
  99. writel(0, regs + MVEBU_LCD_WIN_BASE(i));
  100. writel(0, regs + MVEBU_LCD_WIN_REMAP(i));
  101. }
  102. /* Write LCD bridge window registers */
  103. for (i = 0; i < dram->num_cs; i++) {
  104. const struct mbus_dram_window *cs = dram->cs + i;
  105. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  106. (dram->mbus_dram_target_id << 4) | 1,
  107. regs + MVEBU_LCD_WIN_CONTROL(i));
  108. writel(cs->base & 0xffff0000, regs + MVEBU_LCD_WIN_BASE(i));
  109. }
  110. }
  111. /* Initialize LCD registers */
  112. static void mvebu_lcd_register_init(struct mvebu_lcd_info *lcd_info,
  113. uintptr_t regs)
  114. {
  115. /* Local variable for easier handling */
  116. int x = lcd_info->x_res;
  117. int y = lcd_info->y_res;
  118. u32 val;
  119. /* Setup Mbus Bridge Windows */
  120. mvebu_lcd_conf_mbus_registers(regs);
  121. /*
  122. * Set LVDS Pads Control Register
  123. * wr 0 182F0 FFE00000
  124. */
  125. clrbits_le32(MVEBU_LVDS_PADS_REG, 0x1f << 16);
  126. /*
  127. * Set the LCD_CFG_GRA_START_ADDR0/1 Registers
  128. * This is supposed to point to the "physical" memory at memory
  129. * end (currently 1GB-64MB but also may be 2GB-64MB).
  130. * See also the Window 0 settings!
  131. */
  132. writel(lcd_info->fb_base, regs + MVEBU_LCD_CFG_GRA_START_ADDR0);
  133. writel(lcd_info->fb_base, regs + MVEBU_LCD_CFG_GRA_START_ADDR1);
  134. /*
  135. * Set the LCD_CFG_GRA_PITCH Register
  136. * Bits 31-28: Duty Cycle of Backlight. value/16=High (0x8=Mid Setting)
  137. * Bits 25-16: Backlight divider from 32kHz Clock
  138. * (here 16=0x10 for 1kHz)
  139. * Bits 15-00: Line Length in Bytes
  140. * 240*2 (for RGB1555)=480=0x1E0
  141. */
  142. writel(0x80100000 + 2 * x, regs + MVEBU_LCD_CFG_GRA_PITCH);
  143. /*
  144. * Set the LCD_SPU_GRA_OVSA_HPXL_VLN Register
  145. * Bits 31-16: Vertical start of graphical overlay on screen
  146. * Bits 15-00: Horizontal start of graphical overlay on screen
  147. */
  148. writel(0x00000000, regs + MVEBU_LCD_SPU_GRA_OVSA_HPXL_VLN);
  149. /*
  150. * Set the LCD_SPU_GRA_HPXL_VLN Register
  151. * Bits 31-16: Vertical size of graphical overlay 320=0x140
  152. * Bits 15-00: Horizontal size of graphical overlay 240=0xF0
  153. * Values before zooming
  154. */
  155. writel((y << 16) | x, regs + MVEBU_LCD_SPU_GRA_HPXL_VLN);
  156. /*
  157. * Set the LCD_SPU_GZM_HPXL_VLN Register
  158. * Bits 31-16: Vertical size of graphical overlay 320=0x140
  159. * Bits 15-00: Horizontal size of graphical overlay 240=0xF0
  160. * Values after zooming
  161. */
  162. writel((y << 16) | x, regs + MVEBU_LCD_SPU_GZM_HPXL_VLN);
  163. /*
  164. * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
  165. * Bits 31-16: Vertical position of HW Cursor 320=0x140
  166. * Bits 15-00: Horizontal position of HW Cursor 240=0xF0
  167. */
  168. writel((y << 16) | x, regs + MVEBU_LCD_SPU_HWC_OVSA_HPXL_VLN);
  169. /*
  170. * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
  171. * Bits 31-16: Vertical size of HW Cursor
  172. * Bits 15-00: Horizontal size of HW Cursor
  173. */
  174. writel(0x00000000, regs + MVEBU_LCD_SPU_HWC_HPXL_VLN);
  175. /*
  176. * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
  177. * Bits 31-16: Screen total vertical lines:
  178. * VSYNC = 1
  179. * Vertical Front Porch = 2
  180. * Vertical Lines = 320
  181. * Vertical Back Porch = 2
  182. * SUM = 325 = 0x0145
  183. * Bits 15-00: Screen total horizontal pixels:
  184. * HSYNC = 1
  185. * Horizontal Front Porch = 44
  186. * Horizontal Lines = 240
  187. * Horizontal Back Porch = 2
  188. * SUM = 287 = 0x011F
  189. * Note: For the display the backporch is between SYNC and
  190. * the start of the pixels.
  191. * This is not certain for the Marvell (!?)
  192. */
  193. val = ((y + lcd_info->y_fp + lcd_info->y_bp + 1) << 16) |
  194. (x + lcd_info->x_fp + lcd_info->x_bp + 1);
  195. writel(val, regs + MVEBU_LCD_SPUT_V_H_TOTAL);
  196. /*
  197. * Set the LCD_SPU_V_H_ACTIVE Register
  198. * Bits 31-16: Screen active vertical lines 320=0x140
  199. * Bits 15-00: Screen active horizontakl pixels 240=0x00F0
  200. */
  201. writel((y << 16) | x, regs + MVEBU_LCD_SPU_V_H_ACTIVE);
  202. /*
  203. * Set the LCD_SPU_H_PORCH Register
  204. * Bits 31-16: Screen horizontal backporch 44=0x2c
  205. * Bits 15-00: Screen horizontal frontporch 2=0x02
  206. * Note: The terms "front" and "back" for the Marvell seem to be
  207. * exactly opposite to the display.
  208. */
  209. writel((lcd_info->x_fp << 16) | lcd_info->x_bp,
  210. regs + MVEBU_LCD_SPU_H_PORCH);
  211. /*
  212. * Set the LCD_SPU_V_PORCH Register
  213. * Bits 31-16: Screen vertical backporch 2=0x02
  214. * Bits 15-00: Screen vertical frontporch 2=0x02
  215. * Note: The terms "front" and "back" for the Marvell seem to be exactly
  216. * opposite to the display.
  217. */
  218. writel((lcd_info->y_fp << 16) | lcd_info->y_bp,
  219. regs + MVEBU_LCD_SPU_V_PORCH);
  220. /*
  221. * Set the LCD_SPU_BLANKCOLOR Register
  222. * This should be black = 0
  223. * For tests this is magenta=00FF00FF
  224. */
  225. writel(0x00FF00FF, regs + MVEBU_LCD_SPU_BLANKCOLOR);
  226. /*
  227. * Registers in the range of 0x0128 to 0x012C are colors for the cursor
  228. * Registers in the range of 0x0130 to 0x0138 are colors for video
  229. * color keying
  230. */
  231. /*
  232. * Set the LCD_SPU_RDREG4F Register
  233. * Bits 31-12: Reservd
  234. * Bit 11: SRAM Wait
  235. * Bit 10: Smart display fast TX (must be 1)
  236. * Bit 9: DMA Arbitration Video/Graphics overlay: 0=interleaved
  237. * Bit 8: FIFO watermark for DMA: 0=disable
  238. * Bits 07-00: Empty 8B FIFO entries to trigger DMA, default=0x80
  239. */
  240. writel(0x00000780, regs + MVEBU_LCD_CFG_RDREG4F);
  241. /*
  242. * Set the LCD_SPU_DMACTRL 0 Register
  243. * Bit 31: Disable overlay blending 1=disable
  244. * Bit 30: Gamma correction enable, 0=disable
  245. * Bit 29: Video Contrast/Saturation/Hue Adjust enable, 0=disable
  246. * Bit 28: Color palette enable, 0=disable
  247. * Bit 27: DMA AXI Arbiter, 1=default
  248. * Bit 26: HW Cursor 1-bit mode
  249. * Bit 25: HW Cursor or 1- or 2-bit mode
  250. * Bit 24: HW Cursor enabled, 0=disable
  251. * Bits 23-20: Graphics Memory Color Format: 0x1=RGB1555
  252. * Bits 19-16: Video Memory Color Format: 0x1=RGB1555
  253. * Bit 15: Memory Toggle between frame 0 and 1: 0=disable
  254. * Bit 14: Graphics horizontal scaling enable: 0=disable
  255. * Bit 13: Graphics test mode: 0=disable
  256. * Bit 12: Graphics SWAP R and B: 0=disable
  257. * Bit 11: Graphics SWAP U and V: 0=disable
  258. * Bit 10: Graphics SWAP Y and U/V: 0=disable
  259. * Bit 09: Graphic YUV to RGB Conversion: 0=disable
  260. * Bit 08: Graphic Transfer: 1=enable
  261. * Bit 07: Memory Toggle: 0=disable
  262. * Bit 06: Video horizontal scaling enable: 0=disable
  263. * Bit 05: Video test mode: 0=disable
  264. * Bit 04: Video SWAP R and B: 0=disable
  265. * Bit 03: Video SWAP U and V: 0=disable
  266. * Bit 02: Video SWAP Y and U/V: 0=disable
  267. * Bit 01: Video YUV to RGB Conversion: 0=disable
  268. * Bit 00: Video Transfer: 0=disable
  269. */
  270. writel(0x88111100, regs + MVEBU_LCD_SPU_DMA_CTRL0);
  271. /*
  272. * Set the LCD_SPU_DMA_CTRL1 Register
  273. * Bit 31: Manual DMA Trigger = 0
  274. * Bits 30-28: DMA Trigger Source: 0x2 VSYNC
  275. * Bit 28: VSYNC_INV: 0=Rising Edge, 1=Falling Edge
  276. * Bits 26-24: Color Key Mode: 0=disable
  277. * Bit 23: Fill low bits: 0=fill with zeroes
  278. * Bit 22: Reserved
  279. * Bit 21: Gated Clock: 0=disable
  280. * Bit 20: Power Save enable: 0=disable
  281. * Bits 19-18: Reserved
  282. * Bits 17-16: Configure Video/Graphic Path: 0x1: Graphic path alpha.
  283. * Bits 15-08: Configure Alpha: 0x00.
  284. * Bits 07-00: Reserved.
  285. */
  286. writel(0x20010000, regs + MVEBU_LCD_SPU_DMA_CTRL1);
  287. /*
  288. * Set the LCD_SPU_SRAM_CTRL Register
  289. * Reset to default = 0000C000
  290. * Bits 15-14: SRAM control: init=0x3, Read=0, Write=2
  291. * Bits 11-08: SRAM address ID: 0=gamma_yr, 1=gammy_ug, 2=gamma_vb,
  292. * 3=palette, 15=cursor
  293. */
  294. writel(0x0000C000, regs + MVEBU_LCD_SPU_SRAM_CTRL);
  295. /*
  296. * LCD_SPU_SRAM_WRDAT register: 019C
  297. * LCD_SPU_SRAM_PARA0 register: 01A0
  298. * LCD_SPU_SRAM_PARA1 register: 01A4 - Cursor control/Power settings
  299. */
  300. writel(0x00000000, regs + MVEBU_LCD_SPU_SRAM_PARA1);
  301. /* Clock settings in the at 01A8 and in the range F0A0 see below */
  302. /*
  303. * Set LCD_SPU_CONTRAST
  304. * Bits 31-16: Brightness sign ext. 8-bit value +255 to -255: default=0
  305. * Bits 15-00: Contrast sign ext. 8-bit value +255 to -255: default=0
  306. */
  307. writel(0x00000000, regs + MVEBU_LCD_SPU_CONTRAST);
  308. /*
  309. * Set LCD_SPU_SATURATION
  310. * Bits 31-16: Multiplier signed 4.12 fixed point value
  311. * Bits 15-00: Saturation signed 4.12 fixed point value
  312. */
  313. writel(0x10001000, regs + MVEBU_LCD_SPU_SATURATION);
  314. /*
  315. * Set LCD_SPU_HUE
  316. * Bits 31-16: Sine signed 2.14 fixed point value
  317. * Bits 15-00: Cosine signed 2.14 fixed point value
  318. */
  319. writel(0x00000000, regs + MVEBU_LCD_SPU_CBSH_HUE);
  320. /*
  321. * Set LCD_SPU_DUMB_CTRL
  322. * Bits 31-28: LCD Type: 3=18 bit RGB | 6=24 bit RGB888
  323. * Bits 27-12: Reserved
  324. * Bit 11: LCD DMA Pipeline Enable: 1=Enable
  325. * Bits 10-09: Reserved
  326. * Bit 8: LCD GPIO pin (??)
  327. * Bit 7: Reverse RGB
  328. * Bit 6: Invert composite blank signal DE/EN (??)
  329. * Bit 5: Invert composite sync signal
  330. * Bit 4: Invert Pixel Valid Enable DE/EN (??)
  331. * Bit 3: Invert VSYNC
  332. * Bit 2: Invert HSYNC
  333. * Bit 1: Invert Pixel Clock
  334. * Bit 0: Enable LCD Panel: 1=Enable
  335. * Question: Do we have to disable Smart and Dumb LCD
  336. * and separately enable LVDS?
  337. */
  338. writel(0x6000080F, regs + MVEBU_LCD_SPU_DUMB_CTRL);
  339. /*
  340. * Set LCD_SPU_IOPAD_CTRL
  341. * Bits 31-20: Reserved
  342. * Bits 19-18: Vertical Interpolation: 0=Disable
  343. * Bits 17-16: Reserved
  344. * Bit 15: Graphics Vertical Mirror enable: 0=disable
  345. * Bit 14: Reserved
  346. * Bit 13: Video Vertical Mirror enable: 0=disable
  347. * Bit 12: Reserved
  348. * Bit 11: Command Vertical Mirror enable: 0=disable
  349. * Bit 10: Reserved
  350. * Bits 09-08: YUV to RGB Color space conversion: 0 (Not used)
  351. * Bits 07-04: AXI Bus Master: 0x4: no crossing of 4k boundary,
  352. * 128 Bytes burst
  353. * Bits 03-00: LCD pins: ??? 0=24-bit Dump panel ??
  354. */
  355. writel(0x000000C0, regs + MVEBU_LCD_SPU_IOPAD_CONTROL);
  356. /*
  357. * Set SUP_IRQ_ENA_2: Disable all interrupts
  358. */
  359. writel(0x00000000, regs + MVEBU_LCD_SPU_IRQ_ENA_2);
  360. /*
  361. * Set SUP_IRQ_ENA: Disable all interrupts.
  362. */
  363. writel(0x00000000, regs + MVEBU_LCD_SPU_IRQ_ENA);
  364. /*
  365. * Set up ADDL Control Register
  366. * Bits 31-29: 0x0 = Fastest Delay Line (default)
  367. * 0x3 = Slowest Delay Line (default)
  368. * Bit 28: Calibration done status.
  369. * Bit 27: Reserved
  370. * Bit 26: Set Pixel Clock to ADDL output
  371. * Bit 25: Reduce CAL Enable
  372. * Bits 24-22: Manual calibration value.
  373. * Bit 21: Manual calibration enable.
  374. * Bit 20: Restart Auto Cal
  375. * Bits 19-16: Calibration Threshold voltage, default= 0x2
  376. * Bite 15-14: Reserved
  377. * Bits 13-11: Divisor for ADDL Clock: 0x1=/2, 0x3=/8, 0x5=/16
  378. * Bit 10: Power Down ADDL module, default = 1!
  379. * Bits 09-08: Test point configuration: 0x2=Bias, 0x3=High-z
  380. * Bit 07: Reset ADDL
  381. * Bit 06: Invert ADLL Clock
  382. * Bits 05-00: Delay taps, 0x3F=Half Cycle, 0x00=No delay
  383. * Note: ADLL is used for a VGA interface with DAC - not used here
  384. */
  385. writel(0x00000000, regs + MVEBU_LCD_ADLL_CTRL);
  386. /*
  387. * Set the LCD_CLK_DIS Register:
  388. * Bits 3 and 4 must be 1
  389. */
  390. writel(0x00000018, regs + MVEBU_LCD_CLK_DIS);
  391. /*
  392. * Set the LCD_VGA_HSYNC/VSYNC Delay Register:
  393. * Bits 03-00: Sets the delay for the HSYNC and VSYNC signals
  394. */
  395. writel(0x00000000, regs + MVEBU_LCD_VGA_HVSYNC_DELAY);
  396. /*
  397. * Clock registers
  398. * See page 475 in the functional spec.
  399. */
  400. /* Step 1 and 2: Disable the PLL */
  401. /*
  402. * Disable PLL, see "LCD Clock Configuration 1 Register" below
  403. */
  404. writel(0x8FF40007, regs + MVEBU_LCD_CLK_CFG_1);
  405. /*
  406. * Powerdown, see "LCD Clock Configuration 0 Register" below
  407. */
  408. writel(0x94000174, regs + MVEBU_LCD_CLK_CFG_0);
  409. /*
  410. * Set the LCD_CFG_SCLK_DIV Register
  411. * This is set fix to 0x40000001 for the LVDS output:
  412. * Bits 31-30: SCLCK Source: 0=AXIBus, 1=AHBus, 2=PLLDivider0
  413. * Bits 15-01: Clock Divider: Bypass for LVDS=0x0001
  414. * See page 475 in section 28.5.
  415. */
  416. writel(0x80000001, regs + MVEBU_LCD_CFG_SCLK_DIV);
  417. /*
  418. * Set the LCD Clock Configuration 0 Register:
  419. * Bit 31: Powerdown: 0=Power up
  420. * Bits 30-29: Reserved
  421. * Bits 28-26: PLL_KDIV: This encodes K
  422. * K=16 => 0x5
  423. * Bits 25-17: PLL_MDIV: This is M-1:
  424. * M=1 => 0x0
  425. * Bits 16-13: VCO band: 0x1 for 700-920MHz
  426. * Bits 12-04: PLL_NDIV: This is N-1 and corresponds to R1_CTRL!
  427. * N=28=0x1C => 0x1B
  428. * Bits 03-00: R1_CTRL (for N=28 => 0x4)
  429. */
  430. writel(0x940021B4, regs + MVEBU_LCD_CLK_CFG_0);
  431. /*
  432. * Set the LCD Clock Configuration 1 Register:
  433. * Bits 31-19: Reserved
  434. * Bit 18: Select PLL: Core PLL, 1=Dedicated PPL
  435. * Bit 17: Clock Output Enable: 0=disable, 1=enable
  436. * Bit 16: Select RefClk: 0=RefClk (25MHz), 1=External
  437. * Bit 15: Half-Div, Device Clock by DIV+0.5*Half-Dev
  438. * Bits 14-13: Reserved
  439. * Bits 12-00: PLL Full Divider [Note: Assumed to be the Post-Divider
  440. * M' for LVDS=7!]
  441. */
  442. writel(0x8FF40007, regs + MVEBU_LCD_CLK_CFG_1);
  443. /*
  444. * Set the LVDS Clock Configuration Register:
  445. * Bit 31: Clock Gating for the input clock to the LVDS
  446. * Bit 30: LVDS Serializer enable: 1=Enabled
  447. * Bits 29-11: Reserved
  448. * Bit 11-08: LVDS Clock delay: 0x02 (default): by 2 pixel clock/7
  449. * Bits 07-02: Reserved
  450. * Bit 01: 24bbp Option: 0=Option_1,1=Option2
  451. * Bit 00: 1=24bbp Panel: 0=18bpp Panel
  452. * Note: Bits 0 and must be verified with the help of the
  453. * Interface/display
  454. */
  455. writel(0xC0000201, regs + MVEBU_LCD_LVDS_CLK_CFG);
  456. /*
  457. * Power up PLL (Clock Config 0)
  458. */
  459. writel(0x140021B4, regs + MVEBU_LCD_CLK_CFG_0);
  460. /* wait 10 ms */
  461. mdelay(10);
  462. /*
  463. * Enable PLL (Clock Config 1)
  464. */
  465. writel(0x8FF60007, regs + MVEBU_LCD_CLK_CFG_1);
  466. }
  467. static int mvebu_video_probe(struct udevice *dev)
  468. {
  469. struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
  470. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  471. struct mvebu_video_priv *priv = dev_get_priv(dev);
  472. struct mvebu_lcd_info lcd_info;
  473. struct display_timing timings;
  474. u32 fb_start, fb_end;
  475. int ret;
  476. priv->regs = dev_read_addr(dev);
  477. if (priv->regs == FDT_ADDR_T_NONE) {
  478. dev_err(dev, "failed to get LCD address\n");
  479. return -ENXIO;
  480. }
  481. ret = ofnode_decode_display_timing(dev_ofnode(dev), 0, &timings);
  482. if (ret) {
  483. dev_err(dev, "failed to get any display timings\n");
  484. return -EINVAL;
  485. }
  486. /* Use DT timing (resolution) in internal info struct */
  487. lcd_info.fb_base = plat->base;
  488. lcd_info.x_res = timings.hactive.typ;
  489. lcd_info.x_fp = timings.hfront_porch.typ;
  490. lcd_info.x_bp = timings.hback_porch.typ;
  491. lcd_info.y_res = timings.vactive.typ;
  492. lcd_info.y_fp = timings.vfront_porch.typ;
  493. lcd_info.y_bp = timings.vback_porch.typ;
  494. /* Initialize the LCD controller */
  495. mvebu_lcd_register_init(&lcd_info, priv->regs);
  496. /* Enable dcache for the frame buffer */
  497. fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
  498. fb_end = plat->base + plat->size;
  499. fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
  500. mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
  501. DCACHE_WRITEBACK);
  502. video_set_flush_dcache(dev, true);
  503. uc_priv->xsize = lcd_info.x_res;
  504. uc_priv->ysize = lcd_info.y_res;
  505. uc_priv->bpix = VIDEO_BPP16; /* Uses RGB555 format */
  506. return 0;
  507. }
  508. static int mvebu_video_bind(struct udevice *dev)
  509. {
  510. struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
  511. plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
  512. (1 << LCD_MAX_LOG2_BPP) / 8;
  513. return 0;
  514. }
  515. static const struct udevice_id mvebu_video_ids[] = {
  516. { .compatible = "marvell,armada-xp-lcd" },
  517. { }
  518. };
  519. U_BOOT_DRIVER(mvebu_video) = {
  520. .name = "mvebu_video",
  521. .id = UCLASS_VIDEO,
  522. .of_match = mvebu_video_ids,
  523. .bind = mvebu_video_bind,
  524. .probe = mvebu_video_probe,
  525. .priv_auto_alloc_size = sizeof(struct mvebu_video_priv),
  526. };