18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Atmel AT91 AIC5 (Advanced Interrupt Controller) driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci *  Copyright (C) 2004 SAN People
58c2ecf20Sopenharmony_ci *  Copyright (C) 2004 ATMEL
68c2ecf20Sopenharmony_ci *  Copyright (C) Rick Bronson
78c2ecf20Sopenharmony_ci *  Copyright (C) 2014 Free Electrons
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
128c2ecf20Sopenharmony_ci * License version 2.  This program is licensed "as is" without any
138c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/init.h>
178c2ecf20Sopenharmony_ci#include <linux/module.h>
188c2ecf20Sopenharmony_ci#include <linux/mm.h>
198c2ecf20Sopenharmony_ci#include <linux/bitmap.h>
208c2ecf20Sopenharmony_ci#include <linux/types.h>
218c2ecf20Sopenharmony_ci#include <linux/irq.h>
228c2ecf20Sopenharmony_ci#include <linux/irqchip.h>
238c2ecf20Sopenharmony_ci#include <linux/of.h>
248c2ecf20Sopenharmony_ci#include <linux/of_address.h>
258c2ecf20Sopenharmony_ci#include <linux/of_irq.h>
268c2ecf20Sopenharmony_ci#include <linux/irqdomain.h>
278c2ecf20Sopenharmony_ci#include <linux/err.h>
288c2ecf20Sopenharmony_ci#include <linux/slab.h>
298c2ecf20Sopenharmony_ci#include <linux/io.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include <asm/exception.h>
328c2ecf20Sopenharmony_ci#include <asm/mach/irq.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include "irq-atmel-aic-common.h"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* Number of irq lines managed by AIC */
378c2ecf20Sopenharmony_ci#define NR_AIC5_IRQS	128
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define AT91_AIC5_SSR		0x0
408c2ecf20Sopenharmony_ci#define AT91_AIC5_INTSEL_MSK	(0x7f << 0)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define AT91_AIC5_SMR			0x4
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define AT91_AIC5_SVR			0x8
458c2ecf20Sopenharmony_ci#define AT91_AIC5_IVR			0x10
468c2ecf20Sopenharmony_ci#define AT91_AIC5_FVR			0x14
478c2ecf20Sopenharmony_ci#define AT91_AIC5_ISR			0x18
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define AT91_AIC5_IPR0			0x20
508c2ecf20Sopenharmony_ci#define AT91_AIC5_IPR1			0x24
518c2ecf20Sopenharmony_ci#define AT91_AIC5_IPR2			0x28
528c2ecf20Sopenharmony_ci#define AT91_AIC5_IPR3			0x2c
538c2ecf20Sopenharmony_ci#define AT91_AIC5_IMR			0x30
548c2ecf20Sopenharmony_ci#define AT91_AIC5_CISR			0x34
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define AT91_AIC5_IECR			0x40
578c2ecf20Sopenharmony_ci#define AT91_AIC5_IDCR			0x44
588c2ecf20Sopenharmony_ci#define AT91_AIC5_ICCR			0x48
598c2ecf20Sopenharmony_ci#define AT91_AIC5_ISCR			0x4c
608c2ecf20Sopenharmony_ci#define AT91_AIC5_EOICR			0x38
618c2ecf20Sopenharmony_ci#define AT91_AIC5_SPU			0x3c
628c2ecf20Sopenharmony_ci#define AT91_AIC5_DCR			0x6c
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define AT91_AIC5_FFER			0x50
658c2ecf20Sopenharmony_ci#define AT91_AIC5_FFDR			0x54
668c2ecf20Sopenharmony_ci#define AT91_AIC5_FFSR			0x58
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic struct irq_domain *aic5_domain;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic asmlinkage void __exception_irq_entry
718c2ecf20Sopenharmony_ciaic5_handle(struct pt_regs *regs)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(aic5_domain, 0);
748c2ecf20Sopenharmony_ci	u32 irqnr;
758c2ecf20Sopenharmony_ci	u32 irqstat;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	irqnr = irq_reg_readl(bgc, AT91_AIC5_IVR);
788c2ecf20Sopenharmony_ci	irqstat = irq_reg_readl(bgc, AT91_AIC5_ISR);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	if (!irqstat)
818c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, 0, AT91_AIC5_EOICR);
828c2ecf20Sopenharmony_ci	else
838c2ecf20Sopenharmony_ci		handle_domain_irq(aic5_domain, irqnr, regs);
848c2ecf20Sopenharmony_ci}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic void aic5_mask(struct irq_data *d)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
898c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
908c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	/*
938c2ecf20Sopenharmony_ci	 * Disable interrupt on AIC5. We always take the lock of the
948c2ecf20Sopenharmony_ci	 * first irq chip as all chips share the same registers.
958c2ecf20Sopenharmony_ci	 */
968c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
978c2ecf20Sopenharmony_ci	irq_reg_writel(gc, d->hwirq, AT91_AIC5_SSR);
988c2ecf20Sopenharmony_ci	irq_reg_writel(gc, 1, AT91_AIC5_IDCR);
998c2ecf20Sopenharmony_ci	gc->mask_cache &= ~d->mask;
1008c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_cistatic void aic5_unmask(struct irq_data *d)
1048c2ecf20Sopenharmony_ci{
1058c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
1068c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
1078c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	/*
1108c2ecf20Sopenharmony_ci	 * Enable interrupt on AIC5. We always take the lock of the
1118c2ecf20Sopenharmony_ci	 * first irq chip as all chips share the same registers.
1128c2ecf20Sopenharmony_ci	 */
1138c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
1148c2ecf20Sopenharmony_ci	irq_reg_writel(gc, d->hwirq, AT91_AIC5_SSR);
1158c2ecf20Sopenharmony_ci	irq_reg_writel(gc, 1, AT91_AIC5_IECR);
1168c2ecf20Sopenharmony_ci	gc->mask_cache |= d->mask;
1178c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic int aic5_retrigger(struct irq_data *d)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
1238c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	/* Enable interrupt on AIC5 */
1268c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
1278c2ecf20Sopenharmony_ci	irq_reg_writel(bgc, d->hwirq, AT91_AIC5_SSR);
1288c2ecf20Sopenharmony_ci	irq_reg_writel(bgc, 1, AT91_AIC5_ISCR);
1298c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	return 1;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic int aic5_set_type(struct irq_data *d, unsigned type)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
1378c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
1388c2ecf20Sopenharmony_ci	unsigned int smr;
1398c2ecf20Sopenharmony_ci	int ret;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
1428c2ecf20Sopenharmony_ci	irq_reg_writel(bgc, d->hwirq, AT91_AIC5_SSR);
1438c2ecf20Sopenharmony_ci	smr = irq_reg_readl(bgc, AT91_AIC5_SMR);
1448c2ecf20Sopenharmony_ci	ret = aic_common_set_type(d, type, &smr);
1458c2ecf20Sopenharmony_ci	if (!ret)
1468c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, smr, AT91_AIC5_SMR);
1478c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	return ret;
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
1538c2ecf20Sopenharmony_cistatic u32 *smr_cache;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic void aic5_suspend(struct irq_data *d)
1568c2ecf20Sopenharmony_ci{
1578c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
1588c2ecf20Sopenharmony_ci	struct irq_domain_chip_generic *dgc = domain->gc;
1598c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
1608c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1618c2ecf20Sopenharmony_ci	int i;
1628c2ecf20Sopenharmony_ci	u32 mask;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	if (smr_cache)
1658c2ecf20Sopenharmony_ci		for (i = 0; i < domain->revmap_size; i++) {
1668c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, i, AT91_AIC5_SSR);
1678c2ecf20Sopenharmony_ci			smr_cache[i] = irq_reg_readl(bgc, AT91_AIC5_SMR);
1688c2ecf20Sopenharmony_ci		}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
1718c2ecf20Sopenharmony_ci	for (i = 0; i < dgc->irqs_per_chip; i++) {
1728c2ecf20Sopenharmony_ci		mask = 1 << i;
1738c2ecf20Sopenharmony_ci		if ((mask & gc->mask_cache) == (mask & gc->wake_active))
1748c2ecf20Sopenharmony_ci			continue;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, i + gc->irq_base, AT91_AIC5_SSR);
1778c2ecf20Sopenharmony_ci		if (mask & gc->wake_active)
1788c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, 1, AT91_AIC5_IECR);
1798c2ecf20Sopenharmony_ci		else
1808c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, 1, AT91_AIC5_IDCR);
1818c2ecf20Sopenharmony_ci	}
1828c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic void aic5_resume(struct irq_data *d)
1868c2ecf20Sopenharmony_ci{
1878c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
1888c2ecf20Sopenharmony_ci	struct irq_domain_chip_generic *dgc = domain->gc;
1898c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
1908c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
1918c2ecf20Sopenharmony_ci	int i;
1928c2ecf20Sopenharmony_ci	u32 mask;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	if (smr_cache) {
1978c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, 0xffffffff, AT91_AIC5_SPU);
1988c2ecf20Sopenharmony_ci		for (i = 0; i < domain->revmap_size; i++) {
1998c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, i, AT91_AIC5_SSR);
2008c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, i, AT91_AIC5_SVR);
2018c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, smr_cache[i], AT91_AIC5_SMR);
2028c2ecf20Sopenharmony_ci		}
2038c2ecf20Sopenharmony_ci	}
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	for (i = 0; i < dgc->irqs_per_chip; i++) {
2068c2ecf20Sopenharmony_ci		mask = 1 << i;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci		if (!smr_cache &&
2098c2ecf20Sopenharmony_ci		    ((mask & gc->mask_cache) == (mask & gc->wake_active)))
2108c2ecf20Sopenharmony_ci			continue;
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, i + gc->irq_base, AT91_AIC5_SSR);
2138c2ecf20Sopenharmony_ci		if (mask & gc->mask_cache)
2148c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, 1, AT91_AIC5_IECR);
2158c2ecf20Sopenharmony_ci		else
2168c2ecf20Sopenharmony_ci			irq_reg_writel(bgc, 1, AT91_AIC5_IDCR);
2178c2ecf20Sopenharmony_ci	}
2188c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistatic void aic5_pm_shutdown(struct irq_data *d)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	struct irq_domain *domain = d->domain;
2248c2ecf20Sopenharmony_ci	struct irq_domain_chip_generic *dgc = domain->gc;
2258c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
2268c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
2278c2ecf20Sopenharmony_ci	int i;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	irq_gc_lock(bgc);
2308c2ecf20Sopenharmony_ci	for (i = 0; i < dgc->irqs_per_chip; i++) {
2318c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, i + gc->irq_base, AT91_AIC5_SSR);
2328c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, 1, AT91_AIC5_IDCR);
2338c2ecf20Sopenharmony_ci		irq_reg_writel(bgc, 1, AT91_AIC5_ICCR);
2348c2ecf20Sopenharmony_ci	}
2358c2ecf20Sopenharmony_ci	irq_gc_unlock(bgc);
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci#else
2388c2ecf20Sopenharmony_ci#define aic5_suspend		NULL
2398c2ecf20Sopenharmony_ci#define aic5_resume		NULL
2408c2ecf20Sopenharmony_ci#define aic5_pm_shutdown	NULL
2418c2ecf20Sopenharmony_ci#endif /* CONFIG_PM */
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistatic void __init aic5_hw_init(struct irq_domain *domain)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc = irq_get_domain_generic_chip(domain, 0);
2468c2ecf20Sopenharmony_ci	int i;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/*
2498c2ecf20Sopenharmony_ci	 * Perform 8 End Of Interrupt Command to make sure AIC
2508c2ecf20Sopenharmony_ci	 * will not Lock out nIRQ
2518c2ecf20Sopenharmony_ci	 */
2528c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++)
2538c2ecf20Sopenharmony_ci		irq_reg_writel(gc, 0, AT91_AIC5_EOICR);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	/*
2568c2ecf20Sopenharmony_ci	 * Spurious Interrupt ID in Spurious Vector Register.
2578c2ecf20Sopenharmony_ci	 * When there is no current interrupt, the IRQ Vector Register
2588c2ecf20Sopenharmony_ci	 * reads the value stored in AIC_SPU
2598c2ecf20Sopenharmony_ci	 */
2608c2ecf20Sopenharmony_ci	irq_reg_writel(gc, 0xffffffff, AT91_AIC5_SPU);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	/* No debugging in AIC: Debug (Protect) Control Register */
2638c2ecf20Sopenharmony_ci	irq_reg_writel(gc, 0, AT91_AIC5_DCR);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/* Disable and clear all interrupts initially */
2668c2ecf20Sopenharmony_ci	for (i = 0; i < domain->revmap_size; i++) {
2678c2ecf20Sopenharmony_ci		irq_reg_writel(gc, i, AT91_AIC5_SSR);
2688c2ecf20Sopenharmony_ci		irq_reg_writel(gc, i, AT91_AIC5_SVR);
2698c2ecf20Sopenharmony_ci		irq_reg_writel(gc, 1, AT91_AIC5_IDCR);
2708c2ecf20Sopenharmony_ci		irq_reg_writel(gc, 1, AT91_AIC5_ICCR);
2718c2ecf20Sopenharmony_ci	}
2728c2ecf20Sopenharmony_ci}
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cistatic int aic5_irq_domain_xlate(struct irq_domain *d,
2758c2ecf20Sopenharmony_ci				 struct device_node *ctrlr,
2768c2ecf20Sopenharmony_ci				 const u32 *intspec, unsigned int intsize,
2778c2ecf20Sopenharmony_ci				 irq_hw_number_t *out_hwirq,
2788c2ecf20Sopenharmony_ci				 unsigned int *out_type)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	struct irq_chip_generic *bgc = irq_get_domain_generic_chip(d, 0);
2818c2ecf20Sopenharmony_ci	unsigned long flags;
2828c2ecf20Sopenharmony_ci	unsigned smr;
2838c2ecf20Sopenharmony_ci	int ret;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	if (!bgc)
2868c2ecf20Sopenharmony_ci		return -EINVAL;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	ret = aic_common_irq_domain_xlate(d, ctrlr, intspec, intsize,
2898c2ecf20Sopenharmony_ci					  out_hwirq, out_type);
2908c2ecf20Sopenharmony_ci	if (ret)
2918c2ecf20Sopenharmony_ci		return ret;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	irq_gc_lock_irqsave(bgc, flags);
2948c2ecf20Sopenharmony_ci	irq_reg_writel(bgc, *out_hwirq, AT91_AIC5_SSR);
2958c2ecf20Sopenharmony_ci	smr = irq_reg_readl(bgc, AT91_AIC5_SMR);
2968c2ecf20Sopenharmony_ci	aic_common_set_priority(intspec[2], &smr);
2978c2ecf20Sopenharmony_ci	irq_reg_writel(bgc, smr, AT91_AIC5_SMR);
2988c2ecf20Sopenharmony_ci	irq_gc_unlock_irqrestore(bgc, flags);
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	return ret;
3018c2ecf20Sopenharmony_ci}
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_cistatic const struct irq_domain_ops aic5_irq_ops = {
3048c2ecf20Sopenharmony_ci	.map	= irq_map_generic_chip,
3058c2ecf20Sopenharmony_ci	.xlate	= aic5_irq_domain_xlate,
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic void __init sama5d3_aic_irq_fixup(void)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	aic_common_rtc_irq_fixup();
3118c2ecf20Sopenharmony_ci}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic void __init sam9x60_aic_irq_fixup(void)
3148c2ecf20Sopenharmony_ci{
3158c2ecf20Sopenharmony_ci	aic_common_rtc_irq_fixup();
3168c2ecf20Sopenharmony_ci	aic_common_rtt_irq_fixup();
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic const struct of_device_id aic5_irq_fixups[] __initconst = {
3208c2ecf20Sopenharmony_ci	{ .compatible = "atmel,sama5d3", .data = sama5d3_aic_irq_fixup },
3218c2ecf20Sopenharmony_ci	{ .compatible = "atmel,sama5d4", .data = sama5d3_aic_irq_fixup },
3228c2ecf20Sopenharmony_ci	{ .compatible = "microchip,sam9x60", .data = sam9x60_aic_irq_fixup },
3238c2ecf20Sopenharmony_ci	{ /* sentinel */ },
3248c2ecf20Sopenharmony_ci};
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_cistatic int __init aic5_of_init(struct device_node *node,
3278c2ecf20Sopenharmony_ci			       struct device_node *parent,
3288c2ecf20Sopenharmony_ci			       int nirqs)
3298c2ecf20Sopenharmony_ci{
3308c2ecf20Sopenharmony_ci	struct irq_chip_generic *gc;
3318c2ecf20Sopenharmony_ci	struct irq_domain *domain;
3328c2ecf20Sopenharmony_ci	int nchips;
3338c2ecf20Sopenharmony_ci	int i;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	if (nirqs > NR_AIC5_IRQS)
3368c2ecf20Sopenharmony_ci		return -EINVAL;
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	if (aic5_domain)
3398c2ecf20Sopenharmony_ci		return -EEXIST;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	domain = aic_common_of_init(node, &aic5_irq_ops, "atmel-aic5",
3428c2ecf20Sopenharmony_ci				    nirqs, aic5_irq_fixups);
3438c2ecf20Sopenharmony_ci	if (IS_ERR(domain))
3448c2ecf20Sopenharmony_ci		return PTR_ERR(domain);
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	aic5_domain = domain;
3478c2ecf20Sopenharmony_ci	nchips = aic5_domain->revmap_size / 32;
3488c2ecf20Sopenharmony_ci	for (i = 0; i < nchips; i++) {
3498c2ecf20Sopenharmony_ci		gc = irq_get_domain_generic_chip(domain, i * 32);
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci		gc->chip_types[0].regs.eoi = AT91_AIC5_EOICR;
3528c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_mask = aic5_mask;
3538c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_unmask = aic5_unmask;
3548c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_retrigger = aic5_retrigger;
3558c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_set_type = aic5_set_type;
3568c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_suspend = aic5_suspend;
3578c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_resume = aic5_resume;
3588c2ecf20Sopenharmony_ci		gc->chip_types[0].chip.irq_pm_shutdown = aic5_pm_shutdown;
3598c2ecf20Sopenharmony_ci	}
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	aic5_hw_init(domain);
3628c2ecf20Sopenharmony_ci	set_handle_irq(aic5_handle);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	return 0;
3658c2ecf20Sopenharmony_ci}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci#define NR_SAMA5D2_IRQS		77
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistatic int __init sama5d2_aic5_of_init(struct device_node *node,
3708c2ecf20Sopenharmony_ci				       struct device_node *parent)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
3738c2ecf20Sopenharmony_ci	smr_cache = kcalloc(DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32,
3748c2ecf20Sopenharmony_ci			    sizeof(*smr_cache), GFP_KERNEL);
3758c2ecf20Sopenharmony_ci	if (!smr_cache)
3768c2ecf20Sopenharmony_ci		return -ENOMEM;
3778c2ecf20Sopenharmony_ci#endif
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	return aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ciIRQCHIP_DECLARE(sama5d2_aic5, "atmel,sama5d2-aic", sama5d2_aic5_of_init);
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci#define NR_SAMA5D3_IRQS		48
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic int __init sama5d3_aic5_of_init(struct device_node *node,
3868c2ecf20Sopenharmony_ci				       struct device_node *parent)
3878c2ecf20Sopenharmony_ci{
3888c2ecf20Sopenharmony_ci	return aic5_of_init(node, parent, NR_SAMA5D3_IRQS);
3898c2ecf20Sopenharmony_ci}
3908c2ecf20Sopenharmony_ciIRQCHIP_DECLARE(sama5d3_aic5, "atmel,sama5d3-aic", sama5d3_aic5_of_init);
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci#define NR_SAMA5D4_IRQS		68
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_cistatic int __init sama5d4_aic5_of_init(struct device_node *node,
3958c2ecf20Sopenharmony_ci				       struct device_node *parent)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	return aic5_of_init(node, parent, NR_SAMA5D4_IRQS);
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ciIRQCHIP_DECLARE(sama5d4_aic5, "atmel,sama5d4-aic", sama5d4_aic5_of_init);
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci#define NR_SAM9X60_IRQS		50
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_cistatic int __init sam9x60_aic5_of_init(struct device_node *node,
4048c2ecf20Sopenharmony_ci				       struct device_node *parent)
4058c2ecf20Sopenharmony_ci{
4068c2ecf20Sopenharmony_ci	return aic5_of_init(node, parent, NR_SAM9X60_IRQS);
4078c2ecf20Sopenharmony_ci}
4088c2ecf20Sopenharmony_ciIRQCHIP_DECLARE(sam9x60_aic5, "microchip,sam9x60-aic", sam9x60_aic5_of_init);
409