blob: 0c54f7a304b16d7fe27b83562b1ad7d7d0d12919 [file] [log] [blame]
Angel Ponsa2ee7612020-04-04 18:51:15 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Elyes HAOUAS30818552019-06-23 07:03:59 +02002
Patrick Georgi40a3e322015-06-22 19:41:29 +02003#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +02005#include <stdint.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +02006#include <device/device.h>
7#include <soc/nvidia/tegra/dc.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +02008#include <soc/display.h>
Patrick Rudolph8b56c8c2020-02-19 12:57:00 +01009#include <framebuffer_info.h>
Patrick Georgi40a3e322015-06-22 19:41:29 +020010
Elyes HAOUAS30818552019-06-23 07:03:59 +020011#include "chip.h"
12
Patrick Georgi40a3e322015-06-22 19:41:29 +020013int dump = 0;
Elyes HAOUAS39303d52018-07-08 12:40:45 +020014unsigned long READL(void *p)
Patrick Georgi40a3e322015-06-22 19:41:29 +020015{
Elyes HAOUAS88607a42018-10-05 10:36:45 +020016 unsigned long value;
Patrick Georgi40a3e322015-06-22 19:41:29 +020017
18 /*
19 * In case of hard hung on readl(p), we can set dump > 1 to print out
20 * the address accessed.
21 */
Elyes HAOUAS88607a42018-10-05 10:36:45 +020022 if (dump > 1)
Patrick Georgi40a3e322015-06-22 19:41:29 +020023 printk(BIOS_SPEW, "readl %p\n", p);
24
Elyes HAOUAS88607a42018-10-05 10:36:45 +020025 value = read32(p);
26 if (dump)
Patrick Georgi40a3e322015-06-22 19:41:29 +020027 printk(BIOS_SPEW, "readl %p %08lx\n", p, value);
Elyes HAOUAS88607a42018-10-05 10:36:45 +020028 return value;
Patrick Georgi40a3e322015-06-22 19:41:29 +020029}
30
Elyes HAOUAS39303d52018-07-08 12:40:45 +020031void WRITEL(unsigned long value, void *p)
Patrick Georgi40a3e322015-06-22 19:41:29 +020032{
Elyes HAOUAS88607a42018-10-05 10:36:45 +020033 if (dump)
Patrick Georgi40a3e322015-06-22 19:41:29 +020034 printk(BIOS_SPEW, "writel %p %08lx\n", p, value);
Elyes HAOUAS88607a42018-10-05 10:36:45 +020035 write32(p, value);
Patrick Georgi40a3e322015-06-22 19:41:29 +020036}
37
38/* return in 1000ths of a Hertz */
39static int tegra_calc_refresh(const struct soc_nvidia_tegra210_config *config)
40{
41 int refresh;
42 int h_total = htotal(config);
43 int v_total = vtotal(config);
44 int pclk = config->pixel_clock;
45
46 if (!pclk || !h_total || !v_total)
47 return 0;
48 refresh = pclk / h_total;
49 refresh *= 1000;
50 refresh /= v_total;
51 return refresh;
52}
53
54static void print_mode(const struct soc_nvidia_tegra210_config *config)
55{
56 if (config) {
57 int refresh = tegra_calc_refresh(config);
58 printk(BIOS_ERR,
59 "Panel Mode: %dx%d@%d.%03uHz pclk=%d\n",
60 config->xres, config->yres,
61 refresh / 1000, refresh % 1000,
62 config->pixel_clock);
63 }
64}
65
66int update_display_mode(struct display_controller *disp_ctrl,
Elyes HAOUAS88607a42018-10-05 10:36:45 +020067 struct soc_nvidia_tegra210_config *config)
Patrick Georgi40a3e322015-06-22 19:41:29 +020068{
69 print_mode(config);
70
71 printk(BIOS_ERR, "config: xres:yres: %d x %d\n ",
72 config->xres, config->yres);
73 printk(BIOS_ERR, " href_sync:vref_sync: %d x %d\n ",
74 config->href_to_sync, config->vref_to_sync);
75 printk(BIOS_ERR, " hsyn_width:vsyn_width: %d x %d\n ",
76 config->hsync_width, config->vsync_width);
77 printk(BIOS_ERR, " hfnt_porch:vfnt_porch: %d x %d\n ",
78 config->hfront_porch, config->vfront_porch);
79 printk(BIOS_ERR, " hbk_porch:vbk_porch: %d x %d\n ",
80 config->hback_porch, config->vback_porch);
81
82 WRITEL(0x0, &disp_ctrl->disp.disp_timing_opt);
83 WRITEL(0x0, &disp_ctrl->disp.disp_color_ctrl);
84
85 /* select win opt */
86 WRITEL(config->win_opt, &disp_ctrl->disp.disp_win_opt);
87
88 WRITEL(config->vref_to_sync << 16 | config->href_to_sync,
89 &disp_ctrl->disp.ref_to_sync);
90
91 WRITEL(config->vsync_width << 16 | config->hsync_width,
92 &disp_ctrl->disp.sync_width);
93
Patrick Georgi40a3e322015-06-22 19:41:29 +020094 WRITEL((config->vback_porch << 16) | config->hback_porch,
95 &disp_ctrl->disp.back_porch);
96
97 WRITEL((config->vfront_porch << 16) | config->hfront_porch,
98 &disp_ctrl->disp.front_porch);
99
100 WRITEL(config->xres | (config->yres << 16),
101 &disp_ctrl->disp.disp_active);
102
103 /*
104 * PixelClock = (PLLD / 2) / ShiftClockDiv / PixelClockDiv.
105 *
106 * default: Set both shift_clk_div and pixel_clock_div to 1
107 */
108 update_display_shift_clock_divider(disp_ctrl, SHIFT_CLK_DIVIDER(1));
109
110 return 0;
111}
112
113void update_display_shift_clock_divider(struct display_controller *disp_ctrl,
Elyes HAOUAS88607a42018-10-05 10:36:45 +0200114 u32 shift_clock_div)
Patrick Georgi40a3e322015-06-22 19:41:29 +0200115{
116 WRITEL((PIXEL_CLK_DIVIDER_PCD1 << PIXEL_CLK_DIVIDER_SHIFT) |
117 (shift_clock_div & 0xff) << SHIFT_CLK_DIVIDER_SHIFT,
118 &disp_ctrl->disp.disp_clk_ctrl);
119 printk(BIOS_DEBUG, "%s: ShiftClockDiv=%u\n",
120 __func__, shift_clock_div);
121}
122
123/*
124 * update_window:
125 * set up window registers and activate window except two:
126 * frame buffer base address register (WINBUF_START_ADDR) and
127 * display enable register (_DISP_DISP_WIN_OPTIONS). This is
Paul Kocialkowski536f5a72016-05-07 14:31:35 +0200128 * because framebuffer is not available until payload stage.
Patrick Georgi40a3e322015-06-22 19:41:29 +0200129 */
130void update_window(const struct soc_nvidia_tegra210_config *config)
131{
132 struct display_controller *disp_ctrl =
133 (void *)config->display_controller;
134 u32 val;
135
136 WRITEL(WINDOW_A_SELECT, &disp_ctrl->cmd.disp_win_header);
137
138 WRITEL(((config->yres << 16) | config->xres), &disp_ctrl->win.size);
139
140 WRITEL(((config->display_yres << 16) |
141 (config->display_xres *
142 config->framebuffer_bits_per_pixel / 8)),
143 &disp_ctrl->win.prescaled_size);
144
145 val = ALIGN_UP((config->display_xres *
146 config->framebuffer_bits_per_pixel / 8), 64);
147 WRITEL(val, &disp_ctrl->win.line_stride);
148
149 WRITEL(config->color_depth, &disp_ctrl->win.color_depth);
150 WRITEL(COLOR_BLACK, &disp_ctrl->disp.blend_background_color);
151
152 WRITEL(((DDA_INC(config->display_yres, config->yres) << 16) |
153 DDA_INC(config->display_xres, config->xres)),
154 &disp_ctrl->win.dda_increment);
155
156 WRITEL(DISP_CTRL_MODE_C_DISPLAY, &disp_ctrl->cmd.disp_cmd);
157
158 WRITEL(WRITE_MUX_ACTIVE, &disp_ctrl->cmd.state_access);
159
160 WRITEL(0, &disp_ctrl->win.buffer_addr_mode);
161
162 val = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
163 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
164 WRITEL(val, &disp_ctrl->cmd.disp_pow_ctrl);
165
166 val = GENERAL_UPDATE | WIN_A_UPDATE;
167 WRITEL(val, &disp_ctrl->cmd.state_ctrl);
168
169 val = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
170 WRITEL(val, &disp_ctrl->cmd.state_ctrl);
171}
172
173int tegra_dc_init(struct display_controller *disp_ctrl)
174{
175 /* do not accept interrupts during initialization */
176 WRITEL(0x00000000, &disp_ctrl->cmd.int_mask);
177 WRITEL(WRITE_MUX_ASSEMBLY | READ_MUX_ASSEMBLY,
178 &disp_ctrl->cmd.state_access);
179 WRITEL(WINDOW_A_SELECT, &disp_ctrl->cmd.disp_win_header);
180 WRITEL(0x00000000, &disp_ctrl->win.win_opt);
181 WRITEL(0x00000000, &disp_ctrl->win.byte_swap);
182 WRITEL(0x00000000, &disp_ctrl->win.buffer_ctrl);
183
184 WRITEL(0x00000000, &disp_ctrl->win.pos);
185 WRITEL(0x00000000, &disp_ctrl->win.h_initial_dda);
186 WRITEL(0x00000000, &disp_ctrl->win.v_initial_dda);
187 WRITEL(0x00000000, &disp_ctrl->win.dda_increment);
188 WRITEL(0x00000000, &disp_ctrl->win.dv_ctrl);
189
190 WRITEL(0x01000000, &disp_ctrl->win.blend_layer_ctrl);
191 WRITEL(0x00000000, &disp_ctrl->win.blend_match_select);
192 WRITEL(0x00000000, &disp_ctrl->win.blend_nomatch_select);
193 WRITEL(0x00000000, &disp_ctrl->win.blend_alpha_1bit);
194
195 WRITEL(0x00000000, &disp_ctrl->winbuf.start_addr_hi);
196 WRITEL(0x00000000, &disp_ctrl->winbuf.addr_h_offset);
197 WRITEL(0x00000000, &disp_ctrl->winbuf.addr_v_offset);
198
199 WRITEL(0x00000000, &disp_ctrl->com.crc_checksum);
200 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[0]);
201 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[1]);
202 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[2]);
203 WRITEL(0x00000000, &disp_ctrl->com.pin_output_enb[3]);
204 WRITEL(0x00000000, &disp_ctrl->disp.disp_signal_opt0);
205
206 return 0;
207}
208
209/*
210 * Save mode to cb tables
211 */
212void pass_mode_info_to_payload(
213 struct soc_nvidia_tegra210_config *config)
214{
Patrick Rudolph8b56c8c2020-02-19 12:57:00 +0100215 const uint32_t bytes_per_line = ALIGN_UP(config->display_xres *
216 DIV_ROUND_UP(config->framebuffer_bits_per_pixel, 8), 64);
217 /* The framebuffer address is zero to let the payload allocate it */
218 fb_add_framebuffer_info(0, config->display_xres, config->display_yres,
219 bytes_per_line, config->framebuffer_bits_per_pixel);
Patrick Georgi40a3e322015-06-22 19:41:29 +0200220}