Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Novena video output support |
| 4 | * |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 5 | * IT6251 code based on code Copyright (C) 2014 Sean Cross |
| 6 | * from https://github.com/xobs/novena-linux.git commit |
| 7 | * 3d85836ee1377d445531928361809612aa0a18db |
| 8 | * |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 9 | * Copyright (C) 2014 Marek Vasut <marex@denx.de> |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 14 | #include <linux/errno.h> |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 15 | #include <asm/gpio.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/arch/clock.h> |
| 18 | #include <asm/arch/crm_regs.h> |
| 19 | #include <asm/arch/imx-regs.h> |
| 20 | #include <asm/arch/iomux.h> |
| 21 | #include <asm/arch/mxc_hdmi.h> |
| 22 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 23 | #include <asm/mach-imx/iomux-v3.h> |
| 24 | #include <asm/mach-imx/mxc_i2c.h> |
| 25 | #include <asm/mach-imx/video.h> |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 26 | #include <i2c.h> |
| 27 | #include <input.h> |
| 28 | #include <ipu_pixfmt.h> |
| 29 | #include <linux/fb.h> |
| 30 | #include <linux/input.h> |
| 31 | #include <malloc.h> |
| 32 | #include <stdio_dev.h> |
| 33 | |
| 34 | #include "novena.h" |
| 35 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 36 | #define IT6251_VENDOR_ID_LOW 0x00 |
| 37 | #define IT6251_VENDOR_ID_HIGH 0x01 |
| 38 | #define IT6251_DEVICE_ID_LOW 0x02 |
| 39 | #define IT6251_DEVICE_ID_HIGH 0x03 |
| 40 | #define IT6251_SYSTEM_STATUS 0x0d |
| 41 | #define IT6251_SYSTEM_STATUS_RINTSTATUS (1 << 0) |
| 42 | #define IT6251_SYSTEM_STATUS_RHPDSTATUS (1 << 1) |
| 43 | #define IT6251_SYSTEM_STATUS_RVIDEOSTABLE (1 << 2) |
| 44 | #define IT6251_SYSTEM_STATUS_RPLL_IOLOCK (1 << 3) |
| 45 | #define IT6251_SYSTEM_STATUS_RPLL_XPLOCK (1 << 4) |
| 46 | #define IT6251_SYSTEM_STATUS_RPLL_SPLOCK (1 << 5) |
| 47 | #define IT6251_SYSTEM_STATUS_RAUXFREQ_LOCK (1 << 6) |
| 48 | #define IT6251_REF_STATE 0x0e |
| 49 | #define IT6251_REF_STATE_MAIN_LINK_DISABLED (1 << 0) |
| 50 | #define IT6251_REF_STATE_AUX_CHANNEL_READ (1 << 1) |
| 51 | #define IT6251_REF_STATE_CR_PATTERN (1 << 2) |
| 52 | #define IT6251_REF_STATE_EQ_PATTERN (1 << 3) |
| 53 | #define IT6251_REF_STATE_NORMAL_OPERATION (1 << 4) |
| 54 | #define IT6251_REF_STATE_MUTED (1 << 5) |
| 55 | |
| 56 | #define IT6251_REG_PCLK_CNT_LOW 0x57 |
| 57 | #define IT6251_REG_PCLK_CNT_HIGH 0x58 |
| 58 | |
| 59 | #define IT6521_RETRY_MAX 20 |
| 60 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 61 | static struct udevice *it6251_chip; |
| 62 | static struct udevice *it6251_lvds; |
| 63 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 64 | static int it6251_is_stable(void) |
| 65 | { |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 66 | int status; |
| 67 | int clkcnt; |
| 68 | int rpclkcnt; |
| 69 | int refstate; |
| 70 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 71 | rpclkcnt = (dm_i2c_reg_read(it6251_chip, 0x13) & 0xff) | |
| 72 | ((dm_i2c_reg_read(it6251_chip, 0x14) << 8) & 0x0f00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 73 | debug("RPCLKCnt: %d\n", rpclkcnt); |
| 74 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 75 | status = dm_i2c_reg_read(it6251_chip, IT6251_SYSTEM_STATUS); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 76 | debug("System status: 0x%02x\n", status); |
| 77 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 78 | clkcnt = (dm_i2c_reg_read(it6251_lvds, IT6251_REG_PCLK_CNT_LOW) & 0xff) | |
| 79 | ((dm_i2c_reg_read(it6251_lvds, IT6251_REG_PCLK_CNT_HIGH) << 8) & |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 80 | 0x0f00); |
| 81 | debug("Clock: 0x%02x\n", clkcnt); |
| 82 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 83 | refstate = dm_i2c_reg_read(it6251_lvds, IT6251_REF_STATE); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 84 | debug("Ref Link State: 0x%02x\n", refstate); |
| 85 | |
| 86 | if ((refstate & 0x1f) != 0) |
| 87 | return 0; |
| 88 | |
| 89 | /* If video is muted, that's a failure */ |
| 90 | if (refstate & IT6251_REF_STATE_MUTED) |
| 91 | return 0; |
| 92 | |
| 93 | if (!(status & IT6251_SYSTEM_STATUS_RVIDEOSTABLE)) |
| 94 | return 0; |
| 95 | |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | static int it6251_ready(void) |
| 100 | { |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 101 | /* Test if the IT6251 came out of reset by reading ID regs. */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 102 | if (dm_i2c_reg_read(it6251_chip, IT6251_VENDOR_ID_LOW) != 0x15) |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 103 | return 0; |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 104 | if (dm_i2c_reg_read(it6251_chip, IT6251_VENDOR_ID_HIGH) != 0xca) |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 105 | return 0; |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 106 | if (dm_i2c_reg_read(it6251_chip, IT6251_DEVICE_ID_LOW) != 0x51) |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 107 | return 0; |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 108 | if (dm_i2c_reg_read(it6251_chip, IT6251_DEVICE_ID_HIGH) != 0x62) |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 109 | return 0; |
| 110 | |
| 111 | return 1; |
| 112 | } |
| 113 | |
| 114 | static void it6251_program_regs(void) |
| 115 | { |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 116 | dm_i2c_reg_write(it6251_chip, 0x05, 0x00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 117 | mdelay(1); |
| 118 | |
| 119 | /* set LVDSRX address, and enable */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 120 | dm_i2c_reg_write(it6251_chip, 0xfd, 0xbc); |
| 121 | dm_i2c_reg_write(it6251_chip, 0xfe, 0x01); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * LVDSRX |
| 125 | */ |
| 126 | /* This write always fails, because the chip goes into reset */ |
| 127 | /* reset LVDSRX */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 128 | dm_i2c_reg_write(it6251_lvds, 0x05, 0xff); |
| 129 | dm_i2c_reg_write(it6251_lvds, 0x05, 0x00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 130 | |
| 131 | /* reset LVDSRX PLL */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 132 | dm_i2c_reg_write(it6251_lvds, 0x3b, 0x42); |
| 133 | dm_i2c_reg_write(it6251_lvds, 0x3b, 0x43); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 134 | |
| 135 | /* something with SSC PLL */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 136 | dm_i2c_reg_write(it6251_lvds, 0x3c, 0x08); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 137 | /* don't swap links, but writing reserved registers */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 138 | dm_i2c_reg_write(it6251_lvds, 0x0b, 0x88); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 139 | |
| 140 | /* JEIDA, 8-bit depth 0x11, orig 0x42 */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 141 | dm_i2c_reg_write(it6251_lvds, 0x2c, 0x01); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 142 | /* "reserved" */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 143 | dm_i2c_reg_write(it6251_lvds, 0x32, 0x04); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 144 | /* "reserved" */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 145 | dm_i2c_reg_write(it6251_lvds, 0x35, 0xe0); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 146 | /* "reserved" + clock delay */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 147 | dm_i2c_reg_write(it6251_lvds, 0x2b, 0x24); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 148 | |
| 149 | /* reset LVDSRX pix clock */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 150 | dm_i2c_reg_write(it6251_lvds, 0x05, 0x02); |
| 151 | dm_i2c_reg_write(it6251_lvds, 0x05, 0x00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * DPTX |
| 155 | */ |
| 156 | /* set for two lane mode, normal op, no swapping, no downspread */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 157 | dm_i2c_reg_write(it6251_chip, 0x16, 0x02); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 158 | |
| 159 | /* some AUX channel EDID magic */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 160 | dm_i2c_reg_write(it6251_chip, 0x23, 0x40); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 161 | |
| 162 | /* power down lanes 3-0 */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 163 | dm_i2c_reg_write(it6251_chip, 0x5c, 0xf3); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 164 | |
| 165 | /* enable DP scrambling, change EQ CR phase */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 166 | dm_i2c_reg_write(it6251_chip, 0x5f, 0x06); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 167 | |
| 168 | /* color mode RGB, pclk/2 */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 169 | dm_i2c_reg_write(it6251_chip, 0x60, 0x02); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 170 | /* dual pixel input mode, no EO swap, no RGB swap */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 171 | dm_i2c_reg_write(it6251_chip, 0x61, 0x04); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 172 | /* M444B24 video format */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 173 | dm_i2c_reg_write(it6251_chip, 0x62, 0x01); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 174 | |
| 175 | /* vesa range / not interlace / vsync high / hsync high */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 176 | dm_i2c_reg_write(it6251_chip, 0xa0, 0x0F); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 177 | |
| 178 | /* hpd event timer set to 1.6-ish ms */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 179 | dm_i2c_reg_write(it6251_chip, 0xc9, 0xf5); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 180 | |
| 181 | /* more reserved magic */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 182 | dm_i2c_reg_write(it6251_chip, 0xca, 0x4d); |
| 183 | dm_i2c_reg_write(it6251_chip, 0xcb, 0x37); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 184 | |
| 185 | /* enhanced framing mode, auto video fifo reset, video mute disable */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 186 | dm_i2c_reg_write(it6251_chip, 0xd3, 0x03); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 187 | |
| 188 | /* "vidstmp" and some reserved stuff */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 189 | dm_i2c_reg_write(it6251_chip, 0xd4, 0x45); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 190 | |
| 191 | /* queue number -- reserved */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 192 | dm_i2c_reg_write(it6251_chip, 0xe7, 0xa0); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 193 | /* info frame packets and reserved */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 194 | dm_i2c_reg_write(it6251_chip, 0xe8, 0x33); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 195 | /* more AVI stuff */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 196 | dm_i2c_reg_write(it6251_chip, 0xec, 0x00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 197 | |
| 198 | /* select PC master reg for aux channel? */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 199 | dm_i2c_reg_write(it6251_chip, 0x23, 0x42); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 200 | |
| 201 | /* send PC request commands */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 202 | dm_i2c_reg_write(it6251_chip, 0x24, 0x00); |
| 203 | dm_i2c_reg_write(it6251_chip, 0x25, 0x00); |
| 204 | dm_i2c_reg_write(it6251_chip, 0x26, 0x00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 205 | |
| 206 | /* native aux read */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 207 | dm_i2c_reg_write(it6251_chip, 0x2b, 0x00); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 208 | /* back to internal */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 209 | dm_i2c_reg_write(it6251_chip, 0x23, 0x40); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 210 | |
| 211 | /* voltage swing level 3 */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 212 | dm_i2c_reg_write(it6251_chip, 0x19, 0xff); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 213 | /* pre-emphasis level 3 */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 214 | dm_i2c_reg_write(it6251_chip, 0x1a, 0xff); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 215 | |
| 216 | /* start link training */ |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 217 | dm_i2c_reg_write(it6251_chip, 0x17, 0x01); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static int it6251_init(void) |
| 221 | { |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 222 | int reg; |
| 223 | int tries, retries = 0; |
| 224 | |
| 225 | for (retries = 0; retries < IT6521_RETRY_MAX; retries++) { |
| 226 | /* Program the chip. */ |
| 227 | it6251_program_regs(); |
| 228 | |
| 229 | /* Wait for video stable. */ |
| 230 | for (tries = 0; tries < 100; tries++) { |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 231 | reg = dm_i2c_reg_read(it6251_chip, 0x17); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 232 | /* Test Link CFG, STS, LCS read done. */ |
| 233 | if ((reg & 0xe0) != 0xe0) { |
| 234 | /* Not yet, wait a bit more. */ |
| 235 | mdelay(2); |
| 236 | continue; |
| 237 | } |
| 238 | |
| 239 | /* Test if the video input is stable. */ |
| 240 | if (it6251_is_stable()) |
| 241 | return 0; |
| 242 | } |
| 243 | /* |
| 244 | * If we couldn't stabilize, requeue and try again, |
| 245 | * because it means that the LVDS channel isn't |
| 246 | * stable yet. |
| 247 | */ |
| 248 | printf("Display didn't stabilize.\n"); |
| 249 | printf("This may be because the LVDS port is still in powersave mode.\n"); |
| 250 | mdelay(50); |
| 251 | } |
| 252 | |
| 253 | return -EINVAL; |
| 254 | } |
| 255 | |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 256 | static void enable_hdmi(struct display_info_t const *dev) |
| 257 | { |
| 258 | imx_enable_hdmi_phy(); |
| 259 | } |
| 260 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 261 | static int lvds_enabled; |
| 262 | |
| 263 | static void enable_lvds(struct display_info_t const *dev) |
| 264 | { |
| 265 | if (lvds_enabled) |
| 266 | return; |
| 267 | |
| 268 | /* ITE IT6251 power enable. */ |
Marek Vasut | 7149cc8 | 2019-05-17 20:32:16 +0200 | [diff] [blame] | 269 | gpio_request(NOVENA_ITE6251_PWR_GPIO, "ite6251-power"); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 270 | gpio_direction_output(NOVENA_ITE6251_PWR_GPIO, 0); |
| 271 | mdelay(10); |
| 272 | gpio_direction_output(NOVENA_ITE6251_PWR_GPIO, 1); |
| 273 | mdelay(20); |
| 274 | lvds_enabled = 1; |
| 275 | } |
| 276 | |
| 277 | static int detect_lvds(struct display_info_t const *dev) |
| 278 | { |
| 279 | int ret, loops = 250; |
| 280 | |
| 281 | enable_lvds(dev); |
| 282 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 283 | if (!it6251_chip) { |
| 284 | ret = i2c_get_chip_for_busnum(NOVENA_IT6251_I2C_BUS, |
| 285 | NOVENA_IT6251_CHIPADDR, |
| 286 | 1, &it6251_chip); |
| 287 | if (ret) { |
| 288 | puts("Cannot select IT6251 I2C bus.\n"); |
| 289 | return 0; |
| 290 | } |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* Wait up-to ~250 mS for the LVDS to come up. */ |
| 294 | while (--loops) { |
| 295 | ret = it6251_ready(); |
| 296 | if (ret) |
| 297 | return ret; |
| 298 | |
| 299 | mdelay(1); |
| 300 | } |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 305 | struct display_info_t const displays[] = { |
| 306 | { |
| 307 | /* HDMI Output */ |
| 308 | .bus = -1, |
| 309 | .addr = 0, |
| 310 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 311 | .detect = detect_hdmi, |
| 312 | .enable = enable_hdmi, |
| 313 | .mode = { |
| 314 | .name = "HDMI", |
| 315 | .refresh = 60, |
| 316 | .xres = 1024, |
| 317 | .yres = 768, |
| 318 | .pixclock = 15384, |
| 319 | .left_margin = 220, |
| 320 | .right_margin = 40, |
| 321 | .upper_margin = 21, |
| 322 | .lower_margin = 7, |
| 323 | .hsync_len = 60, |
| 324 | .vsync_len = 10, |
| 325 | .sync = FB_SYNC_EXT, |
| 326 | .vmode = FB_VMODE_NONINTERLACED |
| 327 | }, |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 328 | }, { |
| 329 | /* LVDS Output: N133HSE-EA1 Rev. C1 */ |
| 330 | .bus = -1, |
| 331 | .pixfmt = IPU_PIX_FMT_RGB24, |
| 332 | .detect = detect_lvds, |
| 333 | .enable = enable_lvds, |
| 334 | .mode = { |
| 335 | .name = "Chimei-FHD", |
| 336 | .refresh = 60, |
| 337 | .xres = 1920, |
| 338 | .yres = 1080, |
| 339 | .pixclock = 15384, |
| 340 | .left_margin = 148, |
| 341 | .right_margin = 88, |
| 342 | .upper_margin = 36, |
| 343 | .lower_margin = 4, |
| 344 | .hsync_len = 44, |
| 345 | .vsync_len = 5, |
| 346 | .sync = FB_SYNC_HOR_HIGH_ACT | |
| 347 | FB_SYNC_VERT_HIGH_ACT | |
| 348 | FB_SYNC_EXT, |
| 349 | .vmode = FB_VMODE_NONINTERLACED, |
| 350 | }, |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 351 | }, |
| 352 | }; |
| 353 | |
| 354 | size_t display_count = ARRAY_SIZE(displays); |
| 355 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 356 | static void enable_vpll(void) |
| 357 | { |
| 358 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 359 | int timeout = 100000; |
| 360 | |
| 361 | setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN); |
| 362 | |
| 363 | clrsetbits_le32(&ccm->analog_pll_video, |
| 364 | BM_ANADIG_PLL_VIDEO_DIV_SELECT | |
| 365 | BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT, |
| 366 | BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) | |
| 367 | BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1)); |
| 368 | |
| 369 | writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num); |
| 370 | writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom); |
| 371 | |
| 372 | clrbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN); |
| 373 | |
| 374 | while (timeout--) |
| 375 | if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK) |
| 376 | break; |
| 377 | if (timeout < 0) |
| 378 | printf("Warning: video pll lock timeout!\n"); |
| 379 | |
| 380 | clrsetbits_le32(&ccm->analog_pll_video, |
| 381 | BM_ANADIG_PLL_VIDEO_BYPASS, |
| 382 | BM_ANADIG_PLL_VIDEO_ENABLE); |
| 383 | } |
| 384 | |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 385 | void setup_display_clock(void) |
| 386 | { |
| 387 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 388 | struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 389 | |
| 390 | enable_ipu_clock(); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 391 | enable_vpll(); |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 392 | imx_setup_hdmi(); |
| 393 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 394 | /* Turn on IPU LDB DI0 clocks */ |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 395 | setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK); |
| 396 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 397 | /* Switch LDB DI0 to PLL5 (Video PLL) */ |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 398 | clrsetbits_le32(&mxc_ccm->cs2cdr, |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 399 | MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK, |
| 400 | (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)); |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 401 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 402 | /* LDB clock div by 3.5 */ |
| 403 | clrbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV); |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 404 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 405 | /* DI0 clock derived from ldb_di0_clk */ |
| 406 | clrsetbits_le32(&mxc_ccm->chsccdr, |
| 407 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK, |
| 408 | (CHSCCDR_CLK_SEL_LDB_DI0 << |
| 409 | MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET) |
| 410 | ); |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 411 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 412 | /* Enable both LVDS channels, both connected to DI0. */ |
| 413 | writel(IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_HIGH | |
| 414 | IOMUXC_GPR2_BIT_MAPPING_CH1_JEIDA | |
| 415 | IOMUXC_GPR2_DATA_WIDTH_CH1_24BIT | |
| 416 | IOMUXC_GPR2_BIT_MAPPING_CH0_JEIDA | |
| 417 | IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT | |
| 418 | IOMUXC_GPR2_SPLIT_MODE_EN_MASK | |
| 419 | IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0 | |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 420 | IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0, |
| 421 | &iomux->gpr[2]); |
| 422 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 423 | clrsetbits_le32(&iomux->gpr[3], |
| 424 | IOMUXC_GPR3_LVDS0_MUX_CTL_MASK | |
| 425 | IOMUXC_GPR3_LVDS1_MUX_CTL_MASK, |
| 426 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 << |
| 427 | IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET) | |
| 428 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0 << |
| 429 | IOMUXC_GPR3_LVDS1_MUX_CTL_OFFSET) |
| 430 | ); |
| 431 | } |
| 432 | |
| 433 | void setup_display_lvds(void) |
| 434 | { |
| 435 | int ret; |
| 436 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 437 | if (!it6251_chip) { |
| 438 | ret = i2c_get_chip_for_busnum(NOVENA_IT6251_I2C_BUS, |
| 439 | NOVENA_IT6251_CHIPADDR, |
| 440 | 1, &it6251_chip); |
| 441 | if (ret) { |
| 442 | puts("Cannot select LVDS-to-eDP I2C bus.\n"); |
| 443 | return; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | ret = i2c_get_chip_for_busnum(NOVENA_IT6251_I2C_BUS, |
| 448 | NOVENA_IT6251_LVDSADDR, 1, &it6251_lvds); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 449 | if (ret) { |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 450 | puts("Cannot find IT6251 LVDS bus.\n"); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
| 454 | /* The IT6251 should be ready now, if it's not, it's not connected. */ |
| 455 | ret = it6251_ready(); |
| 456 | if (!ret) |
| 457 | return; |
| 458 | |
| 459 | /* Init the LVDS-to-eDP chip and if it succeeded, enable backlight. */ |
| 460 | ret = it6251_init(); |
| 461 | if (!ret) { |
Marek Vasut | 7149cc8 | 2019-05-17 20:32:16 +0200 | [diff] [blame] | 462 | gpio_request(NOVENA_BACKLIGHT_PWR_GPIO, "backlight-power"); |
| 463 | gpio_request(NOVENA_BACKLIGHT_PWM_GPIO, "backlight-pwm"); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 464 | /* Backlight power enable. */ |
| 465 | gpio_direction_output(NOVENA_BACKLIGHT_PWR_GPIO, 1); |
| 466 | /* PWM backlight pin, always on for full brightness. */ |
| 467 | gpio_direction_output(NOVENA_BACKLIGHT_PWM_GPIO, 1); |
| 468 | } |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 469 | } |