321-irqchip-add-support-for-bcm6345-style-external-inter.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. From cf908990d4a8ccdb73ee4484aa8cadad379ca314 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jogo@openwrt.org>
  3. Date: Sun, 30 Nov 2014 14:54:27 +0100
  4. Subject: [PATCH 2/5] irqchip: add support for bcm6345-style external
  5. interrupt controller
  6. Signed-off-by: Jonas Gorski <jogo@openwrt.org>
  7. ---
  8. .../interrupt-controller/brcm,bcm6345-ext-intc.txt | 29 ++
  9. drivers/irqchip/Kconfig | 4 +
  10. drivers/irqchip/Makefile | 1 +
  11. drivers/irqchip/irq-bcm6345-ext.c | 287 ++++++++++++++++++++
  12. include/linux/irqchip/irq-bcm6345-ext.h | 14 +
  13. 5 files changed, 335 insertions(+)
  14. create mode 100644 Documentation/devicetree/bindings/interrupt-controller/brcm,bcm6345-ext-intc.txt
  15. create mode 100644 drivers/irqchip/irq-bcm6345-ext.c
  16. create mode 100644 include/linux/irqchip/irq-bcm6345-ext.h
  17. --- /dev/null
  18. +++ b/Documentation/devicetree/bindings/interrupt-controller/brcm,bcm6345-ext-intc.txt
  19. @@ -0,0 +1,29 @@
  20. +Broadcom BCM6345-style external interrupt controller
  21. +
  22. +Required properties:
  23. +
  24. +- compatible: Should be "brcm,bcm6345-ext-intc".
  25. +- reg: Specifies the base physical addresses and size of the registers.
  26. +- interrupt-controller: identifies the node as an interrupt controller.
  27. +- #interrupt-cells: Specifies the number of cells needed to encode an interrupt
  28. + source, Should be 2.
  29. +- interrupt-parent: Specifies the phandle to the parent interrupt controller
  30. + this one is cascaded from.
  31. +- interrupts: Specifies the interrupt line(s) in the interrupt-parent controller
  32. + node, valid values depend on the type of parent interrupt controller.
  33. +
  34. +Optional properties:
  35. +
  36. +- brcm,field-width: Size of each field (mask, clear, sense, ...) in bits in the
  37. + register. Defaults to 4.
  38. +
  39. +Example:
  40. +
  41. +ext_intc: interrupt-controller@10000018 {
  42. + compatible = "brcm,bcm6345-ext-intc";
  43. + interrupt-parent = <&periph_intc>;
  44. + #interrupt-cells = <2>;
  45. + reg = <0x10000018 0x4>;
  46. + interrupt-controller;
  47. + interrupts = <24>, <25>, <26>, <27>;
  48. +};
  49. --- a/drivers/irqchip/Kconfig
  50. +++ b/drivers/irqchip/Kconfig
  51. @@ -80,6 +80,10 @@ config BRCMSTB_L2_IRQ
  52. select GENERIC_IRQ_CHIP
  53. select IRQ_DOMAIN
  54. +config BCM6345_EXT_IRQ
  55. + bool
  56. + select IRQ_DOMAIN
  57. +
  58. config BCM6345_PERIPH_IRQ
  59. bool
  60. select IRQ_DOMAIN
  61. --- a/drivers/irqchip/Makefile
  62. +++ b/drivers/irqchip/Makefile
  63. @@ -9,6 +9,7 @@ obj-$(CONFIG_ARCH_MVEBU) += irq-armada-
  64. obj-$(CONFIG_IRQ_MXS) += irq-mxs.o
  65. obj-$(CONFIG_ARCH_TEGRA) += irq-tegra.o
  66. obj-$(CONFIG_ARCH_S3C24XX) += irq-s3c24xx.o
  67. +obj-$(CONFIG_BCM6345_EXT_IRQ) += irq-bcm6345-ext.o
  68. obj-$(CONFIG_BCM6345_PERIPH_IRQ) += irq-bcm6345-periph.o
  69. obj-$(CONFIG_DW_APB_ICTL) += irq-dw-apb-ictl.o
  70. obj-$(CONFIG_METAG) += irq-metag-ext.o
  71. --- /dev/null
  72. +++ b/drivers/irqchip/irq-bcm6345-ext.c
  73. @@ -0,0 +1,288 @@
  74. +/*
  75. + * This file is subject to the terms and conditions of the GNU General Public
  76. + * License. See the file "COPYING" in the main directory of this archive
  77. + * for more details.
  78. + *
  79. + * Copyright (C) 2014 Jonas Gorski <jogo@openwrt.org>
  80. + */
  81. +
  82. +#include <linux/ioport.h>
  83. +#include <linux/irq.h>
  84. +#include <linux/irqchip.h>
  85. +#include <linux/irqchip/chained_irq.h>
  86. +#include <linux/irqchip/irq-bcm6345-ext.h>
  87. +#include <linux/kernel.h>
  88. +#include <linux/of.h>
  89. +#include <linux/of_irq.h>
  90. +#include <linux/of_address.h>
  91. +#include <linux/slab.h>
  92. +#include <linux/spinlock.h>
  93. +
  94. +#ifdef CONFIG_BCM63XX
  95. +#include <asm/mach-bcm63xx/bcm63xx_irq.h>
  96. +
  97. +#define VIRQ_BASE IRQ_EXTERNAL_BASE
  98. +#else
  99. +#define VIRQ_BASE 0
  100. +#endif
  101. +
  102. +#define MAX_IRQS 4
  103. +
  104. +#define EXTIRQ_CFG_SENSE 0
  105. +#define EXTIRQ_CFG_STAT 1
  106. +#define EXTIRQ_CFG_CLEAR 2
  107. +#define EXTIRQ_CFG_MASK 3
  108. +#define EXTIRQ_CFG_BOTHEDGE 4
  109. +#define EXTIRQ_CFG_LEVELSENSE 5
  110. +
  111. +struct intc_data {
  112. + struct irq_chip chip;
  113. + struct irq_domain *domain;
  114. + raw_spinlock_t lock;
  115. +
  116. + int parent_irq[MAX_IRQS];
  117. + void __iomem *reg;
  118. + int shift;
  119. +};
  120. +
  121. +static void bcm6345_ext_intc_irq_handle(struct irq_desc *desc)
  122. +{
  123. + struct intc_data *data = irq_desc_get_handler_data(desc);
  124. + struct irq_chip *chip = irq_desc_get_chip(desc);
  125. + unsigned int irq = irq_desc_get_irq(desc);
  126. + unsigned int idx;
  127. +
  128. + chained_irq_enter(chip, desc);
  129. +
  130. + for (idx = 0; idx < MAX_IRQS; idx++) {
  131. + if (data->parent_irq[idx] != irq)
  132. + continue;
  133. +
  134. + generic_handle_irq(irq_find_mapping(data->domain, idx));
  135. + }
  136. +
  137. + chained_irq_exit(chip, desc);
  138. +}
  139. +
  140. +static void bcm6345_ext_intc_irq_ack(struct irq_data *data)
  141. +{
  142. + struct intc_data *priv = data->domain->host_data;
  143. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  144. + u32 reg;
  145. +
  146. + raw_spin_lock(&priv->lock);
  147. + reg = __raw_readl(priv->reg);
  148. + reg |= 1 << (hwirq + EXTIRQ_CFG_CLEAR * priv->shift);
  149. + __raw_writel(reg, priv->reg);
  150. + raw_spin_unlock(&priv->lock);
  151. +}
  152. +
  153. +static void bcm6345_ext_intc_irq_mask(struct irq_data *data)
  154. +{
  155. + struct intc_data *priv = data->domain->host_data;
  156. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  157. + u32 reg;
  158. +
  159. + raw_spin_lock(&priv->lock);
  160. + reg = __raw_readl(priv->reg);
  161. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_MASK * priv->shift));
  162. + __raw_writel(reg, priv->reg);
  163. + raw_spin_unlock(&priv->lock);
  164. +}
  165. +
  166. +static void bcm6345_ext_intc_irq_unmask(struct irq_data *data)
  167. +{
  168. + struct intc_data *priv = data->domain->host_data;
  169. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  170. + u32 reg;
  171. +
  172. + raw_spin_lock(&priv->lock);
  173. + reg = __raw_readl(priv->reg);
  174. + reg |= 1 << (hwirq + EXTIRQ_CFG_MASK * priv->shift);
  175. + __raw_writel(reg, priv->reg);
  176. + raw_spin_unlock(&priv->lock);
  177. +}
  178. +
  179. +static int bcm6345_ext_intc_set_type(struct irq_data *data,
  180. + unsigned int flow_type)
  181. +{
  182. + struct intc_data *priv = data->domain->host_data;
  183. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  184. + bool levelsense = 0, sense = 0, bothedge = 0;
  185. + u32 reg;
  186. +
  187. + flow_type &= IRQ_TYPE_SENSE_MASK;
  188. +
  189. + if (flow_type == IRQ_TYPE_NONE)
  190. + flow_type = IRQ_TYPE_LEVEL_LOW;
  191. +
  192. + switch (flow_type) {
  193. + case IRQ_TYPE_EDGE_BOTH:
  194. + bothedge = 1;
  195. + break;
  196. +
  197. + case IRQ_TYPE_EDGE_RISING:
  198. + break;
  199. +
  200. + case IRQ_TYPE_EDGE_FALLING:
  201. + sense = 1;
  202. + break;
  203. +
  204. + case IRQ_TYPE_LEVEL_HIGH:
  205. + levelsense = 1;
  206. + sense = 1;
  207. + break;
  208. +
  209. + case IRQ_TYPE_LEVEL_LOW:
  210. + levelsense = 1;
  211. + break;
  212. +
  213. + default:
  214. + pr_err("bogus flow type combination given!\n");
  215. + return -EINVAL;
  216. + }
  217. +
  218. + raw_spin_lock(&priv->lock);
  219. + reg = __raw_readl(priv->reg);
  220. +
  221. + if (levelsense)
  222. + reg |= 1 << (hwirq + EXTIRQ_CFG_LEVELSENSE * priv->shift);
  223. + else
  224. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_LEVELSENSE * priv->shift));
  225. + if (sense)
  226. + reg |= 1 << (hwirq + EXTIRQ_CFG_SENSE * priv->shift);
  227. + else
  228. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_SENSE * priv->shift));
  229. + if (bothedge)
  230. + reg |= 1 << (hwirq + EXTIRQ_CFG_BOTHEDGE * priv->shift);
  231. + else
  232. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_BOTHEDGE * priv->shift));
  233. +
  234. + __raw_writel(reg, priv->reg);
  235. + raw_spin_unlock(&priv->lock);
  236. +
  237. + irqd_set_trigger_type(data, flow_type);
  238. + if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  239. + irq_set_handler_locked(data, handle_level_irq);
  240. + else
  241. + irq_set_handler_locked(data, handle_edge_irq);
  242. +
  243. + return 0;
  244. +}
  245. +
  246. +static int bcm6345_ext_intc_map(struct irq_domain *d, unsigned int irq,
  247. + irq_hw_number_t hw)
  248. +{
  249. + struct intc_data *priv = d->host_data;
  250. +
  251. + irq_set_chip_and_handler(irq, &priv->chip, handle_level_irq);
  252. +
  253. + return 0;
  254. +}
  255. +
  256. +static const struct irq_domain_ops bcm6345_ext_domain_ops = {
  257. + .xlate = irq_domain_xlate_twocell,
  258. + .map = bcm6345_ext_intc_map,
  259. +};
  260. +
  261. +static int __init __bcm6345_ext_intc_init(struct device_node *node,
  262. + int num_irqs, int *irqs,
  263. + void __iomem *reg, int shift)
  264. +{
  265. + struct intc_data *data;
  266. + unsigned int i;
  267. + int start = VIRQ_BASE;
  268. +
  269. + data = kzalloc(sizeof(*data), GFP_KERNEL);
  270. + if (!data)
  271. + return -ENOMEM;
  272. +
  273. + raw_spin_lock_init(&data->lock);
  274. +
  275. + for (i = 0; i < num_irqs; i++) {
  276. + data->parent_irq[i] = irqs[i];
  277. +
  278. + irq_set_handler_data(irqs[i], data);
  279. + irq_set_chained_handler(irqs[i], bcm6345_ext_intc_irq_handle);
  280. + }
  281. +
  282. + data->reg = reg;
  283. + data->shift = shift;
  284. +
  285. + data->chip.name = "bcm6345-ext-intc";
  286. + data->chip.irq_ack = bcm6345_ext_intc_irq_ack;
  287. + data->chip.irq_mask = bcm6345_ext_intc_irq_mask;
  288. + data->chip.irq_unmask = bcm6345_ext_intc_irq_unmask;
  289. + data->chip.irq_set_type = bcm6345_ext_intc_set_type;
  290. +
  291. + /*
  292. + * If we have less than 4 irqs, this is the second controller on
  293. + * bcm63xx. So increase the VIRQ start to not overlap with the first
  294. + * one, but only do so if we actually use a non-zero start.
  295. + *
  296. + * This can be removed when bcm63xx has no legacy users anymore.
  297. + */
  298. + if (start && num_irqs < 4)
  299. + start += 4;
  300. +
  301. + data->domain = irq_domain_add_simple(node, num_irqs, start,
  302. + &bcm6345_ext_domain_ops, data);
  303. + if (!data->domain) {
  304. + kfree(data);
  305. + return -ENOMEM;
  306. + }
  307. +
  308. + return 0;
  309. +}
  310. +
  311. +void __init bcm6345_ext_intc_init(int num_irqs, int *irqs, void __iomem *reg,
  312. + int shift)
  313. +{
  314. + __bcm6345_ext_intc_init(NULL, num_irqs, irqs, reg, shift);
  315. +}
  316. +
  317. +#ifdef CONFIG_OF
  318. +static int __init bcm6345_ext_intc_of_init(struct device_node *node,
  319. + struct device_node *parent)
  320. +{
  321. + int num_irqs, ret = -EINVAL;
  322. + unsigned i;
  323. + void __iomem *base;
  324. + int irqs[MAX_IRQS] = { 0 };
  325. + u32 shift;
  326. +
  327. + num_irqs = of_irq_count(node);
  328. +
  329. + if (!num_irqs || num_irqs > MAX_IRQS)
  330. + return -EINVAL;
  331. +
  332. + if (of_property_read_u32(node, "brcm,field-width", &shift))
  333. + shift = 4;
  334. +
  335. + for (i = 0; i < num_irqs; i++) {
  336. + irqs[i] = irq_of_parse_and_map(node, i);
  337. + if (!irqs[i]) {
  338. + ret = -ENOMEM;
  339. + goto out_unmap;
  340. + }
  341. + }
  342. +
  343. + base = of_iomap(node, 0);
  344. + if (!base)
  345. + goto out_unmap;
  346. +
  347. + ret = __bcm6345_ext_intc_init(node, num_irqs, irqs, base, shift);
  348. + if (!ret)
  349. + return 0;
  350. +out_unmap:
  351. + iounmap(base);
  352. +
  353. + for (i = 0; i < num_irqs; i++)
  354. + irq_dispose_mapping(irqs[i]);
  355. +
  356. + return ret;
  357. +}
  358. +
  359. +IRQCHIP_DECLARE(bcm6345_ext_intc, "brcm,bcm6345-ext-intc",
  360. + bcm6345_ext_intc_of_init);
  361. +#endif
  362. --- /dev/null
  363. +++ b/include/linux/irqchip/irq-bcm6345-ext.h
  364. @@ -0,0 +1,14 @@
  365. +/*
  366. + * This file is subject to the terms and conditions of the GNU General Public
  367. + * License. See the file "COPYING" in the main directory of this archive
  368. + * for more details.
  369. + *
  370. + * Copyright (C) 2014 Jonas Gorski <jogo@openwrt.org>
  371. + */
  372. +
  373. +#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_H
  374. +#define __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_H
  375. +
  376. +void bcm6345_ext_intc_init(int n_irqs, int *irqs, void __iomem *reg, int shift);
  377. +
  378. +#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_H */