blob: 67f98431b58292667b09682007adf69d80e391aa [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut5da39bf2014-12-16 14:09:22 +01002/*
3 * Novena video output support
4 *
Marek Vasut7d4dcba2014-12-16 14:09:23 +01005 * IT6251 code based on code Copyright (C) 2014 Sean Cross
6 * from https://github.com/xobs/novena-linux.git commit
7 * 3d85836ee1377d445531928361809612aa0a18db
8 *
Marek Vasut5da39bf2014-12-16 14:09:22 +01009 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
Marek Vasut5da39bf2014-12-16 14:09:22 +010010 */
11
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090014#include <linux/errno.h>
Marek Vasut5da39bf2014-12-16 14:09:22 +010015#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 Babic33731bc2017-06-29 10:16:06 +020023#include <asm/mach-imx/iomux-v3.h>
24#include <asm/mach-imx/mxc_i2c.h>
25#include <asm/mach-imx/video.h>
Marek Vasut5da39bf2014-12-16 14:09:22 +010026#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 Vasut7d4dcba2014-12-16 14:09:23 +010036#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 Gustschin1b6a7ca2024-08-03 18:15:09 +020061static struct udevice *it6251_chip;
62static struct udevice *it6251_lvds;
63
Marek Vasut7d4dcba2014-12-16 14:09:23 +010064static int it6251_is_stable(void)
65{
Marek Vasut7d4dcba2014-12-16 14:09:23 +010066 int status;
67 int clkcnt;
68 int rpclkcnt;
69 int refstate;
70
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +020071 rpclkcnt = (dm_i2c_reg_read(it6251_chip, 0x13) & 0xff) |
72 ((dm_i2c_reg_read(it6251_chip, 0x14) << 8) & 0x0f00);
Marek Vasut7d4dcba2014-12-16 14:09:23 +010073 debug("RPCLKCnt: %d\n", rpclkcnt);
74
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +020075 status = dm_i2c_reg_read(it6251_chip, IT6251_SYSTEM_STATUS);
Marek Vasut7d4dcba2014-12-16 14:09:23 +010076 debug("System status: 0x%02x\n", status);
77
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +020078 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 Vasut7d4dcba2014-12-16 14:09:23 +010080 0x0f00);
81 debug("Clock: 0x%02x\n", clkcnt);
82
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +020083 refstate = dm_i2c_reg_read(it6251_lvds, IT6251_REF_STATE);
Marek Vasut7d4dcba2014-12-16 14:09:23 +010084 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
99static int it6251_ready(void)
100{
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100101 /* Test if the IT6251 came out of reset by reading ID regs. */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200102 if (dm_i2c_reg_read(it6251_chip, IT6251_VENDOR_ID_LOW) != 0x15)
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100103 return 0;
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200104 if (dm_i2c_reg_read(it6251_chip, IT6251_VENDOR_ID_HIGH) != 0xca)
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100105 return 0;
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200106 if (dm_i2c_reg_read(it6251_chip, IT6251_DEVICE_ID_LOW) != 0x51)
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100107 return 0;
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200108 if (dm_i2c_reg_read(it6251_chip, IT6251_DEVICE_ID_HIGH) != 0x62)
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100109 return 0;
110
111 return 1;
112}
113
114static void it6251_program_regs(void)
115{
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200116 dm_i2c_reg_write(it6251_chip, 0x05, 0x00);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100117 mdelay(1);
118
119 /* set LVDSRX address, and enable */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200120 dm_i2c_reg_write(it6251_chip, 0xfd, 0xbc);
121 dm_i2c_reg_write(it6251_chip, 0xfe, 0x01);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100122
123 /*
124 * LVDSRX
125 */
126 /* This write always fails, because the chip goes into reset */
127 /* reset LVDSRX */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200128 dm_i2c_reg_write(it6251_lvds, 0x05, 0xff);
129 dm_i2c_reg_write(it6251_lvds, 0x05, 0x00);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100130
131 /* reset LVDSRX PLL */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200132 dm_i2c_reg_write(it6251_lvds, 0x3b, 0x42);
133 dm_i2c_reg_write(it6251_lvds, 0x3b, 0x43);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100134
135 /* something with SSC PLL */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200136 dm_i2c_reg_write(it6251_lvds, 0x3c, 0x08);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100137 /* don't swap links, but writing reserved registers */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200138 dm_i2c_reg_write(it6251_lvds, 0x0b, 0x88);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100139
140 /* JEIDA, 8-bit depth 0x11, orig 0x42 */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200141 dm_i2c_reg_write(it6251_lvds, 0x2c, 0x01);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100142 /* "reserved" */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200143 dm_i2c_reg_write(it6251_lvds, 0x32, 0x04);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100144 /* "reserved" */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200145 dm_i2c_reg_write(it6251_lvds, 0x35, 0xe0);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100146 /* "reserved" + clock delay */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200147 dm_i2c_reg_write(it6251_lvds, 0x2b, 0x24);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100148
149 /* reset LVDSRX pix clock */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200150 dm_i2c_reg_write(it6251_lvds, 0x05, 0x02);
151 dm_i2c_reg_write(it6251_lvds, 0x05, 0x00);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100152
153 /*
154 * DPTX
155 */
156 /* set for two lane mode, normal op, no swapping, no downspread */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200157 dm_i2c_reg_write(it6251_chip, 0x16, 0x02);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100158
159 /* some AUX channel EDID magic */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200160 dm_i2c_reg_write(it6251_chip, 0x23, 0x40);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100161
162 /* power down lanes 3-0 */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200163 dm_i2c_reg_write(it6251_chip, 0x5c, 0xf3);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100164
165 /* enable DP scrambling, change EQ CR phase */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200166 dm_i2c_reg_write(it6251_chip, 0x5f, 0x06);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100167
168 /* color mode RGB, pclk/2 */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200169 dm_i2c_reg_write(it6251_chip, 0x60, 0x02);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100170 /* dual pixel input mode, no EO swap, no RGB swap */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200171 dm_i2c_reg_write(it6251_chip, 0x61, 0x04);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100172 /* M444B24 video format */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200173 dm_i2c_reg_write(it6251_chip, 0x62, 0x01);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100174
175 /* vesa range / not interlace / vsync high / hsync high */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200176 dm_i2c_reg_write(it6251_chip, 0xa0, 0x0F);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100177
178 /* hpd event timer set to 1.6-ish ms */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200179 dm_i2c_reg_write(it6251_chip, 0xc9, 0xf5);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100180
181 /* more reserved magic */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200182 dm_i2c_reg_write(it6251_chip, 0xca, 0x4d);
183 dm_i2c_reg_write(it6251_chip, 0xcb, 0x37);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100184
185 /* enhanced framing mode, auto video fifo reset, video mute disable */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200186 dm_i2c_reg_write(it6251_chip, 0xd3, 0x03);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100187
188 /* "vidstmp" and some reserved stuff */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200189 dm_i2c_reg_write(it6251_chip, 0xd4, 0x45);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100190
191 /* queue number -- reserved */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200192 dm_i2c_reg_write(it6251_chip, 0xe7, 0xa0);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100193 /* info frame packets and reserved */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200194 dm_i2c_reg_write(it6251_chip, 0xe8, 0x33);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100195 /* more AVI stuff */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200196 dm_i2c_reg_write(it6251_chip, 0xec, 0x00);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100197
198 /* select PC master reg for aux channel? */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200199 dm_i2c_reg_write(it6251_chip, 0x23, 0x42);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100200
201 /* send PC request commands */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200202 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 Vasut7d4dcba2014-12-16 14:09:23 +0100205
206 /* native aux read */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200207 dm_i2c_reg_write(it6251_chip, 0x2b, 0x00);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100208 /* back to internal */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200209 dm_i2c_reg_write(it6251_chip, 0x23, 0x40);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100210
211 /* voltage swing level 3 */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200212 dm_i2c_reg_write(it6251_chip, 0x19, 0xff);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100213 /* pre-emphasis level 3 */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200214 dm_i2c_reg_write(it6251_chip, 0x1a, 0xff);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100215
216 /* start link training */
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200217 dm_i2c_reg_write(it6251_chip, 0x17, 0x01);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100218}
219
220static int it6251_init(void)
221{
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100222 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 Gustschin1b6a7ca2024-08-03 18:15:09 +0200231 reg = dm_i2c_reg_read(it6251_chip, 0x17);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100232 /* 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 Vasut5da39bf2014-12-16 14:09:22 +0100256static void enable_hdmi(struct display_info_t const *dev)
257{
258 imx_enable_hdmi_phy();
259}
260
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100261static int lvds_enabled;
262
263static void enable_lvds(struct display_info_t const *dev)
264{
265 if (lvds_enabled)
266 return;
267
268 /* ITE IT6251 power enable. */
Marek Vasut7149cc82019-05-17 20:32:16 +0200269 gpio_request(NOVENA_ITE6251_PWR_GPIO, "ite6251-power");
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100270 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
277static int detect_lvds(struct display_info_t const *dev)
278{
279 int ret, loops = 250;
280
281 enable_lvds(dev);
282
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200283 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 Vasut7d4dcba2014-12-16 14:09:23 +0100291 }
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 Vasut5da39bf2014-12-16 14:09:22 +0100305struct 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 Vasut7d4dcba2014-12-16 14:09:23 +0100328 }, {
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 Vasut5da39bf2014-12-16 14:09:22 +0100351 },
352};
353
354size_t display_count = ARRAY_SIZE(displays);
355
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100356static 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 Vasut5da39bf2014-12-16 14:09:22 +0100385void 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 Vasut7d4dcba2014-12-16 14:09:23 +0100391 enable_vpll();
Marek Vasut5da39bf2014-12-16 14:09:22 +0100392 imx_setup_hdmi();
393
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100394 /* Turn on IPU LDB DI0 clocks */
Marek Vasut5da39bf2014-12-16 14:09:22 +0100395 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
396
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100397 /* Switch LDB DI0 to PLL5 (Video PLL) */
Marek Vasut5da39bf2014-12-16 14:09:22 +0100398 clrsetbits_le32(&mxc_ccm->cs2cdr,
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100399 MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK,
400 (0 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET));
Marek Vasut5da39bf2014-12-16 14:09:22 +0100401
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100402 /* LDB clock div by 3.5 */
403 clrbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
Marek Vasut5da39bf2014-12-16 14:09:22 +0100404
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100405 /* 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 Vasut5da39bf2014-12-16 14:09:22 +0100411
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100412 /* 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 Vasut5da39bf2014-12-16 14:09:22 +0100420 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
421 &iomux->gpr[2]);
422
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100423 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
433void setup_display_lvds(void)
434{
435 int ret;
436
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200437 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 Vasut7d4dcba2014-12-16 14:09:23 +0100449 if (ret) {
Anatolij Gustschin1b6a7ca2024-08-03 18:15:09 +0200450 puts("Cannot find IT6251 LVDS bus.\n");
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100451 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 Vasut7149cc82019-05-17 20:32:16 +0200462 gpio_request(NOVENA_BACKLIGHT_PWR_GPIO, "backlight-power");
463 gpio_request(NOVENA_BACKLIGHT_PWM_GPIO, "backlight-pwm");
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100464 /* 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 Vasut5da39bf2014-12-16 14:09:22 +0100469}