hdmi_pll.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * HDMI PLL
  3. *
  4. * Copyright (C) 2013 Texas Instruments Incorporated
  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 dsi_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 dsi_init_pll_data(struct platform_device *pdev, struct hdmi_pll_data *hpll)
  104. {
  105. struct dss_pll *pll = &hpll->pll;
  106. struct clk *clk;
  107. int r;
  108. clk = devm_clk_get(&pdev->dev, "sys_clk");
  109. if (IS_ERR(clk)) {
  110. DSSERR("can't get sys_clk\n");
  111. return PTR_ERR(clk);
  112. }
  113. pll->name = "hdmi";
  114. pll->id = DSS_PLL_HDMI;
  115. pll->base = hpll->base;
  116. pll->clkin = clk;
  117. switch (omapdss_get_version()) {
  118. case OMAPDSS_VER_OMAP4430_ES1:
  119. case OMAPDSS_VER_OMAP4430_ES2:
  120. case OMAPDSS_VER_OMAP4:
  121. pll->hw = &dss_omap4_hdmi_pll_hw;
  122. break;
  123. case OMAPDSS_VER_OMAP5:
  124. case OMAPDSS_VER_DRA7xx:
  125. pll->hw = &dss_omap5_hdmi_pll_hw;
  126. break;
  127. default:
  128. return -ENODEV;
  129. }
  130. pll->ops = &dsi_pll_ops;
  131. r = dss_pll_register(pll);
  132. if (r)
  133. return r;
  134. return 0;
  135. }
  136. int hdmi_pll_init(struct platform_device *pdev, struct hdmi_pll_data *pll,
  137. struct hdmi_wp_data *wp)
  138. {
  139. int r;
  140. struct resource *res;
  141. pll->pdev = pdev;
  142. pll->wp = wp;
  143. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll");
  144. if (!res) {
  145. DSSERR("can't get PLL mem resource\n");
  146. return -EINVAL;
  147. }
  148. pll->base = devm_ioremap_resource(&pdev->dev, res);
  149. if (IS_ERR(pll->base)) {
  150. DSSERR("can't ioremap PLLCTRL\n");
  151. return PTR_ERR(pll->base);
  152. }
  153. r = dsi_init_pll_data(pdev, pll);
  154. if (r) {
  155. DSSERR("failed to init HDMI PLL\n");
  156. return r;
  157. }
  158. return 0;
  159. }
  160. void hdmi_pll_uninit(struct hdmi_pll_data *hpll)
  161. {
  162. struct dss_pll *pll = &hpll->pll;
  163. dss_pll_unregister(pll);
  164. }