Skip to content

Commit

Permalink
DAC & HDMI audio
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan authored and Alan committed May 6, 2023
1 parent 98f42d0 commit 99a7ebc
Show file tree
Hide file tree
Showing 13 changed files with 4,651 additions and 6 deletions.
22 changes: 16 additions & 6 deletions drivers/clk/sunxi-ng/ccu-sun50i-h616.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,21 @@ static struct ccu_nkmp pll_de_clk = {
* This clashes with our fixed PLL_POST_DIV_P.
*/
#define SUN50I_H616_PLL_AUDIO_REG 0x078

static struct ccu_sdm_setting pll_audio_sdm_table[] = {
{ .rate = 90316800, .pattern = 0xc001288d, .m = 3, .n = 22 },
{ .rate = 98304000, .pattern = 0xc001eb85, .m = 5, .n = 40 },
};

static struct ccu_nm pll_audio_hs_clk = {
.enable = BIT(31),
.lock = BIT(28),
.n = _SUNXI_CCU_MULT_MIN(8, 8, 12),
.m = _SUNXI_CCU_DIV(1, 1), /* input divider */
.m = _SUNXI_CCU_DIV(16, 6),
.sdm = _SUNXI_CCU_SDM(pll_audio_sdm_table,
BIT(24), 0x178, BIT(31)),
.common = {
.features = CCU_FEATURE_SIGMA_DELTA_MOD,
.reg = 0x078,
.hw.init = CLK_HW_INIT("pll-audio-hs", "osc24M",
&ccu_nm_ops,
Expand Down Expand Up @@ -688,13 +697,13 @@ static const struct clk_hw *clk_parent_pll_audio[] = {
*/
static CLK_FIXED_FACTOR_HWS(pll_audio_1x_clk, "pll-audio-1x",
clk_parent_pll_audio,
96, 1, CLK_SET_RATE_PARENT);
4, 1, CLK_SET_RATE_PARENT);
static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
clk_parent_pll_audio,
48, 1, CLK_SET_RATE_PARENT);
2, 1, CLK_SET_RATE_PARENT);
static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
clk_parent_pll_audio,
24, 1, CLK_SET_RATE_PARENT);
1, 1, CLK_SET_RATE_PARENT);

static const struct clk_hw *pll_periph0_parents[] = {
&pll_periph0_clk.common.hw
Expand Down Expand Up @@ -1135,8 +1144,9 @@ static int sun50i_h616_ccu_probe(struct platform_device *pdev)
* of it to 2, so 24576000 and 22579200 rates can be set exactly.
*/
val = readl(reg + SUN50I_H616_PLL_AUDIO_REG);
val &= ~(GENMASK(21, 16) | BIT(0));
writel(val | (11 << 16) | BIT(0), reg + SUN50I_H616_PLL_AUDIO_REG);
val &= ~BIT(1);
val |= BIT(0);
writel(val, reg + SUN50I_H616_PLL_AUDIO_REG);

/*
* First clock parent (osc32K) is unusable for CEC. But since there
Expand Down
4 changes: 4 additions & 0 deletions include/sound/soc-dai.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ struct snd_compr_stream;
*
* "Negative" FSYNC polarity is the one opposite of "normal" polarity.
*/
#if defined(CONFIG_SND_SOC_SUN50I_AHUB)
#define SND_SOC_DAIFMT_NB_NF (1 << 8) /* normal bit clock + frame */
#else
#define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
#endif
#define SND_SOC_DAIFMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */
#define SND_SOC_DAIFMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */
#define SND_SOC_DAIFMT_IB_IF (4 << 8) /* invert BCLK + FRM */
Expand Down
13 changes: 13 additions & 0 deletions sound/soc/codecs/hdmi-codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
int ret = 0;

#if ! defined(CONFIG_SND_SOC_SUN50I_HDMI)
mutex_lock(&hcp->lock);
if (hcp->busy) {
dev_err(dai->dev, "Only one simultaneous stream supported!\n");
Expand All @@ -442,6 +443,7 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
if (ret)
goto err;
}
#endif

if (tx && hcp->hcd.ops->get_eld) {
ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->hcd.data,
Expand Down Expand Up @@ -469,12 +471,14 @@ static void hdmi_codec_shutdown(struct snd_pcm_substream *substream,
{
struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai);

#if ! defined(CONFIG_SND_SOC_SUN50I_HDMI)
hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN;
hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data);

mutex_lock(&hcp->lock);
hcp->busy = false;
mutex_unlock(&hcp->lock);
#endif
}

static int hdmi_codec_fill_codec_params(struct snd_soc_dai *dai,
Expand Down Expand Up @@ -1044,6 +1048,15 @@ static int hdmi_codec_probe(struct platform_device *pdev)
__func__, ret);
return ret;
}

