pmc.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2012,2013 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 <linux/of_address.h>
  21. #define PMC_CTRL 0x0
  22. #define PMC_CTRL_INTR_LOW (1 << 17)
  23. static void __iomem *tegra_pmc_base;
  24. static bool tegra_pmc_invert_interrupt;
  25. static inline u32 tegra_pmc_readl(u32 reg)
  26. {
  27. return readl(tegra_pmc_base + reg);
  28. }
  29. static inline void tegra_pmc_writel(u32 val, u32 reg)
  30. {
  31. writel(val, tegra_pmc_base + reg);
  32. }
  33. static const struct of_device_id matches[] __initconst = {
  34. { .compatible = "nvidia,tegra114-pmc" },
  35. { .compatible = "nvidia,tegra30-pmc" },
  36. { .compatible = "nvidia,tegra20-pmc" },
  37. { }
  38. };
  39. static void tegra_pmc_parse_dt(void)
  40. {
  41. struct device_node *np;
  42. np = of_find_matching_node(NULL, matches);
  43. BUG_ON(!np);
  44. tegra_pmc_base = of_iomap(np, 0);
  45. tegra_pmc_invert_interrupt = of_property_read_bool(np,
  46. "nvidia,invert-interrupt");
  47. }
  48. void __init tegra_pmc_init(void)
  49. {
  50. u32 val;
  51. tegra_pmc_parse_dt();
  52. val = tegra_pmc_readl(PMC_CTRL);
  53. if (tegra_pmc_invert_interrupt)
  54. val |= PMC_CTRL_INTR_LOW;
  55. else
  56. val &= ~PMC_CTRL_INTR_LOW;
  57. tegra_pmc_writel(val, PMC_CTRL);
  58. }