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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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" or "brcm,bcm6318-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,301 @@
  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. + unsigned int toggle_clear_on_ack:1;
  120. +};
  121. +
  122. +static void bcm6345_ext_intc_irq_handle(struct irq_desc *desc)
  123. +{
  124. + struct intc_data *data = irq_desc_get_handler_data(desc);
  125. + struct irq_chip *chip = irq_desc_get_chip(desc);
  126. + unsigned int irq = irq_desc_get_irq(desc);
  127. + unsigned int idx;
  128. +
  129. + chained_irq_enter(chip, desc);
  130. +
  131. + for (idx = 0; idx < MAX_IRQS; idx++) {
  132. + if (data->parent_irq[idx] != irq)
  133. + continue;
  134. +
  135. + generic_handle_irq(irq_find_mapping(data->domain, idx));
  136. + }
  137. +
  138. + chained_irq_exit(chip, desc);
  139. +}
  140. +
  141. +static void bcm6345_ext_intc_irq_ack(struct irq_data *data)
  142. +{
  143. + struct intc_data *priv = data->domain->host_data;
  144. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  145. + u32 reg;
  146. +
  147. + raw_spin_lock(&priv->lock);
  148. + reg = __raw_readl(priv->reg);
  149. + __raw_writel(reg | (1 << (hwirq + EXTIRQ_CFG_CLEAR * priv->shift)),
  150. + priv->reg);
  151. + if (priv->toggle_clear_on_ack)
  152. + __raw_writel(reg, priv->reg);
  153. + raw_spin_unlock(&priv->lock);
  154. +}
  155. +
  156. +static void bcm6345_ext_intc_irq_mask(struct irq_data *data)
  157. +{
  158. + struct intc_data *priv = data->domain->host_data;
  159. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  160. + u32 reg;
  161. +
  162. + raw_spin_lock(&priv->lock);
  163. + reg = __raw_readl(priv->reg);
  164. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_MASK * priv->shift));
  165. + __raw_writel(reg, priv->reg);
  166. + raw_spin_unlock(&priv->lock);
  167. +}
  168. +
  169. +static void bcm6345_ext_intc_irq_unmask(struct irq_data *data)
  170. +{
  171. + struct intc_data *priv = data->domain->host_data;
  172. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  173. + u32 reg;
  174. +
  175. + raw_spin_lock(&priv->lock);
  176. + reg = __raw_readl(priv->reg);
  177. + reg |= 1 << (hwirq + EXTIRQ_CFG_MASK * priv->shift);
  178. + __raw_writel(reg, priv->reg);
  179. + raw_spin_unlock(&priv->lock);
  180. +}
  181. +
  182. +static int bcm6345_ext_intc_set_type(struct irq_data *data,
  183. + unsigned int flow_type)
  184. +{
  185. + struct intc_data *priv = data->domain->host_data;
  186. + irq_hw_number_t hwirq = irqd_to_hwirq(data);
  187. + bool levelsense = 0, sense = 0, bothedge = 0;
  188. + u32 reg;
  189. +
  190. + flow_type &= IRQ_TYPE_SENSE_MASK;
  191. +
  192. + if (flow_type == IRQ_TYPE_NONE)
  193. + flow_type = IRQ_TYPE_LEVEL_LOW;
  194. +
  195. + switch (flow_type) {
  196. + case IRQ_TYPE_EDGE_BOTH:
  197. + bothedge = 1;
  198. + break;
  199. +
  200. + case IRQ_TYPE_EDGE_RISING:
  201. + break;
  202. +
  203. + case IRQ_TYPE_EDGE_FALLING:
  204. + sense = 1;
  205. + break;
  206. +
  207. + case IRQ_TYPE_LEVEL_HIGH:
  208. + levelsense = 1;
  209. + sense = 1;
  210. + break;
  211. +
  212. + case IRQ_TYPE_LEVEL_LOW:
  213. + levelsense = 1;
  214. + break;
  215. +
  216. + default:
  217. + pr_err("bogus flow type combination given!\n");
  218. + return -EINVAL;
  219. + }
  220. +
  221. + raw_spin_lock(&priv->lock);
  222. + reg = __raw_readl(priv->reg);
  223. +
  224. + if (levelsense)
  225. + reg |= 1 << (hwirq + EXTIRQ_CFG_LEVELSENSE * priv->shift);
  226. + else
  227. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_LEVELSENSE * priv->shift));
  228. + if (sense)
  229. + reg |= 1 << (hwirq + EXTIRQ_CFG_SENSE * priv->shift);
  230. + else
  231. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_SENSE * priv->shift));
  232. + if (bothedge)
  233. + reg |= 1 << (hwirq + EXTIRQ_CFG_BOTHEDGE * priv->shift);
  234. + else
  235. + reg &= ~(1 << (hwirq + EXTIRQ_CFG_BOTHEDGE * priv->shift));
  236. +
  237. + __raw_writel(reg, priv->reg);
  238. + raw_spin_unlock(&priv->lock);
  239. +
  240. + irqd_set_trigger_type(data, flow_type);
  241. + if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  242. + irq_set_handler_locked(data, handle_level_irq);
  243. + else
  244. + irq_set_handler_locked(data, handle_edge_irq);
  245. +
  246. + return 0;
  247. +}
  248. +
  249. +static int bcm6345_ext_intc_map(struct irq_domain *d, unsigned int irq,
  250. + irq_hw_number_t hw)
  251. +{
  252. + struct intc_data *priv = d->host_data;
  253. +
  254. + irq_set_chip_and_handler(irq, &priv->chip, handle_level_irq);
  255. +
  256. + return 0;
  257. +}
  258. +
  259. +static const struct irq_domain_ops bcm6345_ext_domain_ops = {
  260. + .xlate = irq_domain_xlate_twocell,
  261. + .map = bcm6345_ext_intc_map,
  262. +};
  263. +
  264. +static int __init __bcm6345_ext_intc_init(struct device_node *node,
  265. + int num_irqs, int *irqs,
  266. + void __iomem *reg, int shift,
  267. + bool toggle_clear_on_ack)
  268. +{
  269. + struct intc_data *data;
  270. + unsigned int i;
  271. + int start = VIRQ_BASE;
  272. +
  273. + data = kzalloc(sizeof(*data), GFP_KERNEL);
  274. + if (!data)
  275. + return -ENOMEM;
  276. +
  277. + raw_spin_lock_init(&data->lock);
  278. +
  279. + for (i = 0; i < num_irqs; i++) {
  280. + data->parent_irq[i] = irqs[i];
  281. +
  282. + irq_set_handler_data(irqs[i], data);
  283. + irq_set_chained_handler(irqs[i], bcm6345_ext_intc_irq_handle);
  284. + }
  285. +
  286. + data->reg = reg;
  287. + data->shift = shift;
  288. + data->toggle_clear_on_ack = toggle_clear_on_ack;
  289. +
  290. + data->chip.name = "bcm6345-ext-intc";
  291. + data->chip.irq_ack = bcm6345_ext_intc_irq_ack;
  292. + data->chip.irq_mask = bcm6345_ext_intc_irq_mask;
  293. + data->chip.irq_unmask = bcm6345_ext_intc_irq_unmask;
  294. + data->chip.irq_set_type = bcm6345_ext_intc_set_type;
  295. +
  296. + /*
  297. + * If we have less than 4 irqs, this is the second controller on
  298. + * bcm63xx. So increase the VIRQ start to not overlap with the first
  299. + * one, but only do so if we actually use a non-zero start.
  300. + *
  301. + * This can be removed when bcm63xx has no legacy users anymore.
  302. + */
  303. + if (start && num_irqs < 4)
  304. + start += 4;
  305. +
  306. + data->domain = irq_domain_add_simple(node, num_irqs, start,
  307. + &bcm6345_ext_domain_ops, data);
  308. + if (!data->domain) {
  309. + kfree(data);
  310. + return -ENOMEM;
  311. + }
  312. +
  313. + return 0;
  314. +}
  315. +
  316. +void __init bcm6345_ext_intc_init(int num_irqs, int *irqs, void __iomem *reg,
  317. + int shift)
  318. +{
  319. + __bcm6345_ext_intc_init(NULL, num_irqs, irqs, reg, shift, false);
  320. +}
  321. +
  322. +#ifdef CONFIG_OF
  323. +static int __init bcm6345_ext_intc_of_init(struct device_node *node,
  324. + struct device_node *parent)
  325. +{
  326. + int num_irqs, ret = -EINVAL;
  327. + unsigned i;
  328. + void __iomem *base;
  329. + int irqs[MAX_IRQS] = { 0 };
  330. + u32 shift;
  331. + bool toggle_clear_on_ack = false;
  332. +
  333. + num_irqs = of_irq_count(node);
  334. +
  335. + if (!num_irqs || num_irqs > MAX_IRQS)
  336. + return -EINVAL;
  337. +
  338. + if (of_property_read_u32(node, "brcm,field-width", &shift))
  339. + shift = 4;
  340. +
  341. + /* on BCM6318 setting CLEAR seems to continuously mask interrupts */
  342. + if (of_device_is_compatible(node, "brcm,bcm6318-ext-intc"))
  343. + toggle_clear_on_ack = true;
  344. +
  345. + for (i = 0; i < num_irqs; i++) {
  346. + irqs[i] = irq_of_parse_and_map(node, i);
  347. + if (!irqs[i]) {
  348. + ret = -ENOMEM;
  349. + goto out_unmap;
  350. + }
  351. + }
  352. +
  353. + base = of_iomap(node, 0);
  354. + if (!base)
  355. + goto out_unmap;
  356. +
  357. + ret = __bcm6345_ext_intc_init(node, num_irqs, irqs, base, shift,
  358. + toggle_clear_on_ack);
  359. + if (!ret)
  360. + return 0;
  361. +out_unmap:
  362. + iounmap(base);
  363. +
  364. + for (i = 0; i < num_irqs; i++)
  365. + irq_dispose_mapping(irqs[i]);
  366. +
  367. + return ret;
  368. +}
  369. +
  370. +IRQCHIP_DECLARE(bcm6318_ext_intc, "brcm,bcm6318-ext-intc",
  371. + bcm6345_ext_intc_of_init);
  372. +IRQCHIP_DECLARE(bcm6345_ext_intc, "brcm,bcm6345-ext-intc",
  373. + bcm6345_ext_intc_of_init);
  374. +#endif
  375. --- /dev/null
  376. +++ b/include/linux/irqchip/irq-bcm6345-ext.h
  377. @@ -0,0 +1,14 @@
  378. +/*
  379. + * This file is subject to the terms and conditions of the GNU General Public
  380. + * License. See the file "COPYING" in the main directory of this archive
  381. + * for more details.
  382. + *
  383. + * Copyright (C) 2014 Jonas Gorski <jogo@openwrt.org>
  384. + */
  385. +
  386. +#ifndef __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_H
  387. +#define __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_H
  388. +
  389. +void bcm6345_ext_intc_init(int n_irqs, int *irqs, void __iomem *reg, int shift);
  390. +
  391. +#endif /* __INCLUDE_LINUX_IRQCHIP_IRQ_BCM6345_EXT_H */