common.c 25 KB

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