exynos-combiner.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * Combiner irqchip 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/err.h>
  12. #include <linux/export.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/slab.h>
  16. #include <linux/irqdomain.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_irq.h>
  19. #include <asm/mach/irq.h>
  20. #ifdef CONFIG_EXYNOS_ATAGS
  21. #include <plat/cpu.h>
  22. #endif
  23. #include "irqchip.h"
  24. #define COMBINER_ENABLE_SET 0x0
  25. #define COMBINER_ENABLE_CLEAR 0x4
  26. #define COMBINER_INT_STATUS 0xC
  27. #define IRQ_IN_COMBINER 8
  28. static DEFINE_SPINLOCK(irq_controller_lock);
  29. struct combiner_chip_data {
  30. unsigned int hwirq_offset;
  31. unsigned int irq_mask;
  32. void __iomem *base;
  33. unsigned int parent_irq;
  34. };
  35. static struct irq_domain *combiner_irq_domain;
  36. static inline void __iomem *combiner_base(struct irq_data *data)
  37. {
  38. struct combiner_chip_data *combiner_data =
  39. irq_data_get_irq_chip_data(data);
  40. return combiner_data->base;
  41. }
  42. static void combiner_mask_irq(struct irq_data *data)
  43. {
  44. u32 mask = 1 << (data->hwirq % 32);
  45. __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
  46. }
  47. static void combiner_unmask_irq(struct irq_data *data)
  48. {
  49. u32 mask = 1 << (data->hwirq % 32);
  50. __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
  51. }
  52. static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
  53. {
  54. struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
  55. struct irq_chip *chip = irq_get_chip(irq);
  56. unsigned int cascade_irq, combiner_irq;
  57. unsigned long status;
  58. chained_irq_enter(chip, desc);
  59. spin_lock(&irq_controller_lock);
  60. status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
  61. spin_unlock(&irq_controller_lock);
  62. status &= chip_data->irq_mask;
  63. if (status == 0)
  64. goto out;
  65. combiner_irq = chip_data->hwirq_offset + __ffs(status);
  66. cascade_irq = irq_find_mapping(combiner_irq_domain, combiner_irq);
  67. if (unlikely(!cascade_irq))
  68. do_bad_IRQ(irq, desc);
  69. else
  70. generic_handle_irq(cascade_irq);
  71. out:
  72. chained_irq_exit(chip, desc);
  73. }
  74. #ifdef CONFIG_SMP
  75. static int combiner_set_affinity(struct irq_data *d,
  76. const struct cpumask *mask_val, bool force)
  77. {
  78. struct combiner_chip_data *chip_data = irq_data_get_irq_chip_data(d);
  79. struct irq_chip *chip = irq_get_chip(chip_data->parent_irq);
  80. struct irq_data *data = irq_get_irq_data(chip_data->parent_irq);
  81. if (chip && chip->irq_set_affinity)
  82. return chip->irq_set_affinity(data, mask_val, force);
  83. else
  84. return -EINVAL;
  85. }
  86. #endif
  87. static struct irq_chip combiner_chip = {
  88. .name = "COMBINER",
  89. .irq_mask = combiner_mask_irq,
  90. .irq_unmask = combiner_unmask_irq,
  91. #ifdef CONFIG_SMP
  92. .irq_set_affinity = combiner_set_affinity,
  93. #endif
  94. };
  95. static void __init combiner_cascade_irq(struct combiner_chip_data *combiner_data,
  96. unsigned int irq)
  97. {
  98. if (irq_set_handler_data(irq, combiner_data) != 0)
  99. BUG();
  100. irq_set_chained_handler(irq, combiner_handle_cascade_irq);
  101. }
  102. static void __init combiner_init_one(struct combiner_chip_data *combiner_data,
  103. unsigned int combiner_nr,
  104. void __iomem *base, unsigned int irq)
  105. {
  106. combiner_data->base = base;
  107. combiner_data->hwirq_offset = (combiner_nr & ~3) * IRQ_IN_COMBINER;
  108. combiner_data->irq_mask = 0xff << ((combiner_nr % 4) << 3);
  109. combiner_data->parent_irq = irq;
  110. /* Disable all interrupts */
  111. __raw_writel(combiner_data->irq_mask, base + COMBINER_ENABLE_CLEAR);
  112. }
  113. #ifdef CONFIG_OF
  114. static int combiner_irq_domain_xlate(struct irq_domain *d,
  115. struct device_node *controller,
  116. const u32 *intspec, unsigned int intsize,
  117. unsigned long *out_hwirq,
  118. unsigned int *out_type)
  119. {
  120. if (d->of_node != controller)
  121. return -EINVAL;
  122. if (intsize < 2)
  123. return -EINVAL;
  124. *out_hwirq = intspec[0] * IRQ_IN_COMBINER + intspec[1];
  125. *out_type = 0;
  126. return 0;
  127. }
  128. #else
  129. static int combiner_irq_domain_xlate(struct irq_domain *d,
  130. struct device_node *controller,
  131. const u32 *intspec, unsigned int intsize,
  132. unsigned long *out_hwirq,
  133. unsigned int *out_type)
  134. {
  135. return -EINVAL;
  136. }
  137. #endif
  138. static int combiner_irq_domain_map(struct irq_domain *d, unsigned int irq,
  139. irq_hw_number_t hw)
  140. {
  141. struct combiner_chip_data *combiner_data = d->host_data;
  142. irq_set_chip_and_handler(irq, &combiner_chip, handle_level_irq);
  143. irq_set_chip_data(irq, &combiner_data[hw >> 3]);
  144. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  145. return 0;
  146. }
  147. static struct irq_domain_ops combiner_irq_domain_ops = {
  148. .xlate = combiner_irq_domain_xlate,
  149. .map = combiner_irq_domain_map,
  150. };
  151. static unsigned int combiner_lookup_irq(int group)
  152. {
  153. #ifdef CONFIG_EXYNOS_ATAGS
  154. if (group < EXYNOS4210_MAX_COMBINER_NR || soc_is_exynos5250())
  155. return IRQ_SPI(group);
  156. switch (group) {
  157. case 16:
  158. return IRQ_SPI(107);
  159. case 17:
  160. return IRQ_SPI(108);
  161. case 18:
  162. return IRQ_SPI(48);
  163. case 19:
  164. return IRQ_SPI(42);
  165. }
  166. #endif
  167. return 0;
  168. }
  169. void __init combiner_init(void __iomem *combiner_base,
  170. struct device_node *np,
  171. unsigned int max_nr,
  172. int irq_base)
  173. {
  174. int i, irq;
  175. unsigned int nr_irq;
  176. struct combiner_chip_data *combiner_data;
  177. nr_irq = max_nr * IRQ_IN_COMBINER;
  178. combiner_data = kcalloc(max_nr, sizeof (*combiner_data), GFP_KERNEL);
  179. if (!combiner_data) {
  180. pr_warning("%s: could not allocate combiner data\n", __func__);
  181. return;
  182. }
  183. combiner_irq_domain = irq_domain_add_simple(np, nr_irq, irq_base,
  184. &combiner_irq_domain_ops, combiner_data);
  185. if (WARN_ON(!combiner_irq_domain)) {
  186. pr_warning("%s: irq domain init failed\n", __func__);
  187. return;
  188. }
  189. for (i = 0; i < max_nr; i++) {
  190. #ifdef CONFIG_OF
  191. if (np)
  192. irq = irq_of_parse_and_map(np, i);
  193. else
  194. #endif
  195. irq = combiner_lookup_irq(i);
  196. combiner_init_one(&combiner_data[i], i,
  197. combiner_base + (i >> 2) * 0x10, irq);
  198. combiner_cascade_irq(&combiner_data[i], irq);
  199. }
  200. }
  201. #ifdef CONFIG_OF
  202. static int __init combiner_of_init(struct device_node *np,
  203. struct device_node *parent)
  204. {
  205. void __iomem *combiner_base;
  206. unsigned int max_nr = 20;
  207. int irq_base = -1;
  208. combiner_base = of_iomap(np, 0);
  209. if (!combiner_base) {
  210. pr_err("%s: failed to map combiner registers\n", __func__);
  211. return -ENXIO;
  212. }
  213. if (of_property_read_u32(np, "samsung,combiner-nr", &max_nr)) {
  214. pr_info("%s: number of combiners not specified, "
  215. "setting default as %d.\n",
  216. __func__, max_nr);
  217. }
  218. /*
  219. * FIXME: This is a hardwired COMBINER_IRQ(0,0). Once all devices
  220. * get their IRQ from DT, remove this in order to get dynamic
  221. * allocation.
  222. */
  223. irq_base = 160;
  224. combiner_init(combiner_base, np, max_nr, irq_base);
  225. return 0;
  226. }
  227. IRQCHIP_DECLARE(exynos4210_combiner, "samsung,exynos4210-combiner",
  228. combiner_of_init);
  229. #endif