Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #define DSS_SUBSYS_NAME "HDMI"
0004 
0005 #include <linux/kernel.h>
0006 #include <linux/err.h>
0007 #include <linux/of.h>
0008 #include <video/omapfb_dss.h>
0009 
0010 #include "hdmi.h"
0011 
0012 int hdmi_parse_lanes_of(struct platform_device *pdev, struct device_node *ep,
0013     struct hdmi_phy_data *phy)
0014 {
0015     struct property *prop;
0016     int r, len;
0017 
0018     prop = of_find_property(ep, "lanes", &len);
0019     if (prop) {
0020         u32 lanes[8];
0021 
0022         if (len / sizeof(u32) != ARRAY_SIZE(lanes)) {
0023             dev_err(&pdev->dev, "bad number of lanes\n");
0024             return -EINVAL;
0025         }
0026 
0027         r = of_property_read_u32_array(ep, "lanes", lanes,
0028             ARRAY_SIZE(lanes));
0029         if (r) {
0030             dev_err(&pdev->dev, "failed to read lane data\n");
0031             return r;
0032         }
0033 
0034         r = hdmi_phy_parse_lanes(phy, lanes);
0035         if (r) {
0036             dev_err(&pdev->dev, "failed to parse lane data\n");
0037             return r;
0038         }
0039     } else {
0040         static const u32 default_lanes[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
0041 
0042         r = hdmi_phy_parse_lanes(phy, default_lanes);
0043         if (WARN_ON(r)) {
0044             dev_err(&pdev->dev, "failed to parse lane data\n");
0045             return r;
0046         }
0047     }
0048 
0049     return 0;
0050 }
0051 
0052 int hdmi_compute_acr(u32 pclk, u32 sample_freq, u32 *n, u32 *cts)
0053 {
0054     u32 deep_color;
0055     bool deep_color_correct = false;
0056 
0057     if (n == NULL || cts == NULL)
0058         return -EINVAL;
0059 
0060     /* TODO: When implemented, query deep color mode here. */
0061     deep_color = 100;
0062 
0063     /*
0064      * When using deep color, the default N value (as in the HDMI
0065      * specification) yields to an non-integer CTS. Hence, we
0066      * modify it while keeping the restrictions described in
0067      * section 7.2.1 of the HDMI 1.4a specification.
0068      */
0069     switch (sample_freq) {
0070     case 32000:
0071     case 48000:
0072     case 96000:
0073     case 192000:
0074         if (deep_color == 125)
0075             if (pclk == 27027000 || pclk == 74250000)
0076                 deep_color_correct = true;
0077         if (deep_color == 150)
0078             if (pclk == 27027000)
0079                 deep_color_correct = true;
0080         break;
0081     case 44100:
0082     case 88200:
0083     case 176400:
0084         if (deep_color == 125)
0085             if (pclk == 27027000)
0086                 deep_color_correct = true;
0087         break;
0088     default:
0089         return -EINVAL;
0090     }
0091 
0092     if (deep_color_correct) {
0093         switch (sample_freq) {
0094         case 32000:
0095             *n = 8192;
0096             break;
0097         case 44100:
0098             *n = 12544;
0099             break;
0100         case 48000:
0101             *n = 8192;
0102             break;
0103         case 88200:
0104             *n = 25088;
0105             break;
0106         case 96000:
0107             *n = 16384;
0108             break;
0109         case 176400:
0110             *n = 50176;
0111             break;
0112         case 192000:
0113             *n = 32768;
0114             break;
0115         default:
0116             return -EINVAL;
0117         }
0118     } else {
0119         switch (sample_freq) {
0120         case 32000:
0121             *n = 4096;
0122             break;
0123         case 44100:
0124             *n = 6272;
0125             break;
0126         case 48000:
0127             *n = 6144;
0128             break;
0129         case 88200:
0130             *n = 12544;
0131             break;
0132         case 96000:
0133             *n = 12288;
0134             break;
0135         case 176400:
0136             *n = 25088;
0137             break;
0138         case 192000:
0139             *n = 24576;
0140             break;
0141         default:
0142             return -EINVAL;
0143         }
0144     }
0145     /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
0146     *cts = (pclk/1000) * (*n / 128) * deep_color / (sample_freq / 10);
0147 
0148     return 0;
0149 }