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