setup.c 13 KB

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