From patchwork Tue May 7 05:11:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 10932279 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 522CE924 for ; Tue, 7 May 2019 05:13:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F7D228879 for ; Tue, 7 May 2019 05:13:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 339AB2888E; Tue, 7 May 2019 05:13:26 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 336DD28879 for ; Tue, 7 May 2019 05:13:24 +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 B2D901803; Tue, 7 May 2019 07:12:32 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B2D901803 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557206002; bh=Oj+GBhErxa7qPw38ilgBVFgf955jAXdSVP5+qj4h9Sg=; h=Date:From:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=rwtRFwk0oi3jol69wrMEqXO3wXODCXcDDYPjMZP/7lPUhUBu1Oxeq3oarAKsrzM+H Bjl8lA3LsCizjlanlFX03QeddsBE6K8QNpjvoJ/S9FLIhVJFYaW7cCjjQKiCSnnNt4 HZbjwXI98D1gurNbOhrrlUSVoIU9qMG9p80F3MUw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 310B2F807B5; Tue, 7 May 2019 07:12:32 +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 A688DF89674; Tue, 7 May 2019 07:12:27 +0200 (CEST) Received: from mail-yw1-xc49.google.com (mail-yw1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 79C9AF89671 for ; Tue, 7 May 2019 07:12:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 79C9AF89671 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tmPYiA88" Received: by mail-yw1-xc49.google.com with SMTP id v123so29617166ywf.16 for ; Mon, 06 May 2019 22:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=Pvv2wbS5Kj009HIS8CNJwa937mTMwhbCEwAVBmg46RY=; b=tmPYiA88sQ238n487Rt0I0ebfaLgp4YU7aJEHj/2irRmaD6dkYf5Dfsqe2hWccHheh Vi16PnSs3saLor4yWFAv6hJ121FJMzS4xjXGekjAzjjDMoAJjONgGoMUXoRGsGXpGMQx 9OGNmkKUvKwftPDm3SeCzue/rAfyIISAmsLCwI2KxBcRk0Cc1J3PRO6v2VClivrbJIhN D77d9LW5YWnIDmOQGdy9EqlxHwoFOPCFDfT7zEkmD8Z1J7BSn3yS8K5KoHS9NnchpmNe m/z95A25xnrBcdmUz3FoGJdE5G4+Li/BQmp89PtkROpgtvznq/VLW/16RHu64g8/w7cj ug4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Pvv2wbS5Kj009HIS8CNJwa937mTMwhbCEwAVBmg46RY=; b=JfG6yAU8/8vuZPlmMYGqoF1sDJKvkj8Fgn0y8bu3LViQ4NqkgXKf0O0nbxBlca1Ii6 KOnftxPhrKgY7kf9o2ZKFymsep33ACwT3X2pwDgsanriYgYWJod84b+6hJ+XmfjTbMgT gMEj6iK3DsTPNlsKcJhWzaRnf800drWJZjprbISPo+WFAtGcjDLA4MNPxWqo9ByRGjc7 MNMM9GjbhUJQb3Fud/2WLG43+V/CmJfS6FCZZJwK4YouSsxEI76CajNMgwYah8xtVwL8 g4PTwpWHLRuhca/TOUGhmoyyPIMTVdAvazA30CcqWA2PykkUP4WnetiF3RiEIprvkCUM MjOA== X-Gm-Message-State: APjAAAU4Ba5wYxeZMYG7Va/LBagqVkVbN3I7Zl9VkLbxSRYAhNljMci/ TDzdx6ihZr+rb8hBOxiqh6g4zRA7QbQV X-Google-Smtp-Source: APXvYqxjP/I6HDLlioM/ew2vO9f68fgZSHblWQowF+5LEIF3/u78ItoyeSzrLRCiX0PEhOobcBR8UVOLGZQ0 X-Received: by 2002:a81:84cc:: with SMTP id u195mr21463128ywf.501.1557205942471; Mon, 06 May 2019 22:12:22 -0700 (PDT) Date: Tue, 7 May 2019 13:11:40 +0800 Message-Id: <20190507051140.240245-1-tzungbi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog From: Tzung-Bi Shih To: broonie@kernel.org, tiwai@suse.com Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH] ASoC: max98357a: release GPIO when component removing 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 Component's probe() gets GPIO for "sdmode-gpios" via devm_gpiod_get_optional(). The GPIO binds to the device. When the component get removed but the device does not, the GPIO still binds to the device. Then, when the component be probed again, devm_gpiod_get_optional() returns EBUSY. Release the GPIO proactively when component is removing. Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/max98357a.c | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c index d037a3e4d323..b11c6cb81f55 100644 --- a/sound/soc/codecs/max98357a.c +++ b/sound/soc/codecs/max98357a.c @@ -27,24 +27,28 @@ #include #include +struct max98357a_priv { + struct gpio_desc *sdmode; +}; + static int max98357a_daiops_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { - struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai); + struct max98357a_priv *max98357a = snd_soc_dai_get_drvdata(dai); - if (!sdmode) + if (!max98357a->sdmode) return 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: - gpiod_set_value(sdmode, 1); + gpiod_set_value(max98357a->sdmode, 1); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: - gpiod_set_value(sdmode, 0); + gpiod_set_value(max98357a->sdmode, 0); break; } @@ -61,19 +65,31 @@ static const struct snd_soc_dapm_route max98357a_dapm_routes[] = { static int max98357a_component_probe(struct snd_soc_component *component) { - struct gpio_desc *sdmode; + struct max98357a_priv *max98357a = + snd_soc_component_get_drvdata(component); - sdmode = devm_gpiod_get_optional(component->dev, "sdmode", GPIOD_OUT_LOW); - if (IS_ERR(sdmode)) - return PTR_ERR(sdmode); + max98357a->sdmode = devm_gpiod_get_optional(component->dev, + "sdmode", GPIOD_OUT_LOW); + if (IS_ERR(max98357a->sdmode)) + return PTR_ERR(max98357a->sdmode); - snd_soc_component_set_drvdata(component, sdmode); + snd_soc_component_set_drvdata(component, max98357a); return 0; } +static void max98357a_component_remove(struct snd_soc_component *component) +{ + struct max98357a_priv *max98357a = + snd_soc_component_get_drvdata(component); + + if (max98357a->sdmode) + devm_gpiod_put(component->dev, max98357a->sdmode); +} + static const struct snd_soc_component_driver max98357a_component_driver = { .probe = max98357a_component_probe, + .remove = max98357a_component_remove, .dapm_widgets = max98357a_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(max98357a_dapm_widgets), .dapm_routes = max98357a_dapm_routes, @@ -112,6 +128,14 @@ static struct snd_soc_dai_driver max98357a_dai_driver = { static int max98357a_platform_probe(struct platform_device *pdev) { + struct max98357a_priv *max98357a; + + max98357a = devm_kzalloc(&pdev->dev, sizeof(*max98357a), GFP_KERNEL); + if (!max98357a) + return -ENOMEM; + + dev_set_drvdata(&pdev->dev, max98357a); + return devm_snd_soc_register_component(&pdev->dev, &max98357a_component_driver, &max98357a_dai_driver, 1);