blob: 6b5c8b8abe02eba3fc52ab65b290135fabee4579 [file] [log] [blame]
Erik Gilling5ad36c52010-03-15 23:04:46 -07001/*
2 * Copyright (C) 2010 Google, Inc.
3 *
4 * Author:
5 * Colin Cross <ccross@google.com>
6 *
Gary King460907b2010-04-05 20:30:59 -07007 * Copyright (C) 2010, NVIDIA Corporation
8 *
Erik Gilling5ad36c52010-03-15 23:04:46 -07009 * 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>
Colin Cross3524b702010-11-28 22:23:55 -080021#include <linux/delay.h>
Erik Gilling5ad36c52010-03-15 23:04:46 -070022#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/io.h>
26
27#include <asm/hardware/gic.h>
28
29#include <mach/iomap.h>
Colin Cross3524b702010-11-28 22:23:55 -080030#include <mach/legacy_irq.h>
Colin Cross2ea67fd2010-10-04 08:49:49 -070031#include <mach/suspend.h>
Erik Gilling5ad36c52010-03-15 23:04:46 -070032
33#include "board.h"
34
Colin Cross3524b702010-11-28 22:23:55 -080035#define PMC_CTRL 0x0
36#define PMC_CTRL_LATCH_WAKEUPS (1 << 5)
37#define PMC_WAKE_MASK 0xc
38#define PMC_WAKE_LEVEL 0x10
39#define PMC_WAKE_STATUS 0x14
40#define PMC_SW_WAKE_STATUS 0x18
41#define PMC_DPD_SAMPLE 0x20
Gary King460907b2010-04-05 20:30:59 -070042
Colin Cross3524b702010-11-28 22:23:55 -080043static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
Gary King460907b2010-04-05 20:30:59 -070044
Colin Cross3524b702010-11-28 22:23:55 -080045static u32 tegra_lp0_wake_enb;
46static u32 tegra_lp0_wake_level;
47static u32 tegra_lp0_wake_level_any;
Gary King460907b2010-04-05 20:30:59 -070048
Colin Crosscc939752010-11-28 20:14:53 -080049static void (*tegra_gic_mask_irq)(struct irq_data *d);
50static void (*tegra_gic_unmask_irq)(struct irq_data *d);
Colin Cross26d902c2011-02-09 22:17:17 -080051static void (*tegra_gic_ack_irq)(struct irq_data *d);
Gary King460907b2010-04-05 20:30:59 -070052
Colin Cross3524b702010-11-28 22:23:55 -080053/* ensures that sufficient time is passed for a register write to
54 * serialize into the 32KHz domain */
55static void pmc_32kwritel(u32 val, unsigned long offs)
56{
57 writel(val, pmc + offs);
58 udelay(130);
59}
60
61int tegra_set_lp1_wake(int irq, int enable)
62{
63 return tegra_legacy_irq_set_wake(irq, enable);
64}
65
66void tegra_set_lp0_wake_pads(u32 wake_enb, u32 wake_level, u32 wake_any)
67{
68 u32 temp;
69 u32 status;
70 u32 lvl;
71
72 wake_level &= wake_enb;
73 wake_any &= wake_enb;
74
75 wake_level |= (tegra_lp0_wake_level & tegra_lp0_wake_enb);
76 wake_any |= (tegra_lp0_wake_level_any & tegra_lp0_wake_enb);
77
78 wake_enb |= tegra_lp0_wake_enb;
79
80 pmc_32kwritel(0, PMC_SW_WAKE_STATUS);
81 temp = readl(pmc + PMC_CTRL);
82 temp |= PMC_CTRL_LATCH_WAKEUPS;
83 pmc_32kwritel(temp, PMC_CTRL);
84 temp &= ~PMC_CTRL_LATCH_WAKEUPS;
85 pmc_32kwritel(temp, PMC_CTRL);
86 status = readl(pmc + PMC_SW_WAKE_STATUS);
87 lvl = readl(pmc + PMC_WAKE_LEVEL);
88
89 /* flip the wakeup trigger for any-edge triggered pads
90 * which are currently asserting as wakeups */
91 lvl ^= status;
92 lvl &= wake_any;
93
94 wake_level |= lvl;
95
96 writel(wake_level, pmc + PMC_WAKE_LEVEL);
97 /* Enable DPD sample to trigger sampling pads data and direction
98 * in which pad will be driven during lp0 mode*/
99 writel(0x1, pmc + PMC_DPD_SAMPLE);
100
101 writel(wake_enb, pmc + PMC_WAKE_MASK);
102}
Gary King460907b2010-04-05 20:30:59 -0700103
Lennert Buytenhek37337a82010-11-29 11:14:46 +0100104static void tegra_mask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -0700105{
Colin Crosscc939752010-11-28 20:14:53 -0800106 tegra_gic_mask_irq(d);
Colin Cross3524b702010-11-28 22:23:55 -0800107 tegra_legacy_mask_irq(d->irq);
Gary King460907b2010-04-05 20:30:59 -0700108}
109
Lennert Buytenhek37337a82010-11-29 11:14:46 +0100110static void tegra_unmask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -0700111{
Colin Crosscc939752010-11-28 20:14:53 -0800112 tegra_gic_unmask_irq(d);
Colin Cross3524b702010-11-28 22:23:55 -0800113 tegra_legacy_unmask_irq(d->irq);
Gary King460907b2010-04-05 20:30:59 -0700114}
115
Colin Cross26d902c2011-02-09 22:17:17 -0800116static void tegra_ack(struct irq_data *d)
117{
118 tegra_legacy_force_irq_clr(d->irq);
119 tegra_gic_ack_irq(d);
120}
121
122static int tegra_retrigger(struct irq_data *d)
123{
124 tegra_legacy_force_irq_set(d->irq);
125 return 1;
126}
127
Gary King460907b2010-04-05 20:30:59 -0700128static struct irq_chip tegra_irq = {
Colin Cross3524b702010-11-28 22:23:55 -0800129 .name = "PPI",
Colin Cross26d902c2011-02-09 22:17:17 -0800130 .irq_ack = tegra_ack,
Colin Cross3524b702010-11-28 22:23:55 -0800131 .irq_mask = tegra_mask,
132 .irq_unmask = tegra_unmask,
Colin Cross26d902c2011-02-09 22:17:17 -0800133 .irq_retrigger = tegra_retrigger,
Gary King460907b2010-04-05 20:30:59 -0700134};
135
Erik Gilling5ad36c52010-03-15 23:04:46 -0700136void __init tegra_init_irq(void)
137{
Gary King460907b2010-04-05 20:30:59 -0700138 struct irq_chip *gic;
139 unsigned int i;
Colin Cross3524b702010-11-28 22:23:55 -0800140 int irq;
Gary King460907b2010-04-05 20:30:59 -0700141
Colin Cross3524b702010-11-28 22:23:55 -0800142 tegra_init_legacy_irq();
Gary King460907b2010-04-05 20:30:59 -0700143
Russell Kingb580b892010-12-04 15:55:14 +0000144 gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
145 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
Gary King460907b2010-04-05 20:30:59 -0700146
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100147 gic = irq_get_chip(29);
Colin Crosscc939752010-11-28 20:14:53 -0800148 tegra_gic_unmask_irq = gic->irq_unmask;
149 tegra_gic_mask_irq = gic->irq_mask;
Colin Cross26d902c2011-02-09 22:17:17 -0800150 tegra_gic_ack_irq = gic->irq_ack;
Gary King460907b2010-04-05 20:30:59 -0700151#ifdef CONFIG_SMP
Lennert Buytenhek37337a82010-11-29 11:14:46 +0100152 tegra_irq.irq_set_affinity = gic->irq_set_affinity;
Gary King460907b2010-04-05 20:30:59 -0700153#endif
154
Colin Cross3524b702010-11-28 22:23:55 -0800155 for (i = 0; i < INT_MAIN_NR; i++) {
156 irq = INT_PRI_BASE + i;
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100157 irq_set_chip(irq, &tegra_irq);
158 irq_set_handler(irq, handle_level_irq);
Colin Cross3524b702010-11-28 22:23:55 -0800159 set_irq_flags(irq, IRQF_VALID);
Gary King460907b2010-04-05 20:30:59 -0700160 }
Erik Gilling5ad36c52010-03-15 23:04:46 -0700161}