[alsa-devel] [PATCH v7 0/9] ASoC: MT8173 HDMI codec support
Since the hdmi-codec patches are now applied [1], I have merged the hdmi-codec interface into the initial MT8173 HDMI [2] driver submission. This series now only enables the HDMI dai-links in the mt8173-rt5650-rt5676 and mt8173-rt5650 machine drivers and adds hdmi-codec ELD support and the still up in the air hdmi notifications between DRM encoder driver and hdmi-codec.
Changes since v6: - Dropped "drm/mediatek: hdmi: Add audio interface to the hdmi-codec driver", patch now merged into MT8173 HDMI encoder patch. - Fixed jack detection in case HDMI is already connected at boot and the hdmi-codec driver registers the notifier block after the HDMI_CONNECTED notification is issued.
[1] commit 09184118a8ab ("ASoC: hdmi-codec: Add hdmi-codec for external HDMI-encoders") of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git topic/hdmi The mediatek drm patches apply on top of [2] https://patchwork.kernel.org/patch/8887051/ ("drm/mediatek: Add HDMI support") and need this patch: [3] https://patchwork.kernel.org/patch/8091531/ ("video: hdmi: add helper function for N and CTS")
regards Philipp
Koro Chen (1): ASoC: mediatek: Add HDMI dai-links in the mt8173-rt5650-rt5676 machine driver
PC Liao (1): ASoC: mediatek: Add HDMI dai-links to the mt8173-rt5650 machine driver
Philipp Zabel (7): ASoC: hdmi-codec: Add ELD control video: rmk's HDMI notification prototype ASoC: hdmi-codec: Use HDMI notifications to add jack support ASoC: mediatek: Add jack detection support to mt8173-rt5650-rt5676 machine driver ASoC: mediatek: Add jack detection support to the mt8173-rt5650 machine driver drm/mediatek: hdmi: issue notifications drm/mediatek: hdmi: use helper function for N and CTS calculation
.../bindings/sound/mt8173-rt5650-rt5676.txt | 5 +- .../devicetree/bindings/sound/mt8173-rt5650.txt | 5 +- drivers/gpu/drm/mediatek/mtk_cec.c | 11 ++ drivers/gpu/drm/mediatek/mtk_hdmi.c | 88 ++++----------- drivers/video/Kconfig | 3 + drivers/video/Makefile | 1 + drivers/video/hdmi-notifier.c | 61 ++++++++++ include/linux/hdmi-notifier.h | 44 ++++++++ include/sound/hdmi-codec.h | 6 + sound/soc/codecs/Kconfig | 1 + sound/soc/codecs/hdmi-codec.c | 124 +++++++++++++++++++-- sound/soc/mediatek/Kconfig | 2 + sound/soc/mediatek/mt8173-rt5650-rt5676.c | 48 ++++++++ sound/soc/mediatek/mt8173-rt5650.c | 47 ++++++++ 14 files changed, 370 insertions(+), 76 deletions(-) create mode 100644 drivers/video/hdmi-notifier.c create mode 100644 include/linux/hdmi-notifier.h
From: Koro Chen koro.chen@mediatek.com
This creates pcmC0D2p for the HDMI playback in the same card.
Signed-off-by: Koro Chen koro.chen@mediatek.com Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- .../bindings/sound/mt8173-rt5650-rt5676.txt | 5 ++-- sound/soc/mediatek/Kconfig | 1 + sound/soc/mediatek/mt8173-rt5650-rt5676.c | 27 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt b/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt index f205ce9..ac28cdb 100644 --- a/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt +++ b/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt @@ -1,15 +1,16 @@ -MT8173 with RT5650 RT5676 CODECS +MT8173 with RT5650 RT5676 CODECS and HDMI via I2S
Required properties: - compatible : "mediatek,mt8173-rt5650-rt5676" - mediatek,audio-codec: the phandles of rt5650 and rt5676 codecs + and of the hdmi encoder node - mediatek,platform: the phandle of MT8173 ASoC platform
Example:
sound { compatible = "mediatek,mt8173-rt5650-rt5676"; - mediatek,audio-codec = <&rt5650 &rt5676>; + mediatek,audio-codec = <&rt5650 &rt5676 &hdmi0>; mediatek,platform = <&afe>; };
diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig index f7e789e..3abf51c 100644 --- a/sound/soc/mediatek/Kconfig +++ b/sound/soc/mediatek/Kconfig @@ -43,6 +43,7 @@ config SND_SOC_MT8173_RT5650_RT5676 depends on SND_SOC_MEDIATEK && I2C select SND_SOC_RT5645 select SND_SOC_RT5677 + select SND_SOC_HDMI_CODEC help This adds ASoC driver for Mediatek MT8173 boards with the RT5650 and RT5676 codecs. diff --git a/sound/soc/mediatek/mt8173-rt5650-rt5676.c b/sound/soc/mediatek/mt8173-rt5650-rt5676.c index 5c4c58c..bb59392 100644 --- a/sound/soc/mediatek/mt8173-rt5650-rt5676.c +++ b/sound/soc/mediatek/mt8173-rt5650-rt5676.c @@ -134,7 +134,9 @@ static struct snd_soc_dai_link_component mt8173_rt5650_rt5676_codecs[] = { enum { DAI_LINK_PLAYBACK, DAI_LINK_CAPTURE, + DAI_LINK_HDMI, DAI_LINK_CODEC_I2S, + DAI_LINK_HDMI_I2S, DAI_LINK_INTERCODEC };
@@ -161,6 +163,16 @@ static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = { .dynamic = 1, .dpcm_capture = 1, }, + [DAI_LINK_HDMI] = { + .name = "HDMI", + .stream_name = "HDMI PCM", + .cpu_dai_name = "HDMI", + .codec_name = "snd-soc-dummy", + .codec_dai_name = "snd-soc-dummy-dai", + .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, + .dynamic = 1, + .dpcm_playback = 1, + },
/* Back End DAI links */ [DAI_LINK_CODEC_I2S] = { @@ -177,6 +189,13 @@ static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = { .dpcm_playback = 1, .dpcm_capture = 1, }, + [DAI_LINK_HDMI_I2S] = { + .name = "HDMI BE", + .cpu_dai_name = "HDMIO", + .no_pcm = 1, + .codec_dai_name = "i2s-hifi", + .dpcm_playback = 1, + }, /* rt5676 <-> rt5650 intercodec link: Sets rt5676 I2S2 as master */ [DAI_LINK_INTERCODEC] = { .name = "rt5650_rt5676 intercodec", @@ -251,6 +270,14 @@ static int mt8173_rt5650_rt5676_dev_probe(struct platform_device *pdev) mt8173_rt5650_rt5676_dais[DAI_LINK_INTERCODEC].codec_of_node = mt8173_rt5650_rt5676_codecs[1].of_node;
+ mt8173_rt5650_rt5676_dais[DAI_LINK_HDMI_I2S].codec_of_node = + of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 2); + if (!mt8173_rt5650_rt5676_dais[DAI_LINK_HDMI_I2S].codec_of_node) { + dev_err(&pdev->dev, + "Property 'audio-codec' missing or invalid\n"); + return -EINVAL; + } + card->dev = &pdev->dev; platform_set_drvdata(pdev, card);
From: PC Liao pc.liao@mediatek.com
This patch adds HDMI audio output support to the MT8173 RT5650 machine driver.
Signed-off-by: PC Liao pc.liao@mediatek.com Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- .../devicetree/bindings/sound/mt8173-rt5650.txt | 5 +++-- sound/soc/mediatek/Kconfig | 1 + sound/soc/mediatek/mt8173-rt5650.c | 26 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt b/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt index fe5a5ef..6b182c4 100644 --- a/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt +++ b/Documentation/devicetree/bindings/sound/mt8173-rt5650.txt @@ -1,15 +1,16 @@ -MT8173 with RT5650 CODECS +MT8173 with RT5650 CODECS and HDMI via I2S
Required properties: - compatible : "mediatek,mt8173-rt5650" - mediatek,audio-codec: the phandles of rt5650 codecs + and of the hdmi encoder node - mediatek,platform: the phandle of MT8173 ASoC platform
Example:
sound { compatible = "mediatek,mt8173-rt5650"; - mediatek,audio-codec = <&rt5650>; + mediatek,audio-codec = <&rt5650 &hdmi0>; mediatek,platform = <&afe>; };
diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig index 3abf51c..4536e6a 100644 --- a/sound/soc/mediatek/Kconfig +++ b/sound/soc/mediatek/Kconfig @@ -21,6 +21,7 @@ config SND_SOC_MT8173_RT5650 tristate "ASoC Audio driver for MT8173 with RT5650 codec" depends on SND_SOC_MEDIATEK && I2C select SND_SOC_RT5645 + select SND_SOC_HDMI_CODEC help This adds ASoC driver for Mediatek MT8173 boards with the RT5650 audio codec. diff --git a/sound/soc/mediatek/mt8173-rt5650.c b/sound/soc/mediatek/mt8173-rt5650.c index bb09bb1..0bd8324 100644 --- a/sound/soc/mediatek/mt8173-rt5650.c +++ b/sound/soc/mediatek/mt8173-rt5650.c @@ -117,7 +117,9 @@ static struct snd_soc_dai_link_component mt8173_rt5650_codecs[] = { enum { DAI_LINK_PLAYBACK, DAI_LINK_CAPTURE, + DAI_LINK_HDMI, DAI_LINK_CODEC_I2S, + DAI_LINK_HDMI_I2S, };
/* Digital audio interface glue - connects codec <---> CPU */ @@ -143,6 +145,16 @@ static struct snd_soc_dai_link mt8173_rt5650_dais[] = { .dynamic = 1, .dpcm_capture = 1, }, + [DAI_LINK_HDMI] = { + .name = "HDMI", + .stream_name = "HDMI PCM", + .cpu_dai_name = "HDMI", + .codec_name = "snd-soc-dummy", + .codec_dai_name = "snd-soc-dummy-dai", + .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, + .dynamic = 1, + .dpcm_playback = 1, + }, /* Back End DAI links */ [DAI_LINK_CODEC_I2S] = { .name = "Codec", @@ -158,6 +170,13 @@ static struct snd_soc_dai_link mt8173_rt5650_dais[] = { .dpcm_playback = 1, .dpcm_capture = 1, }, + [DAI_LINK_HDMI_I2S] = { + .name = "HDMI BE", + .cpu_dai_name = "HDMIO", + .no_pcm = 1, + .codec_dai_name = "i2s-hifi", + .dpcm_playback = 1, + }, };
static struct snd_soc_card mt8173_rt5650_card = { @@ -199,6 +218,13 @@ static int mt8173_rt5650_dev_probe(struct platform_device *pdev) "Property 'audio-codec' missing or invalid\n"); return -EINVAL; } + mt8173_rt5650_dais[DAI_LINK_HDMI_I2S].codec_of_node = + of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 1); + if (!mt8173_rt5650_dais[DAI_LINK_HDMI_I2S].codec_of_node) { + dev_err(&pdev->dev, + "Property 'audio-codec' missing or invalid\n"); + return -EINVAL; + } card->dev = &pdev->dev; platform_set_drvdata(pdev, card);
On Wed, Apr 20, 2016 at 10:59:57AM +0200, Philipp Zabel wrote:
From: PC Liao pc.liao@mediatek.com
This patch adds HDMI audio output support to the MT8173 RT5650 machine driver.
This doesn't apply against current code, please check and resend.
ALSA doesn't know about all the different compressed audio formats, so there is no interface to let userspace enumerate the formats that are supported by the connected sink. Exporting the raw ELD bytes to userspace allows an application to select the appropriate audio format depending on the current capabilities of the connected HDMI sink device. Usually userspace then just pretends to ALSA that the data is in one of the raw 16-bit PCM audio formats and relies on the IEC controls to tell the sink how to interpret the data.
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de Reviewed-by: Jyri Sarha jsarha@ti.com Tested-by: Jyri Sarha jsarha@ti.com --- sound/soc/codecs/hdmi-codec.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index b46b8ed..c78333b 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -47,6 +47,42 @@ enum { DAI_ID_SPDIF, };
+static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; + uinfo->count = sizeof(hcp->eld); + + return 0; +} + +static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + + mutex_lock(&hcp->eld_lock); + memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); + mutex_unlock(&hcp->eld_lock); + + return 0; +} + +static const struct snd_kcontrol_new hdmi_controls[] = { + { + .access = SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = "ELD", + .info = hdmi_eld_ctl_info, + .get = hdmi_eld_ctl_get, + }, +}; + static int hdmi_codec_new_stream(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { @@ -312,6 +348,8 @@ static const struct snd_soc_dai_driver hdmi_spdif_dai = { };
static struct snd_soc_codec_driver hdmi_codec = { + .controls = hdmi_controls, + .num_controls = ARRAY_SIZE(hdmi_controls), .dapm_widgets = hdmi_widgets, .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), .dapm_routes = hdmi_routes,
The patch
ASoC: hdmi-codec: Add ELD control
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 81151cfb6bfe69f1c5a52b795eb005226a322c9e Mon Sep 17 00:00:00 2001
From: Philipp Zabel p.zabel@pengutronix.de Date: Wed, 20 Apr 2016 10:59:58 +0200 Subject: [PATCH] ASoC: hdmi-codec: Add ELD control
ALSA doesn't know about all the different compressed audio formats, so there is no interface to let userspace enumerate the formats that are supported by the connected sink. Exporting the raw ELD bytes to userspace allows an application to select the appropriate audio format depending on the current capabilities of the connected HDMI sink device. Usually userspace then just pretends to ALSA that the data is in one of the raw 16-bit PCM audio formats and relies on the IEC controls to tell the sink how to interpret the data.
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de Reviewed-by: Jyri Sarha jsarha@ti.com Tested-by: Jyri Sarha jsarha@ti.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/codecs/hdmi-codec.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index b46b8edb9319..c78333b4311d 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -47,6 +47,42 @@ enum { DAI_ID_SPDIF, };
+static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; + uinfo->count = sizeof(hcp->eld); + + return 0; +} + +static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + + mutex_lock(&hcp->eld_lock); + memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); + mutex_unlock(&hcp->eld_lock); + + return 0; +} + +static const struct snd_kcontrol_new hdmi_controls[] = { + { + .access = SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = "ELD", + .info = hdmi_eld_ctl_info, + .get = hdmi_eld_ctl_get, + }, +}; + static int hdmi_codec_new_stream(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { @@ -312,6 +348,8 @@ static const struct snd_soc_dai_driver hdmi_spdif_dai = { };
static struct snd_soc_codec_driver hdmi_codec = { + .controls = hdmi_controls, + .num_controls = ARRAY_SIZE(hdmi_controls), .dapm_widgets = hdmi_widgets, .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), .dapm_routes = hdmi_routes,
It would have been good to have this as a generic ALSA control rather than an ASoC control. The dw-hdmi driver is an ALSA driver, and now we have to re-invent this for ALSA...
On Thu, Apr 21, 2016 at 05:18:23PM +0100, Mark Brown wrote:
The patch
ASoC: hdmi-codec: Add ELD control
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 81151cfb6bfe69f1c5a52b795eb005226a322c9e Mon Sep 17 00:00:00 2001
From: Philipp Zabel p.zabel@pengutronix.de Date: Wed, 20 Apr 2016 10:59:58 +0200 Subject: [PATCH] ASoC: hdmi-codec: Add ELD control
ALSA doesn't know about all the different compressed audio formats, so there is no interface to let userspace enumerate the formats that are supported by the connected sink. Exporting the raw ELD bytes to userspace allows an application to select the appropriate audio format depending on the current capabilities of the connected HDMI sink device. Usually userspace then just pretends to ALSA that the data is in one of the raw 16-bit PCM audio formats and relies on the IEC controls to tell the sink how to interpret the data.
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de Reviewed-by: Jyri Sarha jsarha@ti.com Tested-by: Jyri Sarha jsarha@ti.com Signed-off-by: Mark Brown broonie@kernel.org
sound/soc/codecs/hdmi-codec.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index b46b8edb9319..c78333b4311d 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -47,6 +47,42 @@ enum { DAI_ID_SPDIF, };
+static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo)
+{
- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
- struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
- uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
- uinfo->count = sizeof(hcp->eld);
- return 0;
+}
+static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
+{
- struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
- struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
- mutex_lock(&hcp->eld_lock);
- memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld));
- mutex_unlock(&hcp->eld_lock);
- return 0;
+}
+static const struct snd_kcontrol_new hdmi_controls[] = {
- {
.access = SNDRV_CTL_ELEM_ACCESS_READ |
SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "ELD",
.info = hdmi_eld_ctl_info,
.get = hdmi_eld_ctl_get,
- },
+};
static int hdmi_codec_new_stream(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { @@ -312,6 +348,8 @@ static const struct snd_soc_dai_driver hdmi_spdif_dai = { };
static struct snd_soc_codec_driver hdmi_codec = {
- .controls = hdmi_controls,
- .num_controls = ARRAY_SIZE(hdmi_controls), .dapm_widgets = hdmi_widgets, .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), .dapm_routes = hdmi_routes,
-- 2.8.0.rc3
On Wed, Apr 27, 2016 at 10:42:19AM +0100, Russell King - ARM Linux wrote:
It would have been good to have this as a generic ALSA control rather than an ASoC control. The dw-hdmi driver is an ALSA driver, and now we have to re-invent this for ALSA...
We can always just incrementally move the code to the ALSA top level, though it's so thin that I'm not sure it's really buying much.
This is Russell's HDMI notification prototype [1], currently waiting for the HDMI CEC situation to resolve.
The use case for the notifications on MediaTek MT8173 is to let the (dis)connection notifications control an ALSA jack object.
No Signed-off-by since this is not my code, and still up for discussion.
[1] https://patchwork.kernel.org/patch/8351501/ --- drivers/video/Kconfig | 3 +++ drivers/video/Makefile | 1 + drivers/video/hdmi-notifier.c | 61 +++++++++++++++++++++++++++++++++++++++++++ include/linux/hdmi-notifier.h | 44 +++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 drivers/video/hdmi-notifier.c create mode 100644 include/linux/hdmi-notifier.h
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index e0606c0..193649c 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -40,6 +40,9 @@ config VIDEOMODE_HELPERS config HDMI bool
+config HDMI_NOTIFIERS + bool + if VT source "drivers/video/console/Kconfig" endif diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 9ad3c17..65f5649 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_VGASTATE) += vgastate.o obj-$(CONFIG_HDMI) += hdmi.o +obj-$(CONFIG_HDMI_NOTIFIERS) += hdmi-notifier.o
obj-$(CONFIG_VT) += console/ obj-$(CONFIG_LOGO) += logo/ diff --git a/drivers/video/hdmi-notifier.c b/drivers/video/hdmi-notifier.c new file mode 100644 index 0000000..a233359 --- /dev/null +++ b/drivers/video/hdmi-notifier.c @@ -0,0 +1,61 @@ +#include <linux/export.h> +#include <linux/hdmi-notifier.h> +#include <linux/notifier.h> +#include <linux/string.h> + +static BLOCKING_NOTIFIER_HEAD(hdmi_notifier); + +int hdmi_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&hdmi_notifier, nb); +} +EXPORT_SYMBOL_GPL(hdmi_register_notifier); + +int hdmi_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&hdmi_notifier, nb); +} +EXPORT_SYMBOL_GPL(hdmi_unregister_notifier); + +void hdmi_event_connect(struct device *dev) +{ + struct hdmi_event_base base; + + base.source = dev; + + blocking_notifier_call_chain(&hdmi_notifier, HDMI_CONNECTED, &base); +} +EXPORT_SYMBOL_GPL(hdmi_event_connect); + +void hdmi_event_disconnect(struct device *dev) +{ + struct hdmi_event_base base; + + base.source = dev; + + blocking_notifier_call_chain(&hdmi_notifier, HDMI_DISCONNECTED, &base); +} +EXPORT_SYMBOL_GPL(hdmi_event_disconnect); + +void hdmi_event_new_edid(struct device *dev, const void *edid, size_t size) +{ + struct hdmi_event_new_edid new_edid; + + new_edid.base.source = dev; + new_edid.edid = edid; + new_edid.size = size; + + blocking_notifier_call_chain(&hdmi_notifier, HDMI_NEW_EDID, &new_edid); +} +EXPORT_SYMBOL_GPL(hdmi_event_new_edid); + +void hdmi_event_new_eld(struct device *dev, const void *eld) +{ + struct hdmi_event_new_eld new_eld; + + new_eld.base.source = dev; + memcpy(new_eld.eld, eld, sizeof(new_eld.eld)); + + blocking_notifier_call_chain(&hdmi_notifier, HDMI_NEW_ELD, &new_eld); +} +EXPORT_SYMBOL_GPL(hdmi_event_new_eld); diff --git a/include/linux/hdmi-notifier.h b/include/linux/hdmi-notifier.h new file mode 100644 index 0000000..9c5ad49 --- /dev/null +++ b/include/linux/hdmi-notifier.h @@ -0,0 +1,44 @@ +#ifndef LINUX_HDMI_NOTIFIER_H +#define LINUX_HDMI_NOTIFIER_H + +#include <linux/types.h> + +enum { + HDMI_CONNECTED, + HDMI_DISCONNECTED, + HDMI_NEW_EDID, + HDMI_NEW_ELD, +}; + +struct hdmi_event_base { + struct device *source; +}; + +struct hdmi_event_new_edid { + struct hdmi_event_base base; + const void *edid; + size_t size; +}; + +struct hdmi_event_new_eld { + struct hdmi_event_base base; + unsigned char eld[128]; +}; + +union hdmi_event { + struct hdmi_event_base base; + struct hdmi_event_new_edid edid; + struct hdmi_event_new_eld eld; +}; + +struct notifier_block; + +int hdmi_register_notifier(struct notifier_block *nb); +int hdmi_unregister_notifier(struct notifier_block *nb); + +void hdmi_event_connect(struct device *dev); +void hdmi_event_disconnect(struct device *dev); +void hdmi_event_new_edid(struct device *dev, const void *edid, size_t size); +void hdmi_event_new_eld(struct device *dev, const void *eld); + +#endif
Use HDMI connection / disconnection notifications to update an ALSA jack object. Also make a copy of the ELD block after every change.
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- Changes since v6: - Also issue a jack connection report on HDMI_NEW_ELD, in case the preceding HDMI_CONNECTED was missed, for example because it was issued before hdmi-codec registered the notifier. --- include/sound/hdmi-codec.h | 6 +++ sound/soc/codecs/Kconfig | 1 + sound/soc/codecs/hdmi-codec.c | 86 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 85 insertions(+), 8 deletions(-)
diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h index fc3a481..9265a90 100644 --- a/include/sound/hdmi-codec.h +++ b/include/sound/hdmi-codec.h @@ -95,6 +95,12 @@ struct hdmi_codec_pdata { int max_i2s_channels; };
+struct snd_soc_codec; +struct snd_soc_jack; + +int hdmi_codec_set_jack_detect(struct snd_soc_codec *codec, + struct snd_soc_jack *jack); + #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec"
#endif /* __HDMI_CODEC_H__ */ diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 06d0e05..b45eaaf 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -480,6 +480,7 @@ config SND_SOC_DMIC
config SND_SOC_HDMI_CODEC tristate + select HDMI_NOTIFIERS select SND_PCM_ELD select SND_PCM_IEC958
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index c78333b..8337389 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -12,9 +12,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ +#include <linux/hdmi-notifier.h> #include <linux/module.h> +#include <linux/notifier.h> #include <linux/string.h> #include <sound/core.h> +#include <sound/jack.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -27,11 +30,16 @@ struct hdmi_codec_priv { struct hdmi_codec_pdata hcd; struct snd_soc_dai_driver *daidrv; + struct snd_soc_jack *jack; struct hdmi_codec_daifmt daifmt[2]; struct mutex current_stream_lock; struct snd_pcm_substream *current_stream; struct snd_pcm_hw_constraint_list ratec; + struct mutex eld_lock; uint8_t eld[MAX_ELD_BYTES]; + struct device *dev; + struct notifier_block nb; + unsigned int jack_status; };
static const struct snd_soc_dapm_widget hdmi_widgets[] = { @@ -105,7 +113,7 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); - int ret = 0; + int ret;
dev_dbg(dai->dev, "%s()\n", __func__);
@@ -124,17 +132,15 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream, }
if (hcp->hcd.ops->get_eld) { + mutex_lock(&hcp->eld_lock); ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->eld, sizeof(hcp->eld)); - - if (!ret) { + if (!ret) ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld); - if (ret) - return ret; - } + mutex_unlock(&hcp->eld_lock); } - return 0; + return ret; }
static void hdmi_codec_shutdown(struct snd_pcm_substream *substream, @@ -356,6 +362,63 @@ static struct snd_soc_codec_driver hdmi_codec = { .num_dapm_routes = ARRAY_SIZE(hdmi_routes), };
+static void hdmi_codec_jack_report(struct hdmi_codec_priv *hcp, + unsigned int jack_status) +{ + if (!hcp->jack) + return; + + if (jack_status != hcp->jack_status) { + snd_soc_jack_report(hcp->jack, jack_status, SND_JACK_LINEOUT); + hcp->jack_status = jack_status; + } +} + +static int hdmi_codec_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct hdmi_codec_priv *hcp = container_of(nb, struct hdmi_codec_priv, + nb); + union hdmi_event *event_block = data; + + if (hcp->dev->parent != event_block->base.source) + return NOTIFY_OK; + + if (!hcp->jack) + return NOTIFY_OK; + + switch (event) { + case HDMI_CONNECTED: + hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT); + break; + case HDMI_DISCONNECTED: + hdmi_codec_jack_report(hcp, 0); + break; + case HDMI_NEW_ELD: + hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT); + mutex_lock(&hcp->eld_lock); + memcpy(hcp->eld, event_block->eld.eld, sizeof(hcp->eld)); + mutex_unlock(&hcp->eld_lock); + break; + } + + return NOTIFY_OK; +} + +int hdmi_codec_set_jack_detect(struct snd_soc_codec *codec, + struct snd_soc_jack *jack) +{ + struct hdmi_codec_priv *hcp = snd_soc_codec_get_drvdata(codec); + + hcp->jack = jack; + hcp->nb.notifier_call = hdmi_codec_notify; + + hdmi_register_notifier(&hcp->nb); + + return 0; +} +EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect); + static int hdmi_codec_probe(struct platform_device *pdev) { struct hdmi_codec_pdata *hcd = pdev->dev.platform_data; @@ -384,6 +447,7 @@ static int hdmi_codec_probe(struct platform_device *pdev)
hcp->hcd = *hcd; mutex_init(&hcp->current_stream_lock); + mutex_init(&hcp->eld_lock);
hcp->daidrv = devm_kzalloc(dev, dai_count * sizeof(*hcp->daidrv), GFP_KERNEL); @@ -400,6 +464,8 @@ static int hdmi_codec_probe(struct platform_device *pdev) if (hcd->spdif) hcp->daidrv[i] = hdmi_spdif_dai;
+ dev_set_drvdata(dev, hcp); + ret = snd_soc_register_codec(dev, &hdmi_codec, hcp->daidrv, dai_count); if (ret) { @@ -408,12 +474,16 @@ static int hdmi_codec_probe(struct platform_device *pdev) return ret; }
- dev_set_drvdata(dev, hcp); + hcp->dev = dev; + return 0; }
static int hdmi_codec_remove(struct platform_device *pdev) { + struct hdmi_codec_priv *hcp = platform_get_drvdata(pdev); + + hdmi_unregister_notifier(&hcp->nb); snd_soc_unregister_codec(&pdev->dev); return 0; }
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- sound/soc/mediatek/mt8173-rt5650-rt5676.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/sound/soc/mediatek/mt8173-rt5650-rt5676.c b/sound/soc/mediatek/mt8173-rt5650-rt5676.c index bb59392..def9d950 100644 --- a/sound/soc/mediatek/mt8173-rt5650-rt5676.c +++ b/sound/soc/mediatek/mt8173-rt5650-rt5676.c @@ -18,6 +18,7 @@ #include <linux/gpio.h> #include <linux/of_gpio.h> #include <sound/soc.h> +#include <sound/hdmi-codec.h> #include <sound/jack.h> #include "../codecs/rt5645.h" #include "../codecs/rt5677.h" @@ -131,6 +132,25 @@ static struct snd_soc_dai_link_component mt8173_rt5650_rt5676_codecs[] = { }, };
+static struct snd_soc_jack mt8173_hdmi_card_jack; + +static int mt8173_hdmi_init(struct snd_soc_pcm_runtime *runtime) +{ + struct snd_soc_card *card = runtime->card; + struct snd_soc_codec *codec = runtime->codec; + int ret; + + /* enable jack detection */ + ret = snd_soc_card_jack_new(card, "HDMI Jack", SND_JACK_LINEOUT, + &mt8173_hdmi_card_jack, NULL, 0); + if (ret) { + dev_err(card->dev, "Can't new HDMI Jack %d\n", ret); + return ret; + } + + return hdmi_codec_set_jack_detect(codec, &mt8173_hdmi_card_jack); +} + enum { DAI_LINK_PLAYBACK, DAI_LINK_CAPTURE, @@ -195,6 +215,7 @@ static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = { .no_pcm = 1, .codec_dai_name = "i2s-hifi", .dpcm_playback = 1, + .init = mt8173_hdmi_init, }, /* rt5676 <-> rt5650 intercodec link: Sets rt5676 I2S2 as master */ [DAI_LINK_INTERCODEC] = {
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- sound/soc/mediatek/mt8173-rt5650.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/sound/soc/mediatek/mt8173-rt5650.c b/sound/soc/mediatek/mt8173-rt5650.c index 0bd8324..55eeca5 100644 --- a/sound/soc/mediatek/mt8173-rt5650.c +++ b/sound/soc/mediatek/mt8173-rt5650.c @@ -18,6 +18,7 @@ #include <linux/gpio.h> #include <linux/of_gpio.h> #include <sound/soc.h> +#include <sound/hdmi-codec.h> #include <sound/jack.h> #include "../codecs/rt5645.h"
@@ -114,6 +115,25 @@ static struct snd_soc_dai_link_component mt8173_rt5650_codecs[] = { }, };
+static struct snd_soc_jack mt8173_hdmi_card_jack; + +static int mt8173_hdmi_init(struct snd_soc_pcm_runtime *runtime) +{ + struct snd_soc_card *card = runtime->card; + struct snd_soc_codec *codec = runtime->codec; + int ret; + + /* enable jack detection */ + ret = snd_soc_card_jack_new(card, "HDMI Jack", SND_JACK_LINEOUT, + &mt8173_hdmi_card_jack, NULL, 0); + if (ret) { + dev_err(card->dev, "Can't new HDMI Jack %d\n", ret); + return ret; + } + + return hdmi_codec_set_jack_detect(codec, &mt8173_hdmi_card_jack); +} + enum { DAI_LINK_PLAYBACK, DAI_LINK_CAPTURE, @@ -176,6 +196,7 @@ static struct snd_soc_dai_link mt8173_rt5650_dais[] = { .no_pcm = 1, .codec_dai_name = "i2s-hifi", .dpcm_playback = 1, + .init = mt8173_hdmi_init, }, };
Issue hot-plug detection, EDID update, and ELD update notifications from the CEC and HDMI drivers.
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- drivers/gpu/drm/mediatek/mtk_cec.c | 11 +++++++++++ drivers/gpu/drm/mediatek/mtk_hdmi.c | 3 +++ 2 files changed, 14 insertions(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_cec.c b/drivers/gpu/drm/mediatek/mtk_cec.c index 7a3eb8c..f78a73c 100644 --- a/drivers/gpu/drm/mediatek/mtk_cec.c +++ b/drivers/gpu/drm/mediatek/mtk_cec.c @@ -13,6 +13,7 @@ */ #include <linux/clk.h> #include <linux/delay.h> +#include <linux/hdmi-notifier.h> #include <linux/io.h> #include <linux/interrupt.h> #include <linux/platform_device.h> @@ -105,6 +106,12 @@ void mtk_cec_set_hpd_event(struct device *dev, cec->hdmi_dev = hdmi_dev; cec->hpd_event = hpd_event; spin_unlock_irqrestore(&cec->lock, flags); + + /* Initial notification event to set jack state */ + if (mtk_cec_hpd_high(dev)) + hdmi_event_connect(hdmi_dev); + else + hdmi_event_disconnect(hdmi_dev); }
bool mtk_cec_hpd_high(struct device *dev) @@ -179,6 +186,10 @@ static irqreturn_t mtk_cec_htplg_isr_thread(int irq, void *arg) if (cec->hpd != hpd) { dev_dbg(dev, "hotplug event! cur hpd = %d, hpd = %d\n", cec->hpd, hpd); + if (hpd) + hdmi_event_connect(cec->hdmi_dev); + else + hdmi_event_disconnect(cec->hdmi_dev); cec->hpd = hpd; mtk_cec_hpd_event(cec, hpd); } diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index 21ea430..06e3811 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -20,6 +20,7 @@ #include <linux/clk.h> #include <linux/delay.h> #include <linux/hdmi.h> +#include <linux/hdmi-notifier.h> #include <linux/i2c.h> #include <linux/io.h> #include <linux/kernel.h> @@ -1226,9 +1227,11 @@ static int mtk_hdmi_conn_get_modes(struct drm_connector *conn) hdmi->dvi_mode = !drm_detect_monitor_audio(edid);
drm_mode_connector_update_edid_property(conn, edid); + hdmi_event_new_edid(hdmi->dev, edid, sizeof(*edid));
ret = drm_add_edid_modes(conn, edid); drm_edid_to_eld(conn, edid); + hdmi_event_new_eld(hdmi->dev, conn->eld); kfree(edid); return ret; }
Use the hdmi helper function [1] to calculate N and CTS.
[1] https://patchwork.kernel.org/patch/8091531/ ("video: hdmi: add helper function for N and CTS")
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de --- drivers/gpu/drm/mediatek/mtk_hdmi.c | 85 +++++++++---------------------------- 1 file changed, 21 insertions(+), 64 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index 06e3811..da6edef 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -656,65 +656,6 @@ static const struct hdmi_acr_n hdmi_rec_n_table[] = { { 0, { 4096, 6272, 6144 } }, /* all other TMDS clocks */ };
-/** - * hdmi_recommended_n() - Return N value recommended by HDMI specification - * @freq: audio sample rate in Hz - * @clock: rounded TMDS clock in kHz - */ -static unsigned int hdmi_recommended_n(unsigned int freq, unsigned int clock) -{ - const struct hdmi_acr_n *recommended; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(hdmi_rec_n_table) - 1; i++) { - if (clock == hdmi_rec_n_table[i].clock) - break; - } - recommended = hdmi_rec_n_table + i; - - switch (freq) { - case 32000: - return recommended->n[0]; - case 44100: - return recommended->n[1]; - case 48000: - return recommended->n[2]; - case 88200: - return recommended->n[1] * 2; - case 96000: - return recommended->n[2] * 2; - case 176400: - return recommended->n[1] * 4; - case 192000: - return recommended->n[2] * 4; - default: - return (128 * freq) / 1000; - } -} - -static unsigned int hdmi_mode_clock_to_hz(unsigned int clock) -{ - switch (clock) { - case 25175: - return 25174825; /* 25.2/1.001 MHz */ - case 74176: - return 74175824; /* 74.25/1.001 MHz */ - case 148352: - return 148351648; /* 148.5/1.001 MHz */ - case 296703: - return 296703297; /* 297/1.001 MHz */ - default: - return clock * 1000; - } -} - -static unsigned int hdmi_expected_cts(unsigned int audio_sample_rate, - unsigned int tmds_clock, unsigned int n) -{ - return DIV_ROUND_CLOSEST_ULL((u64)hdmi_mode_clock_to_hz(tmds_clock) * n, - 128 * audio_sample_rate); -} - static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n, unsigned int cts) { @@ -739,21 +680,37 @@ static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n, mtk_hdmi_write(hdmi, GRL_NCTS, val[i]); }
+static unsigned int hdmi_mode_clock_to_hz(unsigned int clock) +{ + switch (clock) { + case 25175: + return 25174825; /* 25.2/1.001 MHz */ + case 74176: + return 74175824; /* 74.25/1.001 MHz */ + case 148352: + return 148351648; /* 148.5/1.001 MHz */ + case 296703: + return 296703296; /* 297/1.001 MHz */ + default: + return clock * 1000; + } +} + static void mtk_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int sample_rate, unsigned int clock) { - unsigned int n, cts; + struct hdmi_audio_n_cts n_cts;
- n = hdmi_recommended_n(sample_rate, clock); - cts = hdmi_expected_cts(sample_rate, clock, n); + hdmi_audio_get_coherent_n_cts(sample_rate, hdmi_mode_clock_to_hz(clock), + &n_cts);
dev_dbg(hdmi->dev, "%s: sample_rate=%u, clock=%d, cts=%u, n=%u\n", - __func__, sample_rate, clock, n, cts); + __func__, sample_rate, clock, n_cts.cts, n_cts.n);
mtk_hdmi_mask(hdmi, DUMMY_304, AUDIO_I2S_NCTS_SEL_64, AUDIO_I2S_NCTS_SEL); - do_hdmi_hw_aud_set_ncts(hdmi, n, cts); + do_hdmi_hw_aud_set_ncts(hdmi, n_cts.n, n_cts.cts); }
static u8 mtk_hdmi_aud_get_chnl_count(enum hdmi_aud_channel_type channel_type)
Hello Philipp,
FYI, i'm currently finalizing a new version of the helper function with minor updates ( typo and code optimization), i should send it tomorrow.
Regards Arnaud
On 04/20/2016 11:00 AM, Philipp Zabel wrote:
Use the hdmi helper function [1] to calculate N and CTS.
[1] https://patchwork.kernel.org/patch/8091531/ ("video: hdmi: add helper function for N and CTS")
Signed-off-by: Philipp Zabel p.zabel@pengutronix.de
drivers/gpu/drm/mediatek/mtk_hdmi.c | 85 +++++++++---------------------------- 1 file changed, 21 insertions(+), 64 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index 06e3811..da6edef 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -656,65 +656,6 @@ static const struct hdmi_acr_n hdmi_rec_n_table[] = { { 0, { 4096, 6272, 6144 } }, /* all other TMDS clocks */ };
-/**
- hdmi_recommended_n() - Return N value recommended by HDMI specification
- @freq: audio sample rate in Hz
- @clock: rounded TMDS clock in kHz
- */
-static unsigned int hdmi_recommended_n(unsigned int freq, unsigned int clock) -{
- const struct hdmi_acr_n *recommended;
- unsigned int i;
- for (i = 0; i < ARRAY_SIZE(hdmi_rec_n_table) - 1; i++) {
if (clock == hdmi_rec_n_table[i].clock)
break;
- }
- recommended = hdmi_rec_n_table + i;
- switch (freq) {
- case 32000:
return recommended->n[0];
- case 44100:
return recommended->n[1];
- case 48000:
return recommended->n[2];
- case 88200:
return recommended->n[1] * 2;
- case 96000:
return recommended->n[2] * 2;
- case 176400:
return recommended->n[1] * 4;
- case 192000:
return recommended->n[2] * 4;
- default:
return (128 * freq) / 1000;
- }
-}
-static unsigned int hdmi_mode_clock_to_hz(unsigned int clock) -{
- switch (clock) {
- case 25175:
return 25174825; /* 25.2/1.001 MHz */
- case 74176:
return 74175824; /* 74.25/1.001 MHz */
- case 148352:
return 148351648; /* 148.5/1.001 MHz */
- case 296703:
return 296703297; /* 297/1.001 MHz */
- default:
return clock * 1000;
- }
-}
-static unsigned int hdmi_expected_cts(unsigned int audio_sample_rate,
unsigned int tmds_clock, unsigned int n)
-{
- return DIV_ROUND_CLOSEST_ULL((u64)hdmi_mode_clock_to_hz(tmds_clock) * n,
128 * audio_sample_rate);
-}
static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n, unsigned int cts) { @@ -739,21 +680,37 @@ static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n, mtk_hdmi_write(hdmi, GRL_NCTS, val[i]); }
+static unsigned int hdmi_mode_clock_to_hz(unsigned int clock) +{
- switch (clock) {
- case 25175:
return 25174825; /* 25.2/1.001 MHz */
- case 74176:
return 74175824; /* 74.25/1.001 MHz */
- case 148352:
return 148351648; /* 148.5/1.001 MHz */
- case 296703:
return 296703296; /* 297/1.001 MHz */
- default:
return clock * 1000;
- }
+}
static void mtk_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int sample_rate, unsigned int clock) {
- unsigned int n, cts;
- struct hdmi_audio_n_cts n_cts;
- n = hdmi_recommended_n(sample_rate, clock);
- cts = hdmi_expected_cts(sample_rate, clock, n);
hdmi_audio_get_coherent_n_cts(sample_rate, hdmi_mode_clock_to_hz(clock),
&n_cts);
dev_dbg(hdmi->dev, "%s: sample_rate=%u, clock=%d, cts=%u, n=%u\n",
__func__, sample_rate, clock, n, cts);
__func__, sample_rate, clock, n_cts.cts, n_cts.n);
mtk_hdmi_mask(hdmi, DUMMY_304, AUDIO_I2S_NCTS_SEL_64, AUDIO_I2S_NCTS_SEL);
- do_hdmi_hw_aud_set_ncts(hdmi, n, cts);
- do_hdmi_hw_aud_set_ncts(hdmi, n_cts.n, n_cts.cts);
}
static u8 mtk_hdmi_aud_get_chnl_count(enum hdmi_aud_channel_type channel_type)
participants (4)
-
Arnaud Pouliquen
-
Mark Brown
-
Philipp Zabel
-
Russell King - ARM Linux