sst-acpi.c 7.7 KB

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