| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 1 | /* | 
| Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 2 |  * Copyright (C) 2011 Google, Inc. | 
| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 3 |  * | 
 | 4 |  * Author: | 
| Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 5 |  *	Colin Cross <ccross@android.com> | 
| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 6 |  * | 
| Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 7 |  * Copyright (C) 2010, NVIDIA Corporation | 
 | 8 |  * | 
| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 9 |  * This software is licensed under the terms of the GNU General Public | 
 | 10 |  * License version 2, as published by the Free Software Foundation, and | 
 | 11 |  * may be copied, distributed, and modified under those terms. | 
 | 12 |  * | 
 | 13 |  * This program is distributed in the hope that it will be useful, | 
 | 14 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 15 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 16 |  * GNU General Public License for more details. | 
 | 17 |  * | 
 | 18 |  */ | 
 | 19 |  | 
 | 20 | #include <linux/kernel.h> | 
| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 21 | #include <linux/interrupt.h> | 
 | 22 | #include <linux/irq.h> | 
 | 23 | #include <linux/io.h> | 
 | 24 |  | 
 | 25 | #include <asm/hardware/gic.h> | 
 | 26 |  | 
 | 27 | #include <mach/iomap.h> | 
 | 28 |  | 
 | 29 | #include "board.h" | 
 | 30 |  | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 31 | #define ICTLR_CPU_IEP_VFIQ	0x08 | 
 | 32 | #define ICTLR_CPU_IEP_FIR	0x14 | 
 | 33 | #define ICTLR_CPU_IEP_FIR_SET	0x18 | 
 | 34 | #define ICTLR_CPU_IEP_FIR_CLR	0x1c | 
 | 35 |  | 
 | 36 | #define ICTLR_CPU_IER		0x20 | 
 | 37 | #define ICTLR_CPU_IER_SET	0x24 | 
 | 38 | #define ICTLR_CPU_IER_CLR	0x28 | 
 | 39 | #define ICTLR_CPU_IEP_CLASS	0x2C | 
 | 40 |  | 
 | 41 | #define ICTLR_COP_IER		0x30 | 
 | 42 | #define ICTLR_COP_IER_SET	0x34 | 
 | 43 | #define ICTLR_COP_IER_CLR	0x38 | 
 | 44 | #define ICTLR_COP_IEP_CLASS	0x3c | 
 | 45 |  | 
 | 46 | #define NUM_ICTLRS 4 | 
 | 47 | #define FIRST_LEGACY_IRQ 32 | 
 | 48 |  | 
 | 49 | static void __iomem *ictlr_reg_base[] = { | 
 | 50 | 	IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE), | 
 | 51 | 	IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE), | 
 | 52 | 	IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE), | 
 | 53 | 	IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE), | 
 | 54 | }; | 
 | 55 |  | 
 | 56 | static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg) | 
 | 57 | { | 
 | 58 | 	void __iomem *base; | 
 | 59 | 	u32 mask; | 
 | 60 |  | 
 | 61 | 	BUG_ON(irq < FIRST_LEGACY_IRQ || | 
 | 62 | 		irq >= FIRST_LEGACY_IRQ + NUM_ICTLRS * 32); | 
 | 63 |  | 
 | 64 | 	base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32]; | 
 | 65 | 	mask = BIT((irq - FIRST_LEGACY_IRQ) % 32); | 
 | 66 |  | 
 | 67 | 	__raw_writel(mask, base + reg); | 
 | 68 | } | 
 | 69 |  | 
| Lennert Buytenhek | 37337a8 | 2010-11-29 11:14:46 +0100 | [diff] [blame] | 70 | static void tegra_mask(struct irq_data *d) | 
| Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 71 | { | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 72 | 	if (d->irq < FIRST_LEGACY_IRQ) | 
 | 73 | 		return; | 
 | 74 |  | 
 | 75 | 	tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR); | 
| Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 76 | } | 
 | 77 |  | 
| Lennert Buytenhek | 37337a8 | 2010-11-29 11:14:46 +0100 | [diff] [blame] | 78 | static void tegra_unmask(struct irq_data *d) | 
| Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 79 | { | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 80 | 	if (d->irq < FIRST_LEGACY_IRQ) | 
 | 81 | 		return; | 
 | 82 |  | 
 | 83 | 	tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET); | 
| Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 84 | } | 
 | 85 |  | 
| Colin Cross | 26d902c | 2011-02-09 22:17:17 -0800 | [diff] [blame] | 86 | static void tegra_ack(struct irq_data *d) | 
 | 87 | { | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 88 | 	if (d->irq < FIRST_LEGACY_IRQ) | 
 | 89 | 		return; | 
 | 90 |  | 
 | 91 | 	tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); | 
| Colin Cross | 26d902c | 2011-02-09 22:17:17 -0800 | [diff] [blame] | 92 | } | 
 | 93 |  | 
| Colin Cross | 4bd66cf | 2011-05-01 15:27:34 -0700 | [diff] [blame] | 94 | static void tegra_eoi(struct irq_data *d) | 
 | 95 | { | 
 | 96 | 	if (d->irq < FIRST_LEGACY_IRQ) | 
 | 97 | 		return; | 
 | 98 |  | 
 | 99 | 	tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); | 
 | 100 | } | 
 | 101 |  | 
| Colin Cross | 26d902c | 2011-02-09 22:17:17 -0800 | [diff] [blame] | 102 | static int tegra_retrigger(struct irq_data *d) | 
 | 103 | { | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 104 | 	if (d->irq < FIRST_LEGACY_IRQ) | 
| Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 105 | 		return 0; | 
 | 106 |  | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 107 | 	tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET); | 
 | 108 |  | 
| Colin Cross | 26d902c | 2011-02-09 22:17:17 -0800 | [diff] [blame] | 109 | 	return 1; | 
 | 110 | } | 
 | 111 |  | 
| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 112 | void __init tegra_init_irq(void) | 
 | 113 | { | 
| Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 114 | 	int i; | 
 | 115 |  | 
 | 116 | 	for (i = 0; i < NUM_ICTLRS; i++) { | 
 | 117 | 		void __iomem *ictlr = ictlr_reg_base[i]; | 
 | 118 | 		writel(~0, ictlr + ICTLR_CPU_IER_CLR); | 
 | 119 | 		writel(0, ictlr + ICTLR_CPU_IEP_CLASS); | 
 | 120 | 	} | 
| Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 121 |  | 
| Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 122 | 	gic_arch_extn.irq_ack = tegra_ack; | 
| Colin Cross | 4bd66cf | 2011-05-01 15:27:34 -0700 | [diff] [blame] | 123 | 	gic_arch_extn.irq_eoi = tegra_eoi; | 
| Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 124 | 	gic_arch_extn.irq_mask = tegra_mask; | 
 | 125 | 	gic_arch_extn.irq_unmask = tegra_unmask; | 
 | 126 | 	gic_arch_extn.irq_retrigger = tegra_retrigger; | 
 | 127 |  | 
| Russell King | b580b89 | 2010-12-04 15:55:14 +0000 | [diff] [blame] | 128 | 	gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE), | 
 | 129 | 		 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100)); | 
| Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 130 | } |