sst-acpi.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #include <linux/acpi.h>
  17. #include <linux/device.h>
  18. #include <linux/firmware.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include "sst-dsp.h"
  22. #include <sound/soc-acpi.h>
  23. #include <sound/soc-acpi-intel-match.h>
  24. #define SST_LPT_DSP_DMA_ADDR_OFFSET 0x0F0000
  25. #define SST_WPT_DSP_DMA_ADDR_OFFSET 0x0FE000
  26. #define SST_LPT_DSP_DMA_SIZE (1024 - 1)
  27. /* Descriptor for setting up SST platform data */
  28. struct sst_acpi_desc {
  29. const char *drv_name;
  30. struct snd_soc_acpi_mach *machines;
  31. /* Platform resource indexes. Must set to -1 if not used */
  32. int resindex_lpe_base;
  33. int resindex_pcicfg_base;
  34. int resindex_fw_base;
  35. int irqindex_host_ipc;
  36. int resindex_dma_base;
  37. /* Unique number identifying the SST core on platform */
  38. int sst_id;
  39. /* DMA only valid when resindex_dma_base != -1*/
  40. int dma_engine;
  41. int dma_size;
  42. };
  43. struct sst_acpi_priv {
  44. struct platform_device *pdev_mach;
  45. struct platform_device *pdev_pcm;
  46. struct sst_pdata sst_pdata;
  47. struct sst_acpi_desc *desc;
  48. struct snd_soc_acpi_mach *mach;
  49. };
  50. static void sst_acpi_fw_cb(const struct firmware *fw, void *context)
  51. {
  52. struct platform_device *pdev = context;
  53. struct device *dev = &pdev->dev;
  54. struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
  55. struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
  56. struct sst_acpi_desc *desc = sst_acpi->desc;
  57. struct snd_soc_acpi_mach *mach = sst_acpi->mach;
  58. sst_pdata->fw = fw;
  59. if (!fw) {
  60. dev_err(dev, "Cannot load firmware %s\n", mach->fw_filename);
  61. return;
  62. }
  63. /* register PCM and DAI driver */
  64. sst_acpi->pdev_pcm =
  65. platform_device_register_data(dev, desc->drv_name, -1,
  66. sst_pdata, sizeof(*sst_pdata));
  67. if (IS_ERR(sst_acpi->pdev_pcm)) {
  68. dev_err(dev, "Cannot register device %s. Error %d\n",
  69. desc->drv_name, (int)PTR_ERR(sst_acpi->pdev_pcm));
  70. }
  71. return;
  72. }
  73. static int sst_acpi_probe(struct platform_device *pdev)
  74. {
  75. const struct acpi_device_id *id;
  76. struct device *dev = &pdev->dev;
  77. struct sst_acpi_priv *sst_acpi;
  78. struct sst_pdata *sst_pdata;
  79. struct snd_soc_acpi_mach *mach;
  80. struct sst_acpi_desc *desc;
  81. struct resource *mmio;
  82. int ret = 0;
  83. sst_acpi = devm_kzalloc(dev, sizeof(*sst_acpi), GFP_KERNEL);
  84. if (sst_acpi == NULL)
  85. return -ENOMEM;
  86. id = acpi_match_device(dev->driver->acpi_match_table, dev);
  87. if (!id)
  88. return -ENODEV;
  89. desc = (struct sst_acpi_desc *)id->driver_data;
  90. mach = snd_soc_acpi_find_machine(desc->machines);
  91. if (mach == NULL) {
  92. dev_err(dev, "No matching ASoC machine driver found\n");
  93. return -ENODEV;
  94. }
  95. sst_pdata = &sst_acpi->sst_pdata;
  96. sst_pdata->id = desc->sst_id;
  97. sst_pdata->dma_dev = dev;
  98. sst_acpi->desc = desc;
  99. sst_acpi->mach = mach;
  100. sst_pdata->resindex_dma_base = desc->resindex_dma_base;
  101. if (desc->resindex_dma_base >= 0) {
  102. sst_pdata->dma_engine = desc->dma_engine;
  103. sst_pdata->dma_base = desc->resindex_dma_base;
  104. sst_pdata->dma_size = desc->dma_size;
  105. }
  106. if (desc->irqindex_host_ipc >= 0)
  107. sst_pdata->irq = platform_get_irq(pdev, desc->irqindex_host_ipc);
  108. if (desc->resindex_lpe_base >= 0) {
  109. mmio = platform_get_resource(pdev, IORESOURCE_MEM,
  110. desc->resindex_lpe_base);
  111. if (mmio) {
  112. sst_pdata->lpe_base = mmio->start;
  113. sst_pdata->lpe_size = resource_size(mmio);
  114. }
  115. }
  116. if (desc->resindex_pcicfg_base >= 0) {
  117. mmio = platform_get_resource(pdev, IORESOURCE_MEM,
  118. desc->resindex_pcicfg_base);
  119. if (mmio) {
  120. sst_pdata->pcicfg_base = mmio->start;
  121. sst_pdata->pcicfg_size = resource_size(mmio);
  122. }
  123. }
  124. if (desc->resindex_fw_base >= 0) {
  125. mmio = platform_get_resource(pdev, IORESOURCE_MEM,
  126. desc->resindex_fw_base);
  127. if (mmio) {
  128. sst_pdata->fw_base = mmio->start;
  129. sst_pdata->fw_size = resource_size(mmio);
  130. }
  131. }
  132. platform_set_drvdata(pdev, sst_acpi);
  133. /* register machine driver */
  134. sst_acpi->pdev_mach =
  135. platform_device_register_data(dev, mach->drv_name, -1,
  136. sst_pdata, sizeof(*sst_pdata));
  137. if (IS_ERR(sst_acpi->pdev_mach))
  138. return PTR_ERR(sst_acpi->pdev_mach);
  139. /* continue SST probing after firmware is loaded */
  140. ret = request_firmware_nowait(THIS_MODULE, true, mach->fw_filename,
  141. dev, GFP_KERNEL, pdev, sst_acpi_fw_cb);
  142. if (ret)
  143. platform_device_unregister(sst_acpi->pdev_mach);
  144. return ret;
  145. }
  146. static int sst_acpi_remove(struct platform_device *pdev)
  147. {
  148. struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
  149. struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
  150. platform_device_unregister(sst_acpi->pdev_mach);
  151. if (!IS_ERR_OR_NULL(sst_acpi->pdev_pcm))
  152. platform_device_unregister(sst_acpi->pdev_pcm);
  153. release_firmware(sst_pdata->fw);
  154. return 0;
  155. }
  156. static struct sst_acpi_desc sst_acpi_haswell_desc = {
  157. .drv_name = "haswell-pcm-audio",
  158. .machines = snd_soc_acpi_intel_haswell_machines,
  159. .resindex_lpe_base = 0,
  160. .resindex_pcicfg_base = 1,
  161. .resindex_fw_base = -1,
  162. .irqindex_host_ipc = 0,
  163. .sst_id = SST_DEV_ID_LYNX_POINT,
  164. .dma_engine = SST_DMA_TYPE_DW,
  165. .resindex_dma_base = SST_LPT_DSP_DMA_ADDR_OFFSET,
  166. .dma_size = SST_LPT_DSP_DMA_SIZE,
  167. };
  168. static struct sst_acpi_desc sst_acpi_broadwell_desc = {
  169. .drv_name = "haswell-pcm-audio",
  170. .machines = snd_soc_acpi_intel_broadwell_machines,
  171. .resindex_lpe_base = 0,
  172. .resindex_pcicfg_base = 1,
  173. .resindex_fw_base = -1,
  174. .irqindex_host_ipc = 0,
  175. .sst_id = SST_DEV_ID_WILDCAT_POINT,
  176. .dma_engine = SST_DMA_TYPE_DW,
  177. .resindex_dma_base = SST_WPT_DSP_DMA_ADDR_OFFSET,
  178. .dma_size = SST_LPT_DSP_DMA_SIZE,
  179. };
  180. #if !IS_ENABLED(CONFIG_SND_SST_IPC_ACPI)
  181. static struct sst_acpi_desc sst_acpi_baytrail_desc = {
  182. .drv_name = "baytrail-pcm-audio",
  183. .machines = snd_soc_acpi_intel_baytrail_legacy_machines,
  184. .resindex_lpe_base = 0,
  185. .resindex_pcicfg_base = 1,
  186. .resindex_fw_base = 2,
  187. .irqindex_host_ipc = 5,
  188. .sst_id = SST_DEV_ID_BYT,
  189. .resindex_dma_base = -1,
  190. };
  191. #endif
  192. static const struct acpi_device_id sst_acpi_match[] = {
  193. { "INT33C8", (unsigned long)&sst_acpi_haswell_desc },
  194. { "INT3438", (unsigned long)&sst_acpi_broadwell_desc },
  195. #if !IS_ENABLED(CONFIG_SND_SST_IPC_ACPI)
  196. { "80860F28", (unsigned long)&sst_acpi_baytrail_desc },
  197. #endif
  198. { }
  199. };
  200. MODULE_DEVICE_TABLE(acpi, sst_acpi_match);
  201. static struct platform_driver sst_acpi_driver = {
  202. .probe = sst_acpi_probe,
  203. .remove = sst_acpi_remove,
  204. .driver = {
  205. .name = "sst-acpi",
  206. .acpi_match_table = ACPI_PTR(sst_acpi_match),
  207. },
  208. };
  209. module_platform_driver(sst_acpi_driver);
  210. MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>");
  211. MODULE_DESCRIPTION("Intel SST loader on ACPI systems");
  212. MODULE_LICENSE("GPL v2");