setup.c 6.8 KB

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