All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
To: broonie@kernel.org, brian.austin@cirrus.com
Cc: mark.rutland@arm.com, devicetree@vger.kernel.org,
	alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
	lgirdwood@gmail.com, Paul.Handrigan@cirrus.com,
	robh+dt@kernel.org
Subject: [PATCH 4/4] ASoC: cs35l35: Add multi-device synchronisation
Date: Thu, 18 May 2017 16:32:39 +0100	[thread overview]
Message-ID: <1495121559-1063-4-git-send-email-ckeepax@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1495121559-1063-1-git-send-email-ckeepax@opensource.wolfsonmicro.com>

This patch adds multi-device synchronisation capabilities to the
CS35L35 amp.

In stereo mode you can select to have the devices communicate
certain features to each other. Add options to allow the amps to
synchronise the audio group delay, the brown out protection and the
over temperature warning.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
 sound/soc/codecs/cs35l35.c | 48 +++++++++++++++++++++++++++++++++++++++++++---
 sound/soc/codecs/cs35l35.h |  9 +++++++++
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/cs35l35.c b/sound/soc/codecs/cs35l35.c
index 375be49..a587269 100644
--- a/sound/soc/codecs/cs35l35.c
+++ b/sound/soc/codecs/cs35l35.c
@@ -310,11 +310,49 @@ static const struct snd_kcontrol_new cs35l35_aud_controls[] = {
 			amp_gain_tlv),
 };
 
-static const struct snd_kcontrol_new cs35l35_adv_controls[] = {
+static int cs35l35_put_sync(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
+	struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
+	struct cs35l35_private *cs35l35 = snd_soc_codec_get_drvdata(codec);
+	unsigned int val;
+	int ret;
+
+	snd_soc_dapm_mutex_lock(dapm);
+
+	ret = regmap_read(cs35l35->regmap, CS35L35_PWRCTL1, &val);
+	if (ret) {
+		dev_err(cs35l35->dev, "Failed to check power state: %d\n", ret);
+		goto err;
+	}
+
+	if (!(val & CS35L35_PDN_ALL)) {
+		dev_err(cs35l35->dev, "Can't change sync when active\n");
+		ret = -EBUSY;
+		goto err;
+	}
+
+	ret = snd_soc_put_volsw(kcontrol, ucontrol);
+
+err:
+	snd_soc_dapm_mutex_unlock(dapm);
+
+	return ret;
+}
+
+static const struct snd_kcontrol_new cs35l35_stereo_controls[] = {
 	SOC_SINGLE_SX_TLV("Digital Advisory Volume", CS35L35_ADV_DIG_VOL,
 		      0, 0x34, 0xE4, dig_vol_tlv),
 	SOC_SINGLE_TLV("Analog Advisory Volume", CS35L35_AMP_GAIN_ADV_CTL, 0, 19, 0,
 			amp_gain_tlv),
+
+	SOC_SINGLE_EXT("SYNC Audio", CS35L35_MULT_DEV_SYNCH2, 1, 1, 0,
+		       snd_soc_get_volsw, cs35l35_put_sync),
+	SOC_SINGLE_EXT("SYNC VPBR", CS35L35_MULT_DEV_SYNCH2, 2, 1, 0,
+		       snd_soc_get_volsw, cs35l35_put_sync),
+	SOC_SINGLE_EXT("SYNC OTW", CS35L35_MULT_DEV_SYNCH2, 3, 1, 0,
+		       snd_soc_get_volsw, cs35l35_put_sync),
 };
 
 static const struct snd_soc_dapm_widget cs35l35_dapm_widgets[] = {
@@ -872,8 +910,12 @@ static int cs35l35_codec_probe(struct snd_soc_codec *codec)
 			regmap_update_bits(cs35l35->regmap, CS35L35_CLASS_H_CTL,
 					CS35L35_CH_STEREO_MASK,
 					1 << CS35L35_CH_STEREO_SHIFT);
-		ret = snd_soc_add_codec_controls(codec, cs35l35_adv_controls,
-					ARRAY_SIZE(cs35l35_adv_controls));
+
+		regmap_update_bits(cs35l35->regmap, CS35L35_MULT_DEV_SYNCH2,
+				   CS35L35_SYNC_EN_MASK, 1);
+
+		ret = snd_soc_add_codec_controls(codec, cs35l35_stereo_controls,
+					ARRAY_SIZE(cs35l35_stereo_controls));
 		if (ret)
 			return ret;
 	}
diff --git a/sound/soc/codecs/cs35l35.h b/sound/soc/codecs/cs35l35.h
index 621bfef..7cec198 100644
--- a/sound/soc/codecs/cs35l35.h
+++ b/sound/soc/codecs/cs35l35.h
@@ -273,6 +273,15 @@
 #define CS35L35_VMON_OVFL		0x08
 #define CS35L35_IMON_OVFL		0x04
 
+/* Mulit-Device Sync */
+#define CS35L35_SYNC_EN_MASK		0x01
+#define CS35L35_SYNC_MS_MASK		0x20
+#define CS35L35_SYNC_MS_SHIFT		5
+#define CS35L35_SYNC_MS_CTRL_MASK	0x10
+#define CS35L35_SYNC_MS_CTRL_SHIFT	4
+#define CS35L35_SYNC_CLK_SEL_MASK	0x02
+#define CS35L35_SYNC_CLK_SEL_SHIFT	1
+
 #define CS35L35_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | \
 			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
 
-- 
2.1.4

  reply	other threads:[~2017-05-18 15:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-18 15:32 [PATCH 1/4] ASoC: cs35l35: Add Boost Inductor Calculation Charles Keepax
2017-05-18 15:32 ` Charles Keepax [this message]
     [not found]   ` <1495121559-1063-4-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2017-05-29 13:53     ` [PATCH 4/4] ASoC: cs35l35: Add multi-device synchronisation Mark Brown
2017-05-30  8:51       ` Charles Keepax
2017-06-01 11:45         ` Charles Keepax
     [not found]         ` <20170530085138.GR1594-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2017-06-02 17:11           ` Mark Brown
     [not found] ` <1495121559-1063-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2017-05-18 15:32   ` [PATCH 2/4] ASoC: cs35l35: Add DT handling for Inductor Charles Keepax
     [not found]     ` <1495121559-1063-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2017-05-19 17:03       ` Applied "ASoC: cs35l35: Add DT handling for Inductor" to the asoc tree Mark Brown
2017-05-18 15:32   ` [PATCH 3/4] ASoC: cs35l35: Correctly handle 0 for bst_ipk Charles Keepax
     [not found]     ` <1495121559-1063-3-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2017-05-19 17:03       ` Applied "ASoC: cs35l35: Correctly handle 0 for bst_ipk" to the asoc tree Mark Brown
2017-05-19 17:03   ` Applied "ASoC: cs35l35: Add Boost Inductor Calculation" " Mark Brown
2017-05-22 13:18   ` [PATCH 1/4] ASoC: cs35l35: Add Boost Inductor Calculation Austin, Brian

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=1495121559-1063-4-git-send-email-ckeepax@opensource.wolfsonmicro.com \
    --to=ckeepax@opensource.wolfsonmicro.com \
    --cc=Paul.Handrigan@cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=brian.austin@cirrus.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=robh+dt@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.