From patchwork Fri Jul 13 15:36:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10523599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9AE5B60626 for ; Fri, 13 Jul 2018 15:39:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89A3D29BBC for ; Fri, 13 Jul 2018 15:39:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DEDA29BCC; Fri, 13 Jul 2018 15:39:35 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B88CC29BC7 for ; Fri, 13 Jul 2018 15:39:34 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 760F4267732; Fri, 13 Jul 2018 17:39:27 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 7377A26772A; Fri, 13 Jul 2018 17:39:24 +0200 (CEST) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by alsa0.perex.cz (Postfix) with ESMTP id 97E16267727 for ; Fri, 13 Jul 2018 17:39:22 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id a3-v6so16329450wrt.2 for ; Fri, 13 Jul 2018 08:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MzGp1j0ioWGKIzF4+VhKRBq/gMz1o36NO5cj7JYy6/I=; b=fEBEpc519bIcEIfUAJ8WbWRjMN81gnjLQ7wWbdcC4CPV7K84EyA1AYJY9T0+RsY9Nd wttg4qIEZl3ewEoDViECfR6x373I1sMfENgO+0Cy62SM5dlmfPOd3OOE36KkQOIFJVj/ oX7vczhg74ZG/DEa8TSwsbC1rLJjBbzxaz98k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MzGp1j0ioWGKIzF4+VhKRBq/gMz1o36NO5cj7JYy6/I=; b=C21aofnmiJ8L9h1xlSLubin2+1qVBId/1b+p1TT1+9fH3JVi9BMIGvytQUx9xVoT4D 20QY3N+rsWUSXDeHPiRqRP9tSVTQ4pc6+0D4YgeTidelfY26PguMVxuComOgQU6TNETb QlbTgXiULMZET/JLth+V787EBqcveFzPlVeDni7osb8Rcmi4jesDI0eJXujJ0AM5Ofg6 xn0jC9OHx+YZick3r+TtXHxOD8x0eAudikantIxlFJk1dWXyl0sQ1w7d96pvpJsXncAU J4ywce6ClC1Pm24/RqrpXMLj7by3hwMziup09W2xF4jgzrtzEuDi+Y2wjLm1iOfTc6zN dx/A== X-Gm-Message-State: AOUpUlEa/5A7pdtIuFiA1xlnfGSQ6mV03maMEmj7Ev/KOnASPV2R1jHS QK1Qvt5i0T6ZV4bdf6TQmnT5sQ== X-Google-Smtp-Source: AAOMgpdw7PQ0f2pZoK/XSQ3hT1PiolrWakCLfApHLSvm1Ol3rtA+paTt7fqZlWIRmLsQKuuMwW5ILg== X-Received: by 2002:adf:9c91:: with SMTP id d17-v6mr5144212wre.11.1531496362148; Fri, 13 Jul 2018 08:39:22 -0700 (PDT) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id 63-v6sm4840902wmo.22.2018.07.13.08.39.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Jul 2018 08:39:21 -0700 (PDT) From: Srinivas Kandagatla To: broonie@kernel.org, lgirdwood@gmail.com, alsa-devel@alsa-project.org Date: Fri, 13 Jul 2018 16:36:28 +0100 Message-Id: <20180713153632.32511-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180713153632.32511-1-srinivas.kandagatla@linaro.org> References: <20180713153632.32511-1-srinivas.kandagatla@linaro.org> Cc: bgoswami@codeaurora.org, linux-kernel@vger.kernel.org, tiwai@suse.com, vkoul@kernel.org, rohitkr@codeaurora.org, Srinivas Kandagatla Subject: [alsa-devel] [PATCH v2 1/5] ASoC: core: add support to card re-bind using component framework X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP This patch aims at achieving dynamic behaviour of audio card when the dependent components disappear and reappear. With this patch the card is removed if any of the dependent component is removed and card is added back if the dependent component comes back. All this is done using component framework and matching based on component name. Signed-off-by: Srinivas Kandagatla --- include/sound/soc.h | 7 ++++++ sound/soc/soc-core.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/sound/soc.h b/include/sound/soc.h index a4915148f739..a23ecdf3eff1 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1090,6 +1091,12 @@ struct snd_soc_card { struct work_struct deferred_resume_work; + /* component framework related */ + bool components_added; + /* set in machine driver to enable/disable auto re-binding */ + bool auto_bind; + struct component_match *match; + /* lists of probed devices belonging to this card */ struct list_head component_dev_list; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 6d33634b934b..65d11c13117f 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -279,11 +279,28 @@ static inline void snd_soc_debugfs_exit(void) #endif +static int snd_soc_card_comp_compare(struct device *dev, void *data) +{ + struct snd_soc_component *component; + + lockdep_assert_held(&client_mutex); + list_for_each_entry(component, &component_list, list) { + if (dev == component->dev) { + if (!strcmp(component->name, data)) + return 1; + break; + } + } + + return 0; +} + static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, struct snd_soc_component *component) { struct snd_soc_rtdcom_list *rtdcom; struct snd_soc_rtdcom_list *new_rtdcom; + char *cname; for_each_rtdcom(rtd, rtdcom) { /* already connected */ @@ -300,6 +317,13 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, list_add_tail(&new_rtdcom->list, &rtd->component_list); + if (rtd->card->auto_bind && !rtd->card->components_added) { + cname = devm_kasprintf(rtd->card->dev, GFP_KERNEL, + "%s", component->name); + component_match_add(rtd->card->dev, &rtd->card->match, + snd_soc_card_comp_compare, cname); + } + return 0; } @@ -835,6 +859,25 @@ static bool soc_is_dai_link_bound(struct snd_soc_card *card, return false; } +static int snd_soc_card_comp_bind(struct device *dev) +{ + struct snd_soc_card *card = dev_get_drvdata(dev); + + if (card->instantiated) + return 0; + + return snd_soc_register_card(card); +} + +static void snd_soc_card_comp_unbind(struct device *dev) +{ +} + +static const struct component_master_ops snd_soc_card_comp_ops = { + .bind = snd_soc_card_comp_bind, + .unbind = snd_soc_card_comp_unbind, +}; + static int soc_bind_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link) { @@ -2108,6 +2151,12 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) card->instantiated = 1; snd_soc_dapm_sync(&card->dapm); + if (card->auto_bind && !card->components_added) { + component_master_add_with_match(card->dev, + &snd_soc_card_comp_ops, + card->match); + card->components_added = true; + } mutex_unlock(&card->mutex); mutex_unlock(&client_mutex); @@ -2757,6 +2806,9 @@ int snd_soc_unregister_card(struct snd_soc_card *card) dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); } + if (!card->auto_bind && card->components_added) + component_master_del(card->dev, &snd_soc_card_comp_ops); + return 0; } EXPORT_SYMBOL_GPL(snd_soc_unregister_card); @@ -3169,8 +3221,17 @@ int snd_soc_add_component(struct device *dev, snd_soc_component_add(component); + ret = component_add(dev, NULL); + if (ret < 0) { + dev_err(dev, "ASoC: Failed to add Component: %d\n", ret); + goto err_comp; + } + return 0; +err_comp: + soc_remove_component(component); + snd_soc_unregister_dais(component); err_cleanup: snd_soc_component_cleanup(component); err_free: @@ -3218,6 +3279,7 @@ static int __snd_soc_unregister_component(struct device *dev) mutex_unlock(&client_mutex); if (found) { + component_del(dev, NULL); snd_soc_component_cleanup(component); }