clk-tegra-audio.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/delay.h>
  21. #include <linux/export.h>
  22. #include <linux/clk/tegra.h>
  23. #include "clk.h"
  24. #include "clk-id.h"
  25. #define AUDIO_SYNC_CLK_I2S0 0x4a0
  26. #define AUDIO_SYNC_CLK_I2S1 0x4a4
  27. #define AUDIO_SYNC_CLK_I2S2 0x4a8
  28. #define AUDIO_SYNC_CLK_I2S3 0x4ac
  29. #define AUDIO_SYNC_CLK_I2S4 0x4b0
  30. #define AUDIO_SYNC_CLK_SPDIF 0x4b4
  31. #define AUDIO_SYNC_DOUBLER 0x49c
  32. #define PLLA_OUT 0xb4
  33. struct tegra_sync_source_initdata {
  34. char *name;
  35. unsigned long rate;
  36. unsigned long max_rate;
  37. int clk_id;
  38. };
  39. #define SYNC(_name) \
  40. {\
  41. .name = #_name,\
  42. .rate = 24000000,\
  43. .max_rate = 24000000,\
  44. .clk_id = tegra_clk_ ## _name,\
  45. }
  46. struct tegra_audio_clk_initdata {
  47. char *gate_name;
  48. char *mux_name;
  49. u32 offset;
  50. int gate_clk_id;
  51. int mux_clk_id;
  52. };
  53. #define AUDIO(_name, _offset) \
  54. {\
  55. .gate_name = #_name,\
  56. .mux_name = #_name"_mux",\
  57. .offset = _offset,\
  58. .gate_clk_id = tegra_clk_ ## _name,\
  59. .mux_clk_id = tegra_clk_ ## _name ## _mux,\
  60. }
  61. struct tegra_audio2x_clk_initdata {
  62. char *parent;
  63. char *gate_name;
  64. char *name_2x;
  65. char *div_name;
  66. int clk_id;
  67. int clk_num;
  68. u8 div_offset;
  69. };
  70. #define AUDIO2X(_name, _num, _offset) \
  71. {\
  72. .parent = #_name,\
  73. .gate_name = #_name"_2x",\
  74. .name_2x = #_name"_doubler",\
  75. .div_name = #_name"_div",\
  76. .clk_id = tegra_clk_ ## _name ## _2x,\
  77. .clk_num = _num,\
  78. .div_offset = _offset,\
  79. }
  80. static DEFINE_SPINLOCK(clk_doubler_lock);
  81. static const char *mux_audio_sync_clk[] = { "spdif_in_sync", "i2s0_sync",
  82. "i2s1_sync", "i2s2_sync", "i2s3_sync", "i2s4_sync", "vimclk_sync",
  83. };
  84. static struct tegra_sync_source_initdata sync_source_clks[] __initdata = {
  85. SYNC(spdif_in_sync),
  86. SYNC(i2s0_sync),
  87. SYNC(i2s1_sync),
  88. SYNC(i2s2_sync),
  89. SYNC(i2s3_sync),
  90. SYNC(i2s4_sync),
  91. SYNC(vimclk_sync),
  92. };
  93. static struct tegra_audio_clk_initdata audio_clks[] = {
  94. AUDIO(audio0, AUDIO_SYNC_CLK_I2S0),
  95. AUDIO(audio1, AUDIO_SYNC_CLK_I2S1),
  96. AUDIO(audio2, AUDIO_SYNC_CLK_I2S2),
  97. AUDIO(audio3, AUDIO_SYNC_CLK_I2S3),
  98. AUDIO(audio4, AUDIO_SYNC_CLK_I2S4),
  99. AUDIO(spdif, AUDIO_SYNC_CLK_SPDIF),
  100. };
  101. static struct tegra_audio2x_clk_initdata audio2x_clks[] = {
  102. AUDIO2X(audio0, 113, 24),
  103. AUDIO2X(audio1, 114, 25),
  104. AUDIO2X(audio2, 115, 26),
  105. AUDIO2X(audio3, 116, 27),
  106. AUDIO2X(audio4, 117, 28),
  107. AUDIO2X(spdif, 118, 29),
  108. };
  109. void __init tegra_audio_clk_init(void __iomem *clk_base,
  110. void __iomem *pmc_base, struct tegra_clk *tegra_clks,
  111. struct tegra_audio_clk_info *audio_info,
  112. unsigned int num_plls)
  113. {
  114. struct clk *clk;
  115. struct clk **dt_clk;
  116. int i;
  117. if (!audio_info || num_plls < 1) {
  118. pr_err("No audio data passed to tegra_audio_clk_init\n");
  119. WARN_ON(1);
  120. return;
  121. }
  122. for (i = 0; i < num_plls; i++) {
  123. struct tegra_audio_clk_info *info = &audio_info[i];
  124. dt_clk = tegra_lookup_dt_id(info->clk_id, tegra_clks);
  125. if (dt_clk) {
  126. clk = tegra_clk_register_pll(info->name, info->parent,
  127. clk_base, pmc_base, 0, info->pll_params,
  128. NULL);
  129. *dt_clk = clk;
  130. }
  131. }
  132. /* PLLA_OUT0 */
  133. dt_clk = tegra_lookup_dt_id(tegra_clk_pll_a_out0, tegra_clks);
  134. if (dt_clk) {
  135. clk = tegra_clk_register_divider("pll_a_out0_div", "pll_a",
  136. clk_base + PLLA_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  137. 8, 8, 1, NULL);
  138. clk = tegra_clk_register_pll_out("pll_a_out0", "pll_a_out0_div",
  139. clk_base + PLLA_OUT, 1, 0, CLK_IGNORE_UNUSED |
  140. CLK_SET_RATE_PARENT, 0, NULL);
  141. *dt_clk = clk;
  142. }
  143. for (i = 0; i < ARRAY_SIZE(sync_source_clks); i++) {
  144. struct tegra_sync_source_initdata *data;
  145. data = &sync_source_clks[i];
  146. dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks);
  147. if (!dt_clk)
  148. continue;
  149. clk = tegra_clk_register_sync_source(data->name,
  150. data->rate, data->max_rate);
  151. *dt_clk = clk;
  152. }
  153. for (i = 0; i < ARRAY_SIZE(audio_clks); i++) {
  154. struct tegra_audio_clk_initdata *data;
  155. data = &audio_clks[i];
  156. dt_clk = tegra_lookup_dt_id(data->mux_clk_id, tegra_clks);
  157. if (!dt_clk)
  158. continue;
  159. clk = clk_register_mux(NULL, data->mux_name, mux_audio_sync_clk,
  160. ARRAY_SIZE(mux_audio_sync_clk),
  161. CLK_SET_RATE_NO_REPARENT,
  162. clk_base + data->offset, 0, 3, 0,
  163. NULL);
  164. *dt_clk = clk;
  165. dt_clk = tegra_lookup_dt_id(data->gate_clk_id, tegra_clks);
  166. if (!dt_clk)
  167. continue;
  168. clk = clk_register_gate(NULL, data->gate_name, data->mux_name,
  169. 0, clk_base + data->offset, 4,
  170. CLK_GATE_SET_TO_DISABLE, NULL);
  171. *dt_clk = clk;
  172. }
  173. for (i = 0; i < ARRAY_SIZE(audio2x_clks); i++) {
  174. struct tegra_audio2x_clk_initdata *data;
  175. data = &audio2x_clks[i];
  176. dt_clk = tegra_lookup_dt_id(data->clk_id, tegra_clks);
  177. if (!dt_clk)
  178. continue;
  179. clk = clk_register_fixed_factor(NULL, data->name_2x,
  180. data->parent, CLK_SET_RATE_PARENT, 2, 1);
  181. clk = tegra_clk_register_divider(data->div_name,
  182. data->name_2x, clk_base + AUDIO_SYNC_DOUBLER,
  183. 0, 0, data->div_offset, 1, 0,
  184. &clk_doubler_lock);
  185. clk = tegra_clk_register_periph_gate(data->gate_name,
  186. data->div_name, TEGRA_PERIPH_NO_RESET,
  187. clk_base, CLK_SET_RATE_PARENT, data->clk_num,
  188. periph_clk_enb_refcnt);
  189. *dt_clk = clk;
  190. }
  191. }