setup.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 <asm/bootinfo.h>
  20. #include <asm/time.h> /* for mips_hpt_frequency */
  21. #include <asm/reboot.h> /* for _machine_{restart,halt} */
  22. #include <asm/mips_machine.h>
  23. #include <asm/mach-ath79/ath79.h>
  24. #include <asm/mach-ath79/ar71xx_regs.h>
  25. #include "common.h"
  26. #include "dev-common.h"
  27. #include "machtypes.h"
  28. #define ATH79_SYS_TYPE_LEN 64
  29. #define AR71XX_BASE_FREQ 40000000
  30. #define AR724X_BASE_FREQ 5000000
  31. #define AR913X_BASE_FREQ 5000000
  32. static char ath79_sys_type[ATH79_SYS_TYPE_LEN];
  33. static void ath79_restart(char *command)
  34. {
  35. ath79_device_reset_set(AR71XX_RESET_FULL_CHIP);
  36. for (;;)
  37. if (cpu_wait)
  38. cpu_wait();
  39. }
  40. static void ath79_halt(void)
  41. {
  42. while (1)
  43. cpu_wait();
  44. }
  45. static void __init ath79_detect_sys_type(void)
  46. {
  47. char *chip = "????";
  48. u32 id;
  49. u32 major;
  50. u32 minor;
  51. u32 rev = 0;
  52. id = ath79_reset_rr(AR71XX_RESET_REG_REV_ID);
  53. major = id & REV_ID_MAJOR_MASK;
  54. switch (major) {
  55. case REV_ID_MAJOR_AR71XX:
  56. minor = id & AR71XX_REV_ID_MINOR_MASK;
  57. rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  58. rev &= AR71XX_REV_ID_REVISION_MASK;
  59. switch (minor) {
  60. case AR71XX_REV_ID_MINOR_AR7130:
  61. ath79_soc = ATH79_SOC_AR7130;
  62. chip = "7130";
  63. break;
  64. case AR71XX_REV_ID_MINOR_AR7141:
  65. ath79_soc = ATH79_SOC_AR7141;
  66. chip = "7141";
  67. break;
  68. case AR71XX_REV_ID_MINOR_AR7161:
  69. ath79_soc = ATH79_SOC_AR7161;
  70. chip = "7161";
  71. break;
  72. }
  73. break;
  74. case REV_ID_MAJOR_AR7240:
  75. ath79_soc = ATH79_SOC_AR7240;
  76. chip = "7240";
  77. rev = id & AR724X_REV_ID_REVISION_MASK;
  78. break;
  79. case REV_ID_MAJOR_AR7241:
  80. ath79_soc = ATH79_SOC_AR7241;
  81. chip = "7241";
  82. rev = id & AR724X_REV_ID_REVISION_MASK;
  83. break;
  84. case REV_ID_MAJOR_AR7242:
  85. ath79_soc = ATH79_SOC_AR7242;
  86. chip = "7242";
  87. rev = id & AR724X_REV_ID_REVISION_MASK;
  88. break;
  89. case REV_ID_MAJOR_AR913X:
  90. minor = id & AR913X_REV_ID_MINOR_MASK;
  91. rev = id >> AR913X_REV_ID_REVISION_SHIFT;
  92. rev &= AR913X_REV_ID_REVISION_MASK;
  93. switch (minor) {
  94. case AR913X_REV_ID_MINOR_AR9130:
  95. ath79_soc = ATH79_SOC_AR9130;
  96. chip = "9130";
  97. break;
  98. case AR913X_REV_ID_MINOR_AR9132:
  99. ath79_soc = ATH79_SOC_AR9132;
  100. chip = "9132";
  101. break;
  102. }
  103. break;
  104. case REV_ID_MAJOR_AR9330:
  105. ath79_soc = ATH79_SOC_AR9330;
  106. chip = "9330";
  107. rev = id & AR933X_REV_ID_REVISION_MASK;
  108. break;
  109. case REV_ID_MAJOR_AR9331:
  110. ath79_soc = ATH79_SOC_AR9331;
  111. chip = "9331";
  112. rev = id & AR933X_REV_ID_REVISION_MASK;
  113. break;
  114. case REV_ID_MAJOR_AR9341:
  115. ath79_soc = ATH79_SOC_AR9341;
  116. chip = "9341";
  117. rev = id & AR934X_REV_ID_REVISION_MASK;
  118. break;
  119. case REV_ID_MAJOR_AR9342:
  120. ath79_soc = ATH79_SOC_AR9342;
  121. chip = "9342";
  122. rev = id & AR934X_REV_ID_REVISION_MASK;
  123. break;
  124. case REV_ID_MAJOR_AR9344:
  125. ath79_soc = ATH79_SOC_AR9344;
  126. chip = "9344";
  127. rev = id & AR934X_REV_ID_REVISION_MASK;
  128. break;
  129. case REV_ID_MAJOR_QCA9556:
  130. ath79_soc = ATH79_SOC_QCA9556;
  131. chip = "9556";
  132. rev = id & QCA955X_REV_ID_REVISION_MASK;
  133. break;
  134. case REV_ID_MAJOR_QCA9558:
  135. ath79_soc = ATH79_SOC_QCA9558;
  136. chip = "9558";
  137. rev = id & QCA955X_REV_ID_REVISION_MASK;
  138. break;
  139. default:
  140. panic("ath79: unknown SoC, id:0x%08x", id);
  141. }
  142. ath79_soc_rev = rev;
  143. if (soc_is_qca955x())
  144. sprintf(ath79_sys_type, "Qualcomm Atheros QCA%s rev %u",
  145. chip, rev);
  146. else
  147. sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
  148. pr_info("SoC: %s\n", ath79_sys_type);
  149. }
  150. const char *get_system_type(void)
  151. {
  152. return ath79_sys_type;
  153. }
  154. unsigned int __cpuinit get_c0_compare_int(void)
  155. {
  156. return CP0_LEGACY_COMPARE_IRQ;
  157. }
  158. void __init plat_mem_setup(void)
  159. {
  160. set_io_port_base(KSEG1);
  161. ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  162. AR71XX_RESET_SIZE);
  163. ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  164. AR71XX_PLL_SIZE);
  165. ath79_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  166. AR71XX_DDR_CTRL_SIZE);
  167. ath79_detect_sys_type();
  168. detect_memory_region(0, ATH79_MEM_SIZE_MIN, ATH79_MEM_SIZE_MAX);
  169. ath79_clocks_init();
  170. _machine_restart = ath79_restart;
  171. _machine_halt = ath79_halt;
  172. pm_power_off = ath79_halt;
  173. }
  174. void __init plat_time_init(void)
  175. {
  176. struct clk *clk;
  177. clk = clk_get(NULL, "cpu");
  178. if (IS_ERR(clk))
  179. panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
  180. mips_hpt_frequency = clk_get_rate(clk) / 2;
  181. }
  182. static int __init ath79_setup(void)
  183. {
  184. ath79_gpio_init();
  185. ath79_register_uart();
  186. ath79_register_wdt();
  187. mips_machine_setup();
  188. return 0;
  189. }
  190. arch_initcall(ath79_setup);
  191. static void __init ath79_generic_init(void)
  192. {
  193. /* Nothing to do */
  194. }
  195. MIPS_MACHINE(ATH79_MACH_GENERIC,
  196. "Generic",
  197. "Generic AR71XX/AR724X/AR913X based board",
  198. ath79_generic_init);