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