Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 11 | #include <common.h> |
| 12 | #include <lcd.h> |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 13 | #include <fdtdec.h> |
| 14 | #include <libfdt.h> |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/clock.h> |
| 18 | #include <asm/arch/clk.h> |
| 19 | #include <asm/arch/mipi_dsim.h> |
Donghwa Lee | bc72aeb | 2012-07-02 01:16:08 +0000 | [diff] [blame] | 20 | #include <asm/arch/dp_info.h> |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 21 | #include <asm/arch/system.h> |
Ajay Kumar | 39ea08b | 2015-03-04 19:05:26 +0530 | [diff] [blame] | 22 | #include <asm/gpio.h> |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 23 | #include <asm-generic/errno.h> |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 24 | |
| 25 | #include "exynos_fb.h" |
| 26 | |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Simon Glass | 6d27559 | 2016-02-21 21:08:40 -0700 | [diff] [blame] | 29 | struct vidinfo panel_info = { |
Ajay Kumar | 1176348 | 2014-09-05 16:53:30 +0530 | [diff] [blame] | 30 | /* |
| 31 | * Insert a value here so that we don't end up in the BSS |
| 32 | * Reference: drivers/video/tegra.c |
| 33 | */ |
| 34 | .vl_col = -1, |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 35 | }; |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 36 | |
Nikita Kiryanov | ec3685d | 2015-02-03 13:32:21 +0200 | [diff] [blame] | 37 | ushort *configuration_get_cmap(void) |
| 38 | { |
| 39 | #if defined(CONFIG_LCD_LOGO) |
| 40 | return bmp_logo_palette; |
| 41 | #else |
| 42 | return NULL; |
| 43 | #endif |
| 44 | } |
| 45 | |
Simon Glass | 4d022cc | 2016-02-21 21:08:41 -0700 | [diff] [blame] | 46 | static void exynos_lcd_init(struct vidinfo *vid, ulong lcd_base) |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 47 | { |
Simon Glass | 4d022cc | 2016-02-21 21:08:41 -0700 | [diff] [blame] | 48 | exynos_fimd_lcd_init(vid, lcd_base); |
Ćukasz Majewski | 43905f4 | 2013-01-08 03:48:40 +0000 | [diff] [blame] | 49 | |
| 50 | /* Enable flushing after LCD writes if requested */ |
| 51 | lcd_set_flush_dcache(1); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 54 | __weak void exynos_cfg_lcd_gpio(void) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 55 | { |
| 56 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 57 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 58 | __weak void exynos_backlight_on(unsigned int onoff) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 59 | { |
| 60 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 61 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 62 | __weak void exynos_reset_lcd(void) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 63 | { |
| 64 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 65 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 66 | __weak void exynos_lcd_power_on(void) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 67 | { |
| 68 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 69 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 70 | __weak void exynos_cfg_ldo(void) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 71 | { |
| 72 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 73 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 74 | __weak void exynos_enable_ldo(unsigned int onoff) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 75 | { |
| 76 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 77 | |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 78 | __weak void exynos_backlight_reset(void) |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 79 | { |
| 80 | } |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 81 | |
Simon Glass | 6d27559 | 2016-02-21 21:08:40 -0700 | [diff] [blame] | 82 | __weak int exynos_lcd_misc_init(struct vidinfo *vid) |
Piotr Wilczek | 386fd02 | 2014-03-07 14:59:40 +0100 | [diff] [blame] | 83 | { |
| 84 | return 0; |
| 85 | } |
Piotr Wilczek | 386fd02 | 2014-03-07 14:59:40 +0100 | [diff] [blame] | 86 | |
Simon Glass | 6d27559 | 2016-02-21 21:08:40 -0700 | [diff] [blame] | 87 | static void lcd_panel_on(struct vidinfo *vid) |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 88 | { |
Ajay Kumar | 39ea08b | 2015-03-04 19:05:26 +0530 | [diff] [blame] | 89 | struct gpio_desc pwm_out_gpio; |
| 90 | struct gpio_desc bl_en_gpio; |
| 91 | unsigned int node; |
| 92 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 93 | udelay(vid->init_delay); |
| 94 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 95 | exynos_backlight_reset(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 96 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 97 | exynos_cfg_lcd_gpio(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 98 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 99 | exynos_lcd_power_on(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 100 | |
| 101 | udelay(vid->power_on_delay); |
| 102 | |
Donghwa Lee | bc72aeb | 2012-07-02 01:16:08 +0000 | [diff] [blame] | 103 | if (vid->dp_enabled) |
| 104 | exynos_init_dp(); |
| 105 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 106 | exynos_reset_lcd(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 107 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 108 | udelay(vid->reset_delay); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 109 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 110 | exynos_backlight_on(1); |
| 111 | |
Ajay Kumar | 39ea08b | 2015-03-04 19:05:26 +0530 | [diff] [blame] | 112 | node = fdtdec_next_compatible(gd->fdt_blob, 0, |
| 113 | COMPAT_SAMSUNG_EXYNOS_FIMD); |
| 114 | if (node <= 0) { |
| 115 | debug("FIMD: Can't get device node for FIMD\n"); |
| 116 | return; |
| 117 | } |
| 118 | gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,pwm-out-gpio", |
| 119 | 0, &pwm_out_gpio, |
| 120 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 121 | |
| 122 | gpio_request_by_name_nodev(gd->fdt_blob, node, "samsung,bl-en-gpio", 0, |
| 123 | &bl_en_gpio, |
| 124 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 125 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 126 | exynos_cfg_ldo(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 127 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 128 | exynos_enable_ldo(1); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 129 | |
| 130 | if (vid->mipi_enabled) |
| 131 | exynos_mipi_dsi_init(); |
| 132 | } |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 133 | |
Ajay Kumar | 1176348 | 2014-09-05 16:53:30 +0530 | [diff] [blame] | 134 | int exynos_lcd_early_init(const void *blob) |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 135 | { |
| 136 | unsigned int node; |
| 137 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD); |
| 138 | if (node <= 0) { |
| 139 | debug("exynos_fb: Can't get device node for fimd\n"); |
| 140 | return -ENODEV; |
| 141 | } |
| 142 | |
| 143 | panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0); |
| 144 | if (panel_info.vl_col == 0) { |
| 145 | debug("Can't get XRES\n"); |
| 146 | return -ENXIO; |
| 147 | } |
| 148 | |
| 149 | panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0); |
| 150 | if (panel_info.vl_row == 0) { |
| 151 | debug("Can't get YRES\n"); |
| 152 | return -ENXIO; |
| 153 | } |
| 154 | |
| 155 | panel_info.vl_width = fdtdec_get_int(blob, node, |
| 156 | "samsung,vl-width", 0); |
| 157 | |
| 158 | panel_info.vl_height = fdtdec_get_int(blob, node, |
| 159 | "samsung,vl-height", 0); |
| 160 | |
| 161 | panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0); |
| 162 | if (panel_info.vl_freq == 0) { |
| 163 | debug("Can't get refresh rate\n"); |
| 164 | return -ENXIO; |
| 165 | } |
| 166 | |
| 167 | if (fdtdec_get_bool(blob, node, "samsung,vl-clkp")) |
| 168 | panel_info.vl_clkp = CONFIG_SYS_LOW; |
| 169 | |
| 170 | if (fdtdec_get_bool(blob, node, "samsung,vl-oep")) |
| 171 | panel_info.vl_oep = CONFIG_SYS_LOW; |
| 172 | |
| 173 | if (fdtdec_get_bool(blob, node, "samsung,vl-hsp")) |
| 174 | panel_info.vl_hsp = CONFIG_SYS_LOW; |
| 175 | |
| 176 | if (fdtdec_get_bool(blob, node, "samsung,vl-vsp")) |
| 177 | panel_info.vl_vsp = CONFIG_SYS_LOW; |
| 178 | |
| 179 | if (fdtdec_get_bool(blob, node, "samsung,vl-dp")) |
| 180 | panel_info.vl_dp = CONFIG_SYS_LOW; |
| 181 | |
| 182 | panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0); |
| 183 | if (panel_info.vl_bpix == 0) { |
| 184 | debug("Can't get bits per pixel\n"); |
| 185 | return -ENXIO; |
| 186 | } |
| 187 | |
| 188 | panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0); |
| 189 | if (panel_info.vl_hspw == 0) { |
| 190 | debug("Can't get hsync width\n"); |
| 191 | return -ENXIO; |
| 192 | } |
| 193 | |
| 194 | panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0); |
| 195 | if (panel_info.vl_hfpd == 0) { |
| 196 | debug("Can't get right margin\n"); |
| 197 | return -ENXIO; |
| 198 | } |
| 199 | |
| 200 | panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node, |
| 201 | "samsung,vl-hbpd", 0); |
| 202 | if (panel_info.vl_hbpd == 0) { |
| 203 | debug("Can't get left margin\n"); |
| 204 | return -ENXIO; |
| 205 | } |
| 206 | |
| 207 | panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node, |
| 208 | "samsung,vl-vspw", 0); |
| 209 | if (panel_info.vl_vspw == 0) { |
| 210 | debug("Can't get vsync width\n"); |
| 211 | return -ENXIO; |
| 212 | } |
| 213 | |
| 214 | panel_info.vl_vfpd = fdtdec_get_int(blob, node, |
| 215 | "samsung,vl-vfpd", 0); |
| 216 | if (panel_info.vl_vfpd == 0) { |
| 217 | debug("Can't get lower margin\n"); |
| 218 | return -ENXIO; |
| 219 | } |
| 220 | |
| 221 | panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0); |
| 222 | if (panel_info.vl_vbpd == 0) { |
| 223 | debug("Can't get upper margin\n"); |
| 224 | return -ENXIO; |
| 225 | } |
| 226 | |
| 227 | panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node, |
| 228 | "samsung,vl-cmd-allow-len", 0); |
| 229 | |
| 230 | panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0); |
| 231 | panel_info.init_delay = fdtdec_get_int(blob, node, |
| 232 | "samsung,init-delay", 0); |
| 233 | panel_info.power_on_delay = fdtdec_get_int(blob, node, |
| 234 | "samsung,power-on-delay", 0); |
| 235 | panel_info.reset_delay = fdtdec_get_int(blob, node, |
| 236 | "samsung,reset-delay", 0); |
| 237 | panel_info.interface_mode = fdtdec_get_int(blob, node, |
| 238 | "samsung,interface-mode", 0); |
| 239 | panel_info.mipi_enabled = fdtdec_get_int(blob, node, |
| 240 | "samsung,mipi-enabled", 0); |
| 241 | panel_info.dp_enabled = fdtdec_get_int(blob, node, |
| 242 | "samsung,dp-enabled", 0); |
| 243 | panel_info.cs_setup = fdtdec_get_int(blob, node, |
| 244 | "samsung,cs-setup", 0); |
| 245 | panel_info.wr_setup = fdtdec_get_int(blob, node, |
| 246 | "samsung,wr-setup", 0); |
| 247 | panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0); |
| 248 | panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0); |
| 249 | |
| 250 | panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0); |
| 251 | if (panel_info.logo_on) { |
| 252 | panel_info.logo_width = fdtdec_get_int(blob, node, |
| 253 | "samsung,logo-width", 0); |
| 254 | panel_info.logo_height = fdtdec_get_int(blob, node, |
| 255 | "samsung,logo-height", 0); |
| 256 | panel_info.logo_addr = fdtdec_get_int(blob, node, |
| 257 | "samsung,logo-addr", 0); |
| 258 | } |
| 259 | |
| 260 | panel_info.rgb_mode = fdtdec_get_int(blob, node, |
| 261 | "samsung,rgb-mode", 0); |
| 262 | panel_info.pclk_name = fdtdec_get_int(blob, node, |
| 263 | "samsung,pclk-name", 0); |
| 264 | panel_info.sclk_div = fdtdec_get_int(blob, node, |
| 265 | "samsung,sclk-div", 0); |
| 266 | panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node, |
| 267 | "samsung,dual-lcd-enabled", 0); |
| 268 | |
| 269 | return 0; |
| 270 | } |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 271 | |
| 272 | void lcd_ctrl_init(void *lcdbase) |
| 273 | { |
| 274 | set_system_display_ctrl(); |
| 275 | set_lcd_clk(); |
| 276 | |
Piotr Wilczek | 386fd02 | 2014-03-07 14:59:40 +0100 | [diff] [blame] | 277 | #ifdef CONFIG_EXYNOS_MIPI_DSIM |
| 278 | exynos_init_dsim_platform_data(&panel_info); |
| 279 | #endif |
| 280 | exynos_lcd_misc_init(&panel_info); |
Piotr Wilczek | 386fd02 | 2014-03-07 14:59:40 +0100 | [diff] [blame] | 281 | |
Simon Glass | 4d022cc | 2016-02-21 21:08:41 -0700 | [diff] [blame] | 282 | exynos_lcd_init(&panel_info, (ulong)lcdbase); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void lcd_enable(void) |
| 286 | { |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 287 | if (panel_info.logo_on) { |
Simon Glass | 860ef00 | 2016-02-21 21:08:43 -0700 | [diff] [blame^] | 288 | memset((void *)gd->fb_base, 0, |
| 289 | panel_info.vl_width * panel_info.vl_height * |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 290 | (NBITS(panel_info.vl_bpix) >> 3)); |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 293 | lcd_panel_on(&panel_info); |
| 294 | } |
| 295 | |
| 296 | /* dummy function */ |
| 297 | void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) |
| 298 | { |
| 299 | return; |
| 300 | } |