mx3fb.c 22 KB

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