Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751903AbdIOAbc (ORCPT ); Thu, 14 Sep 2017 20:31:32 -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 S1751752AbdIOAa6 (ORCPT ); Thu, 14 Sep 2017 20:30:58 -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:37 -0700 Message-Id: <1505435439-18012-2-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: d76b71b4-ddf3-4d37-2c83-08d4fbd10644 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;BLUPR11MB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BmXCdqZhaAVdzRi9iTQmaX7zsTAhS0Ix8pS4zJIiQB9pq0B2eNsQk2W9xcRAzS5auGzxFLJ7YNJZL90iUq1DYMrbmsGU+GDMwenzC3ZpJD2I8/8FhNcDb6PtAVQrrzkylv3pGHz/dPl+SdGYRZNzWihCzm0kcjQW57FdneXjbzDOSzaVpuCkPUzo+QliSFRhWgcwugsr5/VY38EccDg4WrAtu8/FFzzYMYPOgKo6YiG6CVmPaj+yoDBS0tL+Nvq96ehr5QpXSPNelqb5yu1aAJhB3HNldGD6jsCCAE+myELGjlj/a3eccWrRsS0u6mXi15jA9K6ZQ8+PoRcymH6ETcXxU1b6V46+n;4:80LylFDl8QjTWIJ90NEl9EdAU49yUBI5D8ictbH81chAkBlUozo3QXIJH4IthyduiJUiwWHqe27SiazILQzIeujIv2Q1t0CtR5jZyCg64tF4awNU5X+iWUdJrWrBNHGRV8xjf7HG1ZIscJgHRzH6/vZKUVgTM/GJ1AVG71jvhVqnwoAeGzPvzkTLqfjBm7vwjPYaFuUxhWHMJL72zb2CS+KHI2IrpCC658FIWmkEgnQM57q1mRbb0QWPI819PwZpLVzt+qU4+Xvc++XAq0xbZsiw8ZbnEJKiSo/pwYJ6W0Kr7eeZKsypwR5dhEhKlQ77iltTUknuTtmlzj+VVogEVQ== X-Exchange-Antispam-Report-Test: UriScan:(108721460000369)(17755550239193); 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)(54534003)(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:POaAUUn1Ti3DPujEy46La/bqrIsAB8df84TSbpKh4?= =?us-ascii?Q?08pP5s65+rl57jtDj7lV8Dd7/kr2RY7JUxt0AOFnVPNKKVQkT08SqUHANdQD?= =?us-ascii?Q?99gM2L1110X4gS1n1xUgiDjy2TDxu94xSsk7mLFAHje7Sffac3Mj8wsKwrHN?= =?us-ascii?Q?1DDnEZysusZeXyGVGSjVFic/dYseHvBaHvQkWxNvg9gqWBU3fmjtW5N9+E0l?= =?us-ascii?Q?LJRftafUkhFzxTq8LY93AWJetyxfJfa5jTOlknCEkKgCTgsunIoGZxu5JeWO?= =?us-ascii?Q?/3UfbpB/oUBabwdwvdCNGsgSdEnZOsM4h4+B9dWMPtgvq5FHgcKykXImUO6b?= =?us-ascii?Q?9p7SaykClu7K7m28dxIuCBTldDfztNFvFJErQDR+KBQ4TTSKqpxMPmP2xttm?= =?us-ascii?Q?pDvkG5L5PQQ1LpikoMV4PqaHisDC/6ZHKhAo8nDS754rGgMnMM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+oqCogPFzkAf1FCMShtR5VcZY3jBoI0CDhEUhfj0rUQ3w62671rrxkw5QWYyqEo9FiJwb1wmd089SyEA2IYaJTYNj39vEw07ZZ+ik0l6+MVsfV70/cX7M+55Zyrrke9jbgs+kJepCjQQIoBDu/NsnmjpWV9CEE7TKWqtlMVGW2Nwp/TduCgPvWCgSIw01Spsu8XSMZWITIsrml8oJkx3A0k6GY8mN1LNxKJaZg6t68P5jJWwU6ctDIMvZXvH74Jc9Zirt6o/1F6ZpgSFAdOXH0IwyV9YHB65bPqLiUc29w==;5:t4U2HpWUkwr99dFAPw1BJ6OKMmhLFyMO4dVdxErRsuf9SEmC7Oai/pXNR8TfopKoEqYF+nbX6RP4TcbnFBJ76+fiZSjGfd/iFfy0KOUIQfyuJ/G0skklHTjV/0C8zUhQh3ifRek9U7WwoSYR7iJ+UBqAjqfxCMna3oWSg0N7S0w=;24:IjSLifuZNfv4RbL8mVK2jtiBv5+zXyJ7T+UVai9ntxvEz+YfjpjMFlprWfV0He5JfL7bZvrXuS6S455I5KyhTmD7L8UwbYOG7bdvpFSA8qo=;7:KgZ6bj6vsm4k9e6eBPpeQ7VKnypH+BDx3GIOCpMcvansNoFoqwBRO+vo43ysUtxFuzKxRzepF7hCcl6wsqQkI9nEWfEjRkbahVjCKxzeThAjg33/z8Bus9hMTpJWkG5ht65Mm0u+EbqbjJaer5F6tYSGP/KTfnEH1UpS+vv+F4k6Q0iRCVGnTcNWSv3Bu6W4edxyKqLwMHVhjISzDnyNpp4l/r1Cm/FX5tEjQP5VnO4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: maximintegrated.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2017 00:30:52.8418 (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: 5234 Lines: 185 Signed-off-by: Ryan Lee --- Changelog: Added 'max98927_dai_tdm_slot' function to set proper slot configuration. Added variable 'tdm_mode' to avoid BCLK overwrite after 'max98927_dai_tdm_slot' configure BCLK value. :BCLK value is being set inside 'max98927_dai_tdm_slot' function when it is tdm mode because number of slots and slot width information is available here. :'max98927_set_clock' is called from hw_params and slot information is not available in this function so it can overwrite BCLK value. :Variable 'tdm_mode' will be cleared after SND_SOC_DAPM_POST_PMD event is recieved. Added 'max98927_get_bclk_sel' to avoid code duplication and support BCLK up to 512. sound/soc/codecs/max98927.c | 118 ++++++++++++++++++++++++++++++++++++++------ sound/soc/codecs/max98927.h | 1 + 2 files changed, 103 insertions(+), 16 deletions(-) diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c index 6f7b3ef..116cb9b 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, @@ -434,6 +519,7 @@ static int max98927_dac_event(struct snd_soc_dapm_widget *w, regmap_update_bits(max98927->regmap, MAX98927_R003A_AMP_EN, MAX98927_AMP_EN_MASK, 0); + max98927->tdm_mode = 0; break; default: return 0; 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