setup.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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_AR913X:
  100. minor = id & AR913X_REV_ID_MINOR_MASK;
  101. rev = id >> AR913X_REV_ID_REVISION_SHIFT;
  102. rev &= AR913X_REV_ID_REVISION_MASK;
  103. switch (minor) {
  104. case AR913X_REV_ID_MINOR_AR9130:
  105. ath79_soc = ATH79_SOC_AR9130;
  106. chip = "9130";
  107. break;
  108. case AR913X_REV_ID_MINOR_AR9132:
  109. ath79_soc = ATH79_SOC_AR9132;
  110. chip = "9132";
  111. break;
  112. }
  113. break;
  114. default:
  115. panic("ath79: unknown SoC, id:0x%08x\n", id);
  116. }
  117. sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
  118. pr_info("SoC: %s\n", ath79_sys_type);
  119. }
  120. const char *get_system_type(void)
  121. {
  122. return ath79_sys_type;
  123. }
  124. unsigned int __cpuinit get_c0_compare_int(void)
  125. {
  126. return CP0_LEGACY_COMPARE_IRQ;
  127. }
  128. void __init plat_mem_setup(void)
  129. {
  130. set_io_port_base(KSEG1);
  131. ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
  132. AR71XX_RESET_SIZE);
  133. ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
  134. AR71XX_PLL_SIZE);
  135. ath79_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  136. AR71XX_DDR_CTRL_SIZE);
  137. ath79_detect_sys_type();
  138. ath79_detect_mem_size();
  139. ath79_clocks_init();
  140. _machine_restart = ath79_restart;
  141. _machine_halt = ath79_halt;
  142. pm_power_off = ath79_halt;
  143. }
  144. void __init plat_time_init(void)
  145. {
  146. struct clk *clk;
  147. clk = clk_get(NULL, "cpu");
  148. if (IS_ERR(clk))
  149. panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
  150. mips_hpt_frequency = clk_get_rate(clk) / 2;
  151. }
  152. static int __init ath79_setup(void)
  153. {
  154. ath79_gpio_init();
  155. ath79_register_uart();
  156. ath79_register_wdt();
  157. mips_machine_setup();
  158. return 0;
  159. }
  160. arch_initcall(ath79_setup);
  161. static void __init ath79_generic_init(void)
  162. {
  163. /* Nothing to do */
  164. }
  165. MIPS_MACHINE(ATH79_MACH_GENERIC,
  166. "Generic",
  167. "Generic AR71XX/AR724X/AR913X based board",
  168. ath79_generic_init);