dh_imx6.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * DHCOM DH-iMX6 PDK board support
  3. *
  4. * Copyright (C) 2017 Marek Vasut <marex@denx.de>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/arch/clock.h>
  10. #include <asm/arch/crm_regs.h>
  11. #include <asm/arch/imx-regs.h>
  12. #include <asm/arch/iomux.h>
  13. #include <asm/arch/mx6-pins.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/gpio.h>
  16. #include <asm/io.h>
  17. #include <asm/mach-imx/boot_mode.h>
  18. #include <asm/mach-imx/iomux-v3.h>
  19. #include <asm/mach-imx/mxc_i2c.h>
  20. #include <asm/mach-imx/sata.h>
  21. #include <errno.h>
  22. #include <fsl_esdhc.h>
  23. #include <fuse.h>
  24. #include <i2c.h>
  25. #include <miiphy.h>
  26. #include <mmc.h>
  27. #include <net.h>
  28. #include <netdev.h>
  29. #include <usb.h>
  30. #include <usb/ehci-ci.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. #define I2C_PAD_CTRL \
  33. (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
  34. PAD_CTL_HYS | PAD_CTL_ODE | PAD_CTL_SRE_FAST)
  35. #define EEPROM_I2C_ADDRESS 0x50
  36. #define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
  37. static struct i2c_pads_info dh6sdl_i2c_pad_info0 = {
  38. .scl = {
  39. .i2c_mode = MX6DL_PAD_EIM_D21__I2C1_SCL | PC,
  40. .gpio_mode = MX6DL_PAD_EIM_D21__GPIO3_IO21 | PC,
  41. .gp = IMX_GPIO_NR(3, 21)
  42. },
  43. .sda = {
  44. .i2c_mode = MX6DL_PAD_EIM_D28__I2C1_SDA | PC,
  45. .gpio_mode = MX6DL_PAD_EIM_D28__GPIO3_IO28 | PC,
  46. .gp = IMX_GPIO_NR(3, 28)
  47. }
  48. };
  49. static struct i2c_pads_info dh6sdl_i2c_pad_info1 = {
  50. .scl = {
  51. .i2c_mode = MX6DL_PAD_KEY_COL3__I2C2_SCL | PC,
  52. .gpio_mode = MX6DL_PAD_KEY_COL3__GPIO4_IO12 | PC,
  53. .gp = IMX_GPIO_NR(4, 12)
  54. },
  55. .sda = {
  56. .i2c_mode = MX6DL_PAD_KEY_ROW3__I2C2_SDA | PC,
  57. .gpio_mode = MX6DL_PAD_KEY_ROW3__GPIO4_IO13 | PC,
  58. .gp = IMX_GPIO_NR(4, 13)
  59. }
  60. };
  61. static struct i2c_pads_info dh6sdl_i2c_pad_info2 = {
  62. .scl = {
  63. .i2c_mode = MX6DL_PAD_GPIO_3__I2C3_SCL | PC,
  64. .gpio_mode = MX6DL_PAD_GPIO_3__GPIO1_IO03 | PC,
  65. .gp = IMX_GPIO_NR(1, 3)
  66. },
  67. .sda = {
  68. .i2c_mode = MX6DL_PAD_GPIO_6__I2C3_SDA | PC,
  69. .gpio_mode = MX6DL_PAD_GPIO_6__GPIO1_IO06 | PC,
  70. .gp = IMX_GPIO_NR(1, 6)
  71. }
  72. };
  73. static struct i2c_pads_info dh6dq_i2c_pad_info0 = {
  74. .scl = {
  75. .i2c_mode = MX6Q_PAD_EIM_D21__I2C1_SCL | PC,
  76. .gpio_mode = MX6Q_PAD_EIM_D21__GPIO3_IO21 | PC,
  77. .gp = IMX_GPIO_NR(3, 21)
  78. },
  79. .sda = {
  80. .i2c_mode = MX6Q_PAD_EIM_D28__I2C1_SDA | PC,
  81. .gpio_mode = MX6Q_PAD_EIM_D28__GPIO3_IO28 | PC,
  82. .gp = IMX_GPIO_NR(3, 28)
  83. }
  84. };
  85. static struct i2c_pads_info dh6dq_i2c_pad_info1 = {
  86. .scl = {
  87. .i2c_mode = MX6Q_PAD_KEY_COL3__I2C2_SCL | PC,
  88. .gpio_mode = MX6Q_PAD_KEY_COL3__GPIO4_IO12 | PC,
  89. .gp = IMX_GPIO_NR(4, 12)
  90. },
  91. .sda = {
  92. .i2c_mode = MX6Q_PAD_KEY_ROW3__I2C2_SDA | PC,
  93. .gpio_mode = MX6Q_PAD_KEY_ROW3__GPIO4_IO13 | PC,
  94. .gp = IMX_GPIO_NR(4, 13)
  95. }
  96. };
  97. static struct i2c_pads_info dh6dq_i2c_pad_info2 = {
  98. .scl = {
  99. .i2c_mode = MX6Q_PAD_GPIO_3__I2C3_SCL | PC,
  100. .gpio_mode = MX6Q_PAD_GPIO_3__GPIO1_IO03 | PC,
  101. .gp = IMX_GPIO_NR(1, 3)
  102. },
  103. .sda = {
  104. .i2c_mode = MX6Q_PAD_GPIO_6__I2C3_SDA | PC,
  105. .gpio_mode = MX6Q_PAD_GPIO_6__GPIO1_IO06 | PC,
  106. .gp = IMX_GPIO_NR(1, 6)
  107. }
  108. };
  109. int dram_init(void)
  110. {
  111. gd->ram_size = imx_ddr_size();
  112. return 0;
  113. }
  114. /*
  115. * Do not overwrite the console
  116. * Use always serial for U-Boot console
  117. */
  118. int overwrite_console(void)
  119. {
  120. return 1;
  121. }
  122. #ifdef CONFIG_FEC_MXC
  123. static void eth_phy_reset(void)
  124. {
  125. /* Reset PHY */
  126. gpio_direction_output(IMX_GPIO_NR(5, 0) , 0);
  127. udelay(500);
  128. gpio_set_value(IMX_GPIO_NR(5, 0), 1);
  129. /* Enable VIO */
  130. gpio_direction_output(IMX_GPIO_NR(1, 7) , 0);
  131. /*
  132. * KSZ9021 PHY needs at least 10 mSec after PHY reset
  133. * is released to stabilize
  134. */
  135. mdelay(10);
  136. }
  137. static int setup_fec_clock(void)
  138. {
  139. struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
  140. /* set gpr1[21] to select anatop clock */
  141. clrsetbits_le32(&iomuxc_regs->gpr[1], 0x1 << 21, 0x1 << 21);
  142. return enable_fec_anatop_clock(0, ENET_50MHZ);
  143. }
  144. int board_eth_init(bd_t *bis)
  145. {
  146. uint32_t base = IMX_FEC_BASE;
  147. struct mii_dev *bus = NULL;
  148. struct phy_device *phydev = NULL;
  149. setup_fec_clock();
  150. eth_phy_reset();
  151. bus = fec_get_miibus(base, -1);
  152. if (!bus)
  153. return -EINVAL;
  154. /* Scan PHY 0 */
  155. phydev = phy_find_by_mask(bus, 0xf, PHY_INTERFACE_MODE_RGMII);
  156. if (!phydev) {
  157. printf("Ethernet PHY not found!\n");
  158. return -EINVAL;
  159. }
  160. return fec_probe(bis, -1, base, bus, phydev);
  161. }
  162. #endif
  163. #ifdef CONFIG_FSL_ESDHC
  164. #define USDHC2_CD_GPIO IMX_GPIO_NR(6, 16)
  165. #define USDHC3_CD_GPIO IMX_GPIO_NR(7, 8)
  166. static struct fsl_esdhc_cfg usdhc_cfg[3] = {
  167. { USDHC2_BASE_ADDR },
  168. { USDHC3_BASE_ADDR },
  169. { USDHC4_BASE_ADDR },
  170. };
  171. int board_mmc_getcd(struct mmc *mmc)
  172. {
  173. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  174. switch (cfg->esdhc_base) {
  175. case USDHC2_BASE_ADDR:
  176. return gpio_get_value(USDHC2_CD_GPIO);
  177. case USDHC3_BASE_ADDR:
  178. return !gpio_get_value(USDHC3_CD_GPIO);
  179. case USDHC4_BASE_ADDR:
  180. return 1; /* eMMC/uSDHC4 is always present */
  181. }
  182. return 0;
  183. }
  184. int board_mmc_init(bd_t *bis)
  185. {
  186. int i, ret;
  187. /*
  188. * According to the board_mmc_init() the following map is done:
  189. * (U-Boot device node) (Physical Port)
  190. * mmc0 SD interface
  191. * mmc1 micro SD
  192. * mmc2 eMMC
  193. */
  194. gpio_direction_input(USDHC2_CD_GPIO);
  195. gpio_direction_input(USDHC3_CD_GPIO);
  196. usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
  197. usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
  198. usdhc_cfg[2].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
  199. for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
  200. ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
  201. if (ret)
  202. return ret;
  203. }
  204. return 0;
  205. }
  206. #endif
  207. #ifdef CONFIG_USB_EHCI_MX6
  208. static void setup_usb(void)
  209. {
  210. /*
  211. * Set daisy chain for otg_pin_id on MX6Q.
  212. * For MX6DL, this bit is reserved.
  213. */
  214. imx_iomux_set_gpr_register(1, 13, 1, 0);
  215. }
  216. int board_usb_phy_mode(int port)
  217. {
  218. return USB_INIT_HOST;
  219. }
  220. /* Use only Port 1 == DHCOM USB Host 1 */
  221. int board_ehci_hcd_init(int port)
  222. {
  223. if (port == 1)
  224. return 0;
  225. else
  226. return -ENODEV;
  227. }
  228. int board_ehci_power(int port, int on)
  229. {
  230. switch (port) {
  231. case 0:
  232. break;
  233. case 1:
  234. gpio_direction_output(IMX_GPIO_NR(3, 31), !!on);
  235. break;
  236. default:
  237. printf("MXC USB port %d not yet supported\n", port);
  238. return -EINVAL;
  239. }
  240. return 0;
  241. }
  242. #endif
  243. static int setup_dhcom_mac_from_fuse(void)
  244. {
  245. unsigned char enetaddr[6];
  246. int ret;
  247. ret = eth_env_get_enetaddr("ethaddr", enetaddr);
  248. if (ret) /* ethaddr is already set */
  249. return 0;
  250. imx_get_mac_from_fuse(0, enetaddr);
  251. if (is_valid_ethaddr(enetaddr)) {
  252. eth_env_set_enetaddr("ethaddr", enetaddr);
  253. return 0;
  254. }
  255. ret = i2c_set_bus_num(2);
  256. if (ret) {
  257. printf("Error switching I2C bus!\n");
  258. return ret;
  259. }
  260. ret = i2c_read(EEPROM_I2C_ADDRESS, 0xfa, 0x1, enetaddr, 0x6);
  261. if (ret) {
  262. printf("Error reading configuration EEPROM!\n");
  263. return ret;
  264. }
  265. if (is_valid_ethaddr(enetaddr))
  266. eth_env_set_enetaddr("ethaddr", enetaddr);
  267. return 0;
  268. }
  269. int board_early_init_f(void)
  270. {
  271. #ifdef CONFIG_USB_EHCI_MX6
  272. setup_usb();
  273. #endif
  274. return 0;
  275. }
  276. #ifdef CONFIG_MXC_SPI
  277. int board_spi_cs_gpio(unsigned bus, unsigned cs)
  278. {
  279. if (bus == 0 && cs == 0)
  280. return IMX_GPIO_NR(2, 30);
  281. else
  282. return -1;
  283. }
  284. #endif
  285. int board_init(void)
  286. {
  287. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  288. /* address of boot parameters */
  289. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  290. /* Enable eim_slow clocks */
  291. setbits_le32(&mxc_ccm->CCGR6, 0x1 << MXC_CCM_CCGR6_EMI_SLOW_OFFSET);
  292. #ifdef CONFIG_SYS_I2C_MXC
  293. if (is_mx6dq()) {
  294. setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6dq_i2c_pad_info0);
  295. setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6dq_i2c_pad_info1);
  296. setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6dq_i2c_pad_info2);
  297. } else {
  298. setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6sdl_i2c_pad_info0);
  299. setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6sdl_i2c_pad_info1);
  300. setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &dh6sdl_i2c_pad_info2);
  301. }
  302. #endif
  303. #ifdef CONFIG_SATA
  304. setup_sata();
  305. #endif
  306. setup_dhcom_mac_from_fuse();
  307. return 0;
  308. }
  309. #ifdef CONFIG_CMD_BMODE
  310. static const struct boot_mode board_boot_modes[] = {
  311. /* 4 bit bus width */
  312. {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
  313. {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
  314. /* 8 bit bus width */
  315. {"emmc", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
  316. {NULL, 0},
  317. };
  318. #endif
  319. #define HW_CODE_BIT_0 IMX_GPIO_NR(2, 19)
  320. #define HW_CODE_BIT_1 IMX_GPIO_NR(6, 6)
  321. #define HW_CODE_BIT_2 IMX_GPIO_NR(2, 16)
  322. static int board_get_hwcode(void)
  323. {
  324. int hw_code;
  325. gpio_direction_input(HW_CODE_BIT_0);
  326. gpio_direction_input(HW_CODE_BIT_1);
  327. gpio_direction_input(HW_CODE_BIT_2);
  328. /* HW 100 + HW 200 = 00b; HW 300 = 01b */
  329. hw_code = ((gpio_get_value(HW_CODE_BIT_2) << 2) |
  330. (gpio_get_value(HW_CODE_BIT_1) << 1) |
  331. gpio_get_value(HW_CODE_BIT_0)) + 2;
  332. return hw_code;
  333. }
  334. int board_late_init(void)
  335. {
  336. u32 hw_code;
  337. char buf[16];
  338. hw_code = board_get_hwcode();
  339. switch (get_cpu_type()) {
  340. case MXC_CPU_MX6SOLO:
  341. snprintf(buf, sizeof(buf), "imx6s-dhcom%1d", hw_code);
  342. break;
  343. case MXC_CPU_MX6DL:
  344. snprintf(buf, sizeof(buf), "imx6dl-dhcom%1d", hw_code);
  345. break;
  346. case MXC_CPU_MX6D:
  347. snprintf(buf, sizeof(buf), "imx6d-dhcom%1d", hw_code);
  348. break;
  349. case MXC_CPU_MX6Q:
  350. snprintf(buf, sizeof(buf), "imx6q-dhcom%1d", hw_code);
  351. break;
  352. default:
  353. snprintf(buf, sizeof(buf), "UNKNOWN%1d", hw_code);
  354. break;
  355. }
  356. env_set("dhcom", buf);
  357. #ifdef CONFIG_CMD_BMODE
  358. add_board_boot_modes(board_boot_modes);
  359. #endif
  360. return 0;
  361. }
  362. int checkboard(void)
  363. {
  364. puts("Board: DHCOM i.MX6\n");
  365. return 0;
  366. }