blob: 5d8874f323abb14e39c85f036866e4db88a94982 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasse161ccf2012-10-17 13:24:51 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glasse161ccf2012-10-17 13:24:51 +00004 */
Simon Glassb1c50fb2016-01-30 16:37:57 -07005
Svyatoslav Ryhel7673aba2023-03-27 11:11:46 +03006#include <backlight.h>
Simon Glasse865ef32016-01-30 16:37:56 -07007#include <dm.h>
Simon Glasse161ccf2012-10-17 13:24:51 +00008#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass44fe9e42016-05-08 16:55:20 -060010#include <panel.h>
Simon Glass655306c2020-05-10 11:39:58 -060011#include <part.h>
Simon Glassd8af3c92016-01-30 16:38:01 -070012#include <pwm.h>
Simon Glasse865ef32016-01-30 16:37:56 -070013#include <video.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glasse161ccf2012-10-17 13:24:51 +000016#include <asm/system.h>
17#include <asm/gpio.h>
Simon Glassd8fc3c52016-01-30 16:37:53 -070018#include <asm/io.h>
Simon Glasse161ccf2012-10-17 13:24:51 +000019
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 Ryhel75fec412024-01-23 19:16:18 +020024
25#include "tegra-dc.h"
Simon Glasse161ccf2012-10-17 13:24:51 +000026
27DECLARE_GLOBAL_DATA_PTR;
28
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +020029/* Holder of Tegra per-SOC DC differences */
30struct tegra_dc_soc_info {
31 bool has_timer;
32 bool has_rgb;
33};
34
Simon Glass923128f2016-01-30 16:37:55 -070035/* Information about the display controller */
36struct tegra_lcd_priv {
Simon Glass923128f2016-01-30 16:37:55 -070037 int width; /* width in pixels */
38 int height; /* height in pixels */
Simon Glass44fe9e42016-05-08 16:55:20 -060039 enum video_log2_bpp log2_bpp; /* colour depth */
40 struct display_timing timing;
41 struct udevice *panel;
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +030042 struct dc_ctlr *dc; /* Display controller regmap */
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +020043 const struct tegra_dc_soc_info *soc;
Simon Glass923128f2016-01-30 16:37:55 -070044 fdt_addr_t frame_buffer; /* Address of frame buffer */
45 unsigned pixel_clock; /* Pixel clock in Hz */
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +030046 int dc_clk[2]; /* Contains clk and its parent */
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030047 bool rotation; /* 180 degree panel turn */
Simon Glass923128f2016-01-30 16:37:55 -070048};
49
Simon Glasse161ccf2012-10-17 13:24:51 +000050enum {
51 /* Maximum LCD size we support */
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +020052 LCD_MAX_WIDTH = 2560,
53 LCD_MAX_HEIGHT = 1600,
Simon Glasse865ef32016-01-30 16:37:56 -070054 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
Simon Glasse161ccf2012-10-17 13:24:51 +000055};
56
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030057static void update_window(struct tegra_lcd_priv *priv,
58 struct disp_ctl_win *win)
Simon Glassd8fc3c52016-01-30 16:37:53 -070059{
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030060 struct dc_ctlr *dc = priv->dc;
Simon Glassd8fc3c52016-01-30 16:37:53 -070061 unsigned h_dda, v_dda;
62 unsigned long val;
63
64 val = readl(&dc->cmd.disp_win_header);
65 val |= WINDOW_A_SELECT;
66 writel(val, &dc->cmd.disp_win_header);
67
68 writel(win->fmt, &dc->win.color_depth);
69
70 clrsetbits_le32(&dc->win.byte_swap, BYTE_SWAP_MASK,
71 BYTE_SWAP_NOSWAP << BYTE_SWAP_SHIFT);
72
73 val = win->out_x << H_POSITION_SHIFT;
74 val |= win->out_y << V_POSITION_SHIFT;
75 writel(val, &dc->win.pos);
76
77 val = win->out_w << H_SIZE_SHIFT;
78 val |= win->out_h << V_SIZE_SHIFT;
79 writel(val, &dc->win.size);
80
81 val = (win->w * win->bpp / 8) << H_PRESCALED_SIZE_SHIFT;
82 val |= win->h << V_PRESCALED_SIZE_SHIFT;
83 writel(val, &dc->win.prescaled_size);
84
85 writel(0, &dc->win.h_initial_dda);
86 writel(0, &dc->win.v_initial_dda);
87
88 h_dda = (win->w * 0x1000) / max(win->out_w - 1, 1U);
89 v_dda = (win->h * 0x1000) / max(win->out_h - 1, 1U);
90
91 val = h_dda << H_DDA_INC_SHIFT;
92 val |= v_dda << V_DDA_INC_SHIFT;
93 writel(val, &dc->win.dda_increment);
94
95 writel(win->stride, &dc->win.line_stride);
96 writel(0, &dc->win.buf_stride);
97
98 val = WIN_ENABLE;
99 if (win->bpp < 24)
100 val |= COLOR_EXPAND;
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300101
102 if (priv->rotation)
103 val |= H_DIRECTION | V_DIRECTION;
104
Simon Glassd8fc3c52016-01-30 16:37:53 -0700105 writel(val, &dc->win.win_opt);
106
107 writel((unsigned long)win->phys_addr, &dc->winbuf.start_addr);
108 writel(win->x, &dc->winbuf.addr_h_offset);
109 writel(win->y, &dc->winbuf.addr_v_offset);
110
111 writel(0xff00, &dc->win.blend_nokey);
112 writel(0xff00, &dc->win.blend_1win);
113
114 val = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
115 val |= GENERAL_UPDATE | WIN_A_UPDATE;
116 writel(val, &dc->cmd.state_ctrl);
117}
118
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200119static int update_display_mode(struct tegra_lcd_priv *priv)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700120{
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200121 struct dc_disp_reg *disp = &priv->dc->disp;
Simon Glass44fe9e42016-05-08 16:55:20 -0600122 struct display_timing *dt = &priv->timing;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700123 unsigned long val;
124 unsigned long rate;
125 unsigned long div;
126
127 writel(0x0, &disp->disp_timing_opt);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700128
Simon Glass44fe9e42016-05-08 16:55:20 -0600129 writel(1 | 1 << 16, &disp->ref_to_sync);
130 writel(dt->hsync_len.typ | dt->vsync_len.typ << 16, &disp->sync_width);
131 writel(dt->hback_porch.typ | dt->vback_porch.typ << 16,
132 &disp->back_porch);
133 writel((dt->hfront_porch.typ - 1) | (dt->vfront_porch.typ - 1) << 16,
134 &disp->front_porch);
135 writel(dt->hactive.typ | (dt->vactive.typ << 16), &disp->disp_active);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700136
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200137 if (priv->soc->has_rgb) {
138 val = DE_SELECT_ACTIVE << DE_SELECT_SHIFT;
139 val |= DE_CONTROL_NORMAL << DE_CONTROL_SHIFT;
140 writel(val, &disp->data_enable_opt);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700141
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200142 val = DATA_FORMAT_DF1P1C << DATA_FORMAT_SHIFT;
143 val |= DATA_ALIGNMENT_MSB << DATA_ALIGNMENT_SHIFT;
144 val |= DATA_ORDER_RED_BLUE << DATA_ORDER_SHIFT;
145 writel(val, &disp->disp_interface_ctrl);
146 }
Simon Glassd8fc3c52016-01-30 16:37:53 -0700147
148 /*
149 * The pixel clock divider is in 7.1 format (where the bottom bit
150 * represents 0.5). Here we calculate the divider needed to get from
151 * the display clock (typically 600MHz) to the pixel clock. We round
152 * up or down as requried.
153 */
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300154 rate = clock_get_periph_rate(priv->dc_clk[0], priv->dc_clk[1]);
Simon Glasse865ef32016-01-30 16:37:56 -0700155 div = ((rate * 2 + priv->pixel_clock / 2) / priv->pixel_clock) - 2;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700156 debug("Display clock %lu, divider %lu\n", rate, div);
157
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200158 if (priv->soc->has_rgb)
159 writel(0x00010001, &disp->shift_clk_opt);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700160
161 val = PIXEL_CLK_DIVIDER_PCD1 << PIXEL_CLK_DIVIDER_SHIFT;
162 val |= div << SHIFT_CLK_DIVIDER_SHIFT;
163 writel(val, &disp->disp_clk_ctrl);
164
165 return 0;
166}
167
168/* Start up the display and turn on power to PWMs */
169static void basic_init(struct dc_cmd_reg *cmd)
170{
171 u32 val;
172
173 writel(0x00000100, &cmd->gen_incr_syncpt_ctrl);
174 writel(0x0000011a, &cmd->cont_syncpt_vsync);
175 writel(0x00000000, &cmd->int_type);
176 writel(0x00000000, &cmd->int_polarity);
177 writel(0x00000000, &cmd->int_mask);
178 writel(0x00000000, &cmd->int_enb);
179
180 val = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE;
181 val |= PW3_ENABLE | PW4_ENABLE | PM0_ENABLE;
182 val |= PM1_ENABLE;
183 writel(val, &cmd->disp_pow_ctrl);
184
185 val = readl(&cmd->disp_cmd);
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200186 val &= ~CTRL_MODE_MASK;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700187 val |= CTRL_MODE_C_DISPLAY << CTRL_MODE_SHIFT;
188 writel(val, &cmd->disp_cmd);
189}
190
191static void basic_init_timer(struct dc_disp_reg *disp)
192{
193 writel(0x00000020, &disp->mem_high_pri);
194 writel(0x00000001, &disp->mem_high_pri_timer);
195}
196
197static const u32 rgb_enb_tab[PIN_REG_COUNT] = {
198 0x00000000,
199 0x00000000,
200 0x00000000,
201 0x00000000,
202};
203
204static const u32 rgb_polarity_tab[PIN_REG_COUNT] = {
205 0x00000000,
206 0x01000000,
207 0x00000000,
208 0x00000000,
209};
210
211static const u32 rgb_data_tab[PIN_REG_COUNT] = {
212 0x00000000,
213 0x00000000,
214 0x00000000,
215 0x00000000,
216};
217
218static const u32 rgb_sel_tab[PIN_OUTPUT_SEL_COUNT] = {
219 0x00000000,
220 0x00000000,
221 0x00000000,
222 0x00000000,
223 0x00210222,
224 0x00002200,
225 0x00020000,
226};
227
228static void rgb_enable(struct dc_com_reg *com)
229{
230 int i;
231
232 for (i = 0; i < PIN_REG_COUNT; i++) {
233 writel(rgb_enb_tab[i], &com->pin_output_enb[i]);
234 writel(rgb_polarity_tab[i], &com->pin_output_polarity[i]);
235 writel(rgb_data_tab[i], &com->pin_output_data[i]);
236 }
237
238 for (i = 0; i < PIN_OUTPUT_SEL_COUNT; i++)
239 writel(rgb_sel_tab[i], &com->pin_output_sel[i]);
240}
241
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200242static int setup_window(struct tegra_lcd_priv *priv,
243 struct disp_ctl_win *win)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700244{
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300245 if (priv->rotation) {
Svyatoslav Ryhel597eecb2024-01-23 19:16:17 +0200246 win->x = priv->width * 2 - 1;
247 win->y = priv->height - 1;
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300248 } else {
249 win->x = 0;
250 win->y = 0;
251 }
252
Simon Glasse865ef32016-01-30 16:37:56 -0700253 win->w = priv->width;
254 win->h = priv->height;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700255 win->out_x = 0;
256 win->out_y = 0;
Simon Glasse865ef32016-01-30 16:37:56 -0700257 win->out_w = priv->width;
258 win->out_h = priv->height;
259 win->phys_addr = priv->frame_buffer;
260 win->stride = priv->width * (1 << priv->log2_bpp) / 8;
261 debug("%s: depth = %d\n", __func__, priv->log2_bpp);
262 switch (priv->log2_bpp) {
Simon Glass44fe9e42016-05-08 16:55:20 -0600263 case VIDEO_BPP32:
Simon Glassd8fc3c52016-01-30 16:37:53 -0700264 win->fmt = COLOR_DEPTH_R8G8B8A8;
265 win->bpp = 32;
266 break;
Simon Glass44fe9e42016-05-08 16:55:20 -0600267 case VIDEO_BPP16:
Simon Glassd8fc3c52016-01-30 16:37:53 -0700268 win->fmt = COLOR_DEPTH_B5G6R5;
269 win->bpp = 16;
270 break;
271
272 default:
273 debug("Unsupported LCD bit depth");
274 return -1;
275 }
276
277 return 0;
278}
279
Simon Glassd8fc3c52016-01-30 16:37:53 -0700280/**
Simon Glassd8fc3c52016-01-30 16:37:53 -0700281 * Register a new display based on device tree configuration.
282 *
Robert P. J. Day8d56db92016-07-15 13:44:45 -0400283 * The frame buffer can be positioned by U-Boot or overridden by the fdt.
Simon Glassd8fc3c52016-01-30 16:37:53 -0700284 * You should pass in the U-Boot address here, and check the contents of
Simon Glass923128f2016-01-30 16:37:55 -0700285 * struct tegra_lcd_priv to see what was actually chosen.
Simon Glassd8fc3c52016-01-30 16:37:53 -0700286 *
Simon Glasse865ef32016-01-30 16:37:56 -0700287 * @param priv Driver's private data
Simon Glassd8fc3c52016-01-30 16:37:53 -0700288 * @param default_lcd_base Default address of LCD frame buffer
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100289 * Return: 0 if ok, -1 on error (unsupported bits per pixel)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700290 */
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200291static int tegra_display_probe(struct tegra_lcd_priv *priv,
Simon Glasse865ef32016-01-30 16:37:56 -0700292 void *default_lcd_base)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700293{
294 struct disp_ctl_win window;
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300295 unsigned long rate = clock_get_rate(priv->dc_clk[1]);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700296
Simon Glasse865ef32016-01-30 16:37:56 -0700297 priv->frame_buffer = (u32)default_lcd_base;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700298
Simon Glassd8fc3c52016-01-30 16:37:53 -0700299 /*
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200300 * We halve the rate if DISP1 parent is PLLD, since actual parent
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300301 * is plld_out0 which is PLLD divided by 2.
Simon Glassd8fc3c52016-01-30 16:37:53 -0700302 */
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300303 if (priv->dc_clk[1] == CLOCK_ID_DISPLAY)
304 rate /= 2;
305
306 /*
307 * HOST1X is init by default at 150MHz with PLLC as parent
308 */
309 clock_start_periph_pll(PERIPH_ID_HOST1X, CLOCK_ID_CGENERAL,
310 150 * 1000000);
311 clock_start_periph_pll(priv->dc_clk[0], priv->dc_clk[1],
312 rate);
313
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +0300314 basic_init(&priv->dc->cmd);
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200315
316 if (priv->soc->has_timer)
317 basic_init_timer(&priv->dc->disp);
318
319 if (priv->soc->has_rgb)
320 rgb_enable(&priv->dc->com);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700321
Simon Glasse865ef32016-01-30 16:37:56 -0700322 if (priv->pixel_clock)
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200323 update_display_mode(priv);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700324
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200325 if (setup_window(priv, &window))
Simon Glassd8fc3c52016-01-30 16:37:53 -0700326 return -1;
327
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300328 update_window(priv, &window);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700329
330 return 0;
331}
332
Simon Glasse865ef32016-01-30 16:37:56 -0700333static int tegra_lcd_probe(struct udevice *dev)
Simon Glasse161ccf2012-10-17 13:24:51 +0000334{
Simon Glassb75b15b2020-12-03 16:55:23 -0700335 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glasse865ef32016-01-30 16:37:56 -0700336 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
337 struct tegra_lcd_priv *priv = dev_get_priv(dev);
Simon Glass44fe9e42016-05-08 16:55:20 -0600338 int ret;
Simon Glasse865ef32016-01-30 16:37:56 -0700339
Simon Glasse865ef32016-01-30 16:37:56 -0700340 /* Initialize the Tegra display controller */
Marcel Ziswilercad56712023-03-27 11:11:40 +0300341#ifdef CONFIG_TEGRA20
Simon Glass44fe9e42016-05-08 16:55:20 -0600342 funcmux_select(PERIPH_ID_DISP1, FUNCMUX_DEFAULT);
Marcel Ziswilercad56712023-03-27 11:11:40 +0300343#endif
344
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200345 if (tegra_display_probe(priv, (void *)plat->base)) {
346 debug("%s: Failed to probe display driver\n", __func__);
Simon Glasse865ef32016-01-30 16:37:56 -0700347 return -1;
Simon Glasse161ccf2012-10-17 13:24:51 +0000348 }
Simon Glasse865ef32016-01-30 16:37:56 -0700349
Marcel Ziswilercad56712023-03-27 11:11:40 +0300350#ifdef CONFIG_TEGRA20
Simon Glass44fe9e42016-05-08 16:55:20 -0600351 pinmux_set_func(PMUX_PINGRP_GPU, PMUX_FUNC_PWM);
352 pinmux_tristate_disable(PMUX_PINGRP_GPU);
Marcel Ziswilercad56712023-03-27 11:11:40 +0300353#endif
Simon Glass44fe9e42016-05-08 16:55:20 -0600354
355 ret = panel_enable_backlight(priv->panel);
356 if (ret) {
357 debug("%s: Cannot enable backlight, ret=%d\n", __func__, ret);
358 return ret;
359 }
Simon Glasse865ef32016-01-30 16:37:56 -0700360
Svyatoslav Ryhel7673aba2023-03-27 11:11:46 +0300361 ret = panel_set_backlight(priv->panel, BACKLIGHT_DEFAULT);
362 if (ret) {
363 debug("%s: Cannot set backlight to default, ret=%d\n", __func__, ret);
364 return ret;
365 }
366
Simon Glassbbdae4b2016-05-08 16:55:21 -0600367 mmu_set_region_dcache_behaviour(priv->frame_buffer, plat->size,
368 DCACHE_WRITETHROUGH);
Simon Glasse865ef32016-01-30 16:37:56 -0700369
370 /* Enable flushing after LCD writes if requested */
Simon Glassbbdae4b2016-05-08 16:55:21 -0600371 video_set_flush_dcache(dev, true);
Simon Glasse865ef32016-01-30 16:37:56 -0700372
373 uc_priv->xsize = priv->width;
374 uc_priv->ysize = priv->height;
375 uc_priv->bpix = priv->log2_bpp;
376 debug("LCD frame buffer at %pa, size %x\n", &priv->frame_buffer,
377 plat->size);
378
379 return 0;
380}
381
Simon Glassaad29ae2020-12-03 16:55:21 -0700382static int tegra_lcd_of_to_plat(struct udevice *dev)
Simon Glass60740e72016-01-30 16:37:59 -0700383{
384 struct tegra_lcd_priv *priv = dev_get_priv(dev);
385 const void *blob = gd->fdt_blob;
Simon Glass44fe9e42016-05-08 16:55:20 -0600386 struct display_timing *timing;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700387 int node = dev_of_offset(dev);
Simon Glass60740e72016-01-30 16:37:59 -0700388 int panel_node;
389 int rgb;
Simon Glassd8af3c92016-01-30 16:38:01 -0700390 int ret;
Simon Glass60740e72016-01-30 16:37:59 -0700391
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +0300392 priv->dc = (struct dc_ctlr *)dev_read_addr_ptr(dev);
393 if (!priv->dc) {
Simon Glass60740e72016-01-30 16:37:59 -0700394 debug("%s: No display controller address\n", __func__);
395 return -EINVAL;
396 }
397
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200398 priv->soc = (struct tegra_dc_soc_info *)dev_get_driver_data(dev);
399
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300400 ret = clock_decode_pair(dev, priv->dc_clk);
401 if (ret < 0) {
402 debug("%s: Cannot decode clocks for '%s' (ret = %d)\n",
403 __func__, dev->name, ret);
404 return -EINVAL;
405 }
406
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300407 priv->rotation = dev_read_bool(dev, "nvidia,180-rotation");
408
Simon Glass60740e72016-01-30 16:37:59 -0700409 rgb = fdt_subnode_offset(blob, node, "rgb");
Simon Glass44fe9e42016-05-08 16:55:20 -0600410 if (rgb < 0) {
411 debug("%s: Cannot find rgb subnode for '%s' (ret=%d)\n",
412 __func__, dev->name, rgb);
Simon Glass60740e72016-01-30 16:37:59 -0700413 return -EINVAL;
414 }
415
Simon Glass44fe9e42016-05-08 16:55:20 -0600416 /*
417 * Sadly the panel phandle is in an rgb subnode so we cannot use
418 * uclass_get_device_by_phandle().
419 */
420 panel_node = fdtdec_lookup_phandle(blob, rgb, "nvidia,panel");
421 if (panel_node < 0) {
422 debug("%s: Cannot find panel information\n", __func__);
Simon Glass60740e72016-01-30 16:37:59 -0700423 return -EINVAL;
424 }
Svyatoslav Ryheld8806292023-03-27 11:11:43 +0300425
Simon Glass44fe9e42016-05-08 16:55:20 -0600426 ret = uclass_get_device_by_of_offset(UCLASS_PANEL, panel_node,
427 &priv->panel);
Simon Glassd8af3c92016-01-30 16:38:01 -0700428 if (ret) {
Simon Glass44fe9e42016-05-08 16:55:20 -0600429 debug("%s: Cannot find panel for '%s' (ret=%d)\n", __func__,
430 dev->name, ret);
431 return ret;
Simon Glassd8af3c92016-01-30 16:38:01 -0700432 }
Simon Glass60740e72016-01-30 16:37:59 -0700433
Svyatoslav Ryhel0c8aa5e2023-03-27 11:11:47 +0300434 if (!strcmp(priv->panel->name, TEGRA_DSI_A) ||
435 !strcmp(priv->panel->name, TEGRA_DSI_B)) {
436 struct tegra_dc_plat *dc_plat = dev_get_plat(priv->panel);
437
438 dc_plat->dev = dev;
439 dc_plat->dc = priv->dc;
440 }
441
Svyatoslav Ryheld8806292023-03-27 11:11:43 +0300442 ret = panel_get_display_timing(priv->panel, &priv->timing);
443 if (ret) {
444 ret = fdtdec_decode_display_timing(blob, rgb, 0, &priv->timing);
445 if (ret) {
446 debug("%s: Cannot read display timing for '%s' (ret=%d)\n",
447 __func__, dev->name, ret);
448 return -EINVAL;
449 }
450 }
451
452 timing = &priv->timing;
453 priv->width = timing->hactive.typ;
454 priv->height = timing->vactive.typ;
455 priv->pixel_clock = timing->pixelclock.typ;
456 priv->log2_bpp = VIDEO_BPP16;
457
Simon Glass60740e72016-01-30 16:37:59 -0700458 return 0;
459}
460
Simon Glasse865ef32016-01-30 16:37:56 -0700461static int tegra_lcd_bind(struct udevice *dev)
462{
Simon Glassb75b15b2020-12-03 16:55:23 -0700463 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Stephen Warren225da8b2016-04-19 16:19:30 -0600464 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700465 int node = dev_of_offset(dev);
Stephen Warren225da8b2016-04-19 16:19:30 -0600466 int rgb;
467
468 rgb = fdt_subnode_offset(blob, node, "rgb");
469 if ((rgb < 0) || !fdtdec_get_is_enabled(blob, rgb))
470 return -ENODEV;
Simon Glasse865ef32016-01-30 16:37:56 -0700471
472 plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
473 (1 << LCD_MAX_LOG2_BPP) / 8;
474
475 return 0;
Simon Glasse161ccf2012-10-17 13:24:51 +0000476}
Simon Glasse865ef32016-01-30 16:37:56 -0700477
478static const struct video_ops tegra_lcd_ops = {
479};
480
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200481static const struct tegra_dc_soc_info tegra20_dc_soc_info = {
482 .has_timer = true,
483 .has_rgb = true,
484};
485
486static const struct tegra_dc_soc_info tegra30_dc_soc_info = {
487 .has_timer = false,
488 .has_rgb = true,
489};
490
491static const struct tegra_dc_soc_info tegra114_dc_soc_info = {
492 .has_timer = false,
493 .has_rgb = false,
494};
495
Simon Glasse865ef32016-01-30 16:37:56 -0700496static const struct udevice_id tegra_lcd_ids[] = {
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200497 {
498 .compatible = "nvidia,tegra20-dc",
499 .data = (ulong)&tegra20_dc_soc_info
500 }, {
501 .compatible = "nvidia,tegra30-dc",
502 .data = (ulong)&tegra30_dc_soc_info
503 }, {
504 .compatible = "nvidia,tegra114-dc",
505 .data = (ulong)&tegra114_dc_soc_info
506 }, {
507 /* sentinel */
508 }
Simon Glasse865ef32016-01-30 16:37:56 -0700509};
510
511U_BOOT_DRIVER(tegra_lcd) = {
Svyatoslav Ryhel9d53a7b2024-01-23 19:16:16 +0200512 .name = "tegra_lcd",
513 .id = UCLASS_VIDEO,
514 .of_match = tegra_lcd_ids,
515 .ops = &tegra_lcd_ops,
516 .bind = tegra_lcd_bind,
517 .probe = tegra_lcd_probe,
Simon Glassaad29ae2020-12-03 16:55:21 -0700518 .of_to_plat = tegra_lcd_of_to_plat,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700519 .priv_auto = sizeof(struct tegra_lcd_priv),
Simon Glasse865ef32016-01-30 16:37:56 -0700520};