blob: 3e185ad82a29e31ebb895f91accecf8ccfe43c08 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +03002/*
3 * Board functions for Compulab CM-FX6 board
4 *
5 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
6 *
7 * Author: Nikita Kiryanov <nikita@compulab.co.il>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +03008 */
9
10#include <common.h>
Simon Glassbf8950e2017-07-29 11:35:25 -060011#include <ahci.h>
Simon Glassc0d07c22014-10-01 19:57:28 -060012#include <dm.h>
Simon Glassbf8950e2017-07-29 11:35:25 -060013#include <dwc_ahsata.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060014#include <env.h>
Yangbo Lu73340382019-06-21 11:42:28 +080015#include <fsl_esdhc_imx.h>
Simon Glassa7b51302019-11-14 12:57:46 -070016#include <init.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030017#include <miiphy.h>
Christopher Spinrathd706b572016-07-12 23:37:36 +020018#include <mtd_node.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030019#include <netdev.h>
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +030020#include <errno.h>
Nikita Kiryanov7eeccf42015-08-30 15:36:47 +030021#include <usb.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030022#include <fdt_support.h>
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +030023#include <sata.h>
Nikita Kiryanov7f9ceea2015-01-14 10:42:54 +020024#include <splash.h>
Nikita Kiryanov59d06092014-08-20 15:09:01 +030025#include <asm/arch/crm_regs.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030026#include <asm/arch/sys_proto.h>
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +030027#include <asm/arch/iomux.h>
Nikita Kiryanov89581372015-01-14 10:42:46 +020028#include <asm/arch/mxc_hdmi.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020029#include <asm/mach-imx/mxc_i2c.h>
30#include <asm/mach-imx/sata.h>
31#include <asm/mach-imx/video.h>
Nikita Kiryanov59d06092014-08-20 15:09:01 +030032#include <asm/io.h>
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +030033#include <asm/gpio.h>
Masahiro Yamada22c97de2014-10-24 12:41:19 +090034#include <dm/platform_data/serial_mxc.h>
Simon Glassbf8950e2017-07-29 11:35:25 -060035#include <dm/device-internal.h>
Christopher Spinrathd706b572016-07-12 23:37:36 +020036#include <jffs2/load_kernel.h>
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030037#include "common.h"
Nikita Kiryanov266728a2014-08-20 15:09:05 +030038#include "../common/eeprom.h"
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020039#include "../common/common.h"
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +030040
41DECLARE_GLOBAL_DATA_PTR;
42
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020043#ifdef CONFIG_SPLASH_SCREEN
44static struct splash_location cm_fx6_splash_locations[] = {
45 {
46 .name = "sf",
47 .storage = SPLASH_STORAGE_SF,
Nikita Kiryanov74282712015-10-29 11:54:41 +020048 .flags = SPLASH_STORAGE_RAW,
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020049 .offset = 0x100000,
50 },
Nikita Kiryanovb9035ad2015-10-29 11:54:44 +020051 {
52 .name = "mmc_fs",
53 .storage = SPLASH_STORAGE_MMC,
54 .flags = SPLASH_STORAGE_FS,
55 .devpart = "2:1",
56 },
57 {
58 .name = "usb_fs",
59 .storage = SPLASH_STORAGE_USB,
60 .flags = SPLASH_STORAGE_FS,
61 .devpart = "0:1",
62 },
63 {
64 .name = "sata_fs",
65 .storage = SPLASH_STORAGE_SATA,
66 .flags = SPLASH_STORAGE_FS,
67 .devpart = "0:1",
68 },
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020069};
70
71int splash_screen_prepare(void)
72{
Nikita Kiryanov7f9ceea2015-01-14 10:42:54 +020073 return splash_source_load(cm_fx6_splash_locations,
74 ARRAY_SIZE(cm_fx6_splash_locations));
Nikita Kiryanov12ffcf42015-01-14 10:42:53 +020075}
76#endif
77
Nikita Kiryanov89581372015-01-14 10:42:46 +020078#ifdef CONFIG_IMX_HDMI
79static void cm_fx6_enable_hdmi(struct display_info_t const *dev)
80{
Nikita Kiryanova0f47eb2015-07-23 17:19:31 +030081 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
82 imx_setup_hdmi();
83 setbits_le32(&mxc_ccm->CCGR3, MXC_CCM_CCGR3_IPU1_IPU_DI0_MASK);
Nikita Kiryanov89581372015-01-14 10:42:46 +020084 imx_enable_hdmi_phy();
85}
86
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +030087static struct display_info_t preset_hdmi_1024X768 = {
88 .bus = -1,
89 .addr = 0,
90 .pixfmt = IPU_PIX_FMT_RGB24,
91 .enable = cm_fx6_enable_hdmi,
92 .mode = {
93 .name = "HDMI",
94 .refresh = 60,
95 .xres = 1024,
96 .yres = 768,
97 .pixclock = 40385,
98 .left_margin = 220,
99 .right_margin = 40,
100 .upper_margin = 21,
101 .lower_margin = 7,
102 .hsync_len = 60,
103 .vsync_len = 10,
104 .sync = FB_SYNC_EXT,
105 .vmode = FB_VMODE_NONINTERLACED,
106 }
Nikita Kiryanov89581372015-01-14 10:42:46 +0200107};
Nikita Kiryanov89581372015-01-14 10:42:46 +0200108
109static void cm_fx6_setup_display(void)
110{
Nikita Kiryanov2d618092015-07-23 17:19:28 +0300111 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Nikita Kiryanov89581372015-01-14 10:42:46 +0200112
113 enable_ipu_clock();
Nikita Kiryanov2d618092015-07-23 17:19:28 +0300114 clrbits_le32(&iomuxc_regs->gpr[3], MXC_CCM_CCGR3_IPU1_IPU_DI0_MASK);
Nikita Kiryanov89581372015-01-14 10:42:46 +0200115}
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +0300116
117int board_video_skip(void)
118{
119 int ret;
120 struct display_info_t *preset;
Simon Glass64b723f2017-08-03 12:22:12 -0600121 char const *panel = env_get("displaytype");
Nikita Kiryanovba182c72015-07-23 17:19:30 +0300122
123 if (!panel) /* Also accept panel for backward compatibility */
Simon Glass64b723f2017-08-03 12:22:12 -0600124 panel = env_get("panel");
Nikita Kiryanov9b1bc392015-07-23 17:19:29 +0300125
126 if (!panel)
127 return -ENOENT;
128
129 if (!strcmp(panel, "HDMI"))
130 preset = &preset_hdmi_1024X768;
131 else
132 return -EINVAL;
133
134 ret = ipuv3_fb_init(&preset->mode, 0, preset->pixfmt);
135 if (ret) {
136 printf("Can't init display %s: %d\n", preset->mode.name, ret);
137 return ret;
138 }
139
140 preset->enable(preset);
141 printf("Display: %s (%ux%u)\n", preset->mode.name, preset->mode.xres,
142 preset->mode.yres);
143
144 return 0;
145}
Nikita Kiryanov89581372015-01-14 10:42:46 +0200146#else
147static inline void cm_fx6_setup_display(void) {}
148#endif /* CONFIG_VIDEO_IPUV3 */
149
Suniel Mahesh16102852019-11-20 15:25:00 +0530150int ipu_displays_init(void)
151{
152 return board_video_skip();
153}
154
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300155#ifdef CONFIG_DWC_AHSATA
156static int cm_fx6_issd_gpios[] = {
157 /* The order of the GPIOs in the array is important! */
Nikita Kiryanov97d5daf2014-10-29 17:56:21 +0200158 CM_FX6_SATA_LDO_EN,
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300159 CM_FX6_SATA_PHY_SLP,
160 CM_FX6_SATA_NRSTDLY,
161 CM_FX6_SATA_PWREN,
162 CM_FX6_SATA_NSTANDBY1,
163 CM_FX6_SATA_NSTANDBY2,
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300164};
165
166static void cm_fx6_sata_power(int on)
167{
168 int i;
169
170 if (!on) { /* tell the iSSD that the power will be removed */
171 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 1);
172 mdelay(10);
173 }
174
175 for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
176 gpio_direction_output(cm_fx6_issd_gpios[i], on);
177 udelay(100);
178 }
179
180 if (!on) /* for compatibility lower the power loss interrupt */
181 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
182}
183
184static iomux_v3_cfg_t const sata_pads[] = {
185 /* SATA PWR */
186 IOMUX_PADS(PAD_ENET_TX_EN__GPIO1_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
187 IOMUX_PADS(PAD_EIM_A22__GPIO2_IO16 | MUX_PAD_CTRL(NO_PAD_CTRL)),
188 IOMUX_PADS(PAD_EIM_D20__GPIO3_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL)),
189 IOMUX_PADS(PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
190 /* SATA CTRL */
191 IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL)),
192 IOMUX_PADS(PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL)),
193 IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
194 IOMUX_PADS(PAD_EIM_A23__GPIO6_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
195 IOMUX_PADS(PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL)),
196};
197
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300198static int cm_fx6_setup_issd(void)
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300199{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300200 int ret, i;
201
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300202 SETUP_IOMUX_PADS(sata_pads);
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300203
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300204 for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
205 ret = gpio_request(cm_fx6_issd_gpios[i], "sata");
206 if (ret)
207 return ret;
208 }
209
210 ret = gpio_request(CM_FX6_SATA_PWLOSS_INT, "sata_pwloss_int");
211 if (ret)
212 return ret;
213
214 return 0;
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300215}
216
217#define CM_FX6_SATA_INIT_RETRIES 10
Simon Glassbf8950e2017-07-29 11:35:25 -0600218
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300219#else
220static int cm_fx6_setup_issd(void) { return 0; }
Nikita Kiryanov2fe0b7b2014-08-20 15:09:06 +0300221#endif
222
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300223#ifdef CONFIG_SYS_I2C_MXC
224#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
225 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
226 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
227
228I2C_PADS(i2c0_pads,
229 PAD_EIM_D21__I2C1_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
230 PAD_EIM_D21__GPIO3_IO21 | MUX_PAD_CTRL(I2C_PAD_CTRL),
231 IMX_GPIO_NR(3, 21),
232 PAD_EIM_D28__I2C1_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
233 PAD_EIM_D28__GPIO3_IO28 | MUX_PAD_CTRL(I2C_PAD_CTRL),
234 IMX_GPIO_NR(3, 28));
235
236I2C_PADS(i2c1_pads,
237 PAD_KEY_COL3__I2C2_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
238 PAD_KEY_COL3__GPIO4_IO12 | MUX_PAD_CTRL(I2C_PAD_CTRL),
239 IMX_GPIO_NR(4, 12),
240 PAD_KEY_ROW3__I2C2_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
241 PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(I2C_PAD_CTRL),
242 IMX_GPIO_NR(4, 13));
243
244I2C_PADS(i2c2_pads,
245 PAD_GPIO_3__I2C3_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
246 PAD_GPIO_3__GPIO1_IO03 | MUX_PAD_CTRL(I2C_PAD_CTRL),
247 IMX_GPIO_NR(1, 3),
248 PAD_GPIO_6__I2C3_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
249 PAD_GPIO_6__GPIO1_IO06 | MUX_PAD_CTRL(I2C_PAD_CTRL),
250 IMX_GPIO_NR(1, 6));
251
252
Simon Glass8d914362014-10-01 19:57:24 -0600253static int cm_fx6_setup_one_i2c(int busnum, struct i2c_pads_info *pads)
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300254{
Simon Glass8d914362014-10-01 19:57:24 -0600255 int ret;
256
257 ret = setup_i2c(busnum, CONFIG_SYS_I2C_SPEED, 0x7f, pads);
258 if (ret)
259 printf("Warning: I2C%d setup failed: %d\n", busnum, ret);
260
261 return ret;
262}
263
264static int cm_fx6_setup_i2c(void)
265{
266 int ret = 0, err;
267
268 /* i2c<x>_pads are wierd macro variables; we can't use an array */
269 err = cm_fx6_setup_one_i2c(0, I2C_PADS_INFO(i2c0_pads));
270 if (err)
271 ret = err;
272 err = cm_fx6_setup_one_i2c(1, I2C_PADS_INFO(i2c1_pads));
273 if (err)
274 ret = err;
275 err = cm_fx6_setup_one_i2c(2, I2C_PADS_INFO(i2c2_pads));
276 if (err)
277 ret = err;
278
279 return ret;
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300280}
281#else
Simon Glass8d914362014-10-01 19:57:24 -0600282static int cm_fx6_setup_i2c(void) { return 0; }
Nikita Kiryanov675a1d92014-08-20 15:09:04 +0300283#endif
284
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300285#ifdef CONFIG_USB_EHCI_MX6
286#define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
287 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
288 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300289#define MX6_USBNC_BASEADDR 0x2184800
290#define USBNC_USB_H1_PWR_POL (1 << 9)
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300291
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300292static int cm_fx6_setup_usb_host(void)
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300293{
294 int err;
295
296 err = gpio_request(CM_FX6_USB_HUB_RST, "usb hub rst");
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300297 if (err)
298 return err;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300299
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300300 SETUP_IOMUX_PAD(PAD_GPIO_0__USB_H1_PWR | MUX_PAD_CTRL(NO_PAD_CTRL));
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300301 SETUP_IOMUX_PAD(PAD_SD3_RST__GPIO7_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL));
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300302
303 return 0;
304}
305
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300306static int cm_fx6_setup_usb_otg(void)
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300307{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300308 int err;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300309 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
310
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300311 err = gpio_request(SB_FX6_USB_OTG_PWR, "usb-pwr");
312 if (err) {
313 printf("USB OTG pwr gpio request failed: %d\n", err);
314 return err;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300315 }
316
317 SETUP_IOMUX_PAD(PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL));
318 SETUP_IOMUX_PAD(PAD_ENET_RX_ER__USB_OTG_ID |
319 MUX_PAD_CTRL(WEAK_PULLDOWN));
320 clrbits_le32(&iomux->gpr[1], IOMUXC_GPR1_OTG_ID_MASK);
321 /* disable ext. charger detect, or it'll affect signal quality at dp. */
322 return gpio_direction_output(SB_FX6_USB_OTG_PWR, 0);
323}
324
Nikita Kiryanov7eeccf42015-08-30 15:36:47 +0300325int board_usb_phy_mode(int port)
326{
327 return USB_INIT_HOST;
328}
329
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300330int board_ehci_hcd_init(int port)
331{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300332 int ret;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300333 u32 *usbnc_usb_uh1_ctrl = (u32 *)(MX6_USBNC_BASEADDR + 4);
334
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300335 /* Only 1 host controller in use. port 0 is OTG & needs no attention */
336 if (port != 1)
337 return 0;
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300338
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300339 /* Set PWR polarity to match power switch's enable polarity */
340 setbits_le32(usbnc_usb_uh1_ctrl, USBNC_USB_H1_PWR_POL);
341 ret = gpio_direction_output(CM_FX6_USB_HUB_RST, 0);
342 if (ret)
343 return ret;
344
345 udelay(10);
346 ret = gpio_direction_output(CM_FX6_USB_HUB_RST, 1);
347 if (ret)
348 return ret;
349
350 mdelay(1);
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300351
352 return 0;
353}
354
355int board_ehci_power(int port, int on)
356{
357 if (port == 0)
358 return gpio_direction_output(SB_FX6_USB_OTG_PWR, on);
359
360 return 0;
361}
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300362#else
363static int cm_fx6_setup_usb_otg(void) { return 0; }
364static int cm_fx6_setup_usb_host(void) { return 0; }
Nikita Kiryanova2f2f3c2014-08-20 15:09:03 +0300365#endif
366
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300367#ifdef CONFIG_FEC_MXC
368#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
369 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
370
371static int mx6_rgmii_rework(struct phy_device *phydev)
372{
373 unsigned short val;
374
375 /* Ar8031 phy SmartEEE feature cause link status generates glitch,
376 * which cause ethernet link down/up issue, so disable SmartEEE
377 */
378 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
379 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
380 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
381 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
382 val &= ~(0x1 << 8);
383 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
384
385 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
386 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
387 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
388 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
389
390 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
391 val &= 0xffe3;
392 val |= 0x18;
393 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
394
395 /* introduce tx clock delay */
396 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
397 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
398 val |= 0x0100;
399 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
400
401 return 0;
402}
403
404int board_phy_config(struct phy_device *phydev)
405{
406 mx6_rgmii_rework(phydev);
407
408 if (phydev->drv->config)
409 return phydev->drv->config(phydev);
410
411 return 0;
412}
413
414static iomux_v3_cfg_t const enet_pads[] = {
415 IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
416 IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
417 IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
418 IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
419 IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
420 IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
421 IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
422 IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
423 IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
424 IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
425 IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
426 IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
427 IOMUX_PADS(PAD_GPIO_0__CCM_CLKO1 | MUX_PAD_CTRL(NO_PAD_CTRL)),
428 IOMUX_PADS(PAD_GPIO_3__CCM_CLKO2 | MUX_PAD_CTRL(NO_PAD_CTRL)),
429 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(0x84)),
430 IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
431 MUX_PAD_CTRL(ENET_PAD_CTRL)),
432 IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
433 MUX_PAD_CTRL(ENET_PAD_CTRL)),
434 IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
435 MUX_PAD_CTRL(ENET_PAD_CTRL)),
436};
437
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200438static int handle_mac_address(char *env_var, uint eeprom_bus)
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300439{
440 unsigned char enetaddr[6];
441 int rc;
442
Simon Glass399a9ce2017-08-03 12:22:14 -0600443 rc = eth_env_get_enetaddr(env_var, enetaddr);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300444 if (rc)
445 return 0;
446
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200447 rc = cl_eeprom_read_mac_addr(enetaddr, eeprom_bus);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300448 if (rc)
449 return rc;
450
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500451 if (!is_valid_ethaddr(enetaddr))
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300452 return -1;
453
Simon Glass8551d552017-08-03 12:22:11 -0600454 return eth_env_set_enetaddr(env_var, enetaddr);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300455}
456
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200457#define SB_FX6_I2C_EEPROM_BUS 0
458#define NO_MAC_ADDR "No MAC address found for %s\n"
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300459int board_eth_init(bd_t *bis)
460{
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300461 int err;
462
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200463 if (handle_mac_address("ethaddr", CONFIG_SYS_I2C_EEPROM_BUS))
464 printf(NO_MAC_ADDR, "primary NIC");
465
466 if (handle_mac_address("eth1addr", SB_FX6_I2C_EEPROM_BUS))
467 printf(NO_MAC_ADDR, "secondary NIC");
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300468
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300469 SETUP_IOMUX_PADS(enet_pads);
470 /* phy reset */
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300471 err = gpio_request(CM_FX6_ENET_NRST, "enet_nrst");
472 if (err)
473 printf("Etnernet NRST gpio request failed: %d\n", err);
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300474 gpio_direction_output(CM_FX6_ENET_NRST, 0);
475 udelay(500);
476 gpio_set_value(CM_FX6_ENET_NRST, 1);
477 enable_enet_clk(1);
478 return cpu_eth_init(bis);
479}
480#endif
481
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300482#ifdef CONFIG_NAND_MXS
483static iomux_v3_cfg_t const nand_pads[] = {
484 IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
485 IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
486 IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
487 IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
488 IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
489 IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
490 IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
491 IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
492 IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
493 IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
494 IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
495 IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
496 IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
497 IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
498};
499
500static void cm_fx6_setup_gpmi_nand(void)
501{
502 SETUP_IOMUX_PADS(nand_pads);
503 /* Enable clock roots */
504 enable_usdhc_clk(1, 3);
505 enable_usdhc_clk(1, 4);
506
507 setup_gpmi_io_clk(MXC_CCM_CS2CDR_ENFC_CLK_PODF(0xf) |
508 MXC_CCM_CS2CDR_ENFC_CLK_PRED(1) |
509 MXC_CCM_CS2CDR_ENFC_CLK_SEL(0));
510}
511#else
512static void cm_fx6_setup_gpmi_nand(void) {}
513#endif
514
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300515#ifdef CONFIG_MXC_SPI
516int cm_fx6_setup_ecspi(void)
517{
518 cm_fx6_set_ecspi_iomux();
519 return gpio_request(CM_FX6_ECSPI_BUS0_CS0, "ecspi_bus0_cs0");
520}
521#else
522int cm_fx6_setup_ecspi(void) { return 0; }
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300523#endif
524
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300525#ifdef CONFIG_OF_BOARD_SETUP
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300526#define USDHC3_PATH "/soc/aips-bus@02100000/usdhc@02198000/"
Christopher Spinrathd706b572016-07-12 23:37:36 +0200527
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900528static const struct node_info nodes[] = {
Christopher Spinrathd706b572016-07-12 23:37:36 +0200529 /*
530 * Both entries target the same flash chip. The st,m25p compatible
531 * is used in the vendor device trees, while upstream uses (the
Christopher Spinrath2e158322016-08-23 16:08:52 +0200532 * documented) jedec,spi-nor compatible.
Christopher Spinrathd706b572016-07-12 23:37:36 +0200533 */
534 { "st,m25p", MTD_DEV_TYPE_NOR, },
535 { "jedec,spi-nor", MTD_DEV_TYPE_NOR, },
536};
537
Simon Glass2aec3cc2014-10-23 18:58:47 -0600538int ft_board_setup(void *blob, bd_t *bd)
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300539{
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300540 u32 baseboard_rev;
541 int nodeoffset;
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300542 uint8_t enetaddr[6];
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300543 char baseboard_name[16];
544 int err;
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300545
Hannes Schmelzerd3dbac82016-09-20 18:10:43 +0200546 fdt_shrink_to_minimum(blob, 0); /* Make room for new properties */
Christopher Spinrathd706b572016-07-12 23:37:36 +0200547
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300548 /* MAC addr */
Simon Glass399a9ce2017-08-03 12:22:14 -0600549 if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
Nikita Kiryanov8d25a512015-01-14 10:42:42 +0200550 fdt_find_and_setprop(blob,
551 "/soc/aips-bus@02100000/ethernet@02188000",
552 "local-mac-address", enetaddr, 6, 1);
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300553 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600554
Simon Glass399a9ce2017-08-03 12:22:14 -0600555 if (eth_env_get_enetaddr("eth1addr", enetaddr)) {
Nikita Kiryanov2c4c9222015-01-14 10:42:44 +0200556 fdt_find_and_setprop(blob, "/eth@pcie", "local-mac-address",
557 enetaddr, 6, 1);
558 }
559
Christopher Spinrath2e158322016-08-23 16:08:52 +0200560 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
561
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300562 baseboard_rev = cl_eeprom_get_board_rev(0);
563 err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
564 if (err || baseboard_rev == 0)
565 return 0; /* Assume not an early revision SB-FX6m baseboard */
566
567 if (!strncmp("SB-FX6m", baseboard_name, 7) && baseboard_rev <= 120) {
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300568 nodeoffset = fdt_path_offset(blob, USDHC3_PATH);
569 fdt_delprop(blob, nodeoffset, "cd-gpios");
Christopher Spinrathad3e0d72016-06-16 14:02:56 +0200570 fdt_find_and_setprop(blob, USDHC3_PATH, "broken-cd",
Nikita Kiryanov0a9c1b82015-09-06 11:48:38 +0300571 NULL, 0, 1);
572 fdt_find_and_setprop(blob, USDHC3_PATH, "keep-power-in-suspend",
573 NULL, 0, 1);
574 }
575
Simon Glass2aec3cc2014-10-23 18:58:47 -0600576 return 0;
Nikita Kiryanov5d95fd82014-08-20 15:09:02 +0300577}
578#endif
579
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300580int board_init(void)
581{
Simon Glass8d914362014-10-01 19:57:24 -0600582 int ret;
583
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300584 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300585 cm_fx6_setup_gpmi_nand();
Simon Glass8d914362014-10-01 19:57:24 -0600586
Nikita Kiryanov2fc7d2a2014-10-02 17:17:24 +0300587 ret = cm_fx6_setup_ecspi();
588 if (ret)
589 printf("Warning: ECSPI setup failed: %d\n", ret);
590
591 ret = cm_fx6_setup_usb_otg();
592 if (ret)
593 printf("Warning: USB OTG setup failed: %d\n", ret);
594
595 ret = cm_fx6_setup_usb_host();
596 if (ret)
597 printf("Warning: USB host setup failed: %d\n", ret);
598
599 /*
600 * cm-fx6 may have iSSD not assembled and in this case it has
601 * bypasses for a (m)SATA socket on the baseboard. The socketed
602 * device is not controlled by those GPIOs. So just print a warning
603 * if the setup fails.
604 */
605 ret = cm_fx6_setup_issd();
606 if (ret)
607 printf("Warning: iSSD setup failed: %d\n", ret);
608
Simon Glass8d914362014-10-01 19:57:24 -0600609 /* Warn on failure but do not abort boot */
610 ret = cm_fx6_setup_i2c();
611 if (ret)
612 printf("Warning: I2C setup failed: %d\n", ret);
Nikita Kiryanov59d06092014-08-20 15:09:01 +0300613
Nikita Kiryanov89581372015-01-14 10:42:46 +0200614 cm_fx6_setup_display();
615
Simon Glass220b8da2017-07-29 11:35:27 -0600616 /* This should be done in the MMC driver when MX6 has a clock driver */
Yangbo Lu73340382019-06-21 11:42:28 +0800617#ifdef CONFIG_FSL_ESDHC_IMX
Simon Glass220b8da2017-07-29 11:35:27 -0600618 if (IS_ENABLED(CONFIG_BLK)) {
619 int i;
620
621 cm_fx6_set_usdhc_iomux();
622 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++)
623 enable_usdhc_clk(1, i);
624 }
625#endif
626
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300627 return 0;
628}
629
Christopher Spinrathf306a5a2018-01-09 22:01:35 +0100630int board_late_init(void)
631{
632#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
633 char baseboard_name[16];
634 int err;
635
636 if (is_mx6dq())
637 env_set("board_rev", "MX6Q");
638 else if (is_mx6dl())
639 env_set("board_rev", "MX6DL");
640
641 err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
642 if (err)
643 return 0;
644
645 if (!strncmp("SB-FX6m", baseboard_name, 7))
646 env_set("board_name", "Utilite");
647#endif
648 return 0;
649}
650
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300651int checkboard(void)
652{
653 puts("Board: CM-FX6\n");
654 return 0;
655}
656
Nikita Kiryanovc69901b2015-08-30 15:36:48 +0300657int misc_init_r(void)
658{
659 cl_print_pcb_info();
660
661 return 0;
662}
663
Simon Glass2f949c32017-03-31 08:40:32 -0600664int dram_init_banksize(void)
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300665{
666 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
667 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
668
669 switch (gd->ram_size) {
670 case 0x10000000: /* DDR_16BIT_256MB */
671 gd->bd->bi_dram[0].size = 0x10000000;
672 gd->bd->bi_dram[1].size = 0;
673 break;
674 case 0x20000000: /* DDR_32BIT_512MB */
675 gd->bd->bi_dram[0].size = 0x20000000;
676 gd->bd->bi_dram[1].size = 0;
677 break;
678 case 0x40000000:
679 if (is_cpu_type(MXC_CPU_MX6SOLO)) { /* DDR_32BIT_1GB */
680 gd->bd->bi_dram[0].size = 0x20000000;
681 gd->bd->bi_dram[1].size = 0x20000000;
682 } else { /* DDR_64BIT_1GB */
683 gd->bd->bi_dram[0].size = 0x40000000;
684 gd->bd->bi_dram[1].size = 0;
685 }
686 break;
687 case 0x80000000: /* DDR_64BIT_2GB */
688 gd->bd->bi_dram[0].size = 0x40000000;
689 gd->bd->bi_dram[1].size = 0x40000000;
690 break;
691 case 0xEFF00000: /* DDR_64BIT_4GB */
692 gd->bd->bi_dram[0].size = 0x70000000;
693 gd->bd->bi_dram[1].size = 0x7FF00000;
694 break;
695 }
Simon Glass2f949c32017-03-31 08:40:32 -0600696
697 return 0;
Nikita Kiryanovf5cab0f2014-09-07 18:59:29 +0300698}
699
700int dram_init(void)
701{
702 gd->ram_size = imx_ddr_size();
703 switch (gd->ram_size) {
704 case 0x10000000:
705 case 0x20000000:
706 case 0x40000000:
707 case 0x80000000:
708 break;
709 case 0xF0000000:
710 gd->ram_size -= 0x100000;
711 break;
712 default:
713 printf("ERROR: Unsupported DRAM size 0x%lx\n", gd->ram_size);
714 return -1;
715 }
716
717 return 0;
718}
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300719
720u32 get_board_rev(void)
721{
Nikita Kiryanov7fa68352015-09-06 11:48:35 +0300722 return cl_eeprom_get_board_rev(CONFIG_SYS_I2C_EEPROM_BUS);
Nikita Kiryanov266728a2014-08-20 15:09:05 +0300723}
724
Simon Glassc0d07c22014-10-01 19:57:28 -0600725static struct mxc_serial_platdata cm_fx6_mxc_serial_plat = {
726 .reg = (struct mxc_uart *)UART4_BASE,
727};
728
729U_BOOT_DEVICE(cm_fx6_serial) = {
730 .name = "serial_mxc",
731 .platdata = &cm_fx6_mxc_serial_plat,
732};
Simon Glassbf8950e2017-07-29 11:35:25 -0600733
734#if CONFIG_IS_ENABLED(AHCI)
735static int sata_imx_probe(struct udevice *dev)
736{
737 int i, err;
738
739 /* Make sure this gpio has logical 0 value */
740 gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
741 udelay(100);
742 cm_fx6_sata_power(1);
743
744 for (i = 0; i < CM_FX6_SATA_INIT_RETRIES; i++) {
745 err = setup_sata();
746 if (err) {
747 printf("SATA setup failed: %d\n", err);
748 return err;
749 }
750
751 udelay(100);
752
753 err = dwc_ahsata_probe(dev);
754 if (!err)
755 break;
756
757 /* There is no device on the SATA port */
758 if (sata_dm_port_status(0, 0) == 0)
759 break;
760
761 /* There's a device, but link not established. Retry */
762 device_remove(dev, DM_REMOVE_NORMAL);
763 }
764
765 return 0;
766}
767
768static int sata_imx_remove(struct udevice *dev)
769{
770 cm_fx6_sata_power(0);
771 mdelay(250);
772
773 return 0;
774}
775
776struct ahci_ops sata_imx_ops = {
777 .port_status = dwc_ahsata_port_status,
778 .reset = dwc_ahsata_bus_reset,
779 .scan = dwc_ahsata_scan,
780};
781
782static const struct udevice_id sata_imx_ids[] = {
783 { .compatible = "fsl,imx6q-ahci" },
784 { }
785};
786
787U_BOOT_DRIVER(sata_imx) = {
788 .name = "dwc_ahci",
789 .id = UCLASS_AHCI,
790 .of_match = sata_imx_ids,
791 .ops = &sata_imx_ops,
792 .probe = sata_imx_probe,
793 .remove = sata_imx_remove, /* reset bus to stop it */
794};
795#endif /* AHCI */