Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 16 | #include <arch/io.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 17 | #include <boot/tables.h> |
| 18 | #include <cbmem.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 19 | #include <console/console.h> |
| 20 | #include <cpu/cpu.h> |
| 21 | #include <delay.h> |
| 22 | #include <device/device.h> |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 23 | #include <edid.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 24 | #include <lib.h> |
| 25 | #include <soc/addressmap.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 26 | #include <soc/clock.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 27 | #include <soc/display.h> |
| 28 | #include <soc/sdram.h> |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 29 | #include <soc/nvidia/tegra/dc.h> |
Andrew Chew | 7f0cb15 | 2014-02-10 16:44:18 -0800 | [diff] [blame] | 30 | #include <soc/nvidia/tegra/pwm.h> |
Julius Werner | f0d21ff3 | 2014-10-20 13:24:14 -0700 | [diff] [blame] | 31 | #include <stdint.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 36 | #include "chip.h" |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 37 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 38 | struct tegra_dc dc_data; |
| 39 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 40 | int dump = 0; |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 41 | unsigned long READL(void *p) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 42 | { |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame^] | 43 | unsigned long value; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * In case of hard hung on readl(p), we can set dump > 1 to print out |
| 47 | * the address accessed. |
| 48 | */ |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame^] | 49 | if (dump > 1) |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 50 | printk(BIOS_SPEW, "readl %p\n", p); |
| 51 | |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame^] | 52 | value = read32(p); |
| 53 | if (dump) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 54 | printk(BIOS_SPEW, "readl %p %08lx\n", p, value); |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame^] | 55 | return value; |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 56 | } |
| 57 | |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 58 | void WRITEL(unsigned long value, void *p) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 59 | { |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame^] | 60 | if (dump) |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 61 | printk(BIOS_SPEW, "writel %p %08lx\n", p, value); |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame^] | 62 | write32(p, value); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 63 | } |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 64 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 65 | /* return in 1000ths of a Hertz */ |
| 66 | static int tegra_dc_calc_refresh(const struct soc_nvidia_tegra124_config *config) |
| 67 | { |
| 68 | int h_total, v_total, refresh; |
| 69 | int pclk = config->pixel_clock; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 70 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 71 | h_total = config->xres + config->hfront_porch + config->hback_porch + |
| 72 | config->hsync_width; |
| 73 | v_total = config->yres + config->vfront_porch + config->vback_porch + |
| 74 | config->vsync_width; |
| 75 | if (!pclk || !h_total || !v_total) |
| 76 | return 0; |
| 77 | refresh = pclk / h_total; |
| 78 | refresh *= 1000; |
| 79 | refresh /= v_total; |
| 80 | return refresh; |
| 81 | } |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 82 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 83 | static void print_mode(const struct soc_nvidia_tegra124_config *config) |
| 84 | { |
| 85 | if (config) { |
| 86 | int refresh = tegra_dc_calc_refresh(config); |
| 87 | printk(BIOS_ERR, |
| 88 | "MODE:%dx%d@%d.%03uHz pclk=%d\n", |
| 89 | config->xres, config->yres, |
| 90 | refresh / 1000, refresh % 1000, |
| 91 | config->pixel_clock); |
| 92 | } |
| 93 | } |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 94 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 95 | static int update_display_mode(struct display_controller *disp_ctrl, |
Julius Werner | edf6b57 | 2013-10-25 17:49:26 -0700 | [diff] [blame] | 96 | struct soc_nvidia_tegra124_config *config) |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 97 | { |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 98 | print_mode(config); |
| 99 | |
| 100 | WRITEL(0x1, &disp_ctrl->disp.disp_timing_opt); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 101 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 102 | WRITEL(config->vref_to_sync << 16 | config->href_to_sync, |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 103 | &disp_ctrl->disp.ref_to_sync); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 104 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 105 | WRITEL(config->vsync_width << 16 | config->hsync_width, |
| 106 | &disp_ctrl->disp.sync_width); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 107 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 108 | WRITEL(((config->vback_porch - config->vref_to_sync) << 16) | config->hback_porch, |
| 109 | &disp_ctrl->disp.back_porch); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 110 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 111 | WRITEL(((config->vfront_porch + config->vref_to_sync) << 16) | config->hfront_porch, |
| 112 | &disp_ctrl->disp.front_porch); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 113 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 114 | WRITEL(config->xres | (config->yres << 16), |
| 115 | &disp_ctrl->disp.disp_active); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 116 | |
Hung-Te Lin | 1a8e0af | 2014-04-08 20:03:40 +0800 | [diff] [blame] | 117 | /** |
| 118 | * We want to use PLLD_out0, which is PLLD / 2: |
| 119 | * PixelClock = (PLLD / 2) / ShiftClockDiv / PixelClockDiv. |
| 120 | * |
| 121 | * Currently most panels work inside clock range 50MHz~100MHz, and PLLD |
| 122 | * has some requirements to have VCO in range 500MHz~1000MHz (see |
| 123 | * clock.c for more detail). To simplify calculation, we set |
Ken Chang | cbae0de | 2014-04-18 13:52:48 +0800 | [diff] [blame] | 124 | * PixelClockDiv to 1 and ShiftClockDiv to 1. In future these values |
Hung-Te Lin | 1a8e0af | 2014-04-08 20:03:40 +0800 | [diff] [blame] | 125 | * may be calculated by clock_display, to allow wider frequency range. |
| 126 | * |
| 127 | * Note ShiftClockDiv is a 7.1 format value. |
| 128 | */ |
Ken Chang | cbae0de | 2014-04-18 13:52:48 +0800 | [diff] [blame] | 129 | const u32 shift_clock_div = 1; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 130 | WRITEL((PIXEL_CLK_DIVIDER_PCD1 << PIXEL_CLK_DIVIDER_SHIFT) | |
Hung-Te Lin | 1a8e0af | 2014-04-08 20:03:40 +0800 | [diff] [blame] | 131 | ((shift_clock_div - 1) * 2) << SHIFT_CLK_DIVIDER_SHIFT, |
| 132 | &disp_ctrl->disp.disp_clk_ctrl); |
| 133 | printk(BIOS_DEBUG, "%s: PixelClock=%u, ShiftClockDiv=%u\n", |
| 134 | __func__, config->pixel_clock, shift_clock_div); |
Vince Hsu | c09642e | 2014-05-16 12:46:02 +0800 | [diff] [blame] | 135 | return 0; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 138 | static void update_window(struct display_controller *disp_ctrl, |
| 139 | struct soc_nvidia_tegra124_config *config) |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 140 | { |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 141 | u32 val; |
| 142 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 143 | WRITEL(WINDOW_A_SELECT, &disp_ctrl->cmd.disp_win_header); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 144 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 145 | WRITEL(((config->yres << 16) | config->xres), &disp_ctrl->win.size); |
| 146 | WRITEL(((config->yres << 16) | |
| 147 | (config->xres * config->framebuffer_bits_per_pixel / 8)), |
| 148 | &disp_ctrl->win.prescaled_size); |
| 149 | WRITEL(((config->xres * config->framebuffer_bits_per_pixel / 8 + 31) / |
| 150 | 32 * 32), &disp_ctrl->win.line_stride); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 151 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 152 | WRITEL(config->color_depth, &disp_ctrl->win.color_depth); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 153 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 154 | WRITEL(config->framebuffer_base, &disp_ctrl->winbuf.start_addr); |
| 155 | WRITEL((V_DDA_INC(0x1000) | H_DDA_INC(0x1000)), &disp_ctrl->win.dda_increment); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 156 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 157 | WRITEL(COLOR_WHITE, &disp_ctrl->disp.blend_background_color); |
| 158 | WRITEL(DISP_CTRL_MODE_C_DISPLAY, &disp_ctrl->cmd.disp_cmd); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 159 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 160 | WRITEL(WRITE_MUX_ACTIVE, &disp_ctrl->cmd.state_access); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 161 | |
| 162 | val = GENERAL_ACT_REQ | WIN_A_ACT_REQ; |
| 163 | val |= GENERAL_UPDATE | WIN_A_UPDATE; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 164 | WRITEL(val, &disp_ctrl->cmd.state_ctrl); |
| 165 | |
| 166 | // Enable win_a |
| 167 | val = READL(&disp_ctrl->win.win_opt); |
| 168 | WRITEL(val | WIN_ENABLE, &disp_ctrl->win.win_opt); |
| 169 | } |
| 170 | |
| 171 | static int tegra_dc_init(struct display_controller *disp_ctrl) |
| 172 | { |
| 173 | /* do not accept interrupts during initialization */ |
| 174 | WRITEL(0x00000000, &disp_ctrl->cmd.int_mask); |
| 175 | WRITEL(WRITE_MUX_ASSEMBLY | READ_MUX_ASSEMBLY, |
| 176 | &disp_ctrl->cmd.state_access); |
| 177 | WRITEL(WINDOW_A_SELECT, &disp_ctrl->cmd.disp_win_header); |
| 178 | WRITEL(0x00000000, &disp_ctrl->win.win_opt); |
| 179 | WRITEL(0x00000000, &disp_ctrl->win.byte_swap); |
| 180 | WRITEL(0x00000000, &disp_ctrl->win.buffer_ctrl); |
| 181 | |
| 182 | WRITEL(0x00000000, &disp_ctrl->win.pos); |
| 183 | WRITEL(0x00000000, &disp_ctrl->win.h_initial_dda); |
| 184 | WRITEL(0x00000000, &disp_ctrl->win.v_initial_dda); |
| 185 | WRITEL(0x00000000, &disp_ctrl->win.dda_increment); |
| 186 | WRITEL(0x00000000, &disp_ctrl->win.dv_ctrl); |
| 187 | |
| 188 | WRITEL(0x01000000, &disp_ctrl->win.blend_layer_ctrl); |
| 189 | WRITEL(0x00000000, &disp_ctrl->win.blend_match_select); |
| 190 | WRITEL(0x00000000, &disp_ctrl->win.blend_nomatch_select); |
| 191 | WRITEL(0x00000000, &disp_ctrl->win.blend_alpha_1bit); |
| 192 | |
| 193 | WRITEL(0x00000000, &disp_ctrl->winbuf.start_addr_hi); |
| 194 | WRITEL(0x00000000, &disp_ctrl->winbuf.addr_h_offset); |
| 195 | WRITEL(0x00000000, &disp_ctrl->winbuf.addr_v_offset); |
| 196 | |
| 197 | WRITEL(0x00000000, &disp_ctrl->com.crc_checksum); |
| 198 | WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[0]); |
| 199 | WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[1]); |
| 200 | WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[2]); |
| 201 | WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[3]); |
| 202 | WRITEL(0x00000000, &disp_ctrl->disp.disp_signal_opt0); |
| 203 | |
| 204 | return 0; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 207 | uint32_t fb_base_mb(void) |
| 208 | { |
Gabe Black | 5cbbc70 | 2014-02-08 05:17:38 -0800 | [diff] [blame] | 209 | return sdram_max_addressable_mb() - FB_SIZE_MB; |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 212 | /* this is really aimed at the lcd panel. That said, there are two display |
| 213 | * devices on this part and we may someday want to extend it for other boards. |
| 214 | */ |
Elyes HAOUAS | 3fcb218 | 2018-05-25 10:03:57 +0200 | [diff] [blame] | 215 | void display_startup(struct device *dev) |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 216 | { |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 217 | struct soc_nvidia_tegra124_config *config = dev->chip_info; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 218 | struct display_controller *disp_ctrl = (void *)config->display_controller; |
Elyes HAOUAS | 05498a2 | 2018-05-28 16:26:43 +0200 | [diff] [blame] | 219 | struct pwm_controller *pwm = (void *)TEGRA_PWM_BASE; |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 220 | struct tegra_dc *dc = &dc_data; |
Vince Hsu | 1e3679d | 2014-06-11 17:14:05 +0800 | [diff] [blame] | 221 | u32 plld_rate; |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 222 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 223 | /* init dc */ |
| 224 | dc->base = (void *)TEGRA_ARM_DISPLAYA; |
| 225 | dc->config = config; |
| 226 | config->dc_data = dc; |
| 227 | |
Hung-Te Lin | 3af0d31 | 2014-04-02 21:57:40 +0800 | [diff] [blame] | 228 | /* Note dp_init may read EDID and change some config values. */ |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 229 | dp_init(config); |
| 230 | |
Hung-Te Lin | 3af0d31 | 2014-04-02 21:57:40 +0800 | [diff] [blame] | 231 | /* should probably just make it all MiB ... in future */ |
| 232 | u32 framebuffer_size_mb = config->framebuffer_size / MiB; |
| 233 | u32 framebuffer_base_mb= config->framebuffer_base / MiB; |
| 234 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 235 | /* light it all up */ |
| 236 | /* This one may have been done in romstage but that's ok for now. */ |
| 237 | if (config->panel_vdd_gpio){ |
| 238 | gpio_output(config->panel_vdd_gpio, 1); |
| 239 | printk(BIOS_SPEW,"%s: panel_vdd setting gpio %08x to %d\n", |
| 240 | __func__, config->panel_vdd_gpio, 1); |
| 241 | } |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 242 | udelay(config->vdd_delay_ms * 1000); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 243 | if (config->backlight_vdd_gpio){ |
| 244 | gpio_output(config->backlight_vdd_gpio, 1); |
| 245 | printk(BIOS_SPEW,"%s: backlight vdd setting gpio %08x to %d\n", |
| 246 | __func__, config->backlight_vdd_gpio, 1); |
| 247 | } |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 248 | if (config->lvds_shutdown_gpio){ |
| 249 | gpio_output(config->lvds_shutdown_gpio, 0); |
| 250 | printk(BIOS_SPEW,"%s: lvds shutdown setting gpio %08x to %d\n", |
| 251 | __func__, config->lvds_shutdown_gpio, 0); |
| 252 | } |
Andrew Chew | 7f0cb15 | 2014-02-10 16:44:18 -0800 | [diff] [blame] | 253 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 254 | if (framebuffer_size_mb == 0){ |
| 255 | framebuffer_size_mb = ALIGN_UP(config->xres * config->yres * |
| 256 | (config->framebuffer_bits_per_pixel / 8), MiB)/MiB; |
| 257 | } |
| 258 | |
| 259 | if (! framebuffer_base_mb) |
Tom Warren | 64982c50 | 2014-01-23 13:37:50 -0700 | [diff] [blame] | 260 | framebuffer_base_mb = fb_base_mb(); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 261 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 262 | config->framebuffer_size = framebuffer_size_mb * MiB; |
| 263 | config->framebuffer_base = framebuffer_base_mb * MiB; |
| 264 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 265 | mmu_config_range(framebuffer_base_mb, framebuffer_size_mb, |
Aaron Durbin | 9cbc90a | 2016-07-25 11:30:43 -0500 | [diff] [blame] | 266 | DCACHE_WRITETHROUGH); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 267 | |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 268 | printk(BIOS_SPEW, "LCD frame buffer at %dMiB to %dMiB\n", framebuffer_base_mb, |
| 269 | framebuffer_base_mb + framebuffer_size_mb); |
| 270 | |
| 271 | /* GPIO magic here if needed to start powering up things. You |
| 272 | * really only want to enable vdd, wait a bit, and then enable |
| 273 | * the panel. However ... the timings in the tegra20 dts make |
| 274 | * no sense to me. I'm pretty sure they're wrong. |
| 275 | * The panel_vdd is done in the romstage, so we need only |
| 276 | * light things up here once we're sure it's all working. |
| 277 | */ |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 278 | |
Vince Hsu | c09642e | 2014-05-16 12:46:02 +0800 | [diff] [blame] | 279 | /* The plld is programmed with the assumption of the SHIFT_CLK_DIVIDER |
| 280 | * and PIXEL_CLK_DIVIDER are zero (divide by 1). See the |
| 281 | * update_display_mode() for detail. |
| 282 | */ |
Vince Hsu | 1e3679d | 2014-06-11 17:14:05 +0800 | [diff] [blame] | 283 | plld_rate = clock_display(config->pixel_clock * 2); |
| 284 | if (plld_rate == 0) { |
Vince Hsu | c09642e | 2014-05-16 12:46:02 +0800 | [diff] [blame] | 285 | printk(BIOS_ERR, "dc: clock init failed\n"); |
| 286 | return; |
Vince Hsu | 1e3679d | 2014-06-11 17:14:05 +0800 | [diff] [blame] | 287 | } else if (plld_rate != config->pixel_clock * 2) { |
| 288 | printk(BIOS_WARNING, "dc: plld rounded to %u\n", plld_rate); |
| 289 | config->pixel_clock = plld_rate / 2; |
| 290 | } |
Vince Hsu | c09642e | 2014-05-16 12:46:02 +0800 | [diff] [blame] | 291 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 292 | /* Init dc */ |
| 293 | if (tegra_dc_init(disp_ctrl)) { |
| 294 | printk(BIOS_ERR, "dc: init failed\n"); |
| 295 | return; |
| 296 | } |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 297 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 298 | /* Configure dc mode */ |
Hung-Te Lin | 1a8e0af | 2014-04-08 20:03:40 +0800 | [diff] [blame] | 299 | if (update_display_mode(disp_ctrl, config)) { |
| 300 | printk(BIOS_ERR, "dc: failed to configure display mode.\n"); |
| 301 | return; |
| 302 | } |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 303 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 304 | /* Enable dp */ |
| 305 | dp_enable(dc->out); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 306 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 307 | /* Init frame buffer */ |
Andrew Bresticker | 24d4f7f | 2013-12-18 22:41:34 -0800 | [diff] [blame] | 308 | memset((void *)(framebuffer_base_mb*MiB), 0x00, |
| 309 | framebuffer_size_mb*MiB); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 310 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 311 | update_window(disp_ctrl, config); |
| 312 | |
Ken Chang | 5a056d3 | 2014-04-22 12:55:00 +0800 | [diff] [blame] | 313 | /* Set up Tegra PWM n (where n is specified in config->pwm) to drive the |
| 314 | * panel backlight. |
| 315 | */ |
| 316 | printk(BIOS_SPEW, "%s: enable panel backlight pwm\n", __func__); |
| 317 | WRITEL(((1 << NV_PWM_CSR_ENABLE_SHIFT) | |
| 318 | (220 << NV_PWM_CSR_PULSE_WIDTH_SHIFT) | /* 220/256 */ |
| 319 | 0x02e), /* frequency divider */ |
| 320 | &pwm->pwm[config->pwm].csr); |
| 321 | |
| 322 | udelay(config->pwm_to_bl_delay_ms * 1000); |
| 323 | if (config->backlight_en_gpio){ |
| 324 | gpio_output(config->backlight_en_gpio, 1); |
| 325 | printk(BIOS_SPEW,"%s: backlight enable setting gpio %08x to %d\n", |
| 326 | __func__, config->backlight_en_gpio, 1); |
| 327 | } |
| 328 | |
Jimmy Zhang | bd5925a | 2014-03-10 12:42:05 -0700 | [diff] [blame] | 329 | printk(BIOS_INFO, "%s: display init done.\n", __func__); |
| 330 | |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 331 | /* tell depthcharge ... |
| 332 | */ |
| 333 | struct edid edid; |
Julius Werner | 6911219 | 2016-03-14 17:29:55 -0700 | [diff] [blame] | 334 | edid.mode.va = config->yres; |
| 335 | edid.mode.ha = config->xres; |
| 336 | edid_set_framebuffer_bits_per_pixel(&edid, |
Paul Kocialkowski | bc141de | 2016-05-14 15:25:51 +0200 | [diff] [blame] | 337 | config->framebuffer_bits_per_pixel, 32); |
Hung-Te Lin | 2fc3b62 | 2013-10-21 21:43:03 +0800 | [diff] [blame] | 338 | set_vbe_mode_info_valid(&edid, (uintptr_t)(framebuffer_base_mb*MiB)); |
Gabe Black | d40be11 | 2013-10-09 23:45:07 -0700 | [diff] [blame] | 339 | } |