exynos-combiner.c 6.7 KB

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