hwinit-common.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. *
  3. * Common functions for OMAP4/5 based boards
  4. *
  5. * (C) Copyright 2010
  6. * Texas Instruments, <www.ti.com>
  7. *
  8. * Author :
  9. * Aneesh V <aneesh@ti.com>
  10. * Steve Sakoman <steve@sakoman.com>
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <common.h>
  31. #include <spl.h>
  32. #include <asm/arch/sys_proto.h>
  33. #include <asm/sizes.h>
  34. #include <asm/emif.h>
  35. #include <asm/omap_common.h>
  36. #include <linux/compiler.h>
  37. #include <asm/cache.h>
  38. #include <asm/system.h>
  39. #define ARMV7_DCACHE_WRITEBACK 0xe
  40. #define ARMV7_DOMAIN_CLIENT 1
  41. #define ARMV7_DOMAIN_MASK (0x3 << 0)
  42. DECLARE_GLOBAL_DATA_PTR;
  43. void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
  44. {
  45. int i;
  46. struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
  47. for (i = 0; i < size; i++, pad++)
  48. writew(pad->val, base + pad->offset);
  49. }
  50. static void set_mux_conf_regs(void)
  51. {
  52. switch (omap_hw_init_context()) {
  53. case OMAP_INIT_CONTEXT_SPL:
  54. set_muxconf_regs_essential();
  55. break;
  56. case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
  57. #ifdef CONFIG_SYS_ENABLE_PADS_ALL
  58. set_muxconf_regs_non_essential();
  59. #endif
  60. break;
  61. case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
  62. case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
  63. set_muxconf_regs_essential();
  64. #ifdef CONFIG_SYS_ENABLE_PADS_ALL
  65. set_muxconf_regs_non_essential();
  66. #endif
  67. break;
  68. }
  69. }
  70. u32 cortex_rev(void)
  71. {
  72. unsigned int rev;
  73. /* Read Main ID Register (MIDR) */
  74. asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
  75. return rev;
  76. }
  77. void omap_rev_string(void)
  78. {
  79. u32 omap_rev = omap_revision();
  80. u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
  81. u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
  82. u32 major_rev = (omap_rev & 0x00000F00) >> 8;
  83. u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
  84. if (soc_variant)
  85. printf("OMAP");
  86. else
  87. printf("DRA");
  88. printf("%x ES%x.%x\n", omap_variant, major_rev,
  89. minor_rev);
  90. }
  91. #ifdef CONFIG_SPL_BUILD
  92. void spl_display_print(void)
  93. {
  94. omap_rev_string();
  95. }
  96. #endif
  97. void __weak srcomp_enable(void)
  98. {
  99. }
  100. static void save_omap_boot_params(void)
  101. {
  102. u32 rom_params = *((u32 *)OMAP_SRAM_SCRATCH_BOOT_PARAMS);
  103. u8 boot_device;
  104. u32 dev_desc, dev_data;
  105. if ((rom_params < NON_SECURE_SRAM_START) ||
  106. (rom_params > NON_SECURE_SRAM_END))
  107. return;
  108. /*
  109. * rom_params can be type casted to omap_boot_parameters and
  110. * used. But it not correct to assume that romcode structure
  111. * encoding would be same as u-boot. So use the defined offsets.
  112. */
  113. gd->arch.omap_boot_params.omap_bootdevice = boot_device =
  114. *((u8 *)(rom_params + BOOT_DEVICE_OFFSET));
  115. gd->arch.omap_boot_params.ch_flags =
  116. *((u8 *)(rom_params + CH_FLAGS_OFFSET));
  117. if ((boot_device >= MMC_BOOT_DEVICES_START) &&
  118. (boot_device <= MMC_BOOT_DEVICES_END)) {
  119. if ((omap_hw_init_context() ==
  120. OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)) {
  121. gd->arch.omap_boot_params.omap_bootmode =
  122. *((u8 *)(rom_params + BOOT_MODE_OFFSET));
  123. } else {
  124. dev_desc = *((u32 *)(rom_params + DEV_DESC_PTR_OFFSET));
  125. dev_data = *((u32 *)(dev_desc + DEV_DATA_PTR_OFFSET));
  126. gd->arch.omap_boot_params.omap_bootmode =
  127. *((u32 *)(dev_data + BOOT_MODE_OFFSET));
  128. }
  129. }
  130. }
  131. #ifdef CONFIG_ARCH_CPU_INIT
  132. /*
  133. * SOC specific cpu init
  134. */
  135. int arch_cpu_init(void)
  136. {
  137. save_omap_boot_params();
  138. return 0;
  139. }
  140. #endif /* CONFIG_ARCH_CPU_INIT */
  141. /*
  142. * Routine: s_init
  143. * Description: Does early system init of watchdog, muxing, andclocks
  144. * Watchdog disable is done always. For the rest what gets done
  145. * depends on the boot mode in which this function is executed
  146. * 1. s_init of SPL running from SRAM
  147. * 2. s_init of U-Boot running from FLASH
  148. * 3. s_init of U-Boot loaded to SDRAM by SPL
  149. * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
  150. * Configuration Header feature
  151. * Please have a look at the respective functions to see what gets
  152. * done in each of these cases
  153. * This function is called with SRAM stack.
  154. */
  155. void s_init(void)
  156. {
  157. /*
  158. * Save the boot parameters passed from romcode.
  159. * We cannot delay the saving further than this,
  160. * to prevent overwrites.
  161. */
  162. #ifdef CONFIG_SPL_BUILD
  163. save_omap_boot_params();
  164. #endif
  165. init_omap_revision();
  166. hw_data_init();
  167. #ifdef CONFIG_SPL_BUILD
  168. if (warm_reset() && (omap_revision() <= OMAP5430_ES1_0))
  169. force_emif_self_refresh();
  170. #endif
  171. watchdog_init();
  172. set_mux_conf_regs();
  173. #ifdef CONFIG_SPL_BUILD
  174. srcomp_enable();
  175. setup_clocks_for_console();
  176. gd = &gdata;
  177. preloader_console_init();
  178. do_io_settings();
  179. #endif
  180. prcm_init();
  181. #ifdef CONFIG_SPL_BUILD
  182. timer_init();
  183. /* For regular u-boot sdram_init() is called from dram_init() */
  184. sdram_init();
  185. #endif
  186. }
  187. /*
  188. * Routine: wait_for_command_complete
  189. * Description: Wait for posting to finish on watchdog
  190. */
  191. void wait_for_command_complete(struct watchdog *wd_base)
  192. {
  193. int pending = 1;
  194. do {
  195. pending = readl(&wd_base->wwps);
  196. } while (pending);
  197. }
  198. /*
  199. * Routine: watchdog_init
  200. * Description: Shut down watch dogs
  201. */
  202. void watchdog_init(void)
  203. {
  204. struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
  205. writel(WD_UNLOCK1, &wd2_base->wspr);
  206. wait_for_command_complete(wd2_base);
  207. writel(WD_UNLOCK2, &wd2_base->wspr);
  208. }
  209. /*
  210. * This function finds the SDRAM size available in the system
  211. * based on DMM section configurations
  212. * This is needed because the size of memory installed may be
  213. * different on different versions of the board
  214. */
  215. u32 omap_sdram_size(void)
  216. {
  217. u32 section, i, valid;
  218. u64 sdram_start = 0, sdram_end = 0, addr,
  219. size, total_size = 0, trap_size = 0;
  220. for (i = 0; i < 4; i++) {
  221. section = __raw_readl(DMM_BASE + i*4);
  222. valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
  223. (EMIF_SDRC_ADDRSPC_SHIFT);
  224. addr = section & EMIF_SYS_ADDR_MASK;
  225. /* See if the address is valid */
  226. if ((addr >= DRAM_ADDR_SPACE_START) &&
  227. (addr < DRAM_ADDR_SPACE_END)) {
  228. size = ((section & EMIF_SYS_SIZE_MASK) >>
  229. EMIF_SYS_SIZE_SHIFT);
  230. size = 1 << size;
  231. size *= SZ_16M;
  232. if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
  233. if (!sdram_start || (addr < sdram_start))
  234. sdram_start = addr;
  235. if (!sdram_end || ((addr + size) > sdram_end))
  236. sdram_end = addr + size;
  237. } else {
  238. trap_size = size;
  239. }
  240. }
  241. }
  242. total_size = (sdram_end - sdram_start) - (trap_size);
  243. return total_size;
  244. }
  245. /*
  246. * Routine: dram_init
  247. * Description: sets uboots idea of sdram size
  248. */
  249. int dram_init(void)
  250. {
  251. sdram_init();
  252. gd->ram_size = omap_sdram_size();
  253. return 0;
  254. }
  255. /*
  256. * Print board information
  257. */
  258. int checkboard(void)
  259. {
  260. puts(sysinfo.board_string);
  261. return 0;
  262. }
  263. /*
  264. * get_device_type(): tell if GP/HS/EMU/TST
  265. */
  266. u32 get_device_type(void)
  267. {
  268. return (readl((*ctrl)->control_status) &
  269. (DEVICE_TYPE_MASK)) >> DEVICE_TYPE_SHIFT;
  270. }
  271. /*
  272. * Print CPU information
  273. */
  274. int print_cpuinfo(void)
  275. {
  276. puts("CPU : ");
  277. omap_rev_string();
  278. return 0;
  279. }
  280. #ifndef CONFIG_SYS_DCACHE_OFF
  281. void enable_caches(void)
  282. {
  283. /* Enable D-cache. I-cache is already enabled in start.S */
  284. dcache_enable();
  285. }
  286. void dram_bank_mmu_setup(int bank)
  287. {
  288. bd_t *bd = gd->bd;
  289. int i;
  290. u32 start = bd->bi_dram[bank].start >> 20;
  291. u32 size = bd->bi_dram[bank].size >> 20;
  292. u32 end = start + size;
  293. debug("%s: bank: %d\n", __func__, bank);
  294. for (i = start; i < end; i++)
  295. set_section_dcache(i, ARMV7_DCACHE_WRITEBACK);
  296. }
  297. void arm_init_domains(void)
  298. {
  299. u32 reg;
  300. reg = get_dacr();
  301. /*
  302. * Set DOMAIN to client access so that all permissions
  303. * set in pagetables are validated by the mmu.
  304. */
  305. reg &= ~ARMV7_DOMAIN_MASK;
  306. reg |= ARMV7_DOMAIN_CLIENT;
  307. set_dacr(reg);
  308. }
  309. #endif