setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation.
  3. * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  4. *
  5. * Under GPLv2
  6. */
  7. #define pr_fmt(fmt) "AT91: " fmt
  8. #include <linux/module.h>
  9. #include <linux/io.h>
  10. #include <linux/mm.h>
  11. #include <linux/pm.h>
  12. #include <linux/of_address.h>
  13. #include <linux/pinctrl/machine.h>
  14. #include <linux/clk/at91_pmc.h>
  15. #include <asm/system_misc.h>
  16. #include <asm/mach/map.h>
  17. #include <mach/hardware.h>
  18. #include <mach/cpu.h>
  19. #include <mach/at91_dbgu.h>
  20. #include "soc.h"
  21. #include "generic.h"
  22. #include "pm.h"
  23. struct at91_init_soc __initdata at91_boot_soc;
  24. struct at91_socinfo at91_soc_initdata;
  25. EXPORT_SYMBOL(at91_soc_initdata);
  26. void __init at91rm9200_set_type(int type)
  27. {
  28. if (type == ARCH_REVISON_9200_PQFP)
  29. at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
  30. else
  31. at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
  32. pr_info("filled in soc subtype: %s\n",
  33. at91_get_soc_subtype(&at91_soc_initdata));
  34. }
  35. void __init at91_init_irq_default(void)
  36. {
  37. at91_init_interrupts(at91_boot_soc.default_irq_priority);
  38. }
  39. void __init at91_init_interrupts(unsigned int *priority)
  40. {
  41. /* Initialize the AIC interrupt controller */
  42. if (IS_ENABLED(CONFIG_OLD_IRQ_AT91))
  43. at91_aic_init(priority, at91_boot_soc.extern_irq);
  44. /* Enable GPIO interrupts */
  45. at91_gpio_irq_setup();
  46. }
  47. void __iomem *at91_ramc_base[2];
  48. EXPORT_SYMBOL_GPL(at91_ramc_base);
  49. void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
  50. {
  51. if (id < 0 || id > 1) {
  52. pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
  53. BUG();
  54. }
  55. at91_ramc_base[id] = ioremap(addr, size);
  56. if (!at91_ramc_base[id])
  57. panic(pr_fmt("Impossible to ioremap ramc.%d 0x%x\n"), id, addr);
  58. }
  59. static struct map_desc sram_desc[2] __initdata;
  60. void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
  61. {
  62. struct map_desc *desc = &sram_desc[bank];
  63. desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
  64. if (bank > 0)
  65. desc->virtual -= sram_desc[bank - 1].length;
  66. desc->pfn = __phys_to_pfn(base);
  67. desc->length = length;
  68. desc->type = MT_MEMORY_RWX_NONCACHED;
  69. pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
  70. base, length, desc->virtual);
  71. iotable_init(desc, 1);
  72. }
  73. static struct map_desc at91_io_desc __initdata __maybe_unused = {
  74. .virtual = (unsigned long)AT91_VA_BASE_SYS,
  75. .pfn = __phys_to_pfn(AT91_BASE_SYS),
  76. .length = SZ_16K,
  77. .type = MT_DEVICE,
  78. };
  79. static struct map_desc at91_alt_io_desc __initdata __maybe_unused = {
  80. .virtual = (unsigned long)AT91_ALT_VA_BASE_SYS,
  81. .pfn = __phys_to_pfn(AT91_ALT_BASE_SYS),
  82. .length = 24 * SZ_1K,
  83. .type = MT_DEVICE,
  84. };
  85. static void __init soc_detect(u32 dbgu_base)
  86. {
  87. u32 cidr, socid;
  88. cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
  89. socid = cidr & ~AT91_CIDR_VERSION;
  90. switch (socid) {
  91. case ARCH_ID_AT91RM9200:
  92. at91_soc_initdata.type = AT91_SOC_RM9200;
  93. if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
  94. at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
  95. at91_boot_soc = at91rm9200_soc;
  96. break;
  97. case ARCH_ID_AT91SAM9260:
  98. at91_soc_initdata.type = AT91_SOC_SAM9260;
  99. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  100. at91_boot_soc = at91sam9260_soc;
  101. break;
  102. case ARCH_ID_AT91SAM9261:
  103. at91_soc_initdata.type = AT91_SOC_SAM9261;
  104. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  105. at91_boot_soc = at91sam9261_soc;
  106. break;
  107. case ARCH_ID_AT91SAM9263:
  108. at91_soc_initdata.type = AT91_SOC_SAM9263;
  109. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  110. at91_boot_soc = at91sam9263_soc;
  111. break;
  112. case ARCH_ID_AT91SAM9G20:
  113. at91_soc_initdata.type = AT91_SOC_SAM9G20;
  114. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  115. at91_boot_soc = at91sam9260_soc;
  116. break;
  117. case ARCH_ID_AT91SAM9G45:
  118. at91_soc_initdata.type = AT91_SOC_SAM9G45;
  119. if (cidr == ARCH_ID_AT91SAM9G45ES)
  120. at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
  121. at91_boot_soc = at91sam9g45_soc;
  122. break;
  123. case ARCH_ID_AT91SAM9RL64:
  124. at91_soc_initdata.type = AT91_SOC_SAM9RL;
  125. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  126. at91_boot_soc = at91sam9rl_soc;
  127. break;
  128. case ARCH_ID_AT91SAM9X5:
  129. at91_soc_initdata.type = AT91_SOC_SAM9X5;
  130. at91_boot_soc = at91sam9x5_soc;
  131. break;
  132. case ARCH_ID_AT91SAM9N12:
  133. at91_soc_initdata.type = AT91_SOC_SAM9N12;
  134. at91_boot_soc = at91sam9n12_soc;
  135. break;
  136. case ARCH_ID_SAMA5:
  137. at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
  138. if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
  139. at91_soc_initdata.type = AT91_SOC_SAMA5D3;
  140. at91_boot_soc = sama5d3_soc;
  141. }
  142. break;
  143. }
  144. /* at91sam9g10 */
  145. if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
  146. at91_soc_initdata.type = AT91_SOC_SAM9G10;
  147. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
  148. at91_boot_soc = at91sam9261_soc;
  149. }
  150. /* at91sam9xe */
  151. else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
  152. at91_soc_initdata.type = AT91_SOC_SAM9260;
  153. at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
  154. at91_boot_soc = at91sam9260_soc;
  155. }
  156. if (!at91_soc_is_detected())
  157. return;
  158. at91_soc_initdata.cidr = cidr;
  159. /* sub version of soc */
  160. if (!at91_soc_initdata.exid)
  161. at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
  162. if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
  163. switch (at91_soc_initdata.exid) {
  164. case ARCH_EXID_AT91SAM9M10:
  165. at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
  166. break;
  167. case ARCH_EXID_AT91SAM9G46:
  168. at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
  169. break;
  170. case ARCH_EXID_AT91SAM9M11:
  171. at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
  172. break;
  173. }
  174. }
  175. if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
  176. switch (at91_soc_initdata.exid) {
  177. case ARCH_EXID_AT91SAM9G15:
  178. at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
  179. break;
  180. case ARCH_EXID_AT91SAM9G35:
  181. at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
  182. break;
  183. case ARCH_EXID_AT91SAM9X35:
  184. at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
  185. break;
  186. case ARCH_EXID_AT91SAM9G25:
  187. at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
  188. break;
  189. case ARCH_EXID_AT91SAM9X25:
  190. at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
  191. break;
  192. }
  193. }
  194. if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
  195. switch (at91_soc_initdata.exid) {
  196. case ARCH_EXID_SAMA5D31:
  197. at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
  198. break;
  199. case ARCH_EXID_SAMA5D33:
  200. at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
  201. break;
  202. case ARCH_EXID_SAMA5D34:
  203. at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
  204. break;
  205. case ARCH_EXID_SAMA5D35:
  206. at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
  207. break;
  208. case ARCH_EXID_SAMA5D36:
  209. at91_soc_initdata.subtype = AT91_SOC_SAMA5D36;
  210. break;
  211. }
  212. }
  213. }
  214. static void __init alt_soc_detect(u32 dbgu_base)
  215. {
  216. u32 cidr, socid;
  217. /* SoC ID */
  218. cidr = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
  219. socid = cidr & ~AT91_CIDR_VERSION;
  220. switch (socid) {
  221. case ARCH_ID_SAMA5:
  222. at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
  223. if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
  224. at91_soc_initdata.type = AT91_SOC_SAMA5D3;
  225. at91_boot_soc = sama5d3_soc;
  226. } else if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D4) {
  227. at91_soc_initdata.type = AT91_SOC_SAMA5D4;
  228. at91_boot_soc = sama5d4_soc;
  229. }
  230. break;
  231. }
  232. if (!at91_soc_is_detected())
  233. return;
  234. at91_soc_initdata.cidr = cidr;
  235. /* sub version of soc */
  236. if (!at91_soc_initdata.exid)
  237. at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
  238. if (at91_soc_initdata.type == AT91_SOC_SAMA5D4) {
  239. switch (at91_soc_initdata.exid) {
  240. case ARCH_EXID_SAMA5D41:
  241. at91_soc_initdata.subtype = AT91_SOC_SAMA5D41;
  242. break;
  243. case ARCH_EXID_SAMA5D42:
  244. at91_soc_initdata.subtype = AT91_SOC_SAMA5D42;
  245. break;
  246. case ARCH_EXID_SAMA5D43:
  247. at91_soc_initdata.subtype = AT91_SOC_SAMA5D43;
  248. break;
  249. case ARCH_EXID_SAMA5D44:
  250. at91_soc_initdata.subtype = AT91_SOC_SAMA5D44;
  251. break;
  252. }
  253. }
  254. }
  255. static const char *soc_name[] = {
  256. [AT91_SOC_RM9200] = "at91rm9200",
  257. [AT91_SOC_SAM9260] = "at91sam9260",
  258. [AT91_SOC_SAM9261] = "at91sam9261",
  259. [AT91_SOC_SAM9263] = "at91sam9263",
  260. [AT91_SOC_SAM9G10] = "at91sam9g10",
  261. [AT91_SOC_SAM9G20] = "at91sam9g20",
  262. [AT91_SOC_SAM9G45] = "at91sam9g45",
  263. [AT91_SOC_SAM9RL] = "at91sam9rl",
  264. [AT91_SOC_SAM9X5] = "at91sam9x5",
  265. [AT91_SOC_SAM9N12] = "at91sam9n12",
  266. [AT91_SOC_SAMA5D3] = "sama5d3",
  267. [AT91_SOC_SAMA5D4] = "sama5d4",
  268. [AT91_SOC_UNKNOWN] = "Unknown",
  269. };
  270. const char *at91_get_soc_type(struct at91_socinfo *c)
  271. {
  272. return soc_name[c->type];
  273. }
  274. EXPORT_SYMBOL(at91_get_soc_type);
  275. static const char *soc_subtype_name[] = {
  276. [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
  277. [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
  278. [AT91_SOC_SAM9XE] = "at91sam9xe",
  279. [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
  280. [AT91_SOC_SAM9M10] = "at91sam9m10",
  281. [AT91_SOC_SAM9G46] = "at91sam9g46",
  282. [AT91_SOC_SAM9M11] = "at91sam9m11",
  283. [AT91_SOC_SAM9G15] = "at91sam9g15",
  284. [AT91_SOC_SAM9G35] = "at91sam9g35",
  285. [AT91_SOC_SAM9X35] = "at91sam9x35",
  286. [AT91_SOC_SAM9G25] = "at91sam9g25",
  287. [AT91_SOC_SAM9X25] = "at91sam9x25",
  288. [AT91_SOC_SAMA5D31] = "sama5d31",
  289. [AT91_SOC_SAMA5D33] = "sama5d33",
  290. [AT91_SOC_SAMA5D34] = "sama5d34",
  291. [AT91_SOC_SAMA5D35] = "sama5d35",
  292. [AT91_SOC_SAMA5D36] = "sama5d36",
  293. [AT91_SOC_SAMA5D41] = "sama5d41",
  294. [AT91_SOC_SAMA5D42] = "sama5d42",
  295. [AT91_SOC_SAMA5D43] = "sama5d43",
  296. [AT91_SOC_SAMA5D44] = "sama5d44",
  297. [AT91_SOC_SUBTYPE_NONE] = "None",
  298. [AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
  299. };
  300. const char *at91_get_soc_subtype(struct at91_socinfo *c)
  301. {
  302. return soc_subtype_name[c->subtype];
  303. }
  304. EXPORT_SYMBOL(at91_get_soc_subtype);
  305. void __init at91_map_io(void)
  306. {
  307. /* Map peripherals */
  308. iotable_init(&at91_io_desc, 1);
  309. at91_soc_initdata.type = AT91_SOC_UNKNOWN;
  310. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
  311. soc_detect(AT91_BASE_DBGU0);
  312. if (!at91_soc_is_detected())
  313. soc_detect(AT91_BASE_DBGU1);
  314. if (!at91_soc_is_detected())
  315. panic(pr_fmt("Impossible to detect the SOC type"));
  316. pr_info("Detected soc type: %s\n",
  317. at91_get_soc_type(&at91_soc_initdata));
  318. if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
  319. pr_info("Detected soc subtype: %s\n",
  320. at91_get_soc_subtype(&at91_soc_initdata));
  321. if (!at91_soc_is_enabled())
  322. panic(pr_fmt("Soc not enabled"));
  323. if (at91_boot_soc.map_io)
  324. at91_boot_soc.map_io();
  325. }
  326. void __init at91_alt_map_io(void)
  327. {
  328. /* Map peripherals */
  329. iotable_init(&at91_alt_io_desc, 1);
  330. at91_soc_initdata.type = AT91_SOC_UNKNOWN;
  331. at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
  332. alt_soc_detect(AT91_BASE_DBGU2);
  333. if (!at91_soc_is_detected())
  334. panic("AT91: Impossible to detect the SOC type");
  335. pr_info("AT91: Detected soc type: %s\n",
  336. at91_get_soc_type(&at91_soc_initdata));
  337. if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
  338. pr_info("AT91: Detected soc subtype: %s\n",
  339. at91_get_soc_subtype(&at91_soc_initdata));
  340. if (!at91_soc_is_enabled())
  341. panic("AT91: Soc not enabled");
  342. if (at91_boot_soc.map_io)
  343. at91_boot_soc.map_io();
  344. }
  345. void __iomem *at91_matrix_base;
  346. EXPORT_SYMBOL_GPL(at91_matrix_base);
  347. void __init at91_ioremap_matrix(u32 base_addr)
  348. {
  349. at91_matrix_base = ioremap(base_addr, 512);
  350. if (!at91_matrix_base)
  351. panic(pr_fmt("Impossible to ioremap at91_matrix_base\n"));
  352. }
  353. #if defined(CONFIG_OF) && !defined(CONFIG_ARCH_AT91X40)
  354. static struct of_device_id ramc_ids[] = {
  355. { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
  356. { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
  357. { .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby },
  358. { .compatible = "atmel,sama5d3-ddramc", .data = at91_ddr_standby },
  359. { /*sentinel*/ }
  360. };
  361. static void at91_dt_ramc(void)
  362. {
  363. struct device_node *np;
  364. const struct of_device_id *of_id;
  365. int idx = 0;
  366. const void *standby = NULL;
  367. for_each_matching_node_and_match(np, ramc_ids, &of_id) {
  368. at91_ramc_base[idx] = of_iomap(np, 0);
  369. if (!at91_ramc_base[idx])
  370. panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx);
  371. if (!standby)
  372. standby = of_id->data;
  373. idx++;
  374. }
  375. if (!idx)
  376. panic(pr_fmt("unable to find compatible ram controller node in dtb\n"));
  377. if (!standby) {
  378. pr_warn("ramc no standby function available\n");
  379. return;
  380. }
  381. at91_pm_set_standby(standby);
  382. }
  383. void __init at91rm9200_dt_initialize(void)
  384. {
  385. at91_dt_ramc();
  386. /* Init clock subsystem */
  387. at91_dt_clock_init();
  388. /* Register the processor-specific clocks */
  389. if (at91_boot_soc.register_clocks)
  390. at91_boot_soc.register_clocks();
  391. at91_boot_soc.init();
  392. }
  393. void __init at91_dt_initialize(void)
  394. {
  395. at91_dt_ramc();
  396. /* Init clock subsystem */
  397. at91_dt_clock_init();
  398. /* Register the processor-specific clocks */
  399. if (at91_boot_soc.register_clocks)
  400. at91_boot_soc.register_clocks();
  401. if (at91_boot_soc.init)
  402. at91_boot_soc.init();
  403. }
  404. #endif
  405. void __init at91_initialize(unsigned long main_clock)
  406. {
  407. at91_boot_soc.ioremap_registers();
  408. /* Init clock subsystem */
  409. at91_clock_init(main_clock);
  410. /* Register the processor-specific clocks */
  411. at91_boot_soc.register_clocks();
  412. at91_boot_soc.init();
  413. pinctrl_provide_dummies();
  414. }
  415. void __init at91_register_devices(void)
  416. {
  417. at91_boot_soc.register_devices();
  418. }
  419. void __init at91_init_time(void)
  420. {
  421. at91_boot_soc.init_time();
  422. }