1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2013 Stefan Roese <sr@denx.de>
4 */
5
6 #include <common.h>
7 #include <init.h>
8 #include <net.h>
9 #include <asm/global_data.h>
10 #include <asm/io.h>
11 #include <asm/arch/clock.h>
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch/iomux.h>
14 #include <asm/arch/mx6-pins.h>
15 #include <asm/arch/crm_regs.h>
16 #include <asm/arch/sys_proto.h>
17 #include <asm/gpio.h>
18 #include <asm/mach-imx/iomux-v3.h>
19 #include <asm/mach-imx/mxc_i2c.h>
20 #include <asm/mach-imx/boot_mode.h>
21 #include <mmc.h>
22 #include <fsl_esdhc_imx.h>
23 #include <micrel.h>
24 #include <miiphy.h>
25 #include <netdev.h>
26 #include <linux/delay.h>
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
31 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
32
33 #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
34 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
35
36 #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
37 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
38
39 #define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
40 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
41 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
42
dram_init(void)43 int dram_init(void)
44 {
45 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
46
47 return 0;
48 }
49
50 iomux_v3_cfg_t const uart1_pads[] = {
51 MX6_PAD_SD3_DAT6__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
52 MX6_PAD_SD3_DAT7__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
53 };
54
55 iomux_v3_cfg_t const uart2_pads[] = {
56 MX6_PAD_EIM_D26__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
57 MX6_PAD_EIM_D27__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
58 };
59
60 iomux_v3_cfg_t const uart4_pads[] = {
61 MX6_PAD_CSI0_DAT12__UART4_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
62 MX6_PAD_CSI0_DAT13__UART4_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
63 };
64
65 #define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
66
67 struct i2c_pads_info i2c_pad_info0 = {
68 .scl = {
69 .i2c_mode = MX6_PAD_CSI0_DAT9__I2C1_SCL | PC,
70 .gpio_mode = MX6_PAD_CSI0_DAT9__GPIO5_IO27 | PC,
71 .gp = IMX_GPIO_NR(5, 27)
72 },
73 .sda = {
74 .i2c_mode = MX6_PAD_CSI0_DAT8__I2C1_SDA | PC,
75 .gpio_mode = MX6_PAD_CSI0_DAT8__GPIO5_IO26 | PC,
76 .gp = IMX_GPIO_NR(5, 26)
77 }
78 };
79
80 struct i2c_pads_info i2c_pad_info2 = {
81 .scl = {
82 .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC,
83 .gpio_mode = MX6_PAD_GPIO_3__GPIO1_IO03 | PC,
84 .gp = IMX_GPIO_NR(1, 3)
85 },
86 .sda = {
87 .i2c_mode = MX6_PAD_GPIO_16__I2C3_SDA | PC,
88 .gpio_mode = MX6_PAD_GPIO_16__GPIO7_IO11 | PC,
89 .gp = IMX_GPIO_NR(7, 11)
90 }
91 };
92
93 iomux_v3_cfg_t const usdhc3_pads[] = {
94 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
97 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
98 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
99 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
100 MX6_PAD_SD3_DAT5__GPIO7_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
101 };
102
103 iomux_v3_cfg_t const enet_pads1[] = {
104 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
105 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
106 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
107 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
108 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
109 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
110 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
111 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
112 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
113 /* pin 35 - 1 (PHY_AD2) on reset */
114 MX6_PAD_RGMII_RXC__GPIO6_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL),
115 /* pin 32 - 1 - (MODE0) all */
116 MX6_PAD_RGMII_RD0__GPIO6_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL),
117 /* pin 31 - 1 - (MODE1) all */
118 MX6_PAD_RGMII_RD1__GPIO6_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL),
119 /* pin 28 - 1 - (MODE2) all */
120 MX6_PAD_RGMII_RD2__GPIO6_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL),
121 /* pin 27 - 1 - (MODE3) all */
122 MX6_PAD_RGMII_RD3__GPIO6_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
123 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
124 MX6_PAD_RGMII_RX_CTL__GPIO6_IO24 | MUX_PAD_CTRL(NO_PAD_CTRL),
125 /* pin 42 PHY nRST */
126 MX6_PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL),
127 };
128
129 iomux_v3_cfg_t const enet_pads2[] = {
130 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
131 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
132 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
133 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
134 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
135 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
136 };
137
138 iomux_v3_cfg_t nfc_pads[] = {
139 MX6_PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL),
140 MX6_PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL),
141 MX6_PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL),
142 MX6_PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL),
143 MX6_PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL),
144 MX6_PAD_NANDF_CS1__NAND_CE1_B | MUX_PAD_CTRL(NO_PAD_CTRL),
145 MX6_PAD_NANDF_CS2__NAND_CE2_B | MUX_PAD_CTRL(NO_PAD_CTRL),
146 MX6_PAD_NANDF_CS3__NAND_CE3_B | MUX_PAD_CTRL(NO_PAD_CTRL),
147 MX6_PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
148 MX6_PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL),
149 MX6_PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL),
150 MX6_PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL),
151 MX6_PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL),
152 MX6_PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL),
153 MX6_PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL),
154 MX6_PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL),
155 MX6_PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL),
156 MX6_PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL),
157 MX6_PAD_SD4_DAT0__NAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL),
158 };
159
setup_gpmi_nand(void)160 static void setup_gpmi_nand(void)
161 {
162 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
163
164 /* config gpmi nand iomux */
165 imx_iomux_v3_setup_multiple_pads(nfc_pads,
166 ARRAY_SIZE(nfc_pads));
167
168 /* config gpmi and bch clock to 100 MHz */
169 clrsetbits_le32(&mxc_ccm->cs2cdr,
170 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
171 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
172 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
173 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
174 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
175 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
176
177 /* enable gpmi and bch clock gating */
178 setbits_le32(&mxc_ccm->CCGR4,
179 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
180 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
181 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
182 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
183 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
184
185 /* enable apbh clock gating */
186 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
187 }
188
setup_iomux_enet(void)189 static void setup_iomux_enet(void)
190 {
191 gpio_direction_output(IMX_GPIO_NR(3, 23), 0);
192 gpio_direction_output(IMX_GPIO_NR(6, 30), 1);
193 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
194 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
195 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
196 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
197 imx_iomux_v3_setup_multiple_pads(enet_pads1, ARRAY_SIZE(enet_pads1));
198 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
199
200 /* Need delay 10ms according to KSZ9021 spec */
201 udelay(1000 * 10);
202 gpio_set_value(IMX_GPIO_NR(3, 23), 1);
203
204 imx_iomux_v3_setup_multiple_pads(enet_pads2, ARRAY_SIZE(enet_pads2));
205 }
206
setup_iomux_uart(void)207 static void setup_iomux_uart(void)
208 {
209 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
210 imx_iomux_v3_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
211 imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads));
212 }
213
214 #ifdef CONFIG_USB_EHCI_MX6
board_ehci_hcd_init(int port)215 int board_ehci_hcd_init(int port)
216 {
217 return 0;
218 }
219
220 #endif
221
222 #ifdef CONFIG_FSL_ESDHC_IMX
223 struct fsl_esdhc_cfg usdhc_cfg[1] = {
224 { USDHC3_BASE_ADDR },
225 };
226
board_mmc_getcd(struct mmc * mmc)227 int board_mmc_getcd(struct mmc *mmc)
228 {
229 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
230
231 if (cfg->esdhc_base == USDHC3_BASE_ADDR) {
232 gpio_direction_input(IMX_GPIO_NR(7, 0));
233 return !gpio_get_value(IMX_GPIO_NR(7, 0));
234 }
235
236 return 0;
237 }
238
board_mmc_init(struct bd_info * bis)239 int board_mmc_init(struct bd_info *bis)
240 {
241 /*
242 * Only one USDHC controller on titianium
243 */
244 imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
245 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
246
247 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
248 }
249 #endif
250
board_phy_config(struct phy_device * phydev)251 int board_phy_config(struct phy_device *phydev)
252 {
253 /* min rx data delay */
254 ksz9021_phy_extended_write(phydev,
255 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x0);
256 /* min tx data delay */
257 ksz9021_phy_extended_write(phydev,
258 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x0);
259 /* max rx/tx clock delay, min rx/tx control */
260 ksz9021_phy_extended_write(phydev,
261 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf0f0);
262 if (phydev->drv->config)
263 phydev->drv->config(phydev);
264
265 return 0;
266 }
267
board_eth_init(struct bd_info * bis)268 int board_eth_init(struct bd_info *bis)
269 {
270 setup_iomux_enet();
271
272 return cpu_eth_init(bis);
273 }
274
board_early_init_f(void)275 int board_early_init_f(void)
276 {
277 setup_iomux_uart();
278
279 return 0;
280 }
281
board_init(void)282 int board_init(void)
283 {
284 /* address of boot parameters */
285 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
286
287 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info0);
288 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
289
290 setup_gpmi_nand();
291
292 return 0;
293 }
294
checkboard(void)295 int checkboard(void)
296 {
297 puts("Board: Titanium\n");
298
299 return 0;
300 }
301
302 #ifdef CONFIG_CMD_BMODE
303 static const struct boot_mode board_boot_modes[] = {
304 /* NAND */
305 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
306 /* 4 bit bus width */
307 { "mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00) },
308 { "mmc1", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00) },
309 { NULL, 0 },
310 };
311 #endif
312
misc_init_r(void)313 int misc_init_r(void)
314 {
315 #ifdef CONFIG_CMD_BMODE
316 add_board_boot_modes(board_boot_modes);
317 #endif
318
319 return 0;
320 }
321