sst_acpi.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * sst_acpi.c - SST (LPE) driver init file for ACPI enumeration.
  3. *
  4. * Copyright (c) 2013, Intel Corporation.
  5. *
  6. * Authors: Ramesh Babu K V <Ramesh.Babu@intel.com>
  7. * Authors: Omair Mohammed Abdullah <omair.m.abdullah@intel.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms and conditions of the GNU General Public License,
  11. * version 2, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. *
  19. */
  20. #include <linux/module.h>
  21. #include <linux/fs.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/slab.h>
  24. #include <linux/io.h>
  25. #include <linux/miscdevice.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/firmware.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/pm_qos.h>
  30. #include <linux/acpi.h>
  31. #include <asm/platform_sst_audio.h>
  32. #include <sound/core.h>
  33. #include <sound/soc.h>
  34. #include <sound/compress_driver.h>
  35. #include <acpi/acbuffer.h>
  36. #include <acpi/platform/acenv.h>
  37. #include <acpi/platform/aclinux.h>
  38. #include <acpi/actypes.h>
  39. #include <acpi/acpi_bus.h>
  40. #include "../sst-mfld-platform.h"
  41. #include "../../common/sst-dsp.h"
  42. #include "sst.h"
  43. struct sst_machines {
  44. char *codec_id;
  45. char board[32];
  46. char machine[32];
  47. void (*machine_quirk)(void);
  48. char firmware[FW_NAME_SIZE];
  49. struct sst_platform_info *pdata;
  50. };
  51. /* LPE viewpoint addresses */
  52. #define SST_BYT_IRAM_PHY_START 0xff2c0000
  53. #define SST_BYT_IRAM_PHY_END 0xff2d4000
  54. #define SST_BYT_DRAM_PHY_START 0xff300000
  55. #define SST_BYT_DRAM_PHY_END 0xff320000
  56. #define SST_BYT_IMR_VIRT_START 0xc0000000 /* virtual addr in LPE */
  57. #define SST_BYT_IMR_VIRT_END 0xc01fffff
  58. #define SST_BYT_SHIM_PHY_ADDR 0xff340000
  59. #define SST_BYT_MBOX_PHY_ADDR 0xff344000
  60. #define SST_BYT_DMA0_PHY_ADDR 0xff298000
  61. #define SST_BYT_DMA1_PHY_ADDR 0xff29c000
  62. #define SST_BYT_SSP0_PHY_ADDR 0xff2a0000
  63. #define SST_BYT_SSP2_PHY_ADDR 0xff2a2000
  64. #define BYT_FW_MOD_TABLE_OFFSET 0x80000
  65. #define BYT_FW_MOD_TABLE_SIZE 0x100
  66. #define BYT_FW_MOD_OFFSET (BYT_FW_MOD_TABLE_OFFSET + BYT_FW_MOD_TABLE_SIZE)
  67. static const struct sst_info byt_fwparse_info = {
  68. .use_elf = false,
  69. .max_streams = 25,
  70. .iram_start = SST_BYT_IRAM_PHY_START,
  71. .iram_end = SST_BYT_IRAM_PHY_END,
  72. .iram_use = true,
  73. .dram_start = SST_BYT_DRAM_PHY_START,
  74. .dram_end = SST_BYT_DRAM_PHY_END,
  75. .dram_use = true,
  76. .imr_start = SST_BYT_IMR_VIRT_START,
  77. .imr_end = SST_BYT_IMR_VIRT_END,
  78. .imr_use = true,
  79. .mailbox_start = SST_BYT_MBOX_PHY_ADDR,
  80. .num_probes = 0,
  81. .lpe_viewpt_rqd = true,
  82. };
  83. static const struct sst_ipc_info byt_ipc_info = {
  84. .ipc_offset = 0,
  85. .mbox_recv_off = 0x400,
  86. };
  87. static const struct sst_lib_dnld_info byt_lib_dnld_info = {
  88. .mod_base = SST_BYT_IMR_VIRT_START,
  89. .mod_end = SST_BYT_IMR_VIRT_END,
  90. .mod_table_offset = BYT_FW_MOD_TABLE_OFFSET,
  91. .mod_table_size = BYT_FW_MOD_TABLE_SIZE,
  92. .mod_ddr_dnld = false,
  93. };
  94. static const struct sst_res_info byt_rvp_res_info = {
  95. .shim_offset = 0x140000,
  96. .shim_size = 0x000100,
  97. .shim_phy_addr = SST_BYT_SHIM_PHY_ADDR,
  98. .ssp0_offset = 0xa0000,
  99. .ssp0_size = 0x1000,
  100. .dma0_offset = 0x98000,
  101. .dma0_size = 0x4000,
  102. .dma1_offset = 0x9c000,
  103. .dma1_size = 0x4000,
  104. .iram_offset = 0x0c0000,
  105. .iram_size = 0x14000,
  106. .dram_offset = 0x100000,
  107. .dram_size = 0x28000,
  108. .mbox_offset = 0x144000,
  109. .mbox_size = 0x1000,
  110. .acpi_lpe_res_index = 0,
  111. .acpi_ddr_index = 2,
  112. .acpi_ipc_irq_index = 5,
  113. };
  114. static struct sst_platform_info byt_rvp_platform_data = {
  115. .probe_data = &byt_fwparse_info,
  116. .ipc_info = &byt_ipc_info,
  117. .lib_info = &byt_lib_dnld_info,
  118. .res_info = &byt_rvp_res_info,
  119. .platform = "sst-mfld-platform",
  120. };
  121. /* Cherryview (Cherrytrail and Braswell) uses same mrfld dpcm fw as Baytrail,
  122. * so pdata is same as Baytrail.
  123. */
  124. static struct sst_platform_info chv_platform_data = {
  125. .probe_data = &byt_fwparse_info,
  126. .ipc_info = &byt_ipc_info,
  127. .lib_info = &byt_lib_dnld_info,
  128. .res_info = &byt_rvp_res_info,
  129. .platform = "sst-mfld-platform",
  130. };
  131. static int sst_platform_get_resources(struct intel_sst_drv *ctx)
  132. {
  133. struct resource *rsrc;
  134. struct platform_device *pdev = to_platform_device(ctx->dev);
  135. /* All ACPI resource request here */
  136. /* Get Shim addr */
  137. rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
  138. ctx->pdata->res_info->acpi_lpe_res_index);
  139. if (!rsrc) {
  140. dev_err(ctx->dev, "Invalid SHIM base from IFWI");
  141. return -EIO;
  142. }
  143. dev_info(ctx->dev, "LPE base: %#x size:%#x", (unsigned int) rsrc->start,
  144. (unsigned int)resource_size(rsrc));
  145. ctx->iram_base = rsrc->start + ctx->pdata->res_info->iram_offset;
  146. ctx->iram_end = ctx->iram_base + ctx->pdata->res_info->iram_size - 1;
  147. dev_info(ctx->dev, "IRAM base: %#x", ctx->iram_base);
  148. ctx->iram = devm_ioremap_nocache(ctx->dev, ctx->iram_base,
  149. ctx->pdata->res_info->iram_size);
  150. if (!ctx->iram) {
  151. dev_err(ctx->dev, "unable to map IRAM");
  152. return -EIO;
  153. }
  154. ctx->dram_base = rsrc->start + ctx->pdata->res_info->dram_offset;
  155. ctx->dram_end = ctx->dram_base + ctx->pdata->res_info->dram_size - 1;
  156. dev_info(ctx->dev, "DRAM base: %#x", ctx->dram_base);
  157. ctx->dram = devm_ioremap_nocache(ctx->dev, ctx->dram_base,
  158. ctx->pdata->res_info->dram_size);
  159. if (!ctx->dram) {
  160. dev_err(ctx->dev, "unable to map DRAM");
  161. return -EIO;
  162. }
  163. ctx->shim_phy_add = rsrc->start + ctx->pdata->res_info->shim_offset;
  164. dev_info(ctx->dev, "SHIM base: %#x", ctx->shim_phy_add);
  165. ctx->shim = devm_ioremap_nocache(ctx->dev, ctx->shim_phy_add,
  166. ctx->pdata->res_info->shim_size);
  167. if (!ctx->shim) {
  168. dev_err(ctx->dev, "unable to map SHIM");
  169. return -EIO;
  170. }
  171. /* reassign physical address to LPE viewpoint address */
  172. ctx->shim_phy_add = ctx->pdata->res_info->shim_phy_addr;
  173. /* Get mailbox addr */
  174. ctx->mailbox_add = rsrc->start + ctx->pdata->res_info->mbox_offset;
  175. dev_info(ctx->dev, "Mailbox base: %#x", ctx->mailbox_add);
  176. ctx->mailbox = devm_ioremap_nocache(ctx->dev, ctx->mailbox_add,
  177. ctx->pdata->res_info->mbox_size);
  178. if (!ctx->mailbox) {
  179. dev_err(ctx->dev, "unable to map mailbox");
  180. return -EIO;
  181. }
  182. /* reassign physical address to LPE viewpoint address */
  183. ctx->mailbox_add = ctx->info.mailbox_start;
  184. rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
  185. ctx->pdata->res_info->acpi_ddr_index);
  186. if (!rsrc) {
  187. dev_err(ctx->dev, "Invalid DDR base from IFWI");
  188. return -EIO;
  189. }
  190. ctx->ddr_base = rsrc->start;
  191. ctx->ddr_end = rsrc->end;
  192. dev_info(ctx->dev, "DDR base: %#x", ctx->ddr_base);
  193. ctx->ddr = devm_ioremap_nocache(ctx->dev, ctx->ddr_base,
  194. resource_size(rsrc));
  195. if (!ctx->ddr) {
  196. dev_err(ctx->dev, "unable to map DDR");
  197. return -EIO;
  198. }
  199. /* Find the IRQ */
  200. ctx->irq_num = platform_get_irq(pdev,
  201. ctx->pdata->res_info->acpi_ipc_irq_index);
  202. return 0;
  203. }
  204. static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
  205. void *context, void **ret)
  206. {
  207. *(bool *)context = true;
  208. return AE_OK;
  209. }
  210. static struct sst_machines *sst_acpi_find_machine(
  211. struct sst_machines *machines)
  212. {
  213. struct sst_machines *mach;
  214. bool found = false;
  215. for (mach = machines; mach->codec_id; mach++)
  216. if (ACPI_SUCCESS(acpi_get_devices(mach->codec_id,
  217. sst_acpi_mach_match,
  218. &found, NULL)) && found)
  219. return mach;
  220. return NULL;
  221. }
  222. static int sst_acpi_probe(struct platform_device *pdev)
  223. {
  224. struct device *dev = &pdev->dev;
  225. int ret = 0;
  226. struct intel_sst_drv *ctx;
  227. const struct acpi_device_id *id;
  228. struct sst_machines *mach;
  229. struct platform_device *mdev;
  230. struct platform_device *plat_dev;
  231. unsigned int dev_id;
  232. id = acpi_match_device(dev->driver->acpi_match_table, dev);
  233. if (!id)
  234. return -ENODEV;
  235. dev_dbg(dev, "for %s", id->id);
  236. mach = (struct sst_machines *)id->driver_data;
  237. mach = sst_acpi_find_machine(mach);
  238. if (mach == NULL) {
  239. dev_err(dev, "No matching machine driver found\n");
  240. return -ENODEV;
  241. }
  242. ret = kstrtouint(id->id, 16, &dev_id);
  243. if (ret < 0) {
  244. dev_err(dev, "Unique device id conversion error: %d\n", ret);
  245. return ret;
  246. }
  247. dev_dbg(dev, "ACPI device id: %x\n", dev_id);
  248. plat_dev = platform_device_register_data(dev, mach->pdata->platform, -1, NULL, 0);
  249. if (IS_ERR(plat_dev)) {
  250. dev_err(dev, "Failed to create machine device: %s\n", mach->pdata->platform);
  251. return PTR_ERR(plat_dev);
  252. }
  253. /* Create platform device for sst machine driver */
  254. mdev = platform_device_register_data(dev, mach->machine, -1, NULL, 0);
  255. if (IS_ERR(mdev)) {
  256. dev_err(dev, "Failed to create machine device: %s\n", mach->machine);
  257. return PTR_ERR(mdev);
  258. }
  259. ret = sst_alloc_drv_context(&ctx, dev, dev_id);
  260. if (ret < 0)
  261. return ret;
  262. /* Fill sst platform data */
  263. ctx->pdata = mach->pdata;
  264. strcpy(ctx->firmware_name, mach->firmware);
  265. ret = sst_platform_get_resources(ctx);
  266. if (ret)
  267. return ret;
  268. ret = sst_context_init(ctx);
  269. if (ret < 0)
  270. return ret;
  271. /* need to save shim registers in BYT */
  272. ctx->shim_regs64 = devm_kzalloc(ctx->dev, sizeof(*ctx->shim_regs64),
  273. GFP_KERNEL);
  274. if (!ctx->shim_regs64) {
  275. ret = -ENOMEM;
  276. goto do_sst_cleanup;
  277. }
  278. sst_configure_runtime_pm(ctx);
  279. platform_set_drvdata(pdev, ctx);
  280. return ret;
  281. do_sst_cleanup:
  282. sst_context_cleanup(ctx);
  283. platform_set_drvdata(pdev, NULL);
  284. dev_err(ctx->dev, "failed with %d\n", ret);
  285. return ret;
  286. }
  287. /**
  288. * intel_sst_remove - remove function
  289. *
  290. * @pdev: platform device structure
  291. *
  292. * This function is called by OS when a device is unloaded
  293. * This frees the interrupt etc
  294. */
  295. static int sst_acpi_remove(struct platform_device *pdev)
  296. {
  297. struct intel_sst_drv *ctx;
  298. ctx = platform_get_drvdata(pdev);
  299. sst_context_cleanup(ctx);
  300. platform_set_drvdata(pdev, NULL);
  301. return 0;
  302. }
  303. static struct sst_machines sst_acpi_bytcr[] = {
  304. {"10EC5640", "T100", "bytt100_rt5640", NULL, "intel/fw_sst_0f28.bin",
  305. &byt_rvp_platform_data },
  306. {},
  307. };
  308. /* Cherryview-based platforms: CherryTrail and Braswell */
  309. static struct sst_machines sst_acpi_chv[] = {
  310. {"10EC5670", "cht-bsw", "cht-bsw-rt5672", NULL, "intel/fw_sst_22a8.bin",
  311. &chv_platform_data },
  312. {"10EC5645", "cht-bsw", "cht-bsw-rt5645", NULL, "intel/fw_sst_22a8.bin",
  313. &chv_platform_data },
  314. {"10EC5650", "cht-bsw", "cht-bsw-rt5645", NULL, "intel/fw_sst_22a8.bin",
  315. &chv_platform_data },
  316. {"193C9890", "cht-bsw", "cht-bsw-max98090", NULL,
  317. "intel/fw_sst_22a8.bin", &chv_platform_data },
  318. {},
  319. };
  320. static const struct acpi_device_id sst_acpi_ids[] = {
  321. { "80860F28", (unsigned long)&sst_acpi_bytcr},
  322. { "808622A8", (unsigned long) &sst_acpi_chv},
  323. { },
  324. };
  325. MODULE_DEVICE_TABLE(acpi, sst_acpi_ids);
  326. static struct platform_driver sst_acpi_driver = {
  327. .driver = {
  328. .name = "intel_sst_acpi",
  329. .acpi_match_table = ACPI_PTR(sst_acpi_ids),
  330. .pm = &intel_sst_pm,
  331. },
  332. .probe = sst_acpi_probe,
  333. .remove = sst_acpi_remove,
  334. };
  335. module_platform_driver(sst_acpi_driver);
  336. MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine ACPI Driver");
  337. MODULE_AUTHOR("Ramesh Babu K V");
  338. MODULE_AUTHOR("Omair Mohammed Abdullah");
  339. MODULE_LICENSE("GPL v2");
  340. MODULE_ALIAS("sst");