blob: f53ad46397022c685abcc22c161405d20b50bbfd [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
Simon Glasse161ccf2012-10-17 13:24:51 +00006#include <common.h>
Svyatoslav Ryhel7673aba2023-03-27 11:11:46 +03007#include <backlight.h>
Simon Glasse865ef32016-01-30 16:37:56 -07008#include <dm.h>
Simon Glasse161ccf2012-10-17 13:24:51 +00009#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass44fe9e42016-05-08 16:55:20 -060011#include <panel.h>
Simon Glass655306c2020-05-10 11:39:58 -060012#include <part.h>
Simon Glassd8af3c92016-01-30 16:38:01 -070013#include <pwm.h>
Simon Glasse865ef32016-01-30 16:37:56 -070014#include <video.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glasse161ccf2012-10-17 13:24:51 +000017#include <asm/system.h>
18#include <asm/gpio.h>
Simon Glassd8fc3c52016-01-30 16:37:53 -070019#include <asm/io.h>
Simon Glasse161ccf2012-10-17 13:24:51 +000020
21#include <asm/arch/clock.h>
22#include <asm/arch/funcmux.h>
23#include <asm/arch/pinmux.h>
24#include <asm/arch/pwm.h>
25#include <asm/arch/display.h>
26#include <asm/arch-tegra/timer.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
Simon Glass923128f2016-01-30 16:37:55 -070030/* Information about the display controller */
31struct tegra_lcd_priv {
Simon Glass923128f2016-01-30 16:37:55 -070032 int width; /* width in pixels */
33 int height; /* height in pixels */
Simon Glass44fe9e42016-05-08 16:55:20 -060034 enum video_log2_bpp log2_bpp; /* colour depth */
35 struct display_timing timing;
36 struct udevice *panel;
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +030037 struct dc_ctlr *dc; /* Display controller regmap */
Simon Glass923128f2016-01-30 16:37:55 -070038 fdt_addr_t frame_buffer; /* Address of frame buffer */
39 unsigned pixel_clock; /* Pixel clock in Hz */
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +030040 int dc_clk[2]; /* Contains clk and its parent */
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030041 bool rotation; /* 180 degree panel turn */
Simon Glass923128f2016-01-30 16:37:55 -070042};
43
Simon Glasse161ccf2012-10-17 13:24:51 +000044enum {
45 /* Maximum LCD size we support */
Marcel Ziswilercad56712023-03-27 11:11:40 +030046 LCD_MAX_WIDTH = 1920,
47 LCD_MAX_HEIGHT = 1200,
Simon Glasse865ef32016-01-30 16:37:56 -070048 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
Simon Glasse161ccf2012-10-17 13:24:51 +000049};
50
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030051static void update_window(struct tegra_lcd_priv *priv,
52 struct disp_ctl_win *win)
Simon Glassd8fc3c52016-01-30 16:37:53 -070053{
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030054 struct dc_ctlr *dc = priv->dc;
Simon Glassd8fc3c52016-01-30 16:37:53 -070055 unsigned h_dda, v_dda;
56 unsigned long val;
57
58 val = readl(&dc->cmd.disp_win_header);
59 val |= WINDOW_A_SELECT;
60 writel(val, &dc->cmd.disp_win_header);
61
62 writel(win->fmt, &dc->win.color_depth);
63
64 clrsetbits_le32(&dc->win.byte_swap, BYTE_SWAP_MASK,
65 BYTE_SWAP_NOSWAP << BYTE_SWAP_SHIFT);
66
67 val = win->out_x << H_POSITION_SHIFT;
68 val |= win->out_y << V_POSITION_SHIFT;
69 writel(val, &dc->win.pos);
70
71 val = win->out_w << H_SIZE_SHIFT;
72 val |= win->out_h << V_SIZE_SHIFT;
73 writel(val, &dc->win.size);
74
75 val = (win->w * win->bpp / 8) << H_PRESCALED_SIZE_SHIFT;
76 val |= win->h << V_PRESCALED_SIZE_SHIFT;
77 writel(val, &dc->win.prescaled_size);
78
79 writel(0, &dc->win.h_initial_dda);
80 writel(0, &dc->win.v_initial_dda);
81
82 h_dda = (win->w * 0x1000) / max(win->out_w - 1, 1U);
83 v_dda = (win->h * 0x1000) / max(win->out_h - 1, 1U);
84
85 val = h_dda << H_DDA_INC_SHIFT;
86 val |= v_dda << V_DDA_INC_SHIFT;
87 writel(val, &dc->win.dda_increment);
88
89 writel(win->stride, &dc->win.line_stride);
90 writel(0, &dc->win.buf_stride);
91
92 val = WIN_ENABLE;
93 if (win->bpp < 24)
94 val |= COLOR_EXPAND;
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +030095
96 if (priv->rotation)
97 val |= H_DIRECTION | V_DIRECTION;
98
Simon Glassd8fc3c52016-01-30 16:37:53 -070099 writel(val, &dc->win.win_opt);
100
101 writel((unsigned long)win->phys_addr, &dc->winbuf.start_addr);
102 writel(win->x, &dc->winbuf.addr_h_offset);
103 writel(win->y, &dc->winbuf.addr_v_offset);
104
105 writel(0xff00, &dc->win.blend_nokey);
106 writel(0xff00, &dc->win.blend_1win);
107
108 val = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
109 val |= GENERAL_UPDATE | WIN_A_UPDATE;
110 writel(val, &dc->cmd.state_ctrl);
111}
112
Simon Glassd8fc3c52016-01-30 16:37:53 -0700113static int update_display_mode(struct dc_disp_reg *disp,
Simon Glasse865ef32016-01-30 16:37:56 -0700114 struct tegra_lcd_priv *priv)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700115{
Simon Glass44fe9e42016-05-08 16:55:20 -0600116 struct display_timing *dt = &priv->timing;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700117 unsigned long val;
118 unsigned long rate;
119 unsigned long div;
120
121 writel(0x0, &disp->disp_timing_opt);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700122
Simon Glass44fe9e42016-05-08 16:55:20 -0600123 writel(1 | 1 << 16, &disp->ref_to_sync);
124 writel(dt->hsync_len.typ | dt->vsync_len.typ << 16, &disp->sync_width);
125 writel(dt->hback_porch.typ | dt->vback_porch.typ << 16,
126 &disp->back_porch);
127 writel((dt->hfront_porch.typ - 1) | (dt->vfront_porch.typ - 1) << 16,
128 &disp->front_porch);
129 writel(dt->hactive.typ | (dt->vactive.typ << 16), &disp->disp_active);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700130
131 val = DE_SELECT_ACTIVE << DE_SELECT_SHIFT;
132 val |= DE_CONTROL_NORMAL << DE_CONTROL_SHIFT;
133 writel(val, &disp->data_enable_opt);
134
135 val = DATA_FORMAT_DF1P1C << DATA_FORMAT_SHIFT;
136 val |= DATA_ALIGNMENT_MSB << DATA_ALIGNMENT_SHIFT;
137 val |= DATA_ORDER_RED_BLUE << DATA_ORDER_SHIFT;
138 writel(val, &disp->disp_interface_ctrl);
139
140 /*
141 * The pixel clock divider is in 7.1 format (where the bottom bit
142 * represents 0.5). Here we calculate the divider needed to get from
143 * the display clock (typically 600MHz) to the pixel clock. We round
144 * up or down as requried.
145 */
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300146 rate = clock_get_periph_rate(priv->dc_clk[0], priv->dc_clk[1]);
Simon Glasse865ef32016-01-30 16:37:56 -0700147 div = ((rate * 2 + priv->pixel_clock / 2) / priv->pixel_clock) - 2;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700148 debug("Display clock %lu, divider %lu\n", rate, div);
149
150 writel(0x00010001, &disp->shift_clk_opt);
151
152 val = PIXEL_CLK_DIVIDER_PCD1 << PIXEL_CLK_DIVIDER_SHIFT;
153 val |= div << SHIFT_CLK_DIVIDER_SHIFT;
154 writel(val, &disp->disp_clk_ctrl);
155
156 return 0;
157}
158
159/* Start up the display and turn on power to PWMs */
160static void basic_init(struct dc_cmd_reg *cmd)
161{
162 u32 val;
163
164 writel(0x00000100, &cmd->gen_incr_syncpt_ctrl);
165 writel(0x0000011a, &cmd->cont_syncpt_vsync);
166 writel(0x00000000, &cmd->int_type);
167 writel(0x00000000, &cmd->int_polarity);
168 writel(0x00000000, &cmd->int_mask);
169 writel(0x00000000, &cmd->int_enb);
170
171 val = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE;
172 val |= PW3_ENABLE | PW4_ENABLE | PM0_ENABLE;
173 val |= PM1_ENABLE;
174 writel(val, &cmd->disp_pow_ctrl);
175
176 val = readl(&cmd->disp_cmd);
177 val |= CTRL_MODE_C_DISPLAY << CTRL_MODE_SHIFT;
178 writel(val, &cmd->disp_cmd);
179}
180
181static void basic_init_timer(struct dc_disp_reg *disp)
182{
183 writel(0x00000020, &disp->mem_high_pri);
184 writel(0x00000001, &disp->mem_high_pri_timer);
185}
186
187static const u32 rgb_enb_tab[PIN_REG_COUNT] = {
188 0x00000000,
189 0x00000000,
190 0x00000000,
191 0x00000000,
192};
193
194static const u32 rgb_polarity_tab[PIN_REG_COUNT] = {
195 0x00000000,
196 0x01000000,
197 0x00000000,
198 0x00000000,
199};
200
201static const u32 rgb_data_tab[PIN_REG_COUNT] = {
202 0x00000000,
203 0x00000000,
204 0x00000000,
205 0x00000000,
206};
207
208static const u32 rgb_sel_tab[PIN_OUTPUT_SEL_COUNT] = {
209 0x00000000,
210 0x00000000,
211 0x00000000,
212 0x00000000,
213 0x00210222,
214 0x00002200,
215 0x00020000,
216};
217
218static void rgb_enable(struct dc_com_reg *com)
219{
220 int i;
221
222 for (i = 0; i < PIN_REG_COUNT; i++) {
223 writel(rgb_enb_tab[i], &com->pin_output_enb[i]);
224 writel(rgb_polarity_tab[i], &com->pin_output_polarity[i]);
225 writel(rgb_data_tab[i], &com->pin_output_data[i]);
226 }
227
228 for (i = 0; i < PIN_OUTPUT_SEL_COUNT; i++)
229 writel(rgb_sel_tab[i], &com->pin_output_sel[i]);
230}
231
232static int setup_window(struct disp_ctl_win *win,
Simon Glasse865ef32016-01-30 16:37:56 -0700233 struct tegra_lcd_priv *priv)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700234{
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300235 if (priv->rotation) {
236 win->x = priv->width * 2;
237 win->y = priv->height;
238 } else {
239 win->x = 0;
240 win->y = 0;
241 }
242
Simon Glasse865ef32016-01-30 16:37:56 -0700243 win->w = priv->width;
244 win->h = priv->height;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700245 win->out_x = 0;
246 win->out_y = 0;
Simon Glasse865ef32016-01-30 16:37:56 -0700247 win->out_w = priv->width;
248 win->out_h = priv->height;
249 win->phys_addr = priv->frame_buffer;
250 win->stride = priv->width * (1 << priv->log2_bpp) / 8;
251 debug("%s: depth = %d\n", __func__, priv->log2_bpp);
252 switch (priv->log2_bpp) {
Simon Glass44fe9e42016-05-08 16:55:20 -0600253 case VIDEO_BPP32:
Simon Glassd8fc3c52016-01-30 16:37:53 -0700254 win->fmt = COLOR_DEPTH_R8G8B8A8;
255 win->bpp = 32;
256 break;
Simon Glass44fe9e42016-05-08 16:55:20 -0600257 case VIDEO_BPP16:
Simon Glassd8fc3c52016-01-30 16:37:53 -0700258 win->fmt = COLOR_DEPTH_B5G6R5;
259 win->bpp = 16;
260 break;
261
262 default:
263 debug("Unsupported LCD bit depth");
264 return -1;
265 }
266
267 return 0;
268}
269
Simon Glassd8fc3c52016-01-30 16:37:53 -0700270/**
Simon Glassd8fc3c52016-01-30 16:37:53 -0700271 * Register a new display based on device tree configuration.
272 *
Robert P. J. Day8d56db92016-07-15 13:44:45 -0400273 * The frame buffer can be positioned by U-Boot or overridden by the fdt.
Simon Glassd8fc3c52016-01-30 16:37:53 -0700274 * You should pass in the U-Boot address here, and check the contents of
Simon Glass923128f2016-01-30 16:37:55 -0700275 * struct tegra_lcd_priv to see what was actually chosen.
Simon Glassd8fc3c52016-01-30 16:37:53 -0700276 *
277 * @param blob Device tree blob
Simon Glasse865ef32016-01-30 16:37:56 -0700278 * @param priv Driver's private data
Simon Glassd8fc3c52016-01-30 16:37:53 -0700279 * @param default_lcd_base Default address of LCD frame buffer
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100280 * Return: 0 if ok, -1 on error (unsupported bits per pixel)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700281 */
Simon Glasse865ef32016-01-30 16:37:56 -0700282static int tegra_display_probe(const void *blob, struct tegra_lcd_priv *priv,
283 void *default_lcd_base)
Simon Glassd8fc3c52016-01-30 16:37:53 -0700284{
285 struct disp_ctl_win window;
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300286 unsigned long rate = clock_get_rate(priv->dc_clk[1]);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700287
Simon Glasse865ef32016-01-30 16:37:56 -0700288 priv->frame_buffer = (u32)default_lcd_base;
Simon Glassd8fc3c52016-01-30 16:37:53 -0700289
Simon Glassd8fc3c52016-01-30 16:37:53 -0700290 /*
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300291 * We halve the rate if DISP1 paret is PLLD, since actual parent
292 * is plld_out0 which is PLLD divided by 2.
Simon Glassd8fc3c52016-01-30 16:37:53 -0700293 */
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300294 if (priv->dc_clk[1] == CLOCK_ID_DISPLAY)
295 rate /= 2;
296
297 /*
298 * HOST1X is init by default at 150MHz with PLLC as parent
299 */
300 clock_start_periph_pll(PERIPH_ID_HOST1X, CLOCK_ID_CGENERAL,
301 150 * 1000000);
302 clock_start_periph_pll(priv->dc_clk[0], priv->dc_clk[1],
303 rate);
304
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +0300305 basic_init(&priv->dc->cmd);
306 basic_init_timer(&priv->dc->disp);
307 rgb_enable(&priv->dc->com);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700308
Simon Glasse865ef32016-01-30 16:37:56 -0700309 if (priv->pixel_clock)
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +0300310 update_display_mode(&priv->dc->disp, priv);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700311
Simon Glasse865ef32016-01-30 16:37:56 -0700312 if (setup_window(&window, priv))
Simon Glassd8fc3c52016-01-30 16:37:53 -0700313 return -1;
314
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300315 update_window(priv, &window);
Simon Glassd8fc3c52016-01-30 16:37:53 -0700316
317 return 0;
318}
319
Simon Glasse865ef32016-01-30 16:37:56 -0700320static int tegra_lcd_probe(struct udevice *dev)
Simon Glasse161ccf2012-10-17 13:24:51 +0000321{
Simon Glassb75b15b2020-12-03 16:55:23 -0700322 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glasse865ef32016-01-30 16:37:56 -0700323 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
324 struct tegra_lcd_priv *priv = dev_get_priv(dev);
325 const void *blob = gd->fdt_blob;
Simon Glass44fe9e42016-05-08 16:55:20 -0600326 int ret;
Simon Glasse865ef32016-01-30 16:37:56 -0700327
Simon Glasse865ef32016-01-30 16:37:56 -0700328 /* Initialize the Tegra display controller */
Marcel Ziswilercad56712023-03-27 11:11:40 +0300329#ifdef CONFIG_TEGRA20
Simon Glass44fe9e42016-05-08 16:55:20 -0600330 funcmux_select(PERIPH_ID_DISP1, FUNCMUX_DEFAULT);
Marcel Ziswilercad56712023-03-27 11:11:40 +0300331#endif
332
Simon Glasse865ef32016-01-30 16:37:56 -0700333 if (tegra_display_probe(blob, priv, (void *)plat->base)) {
334 printf("%s: Failed to probe display driver\n", __func__);
335 return -1;
Simon Glasse161ccf2012-10-17 13:24:51 +0000336 }
Simon Glasse865ef32016-01-30 16:37:56 -0700337
Marcel Ziswilercad56712023-03-27 11:11:40 +0300338#ifdef CONFIG_TEGRA20
Simon Glass44fe9e42016-05-08 16:55:20 -0600339 pinmux_set_func(PMUX_PINGRP_GPU, PMUX_FUNC_PWM);
340 pinmux_tristate_disable(PMUX_PINGRP_GPU);
Marcel Ziswilercad56712023-03-27 11:11:40 +0300341#endif
Simon Glass44fe9e42016-05-08 16:55:20 -0600342
343 ret = panel_enable_backlight(priv->panel);
344 if (ret) {
345 debug("%s: Cannot enable backlight, ret=%d\n", __func__, ret);
346 return ret;
347 }
Simon Glasse865ef32016-01-30 16:37:56 -0700348
Svyatoslav Ryhel7673aba2023-03-27 11:11:46 +0300349 ret = panel_set_backlight(priv->panel, BACKLIGHT_DEFAULT);
350 if (ret) {
351 debug("%s: Cannot set backlight to default, ret=%d\n", __func__, ret);
352 return ret;
353 }
354
Simon Glassbbdae4b2016-05-08 16:55:21 -0600355 mmu_set_region_dcache_behaviour(priv->frame_buffer, plat->size,
356 DCACHE_WRITETHROUGH);
Simon Glasse865ef32016-01-30 16:37:56 -0700357
358 /* Enable flushing after LCD writes if requested */
Simon Glassbbdae4b2016-05-08 16:55:21 -0600359 video_set_flush_dcache(dev, true);
Simon Glasse865ef32016-01-30 16:37:56 -0700360
361 uc_priv->xsize = priv->width;
362 uc_priv->ysize = priv->height;
363 uc_priv->bpix = priv->log2_bpp;
364 debug("LCD frame buffer at %pa, size %x\n", &priv->frame_buffer,
365 plat->size);
366
367 return 0;
368}
369
Simon Glassaad29ae2020-12-03 16:55:21 -0700370static int tegra_lcd_of_to_plat(struct udevice *dev)
Simon Glass60740e72016-01-30 16:37:59 -0700371{
372 struct tegra_lcd_priv *priv = dev_get_priv(dev);
373 const void *blob = gd->fdt_blob;
Simon Glass44fe9e42016-05-08 16:55:20 -0600374 struct display_timing *timing;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700375 int node = dev_of_offset(dev);
Simon Glass60740e72016-01-30 16:37:59 -0700376 int panel_node;
377 int rgb;
Simon Glassd8af3c92016-01-30 16:38:01 -0700378 int ret;
Simon Glass60740e72016-01-30 16:37:59 -0700379
Svyatoslav Ryhel9716fe52023-03-27 11:11:44 +0300380 priv->dc = (struct dc_ctlr *)dev_read_addr_ptr(dev);
381 if (!priv->dc) {
Simon Glass60740e72016-01-30 16:37:59 -0700382 debug("%s: No display controller address\n", __func__);
383 return -EINVAL;
384 }
385
Svyatoslav Ryhelc1f260a2023-03-27 11:11:42 +0300386 ret = clock_decode_pair(dev, priv->dc_clk);
387 if (ret < 0) {
388 debug("%s: Cannot decode clocks for '%s' (ret = %d)\n",
389 __func__, dev->name, ret);
390 return -EINVAL;
391 }
392
Svyatoslav Ryhel4f5b79b2023-03-27 11:11:45 +0300393 priv->rotation = dev_read_bool(dev, "nvidia,180-rotation");
394
Simon Glass60740e72016-01-30 16:37:59 -0700395 rgb = fdt_subnode_offset(blob, node, "rgb");
Simon Glass44fe9e42016-05-08 16:55:20 -0600396 if (rgb < 0) {
397 debug("%s: Cannot find rgb subnode for '%s' (ret=%d)\n",
398 __func__, dev->name, rgb);
Simon Glass60740e72016-01-30 16:37:59 -0700399 return -EINVAL;
400 }
401
Simon Glass44fe9e42016-05-08 16:55:20 -0600402 /*
403 * Sadly the panel phandle is in an rgb subnode so we cannot use
404 * uclass_get_device_by_phandle().
405 */
406 panel_node = fdtdec_lookup_phandle(blob, rgb, "nvidia,panel");
407 if (panel_node < 0) {
408 debug("%s: Cannot find panel information\n", __func__);
Simon Glass60740e72016-01-30 16:37:59 -0700409 return -EINVAL;
410 }
Svyatoslav Ryheld8806292023-03-27 11:11:43 +0300411
Simon Glass44fe9e42016-05-08 16:55:20 -0600412 ret = uclass_get_device_by_of_offset(UCLASS_PANEL, panel_node,
413 &priv->panel);
Simon Glassd8af3c92016-01-30 16:38:01 -0700414 if (ret) {
Simon Glass44fe9e42016-05-08 16:55:20 -0600415 debug("%s: Cannot find panel for '%s' (ret=%d)\n", __func__,
416 dev->name, ret);
417 return ret;
Simon Glassd8af3c92016-01-30 16:38:01 -0700418 }
Simon Glass60740e72016-01-30 16:37:59 -0700419
Svyatoslav Ryhel0c8aa5e2023-03-27 11:11:47 +0300420 if (!strcmp(priv->panel->name, TEGRA_DSI_A) ||
421 !strcmp(priv->panel->name, TEGRA_DSI_B)) {
422 struct tegra_dc_plat *dc_plat = dev_get_plat(priv->panel);
423
424 dc_plat->dev = dev;
425 dc_plat->dc = priv->dc;
426 }
427
Svyatoslav Ryheld8806292023-03-27 11:11:43 +0300428 ret = panel_get_display_timing(priv->panel, &priv->timing);
429 if (ret) {
430 ret = fdtdec_decode_display_timing(blob, rgb, 0, &priv->timing);
431 if (ret) {
432 debug("%s: Cannot read display timing for '%s' (ret=%d)\n",
433 __func__, dev->name, ret);
434 return -EINVAL;
435 }
436 }
437
438 timing = &priv->timing;
439 priv->width = timing->hactive.typ;
440 priv->height = timing->vactive.typ;
441 priv->pixel_clock = timing->pixelclock.typ;
442 priv->log2_bpp = VIDEO_BPP16;
443
Simon Glass60740e72016-01-30 16:37:59 -0700444 return 0;
445}
446
Simon Glasse865ef32016-01-30 16:37:56 -0700447static int tegra_lcd_bind(struct udevice *dev)
448{
Simon Glassb75b15b2020-12-03 16:55:23 -0700449 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Stephen Warren225da8b2016-04-19 16:19:30 -0600450 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700451 int node = dev_of_offset(dev);
Stephen Warren225da8b2016-04-19 16:19:30 -0600452 int rgb;
453
454 rgb = fdt_subnode_offset(blob, node, "rgb");
455 if ((rgb < 0) || !fdtdec_get_is_enabled(blob, rgb))
456 return -ENODEV;
Simon Glasse865ef32016-01-30 16:37:56 -0700457
458 plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
459 (1 << LCD_MAX_LOG2_BPP) / 8;
460
461 return 0;
Simon Glasse161ccf2012-10-17 13:24:51 +0000462}
Simon Glasse865ef32016-01-30 16:37:56 -0700463
464static const struct video_ops tegra_lcd_ops = {
465};
466
467static const struct udevice_id tegra_lcd_ids[] = {
468 { .compatible = "nvidia,tegra20-dc" },
Marcel Ziswilercad56712023-03-27 11:11:40 +0300469 { .compatible = "nvidia,tegra30-dc" },
Simon Glasse865ef32016-01-30 16:37:56 -0700470 { }
471};
472
473U_BOOT_DRIVER(tegra_lcd) = {
474 .name = "tegra_lcd",
475 .id = UCLASS_VIDEO,
476 .of_match = tegra_lcd_ids,
477 .ops = &tegra_lcd_ops,
478 .bind = tegra_lcd_bind,
479 .probe = tegra_lcd_probe,
Simon Glassaad29ae2020-12-03 16:55:21 -0700480 .of_to_plat = tegra_lcd_of_to_plat,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700481 .priv_auto = sizeof(struct tegra_lcd_priv),
Simon Glasse865ef32016-01-30 16:37:56 -0700482};