setup.c 5.1 KB

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