lcd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. #include "amt630h.h"
  2. #include "board.h"
  3. #include "lcd.h"
  4. #include "gpio.h"
  5. #include "clock.h"
  6. #include "sysctl.h"
  7. #include "timer.h"
  8. /* LCD timing */
  9. #define LCD_PARAM0 0x000
  10. #define LCD_PARAM1 0x004
  11. #define LCD_PARAM2 0x008
  12. #define LCD_PARAM3 0x00C
  13. #define LCD_PARAM4 0x010
  14. #define LCD_PARAM5 0x014
  15. #define LCD_PARAM6 0x018
  16. #define LCD_PARAM7 0x01C
  17. #define LCD_PARAM8 0x020
  18. #define LCD_PARAM9 0x024
  19. #define LCD_PARAM10 0x028
  20. #define LCD_PARAM11 0x02C
  21. #define LCD_PARAM12 0x030
  22. #define LCD_PARAM13 0x034
  23. #define LCD_PARAM14 0x038
  24. #define LCD_PARAM15 0x03C
  25. #define LCD_PARAM16 0x040
  26. #define LCD_PARAM17 0x044
  27. #define LCD_PARAM18 0x048
  28. #define LCD_PARAM19 0x04C
  29. #define LCD_PARAM20 0x050
  30. #define LCD_PARAM21 0x054
  31. #define LCD_PARAM22 0x058
  32. /* OSD */
  33. #define LCD_OSD0_PARAM0 0x05C
  34. #define LCD_OSD0_PARAM1 0x060
  35. #define LCD_OSD0_PARAM2 0x064
  36. #define LCD_OSD0_PARAM3 0x068
  37. #define LCD_OSD0_PARAM4 0x06C
  38. #define LCD_OSD0_PARAM5 0x070
  39. #define LCD_OSD1_PARAM0 0x074
  40. #define LCD_OSD1_PARAM1 0x078
  41. #define LCD_OSD1_PARAM2 0x07C
  42. #define LCD_OSD1_PARAM3 0x080
  43. #define LCD_OSD1_PARAM4 0x084
  44. #define LCD_OSD1_PARAM5 0x088
  45. #define LCD_OSD01_PARAM 0x08C
  46. #define LCD_OSD_COEF_SYNC 0x090
  47. #define LCD_OSD0_PARAM2_RD 0x280
  48. #define LCD_OSD0_PARAM3_RD 0x284
  49. #define LCD_OSD0_PARAM4_RD 0x288
  50. #define LCD_OSD1_PARAM2_RD 0x28C
  51. #define LCD_OSD1_PARAM3_RD 0x290
  52. #define LCD_OSD1_PARAM4_RD 0x294
  53. /* Dithering */
  54. #define LCD_DITHERING_CFG0 0x0BC
  55. #define LCD_DITHERING_CFG1 0x0C0
  56. #define LCD_DITHERING_CFG2 0x0C4
  57. #define LCD_INTR_CLR 0x0C8
  58. #define LCD_STATUS_REG 0x0CC
  59. #define LCD_R_BIT_ORDER 0x130
  60. #define LCD_G_BIT_ORDER 0x134
  61. #define LCD_B_BIT_ORDER 0x138
  62. #define LCD_GAMMA_REG 0x13c
  63. /* CPU screen & SRGB screen */
  64. #define LCD_SRGB_CFG 0x200
  65. #define LCD_CPU_SCR_SOFT_REG 0x0E0
  66. #define LCD_CPU_SCR_CTRL_REG 0x0E4
  67. #define LCD_ADR_CLR_DATA_REG0 0x0E8
  68. #define LCD_ADR_CLR_DATA_REG1 0x0EC
  69. #define LCD_ADR_CLR_DATA_REG2 0x0F0
  70. #define LCD_ADR_CLR_DATA_REG3 0x0F4
  71. #define LCD_ADR_CLR_DATA_REG4 0x0F8
  72. #define LCD_ADR_CLR_DATA_REG5 0x0FC
  73. #define LCD_ADR_CLR_DATA_REG6 0x100
  74. #define LCD_ADR_CLR_DATA_REG7 0x104
  75. #define LCD_ADR_CLR_DATA_REG8 0x108
  76. #define LCD_ADR_CLR_DATA_REG9 0x10C
  77. #define LCD_ADR_CLR_DATA_REGA 0x110
  78. #define LCD_ADR_CLR_DATA_REGB 0x114
  79. #define LCD_ADR_CLR_DATA_REGC 0x118
  80. #define LCD_ADR_CLR_DATA_REGD 0x11C
  81. #define LCD_ADR_CLR_DATA_REGE 0x120
  82. #define LCD_ADR_CLR_DATA_REGF 0x124
  83. #define LCD_CPU_SCREEN_STATUS 0x128
  84. #define LCD_OSD_CCM_REG0 0x208
  85. #define LCD_OSD_CCM_REG1 0x20C
  86. #define LCD_OSD_CCM_REG2 0x210
  87. #define LCD_OSD_CCM_REG3 0x214
  88. #define LCD_OSD_CCM_REG4 0x218
  89. #define LCD_OSD_CCM_REG5 0x21C
  90. #define LCD_CCM_EN_REG0 0x238
  91. #define LCD_CCM_EN_REG1 0x23C
  92. #define LCD_CCM_EN_REG2 0x240
  93. #define LCD_CCM_EN_REG3 0x244
  94. #define LCD_CCM_EN_REG4 0x248
  95. #define LCD_CCM_EN_REG5 0x24C
  96. #define LCD_CCM_EN_REG 0x250
  97. #define LCD_ITU_EAV_CODE_CFG 0x254
  98. #define LCD_ITU_SAV_CODE_CFG 0x258
  99. #define LCD_HLOCK_CFG_RG 0x25C
  100. static uint32_t fb_addr = 0;
  101. struct ark_lcd_timing
  102. {
  103. uint32_t vs_start;
  104. uint32_t hs_start;
  105. uint32_t hd; //width
  106. uint32_t vd; //height
  107. uint32_t vbp;
  108. uint32_t vfp;
  109. uint32_t vsw;
  110. uint32_t hbp;
  111. uint32_t hfp;
  112. uint32_t hsw;
  113. };
  114. static void ark_lcd_writel(uint32_t reg, uint32_t mask, uint8_t offset, uint32_t val)
  115. {
  116. uint32_t tmp = readl(REGS_LCD_BASE+reg);
  117. tmp &= (~(mask << offset));
  118. tmp |= (val << offset);
  119. writel(tmp, REGS_LCD_BASE+reg);
  120. }
  121. int ark_lcd_set_osd_sync(LCD_OSD_LAYER osd)
  122. {
  123. if(osd >= LCD_OSD_NUMS) {
  124. return -1;
  125. }
  126. if(osd == LCD_OSD0)
  127. writel(readl(REGS_LCD_BASE+LCD_OSD_COEF_SYNC)|(1<<0), REGS_LCD_BASE+LCD_OSD_COEF_SYNC);
  128. else if(osd == LCD_OSD1)
  129. writel(readl(REGS_LCD_BASE+LCD_OSD_COEF_SYNC)|(1<<1), REGS_LCD_BASE+LCD_OSD_COEF_SYNC);
  130. else if(osd == LCD_OSD_NUMS)
  131. writel(readl(REGS_LCD_BASE+LCD_OSD_COEF_SYNC)|(3<<0), REGS_LCD_BASE+LCD_OSD_COEF_SYNC);
  132. return 0;
  133. }
  134. static int ark_lcd_set_osd_stride(LCD_OSD_LAYER osd, uint32_t width)
  135. {
  136. uint32_t reg = LCD_OSD0_PARAM5 + osd*0x18;
  137. if(osd >= LCD_OSD_NUMS) {
  138. return -1;
  139. }
  140. if(width > 0xFFF) {
  141. return -1;
  142. }
  143. ark_lcd_writel(reg, 0xFFF, 0, width);
  144. return 0;
  145. }
  146. int ark_lcd_get_osd_size(LCD_OSD_LAYER osd, uint32_t *width, uint32_t *height)
  147. {
  148. uint32_t reg = LCD_OSD0_PARAM0 + osd*0x18;
  149. uint32_t val;
  150. if(osd>= LCD_OSD_NUMS) {
  151. return -1;
  152. }
  153. val = readl(REGS_LCD_BASE+reg);
  154. *width = (val >> 6) & 0xFFF;
  155. *height = (val >> 18) & 0xFFF;
  156. return 0;
  157. }
  158. int ark_lcd_set_osd_size(LCD_OSD_LAYER osd, uint32_t width, uint32_t height)
  159. {
  160. uint32_t reg = LCD_OSD0_PARAM0 + osd*0x18;
  161. if(osd>= LCD_OSD_NUMS) {
  162. return -1;
  163. }
  164. width &= 0xFFF;
  165. height &= 0xFFF;
  166. ark_lcd_writel(reg, 0xFFFFFF, 6, (height<<12)|width);
  167. ark_lcd_set_osd_stride(osd, width);
  168. return 0;
  169. }
  170. int ark_lcd_set_osd_format(LCD_OSD_LAYER osd, LCD_OSD_FORMAT format)
  171. {
  172. uint32_t reg = LCD_OSD0_PARAM0 + osd*0x18;
  173. if(osd >= LCD_OSD_NUMS) {
  174. return -1;
  175. }
  176. if(format >= LCD_OSD_FORAMT_NUMS) {
  177. return -1;
  178. }
  179. ark_lcd_writel(reg, 0x7, 3, format);
  180. return 0;
  181. }
  182. int ark_lcd_osd_enable(LCD_OSD_LAYER osd, uint8_t enable)
  183. {
  184. uint32_t reg = LCD_OSD0_PARAM0 + osd*0x18;
  185. if(osd >= LCD_OSD_NUMS) {
  186. return -1;
  187. }
  188. ark_lcd_writel(reg, 0x1, 1, (enable?1:0));
  189. return 0;
  190. }
  191. int ark_lcd_osd_coeff_enable(LCD_OSD_LAYER osd, uint8_t enable)
  192. {
  193. uint32_t reg = LCD_OSD0_PARAM0 + osd*0x18;
  194. if(osd >= LCD_OSD_NUMS) {
  195. return -1;
  196. }
  197. ark_lcd_writel(reg, 0x0, 1, (enable?1:0));
  198. return 0;
  199. }
  200. int ark_lcd_osd_set_coeff(LCD_OSD_LAYER osd, uint32_t value)
  201. {
  202. uint32_t reg = LCD_OSD0_PARAM1 + osd*0x18;
  203. if(osd >= LCD_OSD_NUMS) {
  204. return -1;
  205. }
  206. ark_lcd_writel(reg, 0xFF, 24, value);
  207. return 0;
  208. }
  209. int ark_lcd_set_osd_possition(LCD_OSD_LAYER osd, uint32_t h, uint32_t v)
  210. {
  211. uint32_t reg = LCD_OSD0_PARAM1 + osd*0x18;
  212. if(osd >= LCD_OSD_NUMS) {
  213. return -1;
  214. }
  215. if((v > 0xFFF) || (h > 0xFFF)) {
  216. return -1;
  217. }
  218. ark_lcd_writel(reg, 0xFFFFFF, 0, ((v<<12)|h));
  219. return 0;
  220. }
  221. int ark_lcd_get_osd_yaddr(LCD_OSD_LAYER osd, uint32_t *yaddr)
  222. {
  223. uint32_t reg = LCD_OSD0_PARAM2 + osd*0x18;
  224. if(osd >= LCD_OSD_NUMS) {
  225. return -1;
  226. }
  227. *yaddr = readl(REGS_LCD_BASE+reg);
  228. return 0;
  229. }
  230. int ark_lcd_set_osd_yaddr(LCD_OSD_LAYER osd, uint32_t yaddr)
  231. {
  232. uint32_t reg = LCD_OSD0_PARAM2 + osd*0x18;
  233. if(osd >= LCD_OSD_NUMS) {
  234. return -1;
  235. }
  236. writel(yaddr, REGS_LCD_BASE+reg);
  237. return 0;
  238. }
  239. int ark_lcd_set_osd_uaddr(LCD_OSD_LAYER osd, uint32_t uaddr)
  240. {
  241. uint32_t reg = LCD_OSD0_PARAM3 + osd*0x18;
  242. if(osd >= LCD_OSD_NUMS) {
  243. return -1;
  244. }
  245. writel(uaddr, REGS_LCD_BASE+reg);
  246. return 0;
  247. }
  248. int ark_lcd_set_osd_vaddr(LCD_OSD_LAYER osd, uint32_t vaddr)
  249. {
  250. uint32_t reg = LCD_OSD0_PARAM4 + osd*0x18;
  251. if(osd >= LCD_OSD_NUMS) {
  252. return -1;
  253. }
  254. writel(vaddr, REGS_LCD_BASE+reg);
  255. return 0;
  256. }
  257. int ark_lcd_set_osd_mult_coef(LCD_OSD_LAYER osd, uint32_t value)
  258. {
  259. uint32_t reg = LCD_OSD0_PARAM5 + osd*0x18;
  260. if(osd >= LCD_OSD_NUMS) {
  261. return -1;
  262. }
  263. if(value > 0x7F) {
  264. return -1;
  265. }
  266. ark_lcd_writel(reg, 0x7F, 24, value);
  267. return 0;
  268. }
  269. int ark_lcd_set_osd_h_offset(LCD_OSD_LAYER osd, uint32_t offset)
  270. {
  271. uint32_t reg = LCD_OSD0_PARAM5 + osd*0x18;
  272. if(osd >= LCD_OSD_NUMS) {
  273. return -1;
  274. }
  275. if(offset > 0xFFF) {
  276. return -1;
  277. }
  278. ark_lcd_writel(reg, 0xFFF, 12, offset);
  279. return 0;
  280. }
  281. int ark_lcd_set_osd_yuv420_mode(LCD_OSD_LAYER osd, LCD_OSD_YUV420_MODE mode)
  282. {
  283. uint32_t reg = LCD_OSD01_PARAM;
  284. if(osd >= LCD_OSD_NUMS) {
  285. return -1;
  286. }
  287. if(mode > LCD_OSD_Y_UV420) {
  288. return -1;
  289. }
  290. if (osd == LCD_OSD0)
  291. ark_lcd_writel(reg, 0x1, 12, mode);
  292. else
  293. ark_lcd_writel(reg, 0x1, 14, mode);
  294. return 0;
  295. }
  296. int ark_lcd_enable(uint8_t enable)
  297. {
  298. ark_lcd_writel(LCD_PARAM0, 0x01, 0, (enable?1:0));
  299. return 0;
  300. }
  301. static int ark_lcd_timing_init(struct ark_lcd_timing *timing)
  302. {
  303. uint32_t VS_START, HS_START, HD, VD;
  304. uint32_t VBP, VFP, VSW, TV;
  305. uint32_t HBP, HFP, HSW, TH;
  306. uint32_t lcd_param0, lcd_param1, lcd_param2, lcd_param3 ;
  307. uint32_t lcd_param4, lcd_param5, lcd_param6, lcd_param7 ;
  308. uint32_t lcd_param8, lcd_param9, lcd_param10, lcd_param11 ;
  309. uint32_t lcd_param12, lcd_param13, lcd_param14, lcd_param15 ;
  310. uint32_t lcd_param16, lcd_param17;
  311. uint8_t stop_lcd = 0 ;
  312. VS_START = timing->vs_start;
  313. HS_START = timing->hs_start;
  314. HD = timing->hd;
  315. VD = timing->vd;
  316. VBP = timing->vbp;
  317. VFP = timing->vfp;
  318. VSW = timing->vsw;
  319. TV =(VS_START+VSW+VBP+VD+VFP);
  320. HBP = timing->hbp;
  321. HFP = timing->hfp;
  322. HSW = timing->hsw;
  323. TH = (HS_START+HSW+HBP+HD+HFP);
  324. #define lcd_enable 0 // 1
  325. #define screen_width HD
  326. #define rgb_pad_mode LCD_WIRING_MODE
  327. #define direct_enable 0
  328. #define mem_lcd_enable 0
  329. #define range_coeff_y 0
  330. #define range_coeff_uv 0
  331. #define lcd_done_intr_enable 1
  332. #define dac_for_video 0
  333. #define dac_for_cvbs 0
  334. #define lcd_interlace_flag 0
  335. #define screen_type 1 //pRGB_i 0 pRGB_p 1 sRGB_p 2 ITU656 3
  336. #define VSW1_enable 0
  337. #define LcdVComp 0
  338. #define itu_pal_ntsc 0
  339. #define hsync_ivs 1
  340. #define vsync_ivs 1
  341. #define lcd_ac_ivs 0
  342. #define test_on_flag 0
  343. #define back_color (0x00<<16)|(0x00<<8)|(0x00)
  344. #define DEN_h_rise (HFP+HSW+HBP)
  345. #define DEN_h_fall (HFP+HSW+HBP+HD)//(20+800*1)
  346. #define DEN0_v_rise (VFP+VSW+VBP)
  347. #define DEN0_v_fall (VFP+VSW+VBP+VD)
  348. #define DEN1_v_rise (VFP+VSW+VBP)
  349. #define DEN1_v_fall (VFP+VSW+VBP+VD)
  350. // 帧频 = LCD时钟/(CPL * LPS)
  351. // 每行时钟周期个数
  352. #define CPL (TH) // clock cycles per line max 4096 ; from register timing2 16
  353. #define LPS (TV) // Lines per screen value ; from register timing1 0
  354. #define HSW_rise (HFP)
  355. #define HSW_fall (HFP+HSW)
  356. #define VSW0_v_rise (VFP) // Vertical sync width value ; from register timing1 10
  357. #define VSW0_v_fall (VFP+VFP) // Vertical sync width value ; from register timing1 10
  358. #define VSW0_h_rise (HFP)
  359. #define VSW0_h_fall (HFP+HSW)
  360. #define VSW1_v_rise (VFP) // Vertical sync width value ; from register timing1 10
  361. #define VSW1_v_fall (VFP+VSW) // Vertical sync width value ; from register timing1 10
  362. #define VSW1_h_rise (HFP)
  363. #define VSW1_h_fall (HFP+HSW)
  364. writel(0, REGS_LCD_BASE+LCD_PARAM0);
  365. lcd_param0 =
  366. lcd_enable |
  367. (screen_width<<1) |
  368. (rgb_pad_mode<<13) |
  369. (direct_enable<<16) |
  370. (mem_lcd_enable<<17)|
  371. (range_coeff_y<<18) |
  372. (range_coeff_uv<<22)|
  373. (lcd_done_intr_enable<<26)|
  374. (dac_for_video<<27) |
  375. (dac_for_cvbs<<28) |
  376. (1<<30) |
  377. (stop_lcd<<31);
  378. lcd_param1 =
  379. (lcd_interlace_flag<<0) |
  380. (screen_type<<1) |
  381. (VSW1_enable<<13) |
  382. (LcdVComp<<14) |
  383. (itu_pal_ntsc<<15) |
  384. (hsync_ivs<<17) |
  385. (vsync_ivs<<18) |
  386. (lcd_ac_ivs<<19) |
  387. (1<<21) |
  388. (1<<23) |
  389. (test_on_flag<<31);
  390. lcd_param2 =
  391. (back_color<<0) |
  392. (1<<24) |
  393. (1<<25);
  394. lcd_param3 =
  395. (DEN_h_rise<<0) |
  396. (DEN_h_fall<<12) ;
  397. lcd_param4 =
  398. (DEN0_v_rise<<0) |
  399. (DEN0_v_fall<<12) ;
  400. lcd_param5 =
  401. (DEN1_v_rise<<0) |
  402. (DEN1_v_fall<<12 ) ;
  403. lcd_param6 =
  404. (CPL<<0) | // clock cycles per line max 4096 ; from register timing2 16
  405. (LPS<<12) ; // Lines per screen value ; from register timing1 0
  406. lcd_param7 =
  407. (HSW_rise<<0)|
  408. (HSW_fall<<12) ;
  409. lcd_param8 =
  410. (VSW0_v_rise<<0)| // Vertical sync width value ; from register timing1 10
  411. (VSW0_v_fall<<12) ; // Vertical sync width value ; from register timing1 10
  412. lcd_param9 =
  413. (VSW0_h_rise <<0 )|
  414. (VSW0_h_fall <<12 ) ;
  415. lcd_param10 =
  416. (VSW1_v_rise<<0)|
  417. (VSW1_v_fall<<12) ;
  418. lcd_param11 =
  419. (VSW1_h_rise<<0)|
  420. (VSW1_h_fall<<12) ;
  421. lcd_param12 = 66 | (129<<9) | (25<<18);
  422. lcd_param13 = 38 | (74<<9) | (112<<18);
  423. lcd_param14 = 112 | (94<<9) | (18<<18);
  424. lcd_param15 = 256 | (0<<9) | (351<<18);
  425. lcd_param16 = 256 | (86<<9) | (179<<18);
  426. lcd_param17 = 256 | (443<<10) | (0<<19);
  427. writel(lcd_param1, REGS_LCD_BASE+LCD_PARAM1);
  428. writel(lcd_param2, REGS_LCD_BASE+LCD_PARAM2);
  429. writel(lcd_param3, REGS_LCD_BASE+LCD_PARAM3);
  430. writel(lcd_param4, REGS_LCD_BASE+LCD_PARAM4);
  431. writel(lcd_param5, REGS_LCD_BASE+LCD_PARAM5);
  432. writel(lcd_param6, REGS_LCD_BASE+LCD_PARAM6);
  433. writel(lcd_param7, REGS_LCD_BASE+LCD_PARAM7);
  434. writel(lcd_param8, REGS_LCD_BASE+LCD_PARAM8);
  435. writel(lcd_param9, REGS_LCD_BASE+LCD_PARAM9);
  436. writel(lcd_param10, REGS_LCD_BASE+LCD_PARAM10);
  437. writel(lcd_param11, REGS_LCD_BASE+LCD_PARAM11);
  438. writel(lcd_param12, REGS_LCD_BASE+LCD_PARAM12);
  439. writel(lcd_param13, REGS_LCD_BASE+LCD_PARAM13);
  440. writel(lcd_param14, REGS_LCD_BASE+LCD_PARAM14);
  441. writel(lcd_param15, REGS_LCD_BASE+LCD_PARAM15);
  442. writel(lcd_param16, REGS_LCD_BASE+LCD_PARAM16);
  443. writel(lcd_param17, REGS_LCD_BASE+LCD_PARAM17);
  444. writel(lcd_param0, REGS_LCD_BASE+LCD_PARAM0);
  445. #if LCD_WIRING_BIT_ORDER == LCD_WIRING_BIT_ORDER_LSB
  446. writel((0<<21|1<<18|2<<15|3<<12|4<<9|5<<6|6<<3|7<<0), REGS_LCD_BASE+LCD_R_BIT_ORDER);
  447. writel((0<<21|1<<18|2<<15|3<<12|4<<9|5<<6|6<<3|7<<0), REGS_LCD_BASE+LCD_G_BIT_ORDER);
  448. writel((0<<21|1<<18|2<<15|3<<12|4<<9|5<<6|6<<3|7<<0), REGS_LCD_BASE+LCD_B_BIT_ORDER);
  449. #elif LCD_WIRING_BIT_ORDER == LCD_WIRING_BIT_ORDER_MSB
  450. writel((7<<21|6<<18|5<<15|4<<12|3<<9|2<<6|1<<3|0<<0), REGS_LCD_BASE+LCD_R_BIT_ORDER);
  451. writel((7<<21|6<<18|5<<15|4<<12|3<<9|2<<6|1<<3|0<<0), REGS_LCD_BASE+LCD_G_BIT_ORDER);
  452. writel((7<<21|6<<18|5<<15|4<<12|3<<9|2<<6|1<<3|0<<0), REGS_LCD_BASE+LCD_B_BIT_ORDER);
  453. #endif
  454. return 0;
  455. }
  456. static int ark_lcd_hw_init()
  457. {
  458. uint32_t HD, VD;
  459. HD = LCD_WIDTH;
  460. VD = LCD_HEIGHT;
  461. uint8_t osd_0_hflip = 0;
  462. uint8_t osd_0_vflip = 0;
  463. uint8_t osd_0_uvfirst = 0;
  464. uint8_t osd_0_yuv420mode = 1;
  465. //uint8_t osd_0_yuv422mode = 0;
  466. uint8_t osd_1_hflip = 0;
  467. uint8_t osd_1_vflip = 0;
  468. uint32_t osd_01_param =
  469. //osd_0_yuv422mode<<20|
  470. osd_0_hflip<<16|
  471. osd_0_vflip<<17|
  472. osd_1_hflip<<18|
  473. osd_1_vflip<<19|
  474. osd_0_yuv420mode<<12|
  475. osd_0_uvfirst<<13;
  476. writel(osd_01_param, REGS_LCD_BASE+LCD_OSD01_PARAM);
  477. //osd0 init
  478. ark_lcd_set_osd_size(LCD_OSD0, HD, VD);
  479. ark_lcd_set_osd_format(LCD_OSD0, LCD_OSD_FORAMT_YUV420);
  480. ark_lcd_set_osd_possition(LCD_OSD0, 0, 0);
  481. ark_lcd_set_osd_yaddr(LCD_OSD0, fb_addr);
  482. ark_lcd_set_osd_uaddr(LCD_OSD0, fb_addr + HD * VD);
  483. ark_lcd_set_osd_vaddr(LCD_OSD0, fb_addr + HD * VD);
  484. ark_lcd_set_osd_h_offset(LCD_OSD0, 0);
  485. ark_lcd_set_osd_mult_coef(LCD_OSD0, 64);
  486. ark_lcd_osd_enable(LCD_OSD0, 0);
  487. ark_lcd_set_osd_sync(LCD_OSD0);
  488. //osd1 init
  489. ark_lcd_set_osd_size(LCD_OSD1, HD, VD);
  490. #if LCD_BPP == 32
  491. ark_lcd_set_osd_format(LCD_OSD1, LCD_OSD_FORAMT_ARGB888);
  492. ark_lcd_osd_coeff_enable(LCD_OSD1, 0);
  493. #elif LCD_BPP == 16
  494. ark_lcd_set_osd_format(LCD_OSD1, LCD_OSD_FORAMT_RGB565);
  495. ark_lcd_osd_coeff_enable(LCD_OSD1, 1);
  496. ark_lcd_osd_set_coeff(LCD_OSD1, 255);
  497. #endif
  498. ark_lcd_set_osd_possition(LCD_OSD1, 0, 0);
  499. ark_lcd_set_osd_h_offset(LCD_OSD1, 0);
  500. ark_lcd_set_osd_mult_coef(LCD_OSD1, 64);
  501. ark_lcd_set_osd_yaddr(LCD_OSD1, fb_addr);
  502. ark_lcd_osd_enable(LCD_OSD1, 0);
  503. ark_lcd_set_osd_sync(LCD_OSD1);
  504. ark_lcd_enable(1);
  505. return 0;
  506. }
  507. static int ark_lcd_clk_init(uint32_t freq)
  508. {
  509. vClkSetRate(CLK_LCD, freq);
  510. return 0;
  511. }
  512. #if LCD_INTERFACE_TYPE == LCD_INTERFACE_LVDS
  513. static void lvds_screen_reset(void)
  514. {
  515. gpio_direction_output(LVDS_SCREEN_RST_GPIO, 0);
  516. udelay(100);
  517. gpio_direction_output(LVDS_SCREEN_RST_GPIO, 1);
  518. mdelay(20);
  519. }
  520. #endif
  521. int lcd_init(void)
  522. {
  523. struct ark_lcd_timing timing;
  524. int ret = 0;
  525. /* lcd pad select */
  526. #if LCD_INTERFACE_TYPE == LCD_INTERFACE_TTL
  527. vSysctlConfigure(SYS_PAD_CTRL04, 0, 0xffffffff, 0x55555555);
  528. vSysctlConfigure(SYS_PAD_CTRL05, 0, 0xffffff, 0x555555);
  529. #elif LCD_INTERFACE_TYPE == LCD_INTERFACE_LVDS
  530. vSysctlConfigure(SYS_PAD_CTRL04, 0, 0xfffff, 0xaaaaa);
  531. #endif
  532. /* lcd timing init */
  533. timing.vs_start = 0;
  534. timing.hs_start = 0;
  535. timing.hd = LCD_WIDTH;
  536. timing.vd = LCD_HEIGHT;
  537. timing.vbp = LCD_TIMING_VBP;
  538. timing.vfp = LCD_TIMING_VFP;
  539. timing.vsw = LCD_TIMING_VSW;
  540. timing.hbp = LCD_TIMING_HBP;
  541. timing.hfp = LCD_TIMING_HFP;
  542. timing.hsw = LCD_TIMING_HSW;
  543. ark_lcd_clk_init(LCD_CLK_FREQ);
  544. #if LCD_INTERFACE_TYPE == LCD_INTERFACE_LVDS
  545. uint32_t lvds_cfg = 0xe0ec;
  546. #if LVDS_PANEL_FORMAT == LVDS_PANEL_FORMAT_TI
  547. lvds_cfg |= (1 << 16);
  548. #endif
  549. #if LVDS_PANEL_DATA == LVDS_PANEL_DATA_8BIT
  550. lvds_cfg &= ~(1 << 15);
  551. lvds_cfg |= (1 << 4) | 1;
  552. #endif
  553. writel(lvds_cfg, REGS_SYSCTL_BASE + SYS_ANA3_CFG);
  554. lvds_screen_reset();
  555. #endif
  556. ark_lcd_timing_init(&timing);
  557. ark_lcd_hw_init();
  558. return ret;
  559. }