xref: /openbmc/u-boot/board/engicam/imx6q/imx6q.c (revision 699e831e)
1 /*
2  * Copyright (C) 2016 Amarula Solutions B.V.
3  * Copyright (C) 2016 Engicam S.r.l.
4  * Author: Jagan Teki <jagan@amarulasolutions.com>
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 #include <common.h>
10 
11 #include <asm/io.h>
12 #include <asm/gpio.h>
13 #include <linux/sizes.h>
14 
15 #include <asm/arch/clock.h>
16 #include <asm/arch/crm_regs.h>
17 #include <asm/arch/iomux.h>
18 #include <asm/arch/mx6-pins.h>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/mach-imx/iomux-v3.h>
21 #include <asm/mach-imx/video.h>
22 
23 #include "../common/board.h"
24 
25 #ifdef CONFIG_NAND_MXS
26 #define GPMI_PAD_CTRL0	(PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
27 #define GPMI_PAD_CTRL1	(PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
28 			PAD_CTL_SRE_FAST)
29 #define GPMI_PAD_CTRL2	(GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
30 
31 static iomux_v3_cfg_t gpmi_pads[] = {
32 	IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
33 	IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
34 	IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
35 	IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B	| MUX_PAD_CTRL(GPMI_PAD_CTRL0)),
36 	IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
37 	IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
38 	IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
39 	IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
40 	IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
41 	IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
42 	IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
43 	IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
44 	IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
45 	IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
46 	IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07	| MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
47 };
48 
49 void setup_gpmi_nand(void)
50 {
51 	struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
52 
53 	/* config gpmi nand iomux */
54 	SETUP_IOMUX_PADS(gpmi_pads);
55 
56 	/* gate ENFC_CLK_ROOT clock first,before clk source switch */
57 	clrbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
58 
59 	/* config gpmi and bch clock to 100 MHz */
60 	clrsetbits_le32(&mxc_ccm->cs2cdr,
61 			MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
62 			MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
63 			MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
64 			MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
65 			MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
66 			MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
67 
68 	/* enable ENFC_CLK_ROOT clock */
69 	setbits_le32(&mxc_ccm->CCGR2, MXC_CCM_CCGR2_IOMUX_IPT_CLK_IO_MASK);
70 
71 	/* enable gpmi and bch clock gating */
72 	setbits_le32(&mxc_ccm->CCGR4,
73 		     MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
74 		     MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
75 		     MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
76 		     MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
77 		     MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
78 
79 	/* enable apbh clock gating */
80 	setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
81 }
82 #endif
83 
84 #if defined(CONFIG_VIDEO_IPUV3)
85 static iomux_v3_cfg_t const rgb_pads[] = {
86 	IOMUX_PADS(PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK),
87 	IOMUX_PADS(PAD_DI0_PIN15__IPU1_DI0_PIN15),
88 	IOMUX_PADS(PAD_DI0_PIN2__IPU1_DI0_PIN02),
89 	IOMUX_PADS(PAD_DI0_PIN3__IPU1_DI0_PIN03),
90 	IOMUX_PADS(PAD_DISP0_DAT0__IPU1_DISP0_DATA00),
91 	IOMUX_PADS(PAD_DISP0_DAT1__IPU1_DISP0_DATA01),
92 	IOMUX_PADS(PAD_DISP0_DAT2__IPU1_DISP0_DATA02),
93 	IOMUX_PADS(PAD_DISP0_DAT3__IPU1_DISP0_DATA03),
94 	IOMUX_PADS(PAD_DISP0_DAT4__IPU1_DISP0_DATA04),
95 	IOMUX_PADS(PAD_DISP0_DAT5__IPU1_DISP0_DATA05),
96 	IOMUX_PADS(PAD_DISP0_DAT6__IPU1_DISP0_DATA06),
97 	IOMUX_PADS(PAD_DISP0_DAT7__IPU1_DISP0_DATA07),
98 	IOMUX_PADS(PAD_DISP0_DAT8__IPU1_DISP0_DATA08),
99 	IOMUX_PADS(PAD_DISP0_DAT9__IPU1_DISP0_DATA09),
100 	IOMUX_PADS(PAD_DISP0_DAT10__IPU1_DISP0_DATA10),
101 	IOMUX_PADS(PAD_DISP0_DAT11__IPU1_DISP0_DATA11),
102 	IOMUX_PADS(PAD_DISP0_DAT12__IPU1_DISP0_DATA12),
103 	IOMUX_PADS(PAD_DISP0_DAT13__IPU1_DISP0_DATA13),
104 	IOMUX_PADS(PAD_DISP0_DAT14__IPU1_DISP0_DATA14),
105 	IOMUX_PADS(PAD_DISP0_DAT15__IPU1_DISP0_DATA15),
106 	IOMUX_PADS(PAD_DISP0_DAT16__IPU1_DISP0_DATA16),
107 	IOMUX_PADS(PAD_DISP0_DAT17__IPU1_DISP0_DATA17),
108 };
109 
110 static void enable_rgb(struct display_info_t const *dev)
111 {
112 	SETUP_IOMUX_PADS(rgb_pads);
113 }
114 
115 struct display_info_t const displays[] = {
116 	{
117 		.bus	= -1,
118 		.addr	= 0,
119 		.pixfmt	= IPU_PIX_FMT_RGB666,
120 		.detect	= NULL,
121 		.enable	= enable_rgb,
122 		.mode	= {
123 			.name           = "Amp-WD",
124 			.refresh        = 60,
125 			.xres           = 800,
126 			.yres           = 480,
127 			.pixclock       = 30000,
128 			.left_margin    = 30,
129 			.right_margin   = 30,
130 			.upper_margin   = 5,
131 			.lower_margin   = 5,
132 			.hsync_len      = 64,
133 			.vsync_len      = 20,
134 			.sync           = FB_SYNC_EXT,
135 			.vmode          = FB_VMODE_NONINTERLACED
136 		}
137 	},
138 };
139 
140 size_t display_count = ARRAY_SIZE(displays);
141 
142 void setup_display(void)
143 {
144 	struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
145 	struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
146 	int reg;
147 
148 	enable_ipu_clock();
149 
150 	/* Turn on LDB0,IPU,IPU DI0 clocks */
151 	reg = __raw_readl(&mxc_ccm->CCGR3);
152 	reg |=  (MXC_CCM_CCGR3_LDB_DI0_MASK | 0xffff);
153 	writel(reg, &mxc_ccm->CCGR3);
154 
155 	/* set LDB0, LDB1 clk select to 011/011 */
156 	reg = readl(&mxc_ccm->cs2cdr);
157 	reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK |
158 		MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
159 	reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET) |
160 		(3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
161 	writel(reg, &mxc_ccm->cs2cdr);
162 
163 	reg = readl(&mxc_ccm->cscmr2);
164 	reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
165 	writel(reg, &mxc_ccm->cscmr2);
166 
167 	reg = readl(&mxc_ccm->chsccdr);
168 	reg |= (CHSCCDR_CLK_SEL_LDB_DI0 <<
169 		MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
170 	writel(reg, &mxc_ccm->chsccdr);
171 
172 	reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES |
173 		IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH |
174 		IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW |
175 		IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG |
176 		IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT |
177 		IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG |
178 		IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
179 		IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED |
180 		IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
181 	writel(reg, &iomux->gpr[2]);
182 
183 	reg = readl(&iomux->gpr[3]);
184 	reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK) |
185 		(IOMUXC_GPR3_MUX_SRC_IPU1_DI0 <<
186 		IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
187 	writel(reg, &iomux->gpr[3]);
188 }
189 #endif /* CONFIG_VIDEO_IPUV3 */
190 
191 #ifdef CONFIG_ENV_IS_IN_MMC
192 int board_mmc_get_env_dev(int devno)
193 {
194 	/* i.CoreM6 RQS has USDHC3 for SD and USDHC4 for eMMC */
195 	return (devno == 0) ? 0: (devno - 1);
196 }
197 #endif
198