From patchwork Wed Apr 17 10:05:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akshu Agrawal X-Patchwork-Id: 10905103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA69217E0 for ; Wed, 17 Apr 2019 10:06:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8FA289EC for ; Wed, 17 Apr 2019 10:06:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F88E28A5C; Wed, 17 Apr 2019 10:06:22 +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,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,MISSING_HEADERS,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 61F85289EC for ; Wed, 17 Apr 2019 10:06:21 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D162C84D; Wed, 17 Apr 2019 12:05:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D162C84D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1555495578; bh=K0CNEvsFiZNTPVPcyEdK6ewYrMSYeJd5FI92odF9xBk=; h=From:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=WuYoveafJO6Jmiludant9VHPjErWIy0r/7l7+WP+IFd6zSgXSMUMWaff9AoGrSZNq 4oj2+2yzHD62AScaUNSAIHNnaUcos4e82xrW8aNbsGKLoC6iYRsYLxuqrPDHlmQGKo WMJhK8Ok0biiQn16o4pluKFBcybIzN0/buS9vO9Y= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4962EF896EA; Wed, 17 Apr 2019 12:05:28 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 46163F896EC; Wed, 17 Apr 2019 12:05:26 +0200 (CEST) Received: from NAM05-DM3-obe.outbound.protection.outlook.com (mail-eopbgr730080.outbound.protection.outlook.com [40.107.73.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id ED443F896E2 for ; Wed, 17 Apr 2019 12:05:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz ED443F896E2 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="x3OdOQU7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2roTmt/UVCUG/E3QyPzabwPhhj+9FPZqhVgX2Et4iEw=; b=x3OdOQU76mxjh3rjqJoOJgtEqAk9KOv0o4HFT3vYrE7P9wuS97pIsezrFvY7APaP/iq1YBVjAivSO7pfO57QoShKzCL4KSI8dPPgaplz2GrW+EW0ncgnBaTekRE4+3k+2pfHGBBBIy3otnmUl0a/Jz21E9lREPeeam14Cd12ZzY= Received: from MN2PR12MB2878.namprd12.prod.outlook.com (20.179.80.143) by MN2PR12MB3360.namprd12.prod.outlook.com (20.178.241.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.19; Wed, 17 Apr 2019 10:05:14 +0000 Received: from MN2PR12MB2878.namprd12.prod.outlook.com ([fe80::c5a0:395e:b9c6:4e5a]) by MN2PR12MB2878.namprd12.prod.outlook.com ([fe80::c5a0:395e:b9c6:4e5a%6]) with mapi id 15.20.1792.018; Wed, 17 Apr 2019 10:05:14 +0000 From: "Agrawal, Akshu" Thread-Topic: [v3] ASoC: AMD: Configure wclk and bclk of master codec Thread-Index: AQHU9QUM4SzXG9ec60yG0w+RonnVUg== Date: Wed, 17 Apr 2019 10:05:13 +0000 Message-ID: <20190417100447.10321-1-akshu.agrawal@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR01CA0080.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00::20) To MN2PR12MB2878.namprd12.prod.outlook.com (2603:10b6:208:aa::15) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Akshu.Agrawal@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.156.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1d453517-0d3b-4413-97ba-08d6c31c2e39 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600140)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:MN2PR12MB3360; x-ms-traffictypediagnostic: MN2PR12MB3360: x-microsoft-antispam-prvs: x-forefront-prvs: 0010D93EFE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(136003)(346002)(366004)(376002)(189003)(199004)(6506007)(6512007)(186003)(54906003)(102836004)(66066001)(386003)(59246006)(5660300002)(14454004)(26005)(476003)(72206003)(97736004)(81166006)(486006)(478600001)(99286004)(14444005)(50226002)(8936002)(71200400001)(256004)(2616005)(52116002)(6436002)(6486002)(6116002)(68736007)(71190400001)(1076003)(7416002)(81156014)(8676002)(4326008)(316002)(2906002)(7736002)(36756003)(1671002)(305945005)(25786009)(3846002)(105586002)(86362001)(106356001)(109986005)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR12MB3360; H:MN2PR12MB2878.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 2UheofrJF1rozGxJlbP7RpMVRyZo2WATgKNkzdUN+a+G6c5r55gZdccV2iwaP5Twy0x0n//VOPydhbQ1bsSWqotI2kLAwGMgxRU90EGTG44z9aUxD18jVTUc7+YhPkpaz4sNAa81Nn7/N8n7a8cQA0LT2X0tsGVAjhNUR5MzOtp2eG54OMUUPSXEuSYEPvqr+gDGazuLAX750OSxdoGCzpkXQYAG9i6Yxg5hhmWKoh5mr1HxQWqJ3I7LgE1ej2YF8+1M9lm3m3qdqSHV5FoQL1GerZ855dpayGu7E6ESdZSpHOnGKRZR/u/sgO4yhKLWSR55tahc8fHiieL8O0yG0lPl/qVNqbxmOQxeOLVX7BLL9lgdylT7NxatDEj2V1OLvOGlhiJGUSUBSniSx6IEtf90P3nk9pM1M3JP440XFvw= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d453517-0d3b-4413-97ba-08d6c31c2e39 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Apr 2019 10:05:13.4319 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3360 Cc: "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Andi Kleen , open list , Takashi Iwai , Liam Girdwood , "djkurtz@chromium.org" , "Agrawal, Akshu" , Julia Lawall , Mark Brown , "Mukunda, Vijendar" , "Deucher, Alexander" , "Adam.Thomson.Opensource@diasemi.com" Subject: [alsa-devel] [v3] ASoC: AMD: Configure wclk and bclk of master codec X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP With CCF support in da7219, we can now set the correct rate of wclk and bclk. Signed-off-by: Akshu Agrawal --- v2: Removed clk set rate and enable/disable from da7219 ops as da7219 codec takes care of them internally. Clock configuration kept for those codecs where da7219 acts as master of clock. As suggested by Adam Thomson. v3: As per spec, adau7002 bclk to be minimum of 64x of wclk. Hence, limiting bclk for all codecs. Also, because of this changes done in v2 of this patch have to be brought back. sound/soc/amd/acp-da7219-max98357a.c | 66 ++++++++++++++++++---------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/sound/soc/amd/acp-da7219-max98357a.c b/sound/soc/amd/acp-da7219-max98357a.c index 8a619a75b3a9..16b0ea3a3d72 100644 --- a/sound/soc/amd/acp-da7219-max98357a.c +++ b/sound/soc/amd/acp-da7219-max98357a.c @@ -46,7 +46,8 @@ #define DUAL_CHANNEL 2 static struct snd_soc_jack cz_jack; -static struct clk *da7219_dai_clk; +static struct clk *da7219_dai_wclk; +static struct clk *da7219_dai_bclk; extern bool bt_uart_enable; static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) @@ -72,7 +73,8 @@ static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) return ret; } - da7219_dai_clk = clk_get(component->dev, "da7219-dai-bclk"); + da7219_dai_wclk = clk_get(component->dev, "da7219-dai-wclk"); + da7219_dai_bclk = clk_get(component->dev, "da7219-dai-bclk"); ret = snd_soc_card_jack_new(card, "Headset Jack", SND_JACK_HEADSET | SND_JACK_LINEOUT | @@ -94,12 +96,15 @@ static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) return 0; } -static int da7219_clk_enable(struct snd_pcm_substream *substream) +static int da7219_clk_enable(struct snd_pcm_substream *substream, + int wclk_rate, int bclk_rate) { int ret = 0; struct snd_soc_pcm_runtime *rtd = substream->private_data; - ret = clk_prepare_enable(da7219_dai_clk); + clk_set_rate(da7219_dai_wclk, wclk_rate); + clk_set_rate(da7219_dai_bclk, bclk_rate); + ret = clk_prepare_enable(da7219_dai_bclk); if (ret < 0) { dev_err(rtd->dev, "can't enable master clock %d\n", ret); return ret; @@ -110,7 +115,7 @@ static int da7219_clk_enable(struct snd_pcm_substream *substream) static void da7219_clk_disable(void) { - clk_disable_unprepare(da7219_dai_clk); + clk_disable_unprepare(da7219_dai_bclk); } static const unsigned int channels[] = { @@ -151,7 +156,7 @@ static int cz_da7219_play_startup(struct snd_pcm_substream *substream) &constraints_rates); machine->play_i2s_instance = I2S_SP_INSTANCE; - return da7219_clk_enable(substream); + return 0; } static int cz_da7219_cap_startup(struct snd_pcm_substream *substream) @@ -173,12 +178,7 @@ static int cz_da7219_cap_startup(struct snd_pcm_substream *substream) machine->cap_i2s_instance = I2S_SP_INSTANCE; machine->capture_channel = CAP_CHANNEL1; - return da7219_clk_enable(substream); -} - -static void cz_da7219_shutdown(struct snd_pcm_substream *substream) -{ - da7219_clk_disable(); + return 0; } static int cz_max_startup(struct snd_pcm_substream *substream) @@ -199,12 +199,7 @@ static int cz_max_startup(struct snd_pcm_substream *substream) &constraints_rates); machine->play_i2s_instance = I2S_BT_INSTANCE; - return da7219_clk_enable(substream); -} - -static void cz_max_shutdown(struct snd_pcm_substream *substream) -{ - da7219_clk_disable(); + return 0; } static int cz_dmic0_startup(struct snd_pcm_substream *substream) @@ -225,7 +220,7 @@ static int cz_dmic0_startup(struct snd_pcm_substream *substream) &constraints_rates); machine->cap_i2s_instance = I2S_BT_INSTANCE; - return da7219_clk_enable(substream); + return 0; } static int cz_dmic1_startup(struct snd_pcm_substream *substream) @@ -247,10 +242,28 @@ static int cz_dmic1_startup(struct snd_pcm_substream *substream) machine->cap_i2s_instance = I2S_SP_INSTANCE; machine->capture_channel = CAP_CHANNEL0; - return da7219_clk_enable(substream); + return 0; } -static void cz_dmic_shutdown(struct snd_pcm_substream *substream) +static int cz_da7219_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + int wclk, bclk; + + wclk = params_rate(params); + bclk = wclk * params_channels(params) * + snd_pcm_format_width(params_format(params)); + /* ADAU7002 spec: "The ADAU7002 requires a BCLK rate + * that is minimum of 64x the LRCLK sample rate." + * DA7219 is the only clk source so for all codecs + * we have to limit bclk to 64X lrclk. + */ + if (bclk < (wclk * 64)) + bclk = wclk * 64; + return da7219_clk_enable(substream, wclk, bclk); +} + +static void cz_da7219_shutdown(struct snd_pcm_substream *substream) { da7219_clk_disable(); } @@ -258,26 +271,31 @@ static void cz_dmic_shutdown(struct snd_pcm_substream *substream) static const struct snd_soc_ops cz_da7219_play_ops = { .startup = cz_da7219_play_startup, .shutdown = cz_da7219_shutdown, + .hw_params = cz_da7219_params, }; static const struct snd_soc_ops cz_da7219_cap_ops = { .startup = cz_da7219_cap_startup, .shutdown = cz_da7219_shutdown, + .hw_params = cz_da7219_params, }; static const struct snd_soc_ops cz_max_play_ops = { .startup = cz_max_startup, - .shutdown = cz_max_shutdown, + .shutdown = cz_da7219_shutdown, + .hw_params = cz_da7219_params, }; static const struct snd_soc_ops cz_dmic0_cap_ops = { .startup = cz_dmic0_startup, - .shutdown = cz_dmic_shutdown, + .shutdown = cz_da7219_shutdown, + .hw_params = cz_da7219_params, }; static const struct snd_soc_ops cz_dmic1_cap_ops = { .startup = cz_dmic1_startup, - .shutdown = cz_dmic_shutdown, + .shutdown = cz_da7219_shutdown, + .hw_params = cz_da7219_params, }; static struct snd_soc_dai_link cz_dai_7219_98357[] = {