Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754345AbbFKLOO (ORCPT ); Thu, 11 Jun 2015 07:14:14 -0400 Received: from mail-bl2on0102.outbound.protection.outlook.com ([65.55.169.102]:52885 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752369AbbFKLN7 (ORCPT ); Thu, 11 Jun 2015 07:13:59 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; From: Zidan Wang To: CC: , , , , , , , , Zidan Wang Subject: [alsa-devel][PATCH 1/4] ASoC: wm8960: codec mclk should be enabled early to avoid jack detect error Date: Thu, 11 Jun 2015 19:14:33 +0800 Message-ID: <880838f666b591f5ffb0de1e39df5e3734846246.1434020423.git.zidan.wang@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD037;1:5gFu7ZirmqbJZ5vyv9oFwaDi01z5qjZ9OFNlK0e18ObkzuLEYHCAcGyQ30IPkRRwYqmi+wpg11o87p3CwbiYmga68N1VTWqF6X8UETL7NfTKu8rYkUeGFDPyXegfmx4ZI/Pv26UqADsY8PfNx+CUaarPHcQIL6nbGezQOM+d2hyGKPZ2ICWAqPiCYdYaViv4dwMMnqp0r31MCJz2gK3fTLVdEi9+rYR01nRohGdnnua5H364YqUspwO4cVUGxwyDxceIgPQl6fpm7W826BjjbsZyoXfUUT6eewU958lF8Qbwj/iwe8jgVRavqy1q9Fj4c4Vv1m07yFrdhwaq9v0h4+biwn6+EL8Mndpyitz5zgs= X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(189002)(199003)(229853001)(2950100001)(46102003)(48376002)(92566002)(104016003)(33646002)(86362001)(106466001)(189998001)(77156002)(62966003)(118296001)(6806004)(77096005)(50466002)(2351001)(19580395003)(110136002)(36756003)(107886002)(50226001)(5001960100002)(87936001)(50986999)(105606002)(85426001)(47776003)(76176999)(19580405001)(4001430100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BY1PR0301MB1256;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BY1PR0301MB1256;2:Wdc+xBFnLf5m9JmW6b7r9IboBLp8se8aHqGJ924zo9XP0gUqzYDgt2jxqXAhj6JN;2:lMU0sqar32V+Y6MFGtA7EGlP/6IVHRClTBHwbQTw+pughMy1lxi4KhWybUGTvmAgGcl9SBhPjRULpEADgmRQCTe2O6zm1KLI4voFhYLSzx0sHE/E3v00sLXcZKy3F1f0dmzTCr9P7JBhqxLMAnJ76+qFZ5qQ+RvH9hggCZooVqhCcNlJ4km3tIzHL+KJZkdh+QAqfmhcdfm4i8hIP9sU4n17ZwnZtOPshLixlb0ozZI=;6:/55tD9KRjOavdN3jZujNF6N3xEid2L88v1wFIG+oyCUnXM8H7lvK1QTS9INQWPE0xQbCJcdtdMokdDd2gKUDc6nT+1XpFKWSFz+3TQkwmsPk0uYAESdAWTahPB8pLbCwdR/4DQStoxcbkeZRami4SvAk8Ft1fPtLsi/NBW16gD0Ba/hkM4KTjb6R913P+83a6oUFRSW1doID6T7GE23S3uMLAM3oP5SWDjKg9WP1l8i0gX94vf7PMO1eFFGcjDjVmGIkdsbt/9m7jAJHp+Tg5rn7a93kmxjAQGkQyKidYG924VAxYWnDumv1O3dPpAU/t+rbqTT0/3vsbMzAlFotSg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0301MB1256; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)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7iCrVLULfs0Do3q1WhmewkezV8k5P59p8YK8CXpddQBomSEZlPtGtEzrBJOsBACVFPGM68zoPCwzWSn0VBBonnTKnzoKB5748kkKe/4UqmlZYy3lCEjYRoS53OV8FaDYmDdGh63IzFfmorOM5t5a+b4YwakmoWtsvhrjAJnF0u0YWsm3fSEOSzqkqrS0vRgOct+Li3qx+x7MVDPYl+ks5EVTR376FXY/l0Edg/NlgdWB/EqFstKw3m4/yb8qDPLnFuklO2yrm0Yi7ZfZJmzY6mlYXyp/YZ10TJl3AYq0WhAx+NBsvO8hDq/djYqQSgy8iB2PKRFJ7xxG8u+WZJNyOE7CPA= X-Microsoft-Exchange-Diagnostics: 1;BY1PR0301MB1256;3:Pve7zJHyVC8F31gVun0Bzsgamf3fAD5YYYZGr4DWE8doHKFC/5ce4TpZII33xpIvS2ESIPo7lqrt2Nx/kLVka6rJzz4cAqO2GTR8hX3iR+BeDOU5JMavgGd4xwkMQMe6ia08GB+/EQ7gfDTwZSDsJw==;10:y8sjlcdHG9s4r1n18dcGHgTG+J1oInTbw6AhTzHRU3ppIdZiMWov3Brw46xArcrKu8sOWN3jRb3U0QVavqv0ttxN0/VyccYGozqESQCcuQI=;6:3S/wh71GQOYTW3Yn0MijbH9BA2XqBAGCKqsY5JvSVhQ6iS79CyWP2qsc50TdJooE X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2015 11:13:50.7947 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0301MB1256 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3905 Lines: 140 It will playback from speaker in the first 2 seconds, then switch to headphone. Steps to reproduce this issue: 1. plug out headphone and playback a wav. 2. stop playback and wait for at least 5 seconds, then plug in headphone and playback a wav. Signed-off-by: Zidan Wang --- sound/soc/codecs/wm8960.c | 73 +++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 761418f..729205f 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -491,6 +491,34 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec) return 0; } +int wm8960_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *codec_dai) +{ + struct snd_soc_codec *codec = codec_dai->codec; + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); + int ret; + + if (!IS_ERR(wm8960->mclk)) { + ret = clk_prepare_enable(wm8960->mclk); + if (ret) { + dev_err(codec->dev, + "Failed to enable MCLK: %d\n", ret); + return ret; + } + } + return 0; +} + +void wm8960_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *codec_dai) +{ + struct snd_soc_codec *codec = codec_dai->codec; + struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); + + if (!IS_ERR(wm8960->mclk)) + clk_disable_unprepare(wm8960->mclk); +} + static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { @@ -702,38 +730,14 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); - int ret; switch (level) { case SND_SOC_BIAS_ON: break; case SND_SOC_BIAS_PREPARE: - switch (snd_soc_codec_get_bias_level(codec)) { - case SND_SOC_BIAS_STANDBY: - if (!IS_ERR(wm8960->mclk)) { - ret = clk_prepare_enable(wm8960->mclk); - if (ret) { - dev_err(codec->dev, - "Failed to enable MCLK: %d\n", - ret); - return ret; - } - } - - /* Set VMID to 2x50k */ - snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80); - break; - - case SND_SOC_BIAS_ON: - if (!IS_ERR(wm8960->mclk)) - clk_disable_unprepare(wm8960->mclk); - break; - - default: - break; - } - + /* Set VMID to 2x50k */ + snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80); break; case SND_SOC_BIAS_STANDBY: @@ -780,7 +784,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); - int reg, ret; + int reg; switch (level) { case SND_SOC_BIAS_ON: @@ -821,22 +825,9 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec, WM8960_VREF, WM8960_VREF); msleep(100); - - if (!IS_ERR(wm8960->mclk)) { - ret = clk_prepare_enable(wm8960->mclk); - if (ret) { - dev_err(codec->dev, - "Failed to enable MCLK: %d\n", - ret); - return ret; - } - } break; case SND_SOC_BIAS_ON: - if (!IS_ERR(wm8960->mclk)) - clk_disable_unprepare(wm8960->mclk); - /* Enable anti-pop mode */ snd_soc_update_bits(codec, WM8960_APOP1, WM8960_POBCTRL | WM8960_SOFT_ST | @@ -1059,6 +1050,8 @@ static int wm8960_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) static const struct snd_soc_dai_ops wm8960_dai_ops = { + .startup = wm8960_startup, + .shutdown = wm8960_shutdown, .hw_params = wm8960_hw_params, .digital_mute = wm8960_mute, .set_fmt = wm8960_set_dai_fmt, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/