Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751297AbdH1Xbg (ORCPT ); Mon, 28 Aug 2017 19:31:36 -0400 Received: from mail-cys01nam02on0125.outbound.protection.outlook.com ([104.47.37.125]:29802 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751237AbdH1Xbe (ORCPT ); Mon, 28 Aug 2017 19:31:34 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=RyanS.Lee@maximintegrated.com; From: Ryan Lee To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, ryans.lee@maximintegrated.com, kuninori.morimoto.gx@renesas.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: ryan.lee.maxim@gmail.com Subject: [PATCH 1/9] ASoC: max98927: Added support for DSP_A and DSP_B format Date: Mon, 28 Aug 2017 16:30:53 -0700 Message-Id: <1503963061-14763-1-git-send-email-ryans.lee@maximintegrated.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [204.17.143.20] X-ClientProxiedBy: BN6PR16CA0010.namprd16.prod.outlook.com (10.172.212.148) To SN1PR11MB0848.namprd11.prod.outlook.com (10.163.208.146) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 916d80c0-310b-420a-bd67-08d4ee6ce9c5 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN1PR11MB0848; X-Microsoft-Exchange-Diagnostics: 1;SN1PR11MB0848;3:MTgqQ92lPpnMOqhFS/8cpbwa4qWqC299+5MtJLj34K+ojlzPJchbWGClJPYEskvG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ZW6YXesQj980neMLycoBTOwnZgjgsyA28T237xUlW2BEtgH2THXZF1QwSXS0EdjxFh1smhw26ms5GbRVIBqmlVv7V9IZzSVpBzWvq9ByYKg33uUgSfHZ0FM5BEoUofWpb0zD8uK5NZ48YXr/3r9oRImB36BSf0wqb3C5rd2K418Fg4B44+LLH3Ri+M8cjmJKpqiMq9KzRgjgGn/7DnI7GlfIXdEXWkcjdc9WDxnFgHpQuL6EgttcmKYdmtZHy1R5SqPG9svM5lDz92Wwg3XcRLKKc0eLopK6yBd;4:ixHXnK/XshPKWs7Dp6RpH4sYUIiPquTBwDvWZI7pG7Nk5c0Kf4+6/dXud/sqBHcJFpjBvtzLP26pq8NH2gBPR2d9r9A9vlQtsTuXfibIq+OoNbso3hQeouP30uHoB4tmQAf697u/p8tnyfBMJPzpXT3AAQrVwRVRkOAG6xTP4Yd30j+Yqm/B2FwuIRNr478TbgFOKRxlrHfHM2sXr5cUAfXYXyj/kz/9mJiIKs0toi39qVUc8WSfzelc6K+B8OnmjMFRDZ4zYGY3ZqeZxQGKQBZ1TQikF2MCVdEKqK4s+S0= X-Exchange-Antispam-Report-Test: UriScan:(108721460000369); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123564025)(20161123555025)(20161123562025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN1PR11MB0848;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN1PR11MB0848; X-Forefront-PRVS: 0413C9F1ED X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(7370300001)(6009001)(39860400002)(199003)(189002)(105586002)(33646002)(106356001)(189998001)(2906002)(6512007)(86362001)(50986999)(53416004)(110136004)(42186005)(66066001)(7350300001)(6116002)(68736007)(4326008)(47776003)(3846002)(5003940100001)(8676002)(50466002)(48376002)(81156014)(25786009)(101416001)(81166006)(6486002)(6506006)(6666003)(478600001)(50226002)(53936002)(36756003)(72206003)(305945005)(97736004)(5660300001)(69596002)(7736002)(2004002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR11MB0848;H:ryan-ThinkPad-T430.maxim-ic.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR11MB0848;23:N01fMR+hm8Ba3JIoelk1tqcaNZ5xIJveG4dOOCtbC?= =?us-ascii?Q?R/jQ6IXOZiAQ9tnBm8FnLHoBNl0UW1hw3taINGBut5ruDWOS0FO/T/Fg5+Ll?= =?us-ascii?Q?NEXuBAhgo3KewggqAEftDyXGK/vFS8WPE/sIh06vFb+nMBXWPUB+BwmffYcA?= =?us-ascii?Q?aJrkhhqCAtBXDywMK3AGxa1aFZe5iHOAyS6iVMgE6M1ia6gUvL2Av6kq3pAB?= =?us-ascii?Q?a4pPZWDCWWQI3w4eI7eTsN5zC3JkOfNXPbLF48rz3vFF0a0YVQ41PHc8KpQq?= =?us-ascii?Q?9rR2TfySSv2VW9p5klY66hCVAi3Rb+SBXMNsLDLqFCyP2KPOhh0pbQ6rICAk?= =?us-ascii?Q?J59KD/Ej/etRcrwq5+hTtUzUwzJ/nwmFPl5jpOUr2m4s/t7hvYwh2GXw7LAB?= =?us-ascii?Q?bqA5Xz/4fBG3XPgUnTytG3Gp41Mn0O3KaaLRh65m2DW93MHmSoAe9S+IKoum?= =?us-ascii?Q?X8AbS2hwZ/KKcmybsh1yv2V+OQb9EirgPKrH5TIQn5mqmIpf4x7wHJBqZmW0?= =?us-ascii?Q?FrfQjTA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fS0EnEOZujMINX3xzHqFxLHXNAD2eu5gDvrglFe9IFhE66g==;5:+K+rq8xUoioGToS/UolcHxw0AsEjx1HtDJzu8nWvJQ2z2xiKiRQ1JV3FSjcrMMWU5te7KYx85MDcO20NtKT1n+JN+3L5kJXVOroJ7+WuXJW2F8ILDSWHVshWqM2cNIgANLoiRH7wrgXDlDwVARhmWg==;24:HXrXxYBgrlfdNpfrA5V1dxnNmHFfeBeBnnIx+HJU6PCmWD9VCO2XitN3LbDcgm5ZyQnpeZyiFsVOxmksAuftjKC5TwGz/oz2Bnd7FG/qjrU=;7:t2cUG0FawrwZ5fDZmpHVvT6qVNI4lWQCaeTAeSdP8xvriwtyA03R6Wpf3PHIRXq92S1Z1buaUecXdPGZf9LrZPLvoAzyvsn40j2xvUmVl002wJlNJBitsw/b5xP2ZuR7OJBNkly6zt+2/wpaCF3COD/vUVqsGs2fO5/FeXulxLrS9wUaWoqd5uSRoJHE9yzuyWX2H9Hkjz3eL0Tdw/GMM//j2mNIvQ1lywQjXSj0xUQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: maximintegrated.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2017 23:31:30.1073 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR11MB0848 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7621 Lines: 256 Signed-off-by: Ryan Lee --- sound/soc/codecs/max98927.c | 141 ++++++++++++++++++++++++++++++++++++-------- sound/soc/codecs/max98927.h | 6 +- 2 files changed, 120 insertions(+), 27 deletions(-) diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c index b0380b5..951cc05 100644 --- a/sound/soc/codecs/max98927.c +++ b/sound/soc/codecs/max98927.c @@ -1,7 +1,7 @@ /* * max98927.c -- MAX98927 ALSA Soc Audio driver * - * Copyright (C) 2016 Maxim Integrated Products + * Copyright (C) 2016-2017 Maxim Integrated Products * Author: Ryan Lee * * This program is free software; you can redistribute it and/or modify it @@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec); unsigned int mode = 0; unsigned int format = 0; + bool use_pdm = false; unsigned int invert = 0; dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt); @@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) /* interface format */ switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: - max98927->iface |= SND_SOC_DAIFMT_I2S; format = MAX98927_PCM_FORMAT_I2S; break; case SND_SOC_DAIFMT_LEFT_J: - max98927->iface |= SND_SOC_DAIFMT_LEFT_J; format = MAX98927_PCM_FORMAT_LJ; break; + case SND_SOC_DAIFMT_DSP_A: + format = MAX98927_PCM_FORMAT_TDM_MODE1; + break; + case SND_SOC_DAIFMT_DSP_B: + format = MAX98927_PCM_FORMAT_TDM_MODE0; + break; case SND_SOC_DAIFMT_PDM: - max98927->iface |= SND_SOC_DAIFMT_PDM; + use_pdm = true; break; default: return -EINVAL; } + max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK; - /* pcm channel configuration */ - if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) { + if (!use_pdm) { + /* pcm channel configuration */ regmap_update_bits(max98927->regmap, MAX98927_R0018_PCM_RX_EN_A, MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, @@ -217,13 +223,12 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) MAX98927_R003B_SPK_SRC_SEL, MAX98927_SPK_SRC_MASK, 0); - } else regmap_update_bits(max98927->regmap, - MAX98927_R0018_PCM_RX_EN_A, - MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0); + MAX98927_R0035_PDM_RX_CTRL, + MAX98927_PDM_RX_EN_MASK, 0); - /* pdm channel configuration */ - if (max98927->iface & SND_SOC_DAIFMT_PDM) { + } else { + /* pdm channel configuration */ regmap_update_bits(max98927->regmap, MAX98927_R0035_PDM_RX_CTRL, MAX98927_PDM_RX_EN_MASK, 1); @@ -231,10 +236,12 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) regmap_update_bits(max98927->regmap, MAX98927_R003B_SPK_SRC_SEL, MAX98927_SPK_SRC_MASK, 3); - } else + regmap_update_bits(max98927->regmap, - MAX98927_R0035_PDM_RX_CTRL, - MAX98927_PDM_RX_EN_MASK, 0); + MAX98927_R0018_PCM_RX_EN_A, + MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0); + + } return 0; } @@ -245,6 +252,21 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 13000000, 19200000, }; +/* BCLKs per LRCLK */ +static const int bclk_sel_table[] = { + 32, 48, 64, 96, 128, 192, 256, 384, 512, +}; + +static int max98927_get_bclk_sel(int bclk) +{ + int i; + /* match BCLKs per LRCLK */ + for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) { + if (bclk_sel_table[i] == bclk) + return i + 2; + } + return 0; +} static int max98927_set_clock(struct max98927_priv *max98927, struct snd_pcm_hw_params *params) { @@ -270,19 +292,17 @@ static int max98927_set_clock(struct max98927_priv *max98927, i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT); } - switch (blr_clk_ratio) { - case 32: - value = 2; - break; - case 48: - value = 3; - break; - case 64: - value = 4; - break; - default: + if ((max98927->iface == SND_SOC_DAIFMT_DSP_A) || + (max98927->iface == SND_SOC_DAIFMT_DSP_B)) + return 0; + + /* BCLK configuration */ + value = max98927_get_bclk_sel(blr_clk_ratio); + if (!value) { + dev_err(codec->dev, "BCLK %d not supported\n", blr_clk_ratio); return -EINVAL; } + regmap_update_bits(max98927->regmap, MAX98927_R0022_PCM_CLK_SETUP, MAX98927_PCM_CLK_SETUP_BSEL_MASK, @@ -386,6 +406,76 @@ static int max98927_dai_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } +static int max98927_dai_tdm_slot(struct snd_soc_dai *dai, + unsigned int tx_mask, unsigned int rx_mask, + int slots, int slot_width) +{ + struct snd_soc_codec *codec = dai->codec; + struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec); + int bsel = 0; + unsigned int chan_sz = 0; + + /* BCLK configuration */ + bsel = max98927_get_bclk_sel(slots * slot_width); + if (bsel == 0) { + dev_err(codec->dev, "BCLK %d not supported\n", + slots * slot_width); + return -EINVAL; + } + + regmap_update_bits(max98927->regmap, + MAX98927_R0022_PCM_CLK_SETUP, + MAX98927_PCM_CLK_SETUP_BSEL_MASK, + bsel); + + /* Channel size configuration */ + switch (slot_width) { + case 16: + chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_16; + break; + case 24: + chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_24; + break; + case 32: + chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32; + break; + default: + dev_err(codec->dev, "format unsupported %d\n", + slot_width); + return -EINVAL; + } + + regmap_update_bits(max98927->regmap, + MAX98927_R0020_PCM_MODE_CFG, + MAX98927_PCM_MODE_CFG_CHANSZ_MASK, chan_sz); + + /* Rx slot configuration */ + regmap_write(max98927->regmap, + MAX98927_R0018_PCM_RX_EN_A, + rx_mask & 0xFF); + regmap_write(max98927->regmap, + MAX98927_R0019_PCM_RX_EN_B, + (rx_mask & 0xFF00) >> 8); + + /* Tx slot configuration */ + regmap_write(max98927->regmap, + MAX98927_R001A_PCM_TX_EN_A, + tx_mask & 0xFF); + regmap_write(max98927->regmap, + MAX98927_R001B_PCM_TX_EN_B, + (tx_mask & 0xFF00) >> 8); + + /* Tx slot Hi-Z configuration */ + regmap_write(max98927->regmap, + MAX98927_R001C_PCM_TX_HIZ_CTRL_A, + ~tx_mask & 0xFF); + regmap_write(max98927->regmap, + MAX98927_R001D_PCM_TX_HIZ_CTRL_B, + (~tx_mask & 0xFF00) >> 8); + + return 0; +} + #define MAX98927_RATES SNDRV_PCM_RATE_8000_48000 #define MAX98927_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ @@ -405,6 +495,7 @@ static int max98927_dai_set_sysclk(struct snd_soc_dai *dai, .set_sysclk = max98927_dai_set_sysclk, .set_fmt = max98927_dai_set_fmt, .hw_params = max98927_dai_hw_params, + .set_tdm_slot = max98927_dai_tdm_slot, }; static int max98927_dac_event(struct snd_soc_dapm_widget *w, diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h index ece6a60..bf7a6f92 100644 --- a/sound/soc/codecs/max98927.h +++ b/sound/soc/codecs/max98927.h @@ -1,7 +1,7 @@ /* * max98927.h -- MAX98927 ALSA Soc Audio driver * - * Copyright 2013-15 Maxim Integrated Products + * Copyright (C) 2016-2017 Maxim Integrated Products * Author: Ryan Lee * * This program is free software; you can redistribute it and/or modify it @@ -161,7 +161,9 @@ #define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3) #define MAX98927_PCM_FORMAT_I2S (0x0 << 0) #define MAX98927_PCM_FORMAT_LJ (0x1 << 0) - +#define MAX98927_PCM_FORMAT_TDM_MODE0 (0x3 << 0) +#define MAX98927_PCM_FORMAT_TDM_MODE1 (0x4 << 0) +#define MAX98927_PCM_FORMAT_TDM_MODE2 (0x5 << 0) #define MAX98927_PCM_MODE_CFG_CHANSZ_MASK (0x3 << 6) #define MAX98927_PCM_MODE_CFG_CHANSZ_16 (0x1 << 6) #define MAX98927_PCM_MODE_CFG_CHANSZ_24 (0x2 << 6) -- 1.9.1