setup.c 11 KB

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