mx3fb.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /*
  2. * Copyright (C) 2009
  3. * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <lcd.h>
  25. #include <asm/arch/mx31.h>
  26. #include <asm/arch/mx31-regs.h>
  27. #include <asm/errno.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. void *lcd_base; /* Start of framebuffer memory */
  30. void *lcd_console_address; /* Start of console buffer */
  31. int lcd_line_length;
  32. int lcd_color_fg;
  33. int lcd_color_bg;
  34. short console_col;
  35. short console_row;
  36. void lcd_initcolregs(void)
  37. {
  38. }
  39. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
  40. {
  41. }
  42. void lcd_disable(void)
  43. {
  44. }
  45. void lcd_panel_disable(void)
  46. {
  47. }
  48. #define msleep(a) udelay(a * 1000)
  49. #if defined(CONFIG_DISPLAY_VBEST_VGG322403)
  50. #define XRES 320
  51. #define YRES 240
  52. #define PANEL_TYPE IPU_PANEL_TFT
  53. #define PIXEL_CLK 156000
  54. #define PIXEL_FMT IPU_PIX_FMT_RGB666
  55. #define H_START_WIDTH 20 /* left_margin */
  56. #define H_SYNC_WIDTH 30 /* hsync_len */
  57. #define H_END_WIDTH (38 + 30) /* right_margin + hsync_len */
  58. #define V_START_WIDTH 7 /* upper_margin */
  59. #define V_SYNC_WIDTH 3 /* vsync_len */
  60. #define V_END_WIDTH (26 + 3) /* lower_margin + vsync_len */
  61. #define SIG_POL (DI_D3_DRDY_SHARP_POL | DI_D3_CLK_POL)
  62. #define IF_CONF 0
  63. #define IF_CLK_DIV 0x175
  64. #elif defined(CONFIG_DISPLAY_COM57H5M10XRC)
  65. #define XRES 640
  66. #define YRES 480
  67. #define PANEL_TYPE IPU_PANEL_TFT
  68. #define PIXEL_CLK 40000
  69. #define PIXEL_FMT IPU_PIX_FMT_RGB666
  70. #define H_START_WIDTH 120 /* left_margin */
  71. #define H_SYNC_WIDTH 30 /* hsync_len */
  72. #define H_END_WIDTH (10 + 30) /* right_margin + hsync_len */
  73. #define V_START_WIDTH 35 /* upper_margin */
  74. #define V_SYNC_WIDTH 3 /* vsync_len */
  75. #define V_END_WIDTH (7 + 3) /* lower_margin + vsync_len */
  76. #define SIG_POL (DI_D3_DRDY_SHARP_POL | DI_D3_CLK_POL)
  77. #define IF_CONF 0
  78. #define IF_CLK_DIV 0x175
  79. #else
  80. #define XRES 240
  81. #define YRES 320
  82. #define PANEL_TYPE IPU_PANEL_TFT
  83. #define PIXEL_CLK 185925
  84. #define PIXEL_FMT IPU_PIX_FMT_RGB666
  85. #define H_START_WIDTH 9 /* left_margin */
  86. #define H_SYNC_WIDTH 1 /* hsync_len */
  87. #define H_END_WIDTH (16 + 1) /* right_margin + hsync_len */
  88. #define V_START_WIDTH 7 /* upper_margin */
  89. #define V_SYNC_WIDTH 1 /* vsync_len */
  90. #define V_END_WIDTH (9 + 1) /* lower_margin + vsync_len */
  91. #define SIG_POL (DI_D3_DRDY_SHARP_POL | DI_D3_CLK_POL)
  92. #define IF_CONF 0
  93. #define IF_CLK_DIV 0x175
  94. #endif
  95. #define LCD_COLOR_IPU LCD_COLOR16
  96. static ushort colormap[256];
  97. vidinfo_t panel_info = {
  98. .vl_col = XRES,
  99. .vl_row = YRES,
  100. .vl_bpix = LCD_COLOR_IPU,
  101. .cmap = colormap,
  102. };
  103. #define BIT_PER_PIXEL NBITS(LCD_COLOR_IPU)
  104. /* IPU DMA Controller channel definitions. */
  105. enum ipu_channel {
  106. IDMAC_IC_0 = 0, /* IC (encoding task) to memory */
  107. IDMAC_IC_1 = 1, /* IC (viewfinder task) to memory */
  108. IDMAC_ADC_0 = 1,
  109. IDMAC_IC_2 = 2,
  110. IDMAC_ADC_1 = 2,
  111. IDMAC_IC_3 = 3,
  112. IDMAC_IC_4 = 4,
  113. IDMAC_IC_5 = 5,
  114. IDMAC_IC_6 = 6,
  115. IDMAC_IC_7 = 7, /* IC (sensor data) to memory */
  116. IDMAC_IC_8 = 8,
  117. IDMAC_IC_9 = 9,
  118. IDMAC_IC_10 = 10,
  119. IDMAC_IC_11 = 11,
  120. IDMAC_IC_12 = 12,
  121. IDMAC_IC_13 = 13,
  122. IDMAC_SDC_0 = 14, /* Background synchronous display data */
  123. IDMAC_SDC_1 = 15, /* Foreground data (overlay) */
  124. IDMAC_SDC_2 = 16,
  125. IDMAC_SDC_3 = 17,
  126. IDMAC_ADC_2 = 18,
  127. IDMAC_ADC_3 = 19,
  128. IDMAC_ADC_4 = 20,
  129. IDMAC_ADC_5 = 21,
  130. IDMAC_ADC_6 = 22,
  131. IDMAC_ADC_7 = 23,
  132. IDMAC_PF_0 = 24,
  133. IDMAC_PF_1 = 25,
  134. IDMAC_PF_2 = 26,
  135. IDMAC_PF_3 = 27,
  136. IDMAC_PF_4 = 28,
  137. IDMAC_PF_5 = 29,
  138. IDMAC_PF_6 = 30,
  139. IDMAC_PF_7 = 31,
  140. };
  141. /* More formats can be copied from the Linux driver if needed */
  142. enum pixel_fmt {
  143. /* 2 bytes */
  144. IPU_PIX_FMT_RGB565,
  145. IPU_PIX_FMT_RGB666,
  146. IPU_PIX_FMT_BGR666,
  147. /* 3 bytes */
  148. IPU_PIX_FMT_RGB24,
  149. };
  150. struct pixel_fmt_cfg {
  151. u32 b0;
  152. u32 b1;
  153. u32 b2;
  154. u32 acc;
  155. };
  156. static struct pixel_fmt_cfg fmt_cfg[] = {
  157. [IPU_PIX_FMT_RGB24] = {
  158. 0x1600AAAA, 0x00E05555, 0x00070000, 3,
  159. },
  160. [IPU_PIX_FMT_RGB666] = {
  161. 0x0005000F, 0x000B000F, 0x0011000F, 1,
  162. },
  163. [IPU_PIX_FMT_BGR666] = {
  164. 0x0011000F, 0x000B000F, 0x0005000F, 1,
  165. },
  166. [IPU_PIX_FMT_RGB565] = {
  167. 0x0004003F, 0x000A000F, 0x000F003F, 1,
  168. }
  169. };
  170. enum ipu_panel {
  171. IPU_PANEL_SHARP_TFT,
  172. IPU_PANEL_TFT,
  173. };
  174. /* IPU Common registers */
  175. /* IPU_CONF and its bits already defined in mx31-regs.h */
  176. #define IPU_CHA_BUF0_RDY (0x04 + IPU_BASE)
  177. #define IPU_CHA_BUF1_RDY (0x08 + IPU_BASE)
  178. #define IPU_CHA_DB_MODE_SEL (0x0C + IPU_BASE)
  179. #define IPU_CHA_CUR_BUF (0x10 + IPU_BASE)
  180. #define IPU_FS_PROC_FLOW (0x14 + IPU_BASE)
  181. #define IPU_FS_DISP_FLOW (0x18 + IPU_BASE)
  182. #define IPU_TASKS_STAT (0x1C + IPU_BASE)
  183. #define IPU_IMA_ADDR (0x20 + IPU_BASE)
  184. #define IPU_IMA_DATA (0x24 + IPU_BASE)
  185. #define IPU_INT_CTRL_1 (0x28 + IPU_BASE)
  186. #define IPU_INT_CTRL_2 (0x2C + IPU_BASE)
  187. #define IPU_INT_CTRL_3 (0x30 + IPU_BASE)
  188. #define IPU_INT_CTRL_4 (0x34 + IPU_BASE)
  189. #define IPU_INT_CTRL_5 (0x38 + IPU_BASE)
  190. #define IPU_INT_STAT_1 (0x3C + IPU_BASE)
  191. #define IPU_INT_STAT_2 (0x40 + IPU_BASE)
  192. #define IPU_INT_STAT_3 (0x44 + IPU_BASE)
  193. #define IPU_INT_STAT_4 (0x48 + IPU_BASE)
  194. #define IPU_INT_STAT_5 (0x4C + IPU_BASE)
  195. #define IPU_BRK_CTRL_1 (0x50 + IPU_BASE)
  196. #define IPU_BRK_CTRL_2 (0x54 + IPU_BASE)
  197. #define IPU_BRK_STAT (0x58 + IPU_BASE)
  198. #define IPU_DIAGB_CTRL (0x5C + IPU_BASE)
  199. /* Image Converter Registers */
  200. #define IC_CONF (0x88 + IPU_BASE)
  201. #define IC_PRP_ENC_RSC (0x8C + IPU_BASE)
  202. #define IC_PRP_VF_RSC (0x90 + IPU_BASE)
  203. #define IC_PP_RSC (0x94 + IPU_BASE)
  204. #define IC_CMBP_1 (0x98 + IPU_BASE)
  205. #define IC_CMBP_2 (0x9C + IPU_BASE)
  206. #define PF_CONF (0xA0 + IPU_BASE)
  207. #define IDMAC_CONF (0xA4 + IPU_BASE)
  208. #define IDMAC_CHA_EN (0xA8 + IPU_BASE)
  209. #define IDMAC_CHA_PRI (0xAC + IPU_BASE)
  210. #define IDMAC_CHA_BUSY (0xB0 + IPU_BASE)
  211. /* Image Converter Register bits */
  212. #define IC_CONF_PRPENC_EN 0x00000001
  213. #define IC_CONF_PRPENC_CSC1 0x00000002
  214. #define IC_CONF_PRPENC_ROT_EN 0x00000004
  215. #define IC_CONF_PRPVF_EN 0x00000100
  216. #define IC_CONF_PRPVF_CSC1 0x00000200
  217. #define IC_CONF_PRPVF_CSC2 0x00000400
  218. #define IC_CONF_PRPVF_CMB 0x00000800
  219. #define IC_CONF_PRPVF_ROT_EN 0x00001000
  220. #define IC_CONF_PP_EN 0x00010000
  221. #define IC_CONF_PP_CSC1 0x00020000
  222. #define IC_CONF_PP_CSC2 0x00040000
  223. #define IC_CONF_PP_CMB 0x00080000
  224. #define IC_CONF_PP_ROT_EN 0x00100000
  225. #define IC_CONF_IC_GLB_LOC_A 0x10000000
  226. #define IC_CONF_KEY_COLOR_EN 0x20000000
  227. #define IC_CONF_RWS_EN 0x40000000
  228. #define IC_CONF_CSI_MEM_WR_EN 0x80000000
  229. /* SDC Registers */
  230. #define SDC_COM_CONF (0xB4 + IPU_BASE)
  231. #define SDC_GW_CTRL (0xB8 + IPU_BASE)
  232. #define SDC_FG_POS (0xBC + IPU_BASE)
  233. #define SDC_BG_POS (0xC0 + IPU_BASE)
  234. #define SDC_CUR_POS (0xC4 + IPU_BASE)
  235. #define SDC_PWM_CTRL (0xC8 + IPU_BASE)
  236. #define SDC_CUR_MAP (0xCC + IPU_BASE)
  237. #define SDC_HOR_CONF (0xD0 + IPU_BASE)
  238. #define SDC_VER_CONF (0xD4 + IPU_BASE)
  239. #define SDC_SHARP_CONF_1 (0xD8 + IPU_BASE)
  240. #define SDC_SHARP_CONF_2 (0xDC + IPU_BASE)
  241. /* Register bits */
  242. #define SDC_COM_TFT_COLOR 0x00000001UL
  243. #define SDC_COM_FG_EN 0x00000010UL
  244. #define SDC_COM_GWSEL 0x00000020UL
  245. #define SDC_COM_GLB_A 0x00000040UL
  246. #define SDC_COM_KEY_COLOR_G 0x00000080UL
  247. #define SDC_COM_BG_EN 0x00000200UL
  248. #define SDC_COM_SHARP 0x00001000UL
  249. #define SDC_V_SYNC_WIDTH_L 0x00000001UL
  250. /* Display Interface registers */
  251. #define DI_DISP_IF_CONF (0x0124 + IPU_BASE)
  252. #define DI_DISP_SIG_POL (0x0128 + IPU_BASE)
  253. #define DI_SER_DISP1_CONF (0x012C + IPU_BASE)
  254. #define DI_SER_DISP2_CONF (0x0130 + IPU_BASE)
  255. #define DI_HSP_CLK_PER (0x0134 + IPU_BASE)
  256. #define DI_DISP0_TIME_CONF_1 (0x0138 + IPU_BASE)
  257. #define DI_DISP0_TIME_CONF_2 (0x013C + IPU_BASE)
  258. #define DI_DISP0_TIME_CONF_3 (0x0140 + IPU_BASE)
  259. #define DI_DISP1_TIME_CONF_1 (0x0144 + IPU_BASE)
  260. #define DI_DISP1_TIME_CONF_2 (0x0148 + IPU_BASE)
  261. #define DI_DISP1_TIME_CONF_3 (0x014C + IPU_BASE)
  262. #define DI_DISP2_TIME_CONF_1 (0x0150 + IPU_BASE)
  263. #define DI_DISP2_TIME_CONF_2 (0x0154 + IPU_BASE)
  264. #define DI_DISP2_TIME_CONF_3 (0x0158 + IPU_BASE)
  265. #define DI_DISP3_TIME_CONF (0x015C + IPU_BASE)
  266. #define DI_DISP0_DB0_MAP (0x0160 + IPU_BASE)
  267. #define DI_DISP0_DB1_MAP (0x0164 + IPU_BASE)
  268. #define DI_DISP0_DB2_MAP (0x0168 + IPU_BASE)
  269. #define DI_DISP0_CB0_MAP (0x016C + IPU_BASE)
  270. #define DI_DISP0_CB1_MAP (0x0170 + IPU_BASE)
  271. #define DI_DISP0_CB2_MAP (0x0174 + IPU_BASE)
  272. #define DI_DISP1_DB0_MAP (0x0178 + IPU_BASE)
  273. #define DI_DISP1_DB1_MAP (0x017C + IPU_BASE)
  274. #define DI_DISP1_DB2_MAP (0x0180 + IPU_BASE)
  275. #define DI_DISP1_CB0_MAP (0x0184 + IPU_BASE)
  276. #define DI_DISP1_CB1_MAP (0x0188 + IPU_BASE)
  277. #define DI_DISP1_CB2_MAP (0x018C + IPU_BASE)
  278. #define DI_DISP2_DB0_MAP (0x0190 + IPU_BASE)
  279. #define DI_DISP2_DB1_MAP (0x0194 + IPU_BASE)
  280. #define DI_DISP2_DB2_MAP (0x0198 + IPU_BASE)
  281. #define DI_DISP2_CB0_MAP (0x019C + IPU_BASE)
  282. #define DI_DISP2_CB1_MAP (0x01A0 + IPU_BASE)
  283. #define DI_DISP2_CB2_MAP (0x01A4 + IPU_BASE)
  284. #define DI_DISP3_B0_MAP (0x01A8 + IPU_BASE)
  285. #define DI_DISP3_B1_MAP (0x01AC + IPU_BASE)
  286. #define DI_DISP3_B2_MAP (0x01B0 + IPU_BASE)
  287. #define DI_DISP_ACC_CC (0x01B4 + IPU_BASE)
  288. #define DI_DISP_LLA_CONF (0x01B8 + IPU_BASE)
  289. #define DI_DISP_LLA_DATA (0x01BC + IPU_BASE)
  290. /* DI_DISP_SIG_POL bits */
  291. #define DI_D3_VSYNC_POL (1 << 28)
  292. #define DI_D3_HSYNC_POL (1 << 27)
  293. #define DI_D3_DRDY_SHARP_POL (1 << 26)
  294. #define DI_D3_CLK_POL (1 << 25)
  295. #define DI_D3_DATA_POL (1 << 24)
  296. /* DI_DISP_IF_CONF bits */
  297. #define DI_D3_CLK_IDLE (1 << 26)
  298. #define DI_D3_CLK_SEL (1 << 25)
  299. #define DI_D3_DATAMSK (1 << 24)
  300. #define IOMUX_PADNUM_MASK 0x1ff
  301. #define IOMUX_GPIONUM_SHIFT 9
  302. #define IOMUX_GPIONUM_MASK (0xff << IOMUX_GPIONUM_SHIFT)
  303. #define IOMUX_PIN(gpionum, padnum) ((padnum) & IOMUX_PADNUM_MASK)
  304. #define IOMUX_MODE_L(pin, mode) IOMUX_MODE(((pin) + 0xc) ^ 3, mode)
  305. struct chan_param_mem_planar {
  306. /* Word 0 */
  307. u32 xv:10;
  308. u32 yv:10;
  309. u32 xb:12;
  310. u32 yb:12;
  311. u32 res1:2;
  312. u32 nsb:1;
  313. u32 lnpb:6;
  314. u32 ubo_l:11;
  315. u32 ubo_h:15;
  316. u32 vbo_l:17;
  317. u32 vbo_h:9;
  318. u32 res2:3;
  319. u32 fw:12;
  320. u32 fh_l:8;
  321. u32 fh_h:4;
  322. u32 res3:28;
  323. /* Word 1 */
  324. u32 eba0;
  325. u32 eba1;
  326. u32 bpp:3;
  327. u32 sl:14;
  328. u32 pfs:3;
  329. u32 bam:3;
  330. u32 res4:2;
  331. u32 npb:6;
  332. u32 res5:1;
  333. u32 sat:2;
  334. u32 res6:30;
  335. } __attribute__ ((packed));
  336. struct chan_param_mem_interleaved {
  337. /* Word 0 */
  338. u32 xv:10;
  339. u32 yv:10;
  340. u32 xb:12;
  341. u32 yb:12;
  342. u32 sce:1;
  343. u32 res1:1;
  344. u32 nsb:1;
  345. u32 lnpb:6;
  346. u32 sx:10;
  347. u32 sy_l:1;
  348. u32 sy_h:9;
  349. u32 ns:10;
  350. u32 sm:10;
  351. u32 sdx_l:3;
  352. u32 sdx_h:2;
  353. u32 sdy:5;
  354. u32 sdrx:1;
  355. u32 sdry:1;
  356. u32 sdr1:1;
  357. u32 res2:2;
  358. u32 fw:12;
  359. u32 fh_l:8;
  360. u32 fh_h:4;
  361. u32 res3:28;
  362. /* Word 1 */
  363. u32 eba0;
  364. u32 eba1;
  365. u32 bpp:3;
  366. u32 sl:14;
  367. u32 pfs:3;
  368. u32 bam:3;
  369. u32 res4:2;
  370. u32 npb:6;
  371. u32 res5:1;
  372. u32 sat:2;
  373. u32 scc:1;
  374. u32 ofs0:5;
  375. u32 ofs1:5;
  376. u32 ofs2:5;
  377. u32 ofs3:5;
  378. u32 wid0:3;
  379. u32 wid1:3;
  380. u32 wid2:3;
  381. u32 wid3:3;
  382. u32 dec_sel:1;
  383. u32 res6:28;
  384. } __attribute__ ((packed));
  385. union chan_param_mem {
  386. struct chan_param_mem_planar pp;
  387. struct chan_param_mem_interleaved ip;
  388. };
  389. static inline u32 reg_read(unsigned long reg)
  390. {
  391. return __REG(reg);
  392. }
  393. static inline void reg_write(u32 value, unsigned long reg)
  394. {
  395. __REG(reg) = value;
  396. }
  397. /*
  398. * sdc_init_panel() - initialize a synchronous LCD panel.
  399. * @width: width of panel in pixels.
  400. * @height: height of panel in pixels.
  401. * @pixel_fmt: pixel format of buffer as FOURCC ASCII code.
  402. * @return: 0 on success or negative error code on failure.
  403. */
  404. static int sdc_init_panel(u16 width, u16 height, enum pixel_fmt pixel_fmt)
  405. {
  406. u32 reg;
  407. uint32_t old_conf;
  408. /* Init panel size and blanking periods */
  409. reg = ((H_SYNC_WIDTH - 1) << 26) |
  410. ((u32)(width + H_START_WIDTH + H_END_WIDTH - 1) << 16);
  411. reg_write(reg, SDC_HOR_CONF);
  412. reg = ((V_SYNC_WIDTH - 1) << 26) | SDC_V_SYNC_WIDTH_L |
  413. ((u32)(height + V_START_WIDTH + V_END_WIDTH - 1) << 16);
  414. reg_write(reg, SDC_VER_CONF);
  415. switch (PANEL_TYPE) {
  416. case IPU_PANEL_SHARP_TFT:
  417. reg_write(0x00FD0102L, SDC_SHARP_CONF_1);
  418. reg_write(0x00F500F4L, SDC_SHARP_CONF_2);
  419. reg_write(SDC_COM_SHARP | SDC_COM_TFT_COLOR, SDC_COM_CONF);
  420. break;
  421. case IPU_PANEL_TFT:
  422. reg_write(SDC_COM_TFT_COLOR, SDC_COM_CONF);
  423. break;
  424. default:
  425. return -EINVAL;
  426. }
  427. /* Init clocking */
  428. /*
  429. * Calculate divider: fractional part is 4 bits so simply multiple by
  430. * 2^4 to get fractional part, as long as we stay under ~250MHz and on
  431. * i.MX31 it (HSP_CLK) is <= 178MHz. Currently 128.267MHz
  432. */
  433. reg_write((((IF_CLK_DIV / 8) - 1) << 22) |
  434. IF_CLK_DIV, DI_DISP3_TIME_CONF);
  435. /* DI settings */
  436. old_conf = reg_read(DI_DISP_IF_CONF) & 0x78FFFFFF;
  437. reg_write(old_conf | IF_CONF, DI_DISP_IF_CONF);
  438. old_conf = reg_read(DI_DISP_SIG_POL) & 0xE0FFFFFF;
  439. reg_write(old_conf | SIG_POL, DI_DISP_SIG_POL);
  440. reg_write(fmt_cfg[pixel_fmt].b0, DI_DISP3_B0_MAP);
  441. reg_write(fmt_cfg[pixel_fmt].b1, DI_DISP3_B1_MAP);
  442. reg_write(fmt_cfg[pixel_fmt].b2, DI_DISP3_B2_MAP);
  443. reg_write(reg_read(DI_DISP_ACC_CC) |
  444. ((fmt_cfg[pixel_fmt].acc - 1) << 12), DI_DISP_ACC_CC);
  445. return 0;
  446. }
  447. static void ipu_ch_param_set_size(union chan_param_mem *params,
  448. uint32_t pixel_fmt, uint16_t width,
  449. uint16_t height, uint16_t stride)
  450. {
  451. params->pp.fw = width - 1;
  452. params->pp.fh_l = height - 1;
  453. params->pp.fh_h = (height - 1) >> 8;
  454. params->pp.sl = stride - 1;
  455. /* See above, for further formats see the Linux driver */
  456. switch (pixel_fmt) {
  457. case IPU_PIX_FMT_RGB565:
  458. params->ip.bpp = 2;
  459. params->ip.pfs = 4;
  460. params->ip.npb = 7;
  461. params->ip.sat = 2; /* SAT = 32-bit access */
  462. params->ip.ofs0 = 0; /* Red bit offset */
  463. params->ip.ofs1 = 5; /* Green bit offset */
  464. params->ip.ofs2 = 11; /* Blue bit offset */
  465. params->ip.ofs3 = 16; /* Alpha bit offset */
  466. params->ip.wid0 = 4; /* Red bit width - 1 */
  467. params->ip.wid1 = 5; /* Green bit width - 1 */
  468. params->ip.wid2 = 4; /* Blue bit width - 1 */
  469. break;
  470. case IPU_PIX_FMT_RGB24:
  471. params->ip.bpp = 1; /* 24 BPP & RGB PFS */
  472. params->ip.pfs = 4;
  473. params->ip.npb = 7;
  474. params->ip.sat = 2; /* SAT = 32-bit access */
  475. params->ip.ofs0 = 16; /* Red bit offset */
  476. params->ip.ofs1 = 8; /* Green bit offset */
  477. params->ip.ofs2 = 0; /* Blue bit offset */
  478. params->ip.ofs3 = 24; /* Alpha bit offset */
  479. params->ip.wid0 = 7; /* Red bit width - 1 */
  480. params->ip.wid1 = 7; /* Green bit width - 1 */
  481. params->ip.wid2 = 7; /* Blue bit width - 1 */
  482. break;
  483. default:
  484. break;
  485. }
  486. params->pp.nsb = 1;
  487. }
  488. static void ipu_ch_param_set_buffer(union chan_param_mem *params,
  489. void *buf0, void *buf1)
  490. {
  491. params->pp.eba0 = (u32)buf0;
  492. params->pp.eba1 = (u32)buf1;
  493. }
  494. static void ipu_write_param_mem(uint32_t addr, uint32_t *data,
  495. uint32_t num_words)
  496. {
  497. for (; num_words > 0; num_words--) {
  498. reg_write(addr, IPU_IMA_ADDR);
  499. reg_write(*data++, IPU_IMA_DATA);
  500. addr++;
  501. if ((addr & 0x7) == 5) {
  502. addr &= ~0x7; /* set to word 0 */
  503. addr += 8; /* increment to next row */
  504. }
  505. }
  506. }
  507. static uint32_t bpp_to_pixfmt(int bpp)
  508. {
  509. switch (bpp) {
  510. case 16:
  511. return IPU_PIX_FMT_RGB565;
  512. default:
  513. return 0;
  514. }
  515. }
  516. static uint32_t dma_param_addr(enum ipu_channel channel)
  517. {
  518. /* Channel Parameter Memory */
  519. return 0x10000 | (channel << 4);
  520. }
  521. static void ipu_init_channel_buffer(enum ipu_channel channel, void *fbmem)
  522. {
  523. union chan_param_mem params = {};
  524. uint32_t reg;
  525. uint32_t stride_bytes;
  526. stride_bytes = (XRES * ((BIT_PER_PIXEL + 7) / 8) + 3) & ~3;
  527. /* Build parameter memory data for DMA channel */
  528. ipu_ch_param_set_size(&params, bpp_to_pixfmt(BIT_PER_PIXEL),
  529. XRES, YRES, stride_bytes);
  530. ipu_ch_param_set_buffer(&params, fbmem, NULL);
  531. params.pp.bam = 0;
  532. /* Some channels (rotation) have restriction on burst length */
  533. switch (channel) {
  534. case IDMAC_SDC_0:
  535. /* In original code only IPU_PIX_FMT_RGB565 was setting burst */
  536. params.pp.npb = 16 - 1;
  537. break;
  538. default:
  539. break;
  540. }
  541. ipu_write_param_mem(dma_param_addr(channel), (uint32_t *)&params, 10);
  542. /* Disable double-buffering */
  543. reg = reg_read(IPU_CHA_DB_MODE_SEL);
  544. reg &= ~(1UL << channel);
  545. reg_write(reg, IPU_CHA_DB_MODE_SEL);
  546. }
  547. static void ipu_channel_set_priority(enum ipu_channel channel,
  548. int prio)
  549. {
  550. u32 reg = reg_read(IDMAC_CHA_PRI);
  551. if (prio)
  552. reg |= 1UL << channel;
  553. else
  554. reg &= ~(1UL << channel);
  555. reg_write(reg, IDMAC_CHA_PRI);
  556. }
  557. /*
  558. * ipu_enable_channel() - enable an IPU channel.
  559. * @channel: channel ID.
  560. * @return: 0 on success or negative error code on failure.
  561. */
  562. static int ipu_enable_channel(enum ipu_channel channel)
  563. {
  564. uint32_t reg;
  565. /* Reset to buffer 0 */
  566. reg_write(1UL << channel, IPU_CHA_CUR_BUF);
  567. switch (channel) {
  568. case IDMAC_SDC_0:
  569. ipu_channel_set_priority(channel, 1);
  570. break;
  571. default:
  572. break;
  573. }
  574. reg = reg_read(IDMAC_CHA_EN);
  575. reg_write(reg | (1UL << channel), IDMAC_CHA_EN);
  576. return 0;
  577. }
  578. static int ipu_update_channel_buffer(enum ipu_channel channel, void *buf)
  579. {
  580. uint32_t reg;
  581. reg = reg_read(IPU_CHA_BUF0_RDY);
  582. if (reg & (1UL << channel))
  583. return -EACCES;
  584. /* 44.3.3.1.9 - Row Number 1 (WORD1, offset 0) */
  585. reg_write(dma_param_addr(channel) + 0x0008UL, IPU_IMA_ADDR);
  586. reg_write((u32)buf, IPU_IMA_DATA);
  587. return 0;
  588. }
  589. static int idmac_tx_submit(enum ipu_channel channel, void *buf)
  590. {
  591. int ret;
  592. ipu_init_channel_buffer(channel, buf);
  593. /* ipu_idmac.c::ipu_submit_channel_buffers() */
  594. ret = ipu_update_channel_buffer(channel, buf);
  595. if (ret < 0)
  596. return ret;
  597. /* ipu_idmac.c::ipu_select_buffer() */
  598. /* Mark buffer 0 as ready. */
  599. reg_write(1UL << channel, IPU_CHA_BUF0_RDY);
  600. ret = ipu_enable_channel(channel);
  601. return ret;
  602. }
  603. static void sdc_enable_channel(void *fbmem)
  604. {
  605. int ret;
  606. u32 reg;
  607. ret = idmac_tx_submit(IDMAC_SDC_0, fbmem);
  608. /* mx3fb.c::sdc_fb_init() */
  609. if (ret >= 0) {
  610. reg = reg_read(SDC_COM_CONF);
  611. reg_write(reg | SDC_COM_BG_EN, SDC_COM_CONF);
  612. }
  613. /*
  614. * Attention! Without this msleep the channel keeps generating
  615. * interrupts. Next sdc_set_brightness() is going to be called
  616. * from mx3fb_blank().
  617. */
  618. msleep(2);
  619. }
  620. /*
  621. * mx3fb_set_par() - set framebuffer parameters and change the operating mode.
  622. * @return: 0 on success or negative error code on failure.
  623. */
  624. static int mx3fb_set_par(void)
  625. {
  626. int ret;
  627. ret = sdc_init_panel(XRES, YRES, PIXEL_FMT);
  628. if (ret < 0)
  629. return ret;
  630. reg_write((H_START_WIDTH << 16) | V_START_WIDTH, SDC_BG_POS);
  631. return 0;
  632. }
  633. /* References in this function refer to respective Linux kernel sources */
  634. void lcd_enable(void)
  635. {
  636. u32 reg;
  637. /* pcm037.c::mxc_board_init() */
  638. /* Display Interface #3 */
  639. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD0, MUX_CTL_FUNC));
  640. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD1, MUX_CTL_FUNC));
  641. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD2, MUX_CTL_FUNC));
  642. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD3, MUX_CTL_FUNC));
  643. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD4, MUX_CTL_FUNC));
  644. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD5, MUX_CTL_FUNC));
  645. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD6, MUX_CTL_FUNC));
  646. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD7, MUX_CTL_FUNC));
  647. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD8, MUX_CTL_FUNC));
  648. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD9, MUX_CTL_FUNC));
  649. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD10, MUX_CTL_FUNC));
  650. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD11, MUX_CTL_FUNC));
  651. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD12, MUX_CTL_FUNC));
  652. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD13, MUX_CTL_FUNC));
  653. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD14, MUX_CTL_FUNC));
  654. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD15, MUX_CTL_FUNC));
  655. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD16, MUX_CTL_FUNC));
  656. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_LD17, MUX_CTL_FUNC));
  657. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_VSYNC3, MUX_CTL_FUNC));
  658. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_HSYNC, MUX_CTL_FUNC));
  659. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_FPSHIFT, MUX_CTL_FUNC));
  660. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_DRDY0, MUX_CTL_FUNC));
  661. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_D3_REV, MUX_CTL_FUNC));
  662. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_CONTRAST, MUX_CTL_FUNC));
  663. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_D3_SPL, MUX_CTL_FUNC));
  664. mx31_gpio_mux(IOMUX_MODE_L(MX31_PIN_D3_CLS, MUX_CTL_FUNC));
  665. /* ipu_idmac.c::ipu_probe() */
  666. /* Start the clock */
  667. __REG(CCM_CGR1) = __REG(CCM_CGR1) | (3 << 22);
  668. /* ipu_idmac.c::ipu_idmac_init() */
  669. /* Service request counter to maximum - shouldn't be needed */
  670. reg_write(0x00000070, IDMAC_CONF);
  671. /* ipu_idmac.c::ipu_init_channel() */
  672. /* Enable IPU sub modules */
  673. reg = reg_read(IPU_CONF) | IPU_CONF_SDC_EN | IPU_CONF_DI_EN;
  674. reg_write(reg, IPU_CONF);
  675. /* mx3fb.c::init_fb_chan() */
  676. /* set Display Interface clock period */
  677. reg_write(0x00100010L, DI_HSP_CLK_PER);
  678. /* Might need to trigger HSP clock change - see 44.3.3.8.5 */
  679. /* mx3fb.c::sdc_set_brightness() */
  680. /* This might be board-specific */
  681. reg_write(0x03000000UL | 255 << 16, SDC_PWM_CTRL);
  682. /* mx3fb.c::sdc_set_global_alpha() */
  683. /* Use global - not per-pixel - Alpha-blending */
  684. reg = reg_read(SDC_GW_CTRL) & 0x00FFFFFFL;
  685. reg_write(reg | ((uint32_t) 0xff << 24), SDC_GW_CTRL);
  686. reg = reg_read(SDC_COM_CONF);
  687. reg_write(reg | SDC_COM_GLB_A, SDC_COM_CONF);
  688. /* mx3fb.c::sdc_set_color_key() */
  689. /* Disable colour-keying for background */
  690. reg = reg_read(SDC_COM_CONF) &
  691. ~(SDC_COM_GWSEL | SDC_COM_KEY_COLOR_G);
  692. reg_write(reg, SDC_COM_CONF);
  693. mx3fb_set_par();
  694. sdc_enable_channel(lcd_base);
  695. /*
  696. * Linux driver calls sdc_set_brightness() here again,
  697. * once is enough for us
  698. */
  699. }
  700. void lcd_ctrl_init(void *lcdbase)
  701. {
  702. u32 mem_len = XRES * YRES * BIT_PER_PIXEL / 8;
  703. /*
  704. * We rely on lcdbase being a physical address, i.e., either MMU off,
  705. * or 1-to-1 mapping. Might want to add some virt2phys here.
  706. */
  707. if (!lcdbase)
  708. return;
  709. memset(lcdbase, 0, mem_len);
  710. }
  711. ulong calc_fbsize(void)
  712. {
  713. return ((panel_info.vl_col * panel_info.vl_row *
  714. NBITS(panel_info.vl_bpix)) / 8) + PAGE_SIZE;
  715. }
  716. int overwrite_console(void)
  717. {
  718. /* Keep stdout / stderr on serial, our LCD is for splashscreen only */
  719. return 1;
  720. }