exynos_fb.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <config.h>
  10. #include <common.h>
  11. #include <lcd.h>
  12. #include <fdtdec.h>
  13. #include <libfdt.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/clock.h>
  17. #include <asm/arch/clk.h>
  18. #include <asm/arch/mipi_dsim.h>
  19. #include <asm/arch/dp_info.h>
  20. #include <asm/arch/system.h>
  21. #include <asm-generic/errno.h>
  22. #include "exynos_fb.h"
  23. DECLARE_GLOBAL_DATA_PTR;
  24. static unsigned int panel_width, panel_height;
  25. #ifdef CONFIG_OF_CONTROL
  26. vidinfo_t panel_info = {
  27. /*
  28. * Insert a value here so that we don't end up in the BSS
  29. * Reference: drivers/video/tegra.c
  30. */
  31. .vl_col = -1,
  32. };
  33. #endif
  34. static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
  35. {
  36. unsigned long palette_size;
  37. unsigned int fb_size;
  38. fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3);
  39. palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
  40. exynos_fimd_lcd_init_mem((unsigned long)lcdbase,
  41. (unsigned long)fb_size, palette_size);
  42. }
  43. static void exynos_lcd_init(vidinfo_t *vid)
  44. {
  45. exynos_fimd_lcd_init(vid);
  46. /* Enable flushing after LCD writes if requested */
  47. lcd_set_flush_dcache(1);
  48. }
  49. __weak void exynos_cfg_lcd_gpio(void)
  50. {
  51. }
  52. __weak void exynos_backlight_on(unsigned int onoff)
  53. {
  54. }
  55. __weak void exynos_reset_lcd(void)
  56. {
  57. }
  58. __weak void exynos_lcd_power_on(void)
  59. {
  60. }
  61. __weak void exynos_cfg_ldo(void)
  62. {
  63. }
  64. __weak void exynos_enable_ldo(unsigned int onoff)
  65. {
  66. }
  67. __weak void exynos_backlight_reset(void)
  68. {
  69. }
  70. __weak int exynos_lcd_misc_init(vidinfo_t *vid)
  71. {
  72. return 0;
  73. }
  74. static void lcd_panel_on(vidinfo_t *vid)
  75. {
  76. udelay(vid->init_delay);
  77. exynos_backlight_reset();
  78. exynos_cfg_lcd_gpio();
  79. exynos_lcd_power_on();
  80. udelay(vid->power_on_delay);
  81. if (vid->dp_enabled)
  82. exynos_init_dp();
  83. exynos_reset_lcd();
  84. udelay(vid->reset_delay);
  85. exynos_backlight_on(1);
  86. exynos_cfg_ldo();
  87. exynos_enable_ldo(1);
  88. if (vid->mipi_enabled)
  89. exynos_mipi_dsi_init();
  90. }
  91. #ifdef CONFIG_OF_CONTROL
  92. int exynos_lcd_early_init(const void *blob)
  93. {
  94. unsigned int node;
  95. node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD);
  96. if (node <= 0) {
  97. debug("exynos_fb: Can't get device node for fimd\n");
  98. return -ENODEV;
  99. }
  100. panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0);
  101. if (panel_info.vl_col == 0) {
  102. debug("Can't get XRES\n");
  103. return -ENXIO;
  104. }
  105. panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0);
  106. if (panel_info.vl_row == 0) {
  107. debug("Can't get YRES\n");
  108. return -ENXIO;
  109. }
  110. panel_info.vl_width = fdtdec_get_int(blob, node,
  111. "samsung,vl-width", 0);
  112. panel_info.vl_height = fdtdec_get_int(blob, node,
  113. "samsung,vl-height", 0);
  114. panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0);
  115. if (panel_info.vl_freq == 0) {
  116. debug("Can't get refresh rate\n");
  117. return -ENXIO;
  118. }
  119. if (fdtdec_get_bool(blob, node, "samsung,vl-clkp"))
  120. panel_info.vl_clkp = CONFIG_SYS_LOW;
  121. if (fdtdec_get_bool(blob, node, "samsung,vl-oep"))
  122. panel_info.vl_oep = CONFIG_SYS_LOW;
  123. if (fdtdec_get_bool(blob, node, "samsung,vl-hsp"))
  124. panel_info.vl_hsp = CONFIG_SYS_LOW;
  125. if (fdtdec_get_bool(blob, node, "samsung,vl-vsp"))
  126. panel_info.vl_vsp = CONFIG_SYS_LOW;
  127. if (fdtdec_get_bool(blob, node, "samsung,vl-dp"))
  128. panel_info.vl_dp = CONFIG_SYS_LOW;
  129. panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0);
  130. if (panel_info.vl_bpix == 0) {
  131. debug("Can't get bits per pixel\n");
  132. return -ENXIO;
  133. }
  134. panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0);
  135. if (panel_info.vl_hspw == 0) {
  136. debug("Can't get hsync width\n");
  137. return -ENXIO;
  138. }
  139. panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0);
  140. if (panel_info.vl_hfpd == 0) {
  141. debug("Can't get right margin\n");
  142. return -ENXIO;
  143. }
  144. panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node,
  145. "samsung,vl-hbpd", 0);
  146. if (panel_info.vl_hbpd == 0) {
  147. debug("Can't get left margin\n");
  148. return -ENXIO;
  149. }
  150. panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node,
  151. "samsung,vl-vspw", 0);
  152. if (panel_info.vl_vspw == 0) {
  153. debug("Can't get vsync width\n");
  154. return -ENXIO;
  155. }
  156. panel_info.vl_vfpd = fdtdec_get_int(blob, node,
  157. "samsung,vl-vfpd", 0);
  158. if (panel_info.vl_vfpd == 0) {
  159. debug("Can't get lower margin\n");
  160. return -ENXIO;
  161. }
  162. panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0);
  163. if (panel_info.vl_vbpd == 0) {
  164. debug("Can't get upper margin\n");
  165. return -ENXIO;
  166. }
  167. panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node,
  168. "samsung,vl-cmd-allow-len", 0);
  169. panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0);
  170. panel_info.init_delay = fdtdec_get_int(blob, node,
  171. "samsung,init-delay", 0);
  172. panel_info.power_on_delay = fdtdec_get_int(blob, node,
  173. "samsung,power-on-delay", 0);
  174. panel_info.reset_delay = fdtdec_get_int(blob, node,
  175. "samsung,reset-delay", 0);
  176. panel_info.interface_mode = fdtdec_get_int(blob, node,
  177. "samsung,interface-mode", 0);
  178. panel_info.mipi_enabled = fdtdec_get_int(blob, node,
  179. "samsung,mipi-enabled", 0);
  180. panel_info.dp_enabled = fdtdec_get_int(blob, node,
  181. "samsung,dp-enabled", 0);
  182. panel_info.cs_setup = fdtdec_get_int(blob, node,
  183. "samsung,cs-setup", 0);
  184. panel_info.wr_setup = fdtdec_get_int(blob, node,
  185. "samsung,wr-setup", 0);
  186. panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0);
  187. panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0);
  188. panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0);
  189. if (panel_info.logo_on) {
  190. panel_info.logo_width = fdtdec_get_int(blob, node,
  191. "samsung,logo-width", 0);
  192. panel_info.logo_height = fdtdec_get_int(blob, node,
  193. "samsung,logo-height", 0);
  194. panel_info.logo_addr = fdtdec_get_int(blob, node,
  195. "samsung,logo-addr", 0);
  196. }
  197. panel_info.rgb_mode = fdtdec_get_int(blob, node,
  198. "samsung,rgb-mode", 0);
  199. panel_info.pclk_name = fdtdec_get_int(blob, node,
  200. "samsung,pclk-name", 0);
  201. panel_info.sclk_div = fdtdec_get_int(blob, node,
  202. "samsung,sclk-div", 0);
  203. panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node,
  204. "samsung,dual-lcd-enabled", 0);
  205. return 0;
  206. }
  207. #endif
  208. void lcd_ctrl_init(void *lcdbase)
  209. {
  210. set_system_display_ctrl();
  211. set_lcd_clk();
  212. #ifdef CONFIG_OF_CONTROL
  213. #ifdef CONFIG_EXYNOS_MIPI_DSIM
  214. exynos_init_dsim_platform_data(&panel_info);
  215. #endif
  216. exynos_lcd_misc_init(&panel_info);
  217. #else
  218. /* initialize parameters which is specific to panel. */
  219. init_panel_info(&panel_info);
  220. #endif
  221. panel_width = panel_info.vl_width;
  222. panel_height = panel_info.vl_height;
  223. exynos_lcd_init_mem(lcdbase, &panel_info);
  224. exynos_lcd_init(&panel_info);
  225. }
  226. void lcd_enable(void)
  227. {
  228. if (panel_info.logo_on) {
  229. memset((void *) gd->fb_base, 0, panel_width * panel_height *
  230. (NBITS(panel_info.vl_bpix) >> 3));
  231. }
  232. lcd_panel_on(&panel_info);
  233. }
  234. /* dummy function */
  235. void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
  236. {
  237. return;
  238. }