hdmi_common.c 2.7 KB

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