pmc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/io.h>
  19. #include <linux/of.h>
  20. #include "iomap.h"
  21. #define PMC_CTRL 0x0
  22. #define PMC_CTRL_INTR_LOW (1 << 17)
  23. static inline u32 tegra_pmc_readl(u32 reg)
  24. {
  25. return readl(IO_ADDRESS(TEGRA_PMC_BASE + reg));
  26. }
  27. static inline void tegra_pmc_writel(u32 val, u32 reg)
  28. {
  29. writel(val, IO_ADDRESS(TEGRA_PMC_BASE + reg));
  30. }
  31. #ifdef CONFIG_OF
  32. static const struct of_device_id matches[] __initconst = {
  33. { .compatible = "nvidia,tegra114-pmc" },
  34. { .compatible = "nvidia,tegra30-pmc" },
  35. { .compatible = "nvidia,tegra20-pmc" },
  36. { }
  37. };
  38. #endif
  39. void __init tegra_pmc_init(void)
  40. {
  41. /*
  42. * For now, Harmony is the only board that uses the PMC, and it wants
  43. * the signal inverted. Seaboard would too if it used the PMC.
  44. * Hopefully by the time other boards want to use the PMC, everything
  45. * will be device-tree, or they also want it inverted.
  46. */
  47. bool invert_interrupt = true;
  48. u32 val;
  49. #ifdef CONFIG_OF
  50. if (of_have_populated_dt()) {
  51. struct device_node *np;
  52. invert_interrupt = false;
  53. np = of_find_matching_node(NULL, matches);
  54. if (np) {
  55. if (of_find_property(np, "nvidia,invert-interrupt",
  56. NULL))
  57. invert_interrupt = true;
  58. }
  59. }
  60. #endif
  61. val = tegra_pmc_readl(PMC_CTRL);
  62. if (invert_interrupt)
  63. val |= PMC_CTRL_INTR_LOW;
  64. else
  65. val &= ~PMC_CTRL_INTR_LOW;
  66. tegra_pmc_writel(val, PMC_CTRL);
  67. }