Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 4 | */ |
Simon Glass | b1c50fb | 2016-01-30 16:37:57 -0700 | [diff] [blame] | 5 | |
Svyatoslav Ryhel | 7673aba | 2023-03-27 11:11:46 +0300 | [diff] [blame] | 6 | #include <backlight.h> |
Jonas Schwöbel | fa2e838 | 2024-01-23 19:16:26 +0200 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 9 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 11 | #include <panel.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 12 | #include <part.h> |
Simon Glass | d8af3c9 | 2016-01-30 16:38:01 -0700 | [diff] [blame] | 13 | #include <pwm.h> |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 14 | #include <video.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 17 | #include <asm/system.h> |
| 18 | #include <asm/gpio.h> |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 19 | #include <asm/io.h> |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 20 | |
| 21 | #include <asm/arch/clock.h> |
| 22 | #include <asm/arch/funcmux.h> |
| 23 | #include <asm/arch/pinmux.h> |
Svyatoslav Ryhel | 1b0789b | 2024-01-23 19:16:22 +0200 | [diff] [blame] | 24 | #include <asm/arch/powergate.h> |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 25 | #include <asm/arch/pwm.h> |
Svyatoslav Ryhel | 75fec41 | 2024-01-23 19:16:18 +0200 | [diff] [blame] | 26 | |
| 27 | #include "tegra-dc.h" |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 31 | /* Holder of Tegra per-SOC DC differences */ |
| 32 | struct tegra_dc_soc_info { |
| 33 | bool has_timer; |
| 34 | bool has_rgb; |
Svyatoslav Ryhel | 1b0789b | 2024-01-23 19:16:22 +0200 | [diff] [blame] | 35 | bool has_pgate; |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
Simon Glass | 923128f | 2016-01-30 16:37:55 -0700 | [diff] [blame] | 38 | /* Information about the display controller */ |
| 39 | struct tegra_lcd_priv { |
Simon Glass | 923128f | 2016-01-30 16:37:55 -0700 | [diff] [blame] | 40 | int width; /* width in pixels */ |
| 41 | int height; /* height in pixels */ |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 42 | enum video_log2_bpp log2_bpp; /* colour depth */ |
| 43 | struct display_timing timing; |
| 44 | struct udevice *panel; |
Svyatoslav Ryhel | 9716fe5 | 2023-03-27 11:11:44 +0300 | [diff] [blame] | 45 | struct dc_ctlr *dc; /* Display controller regmap */ |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 46 | const struct tegra_dc_soc_info *soc; |
Simon Glass | 923128f | 2016-01-30 16:37:55 -0700 | [diff] [blame] | 47 | fdt_addr_t frame_buffer; /* Address of frame buffer */ |
| 48 | unsigned pixel_clock; /* Pixel clock in Hz */ |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 49 | int dc_clk[2]; /* Contains clk and its parent */ |
Svyatoslav Ryhel | d16c105 | 2024-01-23 19:16:23 +0200 | [diff] [blame] | 50 | ulong scdiv; /* Clock divider used by disp_clk_ctrl */ |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 51 | bool rotation; /* 180 degree panel turn */ |
Svyatoslav Ryhel | bae46f3 | 2024-01-23 19:16:19 +0200 | [diff] [blame] | 52 | bool pipe; /* DC controller: 0 for A, 1 for B */ |
Simon Glass | 923128f | 2016-01-30 16:37:55 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 55 | enum { |
| 56 | /* Maximum LCD size we support */ |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 57 | LCD_MAX_WIDTH = 2560, |
| 58 | LCD_MAX_HEIGHT = 1600, |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 59 | LCD_MAX_LOG2_BPP = VIDEO_BPP16, |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 62 | static void update_window(struct tegra_lcd_priv *priv, |
| 63 | struct disp_ctl_win *win) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 64 | { |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 65 | struct dc_ctlr *dc = priv->dc; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 66 | unsigned h_dda, v_dda; |
| 67 | unsigned long val; |
| 68 | |
| 69 | val = readl(&dc->cmd.disp_win_header); |
| 70 | val |= WINDOW_A_SELECT; |
| 71 | writel(val, &dc->cmd.disp_win_header); |
| 72 | |
| 73 | writel(win->fmt, &dc->win.color_depth); |
| 74 | |
| 75 | clrsetbits_le32(&dc->win.byte_swap, BYTE_SWAP_MASK, |
| 76 | BYTE_SWAP_NOSWAP << BYTE_SWAP_SHIFT); |
| 77 | |
| 78 | val = win->out_x << H_POSITION_SHIFT; |
| 79 | val |= win->out_y << V_POSITION_SHIFT; |
| 80 | writel(val, &dc->win.pos); |
| 81 | |
| 82 | val = win->out_w << H_SIZE_SHIFT; |
| 83 | val |= win->out_h << V_SIZE_SHIFT; |
| 84 | writel(val, &dc->win.size); |
| 85 | |
| 86 | val = (win->w * win->bpp / 8) << H_PRESCALED_SIZE_SHIFT; |
| 87 | val |= win->h << V_PRESCALED_SIZE_SHIFT; |
| 88 | writel(val, &dc->win.prescaled_size); |
| 89 | |
| 90 | writel(0, &dc->win.h_initial_dda); |
| 91 | writel(0, &dc->win.v_initial_dda); |
| 92 | |
| 93 | h_dda = (win->w * 0x1000) / max(win->out_w - 1, 1U); |
| 94 | v_dda = (win->h * 0x1000) / max(win->out_h - 1, 1U); |
| 95 | |
| 96 | val = h_dda << H_DDA_INC_SHIFT; |
| 97 | val |= v_dda << V_DDA_INC_SHIFT; |
| 98 | writel(val, &dc->win.dda_increment); |
| 99 | |
| 100 | writel(win->stride, &dc->win.line_stride); |
| 101 | writel(0, &dc->win.buf_stride); |
| 102 | |
| 103 | val = WIN_ENABLE; |
| 104 | if (win->bpp < 24) |
| 105 | val |= COLOR_EXPAND; |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 106 | |
| 107 | if (priv->rotation) |
| 108 | val |= H_DIRECTION | V_DIRECTION; |
| 109 | |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 110 | writel(val, &dc->win.win_opt); |
| 111 | |
| 112 | writel((unsigned long)win->phys_addr, &dc->winbuf.start_addr); |
| 113 | writel(win->x, &dc->winbuf.addr_h_offset); |
| 114 | writel(win->y, &dc->winbuf.addr_v_offset); |
| 115 | |
| 116 | writel(0xff00, &dc->win.blend_nokey); |
| 117 | writel(0xff00, &dc->win.blend_1win); |
| 118 | |
| 119 | val = GENERAL_ACT_REQ | WIN_A_ACT_REQ; |
| 120 | val |= GENERAL_UPDATE | WIN_A_UPDATE; |
| 121 | writel(val, &dc->cmd.state_ctrl); |
| 122 | } |
| 123 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 124 | static int update_display_mode(struct tegra_lcd_priv *priv) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 125 | { |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 126 | struct dc_disp_reg *disp = &priv->dc->disp; |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 127 | struct display_timing *dt = &priv->timing; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 128 | unsigned long val; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 129 | |
| 130 | writel(0x0, &disp->disp_timing_opt); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 131 | |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 132 | writel(1 | 1 << 16, &disp->ref_to_sync); |
| 133 | writel(dt->hsync_len.typ | dt->vsync_len.typ << 16, &disp->sync_width); |
| 134 | writel(dt->hback_porch.typ | dt->vback_porch.typ << 16, |
| 135 | &disp->back_porch); |
| 136 | writel((dt->hfront_porch.typ - 1) | (dt->vfront_porch.typ - 1) << 16, |
| 137 | &disp->front_porch); |
| 138 | writel(dt->hactive.typ | (dt->vactive.typ << 16), &disp->disp_active); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 139 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 140 | if (priv->soc->has_rgb) { |
| 141 | val = DE_SELECT_ACTIVE << DE_SELECT_SHIFT; |
| 142 | val |= DE_CONTROL_NORMAL << DE_CONTROL_SHIFT; |
| 143 | writel(val, &disp->data_enable_opt); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 144 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 145 | val = DATA_FORMAT_DF1P1C << DATA_FORMAT_SHIFT; |
| 146 | val |= DATA_ALIGNMENT_MSB << DATA_ALIGNMENT_SHIFT; |
| 147 | val |= DATA_ORDER_RED_BLUE << DATA_ORDER_SHIFT; |
| 148 | writel(val, &disp->disp_interface_ctrl); |
| 149 | } |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 150 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 151 | if (priv->soc->has_rgb) |
| 152 | writel(0x00010001, &disp->shift_clk_opt); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 153 | |
| 154 | val = PIXEL_CLK_DIVIDER_PCD1 << PIXEL_CLK_DIVIDER_SHIFT; |
Svyatoslav Ryhel | d16c105 | 2024-01-23 19:16:23 +0200 | [diff] [blame] | 155 | val |= priv->scdiv << SHIFT_CLK_DIVIDER_SHIFT; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 156 | writel(val, &disp->disp_clk_ctrl); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /* Start up the display and turn on power to PWMs */ |
| 162 | static void basic_init(struct dc_cmd_reg *cmd) |
| 163 | { |
| 164 | u32 val; |
| 165 | |
| 166 | writel(0x00000100, &cmd->gen_incr_syncpt_ctrl); |
| 167 | writel(0x0000011a, &cmd->cont_syncpt_vsync); |
| 168 | writel(0x00000000, &cmd->int_type); |
| 169 | writel(0x00000000, &cmd->int_polarity); |
| 170 | writel(0x00000000, &cmd->int_mask); |
| 171 | writel(0x00000000, &cmd->int_enb); |
| 172 | |
| 173 | val = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE; |
| 174 | val |= PW3_ENABLE | PW4_ENABLE | PM0_ENABLE; |
| 175 | val |= PM1_ENABLE; |
| 176 | writel(val, &cmd->disp_pow_ctrl); |
| 177 | |
| 178 | val = readl(&cmd->disp_cmd); |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 179 | val &= ~CTRL_MODE_MASK; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 180 | val |= CTRL_MODE_C_DISPLAY << CTRL_MODE_SHIFT; |
| 181 | writel(val, &cmd->disp_cmd); |
| 182 | } |
| 183 | |
| 184 | static void basic_init_timer(struct dc_disp_reg *disp) |
| 185 | { |
| 186 | writel(0x00000020, &disp->mem_high_pri); |
| 187 | writel(0x00000001, &disp->mem_high_pri_timer); |
| 188 | } |
| 189 | |
| 190 | static const u32 rgb_enb_tab[PIN_REG_COUNT] = { |
| 191 | 0x00000000, |
| 192 | 0x00000000, |
| 193 | 0x00000000, |
| 194 | 0x00000000, |
| 195 | }; |
| 196 | |
| 197 | static const u32 rgb_polarity_tab[PIN_REG_COUNT] = { |
| 198 | 0x00000000, |
| 199 | 0x01000000, |
| 200 | 0x00000000, |
| 201 | 0x00000000, |
| 202 | }; |
| 203 | |
| 204 | static const u32 rgb_data_tab[PIN_REG_COUNT] = { |
| 205 | 0x00000000, |
| 206 | 0x00000000, |
| 207 | 0x00000000, |
| 208 | 0x00000000, |
| 209 | }; |
| 210 | |
| 211 | static const u32 rgb_sel_tab[PIN_OUTPUT_SEL_COUNT] = { |
| 212 | 0x00000000, |
| 213 | 0x00000000, |
| 214 | 0x00000000, |
| 215 | 0x00000000, |
| 216 | 0x00210222, |
| 217 | 0x00002200, |
| 218 | 0x00020000, |
| 219 | }; |
| 220 | |
Svyatoslav Ryhel | 0e4a855 | 2024-01-23 19:16:27 +0200 | [diff] [blame] | 221 | static void rgb_enable(struct tegra_lcd_priv *priv) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 222 | { |
Svyatoslav Ryhel | 0e4a855 | 2024-01-23 19:16:27 +0200 | [diff] [blame] | 223 | struct dc_com_reg *com = &priv->dc->com; |
| 224 | struct display_timing *dt = &priv->timing; |
| 225 | u32 value; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 226 | int i; |
| 227 | |
| 228 | for (i = 0; i < PIN_REG_COUNT; i++) { |
| 229 | writel(rgb_enb_tab[i], &com->pin_output_enb[i]); |
| 230 | writel(rgb_polarity_tab[i], &com->pin_output_polarity[i]); |
| 231 | writel(rgb_data_tab[i], &com->pin_output_data[i]); |
| 232 | } |
| 233 | |
Svyatoslav Ryhel | 0e4a855 | 2024-01-23 19:16:27 +0200 | [diff] [blame] | 234 | /* configure H- and V-sync signal polarities */ |
| 235 | value = readl(&com->pin_output_polarity[1]); |
| 236 | |
| 237 | if (dt->flags & DISPLAY_FLAGS_HSYNC_LOW) |
| 238 | value |= LHS_OUTPUT_POLARITY_LOW; |
| 239 | else |
| 240 | value &= ~LHS_OUTPUT_POLARITY_LOW; |
| 241 | |
| 242 | if (dt->flags & DISPLAY_FLAGS_VSYNC_LOW) |
| 243 | value |= LVS_OUTPUT_POLARITY_LOW; |
| 244 | else |
| 245 | value &= ~LVS_OUTPUT_POLARITY_LOW; |
| 246 | |
| 247 | writel(value, &com->pin_output_polarity[1]); |
| 248 | |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 249 | for (i = 0; i < PIN_OUTPUT_SEL_COUNT; i++) |
| 250 | writel(rgb_sel_tab[i], &com->pin_output_sel[i]); |
| 251 | } |
| 252 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 253 | static int setup_window(struct tegra_lcd_priv *priv, |
| 254 | struct disp_ctl_win *win) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 255 | { |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 256 | if (priv->rotation) { |
Svyatoslav Ryhel | 597eecb | 2024-01-23 19:16:17 +0200 | [diff] [blame] | 257 | win->x = priv->width * 2 - 1; |
| 258 | win->y = priv->height - 1; |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 259 | } else { |
| 260 | win->x = 0; |
| 261 | win->y = 0; |
| 262 | } |
| 263 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 264 | win->w = priv->width; |
| 265 | win->h = priv->height; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 266 | win->out_x = 0; |
| 267 | win->out_y = 0; |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 268 | win->out_w = priv->width; |
| 269 | win->out_h = priv->height; |
| 270 | win->phys_addr = priv->frame_buffer; |
| 271 | win->stride = priv->width * (1 << priv->log2_bpp) / 8; |
| 272 | debug("%s: depth = %d\n", __func__, priv->log2_bpp); |
| 273 | switch (priv->log2_bpp) { |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 274 | case VIDEO_BPP32: |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 275 | win->fmt = COLOR_DEPTH_R8G8B8A8; |
| 276 | win->bpp = 32; |
| 277 | break; |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 278 | case VIDEO_BPP16: |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 279 | win->fmt = COLOR_DEPTH_B5G6R5; |
| 280 | win->bpp = 16; |
| 281 | break; |
| 282 | |
| 283 | default: |
| 284 | debug("Unsupported LCD bit depth"); |
| 285 | return -1; |
| 286 | } |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 291 | /** |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 292 | * Register a new display based on device tree configuration. |
| 293 | * |
Robert P. J. Day | 8d56db9 | 2016-07-15 13:44:45 -0400 | [diff] [blame] | 294 | * The frame buffer can be positioned by U-Boot or overridden by the fdt. |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 295 | * You should pass in the U-Boot address here, and check the contents of |
Simon Glass | 923128f | 2016-01-30 16:37:55 -0700 | [diff] [blame] | 296 | * struct tegra_lcd_priv to see what was actually chosen. |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 297 | * |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 298 | * @param priv Driver's private data |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 299 | * @param default_lcd_base Default address of LCD frame buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 300 | * Return: 0 if ok, -1 on error (unsupported bits per pixel) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 301 | */ |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 302 | static int tegra_display_probe(struct tegra_lcd_priv *priv, |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 303 | void *default_lcd_base) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 304 | { |
| 305 | struct disp_ctl_win window; |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 306 | unsigned long rate = clock_get_rate(priv->dc_clk[1]); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 307 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 308 | priv->frame_buffer = (u32)default_lcd_base; |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 309 | |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 310 | /* |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 311 | * We halve the rate if DISP1 parent is PLLD, since actual parent |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 312 | * is plld_out0 which is PLLD divided by 2. |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 313 | */ |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 314 | if (priv->dc_clk[1] == CLOCK_ID_DISPLAY) |
| 315 | rate /= 2; |
| 316 | |
Svyatoslav Ryhel | e38ac62 | 2024-01-23 19:16:20 +0200 | [diff] [blame] | 317 | #ifndef CONFIG_TEGRA20 |
| 318 | /* PLLD2 obeys same rules as PLLD but it is present only on T30+ */ |
| 319 | if (priv->dc_clk[1] == CLOCK_ID_DISPLAY2) |
| 320 | rate /= 2; |
| 321 | #endif |
| 322 | |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 323 | /* |
Svyatoslav Ryhel | d16c105 | 2024-01-23 19:16:23 +0200 | [diff] [blame] | 324 | * The pixel clock divider is in 7.1 format (where the bottom bit |
| 325 | * represents 0.5). Here we calculate the divider needed to get from |
| 326 | * the display clock (typically 600MHz) to the pixel clock. We round |
| 327 | * up or down as required. |
| 328 | */ |
| 329 | if (!priv->scdiv) |
| 330 | priv->scdiv = ((rate * 2 + priv->pixel_clock / 2) |
| 331 | / priv->pixel_clock) - 2; |
| 332 | debug("Display clock %lu, divider %lu\n", rate, priv->scdiv); |
| 333 | |
| 334 | /* |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 335 | * HOST1X is init by default at 150MHz with PLLC as parent |
| 336 | */ |
| 337 | clock_start_periph_pll(PERIPH_ID_HOST1X, CLOCK_ID_CGENERAL, |
| 338 | 150 * 1000000); |
| 339 | clock_start_periph_pll(priv->dc_clk[0], priv->dc_clk[1], |
| 340 | rate); |
| 341 | |
Svyatoslav Ryhel | 9716fe5 | 2023-03-27 11:11:44 +0300 | [diff] [blame] | 342 | basic_init(&priv->dc->cmd); |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 343 | |
| 344 | if (priv->soc->has_timer) |
| 345 | basic_init_timer(&priv->dc->disp); |
| 346 | |
| 347 | if (priv->soc->has_rgb) |
Svyatoslav Ryhel | 0e4a855 | 2024-01-23 19:16:27 +0200 | [diff] [blame] | 348 | rgb_enable(priv); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 349 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 350 | if (priv->pixel_clock) |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 351 | update_display_mode(priv); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 352 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 353 | if (setup_window(priv, &window)) |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 354 | return -1; |
| 355 | |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 356 | update_window(priv, &window); |
Simon Glass | d8fc3c5 | 2016-01-30 16:37:53 -0700 | [diff] [blame] | 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 361 | static int tegra_lcd_probe(struct udevice *dev) |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 362 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 363 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 364 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
| 365 | struct tegra_lcd_priv *priv = dev_get_priv(dev); |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 366 | int ret; |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 367 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 368 | /* Initialize the Tegra display controller */ |
Marcel Ziswiler | cad5671 | 2023-03-27 11:11:40 +0300 | [diff] [blame] | 369 | #ifdef CONFIG_TEGRA20 |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 370 | funcmux_select(PERIPH_ID_DISP1, FUNCMUX_DEFAULT); |
Marcel Ziswiler | cad5671 | 2023-03-27 11:11:40 +0300 | [diff] [blame] | 371 | #endif |
| 372 | |
Svyatoslav Ryhel | 1b0789b | 2024-01-23 19:16:22 +0200 | [diff] [blame] | 373 | if (priv->soc->has_pgate) { |
| 374 | uint powergate; |
| 375 | |
| 376 | if (priv->pipe) |
| 377 | powergate = TEGRA_POWERGATE_DISB; |
| 378 | else |
| 379 | powergate = TEGRA_POWERGATE_DIS; |
| 380 | |
| 381 | ret = tegra_powergate_power_off(powergate); |
| 382 | if (ret < 0) { |
| 383 | log_err("failed to power off DISP gate: %d", ret); |
| 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | ret = tegra_powergate_sequence_power_up(powergate, |
| 388 | priv->dc_clk[0]); |
| 389 | if (ret < 0) { |
| 390 | log_err("failed to power up DISP gate: %d", ret); |
| 391 | return ret; |
| 392 | } |
| 393 | } |
| 394 | |
Svyatoslav Ryhel | d16c105 | 2024-01-23 19:16:23 +0200 | [diff] [blame] | 395 | /* Get shift clock divider from Tegra DSI if used */ |
| 396 | if (!strcmp(priv->panel->name, TEGRA_DSI_A) || |
| 397 | !strcmp(priv->panel->name, TEGRA_DSI_B)) { |
| 398 | struct tegra_dc_plat *dc_plat = dev_get_plat(priv->panel); |
| 399 | |
| 400 | priv->scdiv = dc_plat->scdiv; |
| 401 | } |
| 402 | |
Jonas Schwöbel | fa2e838 | 2024-01-23 19:16:26 +0200 | [diff] [blame] | 403 | /* Clean the framebuffer area */ |
| 404 | memset((u8 *)plat->base, 0, plat->size); |
| 405 | flush_dcache_all(); |
| 406 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 407 | if (tegra_display_probe(priv, (void *)plat->base)) { |
| 408 | debug("%s: Failed to probe display driver\n", __func__); |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 409 | return -1; |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 410 | } |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 411 | |
Marcel Ziswiler | cad5671 | 2023-03-27 11:11:40 +0300 | [diff] [blame] | 412 | #ifdef CONFIG_TEGRA20 |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 413 | pinmux_set_func(PMUX_PINGRP_GPU, PMUX_FUNC_PWM); |
| 414 | pinmux_tristate_disable(PMUX_PINGRP_GPU); |
Marcel Ziswiler | cad5671 | 2023-03-27 11:11:40 +0300 | [diff] [blame] | 415 | #endif |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 416 | |
| 417 | ret = panel_enable_backlight(priv->panel); |
| 418 | if (ret) { |
| 419 | debug("%s: Cannot enable backlight, ret=%d\n", __func__, ret); |
| 420 | return ret; |
| 421 | } |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 422 | |
Simon Glass | bbdae4b | 2016-05-08 16:55:21 -0600 | [diff] [blame] | 423 | mmu_set_region_dcache_behaviour(priv->frame_buffer, plat->size, |
| 424 | DCACHE_WRITETHROUGH); |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 425 | |
| 426 | /* Enable flushing after LCD writes if requested */ |
Simon Glass | bbdae4b | 2016-05-08 16:55:21 -0600 | [diff] [blame] | 427 | video_set_flush_dcache(dev, true); |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 428 | |
| 429 | uc_priv->xsize = priv->width; |
| 430 | uc_priv->ysize = priv->height; |
| 431 | uc_priv->bpix = priv->log2_bpp; |
Jonas Schwöbel | 3acb426 | 2024-01-23 19:16:24 +0200 | [diff] [blame] | 432 | debug("LCD frame buffer at %08x, size %x\n", priv->frame_buffer, |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 433 | plat->size); |
| 434 | |
Jonas Schwöbel | 146ce49 | 2024-01-23 19:16:25 +0200 | [diff] [blame] | 435 | return panel_set_backlight(priv->panel, BACKLIGHT_DEFAULT); |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 438 | static int tegra_lcd_of_to_plat(struct udevice *dev) |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 439 | { |
| 440 | struct tegra_lcd_priv *priv = dev_get_priv(dev); |
| 441 | const void *blob = gd->fdt_blob; |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 442 | struct display_timing *timing; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 443 | int node = dev_of_offset(dev); |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 444 | int panel_node; |
| 445 | int rgb; |
Simon Glass | d8af3c9 | 2016-01-30 16:38:01 -0700 | [diff] [blame] | 446 | int ret; |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 447 | |
Svyatoslav Ryhel | 9716fe5 | 2023-03-27 11:11:44 +0300 | [diff] [blame] | 448 | priv->dc = (struct dc_ctlr *)dev_read_addr_ptr(dev); |
| 449 | if (!priv->dc) { |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 450 | debug("%s: No display controller address\n", __func__); |
| 451 | return -EINVAL; |
| 452 | } |
| 453 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 454 | priv->soc = (struct tegra_dc_soc_info *)dev_get_driver_data(dev); |
| 455 | |
Svyatoslav Ryhel | c1f260a | 2023-03-27 11:11:42 +0300 | [diff] [blame] | 456 | ret = clock_decode_pair(dev, priv->dc_clk); |
| 457 | if (ret < 0) { |
| 458 | debug("%s: Cannot decode clocks for '%s' (ret = %d)\n", |
| 459 | __func__, dev->name, ret); |
| 460 | return -EINVAL; |
| 461 | } |
| 462 | |
Svyatoslav Ryhel | 4f5b79b | 2023-03-27 11:11:45 +0300 | [diff] [blame] | 463 | priv->rotation = dev_read_bool(dev, "nvidia,180-rotation"); |
| 464 | |
Svyatoslav Ryhel | bae46f3 | 2024-01-23 19:16:19 +0200 | [diff] [blame] | 465 | if (!strcmp(dev->name, TEGRA_DC_B)) |
| 466 | priv->pipe = 1; |
| 467 | |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 468 | rgb = fdt_subnode_offset(blob, node, "rgb"); |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 469 | if (rgb < 0) { |
| 470 | debug("%s: Cannot find rgb subnode for '%s' (ret=%d)\n", |
| 471 | __func__, dev->name, rgb); |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 472 | return -EINVAL; |
| 473 | } |
| 474 | |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 475 | /* |
| 476 | * Sadly the panel phandle is in an rgb subnode so we cannot use |
| 477 | * uclass_get_device_by_phandle(). |
| 478 | */ |
| 479 | panel_node = fdtdec_lookup_phandle(blob, rgb, "nvidia,panel"); |
| 480 | if (panel_node < 0) { |
| 481 | debug("%s: Cannot find panel information\n", __func__); |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 482 | return -EINVAL; |
| 483 | } |
Svyatoslav Ryhel | d880629 | 2023-03-27 11:11:43 +0300 | [diff] [blame] | 484 | |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 485 | ret = uclass_get_device_by_of_offset(UCLASS_PANEL, panel_node, |
| 486 | &priv->panel); |
Simon Glass | d8af3c9 | 2016-01-30 16:38:01 -0700 | [diff] [blame] | 487 | if (ret) { |
Simon Glass | 44fe9e4 | 2016-05-08 16:55:20 -0600 | [diff] [blame] | 488 | debug("%s: Cannot find panel for '%s' (ret=%d)\n", __func__, |
| 489 | dev->name, ret); |
| 490 | return ret; |
Simon Glass | d8af3c9 | 2016-01-30 16:38:01 -0700 | [diff] [blame] | 491 | } |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 492 | |
Svyatoslav Ryhel | bae46f3 | 2024-01-23 19:16:19 +0200 | [diff] [blame] | 493 | /* Fill the platform data for internal devices */ |
Svyatoslav Ryhel | 0c8aa5e | 2023-03-27 11:11:47 +0300 | [diff] [blame] | 494 | if (!strcmp(priv->panel->name, TEGRA_DSI_A) || |
| 495 | !strcmp(priv->panel->name, TEGRA_DSI_B)) { |
| 496 | struct tegra_dc_plat *dc_plat = dev_get_plat(priv->panel); |
| 497 | |
| 498 | dc_plat->dev = dev; |
| 499 | dc_plat->dc = priv->dc; |
Svyatoslav Ryhel | bae46f3 | 2024-01-23 19:16:19 +0200 | [diff] [blame] | 500 | dc_plat->pipe = priv->pipe; |
Svyatoslav Ryhel | 0c8aa5e | 2023-03-27 11:11:47 +0300 | [diff] [blame] | 501 | } |
| 502 | |
Svyatoslav Ryhel | d880629 | 2023-03-27 11:11:43 +0300 | [diff] [blame] | 503 | ret = panel_get_display_timing(priv->panel, &priv->timing); |
| 504 | if (ret) { |
| 505 | ret = fdtdec_decode_display_timing(blob, rgb, 0, &priv->timing); |
| 506 | if (ret) { |
| 507 | debug("%s: Cannot read display timing for '%s' (ret=%d)\n", |
| 508 | __func__, dev->name, ret); |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | timing = &priv->timing; |
| 514 | priv->width = timing->hactive.typ; |
| 515 | priv->height = timing->vactive.typ; |
| 516 | priv->pixel_clock = timing->pixelclock.typ; |
| 517 | priv->log2_bpp = VIDEO_BPP16; |
| 518 | |
Simon Glass | 60740e7 | 2016-01-30 16:37:59 -0700 | [diff] [blame] | 519 | return 0; |
| 520 | } |
| 521 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 522 | static int tegra_lcd_bind(struct udevice *dev) |
| 523 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 524 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Stephen Warren | 225da8b | 2016-04-19 16:19:30 -0600 | [diff] [blame] | 525 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 526 | int node = dev_of_offset(dev); |
Stephen Warren | 225da8b | 2016-04-19 16:19:30 -0600 | [diff] [blame] | 527 | int rgb; |
| 528 | |
| 529 | rgb = fdt_subnode_offset(blob, node, "rgb"); |
| 530 | if ((rgb < 0) || !fdtdec_get_is_enabled(blob, rgb)) |
| 531 | return -ENODEV; |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 532 | |
| 533 | plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT * |
| 534 | (1 << LCD_MAX_LOG2_BPP) / 8; |
| 535 | |
| 536 | return 0; |
Simon Glass | e161ccf | 2012-10-17 13:24:51 +0000 | [diff] [blame] | 537 | } |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 538 | |
| 539 | static const struct video_ops tegra_lcd_ops = { |
| 540 | }; |
| 541 | |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 542 | static const struct tegra_dc_soc_info tegra20_dc_soc_info = { |
| 543 | .has_timer = true, |
| 544 | .has_rgb = true, |
Svyatoslav Ryhel | 1b0789b | 2024-01-23 19:16:22 +0200 | [diff] [blame] | 545 | .has_pgate = false, |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 546 | }; |
| 547 | |
| 548 | static const struct tegra_dc_soc_info tegra30_dc_soc_info = { |
| 549 | .has_timer = false, |
| 550 | .has_rgb = true, |
Svyatoslav Ryhel | 1b0789b | 2024-01-23 19:16:22 +0200 | [diff] [blame] | 551 | .has_pgate = false, |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 552 | }; |
| 553 | |
| 554 | static const struct tegra_dc_soc_info tegra114_dc_soc_info = { |
| 555 | .has_timer = false, |
| 556 | .has_rgb = false, |
Svyatoslav Ryhel | 1b0789b | 2024-01-23 19:16:22 +0200 | [diff] [blame] | 557 | .has_pgate = true, |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 558 | }; |
| 559 | |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 560 | static const struct udevice_id tegra_lcd_ids[] = { |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 561 | { |
| 562 | .compatible = "nvidia,tegra20-dc", |
| 563 | .data = (ulong)&tegra20_dc_soc_info |
| 564 | }, { |
| 565 | .compatible = "nvidia,tegra30-dc", |
| 566 | .data = (ulong)&tegra30_dc_soc_info |
| 567 | }, { |
| 568 | .compatible = "nvidia,tegra114-dc", |
| 569 | .data = (ulong)&tegra114_dc_soc_info |
| 570 | }, { |
| 571 | /* sentinel */ |
| 572 | } |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | U_BOOT_DRIVER(tegra_lcd) = { |
Svyatoslav Ryhel | 9d53a7b | 2024-01-23 19:16:16 +0200 | [diff] [blame] | 576 | .name = "tegra_lcd", |
| 577 | .id = UCLASS_VIDEO, |
| 578 | .of_match = tegra_lcd_ids, |
| 579 | .ops = &tegra_lcd_ops, |
| 580 | .bind = tegra_lcd_bind, |
| 581 | .probe = tegra_lcd_probe, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 582 | .of_to_plat = tegra_lcd_of_to_plat, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 583 | .priv_auto = sizeof(struct tegra_lcd_priv), |
Simon Glass | e865ef3 | 2016-01-30 16:37:56 -0700 | [diff] [blame] | 584 | }; |