sst_acpi.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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/platform_device.h>
  26. #include <linux/firmware.h>
  27. #include <linux/pm_runtime.h>
  28. #include <linux/pm_qos.h>
  29. #include <linux/dmi.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 <asm/cpu_device_id.h>
  41. #include <asm/iosf_mbi.h>
  42. #include <sound/soc-acpi.h>
  43. #include <sound/soc-acpi-intel-match.h>
  44. #include "../sst-mfld-platform.h"
  45. #include "../../common/sst-dsp.h"
  46. #include "sst.h"
  47. /* LPE viewpoint addresses */
  48. #define SST_BYT_IRAM_PHY_START 0xff2c0000
  49. #define SST_BYT_IRAM_PHY_END 0xff2d4000
  50. #define SST_BYT_DRAM_PHY_START 0xff300000
  51. #define SST_BYT_DRAM_PHY_END 0xff320000
  52. #define SST_BYT_IMR_VIRT_START 0xc0000000 /* virtual addr in LPE */
  53. #define SST_BYT_IMR_VIRT_END 0xc01fffff
  54. #define SST_BYT_SHIM_PHY_ADDR 0xff340000
  55. #define SST_BYT_MBOX_PHY_ADDR 0xff344000
  56. #define SST_BYT_DMA0_PHY_ADDR 0xff298000
  57. #define SST_BYT_DMA1_PHY_ADDR 0xff29c000
  58. #define SST_BYT_SSP0_PHY_ADDR 0xff2a0000
  59. #define SST_BYT_SSP2_PHY_ADDR 0xff2a2000
  60. #define BYT_FW_MOD_TABLE_OFFSET 0x80000
  61. #define BYT_FW_MOD_TABLE_SIZE 0x100
  62. #define BYT_FW_MOD_OFFSET (BYT_FW_MOD_TABLE_OFFSET + BYT_FW_MOD_TABLE_SIZE)
  63. static const struct sst_info byt_fwparse_info = {
  64. .use_elf = false,
  65. .max_streams = 25,
  66. .iram_start = SST_BYT_IRAM_PHY_START,
  67. .iram_end = SST_BYT_IRAM_PHY_END,
  68. .iram_use = true,
  69. .dram_start = SST_BYT_DRAM_PHY_START,
  70. .dram_end = SST_BYT_DRAM_PHY_END,
  71. .dram_use = true,
  72. .imr_start = SST_BYT_IMR_VIRT_START,
  73. .imr_end = SST_BYT_IMR_VIRT_END,
  74. .imr_use = true,
  75. .mailbox_start = SST_BYT_MBOX_PHY_ADDR,
  76. .num_probes = 0,
  77. .lpe_viewpt_rqd = true,
  78. };
  79. static const struct sst_ipc_info byt_ipc_info = {
  80. .ipc_offset = 0,
  81. .mbox_recv_off = 0x400,
  82. };
  83. static const struct sst_lib_dnld_info byt_lib_dnld_info = {
  84. .mod_base = SST_BYT_IMR_VIRT_START,
  85. .mod_end = SST_BYT_IMR_VIRT_END,
  86. .mod_table_offset = BYT_FW_MOD_TABLE_OFFSET,
  87. .mod_table_size = BYT_FW_MOD_TABLE_SIZE,
  88. .mod_ddr_dnld = false,
  89. };
  90. static const struct sst_res_info byt_rvp_res_info = {
  91. .shim_offset = 0x140000,
  92. .shim_size = 0x000100,
  93. .shim_phy_addr = SST_BYT_SHIM_PHY_ADDR,
  94. .ssp0_offset = 0xa0000,
  95. .ssp0_size = 0x1000,
  96. .dma0_offset = 0x98000,
  97. .dma0_size = 0x4000,
  98. .dma1_offset = 0x9c000,
  99. .dma1_size = 0x4000,
  100. .iram_offset = 0x0c0000,
  101. .iram_size = 0x14000,
  102. .dram_offset = 0x100000,
  103. .dram_size = 0x28000,
  104. .mbox_offset = 0x144000,
  105. .mbox_size = 0x1000,
  106. .acpi_lpe_res_index = 0,
  107. .acpi_ddr_index = 2,
  108. .acpi_ipc_irq_index = 5,
  109. };
  110. /* BYTCR has different BIOS from BYT */
  111. static const struct sst_res_info bytcr_res_info = {
  112. .shim_offset = 0x140000,
  113. .shim_size = 0x000100,
  114. .shim_phy_addr = SST_BYT_SHIM_PHY_ADDR,
  115. .ssp0_offset = 0xa0000,
  116. .ssp0_size = 0x1000,
  117. .dma0_offset = 0x98000,
  118. .dma0_size = 0x4000,
  119. .dma1_offset = 0x9c000,
  120. .dma1_size = 0x4000,
  121. .iram_offset = 0x0c0000,
  122. .iram_size = 0x14000,
  123. .dram_offset = 0x100000,
  124. .dram_size = 0x28000,
  125. .mbox_offset = 0x144000,
  126. .mbox_size = 0x1000,
  127. .acpi_lpe_res_index = 0,
  128. .acpi_ddr_index = 2,
  129. .acpi_ipc_irq_index = 0
  130. };
  131. static struct sst_platform_info byt_rvp_platform_data = {
  132. .probe_data = &byt_fwparse_info,
  133. .ipc_info = &byt_ipc_info,
  134. .lib_info = &byt_lib_dnld_info,
  135. .res_info = &byt_rvp_res_info,
  136. .platform = "sst-mfld-platform",
  137. .streams_lost_on_suspend = true,
  138. };
  139. /* Cherryview (Cherrytrail and Braswell) uses same mrfld dpcm fw as Baytrail,
  140. * so pdata is same as Baytrail, minus the streams_lost_on_suspend quirk.
  141. */
  142. static struct sst_platform_info chv_platform_data = {
  143. .probe_data = &byt_fwparse_info,
  144. .ipc_info = &byt_ipc_info,
  145. .lib_info = &byt_lib_dnld_info,
  146. .res_info = &byt_rvp_res_info,
  147. .platform = "sst-mfld-platform",
  148. };
  149. static int sst_platform_get_resources(struct intel_sst_drv *ctx)
  150. {
  151. struct resource *rsrc;
  152. struct platform_device *pdev = to_platform_device(ctx->dev);
  153. /* All ACPI resource request here */
  154. /* Get Shim addr */
  155. rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
  156. ctx->pdata->res_info->acpi_lpe_res_index);
  157. if (!rsrc) {
  158. dev_err(ctx->dev, "Invalid SHIM base from IFWI\n");
  159. return -EIO;
  160. }
  161. dev_info(ctx->dev, "LPE base: %#x size:%#x", (unsigned int) rsrc->start,
  162. (unsigned int)resource_size(rsrc));
  163. ctx->iram_base = rsrc->start + ctx->pdata->res_info->iram_offset;
  164. ctx->iram_end = ctx->iram_base + ctx->pdata->res_info->iram_size - 1;
  165. dev_info(ctx->dev, "IRAM base: %#x", ctx->iram_base);
  166. ctx->iram = devm_ioremap_nocache(ctx->dev, ctx->iram_base,
  167. ctx->pdata->res_info->iram_size);
  168. if (!ctx->iram) {
  169. dev_err(ctx->dev, "unable to map IRAM\n");
  170. return -EIO;
  171. }
  172. ctx->dram_base = rsrc->start + ctx->pdata->res_info->dram_offset;
  173. ctx->dram_end = ctx->dram_base + ctx->pdata->res_info->dram_size - 1;
  174. dev_info(ctx->dev, "DRAM base: %#x", ctx->dram_base);
  175. ctx->dram = devm_ioremap_nocache(ctx->dev, ctx->dram_base,
  176. ctx->pdata->res_info->dram_size);
  177. if (!ctx->dram) {
  178. dev_err(ctx->dev, "unable to map DRAM\n");
  179. return -EIO;
  180. }
  181. ctx->shim_phy_add = rsrc->start + ctx->pdata->res_info->shim_offset;
  182. dev_info(ctx->dev, "SHIM base: %#x", ctx->shim_phy_add);
  183. ctx->shim = devm_ioremap_nocache(ctx->dev, ctx->shim_phy_add,
  184. ctx->pdata->res_info->shim_size);
  185. if (!ctx->shim) {
  186. dev_err(ctx->dev, "unable to map SHIM\n");
  187. return -EIO;
  188. }
  189. /* reassign physical address to LPE viewpoint address */
  190. ctx->shim_phy_add = ctx->pdata->res_info->shim_phy_addr;
  191. /* Get mailbox addr */
  192. ctx->mailbox_add = rsrc->start + ctx->pdata->res_info->mbox_offset;
  193. dev_info(ctx->dev, "Mailbox base: %#x", ctx->mailbox_add);
  194. ctx->mailbox = devm_ioremap_nocache(ctx->dev, ctx->mailbox_add,
  195. ctx->pdata->res_info->mbox_size);
  196. if (!ctx->mailbox) {
  197. dev_err(ctx->dev, "unable to map mailbox\n");
  198. return -EIO;
  199. }
  200. /* reassign physical address to LPE viewpoint address */
  201. ctx->mailbox_add = ctx->info.mailbox_start;
  202. rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
  203. ctx->pdata->res_info->acpi_ddr_index);
  204. if (!rsrc) {
  205. dev_err(ctx->dev, "Invalid DDR base from IFWI\n");
  206. return -EIO;
  207. }
  208. ctx->ddr_base = rsrc->start;
  209. ctx->ddr_end = rsrc->end;
  210. dev_info(ctx->dev, "DDR base: %#x", ctx->ddr_base);
  211. ctx->ddr = devm_ioremap_nocache(ctx->dev, ctx->ddr_base,
  212. resource_size(rsrc));
  213. if (!ctx->ddr) {
  214. dev_err(ctx->dev, "unable to map DDR\n");
  215. return -EIO;
  216. }
  217. /* Find the IRQ */
  218. ctx->irq_num = platform_get_irq(pdev,
  219. ctx->pdata->res_info->acpi_ipc_irq_index);
  220. if (ctx->irq_num <= 0)
  221. return ctx->irq_num < 0 ? ctx->irq_num : -EIO;
  222. return 0;
  223. }
  224. static int is_byt(void)
  225. {
  226. bool status = false;
  227. static const struct x86_cpu_id cpu_ids[] = {
  228. { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
  229. {}
  230. };
  231. if (x86_match_cpu(cpu_ids))
  232. status = true;
  233. return status;
  234. }
  235. static int is_byt_cr(struct device *dev, bool *bytcr)
  236. {
  237. int status = 0;
  238. if (IS_ENABLED(CONFIG_IOSF_MBI)) {
  239. u32 bios_status;
  240. if (!is_byt() || !iosf_mbi_available()) {
  241. /* bail silently */
  242. return status;
  243. }
  244. status = iosf_mbi_read(BT_MBI_UNIT_PMC, /* 0x04 PUNIT */
  245. MBI_REG_READ, /* 0x10 */
  246. 0x006, /* BIOS_CONFIG */
  247. &bios_status);
  248. if (status) {
  249. dev_err(dev, "could not read PUNIT BIOS_CONFIG\n");
  250. } else {
  251. /* bits 26:27 mirror PMIC options */
  252. bios_status = (bios_status >> 26) & 3;
  253. if ((bios_status == 1) || (bios_status == 3))
  254. *bytcr = true;
  255. else
  256. dev_info(dev, "BYT-CR not detected\n");
  257. }
  258. } else {
  259. dev_info(dev, "IOSF_MBI not enabled, no BYT-CR detection\n");
  260. }
  261. return status;
  262. }
  263. static int sst_acpi_probe(struct platform_device *pdev)
  264. {
  265. struct device *dev = &pdev->dev;
  266. int ret = 0;
  267. struct intel_sst_drv *ctx;
  268. const struct acpi_device_id *id;
  269. struct snd_soc_acpi_mach *mach;
  270. struct platform_device *mdev;
  271. struct platform_device *plat_dev;
  272. struct sst_platform_info *pdata;
  273. unsigned int dev_id;
  274. bool bytcr = false;
  275. id = acpi_match_device(dev->driver->acpi_match_table, dev);
  276. if (!id)
  277. return -ENODEV;
  278. dev_dbg(dev, "for %s\n", id->id);
  279. mach = (struct snd_soc_acpi_mach *)id->driver_data;
  280. mach = snd_soc_acpi_find_machine(mach);
  281. if (mach == NULL) {
  282. dev_err(dev, "No matching machine driver found\n");
  283. return -ENODEV;
  284. }
  285. if (is_byt())
  286. mach->pdata = &byt_rvp_platform_data;
  287. else
  288. mach->pdata = &chv_platform_data;
  289. pdata = mach->pdata;
  290. ret = kstrtouint(id->id, 16, &dev_id);
  291. if (ret < 0) {
  292. dev_err(dev, "Unique device id conversion error: %d\n", ret);
  293. return ret;
  294. }
  295. dev_dbg(dev, "ACPI device id: %x\n", dev_id);
  296. ret = sst_alloc_drv_context(&ctx, dev, dev_id);
  297. if (ret < 0)
  298. return ret;
  299. ret = is_byt_cr(dev, &bytcr);
  300. if (!((ret < 0) || (bytcr == false))) {
  301. dev_info(dev, "Detected Baytrail-CR platform\n");
  302. /* override resource info */
  303. byt_rvp_platform_data.res_info = &bytcr_res_info;
  304. }
  305. plat_dev = platform_device_register_data(dev, pdata->platform, -1,
  306. NULL, 0);
  307. if (IS_ERR(plat_dev)) {
  308. dev_err(dev, "Failed to create machine device: %s\n",
  309. pdata->platform);
  310. return PTR_ERR(plat_dev);
  311. }
  312. /*
  313. * Create platform device for sst machine driver,
  314. * pass machine info as pdata
  315. */
  316. mdev = platform_device_register_data(dev, mach->drv_name, -1,
  317. (const void *)mach, sizeof(*mach));
  318. if (IS_ERR(mdev)) {
  319. dev_err(dev, "Failed to create machine device: %s\n",
  320. mach->drv_name);
  321. return PTR_ERR(mdev);
  322. }
  323. /* Fill sst platform data */
  324. ctx->pdata = pdata;
  325. strcpy(ctx->firmware_name, mach->fw_filename);
  326. ret = sst_platform_get_resources(ctx);
  327. if (ret)
  328. return ret;
  329. ret = sst_context_init(ctx);
  330. if (ret < 0)
  331. return ret;
  332. sst_configure_runtime_pm(ctx);
  333. platform_set_drvdata(pdev, ctx);
  334. return ret;
  335. }
  336. /**
  337. * intel_sst_remove - remove function
  338. *
  339. * @pdev: platform device structure
  340. *
  341. * This function is called by OS when a device is unloaded
  342. * This frees the interrupt etc
  343. */
  344. static int sst_acpi_remove(struct platform_device *pdev)
  345. {
  346. struct intel_sst_drv *ctx;
  347. ctx = platform_get_drvdata(pdev);
  348. sst_context_cleanup(ctx);
  349. platform_set_drvdata(pdev, NULL);
  350. return 0;
  351. }
  352. static const struct acpi_device_id sst_acpi_ids[] = {
  353. { "80860F28", (unsigned long)&snd_soc_acpi_intel_baytrail_machines},
  354. { "808622A8", (unsigned long)&snd_soc_acpi_intel_cherrytrail_machines},
  355. { },
  356. };
  357. MODULE_DEVICE_TABLE(acpi, sst_acpi_ids);
  358. static struct platform_driver sst_acpi_driver = {
  359. .driver = {
  360. .name = "intel_sst_acpi",
  361. .acpi_match_table = ACPI_PTR(sst_acpi_ids),
  362. .pm = &intel_sst_pm,
  363. },
  364. .probe = sst_acpi_probe,
  365. .remove = sst_acpi_remove,
  366. };
  367. module_platform_driver(sst_acpi_driver);
  368. MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine ACPI Driver");
  369. MODULE_AUTHOR("Ramesh Babu K V");
  370. MODULE_AUTHOR("Omair Mohammed Abdullah");
  371. MODULE_LICENSE("GPL v2");
  372. MODULE_ALIAS("sst");