blob: a21e7b00e1f0f24d2d7de9b1957cf66724df1841 [file] [log] [blame]
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +03001/*
2 * Board functions for Compulab CM-FX6 board
3 *
4 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
5 *
6 * Author: Nikita Kiryanov <nikita@compulab.co.il>
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
Simon Glassc0d07c22014-10-01 19:57:28 -060012#include <dm.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030013#include <fsl_esdhc.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030014#include <miiphy.h>
15#include <netdev.h>
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +030016#include <errno.h>
Nikita Kiryanov7eeccf42015-08-30 15:36:47 +030017#include <usb.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030018#include <fdt_support.h>
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +030019#include <sata.h>
Nikita Kiryanov7f9ceea2015-01-14 10:42:54 +020020#include <splash.h>
Nikita Kiryanov59d06092014-08-20 15:09:01 +030021#include <asm/arch/crm_regs.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030022#include <asm/arch/sys_proto.h>
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +030023#include <asm/arch/iomux.h>
Nikita Kiryanov89581372015-01-14 10:42:46 +020024#include <asm/arch/mxc_hdmi.h>
Nikita Kiryanov675a1d92014-08-20 15:09:04 +030025#include <asm/imx-common/mxc_i2c.h>
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +030026#include <asm/imx-common/sata.h>
Nikita Kiryanov89581372015-01-14 10:42:46 +020027#include <asm/imx-common/video.h>
Nikita Kiryanov59d06092014-08-20 15:09:01 +030028#include <asm/io.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030029#include <asm/gpio.h>
Masahiro Yamada22c97de2014-10-24 12:41:19 +090030#include <dm/platform_data/serial_mxc.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030031#include "common.h"
Nikita Kiryanov266728a2014-08-20 15:09:05 +030032#include "../common/eeprom.h"
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020033#include "../common/common.h"
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030034
35DECLARE_GLOBAL_DATA_PTR;
36
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020037#ifdef CONFIG_SPLASH_SCREEN
38static struct splash_location cm_fx6_splash_locations[] = {
39 {
40 .name = "sf",
41 .storage = SPLASH_STORAGE_SF,
Nikita Kiryanov74282712015-10-29 11:54:41 +020042 .flags = SPLASH_STORAGE_RAW,
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020043 .offset = 0x100000,
44 },
Nikita Kiryanovb9035ad2015-10-29 11:54:44 +020045 {
46 .name = "mmc_fs",
47 .storage = SPLASH_STORAGE_MMC,
48 .flags = SPLASH_STORAGE_FS,
49 .devpart = "2:1",
50 },
51 {
52 .name = "usb_fs",
53 .storage = SPLASH_STORAGE_USB,
54 .flags = SPLASH_STORAGE_FS,
55 .devpart = "0:1",
56 },
57 {
58 .name = "sata_fs",
59 .storage = SPLASH_STORAGE_SATA,
60 .flags = SPLASH_STORAGE_FS,
61 .devpart = "0:1",
62 },
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020063};
64
65int splash_screen_prepare(void)
66{
Nikita Kiryanov7f9ceea2015-01-14 10:42:54 +020067 return splash_source_load(cm_fx6_splash_locations,
68 ARRAY_SIZE(cm_fx6_splash_locations));
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020069}
70#endif
71
Nikita Kiryanov89581372015-01-14 10:42:46 +020072#ifdef CONFIG_IMX_HDMI
73static void cm_fx6_enable_hdmi(struct display_info_t const *dev)
74{
Nikita Kiryanova0f47eb2015-07-23 17:19:31 +030075 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
76 imx_setup_hdmi();
77 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU1_IPU_DI0_MASK);
Nikita Kiryanov89581372015-01-14 10:42:46 +020078 imx_enable_hdmi_phy();
79}
80
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +030081static struct display_info_t preset_hdmi_1024X768 = {
82 .bus = -1,
83 .addr = 0,
84 .pixfmt = IPU_PIX_FMT_RGB24,
85 .enable = cm_fx6_enable_hdmi,
86 .mode = {
87 .name = "HDMI",
88 .refresh = 60,
89 .xres = 1024,
90 .yres = 768,
91 .pixclock = 40385,
92 .left_margin = 220,
93 .right_margin = 40,
94 .upper_margin = 21,
95 .lower_margin = 7,
96 .hsync_len = 60,
97 .vsync_len = 10,
98 .sync = FB_SYNC_EXT,
99 .vmode = FB_VMODE_NONINTERLACED,
100 }
Nikita Kiryanov89581372015-01-14 10:42:46 +0200101};
Nikita Kiryanov89581372015-01-14 10:42:46 +0200102
103static void cm_fx6_setup_display(void)
104{
Nikita Kiryanov2d618092015-07-23 17:19:28 +0300105 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Nikita Kiryanov89581372015-01-14 10:42:46 +0200106
107 enable_ipu_clock();
Nikita Kiryanov2d618092015-07-23 17:19:28 +0300108 clrbits_le32(&iomuxc_regs->gpr[3], MXC_CCM_CCGR3_IPU1_IPU_DI0_MASK);
Nikita Kiryanov89581372015-01-14 10:42:46 +0200109}
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +0300110
111int board_video_skip(void)
112{
113 int ret;
114 struct display_info_t *preset;
Nikita Kiryanovba182c72015-07-23 17:19:30 +0300115 char const *panel = getenv("displaytype");
116
117 if (!panel) /* Also accept panel for backward compatibility */
118 panel = getenv("panel");
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +0300119
120 if (!panel)
121 return -ENOENT;
122
123 if (!strcmp(panel, "HDMI"))
124 preset = &preset_hdmi_1024X768;
125 else
126 return -EINVAL;
127
128 ret = ipuv3_fb_init(&preset->mode, 0, preset->pixfmt);
129 if (ret) {
130 printf("Can't init display %s: %d\n", preset->mode.name, ret);
131 return ret;
132 }
133
134 preset->enable(preset);
135 printf("Display: %s (%ux%u)\n", preset->mode.name, preset->mode.xres,
136 preset->mode.yres);
137
138 return 0;
139}
Nikita Kiryanov89581372015-01-14 10:42:46 +0200140#else
141static inline void cm_fx6_setup_display(void) {}
142#endif /* CONFIG_VIDEO_IPUV3 */
143
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300144#ifdef CONFIG_DWC_AHSATA
145static int cm_fx6_issd_gpios[] = {
146 /* The order of the GPIOs in the array is important! */
Nikita Kiryanov97d5daf2014-10-29 17:56:21 +0200147 CM_FX6_SATA_LDO_EN,
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300148 CM_FX6_SATA_PHY_SLP,
149 CM_FX6_SATA_NRSTDLY,
150 CM_FX6_SATA_PWREN,
151 CM_FX6_SATA_NSTANDBY1,
152 CM_FX6_SATA_NSTANDBY2,
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300153};
154
155static void cm_fx6_sata_power(int on)
156{
157 int i;
158
159 if (!on) { /* tell the iSSD that the power will be removed */
160 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 1);
161 mdelay(10);
162 }
163
164 for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
165 gpio_direction_output(cm_fx6_issd_gpios[i], on);
166 udelay(100);
167 }
168
169 if (!on) /* for compatibility lower the power loss interrupt */
170 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
171}
172
173static iomux_v3_cfg_t const sata_pads[] = {
174 /* SATA PWR */
175 IOMUX_PADS(PAD_ENET_TX_EN__GPIO1_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
176 IOMUX_PADS(PAD_EIM_A22__GPIO2_IO16 | MUX_PAD_CTRL(NO_PAD_CTRL)),
177 IOMUX_PADS(PAD_EIM_D20__GPIO3_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL)),
178 IOMUX_PADS(PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
179 /* SATA CTRL */
180 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL)),
181 IOMUX_PADS(PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL)),
182 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
183 IOMUX_PADS(PAD_EIM_A23__GPIO6_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
184 IOMUX_PADS(PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL)),
185};
186
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300187static int cm_fx6_setup_issd(void)
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300188{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300189 int ret, i;
190
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300191 SETUP_IOMUX_PADS(sata_pads);
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300192
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300193 for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
194 ret = gpio_request(cm_fx6_issd_gpios[i], "sata");
195 if (ret)
196 return ret;
197 }
198
199 ret = gpio_request(CM_FX6_SATA_PWLOSS_INT, "sata_pwloss_int");
200 if (ret)
201 return ret;
202
203 return 0;
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300204}
205
206#define CM_FX6_SATA_INIT_RETRIES 10
207int sata_initialize(void)
208{
209 int err, i;
210
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300211 /* Make sure this gpio has logical 0 value */
212 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
213 udelay(100);
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300214 cm_fx6_sata_power(1);
215
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300216 for (i = 0; i < CM_FX6_SATA_INIT_RETRIES; i++) {
217 err = setup_sata();
218 if (err) {
219 printf("SATA setup failed: %d\n", err);
220 return err;
221 }
222
223 udelay(100);
224
225 err = __sata_initialize();
226 if (!err)
227 break;
228
229 /* There is no device on the SATA port */
230 if (sata_port_status(0, 0) == 0)
231 break;
232
233 /* There's a device, but link not established. Retry */
234 }
235
236 return err;
237}
Nikita Kiryanov9e086432014-11-21 12:47:25 +0200238
239int sata_stop(void)
240{
241 __sata_stop();
242 cm_fx6_sata_power(0);
243 mdelay(250);
244
245 return 0;
246}
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300247#else
248static int cm_fx6_setup_issd(void) { return 0; }
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300249#endif
250
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300251#ifdef CONFIG_SYS_I2C_MXC
252#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
253 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
254 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
255
256I2C_PADS(i2c0_pads,
257 PAD_EIM_D21__I2C1_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
258 PAD_EIM_D21__GPIO3_IO21 | MUX_PAD_CTRL(I2C_PAD_CTRL),
259 IMX_GPIO_NR(3, 21),
260 PAD_EIM_D28__I2C1_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
261 PAD_EIM_D28__GPIO3_IO28 | MUX_PAD_CTRL(I2C_PAD_CTRL),
262 IMX_GPIO_NR(3, 28));
263
264I2C_PADS(i2c1_pads,
265 PAD_KEY_COL3__I2C2_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
266 PAD_KEY_COL3__GPIO4_IO12 | MUX_PAD_CTRL(I2C_PAD_CTRL),
267 IMX_GPIO_NR(4, 12),
268 PAD_KEY_ROW3__I2C2_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
269 PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(I2C_PAD_CTRL),
270 IMX_GPIO_NR(4, 13));
271
272I2C_PADS(i2c2_pads,
273 PAD_GPIO_3__I2C3_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
274 PAD_GPIO_3__GPIO1_IO03 | MUX_PAD_CTRL(I2C_PAD_CTRL),
275 IMX_GPIO_NR(1, 3),
276 PAD_GPIO_6__I2C3_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
277 PAD_GPIO_6__GPIO1_IO06 | MUX_PAD_CTRL(I2C_PAD_CTRL),
278 IMX_GPIO_NR(1, 6));
279
280
Simon Glass8d914362014-10-01 19:57:24 -0600281static int cm_fx6_setup_one_i2c(int busnum, struct i2c_pads_info *pads)
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300282{
Simon Glass8d914362014-10-01 19:57:24 -0600283 int ret;
284
285 ret = setup_i2c(busnum, CONFIG_SYS_I2C_SPEED, 0x7f, pads);
286 if (ret)
287 printf("Warning: I2C%d setup failed: %d\n", busnum, ret);
288
289 return ret;
290}
291
292static int cm_fx6_setup_i2c(void)
293{
294 int ret = 0, err;
295
296 /* i2c<x>_pads are wierd macro variables; we can't use an array */
297 err = cm_fx6_setup_one_i2c(0, I2C_PADS_INFO(i2c0_pads));
298 if (err)
299 ret = err;
300 err = cm_fx6_setup_one_i2c(1, I2C_PADS_INFO(i2c1_pads));
301 if (err)
302 ret = err;
303 err = cm_fx6_setup_one_i2c(2, I2C_PADS_INFO(i2c2_pads));
304 if (err)
305 ret = err;
306
307 return ret;
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300308}
309#else
Simon Glass8d914362014-10-01 19:57:24 -0600310static int cm_fx6_setup_i2c(void) { return 0; }
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300311#endif
312
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300313#ifdef CONFIG_USB_EHCI_MX6
314#define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
315 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
316 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300317#define MX6_USBNC_BASEADDR 0x2184800
318#define USBNC_USB_H1_PWR_POL (1 << 9)
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300319
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300320static int cm_fx6_setup_usb_host(void)
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300321{
322 int err;
323
324 err = gpio_request(CM_FX6_USB_HUB_RST, "usb hub rst");
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300325 if (err)
326 return err;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300327
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300328 SETUP_IOMUX_PAD(PAD_GPIO_0__USB_H1_PWR | MUX_PAD_CTRL(NO_PAD_CTRL));
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300329 SETUP_IOMUX_PAD(PAD_SD3_RST__GPIO7_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL));
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300330
331 return 0;
332}
333
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300334static int cm_fx6_setup_usb_otg(void)
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300335{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300336 int err;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300337 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
338
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300339 err = gpio_request(SB_FX6_USB_OTG_PWR, "usb-pwr");
340 if (err) {
341 printf("USB OTG pwr gpio request failed: %d\n", err);
342 return err;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300343 }
344
345 SETUP_IOMUX_PAD(PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL));
346 SETUP_IOMUX_PAD(PAD_ENET_RX_ER__USB_OTG_ID |
347 MUX_PAD_CTRL(WEAK_PULLDOWN));
348 clrbits_le32(&iomux->gpr[1], IOMUXC_GPR1_OTG_ID_MASK);
349 /* disable ext. charger detect, or it'll affect signal quality at dp. */
350 return gpio_direction_output(SB_FX6_USB_OTG_PWR, 0);
351}
352
Nikita Kiryanov7eeccf42015-08-30 15:36:47 +0300353int board_usb_phy_mode(int port)
354{
355 return USB_INIT_HOST;
356}
357
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300358int board_ehci_hcd_init(int port)
359{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300360 int ret;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300361 u32 *usbnc_usb_uh1_ctrl = (u32 *)(MX6_USBNC_BASEADDR + 4);
362
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300363 /* Only 1 host controller in use. port 0 is OTG & needs no attention */
364 if (port != 1)
365 return 0;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300366
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300367 /* Set PWR polarity to match power switch's enable polarity */
368 setbits_le32(usbnc_usb_uh1_ctrl, USBNC_USB_H1_PWR_POL);
369 ret = gpio_direction_output(CM_FX6_USB_HUB_RST, 0);
370 if (ret)
371 return ret;
372
373 udelay(10);
374 ret = gpio_direction_output(CM_FX6_USB_HUB_RST, 1);
375 if (ret)
376 return ret;
377
378 mdelay(1);
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300379
380 return 0;
381}
382
383int board_ehci_power(int port, int on)
384{
385 if (port == 0)
386 return gpio_direction_output(SB_FX6_USB_OTG_PWR, on);
387
388 return 0;
389}
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300390#else
391static int cm_fx6_setup_usb_otg(void) { return 0; }
392static int cm_fx6_setup_usb_host(void) { return 0; }
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300393#endif
394
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300395#ifdef CONFIG_FEC_MXC
396#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
397 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
398
399static int mx6_rgmii_rework(struct phy_device *phydev)
400{
401 unsigned short val;
402
403 /* Ar8031 phy SmartEEE feature cause link status generates glitch,
404 * which cause ethernet link down/up issue, so disable SmartEEE
405 */
406 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
407 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
408 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
409 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
410 val &= ~(0x1 << 8);
411 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
412
413 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
414 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
415 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
416 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
417
418 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
419 val &= 0xffe3;
420 val |= 0x18;
421 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
422
423 /* introduce tx clock delay */
424 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
425 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
426 val |= 0x0100;
427 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
428
429 return 0;
430}
431
432int board_phy_config(struct phy_device *phydev)
433{
434 mx6_rgmii_rework(phydev);
435
436 if (phydev->drv->config)
437 return phydev->drv->config(phydev);
438
439 return 0;
440}
441
442static iomux_v3_cfg_t const enet_pads[] = {
443 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
444 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
445 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
446 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
447 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
448 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
449 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
450 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
451 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
452 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
453 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
454 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
455 IOMUX_PADS(PAD_GPIO_0__CCM_CLKO1 | MUX_PAD_CTRL(NO_PAD_CTRL)),
456 IOMUX_PADS(PAD_GPIO_3__CCM_CLKO2 | MUX_PAD_CTRL(NO_PAD_CTRL)),
457 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(0x84)),
458 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
459 MUX_PAD_CTRL(ENET_PAD_CTRL)),
460 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
461 MUX_PAD_CTRL(ENET_PAD_CTRL)),
462 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
463 MUX_PAD_CTRL(ENET_PAD_CTRL)),
464};
465
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200466static int handle_mac_address(char *env_var, uint eeprom_bus)
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300467{
468 unsigned char enetaddr[6];
469 int rc;
470
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200471 rc = eth_getenv_enetaddr(env_var, enetaddr);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300472 if (rc)
473 return 0;
474
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200475 rc = cl_eeprom_read_mac_addr(enetaddr, eeprom_bus);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300476 if (rc)
477 return rc;
478
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500479 if (!is_valid_ethaddr(enetaddr))
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300480 return -1;
481
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200482 return eth_setenv_enetaddr(env_var, enetaddr);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300483}
484
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200485#define SB_FX6_I2C_EEPROM_BUS 0
486#define NO_MAC_ADDR "No MAC address found for %s\n"
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300487int board_eth_init(bd_t *bis)
488{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300489 int err;
490
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200491 if (handle_mac_address("ethaddr", CONFIG_SYS_I2C_EEPROM_BUS))
492 printf(NO_MAC_ADDR, "primary NIC");
493
494 if (handle_mac_address("eth1addr", SB_FX6_I2C_EEPROM_BUS))
495 printf(NO_MAC_ADDR, "secondary NIC");
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300496
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300497 SETUP_IOMUX_PADS(enet_pads);
498 /* phy reset */
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300499 err = gpio_request(CM_FX6_ENET_NRST, "enet_nrst");
500 if (err)
501 printf("Etnernet NRST gpio request failed: %d\n", err);
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300502 gpio_direction_output(CM_FX6_ENET_NRST, 0);
503 udelay(500);
504 gpio_set_value(CM_FX6_ENET_NRST, 1);
505 enable_enet_clk(1);
506 return cpu_eth_init(bis);
507}
508#endif
509
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300510#ifdef CONFIG_NAND_MXS
511static iomux_v3_cfg_t const nand_pads[] = {
512 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
513 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
514 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
515 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
516 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
517 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
518 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
519 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
520 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
521 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
522 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
523 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
524 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
525 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
526};
527
528static void cm_fx6_setup_gpmi_nand(void)
529{
530 SETUP_IOMUX_PADS(nand_pads);
531 /* Enable clock roots */
532 enable_usdhc_clk(1, 3);
533 enable_usdhc_clk(1, 4);
534
535 setup_gpmi_io_clk(MXC_CCM_CS2CDR_ENFC_CLK_PODF(0xf) |
536 MXC_CCM_CS2CDR_ENFC_CLK_PRED(1) |
537 MXC_CCM_CS2CDR_ENFC_CLK_SEL(0));
538}
539#else
540static void cm_fx6_setup_gpmi_nand(void) {}
541#endif
542
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300543#ifdef CONFIG_FSL_ESDHC
544static struct fsl_esdhc_cfg usdhc_cfg[3] = {
545 {USDHC1_BASE_ADDR},
546 {USDHC2_BASE_ADDR},
547 {USDHC3_BASE_ADDR},
548};
549
550static enum mxc_clock usdhc_clk[3] = {
551 MXC_ESDHC_CLK,
552 MXC_ESDHC2_CLK,
553 MXC_ESDHC3_CLK,
554};
555
556int board_mmc_init(bd_t *bis)
557{
558 int i;
559
560 cm_fx6_set_usdhc_iomux();
561 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
562 usdhc_cfg[i].sdhc_clk = mxc_get_clock(usdhc_clk[i]);
563 usdhc_cfg[i].max_bus_width = 4;
564 fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
565 enable_usdhc_clk(1, i);
566 }
567
568 return 0;
569}
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300570#endif
571
572#ifdef CONFIG_MXC_SPI
573int cm_fx6_setup_ecspi(void)
574{
575 cm_fx6_set_ecspi_iomux();
576 return gpio_request(CM_FX6_ECSPI_BUS0_CS0, "ecspi_bus0_cs0");
577}
578#else
579int cm_fx6_setup_ecspi(void) { return 0; }
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300580#endif
581
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300582#ifdef CONFIG_OF_BOARD_SETUP
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300583#define USDHC3_PATH "/soc/aips-bus@02100000/usdhc@02198000/"
Simon Glass2aec3cc2014-10-23 18:58:47 -0600584int ft_board_setup(void *blob, bd_t *bd)
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300585{
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300586 u32 baseboard_rev;
587 int nodeoffset;
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300588 uint8_t enetaddr[6];
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300589 char baseboard_name[16];
590 int err;
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300591
592 /* MAC addr */
593 if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
Nikita Kiryanov8d25a512015-01-14 10:42:42 +0200594 fdt_find_and_setprop(blob,
595 "/soc/aips-bus@02100000/ethernet@02188000",
596 "local-mac-address", enetaddr, 6, 1);
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300597 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600598
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200599 if (eth_getenv_enetaddr("eth1addr", enetaddr)) {
600 fdt_find_and_setprop(blob, "/eth@pcie", "local-mac-address",
601 enetaddr, 6, 1);
602 }
603
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300604 baseboard_rev = cl_eeprom_get_board_rev(0);
605 err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
606 if (err || baseboard_rev == 0)
607 return 0; /* Assume not an early revision SB-FX6m baseboard */
608
609 if (!strncmp("SB-FX6m", baseboard_name, 7) && baseboard_rev <= 120) {
610 fdt_shrink_to_minimum(blob); /* Make room for new properties */
611 nodeoffset = fdt_path_offset(blob, USDHC3_PATH);
612 fdt_delprop(blob, nodeoffset, "cd-gpios");
613 fdt_find_and_setprop(blob, USDHC3_PATH, "non-removable",
614 NULL, 0, 1);
615 fdt_find_and_setprop(blob, USDHC3_PATH, "keep-power-in-suspend",
616 NULL, 0, 1);
617 }
618
Simon Glass2aec3cc2014-10-23 18:58:47 -0600619 return 0;
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300620}
621#endif
622
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300623int board_init(void)
624{
Simon Glass8d914362014-10-01 19:57:24 -0600625 int ret;
626
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300627 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300628 cm_fx6_setup_gpmi_nand();
Simon Glass8d914362014-10-01 19:57:24 -0600629
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300630 ret = cm_fx6_setup_ecspi();
631 if (ret)
632 printf("Warning: ECSPI setup failed: %d\n", ret);
633
634 ret = cm_fx6_setup_usb_otg();
635 if (ret)
636 printf("Warning: USB OTG setup failed: %d\n", ret);
637
638 ret = cm_fx6_setup_usb_host();
639 if (ret)
640 printf("Warning: USB host setup failed: %d\n", ret);
641
642 /*
643 * cm-fx6 may have iSSD not assembled and in this case it has
644 * bypasses for a (m)SATA socket on the baseboard. The socketed
645 * device is not controlled by those GPIOs. So just print a warning
646 * if the setup fails.
647 */
648 ret = cm_fx6_setup_issd();
649 if (ret)
650 printf("Warning: iSSD setup failed: %d\n", ret);
651
Simon Glass8d914362014-10-01 19:57:24 -0600652 /* Warn on failure but do not abort boot */
653 ret = cm_fx6_setup_i2c();
654 if (ret)
655 printf("Warning: I2C setup failed: %d\n", ret);
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300656
Nikita Kiryanov89581372015-01-14 10:42:46 +0200657 cm_fx6_setup_display();
658
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300659 return 0;
660}
661
662int checkboard(void)
663{
664 puts("Board: CM-FX6\n");
665 return 0;
666}
667
Nikita Kiryanovc69901b2015-08-30 15:36:48 +0300668int misc_init_r(void)
669{
670 cl_print_pcb_info();
671
672 return 0;
673}
674
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300675void dram_init_banksize(void)
676{
677 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
678 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
679
680 switch (gd->ram_size) {
681 case 0x10000000: /* DDR_16BIT_256MB */
682 gd->bd->bi_dram[0].size = 0x10000000;
683 gd->bd->bi_dram[1].size = 0;
684 break;
685 case 0x20000000: /* DDR_32BIT_512MB */
686 gd->bd->bi_dram[0].size = 0x20000000;
687 gd->bd->bi_dram[1].size = 0;
688 break;
689 case 0x40000000:
690 if (is_cpu_type(MXC_CPU_MX6SOLO)) { /* DDR_32BIT_1GB */
691 gd->bd->bi_dram[0].size = 0x20000000;
692 gd->bd->bi_dram[1].size = 0x20000000;
693 } else { /* DDR_64BIT_1GB */
694 gd->bd->bi_dram[0].size = 0x40000000;
695 gd->bd->bi_dram[1].size = 0;
696 }
697 break;
698 case 0x80000000: /* DDR_64BIT_2GB */
699 gd->bd->bi_dram[0].size = 0x40000000;
700 gd->bd->bi_dram[1].size = 0x40000000;
701 break;
702 case 0xEFF00000: /* DDR_64BIT_4GB */
703 gd->bd->bi_dram[0].size = 0x70000000;
704 gd->bd->bi_dram[1].size = 0x7FF00000;
705 break;
706 }
707}
708
709int dram_init(void)
710{
711 gd->ram_size = imx_ddr_size();
712 switch (gd->ram_size) {
713 case 0x10000000:
714 case 0x20000000:
715 case 0x40000000:
716 case 0x80000000:
717 break;
718 case 0xF0000000:
719 gd->ram_size -= 0x100000;
720 break;
721 default:
722 printf("ERROR: Unsupported DRAM size 0x%lx\n", gd->ram_size);
723 return -1;
724 }
725
726 return 0;
727}
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300728
729u32 get_board_rev(void)
730{
Nikita Kiryanov7fa68352015-09-06 11:48:35 +0300731 return cl_eeprom_get_board_rev(CONFIG_SYS_I2C_EEPROM_BUS);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300732}
733
Simon Glassc0d07c22014-10-01 19:57:28 -0600734static struct mxc_serial_platdata cm_fx6_mxc_serial_plat = {
735 .reg = (struct mxc_uart *)UART4_BASE,
736};
737
738U_BOOT_DEVICE(cm_fx6_serial) = {
739 .name = "serial_mxc",
740 .platdata = &cm_fx6_mxc_serial_plat,
741};