setup.c 7.7 KB

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