setup.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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_AT91RM9200:
  69. at91_soc_initdata.type = AT91_SOC_RM9200;
  70. at91_boot_soc = at91rm9200_soc;
  71. break;
  72. case ARCH_ID_AT91SAM9260:
  73. at91_soc_initdata.type = AT91_SOC_SAM9260;
  74. at91_boot_soc = at91sam9260_soc;
  75. break;
  76. case ARCH_ID_AT91SAM9261:
  77. at91_soc_initdata.type = AT91_SOC_SAM9261;
  78. at91_boot_soc = at91sam9261_soc;
  79. break;
  80. case ARCH_ID_AT91SAM9263:
  81. at91_soc_initdata.type = AT91_SOC_SAM9263;
  82. at91_boot_soc = at91sam9263_soc;
  83. break;
  84. case ARCH_ID_AT91SAM9G20:
  85. at91_soc_initdata.type = AT91_SOC_SAM9G20;
  86. at91_boot_soc = at91sam9260_soc;
  87. break;
  88. case ARCH_ID_AT91SAM9G45:
  89. at91_soc_initdata.type = AT91_SOC_SAM9G45;
  90. if (cidr == ARCH_ID_AT91SAM9G45ES)
  91. at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
  92. at91_boot_soc = at91sam9g45_soc;
  93. break;
  94. case ARCH_ID_AT91SAM9RL64:
  95. at91_soc_initdata.type = AT91_SOC_SAM9RL;
  96. at91_boot_soc = at91sam9rl_soc;
  97. break;
  98. case ARCH_ID_AT91SAM9X5:
  99. at91_soc_initdata.type = AT91_SOC_SAM9X5;
  100. at91_boot_soc = at91sam9x5_soc;
  101. break;
  102. }
  103. /* at91sam9g10 */
  104. if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
  105. at91_soc_initdata.type = AT91_SOC_SAM9G10;
  106. at91_boot_soc = at91sam9261_soc;
  107. }
  108. /* at91sam9xe */
  109. else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
  110. at91_soc_initdata.type = AT91_SOC_SAM9260;
  111. at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
  112. at91_boot_soc = at91sam9260_soc;
  113. }
  114. if (!at91_soc_is_detected())
  115. return;
  116. at91_soc_initdata.cidr = cidr;
  117. /* sub version of soc */
  118. at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
  119. if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
  120. switch (at91_soc_initdata.exid) {
  121. case ARCH_EXID_AT91SAM9M10:
  122. at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
  123. break;
  124. case ARCH_EXID_AT91SAM9G46:
  125. at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
  126. break;
  127. case ARCH_EXID_AT91SAM9M11:
  128. at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
  129. break;
  130. }
  131. }
  132. if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
  133. switch (at91_soc_initdata.exid) {
  134. case ARCH_EXID_AT91SAM9G15:
  135. at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
  136. break;
  137. case ARCH_EXID_AT91SAM9G35:
  138. at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
  139. break;
  140. case ARCH_EXID_AT91SAM9X35:
  141. at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
  142. break;
  143. case ARCH_EXID_AT91SAM9G25:
  144. at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
  145. break;
  146. case ARCH_EXID_AT91SAM9X25:
  147. at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
  148. break;
  149. }
  150. }
  151. }
  152. static const char *soc_name[] = {
  153. [AT91_SOC_RM9200] = "at91rm9200",
  154. [AT91_SOC_SAM9260] = "at91sam9260",
  155. [AT91_SOC_SAM9261] = "at91sam9261",
  156. [AT91_SOC_SAM9263] = "at91sam9263",
  157. [AT91_SOC_SAM9G10] = "at91sam9g10",
  158. [AT91_SOC_SAM9G20] = "at91sam9g20",
  159. [AT91_SOC_SAM9G45] = "at91sam9g45",
  160. [AT91_SOC_SAM9RL] = "at91sam9rl",
  161. [AT91_SOC_SAM9X5] = "at91sam9x5",
  162. [AT91_SOC_NONE] = "Unknown"
  163. };
  164. const char *at91_get_soc_type(struct at91_socinfo *c)
  165. {
  166. return soc_name[c->type];
  167. }
  168. EXPORT_SYMBOL(at91_get_soc_type);
  169. static const char *soc_subtype_name[] = {
  170. [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
  171. [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
  172. [AT91_SOC_SAM9XE] = "at91sam9xe",
  173. [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
  174. [AT91_SOC_SAM9M10] = "at91sam9m10",
  175. [AT91_SOC_SAM9G46] = "at91sam9g46",
  176. [AT91_SOC_SAM9M11] = "at91sam9m11",
  177. [AT91_SOC_SAM9G15] = "at91sam9g15",
  178. [AT91_SOC_SAM9G35] = "at91sam9g35",
  179. [AT91_SOC_SAM9X35] = "at91sam9x35",
  180. [AT91_SOC_SAM9G25] = "at91sam9g25",
  181. [AT91_SOC_SAM9X25] = "at91sam9x25",
  182. [AT91_SOC_SUBTYPE_NONE] = "Unknown"
  183. };
  184. const char *at91_get_soc_subtype(struct at91_socinfo *c)
  185. {
  186. return soc_subtype_name[c->subtype];
  187. }
  188. EXPORT_SYMBOL(at91_get_soc_subtype);
  189. void __init at91_map_io(void)
  190. {
  191. /* Map peripherals */
  192. iotable_init(&at91_io_desc, 1);
  193. at91_soc_initdata.type = AT91_SOC_NONE;
  194. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  195. soc_detect(AT91_BASE_DBGU0);
  196. if (!at91_soc_is_detected())
  197. soc_detect(AT91_BASE_DBGU1);
  198. if (!at91_soc_is_detected())
  199. panic("AT91: Impossible to detect the SOC type");
  200. pr_info("AT91: Detected soc type: %s\n",
  201. at91_get_soc_type(&at91_soc_initdata));
  202. pr_info("AT91: Detected soc subtype: %s\n",
  203. at91_get_soc_subtype(&at91_soc_initdata));
  204. if (!at91_soc_is_enabled())
  205. panic("AT91: Soc not enabled");
  206. if (at91_boot_soc.map_io)
  207. at91_boot_soc.map_io();
  208. }
  209. void __iomem *at91_shdwc_base = NULL;
  210. static void at91sam9_poweroff(void)
  211. {
  212. at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  213. }
  214. void __init at91_ioremap_shdwc(u32 base_addr)
  215. {
  216. at91_shdwc_base = ioremap(base_addr, 16);
  217. if (!at91_shdwc_base)
  218. panic("Impossible to ioremap at91_shdwc_base\n");
  219. pm_power_off = at91sam9_poweroff;
  220. }
  221. void __iomem *at91_rstc_base;
  222. void __init at91_ioremap_rstc(u32 base_addr)
  223. {
  224. at91_rstc_base = ioremap(base_addr, 16);
  225. if (!at91_rstc_base)
  226. panic("Impossible to ioremap at91_rstc_base\n");
  227. }
  228. void __init at91_initialize(unsigned long main_clock)
  229. {
  230. at91_boot_soc.ioremap_registers();
  231. /* Init clock subsystem */
  232. at91_clock_init(main_clock);
  233. /* Register the processor-specific clocks */
  234. at91_boot_soc.register_clocks();
  235. at91_boot_soc.init();
  236. }