blob: 59ff692b0b4cf98cf3ca036a9ca8142e2a239108 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Philippe CORNUdcbad9a2017-08-03 12:36:08 +02002/*
yannick fertre3e6077c2018-03-02 15:59:22 +01003 * Copyright (C) 2017-2018 STMicroelectronics - All Rights Reserved
4 * Author(s): Philippe Cornu <philippe.cornu@st.com> for STMicroelectronics.
5 * Yannick Fertre <yannick.fertre@st.com> for STMicroelectronics.
Philippe CORNUdcbad9a2017-08-03 12:36:08 +02006 */
7
8#include <common.h>
9#include <clk.h>
Yannick Fertréd6117082019-10-07 15:29:02 +020010#include <display.h>
Philippe CORNUdcbad9a2017-08-03 12:36:08 +020011#include <dm.h>
12#include <panel.h>
yannick fertre28dc09b2018-03-02 15:59:21 +010013#include <reset.h>
Philippe CORNUdcbad9a2017-08-03 12:36:08 +020014#include <video.h>
Yannick Fertréd6117082019-10-07 15:29:02 +020015#include <video_bridge.h>
Philippe CORNUdcbad9a2017-08-03 12:36:08 +020016#include <asm/io.h>
17#include <asm/arch/gpio.h>
18#include <dm/device-internal.h>
19
Philippe CORNUdcbad9a2017-08-03 12:36:08 +020020struct stm32_ltdc_priv {
21 void __iomem *regs;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +020022 enum video_log2_bpp l2bpp;
23 u32 bg_col_argb;
24 u32 crop_x, crop_y, crop_w, crop_h;
25 u32 alpha;
26};
27
28/* LTDC main registers */
29#define LTDC_IDR 0x00 /* IDentification */
30#define LTDC_LCR 0x04 /* Layer Count */
31#define LTDC_SSCR 0x08 /* Synchronization Size Configuration */
32#define LTDC_BPCR 0x0C /* Back Porch Configuration */
33#define LTDC_AWCR 0x10 /* Active Width Configuration */
34#define LTDC_TWCR 0x14 /* Total Width Configuration */
35#define LTDC_GCR 0x18 /* Global Control */
36#define LTDC_GC1R 0x1C /* Global Configuration 1 */
37#define LTDC_GC2R 0x20 /* Global Configuration 2 */
38#define LTDC_SRCR 0x24 /* Shadow Reload Configuration */
39#define LTDC_GACR 0x28 /* GAmma Correction */
40#define LTDC_BCCR 0x2C /* Background Color Configuration */
41#define LTDC_IER 0x34 /* Interrupt Enable */
42#define LTDC_ISR 0x38 /* Interrupt Status */
43#define LTDC_ICR 0x3C /* Interrupt Clear */
44#define LTDC_LIPCR 0x40 /* Line Interrupt Position Conf. */
45#define LTDC_CPSR 0x44 /* Current Position Status */
46#define LTDC_CDSR 0x48 /* Current Display Status */
47
48/* LTDC layer 1 registers */
49#define LTDC_L1LC1R 0x80 /* L1 Layer Configuration 1 */
50#define LTDC_L1LC2R 0x84 /* L1 Layer Configuration 2 */
51#define LTDC_L1CR 0x84 /* L1 Control */
52#define LTDC_L1WHPCR 0x88 /* L1 Window Hor Position Config */
53#define LTDC_L1WVPCR 0x8C /* L1 Window Vert Position Config */
54#define LTDC_L1CKCR 0x90 /* L1 Color Keying Configuration */
55#define LTDC_L1PFCR 0x94 /* L1 Pixel Format Configuration */
56#define LTDC_L1CACR 0x98 /* L1 Constant Alpha Config */
57#define LTDC_L1DCCR 0x9C /* L1 Default Color Configuration */
58#define LTDC_L1BFCR 0xA0 /* L1 Blend Factors Configuration */
59#define LTDC_L1FBBCR 0xA4 /* L1 FrameBuffer Bus Control */
60#define LTDC_L1AFBCR 0xA8 /* L1 AuxFB Control */
61#define LTDC_L1CFBAR 0xAC /* L1 Color FrameBuffer Address */
62#define LTDC_L1CFBLR 0xB0 /* L1 Color FrameBuffer Length */
63#define LTDC_L1CFBLNR 0xB4 /* L1 Color FrameBuffer Line Nb */
64#define LTDC_L1AFBAR 0xB8 /* L1 AuxFB Address */
65#define LTDC_L1AFBLR 0xBC /* L1 AuxFB Length */
66#define LTDC_L1AFBLNR 0xC0 /* L1 AuxFB Line Number */
67#define LTDC_L1CLUTWR 0xC4 /* L1 CLUT Write */
68
69/* Bit definitions */
70#define SSCR_VSH GENMASK(10, 0) /* Vertical Synchronization Height */
71#define SSCR_HSW GENMASK(27, 16) /* Horizontal Synchronization Width */
72
73#define BPCR_AVBP GENMASK(10, 0) /* Accumulated Vertical Back Porch */
74#define BPCR_AHBP GENMASK(27, 16) /* Accumulated Horizontal Back Porch */
75
76#define AWCR_AAH GENMASK(10, 0) /* Accumulated Active Height */
77#define AWCR_AAW GENMASK(27, 16) /* Accumulated Active Width */
78
79#define TWCR_TOTALH GENMASK(10, 0) /* TOTAL Height */
80#define TWCR_TOTALW GENMASK(27, 16) /* TOTAL Width */
81
82#define GCR_LTDCEN BIT(0) /* LTDC ENable */
83#define GCR_DEN BIT(16) /* Dither ENable */
84#define GCR_PCPOL BIT(28) /* Pixel Clock POLarity-Inverted */
85#define GCR_DEPOL BIT(29) /* Data Enable POLarity-High */
86#define GCR_VSPOL BIT(30) /* Vertical Synchro POLarity-High */
87#define GCR_HSPOL BIT(31) /* Horizontal Synchro POLarity-High */
88
89#define GC1R_WBCH GENMASK(3, 0) /* Width of Blue CHannel output */
90#define GC1R_WGCH GENMASK(7, 4) /* Width of Green Channel output */
91#define GC1R_WRCH GENMASK(11, 8) /* Width of Red Channel output */
92#define GC1R_PBEN BIT(12) /* Precise Blending ENable */
93#define GC1R_DT GENMASK(15, 14) /* Dithering Technique */
94#define GC1R_GCT GENMASK(19, 17) /* Gamma Correction Technique */
95#define GC1R_SHREN BIT(21) /* SHadow Registers ENabled */
96#define GC1R_BCP BIT(22) /* Background Colour Programmable */
97#define GC1R_BBEN BIT(23) /* Background Blending ENabled */
98#define GC1R_LNIP BIT(24) /* Line Number IRQ Position */
99#define GC1R_TP BIT(25) /* Timing Programmable */
100#define GC1R_IPP BIT(26) /* IRQ Polarity Programmable */
101#define GC1R_SPP BIT(27) /* Sync Polarity Programmable */
102#define GC1R_DWP BIT(28) /* Dither Width Programmable */
103#define GC1R_STREN BIT(29) /* STatus Registers ENabled */
104#define GC1R_BMEN BIT(31) /* Blind Mode ENabled */
105
106#define GC2R_EDCA BIT(0) /* External Display Control Ability */
107#define GC2R_STSAEN BIT(1) /* Slave Timing Sync Ability ENabled */
108#define GC2R_DVAEN BIT(2) /* Dual-View Ability ENabled */
109#define GC2R_DPAEN BIT(3) /* Dual-Port Ability ENabled */
110#define GC2R_BW GENMASK(6, 4) /* Bus Width (log2 of nb of bytes) */
111#define GC2R_EDCEN BIT(7) /* External Display Control ENabled */
112
113#define SRCR_IMR BIT(0) /* IMmediate Reload */
114#define SRCR_VBR BIT(1) /* Vertical Blanking Reload */
115
116#define LXCR_LEN BIT(0) /* Layer ENable */
117#define LXCR_COLKEN BIT(1) /* Color Keying Enable */
118#define LXCR_CLUTEN BIT(4) /* Color Look-Up Table ENable */
119
120#define LXWHPCR_WHSTPOS GENMASK(11, 0) /* Window Horizontal StarT POSition */
121#define LXWHPCR_WHSPPOS GENMASK(27, 16) /* Window Horizontal StoP POSition */
122
123#define LXWVPCR_WVSTPOS GENMASK(10, 0) /* Window Vertical StarT POSition */
124#define LXWVPCR_WVSPPOS GENMASK(26, 16) /* Window Vertical StoP POSition */
125
126#define LXPFCR_PF GENMASK(2, 0) /* Pixel Format */
127
128#define LXCACR_CONSTA GENMASK(7, 0) /* CONSTant Alpha */
129
130#define LXBFCR_BF2 GENMASK(2, 0) /* Blending Factor 2 */
131#define LXBFCR_BF1 GENMASK(10, 8) /* Blending Factor 1 */
132
133#define LXCFBLR_CFBLL GENMASK(12, 0) /* Color Frame Buffer Line Length */
134#define LXCFBLR_CFBP GENMASK(28, 16) /* Color Frame Buffer Pitch in bytes */
135
136#define LXCFBLNR_CFBLN GENMASK(10, 0) /* Color Frame Buffer Line Number */
137
138#define BF1_PAXCA 0x600 /* Pixel Alpha x Constant Alpha */
yannick fertre8fa461e2018-03-02 15:59:25 +0100139#define BF1_CA 0x400 /* Constant Alpha */
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200140#define BF2_1PAXCA 0x007 /* 1 - (Pixel Alpha x Constant Alpha) */
yannick fertre8fa461e2018-03-02 15:59:25 +0100141#define BF2_1CA 0x005 /* 1 - Constant Alpha */
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200142
143enum stm32_ltdc_pix_fmt {
144 PF_ARGB8888 = 0,
145 PF_RGB888,
146 PF_RGB565,
147 PF_ARGB1555,
148 PF_ARGB4444,
149 PF_L8,
150 PF_AL44,
151 PF_AL88
152};
153
154/* TODO add more color format support */
155static u32 stm32_ltdc_get_pixel_format(enum video_log2_bpp l2bpp)
156{
157 enum stm32_ltdc_pix_fmt pf;
158
159 switch (l2bpp) {
160 case VIDEO_BPP16:
161 pf = PF_RGB565;
162 break;
163
yannick fertre8fa461e2018-03-02 15:59:25 +0100164 case VIDEO_BPP32:
165 pf = PF_ARGB8888;
166 break;
167
168 case VIDEO_BPP8:
169 pf = PF_L8;
170 break;
171
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200172 case VIDEO_BPP1:
173 case VIDEO_BPP2:
174 case VIDEO_BPP4:
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200175 default:
Yannick Fertréd6117082019-10-07 15:29:02 +0200176 pr_warn("%s: warning %dbpp not supported yet, %dbpp instead\n",
177 __func__, VNBITS(l2bpp), VNBITS(VIDEO_BPP16));
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200178 pf = PF_RGB565;
179 break;
180 }
181
182 debug("%s: %d bpp -> ltdc pf %d\n", __func__, VNBITS(l2bpp), pf);
183
184 return (u32)pf;
185}
186
yannick fertre8fa461e2018-03-02 15:59:25 +0100187static bool has_alpha(u32 fmt)
188{
189 switch (fmt) {
190 case PF_ARGB8888:
191 case PF_ARGB1555:
192 case PF_ARGB4444:
193 case PF_AL44:
194 case PF_AL88:
195 return true;
196 case PF_RGB888:
197 case PF_RGB565:
198 case PF_L8:
199 default:
200 return false;
201 }
202}
203
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200204static void stm32_ltdc_enable(struct stm32_ltdc_priv *priv)
205{
206 /* Reload configuration immediately & enable LTDC */
207 setbits_le32(priv->regs + LTDC_SRCR, SRCR_IMR);
208 setbits_le32(priv->regs + LTDC_GCR, GCR_LTDCEN);
209}
210
Yannick Fertréd6117082019-10-07 15:29:02 +0200211static void stm32_ltdc_set_mode(struct stm32_ltdc_priv *priv,
212 struct display_timing *timings)
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200213{
214 void __iomem *regs = priv->regs;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200215 u32 hsync, vsync, acc_hbp, acc_vbp, acc_act_w, acc_act_h;
216 u32 total_w, total_h;
217 u32 val;
218
219 /* Convert video timings to ltdc timings */
Yannick Fertréd6117082019-10-07 15:29:02 +0200220 hsync = timings->hsync_len.typ - 1;
221 vsync = timings->vsync_len.typ - 1;
222 acc_hbp = hsync + timings->hback_porch.typ;
223 acc_vbp = vsync + timings->vback_porch.typ;
224 acc_act_w = acc_hbp + timings->hactive.typ;
225 acc_act_h = acc_vbp + timings->vactive.typ;
226 total_w = acc_act_w + timings->hfront_porch.typ;
227 total_h = acc_act_h + timings->vfront_porch.typ;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200228
229 /* Synchronization sizes */
230 val = (hsync << 16) | vsync;
231 clrsetbits_le32(regs + LTDC_SSCR, SSCR_VSH | SSCR_HSW, val);
232
233 /* Accumulated back porch */
234 val = (acc_hbp << 16) | acc_vbp;
235 clrsetbits_le32(regs + LTDC_BPCR, BPCR_AVBP | BPCR_AHBP, val);
236
237 /* Accumulated active width */
238 val = (acc_act_w << 16) | acc_act_h;
239 clrsetbits_le32(regs + LTDC_AWCR, AWCR_AAW | AWCR_AAH, val);
240
241 /* Total width & height */
242 val = (total_w << 16) | total_h;
243 clrsetbits_le32(regs + LTDC_TWCR, TWCR_TOTALH | TWCR_TOTALW, val);
244
yannick fertred0cfebf2018-03-02 15:59:24 +0100245 setbits_le32(regs + LTDC_LIPCR, acc_act_h + 1);
246
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200247 /* Signal polarities */
248 val = 0;
Yannick Fertréd6117082019-10-07 15:29:02 +0200249 debug("%s: timing->flags 0x%08x\n", __func__, timings->flags);
250 if (timings->flags & DISPLAY_FLAGS_HSYNC_HIGH)
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200251 val |= GCR_HSPOL;
Yannick Fertréd6117082019-10-07 15:29:02 +0200252 if (timings->flags & DISPLAY_FLAGS_VSYNC_HIGH)
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200253 val |= GCR_VSPOL;
Yannick Fertréd6117082019-10-07 15:29:02 +0200254 if (timings->flags & DISPLAY_FLAGS_DE_HIGH)
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200255 val |= GCR_DEPOL;
Yannick Fertréd6117082019-10-07 15:29:02 +0200256 if (timings->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200257 val |= GCR_PCPOL;
258 clrsetbits_le32(regs + LTDC_GCR,
259 GCR_HSPOL | GCR_VSPOL | GCR_DEPOL | GCR_PCPOL, val);
260
261 /* Overall background color */
262 writel(priv->bg_col_argb, priv->regs + LTDC_BCCR);
263}
264
265static void stm32_ltdc_set_layer1(struct stm32_ltdc_priv *priv, ulong fb_addr)
266{
267 void __iomem *regs = priv->regs;
268 u32 x0, x1, y0, y1;
269 u32 pitch_in_bytes;
270 u32 line_length;
271 u32 bus_width;
272 u32 val, tmp, bpp;
yannick fertre8fa461e2018-03-02 15:59:25 +0100273 u32 format;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200274
275 x0 = priv->crop_x;
276 x1 = priv->crop_x + priv->crop_w - 1;
277 y0 = priv->crop_y;
278 y1 = priv->crop_y + priv->crop_h - 1;
279
280 /* Horizontal start and stop position */
281 tmp = (readl(regs + LTDC_BPCR) & BPCR_AHBP) >> 16;
282 val = ((x1 + 1 + tmp) << 16) + (x0 + 1 + tmp);
283 clrsetbits_le32(regs + LTDC_L1WHPCR, LXWHPCR_WHSTPOS | LXWHPCR_WHSPPOS,
284 val);
285
286 /* Vertical start & stop position */
287 tmp = readl(regs + LTDC_BPCR) & BPCR_AVBP;
288 val = ((y1 + 1 + tmp) << 16) + (y0 + 1 + tmp);
289 clrsetbits_le32(regs + LTDC_L1WVPCR, LXWVPCR_WVSTPOS | LXWVPCR_WVSPPOS,
290 val);
291
292 /* Layer background color */
293 writel(priv->bg_col_argb, regs + LTDC_L1DCCR);
294
295 /* Color frame buffer pitch in bytes & line length */
296 bpp = VNBITS(priv->l2bpp);
297 pitch_in_bytes = priv->crop_w * (bpp >> 3);
298 bus_width = 8 << ((readl(regs + LTDC_GC2R) & GC2R_BW) >> 4);
299 line_length = ((bpp >> 3) * priv->crop_w) + (bus_width >> 3) - 1;
300 val = (pitch_in_bytes << 16) | line_length;
301 clrsetbits_le32(regs + LTDC_L1CFBLR, LXCFBLR_CFBLL | LXCFBLR_CFBP, val);
302
303 /* Pixel format */
yannick fertre8fa461e2018-03-02 15:59:25 +0100304 format = stm32_ltdc_get_pixel_format(priv->l2bpp);
305 clrsetbits_le32(regs + LTDC_L1PFCR, LXPFCR_PF, format);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200306
307 /* Constant alpha value */
308 clrsetbits_le32(regs + LTDC_L1CACR, LXCACR_CONSTA, priv->alpha);
309
yannick fertre8fa461e2018-03-02 15:59:25 +0100310 /* Specifies the blending factors : with or without pixel alpha */
311 /* Manage hw-specific capabilities */
312 val = has_alpha(format) ? BF1_PAXCA | BF2_1PAXCA : BF1_CA | BF2_1CA;
313
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200314 /* Blending factors */
yannick fertre8fa461e2018-03-02 15:59:25 +0100315 clrsetbits_le32(regs + LTDC_L1BFCR, LXBFCR_BF2 | LXBFCR_BF1, val);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200316
317 /* Frame buffer line number */
318 clrsetbits_le32(regs + LTDC_L1CFBLNR, LXCFBLNR_CFBLN, priv->crop_h);
319
320 /* Frame buffer address */
321 writel(fb_addr, regs + LTDC_L1CFBAR);
322
323 /* Enable layer 1 */
324 setbits_le32(priv->regs + LTDC_L1CR, LXCR_LEN);
325}
326
327static int stm32_ltdc_probe(struct udevice *dev)
328{
329 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
330 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
331 struct stm32_ltdc_priv *priv = dev_get_priv(dev);
Yannick Fertréd6117082019-10-07 15:29:02 +0200332 struct udevice *bridge = NULL;
333 struct udevice *panel = NULL;
334 struct display_timing timings;
yannick fertre8d6237b2018-03-02 15:59:23 +0100335 struct clk pclk;
yannick fertre28dc09b2018-03-02 15:59:21 +0100336 struct reset_ctl rst;
Yannick Fertréd6117082019-10-07 15:29:02 +0200337 int ret;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200338
339 priv->regs = (void *)dev_read_addr(dev);
340 if ((fdt_addr_t)priv->regs == FDT_ADDR_T_NONE) {
Yannick Fertréd6117082019-10-07 15:29:02 +0200341 dev_err(dev, "ltdc dt register address error\n");
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200342 return -EINVAL;
343 }
344
yannick fertre8d6237b2018-03-02 15:59:23 +0100345 ret = clk_get_by_index(dev, 0, &pclk);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200346 if (ret) {
Yannick Fertréd6117082019-10-07 15:29:02 +0200347 dev_err(dev, "peripheral clock get error %d\n", ret);
yannick fertre8d6237b2018-03-02 15:59:23 +0100348 return ret;
349 }
350
351 ret = clk_enable(&pclk);
352 if (ret) {
Yannick Fertréd6117082019-10-07 15:29:02 +0200353 dev_err(dev, "peripheral clock enable error %d\n", ret);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200354 return ret;
355 }
356
Yannick Fertréd6117082019-10-07 15:29:02 +0200357 ret = uclass_first_device_err(UCLASS_PANEL, &panel);
yannick fertre28dc09b2018-03-02 15:59:21 +0100358 if (ret) {
Yannick Fertréd6117082019-10-07 15:29:02 +0200359 if (ret != -ENODEV)
360 dev_err(dev, "panel device error %d\n", ret);
361 return ret;
yannick fertre28dc09b2018-03-02 15:59:21 +0100362 }
363
Yannick Fertréd6117082019-10-07 15:29:02 +0200364 ret = panel_get_display_timing(panel, &timings);
yannick fertre8d6237b2018-03-02 15:59:23 +0100365 if (ret) {
Yannick Fertréd6117082019-10-07 15:29:02 +0200366 ret = fdtdec_decode_display_timing(gd->fdt_blob,
367 dev_of_offset(panel),
368 0, &timings);
369 if (ret) {
370 dev_err(dev, "decode display timing error %d\n", ret);
371 return ret;
372 }
yannick fertre8d6237b2018-03-02 15:59:23 +0100373 }
374
Yannick Fertréd6117082019-10-07 15:29:02 +0200375 ret = clk_set_rate(&pclk, timings.pixelclock.typ);
376 if (ret)
377 dev_warn(dev, "fail to set pixel clock %d hz\n",
378 timings.pixelclock.typ);
379
380 debug("%s: Set pixel clock req %d hz get %ld hz\n", __func__,
381 timings.pixelclock.typ, clk_get_rate(&pclk));
382
383 ret = reset_get_by_index(dev, 0, &rst);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200384 if (ret) {
Yannick Fertréd6117082019-10-07 15:29:02 +0200385 dev_err(dev, "missing ltdc hardware reset\n");
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200386 return ret;
387 }
388
Yannick Fertréd6117082019-10-07 15:29:02 +0200389 /* Reset */
390 reset_deassert(&rst);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200391
Yannick Fertréd6117082019-10-07 15:29:02 +0200392 if (IS_ENABLED(CONFIG_VIDEO_BRIDGE)) {
393 ret = uclass_get_device(UCLASS_VIDEO_BRIDGE, 0, &bridge);
394 if (ret)
395 debug("No video bridge, or no backlight on bridge\n");
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200396
Yannick Fertréd6117082019-10-07 15:29:02 +0200397 if (bridge) {
398 ret = video_bridge_attach(bridge);
399 if (ret) {
400 dev_err(dev, "fail to attach bridge\n");
401 return ret;
402 }
403 }
404 }
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200405
406 /* TODO Below parameters are hard-coded for the moment... */
407 priv->l2bpp = VIDEO_BPP16;
408 priv->bg_col_argb = 0xFFFFFFFF; /* white no transparency */
409 priv->crop_x = 0;
410 priv->crop_y = 0;
Yannick Fertréd6117082019-10-07 15:29:02 +0200411 priv->crop_w = timings.hactive.typ;
412 priv->crop_h = timings.vactive.typ;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200413 priv->alpha = 0xFF;
414
415 debug("%s: %dx%d %dbpp frame buffer at 0x%lx\n", __func__,
Yannick Fertréd6117082019-10-07 15:29:02 +0200416 timings.hactive.typ, timings.vactive.typ,
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200417 VNBITS(priv->l2bpp), uc_plat->base);
418 debug("%s: crop %d,%d %dx%d bg 0x%08x alpha %d\n", __func__,
419 priv->crop_x, priv->crop_y, priv->crop_w, priv->crop_h,
420 priv->bg_col_argb, priv->alpha);
421
422 /* Configure & start LTDC */
Yannick Fertréd6117082019-10-07 15:29:02 +0200423 stm32_ltdc_set_mode(priv, &timings);
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200424 stm32_ltdc_set_layer1(priv, uc_plat->base);
425 stm32_ltdc_enable(priv);
426
Yannick Fertréd6117082019-10-07 15:29:02 +0200427 uc_priv->xsize = timings.hactive.typ;
428 uc_priv->ysize = timings.vactive.typ;
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200429 uc_priv->bpix = priv->l2bpp;
430
Yannick Fertréd6117082019-10-07 15:29:02 +0200431 if (!bridge) {
432 ret = panel_enable_backlight(panel);
433 if (ret) {
434 dev_err(dev, "panel %s enable backlight error %d\n",
435 panel->name, ret);
436 return ret;
437 }
438 } else if (IS_ENABLED(CONFIG_VIDEO_BRIDGE)) {
439 ret = video_bridge_set_backlight(bridge, 80);
440 if (ret) {
441 dev_err(dev, "fail to set backlight\n");
442 return ret;
443 }
444 }
445
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200446 video_set_flush_dcache(dev, true);
447
448 return 0;
449}
450
451static int stm32_ltdc_bind(struct udevice *dev)
452{
453 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
454
455 uc_plat->size = CONFIG_VIDEO_STM32_MAX_XRES *
456 CONFIG_VIDEO_STM32_MAX_YRES *
457 (CONFIG_VIDEO_STM32_MAX_BPP >> 3);
458 debug("%s: frame buffer max size %d bytes\n", __func__, uc_plat->size);
459
460 return 0;
461}
462
463static const struct udevice_id stm32_ltdc_ids[] = {
464 { .compatible = "st,stm32-ltdc" },
465 { }
466};
467
468U_BOOT_DRIVER(stm32_ltdc) = {
yannick fertre3e6077c2018-03-02 15:59:22 +0100469 .name = "stm32_display",
470 .id = UCLASS_VIDEO,
471 .of_match = stm32_ltdc_ids,
472 .probe = stm32_ltdc_probe,
473 .bind = stm32_ltdc_bind,
Philippe CORNUdcbad9a2017-08-03 12:36:08 +0200474 .priv_auto_alloc_size = sizeof(struct stm32_ltdc_priv),
475};