blob: 567b75c4c67b83ef96c38426c84bef7397c760aa [file] [log] [blame]
Erik Gilling5ad36c52010-03-15 23:04:46 -07001/*
Colin Cross938fa342011-05-01 14:10:10 -07002 * Copyright (C) 2011 Google, Inc.
Erik Gilling5ad36c52010-03-15 23:04:46 -07003 *
4 * Author:
Colin Cross938fa342011-05-01 14:10:10 -07005 * Colin Cross <ccross@android.com>
Erik Gilling5ad36c52010-03-15 23:04:46 -07006 *
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 Cross3524b702010-11-28 22:23:55 -080049/* ensures that sufficient time is passed for a register write to
50 * serialize into the 32KHz domain */
51static void pmc_32kwritel(u32 val, unsigned long offs)
52{
53 writel(val, pmc + offs);
54 udelay(130);
55}
56
57int tegra_set_lp1_wake(int irq, int enable)
58{
59 return tegra_legacy_irq_set_wake(irq, enable);
60}
61
62void tegra_set_lp0_wake_pads(u32 wake_enb, u32 wake_level, u32 wake_any)
63{
64 u32 temp;
65 u32 status;
66 u32 lvl;
67
68 wake_level &= wake_enb;
69 wake_any &= wake_enb;
70
71 wake_level |= (tegra_lp0_wake_level & tegra_lp0_wake_enb);
72 wake_any |= (tegra_lp0_wake_level_any & tegra_lp0_wake_enb);
73
74 wake_enb |= tegra_lp0_wake_enb;
75
76 pmc_32kwritel(0, PMC_SW_WAKE_STATUS);
77 temp = readl(pmc + PMC_CTRL);
78 temp |= PMC_CTRL_LATCH_WAKEUPS;
79 pmc_32kwritel(temp, PMC_CTRL);
80 temp &= ~PMC_CTRL_LATCH_WAKEUPS;
81 pmc_32kwritel(temp, PMC_CTRL);
82 status = readl(pmc + PMC_SW_WAKE_STATUS);
83 lvl = readl(pmc + PMC_WAKE_LEVEL);
84
85 /* flip the wakeup trigger for any-edge triggered pads
86 * which are currently asserting as wakeups */
87 lvl ^= status;
88 lvl &= wake_any;
89
90 wake_level |= lvl;
91
92 writel(wake_level, pmc + PMC_WAKE_LEVEL);
93 /* Enable DPD sample to trigger sampling pads data and direction
94 * in which pad will be driven during lp0 mode*/
95 writel(0x1, pmc + PMC_DPD_SAMPLE);
96
97 writel(wake_enb, pmc + PMC_WAKE_MASK);
98}
Gary King460907b2010-04-05 20:30:59 -070099
Lennert Buytenhek37337a82010-11-29 11:14:46 +0100100static void tegra_mask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -0700101{
Colin Cross938fa342011-05-01 14:10:10 -0700102 if (d->irq >= 32)
103 tegra_legacy_mask_irq(d->irq);
Gary King460907b2010-04-05 20:30:59 -0700104}
105
Lennert Buytenhek37337a82010-11-29 11:14:46 +0100106static void tegra_unmask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -0700107{
Colin Cross938fa342011-05-01 14:10:10 -0700108 if (d->irq >= 32)
109 tegra_legacy_unmask_irq(d->irq);
Gary King460907b2010-04-05 20:30:59 -0700110}
111
Colin Cross26d902c2011-02-09 22:17:17 -0800112static void tegra_ack(struct irq_data *d)
113{
Colin Cross938fa342011-05-01 14:10:10 -0700114 if (d->irq >= 32)
115 tegra_legacy_force_irq_clr(d->irq);
Colin Cross26d902c2011-02-09 22:17:17 -0800116}
117
118static int tegra_retrigger(struct irq_data *d)
119{
Colin Cross938fa342011-05-01 14:10:10 -0700120 if (d->irq < 32)
121 return 0;
122
Colin Cross26d902c2011-02-09 22:17:17 -0800123 tegra_legacy_force_irq_set(d->irq);
124 return 1;
125}
126
Erik Gilling5ad36c52010-03-15 23:04:46 -0700127void __init tegra_init_irq(void)
128{
Colin Cross3524b702010-11-28 22:23:55 -0800129 tegra_init_legacy_irq();
Gary King460907b2010-04-05 20:30:59 -0700130
Colin Cross938fa342011-05-01 14:10:10 -0700131 gic_arch_extn.irq_ack = tegra_ack;
132 gic_arch_extn.irq_mask = tegra_mask;
133 gic_arch_extn.irq_unmask = tegra_unmask;
134 gic_arch_extn.irq_retrigger = tegra_retrigger;
135
Russell Kingb580b892010-12-04 15:55:14 +0000136 gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
137 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
Erik Gilling5ad36c52010-03-15 23:04:46 -0700138}