setup.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X specific setup
  3. *
  4. * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  5. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. *
  8. * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/err.h>
  18. #include <linux/clk.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/of_fdt.h>
  21. #include <asm/bootinfo.h>
  22. #include <asm/idle.h>
  23. #include <asm/time.h> /* for mips_hpt_frequency */
  24. #include <asm/reboot.h> /* for _machine_{restart,halt} */
  25. #include <asm/mips_machine.h>
  26. #include <asm/prom.h>
  27. #include <asm/fw/fw.h>
  28. #include <asm/mach-ath79/ath79.h>
  29. #include <asm/mach-ath79/ar71xx_regs.h>
  30. #include "common.h"
  31. #include "dev-common.h"
  32. #include "machtypes.h"
  33. #define ATH79_SYS_TYPE_LEN 64
  34. #define AR71XX_BASE_FREQ 40000000
  35. #define AR724X_BASE_FREQ 5000000
  36. #define AR913X_BASE_FREQ 5000000
  37. static char ath79_sys_type[ATH79_SYS_TYPE_LEN];
  38. static void ath79_restart(char *command)
  39. {
  40. local_irq_disable();
  41. ath79_device_reset_set(AR71XX_RESET_FULL_CHIP);
  42. for (;;)
  43. if (cpu_wait)
  44. cpu_wait();
  45. }
  46. static void ath79_halt(void)
  47. {
  48. while (1)
  49. cpu_wait();
  50. }
  51. static void __init ath79_detect_sys_type(void)
  52. {
  53. char *chip = "????";
  54. u32 id;
  55. u32 major;
  56. u32 minor;
  57. u32 rev = 0;
  58. id = ath79_reset_rr(AR71XX_RESET_REG_REV_ID);
  59. major = id & REV_ID_MAJOR_MASK;
  60. switch (major) {
  61. case REV_ID_MAJOR_AR71XX:
  62. minor = id & AR71XX_REV_ID_MINOR_MASK;
  63. rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  64. rev &= AR71XX_REV_ID_REVISION_MASK;
  65. switch (minor) {
  66. case AR71XX_REV_ID_MINOR_AR7130:
  67. ath79_soc = ATH79_SOC_AR7130;
  68. chip = "7130";
  69. break;
  70. case AR71XX_REV_ID_MINOR_AR7141:
  71. ath79_soc = ATH79_SOC_AR7141;
  72. chip = "7141";
  73. break;
  74. case AR71XX_REV_ID_MINOR_AR7161:
  75. ath79_soc = ATH79_SOC_AR7161;
  76. chip = "7161";
  77. break;
  78. }
  79. break;
  80. case REV_ID_MAJOR_AR7240:
  81. ath79_soc = ATH79_SOC_AR7240;
  82. chip = "7240";
  83. rev = id & AR724X_REV_ID_REVISION_MASK;
  84. break;
  85. case REV_ID_MAJOR_AR7241:
  86. ath79_soc = ATH79_SOC_AR7241;
  87. chip = "7241";
  88. rev = id & AR724X_REV_ID_REVISION_MASK;
  89. break;
  90. case REV_ID_MAJOR_AR7242:
  91. ath79_soc = ATH79_SOC_AR7242;
  92. chip = "7242";
  93. rev = id & AR724X_REV_ID_REVISION_MASK;
  94. break;
  95. case REV_ID_MAJOR_AR913X:
  96. minor = id & AR913X_REV_ID_MINOR_MASK;
  97. rev = id >> AR913X_REV_ID_REVISION_SHIFT;
  98. rev &= AR913X_REV_ID_REVISION_MASK;
  99. switch (minor) {
  100. case AR913X_REV_ID_MINOR_AR9130:
  101. ath79_soc = ATH79_SOC_AR9130;
  102. chip = "9130";
  103. break;
  104. case AR913X_REV_ID_MINOR_AR9132:
  105. ath79_soc = ATH79_SOC_AR9132;
  106. chip = "9132";
  107. break;
  108. }
  109. break;
  110. case REV_ID_MAJOR_AR9330:
  111. ath79_soc = ATH79_SOC_AR9330;
  112. chip = "9330";
  113. rev = id & AR933X_REV_ID_REVISION_MASK;
  114. break;
  115. case REV_ID_MAJOR_AR9331:
  116. ath79_soc = ATH79_SOC_AR9331;
  117. chip = "9331";
  118. rev = id & AR933X_REV_ID_REVISION_MASK;
  119. break;
  120. case REV_ID_MAJOR_AR9341:
  121. ath79_soc = ATH79_SOC_AR9341;
  122. chip = "9341";
  123. rev = id & AR934X_REV_ID_REVISION_MASK;
  124. break;
  125. case REV_ID_MAJOR_AR9342:
  126. ath79_soc = ATH79_SOC_AR9342;
  127. chip = "9342";
  128. rev = id & AR934X_REV_ID_REVISION_MASK;
  129. break;
  130. case REV_ID_MAJOR_AR9344:
  131. ath79_soc = ATH79_SOC_AR9344;
  132. chip = "9344";
  133. rev = id & AR934X_REV_ID_REVISION_MASK;
  134. break;
  135. case REV_ID_MAJOR_QCA9556:
  136. ath79_soc = ATH79_SOC_QCA9556;
  137. chip = "9556";
  138. rev = id & QCA955X_REV_ID_REVISION_MASK;
  139. break;
  140. case REV_ID_MAJOR_QCA9558:
  141. ath79_soc = ATH79_SOC_QCA9558;
  142. chip = "9558";
  143. rev = id & QCA955X_REV_ID_REVISION_MASK;
  144. break;
  145. default:
  146. panic("ath79: unknown SoC, id:0x%08x", id);
  147. }
  148. ath79_soc_rev = rev;
  149. if (soc_is_qca955x())
  150. sprintf(ath79_sys_type, "Qualcomm Atheros QCA%s rev %u",
  151. chip, rev);
  152. else
  153. sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
  154. pr_info("SoC: %s\n", ath79_sys_type);
  155. }
  156. const char *get_system_type(void)
  157. {
  158. return ath79_sys_type;
  159. }
  160. int get_c0_perfcount_int(void)
  161. {
  162. return ATH79_MISC_IRQ(5);
  163. }
  164. EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
  165. unsigned int get_c0_compare_int(void)
  166. {
  167. return CP0_LEGACY_COMPARE_IRQ;
  168. }
  169. void __init plat_mem_setup(void)
  170. {
  171. unsigned long fdt_start;
  172. set_io_port_base(KSEG1);
  173. /* Get the position of the FDT passed by the bootloader */
  174. fdt_start = fw_getenvl("fdt_start");
  175. if (fdt_start)
  176. __dt_setup_arch((void *)KSEG0ADDR(fdt_start));
  177. #ifdef CONFIG_BUILTIN_DTB
  178. else
  179. __dt_setup_arch(__dtb_start);
  180. #endif
  181. ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  182. AR71XX_RESET_SIZE);
  183. ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  184. AR71XX_PLL_SIZE);
  185. ath79_detect_sys_type();
  186. ath79_ddr_ctrl_init();
  187. if (mips_machtype != ATH79_MACH_GENERIC_OF)
  188. detect_memory_region(0, ATH79_MEM_SIZE_MIN, ATH79_MEM_SIZE_MAX);
  189. _machine_restart = ath79_restart;
  190. _machine_halt = ath79_halt;
  191. pm_power_off = ath79_halt;
  192. }
  193. void __init plat_time_init(void)
  194. {
  195. unsigned long cpu_clk_rate;
  196. unsigned long ahb_clk_rate;
  197. unsigned long ddr_clk_rate;
  198. unsigned long ref_clk_rate;
  199. ath79_clocks_init();
  200. cpu_clk_rate = ath79_get_sys_clk_rate("cpu");
  201. ahb_clk_rate = ath79_get_sys_clk_rate("ahb");
  202. ddr_clk_rate = ath79_get_sys_clk_rate("ddr");
  203. ref_clk_rate = ath79_get_sys_clk_rate("ref");
  204. pr_info("Clocks: CPU:%lu.%03luMHz, DDR:%lu.%03luMHz, AHB:%lu.%03luMHz, Ref:%lu.%03luMHz\n",
  205. cpu_clk_rate / 1000000, (cpu_clk_rate / 1000) % 1000,
  206. ddr_clk_rate / 1000000, (ddr_clk_rate / 1000) % 1000,
  207. ahb_clk_rate / 1000000, (ahb_clk_rate / 1000) % 1000,
  208. ref_clk_rate / 1000000, (ref_clk_rate / 1000) % 1000);
  209. mips_hpt_frequency = cpu_clk_rate / 2;
  210. }
  211. static int __init ath79_setup(void)
  212. {
  213. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  214. if (mips_machtype == ATH79_MACH_GENERIC_OF)
  215. return 0;
  216. ath79_gpio_init();
  217. ath79_register_uart();
  218. ath79_register_wdt();
  219. mips_machine_setup();
  220. return 0;
  221. }
  222. arch_initcall(ath79_setup);
  223. void __init device_tree_init(void)
  224. {
  225. unflatten_and_copy_device_tree();
  226. }
  227. static void __init ath79_generic_init(void)
  228. {
  229. /* Nothing to do */
  230. }
  231. MIPS_MACHINE(ATH79_MACH_GENERIC,
  232. "Generic",
  233. "Generic AR71XX/AR724X/AR913X based board",
  234. ath79_generic_init);
  235. MIPS_MACHINE(ATH79_MACH_GENERIC_OF,
  236. "DTB",
  237. "Generic AR71XX/AR724X/AR913X based board (DT)",
  238. NULL);