common.c 26 KB

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