From patchwork Thu May 18 15:32:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 9734687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ABFEA601BC for ; Thu, 18 May 2017 15:31:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 942832887E for ; Thu, 18 May 2017 15:31:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8905B2888B; Thu, 18 May 2017 15:31:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9FF12887E for ; Thu, 18 May 2017 15:31:32 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 6BEAB2671DF; Thu, 18 May 2017 17:31:30 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1E0DE267211; Thu, 18 May 2017 17:31:29 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by alsa0.perex.cz (Postfix) with ESMTP id 5CC4C2671BE for ; Thu, 18 May 2017 17:31:25 +0200 (CEST) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v4IFSVTt013176; Thu, 18 May 2017 10:31:25 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.wolfsonmicro.com Received: from mail1.cirrus.com (mail1.cirrus.com [141.131.3.20]) by mx0b-001ae601.pphosted.com with ESMTP id 2adxjk2mj1-1; Thu, 18 May 2017 10:31:25 -0500 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail1.cirrus.com (Postfix) with ESMTP id A57196121AD5; Thu, 18 May 2017 10:31:24 -0500 (CDT) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Thu, 18 May 2017 16:31:24 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.223.36]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id v4IFUMoL010349; Thu, 18 May 2017 16:30:22 +0100 From: Charles Keepax To: , Date: Thu, 18 May 2017 16:32:39 +0100 Message-ID: <1495121559-1063-4-git-send-email-ckeepax@opensource.wolfsonmicro.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495121559-1063-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> References: <1495121559-1063-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> MIME-Version: 1.0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705180101 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: [alsa-devel] [PATCH 4/4] ASoC: cs35l35: Add multi-device synchronisation X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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)