diff --git a/include/sound/sof.h b/include/sound/sof.h index e522e13e7a18d7..835d0ae4770cf0 100644 --- a/include/sound/sof.h +++ b/include/sound/sof.h @@ -23,6 +23,13 @@ struct snd_sof_dsp_ops; +/* SOF probe type */ +enum sof_device_type { + SOF_DEVICE_PCI = 0, + SOF_DEVICE_APCI, + SOF_DEVICE_SPI +}; + /* * SOF Platform data. */ @@ -32,10 +39,9 @@ struct snd_sof_pdata { const char *drv_name; const char *name; - /* parent devices */ + /* parent device */ struct device *dev; - struct pci_dev *pci; - struct platform_device *pdev; + enum sof_device_type type; /* descriptor */ const struct sof_dev_desc *desc; diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index ee76082cd891a9..5aad175d6e2556 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -239,14 +239,9 @@ static int sof_probe(struct platform_device *pdev) /* initialize sof device */ sdev->dev = &pdev->dev; - if (plat_data->pci) { - sdev->pci = plat_data->pci; - sdev->parent = &plat_data->pci->dev; - } else if (plat_data->pdev) { - sdev->parent = &plat_data->pdev->dev; - } else { - sdev->parent = plat_data->dev; - } + sdev->parent = plat_data->dev; + if (plat_data->type == SOF_DEVICE_PCI) + sdev->pci = container_of(plat_data->dev, struct pci_dev, dev); sdev->ops = plat_data->machine->pdata; sdev->pdata = plat_data; diff --git a/sound/soc/sof/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index fec3b012ae7191..dd268c1c1225d6 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -121,7 +121,7 @@ static struct platform_device * mfld_new_mach_data(struct snd_sof_pdata *sof_pdata) { struct snd_soc_acpi_mach pmach; - struct device *dev = &sof_pdata->pdev->dev; + struct device *dev = sof_pdata->dev; const struct snd_soc_acpi_mach *mach = sof_pdata->machine; struct platform_device *pdev = NULL; @@ -134,17 +134,12 @@ static struct platform_device * return pdev; } -struct sof_acpi_priv { - struct snd_sof_pdata *sof_pdata; - struct platform_device *pdev_pcm; -}; - static void sof_acpi_fw_cb(const struct firmware *fw, void *context) { - struct sof_acpi_priv *priv = context; + struct sof_platform_priv *priv = context; struct snd_sof_pdata *sof_pdata = priv->sof_pdata; const struct snd_soc_acpi_mach *mach = sof_pdata->machine; - struct device *dev = &sof_pdata->pdev->dev; + struct device *dev = sof_pdata->dev; sof_pdata->fw = fw; if (!fw) { @@ -209,7 +204,7 @@ static int sof_acpi_probe(struct platform_device *pdev) const struct sof_dev_desc *desc; struct snd_soc_acpi_mach *mach; struct snd_sof_pdata *sof_pdata; - struct sof_acpi_priv *priv; + struct sof_platform_priv *priv; struct snd_sof_dsp_ops *ops; struct platform_device *(*new_mach_data)(struct snd_sof_pdata *pdata); int ret = 0; @@ -278,7 +273,8 @@ static int sof_acpi_probe(struct platform_device *pdev) */ sof_pdata->desc = desc; priv->sof_pdata = sof_pdata; - sof_pdata->pdev = pdev; + sof_pdata->dev = &pdev->dev; + sof_pdata->type = SOF_DEVICE_APCI; dev_set_drvdata(&pdev->dev, priv); /* do we need to generate any machine plat data ? */ @@ -315,7 +311,7 @@ static void sof_acpi_shutdown(struct platform_device *pdev) static int sof_acpi_remove(struct platform_device *pdev) { - struct sof_acpi_priv *priv = dev_get_drvdata(&pdev->dev); + struct sof_platform_priv *priv = dev_get_drvdata(&pdev->dev); struct snd_sof_pdata *sof_pdata = priv->sof_pdata; platform_device_unregister(sof_pdata->pdev_mach); diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index eaa04ad567933a..152a3d36b69ad3 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -114,14 +114,9 @@ static struct sof_dev_desc kbl_desc = { }; #endif -struct sof_pci_priv { - struct snd_sof_pdata *sof_pdata; - struct platform_device *pdev_pcm; -}; - static void sof_pci_fw_cb(const struct firmware *fw, void *context) { - struct sof_pci_priv *priv = context; + struct sof_platform_priv *priv = context; struct snd_sof_pdata *sof_pdata = priv->sof_pdata; const struct snd_soc_acpi_mach *mach = sof_pdata->machine; struct device *dev = sof_pdata->dev; @@ -192,7 +187,7 @@ static int sof_pci_probe(struct pci_dev *pci, (const struct sof_dev_desc *)pci_id->driver_data; struct snd_soc_acpi_mach *mach; struct snd_sof_pdata *sof_pdata; - struct sof_pci_priv *priv; + struct sof_platform_priv *priv; struct snd_sof_dsp_ops *ops; int ret = 0; @@ -256,8 +251,8 @@ static int sof_pci_probe(struct pci_dev *pci, sof_pdata->machine = mach; sof_pdata->desc = (struct sof_dev_desc *)pci_id->driver_data; priv->sof_pdata = sof_pdata; - sof_pdata->pci = pci; sof_pdata->dev = &pci->dev; + sof_pdata->type = SOF_DEVICE_PCI; /* register machine driver */ sof_pdata->pdev_mach = @@ -299,7 +294,7 @@ static void sof_pci_shutdown(struct pci_dev *pci) static void sof_pci_remove(struct pci_dev *pci) { - struct sof_pci_priv *priv = pci_get_drvdata(pci); + struct sof_platform_priv *priv = pci_get_drvdata(pci); struct snd_sof_pdata *sof_pdata = priv->sof_pdata; /* unregister machine driver */ diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index c4162d3973e00a..5def46b92f1957 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -353,6 +353,15 @@ struct snd_sof_dev { void *private; /* core does not touch this */ }; +/* + * SOF platform private struct used as drvdata of + * platform dev (e.g. pci/acpi/spi...) drvdata. + */ +struct sof_platform_priv { + struct snd_sof_pdata *sof_pdata; + struct platform_device *pdev_pcm; +}; + /* * Device Level. */ diff --git a/sound/soc/sof/sof-spi-dev.c b/sound/soc/sof/sof-spi-dev.c index b3811db6d74650..57928d1442c96b 100644 --- a/sound/soc/sof/sof-spi-dev.c +++ b/sound/soc/sof/sof-spi-dev.c @@ -19,14 +19,9 @@ #include #include "sof-priv.h" -struct sof_spi_priv { - struct snd_sof_pdata *sof_pdata; - struct platform_device *pdev_pcm; -}; - static void sof_spi_fw_cb(const struct firmware *fw, void *context) { - struct sof_spi_priv *priv = context; + struct sof_platform_priv *priv = context; struct snd_sof_pdata *sof_pdata = priv->sof_pdata; const struct snd_sof_machine *mach = sof_pdata->machine; struct device *dev = sof_pdata->dev; @@ -61,7 +56,7 @@ static int sof_spi_probe(struct spi_device *spi) const struct snd_sof_machine *mach; struct snd_sof_machine *m; struct snd_sof_pdata *sof_pdata; - struct sof_spi_priv *priv; + struct sof_platform_priv *priv; int ret = 0; dev_dbg(&spi->dev, "SPI DSP detected"); @@ -94,8 +89,8 @@ static int sof_spi_probe(struct spi_device *spi) sof_pdata->machine = mach; sof_pdata->desc = (struct sof_dev_desc *)pci_id->driver_data; priv->sof_pdata = sof_pdata; - sof_pdata->spi = spi; sof_pdata->dev = dev; + sof_pdata->type = SOF_DEVICE_SPI; /* register machine driver */ sof_pdata->pdev_mach = @@ -117,7 +112,7 @@ static int sof_spi_probe(struct spi_device *spi) static int sof_spi_remove(struct spi_device *spi) { - struct sof_spi_priv *priv = spi_get_drvdata(spi); + struct sof_platform_priv *priv = spi_get_drvdata(spi); struct snd_sof_pdata *sof_pdata = priv->sof_pdata; platform_device_unregister(sof_pdata->pdev_mach);