setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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 <linux/of_address.h>
  12. #include <asm/mach/map.h>
  13. #include <mach/hardware.h>
  14. #include <mach/cpu.h>
  15. #include <mach/at91_dbgu.h>
  16. #include <mach/at91_pmc.h>
  17. #include <mach/at91_shdwc.h>
  18. #include "soc.h"
  19. #include "generic.h"
  20. struct at91_init_soc __initdata at91_boot_soc;
  21. struct at91_socinfo at91_soc_initdata;
  22. EXPORT_SYMBOL(at91_soc_initdata);
  23. void __init at91rm9200_set_type(int type)
  24. {
  25. if (type == ARCH_REVISON_9200_PQFP)
  26. at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
  27. else
  28. at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
  29. pr_info("AT91: filled in soc subtype: %s\n",
  30. at91_get_soc_subtype(&at91_soc_initdata));
  31. }
  32. void __init at91_init_irq_default(void)
  33. {
  34. at91_init_interrupts(at91_boot_soc.default_irq_priority);
  35. }
  36. void __init at91_init_interrupts(unsigned int *priority)
  37. {
  38. /* Initialize the AIC interrupt controller */
  39. at91_aic_init(priority);
  40. /* Enable GPIO interrupts */
  41. at91_gpio_irq_setup();
  42. }
  43. void __iomem *at91_ramc_base[2];
  44. void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
  45. {
  46. if (id < 0 || id > 1) {
  47. pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
  48. BUG();
  49. }
  50. at91_ramc_base[id] = ioremap(addr, size);
  51. if (!at91_ramc_base[id])
  52. panic("Impossible to ioremap ramc.%d 0x%x\n", id, addr);
  53. }
  54. static struct map_desc sram_desc[2] __initdata;
  55. void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
  56. {
  57. struct map_desc *desc = &sram_desc[bank];
  58. desc->virtual = AT91_IO_VIRT_BASE - length;
  59. if (bank > 0)
  60. desc->virtual -= sram_desc[bank - 1].length;
  61. desc->pfn = __phys_to_pfn(base);
  62. desc->length = length;
  63. desc->type = MT_DEVICE;
  64. pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
  65. base, length, desc->virtual);
  66. iotable_init(desc, 1);
  67. }
  68. static struct map_desc at91_io_desc __initdata = {
  69. .virtual = AT91_VA_BASE_SYS,
  70. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  71. .length = SZ_16K,
  72. .type = MT_DEVICE,
  73. };
  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_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_SAM9260] = "at91sam9260",
  167. [AT91_SOC_SAM9261] = "at91sam9261",
  168. [AT91_SOC_SAM9263] = "at91sam9263",
  169. [AT91_SOC_SAM9G10] = "at91sam9g10",
  170. [AT91_SOC_SAM9G20] = "at91sam9g20",
  171. [AT91_SOC_SAM9G45] = "at91sam9g45",
  172. [AT91_SOC_SAM9RL] = "at91sam9rl",
  173. [AT91_SOC_SAM9X5] = "at91sam9x5",
  174. [AT91_SOC_NONE] = "Unknown"
  175. };
  176. const char *at91_get_soc_type(struct at91_socinfo *c)
  177. {
  178. return soc_name[c->type];
  179. }
  180. EXPORT_SYMBOL(at91_get_soc_type);
  181. static const char *soc_subtype_name[] = {
  182. [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
  183. [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
  184. [AT91_SOC_SAM9XE] = "at91sam9xe",
  185. [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
  186. [AT91_SOC_SAM9M10] = "at91sam9m10",
  187. [AT91_SOC_SAM9G46] = "at91sam9g46",
  188. [AT91_SOC_SAM9M11] = "at91sam9m11",
  189. [AT91_SOC_SAM9G15] = "at91sam9g15",
  190. [AT91_SOC_SAM9G35] = "at91sam9g35",
  191. [AT91_SOC_SAM9X35] = "at91sam9x35",
  192. [AT91_SOC_SAM9G25] = "at91sam9g25",
  193. [AT91_SOC_SAM9X25] = "at91sam9x25",
  194. [AT91_SOC_SUBTYPE_NONE] = "Unknown"
  195. };
  196. const char *at91_get_soc_subtype(struct at91_socinfo *c)
  197. {
  198. return soc_subtype_name[c->subtype];
  199. }
  200. EXPORT_SYMBOL(at91_get_soc_subtype);
  201. void __init at91_map_io(void)
  202. {
  203. /* Map peripherals */
  204. iotable_init(&at91_io_desc, 1);
  205. at91_soc_initdata.type = AT91_SOC_NONE;
  206. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  207. soc_detect(AT91_BASE_DBGU0);
  208. if (!at91_soc_is_detected())
  209. soc_detect(AT91_BASE_DBGU1);
  210. if (!at91_soc_is_detected())
  211. panic("AT91: Impossible to detect the SOC type");
  212. pr_info("AT91: Detected soc type: %s\n",
  213. at91_get_soc_type(&at91_soc_initdata));
  214. pr_info("AT91: Detected soc subtype: %s\n",
  215. at91_get_soc_subtype(&at91_soc_initdata));
  216. if (!at91_soc_is_enabled())
  217. panic("AT91: Soc not enabled");
  218. if (at91_boot_soc.map_io)
  219. at91_boot_soc.map_io();
  220. }
  221. void __iomem *at91_shdwc_base = NULL;
  222. static void at91sam9_poweroff(void)
  223. {
  224. at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  225. }
  226. void __init at91_ioremap_shdwc(u32 base_addr)
  227. {
  228. at91_shdwc_base = ioremap(base_addr, 16);
  229. if (!at91_shdwc_base)
  230. panic("Impossible to ioremap at91_shdwc_base\n");
  231. pm_power_off = at91sam9_poweroff;
  232. }
  233. void __iomem *at91_rstc_base;
  234. void __init at91_ioremap_rstc(u32 base_addr)
  235. {
  236. at91_rstc_base = ioremap(base_addr, 16);
  237. if (!at91_rstc_base)
  238. panic("Impossible to ioremap at91_rstc_base\n");
  239. }
  240. void __iomem *at91_matrix_base;
  241. void __init at91_ioremap_matrix(u32 base_addr)
  242. {
  243. at91_matrix_base = ioremap(base_addr, 512);
  244. if (!at91_matrix_base)
  245. panic("Impossible to ioremap at91_matrix_base\n");
  246. }
  247. #if defined(CONFIG_OF)
  248. static struct of_device_id rstc_ids[] = {
  249. { .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
  250. { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart },
  251. { /*sentinel*/ }
  252. };
  253. static void at91_dt_rstc(void)
  254. {
  255. struct device_node *np;
  256. const struct of_device_id *of_id;
  257. np = of_find_matching_node(NULL, rstc_ids);
  258. if (!np)
  259. panic("unable to find compatible rstc node in dtb\n");
  260. at91_rstc_base = of_iomap(np, 0);
  261. if (!at91_rstc_base)
  262. panic("unable to map rstc cpu registers\n");
  263. of_id = of_match_node(rstc_ids, np);
  264. if (!of_id)
  265. panic("AT91: rtsc no restart function availlable\n");
  266. arm_pm_restart = of_id->data;
  267. of_node_put(np);
  268. }
  269. static struct of_device_id ramc_ids[] = {
  270. { .compatible = "atmel,at91sam9260-sdramc" },
  271. { .compatible = "atmel,at91sam9g45-ddramc" },
  272. { /*sentinel*/ }
  273. };
  274. static void at91_dt_ramc(void)
  275. {
  276. struct device_node *np;
  277. np = of_find_matching_node(NULL, ramc_ids);
  278. if (!np)
  279. panic("unable to find compatible ram conroller node in dtb\n");
  280. at91_ramc_base[0] = of_iomap(np, 0);
  281. if (!at91_ramc_base[0])
  282. panic("unable to map ramc[0] cpu registers\n");
  283. /* the controller may have 2 banks */
  284. at91_ramc_base[1] = of_iomap(np, 1);
  285. of_node_put(np);
  286. }
  287. static struct of_device_id shdwc_ids[] = {
  288. { .compatible = "atmel,at91sam9260-shdwc", },
  289. { .compatible = "atmel,at91sam9rl-shdwc", },
  290. { .compatible = "atmel,at91sam9x5-shdwc", },
  291. { /*sentinel*/ }
  292. };
  293. static const char *shdwc_wakeup_modes[] = {
  294. [AT91_SHDW_WKMODE0_NONE] = "none",
  295. [AT91_SHDW_WKMODE0_HIGH] = "high",
  296. [AT91_SHDW_WKMODE0_LOW] = "low",
  297. [AT91_SHDW_WKMODE0_ANYLEVEL] = "any",
  298. };
  299. const int at91_dtget_shdwc_wakeup_mode(struct device_node *np)
  300. {
  301. const char *pm;
  302. int err, i;
  303. err = of_property_read_string(np, "atmel,wakeup-mode", &pm);
  304. if (err < 0)
  305. return AT91_SHDW_WKMODE0_ANYLEVEL;
  306. for (i = 0; i < ARRAY_SIZE(shdwc_wakeup_modes); i++)
  307. if (!strcasecmp(pm, shdwc_wakeup_modes[i]))
  308. return i;
  309. return -ENODEV;
  310. }
  311. static void at91_dt_shdwc(void)
  312. {
  313. struct device_node *np;
  314. int wakeup_mode;
  315. u32 reg;
  316. u32 mode = 0;
  317. np = of_find_matching_node(NULL, shdwc_ids);
  318. if (!np) {
  319. pr_debug("AT91: unable to find compatible shutdown (shdwc) conroller node in dtb\n");
  320. return;
  321. }
  322. at91_shdwc_base = of_iomap(np, 0);
  323. if (!at91_shdwc_base)
  324. panic("AT91: unable to map shdwc cpu registers\n");
  325. wakeup_mode = at91_dtget_shdwc_wakeup_mode(np);
  326. if (wakeup_mode < 0) {
  327. pr_warn("AT91: shdwc unknown wakeup mode\n");
  328. goto end;
  329. }
  330. if (!of_property_read_u32(np, "atmel,wakeup-counter", &reg)) {
  331. if (reg > AT91_SHDW_CPTWK0_MAX) {
  332. pr_warn("AT91: shdwc wakeup conter 0x%x > 0x%x reduce it to 0x%x\n",
  333. reg, AT91_SHDW_CPTWK0_MAX, AT91_SHDW_CPTWK0_MAX);
  334. reg = AT91_SHDW_CPTWK0_MAX;
  335. }
  336. mode |= AT91_SHDW_CPTWK0_(reg);
  337. }
  338. if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
  339. mode |= AT91_SHDW_RTCWKEN;
  340. if (of_property_read_bool(np, "atmel,wakeup-rtt-timer"))
  341. mode |= AT91_SHDW_RTTWKEN;
  342. at91_shdwc_write(AT91_SHDW_MR, wakeup_mode | mode);
  343. end:
  344. pm_power_off = at91sam9_poweroff;
  345. of_node_put(np);
  346. }
  347. void __init at91_dt_initialize(void)
  348. {
  349. at91_dt_rstc();
  350. at91_dt_ramc();
  351. at91_dt_shdwc();
  352. /* Init clock subsystem */
  353. at91_dt_clock_init();
  354. /* Register the processor-specific clocks */
  355. at91_boot_soc.register_clocks();
  356. at91_boot_soc.init();
  357. }
  358. #endif
  359. void __init at91_initialize(unsigned long main_clock)
  360. {
  361. at91_boot_soc.ioremap_registers();
  362. /* Init clock subsystem */
  363. at91_clock_init(main_clock);
  364. /* Register the processor-specific clocks */
  365. at91_boot_soc.register_clocks();
  366. at91_boot_soc.init();
  367. }