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 | * |
| 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 | |
| 23 | #include <config.h> |
| 24 | #include <common.h> |
| 25 | #include <lcd.h> |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 26 | #include <fdtdec.h> |
| 27 | #include <libfdt.h> |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 28 | #include <asm/io.h> |
| 29 | #include <asm/arch/cpu.h> |
| 30 | #include <asm/arch/clock.h> |
| 31 | #include <asm/arch/clk.h> |
| 32 | #include <asm/arch/mipi_dsim.h> |
Donghwa Lee | bc72aeb | 2012-07-02 01:16:08 +0000 | [diff] [blame] | 33 | #include <asm/arch/dp_info.h> |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 34 | #include <asm/arch/system.h> |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 35 | #include <asm-generic/errno.h> |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 36 | |
| 37 | #include "exynos_fb.h" |
| 38 | |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 41 | static unsigned int panel_width, panel_height; |
| 42 | |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 43 | /* |
| 44 | * board_init_f(arch/arm/lib/board.c) calls lcd_setmem() which needs |
| 45 | * panel_info.vl_col, panel_info.vl_row and panel_info.vl_bpix to reserve |
| 46 | * FB memory at a very early stage, i.e even before exynos_fimd_parse_dt() |
| 47 | * is called. So, we are forced to statically assign it. |
| 48 | */ |
| 49 | #ifdef CONFIG_OF_CONTROL |
| 50 | vidinfo_t panel_info = { |
| 51 | .vl_col = LCD_XRES, |
| 52 | .vl_row = LCD_YRES, |
| 53 | .vl_bpix = LCD_COLOR16, |
| 54 | }; |
| 55 | #endif |
| 56 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 57 | static void exynos_lcd_init_mem(void *lcdbase, vidinfo_t *vid) |
| 58 | { |
| 59 | unsigned long palette_size; |
| 60 | unsigned int fb_size; |
| 61 | |
Donghwa Lee | 2386f45 | 2012-04-23 15:37:05 +0000 | [diff] [blame] | 62 | fb_size = vid->vl_row * vid->vl_col * (NBITS(vid->vl_bpix) >> 3); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 63 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 64 | palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16; |
| 65 | |
Jeroen Hofstee | 881c4ec | 2013-01-22 10:44:12 +0000 | [diff] [blame] | 66 | exynos_fimd_lcd_init_mem((unsigned long)lcdbase, |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 67 | (unsigned long)fb_size, palette_size); |
| 68 | } |
| 69 | |
| 70 | static void exynos_lcd_init(vidinfo_t *vid) |
| 71 | { |
| 72 | exynos_fimd_lcd_init(vid); |
Ćukasz Majewski | 43905f4 | 2013-01-08 03:48:40 +0000 | [diff] [blame] | 73 | |
| 74 | /* Enable flushing after LCD writes if requested */ |
| 75 | lcd_set_flush_dcache(1); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Ajay Kumar | 6c6a822 | 2013-01-13 23:32:16 +0000 | [diff] [blame] | 78 | #ifdef CONFIG_CMD_BMP |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 79 | static void draw_logo(void) |
| 80 | { |
| 81 | int x, y; |
| 82 | ulong addr; |
| 83 | |
Piotr Wilczek | 79c40e6 | 2012-10-19 05:34:06 +0000 | [diff] [blame] | 84 | if (panel_width >= panel_info.logo_width) { |
| 85 | x = ((panel_width - panel_info.logo_width) >> 1); |
| 86 | } else { |
| 87 | x = 0; |
| 88 | printf("Warning: image width is bigger than display width\n"); |
| 89 | } |
| 90 | |
| 91 | if (panel_height >= panel_info.logo_height) { |
| 92 | y = ((panel_height - panel_info.logo_height) >> 1) - 4; |
| 93 | } else { |
| 94 | y = 0; |
| 95 | printf("Warning: image height is bigger than display height\n"); |
| 96 | } |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 97 | |
| 98 | addr = panel_info.logo_addr; |
| 99 | bmp_display(addr, x, y); |
| 100 | } |
Ajay Kumar | 6c6a822 | 2013-01-13 23:32:16 +0000 | [diff] [blame] | 101 | #endif |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 102 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 103 | void __exynos_cfg_lcd_gpio(void) |
| 104 | { |
| 105 | } |
| 106 | void exynos_cfg_lcd_gpio(void) |
| 107 | __attribute__((weak, alias("__exynos_cfg_lcd_gpio"))); |
| 108 | |
| 109 | void __exynos_backlight_on(unsigned int onoff) |
| 110 | { |
| 111 | } |
| 112 | void exynos_backlight_on(unsigned int onoff) |
| 113 | __attribute__((weak, alias("__exynos_cfg_lcd_gpio"))); |
| 114 | |
| 115 | void __exynos_reset_lcd(void) |
| 116 | { |
| 117 | } |
| 118 | void exynos_reset_lcd(void) |
| 119 | __attribute__((weak, alias("__exynos_reset_lcd"))); |
| 120 | |
| 121 | void __exynos_lcd_power_on(void) |
| 122 | { |
| 123 | } |
| 124 | void exynos_lcd_power_on(void) |
| 125 | __attribute__((weak, alias("__exynos_lcd_power_on"))); |
| 126 | |
| 127 | void __exynos_cfg_ldo(void) |
| 128 | { |
| 129 | } |
| 130 | void exynos_cfg_ldo(void) |
| 131 | __attribute__((weak, alias("__exynos_cfg_ldo"))); |
| 132 | |
| 133 | void __exynos_enable_ldo(unsigned int onoff) |
| 134 | { |
| 135 | } |
| 136 | void exynos_enable_ldo(unsigned int onoff) |
| 137 | __attribute__((weak, alias("__exynos_enable_ldo"))); |
| 138 | |
| 139 | void __exynos_backlight_reset(void) |
| 140 | { |
| 141 | } |
| 142 | void exynos_backlight_reset(void) |
| 143 | __attribute__((weak, alias("__exynos_backlight_reset"))); |
| 144 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 145 | static void lcd_panel_on(vidinfo_t *vid) |
| 146 | { |
| 147 | udelay(vid->init_delay); |
| 148 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 149 | exynos_backlight_reset(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 150 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 151 | exynos_cfg_lcd_gpio(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 152 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 153 | exynos_lcd_power_on(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 154 | |
| 155 | udelay(vid->power_on_delay); |
| 156 | |
Donghwa Lee | bc72aeb | 2012-07-02 01:16:08 +0000 | [diff] [blame] | 157 | if (vid->dp_enabled) |
| 158 | exynos_init_dp(); |
| 159 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 160 | exynos_reset_lcd(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 161 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 162 | udelay(vid->reset_delay); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 163 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 164 | exynos_backlight_on(1); |
| 165 | |
| 166 | exynos_cfg_ldo(); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 167 | |
Ajay Kumar | 41022a1 | 2013-02-21 23:52:57 +0000 | [diff] [blame] | 168 | exynos_enable_ldo(1); |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 169 | |
| 170 | if (vid->mipi_enabled) |
| 171 | exynos_mipi_dsi_init(); |
| 172 | } |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 173 | |
| 174 | #ifdef CONFIG_OF_CONTROL |
| 175 | int exynos_fimd_parse_dt(const void *blob) |
| 176 | { |
| 177 | unsigned int node; |
| 178 | node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_FIMD); |
| 179 | if (node <= 0) { |
| 180 | debug("exynos_fb: Can't get device node for fimd\n"); |
| 181 | return -ENODEV; |
| 182 | } |
| 183 | |
| 184 | panel_info.vl_col = fdtdec_get_int(blob, node, "samsung,vl-col", 0); |
| 185 | if (panel_info.vl_col == 0) { |
| 186 | debug("Can't get XRES\n"); |
| 187 | return -ENXIO; |
| 188 | } |
| 189 | |
| 190 | panel_info.vl_row = fdtdec_get_int(blob, node, "samsung,vl-row", 0); |
| 191 | if (panel_info.vl_row == 0) { |
| 192 | debug("Can't get YRES\n"); |
| 193 | return -ENXIO; |
| 194 | } |
| 195 | |
| 196 | panel_info.vl_width = fdtdec_get_int(blob, node, |
| 197 | "samsung,vl-width", 0); |
| 198 | |
| 199 | panel_info.vl_height = fdtdec_get_int(blob, node, |
| 200 | "samsung,vl-height", 0); |
| 201 | |
| 202 | panel_info.vl_freq = fdtdec_get_int(blob, node, "samsung,vl-freq", 0); |
| 203 | if (panel_info.vl_freq == 0) { |
| 204 | debug("Can't get refresh rate\n"); |
| 205 | return -ENXIO; |
| 206 | } |
| 207 | |
| 208 | if (fdtdec_get_bool(blob, node, "samsung,vl-clkp")) |
| 209 | panel_info.vl_clkp = CONFIG_SYS_LOW; |
| 210 | |
| 211 | if (fdtdec_get_bool(blob, node, "samsung,vl-oep")) |
| 212 | panel_info.vl_oep = CONFIG_SYS_LOW; |
| 213 | |
| 214 | if (fdtdec_get_bool(blob, node, "samsung,vl-hsp")) |
| 215 | panel_info.vl_hsp = CONFIG_SYS_LOW; |
| 216 | |
| 217 | if (fdtdec_get_bool(blob, node, "samsung,vl-vsp")) |
| 218 | panel_info.vl_vsp = CONFIG_SYS_LOW; |
| 219 | |
| 220 | if (fdtdec_get_bool(blob, node, "samsung,vl-dp")) |
| 221 | panel_info.vl_dp = CONFIG_SYS_LOW; |
| 222 | |
| 223 | panel_info.vl_bpix = fdtdec_get_int(blob, node, "samsung,vl-bpix", 0); |
| 224 | if (panel_info.vl_bpix == 0) { |
| 225 | debug("Can't get bits per pixel\n"); |
| 226 | return -ENXIO; |
| 227 | } |
| 228 | |
| 229 | panel_info.vl_hspw = fdtdec_get_int(blob, node, "samsung,vl-hspw", 0); |
| 230 | if (panel_info.vl_hspw == 0) { |
| 231 | debug("Can't get hsync width\n"); |
| 232 | return -ENXIO; |
| 233 | } |
| 234 | |
| 235 | panel_info.vl_hfpd = fdtdec_get_int(blob, node, "samsung,vl-hfpd", 0); |
| 236 | if (panel_info.vl_hfpd == 0) { |
| 237 | debug("Can't get right margin\n"); |
| 238 | return -ENXIO; |
| 239 | } |
| 240 | |
| 241 | panel_info.vl_hbpd = (u_char)fdtdec_get_int(blob, node, |
| 242 | "samsung,vl-hbpd", 0); |
| 243 | if (panel_info.vl_hbpd == 0) { |
| 244 | debug("Can't get left margin\n"); |
| 245 | return -ENXIO; |
| 246 | } |
| 247 | |
| 248 | panel_info.vl_vspw = (u_char)fdtdec_get_int(blob, node, |
| 249 | "samsung,vl-vspw", 0); |
| 250 | if (panel_info.vl_vspw == 0) { |
| 251 | debug("Can't get vsync width\n"); |
| 252 | return -ENXIO; |
| 253 | } |
| 254 | |
| 255 | panel_info.vl_vfpd = fdtdec_get_int(blob, node, |
| 256 | "samsung,vl-vfpd", 0); |
| 257 | if (panel_info.vl_vfpd == 0) { |
| 258 | debug("Can't get lower margin\n"); |
| 259 | return -ENXIO; |
| 260 | } |
| 261 | |
| 262 | panel_info.vl_vbpd = fdtdec_get_int(blob, node, "samsung,vl-vbpd", 0); |
| 263 | if (panel_info.vl_vbpd == 0) { |
| 264 | debug("Can't get upper margin\n"); |
| 265 | return -ENXIO; |
| 266 | } |
| 267 | |
| 268 | panel_info.vl_cmd_allow_len = fdtdec_get_int(blob, node, |
| 269 | "samsung,vl-cmd-allow-len", 0); |
| 270 | |
| 271 | panel_info.win_id = fdtdec_get_int(blob, node, "samsung,winid", 0); |
| 272 | panel_info.init_delay = fdtdec_get_int(blob, node, |
| 273 | "samsung,init-delay", 0); |
| 274 | panel_info.power_on_delay = fdtdec_get_int(blob, node, |
| 275 | "samsung,power-on-delay", 0); |
| 276 | panel_info.reset_delay = fdtdec_get_int(blob, node, |
| 277 | "samsung,reset-delay", 0); |
| 278 | panel_info.interface_mode = fdtdec_get_int(blob, node, |
| 279 | "samsung,interface-mode", 0); |
| 280 | panel_info.mipi_enabled = fdtdec_get_int(blob, node, |
| 281 | "samsung,mipi-enabled", 0); |
| 282 | panel_info.dp_enabled = fdtdec_get_int(blob, node, |
| 283 | "samsung,dp-enabled", 0); |
| 284 | panel_info.cs_setup = fdtdec_get_int(blob, node, |
| 285 | "samsung,cs-setup", 0); |
| 286 | panel_info.wr_setup = fdtdec_get_int(blob, node, |
| 287 | "samsung,wr-setup", 0); |
| 288 | panel_info.wr_act = fdtdec_get_int(blob, node, "samsung,wr-act", 0); |
| 289 | panel_info.wr_hold = fdtdec_get_int(blob, node, "samsung,wr-hold", 0); |
| 290 | |
| 291 | panel_info.logo_on = fdtdec_get_int(blob, node, "samsung,logo-on", 0); |
| 292 | if (panel_info.logo_on) { |
| 293 | panel_info.logo_width = fdtdec_get_int(blob, node, |
| 294 | "samsung,logo-width", 0); |
| 295 | panel_info.logo_height = fdtdec_get_int(blob, node, |
| 296 | "samsung,logo-height", 0); |
| 297 | panel_info.logo_addr = fdtdec_get_int(blob, node, |
| 298 | "samsung,logo-addr", 0); |
| 299 | } |
| 300 | |
| 301 | panel_info.rgb_mode = fdtdec_get_int(blob, node, |
| 302 | "samsung,rgb-mode", 0); |
| 303 | panel_info.pclk_name = fdtdec_get_int(blob, node, |
| 304 | "samsung,pclk-name", 0); |
| 305 | panel_info.sclk_div = fdtdec_get_int(blob, node, |
| 306 | "samsung,sclk-div", 0); |
| 307 | panel_info.dual_lcd_enabled = fdtdec_get_int(blob, node, |
| 308 | "samsung,dual-lcd-enabled", 0); |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | #endif |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 313 | |
| 314 | void lcd_ctrl_init(void *lcdbase) |
| 315 | { |
| 316 | set_system_display_ctrl(); |
| 317 | set_lcd_clk(); |
| 318 | |
Ajay Kumar | ebbace3 | 2013-02-21 23:53:01 +0000 | [diff] [blame] | 319 | #ifdef CONFIG_OF_CONTROL |
| 320 | if (exynos_fimd_parse_dt(gd->fdt_blob)) |
| 321 | debug("Can't get proper panel info\n"); |
| 322 | #endif |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 323 | /* initialize parameters which is specific to panel. */ |
| 324 | init_panel_info(&panel_info); |
| 325 | |
| 326 | panel_width = panel_info.vl_width; |
| 327 | panel_height = panel_info.vl_height; |
| 328 | |
| 329 | exynos_lcd_init_mem(lcdbase, &panel_info); |
| 330 | |
| 331 | exynos_lcd_init(&panel_info); |
| 332 | } |
| 333 | |
| 334 | void lcd_enable(void) |
| 335 | { |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 336 | if (panel_info.logo_on) { |
Jeroen Hofstee | 881c4ec | 2013-01-22 10:44:12 +0000 | [diff] [blame] | 337 | memset((void *) gd->fb_base, 0, panel_width * panel_height * |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 338 | (NBITS(panel_info.vl_bpix) >> 3)); |
Ajay Kumar | 6c6a822 | 2013-01-13 23:32:16 +0000 | [diff] [blame] | 339 | #ifdef CONFIG_CMD_BMP |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 340 | draw_logo(); |
Ajay Kumar | 6c6a822 | 2013-01-13 23:32:16 +0000 | [diff] [blame] | 341 | #endif |
Donghwa Lee | 37980dd | 2012-05-09 19:23:46 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Donghwa Lee | 0112fed | 2012-04-05 19:36:17 +0000 | [diff] [blame] | 344 | lcd_panel_on(&panel_info); |
| 345 | } |
| 346 | |
| 347 | /* dummy function */ |
| 348 | void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue) |
| 349 | { |
| 350 | return; |
| 351 | } |