linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@ti.com>
To: Tony Lindgren <tony@atomide.com>, Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	<alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>,
	<linux-omap@vger.kernel.org>, "Arthur D ." <spinal.by@gmail.com>,
	Merlijn Wajer <merlijn@wizzup.org>, Pavel Machek <pavel@ucw.cz>,
	Sebastian Reichel <sre@kernel.org>
Subject: Re: [PATCH] ASoC: cpcap: Implement set_tdm_slot for voice call support
Date: Wed, 12 Feb 2020 11:17:32 +0200	[thread overview]
Message-ID: <ae2b7d9e-d05e-54ac-4f18-27cc8c4e81a0@ti.com> (raw)
In-Reply-To: <20200211181005.54008-1-tony@atomide.com>



On 11/02/2020 20.10, Tony Lindgren wrote:
> For using cpcap for voice calls, we need to route audio directly from
> the modem to cpcap for TDM (Time Division Multiplexing). The voice call
> is direct data between the modem and cpcap with no CPU involvment. In
> this mode, the cpcap related audio mixer controls work for the speaker
> selection and volume though.
> 
> To do this, we need to implement standard snd_soc_dai_set_tdm_slot()
> for cpcap. Then the modem codec driver can use snd_soc_dai_set_sysclk(),
> snd_soc_dai_set_fmt(), and snd_soc_dai_set_tdm_slot() to configure a
> voice call.
> 
> Let's add cpcap_voice_set_tdm_slot() for this, and cpcap_voice_call()
> helper to configure the additional registers needed for voice call.
> 
> Let's also clear CPCAP_REG_VAUDIOC on init in case we have the bit for
> CPCAP_BIT_VAUDIO_MODE0 set on init.
> 
> Cc: Arthur D. <spinal.by@gmail.com>
> Cc: Merlijn Wajer <merlijn@wizzup.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Sebastian Reichel <sre@kernel.org>
> Signed-off-by: Tony Lindgren <tony@atomide.com>
> ---
>  sound/soc/codecs/cpcap.c | 123 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 123 insertions(+)
> 
> diff --git a/sound/soc/codecs/cpcap.c b/sound/soc/codecs/cpcap.c
> --- a/sound/soc/codecs/cpcap.c
> +++ b/sound/soc/codecs/cpcap.c
> @@ -16,6 +16,14 @@
>  #include <sound/soc.h>
>  #include <sound/tlv.h>
>  
> +/* Register 512 CPCAP_REG_VAUDIOC --- Audio Regulator and Bias Voltage */
> +#define CPCAP_BIT_AUDIO_LOW_PWR           6
> +#define CPCAP_BIT_AUD_LOWPWR_SPEED        5
> +#define CPCAP_BIT_VAUDIOPRISTBY           4
> +#define CPCAP_BIT_VAUDIO_MODE1            2
> +#define CPCAP_BIT_VAUDIO_MODE0            1
> +#define CPCAP_BIT_V_AUDIO_EN              0
> +
>  /* Register 513 CPCAP_REG_CC     --- CODEC */
>  #define CPCAP_BIT_CDC_CLK2                15
>  #define CPCAP_BIT_CDC_CLK1                14
> @@ -221,6 +229,7 @@ struct cpcap_reg_info {
>  };
>  
>  static const struct cpcap_reg_info cpcap_default_regs[] = {
> +	{ CPCAP_REG_VAUDIOC, 0x003F, 0x0000 },
>  	{ CPCAP_REG_CC, 0xFFFF, 0x0000 },
>  	{ CPCAP_REG_CC, 0xFFFF, 0x0000 },
>  	{ CPCAP_REG_CDI, 0xBFFF, 0x0000 },
> @@ -1370,6 +1379,119 @@ static int cpcap_voice_set_dai_fmt(struct snd_soc_dai *codec_dai,
>  	return 0;
>  }
>  
> +/*
> + * Configure codec for voice call if requested.
> + *
> + * We can configure most with snd_soc_dai_set_sysclk(), snd_soc_dai_set_fmt()
> + * and snd_soc_dai_set_tdm_slot(). This function configures the rest of the
> + * cpcap related hardware as CPU is not involved in the voice call.
> + */
> +static int cpcap_voice_call(struct cpcap_audio *cpcap, struct snd_soc_dai *dai,
> +			    bool voice_call)
> +{
> +	int mask, err;
> +
> +	/* Modem to codec VAUDIO_MODE1 */
> +	mask = BIT(CPCAP_BIT_VAUDIO_MODE1);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_VAUDIOC,
> +				 mask, voice_call ? mask : 0);
> +	if (err)
> +		return err;
> +
> +	/* Clear MIC1_MUX for call */
> +	mask = BIT(CPCAP_BIT_MIC1_MUX);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_TXI,
> +				 mask, voice_call ? 0 : mask);
> +	if (err)
> +		return err;
> +
> +	/* Set MIC2_MUX for call */
> +	mask = BIT(CPCAP_BIT_MB_ON1L) | BIT(CPCAP_BIT_MB_ON1R) |
> +		BIT(CPCAP_BIT_MIC2_MUX) | BIT(CPCAP_BIT_MIC2_PGA_EN);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_TXI,
> +				 mask, voice_call ? mask : 0);
> +	if (err)
> +		return err;
> +
> +	/* Enable LDSP for call */
> +	mask = BIT(CPCAP_BIT_A2_LDSP_L_EN) | BIT(CPCAP_BIT_A2_LDSP_R_EN);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_RXOA,
> +				 mask, voice_call ? mask : 0);
> +	if (err)
> +		return err;
> +
> +	/* Enable CPCAP_BIT_PGA_CDC_EN for call */
> +	mask = BIT(CPCAP_BIT_PGA_CDC_EN);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_RXCOA,
> +				 mask, voice_call ? mask : 0);
> +	if (err)
> +		return err;
> +
> +	/* Unmute voice for call */
> +	if (dai) {
> +		err = snd_soc_dai_digital_mute(dai, !voice_call,
> +					       SNDRV_PCM_STREAM_PLAYBACK);
> +		if (err)
> +			return err;
> +	}
> +
> +	/* Set modem to codec mic CDC and HPF for call */
> +	mask = BIT(CPCAP_BIT_MIC2_CDC_EN) | BIT(CPCAP_BIT_CDC_EN_RX) |
> +	       BIT(CPCAP_BIT_AUDOHPF_1) | BIT(CPCAP_BIT_AUDOHPF_0) |
> +	       BIT(CPCAP_BIT_AUDIHPF_1) | BIT(CPCAP_BIT_AUDIHPF_0);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_CC,
> +				 mask, voice_call ? mask : 0);
> +	if (err)
> +		return err;
> +
> +	/* Enable modem to codec CDC for call*/
> +	mask = BIT(CPCAP_BIT_CDC_CLK_EN);
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_CDI,
> +				 mask, voice_call ? mask : 0);
> +
> +	return err;
> +}
> +
> +static int cpcap_voice_set_tdm_slot(struct snd_soc_dai *dai,
> +				    unsigned int tx_mask, unsigned int rx_mask,
> +				    int slots, int slot_width)
> +{
> +	struct snd_soc_component *component = dai->component;
> +	struct cpcap_audio *cpcap = snd_soc_component_get_drvdata(component);
> +	int err, ts_mask, mask;
> +	bool voice_call;
> +
> +	/*
> +	 * Primitive test for voice call, probably needs more checks
> +	 * later on for 16-bit calls detected, Bluetooth headset etc.
> +	 */
> +	if (tx_mask == 0 && rx_mask == 1 && slot_width == 8)
> +		voice_call = true;
> +	else
> +		voice_call = false;

You only have voice call if only rx slot0 is in use?
If you record mono on the voice DAI, then rx_mask is also 1, no?

> +
> +	ts_mask = 0x7 << CPCAP_BIT_MIC2_TIMESLOT0;
> +	ts_mask |= 0x7 << CPCAP_BIT_MIC1_RX_TIMESLOT0;
> +
> +	mask = (tx_mask & 0x7) << CPCAP_BIT_MIC2_TIMESLOT0;
> +	mask |= (rx_mask & 0x7) << CPCAP_BIT_MIC1_RX_TIMESLOT0;
> +
> +	err = regmap_update_bits(cpcap->regmap, CPCAP_REG_CDI,
> +				 ts_mask, mask);
> +	if (err)
> +		return err;
> +
> +	err = cpcap_set_samprate(cpcap, CPCAP_DAI_VOICE, slot_width * 1000);
> +	if (err)
> +		return err;

You will also set the sampling rate for voice in
cpcap_voice_hw_params(), but that is for normal playback/capture, right?

> +
> +	err = cpcap_voice_call(cpcap, dai, voice_call);
> +	if (err)
> +		return err;

It feels like that these should be done via DAPM with codec to codec route?

> +
> +	return 0;
> +}
> +
>  static int cpcap_voice_set_mute(struct snd_soc_dai *dai, int mute)
>  {
>  	struct snd_soc_component *component = dai->component;
> @@ -1391,6 +1513,7 @@ static const struct snd_soc_dai_ops cpcap_dai_voice_ops = {
>  	.hw_params	= cpcap_voice_hw_params,
>  	.set_sysclk	= cpcap_voice_set_dai_sysclk,
>  	.set_fmt	= cpcap_voice_set_dai_fmt,
> +	.set_tdm_slot	= cpcap_voice_set_tdm_slot,
>  	.digital_mute	= cpcap_voice_set_mute,
>  };
>  
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  reply	other threads:[~2020-02-12  9:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 18:10 Tony Lindgren
2020-02-12  9:17 ` Peter Ujfalusi [this message]
2020-02-12 14:46   ` Tony Lindgren
2020-02-14 13:29     ` Peter Ujfalusi
2020-02-17 23:23       ` Tony Lindgren
2020-02-18 15:15         ` Peter Ujfalusi
2020-02-18 15:32           ` Tony Lindgren
2020-02-18 16:44             ` Mark Brown
2020-02-18 17:06             ` Sebastian Reichel
2020-02-18 17:42               ` Mark Brown
2020-02-19 17:39                 ` Tony Lindgren
2020-02-19 17:46                   ` Mark Brown
2020-02-19 18:49                     ` Tony Lindgren
2020-02-19 18:53               ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae2b7d9e-d05e-54ac-4f18-27cc8c4e81a0@ti.com \
    --to=peter.ujfalusi@ti.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=merlijn@wizzup.org \
    --cc=pavel@ucw.cz \
    --cc=perex@perex.cz \
    --cc=spinal.by@gmail.com \
    --cc=sre@kernel.org \
    --cc=tiwai@suse.com \
    --cc=tony@atomide.com \
    --subject='Re: [PATCH] ASoC: cpcap: Implement set_tdm_slot for voice call support' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).