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