setup.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation.
  3. * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  4. *
  5. * Under GPLv2
  6. */
  7. #include <linux/module.h>
  8. #include <linux/io.h>
  9. #include <linux/mm.h>
  10. #include <linux/pm.h>
  11. #include <asm/mach/map.h>
  12. #include <mach/hardware.h>
  13. #include <mach/cpu.h>
  14. #include <mach/at91_dbgu.h>
  15. #include <mach/at91_pmc.h>
  16. #include <mach/at91_shdwc.h>
  17. #include "soc.h"
  18. #include "generic.h"
  19. struct at91_init_soc __initdata at91_boot_soc;
  20. struct at91_socinfo at91_soc_initdata;
  21. EXPORT_SYMBOL(at91_soc_initdata);
  22. void __init at91rm9200_set_type(int type)
  23. {
  24. if (type == ARCH_REVISON_9200_PQFP)
  25. at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
  26. else
  27. at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
  28. pr_info("AT91: filled in soc subtype: %s\n",
  29. at91_get_soc_subtype(&at91_soc_initdata));
  30. }
  31. void __init at91_init_irq_default(void)
  32. {
  33. at91_init_interrupts(at91_boot_soc.default_irq_priority);
  34. }
  35. void __init at91_init_interrupts(unsigned int *priority)
  36. {
  37. /* Initialize the AIC interrupt controller */
  38. at91_aic_init(priority);
  39. /* Enable GPIO interrupts */
  40. at91_gpio_irq_setup();
  41. }
  42. static struct map_desc sram_desc[2] __initdata;
  43. void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
  44. {
  45. struct map_desc *desc = &sram_desc[bank];
  46. desc->virtual = AT91_IO_VIRT_BASE - length;
  47. if (bank > 0)
  48. desc->virtual -= sram_desc[bank - 1].length;
  49. desc->pfn = __phys_to_pfn(base);
  50. desc->length = length;
  51. desc->type = MT_DEVICE;
  52. pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
  53. base, length, desc->virtual);
  54. iotable_init(desc, 1);
  55. }
  56. static struct map_desc at91_io_desc __initdata = {
  57. .virtual = AT91_VA_BASE_SYS,
  58. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  59. .length = SZ_16K,
  60. .type = MT_DEVICE,
  61. };
  62. static void __init soc_detect(u32 dbgu_base)
  63. {
  64. u32 cidr, socid;
  65. cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
  66. socid = cidr & ~AT91_CIDR_VERSION;
  67. switch (socid) {
  68. case ARCH_ID_AT91CAP9: {
  69. #ifdef CONFIG_AT91_PMC_UNIT
  70. u32 pmc_ver = at91_sys_read(AT91_PMC_VER);
  71. if (pmc_ver == ARCH_REVISION_CAP9_B)
  72. at91_soc_initdata.subtype = AT91_SOC_CAP9_REV_B;
  73. else if (pmc_ver == ARCH_REVISION_CAP9_C)
  74. at91_soc_initdata.subtype = AT91_SOC_CAP9_REV_C;
  75. #endif
  76. at91_soc_initdata.type = AT91_SOC_CAP9;
  77. at91_boot_soc = at91cap9_soc;
  78. break;
  79. }
  80. case ARCH_ID_AT91RM9200:
  81. at91_soc_initdata.type = AT91_SOC_RM9200;
  82. at91_boot_soc = at91rm9200_soc;
  83. break;
  84. case ARCH_ID_AT91SAM9260:
  85. at91_soc_initdata.type = AT91_SOC_SAM9260;
  86. at91_boot_soc = at91sam9260_soc;
  87. break;
  88. case ARCH_ID_AT91SAM9261:
  89. at91_soc_initdata.type = AT91_SOC_SAM9261;
  90. at91_boot_soc = at91sam9261_soc;
  91. break;
  92. case ARCH_ID_AT91SAM9263:
  93. at91_soc_initdata.type = AT91_SOC_SAM9263;
  94. at91_boot_soc = at91sam9263_soc;
  95. break;
  96. case ARCH_ID_AT91SAM9G20:
  97. at91_soc_initdata.type = AT91_SOC_SAM9G20;
  98. at91_boot_soc = at91sam9260_soc;
  99. break;
  100. case ARCH_ID_AT91SAM9G45:
  101. at91_soc_initdata.type = AT91_SOC_SAM9G45;
  102. if (cidr == ARCH_ID_AT91SAM9G45ES)
  103. at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
  104. at91_boot_soc = at91sam9g45_soc;
  105. break;
  106. case ARCH_ID_AT91SAM9RL64:
  107. at91_soc_initdata.type = AT91_SOC_SAM9RL;
  108. at91_boot_soc = at91sam9rl_soc;
  109. break;
  110. case ARCH_ID_AT91SAM9X5:
  111. at91_soc_initdata.type = AT91_SOC_SAM9X5;
  112. at91_boot_soc = at91sam9x5_soc;
  113. break;
  114. }
  115. /* at91sam9g10 */
  116. if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
  117. at91_soc_initdata.type = AT91_SOC_SAM9G10;
  118. at91_boot_soc = at91sam9261_soc;
  119. }
  120. /* at91sam9xe */
  121. else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
  122. at91_soc_initdata.type = AT91_SOC_SAM9260;
  123. at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
  124. at91_boot_soc = at91sam9260_soc;
  125. }
  126. if (!at91_soc_is_detected())
  127. return;
  128. at91_soc_initdata.cidr = cidr;
  129. /* sub version of soc */
  130. at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
  131. if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
  132. switch (at91_soc_initdata.exid) {
  133. case ARCH_EXID_AT91SAM9M10:
  134. at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
  135. break;
  136. case ARCH_EXID_AT91SAM9G46:
  137. at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
  138. break;
  139. case ARCH_EXID_AT91SAM9M11:
  140. at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
  141. break;
  142. }
  143. }
  144. if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
  145. switch (at91_soc_initdata.exid) {
  146. case ARCH_EXID_AT91SAM9G15:
  147. at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
  148. break;
  149. case ARCH_EXID_AT91SAM9G35:
  150. at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
  151. break;
  152. case ARCH_EXID_AT91SAM9X35:
  153. at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
  154. break;
  155. case ARCH_EXID_AT91SAM9G25:
  156. at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
  157. break;
  158. case ARCH_EXID_AT91SAM9X25:
  159. at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
  160. break;
  161. }
  162. }
  163. }
  164. static const char *soc_name[] = {
  165. [AT91_SOC_RM9200] = "at91rm9200",
  166. [AT91_SOC_CAP9] = "at91cap9",
  167. [AT91_SOC_SAM9260] = "at91sam9260",
  168. [AT91_SOC_SAM9261] = "at91sam9261",
  169. [AT91_SOC_SAM9263] = "at91sam9263",
  170. [AT91_SOC_SAM9G10] = "at91sam9g10",
  171. [AT91_SOC_SAM9G20] = "at91sam9g20",
  172. [AT91_SOC_SAM9G45] = "at91sam9g45",
  173. [AT91_SOC_SAM9RL] = "at91sam9rl",
  174. [AT91_SOC_SAM9X5] = "at91sam9x5",
  175. [AT91_SOC_NONE] = "Unknown"
  176. };
  177. const char *at91_get_soc_type(struct at91_socinfo *c)
  178. {
  179. return soc_name[c->type];
  180. }
  181. EXPORT_SYMBOL(at91_get_soc_type);
  182. static const char *soc_subtype_name[] = {
  183. [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
  184. [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
  185. [AT91_SOC_CAP9_REV_B] = "at91cap9 revB",
  186. [AT91_SOC_CAP9_REV_C] = "at91cap9 revC",
  187. [AT91_SOC_SAM9XE] = "at91sam9xe",
  188. [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
  189. [AT91_SOC_SAM9M10] = "at91sam9m10",
  190. [AT91_SOC_SAM9G46] = "at91sam9g46",
  191. [AT91_SOC_SAM9M11] = "at91sam9m11",
  192. [AT91_SOC_SAM9G15] = "at91sam9g15",
  193. [AT91_SOC_SAM9G35] = "at91sam9g35",
  194. [AT91_SOC_SAM9X35] = "at91sam9x35",
  195. [AT91_SOC_SAM9G25] = "at91sam9g25",
  196. [AT91_SOC_SAM9X25] = "at91sam9x25",
  197. [AT91_SOC_SUBTYPE_NONE] = "Unknown"
  198. };
  199. const char *at91_get_soc_subtype(struct at91_socinfo *c)
  200. {
  201. return soc_subtype_name[c->subtype];
  202. }
  203. EXPORT_SYMBOL(at91_get_soc_subtype);
  204. void __init at91_map_io(void)
  205. {
  206. /* Map peripherals */
  207. iotable_init(&at91_io_desc, 1);
  208. at91_soc_initdata.type = AT91_SOC_NONE;
  209. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  210. soc_detect(AT91_BASE_DBGU0);
  211. if (!at91_soc_is_detected())
  212. soc_detect(AT91_BASE_DBGU1);
  213. if (!at91_soc_is_detected())
  214. panic("AT91: Impossible to detect the SOC type");
  215. pr_info("AT91: Detected soc type: %s\n",
  216. at91_get_soc_type(&at91_soc_initdata));
  217. pr_info("AT91: Detected soc subtype: %s\n",
  218. at91_get_soc_subtype(&at91_soc_initdata));
  219. if (!at91_soc_is_enabled())
  220. panic("AT91: Soc not enabled");
  221. if (at91_boot_soc.map_io)
  222. at91_boot_soc.map_io();
  223. }
  224. void __iomem *at91_shdwc_base = NULL;
  225. static void at91sam9_poweroff(void)
  226. {
  227. at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  228. }
  229. void __init at91_ioremap_shdwc(u32 base_addr)
  230. {
  231. at91_shdwc_base = ioremap(base_addr, 16);
  232. if (!at91_shdwc_base)
  233. panic("Impossible to ioremap at91_shdwc_base\n");
  234. pm_power_off = at91sam9_poweroff;
  235. }
  236. void __iomem *at91_rstc_base;
  237. void __init at91_ioremap_rstc(u32 base_addr)
  238. {
  239. at91_rstc_base = ioremap(base_addr, 16);
  240. if (!at91_rstc_base)
  241. panic("Impossible to ioremap at91_rstc_base\n");
  242. }
  243. void __init at91_initialize(unsigned long main_clock)
  244. {
  245. at91_boot_soc.ioremap_registers();
  246. /* Init clock subsystem */
  247. at91_clock_init(main_clock);
  248. /* Register the processor-specific clocks */
  249. at91_boot_soc.register_clocks();
  250. at91_boot_soc.init();
  251. }