* [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing
@ 2014-02-19 8:30 Jarkko Nikula
2014-02-19 12:25 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Nikula @ 2014-02-19 8:30 UTC (permalink / raw)
To: alsa-devel; +Cc: Liam Girdwood, Mark Brown, Jarkko Nikula, Liam Girdwood
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 <jarkko.nikula@linux.intel.com>
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
---
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 <linux/acpi.h>
#include <linux/device.h>
+#include <linux/firmware.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -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;
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing
2014-02-19 8:30 [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing Jarkko Nikula
@ 2014-02-19 12:25 ` Mark Brown
2014-02-19 13:50 ` Liam Girdwood
0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2014-02-19 12:25 UTC (permalink / raw)
To: Jarkko Nikula; +Cc: Liam Girdwood, alsa-devel, Liam Girdwood
[-- Attachment #1.1: Type: text/plain, Size: 605 bytes --]
On Wed, Feb 19, 2014 at 10:30:38AM +0200, Jarkko Nikula wrote:
> 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.
The more usual thing to do here is to only request the firmware when the
device is actually being used (in this case on open). This also allows
the firmware to be replaced easily at runtime which is helpful too. It
seems like this is still an improvement though so I've applied it.
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing
2014-02-19 12:25 ` Mark Brown
@ 2014-02-19 13:50 ` Liam Girdwood
2014-02-19 14:14 ` Mark Brown
0 siblings, 1 reply; 4+ messages in thread
From: Liam Girdwood @ 2014-02-19 13:50 UTC (permalink / raw)
To: Mark Brown; +Cc: Koul, Vinod, alsa-devel, Jarkko Nikula, Liam Girdwood
On Wed, 2014-02-19 at 21:25 +0900, Mark Brown wrote:
> On Wed, Feb 19, 2014 at 10:30:38AM +0200, Jarkko Nikula wrote:
> > 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.
>
> The more usual thing to do here is to only request the firmware when the
> device is actually being used (in this case on open). This also allows
> the firmware to be replaced easily at runtime which is helpful too. It
> seems like this is still an improvement though so I've applied it.
Fwiw, we need to load the FW at probe time since it will contain the FW
topology for the SST drivers. The next phase for the SST FW is to use
the ASoC firmware loader for DAPM, Kcontrols + DAI links (Vinod is
working on patch for DAI links iirc, I will be back to the fw loader
next week if all goes to plan). The good news is that the ASoC FW loader
can also unload FW so we should be able to re-load FW at runtime too :)
Liam
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing
2014-02-19 13:50 ` Liam Girdwood
@ 2014-02-19 14:14 ` Mark Brown
0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-02-19 14:14 UTC (permalink / raw)
To: Liam Girdwood; +Cc: Koul, Vinod, alsa-devel, Jarkko Nikula, Liam Girdwood
[-- Attachment #1.1: Type: text/plain, Size: 1047 bytes --]
On Wed, Feb 19, 2014 at 01:50:32PM +0000, Liam Girdwood wrote:
> On Wed, 2014-02-19 at 21:25 +0900, Mark Brown wrote:
> > The more usual thing to do here is to only request the firmware when the
> > device is actually being used (in this case on open). This also allows
> > the firmware to be replaced easily at runtime which is helpful too. It
> > seems like this is still an improvement though so I've applied it.
> Fwiw, we need to load the FW at probe time since it will contain the FW
> topology for the SST drivers. The next phase for the SST FW is to use
> the ASoC firmware loader for DAPM, Kcontrols + DAI links (Vinod is
> working on patch for DAI links iirc, I will be back to the fw loader
> next week if all goes to plan). The good news is that the ASoC FW loader
> can also unload FW so we should be able to re-load FW at runtime too :)
I had thought the firmware loader would be able to cope with the
firmware getting loaded and unloaded at runtime, several of the
potential users actively want to be able to switch firmwares?
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-19 14:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-19 8:30 [PATCHv2] ASoC: Intel: sst-acpi: Request firmware before SST platform driver probing Jarkko Nikula
2014-02-19 12:25 ` Mark Brown
2014-02-19 13:50 ` Liam Girdwood
2014-02-19 14:14 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox