hdmi_common.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0
  2. #define DSS_SUBSYS_NAME "HDMI"
  3. #include <linux/kernel.h>
  4. #include <linux/err.h>
  5. #include <linux/of.h>
  6. #include "omapdss.h"
  7. #include "hdmi.h"
  8. int hdmi_parse_lanes_of(struct platform_device *pdev, struct device_node *ep,
  9. struct hdmi_phy_data *phy)
  10. {
  11. struct property *prop;
  12. int r, len;
  13. prop = of_find_property(ep, "lanes", &len);
  14. if (prop) {
  15. u32 lanes[8];
  16. if (len / sizeof(u32) != ARRAY_SIZE(lanes)) {
  17. dev_err(&pdev->dev, "bad number of lanes\n");
  18. return -EINVAL;
  19. }
  20. r = of_property_read_u32_array(ep, "lanes", lanes,
  21. ARRAY_SIZE(lanes));
  22. if (r) {
  23. dev_err(&pdev->dev, "failed to read lane data\n");
  24. return r;
  25. }
  26. r = hdmi_phy_parse_lanes(phy, lanes);
  27. if (r) {
  28. dev_err(&pdev->dev, "failed to parse lane data\n");
  29. return r;
  30. }
  31. } else {
  32. static const u32 default_lanes[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
  33. r = hdmi_phy_parse_lanes(phy, default_lanes);
  34. if (WARN_ON(r)) {
  35. dev_err(&pdev->dev, "failed to parse lane data\n");
  36. return r;
  37. }
  38. }
  39. return 0;
  40. }
  41. int hdmi_compute_acr(u32 pclk, u32 sample_freq, u32 *n, u32 *cts)
  42. {
  43. u32 deep_color;
  44. bool deep_color_correct = false;
  45. if (n == NULL || cts == NULL)
  46. return -EINVAL;
  47. /* TODO: When implemented, query deep color mode here. */
  48. deep_color = 100;
  49. /*
  50. * When using deep color, the default N value (as in the HDMI
  51. * specification) yields to an non-integer CTS. Hence, we
  52. * modify it while keeping the restrictions described in
  53. * section 7.2.1 of the HDMI 1.4a specification.
  54. */
  55. switch (sample_freq) {
  56. case 32000:
  57. case 48000:
  58. case 96000:
  59. case 192000:
  60. if (deep_color == 125)
  61. if (pclk == 27027000 || pclk == 74250000)
  62. deep_color_correct = true;
  63. if (deep_color == 150)
  64. if (pclk == 27027000)
  65. deep_color_correct = true;
  66. break;
  67. case 44100:
  68. case 88200:
  69. case 176400:
  70. if (deep_color == 125)
  71. if (pclk == 27027000)
  72. deep_color_correct = true;
  73. break;
  74. default:
  75. return -EINVAL;
  76. }
  77. if (deep_color_correct) {
  78. switch (sample_freq) {
  79. case 32000:
  80. *n = 8192;
  81. break;
  82. case 44100:
  83. *n = 12544;
  84. break;
  85. case 48000:
  86. *n = 8192;
  87. break;
  88. case 88200:
  89. *n = 25088;
  90. break;
  91. case 96000:
  92. *n = 16384;
  93. break;
  94. case 176400:
  95. *n = 50176;
  96. break;
  97. case 192000:
  98. *n = 32768;
  99. break;
  100. default:
  101. return -EINVAL;
  102. }
  103. } else {
  104. switch (sample_freq) {
  105. case 32000:
  106. *n = 4096;
  107. break;
  108. case 44100:
  109. *n = 6272;
  110. break;
  111. case 48000:
  112. *n = 6144;
  113. break;
  114. case 88200:
  115. *n = 12544;
  116. break;
  117. case 96000:
  118. *n = 12288;
  119. break;
  120. case 176400:
  121. *n = 25088;
  122. break;
  123. case 192000:
  124. *n = 24576;
  125. break;
  126. default:
  127. return -EINVAL;
  128. }
  129. }
  130. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  131. *cts = (pclk/1000) * (*n / 128) * deep_color / (sample_freq / 10);
  132. return 0;
  133. }