Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Freescale i.MX23/i.MX28 LCDIF driver |
| 4 | * |
| 5 | * Copyright (C) 2011-2013 Marek Vasut <marex@denx.de> |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 6 | */ |
| 7 | #include <common.h> |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 8 | #include <clk.h> |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <dm/device_compat.h> |
Igor Opaniuk | e2a8b18 | 2019-06-04 00:05:57 +0300 | [diff] [blame] | 12 | #include <linux/errno.h> |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 13 | #include <malloc.h> |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 14 | #include <video.h> |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 15 | #include <video_fb.h> |
| 16 | |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Igor Opaniuk | e2a8b18 | 2019-06-04 00:05:57 +0300 | [diff] [blame] | 18 | #include <asm/arch/imx-regs.h> |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 19 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 20 | #include <asm/mach-imx/dma.h> |
Igor Opaniuk | e2a8b18 | 2019-06-04 00:05:57 +0300 | [diff] [blame] | 21 | #include <asm/io.h> |
Marek Vasut | 8f15b5d | 2013-07-30 23:37:54 +0200 | [diff] [blame] | 22 | |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 23 | #include "videomodes.h" |
| 24 | |
| 25 | #define PS2KHZ(ps) (1000000000UL / (ps)) |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 26 | #define HZ2PS(hz) (1000000000UL / ((hz) / 1000)) |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 27 | |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 28 | #define BITS_PP 18 |
| 29 | #define BYTES_PP 4 |
| 30 | |
Marek Vasut | 8f15b5d | 2013-07-30 23:37:54 +0200 | [diff] [blame] | 31 | struct mxs_dma_desc desc; |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 32 | |
Marek Vasut | cd701a1 | 2013-07-30 23:37:53 +0200 | [diff] [blame] | 33 | /** |
| 34 | * mxsfb_system_setup() - Fine-tune LCDIF configuration |
| 35 | * |
| 36 | * This function is used to adjust the LCDIF configuration. This is usually |
| 37 | * needed when driving the controller in System-Mode to operate an 8080 or |
| 38 | * 6800 connected SmartLCD. |
| 39 | */ |
| 40 | __weak void mxsfb_system_setup(void) |
| 41 | { |
| 42 | } |
| 43 | |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 44 | /* |
Marek Vasut | ec58ab2 | 2017-04-05 13:31:01 +0200 | [diff] [blame] | 45 | * ARIES M28EVK: |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 46 | * setenv videomode |
| 47 | * video=ctfb:x:800,y:480,depth:18,mode:0,pclk:30066, |
| 48 | * le:0,ri:256,up:0,lo:45,hs:1,vs:1,sync:100663296,vmode:0 |
Fabio Estevam | a282419 | 2013-05-10 09:14:11 +0000 | [diff] [blame] | 49 | * |
| 50 | * Freescale mx23evk/mx28evk with a Seiko 4.3'' WVGA panel: |
| 51 | * setenv videomode |
| 52 | * video=ctfb:x:800,y:480,depth:24,mode:0,pclk:29851, |
| 53 | * le:89,ri:164,up:23,lo:10,hs:10,vs:10,sync:0,vmode:0 |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 54 | */ |
| 55 | |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 56 | static void mxs_lcd_init(struct udevice *dev, u32 fb_addr, |
| 57 | struct ctfb_res_modes *mode, int bpp) |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 58 | { |
| 59 | struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; |
| 60 | uint32_t word_len = 0, bus_width = 0; |
| 61 | uint8_t valid_data = 0; |
| 62 | |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 63 | #if CONFIG_IS_ENABLED(CLK) |
| 64 | struct clk per_clk; |
| 65 | int ret; |
| 66 | |
| 67 | ret = clk_get_by_name(dev, "per", &per_clk); |
| 68 | if (ret) { |
| 69 | dev_err(dev, "Failed to get mxs clk: %d\n", ret); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | ret = clk_set_rate(&per_clk, PS2KHZ(mode->pixclock) * 1000); |
| 74 | if (ret < 0) { |
| 75 | dev_err(dev, "Failed to set mxs clk: %d\n", ret); |
| 76 | return; |
| 77 | } |
| 78 | #else |
Fabio Estevam | 092da18 | 2019-11-24 17:37:52 -0300 | [diff] [blame] | 79 | /* Kick in the LCDIF clock */ |
| 80 | mxs_set_lcdclk(MXS_LCDIF_BASE, PS2KHZ(mode->pixclock)); |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 81 | #endif |
Fabio Estevam | 092da18 | 2019-11-24 17:37:52 -0300 | [diff] [blame] | 82 | |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 83 | /* Restart the LCDIF block */ |
| 84 | mxs_reset_block(®s->hw_lcdif_ctrl_reg); |
| 85 | |
| 86 | switch (bpp) { |
| 87 | case 24: |
| 88 | word_len = LCDIF_CTRL_WORD_LENGTH_24BIT; |
| 89 | bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_24BIT; |
| 90 | valid_data = 0x7; |
| 91 | break; |
| 92 | case 18: |
| 93 | word_len = LCDIF_CTRL_WORD_LENGTH_24BIT; |
| 94 | bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_18BIT; |
| 95 | valid_data = 0x7; |
| 96 | break; |
| 97 | case 16: |
| 98 | word_len = LCDIF_CTRL_WORD_LENGTH_16BIT; |
| 99 | bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_16BIT; |
| 100 | valid_data = 0xf; |
| 101 | break; |
| 102 | case 8: |
| 103 | word_len = LCDIF_CTRL_WORD_LENGTH_8BIT; |
| 104 | bus_width = LCDIF_CTRL_LCD_DATABUS_WIDTH_8BIT; |
| 105 | valid_data = 0xf; |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | writel(bus_width | word_len | LCDIF_CTRL_DOTCLK_MODE | |
| 110 | LCDIF_CTRL_BYPASS_COUNT | LCDIF_CTRL_LCDIF_MASTER, |
| 111 | ®s->hw_lcdif_ctrl); |
| 112 | |
| 113 | writel(valid_data << LCDIF_CTRL1_BYTE_PACKING_FORMAT_OFFSET, |
| 114 | ®s->hw_lcdif_ctrl1); |
Marek Vasut | cd701a1 | 2013-07-30 23:37:53 +0200 | [diff] [blame] | 115 | |
| 116 | mxsfb_system_setup(); |
| 117 | |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 118 | writel((mode->yres << LCDIF_TRANSFER_COUNT_V_COUNT_OFFSET) | mode->xres, |
| 119 | ®s->hw_lcdif_transfer_count); |
| 120 | |
| 121 | writel(LCDIF_VDCTRL0_ENABLE_PRESENT | LCDIF_VDCTRL0_ENABLE_POL | |
| 122 | LCDIF_VDCTRL0_VSYNC_PERIOD_UNIT | |
| 123 | LCDIF_VDCTRL0_VSYNC_PULSE_WIDTH_UNIT | |
| 124 | mode->vsync_len, ®s->hw_lcdif_vdctrl0); |
| 125 | writel(mode->upper_margin + mode->lower_margin + |
| 126 | mode->vsync_len + mode->yres, |
| 127 | ®s->hw_lcdif_vdctrl1); |
| 128 | writel((mode->hsync_len << LCDIF_VDCTRL2_HSYNC_PULSE_WIDTH_OFFSET) | |
| 129 | (mode->left_margin + mode->right_margin + |
| 130 | mode->hsync_len + mode->xres), |
| 131 | ®s->hw_lcdif_vdctrl2); |
| 132 | writel(((mode->left_margin + mode->hsync_len) << |
| 133 | LCDIF_VDCTRL3_HORIZONTAL_WAIT_CNT_OFFSET) | |
| 134 | (mode->upper_margin + mode->vsync_len), |
| 135 | ®s->hw_lcdif_vdctrl3); |
| 136 | writel((0 << LCDIF_VDCTRL4_DOTCLK_DLY_SEL_OFFSET) | mode->xres, |
| 137 | ®s->hw_lcdif_vdctrl4); |
| 138 | |
Igor Opaniuk | 5fd3553 | 2019-06-04 00:05:56 +0300 | [diff] [blame] | 139 | writel(fb_addr, ®s->hw_lcdif_cur_buf); |
| 140 | writel(fb_addr, ®s->hw_lcdif_next_buf); |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 141 | |
| 142 | /* Flush FIFO first */ |
| 143 | writel(LCDIF_CTRL1_FIFO_CLEAR, ®s->hw_lcdif_ctrl1_set); |
| 144 | |
Marek Vasut | cd701a1 | 2013-07-30 23:37:53 +0200 | [diff] [blame] | 145 | #ifndef CONFIG_VIDEO_MXS_MODE_SYSTEM |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 146 | /* Sync signals ON */ |
| 147 | setbits_le32(®s->hw_lcdif_vdctrl4, LCDIF_VDCTRL4_SYNC_SIGNALS_ON); |
Marek Vasut | cd701a1 | 2013-07-30 23:37:53 +0200 | [diff] [blame] | 148 | #endif |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 149 | |
| 150 | /* FIFO cleared */ |
| 151 | writel(LCDIF_CTRL1_FIFO_CLEAR, ®s->hw_lcdif_ctrl1_clr); |
| 152 | |
| 153 | /* RUN! */ |
| 154 | writel(LCDIF_CTRL_RUN, ®s->hw_lcdif_ctrl_set); |
| 155 | } |
| 156 | |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 157 | static int mxs_probe_common(struct udevice *dev, struct ctfb_res_modes *mode, |
| 158 | int bpp, u32 fb) |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 159 | { |
| 160 | /* Start framebuffer */ |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 161 | mxs_lcd_init(dev, fb, mode, bpp); |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 162 | |
| 163 | #ifdef CONFIG_VIDEO_MXS_MODE_SYSTEM |
| 164 | /* |
| 165 | * If the LCD runs in system mode, the LCD refresh has to be triggered |
| 166 | * manually by setting the RUN bit in HW_LCDIF_CTRL register. To avoid |
| 167 | * having to set this bit manually after every single change in the |
| 168 | * framebuffer memory, we set up specially crafted circular DMA, which |
| 169 | * sets the RUN bit, then waits until it gets cleared and repeats this |
| 170 | * infinitelly. This way, we get smooth continuous updates of the LCD. |
| 171 | */ |
| 172 | struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; |
| 173 | |
| 174 | memset(&desc, 0, sizeof(struct mxs_dma_desc)); |
| 175 | desc.address = (dma_addr_t)&desc; |
| 176 | desc.cmd.data = MXS_DMA_DESC_COMMAND_NO_DMAXFER | MXS_DMA_DESC_CHAIN | |
| 177 | MXS_DMA_DESC_WAIT4END | |
| 178 | (1 << MXS_DMA_DESC_PIO_WORDS_OFFSET); |
| 179 | desc.cmd.pio_words[0] = readl(®s->hw_lcdif_ctrl) | LCDIF_CTRL_RUN; |
| 180 | desc.cmd.next = (uint32_t)&desc.cmd; |
| 181 | |
| 182 | /* Execute the DMA chain. */ |
| 183 | mxs_dma_circ_start(MXS_DMA_CHANNEL_AHB_APBH_LCDIF, &desc); |
| 184 | #endif |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 189 | static int mxs_remove_common(u32 fb) |
Peng Fan | 5f8dbf5 | 2015-10-29 15:54:49 +0800 | [diff] [blame] | 190 | { |
| 191 | struct mxs_lcdif_regs *regs = (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; |
| 192 | int timeout = 1000000; |
| 193 | |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 194 | if (!fb) |
| 195 | return -EINVAL; |
Fabio Estevam | ef84cf6 | 2017-02-22 10:40:22 -0300 | [diff] [blame] | 196 | |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 197 | writel(fb, ®s->hw_lcdif_cur_buf_reg); |
| 198 | writel(fb, ®s->hw_lcdif_next_buf_reg); |
Peng Fan | 5f8dbf5 | 2015-10-29 15:54:49 +0800 | [diff] [blame] | 199 | writel(LCDIF_CTRL1_VSYNC_EDGE_IRQ, ®s->hw_lcdif_ctrl1_clr); |
| 200 | while (--timeout) { |
| 201 | if (readl(®s->hw_lcdif_ctrl1_reg) & |
| 202 | LCDIF_CTRL1_VSYNC_EDGE_IRQ) |
| 203 | break; |
| 204 | udelay(1); |
| 205 | } |
| 206 | mxs_reset_block((struct mxs_register_32 *)®s->hw_lcdif_ctrl_reg); |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | #ifndef CONFIG_DM_VIDEO |
| 212 | |
| 213 | static GraphicDevice panel; |
| 214 | |
| 215 | void lcdif_power_down(void) |
| 216 | { |
| 217 | mxs_remove_common(panel.frameAdrs); |
Peng Fan | 5f8dbf5 | 2015-10-29 15:54:49 +0800 | [diff] [blame] | 218 | } |
| 219 | |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 220 | void *video_hw_init(void) |
| 221 | { |
| 222 | int bpp = -1; |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 223 | int ret = 0; |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 224 | char *penv; |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 225 | void *fb = NULL; |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 226 | struct ctfb_res_modes mode; |
| 227 | |
| 228 | puts("Video: "); |
| 229 | |
| 230 | /* Suck display configuration from "videomode" variable */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 231 | penv = env_get("videomode"); |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 232 | if (!penv) { |
Fabio Estevam | 5614783 | 2013-06-26 16:08:13 -0300 | [diff] [blame] | 233 | puts("MXSFB: 'videomode' variable not set!\n"); |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 234 | return NULL; |
| 235 | } |
| 236 | |
| 237 | bpp = video_get_params(&mode, penv); |
| 238 | |
| 239 | /* fill in Graphic device struct */ |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 240 | sprintf(panel.modeIdent, "%dx%dx%d", mode.xres, mode.yres, bpp); |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 241 | |
| 242 | panel.winSizeX = mode.xres; |
| 243 | panel.winSizeY = mode.yres; |
| 244 | panel.plnSizeX = mode.xres; |
| 245 | panel.plnSizeY = mode.yres; |
| 246 | |
| 247 | switch (bpp) { |
| 248 | case 24: |
| 249 | case 18: |
| 250 | panel.gdfBytesPP = 4; |
| 251 | panel.gdfIndex = GDF_32BIT_X888RGB; |
| 252 | break; |
| 253 | case 16: |
| 254 | panel.gdfBytesPP = 2; |
| 255 | panel.gdfIndex = GDF_16BIT_565RGB; |
| 256 | break; |
| 257 | case 8: |
| 258 | panel.gdfBytesPP = 1; |
| 259 | panel.gdfIndex = GDF__8BIT_INDEX; |
| 260 | break; |
| 261 | default: |
| 262 | printf("MXSFB: Invalid BPP specified! (bpp = %i)\n", bpp); |
| 263 | return NULL; |
| 264 | } |
| 265 | |
| 266 | panel.memSize = mode.xres * mode.yres * panel.gdfBytesPP; |
| 267 | |
| 268 | /* Allocate framebuffer */ |
Marek Vasut | ce74fac | 2013-07-30 23:37:52 +0200 | [diff] [blame] | 269 | fb = memalign(ARCH_DMA_MINALIGN, |
| 270 | roundup(panel.memSize, ARCH_DMA_MINALIGN)); |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 271 | if (!fb) { |
| 272 | printf("MXSFB: Error allocating framebuffer!\n"); |
| 273 | return NULL; |
| 274 | } |
| 275 | |
| 276 | /* Wipe framebuffer */ |
| 277 | memset(fb, 0, panel.memSize); |
| 278 | |
| 279 | panel.frameAdrs = (u32)fb; |
| 280 | |
| 281 | printf("%s\n", panel.modeIdent); |
| 282 | |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 283 | ret = mxs_probe_common(NULL, &mode, bpp, (u32)fb); |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 284 | if (ret) |
| 285 | goto dealloc_fb; |
Marek Vasut | 8f15b5d | 2013-07-30 23:37:54 +0200 | [diff] [blame] | 286 | |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 287 | return (void *)&panel; |
Marek Vasut | 8f15b5d | 2013-07-30 23:37:54 +0200 | [diff] [blame] | 288 | |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 289 | dealloc_fb: |
| 290 | free(fb); |
Marek Vasut | 8f15b5d | 2013-07-30 23:37:54 +0200 | [diff] [blame] | 291 | |
Igor Opaniuk | 3673492 | 2019-06-04 00:05:58 +0300 | [diff] [blame] | 292 | return NULL; |
Marek Vasut | ffdd466 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 293 | } |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 294 | #else /* ifndef CONFIG_DM_VIDEO */ |
| 295 | |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 296 | static int mxs_of_get_timings(struct udevice *dev, |
| 297 | struct display_timing *timings, |
| 298 | u32 *bpp) |
| 299 | { |
| 300 | int ret = 0; |
| 301 | u32 display_phandle; |
| 302 | ofnode display_node; |
| 303 | |
| 304 | ret = ofnode_read_u32(dev_ofnode(dev), "display", &display_phandle); |
| 305 | if (ret) { |
| 306 | dev_err(dev, "required display property isn't provided\n"); |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | |
| 310 | display_node = ofnode_get_by_phandle(display_phandle); |
| 311 | if (!ofnode_valid(display_node)) { |
| 312 | dev_err(dev, "failed to find display subnode\n"); |
| 313 | return -EINVAL; |
| 314 | } |
| 315 | |
| 316 | ret = ofnode_read_u32(display_node, "bits-per-pixel", bpp); |
| 317 | if (ret) { |
| 318 | dev_err(dev, |
| 319 | "required bits-per-pixel property isn't provided\n"); |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | |
| 323 | ret = ofnode_decode_display_timing(display_node, 0, timings); |
| 324 | if (ret) { |
| 325 | dev_err(dev, "failed to get any display timings\n"); |
| 326 | return -EINVAL; |
| 327 | } |
| 328 | |
| 329 | return ret; |
| 330 | } |
| 331 | |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 332 | static int mxs_video_probe(struct udevice *dev) |
| 333 | { |
| 334 | struct video_uc_platdata *plat = dev_get_uclass_platdata(dev); |
| 335 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
| 336 | |
| 337 | struct ctfb_res_modes mode; |
| 338 | struct display_timing timings; |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 339 | u32 bpp = 0; |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 340 | u32 fb_start, fb_end; |
| 341 | int ret; |
| 342 | |
| 343 | debug("%s() plat: base 0x%lx, size 0x%x\n", |
| 344 | __func__, plat->base, plat->size); |
| 345 | |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 346 | ret = mxs_of_get_timings(dev, &timings, &bpp); |
| 347 | if (ret) |
| 348 | return ret; |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 349 | |
| 350 | mode.xres = timings.hactive.typ; |
| 351 | mode.yres = timings.vactive.typ; |
| 352 | mode.left_margin = timings.hback_porch.typ; |
| 353 | mode.right_margin = timings.hfront_porch.typ; |
| 354 | mode.upper_margin = timings.vback_porch.typ; |
| 355 | mode.lower_margin = timings.vfront_porch.typ; |
| 356 | mode.hsync_len = timings.hsync_len.typ; |
| 357 | mode.vsync_len = timings.vsync_len.typ; |
| 358 | mode.pixclock = HZ2PS(timings.pixelclock.typ); |
| 359 | |
Giulio Benetti | f14d000 | 2020-04-08 17:10:13 +0200 | [diff] [blame^] | 360 | ret = mxs_probe_common(dev, &mode, bpp, plat->base); |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 361 | if (ret) |
| 362 | return ret; |
| 363 | |
| 364 | switch (bpp) { |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 365 | case 32: |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 366 | case 24: |
| 367 | case 18: |
| 368 | uc_priv->bpix = VIDEO_BPP32; |
| 369 | break; |
| 370 | case 16: |
| 371 | uc_priv->bpix = VIDEO_BPP16; |
| 372 | break; |
| 373 | case 8: |
| 374 | uc_priv->bpix = VIDEO_BPP8; |
| 375 | break; |
| 376 | default: |
| 377 | dev_err(dev, "invalid bpp specified (bpp = %i)\n", bpp); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
| 381 | uc_priv->xsize = mode.xres; |
| 382 | uc_priv->ysize = mode.yres; |
| 383 | |
| 384 | /* Enable dcache for the frame buffer */ |
| 385 | fb_start = plat->base & ~(MMU_SECTION_SIZE - 1); |
| 386 | fb_end = plat->base + plat->size; |
| 387 | fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT); |
| 388 | mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start, |
| 389 | DCACHE_WRITEBACK); |
| 390 | video_set_flush_dcache(dev, true); |
Sébastien Szymanski | eb9b6a8 | 2019-10-21 15:33:04 +0200 | [diff] [blame] | 391 | gd->fb_base = plat->base; |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | static int mxs_video_bind(struct udevice *dev) |
| 397 | { |
| 398 | struct video_uc_platdata *plat = dev_get_uclass_platdata(dev); |
| 399 | struct display_timing timings; |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 400 | u32 bpp = 0; |
| 401 | u32 bytes_pp = 0; |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 402 | int ret; |
| 403 | |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 404 | ret = mxs_of_get_timings(dev, &timings, &bpp); |
| 405 | if (ret) |
| 406 | return ret; |
| 407 | |
| 408 | switch (bpp) { |
| 409 | case 32: |
| 410 | case 24: |
| 411 | case 18: |
| 412 | bytes_pp = 4; |
| 413 | break; |
| 414 | case 16: |
| 415 | bytes_pp = 2; |
| 416 | break; |
| 417 | case 8: |
| 418 | bytes_pp = 1; |
| 419 | break; |
| 420 | default: |
| 421 | dev_err(dev, "invalid bpp specified (bpp = %i)\n", bpp); |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 422 | return -EINVAL; |
| 423 | } |
| 424 | |
Igor Opaniuk | 994f49a | 2019-06-19 11:47:05 +0300 | [diff] [blame] | 425 | plat->size = timings.hactive.typ * timings.vactive.typ * bytes_pp; |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int mxs_video_remove(struct udevice *dev) |
| 431 | { |
| 432 | struct video_uc_platdata *plat = dev_get_uclass_platdata(dev); |
| 433 | |
| 434 | mxs_remove_common(plat->base); |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | static const struct udevice_id mxs_video_ids[] = { |
| 440 | { .compatible = "fsl,imx23-lcdif" }, |
| 441 | { .compatible = "fsl,imx28-lcdif" }, |
| 442 | { .compatible = "fsl,imx7ulp-lcdif" }, |
| 443 | { /* sentinel */ } |
| 444 | }; |
| 445 | |
| 446 | U_BOOT_DRIVER(mxs_video) = { |
| 447 | .name = "mxs_video", |
| 448 | .id = UCLASS_VIDEO, |
| 449 | .of_match = mxs_video_ids, |
| 450 | .bind = mxs_video_bind, |
| 451 | .probe = mxs_video_probe, |
| 452 | .remove = mxs_video_remove, |
Anatolij Gustschin | f9888f9 | 2020-01-25 23:44:56 +0100 | [diff] [blame] | 453 | .flags = DM_FLAG_PRE_RELOC | DM_FLAG_OS_PREPARE, |
Igor Opaniuk | f5abe40 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 454 | }; |
| 455 | #endif /* ifndef CONFIG_DM_VIDEO */ |