From 0cb24e58d22498d8b5c16c89f05c2161746ed76d Mon Sep 17 00:00:00 2001 From: "peter.yang" Date: Thu, 23 Nov 2017 10:12:09 +0000 Subject: [PATCH] Fix: pcm playback & capture stream can work together, all with 8 channels. --- ac108.c | 47 +++++++++++++++++++++++++++---- seeed-4mic-voicecard.dtbo | Bin 2359 -> 2359 bytes seeed-8mic-voicecard-overlay.dts | 2 +- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/ac108.c b/ac108.c index b153465..f767f62 100644 --- a/ac108.c +++ b/ac108.c @@ -8,6 +8,7 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ +#define DEBUG #include #include #include @@ -51,6 +52,7 @@ struct ac108_priv { unsigned char i2s_mode; unsigned char data_protocol; struct delayed_work dlywork; + int trgr_cnt; }; static struct ac108_priv *ac108; @@ -619,15 +621,16 @@ static int ac108_update_bits(u8 reg, u8 mask, u8 val, struct i2c_client *client) return 0; } +#if 0 static int ac108_multi_chips_read(u8 reg, u8 *rt_value, struct ac108_priv *ac108) { u8 i; + for (i = 0; i < ac108->codec_index; i++) { ac108_read(reg, rt_value++, ac108->i2c[i]); } - return 0; } - +#endif static int ac108_multi_chips_write(u8 reg, u8 val, struct ac108_priv *ac108) { u8 i; @@ -784,7 +787,13 @@ static int ac108_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_h unsigned bclkdiv; u8 r; - dev_dbg(dai->dev, "%s\n", __FUNCTION__); + dev_dbg(dai->dev, "%s() stream=%d\n", + __FUNCTION__, substream->stream); + + /* nothing should be done when it isn't capturing stream. */ + if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) { + return 0; + } channels = params_channels(params); @@ -903,6 +912,8 @@ static int ac108_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_h */ ac108_multi_chips_slots(ac108, channels); + ac108->trgr_cnt = 0; + return 0; } @@ -1107,12 +1118,16 @@ static int ac108_trigger(struct snd_pcm_substream *substream, int cmd, struct ac108_priv *ac108 = snd_soc_codec_get_drvdata(codec); int ret = 0; - dev_dbg(dai->dev, "%s()\n", __FUNCTION__); + dev_dbg(dai->dev, "%s() stream=%d cmd=%d\n", + __FUNCTION__, substream->stream, cmd); switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + if (ac108->trgr_cnt++ > 0) { + break; + } /* disable global clock */ ac108_multi_chips_update_bits(I2S_CTRL, 0x1 << TXEN | 0x1 << GEN, 0x1 << TXEN | 0x0 << GEN, ac108); @@ -1123,7 +1138,7 @@ static int ac108_trigger(struct snd_pcm_substream *substream, int cmd, ac108_multi_chips_write(MOD_RST_CTRL, 1 << I2S | 1 << ADC_DIGITAL | 1 << MIC_OFFSET_CALIBRATION | 1 << ADC_ANALOG, ac108); /* delayed clock starting */ - schedule_delayed_work(&ac108->dlywork, msecs_to_jiffies(50)); + schedule_delayed_work(&ac108->dlywork, msecs_to_jiffies(30)); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: @@ -1170,9 +1185,15 @@ static struct snd_soc_dai_driver ac108_dai0 = { .ops = &ac108_dai_ops, }; - static struct snd_soc_dai_driver ac108_dai1 = { .name = "ac108-codec1", + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = AC108_CHANNELS_MAX, + .rates = AC108_RATES, + .formats = AC108_FORMATS, + }, .capture = { .stream_name = "Capture", .channels_min = 1, @@ -1185,6 +1206,13 @@ static struct snd_soc_dai_driver ac108_dai1 = { static struct snd_soc_dai_driver ac108_dai2 = { .name = "ac108-codec2", + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = AC108_CHANNELS_MAX, + .rates = AC108_RATES, + .formats = AC108_FORMATS, + }, .capture = { .stream_name = "Capture", .channels_min = 1, @@ -1197,6 +1225,13 @@ static struct snd_soc_dai_driver ac108_dai2 = { static struct snd_soc_dai_driver ac108_dai3 = { .name = "ac108-codec3", + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = AC108_CHANNELS_MAX, + .rates = AC108_RATES, + .formats = AC108_FORMATS, + }, .capture = { .stream_name = "Capture", .channels_min = 1, diff --git a/seeed-4mic-voicecard.dtbo b/seeed-4mic-voicecard.dtbo index 02649abdad53e5035a2f1dec32e2441ec3341218..a7c3e9795f26aa27c9e430a67a24478ebe12880d 100644 GIT binary patch delta 14 Vcmdlkv|VU}I5Q*DW(j6_HUJ=615*G1 delta 14 Vcmdlkv|VU}I5Q*5W(j6_HUJ=I162S3 diff --git a/seeed-8mic-voicecard-overlay.dts b/seeed-8mic-voicecard-overlay.dts index 4d5c15c..447b93b 100644 --- a/seeed-8mic-voicecard-overlay.dts +++ b/seeed-8mic-voicecard-overlay.dts @@ -58,7 +58,7 @@ simple-audio-card,bitclock-master = <&codec_dai>; simple-audio-card,frame-master = <&codec_dai>; - simple-audio-card,channels-playback-override = <2>; + simple-audio-card,channels-playback-override = <8>; simple-audio-card,channels-capture-override = <8>; cpu_dai: simple-audio-card,cpu {