2010-03-16 14:04:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Google, Inc.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Colin Cross <ccross@google.com>
|
|
|
|
*
|
2010-04-06 11:30:59 +08:00
|
|
|
* Copyright (C) 2010, NVIDIA Corporation
|
|
|
|
*
|
2010-03-16 14:04:46 +08:00
|
|
|
* 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>
|
2010-11-29 14:23:55 +08:00
|
|
|
#include <linux/delay.h>
|
2010-03-16 14:04:46 +08:00
|
|
|
#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>
|
2010-11-29 14:23:55 +08:00
|
|
|
#include <mach/legacy_irq.h>
|
2010-10-04 23:49:49 +08:00
|
|
|
#include <mach/suspend.h>
|
2010-03-16 14:04:46 +08:00
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
#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
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
static u32 tegra_lp0_wake_enb;
|
|
|
|
static u32 tegra_lp0_wake_level;
|
|
|
|
static u32 tegra_lp0_wake_level_any;
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 12:14:53 +08:00
|
|
|
static void (*tegra_gic_mask_irq)(struct irq_data *d);
|
|
|
|
static void (*tegra_gic_unmask_irq)(struct irq_data *d);
|
2011-02-10 14:17:17 +08:00
|
|
|
static void (*tegra_gic_ack_irq)(struct irq_data *d);
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
/* 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);
|
|
|
|
}
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
int tegra_set_lp1_wake(int irq, int enable)
|
2010-04-06 11:30:59 +08:00
|
|
|
{
|
2010-11-29 14:23:55 +08:00
|
|
|
return tegra_legacy_irq_set_wake(irq, enable);
|
2010-04-06 11:30:59 +08:00
|
|
|
}
|
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
void tegra_set_lp0_wake_pads(u32 wake_enb, u32 wake_level, u32 wake_any)
|
2010-04-06 11:30:59 +08:00
|
|
|
{
|
2010-11-29 14:23:55 +08:00
|
|
|
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);
|
2010-04-06 11:30:59 +08:00
|
|
|
}
|
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
static void tegra_mask(struct irq_data *d)
|
|
|
|
{
|
|
|
|
tegra_gic_mask_irq(d);
|
|
|
|
tegra_legacy_mask_irq(d->irq);
|
|
|
|
}
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
static void tegra_unmask(struct irq_data *d)
|
2010-04-06 11:30:59 +08:00
|
|
|
{
|
2010-11-29 14:23:55 +08:00
|
|
|
tegra_gic_unmask_irq(d);
|
|
|
|
tegra_legacy_unmask_irq(d->irq);
|
2010-04-06 11:30:59 +08:00
|
|
|
}
|
|
|
|
|
2011-02-10 14:17:17 +08:00
|
|
|
static void tegra_ack(struct irq_data *d)
|
|
|
|
{
|
|
|
|
tegra_legacy_force_irq_clr(d->irq);
|
|
|
|
tegra_gic_ack_irq(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tegra_retrigger(struct irq_data *d)
|
|
|
|
{
|
|
|
|
tegra_legacy_force_irq_set(d->irq);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-06 11:30:59 +08:00
|
|
|
static struct irq_chip tegra_irq = {
|
2010-11-29 14:23:55 +08:00
|
|
|
.name = "PPI",
|
2011-02-10 14:17:17 +08:00
|
|
|
.irq_ack = tegra_ack,
|
2010-11-29 14:23:55 +08:00
|
|
|
.irq_mask = tegra_mask,
|
|
|
|
.irq_unmask = tegra_unmask,
|
2011-02-10 14:17:17 +08:00
|
|
|
.irq_retrigger = tegra_retrigger,
|
2010-04-06 11:30:59 +08:00
|
|
|
};
|
|
|
|
|
2010-03-16 14:04:46 +08:00
|
|
|
void __init tegra_init_irq(void)
|
|
|
|
{
|
2010-04-06 11:30:59 +08:00
|
|
|
struct irq_chip *gic;
|
|
|
|
unsigned int i;
|
2010-11-29 14:23:55 +08:00
|
|
|
int irq;
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
tegra_init_legacy_irq();
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2010-12-04 23:55:14 +08:00
|
|
|
gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
|
|
|
|
IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
|
2010-04-06 11:30:59 +08:00
|
|
|
|
2011-03-24 20:25:22 +08:00
|
|
|
gic = irq_get_chip(29);
|
2010-11-29 12:14:53 +08:00
|
|
|
tegra_gic_unmask_irq = gic->irq_unmask;
|
|
|
|
tegra_gic_mask_irq = gic->irq_mask;
|
2011-02-10 14:17:17 +08:00
|
|
|
tegra_gic_ack_irq = gic->irq_ack;
|
2010-04-06 11:30:59 +08:00
|
|
|
#ifdef CONFIG_SMP
|
2010-11-29 18:14:46 +08:00
|
|
|
tegra_irq.irq_set_affinity = gic->irq_set_affinity;
|
2010-04-06 11:30:59 +08:00
|
|
|
#endif
|
|
|
|
|
2010-11-29 14:23:55 +08:00
|
|
|
for (i = 0; i < INT_MAIN_NR; i++) {
|
|
|
|
irq = INT_PRI_BASE + i;
|
2011-03-24 20:35:09 +08:00
|
|
|
irq_set_chip_and_handler(irq, &tegra_irq, handle_level_irq);
|
2010-11-29 14:23:55 +08:00
|
|
|
set_irq_flags(irq, IRQF_VALID);
|
2010-04-06 11:30:59 +08:00
|
|
|
}
|
|
|
|
}
|