clk-mt7622-aud.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2017 MediaTek Inc.
  3. * Author: Chen Zhong <chen.zhong@mediatek.com>
  4. * Sean Wang <sean.wang@mediatek.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/clk-provider.h>
  16. #include <linux/of.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_device.h>
  19. #include <linux/platform_device.h>
  20. #include "clk-mtk.h"
  21. #include "clk-gate.h"
  22. #include <dt-bindings/clock/mt7622-clk.h>
  23. #define GATE_AUDIO0(_id, _name, _parent, _shift) { \
  24. .id = _id, \
  25. .name = _name, \
  26. .parent_name = _parent, \
  27. .regs = &audio0_cg_regs, \
  28. .shift = _shift, \
  29. .ops = &mtk_clk_gate_ops_no_setclr, \
  30. }
  31. #define GATE_AUDIO1(_id, _name, _parent, _shift) { \
  32. .id = _id, \
  33. .name = _name, \
  34. .parent_name = _parent, \
  35. .regs = &audio1_cg_regs, \
  36. .shift = _shift, \
  37. .ops = &mtk_clk_gate_ops_no_setclr, \
  38. }
  39. #define GATE_AUDIO2(_id, _name, _parent, _shift) { \
  40. .id = _id, \
  41. .name = _name, \
  42. .parent_name = _parent, \
  43. .regs = &audio2_cg_regs, \
  44. .shift = _shift, \
  45. .ops = &mtk_clk_gate_ops_no_setclr, \
  46. }
  47. #define GATE_AUDIO3(_id, _name, _parent, _shift) { \
  48. .id = _id, \
  49. .name = _name, \
  50. .parent_name = _parent, \
  51. .regs = &audio3_cg_regs, \
  52. .shift = _shift, \
  53. .ops = &mtk_clk_gate_ops_no_setclr, \
  54. }
  55. static const struct mtk_gate_regs audio0_cg_regs = {
  56. .set_ofs = 0x0,
  57. .clr_ofs = 0x0,
  58. .sta_ofs = 0x0,
  59. };
  60. static const struct mtk_gate_regs audio1_cg_regs = {
  61. .set_ofs = 0x10,
  62. .clr_ofs = 0x10,
  63. .sta_ofs = 0x10,
  64. };
  65. static const struct mtk_gate_regs audio2_cg_regs = {
  66. .set_ofs = 0x14,
  67. .clr_ofs = 0x14,
  68. .sta_ofs = 0x14,
  69. };
  70. static const struct mtk_gate_regs audio3_cg_regs = {
  71. .set_ofs = 0x634,
  72. .clr_ofs = 0x634,
  73. .sta_ofs = 0x634,
  74. };
  75. static const struct mtk_gate audio_clks[] = {
  76. /* AUDIO0 */
  77. GATE_AUDIO0(CLK_AUDIO_AFE, "audio_afe", "rtc", 2),
  78. GATE_AUDIO0(CLK_AUDIO_HDMI, "audio_hdmi", "apll1_ck_sel", 20),
  79. GATE_AUDIO0(CLK_AUDIO_SPDF, "audio_spdf", "apll1_ck_sel", 21),
  80. GATE_AUDIO0(CLK_AUDIO_APLL, "audio_apll", "apll1_ck_sel", 23),
  81. /* AUDIO1 */
  82. GATE_AUDIO1(CLK_AUDIO_I2SIN1, "audio_i2sin1", "a1sys_hp_sel", 0),
  83. GATE_AUDIO1(CLK_AUDIO_I2SIN2, "audio_i2sin2", "a1sys_hp_sel", 1),
  84. GATE_AUDIO1(CLK_AUDIO_I2SIN3, "audio_i2sin3", "a1sys_hp_sel", 2),
  85. GATE_AUDIO1(CLK_AUDIO_I2SIN4, "audio_i2sin4", "a1sys_hp_sel", 3),
  86. GATE_AUDIO1(CLK_AUDIO_I2SO1, "audio_i2so1", "a1sys_hp_sel", 6),
  87. GATE_AUDIO1(CLK_AUDIO_I2SO2, "audio_i2so2", "a1sys_hp_sel", 7),
  88. GATE_AUDIO1(CLK_AUDIO_I2SO3, "audio_i2so3", "a1sys_hp_sel", 8),
  89. GATE_AUDIO1(CLK_AUDIO_I2SO4, "audio_i2so4", "a1sys_hp_sel", 9),
  90. GATE_AUDIO1(CLK_AUDIO_ASRCI1, "audio_asrci1", "asm_h_sel", 12),
  91. GATE_AUDIO1(CLK_AUDIO_ASRCI2, "audio_asrci2", "asm_h_sel", 13),
  92. GATE_AUDIO1(CLK_AUDIO_ASRCO1, "audio_asrco1", "asm_h_sel", 14),
  93. GATE_AUDIO1(CLK_AUDIO_ASRCO2, "audio_asrco2", "asm_h_sel", 15),
  94. GATE_AUDIO1(CLK_AUDIO_INTDIR, "audio_intdir", "intdir_sel", 20),
  95. GATE_AUDIO1(CLK_AUDIO_A1SYS, "audio_a1sys", "a1sys_hp_sel", 21),
  96. GATE_AUDIO1(CLK_AUDIO_A2SYS, "audio_a2sys", "a2sys_hp_sel", 22),
  97. GATE_AUDIO1(CLK_AUDIO_AFE_CONN, "audio_afe_conn", "a1sys_hp_sel", 23),
  98. /* AUDIO2 */
  99. GATE_AUDIO2(CLK_AUDIO_UL1, "audio_ul1", "a1sys_hp_sel", 0),
  100. GATE_AUDIO2(CLK_AUDIO_UL2, "audio_ul2", "a1sys_hp_sel", 1),
  101. GATE_AUDIO2(CLK_AUDIO_UL3, "audio_ul3", "a1sys_hp_sel", 2),
  102. GATE_AUDIO2(CLK_AUDIO_UL4, "audio_ul4", "a1sys_hp_sel", 3),
  103. GATE_AUDIO2(CLK_AUDIO_UL5, "audio_ul5", "a1sys_hp_sel", 4),
  104. GATE_AUDIO2(CLK_AUDIO_UL6, "audio_ul6", "a1sys_hp_sel", 5),
  105. GATE_AUDIO2(CLK_AUDIO_DL1, "audio_dl1", "a1sys_hp_sel", 6),
  106. GATE_AUDIO2(CLK_AUDIO_DL2, "audio_dl2", "a1sys_hp_sel", 7),
  107. GATE_AUDIO2(CLK_AUDIO_DL3, "audio_dl3", "a1sys_hp_sel", 8),
  108. GATE_AUDIO2(CLK_AUDIO_DL4, "audio_dl4", "a1sys_hp_sel", 9),
  109. GATE_AUDIO2(CLK_AUDIO_DL5, "audio_dl5", "a1sys_hp_sel", 10),
  110. GATE_AUDIO2(CLK_AUDIO_DL6, "audio_dl6", "a1sys_hp_sel", 11),
  111. GATE_AUDIO2(CLK_AUDIO_DLMCH, "audio_dlmch", "a1sys_hp_sel", 12),
  112. GATE_AUDIO2(CLK_AUDIO_ARB1, "audio_arb1", "a1sys_hp_sel", 13),
  113. GATE_AUDIO2(CLK_AUDIO_AWB, "audio_awb", "a1sys_hp_sel", 14),
  114. GATE_AUDIO2(CLK_AUDIO_AWB2, "audio_awb2", "a1sys_hp_sel", 15),
  115. GATE_AUDIO2(CLK_AUDIO_DAI, "audio_dai", "a1sys_hp_sel", 16),
  116. GATE_AUDIO2(CLK_AUDIO_MOD, "audio_mod", "a1sys_hp_sel", 17),
  117. /* AUDIO3 */
  118. GATE_AUDIO3(CLK_AUDIO_ASRCI3, "audio_asrci3", "asm_h_sel", 2),
  119. GATE_AUDIO3(CLK_AUDIO_ASRCI4, "audio_asrci4", "asm_h_sel", 3),
  120. GATE_AUDIO3(CLK_AUDIO_ASRCO3, "audio_asrco3", "asm_h_sel", 6),
  121. GATE_AUDIO3(CLK_AUDIO_ASRCO4, "audio_asrco4", "asm_h_sel", 7),
  122. GATE_AUDIO3(CLK_AUDIO_MEM_ASRC1, "audio_mem_asrc1", "asm_h_sel", 10),
  123. GATE_AUDIO3(CLK_AUDIO_MEM_ASRC2, "audio_mem_asrc2", "asm_h_sel", 11),
  124. GATE_AUDIO3(CLK_AUDIO_MEM_ASRC3, "audio_mem_asrc3", "asm_h_sel", 12),
  125. GATE_AUDIO3(CLK_AUDIO_MEM_ASRC4, "audio_mem_asrc4", "asm_h_sel", 13),
  126. GATE_AUDIO3(CLK_AUDIO_MEM_ASRC5, "audio_mem_asrc5", "asm_h_sel", 14),
  127. };
  128. static int clk_mt7622_audiosys_init(struct platform_device *pdev)
  129. {
  130. struct clk_onecell_data *clk_data;
  131. struct device_node *node = pdev->dev.of_node;
  132. int r;
  133. clk_data = mtk_alloc_clk_data(CLK_AUDIO_NR_CLK);
  134. mtk_clk_register_gates(node, audio_clks, ARRAY_SIZE(audio_clks),
  135. clk_data);
  136. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  137. if (r) {
  138. dev_err(&pdev->dev,
  139. "could not register clock provider: %s: %d\n",
  140. pdev->name, r);
  141. goto err_clk_provider;
  142. }
  143. r = devm_of_platform_populate(&pdev->dev);
  144. if (r)
  145. goto err_plat_populate;
  146. return 0;
  147. err_plat_populate:
  148. of_clk_del_provider(node);
  149. err_clk_provider:
  150. return r;
  151. }
  152. static const struct of_device_id of_match_clk_mt7622_aud[] = {
  153. {
  154. .compatible = "mediatek,mt7622-audsys",
  155. .data = clk_mt7622_audiosys_init,
  156. }, {
  157. /* sentinel */
  158. }
  159. };
  160. static int clk_mt7622_aud_probe(struct platform_device *pdev)
  161. {
  162. int (*clk_init)(struct platform_device *);
  163. int r;
  164. clk_init = of_device_get_match_data(&pdev->dev);
  165. if (!clk_init)
  166. return -EINVAL;
  167. r = clk_init(pdev);
  168. if (r)
  169. dev_err(&pdev->dev,
  170. "could not register clock provider: %s: %d\n",
  171. pdev->name, r);
  172. return r;
  173. }
  174. static struct platform_driver clk_mt7622_aud_drv = {
  175. .probe = clk_mt7622_aud_probe,
  176. .driver = {
  177. .name = "clk-mt7622-aud",
  178. .of_match_table = of_match_clk_mt7622_aud,
  179. },
  180. };
  181. builtin_platform_driver(clk_mt7622_aud_drv);