Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Intel SST loader on ACPI systems |
| 3 | * |
| 4 | * Copyright (C) 2013, Intel Corporation. All rights reserved. |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 15 | */ |
| 16 | |
| 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> |
| 22 | |
| 23 | #include "sst-dsp.h" |
| 24 | |
| 25 | #define SST_LPT_DSP_DMA_ADDR_OFFSET 0x0F0000 |
| 26 | #define SST_WPT_DSP_DMA_ADDR_OFFSET 0x0FE000 |
| 27 | #define SST_LPT_DSP_DMA_SIZE (1024 - 1) |
| 28 | |
| 29 | /* Descriptor for SST ASoC machine driver */ |
| 30 | struct sst_acpi_mach { |
| 31 | /* ACPI ID for the matching machine driver. Audio codec for instance */ |
| 32 | const u8 id[ACPI_ID_LEN]; |
| 33 | /* machine driver name */ |
| 34 | const char *drv_name; |
| 35 | /* firmware file name */ |
| 36 | const char *fw_filename; |
| 37 | }; |
| 38 | |
| 39 | /* Descriptor for setting up SST platform data */ |
| 40 | struct sst_acpi_desc { |
| 41 | const char *drv_name; |
| 42 | struct sst_acpi_mach *machines; |
| 43 | /* Platform resource indexes. Must set to -1 if not used */ |
| 44 | int resindex_lpe_base; |
| 45 | int resindex_pcicfg_base; |
| 46 | int resindex_fw_base; |
| 47 | int irqindex_host_ipc; |
| 48 | int resindex_dma_base; |
| 49 | /* Unique number identifying the SST core on platform */ |
| 50 | int sst_id; |
| 51 | /* DMA only valid when resindex_dma_base != -1*/ |
| 52 | int dma_engine; |
| 53 | int dma_size; |
| 54 | }; |
| 55 | |
| 56 | struct sst_acpi_priv { |
| 57 | struct platform_device *pdev_mach; |
| 58 | struct platform_device *pdev_pcm; |
| 59 | struct sst_pdata sst_pdata; |
| 60 | struct sst_acpi_desc *desc; |
| 61 | struct sst_acpi_mach *mach; |
| 62 | }; |
| 63 | |
| 64 | static void sst_acpi_fw_cb(const struct firmware *fw, void *context) |
| 65 | { |
| 66 | struct platform_device *pdev = context; |
| 67 | struct device *dev = &pdev->dev; |
| 68 | struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev); |
| 69 | struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata; |
| 70 | struct sst_acpi_desc *desc = sst_acpi->desc; |
| 71 | struct sst_acpi_mach *mach = sst_acpi->mach; |
| 72 | |
| 73 | sst_pdata->fw = fw; |
| 74 | if (!fw) { |
| 75 | dev_err(dev, "Cannot load firmware %s\n", mach->fw_filename); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | /* register PCM and DAI driver */ |
| 80 | sst_acpi->pdev_pcm = |
| 81 | platform_device_register_data(dev, desc->drv_name, -1, |
| 82 | sst_pdata, sizeof(*sst_pdata)); |
| 83 | if (IS_ERR(sst_acpi->pdev_pcm)) { |
| 84 | dev_err(dev, "Cannot register device %s. Error %d\n", |
| 85 | desc->drv_name, (int)PTR_ERR(sst_acpi->pdev_pcm)); |
| 86 | } |
| 87 | |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level, |
| 92 | void *context, void **ret) |
| 93 | { |
| 94 | *(bool *)context = true; |
| 95 | return AE_OK; |
| 96 | } |
| 97 | |
| 98 | static struct sst_acpi_mach *sst_acpi_find_machine( |
| 99 | struct sst_acpi_mach *machines) |
| 100 | { |
| 101 | struct sst_acpi_mach *mach; |
| 102 | bool found = false; |
| 103 | |
| 104 | for (mach = machines; mach->id[0]; mach++) |
| 105 | if (ACPI_SUCCESS(acpi_get_devices(mach->id, |
| 106 | sst_acpi_mach_match, |
| 107 | &found, NULL)) && found) |
| 108 | return mach; |
| 109 | |
| 110 | return NULL; |
| 111 | } |
| 112 | |
| 113 | static int sst_acpi_probe(struct platform_device *pdev) |
| 114 | { |
| 115 | const struct acpi_device_id *id; |
| 116 | struct device *dev = &pdev->dev; |
| 117 | struct sst_acpi_priv *sst_acpi; |
| 118 | struct sst_pdata *sst_pdata; |
| 119 | struct sst_acpi_mach *mach; |
| 120 | struct sst_acpi_desc *desc; |
| 121 | struct resource *mmio; |
| 122 | int ret = 0; |
| 123 | |
| 124 | sst_acpi = devm_kzalloc(dev, sizeof(*sst_acpi), GFP_KERNEL); |
| 125 | if (sst_acpi == NULL) |
| 126 | return -ENOMEM; |
| 127 | |
| 128 | id = acpi_match_device(dev->driver->acpi_match_table, dev); |
| 129 | if (!id) |
| 130 | return -ENODEV; |
| 131 | |
| 132 | desc = (struct sst_acpi_desc *)id->driver_data; |
| 133 | mach = sst_acpi_find_machine(desc->machines); |
| 134 | if (mach == NULL) { |
| 135 | dev_err(dev, "No matching ASoC machine driver found\n"); |
| 136 | return -ENODEV; |
| 137 | } |
| 138 | |
| 139 | sst_pdata = &sst_acpi->sst_pdata; |
| 140 | sst_pdata->id = desc->sst_id; |
Liam Girdwood | 10df350 | 2014-05-02 16:56:31 +0100 | [diff] [blame] | 141 | sst_pdata->dma_dev = dev; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 142 | sst_acpi->desc = desc; |
| 143 | sst_acpi->mach = mach; |
| 144 | |
| 145 | if (desc->resindex_dma_base >= 0) { |
| 146 | sst_pdata->dma_engine = desc->dma_engine; |
| 147 | sst_pdata->dma_base = desc->resindex_dma_base; |
| 148 | sst_pdata->dma_size = desc->dma_size; |
| 149 | } |
| 150 | |
| 151 | if (desc->irqindex_host_ipc >= 0) |
| 152 | sst_pdata->irq = platform_get_irq(pdev, desc->irqindex_host_ipc); |
| 153 | |
| 154 | if (desc->resindex_lpe_base >= 0) { |
| 155 | mmio = platform_get_resource(pdev, IORESOURCE_MEM, |
| 156 | desc->resindex_lpe_base); |
| 157 | if (mmio) { |
| 158 | sst_pdata->lpe_base = mmio->start; |
| 159 | sst_pdata->lpe_size = resource_size(mmio); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (desc->resindex_pcicfg_base >= 0) { |
| 164 | mmio = platform_get_resource(pdev, IORESOURCE_MEM, |
| 165 | desc->resindex_pcicfg_base); |
| 166 | if (mmio) { |
| 167 | sst_pdata->pcicfg_base = mmio->start; |
| 168 | sst_pdata->pcicfg_size = resource_size(mmio); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (desc->resindex_fw_base >= 0) { |
| 173 | mmio = platform_get_resource(pdev, IORESOURCE_MEM, |
| 174 | desc->resindex_fw_base); |
| 175 | if (mmio) { |
| 176 | sst_pdata->fw_base = mmio->start; |
| 177 | sst_pdata->fw_size = resource_size(mmio); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | platform_set_drvdata(pdev, sst_acpi); |
| 182 | |
| 183 | /* register machine driver */ |
| 184 | sst_acpi->pdev_mach = |
| 185 | platform_device_register_data(dev, mach->drv_name, -1, |
| 186 | sst_pdata, sizeof(*sst_pdata)); |
| 187 | if (IS_ERR(sst_acpi->pdev_mach)) |
| 188 | return PTR_ERR(sst_acpi->pdev_mach); |
| 189 | |
| 190 | /* continue SST probing after firmware is loaded */ |
| 191 | ret = request_firmware_nowait(THIS_MODULE, true, mach->fw_filename, |
| 192 | dev, GFP_KERNEL, pdev, sst_acpi_fw_cb); |
| 193 | if (ret) |
| 194 | platform_device_unregister(sst_acpi->pdev_mach); |
| 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | static int sst_acpi_remove(struct platform_device *pdev) |
| 200 | { |
| 201 | struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev); |
| 202 | struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata; |
| 203 | |
| 204 | platform_device_unregister(sst_acpi->pdev_mach); |
| 205 | if (!IS_ERR_OR_NULL(sst_acpi->pdev_pcm)) |
| 206 | platform_device_unregister(sst_acpi->pdev_pcm); |
| 207 | release_firmware(sst_pdata->fw); |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static struct sst_acpi_mach haswell_machines[] = { |
| 213 | { "INT33CA", "haswell-audio", "intel/IntcSST1.bin" }, |
| 214 | {} |
| 215 | }; |
| 216 | |
| 217 | static struct sst_acpi_desc sst_acpi_haswell_desc = { |
| 218 | .drv_name = "haswell-pcm-audio", |
| 219 | .machines = haswell_machines, |
| 220 | .resindex_lpe_base = 0, |
| 221 | .resindex_pcicfg_base = 1, |
| 222 | .resindex_fw_base = -1, |
| 223 | .irqindex_host_ipc = 0, |
| 224 | .sst_id = SST_DEV_ID_LYNX_POINT, |
| 225 | .dma_engine = SST_DMA_TYPE_DW, |
| 226 | .resindex_dma_base = SST_LPT_DSP_DMA_ADDR_OFFSET, |
| 227 | .dma_size = SST_LPT_DSP_DMA_SIZE, |
| 228 | }; |
| 229 | |
| 230 | static struct sst_acpi_mach broadwell_machines[] = { |
| 231 | { "INT343A", "broadwell-audio", "intel/IntcSST2.bin" }, |
| 232 | {} |
| 233 | }; |
| 234 | |
| 235 | static struct sst_acpi_desc sst_acpi_broadwell_desc = { |
| 236 | .drv_name = "haswell-pcm-audio", |
| 237 | .machines = broadwell_machines, |
| 238 | .resindex_lpe_base = 0, |
| 239 | .resindex_pcicfg_base = 1, |
| 240 | .resindex_fw_base = -1, |
| 241 | .irqindex_host_ipc = 0, |
| 242 | .sst_id = SST_DEV_ID_WILDCAT_POINT, |
| 243 | .dma_engine = SST_DMA_TYPE_DW, |
| 244 | .resindex_dma_base = SST_WPT_DSP_DMA_ADDR_OFFSET, |
| 245 | .dma_size = SST_LPT_DSP_DMA_SIZE, |
| 246 | }; |
| 247 | |
| 248 | static struct sst_acpi_mach baytrail_machines[] = { |
Jarkko Nikula | 9b11eb4 | 2014-08-06 09:48:14 +0300 | [diff] [blame] | 249 | { "10EC5640", "byt-rt5640", "intel/fw_sst_0f28.bin-48kHz_i2s_master" }, |
| 250 | { "193C9890", "byt-max98090", "intel/fw_sst_0f28.bin-48kHz_i2s_master" }, |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 251 | {} |
| 252 | }; |
| 253 | |
| 254 | static struct sst_acpi_desc sst_acpi_baytrail_desc = { |
| 255 | .drv_name = "baytrail-pcm-audio", |
| 256 | .machines = baytrail_machines, |
| 257 | .resindex_lpe_base = 0, |
| 258 | .resindex_pcicfg_base = 1, |
| 259 | .resindex_fw_base = 2, |
| 260 | .irqindex_host_ipc = 5, |
| 261 | .sst_id = SST_DEV_ID_BYT, |
| 262 | .resindex_dma_base = -1, |
| 263 | }; |
| 264 | |
| 265 | static struct acpi_device_id sst_acpi_match[] = { |
| 266 | { "INT33C8", (unsigned long)&sst_acpi_haswell_desc }, |
| 267 | { "INT3438", (unsigned long)&sst_acpi_broadwell_desc }, |
| 268 | { "80860F28", (unsigned long)&sst_acpi_baytrail_desc }, |
| 269 | { } |
| 270 | }; |
| 271 | MODULE_DEVICE_TABLE(acpi, sst_acpi_match); |
| 272 | |
| 273 | static struct platform_driver sst_acpi_driver = { |
| 274 | .probe = sst_acpi_probe, |
| 275 | .remove = sst_acpi_remove, |
| 276 | .driver = { |
| 277 | .name = "sst-acpi", |
| 278 | .owner = THIS_MODULE, |
| 279 | .acpi_match_table = ACPI_PTR(sst_acpi_match), |
| 280 | }, |
| 281 | }; |
| 282 | module_platform_driver(sst_acpi_driver); |
| 283 | |
| 284 | MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>"); |
| 285 | MODULE_DESCRIPTION("Intel SST loader on ACPI systems"); |
| 286 | MODULE_LICENSE("GPL v2"); |