hdmi_pll.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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(DSS_PLL_HDMI, 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(DSS_PLL_HDMI, 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 platform_device *pdev,
  104. struct hdmi_pll_data *hpll)
  105. {
  106. struct dss_pll *pll = &hpll->pll;
  107. struct clk *clk;
  108. int r;
  109. clk = devm_clk_get(&pdev->dev, "sys_clk");
  110. if (IS_ERR(clk)) {
  111. DSSERR("can't get sys_clk\n");
  112. return PTR_ERR(clk);
  113. }
  114. pll->name = "hdmi";
  115. pll->id = DSS_PLL_HDMI;
  116. pll->base = hpll->base;
  117. pll->clkin = clk;
  118. if (hpll->wp->version == 4)
  119. pll->hw = &dss_omap4_hdmi_pll_hw;
  120. else
  121. pll->hw = &dss_omap5_hdmi_pll_hw;
  122. pll->ops = &hdmi_pll_ops;
  123. r = dss_pll_register(pll);
  124. if (r)
  125. return r;
  126. return 0;
  127. }
  128. int hdmi_pll_init(struct platform_device *pdev, struct hdmi_pll_data *pll,
  129. struct hdmi_wp_data *wp)
  130. {
  131. int r;
  132. struct resource *res;
  133. pll->pdev = pdev;
  134. pll->wp = wp;
  135. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll");
  136. pll->base = devm_ioremap_resource(&pdev->dev, res);
  137. if (IS_ERR(pll->base))
  138. return PTR_ERR(pll->base);
  139. r = hdmi_init_pll_data(pdev, pll);
  140. if (r) {
  141. DSSERR("failed to init HDMI PLL\n");
  142. return r;
  143. }
  144. return 0;
  145. }
  146. void hdmi_pll_uninit(struct hdmi_pll_data *hpll)
  147. {
  148. struct dss_pll *pll = &hpll->pll;
  149. dss_pll_unregister(pll);
  150. }