common.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. /*
  2. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * Common Codes for EXYNOS
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/io.h>
  15. #include <linux/device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/sched.h>
  18. #include <linux/serial_core.h>
  19. #include <linux/of.h>
  20. #include <linux/of_irq.h>
  21. #include <linux/export.h>
  22. #include <linux/irqdomain.h>
  23. #include <linux/of_address.h>
  24. #include <asm/proc-fns.h>
  25. #include <asm/exception.h>
  26. #include <asm/hardware/cache-l2x0.h>
  27. #include <asm/hardware/gic.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/mach/irq.h>
  30. #include <asm/cacheflush.h>
  31. #include <mach/regs-irq.h>
  32. #include <mach/regs-pmu.h>
  33. #include <mach/regs-gpio.h>
  34. #include <mach/pmu.h>
  35. #include <plat/cpu.h>
  36. #include <plat/clock.h>
  37. #include <plat/devs.h>
  38. #include <plat/pm.h>
  39. #include <plat/sdhci.h>
  40. #include <plat/gpio-cfg.h>
  41. #include <plat/adc-core.h>
  42. #include <plat/fb-core.h>
  43. #include <plat/fimc-core.h>
  44. #include <plat/iic-core.h>
  45. #include <plat/tv-core.h>
  46. #include <plat/spi-core.h>
  47. #include <plat/regs-serial.h>
  48. #include "common.h"
  49. #define L2_AUX_VAL 0x7C470001
  50. #define L2_AUX_MASK 0xC200ffff
  51. static const char name_exynos4210[] = "EXYNOS4210";
  52. static const char name_exynos4212[] = "EXYNOS4212";
  53. static const char name_exynos4412[] = "EXYNOS4412";
  54. static const char name_exynos5250[] = "EXYNOS5250";
  55. static const char name_exynos5440[] = "EXYNOS5440";
  56. static void exynos4_map_io(void);
  57. static void exynos5_map_io(void);
  58. static void exynos5440_map_io(void);
  59. static void exynos4_init_clocks(int xtal);
  60. static void exynos5_init_clocks(int xtal);
  61. static void exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no);
  62. static int exynos_init(void);
  63. static struct cpu_table cpu_ids[] __initdata = {
  64. {
  65. .idcode = EXYNOS4210_CPU_ID,
  66. .idmask = EXYNOS4_CPU_MASK,
  67. .map_io = exynos4_map_io,
  68. .init_clocks = exynos4_init_clocks,
  69. .init_uarts = exynos_init_uarts,
  70. .init = exynos_init,
  71. .name = name_exynos4210,
  72. }, {
  73. .idcode = EXYNOS4212_CPU_ID,
  74. .idmask = EXYNOS4_CPU_MASK,
  75. .map_io = exynos4_map_io,
  76. .init_clocks = exynos4_init_clocks,
  77. .init_uarts = exynos_init_uarts,
  78. .init = exynos_init,
  79. .name = name_exynos4212,
  80. }, {
  81. .idcode = EXYNOS4412_CPU_ID,
  82. .idmask = EXYNOS4_CPU_MASK,
  83. .map_io = exynos4_map_io,
  84. .init_clocks = exynos4_init_clocks,
  85. .init_uarts = exynos_init_uarts,
  86. .init = exynos_init,
  87. .name = name_exynos4412,
  88. }, {
  89. .idcode = EXYNOS5250_SOC_ID,
  90. .idmask = EXYNOS5_SOC_MASK,
  91. .map_io = exynos5_map_io,
  92. .init_clocks = exynos5_init_clocks,
  93. .init_uarts = exynos_init_uarts,
  94. .init = exynos_init,
  95. .name = name_exynos5250,
  96. }, {
  97. .idcode = EXYNOS5440_SOC_ID,
  98. .idmask = EXYNOS5_SOC_MASK,
  99. .map_io = exynos5440_map_io,
  100. .init = exynos_init,
  101. .name = name_exynos5440,
  102. },
  103. };
  104. /* Initial IO mappings */
  105. static struct map_desc exynos_iodesc[] __initdata = {
  106. {
  107. .virtual = (unsigned long)S5P_VA_CHIPID,
  108. .pfn = __phys_to_pfn(EXYNOS_PA_CHIPID),
  109. .length = SZ_4K,
  110. .type = MT_DEVICE,
  111. },
  112. };
  113. static struct map_desc exynos5440_iodesc[] __initdata = {
  114. {
  115. .virtual = (unsigned long)S5P_VA_CHIPID,
  116. .pfn = __phys_to_pfn(EXYNOS5440_PA_CHIPID),
  117. .length = SZ_4K,
  118. .type = MT_DEVICE,
  119. },
  120. };
  121. static struct map_desc exynos4_iodesc[] __initdata = {
  122. {
  123. .virtual = (unsigned long)S3C_VA_SYS,
  124. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON),
  125. .length = SZ_64K,
  126. .type = MT_DEVICE,
  127. }, {
  128. .virtual = (unsigned long)S3C_VA_TIMER,
  129. .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
  130. .length = SZ_16K,
  131. .type = MT_DEVICE,
  132. }, {
  133. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  134. .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
  135. .length = SZ_4K,
  136. .type = MT_DEVICE,
  137. }, {
  138. .virtual = (unsigned long)S5P_VA_SROMC,
  139. .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
  140. .length = SZ_4K,
  141. .type = MT_DEVICE,
  142. }, {
  143. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  144. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
  145. .length = SZ_4K,
  146. .type = MT_DEVICE,
  147. }, {
  148. .virtual = (unsigned long)S5P_VA_PMU,
  149. .pfn = __phys_to_pfn(EXYNOS4_PA_PMU),
  150. .length = SZ_64K,
  151. .type = MT_DEVICE,
  152. }, {
  153. .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
  154. .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
  155. .length = SZ_4K,
  156. .type = MT_DEVICE,
  157. }, {
  158. .virtual = (unsigned long)S5P_VA_GIC_CPU,
  159. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
  160. .length = SZ_64K,
  161. .type = MT_DEVICE,
  162. }, {
  163. .virtual = (unsigned long)S5P_VA_GIC_DIST,
  164. .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
  165. .length = SZ_64K,
  166. .type = MT_DEVICE,
  167. }, {
  168. .virtual = (unsigned long)S3C_VA_UART,
  169. .pfn = __phys_to_pfn(EXYNOS4_PA_UART),
  170. .length = SZ_512K,
  171. .type = MT_DEVICE,
  172. }, {
  173. .virtual = (unsigned long)S5P_VA_CMU,
  174. .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
  175. .length = SZ_128K,
  176. .type = MT_DEVICE,
  177. }, {
  178. .virtual = (unsigned long)S5P_VA_COREPERI_BASE,
  179. .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI),
  180. .length = SZ_8K,
  181. .type = MT_DEVICE,
  182. }, {
  183. .virtual = (unsigned long)S5P_VA_L2CC,
  184. .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
  185. .length = SZ_4K,
  186. .type = MT_DEVICE,
  187. }, {
  188. .virtual = (unsigned long)S5P_VA_DMC0,
  189. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
  190. .length = SZ_64K,
  191. .type = MT_DEVICE,
  192. }, {
  193. .virtual = (unsigned long)S5P_VA_DMC1,
  194. .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
  195. .length = SZ_64K,
  196. .type = MT_DEVICE,
  197. }, {
  198. .virtual = (unsigned long)S3C_VA_USB_HSPHY,
  199. .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
  200. .length = SZ_4K,
  201. .type = MT_DEVICE,
  202. },
  203. };
  204. static struct map_desc exynos4_iodesc0[] __initdata = {
  205. {
  206. .virtual = (unsigned long)S5P_VA_SYSRAM,
  207. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0),
  208. .length = SZ_4K,
  209. .type = MT_DEVICE,
  210. },
  211. };
  212. static struct map_desc exynos4_iodesc1[] __initdata = {
  213. {
  214. .virtual = (unsigned long)S5P_VA_SYSRAM,
  215. .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1),
  216. .length = SZ_4K,
  217. .type = MT_DEVICE,
  218. },
  219. };
  220. static struct map_desc exynos5_iodesc[] __initdata = {
  221. {
  222. .virtual = (unsigned long)S3C_VA_SYS,
  223. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSCON),
  224. .length = SZ_64K,
  225. .type = MT_DEVICE,
  226. }, {
  227. .virtual = (unsigned long)S3C_VA_TIMER,
  228. .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
  229. .length = SZ_16K,
  230. .type = MT_DEVICE,
  231. }, {
  232. .virtual = (unsigned long)S3C_VA_WATCHDOG,
  233. .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
  234. .length = SZ_4K,
  235. .type = MT_DEVICE,
  236. }, {
  237. .virtual = (unsigned long)S5P_VA_SROMC,
  238. .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
  239. .length = SZ_4K,
  240. .type = MT_DEVICE,
  241. }, {
  242. .virtual = (unsigned long)S5P_VA_SYSTIMER,
  243. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSTIMER),
  244. .length = SZ_4K,
  245. .type = MT_DEVICE,
  246. }, {
  247. .virtual = (unsigned long)S5P_VA_SYSRAM,
  248. .pfn = __phys_to_pfn(EXYNOS5_PA_SYSRAM),
  249. .length = SZ_4K,
  250. .type = MT_DEVICE,
  251. }, {
  252. .virtual = (unsigned long)S5P_VA_CMU,
  253. .pfn = __phys_to_pfn(EXYNOS5_PA_CMU),
  254. .length = 144 * SZ_1K,
  255. .type = MT_DEVICE,
  256. }, {
  257. .virtual = (unsigned long)S5P_VA_PMU,
  258. .pfn = __phys_to_pfn(EXYNOS5_PA_PMU),
  259. .length = SZ_64K,
  260. .type = MT_DEVICE,
  261. }, {
  262. .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
  263. .pfn = __phys_to_pfn(EXYNOS5_PA_COMBINER),
  264. .length = SZ_4K,
  265. .type = MT_DEVICE,
  266. }, {
  267. .virtual = (unsigned long)S3C_VA_UART,
  268. .pfn = __phys_to_pfn(EXYNOS5_PA_UART),
  269. .length = SZ_512K,
  270. .type = MT_DEVICE,
  271. }, {
  272. .virtual = (unsigned long)S5P_VA_GIC_CPU,
  273. .pfn = __phys_to_pfn(EXYNOS5_PA_GIC_CPU),
  274. .length = SZ_8K,
  275. .type = MT_DEVICE,
  276. }, {
  277. .virtual = (unsigned long)S5P_VA_GIC_DIST,
  278. .pfn = __phys_to_pfn(EXYNOS5_PA_GIC_DIST),
  279. .length = SZ_4K,
  280. .type = MT_DEVICE,
  281. },
  282. };
  283. static struct map_desc exynos5440_iodesc0[] __initdata = {
  284. {
  285. .virtual = (unsigned long)S3C_VA_UART,
  286. .pfn = __phys_to_pfn(EXYNOS5440_PA_UART0),
  287. .length = SZ_512K,
  288. .type = MT_DEVICE,
  289. },
  290. };
  291. void exynos4_restart(char mode, const char *cmd)
  292. {
  293. __raw_writel(0x1, S5P_SWRESET);
  294. }
  295. void exynos5_restart(char mode, const char *cmd)
  296. {
  297. u32 val;
  298. void __iomem *addr;
  299. if (of_machine_is_compatible("samsung,exynos5250")) {
  300. val = 0x1;
  301. addr = EXYNOS_SWRESET;
  302. } else if (of_machine_is_compatible("samsung,exynos5440")) {
  303. val = (0x10 << 20) | (0x1 << 16);
  304. addr = EXYNOS5440_SWRESET;
  305. } else {
  306. pr_err("%s: cannot support non-DT\n", __func__);
  307. return;
  308. }
  309. __raw_writel(val, addr);
  310. }
  311. void __init exynos_init_late(void)
  312. {
  313. if (of_machine_is_compatible("samsung,exynos5440"))
  314. /* to be supported later */
  315. return;
  316. exynos_pm_late_initcall();
  317. }
  318. /*
  319. * exynos_map_io
  320. *
  321. * register the standard cpu IO areas
  322. */
  323. void __init exynos_init_io(struct map_desc *mach_desc, int size)
  324. {
  325. /* initialize the io descriptors we need for initialization */
  326. if (of_machine_is_compatible("samsung,exynos5440"))
  327. iotable_init(exynos5440_iodesc, ARRAY_SIZE(exynos5440_iodesc));
  328. else
  329. iotable_init(exynos_iodesc, ARRAY_SIZE(exynos_iodesc));
  330. if (mach_desc)
  331. iotable_init(mach_desc, size);
  332. /* detect cpu id and rev. */
  333. s5p_init_cpu(S5P_VA_CHIPID);
  334. s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
  335. }
  336. static void __init exynos4_map_io(void)
  337. {
  338. iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc));
  339. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0)
  340. iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0));
  341. else
  342. iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1));
  343. /* initialize device information early */
  344. exynos4_default_sdhci0();
  345. exynos4_default_sdhci1();
  346. exynos4_default_sdhci2();
  347. exynos4_default_sdhci3();
  348. s3c_adc_setname("samsung-adc-v3");
  349. s3c_fimc_setname(0, "exynos4-fimc");
  350. s3c_fimc_setname(1, "exynos4-fimc");
  351. s3c_fimc_setname(2, "exynos4-fimc");
  352. s3c_fimc_setname(3, "exynos4-fimc");
  353. s3c_sdhci_setname(0, "exynos4-sdhci");
  354. s3c_sdhci_setname(1, "exynos4-sdhci");
  355. s3c_sdhci_setname(2, "exynos4-sdhci");
  356. s3c_sdhci_setname(3, "exynos4-sdhci");
  357. /* The I2C bus controllers are directly compatible with s3c2440 */
  358. s3c_i2c0_setname("s3c2440-i2c");
  359. s3c_i2c1_setname("s3c2440-i2c");
  360. s3c_i2c2_setname("s3c2440-i2c");
  361. s5p_fb_setname(0, "exynos4-fb");
  362. s5p_hdmi_setname("exynos4-hdmi");
  363. s3c64xx_spi_setname("exynos4210-spi");
  364. }
  365. static void __init exynos5_map_io(void)
  366. {
  367. iotable_init(exynos5_iodesc, ARRAY_SIZE(exynos5_iodesc));
  368. s3c_device_i2c0.resource[0].start = EXYNOS5_PA_IIC(0);
  369. s3c_device_i2c0.resource[0].end = EXYNOS5_PA_IIC(0) + SZ_4K - 1;
  370. s3c_device_i2c0.resource[1].start = EXYNOS5_IRQ_IIC;
  371. s3c_device_i2c0.resource[1].end = EXYNOS5_IRQ_IIC;
  372. s3c_sdhci_setname(0, "exynos4-sdhci");
  373. s3c_sdhci_setname(1, "exynos4-sdhci");
  374. s3c_sdhci_setname(2, "exynos4-sdhci");
  375. s3c_sdhci_setname(3, "exynos4-sdhci");
  376. /* The I2C bus controllers are directly compatible with s3c2440 */
  377. s3c_i2c0_setname("s3c2440-i2c");
  378. s3c_i2c1_setname("s3c2440-i2c");
  379. s3c_i2c2_setname("s3c2440-i2c");
  380. s3c64xx_spi_setname("exynos4210-spi");
  381. }
  382. static void __init exynos4_init_clocks(int xtal)
  383. {
  384. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  385. s3c24xx_register_baseclocks(xtal);
  386. s5p_register_clocks(xtal);
  387. if (soc_is_exynos4210())
  388. exynos4210_register_clocks();
  389. else if (soc_is_exynos4212() || soc_is_exynos4412())
  390. exynos4212_register_clocks();
  391. exynos4_register_clocks();
  392. exynos4_setup_clocks();
  393. }
  394. static void __init exynos5440_map_io(void)
  395. {
  396. iotable_init(exynos5440_iodesc0, ARRAY_SIZE(exynos5440_iodesc0));
  397. }
  398. static void __init exynos5_init_clocks(int xtal)
  399. {
  400. printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
  401. s3c24xx_register_baseclocks(xtal);
  402. s5p_register_clocks(xtal);
  403. exynos5_register_clocks();
  404. exynos5_setup_clocks();
  405. }
  406. #define COMBINER_ENABLE_SET 0x0
  407. #define COMBINER_ENABLE_CLEAR 0x4
  408. #define COMBINER_INT_STATUS 0xC
  409. static DEFINE_SPINLOCK(irq_controller_lock);
  410. struct combiner_chip_data {
  411. unsigned int irq_offset;
  412. unsigned int irq_mask;
  413. void __iomem *base;
  414. };
  415. static struct irq_domain *combiner_irq_domain;
  416. static struct combiner_chip_data combiner_data[MAX_COMBINER_NR];
  417. static inline void __iomem *combiner_base(struct irq_data *data)
  418. {
  419. struct combiner_chip_data *combiner_data =
  420. irq_data_get_irq_chip_data(data);
  421. return combiner_data->base;
  422. }
  423. static void combiner_mask_irq(struct irq_data *data)
  424. {
  425. u32 mask = 1 << (data->hwirq % 32);
  426. __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
  427. }
  428. static void combiner_unmask_irq(struct irq_data *data)
  429. {
  430. u32 mask = 1 << (data->hwirq % 32);
  431. __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
  432. }
  433. static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
  434. {
  435. struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
  436. struct irq_chip *chip = irq_get_chip(irq);
  437. unsigned int cascade_irq, combiner_irq;
  438. unsigned long status;
  439. chained_irq_enter(chip, desc);
  440. spin_lock(&irq_controller_lock);
  441. status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
  442. spin_unlock(&irq_controller_lock);
  443. status &= chip_data->irq_mask;
  444. if (status == 0)
  445. goto out;
  446. combiner_irq = __ffs(status);
  447. cascade_irq = combiner_irq + (chip_data->irq_offset & ~31);
  448. if (unlikely(cascade_irq >= NR_IRQS))
  449. do_bad_IRQ(cascade_irq, desc);
  450. else
  451. generic_handle_irq(cascade_irq);
  452. out:
  453. chained_irq_exit(chip, desc);
  454. }
  455. static struct irq_chip combiner_chip = {
  456. .name = "COMBINER",
  457. .irq_mask = combiner_mask_irq,
  458. .irq_unmask = combiner_unmask_irq,
  459. };
  460. static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq)
  461. {
  462. unsigned int max_nr;
  463. if (soc_is_exynos5250())
  464. max_nr = EXYNOS5_MAX_COMBINER_NR;
  465. else
  466. max_nr = EXYNOS4_MAX_COMBINER_NR;
  467. if (combiner_nr >= max_nr)
  468. BUG();
  469. if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0)
  470. BUG();
  471. irq_set_chained_handler(irq, combiner_handle_cascade_irq);
  472. }
  473. static void __init combiner_init_one(unsigned int combiner_nr,
  474. void __iomem *base)
  475. {
  476. combiner_data[combiner_nr].base = base;
  477. combiner_data[combiner_nr].irq_offset = irq_find_mapping(
  478. combiner_irq_domain, combiner_nr * MAX_IRQ_IN_COMBINER);
  479. combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3);
  480. /* Disable all interrupts */
  481. __raw_writel(combiner_data[combiner_nr].irq_mask,
  482. base + COMBINER_ENABLE_CLEAR);
  483. }
  484. #ifdef CONFIG_OF
  485. static int combiner_irq_domain_xlate(struct irq_domain *d,
  486. struct device_node *controller,
  487. const u32 *intspec, unsigned int intsize,
  488. unsigned long *out_hwirq,
  489. unsigned int *out_type)
  490. {
  491. if (d->of_node != controller)
  492. return -EINVAL;
  493. if (intsize < 2)
  494. return -EINVAL;
  495. *out_hwirq = intspec[0] * MAX_IRQ_IN_COMBINER + intspec[1];
  496. *out_type = 0;
  497. return 0;
  498. }
  499. #else
  500. static int combiner_irq_domain_xlate(struct irq_domain *d,
  501. struct device_node *controller,
  502. const u32 *intspec, unsigned int intsize,
  503. unsigned long *out_hwirq,
  504. unsigned int *out_type)
  505. {
  506. return -EINVAL;
  507. }
  508. #endif
  509. static int combiner_irq_domain_map(struct irq_domain *d, unsigned int irq,
  510. irq_hw_number_t hw)
  511. {
  512. irq_set_chip_and_handler(irq, &combiner_chip, handle_level_irq);
  513. irq_set_chip_data(irq, &combiner_data[hw >> 3]);
  514. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  515. return 0;
  516. }
  517. static struct irq_domain_ops combiner_irq_domain_ops = {
  518. .xlate = combiner_irq_domain_xlate,
  519. .map = combiner_irq_domain_map,
  520. };
  521. static void __init combiner_init(void __iomem *combiner_base,
  522. struct device_node *np)
  523. {
  524. int i, irq, irq_base;
  525. unsigned int max_nr, nr_irq;
  526. if (np) {
  527. if (of_property_read_u32(np, "samsung,combiner-nr", &max_nr)) {
  528. pr_warning("%s: number of combiners not specified, "
  529. "setting default as %d.\n",
  530. __func__, EXYNOS4_MAX_COMBINER_NR);
  531. max_nr = EXYNOS4_MAX_COMBINER_NR;
  532. }
  533. } else {
  534. max_nr = soc_is_exynos5250() ? EXYNOS5_MAX_COMBINER_NR :
  535. EXYNOS4_MAX_COMBINER_NR;
  536. }
  537. nr_irq = max_nr * MAX_IRQ_IN_COMBINER;
  538. irq_base = irq_alloc_descs(COMBINER_IRQ(0, 0), 1, nr_irq, 0);
  539. if (IS_ERR_VALUE(irq_base)) {
  540. irq_base = COMBINER_IRQ(0, 0);
  541. pr_warning("%s: irq desc alloc failed. Continuing with %d as linux irq base\n", __func__, irq_base);
  542. }
  543. combiner_irq_domain = irq_domain_add_legacy(np, nr_irq, irq_base, 0,
  544. &combiner_irq_domain_ops, &combiner_data);
  545. if (WARN_ON(!combiner_irq_domain)) {
  546. pr_warning("%s: irq domain init failed\n", __func__);
  547. return;
  548. }
  549. for (i = 0; i < max_nr; i++) {
  550. combiner_init_one(i, combiner_base + (i >> 2) * 0x10);
  551. irq = IRQ_SPI(i);
  552. #ifdef CONFIG_OF
  553. if (np)
  554. irq = irq_of_parse_and_map(np, i);
  555. #endif
  556. combiner_cascade_irq(i, irq);
  557. }
  558. }
  559. #ifdef CONFIG_OF
  560. int __init combiner_of_init(struct device_node *np, struct device_node *parent)
  561. {
  562. void __iomem *combiner_base;
  563. combiner_base = of_iomap(np, 0);
  564. if (!combiner_base) {
  565. pr_err("%s: failed to map combiner registers\n", __func__);
  566. return -ENXIO;
  567. }
  568. combiner_init(combiner_base, np);
  569. return 0;
  570. }
  571. static const struct of_device_id exynos_dt_irq_match[] = {
  572. { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, },
  573. { .compatible = "arm,cortex-a15-gic", .data = gic_of_init, },
  574. { .compatible = "samsung,exynos4210-combiner",
  575. .data = combiner_of_init, },
  576. {},
  577. };
  578. #endif
  579. void __init exynos4_init_irq(void)
  580. {
  581. unsigned int gic_bank_offset;
  582. gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000;
  583. if (!of_have_populated_dt())
  584. gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset, NULL);
  585. #ifdef CONFIG_OF
  586. else
  587. of_irq_init(exynos_dt_irq_match);
  588. #endif
  589. if (!of_have_populated_dt())
  590. combiner_init(S5P_VA_COMBINER_BASE, NULL);
  591. /*
  592. * The parameters of s5p_init_irq() are for VIC init.
  593. * Theses parameters should be NULL and 0 because EXYNOS4
  594. * uses GIC instead of VIC.
  595. */
  596. s5p_init_irq(NULL, 0);
  597. }
  598. void __init exynos5_init_irq(void)
  599. {
  600. #ifdef CONFIG_OF
  601. of_irq_init(exynos_dt_irq_match);
  602. #endif
  603. /*
  604. * The parameters of s5p_init_irq() are for VIC init.
  605. * Theses parameters should be NULL and 0 because EXYNOS4
  606. * uses GIC instead of VIC.
  607. */
  608. s5p_init_irq(NULL, 0);
  609. }
  610. struct bus_type exynos_subsys = {
  611. .name = "exynos-core",
  612. .dev_name = "exynos-core",
  613. };
  614. static struct device exynos4_dev = {
  615. .bus = &exynos_subsys,
  616. };
  617. static int __init exynos_core_init(void)
  618. {
  619. return subsys_system_register(&exynos_subsys, NULL);
  620. }
  621. core_initcall(exynos_core_init);
  622. #ifdef CONFIG_CACHE_L2X0
  623. static int __init exynos4_l2x0_cache_init(void)
  624. {
  625. int ret;
  626. if (soc_is_exynos5250() || soc_is_exynos5440())
  627. return 0;
  628. ret = l2x0_of_init(L2_AUX_VAL, L2_AUX_MASK);
  629. if (!ret) {
  630. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  631. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  632. return 0;
  633. }
  634. if (!(__raw_readl(S5P_VA_L2CC + L2X0_CTRL) & 0x1)) {
  635. l2x0_saved_regs.phy_base = EXYNOS4_PA_L2CC;
  636. /* TAG, Data Latency Control: 2 cycles */
  637. l2x0_saved_regs.tag_latency = 0x110;
  638. if (soc_is_exynos4212() || soc_is_exynos4412())
  639. l2x0_saved_regs.data_latency = 0x120;
  640. else
  641. l2x0_saved_regs.data_latency = 0x110;
  642. l2x0_saved_regs.prefetch_ctrl = 0x30000007;
  643. l2x0_saved_regs.pwr_ctrl =
  644. (L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN);
  645. l2x0_regs_phys = virt_to_phys(&l2x0_saved_regs);
  646. __raw_writel(l2x0_saved_regs.tag_latency,
  647. S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL);
  648. __raw_writel(l2x0_saved_regs.data_latency,
  649. S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL);
  650. /* L2X0 Prefetch Control */
  651. __raw_writel(l2x0_saved_regs.prefetch_ctrl,
  652. S5P_VA_L2CC + L2X0_PREFETCH_CTRL);
  653. /* L2X0 Power Control */
  654. __raw_writel(l2x0_saved_regs.pwr_ctrl,
  655. S5P_VA_L2CC + L2X0_POWER_CTRL);
  656. clean_dcache_area(&l2x0_regs_phys, sizeof(unsigned long));
  657. clean_dcache_area(&l2x0_saved_regs, sizeof(struct l2x0_regs));
  658. }
  659. l2x0_init(S5P_VA_L2CC, L2_AUX_VAL, L2_AUX_MASK);
  660. return 0;
  661. }
  662. early_initcall(exynos4_l2x0_cache_init);
  663. #endif
  664. static int __init exynos_init(void)
  665. {
  666. printk(KERN_INFO "EXYNOS: Initializing architecture\n");
  667. return device_register(&exynos4_dev);
  668. }
  669. /* uart registration process */
  670. static void __init exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no)
  671. {
  672. struct s3c2410_uartcfg *tcfg = cfg;
  673. u32 ucnt;
  674. for (ucnt = 0; ucnt < no; ucnt++, tcfg++)
  675. tcfg->has_fracval = 1;
  676. if (soc_is_exynos5250())
  677. s3c24xx_init_uartdevs("exynos4210-uart", exynos5_uart_resources, cfg, no);
  678. else
  679. s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no);
  680. }
  681. static void __iomem *exynos_eint_base;
  682. static DEFINE_SPINLOCK(eint_lock);
  683. static unsigned int eint0_15_data[16];
  684. static inline int exynos4_irq_to_gpio(unsigned int irq)
  685. {
  686. if (irq < IRQ_EINT(0))
  687. return -EINVAL;
  688. irq -= IRQ_EINT(0);
  689. if (irq < 8)
  690. return EXYNOS4_GPX0(irq);
  691. irq -= 8;
  692. if (irq < 8)
  693. return EXYNOS4_GPX1(irq);
  694. irq -= 8;
  695. if (irq < 8)
  696. return EXYNOS4_GPX2(irq);
  697. irq -= 8;
  698. if (irq < 8)
  699. return EXYNOS4_GPX3(irq);
  700. return -EINVAL;
  701. }
  702. static inline int exynos5_irq_to_gpio(unsigned int irq)
  703. {
  704. if (irq < IRQ_EINT(0))
  705. return -EINVAL;
  706. irq -= IRQ_EINT(0);
  707. if (irq < 8)
  708. return EXYNOS5_GPX0(irq);
  709. irq -= 8;
  710. if (irq < 8)
  711. return EXYNOS5_GPX1(irq);
  712. irq -= 8;
  713. if (irq < 8)
  714. return EXYNOS5_GPX2(irq);
  715. irq -= 8;
  716. if (irq < 8)
  717. return EXYNOS5_GPX3(irq);
  718. return -EINVAL;
  719. }
  720. static unsigned int exynos4_eint0_15_src_int[16] = {
  721. EXYNOS4_IRQ_EINT0,
  722. EXYNOS4_IRQ_EINT1,
  723. EXYNOS4_IRQ_EINT2,
  724. EXYNOS4_IRQ_EINT3,
  725. EXYNOS4_IRQ_EINT4,
  726. EXYNOS4_IRQ_EINT5,
  727. EXYNOS4_IRQ_EINT6,
  728. EXYNOS4_IRQ_EINT7,
  729. EXYNOS4_IRQ_EINT8,
  730. EXYNOS4_IRQ_EINT9,
  731. EXYNOS4_IRQ_EINT10,
  732. EXYNOS4_IRQ_EINT11,
  733. EXYNOS4_IRQ_EINT12,
  734. EXYNOS4_IRQ_EINT13,
  735. EXYNOS4_IRQ_EINT14,
  736. EXYNOS4_IRQ_EINT15,
  737. };
  738. static unsigned int exynos5_eint0_15_src_int[16] = {
  739. EXYNOS5_IRQ_EINT0,
  740. EXYNOS5_IRQ_EINT1,
  741. EXYNOS5_IRQ_EINT2,
  742. EXYNOS5_IRQ_EINT3,
  743. EXYNOS5_IRQ_EINT4,
  744. EXYNOS5_IRQ_EINT5,
  745. EXYNOS5_IRQ_EINT6,
  746. EXYNOS5_IRQ_EINT7,
  747. EXYNOS5_IRQ_EINT8,
  748. EXYNOS5_IRQ_EINT9,
  749. EXYNOS5_IRQ_EINT10,
  750. EXYNOS5_IRQ_EINT11,
  751. EXYNOS5_IRQ_EINT12,
  752. EXYNOS5_IRQ_EINT13,
  753. EXYNOS5_IRQ_EINT14,
  754. EXYNOS5_IRQ_EINT15,
  755. };
  756. static inline void exynos_irq_eint_mask(struct irq_data *data)
  757. {
  758. u32 mask;
  759. spin_lock(&eint_lock);
  760. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  761. mask |= EINT_OFFSET_BIT(data->irq);
  762. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  763. spin_unlock(&eint_lock);
  764. }
  765. static void exynos_irq_eint_unmask(struct irq_data *data)
  766. {
  767. u32 mask;
  768. spin_lock(&eint_lock);
  769. mask = __raw_readl(EINT_MASK(exynos_eint_base, data->irq));
  770. mask &= ~(EINT_OFFSET_BIT(data->irq));
  771. __raw_writel(mask, EINT_MASK(exynos_eint_base, data->irq));
  772. spin_unlock(&eint_lock);
  773. }
  774. static inline void exynos_irq_eint_ack(struct irq_data *data)
  775. {
  776. __raw_writel(EINT_OFFSET_BIT(data->irq),
  777. EINT_PEND(exynos_eint_base, data->irq));
  778. }
  779. static void exynos_irq_eint_maskack(struct irq_data *data)
  780. {
  781. exynos_irq_eint_mask(data);
  782. exynos_irq_eint_ack(data);
  783. }
  784. static int exynos_irq_eint_set_type(struct irq_data *data, unsigned int type)
  785. {
  786. int offs = EINT_OFFSET(data->irq);
  787. int shift;
  788. u32 ctrl, mask;
  789. u32 newvalue = 0;
  790. switch (type) {
  791. case IRQ_TYPE_EDGE_RISING:
  792. newvalue = S5P_IRQ_TYPE_EDGE_RISING;
  793. break;
  794. case IRQ_TYPE_EDGE_FALLING:
  795. newvalue = S5P_IRQ_TYPE_EDGE_FALLING;
  796. break;
  797. case IRQ_TYPE_EDGE_BOTH:
  798. newvalue = S5P_IRQ_TYPE_EDGE_BOTH;
  799. break;
  800. case IRQ_TYPE_LEVEL_LOW:
  801. newvalue = S5P_IRQ_TYPE_LEVEL_LOW;
  802. break;
  803. case IRQ_TYPE_LEVEL_HIGH:
  804. newvalue = S5P_IRQ_TYPE_LEVEL_HIGH;
  805. break;
  806. default:
  807. printk(KERN_ERR "No such irq type %d", type);
  808. return -EINVAL;
  809. }
  810. shift = (offs & 0x7) * 4;
  811. mask = 0x7 << shift;
  812. spin_lock(&eint_lock);
  813. ctrl = __raw_readl(EINT_CON(exynos_eint_base, data->irq));
  814. ctrl &= ~mask;
  815. ctrl |= newvalue << shift;
  816. __raw_writel(ctrl, EINT_CON(exynos_eint_base, data->irq));
  817. spin_unlock(&eint_lock);
  818. if (soc_is_exynos5250())
  819. s3c_gpio_cfgpin(exynos5_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  820. else
  821. s3c_gpio_cfgpin(exynos4_irq_to_gpio(data->irq), S3C_GPIO_SFN(0xf));
  822. return 0;
  823. }
  824. static struct irq_chip exynos_irq_eint = {
  825. .name = "exynos-eint",
  826. .irq_mask = exynos_irq_eint_mask,
  827. .irq_unmask = exynos_irq_eint_unmask,
  828. .irq_mask_ack = exynos_irq_eint_maskack,
  829. .irq_ack = exynos_irq_eint_ack,
  830. .irq_set_type = exynos_irq_eint_set_type,
  831. #ifdef CONFIG_PM
  832. .irq_set_wake = s3c_irqext_wake,
  833. #endif
  834. };
  835. /*
  836. * exynos4_irq_demux_eint
  837. *
  838. * This function demuxes the IRQ from from EINTs 16 to 31.
  839. * It is designed to be inlined into the specific handler
  840. * s5p_irq_demux_eintX_Y.
  841. *
  842. * Each EINT pend/mask registers handle eight of them.
  843. */
  844. static inline void exynos_irq_demux_eint(unsigned int start)
  845. {
  846. unsigned int irq;
  847. u32 status = __raw_readl(EINT_PEND(exynos_eint_base, start));
  848. u32 mask = __raw_readl(EINT_MASK(exynos_eint_base, start));
  849. status &= ~mask;
  850. status &= 0xff;
  851. while (status) {
  852. irq = fls(status) - 1;
  853. generic_handle_irq(irq + start);
  854. status &= ~(1 << irq);
  855. }
  856. }
  857. static void exynos_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc)
  858. {
  859. struct irq_chip *chip = irq_get_chip(irq);
  860. chained_irq_enter(chip, desc);
  861. exynos_irq_demux_eint(IRQ_EINT(16));
  862. exynos_irq_demux_eint(IRQ_EINT(24));
  863. chained_irq_exit(chip, desc);
  864. }
  865. static void exynos_irq_eint0_15(unsigned int irq, struct irq_desc *desc)
  866. {
  867. u32 *irq_data = irq_get_handler_data(irq);
  868. struct irq_chip *chip = irq_get_chip(irq);
  869. chained_irq_enter(chip, desc);
  870. chip->irq_mask(&desc->irq_data);
  871. if (chip->irq_ack)
  872. chip->irq_ack(&desc->irq_data);
  873. generic_handle_irq(*irq_data);
  874. chip->irq_unmask(&desc->irq_data);
  875. chained_irq_exit(chip, desc);
  876. }
  877. static int __init exynos_init_irq_eint(void)
  878. {
  879. int irq;
  880. #ifdef CONFIG_PINCTRL_SAMSUNG
  881. /*
  882. * The Samsung pinctrl driver provides an integrated gpio/pinmux/pinconf
  883. * functionality along with support for external gpio and wakeup
  884. * interrupts. If the samsung pinctrl driver is enabled and includes
  885. * the wakeup interrupt support, then the setting up external wakeup
  886. * interrupts here can be skipped. This check here is temporary to
  887. * allow exynos4 platforms that do not use Samsung pinctrl driver to
  888. * co-exist with platforms that do. When all of the Samsung Exynos4
  889. * platforms switch over to using the pinctrl driver, the wakeup
  890. * interrupt support code here can be completely removed.
  891. */
  892. struct device_node *pctrl_np, *wkup_np;
  893. const char *pctrl_compat = "samsung,pinctrl-exynos4210";
  894. const char *wkup_compat = "samsung,exynos4210-wakeup-eint";
  895. for_each_compatible_node(pctrl_np, NULL, pctrl_compat) {
  896. if (of_device_is_available(pctrl_np)) {
  897. wkup_np = of_find_compatible_node(pctrl_np, NULL,
  898. wkup_compat);
  899. if (wkup_np)
  900. return -ENODEV;
  901. }
  902. }
  903. #endif
  904. if (soc_is_exynos5440())
  905. return 0;
  906. if (soc_is_exynos5250())
  907. exynos_eint_base = ioremap(EXYNOS5_PA_GPIO1, SZ_4K);
  908. else
  909. exynos_eint_base = ioremap(EXYNOS4_PA_GPIO2, SZ_4K);
  910. if (exynos_eint_base == NULL) {
  911. pr_err("unable to ioremap for EINT base address\n");
  912. return -ENOMEM;
  913. }
  914. for (irq = 0 ; irq <= 31 ; irq++) {
  915. irq_set_chip_and_handler(IRQ_EINT(irq), &exynos_irq_eint,
  916. handle_level_irq);
  917. set_irq_flags(IRQ_EINT(irq), IRQF_VALID);
  918. }
  919. irq_set_chained_handler(EXYNOS_IRQ_EINT16_31, exynos_irq_demux_eint16_31);
  920. for (irq = 0 ; irq <= 15 ; irq++) {
  921. eint0_15_data[irq] = IRQ_EINT(irq);
  922. if (soc_is_exynos5250()) {
  923. irq_set_handler_data(exynos5_eint0_15_src_int[irq],
  924. &eint0_15_data[irq]);
  925. irq_set_chained_handler(exynos5_eint0_15_src_int[irq],
  926. exynos_irq_eint0_15);
  927. } else {
  928. irq_set_handler_data(exynos4_eint0_15_src_int[irq],
  929. &eint0_15_data[irq]);
  930. irq_set_chained_handler(exynos4_eint0_15_src_int[irq],
  931. exynos_irq_eint0_15);
  932. }
  933. }
  934. return 0;
  935. }
  936. arch_initcall(exynos_init_irq_eint);