setup.c 7.5 KB

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