setup.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. ath79_device_reset_set(AR71XX_RESET_FULL_CHIP);
  41. for (;;)
  42. if (cpu_wait)
  43. cpu_wait();
  44. }
  45. static void ath79_halt(void)
  46. {
  47. while (1)
  48. cpu_wait();
  49. }
  50. static void __init ath79_detect_sys_type(void)
  51. {
  52. char *chip = "????";
  53. u32 id;
  54. u32 major;
  55. u32 minor;
  56. u32 rev = 0;
  57. id = ath79_reset_rr(AR71XX_RESET_REG_REV_ID);
  58. major = id & REV_ID_MAJOR_MASK;
  59. switch (major) {
  60. case REV_ID_MAJOR_AR71XX:
  61. minor = id & AR71XX_REV_ID_MINOR_MASK;
  62. rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  63. rev &= AR71XX_REV_ID_REVISION_MASK;
  64. switch (minor) {
  65. case AR71XX_REV_ID_MINOR_AR7130:
  66. ath79_soc = ATH79_SOC_AR7130;
  67. chip = "7130";
  68. break;
  69. case AR71XX_REV_ID_MINOR_AR7141:
  70. ath79_soc = ATH79_SOC_AR7141;
  71. chip = "7141";
  72. break;
  73. case AR71XX_REV_ID_MINOR_AR7161:
  74. ath79_soc = ATH79_SOC_AR7161;
  75. chip = "7161";
  76. break;
  77. }
  78. break;
  79. case REV_ID_MAJOR_AR7240:
  80. ath79_soc = ATH79_SOC_AR7240;
  81. chip = "7240";
  82. rev = id & AR724X_REV_ID_REVISION_MASK;
  83. break;
  84. case REV_ID_MAJOR_AR7241:
  85. ath79_soc = ATH79_SOC_AR7241;
  86. chip = "7241";
  87. rev = id & AR724X_REV_ID_REVISION_MASK;
  88. break;
  89. case REV_ID_MAJOR_AR7242:
  90. ath79_soc = ATH79_SOC_AR7242;
  91. chip = "7242";
  92. rev = id & AR724X_REV_ID_REVISION_MASK;
  93. break;
  94. case REV_ID_MAJOR_AR913X:
  95. minor = id & AR913X_REV_ID_MINOR_MASK;
  96. rev = id >> AR913X_REV_ID_REVISION_SHIFT;
  97. rev &= AR913X_REV_ID_REVISION_MASK;
  98. switch (minor) {
  99. case AR913X_REV_ID_MINOR_AR9130:
  100. ath79_soc = ATH79_SOC_AR9130;
  101. chip = "9130";
  102. break;
  103. case AR913X_REV_ID_MINOR_AR9132:
  104. ath79_soc = ATH79_SOC_AR9132;
  105. chip = "9132";
  106. break;
  107. }
  108. break;
  109. case REV_ID_MAJOR_AR9330:
  110. ath79_soc = ATH79_SOC_AR9330;
  111. chip = "9330";
  112. rev = id & AR933X_REV_ID_REVISION_MASK;
  113. break;
  114. case REV_ID_MAJOR_AR9331:
  115. ath79_soc = ATH79_SOC_AR9331;
  116. chip = "9331";
  117. rev = id & AR933X_REV_ID_REVISION_MASK;
  118. break;
  119. case REV_ID_MAJOR_AR9341:
  120. ath79_soc = ATH79_SOC_AR9341;
  121. chip = "9341";
  122. rev = id & AR934X_REV_ID_REVISION_MASK;
  123. break;
  124. case REV_ID_MAJOR_AR9342:
  125. ath79_soc = ATH79_SOC_AR9342;
  126. chip = "9342";
  127. rev = id & AR934X_REV_ID_REVISION_MASK;
  128. break;
  129. case REV_ID_MAJOR_AR9344:
  130. ath79_soc = ATH79_SOC_AR9344;
  131. chip = "9344";
  132. rev = id & AR934X_REV_ID_REVISION_MASK;
  133. break;
  134. case REV_ID_MAJOR_QCA9556:
  135. ath79_soc = ATH79_SOC_QCA9556;
  136. chip = "9556";
  137. rev = id & QCA955X_REV_ID_REVISION_MASK;
  138. break;
  139. case REV_ID_MAJOR_QCA9558:
  140. ath79_soc = ATH79_SOC_QCA9558;
  141. chip = "9558";
  142. rev = id & QCA955X_REV_ID_REVISION_MASK;
  143. break;
  144. default:
  145. panic("ath79: unknown SoC, id:0x%08x", id);
  146. }
  147. ath79_soc_rev = rev;
  148. if (soc_is_qca955x())
  149. sprintf(ath79_sys_type, "Qualcomm Atheros QCA%s rev %u",
  150. chip, rev);
  151. else
  152. sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
  153. pr_info("SoC: %s\n", ath79_sys_type);
  154. }
  155. const char *get_system_type(void)
  156. {
  157. return ath79_sys_type;
  158. }
  159. int get_c0_perfcount_int(void)
  160. {
  161. return ATH79_MISC_IRQ(5);
  162. }
  163. unsigned int get_c0_compare_int(void)
  164. {
  165. return CP0_LEGACY_COMPARE_IRQ;
  166. }
  167. void __init plat_mem_setup(void)
  168. {
  169. unsigned long fdt_start;
  170. set_io_port_base(KSEG1);
  171. /* Get the position of the FDT passed by the bootloader */
  172. fdt_start = fw_getenvl("fdt_start");
  173. if (fdt_start)
  174. __dt_setup_arch((void *)KSEG0ADDR(fdt_start));
  175. #ifdef CONFIG_BUILTIN_DTB
  176. else
  177. __dt_setup_arch(__dtb_start);
  178. #endif
  179. ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  180. AR71XX_RESET_SIZE);
  181. ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  182. AR71XX_PLL_SIZE);
  183. ath79_ddr_ctrl_init();
  184. ath79_detect_sys_type();
  185. if (mips_machtype != ATH79_MACH_GENERIC_OF)
  186. detect_memory_region(0, ATH79_MEM_SIZE_MIN, ATH79_MEM_SIZE_MAX);
  187. _machine_restart = ath79_restart;
  188. _machine_halt = ath79_halt;
  189. pm_power_off = ath79_halt;
  190. }
  191. void __init plat_time_init(void)
  192. {
  193. unsigned long cpu_clk_rate;
  194. unsigned long ahb_clk_rate;
  195. unsigned long ddr_clk_rate;
  196. unsigned long ref_clk_rate;
  197. ath79_clocks_init();
  198. cpu_clk_rate = ath79_get_sys_clk_rate("cpu");
  199. ahb_clk_rate = ath79_get_sys_clk_rate("ahb");
  200. ddr_clk_rate = ath79_get_sys_clk_rate("ddr");
  201. ref_clk_rate = ath79_get_sys_clk_rate("ref");
  202. pr_info("Clocks: CPU:%lu.%03luMHz, DDR:%lu.%03luMHz, AHB:%lu.%03luMHz, Ref:%lu.%03luMHz\n",
  203. cpu_clk_rate / 1000000, (cpu_clk_rate / 1000) % 1000,
  204. ddr_clk_rate / 1000000, (ddr_clk_rate / 1000) % 1000,
  205. ahb_clk_rate / 1000000, (ahb_clk_rate / 1000) % 1000,
  206. ref_clk_rate / 1000000, (ref_clk_rate / 1000) % 1000);
  207. mips_hpt_frequency = cpu_clk_rate / 2;
  208. }
  209. static int __init ath79_setup(void)
  210. {
  211. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  212. if (mips_machtype == ATH79_MACH_GENERIC_OF)
  213. return 0;
  214. ath79_gpio_init();
  215. ath79_register_uart();
  216. ath79_register_wdt();
  217. mips_machine_setup();
  218. return 0;
  219. }
  220. arch_initcall(ath79_setup);
  221. void __init device_tree_init(void)
  222. {
  223. unflatten_and_copy_device_tree();
  224. }
  225. static void __init ath79_generic_init(void)
  226. {
  227. /* Nothing to do */
  228. }
  229. MIPS_MACHINE(ATH79_MACH_GENERIC,
  230. "Generic",
  231. "Generic AR71XX/AR724X/AR913X based board",
  232. ath79_generic_init);