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