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