sti_vtac.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Author: Benjamin Gaignard <benjamin.gaignard@st.com> for STMicroelectronics.
  4. * License terms: GNU General Public License (GPL), version 2
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/io.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. #include <drm/drmP.h>
  12. /* registers offset */
  13. #define VTAC_CONFIG 0x00
  14. #define VTAC_RX_FIFO_CONFIG 0x04
  15. #define VTAC_FIFO_CONFIG_VAL 0x04
  16. #define VTAC_SYS_CFG8521 0x824
  17. #define VTAC_SYS_CFG8522 0x828
  18. /* Number of phyts per pixel */
  19. #define VTAC_2_5_PPP 0x0005
  20. #define VTAC_3_PPP 0x0006
  21. #define VTAC_4_PPP 0x0008
  22. #define VTAC_5_PPP 0x000A
  23. #define VTAC_6_PPP 0x000C
  24. #define VTAC_13_PPP 0x001A
  25. #define VTAC_14_PPP 0x001C
  26. #define VTAC_15_PPP 0x001E
  27. #define VTAC_16_PPP 0x0020
  28. #define VTAC_17_PPP 0x0022
  29. #define VTAC_18_PPP 0x0024
  30. /* enable bits */
  31. #define VTAC_ENABLE 0x3003
  32. #define VTAC_TX_PHY_ENABLE_CLK_PHY BIT(0)
  33. #define VTAC_TX_PHY_ENABLE_CLK_DLL BIT(1)
  34. #define VTAC_TX_PHY_PLL_NOT_OSC_MODE BIT(3)
  35. #define VTAC_TX_PHY_RST_N_DLL_SWITCH BIT(4)
  36. #define VTAC_TX_PHY_PROG_N3 BIT(9)
  37. /**
  38. * VTAC mode structure
  39. *
  40. * @vid_in_width: Video Data Resolution
  41. * @phyts_width: Width of phyt buses(phyt low and phyt high).
  42. * @phyts_per_pixel: Number of phyts sent per pixel
  43. */
  44. struct sti_vtac_mode {
  45. u32 vid_in_width;
  46. u32 phyts_width;
  47. u32 phyts_per_pixel;
  48. };
  49. static const struct sti_vtac_mode vtac_mode_main = {
  50. .vid_in_width = 0x2,
  51. .phyts_width = 0x2,
  52. .phyts_per_pixel = VTAC_5_PPP,
  53. };
  54. static const struct sti_vtac_mode vtac_mode_aux = {
  55. .vid_in_width = 0x1,
  56. .phyts_width = 0x0,
  57. .phyts_per_pixel = VTAC_17_PPP,
  58. };
  59. /**
  60. * VTAC structure
  61. *
  62. * @dev: pointer to device structure
  63. * @regs: ioremapped registers for RX and TX devices
  64. * @phy_regs: phy registers for TX device
  65. * @clk: clock
  66. * @mode: main or auxillary configuration mode
  67. */
  68. struct sti_vtac {
  69. struct device *dev;
  70. void __iomem *regs;
  71. void __iomem *phy_regs;
  72. struct clk *clk;
  73. const struct sti_vtac_mode *mode;
  74. };
  75. static void sti_vtac_rx_set_config(struct sti_vtac *vtac)
  76. {
  77. u32 config;
  78. /* Enable VTAC clock */
  79. if (clk_prepare_enable(vtac->clk))
  80. DRM_ERROR("Failed to prepare/enable vtac_rx clock.\n");
  81. writel(VTAC_FIFO_CONFIG_VAL, vtac->regs + VTAC_RX_FIFO_CONFIG);
  82. config = VTAC_ENABLE;
  83. config |= vtac->mode->vid_in_width << 4;
  84. config |= vtac->mode->phyts_width << 16;
  85. config |= vtac->mode->phyts_per_pixel << 23;
  86. writel(config, vtac->regs + VTAC_CONFIG);
  87. }
  88. static void sti_vtac_tx_set_config(struct sti_vtac *vtac)
  89. {
  90. u32 phy_config;
  91. u32 config;
  92. /* Enable VTAC clock */
  93. if (clk_prepare_enable(vtac->clk))
  94. DRM_ERROR("Failed to prepare/enable vtac_tx clock.\n");
  95. /* Configure vtac phy */
  96. phy_config = 0x00000000;
  97. writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8522);
  98. phy_config = VTAC_TX_PHY_ENABLE_CLK_PHY;
  99. writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
  100. phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
  101. phy_config |= VTAC_TX_PHY_PROG_N3;
  102. writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
  103. phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
  104. phy_config |= VTAC_TX_PHY_ENABLE_CLK_DLL;
  105. writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
  106. phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
  107. phy_config |= VTAC_TX_PHY_RST_N_DLL_SWITCH;
  108. writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
  109. phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
  110. phy_config |= VTAC_TX_PHY_PLL_NOT_OSC_MODE;
  111. writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
  112. /* Configure vtac tx */
  113. config = VTAC_ENABLE;
  114. config |= vtac->mode->vid_in_width << 4;
  115. config |= vtac->mode->phyts_width << 16;
  116. config |= vtac->mode->phyts_per_pixel << 23;
  117. writel(config, vtac->regs + VTAC_CONFIG);
  118. }
  119. static const struct of_device_id vtac_of_match[] = {
  120. {
  121. .compatible = "st,vtac-main",
  122. .data = &vtac_mode_main,
  123. }, {
  124. .compatible = "st,vtac-aux",
  125. .data = &vtac_mode_aux,
  126. }, {
  127. /* end node */
  128. }
  129. };
  130. MODULE_DEVICE_TABLE(of, vtac_of_match);
  131. static int sti_vtac_probe(struct platform_device *pdev)
  132. {
  133. struct device *dev = &pdev->dev;
  134. struct device_node *np = dev->of_node;
  135. const struct of_device_id *id;
  136. struct sti_vtac *vtac;
  137. struct resource *res;
  138. vtac = devm_kzalloc(dev, sizeof(*vtac), GFP_KERNEL);
  139. if (!vtac)
  140. return -ENOMEM;
  141. vtac->dev = dev;
  142. id = of_match_node(vtac_of_match, np);
  143. if (!id)
  144. return -ENOMEM;
  145. vtac->mode = id->data;
  146. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  147. if (!res) {
  148. DRM_ERROR("Invalid resource\n");
  149. return -ENOMEM;
  150. }
  151. vtac->regs = devm_ioremap_resource(dev, res);
  152. if (IS_ERR(vtac->regs))
  153. return PTR_ERR(vtac->regs);
  154. vtac->clk = devm_clk_get(dev, "vtac");
  155. if (IS_ERR(vtac->clk)) {
  156. DRM_ERROR("Cannot get vtac clock\n");
  157. return PTR_ERR(vtac->clk);
  158. }
  159. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  160. if (res) {
  161. vtac->phy_regs = devm_ioremap_nocache(dev, res->start,
  162. resource_size(res));
  163. sti_vtac_tx_set_config(vtac);
  164. } else {
  165. sti_vtac_rx_set_config(vtac);
  166. }
  167. platform_set_drvdata(pdev, vtac);
  168. DRM_INFO("%s %s\n", __func__, dev_name(vtac->dev));
  169. return 0;
  170. }
  171. static int sti_vtac_remove(struct platform_device *pdev)
  172. {
  173. return 0;
  174. }
  175. struct platform_driver sti_vtac_driver = {
  176. .driver = {
  177. .name = "sti-vtac",
  178. .owner = THIS_MODULE,
  179. .of_match_table = vtac_of_match,
  180. },
  181. .probe = sti_vtac_probe,
  182. .remove = sti_vtac_remove,
  183. };
  184. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  185. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  186. MODULE_LICENSE("GPL");