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