irq.c 3.5 KB
Newer Older
E
Erik Gilling 已提交
1 2 3 4 5 6
/*
 * Copyright (C) 2010 Google, Inc.
 *
 * Author:
 *	Colin Cross <ccross@google.com>
 *
7 8
 * Copyright (C) 2010, NVIDIA Corporation
 *
E
Erik Gilling 已提交
9 10 11 12 13 14 15 16 17 18 19 20
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/kernel.h>
21
#include <linux/delay.h>
E
Erik Gilling 已提交
22 23 24 25 26 27 28 29
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>

#include <asm/hardware/gic.h>

#include <mach/iomap.h>
30
#include <mach/legacy_irq.h>
31
#include <mach/suspend.h>
E
Erik Gilling 已提交
32 33 34

#include "board.h"

35 36 37 38 39 40 41
#define PMC_CTRL		0x0
#define PMC_CTRL_LATCH_WAKEUPS	(1 << 5)
#define PMC_WAKE_MASK		0xc
#define PMC_WAKE_LEVEL		0x10
#define PMC_WAKE_STATUS		0x14
#define PMC_SW_WAKE_STATUS	0x18
#define PMC_DPD_SAMPLE		0x20
42

43
static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
44

45 46 47
static u32 tegra_lp0_wake_enb;
static u32 tegra_lp0_wake_level;
static u32 tegra_lp0_wake_level_any;
48

49 50
static void (*tegra_gic_mask_irq)(struct irq_data *d);
static void (*tegra_gic_unmask_irq)(struct irq_data *d);
51

52 53 54 55 56 57 58
/* ensures that sufficient time is passed for a register write to
 * serialize into the 32KHz domain */
static void pmc_32kwritel(u32 val, unsigned long offs)
{
	writel(val, pmc + offs);
	udelay(130);
}
59

60
int tegra_set_lp1_wake(int irq, int enable)
61
{
62
	return tegra_legacy_irq_set_wake(irq, enable);
63 64
}

65
void tegra_set_lp0_wake_pads(u32 wake_enb, u32 wake_level, u32 wake_any)
66
{
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	u32 temp;
	u32 status;
	u32 lvl;

	wake_level &= wake_enb;
	wake_any &= wake_enb;

	wake_level |= (tegra_lp0_wake_level & tegra_lp0_wake_enb);
	wake_any |= (tegra_lp0_wake_level_any & tegra_lp0_wake_enb);

	wake_enb |= tegra_lp0_wake_enb;

	pmc_32kwritel(0, PMC_SW_WAKE_STATUS);
	temp = readl(pmc + PMC_CTRL);
	temp |= PMC_CTRL_LATCH_WAKEUPS;
	pmc_32kwritel(temp, PMC_CTRL);
	temp &= ~PMC_CTRL_LATCH_WAKEUPS;
	pmc_32kwritel(temp, PMC_CTRL);
	status = readl(pmc + PMC_SW_WAKE_STATUS);
	lvl = readl(pmc + PMC_WAKE_LEVEL);

	/* flip the wakeup trigger for any-edge triggered pads
	 * which are currently asserting as wakeups */
	lvl ^= status;
	lvl &= wake_any;

	wake_level |= lvl;

	writel(wake_level, pmc + PMC_WAKE_LEVEL);
	/* Enable DPD sample to trigger sampling pads data and direction
	 * in which pad will be driven during lp0 mode*/
	writel(0x1, pmc + PMC_DPD_SAMPLE);

	writel(wake_enb, pmc + PMC_WAKE_MASK);
101 102
}

103 104 105 106 107
static void tegra_mask(struct irq_data *d)
{
	tegra_gic_mask_irq(d);
	tegra_legacy_mask_irq(d->irq);
}
108

109
static void tegra_unmask(struct irq_data *d)
110
{
111 112
	tegra_gic_unmask_irq(d);
	tegra_legacy_unmask_irq(d->irq);
113 114 115
}

static struct irq_chip tegra_irq = {
116 117 118
	.name			= "PPI",
	.irq_mask		= tegra_mask,
	.irq_unmask		= tegra_unmask,
119 120
};

E
Erik Gilling 已提交
121 122
void __init tegra_init_irq(void)
{
123 124
	struct irq_chip *gic;
	unsigned int i;
125
	int irq;
126

127
	tegra_init_legacy_irq();
128

129 130
	gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
		 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
131 132

	gic = get_irq_chip(29);
133 134
	tegra_gic_unmask_irq = gic->irq_unmask;
	tegra_gic_mask_irq = gic->irq_mask;
135
	tegra_irq.irq_ack = gic->irq_ack;
136
#ifdef CONFIG_SMP
137
	tegra_irq.irq_set_affinity = gic->irq_set_affinity;
138 139
#endif

140 141 142 143 144
	for (i = 0; i < INT_MAIN_NR; i++) {
		irq = INT_PRI_BASE + i;
		set_irq_chip(irq, &tegra_irq);
		set_irq_handler(irq, handle_level_irq);
		set_irq_flags(irq, IRQF_VALID);
145 146
	}
}