setup.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X specific setup
  3. *
  4. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * Parts of this file are based on Atheros' 2.6.15 BSP
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/err.h>
  17. #include <linux/clk.h>
  18. #include <asm/bootinfo.h>
  19. #include <asm/time.h> /* for mips_hpt_frequency */
  20. #include <asm/reboot.h> /* for _machine_{restart,halt} */
  21. #include <asm/mips_machine.h>
  22. #include <asm/mach-ath79/ath79.h>
  23. #include <asm/mach-ath79/ar71xx_regs.h>
  24. #include "common.h"
  25. #include "dev-common.h"
  26. #include "machtypes.h"
  27. #define ATH79_SYS_TYPE_LEN 64
  28. #define AR71XX_BASE_FREQ 40000000
  29. #define AR724X_BASE_FREQ 5000000
  30. #define AR913X_BASE_FREQ 5000000
  31. static char ath79_sys_type[ATH79_SYS_TYPE_LEN];
  32. static void ath79_restart(char *command)
  33. {
  34. ath79_device_reset_set(AR71XX_RESET_FULL_CHIP);
  35. for (;;)
  36. if (cpu_wait)
  37. cpu_wait();
  38. }
  39. static void ath79_halt(void)
  40. {
  41. while (1)
  42. cpu_wait();
  43. }
  44. static void __init ath79_detect_mem_size(void)
  45. {
  46. unsigned long size;
  47. for (size = ATH79_MEM_SIZE_MIN; size < ATH79_MEM_SIZE_MAX;
  48. size <<= 1) {
  49. if (!memcmp(ath79_detect_mem_size,
  50. ath79_detect_mem_size + size, 1024))
  51. break;
  52. }
  53. add_memory_region(0, size, BOOT_MEM_RAM);
  54. }
  55. static void __init ath79_detect_sys_type(void)
  56. {
  57. char *chip = "????";
  58. u32 id;
  59. u32 major;
  60. u32 minor;
  61. u32 rev = 0;
  62. id = ath79_reset_rr(AR71XX_RESET_REG_REV_ID);
  63. major = id & REV_ID_MAJOR_MASK;
  64. switch (major) {
  65. case REV_ID_MAJOR_AR71XX:
  66. minor = id & AR71XX_REV_ID_MINOR_MASK;
  67. rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
  68. rev &= AR71XX_REV_ID_REVISION_MASK;
  69. switch (minor) {
  70. case AR71XX_REV_ID_MINOR_AR7130:
  71. ath79_soc = ATH79_SOC_AR7130;
  72. chip = "7130";
  73. break;
  74. case AR71XX_REV_ID_MINOR_AR7141:
  75. ath79_soc = ATH79_SOC_AR7141;
  76. chip = "7141";
  77. break;
  78. case AR71XX_REV_ID_MINOR_AR7161:
  79. ath79_soc = ATH79_SOC_AR7161;
  80. chip = "7161";
  81. break;
  82. }
  83. break;
  84. case REV_ID_MAJOR_AR7240:
  85. ath79_soc = ATH79_SOC_AR7240;
  86. chip = "7240";
  87. rev = id & AR724X_REV_ID_REVISION_MASK;
  88. break;
  89. case REV_ID_MAJOR_AR7241:
  90. ath79_soc = ATH79_SOC_AR7241;
  91. chip = "7241";
  92. rev = id & AR724X_REV_ID_REVISION_MASK;
  93. break;
  94. case REV_ID_MAJOR_AR7242:
  95. ath79_soc = ATH79_SOC_AR7242;
  96. chip = "7242";
  97. rev = id & AR724X_REV_ID_REVISION_MASK;
  98. break;
  99. case REV_ID_MAJOR_AR9330:
  100. ath79_soc = ATH79_SOC_AR9330;
  101. chip = "9330";
  102. rev = id & AR933X_REV_ID_REVISION_MASK;
  103. break;
  104. case REV_ID_MAJOR_AR9331:
  105. ath79_soc = ATH79_SOC_AR9331;
  106. chip = "9331";
  107. rev = id & AR933X_REV_ID_REVISION_MASK;
  108. break;
  109. case REV_ID_MAJOR_AR913X:
  110. minor = id & AR913X_REV_ID_MINOR_MASK;
  111. rev = id >> AR913X_REV_ID_REVISION_SHIFT;
  112. rev &= AR913X_REV_ID_REVISION_MASK;
  113. switch (minor) {
  114. case AR913X_REV_ID_MINOR_AR9130:
  115. ath79_soc = ATH79_SOC_AR9130;
  116. chip = "9130";
  117. break;
  118. case AR913X_REV_ID_MINOR_AR9132:
  119. ath79_soc = ATH79_SOC_AR9132;
  120. chip = "9132";
  121. break;
  122. }
  123. break;
  124. default:
  125. panic("ath79: unknown SoC, id:0x%08x", id);
  126. }
  127. ath79_soc_rev = rev;
  128. sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
  129. pr_info("SoC: %s\n", ath79_sys_type);
  130. }
  131. const char *get_system_type(void)
  132. {
  133. return ath79_sys_type;
  134. }
  135. unsigned int __cpuinit get_c0_compare_int(void)
  136. {
  137. return CP0_LEGACY_COMPARE_IRQ;
  138. }
  139. void __init plat_mem_setup(void)
  140. {
  141. set_io_port_base(KSEG1);
  142. ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  143. AR71XX_RESET_SIZE);
  144. ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  145. AR71XX_PLL_SIZE);
  146. ath79_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  147. AR71XX_DDR_CTRL_SIZE);
  148. ath79_detect_sys_type();
  149. ath79_detect_mem_size();
  150. ath79_clocks_init();
  151. _machine_restart = ath79_restart;
  152. _machine_halt = ath79_halt;
  153. pm_power_off = ath79_halt;
  154. }
  155. void __init plat_time_init(void)
  156. {
  157. struct clk *clk;
  158. clk = clk_get(NULL, "cpu");
  159. if (IS_ERR(clk))
  160. panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
  161. mips_hpt_frequency = clk_get_rate(clk) / 2;
  162. }
  163. static int __init ath79_setup(void)
  164. {
  165. ath79_gpio_init();
  166. ath79_register_uart();
  167. ath79_register_wdt();
  168. mips_machine_setup();
  169. return 0;
  170. }
  171. arch_initcall(ath79_setup);
  172. static void __init ath79_generic_init(void)
  173. {
  174. /* Nothing to do */
  175. }
  176. MIPS_MACHINE(ATH79_MACH_GENERIC,
  177. "Generic",
  178. "Generic AR71XX/AR724X/AR913X based board",
  179. ath79_generic_init);