setup.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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/clk-provider.h>
  20. #include <linux/of_platform.h>
  21. #include <linux/of_fdt.h>
  22. #include <asm/bootinfo.h>
  23. #include <asm/idle.h>
  24. #include <asm/time.h> /* for mips_hpt_frequency */
  25. #include <asm/reboot.h> /* for _machine_{restart,halt} */
  26. #include <asm/mips_machine.h>
  27. #include <asm/prom.h>
  28. #include <asm/fw/fw.h>
  29. #include <asm/mach-ath79/ath79.h>
  30. #include <asm/mach-ath79/ar71xx_regs.h>
  31. #include "common.h"
  32. #include "dev-common.h"
  33. #include "machtypes.h"
  34. #define ATH79_SYS_TYPE_LEN 64
  35. static char ath79_sys_type[ATH79_SYS_TYPE_LEN];
  36. static void ath79_restart(char *command)
  37. {
  38. ath79_device_reset_set(AR71XX_RESET_FULL_CHIP);
  39. for (;;)
  40. if (cpu_wait)
  41. cpu_wait();
  42. }
  43. static void ath79_halt(void)
  44. {
  45. while (1)
  46. cpu_wait();
  47. }
  48. static void __init ath79_detect_sys_type(void)
  49. {
  50. char *chip = "????";
  51. u32 id;
  52. u32 major;
  53. u32 minor;
  54. u32 rev = 0;
  55. id = ath79_reset_rr(AR71XX_RESET_REG_REV_ID);
  56. major = id & REV_ID_MAJOR_MASK;
  57. switch (major) {
  58. case REV_ID_MAJOR_AR71XX:
  59. minor = id & AR71XX_REV_ID_MINOR_MASK;
  60. rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  61. rev &= AR71XX_REV_ID_REVISION_MASK;
  62. switch (minor) {
  63. case AR71XX_REV_ID_MINOR_AR7130:
  64. ath79_soc = ATH79_SOC_AR7130;
  65. chip = "7130";
  66. break;
  67. case AR71XX_REV_ID_MINOR_AR7141:
  68. ath79_soc = ATH79_SOC_AR7141;
  69. chip = "7141";
  70. break;
  71. case AR71XX_REV_ID_MINOR_AR7161:
  72. ath79_soc = ATH79_SOC_AR7161;
  73. chip = "7161";
  74. break;
  75. }
  76. break;
  77. case REV_ID_MAJOR_AR7240:
  78. ath79_soc = ATH79_SOC_AR7240;
  79. chip = "7240";
  80. rev = id & AR724X_REV_ID_REVISION_MASK;
  81. break;
  82. case REV_ID_MAJOR_AR7241:
  83. ath79_soc = ATH79_SOC_AR7241;
  84. chip = "7241";
  85. rev = id & AR724X_REV_ID_REVISION_MASK;
  86. break;
  87. case REV_ID_MAJOR_AR7242:
  88. ath79_soc = ATH79_SOC_AR7242;
  89. chip = "7242";
  90. rev = id & AR724X_REV_ID_REVISION_MASK;
  91. break;
  92. case REV_ID_MAJOR_AR913X:
  93. minor = id & AR913X_REV_ID_MINOR_MASK;
  94. rev = id >> AR913X_REV_ID_REVISION_SHIFT;
  95. rev &= AR913X_REV_ID_REVISION_MASK;
  96. switch (minor) {
  97. case AR913X_REV_ID_MINOR_AR9130:
  98. ath79_soc = ATH79_SOC_AR9130;
  99. chip = "9130";
  100. break;
  101. case AR913X_REV_ID_MINOR_AR9132:
  102. ath79_soc = ATH79_SOC_AR9132;
  103. chip = "9132";
  104. break;
  105. }
  106. break;
  107. case REV_ID_MAJOR_AR9330:
  108. ath79_soc = ATH79_SOC_AR9330;
  109. chip = "9330";
  110. rev = id & AR933X_REV_ID_REVISION_MASK;
  111. break;
  112. case REV_ID_MAJOR_AR9331:
  113. ath79_soc = ATH79_SOC_AR9331;
  114. chip = "9331";
  115. rev = id & AR933X_REV_ID_REVISION_MASK;
  116. break;
  117. case REV_ID_MAJOR_AR9341:
  118. ath79_soc = ATH79_SOC_AR9341;
  119. chip = "9341";
  120. rev = id & AR934X_REV_ID_REVISION_MASK;
  121. break;
  122. case REV_ID_MAJOR_AR9342:
  123. ath79_soc = ATH79_SOC_AR9342;
  124. chip = "9342";
  125. rev = id & AR934X_REV_ID_REVISION_MASK;
  126. break;
  127. case REV_ID_MAJOR_AR9344:
  128. ath79_soc = ATH79_SOC_AR9344;
  129. chip = "9344";
  130. rev = id & AR934X_REV_ID_REVISION_MASK;
  131. break;
  132. case REV_ID_MAJOR_QCA9556:
  133. ath79_soc = ATH79_SOC_QCA9556;
  134. chip = "9556";
  135. rev = id & QCA955X_REV_ID_REVISION_MASK;
  136. break;
  137. case REV_ID_MAJOR_QCA9558:
  138. ath79_soc = ATH79_SOC_QCA9558;
  139. chip = "9558";
  140. rev = id & QCA955X_REV_ID_REVISION_MASK;
  141. break;
  142. default:
  143. panic("ath79: unknown SoC, id:0x%08x", id);
  144. }
  145. ath79_soc_rev = rev;
  146. if (soc_is_qca955x())
  147. sprintf(ath79_sys_type, "Qualcomm Atheros QCA%s rev %u",
  148. chip, rev);
  149. else
  150. sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
  151. pr_info("SoC: %s\n", ath79_sys_type);
  152. }
  153. const char *get_system_type(void)
  154. {
  155. return ath79_sys_type;
  156. }
  157. int get_c0_perfcount_int(void)
  158. {
  159. return ATH79_MISC_IRQ(5);
  160. }
  161. EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
  162. unsigned int get_c0_compare_int(void)
  163. {
  164. return CP0_LEGACY_COMPARE_IRQ;
  165. }
  166. void __init plat_mem_setup(void)
  167. {
  168. unsigned long fdt_start;
  169. set_io_port_base(KSEG1);
  170. /* Get the position of the FDT passed by the bootloader */
  171. fdt_start = fw_getenvl("fdt_start");
  172. if (fdt_start)
  173. __dt_setup_arch((void *)KSEG0ADDR(fdt_start));
  174. else if (fw_passed_dtb)
  175. __dt_setup_arch((void *)KSEG0ADDR(fw_passed_dtb));
  176. if (mips_machtype != ATH79_MACH_GENERIC_OF) {
  177. ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  178. AR71XX_RESET_SIZE);
  179. ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  180. AR71XX_PLL_SIZE);
  181. ath79_detect_sys_type();
  182. ath79_ddr_ctrl_init();
  183. detect_memory_region(0, ATH79_MEM_SIZE_MIN, ATH79_MEM_SIZE_MAX);
  184. /* OF machines should use the reset driver */
  185. _machine_restart = ath79_restart;
  186. }
  187. _machine_halt = ath79_halt;
  188. pm_power_off = ath79_halt;
  189. }
  190. static void __init ath79_of_plat_time_init(void)
  191. {
  192. struct device_node *np;
  193. struct clk *clk;
  194. unsigned long cpu_clk_rate;
  195. of_clk_init(NULL);
  196. np = of_get_cpu_node(0, NULL);
  197. if (!np) {
  198. pr_err("Failed to get CPU node\n");
  199. return;
  200. }
  201. clk = of_clk_get(np, 0);
  202. if (IS_ERR(clk)) {
  203. pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk));
  204. return;
  205. }
  206. cpu_clk_rate = clk_get_rate(clk);
  207. pr_info("CPU clock: %lu.%03lu MHz\n",
  208. cpu_clk_rate / 1000000, (cpu_clk_rate / 1000) % 1000);
  209. mips_hpt_frequency = cpu_clk_rate / 2;
  210. clk_put(clk);
  211. }
  212. void __init plat_time_init(void)
  213. {
  214. unsigned long cpu_clk_rate;
  215. unsigned long ahb_clk_rate;
  216. unsigned long ddr_clk_rate;
  217. unsigned long ref_clk_rate;
  218. if (IS_ENABLED(CONFIG_OF) && mips_machtype == ATH79_MACH_GENERIC_OF) {
  219. ath79_of_plat_time_init();
  220. return;
  221. }
  222. ath79_clocks_init();
  223. cpu_clk_rate = ath79_get_sys_clk_rate("cpu");
  224. ahb_clk_rate = ath79_get_sys_clk_rate("ahb");
  225. ddr_clk_rate = ath79_get_sys_clk_rate("ddr");
  226. ref_clk_rate = ath79_get_sys_clk_rate("ref");
  227. pr_info("Clocks: CPU:%lu.%03luMHz, DDR:%lu.%03luMHz, AHB:%lu.%03luMHz, Ref:%lu.%03luMHz\n",
  228. cpu_clk_rate / 1000000, (cpu_clk_rate / 1000) % 1000,
  229. ddr_clk_rate / 1000000, (ddr_clk_rate / 1000) % 1000,
  230. ahb_clk_rate / 1000000, (ahb_clk_rate / 1000) % 1000,
  231. ref_clk_rate / 1000000, (ref_clk_rate / 1000) % 1000);
  232. mips_hpt_frequency = cpu_clk_rate / 2;
  233. }
  234. static int __init ath79_setup(void)
  235. {
  236. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  237. if (mips_machtype == ATH79_MACH_GENERIC_OF)
  238. return 0;
  239. ath79_gpio_init();
  240. ath79_register_uart();
  241. ath79_register_wdt();
  242. mips_machine_setup();
  243. return 0;
  244. }
  245. arch_initcall(ath79_setup);
  246. void __init device_tree_init(void)
  247. {
  248. unflatten_and_copy_device_tree();
  249. }
  250. MIPS_MACHINE(ATH79_MACH_GENERIC,
  251. "Generic",
  252. "Generic AR71XX/AR724X/AR913X based board",
  253. NULL);
  254. MIPS_MACHINE(ATH79_MACH_GENERIC_OF,
  255. "DTB",
  256. "Generic AR71XX/AR724X/AR913X based board (DT)",
  257. NULL);