cm_fx6.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*
  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. #include <common.h>
  11. #include <ahci.h>
  12. #include <dm.h>
  13. #include <dwc_ahsata.h>
  14. #include <fsl_esdhc.h>
  15. #include <miiphy.h>
  16. #include <mtd_node.h>
  17. #include <netdev.h>
  18. #include <errno.h>
  19. #include <usb.h>
  20. #include <fdt_support.h>
  21. #include <sata.h>
  22. #include <splash.h>
  23. #include <asm/arch/crm_regs.h>
  24. #include <asm/arch/sys_proto.h>
  25. #include <asm/arch/iomux.h>
  26. #include <asm/arch/mxc_hdmi.h>
  27. #include <asm/mach-imx/mxc_i2c.h>
  28. #include <asm/mach-imx/sata.h>
  29. #include <asm/mach-imx/video.h>
  30. #include <asm/io.h>
  31. #include <asm/gpio.h>
  32. #include <dm/platform_data/serial_mxc.h>
  33. #include <dm/device-internal.h>
  34. #include <jffs2/load_kernel.h>
  35. #include "common.h"
  36. #include "../common/eeprom.h"
  37. #include "../common/common.h"
  38. DECLARE_GLOBAL_DATA_PTR;
  39. #ifdef CONFIG_SPLASH_SCREEN
  40. static struct splash_location cm_fx6_splash_locations[] = {
  41. {
  42. .name = "sf",
  43. .storage = SPLASH_STORAGE_SF,
  44. .flags = SPLASH_STORAGE_RAW,
  45. .offset = 0x100000,
  46. },
  47. {
  48. .name = "mmc_fs",
  49. .storage = SPLASH_STORAGE_MMC,
  50. .flags = SPLASH_STORAGE_FS,
  51. .devpart = "2:1",
  52. },
  53. {
  54. .name = "usb_fs",
  55. .storage = SPLASH_STORAGE_USB,
  56. .flags = SPLASH_STORAGE_FS,
  57. .devpart = "0:1",
  58. },
  59. {
  60. .name = "sata_fs",
  61. .storage = SPLASH_STORAGE_SATA,
  62. .flags = SPLASH_STORAGE_FS,
  63. .devpart = "0:1",
  64. },
  65. };
  66. int splash_screen_prepare(void)
  67. {
  68. return splash_source_load(cm_fx6_splash_locations,
  69. ARRAY_SIZE(cm_fx6_splash_locations));
  70. }
  71. #endif
  72. #ifdef CONFIG_IMX_HDMI
  73. static void cm_fx6_enable_hdmi(struct display_info_t const *dev)
  74. {
  75. 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);
  78. imx_enable_hdmi_phy();
  79. }
  80. static struct display_info_t preset_hdmi_1024X768 = {
  81. .bus = -1,
  82. .addr = 0,
  83. .pixfmt = IPU_PIX_FMT_RGB24,
  84. .enable = cm_fx6_enable_hdmi,
  85. .mode = {
  86. .name = "HDMI",
  87. .refresh = 60,
  88. .xres = 1024,
  89. .yres = 768,
  90. .pixclock = 40385,
  91. .left_margin = 220,
  92. .right_margin = 40,
  93. .upper_margin = 21,
  94. .lower_margin = 7,
  95. .hsync_len = 60,
  96. .vsync_len = 10,
  97. .sync = FB_SYNC_EXT,
  98. .vmode = FB_VMODE_NONINTERLACED,
  99. }
  100. };
  101. static void cm_fx6_setup_display(void)
  102. {
  103. struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
  104. enable_ipu_clock();
  105. clrbits_le32(&iomuxc_regs->gpr[3], MXC_CCM_CCGR3_IPU1_IPU_DI0_MASK);
  106. }
  107. int board_video_skip(void)
  108. {
  109. int ret;
  110. struct display_info_t *preset;
  111. char const *panel = env_get("displaytype");
  112. if (!panel) /* Also accept panel for backward compatibility */
  113. panel = env_get("panel");
  114. if (!panel)
  115. return -ENOENT;
  116. if (!strcmp(panel, "HDMI"))
  117. preset = &preset_hdmi_1024X768;
  118. else
  119. return -EINVAL;
  120. ret = ipuv3_fb_init(&preset->mode, 0, preset->pixfmt);
  121. if (ret) {
  122. printf("Can't init display %s: %d\n", preset->mode.name, ret);
  123. return ret;
  124. }
  125. preset->enable(preset);
  126. printf("Display: %s (%ux%u)\n", preset->mode.name, preset->mode.xres,
  127. preset->mode.yres);
  128. return 0;
  129. }
  130. #else
  131. static inline void cm_fx6_setup_display(void) {}
  132. #endif /* CONFIG_VIDEO_IPUV3 */
  133. #ifdef CONFIG_DWC_AHSATA
  134. static int cm_fx6_issd_gpios[] = {
  135. /* The order of the GPIOs in the array is important! */
  136. CM_FX6_SATA_LDO_EN,
  137. CM_FX6_SATA_PHY_SLP,
  138. CM_FX6_SATA_NRSTDLY,
  139. CM_FX6_SATA_PWREN,
  140. CM_FX6_SATA_NSTANDBY1,
  141. CM_FX6_SATA_NSTANDBY2,
  142. };
  143. static void cm_fx6_sata_power(int on)
  144. {
  145. int i;
  146. if (!on) { /* tell the iSSD that the power will be removed */
  147. gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 1);
  148. mdelay(10);
  149. }
  150. for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
  151. gpio_direction_output(cm_fx6_issd_gpios[i], on);
  152. udelay(100);
  153. }
  154. if (!on) /* for compatibility lower the power loss interrupt */
  155. gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
  156. }
  157. static iomux_v3_cfg_t const sata_pads[] = {
  158. /* SATA PWR */
  159. IOMUX_PADS(PAD_ENET_TX_EN__GPIO1_IO28 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  160. IOMUX_PADS(PAD_EIM_A22__GPIO2_IO16 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  161. IOMUX_PADS(PAD_EIM_D20__GPIO3_IO20 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  162. IOMUX_PADS(PAD_EIM_A25__GPIO5_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  163. /* SATA CTRL */
  164. IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  165. IOMUX_PADS(PAD_EIM_D23__GPIO3_IO23 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  166. IOMUX_PADS(PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  167. IOMUX_PADS(PAD_EIM_A23__GPIO6_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  168. IOMUX_PADS(PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  169. };
  170. static int cm_fx6_setup_issd(void)
  171. {
  172. int ret, i;
  173. SETUP_IOMUX_PADS(sata_pads);
  174. for (i = 0; i < ARRAY_SIZE(cm_fx6_issd_gpios); i++) {
  175. ret = gpio_request(cm_fx6_issd_gpios[i], "sata");
  176. if (ret)
  177. return ret;
  178. }
  179. ret = gpio_request(CM_FX6_SATA_PWLOSS_INT, "sata_pwloss_int");
  180. if (ret)
  181. return ret;
  182. return 0;
  183. }
  184. #define CM_FX6_SATA_INIT_RETRIES 10
  185. #else
  186. static int cm_fx6_setup_issd(void) { return 0; }
  187. #endif
  188. #ifdef CONFIG_SYS_I2C_MXC
  189. #define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
  190. PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
  191. PAD_CTL_ODE | PAD_CTL_SRE_FAST)
  192. I2C_PADS(i2c0_pads,
  193. PAD_EIM_D21__I2C1_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
  194. PAD_EIM_D21__GPIO3_IO21 | MUX_PAD_CTRL(I2C_PAD_CTRL),
  195. IMX_GPIO_NR(3, 21),
  196. PAD_EIM_D28__I2C1_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
  197. PAD_EIM_D28__GPIO3_IO28 | MUX_PAD_CTRL(I2C_PAD_CTRL),
  198. IMX_GPIO_NR(3, 28));
  199. I2C_PADS(i2c1_pads,
  200. PAD_KEY_COL3__I2C2_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
  201. PAD_KEY_COL3__GPIO4_IO12 | MUX_PAD_CTRL(I2C_PAD_CTRL),
  202. IMX_GPIO_NR(4, 12),
  203. PAD_KEY_ROW3__I2C2_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
  204. PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(I2C_PAD_CTRL),
  205. IMX_GPIO_NR(4, 13));
  206. I2C_PADS(i2c2_pads,
  207. PAD_GPIO_3__I2C3_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL),
  208. PAD_GPIO_3__GPIO1_IO03 | MUX_PAD_CTRL(I2C_PAD_CTRL),
  209. IMX_GPIO_NR(1, 3),
  210. PAD_GPIO_6__I2C3_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL),
  211. PAD_GPIO_6__GPIO1_IO06 | MUX_PAD_CTRL(I2C_PAD_CTRL),
  212. IMX_GPIO_NR(1, 6));
  213. static int cm_fx6_setup_one_i2c(int busnum, struct i2c_pads_info *pads)
  214. {
  215. int ret;
  216. ret = setup_i2c(busnum, CONFIG_SYS_I2C_SPEED, 0x7f, pads);
  217. if (ret)
  218. printf("Warning: I2C%d setup failed: %d\n", busnum, ret);
  219. return ret;
  220. }
  221. static int cm_fx6_setup_i2c(void)
  222. {
  223. int ret = 0, err;
  224. /* i2c<x>_pads are wierd macro variables; we can't use an array */
  225. err = cm_fx6_setup_one_i2c(0, I2C_PADS_INFO(i2c0_pads));
  226. if (err)
  227. ret = err;
  228. err = cm_fx6_setup_one_i2c(1, I2C_PADS_INFO(i2c1_pads));
  229. if (err)
  230. ret = err;
  231. err = cm_fx6_setup_one_i2c(2, I2C_PADS_INFO(i2c2_pads));
  232. if (err)
  233. ret = err;
  234. return ret;
  235. }
  236. #else
  237. static int cm_fx6_setup_i2c(void) { return 0; }
  238. #endif
  239. #ifdef CONFIG_USB_EHCI_MX6
  240. #define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
  241. PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
  242. PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
  243. #define MX6_USBNC_BASEADDR 0x2184800
  244. #define USBNC_USB_H1_PWR_POL (1 << 9)
  245. static int cm_fx6_setup_usb_host(void)
  246. {
  247. int err;
  248. err = gpio_request(CM_FX6_USB_HUB_RST, "usb hub rst");
  249. if (err)
  250. return err;
  251. SETUP_IOMUX_PAD(PAD_GPIO_0__USB_H1_PWR | MUX_PAD_CTRL(NO_PAD_CTRL));
  252. SETUP_IOMUX_PAD(PAD_SD3_RST__GPIO7_IO08 | MUX_PAD_CTRL(NO_PAD_CTRL));
  253. return 0;
  254. }
  255. static int cm_fx6_setup_usb_otg(void)
  256. {
  257. int err;
  258. struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
  259. err = gpio_request(SB_FX6_USB_OTG_PWR, "usb-pwr");
  260. if (err) {
  261. printf("USB OTG pwr gpio request failed: %d\n", err);
  262. return err;
  263. }
  264. SETUP_IOMUX_PAD(PAD_EIM_D22__GPIO3_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL));
  265. SETUP_IOMUX_PAD(PAD_ENET_RX_ER__USB_OTG_ID |
  266. MUX_PAD_CTRL(WEAK_PULLDOWN));
  267. clrbits_le32(&iomux->gpr[1], IOMUXC_GPR1_OTG_ID_MASK);
  268. /* disable ext. charger detect, or it'll affect signal quality at dp. */
  269. return gpio_direction_output(SB_FX6_USB_OTG_PWR, 0);
  270. }
  271. int board_usb_phy_mode(int port)
  272. {
  273. return USB_INIT_HOST;
  274. }
  275. int board_ehci_hcd_init(int port)
  276. {
  277. int ret;
  278. u32 *usbnc_usb_uh1_ctrl = (u32 *)(MX6_USBNC_BASEADDR + 4);
  279. /* Only 1 host controller in use. port 0 is OTG & needs no attention */
  280. if (port != 1)
  281. return 0;
  282. /* Set PWR polarity to match power switch's enable polarity */
  283. setbits_le32(usbnc_usb_uh1_ctrl, USBNC_USB_H1_PWR_POL);
  284. ret = gpio_direction_output(CM_FX6_USB_HUB_RST, 0);
  285. if (ret)
  286. return ret;
  287. udelay(10);
  288. ret = gpio_direction_output(CM_FX6_USB_HUB_RST, 1);
  289. if (ret)
  290. return ret;
  291. mdelay(1);
  292. return 0;
  293. }
  294. int board_ehci_power(int port, int on)
  295. {
  296. if (port == 0)
  297. return gpio_direction_output(SB_FX6_USB_OTG_PWR, on);
  298. return 0;
  299. }
  300. #else
  301. static int cm_fx6_setup_usb_otg(void) { return 0; }
  302. static int cm_fx6_setup_usb_host(void) { return 0; }
  303. #endif
  304. #ifdef CONFIG_FEC_MXC
  305. #define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
  306. PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
  307. static int mx6_rgmii_rework(struct phy_device *phydev)
  308. {
  309. unsigned short val;
  310. /* Ar8031 phy SmartEEE feature cause link status generates glitch,
  311. * which cause ethernet link down/up issue, so disable SmartEEE
  312. */
  313. phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x3);
  314. phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x805d);
  315. phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4003);
  316. val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
  317. val &= ~(0x1 << 8);
  318. phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
  319. /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
  320. phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
  321. phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
  322. phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
  323. val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
  324. val &= 0xffe3;
  325. val |= 0x18;
  326. phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
  327. /* introduce tx clock delay */
  328. phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
  329. val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
  330. val |= 0x0100;
  331. phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
  332. return 0;
  333. }
  334. int board_phy_config(struct phy_device *phydev)
  335. {
  336. mx6_rgmii_rework(phydev);
  337. if (phydev->drv->config)
  338. return phydev->drv->config(phydev);
  339. return 0;
  340. }
  341. static iomux_v3_cfg_t const enet_pads[] = {
  342. IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  343. IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  344. IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  345. IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  346. IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  347. IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  348. IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  349. IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  350. IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  351. IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  352. IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  353. IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  354. IOMUX_PADS(PAD_GPIO_0__CCM_CLKO1 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  355. IOMUX_PADS(PAD_GPIO_3__CCM_CLKO2 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  356. IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(0x84)),
  357. IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
  358. MUX_PAD_CTRL(ENET_PAD_CTRL)),
  359. IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
  360. MUX_PAD_CTRL(ENET_PAD_CTRL)),
  361. IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
  362. MUX_PAD_CTRL(ENET_PAD_CTRL)),
  363. };
  364. static int handle_mac_address(char *env_var, uint eeprom_bus)
  365. {
  366. unsigned char enetaddr[6];
  367. int rc;
  368. rc = eth_env_get_enetaddr(env_var, enetaddr);
  369. if (rc)
  370. return 0;
  371. rc = cl_eeprom_read_mac_addr(enetaddr, eeprom_bus);
  372. if (rc)
  373. return rc;
  374. if (!is_valid_ethaddr(enetaddr))
  375. return -1;
  376. return eth_env_set_enetaddr(env_var, enetaddr);
  377. }
  378. #define SB_FX6_I2C_EEPROM_BUS 0
  379. #define NO_MAC_ADDR "No MAC address found for %s\n"
  380. int board_eth_init(bd_t *bis)
  381. {
  382. int err;
  383. if (handle_mac_address("ethaddr", CONFIG_SYS_I2C_EEPROM_BUS))
  384. printf(NO_MAC_ADDR, "primary NIC");
  385. if (handle_mac_address("eth1addr", SB_FX6_I2C_EEPROM_BUS))
  386. printf(NO_MAC_ADDR, "secondary NIC");
  387. SETUP_IOMUX_PADS(enet_pads);
  388. /* phy reset */
  389. err = gpio_request(CM_FX6_ENET_NRST, "enet_nrst");
  390. if (err)
  391. printf("Etnernet NRST gpio request failed: %d\n", err);
  392. gpio_direction_output(CM_FX6_ENET_NRST, 0);
  393. udelay(500);
  394. gpio_set_value(CM_FX6_ENET_NRST, 1);
  395. enable_enet_clk(1);
  396. return cpu_eth_init(bis);
  397. }
  398. #endif
  399. #ifdef CONFIG_NAND_MXS
  400. static iomux_v3_cfg_t const nand_pads[] = {
  401. IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
  402. IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
  403. IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  404. IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  405. IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  406. IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  407. IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  408. IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  409. IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  410. IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  411. IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  412. IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  413. IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  414. IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  415. };
  416. static void cm_fx6_setup_gpmi_nand(void)
  417. {
  418. SETUP_IOMUX_PADS(nand_pads);
  419. /* Enable clock roots */
  420. enable_usdhc_clk(1, 3);
  421. enable_usdhc_clk(1, 4);
  422. setup_gpmi_io_clk(MXC_CCM_CS2CDR_ENFC_CLK_PODF(0xf) |
  423. MXC_CCM_CS2CDR_ENFC_CLK_PRED(1) |
  424. MXC_CCM_CS2CDR_ENFC_CLK_SEL(0));
  425. }
  426. #else
  427. static void cm_fx6_setup_gpmi_nand(void) {}
  428. #endif
  429. #ifdef CONFIG_MXC_SPI
  430. int cm_fx6_setup_ecspi(void)
  431. {
  432. cm_fx6_set_ecspi_iomux();
  433. return gpio_request(CM_FX6_ECSPI_BUS0_CS0, "ecspi_bus0_cs0");
  434. }
  435. #else
  436. int cm_fx6_setup_ecspi(void) { return 0; }
  437. #endif
  438. #ifdef CONFIG_OF_BOARD_SETUP
  439. #define USDHC3_PATH "/soc/aips-bus@02100000/usdhc@02198000/"
  440. struct node_info nodes[] = {
  441. /*
  442. * Both entries target the same flash chip. The st,m25p compatible
  443. * is used in the vendor device trees, while upstream uses (the
  444. * documented) jedec,spi-nor compatible.
  445. */
  446. { "st,m25p", MTD_DEV_TYPE_NOR, },
  447. { "jedec,spi-nor", MTD_DEV_TYPE_NOR, },
  448. };
  449. int ft_board_setup(void *blob, bd_t *bd)
  450. {
  451. u32 baseboard_rev;
  452. int nodeoffset;
  453. uint8_t enetaddr[6];
  454. char baseboard_name[16];
  455. int err;
  456. fdt_shrink_to_minimum(blob, 0); /* Make room for new properties */
  457. /* MAC addr */
  458. if (eth_env_get_enetaddr("ethaddr", enetaddr)) {
  459. fdt_find_and_setprop(blob,
  460. "/soc/aips-bus@02100000/ethernet@02188000",
  461. "local-mac-address", enetaddr, 6, 1);
  462. }
  463. if (eth_env_get_enetaddr("eth1addr", enetaddr)) {
  464. fdt_find_and_setprop(blob, "/eth@pcie", "local-mac-address",
  465. enetaddr, 6, 1);
  466. }
  467. fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
  468. baseboard_rev = cl_eeprom_get_board_rev(0);
  469. err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
  470. if (err || baseboard_rev == 0)
  471. return 0; /* Assume not an early revision SB-FX6m baseboard */
  472. if (!strncmp("SB-FX6m", baseboard_name, 7) && baseboard_rev <= 120) {
  473. nodeoffset = fdt_path_offset(blob, USDHC3_PATH);
  474. fdt_delprop(blob, nodeoffset, "cd-gpios");
  475. fdt_find_and_setprop(blob, USDHC3_PATH, "broken-cd",
  476. NULL, 0, 1);
  477. fdt_find_and_setprop(blob, USDHC3_PATH, "keep-power-in-suspend",
  478. NULL, 0, 1);
  479. }
  480. return 0;
  481. }
  482. #endif
  483. int board_init(void)
  484. {
  485. int ret;
  486. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  487. cm_fx6_setup_gpmi_nand();
  488. ret = cm_fx6_setup_ecspi();
  489. if (ret)
  490. printf("Warning: ECSPI setup failed: %d\n", ret);
  491. ret = cm_fx6_setup_usb_otg();
  492. if (ret)
  493. printf("Warning: USB OTG setup failed: %d\n", ret);
  494. ret = cm_fx6_setup_usb_host();
  495. if (ret)
  496. printf("Warning: USB host setup failed: %d\n", ret);
  497. /*
  498. * cm-fx6 may have iSSD not assembled and in this case it has
  499. * bypasses for a (m)SATA socket on the baseboard. The socketed
  500. * device is not controlled by those GPIOs. So just print a warning
  501. * if the setup fails.
  502. */
  503. ret = cm_fx6_setup_issd();
  504. if (ret)
  505. printf("Warning: iSSD setup failed: %d\n", ret);
  506. /* Warn on failure but do not abort boot */
  507. ret = cm_fx6_setup_i2c();
  508. if (ret)
  509. printf("Warning: I2C setup failed: %d\n", ret);
  510. cm_fx6_setup_display();
  511. /* This should be done in the MMC driver when MX6 has a clock driver */
  512. #ifdef CONFIG_FSL_ESDHC
  513. if (IS_ENABLED(CONFIG_BLK)) {
  514. int i;
  515. cm_fx6_set_usdhc_iomux();
  516. for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++)
  517. enable_usdhc_clk(1, i);
  518. }
  519. #endif
  520. return 0;
  521. }
  522. int board_late_init(void)
  523. {
  524. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  525. char baseboard_name[16];
  526. int err;
  527. if (is_mx6dq())
  528. env_set("board_rev", "MX6Q");
  529. else if (is_mx6dl())
  530. env_set("board_rev", "MX6DL");
  531. err = cl_eeprom_get_product_name((uchar *)baseboard_name, 0);
  532. if (err)
  533. return 0;
  534. if (!strncmp("SB-FX6m", baseboard_name, 7))
  535. env_set("board_name", "Utilite");
  536. #endif
  537. return 0;
  538. }
  539. int checkboard(void)
  540. {
  541. puts("Board: CM-FX6\n");
  542. return 0;
  543. }
  544. int misc_init_r(void)
  545. {
  546. cl_print_pcb_info();
  547. return 0;
  548. }
  549. int dram_init_banksize(void)
  550. {
  551. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  552. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  553. switch (gd->ram_size) {
  554. case 0x10000000: /* DDR_16BIT_256MB */
  555. gd->bd->bi_dram[0].size = 0x10000000;
  556. gd->bd->bi_dram[1].size = 0;
  557. break;
  558. case 0x20000000: /* DDR_32BIT_512MB */
  559. gd->bd->bi_dram[0].size = 0x20000000;
  560. gd->bd->bi_dram[1].size = 0;
  561. break;
  562. case 0x40000000:
  563. if (is_cpu_type(MXC_CPU_MX6SOLO)) { /* DDR_32BIT_1GB */
  564. gd->bd->bi_dram[0].size = 0x20000000;
  565. gd->bd->bi_dram[1].size = 0x20000000;
  566. } else { /* DDR_64BIT_1GB */
  567. gd->bd->bi_dram[0].size = 0x40000000;
  568. gd->bd->bi_dram[1].size = 0;
  569. }
  570. break;
  571. case 0x80000000: /* DDR_64BIT_2GB */
  572. gd->bd->bi_dram[0].size = 0x40000000;
  573. gd->bd->bi_dram[1].size = 0x40000000;
  574. break;
  575. case 0xEFF00000: /* DDR_64BIT_4GB */
  576. gd->bd->bi_dram[0].size = 0x70000000;
  577. gd->bd->bi_dram[1].size = 0x7FF00000;
  578. break;
  579. }
  580. return 0;
  581. }
  582. int dram_init(void)
  583. {
  584. gd->ram_size = imx_ddr_size();
  585. switch (gd->ram_size) {
  586. case 0x10000000:
  587. case 0x20000000:
  588. case 0x40000000:
  589. case 0x80000000:
  590. break;
  591. case 0xF0000000:
  592. gd->ram_size -= 0x100000;
  593. break;
  594. default:
  595. printf("ERROR: Unsupported DRAM size 0x%lx\n", gd->ram_size);
  596. return -1;
  597. }
  598. return 0;
  599. }
  600. u32 get_board_rev(void)
  601. {
  602. return cl_eeprom_get_board_rev(CONFIG_SYS_I2C_EEPROM_BUS);
  603. }
  604. static struct mxc_serial_platdata cm_fx6_mxc_serial_plat = {
  605. .reg = (struct mxc_uart *)UART4_BASE,
  606. };
  607. U_BOOT_DEVICE(cm_fx6_serial) = {
  608. .name = "serial_mxc",
  609. .platdata = &cm_fx6_mxc_serial_plat,
  610. };
  611. #if CONFIG_IS_ENABLED(AHCI)
  612. static int sata_imx_probe(struct udevice *dev)
  613. {
  614. int i, err;
  615. /* Make sure this gpio has logical 0 value */
  616. gpio_direction_output(CM_FX6_SATA_PWLOSS_INT, 0);
  617. udelay(100);
  618. cm_fx6_sata_power(1);
  619. for (i = 0; i < CM_FX6_SATA_INIT_RETRIES; i++) {
  620. err = setup_sata();
  621. if (err) {
  622. printf("SATA setup failed: %d\n", err);
  623. return err;
  624. }
  625. udelay(100);
  626. err = dwc_ahsata_probe(dev);
  627. if (!err)
  628. break;
  629. /* There is no device on the SATA port */
  630. if (sata_dm_port_status(0, 0) == 0)
  631. break;
  632. /* There's a device, but link not established. Retry */
  633. device_remove(dev, DM_REMOVE_NORMAL);
  634. }
  635. return 0;
  636. }
  637. static int sata_imx_remove(struct udevice *dev)
  638. {
  639. cm_fx6_sata_power(0);
  640. mdelay(250);
  641. return 0;
  642. }
  643. struct ahci_ops sata_imx_ops = {
  644. .port_status = dwc_ahsata_port_status,
  645. .reset = dwc_ahsata_bus_reset,
  646. .scan = dwc_ahsata_scan,
  647. };
  648. static const struct udevice_id sata_imx_ids[] = {
  649. { .compatible = "fsl,imx6q-ahci" },
  650. { }
  651. };
  652. U_BOOT_DRIVER(sata_imx) = {
  653. .name = "dwc_ahci",
  654. .id = UCLASS_AHCI,
  655. .of_match = sata_imx_ids,
  656. .ops = &sata_imx_ops,
  657. .probe = sata_imx_probe,
  658. .remove = sata_imx_remove, /* reset bus to stop it */
  659. };
  660. #endif /* AHCI */