From 9bde59e73796dd8b57a9a638b0b1d7aa6bdcfe48 Mon Sep 17 00:00:00 2001 From: Xing Wang Date: Thu, 1 Feb 2018 09:21:26 +0800 Subject: [PATCH] audio: auge: avout and notify spdifb to hdmitx PD#156734: audio: auge: avout and notify spdifb to hdmitx Change-Id: I63b9fe4d18979b33907a3ed848f99abf42ae8972 Signed-off-by: Xing Wang --- MAINTAINERS | 3 +- arch/arm64/boot/dts/amlogic/g12a_skt.dts | 67 +++++++++++++++++++--------- arch/arm64/boot/dts/amlogic/mesong12a.dtsi | 8 ++++ arch/arm64/configs/meson64_defconfig | 1 + sound/soc/amlogic/Kconfig | 1 + sound/soc/amlogic/Makefile | 1 + sound/soc/amlogic/auge/audio_utils.c | 3 +- sound/soc/amlogic/auge/card.c | 9 ++++ sound/soc/amlogic/auge/regs.h | 4 +- sound/soc/amlogic/auge/spdif.c | 45 ++++++++++++++----- sound/soc/amlogic/auge/spdif_hw.c | 10 +++++ sound/soc/amlogic/auge/spdif_hw.h | 1 + sound/soc/amlogic/auge/tdm.c | 34 +++++++++++++- sound/soc/amlogic/auge/tdm_hw.c | 45 +++++++++++++++++++ sound/soc/amlogic/auge/tdm_hw.h | 4 ++ sound/soc/amlogic/common/Kconfig | 7 +++ sound/soc/amlogic/common/Makefile | 1 + sound/soc/amlogic/{meson => common}/notify.c | 0 sound/soc/amlogic/meson/Makefile | 1 - 19 files changed, 208 insertions(+), 37 deletions(-) create mode 100644 sound/soc/amlogic/common/Kconfig create mode 100644 sound/soc/amlogic/common/Makefile rename sound/soc/amlogic/{meson => common}/notify.c (100%) diff --git a/MAINTAINERS b/MAINTAINERS index 7fa98f0..0e6bdc3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14327,4 +14327,5 @@ F: drivers/amlogic/pinctrl/pinctrl-meson-g12a.c F: include/dt-bindings/clock/amlogic,g12a-audio-clk.h F: include/linux/amlogic/media/sound/auge_utils.h F: sound/soc/amlogic/auge/* -F: sound/soc/codecs/amlogic/aml_codec_t9015.c +F: sound/soc/amlogic/common/* +F: sound/soc/codecs/amlogic/aml_codec_t9015.c \ No newline at end of file diff --git a/arch/arm64/boot/dts/amlogic/g12a_skt.dts b/arch/arm64/boot/dts/amlogic/g12a_skt.dts index 6bbde20..8f9364b 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_skt.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_skt.dts @@ -568,13 +568,17 @@ compatible = "amlogic, aml_codec_T9015"; reg = <0x0 0xFF632000 0x0 0x2000>; is_auge_used = <1>; /* meson or auge chipset used */ - tdmout_index = <0>; - status = "disabled"; + tdmout_index = <1>; + status = "okay"; }; auge_sound { compatible = "amlogic, g12a-sound-card"; aml-audio-card,name = "AML-AUGESOUND"; + aml-audio-card,aux-devs = <&amlogic_codec>; + /*avout mute gpio*/ + avout_mute-gpios = <&gpio_ao GPIOAO_2 GPIO_ACTIVE_HIGH>; + aml-audio-card,dai-link@0 { format = "dsp_a"; mclk-fs = <512>; @@ -615,7 +619,7 @@ system-clock-frequency = <12288000>; }; codec { - sound-dai = <&dummy_codec &dummy_codec>; + sound-dai = <&dummy_codec &amlogic_codec>; }; }; @@ -690,6 +694,21 @@ /* Audio Related end */ }; /* end of / */ +&i2c3 { + status = "okay"; + pinctrl-names="default"; + pinctrl-0=<&c_i2c_master_pin1>; + + tas5707_36: tas5707_36@36 { + compatible = "ti,tas5707"; + #sound-dai-cells = <0>; + reg = <0x1b>; + status = "disabled"; + reset_pin = <&gpio GPIOA_5 0>; + }; + +}; + &audiobus { aml_tdma: tdma { compatible = "amlogic, g12a-snd-tdma"; @@ -707,13 +726,14 @@ aml_tdmb: tdmb { compatible = "amlogic, g12a-snd-tdmb"; #sound-dai-cells = <0>; - dai-tdm-lane-slot-mask-in = <1 1 1 1>; + dai-tdm-lane-slot-mask-in = <0 1 0 0>; + dai-tdm-lane-slot-mask-out = <1 0 0 0>; dai-tdm-clk-sel = <1>; clocks = <&clkaudio CLKID_AUDIO_MCLK_B &clkc CLKID_MPLL1>; clock-names = "mclk", "clk_srcpll"; pinctrl-names = "tdm_pins"; - pinctrl-0 = <&tdmb_mclk /*&tdmout_b &tdmin_b*/>; + pinctrl-0 = <&tdmb_mclk &tdmout_b &tdmin_b>; }; aml_tdmc: tdmc { @@ -743,7 +763,7 @@ clock-names = "sysclk", "fixed_clk", "gate_spdifin", "gate_spdifout", "clk_spdifin", "clk_spdifout"; interrupts = - ; + ; interrupt-names = "irq_spdifin"; pinctrl-names = "spdif_pins"; @@ -758,8 +778,8 @@ &clkaudio CLKID_AUDIO_SPDIFOUTB_CTRL>; clock-names = "sysclk", "gate_spdifout", "clk_spdifout"; - pinctrl-names = "spdif_pins"; - pinctrl-0 = <&spdifout_b>; + //pinctrl-names = "spdif_pins"; + //pinctrl-0 = <&spdifout>; status = "okay"; }; aml_pdm: pdm { @@ -829,17 +849,17 @@ }; }; tdmout_b: tdmout_b { - mux { /* GPIOA_1, GPIOA_2 */ + mux { /* GPIOA_1, GPIOA_2, GPIOA_3 */ groups = "tdmb_sclk", - "tdmb_fs"; + "tdmb_fs", + "tdmb_dout0"; function = "tdmb_out"; }; }; tdmin_b:tdmin_b { - mux { /* GPIOA_3, GPIOA_4 */ - groups = "tdmb_din0", - "tdmb_din1"; + mux { /* GPIOA_4 */ + groups = "tdmb_din1"; function = "tdmb_in"; }; }; @@ -855,7 +875,7 @@ mux { /* GPIOA_12, GPIOA_13, GPIOA_10, GPIOA_8, GPIOA_7*/ groups = "tdmc_sclk_a", "tdmc_fs_a", - "tdmc_dout0" + "tdmc_dout0_a" /*, "tdmc_dout2", * "tdmc_dout3" */; @@ -877,17 +897,20 @@ }; }; - spdifout: spdifout { - mux {/* GPIOH_4 */ - groups = " spdif_out_h"; - function = "spdif_out"; - }; - }; + /* GPIOH_4 */ + /* + * spdifout: spdifout { + * mux { + * groups = "spdif_out_h"; + * function = "spdif_out"; + * }; + *}; + */ pdmin: pdmin { mux { /* gpioa_5, gpioa_6, gpioa_7, gpioa_8, gpioa_9*/ groups = "pdm_din0_a", - "pdm_din1_a", + /*"pdm_din1_a",*/ "pdm_din2_a", "pdm_din3_a", "pdm_dclk_a"; @@ -897,7 +920,7 @@ }; /* end of pinctrl_periphs */ &pinctrl_aobus { - spdifout_b: spdifout_b { + spdifout: spdifout { mux { /* gpiao_10 */ groups = "spdif_out_ao"; function = "spdif_out_ao"; diff --git a/arch/arm64/boot/dts/amlogic/mesong12a.dtsi b/arch/arm64/boot/dts/amlogic/mesong12a.dtsi index ea7a48e..7901001 100644 --- a/arch/arm64/boot/dts/amlogic/mesong12a.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesong12a.dtsi @@ -843,6 +843,14 @@ function = "pwm_e"; }; }; + + c_i2c_master_pin1:c_i2c_pin1 { + mux { + groups = "i2c3_sck_a", + "i2c3_sda_a"; + function = "i2c3"; + }; + }; }; &pinctrl_aobus { diff --git a/arch/arm64/configs/meson64_defconfig b/arch/arm64/configs/meson64_defconfig index 6af564a..6778261 100644 --- a/arch/arm64/configs/meson64_defconfig +++ b/arch/arm64/configs/meson64_defconfig @@ -453,6 +453,7 @@ CONFIG_AMLOGIC_SND_SOC_TAS575X=y CONFIG_AMLOGIC_SND_SOC=y CONFIG_AMLOGIC_SND_SOC_MESON=y CONFIG_AMLOGIC_SND_SOC_AUGE=y +CONFIG_AMLOGIC_SND_SOC_COMMON=y CONFIG_AMLOGIC_SND_SPLIT_MODE=y CONFIG_HIDRAW=y CONFIG_UHID=y diff --git a/sound/soc/amlogic/Kconfig b/sound/soc/amlogic/Kconfig index 41d8d56..dbfff50 100644 --- a/sound/soc/amlogic/Kconfig +++ b/sound/soc/amlogic/Kconfig @@ -33,5 +33,6 @@ config AMLOGIC_SND_SOC_AUGE # All the supported SoCs source "sound/soc/amlogic/meson/Kconfig" source "sound/soc/amlogic/auge/Kconfig" +source "sound/soc/amlogic/common/Kconfig" endif # AMLOGIC_SND_SOC diff --git a/sound/soc/amlogic/Makefile b/sound/soc/amlogic/Makefile index f2f7972..98e8bf6 100644 --- a/sound/soc/amlogic/Makefile +++ b/sound/soc/amlogic/Makefile @@ -3,3 +3,4 @@ KBUILD_CFLAGS += -Wstack-usage=1856 obj-$(CONFIG_AMLOGIC_SND_SOC) += meson/ obj-$(CONFIG_AMLOGIC_SND_SOC) += auge/ +obj-$(CONFIG_AMLOGIC_SND_SOC) += common/ diff --git a/sound/soc/amlogic/auge/audio_utils.c b/sound/soc/amlogic/auge/audio_utils.c index 0d6be15..d261072 100644 --- a/sound/soc/amlogic/auge/audio_utils.c +++ b/sound/soc/amlogic/auge/audio_utils.c @@ -1432,8 +1432,9 @@ void auge_toacodec_ctrl(int tdmout_id) // TODO: check skew for g12a audiobus_write(EE_AUDIO_TOACODEC_CTRL0, 1 << 31 - | tdmout_id << 12 /* data 0*/ + | ((tdmout_id << 2)) << 12 /* data 0*/ | tdmout_id << 8 /* lrclk */ + | 1 << 7 /* Bclk_cap_inv*/ | tdmout_id << 4 /* bclk */ | tdmout_id << 0 /* mclk */ ); diff --git a/sound/soc/amlogic/auge/card.c b/sound/soc/amlogic/auge/card.c index 4aa04e2..0ec8885 100644 --- a/sound/soc/amlogic/auge/card.c +++ b/sound/soc/amlogic/auge/card.c @@ -63,6 +63,7 @@ struct aml_card_data { struct snd_soc_dai_link *dai_link; int spk_mute_gpio; bool spk_mute_active_low; + struct gpio_desc *avout_mute_desc; struct loopback_cfg lb_cfg; struct timer_list timer; struct work_struct work; @@ -752,6 +753,14 @@ static int aml_card_parse_gpios(struct device_node *node, ARRAY_SIZE(card_controls)); } + priv->avout_mute_desc = gpiod_get(dev, + "avout_mute", + GPIOD_OUT_HIGH); + + gpiod_direction_output(priv->avout_mute_desc, + GPIOF_OUT_INIT_HIGH); + pr_info("set av out GPIOF_OUT_INIT_HIGH!\n"); + return 0; } diff --git a/sound/soc/amlogic/auge/regs.h b/sound/soc/amlogic/auge/regs.h index 7c767ec..a4514db 100644 --- a/sound/soc/amlogic/auge/regs.h +++ b/sound/soc/amlogic/auge/regs.h @@ -322,7 +322,9 @@ #define PDM_MUTE_VALUE 0x00d /* clk pad */ -#define EE_AUDIO_MST_PAD_CTRL 0x007 +#define EE_AUDIO_MST_PAD_CTRL0 0x007 +#define EE_AUDIO_MST_PAD_CTRL1 0x008 +#define EE_AUDIO_SW_RESET 0x009 /* spdifout_b clk*/ #define EE_AUDIO_CLK_SPDIFOUT_B_CTRL 0x02d diff --git a/sound/soc/amlogic/auge/spdif.c b/sound/soc/amlogic/auge/spdif.c index 3429675..84425f0 100644 --- a/sound/soc/amlogic/auge/spdif.c +++ b/sound/soc/amlogic/auge/spdif.c @@ -37,6 +37,8 @@ #include "spdif_hw.h" #include "audio_utils.h" +#include + #define DRV_NAME "aml_spdif" #define SPDIF_A 0 @@ -396,10 +398,33 @@ static int aml_dai_spdif_prepare( if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { struct frddr *fr = p_spdif->fddr; + enum frddr_dest dst; + + switch (p_spdif->id) { + case 0: + dst = SPDIFOUT; + break; + case 1: + dst = SPDIFOUT_B; + break; + default: + dev_err(p_spdif->dev, "invalid id: %d\n", p_spdif->id); + return -EINVAL; + } fifo_id = aml_frddr_get_fifo_id(fr); - aml_frddr_select_dst(fr, SPDIFOUT); + aml_frddr_select_dst(fr, dst); aml_frddr_set_fifos(fr, 0x40, 0x20); + + // TODO: TOHDMITX_CTRL0 + if (p_spdif->id == 1) { + /* HDMI audio stream type ID */ + #define AOUT_EVENT_IEC_60958_PCM 0x1 + + spdifoutb_to_hdmitx_ctrl(); + aout_notifier_call_chain(AOUT_EVENT_IEC_60958_PCM, + substream); + } } else { struct toddr *to = p_spdif->tddr; unsigned int msb, lsb, toddr_type; @@ -584,7 +609,7 @@ static struct snd_soc_dai_ops aml_dai_spdif_ops = { static struct snd_soc_dai_driver aml_spdif_dai[] = { { .name = "SPDIF", - .id = 0, + .id = 1, .probe = aml_dai_spdif_probe, .remove = aml_dai_spdif_remove, .playback = { @@ -604,7 +629,7 @@ static struct snd_soc_dai_driver aml_spdif_dai[] = { }, { .name = "SPDIF-B", - .id = 1, + .id = 2, .probe = aml_dai_spdif_probe, .remove = aml_dai_spdif_remove, .playback = { @@ -662,6 +687,12 @@ static int aml_spdif_parse_of(struct platform_device *pdev) if (p_spdif->irq_spdifin < 0) dev_err(dev, "platform_get_irq_byname failed\n"); + /* spdif pinmux */ + p_spdif->pin_ctl = devm_pinctrl_get_select(dev, "spdif_pins"); + if (IS_ERR(p_spdif->pin_ctl)) { + dev_info(dev, "aml_spdif_get_pins error!\n"); + return PTR_ERR(p_spdif->pin_ctl); + } } /* clock for spdif in */ @@ -691,13 +722,6 @@ static int aml_spdif_parse_of(struct platform_device *pdev) return ret; } - /* spdif pinmux */ - p_spdif->pin_ctl = devm_pinctrl_get_select(dev, "spdif_pins"); - if (IS_ERR(p_spdif->pin_ctl)) { - dev_info(dev, "aml_spdif_get_pins error!\n"); - return PTR_ERR(p_spdif->pin_ctl); - } - return 0; } @@ -768,6 +792,7 @@ static int aml_spdif_platform_probe(struct platform_device *pdev) } else dev_warn_once(dev, "check whether to update spdif chipinfo\n"); + pr_info("%s, spdif ID = %u\n", __func__, aml_spdif->id); /* get audio controller */ diff --git a/sound/soc/amlogic/auge/spdif_hw.c b/sound/soc/amlogic/auge/spdif_hw.c index 40a2721..03b1e7e 100644 --- a/sound/soc/amlogic/auge/spdif_hw.c +++ b/sound/soc/amlogic/auge/spdif_hw.c @@ -269,3 +269,13 @@ void aml_spdifout_get_aed_info(int spdifout_id, if (frddrtype) *frddrtype = (val >> 4) & 0x7; } + +void spdifoutb_to_hdmitx_ctrl(void) +{ + audiobus_write(EE_AUDIO_TOHDMITX_CTRL0, + 1 << 31 + | 0 << 2 /* spdif_clk_inv */ + | 1 << 1 /* spdif_out_b */ + | 1 << 0 /* spdif_clk_b */ + ); +} diff --git a/sound/soc/amlogic/auge/spdif_hw.h b/sound/soc/amlogic/auge/spdif_hw.h index 9cd67e2..b47f340 100644 --- a/sound/soc/amlogic/auge/spdif_hw.h +++ b/sound/soc/amlogic/auge/spdif_hw.h @@ -53,4 +53,5 @@ extern void aml_spdifout_select_aed(bool enable, int spdifout_id); extern void aml_spdifout_get_aed_info(int spdifout_id, int *bitwidth, int *frddrtype); +extern void spdifoutb_to_hdmitx_ctrl(void); #endif diff --git a/sound/soc/amlogic/auge/tdm.c b/sound/soc/amlogic/auge/tdm.c index cb705fb..2324329 100644 --- a/sound/soc/amlogic/auge/tdm.c +++ b/sound/soc/amlogic/auge/tdm.c @@ -76,6 +76,9 @@ struct tdm_chipinfo { /* output en (oe) for pinmux */ bool oe_fn; + + /* clk pad */ + bool clk_pad_ctl; }; struct aml_tdm { @@ -570,6 +573,27 @@ static int aml_tdm_set_lanes(struct aml_tdm *p_tdm, stream, p_tdm->id, swap_val); } + + return 0; +} + +static int aml_tdm_set_clk_pad(struct aml_tdm *p_tdm) +{ + unsigned int mpad, mclk_sel; + + // TODO: update pad + if (p_tdm->id >= 1) { + mpad = p_tdm->id - 1; + mclk_sel = p_tdm->id; + } else { + mpad = 0; + mclk_sel = 0; + } + + /* clk pad */ + aml_tdm_clk_pad_select(p_tdm->actrl, mpad, mclk_sel, + p_tdm->id, p_tdm->clk_sel); + return 0; } @@ -605,6 +629,12 @@ static int aml_dai_tdm_hw_params(struct snd_pcm_substream *substream, if (ret) return ret; + if (p_tdm->chipinfo && p_tdm->chipinfo->clk_pad_ctl) { + ret = aml_tdm_set_clk_pad(p_tdm); + if (ret) + return ret; + } + return 0; } @@ -952,21 +982,23 @@ struct tdm_chipinfo g12a_tdma_chipinfo = { .id = TDM_A, .sclk_ws_inv = true, .oe_fn = true, + .clk_pad_ctl = true, }; struct tdm_chipinfo g12a_tdmb_chipinfo = { .id = TDM_B, .sclk_ws_inv = true, .oe_fn = true, + .clk_pad_ctl = true, }; struct tdm_chipinfo g12a_tdmc_chipinfo = { .id = TDM_C, .sclk_ws_inv = true, .oe_fn = true, + .clk_pad_ctl = true, }; - static const struct of_device_id aml_tdm_device_id[] = { { .compatible = "amlogic, axg-snd-tdma", diff --git a/sound/soc/amlogic/auge/tdm_hw.c b/sound/soc/amlogic/auge/tdm_hw.c index 2e97bbf..efabed2 100644 --- a/sound/soc/amlogic/auge/tdm_hw.c +++ b/sound/soc/amlogic/auge/tdm_hw.c @@ -527,3 +527,48 @@ void aml_tdmout_get_aed_info(int tdmout_id, if (frddrtype) *frddrtype = (val >> 4) & 0x7; } + +void aml_tdm_clk_pad_select( + struct aml_audio_controller *actrl, + int mpad, int mclk_sel, + int tdm_index, int clk_sel) +{ + unsigned int reg, mask_offset, val_offset; + + // TODO: fix mclk + if (mpad == 0) { + mask_offset = 0x7 << 0; + val_offset = mclk_sel << 0; + } else if (mpad == 1) { + mask_offset = 0x7 << 4; + val_offset = mclk_sel << 4; + } else { + pr_err("unknown tdm mpad:%d\n", mpad); + return; + } + reg = EE_AUDIO_MST_PAD_CTRL0; + aml_audiobus_update_bits(actrl, reg, + mask_offset, val_offset); + + reg = EE_AUDIO_MST_PAD_CTRL1; + switch (tdm_index) { + case 0: + mask_offset = 0x7 << 16 | 0x7 << 0; + val_offset = clk_sel << 16 | clk_sel << 0; + break; + case 1: + mask_offset = 0x7 << 20 | 0x7 << 4; + val_offset = clk_sel << 20 | clk_sel << 4; + break; + case 2: + mask_offset = 0x7 << 24 | 0x7 << 8; + val_offset = clk_sel << 24 | clk_sel << 8; + break; + default: + pr_err("unknown tdm index:%d\n", tdm_index); + return; + } + aml_audiobus_update_bits(actrl, reg, + mask_offset, val_offset); + +} diff --git a/sound/soc/amlogic/auge/tdm_hw.h b/sound/soc/amlogic/auge/tdm_hw.h index 0dfc4a88..506c016 100644 --- a/sound/soc/amlogic/auge/tdm_hw.h +++ b/sound/soc/amlogic/auge/tdm_hw.h @@ -105,4 +105,8 @@ extern void aml_tdmout_select_aed(bool enable, int tdmout_id); extern void aml_tdmout_get_aed_info(int tdmout_id, int *bitwidth, int *frddrtype); +extern void aml_tdm_clk_pad_select( + struct aml_audio_controller *actrl, + int mpad, int mclk_sel, + int tdm_index, int clk_sel); #endif diff --git a/sound/soc/amlogic/common/Kconfig b/sound/soc/amlogic/common/Kconfig new file mode 100644 index 0000000..d02bbc5 --- /dev/null +++ b/sound/soc/amlogic/common/Kconfig @@ -0,0 +1,7 @@ +menuconfig AMLOGIC_SND_SOC_COMMON + bool "Amlogic Common for ASoC" + default n + help + Say Y or M if you want to add support for common interface attached to + the Amlogic Asoc interface. You will also need + to select the audio interfaces to support below. diff --git a/sound/soc/amlogic/common/Makefile b/sound/soc/amlogic/common/Makefile new file mode 100644 index 0000000..9801a83 --- /dev/null +++ b/sound/soc/amlogic/common/Makefile @@ -0,0 +1 @@ +obj-y += notify.o diff --git a/sound/soc/amlogic/meson/notify.c b/sound/soc/amlogic/common/notify.c similarity index 100% rename from sound/soc/amlogic/meson/notify.c rename to sound/soc/amlogic/common/notify.c diff --git a/sound/soc/amlogic/meson/Makefile b/sound/soc/amlogic/meson/Makefile index 3593cc2..112fce0 100644 --- a/sound/soc/amlogic/meson/Makefile +++ b/sound/soc/amlogic/meson/Makefile @@ -17,7 +17,6 @@ obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-i2s-dai.o obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-i2s2-dai.o obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-pcm-dai.o obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-hw.o -obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += notify.o obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-hw-pcm2bt.o obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-spdif-dai.o obj-$(CONFIG_AMLOGIC_SND_SOC_MESON) += snd-soc-dmic.o -- 2.7.4