hdmi_pll.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * HDMI PLL
  3. *
  4. * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #define DSS_SUBSYS_NAME "HDMIPLL"
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/err.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/pm_runtime.h>
  19. #include "omapdss.h"
  20. #include "dss.h"
  21. #include "hdmi.h"
  22. void hdmi_pll_dump(struct hdmi_pll_data *pll, struct seq_file *s)
  23. {
  24. #define DUMPPLL(r) seq_printf(s, "%-35s %08x\n", #r,\
  25. hdmi_read_reg(pll->base, r))
  26. DUMPPLL(PLLCTRL_PLL_CONTROL);
  27. DUMPPLL(PLLCTRL_PLL_STATUS);
  28. DUMPPLL(PLLCTRL_PLL_GO);
  29. DUMPPLL(PLLCTRL_CFG1);
  30. DUMPPLL(PLLCTRL_CFG2);
  31. DUMPPLL(PLLCTRL_CFG3);
  32. DUMPPLL(PLLCTRL_SSC_CFG1);
  33. DUMPPLL(PLLCTRL_SSC_CFG2);
  34. DUMPPLL(PLLCTRL_CFG4);
  35. }
  36. static int hdmi_pll_enable(struct dss_pll *dsspll)
  37. {
  38. struct hdmi_pll_data *pll = container_of(dsspll, struct hdmi_pll_data, pll);
  39. struct hdmi_wp_data *wp = pll->wp;
  40. int r;
  41. r = pm_runtime_get_sync(&pll->pdev->dev);
  42. WARN_ON(r < 0);
  43. dss_ctrl_pll_enable(dsspll, true);
  44. r = hdmi_wp_set_pll_pwr(wp, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
  45. if (r)
  46. return r;
  47. return 0;
  48. }
  49. static void hdmi_pll_disable(struct dss_pll *dsspll)
  50. {
  51. struct hdmi_pll_data *pll = container_of(dsspll, struct hdmi_pll_data, pll);
  52. struct hdmi_wp_data *wp = pll->wp;
  53. int r;
  54. hdmi_wp_set_pll_pwr(wp, HDMI_PLLPWRCMD_ALLOFF);
  55. dss_ctrl_pll_enable(dsspll, false);
  56. r = pm_runtime_put_sync(&pll->pdev->dev);
  57. WARN_ON(r < 0 && r != -ENOSYS);
  58. }
  59. static const struct dss_pll_ops hdmi_pll_ops = {
  60. .enable = hdmi_pll_enable,
  61. .disable = hdmi_pll_disable,
  62. .set_config = dss_pll_write_config_type_b,
  63. };
  64. static const struct dss_pll_hw dss_omap4_hdmi_pll_hw = {
  65. .type = DSS_PLL_TYPE_B,
  66. .n_max = 255,
  67. .m_min = 20,
  68. .m_max = 4095,
  69. .mX_max = 127,
  70. .fint_min = 500000,
  71. .fint_max = 2500000,
  72. .clkdco_min = 500000000,
  73. .clkdco_low = 1000000000,
  74. .clkdco_max = 2000000000,
  75. .n_msb = 8,
  76. .n_lsb = 1,
  77. .m_msb = 20,
  78. .m_lsb = 9,
  79. .mX_msb[0] = 24,
  80. .mX_lsb[0] = 18,
  81. .has_selfreqdco = true,
  82. };
  83. static const struct dss_pll_hw dss_omap5_hdmi_pll_hw = {
  84. .type = DSS_PLL_TYPE_B,
  85. .n_max = 255,
  86. .m_min = 20,
  87. .m_max = 2045,
  88. .mX_max = 127,
  89. .fint_min = 620000,
  90. .fint_max = 2500000,
  91. .clkdco_min = 750000000,
  92. .clkdco_low = 1500000000,
  93. .clkdco_max = 2500000000UL,
  94. .n_msb = 8,
  95. .n_lsb = 1,
  96. .m_msb = 20,
  97. .m_lsb = 9,
  98. .mX_msb[0] = 24,
  99. .mX_lsb[0] = 18,
  100. .has_selfreqdco = true,
  101. .has_refsel = true,
  102. };
  103. static int hdmi_init_pll_data(struct dss_device *dss,
  104. struct platform_device *pdev,
  105. struct hdmi_pll_data *hpll)
  106. {
  107. struct dss_pll *pll = &hpll->pll;
  108. struct clk *clk;
  109. int r;
  110. clk = devm_clk_get(&pdev->dev, "sys_clk");
  111. if (IS_ERR(clk)) {
  112. DSSERR("can't get sys_clk\n");
  113. return PTR_ERR(clk);
  114. }
  115. pll->name = "hdmi";
  116. pll->id = DSS_PLL_HDMI;
  117. pll->base = hpll->base;
  118. pll->clkin = clk;
  119. if (hpll->wp->version == 4)
  120. pll->hw = &dss_omap4_hdmi_pll_hw;
  121. else
  122. pll->hw = &dss_omap5_hdmi_pll_hw;
  123. pll->ops = &hdmi_pll_ops;
  124. r = dss_pll_register(dss, pll);
  125. if (r)
  126. return r;
  127. return 0;
  128. }
  129. int hdmi_pll_init(struct dss_device *dss, struct platform_device *pdev,
  130. struct hdmi_pll_data *pll, struct hdmi_wp_data *wp)
  131. {
  132. int r;
  133. struct resource *res;
  134. pll->pdev = pdev;
  135. pll->wp = wp;
  136. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll");
  137. pll->base = devm_ioremap_resource(&pdev->dev, res);
  138. if (IS_ERR(pll->base))
  139. return PTR_ERR(pll->base);
  140. r = hdmi_init_pll_data(dss, pdev, pll);
  141. if (r) {
  142. DSSERR("failed to init HDMI PLL\n");
  143. return r;
  144. }
  145. return 0;
  146. }
  147. void hdmi_pll_uninit(struct hdmi_pll_data *hpll)
  148. {
  149. struct dss_pll *pll = &hpll->pll;
  150. dss_pll_unregister(pll);
  151. }