From patchwork Tue Dec 12 16:37:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ughreja, Rakesh A" X-Patchwork-Id: 10107865 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 9B0A5602B3 for ; Tue, 12 Dec 2017 16:38:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B1082947B for ; Tue, 12 Dec 2017 16:38:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E495294AF; Tue, 12 Dec 2017 16:38:10 +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, RCVD_IN_DNSWL_NONE autolearn=ham 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 81DF22947B for ; Tue, 12 Dec 2017 16:38:09 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 73312267070; Tue, 12 Dec 2017 17:38:07 +0100 (CET) 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 19FE22671A3; Tue, 12 Dec 2017 17:38:06 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by alsa0.perex.cz (Postfix) with ESMTP id 2174C266DF0 for ; Tue, 12 Dec 2017 17:38:02 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Dec 2017 08:38:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,395,1508828400"; d="scan'208";a="11259764" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 12 Dec 2017 08:38:01 -0800 Received: from fmsmsx119.amr.corp.intel.com (10.18.124.207) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 12 Dec 2017 08:38:00 -0800 Received: from bgsmsx102.gar.corp.intel.com (10.223.4.172) by FMSMSX119.amr.corp.intel.com (10.18.124.207) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 12 Dec 2017 08:38:00 -0800 Received: from bgsmsx104.gar.corp.intel.com ([169.254.5.23]) by BGSMSX102.gar.corp.intel.com ([10.223.4.172]) with mapi id 14.03.0319.002; Tue, 12 Dec 2017 22:07:57 +0530 From: "Ughreja, Rakesh A" To: Takashi Iwai Thread-Topic: [RFC v2 00/11] Enable HDA Codec support on Intel Platforms (Series2) Thread-Index: AQHTcm2Wzoh36+YDgUa+cfqPxl2DgaM9o8yAgACWkaD//6vxAIAAiWsg//+wtQCAAREnIA== Date: Tue, 12 Dec 2017 16:37:56 +0000 Message-ID: <85DFEED57DC57344B2483EF7BF8CB60579AD52D3@BGSMSX104.gar.corp.intel.com> References: <1512989583-10877-1-git-send-email-rakesh.a.ughreja@intel.com> <85DFEED57DC57344B2483EF7BF8CB60579AD2978@BGSMSX104.gar.corp.intel.com> <85DFEED57DC57344B2483EF7BF8CB60579AD2F48@BGSMSX104.gar.corp.intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYTNhZGFmZTEtNGEyYi00NGE3LTk1ZDUtNDhhNjIzYzdhOTkwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJaNEpZM0taWVpyWlc5cUQ0Sit4MTR6VFpXek9RWGhZQ1g4UGpYSENoU2FUNktaanhZU1MxQlMzQXMrTjg2d2FSIn0= dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.223.10.10] MIME-Version: 1.0 Cc: "alsa-devel@alsa-project.org" , "Koul, Vinod" , "pierre-louis.bossart@linux.intel.com" , "liam.r.girdwood@linux.intel.com" , Patches Audio , "broonie@kernel.org" Subject: Re: [alsa-devel] [RFC v2 00/11] Enable HDA Codec support on Intel Platforms (Series2) 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP >-----Original Message----- >From: Takashi Iwai [mailto:tiwai@suse.de] >Sent: Tuesday, December 12, 2017 12:19 AM >To: Ughreja, Rakesh A >Cc: alsa-devel@alsa-project.org; broonie@kernel.org; >liam.r.girdwood@linux.intel.com; pierre-louis.bossart@linux.intel.com; Koul, >Vinod ; Patches Audio >Subject: Re: [RFC v2 00/11] Enable HDA Codec support on Intel Platforms >(Series2) > >The registration should be triggered from the top-level, i.e. the >controller driver, once after all codecs get probed. Otherwise, it >becomes racy. The user-space will start poking the device before all >the stuff becomes ready. Thank you very much, I understand now. > >That said, at the point when the codec is probed, the card shouldn't >be registered yet. The card gets registered after the all components >are bound and become ready -- which is done a single >snd_card_register() call. At this point, the access points to >user-space are provided. So based on your suggestion when I relooked at the code, I could remove the new function that I added. I could completely reuse the existing function with little change. Does it look okay ? Following is the patch, which I tested and it works for me. I will include this in next series but for now it's only for quick reference. I am calling this API from the hdac_hda codec driver with argument HDA_DEV_ASOC to make sure that it does not register with the bus again. I am not able to call this API from ASoC Platform driver because I don't have snd_card pointer at the time of machine driver probe. Following is the patch. --------------------------- Modify snd_hda_codec_new API so that it can work for legacy as well as ASoC codec drivers. The API takes an additional argument dev_type as HDA_DEV_LEGACY or HDA_DEV_ASOC to distinguish the caller. Signed-off-by: Rakesh Ughreja --- sound/pci/hda/hda_codec.c | 30 +++++++++++++++++++----------- sound/pci/hda/hda_codec.h | 3 ++- sound/pci/hda/hda_controller.c | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 085fd9e..252779c 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -865,7 +865,8 @@ static void snd_hda_codec_dev_release(struct device *dev) * Returns 0 if successful, or a negative error code. */ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, - unsigned int codec_addr, struct hda_codec **codecp) + unsigned int codec_addr, struct hda_codec **codecp, + unsigned int dev_type) { struct hda_codec *codec; char component[31]; @@ -882,20 +883,27 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, if (snd_BUG_ON(codec_addr > HDA_MAX_CODEC_ADDRESS)) return -EINVAL; - codec = kzalloc(sizeof(*codec), GFP_KERNEL); - if (!codec) - return -ENOMEM; + if (dev_type == HDA_DEV_LEGACY) { - sprintf(component, "hdaudioC%dD%d", card->number, codec_addr); - err = snd_hdac_device_init(&codec->core, &bus->core, component, - codec_addr); - if (err < 0) { - kfree(codec); - return err; + codec = kzalloc(sizeof(*codec), GFP_KERNEL); + if (!codec) + return -ENOMEM; + + sprintf(component, "hdaudioC%dD%d", card->number, codec_addr); + err = snd_hdac_device_init(&codec->core, &bus->core, component, + codec_addr); + if (err < 0) { + kfree(codec); + return err; + } + + codec->core.type = HDA_DEV_LEGACY; + + } else { + codec = *codecp; } codec->core.dev.release = snd_hda_codec_dev_release; - codec->core.type = HDA_DEV_LEGACY; codec->core.exec_verb = codec_exec_verb; codec->bus = bus; diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index d3099db..92815b7 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -306,7 +306,8 @@ struct hda_codec { * constructors */ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card, - unsigned int codec_addr, struct hda_codec **codecp); + unsigned int codec_addr, struct hda_codec **codecp, + unsigned int dev_type); int snd_hda_codec_configure(struct hda_codec *codec); int snd_hda_codec_update_widgets(struct hda_codec *codec); diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c index d1eb148..ec887d7 100644 --- a/sound/pci/hda/hda_controller.c +++ b/sound/pci/hda/hda_controller.c @@ -1318,7 +1318,7 @@ int azx_probe_codecs(struct azx *chip, unsigned int max_slots) for (c = 0; c < max_slots; c++) { if ((bus->codec_mask & (1 << c)) & chip->codec_probe_mask) { struct hda_codec *codec; - err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec); + err = snd_hda_codec_new(&chip->bus, chip->card, c, &codec, HDA_DEV_LEGACY); if (err < 0) continue; codec->jackpoll_interval = get_jackpoll_interval(chip);