From patchwork Wed Feb 19 08:30:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 3679141 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2E9B7BF13A for ; Wed, 19 Feb 2014 08:31:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D761201BA for ; Wed, 19 Feb 2014 08:31:37 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id EC86A2017B for ; Wed, 19 Feb 2014 08:31:35 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id ABF8F2651C7; Wed, 19 Feb 2014 09:31:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id A185C2652A8; Wed, 19 Feb 2014 09:31:26 +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 6FDE02652E7; Wed, 19 Feb 2014 09:31:25 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by alsa0.perex.cz (Postfix) with ESMTP id 8273F2652A8 for ; Wed, 19 Feb 2014 09:31:16 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 19 Feb 2014 00:31:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,504,1389772800"; d="scan'208";a="477536283" Received: from mylly.fi.intel.com (HELO mylly.fi.intel.com.) ([10.237.72.152]) by fmsmga001.fm.intel.com with ESMTP; 19 Feb 2014 00:30:47 -0800 From: Jarkko Nikula To: alsa-devel@alsa-project.org Date: Wed, 19 Feb 2014 10:30:38 +0200 Message-Id: <1392798638-20767-1-git-send-email-jarkko.nikula@linux.intel.com> X-Mailer: git-send-email 1.8.5.3 Cc: Liam Girdwood , Mark Brown , Jarkko Nikula , Liam Girdwood Subject: [alsa-devel] [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing 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 We originally thought to request SST audio DSP firmware during the SST platform driver initialization. However plain request_firmware doesn't work in driver probe paths if userspace is not ready to handle it. For instance when drivers are built-in. Implementing asynchronous firmware request in SST platform driver initialization complicates code needlessly since it anyway will fail if firmware is missing. This is more simple to handle by requesting firmware asynchronously in sst_acpi_probe() and register SST platform only after firmware is loaded. Signed-off-by: Jarkko Nikula Acked-by: Liam Girdwood --- V2: - Fix leak in sst_acpi_probe that sst_acpi->pdev_mach wasn't unregistered in case of request_firmware_nowait fails - Test is sst_acpi->pdev_pcm valid before unregistering it in sst_acpi_remove. It can contain not only NULL or valid pointer but an error code too --- sound/soc/intel/sst-acpi.c | 56 ++++++++++++++++++++++++++++++++-------------- sound/soc/intel/sst-dsp.h | 2 +- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/sound/soc/intel/sst-acpi.c b/sound/soc/intel/sst-acpi.c index aba73ca8a923..64154a77d904 100644 --- a/sound/soc/intel/sst-acpi.c +++ b/sound/soc/intel/sst-acpi.c @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -56,6 +57,32 @@ struct sst_acpi_priv { struct sst_acpi_desc *desc; }; +static void sst_acpi_fw_cb(const struct firmware *fw, void *context) +{ + struct platform_device *pdev = context; + struct device *dev = &pdev->dev; + struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev); + struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata; + struct sst_acpi_desc *desc = sst_acpi->desc; + + sst_pdata->fw = fw; + if (!fw) { + dev_err(dev, "Cannot load firmware %s\n", desc->fw_filename); + return; + } + + /* register PCM and DAI driver */ + sst_acpi->pdev_pcm = + platform_device_register_data(dev, desc->drv_name, -1, + sst_pdata, sizeof(*sst_pdata)); + if (IS_ERR(sst_acpi->pdev_pcm)) { + dev_err(dev, "Cannot register device %s. Error %d\n", + desc->drv_name, (int)PTR_ERR(sst_acpi->pdev_pcm)); + } + + return; +} + static int sst_acpi_probe(struct platform_device *pdev) { const struct acpi_device_id *id; @@ -79,7 +106,6 @@ static int sst_acpi_probe(struct platform_device *pdev) desc = mach->res_desc; sst_pdata = &sst_acpi->sst_pdata; sst_pdata->id = desc->sst_id; - sst_pdata->fw_filename = desc->fw_filename; sst_acpi->desc = desc; if (desc->resindex_dma_base >= 0) { @@ -118,37 +144,33 @@ static int sst_acpi_probe(struct platform_device *pdev) } } - /* register PCM and DAI driver */ - sst_acpi->pdev_pcm = - platform_device_register_data(dev, desc->drv_name, -1, - sst_pdata, sizeof(*sst_pdata)); - if (IS_ERR(sst_acpi->pdev_pcm)) - return PTR_ERR(sst_acpi->pdev_pcm); - - /* register machine driver */ platform_set_drvdata(pdev, sst_acpi); + /* register machine driver */ sst_acpi->pdev_mach = platform_device_register_data(dev, mach->drv_name, -1, sst_pdata, sizeof(*sst_pdata)); - if (IS_ERR(sst_acpi->pdev_mach)) { - ret = PTR_ERR(sst_acpi->pdev_mach); - goto sst_err; - } + if (IS_ERR(sst_acpi->pdev_mach)) + return PTR_ERR(sst_acpi->pdev_mach); - return ret; + /* continue SST probing after firmware is loaded */ + ret = request_firmware_nowait(THIS_MODULE, true, desc->fw_filename, + dev, GFP_KERNEL, pdev, sst_acpi_fw_cb); + if (ret) + platform_device_unregister(sst_acpi->pdev_mach); -sst_err: - platform_device_unregister(sst_acpi->pdev_pcm); return ret; } static int sst_acpi_remove(struct platform_device *pdev) { struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev); + struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata; platform_device_unregister(sst_acpi->pdev_mach); - platform_device_unregister(sst_acpi->pdev_pcm); + if (!IS_ERR_OR_NULL(sst_acpi->pdev_pcm)) + platform_device_unregister(sst_acpi->pdev_pcm); + release_firmware(sst_pdata->fw); return 0; } diff --git a/sound/soc/intel/sst-dsp.h b/sound/soc/intel/sst-dsp.h index d134359fecac..3730fd324455 100644 --- a/sound/soc/intel/sst-dsp.h +++ b/sound/soc/intel/sst-dsp.h @@ -152,7 +152,7 @@ struct sst_pdata { int irq; /* Firmware */ - const char *fw_filename; + const struct firmware *fw; /* DMA */ u32 dma_base;