gw_ventana.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013 Gateworks Corporation
  4. *
  5. * Author: Tim Harvey <tharvey@gateworks.com>
  6. */
  7. #include <common.h>
  8. #include <asm/arch/clock.h>
  9. #include <asm/arch/crm_regs.h>
  10. #include <asm/arch/iomux.h>
  11. #include <asm/arch/mx6-pins.h>
  12. #include <asm/arch/mxc_hdmi.h>
  13. #include <asm/arch/sys_proto.h>
  14. #include <asm/gpio.h>
  15. #include <asm/mach-imx/boot_mode.h>
  16. #include <asm/mach-imx/sata.h>
  17. #include <asm/mach-imx/spi.h>
  18. #include <asm/mach-imx/video.h>
  19. #include <asm/io.h>
  20. #include <asm/setup.h>
  21. #include <dm.h>
  22. #include <dm/platform_data/serial_mxc.h>
  23. #include <environment.h>
  24. #include <hwconfig.h>
  25. #include <i2c.h>
  26. #include <fdt_support.h>
  27. #include <fsl_esdhc.h>
  28. #include <jffs2/load_kernel.h>
  29. #include <linux/ctype.h>
  30. #include <miiphy.h>
  31. #include <mtd_node.h>
  32. #include <netdev.h>
  33. #include <pci.h>
  34. #include <power/pmic.h>
  35. #include <power/ltc3676_pmic.h>
  36. #include <power/pfuze100_pmic.h>
  37. #include <fdt_support.h>
  38. #include <jffs2/load_kernel.h>
  39. #include <spi_flash.h>
  40. #include "gsc.h"
  41. #include "common.h"
  42. DECLARE_GLOBAL_DATA_PTR;
  43. /*
  44. * EEPROM board info struct populated by read_eeprom so that we only have to
  45. * read it once.
  46. */
  47. struct ventana_board_info ventana_info;
  48. static int board_type;
  49. /* ENET */
  50. static iomux_v3_cfg_t const enet_pads[] = {
  51. IOMUX_PADS(PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  52. IOMUX_PADS(PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  53. IOMUX_PADS(PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  54. IOMUX_PADS(PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  55. IOMUX_PADS(PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  56. IOMUX_PADS(PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  57. IOMUX_PADS(PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  58. IOMUX_PADS(PAD_RGMII_TX_CTL__RGMII_TX_CTL |
  59. MUX_PAD_CTRL(ENET_PAD_CTRL)),
  60. IOMUX_PADS(PAD_ENET_REF_CLK__ENET_TX_CLK |
  61. MUX_PAD_CTRL(ENET_PAD_CTRL)),
  62. IOMUX_PADS(PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  63. IOMUX_PADS(PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  64. IOMUX_PADS(PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  65. IOMUX_PADS(PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  66. IOMUX_PADS(PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL)),
  67. IOMUX_PADS(PAD_RGMII_RX_CTL__RGMII_RX_CTL |
  68. MUX_PAD_CTRL(ENET_PAD_CTRL)),
  69. /* PHY nRST */
  70. IOMUX_PADS(PAD_ENET_TXD0__GPIO1_IO30 | DIO_PAD_CFG),
  71. };
  72. #ifdef CONFIG_CMD_NAND
  73. static iomux_v3_cfg_t const nfc_pads[] = {
  74. IOMUX_PADS(PAD_NANDF_CLE__NAND_CLE | MUX_PAD_CTRL(NO_PAD_CTRL)),
  75. IOMUX_PADS(PAD_NANDF_ALE__NAND_ALE | MUX_PAD_CTRL(NO_PAD_CTRL)),
  76. IOMUX_PADS(PAD_NANDF_WP_B__NAND_WP_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  77. IOMUX_PADS(PAD_NANDF_RB0__NAND_READY_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  78. IOMUX_PADS(PAD_NANDF_CS0__NAND_CE0_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  79. IOMUX_PADS(PAD_SD4_CMD__NAND_RE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  80. IOMUX_PADS(PAD_SD4_CLK__NAND_WE_B | MUX_PAD_CTRL(NO_PAD_CTRL)),
  81. IOMUX_PADS(PAD_NANDF_D0__NAND_DATA00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  82. IOMUX_PADS(PAD_NANDF_D1__NAND_DATA01 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  83. IOMUX_PADS(PAD_NANDF_D2__NAND_DATA02 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  84. IOMUX_PADS(PAD_NANDF_D3__NAND_DATA03 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  85. IOMUX_PADS(PAD_NANDF_D4__NAND_DATA04 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  86. IOMUX_PADS(PAD_NANDF_D5__NAND_DATA05 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  87. IOMUX_PADS(PAD_NANDF_D6__NAND_DATA06 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  88. IOMUX_PADS(PAD_NANDF_D7__NAND_DATA07 | MUX_PAD_CTRL(NO_PAD_CTRL)),
  89. };
  90. static void setup_gpmi_nand(void)
  91. {
  92. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  93. /* config gpmi nand iomux */
  94. SETUP_IOMUX_PADS(nfc_pads);
  95. /* config gpmi and bch clock to 100 MHz */
  96. clrsetbits_le32(&mxc_ccm->cs2cdr,
  97. MXC_CCM_CS2CDR_ENFC_CLK_PODF_MASK |
  98. MXC_CCM_CS2CDR_ENFC_CLK_PRED_MASK |
  99. MXC_CCM_CS2CDR_ENFC_CLK_SEL_MASK,
  100. MXC_CCM_CS2CDR_ENFC_CLK_PODF(0) |
  101. MXC_CCM_CS2CDR_ENFC_CLK_PRED(3) |
  102. MXC_CCM_CS2CDR_ENFC_CLK_SEL(3));
  103. /* enable gpmi and bch clock gating */
  104. setbits_le32(&mxc_ccm->CCGR4,
  105. MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
  106. MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
  107. MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
  108. MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
  109. MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_OFFSET);
  110. /* enable apbh clock gating */
  111. setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
  112. }
  113. #endif
  114. static void setup_iomux_enet(int gpio)
  115. {
  116. SETUP_IOMUX_PADS(enet_pads);
  117. /* toggle PHY_RST# */
  118. gpio_request(gpio, "phy_rst#");
  119. gpio_direction_output(gpio, 0);
  120. mdelay(10);
  121. gpio_set_value(gpio, 1);
  122. mdelay(100);
  123. }
  124. #ifdef CONFIG_USB_EHCI_MX6
  125. static iomux_v3_cfg_t const usb_pads[] = {
  126. IOMUX_PADS(PAD_GPIO_1__USB_OTG_ID | DIO_PAD_CFG),
  127. IOMUX_PADS(PAD_KEY_COL4__USB_OTG_OC | DIO_PAD_CFG),
  128. /* OTG PWR */
  129. IOMUX_PADS(PAD_EIM_D22__GPIO3_IO22 | DIO_PAD_CFG),
  130. };
  131. int board_ehci_hcd_init(int port)
  132. {
  133. int gpio;
  134. SETUP_IOMUX_PADS(usb_pads);
  135. /* Reset USB HUB */
  136. switch (board_type) {
  137. case GW53xx:
  138. case GW552x:
  139. gpio = (IMX_GPIO_NR(1, 9));
  140. break;
  141. case GW54proto:
  142. case GW54xx:
  143. gpio = (IMX_GPIO_NR(1, 16));
  144. break;
  145. default:
  146. return 0;
  147. }
  148. /* request and toggle hub rst */
  149. gpio_request(gpio, "usb_hub_rst#");
  150. gpio_direction_output(gpio, 0);
  151. mdelay(2);
  152. gpio_set_value(gpio, 1);
  153. return 0;
  154. }
  155. int board_ehci_power(int port, int on)
  156. {
  157. /* enable OTG VBUS */
  158. if (!port && board_type < GW_UNKNOWN) {
  159. if (gpio_cfg[board_type].otgpwr_en)
  160. gpio_set_value(gpio_cfg[board_type].otgpwr_en, on);
  161. }
  162. return 0;
  163. }
  164. #endif /* CONFIG_USB_EHCI_MX6 */
  165. #ifdef CONFIG_MXC_SPI
  166. iomux_v3_cfg_t const ecspi1_pads[] = {
  167. /* SS1 */
  168. IOMUX_PADS(PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(SPI_PAD_CTRL)),
  169. IOMUX_PADS(PAD_EIM_D17__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL)),
  170. IOMUX_PADS(PAD_EIM_D18__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL)),
  171. IOMUX_PADS(PAD_EIM_D16__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL)),
  172. };
  173. int board_spi_cs_gpio(unsigned bus, unsigned cs)
  174. {
  175. return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(3, 19)) : -1;
  176. }
  177. static void setup_spi(void)
  178. {
  179. gpio_request(IMX_GPIO_NR(3, 19), "spi_cs");
  180. gpio_direction_output(IMX_GPIO_NR(3, 19), 1);
  181. SETUP_IOMUX_PADS(ecspi1_pads);
  182. }
  183. #endif
  184. /* configure eth0 PHY board-specific LED behavior */
  185. int board_phy_config(struct phy_device *phydev)
  186. {
  187. unsigned short val;
  188. /* Marvel 88E1510 */
  189. if (phydev->phy_id == 0x1410dd1) {
  190. /*
  191. * Page 3, Register 16: LED[2:0] Function Control Register
  192. * LED[0] (SPD:Amber) R16_3.3:0 to 0111: on-GbE link
  193. * LED[1] (LNK:Green) R16_3.7:4 to 0001: on-link, blink-activity
  194. */
  195. phy_write(phydev, MDIO_DEVAD_NONE, 22, 3);
  196. val = phy_read(phydev, MDIO_DEVAD_NONE, 16);
  197. val &= 0xff00;
  198. val |= 0x0017;
  199. phy_write(phydev, MDIO_DEVAD_NONE, 16, val);
  200. phy_write(phydev, MDIO_DEVAD_NONE, 22, 0);
  201. }
  202. /* TI DP83867 */
  203. else if (phydev->phy_id == 0x2000a231) {
  204. /* configure register 0x170 for ref CLKOUT */
  205. phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x001f);
  206. phy_write(phydev, MDIO_DEVAD_NONE, 14, 0x0170);
  207. phy_write(phydev, MDIO_DEVAD_NONE, 13, 0x401f);
  208. val = phy_read(phydev, MDIO_DEVAD_NONE, 14);
  209. val &= ~0x1f00;
  210. val |= 0x0b00; /* chD tx clock*/
  211. phy_write(phydev, MDIO_DEVAD_NONE, 14, val);
  212. }
  213. if (phydev->drv->config)
  214. phydev->drv->config(phydev);
  215. return 0;
  216. }
  217. #ifdef CONFIG_MV88E61XX_SWITCH
  218. int mv88e61xx_hw_reset(struct phy_device *phydev)
  219. {
  220. struct mii_dev *bus = phydev->bus;
  221. /* GPIO[0] output, CLK125 */
  222. debug("enabling RGMII_REFCLK\n");
  223. bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
  224. 0x1a /*MV_SCRATCH_MISC*/,
  225. (1 << 15) | (0x62 /*MV_GPIO_DIR*/ << 8) | 0xfe);
  226. bus->write(bus, 0x1c /*MV_GLOBAL2*/, 0,
  227. 0x1a /*MV_SCRATCH_MISC*/,
  228. (1 << 15) | (0x68 /*MV_GPIO01_CNTL*/ << 8) | 7);
  229. /* RGMII delay - Physical Control register bit[15:14] */
  230. debug("setting port%d RGMII rx/tx delay\n", CONFIG_MV88E61XX_CPU_PORT);
  231. /* forced 1000mbps full-duplex link */
  232. bus->write(bus, 0x10 + CONFIG_MV88E61XX_CPU_PORT, 0, 1, 0xc0fe);
  233. phydev->autoneg = AUTONEG_DISABLE;
  234. phydev->speed = SPEED_1000;
  235. phydev->duplex = DUPLEX_FULL;
  236. /* LED configuration: 7:4-green (8=Activity) 3:0 amber (9=10Link) */
  237. bus->write(bus, 0x10, 0, 0x16, 0x8089);
  238. bus->write(bus, 0x11, 0, 0x16, 0x8089);
  239. bus->write(bus, 0x12, 0, 0x16, 0x8089);
  240. bus->write(bus, 0x13, 0, 0x16, 0x8089);
  241. return 0;
  242. }
  243. #endif // CONFIG_MV88E61XX_SWITCH
  244. int board_eth_init(bd_t *bis)
  245. {
  246. #ifdef CONFIG_FEC_MXC
  247. struct ventana_board_info *info = &ventana_info;
  248. if (test_bit(EECONFIG_ETH0, info->config)) {
  249. setup_iomux_enet(GP_PHY_RST);
  250. cpu_eth_init(bis);
  251. }
  252. #endif
  253. #ifdef CONFIG_E1000
  254. e1000_initialize(bis);
  255. #endif
  256. #ifdef CONFIG_CI_UDC
  257. /* For otg ethernet*/
  258. usb_eth_initialize(bis);
  259. #endif
  260. /* default to the first detected enet dev */
  261. if (!env_get("ethprime")) {
  262. struct eth_device *dev = eth_get_dev_by_index(0);
  263. if (dev) {
  264. env_set("ethprime", dev->name);
  265. printf("set ethprime to %s\n", env_get("ethprime"));
  266. }
  267. }
  268. return 0;
  269. }
  270. #if defined(CONFIG_VIDEO_IPUV3)
  271. static void enable_hdmi(struct display_info_t const *dev)
  272. {
  273. imx_enable_hdmi_phy();
  274. }
  275. static int detect_i2c(struct display_info_t const *dev)
  276. {
  277. return i2c_set_bus_num(dev->bus) == 0 &&
  278. i2c_probe(dev->addr) == 0;
  279. }
  280. static void enable_lvds(struct display_info_t const *dev)
  281. {
  282. struct iomuxc *iomux = (struct iomuxc *)
  283. IOMUXC_BASE_ADDR;
  284. /* set CH0 data width to 24bit (IOMUXC_GPR2:5 0=18bit, 1=24bit) */
  285. u32 reg = readl(&iomux->gpr[2]);
  286. reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_24BIT;
  287. writel(reg, &iomux->gpr[2]);
  288. /* Enable Backlight */
  289. gpio_request(IMX_GPIO_NR(1, 10), "bklt_gpio");
  290. gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
  291. gpio_request(IMX_GPIO_NR(1, 18), "bklt_en");
  292. SETUP_IOMUX_PAD(PAD_SD1_CMD__GPIO1_IO18 | DIO_PAD_CFG);
  293. gpio_direction_output(IMX_GPIO_NR(1, 18), 1);
  294. }
  295. struct display_info_t const displays[] = {{
  296. /* HDMI Output */
  297. .bus = -1,
  298. .addr = 0,
  299. .pixfmt = IPU_PIX_FMT_RGB24,
  300. .detect = detect_hdmi,
  301. .enable = enable_hdmi,
  302. .mode = {
  303. .name = "HDMI",
  304. .refresh = 60,
  305. .xres = 1024,
  306. .yres = 768,
  307. .pixclock = 15385,
  308. .left_margin = 220,
  309. .right_margin = 40,
  310. .upper_margin = 21,
  311. .lower_margin = 7,
  312. .hsync_len = 60,
  313. .vsync_len = 10,
  314. .sync = FB_SYNC_EXT,
  315. .vmode = FB_VMODE_NONINTERLACED
  316. } }, {
  317. /* Freescale MXC-LVDS1: HannStar HSD100PXN1-A00 w/ egalx_ts cont */
  318. .bus = 2,
  319. .addr = 0x4,
  320. .pixfmt = IPU_PIX_FMT_LVDS666,
  321. .detect = detect_i2c,
  322. .enable = enable_lvds,
  323. .mode = {
  324. .name = "Hannstar-XGA",
  325. .refresh = 60,
  326. .xres = 1024,
  327. .yres = 768,
  328. .pixclock = 15385,
  329. .left_margin = 220,
  330. .right_margin = 40,
  331. .upper_margin = 21,
  332. .lower_margin = 7,
  333. .hsync_len = 60,
  334. .vsync_len = 10,
  335. .sync = FB_SYNC_EXT,
  336. .vmode = FB_VMODE_NONINTERLACED
  337. } }, {
  338. /* DLC700JMG-T-4 */
  339. .bus = 0,
  340. .addr = 0,
  341. .detect = NULL,
  342. .enable = enable_lvds,
  343. .pixfmt = IPU_PIX_FMT_LVDS666,
  344. .mode = {
  345. .name = "DLC700JMGT4",
  346. .refresh = 60,
  347. .xres = 1024, /* 1024x600active pixels */
  348. .yres = 600,
  349. .pixclock = 15385, /* 64MHz */
  350. .left_margin = 220,
  351. .right_margin = 40,
  352. .upper_margin = 21,
  353. .lower_margin = 7,
  354. .hsync_len = 60,
  355. .vsync_len = 10,
  356. .sync = FB_SYNC_EXT,
  357. .vmode = FB_VMODE_NONINTERLACED
  358. } }, {
  359. /* DLC800FIG-T-3 */
  360. .bus = 0,
  361. .addr = 0,
  362. .detect = NULL,
  363. .enable = enable_lvds,
  364. .pixfmt = IPU_PIX_FMT_LVDS666,
  365. .mode = {
  366. .name = "DLC800FIGT3",
  367. .refresh = 60,
  368. .xres = 1024, /* 1024x768 active pixels */
  369. .yres = 768,
  370. .pixclock = 15385, /* 64MHz */
  371. .left_margin = 220,
  372. .right_margin = 40,
  373. .upper_margin = 21,
  374. .lower_margin = 7,
  375. .hsync_len = 60,
  376. .vsync_len = 10,
  377. .sync = FB_SYNC_EXT,
  378. .vmode = FB_VMODE_NONINTERLACED
  379. } } };
  380. size_t display_count = ARRAY_SIZE(displays);
  381. static void setup_display(void)
  382. {
  383. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  384. struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
  385. int reg;
  386. enable_ipu_clock();
  387. imx_setup_hdmi();
  388. /* Turn on LDB0,IPU,IPU DI0 clocks */
  389. reg = __raw_readl(&mxc_ccm->CCGR3);
  390. reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
  391. writel(reg, &mxc_ccm->CCGR3);
  392. /* set LDB0, LDB1 clk select to 011/011 */
  393. reg = readl(&mxc_ccm->cs2cdr);
  394. reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
  395. |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
  396. reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
  397. |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
  398. writel(reg, &mxc_ccm->cs2cdr);
  399. reg = readl(&mxc_ccm->cscmr2);
  400. reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
  401. writel(reg, &mxc_ccm->cscmr2);
  402. reg = readl(&mxc_ccm->chsccdr);
  403. reg |= (CHSCCDR_CLK_SEL_LDB_DI0
  404. <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
  405. writel(reg, &mxc_ccm->chsccdr);
  406. reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
  407. |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
  408. |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
  409. |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
  410. |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
  411. |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
  412. |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
  413. |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
  414. |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
  415. writel(reg, &iomux->gpr[2]);
  416. reg = readl(&iomux->gpr[3]);
  417. reg = (reg & ~IOMUXC_GPR3_LVDS0_MUX_CTL_MASK)
  418. | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
  419. <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
  420. writel(reg, &iomux->gpr[3]);
  421. /* LVDS Backlight GPIO on LVDS connector - output low */
  422. SETUP_IOMUX_PAD(PAD_SD2_CLK__GPIO1_IO10 | DIO_PAD_CFG);
  423. gpio_direction_output(IMX_GPIO_NR(1, 10), 0);
  424. }
  425. #endif /* CONFIG_VIDEO_IPUV3 */
  426. /* setup board specific PMIC */
  427. int power_init_board(void)
  428. {
  429. setup_pmic();
  430. return 0;
  431. }
  432. #if defined(CONFIG_CMD_PCI)
  433. int imx6_pcie_toggle_reset(void)
  434. {
  435. if (board_type < GW_UNKNOWN) {
  436. uint pin = gpio_cfg[board_type].pcie_rst;
  437. gpio_request(pin, "pci_rst#");
  438. gpio_direction_output(pin, 0);
  439. mdelay(50);
  440. gpio_direction_output(pin, 1);
  441. }
  442. return 0;
  443. }
  444. /*
  445. * Most Ventana boards have a PLX PEX860x PCIe switch onboard and use its
  446. * GPIO's as PERST# signals for its downstream ports - configure the GPIO's
  447. * properly and assert reset for 100ms.
  448. */
  449. #define MAX_PCI_DEVS 32
  450. struct pci_dev {
  451. pci_dev_t devfn;
  452. unsigned short vendor;
  453. unsigned short device;
  454. unsigned short class;
  455. unsigned short busno; /* subbordinate busno */
  456. struct pci_dev *ppar;
  457. };
  458. struct pci_dev pci_devs[MAX_PCI_DEVS];
  459. int pci_devno;
  460. int pci_bridgeno;
  461. void board_pci_fixup_dev(struct pci_controller *hose, pci_dev_t dev,
  462. unsigned short vendor, unsigned short device,
  463. unsigned short class)
  464. {
  465. int i;
  466. u32 dw;
  467. struct pci_dev *pdev = &pci_devs[pci_devno++];
  468. debug("%s: %02d:%02d.%02d: %04x:%04x\n", __func__,
  469. PCI_BUS(dev), PCI_DEV(dev), PCI_FUNC(dev), vendor, device);
  470. /* store array of devs for later use in device-tree fixup */
  471. pdev->devfn = dev;
  472. pdev->vendor = vendor;
  473. pdev->device = device;
  474. pdev->class = class;
  475. pdev->ppar = NULL;
  476. if (class == PCI_CLASS_BRIDGE_PCI)
  477. pdev->busno = ++pci_bridgeno;
  478. else
  479. pdev->busno = 0;
  480. /* fixup RC - it should be 00:00.0 not 00:01.0 */
  481. if (PCI_BUS(dev) == 0)
  482. pdev->devfn = 0;
  483. /* find dev's parent */
  484. for (i = 0; i < pci_devno; i++) {
  485. if (pci_devs[i].busno == PCI_BUS(pdev->devfn)) {
  486. pdev->ppar = &pci_devs[i];
  487. break;
  488. }
  489. }
  490. /* assert downstream PERST# */
  491. if (vendor == PCI_VENDOR_ID_PLX &&
  492. (device & 0xfff0) == 0x8600 &&
  493. PCI_DEV(dev) == 0 && PCI_FUNC(dev) == 0) {
  494. debug("configuring PLX 860X downstream PERST#\n");
  495. pci_hose_read_config_dword(hose, dev, 0x62c, &dw);
  496. dw |= 0xaaa8; /* GPIO1-7 outputs */
  497. pci_hose_write_config_dword(hose, dev, 0x62c, dw);
  498. pci_hose_read_config_dword(hose, dev, 0x644, &dw);
  499. dw |= 0xfe; /* GPIO1-7 output high */
  500. pci_hose_write_config_dword(hose, dev, 0x644, dw);
  501. mdelay(100);
  502. }
  503. }
  504. #endif /* CONFIG_CMD_PCI */
  505. #ifdef CONFIG_SERIAL_TAG
  506. /*
  507. * called when setting up ATAGS before booting kernel
  508. * populate serialnum from the following (in order of priority):
  509. * serial# env var
  510. * eeprom
  511. */
  512. void get_board_serial(struct tag_serialnr *serialnr)
  513. {
  514. char *serial = env_get("serial#");
  515. if (serial) {
  516. serialnr->high = 0;
  517. serialnr->low = simple_strtoul(serial, NULL, 10);
  518. } else if (ventana_info.model[0]) {
  519. serialnr->high = 0;
  520. serialnr->low = ventana_info.serial;
  521. } else {
  522. serialnr->high = 0;
  523. serialnr->low = 0;
  524. }
  525. }
  526. #endif
  527. /*
  528. * Board Support
  529. */
  530. int board_early_init_f(void)
  531. {
  532. setup_iomux_uart();
  533. #if defined(CONFIG_VIDEO_IPUV3)
  534. setup_display();
  535. #endif
  536. return 0;
  537. }
  538. int dram_init(void)
  539. {
  540. gd->ram_size = imx_ddr_size();
  541. return 0;
  542. }
  543. int board_init(void)
  544. {
  545. struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
  546. clrsetbits_le32(&iomuxc_regs->gpr[1],
  547. IOMUXC_GPR1_OTG_ID_MASK,
  548. IOMUXC_GPR1_OTG_ID_GPIO1);
  549. /* address of linux boot parameters */
  550. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  551. #ifdef CONFIG_CMD_NAND
  552. setup_gpmi_nand();
  553. #endif
  554. #ifdef CONFIG_MXC_SPI
  555. setup_spi();
  556. #endif
  557. setup_ventana_i2c();
  558. #ifdef CONFIG_SATA
  559. setup_sata();
  560. #endif
  561. /* read Gateworks EEPROM into global struct (used later) */
  562. board_type = read_eeprom(CONFIG_I2C_GSC, &ventana_info);
  563. setup_iomux_gpio(board_type, &ventana_info);
  564. return 0;
  565. }
  566. #if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
  567. /*
  568. * called during late init (after relocation and after board_init())
  569. * by virtue of CONFIG_DISPLAY_BOARDINFO_LATE as we needed i2c initialized and
  570. * EEPROM read.
  571. */
  572. int checkboard(void)
  573. {
  574. struct ventana_board_info *info = &ventana_info;
  575. unsigned char buf[4];
  576. const char *p;
  577. int quiet; /* Quiet or minimal output mode */
  578. quiet = 0;
  579. p = env_get("quiet");
  580. if (p)
  581. quiet = simple_strtol(p, NULL, 10);
  582. else
  583. env_set("quiet", "0");
  584. puts("\nGateworks Corporation Copyright 2014\n");
  585. if (info->model[0]) {
  586. printf("Model: %s\n", info->model);
  587. printf("MFGDate: %02x-%02x-%02x%02x\n",
  588. info->mfgdate[0], info->mfgdate[1],
  589. info->mfgdate[2], info->mfgdate[3]);
  590. printf("Serial:%d\n", info->serial);
  591. } else {
  592. puts("Invalid EEPROM - board will not function fully\n");
  593. }
  594. if (quiet)
  595. return 0;
  596. /* Display GSC firmware revision/CRC/status */
  597. gsc_info(0);
  598. /* Display RTC */
  599. if (!gsc_i2c_read(GSC_RTC_ADDR, 0x00, 1, buf, 4)) {
  600. printf("RTC: %d\n",
  601. buf[0] | buf[1]<<8 | buf[2]<<16 | buf[3]<<24);
  602. }
  603. return 0;
  604. }
  605. #endif
  606. #ifdef CONFIG_CMD_BMODE
  607. /*
  608. * BOOT_CFG1, BOOT_CFG2, BOOT_CFG3, BOOT_CFG4
  609. * see Table 8-11 and Table 5-9
  610. * BOOT_CFG1[7] = 1 (boot from NAND)
  611. * BOOT_CFG1[5] = 0 - raw NAND
  612. * BOOT_CFG1[4] = 0 - default pad settings
  613. * BOOT_CFG1[3:2] = 00 - devices = 1
  614. * BOOT_CFG1[1:0] = 00 - Row Address Cycles = 3
  615. * BOOT_CFG2[4:3] = 00 - Boot Search Count = 2
  616. * BOOT_CFG2[2:1] = 01 - Pages In Block = 64
  617. * BOOT_CFG2[0] = 0 - Reset time 12ms
  618. */
  619. static const struct boot_mode board_boot_modes[] = {
  620. /* NAND: 64pages per block, 3 row addr cycles, 2 copies of FCB/DBBT */
  621. { "nand", MAKE_CFGVAL(0x80, 0x02, 0x00, 0x00) },
  622. { "emmc2", MAKE_CFGVAL(0x60, 0x48, 0x00, 0x00) }, /* GW5600 */
  623. { "emmc3", MAKE_CFGVAL(0x60, 0x50, 0x00, 0x00) }, /* GW5903/GW5904 */
  624. { NULL, 0 },
  625. };
  626. #endif
  627. /* late init */
  628. int misc_init_r(void)
  629. {
  630. struct ventana_board_info *info = &ventana_info;
  631. char buf[256];
  632. int i;
  633. /* set env vars based on EEPROM data */
  634. if (ventana_info.model[0]) {
  635. char str[16], fdt[36];
  636. char *p;
  637. const char *cputype = "";
  638. /*
  639. * FDT name will be prefixed with CPU type. Three versions
  640. * will be created each increasingly generic and bootloader
  641. * env scripts will try loading each from most specific to
  642. * least.
  643. */
  644. if (is_cpu_type(MXC_CPU_MX6Q) ||
  645. is_cpu_type(MXC_CPU_MX6D))
  646. cputype = "imx6q";
  647. else if (is_cpu_type(MXC_CPU_MX6DL) ||
  648. is_cpu_type(MXC_CPU_MX6SOLO))
  649. cputype = "imx6dl";
  650. env_set("soctype", cputype);
  651. if (8 << (ventana_info.nand_flash_size-1) >= 2048)
  652. env_set("flash_layout", "large");
  653. else
  654. env_set("flash_layout", "normal");
  655. memset(str, 0, sizeof(str));
  656. for (i = 0; i < (sizeof(str)-1) && info->model[i]; i++)
  657. str[i] = tolower(info->model[i]);
  658. env_set("model", str);
  659. if (!env_get("fdt_file")) {
  660. sprintf(fdt, "%s-%s.dtb", cputype, str);
  661. env_set("fdt_file", fdt);
  662. }
  663. p = strchr(str, '-');
  664. if (p) {
  665. *p++ = 0;
  666. env_set("model_base", str);
  667. sprintf(fdt, "%s-%s.dtb", cputype, str);
  668. env_set("fdt_file1", fdt);
  669. if (board_type != GW551x &&
  670. board_type != GW552x &&
  671. board_type != GW553x &&
  672. board_type != GW560x)
  673. str[4] = 'x';
  674. str[5] = 'x';
  675. str[6] = 0;
  676. sprintf(fdt, "%s-%s.dtb", cputype, str);
  677. env_set("fdt_file2", fdt);
  678. }
  679. /* initialize env from EEPROM */
  680. if (test_bit(EECONFIG_ETH0, info->config) &&
  681. !env_get("ethaddr")) {
  682. eth_env_set_enetaddr("ethaddr", info->mac0);
  683. }
  684. if (test_bit(EECONFIG_ETH1, info->config) &&
  685. !env_get("eth1addr")) {
  686. eth_env_set_enetaddr("eth1addr", info->mac1);
  687. }
  688. /* board serial-number */
  689. sprintf(str, "%6d", info->serial);
  690. env_set("serial#", str);
  691. /* memory MB */
  692. sprintf(str, "%d", (int) (gd->ram_size >> 20));
  693. env_set("mem_mb", str);
  694. }
  695. /* Set a non-initialized hwconfig based on board configuration */
  696. if (!strcmp(env_get("hwconfig"), "_UNKNOWN_")) {
  697. buf[0] = 0;
  698. if (gpio_cfg[board_type].rs232_en)
  699. strcat(buf, "rs232;");
  700. for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
  701. char buf1[32];
  702. sprintf(buf1, "dio%d:mode=gpio;", i);
  703. if (strlen(buf) + strlen(buf1) < sizeof(buf))
  704. strcat(buf, buf1);
  705. }
  706. env_set("hwconfig", buf);
  707. }
  708. /* setup baseboard specific GPIO based on board and env */
  709. setup_board_gpio(board_type, info);
  710. #ifdef CONFIG_CMD_BMODE
  711. add_board_boot_modes(board_boot_modes);
  712. #endif
  713. /* disable boot watchdog */
  714. gsc_boot_wd_disable();
  715. return 0;
  716. }
  717. #ifdef CONFIG_OF_BOARD_SETUP
  718. static int ft_sethdmiinfmt(void *blob, char *mode)
  719. {
  720. int off;
  721. if (!mode)
  722. return -EINVAL;
  723. off = fdt_node_offset_by_compatible(blob, -1, "nxp,tda1997x");
  724. if (off < 0)
  725. return off;
  726. if (0 == strcasecmp(mode, "yuv422bt656")) {
  727. u8 cfg[] = { 0x00, 0x00, 0x00, 0x82, 0x81, 0x00,
  728. 0x00, 0x00, 0x00 };
  729. mode = "422_ccir";
  730. fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
  731. fdt_setprop_u32(blob, off, "vidout_trc", 1);
  732. fdt_setprop_u32(blob, off, "vidout_blc", 1);
  733. fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
  734. printf(" set HDMI input mode to %s\n", mode);
  735. } else if (0 == strcasecmp(mode, "yuv422smp")) {
  736. u8 cfg[] = { 0x00, 0x00, 0x00, 0x88, 0x87, 0x00,
  737. 0x82, 0x81, 0x00 };
  738. mode = "422_smp";
  739. fdt_setprop(blob, off, "vidout_fmt", mode, strlen(mode) + 1);
  740. fdt_setprop_u32(blob, off, "vidout_trc", 0);
  741. fdt_setprop_u32(blob, off, "vidout_blc", 0);
  742. fdt_setprop(blob, off, "vidout_portcfg", cfg, sizeof(cfg));
  743. printf(" set HDMI input mode to %s\n", mode);
  744. } else {
  745. return -EINVAL;
  746. }
  747. return 0;
  748. }
  749. /* enable a property of a node if the node is found */
  750. static inline void ft_enable_path(void *blob, const char *path)
  751. {
  752. int i = fdt_path_offset(blob, path);
  753. if (i >= 0) {
  754. debug("enabling %s\n", path);
  755. fdt_status_okay(blob, i);
  756. }
  757. }
  758. /* remove a property of a node if the node is found */
  759. static inline void ft_delprop_path(void *blob, const char *path,
  760. const char *name)
  761. {
  762. int i = fdt_path_offset(blob, path);
  763. if (i) {
  764. debug("removing %s/%s\n", path, name);
  765. fdt_delprop(blob, i, name);
  766. }
  767. }
  768. #if defined(CONFIG_CMD_PCI)
  769. #define PCI_ID(x) ( \
  770. (PCI_BUS(x->devfn)<<16)| \
  771. (PCI_DEV(x->devfn)<<11)| \
  772. (PCI_FUNC(x->devfn)<<8) \
  773. )
  774. #define PCIE_PATH "/soc/pcie@0x01000000"
  775. int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
  776. {
  777. uint32_t reg[5];
  778. char node[32];
  779. int np;
  780. sprintf(node, "pcie@%d,%d,%d", PCI_BUS(dev->devfn),
  781. PCI_DEV(dev->devfn), PCI_FUNC(dev->devfn));
  782. np = fdt_subnode_offset(blob, par, node);
  783. if (np >= 0)
  784. return np;
  785. np = fdt_add_subnode(blob, par, node);
  786. if (np < 0) {
  787. printf(" %s failed: no space\n", __func__);
  788. return np;
  789. }
  790. memset(reg, 0, sizeof(reg));
  791. reg[0] = cpu_to_fdt32(PCI_ID(dev));
  792. fdt_setprop(blob, np, "reg", reg, sizeof(reg));
  793. return np;
  794. }
  795. /* build a path of nested PCI devs for all bridges passed through */
  796. int fdt_add_pci_path(void *blob, struct pci_dev *dev)
  797. {
  798. struct pci_dev *bridges[MAX_PCI_DEVS];
  799. int k, np;
  800. /* build list of parents */
  801. np = fdt_path_offset(blob, PCIE_PATH);
  802. if (np < 0)
  803. return np;
  804. k = 0;
  805. while (dev) {
  806. bridges[k++] = dev;
  807. dev = dev->ppar;
  808. };
  809. /* now add them the to DT in reverse order */
  810. while (k--) {
  811. np = fdt_add_pci_node(blob, np, bridges[k]);
  812. if (np < 0)
  813. break;
  814. }
  815. return np;
  816. }
  817. /*
  818. * The GW16082 has a hardware errata errata such that it's
  819. * INTA/B/C/D are mis-mapped to its four slots (slot12-15). Because
  820. * of this normal PCI interrupt swizzling will not work so we will
  821. * provide an irq-map via device-tree.
  822. */
  823. int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
  824. {
  825. int len;
  826. int host;
  827. uint32_t imap_new[8*4*4];
  828. const uint32_t *imap;
  829. uint32_t irq[4];
  830. uint32_t reg[4];
  831. int i;
  832. /* build irq-map based on host controllers map */
  833. host = fdt_path_offset(blob, PCIE_PATH);
  834. if (host < 0) {
  835. printf(" %s failed: missing host\n", __func__);
  836. return host;
  837. }
  838. /* use interrupt data from root complex's node */
  839. imap = fdt_getprop(blob, host, "interrupt-map", &len);
  840. if (!imap || len != 128) {
  841. printf(" %s failed: invalid interrupt-map\n",
  842. __func__);
  843. return -FDT_ERR_NOTFOUND;
  844. }
  845. /* obtain irq's of host controller in pin order */
  846. for (i = 0; i < 4; i++)
  847. irq[(fdt32_to_cpu(imap[(i*8)+3])-1)%4] = imap[(i*8)+6];
  848. /*
  849. * determine number of swizzles necessary:
  850. * For each bridge we pass through we need to swizzle
  851. * the number of the slot we are on.
  852. */
  853. struct pci_dev *d;
  854. int b;
  855. b = 0;
  856. d = dev->ppar;
  857. while(d && d->ppar) {
  858. b += PCI_DEV(d->devfn);
  859. d = d->ppar;
  860. }
  861. /* create new irq mappings for slots12-15
  862. * <skt> <idsel> <slot> <skt-inta> <skt-intb>
  863. * J3 AD28 12 INTD INTA
  864. * J4 AD29 13 INTC INTD
  865. * J5 AD30 14 INTB INTC
  866. * J2 AD31 15 INTA INTB
  867. */
  868. for (i = 0; i < 4; i++) {
  869. /* addr matches bus:dev:func */
  870. u32 addr = dev->busno << 16 | (12+i) << 11;
  871. /* default cells from root complex */
  872. memcpy(&imap_new[i*32], imap, 128);
  873. /* first cell is PCI device address (BDF) */
  874. imap_new[(i*32)+(0*8)+0] = cpu_to_fdt32(addr);
  875. imap_new[(i*32)+(1*8)+0] = cpu_to_fdt32(addr);
  876. imap_new[(i*32)+(2*8)+0] = cpu_to_fdt32(addr);
  877. imap_new[(i*32)+(3*8)+0] = cpu_to_fdt32(addr);
  878. /* third cell is pin */
  879. imap_new[(i*32)+(0*8)+3] = cpu_to_fdt32(1);
  880. imap_new[(i*32)+(1*8)+3] = cpu_to_fdt32(2);
  881. imap_new[(i*32)+(2*8)+3] = cpu_to_fdt32(3);
  882. imap_new[(i*32)+(3*8)+3] = cpu_to_fdt32(4);
  883. /* sixth cell is relative interrupt */
  884. imap_new[(i*32)+(0*8)+6] = irq[(15-(12+i)+b+0)%4];
  885. imap_new[(i*32)+(1*8)+6] = irq[(15-(12+i)+b+1)%4];
  886. imap_new[(i*32)+(2*8)+6] = irq[(15-(12+i)+b+2)%4];
  887. imap_new[(i*32)+(3*8)+6] = irq[(15-(12+i)+b+3)%4];
  888. }
  889. fdt_setprop(blob, np, "interrupt-map", imap_new,
  890. sizeof(imap_new));
  891. reg[0] = cpu_to_fdt32(0xfff00);
  892. reg[1] = 0;
  893. reg[2] = 0;
  894. reg[3] = cpu_to_fdt32(0x7);
  895. fdt_setprop(blob, np, "interrupt-map-mask", reg, sizeof(reg));
  896. fdt_setprop_cell(blob, np, "#interrupt-cells", 1);
  897. fdt_setprop_string(blob, np, "device_type", "pci");
  898. fdt_setprop_cell(blob, np, "#address-cells", 3);
  899. fdt_setprop_cell(blob, np, "#size-cells", 2);
  900. printf(" Added custom interrupt-map for GW16082\n");
  901. return 0;
  902. }
  903. /* The sky2 GigE MAC obtains it's MAC addr from device-tree by default */
  904. int fdt_fixup_sky2(void *blob, int np, struct pci_dev *dev)
  905. {
  906. char *tmp, *end;
  907. char mac[16];
  908. unsigned char mac_addr[6];
  909. int j;
  910. sprintf(mac, "eth1addr");
  911. tmp = env_get(mac);
  912. if (tmp) {
  913. for (j = 0; j < 6; j++) {
  914. mac_addr[j] = tmp ?
  915. simple_strtoul(tmp, &end,16) : 0;
  916. if (tmp)
  917. tmp = (*end) ? end+1 : end;
  918. }
  919. fdt_setprop(blob, np, "local-mac-address", mac_addr,
  920. sizeof(mac_addr));
  921. printf(" Added mac addr for eth1\n");
  922. return 0;
  923. }
  924. return -1;
  925. }
  926. /*
  927. * PCI DT nodes must be nested therefore if we need to apply a DT fixup
  928. * we will walk the PCI bus and add bridge nodes up to the device receiving
  929. * the fixup.
  930. */
  931. void ft_board_pci_fixup(void *blob, bd_t *bd)
  932. {
  933. int i, np;
  934. struct pci_dev *dev;
  935. for (i = 0; i < pci_devno; i++) {
  936. dev = &pci_devs[i];
  937. /*
  938. * The GW16082 consists of a TI XIO2001 PCIe-to-PCI bridge and
  939. * an EEPROM at i2c1-0x50.
  940. */
  941. if ((dev->vendor == PCI_VENDOR_ID_TI) &&
  942. (dev->device == 0x8240) &&
  943. (i2c_set_bus_num(1) == 0) &&
  944. (i2c_probe(0x50) == 0))
  945. {
  946. np = fdt_add_pci_path(blob, dev);
  947. if (np > 0)
  948. fdt_fixup_gw16082(blob, np, dev);
  949. }
  950. /* ethernet1 mac address */
  951. else if ((dev->vendor == PCI_VENDOR_ID_MARVELL) &&
  952. (dev->device == 0x4380))
  953. {
  954. np = fdt_add_pci_path(blob, dev);
  955. if (np > 0)
  956. fdt_fixup_sky2(blob, np, dev);
  957. }
  958. }
  959. }
  960. #endif /* if defined(CONFIG_CMD_PCI) */
  961. void ft_board_wdog_fixup(void *blob, const char *path)
  962. {
  963. ft_delprop_path(blob, path, "ext-reset-output");
  964. ft_delprop_path(blob, path, "fsl,ext-reset-output");
  965. }
  966. /*
  967. * called prior to booting kernel or by 'fdt boardsetup' command
  968. *
  969. * unless 'fdt_noauto' env var is set we will update the following in the DTB:
  970. * - mtd partitions based on mtdparts/mtdids env
  971. * - system-serial (board serial num from EEPROM)
  972. * - board (full model from EEPROM)
  973. * - peripherals removed from DTB if not loaded on board (per EEPROM config)
  974. */
  975. #define UART1_PATH "/soc/aips-bus@02100000/serial@021ec000"
  976. #define WDOG1_PATH "/soc/aips-bus@02000000/wdog@020bc000"
  977. #define WDOG2_PATH "/soc/aips-bus@02000000/wdog@020c0000"
  978. #define GPIO3_PATH "/soc/aips-bus@02000000/gpio@020a4000"
  979. int ft_board_setup(void *blob, bd_t *bd)
  980. {
  981. struct ventana_board_info *info = &ventana_info;
  982. struct ventana_eeprom_config *cfg;
  983. struct node_info nodes[] = {
  984. { "sst,w25q256", MTD_DEV_TYPE_NOR, }, /* SPI flash */
  985. { "fsl,imx6q-gpmi-nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
  986. };
  987. const char *model = env_get("model");
  988. const char *display = env_get("display");
  989. int i;
  990. char rev = 0;
  991. /* determine board revision */
  992. for (i = sizeof(ventana_info.model) - 1; i > 0; i--) {
  993. if (ventana_info.model[i] >= 'A') {
  994. rev = ventana_info.model[i];
  995. break;
  996. }
  997. }
  998. if (env_get("fdt_noauto")) {
  999. puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
  1000. return 0;
  1001. }
  1002. if (test_bit(EECONFIG_NAND, info->config)) {
  1003. /* Update partition nodes using info from mtdparts env var */
  1004. puts(" Updating MTD partitions...\n");
  1005. fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
  1006. }
  1007. /* Update display timings from display env var */
  1008. if (display) {
  1009. if (fdt_fixup_display(blob, fdt_get_alias(blob, "lvds0"),
  1010. display) >= 0)
  1011. printf(" Set display timings for %s...\n", display);
  1012. }
  1013. printf(" Adjusting FDT per EEPROM for %s...\n", model);
  1014. /* board serial number */
  1015. fdt_setprop(blob, 0, "system-serial", env_get("serial#"),
  1016. strlen(env_get("serial#")) + 1);
  1017. /* board (model contains model from device-tree) */
  1018. fdt_setprop(blob, 0, "board", info->model,
  1019. strlen((const char *)info->model) + 1);
  1020. /* set desired digital video capture format */
  1021. ft_sethdmiinfmt(blob, env_get("hdmiinfmt"));
  1022. /*
  1023. * Board model specific fixups
  1024. */
  1025. switch (board_type) {
  1026. case GW51xx:
  1027. /*
  1028. * disable wdog node for GW51xx-A/B to work around
  1029. * errata causing wdog timer to be unreliable.
  1030. */
  1031. if (rev >= 'A' && rev < 'C') {
  1032. i = fdt_path_offset(blob, WDOG1_PATH);
  1033. if (i)
  1034. fdt_status_disabled(blob, i);
  1035. }
  1036. /* GW51xx-E adds WDOG1_B external reset */
  1037. if (rev < 'E')
  1038. ft_board_wdog_fixup(blob, WDOG1_PATH);
  1039. break;
  1040. case GW52xx:
  1041. /* GW522x Uses GPIO3_IO23 instead of GPIO1_IO29 */
  1042. if (info->model[4] == '2') {
  1043. u32 handle = 0;
  1044. u32 *range = NULL;
  1045. i = fdt_node_offset_by_compatible(blob, -1,
  1046. "fsl,imx6q-pcie");
  1047. if (i)
  1048. range = (u32 *)fdt_getprop(blob, i,
  1049. "reset-gpio", NULL);
  1050. if (range) {
  1051. i = fdt_path_offset(blob, GPIO3_PATH);
  1052. if (i)
  1053. handle = fdt_get_phandle(blob, i);
  1054. if (handle) {
  1055. range[0] = cpu_to_fdt32(handle);
  1056. range[1] = cpu_to_fdt32(23);
  1057. }
  1058. }
  1059. /* these have broken usd_vsel */
  1060. if (strstr((const char *)info->model, "SP318-B") ||
  1061. strstr((const char *)info->model, "SP331-B"))
  1062. gpio_cfg[board_type].usd_vsel = 0;
  1063. /* GW522x-B adds WDOG1_B external reset */
  1064. ft_board_wdog_fixup(blob, WDOG1_PATH);
  1065. }
  1066. /* GW520x-E adds WDOG1_B external reset */
  1067. else if (info->model[4] == '0' && rev < 'E')
  1068. ft_board_wdog_fixup(blob, WDOG1_PATH);
  1069. break;
  1070. case GW53xx:
  1071. /* GW53xx-E adds WDOG1_B external reset */
  1072. if (rev < 'E')
  1073. ft_board_wdog_fixup(blob, WDOG1_PATH);
  1074. break;
  1075. case GW54xx:
  1076. /*
  1077. * disable serial2 node for GW54xx for compatibility with older
  1078. * 3.10.x kernel that improperly had this node enabled in the DT
  1079. */
  1080. i = fdt_path_offset(blob, UART1_PATH);
  1081. if (i)
  1082. fdt_del_node(blob, i);
  1083. /* GW54xx-E adds WDOG2_B external reset */
  1084. if (rev < 'E')
  1085. ft_board_wdog_fixup(blob, WDOG2_PATH);
  1086. break;
  1087. case GW551x:
  1088. /*
  1089. * isolate CSI0_DATA_EN for GW551x-A to work around errata
  1090. * causing non functional digital video in (it is not hooked up)
  1091. */
  1092. if (rev == 'A') {
  1093. u32 *range = NULL;
  1094. int len;
  1095. const u32 *handle = NULL;
  1096. i = fdt_node_offset_by_compatible(blob, -1,
  1097. "fsl,imx-tda1997x-video");
  1098. if (i)
  1099. handle = fdt_getprop(blob, i, "pinctrl-0",
  1100. NULL);
  1101. if (handle)
  1102. i = fdt_node_offset_by_phandle(blob,
  1103. fdt32_to_cpu(*handle));
  1104. if (i)
  1105. range = (u32 *)fdt_getprop(blob, i, "fsl,pins",
  1106. &len);
  1107. if (range) {
  1108. len /= sizeof(u32);
  1109. for (i = 0; i < len; i += 6) {
  1110. u32 mux_reg = fdt32_to_cpu(range[i+0]);
  1111. u32 conf_reg = fdt32_to_cpu(range[i+1]);
  1112. /* mux PAD_CSI0_DATA_EN to GPIO */
  1113. if (is_cpu_type(MXC_CPU_MX6Q) &&
  1114. mux_reg == 0x260 &&
  1115. conf_reg == 0x630)
  1116. range[i+3] = cpu_to_fdt32(0x5);
  1117. else if (!is_cpu_type(MXC_CPU_MX6Q) &&
  1118. mux_reg == 0x08c &&
  1119. conf_reg == 0x3a0)
  1120. range[i+3] = cpu_to_fdt32(0x5);
  1121. }
  1122. fdt_setprop_inplace(blob, i, "fsl,pins", range,
  1123. len);
  1124. }
  1125. /* set BT656 video format */
  1126. ft_sethdmiinfmt(blob, "yuv422bt656");
  1127. }
  1128. /* GW551x-C adds WDOG1_B external reset */
  1129. if (rev < 'C')
  1130. ft_board_wdog_fixup(blob, WDOG1_PATH);
  1131. break;
  1132. }
  1133. /* Configure DIO */
  1134. for (i = 0; i < gpio_cfg[board_type].dio_num; i++) {
  1135. struct dio_cfg *cfg = &gpio_cfg[board_type].dio_cfg[i];
  1136. char arg[10];
  1137. sprintf(arg, "dio%d", i);
  1138. if (!hwconfig(arg))
  1139. continue;
  1140. if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
  1141. {
  1142. char path[48];
  1143. sprintf(path, "/soc/aips-bus@02000000/pwm@%08x",
  1144. 0x02080000 + (0x4000 * (cfg->pwm_param - 1)));
  1145. printf(" Enabling pwm%d for DIO%d\n",
  1146. cfg->pwm_param, i);
  1147. ft_enable_path(blob, path);
  1148. }
  1149. }
  1150. /* remove no-1-8-v if UHS-I support is present */
  1151. if (gpio_cfg[board_type].usd_vsel) {
  1152. debug("Enabling UHS-I support\n");
  1153. ft_delprop_path(blob, "/soc/aips-bus@02100000/usdhc@02198000",
  1154. "no-1-8-v");
  1155. }
  1156. #if defined(CONFIG_CMD_PCI)
  1157. if (!env_get("nopcifixup"))
  1158. ft_board_pci_fixup(blob, bd);
  1159. #endif
  1160. /*
  1161. * Peripheral Config:
  1162. * remove nodes by alias path if EEPROM config tells us the
  1163. * peripheral is not loaded on the board.
  1164. */
  1165. if (env_get("fdt_noconfig")) {
  1166. puts(" Skiping periperhal config (fdt_noconfig defined)\n");
  1167. return 0;
  1168. }
  1169. cfg = econfig;
  1170. while (cfg->name) {
  1171. if (!test_bit(cfg->bit, info->config)) {
  1172. fdt_del_node_and_alias(blob, cfg->dtalias ?
  1173. cfg->dtalias : cfg->name);
  1174. }
  1175. cfg++;
  1176. }
  1177. return 0;
  1178. }
  1179. #endif /* CONFIG_OF_BOARD_SETUP */
  1180. static struct mxc_serial_platdata ventana_mxc_serial_plat = {
  1181. .reg = (struct mxc_uart *)UART2_BASE,
  1182. };
  1183. U_BOOT_DEVICE(ventana_serial) = {
  1184. .name = "serial_mxc",
  1185. .platdata = &ventana_mxc_serial_plat,
  1186. };