blob: a33d496b709e4186c238ed01dcecd93dd4711dea [file] [log] [blame]
Christian Gmeiner39d09732014-10-02 13:33:46 +02001/*
2 * Copyright (C) 2010-2013 Freescale Semiconductor, Inc.
3 * Copyright (C) 2014, Bachmann electronic GmbH
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
Christian Gmeiner84c5dd12015-01-19 17:26:46 +01009#include <asm/io.h>
Christian Gmeiner39d09732014-10-02 13:33:46 +020010#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
13#include <malloc.h>
14#include <asm/arch/mx6-pins.h>
15#include <asm/imx-common/iomux-v3.h>
Christian Gmeiner3f97af52014-10-22 11:55:04 +020016#include <asm/imx-common/sata.h>
Christian Gmeiner39d09732014-10-02 13:33:46 +020017#include <asm/imx-common/mxc_i2c.h>
18#include <asm/imx-common/boot_mode.h>
19#include <asm/arch/crm_regs.h>
Christian Gmeinerf77dd6d2015-01-19 17:26:45 +010020#include <asm/arch/sys_proto.h>
Christian Gmeiner39d09732014-10-02 13:33:46 +020021#include <mmc.h>
22#include <fsl_esdhc.h>
23#include <netdev.h>
24#include <i2c.h>
25#include <pca953x.h>
26#include <asm/gpio.h>
27#include <phy.h>
28
29DECLARE_GLOBAL_DATA_PTR;
30
31#define OUTPUT_40OHM (PAD_CTL_SPEED_MED|PAD_CTL_DSE_40ohm)
32
33#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
34 OUTPUT_40OHM | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
35
36#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
37 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
38 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
39
40#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | OUTPUT_40OHM | \
41 PAD_CTL_HYS)
42
43#define SPI_PAD_CTRL (PAD_CTL_HYS | OUTPUT_40OHM | \
44 PAD_CTL_SRE_FAST)
45
46#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | OUTPUT_40OHM | \
47 PAD_CTL_HYS | PAD_CTL_ODE | PAD_CTL_SRE_FAST)
48
49int dram_init(void)
50{
Christian Gmeinerf77dd6d2015-01-19 17:26:45 +010051 gd->ram_size = imx_ddr_size();
Christian Gmeiner39d09732014-10-02 13:33:46 +020052
53 return 0;
54}
55
56static iomux_v3_cfg_t const uart1_pads[] = {
57 MX6_PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
58 MX6_PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
59};
60
61static void setup_iomux_uart(void)
62{
63 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
64}
65
66static iomux_v3_cfg_t const enet_pads[] = {
67 MX6_PAD_KEY_ROW1__ENET_COL | MUX_PAD_CTRL(ENET_PAD_CTRL),
68 MX6_PAD_KEY_COL3__ENET_CRS | MUX_PAD_CTRL(ENET_PAD_CTRL),
69 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
70 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
71 MX6_PAD_GPIO_16__ENET_REF_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
72 MX6_PAD_GPIO_18__ENET_RX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
73 MX6_PAD_ENET_RXD0__ENET_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
74 MX6_PAD_ENET_RXD1__ENET_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
75 MX6_PAD_KEY_COL2__ENET_RX_DATA2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
76 MX6_PAD_KEY_COL0__ENET_RX_DATA3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
77 MX6_PAD_ENET_CRS_DV__ENET_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
78 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
79 MX6_PAD_ENET_TXD0__ENET_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
80 MX6_PAD_ENET_TXD1__ENET_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
81 MX6_PAD_KEY_ROW2__ENET_TX_DATA2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
82 MX6_PAD_KEY_ROW0__ENET_TX_DATA3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
83 MX6_PAD_ENET_TX_EN__ENET_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
84};
85
86static void setup_iomux_enet(void)
87{
88 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
89}
90
91static iomux_v3_cfg_t const ecspi1_pads[] = {
92 MX6_PAD_DISP0_DAT3__ECSPI3_SS0 | MUX_PAD_CTRL(SPI_PAD_CTRL),
93 MX6_PAD_DISP0_DAT4__ECSPI3_SS1 | MUX_PAD_CTRL(SPI_PAD_CTRL),
94 MX6_PAD_DISP0_DAT2__ECSPI3_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
95 MX6_PAD_DISP0_DAT1__ECSPI3_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
96 MX6_PAD_DISP0_DAT0__ECSPI3_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
97};
98
99static void setup_iomux_spi(void)
100{
101 imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads));
102}
103
Christian Gmeiner2e3a1f42014-10-22 11:29:51 +0200104int board_spi_cs_gpio(unsigned bus, unsigned cs)
105{
106 return (bus == 2 && cs == 0) ? (IMX_GPIO_NR(1, 3)) : -1;
107}
108
Christian Gmeiner1199ddc2014-10-23 13:46:41 +0200109static iomux_v3_cfg_t const feature_pads[] = {
110 /* SD card detect */
111 MX6_PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(PAD_CTL_PUS_100K_DOWN),
112
113 /* eMMC soldered? */
114 MX6_PAD_GPIO_19__GPIO4_IO05 | MUX_PAD_CTRL(PAD_CTL_PUS_100K_UP),
115};
116
117static void setup_iomux_features(void)
118{
119 imx_iomux_v3_setup_multiple_pads(feature_pads,
120 ARRAY_SIZE(feature_pads));
121}
122
Christian Gmeinercefe06b2015-06-03 11:33:22 +0200123#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
124
125/* I2C3 - IO expander */
126static struct i2c_pads_info i2c_pad_info2 = {
127 .scl = {
128 .i2c_mode = MX6_PAD_EIM_D17__I2C3_SCL | PC,
129 .gpio_mode = MX6_PAD_EIM_D17__GPIO3_IO17 | PC,
130 .gp = IMX_GPIO_NR(3, 17)
131 },
132 .sda = {
133 .i2c_mode = MX6_PAD_EIM_D18__I2C3_SDA | PC,
134 .gpio_mode = MX6_PAD_EIM_D18__GPIO3_IO18 | PC,
135 .gp = IMX_GPIO_NR(3, 18)
136 }
137};
138
139static void setup_iomux_i2c(void)
140{
141 setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
142}
143
Christian Gmeiner84c5dd12015-01-19 17:26:46 +0100144static void ccgr_init(void)
145{
146 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
147
148 writel(0x00C03F3F, &ccm->CCGR0);
Christian Gmeinere88b8352015-01-19 17:26:47 +0100149 writel(0x0030FC33, &ccm->CCGR1);
Christian Gmeiner84c5dd12015-01-19 17:26:46 +0100150 writel(0x0FFFC000, &ccm->CCGR2);
151 writel(0x3FF00000, &ccm->CCGR3);
152 writel(0x00FFF300, &ccm->CCGR4);
153 writel(0x0F0000C3, &ccm->CCGR5);
154 writel(0x000003FF, &ccm->CCGR6);
155}
156
157static void gpr_init(void)
158{
159 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
160
161 /* enable AXI cache for VDOA/VPU/IPU */
162 writel(0xF00000CF, &iomux->gpr[4]);
163 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
164 writel(0x007F007F, &iomux->gpr[6]);
165 writel(0x007F007F, &iomux->gpr[7]);
166}
167
Christian Gmeiner39d09732014-10-02 13:33:46 +0200168int board_early_init_f(void)
169{
Christian Gmeiner84c5dd12015-01-19 17:26:46 +0100170 ccgr_init();
171 gpr_init();
172
Christian Gmeiner39d09732014-10-02 13:33:46 +0200173 setup_iomux_uart();
174 setup_iomux_spi();
Christian Gmeinercefe06b2015-06-03 11:33:22 +0200175 setup_iomux_i2c();
Christian Gmeiner1199ddc2014-10-23 13:46:41 +0200176 setup_iomux_features();
Christian Gmeiner39d09732014-10-02 13:33:46 +0200177
178 return 0;
179}
180
181static iomux_v3_cfg_t const usdhc3_pads[] = {
182 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
183 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
184 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
185 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
186 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
187 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
188 MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
189 MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
190 MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
191 MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
192 MX6_PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL),
193};
194
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200195iomux_v3_cfg_t const usdhc4_pads[] = {
196 MX6_PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
197 MX6_PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
198 MX6_PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
199 MX6_PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
200 MX6_PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
201 MX6_PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
202};
203
Christian Gmeiner39d09732014-10-02 13:33:46 +0200204int board_mmc_getcd(struct mmc *mmc)
205{
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200206 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
207 int ret;
208
Christian Gmeiner56740fa2014-10-23 13:46:43 +0200209 if (cfg->esdhc_base == USDHC3_BASE_ADDR) {
210 gpio_direction_input(IMX_GPIO_NR(4, 5));
211 ret = gpio_get_value(IMX_GPIO_NR(4, 5));
212 } else {
Christian Gmeinercb0b6982014-11-11 12:57:05 +0100213 gpio_direction_input(IMX_GPIO_NR(1, 5));
214 ret = !gpio_get_value(IMX_GPIO_NR(1, 5));
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200215 }
216
217 return ret;
Christian Gmeiner39d09732014-10-02 13:33:46 +0200218}
219
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200220struct fsl_esdhc_cfg usdhc_cfg[2] = {
Christian Gmeiner39d09732014-10-02 13:33:46 +0200221 {USDHC3_BASE_ADDR},
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200222 {USDHC4_BASE_ADDR},
Christian Gmeiner39d09732014-10-02 13:33:46 +0200223};
224
225int board_mmc_init(bd_t *bis)
226{
Fabio Estevame37197a2014-11-21 16:42:56 -0200227 int ret;
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200228 u32 index = 0;
229
Christian Gmeiner39d09732014-10-02 13:33:46 +0200230 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200231 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
232
Christian Gmeiner39d09732014-10-02 13:33:46 +0200233 usdhc_cfg[0].max_bus_width = 8;
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200234 usdhc_cfg[1].max_bus_width = 4;
Christian Gmeiner39d09732014-10-02 13:33:46 +0200235
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200236 for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
237 switch (index) {
238 case 0:
239 imx_iomux_v3_setup_multiple_pads(
240 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
241 break;
242 case 1:
243 imx_iomux_v3_setup_multiple_pads(
244 usdhc4_pads, ARRAY_SIZE(usdhc4_pads));
245 break;
246 default:
247 printf("Warning: you configured more USDHC controllers"
248 "(%d) then supported by the board (%d)\n",
249 index + 1, CONFIG_SYS_FSL_USDHC_NUM);
Fabio Estevame37197a2014-11-21 16:42:56 -0200250 return -EINVAL;
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200251 }
Christian Gmeiner39d09732014-10-02 13:33:46 +0200252
Fabio Estevame37197a2014-11-21 16:42:56 -0200253 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
254 if (ret)
255 return ret;
Christian Gmeiner5a9ca422014-10-23 13:46:42 +0200256 }
257
Fabio Estevame37197a2014-11-21 16:42:56 -0200258 return 0;
Christian Gmeiner39d09732014-10-02 13:33:46 +0200259}
260
Christian Gmeiner39d09732014-10-02 13:33:46 +0200261static iomux_v3_cfg_t const pwm_pad[] = {
262 MX6_PAD_SD1_CMD__PWM4_OUT | MUX_PAD_CTRL(OUTPUT_40OHM),
263};
264
265static void leds_on(void)
266{
267 /* turn on all possible leds connected via GPIO expander */
268 i2c_set_bus_num(2);
269 pca953x_set_dir(CONFIG_SYS_I2C_PCA953X_ADDR, 0xffff, PCA953X_DIR_OUT);
270 pca953x_set_val(CONFIG_SYS_I2C_PCA953X_ADDR, 0xffff, 0x0);
271}
272
273static void backlight_lcd_off(void)
274{
275 unsigned gpio = IMX_GPIO_NR(2, 0);
276 gpio_direction_output(gpio, 0);
277
278 gpio = IMX_GPIO_NR(2, 3);
279 gpio_direction_output(gpio, 0);
280}
281
282int board_eth_init(bd_t *bis)
283{
284 uint32_t base = IMX_FEC_BASE;
285 struct mii_dev *bus = NULL;
286 struct phy_device *phydev = NULL;
287 int ret;
288
289 setup_iomux_enet();
290
291 bus = fec_get_miibus(base, -1);
292 if (!bus)
293 return 0;
294
295 /* scan phy 0 and 5 */
296 phydev = phy_find_by_mask(bus, 0x21, PHY_INTERFACE_MODE_RGMII);
297 if (!phydev) {
298 free(bus);
299 return 0;
300 }
301
302 /* depending on the phy address we can detect our board version */
303 if (phydev->addr == 0)
304 setenv("boardver", "");
305 else
306 setenv("boardver", "mr");
307
308 printf("using phy at %d\n", phydev->addr);
309 ret = fec_probe(bis, -1, base, bus, phydev);
310 if (ret) {
311 printf("FEC MXC: %s:failed\n", __func__);
312 free(phydev);
313 free(bus);
314 }
315 return 0;
316}
317
318int board_init(void)
319{
320 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
321
322 backlight_lcd_off();
323
Christian Gmeiner39d09732014-10-02 13:33:46 +0200324 leds_on();
325
Christian Gmeiner3f97af52014-10-22 11:55:04 +0200326#ifdef CONFIG_CMD_SATA
327 setup_sata();
328#endif
329
Christian Gmeiner39d09732014-10-02 13:33:46 +0200330 return 0;
331}
332
333int checkboard(void)
334{
335 puts("Board: "CONFIG_SYS_BOARD"\n");
336 return 0;
337}
338
339#ifdef CONFIG_CMD_BMODE
340static const struct boot_mode board_boot_modes[] = {
341 /* 4 bit bus width */
342 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
343 {NULL, 0},
344};
345#endif
346
347int misc_init_r(void)
348{
349#ifdef CONFIG_CMD_BMODE
350 add_board_boot_modes(board_boot_modes);
351#endif
352 return 0;
353}