mx3fb.c 22 KB

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