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