Linux Audio

Check our new training course

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