Prepare v2024.10
[platform/kernel/u-boot.git] / board / ge / mx53ppd / mx53ppd_video.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2017 General Electric Company
4  *
5  * Based on board/freescale/mx53loco/mx53loco_video.c:
6  *
7  * Copyright (C) 2012 Freescale Semiconductor, Inc.
8  * Fabio Estevam <fabio.estevam@freescale.com>
9  */
10
11 #include <dm.h>
12 #include <linux/list.h>
13 #include <asm/arch/iomux-mx53.h>
14 #include <asm/mach-imx/video.h>
15 #include <linux/fb.h>
16 #include <ipu_pixfmt.h>
17 #include <asm/arch/crm_regs.h>
18 #include <asm/arch/imx-regs.h>
19 #include <asm/io.h>
20 #include <panel.h>
21
22 static int detect_lcd(struct display_info_t const *dev)
23 {
24         return 1;
25 }
26
27 static void lcd_enable(void)
28 {
29         struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
30         struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
31
32         /* Set LDB_DI0 as clock source for IPU_DI0 */
33         clrsetbits_le32(&mxc_ccm->cscmr2,
34                         MXC_CCM_CSCMR2_DI0_CLK_SEL_MASK,
35                         MXC_CCM_CSCMR2_DI0_CLK_SEL(
36                                 MXC_CCM_CSCMR2_DI0_CLK_SEL_LDB_DI0_CLK));
37
38         /* Turn on IPU LDB DI0 clocks */
39         setbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_LDB_DI0(3));
40
41         /* Turn on IPU DI0 clocks */
42         setbits_le32(&mxc_ccm->CCGR6, MXC_CCM_CCGR6_IPU_DI0(3));
43
44         /* Configure LDB */
45         writel(IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
46                 IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT |
47                 IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0,
48                 &iomux->gpr[2]);
49 }
50
51 static void do_enable_backlight(struct display_info_t const *dev)
52 {
53         struct udevice *panel;
54         int ret;
55
56         lcd_enable();
57
58         ret = uclass_get_device(UCLASS_PANEL, 0, &panel);
59         if (ret) {
60                 printf("Could not find panel: %d\n", ret);
61                 return;
62         }
63
64         panel_set_backlight(panel, 100);
65         panel_enable_backlight(panel);
66 }
67
68 struct display_info_t const displays[] = {
69         {
70                 .bus    = -1,
71                 .addr   = -1,
72                 .pixfmt = IPU_PIX_FMT_RGB24,
73                 .detect = detect_lcd,
74                 .enable = do_enable_backlight,
75                 .mode = {
76                         .name           = "NV-SPWGRGB888",
77                         .refresh        = 60,
78                         .xres           = 800,
79                         .yres           = 480,
80                         .pixclock       = 15384,
81                         .left_margin    = 16,
82                         .right_margin   = 210,
83                         .upper_margin   = 10,
84                         .lower_margin   = 22,
85                         .hsync_len      = 30,
86                         .vsync_len      = 13,
87                         .sync           = FB_SYNC_EXT,
88                         .vmode          = FB_VMODE_NONINTERLACED
89                 }
90         }
91 };
92
93 size_t display_count = ARRAY_SIZE(displays);