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