blob: 0fd74fdec9642353d282a2925f1c394a3bc8dea3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bo Shenf6b690e2012-05-25 00:59:58 +00002/*
3 * Driver for AT91/AT32 MULTI LAYER LCD Controller
4 *
5 * Copyright (C) 2012 Atmel Corporation
Bo Shenf6b690e2012-05-25 00:59:58 +00006 */
7
8#include <common.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07009#include <cpu_func.h>
Simon Glass336d4612020-02-03 07:36:16 -070010#include <malloc.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060011#include <part.h>
Bo Shenf6b690e2012-05-25 00:59:58 +000012#include <asm/io.h>
13#include <asm/arch/gpio.h>
14#include <asm/arch/clk.h>
Songjun Wu79278312017-04-11 16:33:30 +080015#include <clk.h>
16#include <dm.h>
17#include <fdtdec.h>
Bo Shenf6b690e2012-05-25 00:59:58 +000018#include <lcd.h>
Songjun Wu79278312017-04-11 16:33:30 +080019#include <video.h>
20#include <wait_bit.h>
Bo Shenf6b690e2012-05-25 00:59:58 +000021#include <atmel_hlcdc.h>
22
Nikita Kiryanov38b55082015-02-03 13:32:21 +020023#if defined(CONFIG_LCD_LOGO)
24#include <bmp_logo.h>
25#endif
26
Songjun Wu79278312017-04-11 16:33:30 +080027DECLARE_GLOBAL_DATA_PTR;
28
29#ifndef CONFIG_DM_VIDEO
30
Bo Shenf6b690e2012-05-25 00:59:58 +000031/* configurable parameters */
32#define ATMEL_LCDC_CVAL_DEFAULT 0xc8
33#define ATMEL_LCDC_DMA_BURST_LEN 8
34#ifndef ATMEL_LCDC_GUARD_TIME
35#define ATMEL_LCDC_GUARD_TIME 1
36#endif
37
38#define ATMEL_LCDC_FIFO_SIZE 512
39
Bo Shencfcd1c02012-11-08 17:49:14 +000040/*
41 * the CLUT register map as following
42 * RCLUT(24 ~ 16), GCLUT(15 ~ 8), BCLUT(7 ~ 0)
43 */
44void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
45{
Songjun Wu79278312017-04-11 16:33:30 +080046 writel(panel_info.mmio + ATMEL_LCDC_LUT(regno),
47 ((red << LCDC_BASECLUT_RCLUT_Pos) & LCDC_BASECLUT_RCLUT_Msk)
48 | ((green << LCDC_BASECLUT_GCLUT_Pos) & LCDC_BASECLUT_GCLUT_Msk)
49 | ((blue << LCDC_BASECLUT_BCLUT_Pos) & LCDC_BASECLUT_BCLUT_Msk));
Bo Shencfcd1c02012-11-08 17:49:14 +000050}
51
Nikita Kiryanov38b55082015-02-03 13:32:21 +020052ushort *configuration_get_cmap(void)
53{
54#if defined(CONFIG_LCD_LOGO)
55 return bmp_logo_palette;
56#else
57 return NULL;
58#endif
59}
60
Bo Shenf6b690e2012-05-25 00:59:58 +000061void lcd_ctrl_init(void *lcdbase)
62{
63 unsigned long value;
64 struct lcd_dma_desc *desc;
65 struct atmel_hlcd_regs *regs;
Songjun Wu79278312017-04-11 16:33:30 +080066 int ret;
Bo Shenf6b690e2012-05-25 00:59:58 +000067
68 if (!has_lcdc())
69 return; /* No lcdc */
70
71 regs = (struct atmel_hlcd_regs *)panel_info.mmio;
72
73 /* Disable DISP signal */
Songjun Wu79278312017-04-11 16:33:30 +080074 writel(LCDC_LCDDIS_DISPDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +010075 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_DISPSTS,
76 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +080077 if (ret)
78 printf("%s: %d: Timeout!\n", __func__, __LINE__);
Bo Shenf6b690e2012-05-25 00:59:58 +000079 /* Disable synchronization */
Songjun Wu79278312017-04-11 16:33:30 +080080 writel(LCDC_LCDDIS_SYNCDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +010081 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_LCDSTS,
82 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +080083 if (ret)
84 printf("%s: %d: Timeout!\n", __func__, __LINE__);
Bo Shenf6b690e2012-05-25 00:59:58 +000085 /* Disable pixel clock */
Songjun Wu79278312017-04-11 16:33:30 +080086 writel(LCDC_LCDDIS_CLKDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +010087 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_CLKSTS,
88 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +080089 if (ret)
90 printf("%s: %d: Timeout!\n", __func__, __LINE__);
Bo Shenf6b690e2012-05-25 00:59:58 +000091 /* Disable PWM */
Songjun Wu79278312017-04-11 16:33:30 +080092 writel(LCDC_LCDDIS_PWMDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +010093 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_PWMSTS,
94 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +080095 if (ret)
96 printf("%s: %d: Timeout!\n", __func__, __LINE__);
Bo Shenf6b690e2012-05-25 00:59:58 +000097
98 /* Set pixel clock */
99 value = get_lcdc_clk_rate(0) / panel_info.vl_clk;
100 if (get_lcdc_clk_rate(0) % panel_info.vl_clk)
101 value++;
102
103 if (value < 1) {
104 /* Using system clock as pixel clock */
Songjun Wu79278312017-04-11 16:33:30 +0800105 writel(LCDC_LCDCFG0_CLKDIV(0)
106 | LCDC_LCDCFG0_CGDISHCR
107 | LCDC_LCDCFG0_CGDISHEO
108 | LCDC_LCDCFG0_CGDISOVR1
109 | LCDC_LCDCFG0_CGDISBASE
110 | panel_info.vl_clk_pol
111 | LCDC_LCDCFG0_CLKSEL,
112 &regs->lcdc_lcdcfg0);
Bo Shenf6b690e2012-05-25 00:59:58 +0000113
114 } else {
Songjun Wu79278312017-04-11 16:33:30 +0800115 writel(LCDC_LCDCFG0_CLKDIV(value - 2)
116 | LCDC_LCDCFG0_CGDISHCR
117 | LCDC_LCDCFG0_CGDISHEO
118 | LCDC_LCDCFG0_CGDISOVR1
119 | LCDC_LCDCFG0_CGDISBASE
120 | panel_info.vl_clk_pol,
121 &regs->lcdc_lcdcfg0);
Bo Shenf6b690e2012-05-25 00:59:58 +0000122 }
123
124 /* Initialize control register 5 */
125 value = 0;
126
127 value |= panel_info.vl_sync;
128
129#ifndef LCD_OUTPUT_BPP
130 /* Output is 24bpp */
131 value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
132#else
133 switch (LCD_OUTPUT_BPP) {
134 case 12:
135 value |= LCDC_LCDCFG5_MODE_OUTPUT_12BPP;
136 break;
137 case 16:
138 value |= LCDC_LCDCFG5_MODE_OUTPUT_16BPP;
139 break;
140 case 18:
141 value |= LCDC_LCDCFG5_MODE_OUTPUT_18BPP;
142 break;
143 case 24:
144 value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
145 break;
146 default:
147 BUG();
148 break;
149 }
150#endif
151
152 value |= LCDC_LCDCFG5_GUARDTIME(ATMEL_LCDC_GUARD_TIME);
153 value |= (LCDC_LCDCFG5_DISPDLY | LCDC_LCDCFG5_VSPDLYS);
Songjun Wu79278312017-04-11 16:33:30 +0800154 writel(value, &regs->lcdc_lcdcfg5);
Bo Shenf6b690e2012-05-25 00:59:58 +0000155
156 /* Vertical & Horizontal Timing */
157 value = LCDC_LCDCFG1_VSPW(panel_info.vl_vsync_len - 1);
158 value |= LCDC_LCDCFG1_HSPW(panel_info.vl_hsync_len - 1);
Songjun Wu79278312017-04-11 16:33:30 +0800159 writel(value, &regs->lcdc_lcdcfg1);
Bo Shenf6b690e2012-05-25 00:59:58 +0000160
Wu, Josh1161f982014-03-10 16:40:41 +0800161 value = LCDC_LCDCFG2_VBPW(panel_info.vl_upper_margin);
162 value |= LCDC_LCDCFG2_VFPW(panel_info.vl_lower_margin - 1);
Songjun Wu79278312017-04-11 16:33:30 +0800163 writel(value, &regs->lcdc_lcdcfg2);
Bo Shenf6b690e2012-05-25 00:59:58 +0000164
Wu, Josh1161f982014-03-10 16:40:41 +0800165 value = LCDC_LCDCFG3_HBPW(panel_info.vl_left_margin - 1);
166 value |= LCDC_LCDCFG3_HFPW(panel_info.vl_right_margin - 1);
Songjun Wu79278312017-04-11 16:33:30 +0800167 writel(value, &regs->lcdc_lcdcfg3);
Bo Shenf6b690e2012-05-25 00:59:58 +0000168
169 /* Display size */
170 value = LCDC_LCDCFG4_RPF(panel_info.vl_row - 1);
171 value |= LCDC_LCDCFG4_PPL(panel_info.vl_col - 1);
Songjun Wu79278312017-04-11 16:33:30 +0800172 writel(value, &regs->lcdc_lcdcfg4);
Bo Shenf6b690e2012-05-25 00:59:58 +0000173
Songjun Wu79278312017-04-11 16:33:30 +0800174 writel(LCDC_BASECFG0_BLEN_AHB_INCR4 | LCDC_BASECFG0_DLBO,
175 &regs->lcdc_basecfg0);
Bo Shenf6b690e2012-05-25 00:59:58 +0000176
177 switch (NBITS(panel_info.vl_bpix)) {
178 case 16:
Songjun Wu79278312017-04-11 16:33:30 +0800179 writel(LCDC_BASECFG1_RGBMODE_16BPP_RGB_565,
180 &regs->lcdc_basecfg1);
Bo Shenf6b690e2012-05-25 00:59:58 +0000181 break;
Marek Vasut8c1b7172015-10-23 22:55:40 +0200182 case 32:
Songjun Wu79278312017-04-11 16:33:30 +0800183 writel(LCDC_BASECFG1_RGBMODE_24BPP_RGB_888,
184 &regs->lcdc_basecfg1);
Marek Vasut8c1b7172015-10-23 22:55:40 +0200185 break;
Bo Shenf6b690e2012-05-25 00:59:58 +0000186 default:
187 BUG();
188 break;
189 }
190
Songjun Wu79278312017-04-11 16:33:30 +0800191 writel(LCDC_BASECFG2_XSTRIDE(0), &regs->lcdc_basecfg2);
192 writel(0, &regs->lcdc_basecfg3);
193 writel(LCDC_BASECFG4_DMA, &regs->lcdc_basecfg4);
Bo Shenf6b690e2012-05-25 00:59:58 +0000194
195 /* Disable all interrupts */
Songjun Wu79278312017-04-11 16:33:30 +0800196 writel(~0UL, &regs->lcdc_lcdidr);
197 writel(~0UL, &regs->lcdc_baseidr);
Bo Shenf6b690e2012-05-25 00:59:58 +0000198
199 /* Setup the DMA descriptor, this descriptor will loop to itself */
200 desc = (struct lcd_dma_desc *)(lcdbase - 16);
201
202 desc->address = (u32)lcdbase;
203 /* Disable DMA transfer interrupt & descriptor loaded interrupt. */
204 desc->control = LCDC_BASECTRL_ADDIEN | LCDC_BASECTRL_DSCRIEN
205 | LCDC_BASECTRL_DMAIEN | LCDC_BASECTRL_DFETCH;
206 desc->next = (u32)desc;
207
Wu, Joshb137bd82014-05-19 19:51:27 +0800208 /* Flush the DMA descriptor if we enabled dcache */
209 flush_dcache_range((u32)desc, (u32)desc + sizeof(*desc));
210
Songjun Wu79278312017-04-11 16:33:30 +0800211 writel(desc->address, &regs->lcdc_baseaddr);
212 writel(desc->control, &regs->lcdc_basectrl);
213 writel(desc->next, &regs->lcdc_basenext);
214 writel(LCDC_BASECHER_CHEN | LCDC_BASECHER_UPDATEEN,
215 &regs->lcdc_basecher);
Bo Shenf6b690e2012-05-25 00:59:58 +0000216
217 /* Enable LCD */
Songjun Wu79278312017-04-11 16:33:30 +0800218 value = readl(&regs->lcdc_lcden);
219 writel(value | LCDC_LCDEN_CLKEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100220 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_CLKSTS,
221 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800222 if (ret)
223 printf("%s: %d: Timeout!\n", __func__, __LINE__);
224 value = readl(&regs->lcdc_lcden);
225 writel(value | LCDC_LCDEN_SYNCEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100226 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_LCDSTS,
227 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800228 if (ret)
229 printf("%s: %d: Timeout!\n", __func__, __LINE__);
230 value = readl(&regs->lcdc_lcden);
231 writel(value | LCDC_LCDEN_DISPEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100232 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_DISPSTS,
233 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800234 if (ret)
235 printf("%s: %d: Timeout!\n", __func__, __LINE__);
236 value = readl(&regs->lcdc_lcden);
237 writel(value | LCDC_LCDEN_PWMEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100238 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_PWMSTS,
239 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800240 if (ret)
241 printf("%s: %d: Timeout!\n", __func__, __LINE__);
Wu, Joshb137bd82014-05-19 19:51:27 +0800242
243 /* Enable flushing if we enabled dcache */
244 lcd_set_flush_dcache(1);
Bo Shenf6b690e2012-05-25 00:59:58 +0000245}
Songjun Wu79278312017-04-11 16:33:30 +0800246
247#else
248
249enum {
250 LCD_MAX_WIDTH = 1024,
251 LCD_MAX_HEIGHT = 768,
252 LCD_MAX_LOG2_BPP = VIDEO_BPP16,
253};
254
255struct atmel_hlcdc_priv {
256 struct atmel_hlcd_regs *regs;
257 struct display_timing timing;
258 unsigned int vl_bpix;
259 unsigned int output_mode;
260 unsigned int guard_time;
261 ulong clk_rate;
262};
263
264static int at91_hlcdc_enable_clk(struct udevice *dev)
265{
266 struct atmel_hlcdc_priv *priv = dev_get_priv(dev);
267 struct clk clk;
268 ulong clk_rate;
269 int ret;
270
271 ret = clk_get_by_index(dev, 0, &clk);
272 if (ret)
273 return -EINVAL;
274
275 ret = clk_enable(&clk);
276 if (ret)
277 return ret;
278
279 clk_rate = clk_get_rate(&clk);
280 if (!clk_rate) {
281 clk_disable(&clk);
282 return -ENODEV;
283 }
284
285 priv->clk_rate = clk_rate;
286
287 clk_free(&clk);
288
289 return 0;
290}
291
292static void atmel_hlcdc_init(struct udevice *dev)
293{
294 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
295 struct atmel_hlcdc_priv *priv = dev_get_priv(dev);
296 struct atmel_hlcd_regs *regs = priv->regs;
297 struct display_timing *timing = &priv->timing;
298 struct lcd_dma_desc *desc;
299 unsigned long value, vl_clk_pol;
300 int ret;
301
302 /* Disable DISP signal */
303 writel(LCDC_LCDDIS_DISPDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100304 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_DISPSTS,
305 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800306 if (ret)
307 printf("%s: %d: Timeout!\n", __func__, __LINE__);
308 /* Disable synchronization */
309 writel(LCDC_LCDDIS_SYNCDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100310 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_LCDSTS,
311 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800312 if (ret)
313 printf("%s: %d: Timeout!\n", __func__, __LINE__);
314 /* Disable pixel clock */
315 writel(LCDC_LCDDIS_CLKDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100316 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_CLKSTS,
317 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800318 if (ret)
319 printf("%s: %d: Timeout!\n", __func__, __LINE__);
320 /* Disable PWM */
321 writel(LCDC_LCDDIS_PWMDIS, &regs->lcdc_lcddis);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100322 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_PWMSTS,
323 false, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800324 if (ret)
325 printf("%s: %d: Timeout!\n", __func__, __LINE__);
326
327 /* Set pixel clock */
328 value = priv->clk_rate / timing->pixelclock.typ;
329 if (priv->clk_rate % timing->pixelclock.typ)
330 value++;
331
332 vl_clk_pol = 0;
333 if (timing->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
334 vl_clk_pol = LCDC_LCDCFG0_CLKPOL;
335
336 if (value < 1) {
337 /* Using system clock as pixel clock */
338 writel(LCDC_LCDCFG0_CLKDIV(0)
339 | LCDC_LCDCFG0_CGDISHCR
340 | LCDC_LCDCFG0_CGDISHEO
341 | LCDC_LCDCFG0_CGDISOVR1
342 | LCDC_LCDCFG0_CGDISBASE
343 | vl_clk_pol
344 | LCDC_LCDCFG0_CLKSEL,
345 &regs->lcdc_lcdcfg0);
346
347 } else {
348 writel(LCDC_LCDCFG0_CLKDIV(value - 2)
349 | LCDC_LCDCFG0_CGDISHCR
350 | LCDC_LCDCFG0_CGDISHEO
351 | LCDC_LCDCFG0_CGDISOVR1
352 | LCDC_LCDCFG0_CGDISBASE
353 | vl_clk_pol,
354 &regs->lcdc_lcdcfg0);
355 }
356
357 /* Initialize control register 5 */
358 value = 0;
359
360 if (!(timing->flags & DISPLAY_FLAGS_HSYNC_HIGH))
361 value |= LCDC_LCDCFG5_HSPOL;
362 if (!(timing->flags & DISPLAY_FLAGS_VSYNC_HIGH))
363 value |= LCDC_LCDCFG5_VSPOL;
364
365 switch (priv->output_mode) {
366 case 12:
367 value |= LCDC_LCDCFG5_MODE_OUTPUT_12BPP;
368 break;
369 case 16:
370 value |= LCDC_LCDCFG5_MODE_OUTPUT_16BPP;
371 break;
372 case 18:
373 value |= LCDC_LCDCFG5_MODE_OUTPUT_18BPP;
374 break;
375 case 24:
376 value |= LCDC_LCDCFG5_MODE_OUTPUT_24BPP;
377 break;
378 default:
379 BUG();
380 break;
381 }
382
383 value |= LCDC_LCDCFG5_GUARDTIME(priv->guard_time);
384 value |= (LCDC_LCDCFG5_DISPDLY | LCDC_LCDCFG5_VSPDLYS);
385 writel(value, &regs->lcdc_lcdcfg5);
386
387 /* Vertical & Horizontal Timing */
388 value = LCDC_LCDCFG1_VSPW(timing->vsync_len.typ - 1);
389 value |= LCDC_LCDCFG1_HSPW(timing->hsync_len.typ - 1);
390 writel(value, &regs->lcdc_lcdcfg1);
391
392 value = LCDC_LCDCFG2_VBPW(timing->vback_porch.typ);
393 value |= LCDC_LCDCFG2_VFPW(timing->vfront_porch.typ - 1);
394 writel(value, &regs->lcdc_lcdcfg2);
395
396 value = LCDC_LCDCFG3_HBPW(timing->hback_porch.typ - 1);
397 value |= LCDC_LCDCFG3_HFPW(timing->hfront_porch.typ - 1);
398 writel(value, &regs->lcdc_lcdcfg3);
399
400 /* Display size */
401 value = LCDC_LCDCFG4_RPF(timing->vactive.typ - 1);
402 value |= LCDC_LCDCFG4_PPL(timing->hactive.typ - 1);
403 writel(value, &regs->lcdc_lcdcfg4);
404
405 writel(LCDC_BASECFG0_BLEN_AHB_INCR4 | LCDC_BASECFG0_DLBO,
406 &regs->lcdc_basecfg0);
407
408 switch (VNBITS(priv->vl_bpix)) {
409 case 16:
410 writel(LCDC_BASECFG1_RGBMODE_16BPP_RGB_565,
411 &regs->lcdc_basecfg1);
412 break;
413 case 32:
414 writel(LCDC_BASECFG1_RGBMODE_24BPP_RGB_888,
415 &regs->lcdc_basecfg1);
416 break;
417 default:
418 BUG();
419 break;
420 }
421
422 writel(LCDC_BASECFG2_XSTRIDE(0), &regs->lcdc_basecfg2);
423 writel(0, &regs->lcdc_basecfg3);
424 writel(LCDC_BASECFG4_DMA, &regs->lcdc_basecfg4);
425
426 /* Disable all interrupts */
427 writel(~0UL, &regs->lcdc_lcdidr);
428 writel(~0UL, &regs->lcdc_baseidr);
429
430 /* Setup the DMA descriptor, this descriptor will loop to itself */
Wenyou Yang31e5c892017-06-02 11:29:04 +0800431 desc = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*desc));
432 if (!desc)
433 return;
Songjun Wu79278312017-04-11 16:33:30 +0800434
435 desc->address = (u32)uc_plat->base;
436
437 /* Disable DMA transfer interrupt & descriptor loaded interrupt. */
438 desc->control = LCDC_BASECTRL_ADDIEN | LCDC_BASECTRL_DSCRIEN
439 | LCDC_BASECTRL_DMAIEN | LCDC_BASECTRL_DFETCH;
440 desc->next = (u32)desc;
441
442 /* Flush the DMA descriptor if we enabled dcache */
Wenyou Yang31e5c892017-06-02 11:29:04 +0800443 flush_dcache_range((u32)desc,
444 ALIGN(((u32)desc + sizeof(*desc)),
445 CONFIG_SYS_CACHELINE_SIZE));
Songjun Wu79278312017-04-11 16:33:30 +0800446
447 writel(desc->address, &regs->lcdc_baseaddr);
448 writel(desc->control, &regs->lcdc_basectrl);
449 writel(desc->next, &regs->lcdc_basenext);
450 writel(LCDC_BASECHER_CHEN | LCDC_BASECHER_UPDATEEN,
451 &regs->lcdc_basecher);
452
453 /* Enable LCD */
454 value = readl(&regs->lcdc_lcden);
455 writel(value | LCDC_LCDEN_CLKEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100456 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_CLKSTS,
457 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800458 if (ret)
459 printf("%s: %d: Timeout!\n", __func__, __LINE__);
460 value = readl(&regs->lcdc_lcden);
461 writel(value | LCDC_LCDEN_SYNCEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100462 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_LCDSTS,
463 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800464 if (ret)
465 printf("%s: %d: Timeout!\n", __func__, __LINE__);
466 value = readl(&regs->lcdc_lcden);
467 writel(value | LCDC_LCDEN_DISPEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100468 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_DISPSTS,
469 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800470 if (ret)
471 printf("%s: %d: Timeout!\n", __func__, __LINE__);
472 value = readl(&regs->lcdc_lcden);
473 writel(value | LCDC_LCDEN_PWMEN, &regs->lcdc_lcden);
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +0100474 ret = wait_for_bit_le32(&regs->lcdc_lcdsr, LCDC_LCDSR_PWMSTS,
475 true, 1000, false);
Songjun Wu79278312017-04-11 16:33:30 +0800476 if (ret)
477 printf("%s: %d: Timeout!\n", __func__, __LINE__);
478}
479
480static int atmel_hlcdc_probe(struct udevice *dev)
481{
482 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
483 struct atmel_hlcdc_priv *priv = dev_get_priv(dev);
484 int ret;
485
486 ret = at91_hlcdc_enable_clk(dev);
487 if (ret)
488 return ret;
489
490 atmel_hlcdc_init(dev);
491
492 uc_priv->xsize = priv->timing.hactive.typ;
493 uc_priv->ysize = priv->timing.vactive.typ;
494 uc_priv->bpix = priv->vl_bpix;
495
496 /* Enable flushing if we enabled dcache */
497 video_set_flush_dcache(dev, true);
498
499 return 0;
500}
501
502static int atmel_hlcdc_ofdata_to_platdata(struct udevice *dev)
503{
504 struct atmel_hlcdc_priv *priv = dev_get_priv(dev);
505 const void *blob = gd->fdt_blob;
Simon Glassda409cc2017-05-17 17:18:09 -0600506 int node = dev_of_offset(dev);
Songjun Wu79278312017-04-11 16:33:30 +0800507
Simon Glassa821c4a2017-05-17 17:18:05 -0600508 priv->regs = (struct atmel_hlcd_regs *)devfdt_get_addr(dev);
Songjun Wu79278312017-04-11 16:33:30 +0800509 if (!priv->regs) {
510 debug("%s: No display controller address\n", __func__);
511 return -EINVAL;
512 }
513
Simon Glassda409cc2017-05-17 17:18:09 -0600514 if (fdtdec_decode_display_timing(blob, dev_of_offset(dev),
Songjun Wu79278312017-04-11 16:33:30 +0800515 0, &priv->timing)) {
516 debug("%s: Failed to decode display timing\n", __func__);
517 return -EINVAL;
518 }
519
520 if (priv->timing.hactive.typ > LCD_MAX_WIDTH)
521 priv->timing.hactive.typ = LCD_MAX_WIDTH;
522
523 if (priv->timing.vactive.typ > LCD_MAX_HEIGHT)
524 priv->timing.vactive.typ = LCD_MAX_HEIGHT;
525
526 priv->vl_bpix = fdtdec_get_int(blob, node, "atmel,vl-bpix", 0);
527 if (!priv->vl_bpix) {
528 debug("%s: Failed to get bits per pixel\n", __func__);
529 return -EINVAL;
530 }
531
532 priv->output_mode = fdtdec_get_int(blob, node, "atmel,output-mode", 24);
533 priv->guard_time = fdtdec_get_int(blob, node, "atmel,guard-time", 1);
534
535 return 0;
536}
537
538static int atmel_hlcdc_bind(struct udevice *dev)
539{
540 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
541
542 uc_plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
543 (1 << LCD_MAX_LOG2_BPP) / 8;
544
545 debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
546
547 return 0;
548}
549
550static const struct udevice_id atmel_hlcdc_ids[] = {
551 { .compatible = "atmel,sama5d2-hlcdc" },
552 { .compatible = "atmel,at91sam9x5-hlcdc" },
553 { }
554};
555
556U_BOOT_DRIVER(atmel_hlcdfb) = {
557 .name = "atmel_hlcdfb",
558 .id = UCLASS_VIDEO,
559 .of_match = atmel_hlcdc_ids,
560 .bind = atmel_hlcdc_bind,
561 .probe = atmel_hlcdc_probe,
562 .ofdata_to_platdata = atmel_hlcdc_ofdata_to_platdata,
563 .priv_auto_alloc_size = sizeof(struct atmel_hlcdc_priv),
564};
565
566#endif