blob: 5250522d9168478fbee7273d1e7a9f051f714506 [file] [log] [blame]
Stefan Roeseb29ca4a2013-04-17 00:32:43 +00001/*
2 * Copyright (C) 2013 Stefan Roese <sr@denx.de>
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <common.h>
19#include <asm/io.h>
20#include <asm/arch/clock.h>
21#include <asm/arch/imx-regs.h>
22#include <asm/arch/iomux.h>
23#include <asm/arch/mx6q_pins.h>
24#include <asm/arch/crm_regs.h>
25#include <asm/arch/sys_proto.h>
26#include <asm/gpio.h>
27#include <asm/imx-common/iomux-v3.h>
28#include <asm/imx-common/mxc_i2c.h>
29#include <asm/imx-common/boot_mode.h>
30#include <mmc.h>
31#include <fsl_esdhc.h>
32#include <micrel.h>
33#include <miiphy.h>
34#include <netdev.h>
35
36DECLARE_GLOBAL_DATA_PTR;
37
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000038#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
Stefan Roeseb29ca4a2013-04-17 00:32:43 +000039 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
40
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000041#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
Stefan Roeseb29ca4a2013-04-17 00:32:43 +000042 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
43
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000044#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
Stefan Roeseb29ca4a2013-04-17 00:32:43 +000045 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
46
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000047#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
Stefan Roeseb29ca4a2013-04-17 00:32:43 +000048 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
49 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
50
51int dram_init(void)
52{
53 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
54
55 return 0;
56}
57
58iomux_v3_cfg_t const uart1_pads[] = {
59 MX6_PAD_SD3_DAT6__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
60 MX6_PAD_SD3_DAT7__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
61};
62
63iomux_v3_cfg_t const uart2_pads[] = {
64 MX6_PAD_EIM_D26__UART2_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
65 MX6_PAD_EIM_D27__UART2_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
66};
67
68iomux_v3_cfg_t const uart4_pads[] = {
69 MX6_PAD_CSI0_DAT12__UART4_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
70 MX6_PAD_CSI0_DAT13__UART4_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
71};
72
73#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
74
75struct i2c_pads_info i2c_pad_info0 = {
76 .scl = {
77 .i2c_mode = MX6_PAD_CSI0_DAT9__I2C1_SCL | PC,
78 .gpio_mode = MX6_PAD_CSI0_DAT9__GPIO_5_27 | PC,
79 .gp = IMX_GPIO_NR(5, 27)
80 },
81 .sda = {
82 .i2c_mode = MX6_PAD_CSI0_DAT8__I2C1_SDA | PC,
83 .gpio_mode = MX6_PAD_CSI0_DAT8__GPIO_5_26 | PC,
84 .gp = IMX_GPIO_NR(5, 26)
85 }
86};
87
88struct i2c_pads_info i2c_pad_info2 = {
89 .scl = {
90 .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC,
91 .gpio_mode = MX6_PAD_GPIO_3__GPIO_1_3 | PC,
92 .gp = IMX_GPIO_NR(1, 3)
93 },
94 .sda = {
95 .i2c_mode = MX6_PAD_GPIO_16__I2C3_SDA | PC,
96 .gpio_mode = MX6_PAD_GPIO_16__GPIO_7_11 | PC,
97 .gp = IMX_GPIO_NR(7, 11)
98 }
99};
100
101iomux_v3_cfg_t const usdhc3_pads[] = {
102 MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
103 MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
104 MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
105 MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
106 MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
107 MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
108 MX6_PAD_SD3_DAT5__GPIO_7_0 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
109};
110
111iomux_v3_cfg_t const enet_pads1[] = {
112 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
113 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
114 MX6_PAD_RGMII_TXC__ENET_RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
115 MX6_PAD_RGMII_TD0__ENET_RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
116 MX6_PAD_RGMII_TD1__ENET_RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
117 MX6_PAD_RGMII_TD2__ENET_RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
118 MX6_PAD_RGMII_TD3__ENET_RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
119 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
120 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
121 /* pin 35 - 1 (PHY_AD2) on reset */
122 MX6_PAD_RGMII_RXC__GPIO_6_30 | MUX_PAD_CTRL(NO_PAD_CTRL),
123 /* pin 32 - 1 - (MODE0) all */
124 MX6_PAD_RGMII_RD0__GPIO_6_25 | MUX_PAD_CTRL(NO_PAD_CTRL),
125 /* pin 31 - 1 - (MODE1) all */
126 MX6_PAD_RGMII_RD1__GPIO_6_27 | MUX_PAD_CTRL(NO_PAD_CTRL),
127 /* pin 28 - 1 - (MODE2) all */
128 MX6_PAD_RGMII_RD2__GPIO_6_28 | MUX_PAD_CTRL(NO_PAD_CTRL),
129 /* pin 27 - 1 - (MODE3) all */
130 MX6_PAD_RGMII_RD3__GPIO_6_29 | MUX_PAD_CTRL(NO_PAD_CTRL),
131 /* pin 33 - 1 - (CLK125_EN) 125Mhz clockout enabled */
132 MX6_PAD_RGMII_RX_CTL__GPIO_6_24 | MUX_PAD_CTRL(NO_PAD_CTRL),
133 /* pin 42 PHY nRST */
134 MX6_PAD_EIM_D23__GPIO_3_23 | MUX_PAD_CTRL(NO_PAD_CTRL),
135};
136
137iomux_v3_cfg_t const enet_pads2[] = {
138 MX6_PAD_RGMII_RXC__ENET_RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
139 MX6_PAD_RGMII_RD0__ENET_RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
140 MX6_PAD_RGMII_RD1__ENET_RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
141 MX6_PAD_RGMII_RD2__ENET_RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
142 MX6_PAD_RGMII_RD3__ENET_RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
143 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
144};
145
146iomux_v3_cfg_t nfc_pads[] = {
147 MX6_PAD_NANDF_CLE__RAWNAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL),
148 MX6_PAD_NANDF_ALE__RAWNAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL),
149 MX6_PAD_NANDF_WP_B__RAWNAND_RESETN | MUX_PAD_CTRL(NO_PAD_CTRL),
150 MX6_PAD_NANDF_RB0__RAWNAND_READY0 | MUX_PAD_CTRL(NO_PAD_CTRL),
151 MX6_PAD_NANDF_CS0__RAWNAND_CE0N | MUX_PAD_CTRL(NO_PAD_CTRL),
152 MX6_PAD_NANDF_CS1__RAWNAND_CE1N | MUX_PAD_CTRL(NO_PAD_CTRL),
153 MX6_PAD_NANDF_CS2__RAWNAND_CE2N | MUX_PAD_CTRL(NO_PAD_CTRL),
154 MX6_PAD_NANDF_CS3__RAWNAND_CE3N | MUX_PAD_CTRL(NO_PAD_CTRL),
155 MX6_PAD_SD4_CMD__RAWNAND_RDN | MUX_PAD_CTRL(NO_PAD_CTRL),
156 MX6_PAD_SD4_CLK__RAWNAND_WRN | MUX_PAD_CTRL(NO_PAD_CTRL),
157 MX6_PAD_NANDF_D0__RAWNAND_D0 | MUX_PAD_CTRL(NO_PAD_CTRL),
158 MX6_PAD_NANDF_D1__RAWNAND_D1 | MUX_PAD_CTRL(NO_PAD_CTRL),
159 MX6_PAD_NANDF_D2__RAWNAND_D2 | MUX_PAD_CTRL(NO_PAD_CTRL),
160 MX6_PAD_NANDF_D3__RAWNAND_D3 | MUX_PAD_CTRL(NO_PAD_CTRL),
161 MX6_PAD_NANDF_D4__RAWNAND_D4 | MUX_PAD_CTRL(NO_PAD_CTRL),
162 MX6_PAD_NANDF_D5__RAWNAND_D5 | MUX_PAD_CTRL(NO_PAD_CTRL),
163 MX6_PAD_NANDF_D6__RAWNAND_D6 | MUX_PAD_CTRL(NO_PAD_CTRL),
164 MX6_PAD_NANDF_D7__RAWNAND_D7 | MUX_PAD_CTRL(NO_PAD_CTRL),
165 MX6_PAD_SD4_DAT0__RAWNAND_DQS | MUX_PAD_CTRL(NO_PAD_CTRL),
166};
167
168static void setup_gpmi_nand(void)
169{
170 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
171
172 /* config gpmi nand iomux */
173 imx_iomux_v3_setup_multiple_pads(nfc_pads,
174 ARRAY_SIZE(nfc_pads));
175
176 /* config gpmi and bch clock to 100 MHz */
177 clrsetbits_le32(&mxc_ccm->cs2cdr,
178 MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
179 MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
180 MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
181 MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
182 MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
183 MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
184
185 /* enable gpmi and bch clock gating */
186 setbits_le32(&mxc_ccm->CCGR4,
187 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
188 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
189 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
190 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
191 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
192
193 /* enable apbh clock gating */
194 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
195}
196
197static void setup_iomux_enet(void)
198{
199 gpio_direction_output(IMX_GPIO_NR(3, 23), 0);
200 gpio_direction_output(IMX_GPIO_NR(6, 30), 1);
201 gpio_direction_output(IMX_GPIO_NR(6, 25), 1);
202 gpio_direction_output(IMX_GPIO_NR(6, 27), 1);
203 gpio_direction_output(IMX_GPIO_NR(6, 28), 1);
204 gpio_direction_output(IMX_GPIO_NR(6, 29), 1);
205 imx_iomux_v3_setup_multiple_pads(enet_pads1, ARRAY_SIZE(enet_pads1));
206 gpio_direction_output(IMX_GPIO_NR(6, 24), 1);
207
208 /* Need delay 10ms according to KSZ9021 spec */
209 udelay(1000 * 10);
210 gpio_set_value(IMX_GPIO_NR(3, 23), 1);
211
212 imx_iomux_v3_setup_multiple_pads(enet_pads2, ARRAY_SIZE(enet_pads2));
213}
214
215static void setup_iomux_uart(void)
216{
217 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
218 imx_iomux_v3_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
219 imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads));
220}
221
222#ifdef CONFIG_USB_EHCI_MX6
223int board_ehci_hcd_init(int port)
224{
225 return 0;
226}
227
228#endif
229
230#ifdef CONFIG_FSL_ESDHC
231struct fsl_esdhc_cfg usdhc_cfg[1] = {
232 { USDHC3_BASE_ADDR },
233};
234
235int board_mmc_getcd(struct mmc *mmc)
236{
237 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
238
239 if (cfg->esdhc_base == USDHC3_BASE_ADDR) {
240 gpio_direction_input(IMX_GPIO_NR(7, 0));
241 return !gpio_get_value(IMX_GPIO_NR(7, 0));
242 }
243
244 return 0;
245}
246
247int board_mmc_init(bd_t *bis)
248{
249 /*
250 * Only one USDHC controller on titianium
251 */
252 imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
253 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
254
255 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
256}
257#endif
258
259int board_phy_config(struct phy_device *phydev)
260{
261 /* min rx data delay */
262 ksz9021_phy_extended_write(phydev,
263 MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0x0);
264 /* min tx data delay */
265 ksz9021_phy_extended_write(phydev,
266 MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0x0);
267 /* max rx/tx clock delay, min rx/tx control */
268 ksz9021_phy_extended_write(phydev,
269 MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0xf0f0);
270 if (phydev->drv->config)
271 phydev->drv->config(phydev);
272
273 return 0;
274}
275
276int board_eth_init(bd_t *bis)
277{
278 int ret;
279
280 setup_iomux_enet();
281
282 ret = cpu_eth_init(bis);
283 if (ret)
284 printf("FEC MXC: %s:failed\n", __func__);
285
286 return 0;
287}
288
289int board_early_init_f(void)
290{
291 setup_iomux_uart();
292
293 return 0;
294}
295
296int board_init(void)
297{
298 /* address of boot parameters */
299 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
300
301 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info0);
302 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
303
304 setup_gpmi_nand();
305
306 return 0;
307}
308
309int checkboard(void)
310{
311 puts("Board: Titanium\n");
312
313 return 0;
314}
315
316#ifdef CONFIG_CMD_BMODE
317static const struct boot_mode board_boot_modes[] = {
318 /* NAND */
319 { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
320 /* 4 bit bus width */
321 { "mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00) },
322 { "mmc1", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00) },
323 { NULL, 0 },
324};
325#endif
326
327int misc_init_r(void)
328{
329#ifdef CONFIG_CMD_BMODE
330 add_board_boot_modes(board_boot_modes);
331#endif
332
333 return 0;
334}