meson_vclk.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2016 BayLibre, SAS
  3. * Author: Neil Armstrong <narmstrong@baylibre.com>
  4. * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <drm/drmP.h>
  22. #include "meson_drv.h"
  23. #include "meson_vclk.h"
  24. /*
  25. * VCLK is the "Pixel Clock" frequency generator from a dedicated PLL.
  26. * We handle the following encodings :
  27. * - CVBS 27MHz generator via the VCLK2 to the VENCI and VDAC blocks
  28. *
  29. * What is missing :
  30. * - HDMI Pixel Clocks generation
  31. */
  32. /* HHI Registers */
  33. #define HHI_VID_PLL_CLK_DIV 0x1a0 /* 0x68 offset in data sheet */
  34. #define VID_PLL_EN BIT(19)
  35. #define VID_PLL_BYPASS BIT(18)
  36. #define VID_PLL_PRESET BIT(15)
  37. #define HHI_VIID_CLK_DIV 0x128 /* 0x4a offset in data sheet */
  38. #define VCLK2_DIV_MASK 0xff
  39. #define VCLK2_DIV_EN BIT(16)
  40. #define VCLK2_DIV_RESET BIT(17)
  41. #define CTS_VDAC_SEL_MASK (0xf << 28)
  42. #define CTS_VDAC_SEL_SHIFT 28
  43. #define HHI_VIID_CLK_CNTL 0x12c /* 0x4b offset in data sheet */
  44. #define VCLK2_EN BIT(19)
  45. #define VCLK2_SEL_MASK (0x7 << 16)
  46. #define VCLK2_SEL_SHIFT 16
  47. #define VCLK2_SOFT_RESET BIT(15)
  48. #define VCLK2_DIV1_EN BIT(0)
  49. #define HHI_VID_CLK_DIV 0x164 /* 0x59 offset in data sheet */
  50. #define CTS_ENCI_SEL_MASK (0xf << 28)
  51. #define CTS_ENCI_SEL_SHIFT 28
  52. #define HHI_VID_CLK_CNTL2 0x194 /* 0x65 offset in data sheet */
  53. #define CTS_ENCI_EN BIT(0)
  54. #define CTS_VDAC_EN BIT(4)
  55. #define HHI_VDAC_CNTL0 0x2F4 /* 0xbd offset in data sheet */
  56. #define HHI_VDAC_CNTL1 0x2F8 /* 0xbe offset in data sheet */
  57. #define HHI_HDMI_PLL_CNTL 0x320 /* 0xc8 offset in data sheet */
  58. #define HHI_HDMI_PLL_CNTL2 0x324 /* 0xc9 offset in data sheet */
  59. #define HHI_HDMI_PLL_CNTL3 0x328 /* 0xca offset in data sheet */
  60. #define HHI_HDMI_PLL_CNTL4 0x32C /* 0xcb offset in data sheet */
  61. #define HHI_HDMI_PLL_CNTL5 0x330 /* 0xcc offset in data sheet */
  62. #define HHI_HDMI_PLL_CNTL6 0x334 /* 0xcd offset in data sheet */
  63. #define HDMI_PLL_RESET BIT(28)
  64. #define HDMI_PLL_LOCK BIT(31)
  65. /*
  66. * Setup VCLK2 for 27MHz, and enable clocks for ENCI and VDAC
  67. *
  68. * TOFIX: Refactor into table to also handle HDMI frequency and paths
  69. */
  70. static void meson_venci_cvbs_clock_config(struct meson_drm *priv)
  71. {
  72. unsigned int val;
  73. /* Setup PLL to output 1.485GHz */
  74. if (meson_vpu_is_compatible(priv, "amlogic,meson-gxbb-vpu")) {
  75. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x5800023d);
  76. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x00404e00);
  77. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0x0d5c5091);
  78. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x801da72c);
  79. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x71486980);
  80. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x00000e55);
  81. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4800023d);
  82. } else if (meson_vpu_is_compatible(priv, "amlogic,meson-gxm-vpu") ||
  83. meson_vpu_is_compatible(priv, "amlogic,meson-gxl-vpu")) {
  84. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL, 0x4000027b);
  85. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL2, 0x800cb300);
  86. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL3, 0xa6212844);
  87. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL4, 0x0c4d000c);
  88. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL5, 0x001fa729);
  89. regmap_write(priv->hhi, HHI_HDMI_PLL_CNTL6, 0x01a31500);
  90. /* Reset PLL */
  91. regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
  92. HDMI_PLL_RESET, HDMI_PLL_RESET);
  93. regmap_update_bits(priv->hhi, HHI_HDMI_PLL_CNTL,
  94. HDMI_PLL_RESET, 0);
  95. }
  96. /* Poll for lock bit */
  97. regmap_read_poll_timeout(priv->hhi, HHI_HDMI_PLL_CNTL, val,
  98. (val & HDMI_PLL_LOCK), 10, 0);
  99. /* Disable VCLK2 */
  100. regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL, VCLK2_EN, 0);
  101. /* Disable vid_pll output clock */
  102. regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV, VID_PLL_EN, 0);
  103. regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV, VID_PLL_PRESET, 0);
  104. /* Enable vid_pll bypass to HDMI pll */
  105. regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
  106. VID_PLL_BYPASS, VID_PLL_BYPASS);
  107. /* Enable the vid_pll output clock */
  108. regmap_update_bits(priv->hhi, HHI_VID_PLL_CLK_DIV,
  109. VID_PLL_EN, VID_PLL_EN);
  110. /* Setup the VCLK2 divider value to achieve 27MHz */
  111. regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
  112. VCLK2_DIV_MASK, (55 - 1));
  113. /* select vid_pll for vclk2 */
  114. regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
  115. VCLK2_SEL_MASK, (4 << VCLK2_SEL_SHIFT));
  116. /* enable vclk2 gate */
  117. regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL, VCLK2_EN, VCLK2_EN);
  118. /* select vclk_div1 for enci */
  119. regmap_update_bits(priv->hhi, HHI_VID_CLK_DIV,
  120. CTS_ENCI_SEL_MASK, (8 << CTS_ENCI_SEL_SHIFT));
  121. /* select vclk_div1 for vdac */
  122. regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
  123. CTS_VDAC_SEL_MASK, (8 << CTS_VDAC_SEL_SHIFT));
  124. /* release vclk2_div_reset and enable vclk2_div */
  125. regmap_update_bits(priv->hhi, HHI_VIID_CLK_DIV,
  126. VCLK2_DIV_EN | VCLK2_DIV_RESET, VCLK2_DIV_EN);
  127. /* enable vclk2_div1 gate */
  128. regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
  129. VCLK2_DIV1_EN, VCLK2_DIV1_EN);
  130. /* reset vclk2 */
  131. regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
  132. VCLK2_SOFT_RESET, VCLK2_SOFT_RESET);
  133. regmap_update_bits(priv->hhi, HHI_VIID_CLK_CNTL,
  134. VCLK2_SOFT_RESET, 0);
  135. /* enable enci_clk */
  136. regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
  137. CTS_ENCI_EN, CTS_ENCI_EN);
  138. /* enable vdac_clk */
  139. regmap_update_bits(priv->hhi, HHI_VID_CLK_CNTL2,
  140. CTS_VDAC_EN, CTS_VDAC_EN);
  141. }
  142. void meson_vclk_setup(struct meson_drm *priv, unsigned int target,
  143. unsigned int freq)
  144. {
  145. if (target == MESON_VCLK_TARGET_CVBS && freq == MESON_VCLK_CVBS)
  146. meson_venci_cvbs_clock_config(priv);
  147. }