clk-tegra-pmc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include <linux/io.h>
  17. #include <linux/clk.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/clkdev.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/delay.h>
  23. #include <linux/export.h>
  24. #include <linux/clk/tegra.h>
  25. #include "clk.h"
  26. #include "clk-id.h"
  27. #define PMC_CLK_OUT_CNTRL 0x1a8
  28. #define PMC_DPD_PADS_ORIDE 0x1c
  29. #define PMC_DPD_PADS_ORIDE_BLINK_ENB 20
  30. #define PMC_CTRL 0
  31. #define PMC_CTRL_BLINK_ENB 7
  32. #define PMC_BLINK_TIMER 0x40
  33. struct pmc_clk_init_data {
  34. char *mux_name;
  35. char *gate_name;
  36. const char **parents;
  37. int num_parents;
  38. int mux_id;
  39. int gate_id;
  40. char *dev_name;
  41. u8 mux_shift;
  42. u8 gate_shift;
  43. };
  44. #define PMC_CLK(_num, _mux_shift, _gate_shift)\
  45. {\
  46. .mux_name = "clk_out_" #_num "_mux",\
  47. .gate_name = "clk_out_" #_num,\
  48. .parents = clk_out ##_num ##_parents,\
  49. .num_parents = ARRAY_SIZE(clk_out ##_num ##_parents),\
  50. .mux_id = tegra_clk_clk_out_ ##_num ##_mux,\
  51. .gate_id = tegra_clk_clk_out_ ##_num,\
  52. .dev_name = "extern" #_num,\
  53. .mux_shift = _mux_shift,\
  54. .gate_shift = _gate_shift,\
  55. }
  56. static DEFINE_SPINLOCK(clk_out_lock);
  57. static const char *clk_out1_parents[] = { "clk_m", "clk_m_div2",
  58. "clk_m_div4", "extern1",
  59. };
  60. static const char *clk_out2_parents[] = { "clk_m", "clk_m_div2",
  61. "clk_m_div4", "extern2",
  62. };
  63. static const char *clk_out3_parents[] = { "clk_m", "clk_m_div2",
  64. "clk_m_div4", "extern3",
  65. };
  66. static struct pmc_clk_init_data pmc_clks[] = {
  67. PMC_CLK(1, 6, 2),
  68. PMC_CLK(2, 14, 10),
  69. PMC_CLK(3, 22, 18),
  70. };
  71. void __init tegra_pmc_clk_init(void __iomem *pmc_base,
  72. struct tegra_clk *tegra_clks)
  73. {
  74. struct clk *clk;
  75. struct clk **dt_clk;
  76. int i;
  77. for (i = 0; i < ARRAY_SIZE(pmc_clks); i++) {
  78. struct pmc_clk_init_data *data;
  79. data = pmc_clks + i;
  80. dt_clk = tegra_lookup_dt_id(data->mux_id, tegra_clks);
  81. if (!dt_clk)
  82. continue;
  83. clk = clk_register_mux(NULL, data->mux_name, data->parents,
  84. data->num_parents, CLK_SET_RATE_NO_REPARENT,
  85. pmc_base + PMC_CLK_OUT_CNTRL, data->mux_shift,
  86. 3, 0, &clk_out_lock);
  87. *dt_clk = clk;
  88. dt_clk = tegra_lookup_dt_id(data->gate_id, tegra_clks);
  89. if (!dt_clk)
  90. continue;
  91. clk = clk_register_gate(NULL, data->gate_name, data->mux_name,
  92. 0, pmc_base + PMC_CLK_OUT_CNTRL,
  93. data->gate_shift, 0, &clk_out_lock);
  94. *dt_clk = clk;
  95. clk_register_clkdev(clk, data->dev_name, data->gate_name);
  96. }
  97. /* blink */
  98. writel_relaxed(0, pmc_base + PMC_BLINK_TIMER);
  99. clk = clk_register_gate(NULL, "blink_override", "clk_32k", 0,
  100. pmc_base + PMC_DPD_PADS_ORIDE,
  101. PMC_DPD_PADS_ORIDE_BLINK_ENB, 0, NULL);
  102. dt_clk = tegra_lookup_dt_id(tegra_clk_blink, tegra_clks);
  103. if (!dt_clk)
  104. return;
  105. clk = clk_register_gate(NULL, "blink", "blink_override", 0,
  106. pmc_base + PMC_CTRL,
  107. PMC_CTRL_BLINK_ENB, 0, NULL);
  108. clk_register_clkdev(clk, "blink", NULL);
  109. *dt_clk = clk;
  110. }