exynos_fb.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. *
  4. * Author: InKi Dae <inki.dae@samsung.com>
  5. * Author: Donghwa Lee <dh09.lee@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <config.h>
  23. #include <common.h>
  24. #include <lcd.h>
  25. #include <fdtdec.h>
  26. #include <libfdt.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/cpu.h>
  29. #include <asm/arch/clock.h>
  30. #include <asm/arch/clk.h>
  31. #include <asm/arch/mipi_dsim.h>
  32. #include <asm/arch/dp_info.h>
  33. #include <asm/arch/system.h>
  34. #include <asm-generic/errno.h>
  35. #include "exynos_fb.h"
  36. DECLARE_GLOBAL_DATA_PTR;
  37. static unsigned int panel_width, panel_height;
  38. /*
  39. * board_init_f(arch/arm/lib/board.c) calls lcd_setmem() which needs
  40. * panel_info.vl_col, panel_info.vl_row and panel_info.vl_bpix to reserve
  41. * FB memory at a very early stage, i.e even before exynos_fimd_parse_dt()
  42. * is called. So, we are forced to statically assign it.
  43. */
  44. #ifdef CONFIG_OF_CONTROL
  45. vidinfo_t panel_info = {
  46. .vl_col = LCD_XRES,
  47. .vl_row = LCD_YRES,
  48. .vl_bpix = LCD_COLOR16,
  49. };
  50. #endif
  51. static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
  52. {
  53. unsigned long palette_size;
  54. unsigned int fb_size;
  55. fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
  56. palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
  57. exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
  58. (unsigned long)fb_size, palette_size);
  59. }
  60. static void exynos_lcd_init(vidinfo_t *vid)
  61. {
  62. exynos_fimd_lcd_init(vid);
  63. /* Enable flushing after LCD writes if requested */
  64. lcd_set_flush_dcache(1);
  65. }
  66. #ifdef CONFIG_CMD_BMP
  67. static void draw_logo(void)
  68. {
  69. int x, y;
  70. ulong addr;
  71. if (panel_width >= panel_info.logo_width) {
  72. x = ((panel_width - panel_info.logo_width) >> 1);
  73. } else {
  74. x = 0;
  75. printf("Warning: image width is bigger than display width\n");
  76. }
  77. if (panel_height >= panel_info.logo_height) {
  78. y = ((panel_height - panel_info.logo_height) >> 1) - 4;
  79. } else {
  80. y = 0;
  81. printf("Warning: image height is bigger than display height\n");
  82. }
  83. addr = panel_info.logo_addr;
  84. bmp_display(addr, x, y);
  85. }
  86. #endif
  87. void __exynos_cfg_lcd_gpio(void)
  88. {
  89. }
  90. void exynos_cfg_lcd_gpio(void)
  91. __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
  92. void __exynos_backlight_on(unsigned int onoff)
  93. {
  94. }
  95. void exynos_backlight_on(unsigned int onoff)
  96. __attribute__((weak, alias("__exynos_cfg_lcd_gpio")));
  97. void __exynos_reset_lcd(void)
  98. {
  99. }
  100. void exynos_reset_lcd(void)
  101. __attribute__((weak, alias("__exynos_reset_lcd")));
  102. void __exynos_lcd_power_on(void)
  103. {
  104. }
  105. void exynos_lcd_power_on(void)
  106. __attribute__((weak, alias("__exynos_lcd_power_on")));
  107. void __exynos_cfg_ldo(void)
  108. {
  109. }
  110. void exynos_cfg_ldo(void)
  111. __attribute__((weak, alias("__exynos_cfg_ldo")));
  112. void __exynos_enable_ldo(unsigned int onoff)
  113. {
  114. }
  115. void exynos_enable_ldo(unsigned int onoff)
  116. __attribute__((weak, alias("__exynos_enable_ldo")));
  117. void __exynos_backlight_reset(void)
  118. {
  119. }
  120. void exynos_backlight_reset(void)
  121. __attribute__((weak, alias("__exynos_backlight_reset")));
  122. static void lcd_panel_on(vidinfo_t *vid)
  123. {
  124. udelay(vid->init_delay);
  125. exynos_backlight_reset();
  126. exynos_cfg_lcd_gpio();
  127. exynos_lcd_power_on();
  128. udelay(vid->power_on_delay);
  129. if (vid->dp_enabled)
  130. exynos_init_dp();
  131. exynos_reset_lcd();
  132. udelay(vid->reset_delay);
  133. exynos_backlight_on(1);
  134. exynos_cfg_ldo();
  135. exynos_enable_ldo(1);
  136. if (vid->mipi_enabled)
  137. exynos_mipi_dsi_init();
  138. }
  139. #ifdef CONFIG_OF_CONTROL
  140. int exynos_fimd_parse_dt(const void *blob)
  141. {
  142. unsigned int node;
  143. node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
  144. if (node <= 0) {
  145. debug("exynos_fb: Can't get device node for fimd\n");
  146. return -ENODEV;
  147. }
  148. panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
  149. if (panel_info.vl_col == 0) {
  150. debug("Can't get XRES\n");
  151. return -ENXIO;
  152. }
  153. panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
  154. if (panel_info.vl_row == 0) {
  155. debug("Can't get YRES\n");
  156. return -ENXIO;
  157. }
  158. panel_info.vl_width = fdtdec_get_int(blob, node,
  159. "samsung,vl-width", 0);
  160. panel_info.vl_height = fdtdec_get_int(blob, node,
  161. "samsung,vl-height", 0);
  162. panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
  163. if (panel_info.vl_freq == 0) {
  164. debug("Can't get refresh rate\n");
  165. return -ENXIO;
  166. }
  167. if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
  168. panel_info.vl_clkp = CONFIG_SYS_LOW;
  169. if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
  170. panel_info.vl_oep = CONFIG_SYS_LOW;
  171. if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
  172. panel_info.vl_hsp = CONFIG_SYS_LOW;
  173. if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
  174. panel_info.vl_vsp = CONFIG_SYS_LOW;
  175. if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
  176. panel_info.vl_dp = CONFIG_SYS_LOW;
  177. panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
  178. if (panel_info.vl_bpix == 0) {
  179. debug("Can't get bits per pixel\n");
  180. return -ENXIO;
  181. }
  182. panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
  183. if (panel_info.vl_hspw == 0) {
  184. debug("Can't get hsync width\n");
  185. return -ENXIO;
  186. }
  187. panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
  188. if (panel_info.vl_hfpd == 0) {
  189. debug("Can't get right margin\n");
  190. return -ENXIO;
  191. }
  192. panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
  193. "samsung,vl-hbpd", 0);
  194. if (panel_info.vl_hbpd == 0) {
  195. debug("Can't get left margin\n");
  196. return -ENXIO;
  197. }
  198. panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
  199. "samsung,vl-vspw", 0);
  200. if (panel_info.vl_vspw == 0) {
  201. debug("Can't get vsync width\n");
  202. return -ENXIO;
  203. }
  204. panel_info.vl_vfpd = fdtdec_get_int(blob, node,
  205. "samsung,vl-vfpd", 0);
  206. if (panel_info.vl_vfpd == 0) {
  207. debug("Can't get lower margin\n");
  208. return -ENXIO;
  209. }
  210. panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
  211. if (panel_info.vl_vbpd == 0) {
  212. debug("Can't get upper margin\n");
  213. return -ENXIO;
  214. }
  215. panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
  216. "samsung,vl-cmd-allow-len", 0);
  217. panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
  218. panel_info.init_delay = fdtdec_get_int(blob, node,
  219. "samsung,init-delay", 0);
  220. panel_info.power_on_delay = fdtdec_get_int(blob, node,
  221. "samsung,power-on-delay", 0);
  222. panel_info.reset_delay = fdtdec_get_int(blob, node,
  223. "samsung,reset-delay", 0);
  224. panel_info.interface_mode = fdtdec_get_int(blob, node,
  225. "samsung,interface-mode", 0);
  226. panel_info.mipi_enabled = fdtdec_get_int(blob, node,
  227. "samsung,mipi-enabled", 0);
  228. panel_info.dp_enabled = fdtdec_get_int(blob, node,
  229. "samsung,dp-enabled", 0);
  230. panel_info.cs_setup = fdtdec_get_int(blob, node,
  231. "samsung,cs-setup", 0);
  232. panel_info.wr_setup = fdtdec_get_int(blob, node,
  233. "samsung,wr-setup", 0);
  234. panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
  235. panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
  236. panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
  237. if (panel_info.logo_on) {
  238. panel_info.logo_width = fdtdec_get_int(blob, node,
  239. "samsung,logo-width", 0);
  240. panel_info.logo_height = fdtdec_get_int(blob, node,
  241. "samsung,logo-height", 0);
  242. panel_info.logo_addr = fdtdec_get_int(blob, node,
  243. "samsung,logo-addr", 0);
  244. }
  245. panel_info.rgb_mode = fdtdec_get_int(blob, node,
  246. "samsung,rgb-mode", 0);
  247. panel_info.pclk_name = fdtdec_get_int(blob, node,
  248. "samsung,pclk-name", 0);
  249. panel_info.sclk_div = fdtdec_get_int(blob, node,
  250. "samsung,sclk-div", 0);
  251. panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
  252. "samsung,dual-lcd-enabled", 0);
  253. return 0;
  254. }
  255. #endif
  256. void lcd_ctrl_init(void *lcdbase)
  257. {
  258. set_system_display_ctrl();
  259. set_lcd_clk();
  260. #ifdef CONFIG_OF_CONTROL
  261. if (exynos_fimd_parse_dt(gd->fdt_blob))
  262. debug("Can't get proper panel info\n");
  263. #else
  264. /* initialize parameters which is specific to panel. */
  265. init_panel_info(&panel_info);
  266. #endif
  267. panel_width = panel_info.vl_width;
  268. panel_height = panel_info.vl_height;
  269. exynos_lcd_init_mem(lcdbase, &panel_info);
  270. exynos_lcd_init(&panel_info);
  271. }
  272. void lcd_enable(void)
  273. {
  274. if (panel_info.logo_on) {
  275. memset((void *) gd->fb_base, 0, panel_width * panel_height *
  276. (NBITS(panel_info.vl_bpix) >> 3));
  277. #ifdef CONFIG_CMD_BMP
  278. draw_logo();
  279. #endif
  280. }
  281. lcd_panel_on(&panel_info);
  282. }
  283. /* dummy function */
  284. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
  285. {
  286. return;
  287. }