Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 1 | /* |
Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 Google, Inc. |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 3 | * |
| 4 | * Author: |
Colin Cross | 938fa34 | 2011-05-01 14:10:10 -0700 | [diff] [blame] | 5 | * Colin Cross <ccross@android.com> |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 6 | * |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 7 | * Copyright (C) 2010,2013, NVIDIA Corporation |
Gary King | 460907b | 2010-04-05 20:30:59 -0700 | [diff] [blame] | 8 | * |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 9 | * 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 | |
Joseph Lo | 7e8b15d | 2013-07-19 17:25:24 +0800 | [diff] [blame] | 20 | #include <linux/cpu_pm.h> |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 22 | #include <linux/io.h> |
Rob Herring | 520f7bd | 2012-12-27 13:10:24 -0600 | [diff] [blame] | 23 | #include <linux/irqchip/arm-gic.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 24 | #include <linux/irq.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/of_address.h> |
| 27 | #include <linux/of.h> |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 28 | #include <linux/syscore_ops.h> |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 29 | |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 30 | #include "board.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 31 | #include "iomap.h" |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 32 | |
Joseph Lo | d4b92fb | 2013-01-15 22:10:26 +0000 | [diff] [blame] | 33 | #define SGI_MASK 0xFFFF |
| 34 | |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 35 | #ifdef CONFIG_PM_SLEEP |
Joseph Lo | 7e8b15d | 2013-07-19 17:25:24 +0800 | [diff] [blame] | 36 | static void __iomem *tegra_gic_cpu_base; |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 37 | #endif |
| 38 | |
Joseph Lo | d4b92fb | 2013-01-15 22:10:26 +0000 | [diff] [blame] | 39 | bool tegra_pending_sgi(void) |
| 40 | { |
| 41 | u32 pending_set; |
| 42 | void __iomem *distbase = IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE); |
| 43 | |
| 44 | pending_set = readl_relaxed(distbase + GIC_DIST_PENDING_SET); |
| 45 | |
| 46 | if (pending_set & SGI_MASK) |
| 47 | return true; |
| 48 | |
| 49 | return false; |
| 50 | } |
| 51 | |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 52 | #ifdef CONFIG_PM_SLEEP |
Joseph Lo | 7e8b15d | 2013-07-19 17:25:24 +0800 | [diff] [blame] | 53 | static int tegra_gic_notifier(struct notifier_block *self, |
| 54 | unsigned long cmd, void *v) |
| 55 | { |
| 56 | switch (cmd) { |
| 57 | case CPU_PM_ENTER: |
| 58 | writel_relaxed(0x1E0, tegra_gic_cpu_base + GIC_CPU_CTRL); |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | return NOTIFY_OK; |
| 63 | } |
| 64 | |
| 65 | static struct notifier_block tegra_gic_notifier_block = { |
| 66 | .notifier_call = tegra_gic_notifier, |
| 67 | }; |
| 68 | |
| 69 | static const struct of_device_id tegra114_dt_gic_match[] __initconst = { |
| 70 | { .compatible = "arm,cortex-a15-gic" }, |
| 71 | { } |
| 72 | }; |
| 73 | |
| 74 | static void tegra114_gic_cpu_pm_registration(void) |
| 75 | { |
| 76 | struct device_node *dn; |
| 77 | |
| 78 | dn = of_find_matching_node(NULL, tegra114_dt_gic_match); |
| 79 | if (!dn) |
| 80 | return; |
| 81 | |
| 82 | tegra_gic_cpu_base = of_iomap(dn, 1); |
| 83 | |
| 84 | cpu_pm_register_notifier(&tegra_gic_notifier_block); |
| 85 | } |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 86 | #else |
Joseph Lo | 7e8b15d | 2013-07-19 17:25:24 +0800 | [diff] [blame] | 87 | static void tegra114_gic_cpu_pm_registration(void) { } |
Joseph Lo | e307cc8 | 2013-04-03 19:31:45 +0800 | [diff] [blame] | 88 | #endif |
| 89 | |
Marc Zyngier | e9479e0 | 2015-03-11 15:43:00 +0000 | [diff] [blame] | 90 | static const struct of_device_id tegra_ictlr_match[] __initconst = { |
| 91 | { .compatible = "nvidia,tegra20-ictlr" }, |
| 92 | { .compatible = "nvidia,tegra30-ictlr" }, |
| 93 | { } |
| 94 | }; |
| 95 | |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 96 | void __init tegra_init_irq(void) |
| 97 | { |
Marc Zyngier | 1a703bf | 2015-03-11 15:43:03 +0000 | [diff] [blame] | 98 | if (WARN_ON(!of_find_matching_node(NULL, tegra_ictlr_match))) |
| 99 | pr_warn("Outdated DT detected, suspend/resume will NOT work\n"); |
Colin Cross | d1d8c66 | 2011-05-01 15:26:51 -0700 | [diff] [blame] | 100 | |
Joseph Lo | 7e8b15d | 2013-07-19 17:25:24 +0800 | [diff] [blame] | 101 | tegra114_gic_cpu_pm_registration(); |
Erik Gilling | 5ad36c5 | 2010-03-15 23:04:46 -0700 | [diff] [blame] | 102 | } |