clk-tegra-pmc.c 3.4 KB

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