blob: 147bd668feb1b6ee69f704cc68982a6ab0754545 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutffdd4662013-04-28 09:20:03 +00002/*
3 * Freescale i.MX23/i.MX28 LCDIF driver
4 *
5 * Copyright (C) 2011-2013 Marek Vasut <marex@denx.de>
Marek Vasutffdd4662013-04-28 09:20:03 +00006 */
7#include <common.h>
Giulio Benettif14d0002020-04-08 17:10:13 +02008#include <clk.h>
Igor Opaniukf5abe402019-06-04 00:05:59 +03009#include <dm.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060010#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <asm/cache.h>
Simon Glass9bc15642020-02-03 07:36:16 -070013#include <dm/device_compat.h>
Simon Glassdbd79542020-05-10 11:40:11 -060014#include <linux/delay.h>
Igor Opaniuke2a8b182019-06-04 00:05:57 +030015#include <linux/errno.h>
Marek Vasutffdd4662013-04-28 09:20:03 +000016#include <malloc.h>
Igor Opaniukf5abe402019-06-04 00:05:59 +030017#include <video.h>
Marek Vasutffdd4662013-04-28 09:20:03 +000018#include <video_fb.h>
19
Marek Vasutffdd4662013-04-28 09:20:03 +000020#include <asm/arch/clock.h>
Igor Opaniuke2a8b182019-06-04 00:05:57 +030021#include <asm/arch/imx-regs.h>
Marek Vasutffdd4662013-04-28 09:20:03 +000022#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020024#include <asm/mach-imx/dma.h>
Igor Opaniuke2a8b182019-06-04 00:05:57 +030025#include <asm/io.h>
Marek Vasut8f15b5d2013-07-30 23:37:54 +020026
Marek Vasutffdd4662013-04-28 09:20:03 +000027#include "videomodes.h"
28
29#define PS2KHZ(ps) (1000000000UL / (ps))
Igor Opaniukf5abe402019-06-04 00:05:59 +030030#define HZ2PS(hz) (1000000000UL / ((hz) / 1000))
Marek Vasutffdd4662013-04-28 09:20:03 +000031
Igor Opaniukf5abe402019-06-04 00:05:59 +030032#define BITS_PP 18
33#define BYTES_PP 4
34
Marek Vasut8f15b5d2013-07-30 23:37:54 +020035struct mxs_dma_desc desc;
Marek Vasutffdd4662013-04-28 09:20:03 +000036
Marek Vasutcd701a12013-07-30 23:37:53 +020037/**
38 * mxsfb_system_setup() - Fine-tune LCDIF configuration
39 *
40 * This function is used to adjust the LCDIF configuration. This is usually
41 * needed when driving the controller in System-Mode to operate an 8080 or
42 * 6800 connected SmartLCD.
43 */
44__weak void mxsfb_system_setup(void)
45{
46}
47
Marek Vasutffdd4662013-04-28 09:20:03 +000048/*
Marek Vasutec58ab22017-04-05 13:31:01 +020049 * ARIES M28EVK:
Marek Vasutffdd4662013-04-28 09:20:03 +000050 * setenv videomode
51 * video=ctfb:x:800,y:480,depth:18,mode:0,pclk:30066,
52 * le:0,ri:256,up:0,lo:45,hs:1,vs:1,sync:100663296,vmode:0
Fabio Estevama2824192013-05-10 09:14:11 +000053 *
54 * Freescale mx23evk/mx28evk with a Seiko 4.3'' WVGA panel:
55 * setenv videomode
56 * video=ctfb:x:800,y:480,depth:24,mode:0,pclk:29851,
57 * le:89,ri:164,up:23,lo:10,hs:10,vs:10,sync:0,vmode:0
Marek Vasutffdd4662013-04-28 09:20:03 +000058 */
59
Giulio Benettif14d0002020-04-08 17:10:13 +020060static void mxs_lcd_init(struct udevice *dev, u32 fb_addr,
Giulio Benettiac6d7f12020-04-08 17:10:15 +020061 struct display_timing *timings, int bpp)
Marek Vasutffdd4662013-04-28 09:20:03 +000062{
63 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
Giulio Benettie0305242020-04-08 17:10:16 +020064 const enum display_flags flags = timings->flags;
Marek Vasutffdd4662013-04-28 09:20:03 +000065 uint32_t word_len = 0, bus_width = 0;
66 uint8_t valid_data = 0;
Giulio Benettie0305242020-04-08 17:10:16 +020067 uint32_t vdctrl0;
Marek Vasutffdd4662013-04-28 09:20:03 +000068
Giulio Benettif14d0002020-04-08 17:10:13 +020069#if CONFIG_IS_ENABLED(CLK)
Giulio Benetti3ea47a72021-05-13 12:18:46 +020070 struct clk clk;
Giulio Benettif14d0002020-04-08 17:10:13 +020071 int ret;
72
Giulio Benetti3ea47a72021-05-13 12:18:46 +020073 ret = clk_get_by_name(dev, "pix", &clk);
Giulio Benettif14d0002020-04-08 17:10:13 +020074 if (ret) {
Giulio Benetti3ea47a72021-05-13 12:18:46 +020075 dev_err(dev, "Failed to get mxs pix clk: %d\n", ret);
Giulio Benettif14d0002020-04-08 17:10:13 +020076 return;
77 }
78
Giulio Benetti3ea47a72021-05-13 12:18:46 +020079 ret = clk_set_rate(&clk, timings->pixelclock.typ);
Giulio Benettif14d0002020-04-08 17:10:13 +020080 if (ret < 0) {
Giulio Benetti3ea47a72021-05-13 12:18:46 +020081 dev_err(dev, "Failed to set mxs pix clk: %d\n", ret);
Giulio Benettif14d0002020-04-08 17:10:13 +020082 return;
83 }
Giulio Benettia59f7122020-04-27 17:53:05 +020084
Giulio Benetti3ea47a72021-05-13 12:18:46 +020085 ret = clk_enable(&clk);
Giulio Benettia59f7122020-04-27 17:53:05 +020086 if (ret < 0) {
Giulio Benetti3ea47a72021-05-13 12:18:46 +020087 dev_err(dev, "Failed to enable mxs pix clk: %d\n", ret);
Giulio Benettia59f7122020-04-27 17:53:05 +020088 return;
89 }
Giulio Benetti3ea47a72021-05-13 12:18:46 +020090
91 ret = clk_get_by_name(dev, "axi", &clk);
92 if (!ret) {
93 debug("%s: Failed to get mxs axi clk: %d\n", __func__, ret);
94 } else {
95 ret = clk_enable(&clk);
96 if (ret < 0) {
97 dev_err(dev, "Failed to enable mxs axi clk: %d\n", ret);
98 return;
99 }
100 }
Giulio Benettif14d0002020-04-08 17:10:13 +0200101#else
Fabio Estevam092da182019-11-24 17:37:52 -0300102 /* Kick in the LCDIF clock */
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200103 mxs_set_lcdclk(MXS_LCDIF_BASE, timings->pixelclock.typ / 1000);
Giulio Benettif14d0002020-04-08 17:10:13 +0200104#endif
Fabio Estevam092da182019-11-24 17:37:52 -0300105
Marek Vasutffdd4662013-04-28 09:20:03 +0000106 /* Restart the LCDIF block */
107 mxs_reset_block(&regs->hw_lcdif_ctrl_reg);
108
109 switch (bpp) {
110 case 24:
111 word_len = LCDIF_CTRL_WORD_LENGTH_24BIT;
112 bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_24BIT;
113 valid_data = 0x7;
114 break;
115 case 18:
116 word_len = LCDIF_CTRL_WORD_LENGTH_24BIT;
117 bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_18BIT;
118 valid_data = 0x7;
119 break;
120 case 16:
121 word_len = LCDIF_CTRL_WORD_LENGTH_16BIT;
122 bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_16BIT;
123 valid_data = 0xf;
124 break;
125 case 8:
126 word_len = LCDIF_CTRL_WORD_LENGTH_8BIT;
127 bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_8BIT;
128 valid_data = 0xf;
129 break;
130 }
131
132 writel(bus_width | word_len | LCDIF_CTRL_DOTCLK_MODE |
133 LCDIF_CTRL_BYPASS_COUNT | LCDIF_CTRL_LCDIF_MASTER,
134 &regs->hw_lcdif_ctrl);
135
136 writel(valid_data << LCDIF_CTRL1_BYTE_PACKING_FORMAT_OFFSET,
137 &regs->hw_lcdif_ctrl1);
Marek Vasutcd701a12013-07-30 23:37:53 +0200138
139 mxsfb_system_setup();
140
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200141 writel((timings->vactive.typ << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) |
142 timings->hactive.typ, &regs->hw_lcdif_transfer_count);
Marek Vasutffdd4662013-04-28 09:20:03 +0000143
Giulio Benettie0305242020-04-08 17:10:16 +0200144 vdctrl0 = LCDIF_VDCTRL0_ENABLE_PRESENT | LCDIF_VDCTRL0_ENABLE_POL |
145 LCDIF_VDCTRL0_VSYNC_PERIOD_UNIT |
146 LCDIF_VDCTRL0_VSYNC_PULSE_WIDTH_UNIT |
147 timings->vsync_len.typ;
148
149 if(flags & DISPLAY_FLAGS_HSYNC_HIGH)
150 vdctrl0 |= LCDIF_VDCTRL0_HSYNC_POL;
Giulio Benetti996d96a2020-04-08 17:10:17 +0200151 if(flags & DISPLAY_FLAGS_VSYNC_HIGH)
152 vdctrl0 |= LCDIF_VDCTRL0_VSYNC_POL;
Giulio Benettie9238d62020-04-08 17:10:18 +0200153 if(flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
154 vdctrl0 |= LCDIF_VDCTRL0_DOTCLK_POL;
Giulio Benetti927858e2020-04-08 17:10:19 +0200155 if(flags & DISPLAY_FLAGS_DE_HIGH)
156 vdctrl0 |= LCDIF_VDCTRL0_ENABLE_POL;
157
Giulio Benettie0305242020-04-08 17:10:16 +0200158 writel(vdctrl0, &regs->hw_lcdif_vdctrl0);
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200159 writel(timings->vback_porch.typ + timings->vfront_porch.typ +
160 timings->vsync_len.typ + timings->vactive.typ,
Marek Vasutffdd4662013-04-28 09:20:03 +0000161 &regs->hw_lcdif_vdctrl1);
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200162 writel((timings->hsync_len.typ << LCDIF_VDCTRL2_HSYNC_PULSE_WIDTH_OFFSET) |
163 (timings->hback_porch.typ + timings->hfront_porch.typ +
164 timings->hsync_len.typ + timings->hactive.typ),
Marek Vasutffdd4662013-04-28 09:20:03 +0000165 &regs->hw_lcdif_vdctrl2);
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200166 writel(((timings->hback_porch.typ + timings->hsync_len.typ) <<
Marek Vasutffdd4662013-04-28 09:20:03 +0000167 LCDIF_VDCTRL3_HORIZONTAL_WAIT_CNT_OFFSET) |
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200168 (timings->vback_porch.typ + timings->vsync_len.typ),
Marek Vasutffdd4662013-04-28 09:20:03 +0000169 &regs->hw_lcdif_vdctrl3);
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200170 writel((0 << LCDIF_VDCTRL4_DOTCLK_DLY_SEL_OFFSET) | timings->hactive.typ,
Marek Vasutffdd4662013-04-28 09:20:03 +0000171 &regs->hw_lcdif_vdctrl4);
172
Igor Opaniuk5fd35532019-06-04 00:05:56 +0300173 writel(fb_addr, &regs->hw_lcdif_cur_buf);
174 writel(fb_addr, &regs->hw_lcdif_next_buf);
Marek Vasutffdd4662013-04-28 09:20:03 +0000175
176 /* Flush FIFO first */
177 writel(LCDIF_CTRL1_FIFO_CLEAR, &regs->hw_lcdif_ctrl1_set);
178
Marek Vasutcd701a12013-07-30 23:37:53 +0200179#ifndef CONFIG_VIDEO_MXS_MODE_SYSTEM
Marek Vasutffdd4662013-04-28 09:20:03 +0000180 /* Sync signals ON */
181 setbits_le32(&regs->hw_lcdif_vdctrl4, LCDIF_VDCTRL4_SYNC_SIGNALS_ON);
Marek Vasutcd701a12013-07-30 23:37:53 +0200182#endif
Marek Vasutffdd4662013-04-28 09:20:03 +0000183
184 /* FIFO cleared */
185 writel(LCDIF_CTRL1_FIFO_CLEAR, &regs->hw_lcdif_ctrl1_clr);
186
187 /* RUN! */
188 writel(LCDIF_CTRL_RUN, &regs->hw_lcdif_ctrl_set);
189}
190
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200191static int mxs_probe_common(struct udevice *dev, struct display_timing *timings,
Giulio Benettif14d0002020-04-08 17:10:13 +0200192 int bpp, u32 fb)
Igor Opaniuk36734922019-06-04 00:05:58 +0300193{
194 /* Start framebuffer */
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200195 mxs_lcd_init(dev, fb, timings, bpp);
Igor Opaniuk36734922019-06-04 00:05:58 +0300196
197#ifdef CONFIG_VIDEO_MXS_MODE_SYSTEM
198 /*
199 * If the LCD runs in system mode, the LCD refresh has to be triggered
200 * manually by setting the RUN bit in HW_LCDIF_CTRL register. To avoid
201 * having to set this bit manually after every single change in the
202 * framebuffer memory, we set up specially crafted circular DMA, which
203 * sets the RUN bit, then waits until it gets cleared and repeats this
204 * infinitelly. This way, we get smooth continuous updates of the LCD.
205 */
206 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
207
208 memset(&desc, 0, sizeof(struct mxs_dma_desc));
209 desc.address = (dma_addr_t)&desc;
210 desc.cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_CHAIN |
211 MXS_DMA_DESC_WAIT4END |
212 (1 << MXS_DMA_DESC_PIO_WORDS_OFFSET);
213 desc.cmd.pio_words[0] = readl(&regs->hw_lcdif_ctrl) | LCDIF_CTRL_RUN;
214 desc.cmd.next = (uint32_t)&desc.cmd;
215
216 /* Execute the DMA chain. */
217 mxs_dma_circ_start(MXS_DMA_CHANNEL_AHB_APBH_LCDIF, &desc);
218#endif
219
220 return 0;
221}
222
Igor Opaniukf5abe402019-06-04 00:05:59 +0300223static int mxs_remove_common(u32 fb)
Peng Fan5f8dbf52015-10-29 15:54:49 +0800224{
225 struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
226 int timeout = 1000000;
227
Igor Opaniukf5abe402019-06-04 00:05:59 +0300228 if (!fb)
229 return -EINVAL;
Fabio Estevamef84cf62017-02-22 10:40:22 -0300230
Igor Opaniukf5abe402019-06-04 00:05:59 +0300231 writel(fb, &regs->hw_lcdif_cur_buf_reg);
232 writel(fb, &regs->hw_lcdif_next_buf_reg);
Peng Fan5f8dbf52015-10-29 15:54:49 +0800233 writel(LCDIF_CTRL1_VSYNC_EDGE_IRQ, &regs->hw_lcdif_ctrl1_clr);
234 while (--timeout) {
235 if (readl(&regs->hw_lcdif_ctrl1_reg) &
236 LCDIF_CTRL1_VSYNC_EDGE_IRQ)
237 break;
238 udelay(1);
239 }
240 mxs_reset_block((struct mxs_register_32 *)&regs->hw_lcdif_ctrl_reg);
Igor Opaniukf5abe402019-06-04 00:05:59 +0300241
242 return 0;
243}
244
245#ifndef CONFIG_DM_VIDEO
246
247static GraphicDevice panel;
248
249void lcdif_power_down(void)
250{
251 mxs_remove_common(panel.frameAdrs);
Peng Fan5f8dbf52015-10-29 15:54:49 +0800252}
253
Marek Vasutffdd4662013-04-28 09:20:03 +0000254void *video_hw_init(void)
255{
256 int bpp = -1;
Igor Opaniuk36734922019-06-04 00:05:58 +0300257 int ret = 0;
Marek Vasutffdd4662013-04-28 09:20:03 +0000258 char *penv;
Igor Opaniuk36734922019-06-04 00:05:58 +0300259 void *fb = NULL;
Marek Vasutffdd4662013-04-28 09:20:03 +0000260 struct ctfb_res_modes mode;
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200261 struct display_timing timings;
Marek Vasutffdd4662013-04-28 09:20:03 +0000262
263 puts("Video: ");
264
265 /* Suck display configuration from "videomode" variable */
Simon Glass64b723f2017-08-03 12:22:12 -0600266 penv = env_get("videomode");
Marek Vasutffdd4662013-04-28 09:20:03 +0000267 if (!penv) {
Fabio Estevam56147832013-06-26 16:08:13 -0300268 puts("MXSFB: 'videomode' variable not set!\n");
Marek Vasutffdd4662013-04-28 09:20:03 +0000269 return NULL;
270 }
271
272 bpp = video_get_params(&mode, penv);
273
274 /* fill in Graphic device struct */
Igor Opaniuk36734922019-06-04 00:05:58 +0300275 sprintf(panel.modeIdent, "%dx%dx%d", mode.xres, mode.yres, bpp);
Marek Vasutffdd4662013-04-28 09:20:03 +0000276
277 panel.winSizeX = mode.xres;
278 panel.winSizeY = mode.yres;
279 panel.plnSizeX = mode.xres;
280 panel.plnSizeY = mode.yres;
281
282 switch (bpp) {
283 case 24:
284 case 18:
285 panel.gdfBytesPP = 4;
286 panel.gdfIndex = GDF_32BIT_X888RGB;
287 break;
288 case 16:
289 panel.gdfBytesPP = 2;
290 panel.gdfIndex = GDF_16BIT_565RGB;
291 break;
292 case 8:
293 panel.gdfBytesPP = 1;
294 panel.gdfIndex = GDF__8BIT_INDEX;
295 break;
296 default:
297 printf("MXSFB: Invalid BPP specified! (bpp = %i)\n", bpp);
298 return NULL;
299 }
300
301 panel.memSize = mode.xres * mode.yres * panel.gdfBytesPP;
302
303 /* Allocate framebuffer */
Marek Vasutce74fac2013-07-30 23:37:52 +0200304 fb = memalign(ARCH_DMA_MINALIGN,
305 roundup(panel.memSize, ARCH_DMA_MINALIGN));
Marek Vasutffdd4662013-04-28 09:20:03 +0000306 if (!fb) {
307 printf("MXSFB: Error allocating framebuffer!\n");
308 return NULL;
309 }
310
311 /* Wipe framebuffer */
312 memset(fb, 0, panel.memSize);
313
314 panel.frameAdrs = (u32)fb;
315
316 printf("%s\n", panel.modeIdent);
317
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200318 video_ctfb_mode_to_display_timing(&mode, &timings);
319
320 ret = mxs_probe_common(NULL, &timings, bpp, (u32)fb);
Igor Opaniuk36734922019-06-04 00:05:58 +0300321 if (ret)
322 goto dealloc_fb;
Marek Vasut8f15b5d2013-07-30 23:37:54 +0200323
Igor Opaniuk36734922019-06-04 00:05:58 +0300324 return (void *)&panel;
Marek Vasut8f15b5d2013-07-30 23:37:54 +0200325
Igor Opaniuk36734922019-06-04 00:05:58 +0300326dealloc_fb:
327 free(fb);
Marek Vasut8f15b5d2013-07-30 23:37:54 +0200328
Igor Opaniuk36734922019-06-04 00:05:58 +0300329 return NULL;
Marek Vasutffdd4662013-04-28 09:20:03 +0000330}
Igor Opaniukf5abe402019-06-04 00:05:59 +0300331#else /* ifndef CONFIG_DM_VIDEO */
332
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300333static int mxs_of_get_timings(struct udevice *dev,
334 struct display_timing *timings,
335 u32 *bpp)
336{
337 int ret = 0;
338 u32 display_phandle;
339 ofnode display_node;
340
341 ret = ofnode_read_u32(dev_ofnode(dev), "display", &display_phandle);
342 if (ret) {
343 dev_err(dev, "required display property isn't provided\n");
344 return -EINVAL;
345 }
346
347 display_node = ofnode_get_by_phandle(display_phandle);
348 if (!ofnode_valid(display_node)) {
349 dev_err(dev, "failed to find display subnode\n");
350 return -EINVAL;
351 }
352
353 ret = ofnode_read_u32(display_node, "bits-per-pixel", bpp);
354 if (ret) {
355 dev_err(dev,
356 "required bits-per-pixel property isn't provided\n");
357 return -EINVAL;
358 }
359
360 ret = ofnode_decode_display_timing(display_node, 0, timings);
361 if (ret) {
362 dev_err(dev, "failed to get any display timings\n");
363 return -EINVAL;
364 }
365
366 return ret;
367}
368
Igor Opaniukf5abe402019-06-04 00:05:59 +0300369static int mxs_video_probe(struct udevice *dev)
370{
Simon Glassb75b15b2020-12-03 16:55:23 -0700371 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Igor Opaniukf5abe402019-06-04 00:05:59 +0300372 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
373
Igor Opaniukf5abe402019-06-04 00:05:59 +0300374 struct display_timing timings;
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300375 u32 bpp = 0;
Igor Opaniukf5abe402019-06-04 00:05:59 +0300376 u32 fb_start, fb_end;
377 int ret;
378
379 debug("%s() plat: base 0x%lx, size 0x%x\n",
380 __func__, plat->base, plat->size);
381
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300382 ret = mxs_of_get_timings(dev, &timings, &bpp);
383 if (ret)
384 return ret;
Igor Opaniukf5abe402019-06-04 00:05:59 +0300385
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200386 ret = mxs_probe_common(dev, &timings, bpp, plat->base);
Igor Opaniukf5abe402019-06-04 00:05:59 +0300387 if (ret)
388 return ret;
389
390 switch (bpp) {
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300391 case 32:
Igor Opaniukf5abe402019-06-04 00:05:59 +0300392 case 24:
393 case 18:
394 uc_priv->bpix = VIDEO_BPP32;
395 break;
396 case 16:
397 uc_priv->bpix = VIDEO_BPP16;
398 break;
399 case 8:
400 uc_priv->bpix = VIDEO_BPP8;
401 break;
402 default:
403 dev_err(dev, "invalid bpp specified (bpp = %i)\n", bpp);
404 return -EINVAL;
405 }
406
Giulio Benettiac6d7f12020-04-08 17:10:15 +0200407 uc_priv->xsize = timings.hactive.typ;
408 uc_priv->ysize = timings.vactive.typ;
Igor Opaniukf5abe402019-06-04 00:05:59 +0300409
410 /* Enable dcache for the frame buffer */
411 fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
412 fb_end = plat->base + plat->size;
413 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
414 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
415 DCACHE_WRITEBACK);
416 video_set_flush_dcache(dev, true);
Sébastien Szymanskieb9b6a82019-10-21 15:33:04 +0200417 gd->fb_base = plat->base;
Igor Opaniukf5abe402019-06-04 00:05:59 +0300418
419 return ret;
420}
421
422static int mxs_video_bind(struct udevice *dev)
423{
Simon Glassb75b15b2020-12-03 16:55:23 -0700424 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Igor Opaniukf5abe402019-06-04 00:05:59 +0300425 struct display_timing timings;
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300426 u32 bpp = 0;
427 u32 bytes_pp = 0;
Igor Opaniukf5abe402019-06-04 00:05:59 +0300428 int ret;
429
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300430 ret = mxs_of_get_timings(dev, &timings, &bpp);
431 if (ret)
432 return ret;
433
434 switch (bpp) {
435 case 32:
436 case 24:
437 case 18:
438 bytes_pp = 4;
439 break;
440 case 16:
441 bytes_pp = 2;
442 break;
443 case 8:
444 bytes_pp = 1;
445 break;
446 default:
447 dev_err(dev, "invalid bpp specified (bpp = %i)\n", bpp);
Igor Opaniukf5abe402019-06-04 00:05:59 +0300448 return -EINVAL;
449 }
450
Igor Opaniuk994f49a2019-06-19 11:47:05 +0300451 plat->size = timings.hactive.typ * timings.vactive.typ * bytes_pp;
Igor Opaniukf5abe402019-06-04 00:05:59 +0300452
453 return 0;
454}
455
456static int mxs_video_remove(struct udevice *dev)
457{
Simon Glassb75b15b2020-12-03 16:55:23 -0700458 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Igor Opaniukf5abe402019-06-04 00:05:59 +0300459
460 mxs_remove_common(plat->base);
461
462 return 0;
463}
464
465static const struct udevice_id mxs_video_ids[] = {
466 { .compatible = "fsl,imx23-lcdif" },
467 { .compatible = "fsl,imx28-lcdif" },
468 { .compatible = "fsl,imx7ulp-lcdif" },
Giulio Benetti83677312020-04-08 17:10:14 +0200469 { .compatible = "fsl,imxrt-lcdif" },
Igor Opaniukf5abe402019-06-04 00:05:59 +0300470 { /* sentinel */ }
471};
472
473U_BOOT_DRIVER(mxs_video) = {
474 .name = "mxs_video",
475 .id = UCLASS_VIDEO,
476 .of_match = mxs_video_ids,
477 .bind = mxs_video_bind,
478 .probe = mxs_video_probe,
479 .remove = mxs_video_remove,
Anatolij Gustschinf9888f92020-01-25 23:44:56 +0100480 .flags = DM_FLAG_PRE_RELOC | DM_FLAG_OS_PREPARE,
Igor Opaniukf5abe402019-06-04 00:05:59 +0300481};
482#endif /* ifndef CONFIG_DM_VIDEO */