pmc.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <mach/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,tegra20-pmc" },
  34. { }
  35. };
  36. #endif
  37. void __init tegra_pmc_init(void)
  38. {
  39. /*
  40. * For now, Harmony is the only board that uses the PMC, and it wants
  41. * the signal inverted. Seaboard would too if it used the PMC.
  42. * Hopefully by the time other boards want to use the PMC, everything
  43. * will be device-tree, or they also want it inverted.
  44. */
  45. bool invert_interrupt = true;
  46. u32 val;
  47. #ifdef CONFIG_OF
  48. if (of_have_populated_dt()) {
  49. struct device_node *np;
  50. invert_interrupt = false;
  51. np = of_find_matching_node(NULL, matches);
  52. if (np) {
  53. if (of_find_property(np, "nvidia,invert-interrupt",
  54. NULL))
  55. invert_interrupt = true;
  56. }
  57. }
  58. #endif
  59. val = tegra_pmc_readl(PMC_CTRL);
  60. if (invert_interrupt)
  61. val |= PMC_CTRL_INTR_LOW;
  62. else
  63. val &= ~PMC_CTRL_INTR_LOW;
  64. tegra_pmc_writel(val, PMC_CTRL);
  65. }