xref: /linux/arch/arm/mach-tegra/irq.c (revision 938fa349fbc16880feae4b65e56691ca12ede9ab)
15ad36c5fSErik Gilling /*
2*938fa349SColin Cross  * Copyright (C) 2011 Google, Inc.
35ad36c5fSErik Gilling  *
45ad36c5fSErik Gilling  * Author:
5*938fa349SColin Cross  *	Colin Cross <ccross@android.com>
65ad36c5fSErik Gilling  *
7460907bcSGary King  * Copyright (C) 2010, NVIDIA Corporation
8460907bcSGary King  *
95ad36c5fSErik Gilling  * This software is licensed under the terms of the GNU General Public
105ad36c5fSErik Gilling  * License version 2, as published by the Free Software Foundation, and
115ad36c5fSErik Gilling  * may be copied, distributed, and modified under those terms.
125ad36c5fSErik Gilling  *
135ad36c5fSErik Gilling  * This program is distributed in the hope that it will be useful,
145ad36c5fSErik Gilling  * but WITHOUT ANY WARRANTY; without even the implied warranty of
155ad36c5fSErik Gilling  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165ad36c5fSErik Gilling  * GNU General Public License for more details.
175ad36c5fSErik Gilling  *
185ad36c5fSErik Gilling  */
195ad36c5fSErik Gilling 
205ad36c5fSErik Gilling #include <linux/kernel.h>
213524b70eSColin Cross #include <linux/delay.h>
225ad36c5fSErik Gilling #include <linux/init.h>
235ad36c5fSErik Gilling #include <linux/interrupt.h>
245ad36c5fSErik Gilling #include <linux/irq.h>
255ad36c5fSErik Gilling #include <linux/io.h>
265ad36c5fSErik Gilling 
275ad36c5fSErik Gilling #include <asm/hardware/gic.h>
285ad36c5fSErik Gilling 
295ad36c5fSErik Gilling #include <mach/iomap.h>
303524b70eSColin Cross #include <mach/legacy_irq.h>
312ea67fd1SColin Cross #include <mach/suspend.h>
325ad36c5fSErik Gilling 
335ad36c5fSErik Gilling #include "board.h"
345ad36c5fSErik Gilling 
353524b70eSColin Cross #define PMC_CTRL		0x0
363524b70eSColin Cross #define PMC_CTRL_LATCH_WAKEUPS	(1 << 5)
373524b70eSColin Cross #define PMC_WAKE_MASK		0xc
383524b70eSColin Cross #define PMC_WAKE_LEVEL		0x10
393524b70eSColin Cross #define PMC_WAKE_STATUS		0x14
403524b70eSColin Cross #define PMC_SW_WAKE_STATUS	0x18
413524b70eSColin Cross #define PMC_DPD_SAMPLE		0x20
42460907bcSGary King 
433524b70eSColin Cross static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
44460907bcSGary King 
453524b70eSColin Cross static u32 tegra_lp0_wake_enb;
463524b70eSColin Cross static u32 tegra_lp0_wake_level;
473524b70eSColin Cross static u32 tegra_lp0_wake_level_any;
48460907bcSGary King 
493524b70eSColin Cross /* ensures that sufficient time is passed for a register write to
503524b70eSColin Cross  * serialize into the 32KHz domain */
513524b70eSColin Cross static void pmc_32kwritel(u32 val, unsigned long offs)
523524b70eSColin Cross {
533524b70eSColin Cross 	writel(val, pmc + offs);
543524b70eSColin Cross 	udelay(130);
553524b70eSColin Cross }
563524b70eSColin Cross 
573524b70eSColin Cross int tegra_set_lp1_wake(int irq, int enable)
583524b70eSColin Cross {
593524b70eSColin Cross 	return tegra_legacy_irq_set_wake(irq, enable);
603524b70eSColin Cross }
613524b70eSColin Cross 
623524b70eSColin Cross void tegra_set_lp0_wake_pads(u32 wake_enb, u32 wake_level, u32 wake_any)
633524b70eSColin Cross {
643524b70eSColin Cross 	u32 temp;
653524b70eSColin Cross 	u32 status;
663524b70eSColin Cross 	u32 lvl;
673524b70eSColin Cross 
683524b70eSColin Cross 	wake_level &= wake_enb;
693524b70eSColin Cross 	wake_any &= wake_enb;
703524b70eSColin Cross 
713524b70eSColin Cross 	wake_level |= (tegra_lp0_wake_level & tegra_lp0_wake_enb);
723524b70eSColin Cross 	wake_any |= (tegra_lp0_wake_level_any & tegra_lp0_wake_enb);
733524b70eSColin Cross 
743524b70eSColin Cross 	wake_enb |= tegra_lp0_wake_enb;
753524b70eSColin Cross 
763524b70eSColin Cross 	pmc_32kwritel(0, PMC_SW_WAKE_STATUS);
773524b70eSColin Cross 	temp = readl(pmc + PMC_CTRL);
783524b70eSColin Cross 	temp |= PMC_CTRL_LATCH_WAKEUPS;
793524b70eSColin Cross 	pmc_32kwritel(temp, PMC_CTRL);
803524b70eSColin Cross 	temp &= ~PMC_CTRL_LATCH_WAKEUPS;
813524b70eSColin Cross 	pmc_32kwritel(temp, PMC_CTRL);
823524b70eSColin Cross 	status = readl(pmc + PMC_SW_WAKE_STATUS);
833524b70eSColin Cross 	lvl = readl(pmc + PMC_WAKE_LEVEL);
843524b70eSColin Cross 
853524b70eSColin Cross 	/* flip the wakeup trigger for any-edge triggered pads
863524b70eSColin Cross 	 * which are currently asserting as wakeups */
873524b70eSColin Cross 	lvl ^= status;
883524b70eSColin Cross 	lvl &= wake_any;
893524b70eSColin Cross 
903524b70eSColin Cross 	wake_level |= lvl;
913524b70eSColin Cross 
923524b70eSColin Cross 	writel(wake_level, pmc + PMC_WAKE_LEVEL);
933524b70eSColin Cross 	/* Enable DPD sample to trigger sampling pads data and direction
943524b70eSColin Cross 	 * in which pad will be driven during lp0 mode*/
953524b70eSColin Cross 	writel(0x1, pmc + PMC_DPD_SAMPLE);
963524b70eSColin Cross 
973524b70eSColin Cross 	writel(wake_enb, pmc + PMC_WAKE_MASK);
983524b70eSColin Cross }
99460907bcSGary King 
10037337a8dSLennert Buytenhek static void tegra_mask(struct irq_data *d)
101460907bcSGary King {
102*938fa349SColin Cross 	if (d->irq >= 32)
1033524b70eSColin Cross 		tegra_legacy_mask_irq(d->irq);
104460907bcSGary King }
105460907bcSGary King 
10637337a8dSLennert Buytenhek static void tegra_unmask(struct irq_data *d)
107460907bcSGary King {
108*938fa349SColin Cross 	if (d->irq >= 32)
1093524b70eSColin Cross 		tegra_legacy_unmask_irq(d->irq);
110460907bcSGary King }
111460907bcSGary King 
11226d902c0SColin Cross static void tegra_ack(struct irq_data *d)
11326d902c0SColin Cross {
114*938fa349SColin Cross 	if (d->irq >= 32)
11526d902c0SColin Cross 		tegra_legacy_force_irq_clr(d->irq);
11626d902c0SColin Cross }
11726d902c0SColin Cross 
11826d902c0SColin Cross static int tegra_retrigger(struct irq_data *d)
11926d902c0SColin Cross {
120*938fa349SColin Cross 	if (d->irq < 32)
121*938fa349SColin Cross 		return 0;
122*938fa349SColin Cross 
12326d902c0SColin Cross 	tegra_legacy_force_irq_set(d->irq);
12426d902c0SColin Cross 	return 1;
12526d902c0SColin Cross }
12626d902c0SColin Cross 
1275ad36c5fSErik Gilling void __init tegra_init_irq(void)
1285ad36c5fSErik Gilling {
1293524b70eSColin Cross 	tegra_init_legacy_irq();
130460907bcSGary King 
131*938fa349SColin Cross 	gic_arch_extn.irq_ack = tegra_ack;
132*938fa349SColin Cross 	gic_arch_extn.irq_mask = tegra_mask;
133*938fa349SColin Cross 	gic_arch_extn.irq_unmask = tegra_unmask;
134*938fa349SColin Cross 	gic_arch_extn.irq_retrigger = tegra_retrigger;
135*938fa349SColin Cross 
136b580b899SRussell King 	gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
137b580b899SRussell King 		 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
138460907bcSGary King }
139