Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751866AbdIOAbS (ORCPT ); Thu, 14 Sep 2017 20:31:18 -0400 Received: from mail-co1nam03on0130.outbound.protection.outlook.com ([104.47.40.130]:19017 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751726AbdIOAbA (ORCPT ); Thu, 14 Sep 2017 20:31:00 -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, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: ryan.lee.maxim@gmail.com Subject: [PATCH 2/2] ASoC: max98927: Added max98927_dai_tdm_slot function Date: Thu, 14 Sep 2017 17:30:39 -0700 Message-Id: <1505435439-18012-4-git-send-email-ryans.lee@maximintegrated.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505435439-18012-1-git-send-email-ryans.lee@maximintegrated.com> References: <1505435439-18012-1-git-send-email-ryans.lee@maximintegrated.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [204.17.143.20] X-ClientProxiedBy: MWHPR2201CA0034.namprd22.prod.outlook.com (10.174.164.47) To BLUPR11MB0835.namprd11.prod.outlook.com (10.163.217.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb574a08-2058-4cdc-cdef-08d4fbd107e7 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)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BLUPR11MB0835; X-Microsoft-Exchange-Diagnostics: 1;BLUPR11MB0835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HcXuuyylu0yRYQiD6ufGytEkTBs7h0cje2YUdJog9oHT7bxJGAouJMTYK9PiyMMmlqhESA5ImiVDB7tTNIugm08UEHThzGWCe8+pqFZ7fCRE/NzUAPyqrZPhjTDzXiJ7x8OTr1in5S5ghWHQhUk34C2+bw7HNud9bAjl1iAOG1FggMsjTw7sYvL6B3i/glPdMaAss7DwuW72UL911PeuAgeLzMGWggON+nLcDuqKTN0bCkZRDUrFIBYJJdZd39kjsmk0NxSUN8UI3DN954+YGhMfwBJ956WX68rDIQO1c9qljiyJt5QqF+2/wDJm1aT31SnSghAIlsb4GEj+VVT2V64zzwvHglaNVcpR1s;4:EngI96J54z9iMG0kuIc7Rn+wph8PzG80dM8wcVKdwTmQygbilX6tjPYsNbnZ4DYrPFK3sBmQSqTEr4XqQDtY9+/2vWfZc3wFJyze+Ut7VNxHrZTrZ87Z8J8tbUphM5S6qYzhGCacw9E5J/FoLhGZ7Po7w89yV9WMc2pfk47Mndj65OsV2vSicVXrxAlw1Fkh3Oy4GSTY1V7GiPVpTzdgiACvdpFGEeJWIFPIAVIRpm4PFjZ91ifntIFqUGPaCBAMqP/Jzmgve+fNCG8RNRcH+f+aob3jO+N1cQ+taVnbfgY= 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)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123555025)(20161123558100)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BLUPR11MB0835;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BLUPR11MB0835; X-Forefront-PRVS: 0431F981D8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(39860400002)(376002)(346002)(199003)(189002)(6512007)(5003940100001)(6486002)(305945005)(53416004)(101416001)(7736002)(2950100002)(5660300001)(97736004)(25786009)(2906002)(106356001)(68736007)(6506006)(76176999)(50466002)(189998001)(8936002)(6666003)(86362001)(53936002)(33646002)(36756003)(478600001)(81166006)(4326008)(50226002)(72206003)(66066001)(105586002)(39060400002)(50986999)(48376002)(110136004)(81156014)(16526017)(8676002)(16586007)(3846002)(69596002)(316002)(47776003)(6116002)(15760500002);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR11MB0835;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;BLUPR11MB0835;23:LR84ffzCtCqjgedi3wo5HpoQovNY/+3c3twNrBWNj?= =?us-ascii?Q?D5FoUlyTeBl6ltJITzVKypNPTACMWQFtsXTL/YEPgWeczSbDB9SjHB1opMrL?= =?us-ascii?Q?22Jkj7lWummu6GJyv6HJ6R4ujm36zBF89iVvUVVLctzJe/rVta13Kw07OYwt?= =?us-ascii?Q?P75lK4yAw0KXjCozNFjAqb1Q71WRgqLK89k9q7t1Sn3KA++BXe1qmEL29uHY?= =?us-ascii?Q?KFwNAh5JAByYPukJRy+LKM28DtMLXMdUewKwAFMVeCq9d2+LAc3zt/EqVIe+?= =?us-ascii?Q?cXeTRTVEy17FkxDWiq9leWwZcLpzC0cI4IpPM4jr/uXVwm9xsSUTv9hqdWoW?= =?us-ascii?Q?HVBVShCkU5g+gvPNbDPTZNTdMSfW+sSqSByOnuyaYSlIssrgUATITj68f9Xi?= =?us-ascii?Q?grTTYySQBHmah6wrd5Ae6tIYf8qKWTFXZbbbvCHgmqNzcOpKfiMiZBm83pTI?= =?us-ascii?Q?uOkngxPlt10Zezse8ksdTB81YcIF02wT5A7Ik67TxF48XqcuUYHaxg9NkowO?= =?us-ascii?Q?WjohOYaQ1PqfnZcwtx2rxGkRipcPV7tf43BEhcqanTqzrQCn7JdRgt3W6BAQ?= =?us-ascii?Q?oI2qKekImXhAkPcnhT3jtj/7XoIvJn5QKMM1fwfbN0TWgG3xcZatKO5G/0gI?= =?us-ascii?Q?QO59jgnD+t9pIo8zps3QxHFl8fWuTcnh0Xvb18V0v3NFiqqRtuJSvB2FHvig?= =?us-ascii?Q?tuWl+U63UPQ1mQWey7dTmKXmwBZ05ZXBXIo/rh59YeiEDBSCEjKK9AOASPBI?= =?us-ascii?Q?uNyMk6jay0HYX8cF2N+VShF7Pt+qOvkXTcaWgDPV9SWljHf3ProkESUYa5FV?= =?us-ascii?Q?Jh9acP5DSqCYldTBxAfYcMC1NvPv5rZxMmeoW4sgCsFIbh4YKDBXji6F7VwC?= =?us-ascii?Q?XChPCrUAtS5wNQhJvCB5nTBPe9BlWSmbsESg1JL94p2T+XmHNwQ9POGEDsJo?= =?us-ascii?Q?OyBQ+WYnoedUhXfsshDoAvzQ+9cYq3+S/KU6mlEt9NF1SRf60CssTqUroJzX?= =?us-ascii?Q?FF4u6iMytvHQLeEiOb9YORVMw/ojlvxjuIPqJIDXgsCxuKeXS/LLZtKrf03W?= =?us-ascii?Q?3M/YE9RjnjSHPd6zflVD2ujJLyvUqBPb+VXP0KNFeJOxRxDxsMgUa/EMav28?= =?us-ascii?Q?qiRVCvuG39nSOJqCI693xOqIyBNqTGGZHBcKZYYh9TYzROBa7AhHHdFJZWjS?= =?us-ascii?Q?y+CVdBi6iK7u++t5XWtEapwukY11HPaQ53O?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR11MB0835;6:9dwLKpxLjhpQgabRMJKpThhFtHkMEEnKbqRwUb7ZNRvObfFKtL0fcyUNFwvYp9+0FnbAcYUquJ9dau3EVAbmynlrgFl7u3c4uudT+URPBpP86cHiLZxvv880u8OdRVBcicqTI3OSHaljmncbH5UA4C9yKVoC19zB6u82e7qNsVip/4b1fcaiR6uY3isa/fnSffYgCzgbgKc0UN9+M2+f1efEuIjbw6AP5NQ3rKHuVw5/ed1k3o6srtVztgvvBH3WeRcnroPl6gpUC8b1eAZrKSCbHb0sg0+L/+ZDrVX9zk0vYLZLnOccFQI/d2d/b1HZcF928e1mdIUC/m1xN/j+aw==;5:ugNvgH13l1fdiCtiJOMKN2Z4cqPQYTr5fLUr5Su0bUAmgFgjShYvluLxHwr/OoSQrQX2zz6kT9h39sGGeaaWAhyepeQh8e2NC0YfZELPnIzrCimL2lGVk76kyteau7h17RDZ92m+7Q7YSyQ7Sb5YBj17roMEjnhMEATL9Y+rMVA=;24:yQLhQgIuOxx/upXpkba0SSzshDZB7bHBjs87oySah7nlf7enpbV/oMIy6c/JAVbIauV/75HZFMZdvIabG9H0bimIDLinzwze82MzPOHMdfE=;7:1UL3H1P4voIeJPB37CnHBr7hLqq+gESJNSs9S+pU+voTzRm/LtYYC1VfMeXUfVTs2qFVRAZfHHmiwZj8BOacGzDOseozx4MtbFCsU728zlVJP6Y/j0SYUjn6fqUs+36NLnc4xm3l791WEDZTvbeBLCrc40FjNZ5fA9uOuihJwR+k69oAjRlR/cYx++22vfdl/kWwHvIQg7KRt6MI7h/7X7xwRXSmk6UoeKf8TqRct7U= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: maximintegrated.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2017 00:30:55.6075 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fbd909df-ea69-4788-a554-f24b7854ad03 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR11MB0835 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4681 Lines: 179 Signed-off-by: Ryan Lee --- sound/soc/codecs/max98927.c | 120 ++++++++++++++++++++++++++++++++++++++------ sound/soc/codecs/max98927.h | 1 + 2 files changed, 105 insertions(+), 16 deletions(-) diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c index 6f7b3ef..a1d3935 100644 --- a/sound/soc/codecs/max98927.c +++ b/sound/soc/codecs/max98927.c @@ -250,6 +250,21 @@ static const int rate_table[] = { 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) { @@ -275,23 +290,20 @@ 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: - return -EINVAL; + if (!max98927->tdm_mode) { + /* BCLK configuration */ + value = max98927_get_bclk_sel(blr_clk_ratio); + if (!value) { + dev_err(codec->dev, "format unsupported %d\n", + params_format(params)); + return -EINVAL; + } + + regmap_update_bits(max98927->regmap, + MAX98927_R0022_PCM_CLK_SETUP, + MAX98927_PCM_CLK_SETUP_BSEL_MASK, + value); } - regmap_update_bits(max98927->regmap, - MAX98927_R0022_PCM_CLK_SETUP, - MAX98927_PCM_CLK_SETUP_BSEL_MASK, - value); return 0; } @@ -391,6 +403,78 @@ 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; + + max98927->tdm_mode = true; + + /* 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 | \ @@ -410,6 +494,7 @@ static const struct snd_soc_dai_ops max98927_dai_ops = { .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, @@ -419,6 +504,9 @@ static int max98927_dac_event(struct snd_soc_dapm_widget *w, struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec); switch (event) { + case SND_SOC_DAPM_PRE_PMU: + max98927->tdm_mode = 0; + break; case SND_SOC_DAPM_POST_PMU: regmap_update_bits(max98927->regmap, MAX98927_R003A_AMP_EN, diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h index bf7a6f92..9ea8397 100644 --- a/sound/soc/codecs/max98927.h +++ b/sound/soc/codecs/max98927.h @@ -270,5 +270,6 @@ struct max98927_priv { unsigned int iface; unsigned int master; unsigned int digital_gain; + bool tdm_mode; }; #endif -- 2.7.4