igep00x0.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2010
  4. * ISEE 2007 SL, <www.iseebcn.com>
  5. */
  6. #include <common.h>
  7. #include <status_led.h>
  8. #include <dm.h>
  9. #include <ns16550.h>
  10. #include <twl4030.h>
  11. #include <netdev.h>
  12. #include <spl.h>
  13. #include <asm/gpio.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/mem.h>
  16. #include <asm/arch/mmc_host_def.h>
  17. #include <asm/arch/mux.h>
  18. #include <asm/arch/sys_proto.h>
  19. #include <linux/mtd/mtd.h>
  20. #include <linux/mtd/rawnand.h>
  21. #include <linux/mtd/onenand.h>
  22. #include <jffs2/load_kernel.h>
  23. #include <mtd_node.h>
  24. #include <fdt_support.h>
  25. #include "igep00x0.h"
  26. static const struct ns16550_platdata igep_serial = {
  27. .base = OMAP34XX_UART3,
  28. .reg_shift = 2,
  29. .clock = V_NS16550_CLK,
  30. .fcr = UART_FCR_DEFVAL,
  31. };
  32. U_BOOT_DEVICE(igep_uart) = {
  33. "ns16550_serial",
  34. &igep_serial
  35. };
  36. /*
  37. * Routine: get_board_revision
  38. * Description: GPIO_28 and GPIO_129 are used to read board and revision from
  39. * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from
  40. * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because
  41. * this functionality is shared by USB HOST.
  42. * Once USB reset is applied, U-boot configures these pins as input pullup to
  43. * detect board and revision:
  44. * IGEP0020-RF = 0b00
  45. * IGEP0020-RC = 0b01
  46. * IGEP0030-RG = 0b10
  47. * IGEP0030-RE = 0b11
  48. */
  49. static int get_board_revision(void)
  50. {
  51. int revision;
  52. gpio_request(IGEP0030_USB_TRANSCEIVER_RESET,
  53. "igep0030_usb_transceiver_reset");
  54. gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0);
  55. gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection");
  56. gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION);
  57. revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION);
  58. gpio_free(GPIO_IGEP00X0_BOARD_DETECTION);
  59. gpio_request(GPIO_IGEP00X0_REVISION_DETECTION,
  60. "igep00x0_revision_detection");
  61. gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION);
  62. revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION);
  63. gpio_free(GPIO_IGEP00X0_REVISION_DETECTION);
  64. gpio_free(IGEP0030_USB_TRANSCEIVER_RESET);
  65. return revision;
  66. }
  67. int onenand_board_init(struct mtd_info *mtd)
  68. {
  69. if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
  70. struct onenand_chip *this = mtd->priv;
  71. this->base = (void *)CONFIG_SYS_ONENAND_BASE;
  72. return 0;
  73. }
  74. return 1;
  75. }
  76. #if defined(CONFIG_CMD_NET)
  77. static void reset_net_chip(int gpio)
  78. {
  79. if (!gpio_request(gpio, "eth nrst")) {
  80. gpio_direction_output(gpio, 1);
  81. udelay(1);
  82. gpio_set_value(gpio, 0);
  83. udelay(40);
  84. gpio_set_value(gpio, 1);
  85. mdelay(10);
  86. }
  87. }
  88. /*
  89. * Routine: setup_net_chip
  90. * Description: Setting up the configuration GPMC registers specific to the
  91. * Ethernet hardware.
  92. */
  93. static void setup_net_chip(void)
  94. {
  95. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  96. static const u32 gpmc_lan_config[] = {
  97. NET_LAN9221_GPMC_CONFIG1,
  98. NET_LAN9221_GPMC_CONFIG2,
  99. NET_LAN9221_GPMC_CONFIG3,
  100. NET_LAN9221_GPMC_CONFIG4,
  101. NET_LAN9221_GPMC_CONFIG5,
  102. NET_LAN9221_GPMC_CONFIG6,
  103. };
  104. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
  105. CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
  106. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  107. writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  108. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  109. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  110. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  111. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  112. &ctrl_base->gpmc_nadv_ale);
  113. reset_net_chip(64);
  114. }
  115. int board_eth_init(bd_t *bis)
  116. {
  117. #ifdef CONFIG_SMC911X
  118. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  119. #else
  120. return 0;
  121. #endif
  122. }
  123. #else
  124. static inline void setup_net_chip(void) {}
  125. #endif
  126. #ifdef CONFIG_OF_BOARD_SETUP
  127. static int ft_enable_by_compatible(void *blob, char *compat, int enable)
  128. {
  129. int off = fdt_node_offset_by_compatible(blob, -1, compat);
  130. if (off < 0)
  131. return off;
  132. if (enable)
  133. fdt_status_okay(blob, off);
  134. else
  135. fdt_status_disabled(blob, off);
  136. return 0;
  137. }
  138. int ft_board_setup(void *blob, bd_t *bd)
  139. {
  140. #ifdef CONFIG_FDT_FIXUP_PARTITIONS
  141. static struct node_info nodes[] = {
  142. { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
  143. { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
  144. };
  145. fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
  146. #endif
  147. ft_enable_by_compatible(blob, "ti,omap2-nand",
  148. gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
  149. ft_enable_by_compatible(blob, "ti,omap2-onenand",
  150. gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
  151. return 0;
  152. }
  153. #endif
  154. void set_led(void)
  155. {
  156. switch (get_board_revision()) {
  157. case 0:
  158. case 1:
  159. gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led");
  160. gpio_direction_output(IGEP0020_GPIO_LED, 1);
  161. break;
  162. case 2:
  163. case 3:
  164. gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led");
  165. gpio_direction_output(IGEP0030_GPIO_LED, 0);
  166. break;
  167. default:
  168. /* Should not happen... */
  169. break;
  170. }
  171. }
  172. void set_boardname(void)
  173. {
  174. char rev[5] = { 'F','C','G','E', };
  175. int i = get_board_revision();
  176. rev[i+1] = 0;
  177. env_set("board_rev", rev + i);
  178. env_set("board_name", i < 2 ? "igep0020" : "igep0030");
  179. }
  180. /*
  181. * Routine: misc_init_r
  182. * Description: Configure board specific parts
  183. */
  184. int misc_init_r(void)
  185. {
  186. t2_t *t2_base = (t2_t *)T2_BASE;
  187. u32 pbias_lite;
  188. twl4030_power_init();
  189. /* set VSIM to 1.8V */
  190. twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
  191. TWL4030_PM_RECEIVER_VSIM_VSEL_18,
  192. TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
  193. TWL4030_PM_RECEIVER_DEV_GRP_P1);
  194. /* set up dual-voltage GPIOs to 1.8V */
  195. pbias_lite = readl(&t2_base->pbias_lite);
  196. pbias_lite &= ~PBIASLITEVMODE1;
  197. pbias_lite |= PBIASLITEPWRDNZ1;
  198. writel(pbias_lite, &t2_base->pbias_lite);
  199. if (get_cpu_family() == CPU_OMAP36XX)
  200. writel(readl(OMAP34XX_CTRL_WKUP_CTRL) |
  201. OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
  202. OMAP34XX_CTRL_WKUP_CTRL);
  203. setup_net_chip();
  204. omap_die_id_display();
  205. set_led();
  206. set_boardname();
  207. return 0;
  208. }
  209. void board_mtdparts_default(const char **mtdids, const char **mtdparts)
  210. {
  211. struct mtd_info *mtd = get_mtd_device(NULL, 0);
  212. if (mtd) {
  213. static char ids[24];
  214. static char parts[48];
  215. const char *linux_name = "omap2-nand";
  216. if (strncmp(mtd->name, "onenand0", 8) == 0)
  217. linux_name = "omap2-onenand";
  218. snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
  219. snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
  220. linux_name, 4 * mtd->erasesize >> 10);
  221. *mtdids = ids;
  222. *mtdparts = parts;
  223. }
  224. }