clk-mt8196-vdec.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2025 MediaTek Inc.
  4. * Guangjie Song <guangjie.song@mediatek.com>
  5. * Copyright (c) 2025 Collabora Ltd.
  6. * Laura Nao <laura.nao@collabora.com>
  7. */
  8. #include <dt-bindings/clock/mediatek,mt8196-clock.h>
  9. #include <linux/clk-provider.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. #include "clk-gate.h"
  14. #include "clk-mtk.h"
  15. static const struct mtk_gate_regs vde20_cg_regs = {
  16. .set_ofs = 0x0,
  17. .clr_ofs = 0x4,
  18. .sta_ofs = 0x0,
  19. };
  20. static const struct mtk_gate_regs vde20_hwv_regs = {
  21. .set_ofs = 0x0088,
  22. .clr_ofs = 0x008c,
  23. .sta_ofs = 0x2c44,
  24. };
  25. static const struct mtk_gate_regs vde21_cg_regs = {
  26. .set_ofs = 0x200,
  27. .clr_ofs = 0x204,
  28. .sta_ofs = 0x200,
  29. };
  30. static const struct mtk_gate_regs vde21_hwv_regs = {
  31. .set_ofs = 0x0080,
  32. .clr_ofs = 0x0084,
  33. .sta_ofs = 0x2c40,
  34. };
  35. static const struct mtk_gate_regs vde22_cg_regs = {
  36. .set_ofs = 0x8,
  37. .clr_ofs = 0xc,
  38. .sta_ofs = 0x8,
  39. };
  40. static const struct mtk_gate_regs vde22_hwv_regs = {
  41. .set_ofs = 0x0078,
  42. .clr_ofs = 0x007c,
  43. .sta_ofs = 0x2c3c,
  44. };
  45. #define GATE_HWV_VDE20(_id, _name, _parent, _shift) { \
  46. .id = _id, \
  47. .name = _name, \
  48. .parent_name = _parent, \
  49. .regs = &vde20_cg_regs, \
  50. .hwv_regs = &vde20_hwv_regs, \
  51. .shift = _shift, \
  52. .ops = &mtk_clk_gate_hwv_ops_setclr_inv,\
  53. .flags = CLK_OPS_PARENT_ENABLE, \
  54. }
  55. #define GATE_HWV_VDE21(_id, _name, _parent, _shift) { \
  56. .id = _id, \
  57. .name = _name, \
  58. .parent_name = _parent, \
  59. .regs = &vde21_cg_regs, \
  60. .hwv_regs = &vde21_hwv_regs, \
  61. .shift = _shift, \
  62. .ops = &mtk_clk_gate_hwv_ops_setclr_inv,\
  63. .flags = CLK_OPS_PARENT_ENABLE, \
  64. }
  65. #define GATE_HWV_VDE22(_id, _name, _parent, _shift) { \
  66. .id = _id, \
  67. .name = _name, \
  68. .parent_name = _parent, \
  69. .regs = &vde22_cg_regs, \
  70. .hwv_regs = &vde22_hwv_regs, \
  71. .shift = _shift, \
  72. .ops = &mtk_clk_gate_hwv_ops_setclr_inv,\
  73. .flags = CLK_OPS_PARENT_ENABLE | \
  74. CLK_IGNORE_UNUSED, \
  75. }
  76. static const struct mtk_gate vde2_clks[] = {
  77. /* VDE20 */
  78. GATE_HWV_VDE20(CLK_VDE2_VDEC_CKEN, "vde2_vdec_cken", "vdec", 0),
  79. GATE_HWV_VDE20(CLK_VDE2_VDEC_ACTIVE, "vde2_vdec_active", "vdec", 4),
  80. GATE_HWV_VDE20(CLK_VDE2_VDEC_CKEN_ENG, "vde2_vdec_cken_eng", "vdec", 8),
  81. /* VDE21 */
  82. GATE_HWV_VDE21(CLK_VDE2_LAT_CKEN, "vde2_lat_cken", "vdec", 0),
  83. GATE_HWV_VDE21(CLK_VDE2_LAT_ACTIVE, "vde2_lat_active", "vdec", 4),
  84. GATE_HWV_VDE21(CLK_VDE2_LAT_CKEN_ENG, "vde2_lat_cken_eng", "vdec", 8),
  85. /* VDE22 */
  86. GATE_HWV_VDE22(CLK_VDE2_LARB1_CKEN, "vde2_larb1_cken", "vdec", 0),
  87. };
  88. static const struct mtk_clk_desc vde2_mcd = {
  89. .clks = vde2_clks,
  90. .num_clks = ARRAY_SIZE(vde2_clks),
  91. .need_runtime_pm = true,
  92. };
  93. static const struct mtk_gate_regs vde10_hwv_regs = {
  94. .set_ofs = 0x00a0,
  95. .clr_ofs = 0x00a4,
  96. .sta_ofs = 0x2c50,
  97. };
  98. static const struct mtk_gate_regs vde11_cg_regs = {
  99. .set_ofs = 0x1e0,
  100. .clr_ofs = 0x1e0,
  101. .sta_ofs = 0x1e0,
  102. };
  103. static const struct mtk_gate_regs vde11_hwv_regs = {
  104. .set_ofs = 0x00b0,
  105. .clr_ofs = 0x00b4,
  106. .sta_ofs = 0x2c58,
  107. };
  108. static const struct mtk_gate_regs vde12_cg_regs = {
  109. .set_ofs = 0x1ec,
  110. .clr_ofs = 0x1ec,
  111. .sta_ofs = 0x1ec,
  112. };
  113. static const struct mtk_gate_regs vde12_hwv_regs = {
  114. .set_ofs = 0x00a8,
  115. .clr_ofs = 0x00ac,
  116. .sta_ofs = 0x2c54,
  117. };
  118. static const struct mtk_gate_regs vde13_cg_regs = {
  119. .set_ofs = 0x200,
  120. .clr_ofs = 0x204,
  121. .sta_ofs = 0x200,
  122. };
  123. static const struct mtk_gate_regs vde13_hwv_regs = {
  124. .set_ofs = 0x0098,
  125. .clr_ofs = 0x009c,
  126. .sta_ofs = 0x2c4c,
  127. };
  128. static const struct mtk_gate_regs vde14_hwv_regs = {
  129. .set_ofs = 0x0090,
  130. .clr_ofs = 0x0094,
  131. .sta_ofs = 0x2c48,
  132. };
  133. #define GATE_HWV_VDE10(_id, _name, _parent, _shift) { \
  134. .id = _id, \
  135. .name = _name, \
  136. .parent_name = _parent, \
  137. .regs = &vde20_cg_regs, \
  138. .hwv_regs = &vde10_hwv_regs, \
  139. .shift = _shift, \
  140. .ops = &mtk_clk_gate_hwv_ops_setclr_inv,\
  141. .flags = CLK_OPS_PARENT_ENABLE, \
  142. }
  143. #define GATE_HWV_VDE11(_id, _name, _parent, _shift) { \
  144. .id = _id, \
  145. .name = _name, \
  146. .parent_name = _parent, \
  147. .regs = &vde11_cg_regs, \
  148. .hwv_regs = &vde11_hwv_regs, \
  149. .shift = _shift, \
  150. .ops = &mtk_clk_gate_hwv_ops_setclr_inv, \
  151. .flags = CLK_OPS_PARENT_ENABLE, \
  152. }
  153. #define GATE_HWV_VDE12(_id, _name, _parent, _shift) { \
  154. .id = _id, \
  155. .name = _name, \
  156. .parent_name = _parent, \
  157. .regs = &vde12_cg_regs, \
  158. .hwv_regs = &vde12_hwv_regs, \
  159. .shift = _shift, \
  160. .ops = &mtk_clk_gate_hwv_ops_setclr_inv, \
  161. .flags = CLK_OPS_PARENT_ENABLE \
  162. }
  163. #define GATE_HWV_VDE13(_id, _name, _parent, _shift) { \
  164. .id = _id, \
  165. .name = _name, \
  166. .parent_name = _parent, \
  167. .regs = &vde13_cg_regs, \
  168. .hwv_regs = &vde13_hwv_regs, \
  169. .shift = _shift, \
  170. .ops = &mtk_clk_gate_hwv_ops_setclr_inv,\
  171. .flags = CLK_OPS_PARENT_ENABLE, \
  172. }
  173. #define GATE_HWV_VDE14(_id, _name, _parent, _shift) { \
  174. .id = _id, \
  175. .name = _name, \
  176. .parent_name = _parent, \
  177. .regs = &vde22_cg_regs, \
  178. .hwv_regs = &vde14_hwv_regs, \
  179. .shift = _shift, \
  180. .ops = &mtk_clk_gate_hwv_ops_setclr_inv,\
  181. .flags = CLK_OPS_PARENT_ENABLE | \
  182. CLK_IGNORE_UNUSED, \
  183. }
  184. static const struct mtk_gate vde1_clks[] = {
  185. /* VDE10 */
  186. GATE_HWV_VDE10(CLK_VDE1_VDEC_CKEN, "vde1_vdec_cken", "vdec", 0),
  187. GATE_HWV_VDE10(CLK_VDE1_VDEC_ACTIVE, "vde1_vdec_active", "vdec", 4),
  188. GATE_HWV_VDE10(CLK_VDE1_VDEC_CKEN_ENG, "vde1_vdec_cken_eng", "vdec", 8),
  189. /* VDE11 */
  190. GATE_HWV_VDE11(CLK_VDE1_VDEC_SOC_IPS_EN, "vde1_vdec_soc_ips_en", "vdec", 0),
  191. /* VDE12 */
  192. GATE_HWV_VDE12(CLK_VDE1_VDEC_SOC_APTV_EN, "vde1_aptv_en", "ck_tck_26m_mx9_ck", 0),
  193. GATE_HWV_VDE12(CLK_VDE1_VDEC_SOC_APTV_TOP_EN, "vde1_aptv_topen", "ck_tck_26m_mx9_ck", 1),
  194. /* VDE13 */
  195. GATE_HWV_VDE13(CLK_VDE1_LAT_CKEN, "vde1_lat_cken", "vdec", 0),
  196. GATE_HWV_VDE13(CLK_VDE1_LAT_ACTIVE, "vde1_lat_active", "vdec", 4),
  197. GATE_HWV_VDE13(CLK_VDE1_LAT_CKEN_ENG, "vde1_lat_cken_eng", "vdec", 8),
  198. /* VDE14 */
  199. GATE_HWV_VDE14(CLK_VDE1_LARB1_CKEN, "vde1_larb1_cken", "vdec", 0),
  200. };
  201. static const struct mtk_clk_desc vde1_mcd = {
  202. .clks = vde1_clks,
  203. .num_clks = ARRAY_SIZE(vde1_clks),
  204. .need_runtime_pm = true,
  205. };
  206. static const struct of_device_id of_match_clk_mt8196_vdec[] = {
  207. { .compatible = "mediatek,mt8196-vdecsys", .data = &vde2_mcd },
  208. { .compatible = "mediatek,mt8196-vdecsys-soc", .data = &vde1_mcd },
  209. { /* sentinel */ }
  210. };
  211. MODULE_DEVICE_TABLE(of, of_match_clk_mt8196_vdec);
  212. static struct platform_driver clk_mt8196_vdec_drv = {
  213. .probe = mtk_clk_simple_probe,
  214. .remove = mtk_clk_simple_remove,
  215. .driver = {
  216. .name = "clk-mt8196-vdec",
  217. .of_match_table = of_match_clk_mt8196_vdec,
  218. },
  219. };
  220. module_platform_driver(clk_mt8196_vdec_drv);
  221. MODULE_DESCRIPTION("MediaTek MT8196 Video Decoders clocks driver");
  222. MODULE_LICENSE("GPL");