2 * Intel SST loader on ACPI systems
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/acpi.h>
18 #include <linux/device.h>
19 #include <linux/firmware.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
24 #include <sound/soc-acpi.h>
25 #include <sound/soc-acpi-intel-match.h>
27 #define SST_LPT_DSP_DMA_ADDR_OFFSET 0x0F0000
28 #define SST_WPT_DSP_DMA_ADDR_OFFSET 0x0FE000
29 #define SST_LPT_DSP_DMA_SIZE (1024 - 1)
31 /* Descriptor for setting up SST platform data */
32 struct sst_acpi_desc {
34 struct snd_soc_acpi_mach *machines;
35 /* Platform resource indexes. Must set to -1 if not used */
36 int resindex_lpe_base;
37 int resindex_pcicfg_base;
39 int irqindex_host_ipc;
40 int resindex_dma_base;
41 /* Unique number identifying the SST core on platform */
43 /* DMA only valid when resindex_dma_base != -1*/
48 struct sst_acpi_priv {
49 struct platform_device *pdev_mach;
50 struct platform_device *pdev_pcm;
51 struct sst_pdata sst_pdata;
52 struct sst_acpi_desc *desc;
53 struct snd_soc_acpi_mach *mach;
56 static void sst_acpi_fw_cb(const struct firmware *fw, void *context)
58 struct platform_device *pdev = context;
59 struct device *dev = &pdev->dev;
60 struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
61 struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
62 struct sst_acpi_desc *desc = sst_acpi->desc;
63 struct snd_soc_acpi_mach *mach = sst_acpi->mach;
67 dev_err(dev, "Cannot load firmware %s\n", mach->fw_filename);
71 /* register PCM and DAI driver */
73 platform_device_register_data(dev, desc->drv_name, -1,
74 sst_pdata, sizeof(*sst_pdata));
75 if (IS_ERR(sst_acpi->pdev_pcm)) {
76 dev_err(dev, "Cannot register device %s. Error %d\n",
77 desc->drv_name, (int)PTR_ERR(sst_acpi->pdev_pcm));
83 static int sst_acpi_probe(struct platform_device *pdev)
85 const struct acpi_device_id *id;
86 struct device *dev = &pdev->dev;
87 struct sst_acpi_priv *sst_acpi;
88 struct sst_pdata *sst_pdata;
89 struct snd_soc_acpi_mach *mach;
90 struct sst_acpi_desc *desc;
91 struct resource *mmio;
94 sst_acpi = devm_kzalloc(dev, sizeof(*sst_acpi), GFP_KERNEL);
98 id = acpi_match_device(dev->driver->acpi_match_table, dev);
102 desc = (struct sst_acpi_desc *)id->driver_data;
103 mach = snd_soc_acpi_find_machine(desc->machines);
105 dev_err(dev, "No matching ASoC machine driver found\n");
109 sst_pdata = &sst_acpi->sst_pdata;
110 sst_pdata->id = desc->sst_id;
111 sst_pdata->dma_dev = dev;
112 sst_acpi->desc = desc;
113 sst_acpi->mach = mach;
115 sst_pdata->resindex_dma_base = desc->resindex_dma_base;
116 if (desc->resindex_dma_base >= 0) {
117 sst_pdata->dma_engine = desc->dma_engine;
118 sst_pdata->dma_base = desc->resindex_dma_base;
119 sst_pdata->dma_size = desc->dma_size;
122 if (desc->irqindex_host_ipc >= 0)
123 sst_pdata->irq = platform_get_irq(pdev, desc->irqindex_host_ipc);
125 if (desc->resindex_lpe_base >= 0) {
126 mmio = platform_get_resource(pdev, IORESOURCE_MEM,
127 desc->resindex_lpe_base);
129 sst_pdata->lpe_base = mmio->start;
130 sst_pdata->lpe_size = resource_size(mmio);
134 if (desc->resindex_pcicfg_base >= 0) {
135 mmio = platform_get_resource(pdev, IORESOURCE_MEM,
136 desc->resindex_pcicfg_base);
138 sst_pdata->pcicfg_base = mmio->start;
139 sst_pdata->pcicfg_size = resource_size(mmio);
143 if (desc->resindex_fw_base >= 0) {
144 mmio = platform_get_resource(pdev, IORESOURCE_MEM,
145 desc->resindex_fw_base);
147 sst_pdata->fw_base = mmio->start;
148 sst_pdata->fw_size = resource_size(mmio);
152 platform_set_drvdata(pdev, sst_acpi);
154 /* register machine driver */
155 sst_acpi->pdev_mach =
156 platform_device_register_data(dev, mach->drv_name, -1,
157 sst_pdata, sizeof(*sst_pdata));
158 if (IS_ERR(sst_acpi->pdev_mach))
159 return PTR_ERR(sst_acpi->pdev_mach);
161 /* continue SST probing after firmware is loaded */
162 ret = reject_firmware_nowait(THIS_MODULE, true, mach->fw_filename,
163 dev, GFP_KERNEL, pdev, sst_acpi_fw_cb);
165 platform_device_unregister(sst_acpi->pdev_mach);
170 static int sst_acpi_remove(struct platform_device *pdev)
172 struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
173 struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
175 platform_device_unregister(sst_acpi->pdev_mach);
176 if (!IS_ERR_OR_NULL(sst_acpi->pdev_pcm))
177 platform_device_unregister(sst_acpi->pdev_pcm);
178 release_firmware(sst_pdata->fw);
183 static struct sst_acpi_desc sst_acpi_haswell_desc = {
184 .drv_name = "haswell-pcm-audio",
185 .machines = snd_soc_acpi_intel_haswell_machines,
186 .resindex_lpe_base = 0,
187 .resindex_pcicfg_base = 1,
188 .resindex_fw_base = -1,
189 .irqindex_host_ipc = 0,
190 .sst_id = SST_DEV_ID_LYNX_POINT,
191 .dma_engine = SST_DMA_TYPE_DW,
192 .resindex_dma_base = SST_LPT_DSP_DMA_ADDR_OFFSET,
193 .dma_size = SST_LPT_DSP_DMA_SIZE,
196 static struct sst_acpi_desc sst_acpi_broadwell_desc = {
197 .drv_name = "haswell-pcm-audio",
198 .machines = snd_soc_acpi_intel_broadwell_machines,
199 .resindex_lpe_base = 0,
200 .resindex_pcicfg_base = 1,
201 .resindex_fw_base = -1,
202 .irqindex_host_ipc = 0,
203 .sst_id = SST_DEV_ID_WILDCAT_POINT,
204 .dma_engine = SST_DMA_TYPE_DW,
205 .resindex_dma_base = SST_WPT_DSP_DMA_ADDR_OFFSET,
206 .dma_size = SST_LPT_DSP_DMA_SIZE,
209 #if !IS_ENABLED(CONFIG_SND_SST_IPC_ACPI)
210 static struct sst_acpi_desc sst_acpi_baytrail_desc = {
211 .drv_name = "baytrail-pcm-audio",
212 .machines = snd_soc_acpi_intel_baytrail_legacy_machines,
213 .resindex_lpe_base = 0,
214 .resindex_pcicfg_base = 1,
215 .resindex_fw_base = 2,
216 .irqindex_host_ipc = 5,
217 .sst_id = SST_DEV_ID_BYT,
218 .resindex_dma_base = -1,
222 static const struct acpi_device_id sst_acpi_match[] = {
223 { "INT33C8", (unsigned long)&sst_acpi_haswell_desc },
224 { "INT3438", (unsigned long)&sst_acpi_broadwell_desc },
225 #if !IS_ENABLED(CONFIG_SND_SST_IPC_ACPI)
226 { "80860F28", (unsigned long)&sst_acpi_baytrail_desc },
230 MODULE_DEVICE_TABLE(acpi, sst_acpi_match);
232 static struct platform_driver sst_acpi_driver = {
233 .probe = sst_acpi_probe,
234 .remove = sst_acpi_remove,
237 .acpi_match_table = ACPI_PTR(sst_acpi_match),
240 module_platform_driver(sst_acpi_driver);
242 MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>");
243 MODULE_DESCRIPTION("Intel SST loader on ACPI systems");
244 MODULE_LICENSE("GPL v2");