#if defined(CONFIG_SND_SOC_SUN50I_HDMI)
if (hcp->hcd.ops->audio_startup) {
ret = hcp->hcd.ops->audio_startup(dev, hcp->hcd.data);
if (ret)
return 0;
}
#endif

return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions sound/soc/soc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ static int dummy_dma_open(struct snd_soc_component *component,
* If there are other components associated with rtd, we shouldn't
* override their hwparams
*/
#if ! defined(CONFIG_SND_SOC_SUN50I_HDMI)
for_each_rtd_components(rtd, i, component) {
if (component->driver == &dummy_platform)
return 0;
}
#endif

/* BE's dont need dummy params */
if (!rtd->dai_link->no_pcm)
Expand Down
26 changes: 26 additions & 0 deletions sound/soc/sunxi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ config SND_SUN4I_CODEC
Select Y or M to add support for the Codec embedded in the Allwinner
A10 and affiliated SoCs.

config SND_SUN50IW9_CODEC
tristate "Allwinner H616 Codec Support"
select SND_SOC_GENERIC_DMAENGINE_PCM
select REGMAP_MMIO
help
Select Y or M to add support for the Codec embedded in the Allwinner
H616 and affiliated SoCs.

config SND_SUN8I_CODEC
tristate "Allwinner SUN8I audio codec"
depends on OF
Expand Down Expand Up @@ -67,4 +75,22 @@ config SND_SUN8I_ADDA_PR_REGMAP
tristate
select REGMAP

config SND_SOC_SUN50I_AHUB
bool "Allwinner H616 Audio Hub Support for ASoc"
select REGMAP_MMIO
default n
help
Say Y or M if you want to using ahub module.

config SND_SOC_SUN50I_HDMI
bool "ASoc support for Allwinner H616 HDMI"
select SND_SOC_GENERIC_DMAENGINE_PCM
select DRM_DW_HDMI_I2S_AUDIO
select SND_SOC_HDMI_CODEC
select REGMAP_MMIO
default n
help
Say Y or M here if you want to add support for SoC hdmi audio on Allwinner
H616 boards.

endmenu
9 changes: 9 additions & 0 deletions sound/soc/sunxi/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_SND_SUN4I_CODEC) += sun4i-codec.o
obj-$(CONFIG_SND_SUN50IW9_CODEC) += sun50iw9-codec.o
obj-$(CONFIG_SND_SUN4I_I2S) += sun4i-i2s.o
obj-$(CONFIG_SND_SUN4I_SPDIF) += sun4i-spdif.o
obj-$(CONFIG_SND_SUN8I_CODEC_ANALOG) += sun8i-codec-analog.o
obj-$(CONFIG_SND_SUN50I_CODEC_ANALOG) += sun50i-codec-analog.o
obj-$(CONFIG_SND_SUN8I_CODEC) += sun8i-codec.o
obj-$(CONFIG_SND_SUN8I_ADDA_PR_REGMAP) += sun8i-adda-pr-regmap.o
obj-$(CONFIG_SND_SUN50I_DMIC) += sun50i-dmic.o

# audio hub
obj-$(CONFIG_SND_SOC_SUN50I_AHUB) += sun50i-ahub.o
obj-$(CONFIG_SND_SOC_SUN50I_AHUB) += sun50i-ahub-cpudai.o
obj-$(CONFIG_SND_SOC_SUN50I_AHUB) += sun50i-ahub-daudio.o
# ahub machine
obj-$(CONFIG_SND_SOC_SUN50I_AHUB) += sun50i-sndahub.o
obj-$(CONFIG_SND_SOC_SUN50I_HDMI) += sun50i-sndhdmi.o

0 comments on commit 99a7ebc

Please sign in to comment.