setup.c 7.2 KB

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