igep00x0.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * (C) Copyright 2010
  3. * ISEE 2007 SL, <www.iseebcn.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <status_led.h>
  9. #include <dm.h>
  10. #include <ns16550.h>
  11. #include <twl4030.h>
  12. #include <netdev.h>
  13. #include <spl.h>
  14. #include <asm/gpio.h>
  15. #include <asm/io.h>
  16. #include <asm/arch/mem.h>
  17. #include <asm/arch/mmc_host_def.h>
  18. #include <asm/arch/mux.h>
  19. #include <asm/arch/sys_proto.h>
  20. #include <asm/mach-types.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/nand.h>
  23. #include <linux/mtd/nand.h>
  24. #include <linux/mtd/onenand.h>
  25. #include <jffs2/load_kernel.h>
  26. #include "igep00x0.h"
  27. DECLARE_GLOBAL_DATA_PTR;
  28. static const struct ns16550_platdata igep_serial = {
  29. .base = OMAP34XX_UART3,
  30. .reg_shift = 2,
  31. .clock = V_NS16550_CLK,
  32. .fcr = UART_FCR_DEFVAL,
  33. };
  34. U_BOOT_DEVICE(igep_uart) = {
  35. "ns16550_serial",
  36. &igep_serial
  37. };
  38. /*
  39. * Routine: board_init
  40. * Description: Early hardware init.
  41. */
  42. int board_init(void)
  43. {
  44. int loops = 100;
  45. /* find out flash memory type, assume NAND first */
  46. gpmc_cs0_flash = MTD_DEV_TYPE_NAND;
  47. gpmc_init();
  48. /* Issue a RESET and then READID */
  49. writeb(NAND_CMD_RESET, &gpmc_cfg->cs[0].nand_cmd);
  50. writeb(NAND_CMD_STATUS, &gpmc_cfg->cs[0].nand_cmd);
  51. while ((readl(&gpmc_cfg->cs[0].nand_dat) & NAND_STATUS_READY)
  52. != NAND_STATUS_READY) {
  53. udelay(1);
  54. if (--loops == 0) {
  55. gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND;
  56. gpmc_init(); /* reinitialize for OneNAND */
  57. break;
  58. }
  59. }
  60. /* boot param addr */
  61. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  62. #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
  63. status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
  64. #endif
  65. return 0;
  66. }
  67. #ifdef CONFIG_SPL_BUILD
  68. /*
  69. * Routine: get_board_mem_timings
  70. * Description: If we use SPL then there is no x-loader nor config header
  71. * so we have to setup the DDR timings ourself on both banks.
  72. */
  73. void get_board_mem_timings(struct board_sdrc_timings *timings)
  74. {
  75. int mfr, id, err = identify_nand_chip(&mfr, &id);
  76. timings->mr = MICRON_V_MR_165;
  77. if (!err) {
  78. switch (mfr) {
  79. case NAND_MFR_HYNIX:
  80. timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
  81. timings->ctrla = HYNIX_V_ACTIMA_200;
  82. timings->ctrlb = HYNIX_V_ACTIMB_200;
  83. break;
  84. case NAND_MFR_MICRON:
  85. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  86. timings->ctrla = MICRON_V_ACTIMA_200;
  87. timings->ctrlb = MICRON_V_ACTIMB_200;
  88. break;
  89. default:
  90. /* Should not happen... */
  91. break;
  92. }
  93. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  94. gpmc_cs0_flash = MTD_DEV_TYPE_NAND;
  95. } else {
  96. if (get_cpu_family() == CPU_OMAP34XX) {
  97. timings->mcfg = NUMONYX_V_MCFG_165(256 << 20);
  98. timings->ctrla = NUMONYX_V_ACTIMA_165;
  99. timings->ctrlb = NUMONYX_V_ACTIMB_165;
  100. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  101. } else {
  102. timings->mcfg = NUMONYX_V_MCFG_200(256 << 20);
  103. timings->ctrla = NUMONYX_V_ACTIMA_200;
  104. timings->ctrlb = NUMONYX_V_ACTIMB_200;
  105. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  106. }
  107. gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND;
  108. }
  109. }
  110. #ifdef CONFIG_SPL_OS_BOOT
  111. int spl_start_uboot(void)
  112. {
  113. /* break into full u-boot on 'c' */
  114. if (serial_tstc() && serial_getc() == 'c')
  115. return 1;
  116. return 0;
  117. }
  118. #endif
  119. #endif
  120. int onenand_board_init(struct mtd_info *mtd)
  121. {
  122. if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
  123. struct onenand_chip *this = mtd->priv;
  124. this->base = (void *)CONFIG_SYS_ONENAND_BASE;
  125. return 0;
  126. }
  127. return 1;
  128. }
  129. #if defined(CONFIG_CMD_NET)
  130. static void reset_net_chip(int gpio)
  131. {
  132. if (!gpio_request(gpio, "eth nrst")) {
  133. gpio_direction_output(gpio, 1);
  134. udelay(1);
  135. gpio_set_value(gpio, 0);
  136. udelay(40);
  137. gpio_set_value(gpio, 1);
  138. mdelay(10);
  139. }
  140. }
  141. /*
  142. * Routine: setup_net_chip
  143. * Description: Setting up the configuration GPMC registers specific to the
  144. * Ethernet hardware.
  145. */
  146. static void setup_net_chip(void)
  147. {
  148. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  149. static const u32 gpmc_lan_config[] = {
  150. NET_LAN9221_GPMC_CONFIG1,
  151. NET_LAN9221_GPMC_CONFIG2,
  152. NET_LAN9221_GPMC_CONFIG3,
  153. NET_LAN9221_GPMC_CONFIG4,
  154. NET_LAN9221_GPMC_CONFIG5,
  155. NET_LAN9221_GPMC_CONFIG6,
  156. };
  157. enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
  158. CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
  159. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  160. writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  161. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  162. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  163. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  164. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  165. &ctrl_base->gpmc_nadv_ale);
  166. reset_net_chip(64);
  167. }
  168. int board_eth_init(bd_t *bis)
  169. {
  170. #ifdef CONFIG_SMC911X
  171. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  172. #else
  173. return 0;
  174. #endif
  175. }
  176. #else
  177. static inline void setup_net_chip(void) {}
  178. #endif
  179. #if defined(CONFIG_GENERIC_MMC)
  180. int board_mmc_init(bd_t *bis)
  181. {
  182. return omap_mmc_init(0, 0, 0, -1, -1);
  183. }
  184. #endif
  185. #if defined(CONFIG_GENERIC_MMC)
  186. void board_mmc_power_init(void)
  187. {
  188. twl4030_power_mmc_init(0);
  189. }
  190. #endif
  191. void set_fdt(void)
  192. {
  193. switch (gd->bd->bi_arch_number) {
  194. case MACH_TYPE_IGEP0020:
  195. setenv("fdtfile", "omap3-igep0020.dtb");
  196. break;
  197. case MACH_TYPE_IGEP0030:
  198. setenv("fdtfile", "omap3-igep0030.dtb");
  199. break;
  200. }
  201. }
  202. /*
  203. * Routine: misc_init_r
  204. * Description: Configure board specific parts
  205. */
  206. int misc_init_r(void)
  207. {
  208. twl4030_power_init();
  209. setup_net_chip();
  210. omap_die_id_display();
  211. set_fdt();
  212. return 0;
  213. }
  214. void board_mtdparts_default(const char **mtdids, const char **mtdparts)
  215. {
  216. struct mtd_info *mtd = get_mtd_device(NULL, 0);
  217. if (mtd) {
  218. static char ids[24];
  219. static char parts[48];
  220. const char *linux_name = "omap2-nand";
  221. if (strncmp(mtd->name, "onenand0", 8) == 0)
  222. linux_name = "omap2-onenand";
  223. snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
  224. snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
  225. linux_name, 4 * mtd->erasesize >> 10);
  226. *mtdids = ids;
  227. *mtdparts = parts;
  228. }
  229. }
  230. /*
  231. * Routine: set_muxconf_regs
  232. * Description: Setting up the configuration Mux registers specific to the
  233. * hardware. Many pins need to be moved from protect to primary
  234. * mode.
  235. */
  236. void set_muxconf_regs(void)
  237. {
  238. MUX_DEFAULT();
  239. #if (CONFIG_MACH_TYPE == MACH_TYPE_IGEP0020)
  240. MUX_IGEP0020();
  241. #endif
  242. #if (CONFIG_MACH_TYPE == MACH_TYPE_IGEP0030)
  243. MUX_IGEP0030();
  244. #endif
  245. }