sst_acpi.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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/dmi.h>
  31. #include <linux/acpi.h>
  32. #include <asm/platform_sst_audio.h>
  33. #include <sound/core.h>
  34. #include <sound/soc.h>
  35. #include <sound/compress_driver.h>
  36. #include <acpi/acbuffer.h>
  37. #include <acpi/platform/acenv.h>
  38. #include <acpi/platform/aclinux.h>
  39. #include <acpi/actypes.h>
  40. #include <acpi/acpi_bus.h>
  41. #include <asm/cpu_device_id.h>
  42. #include <asm/iosf_mbi.h>
  43. #include "../sst-mfld-platform.h"
  44. #include "../../common/sst-dsp.h"
  45. #include "../../common/sst-acpi.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. };
  138. /* Cherryview (Cherrytrail and Braswell) uses same mrfld dpcm fw as Baytrail,
  139. * so pdata is same as Baytrail.
  140. */
  141. static struct sst_platform_info chv_platform_data = {
  142. .probe_data = &byt_fwparse_info,
  143. .ipc_info = &byt_ipc_info,
  144. .lib_info = &byt_lib_dnld_info,
  145. .res_info = &byt_rvp_res_info,
  146. .platform = "sst-mfld-platform",
  147. };
  148. static int sst_platform_get_resources(struct intel_sst_drv *ctx)
  149. {
  150. struct resource *rsrc;
  151. struct platform_device *pdev = to_platform_device(ctx->dev);
  152. /* All ACPI resource request here */
  153. /* Get Shim addr */
  154. rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
  155. ctx->pdata->res_info->acpi_lpe_res_index);
  156. if (!rsrc) {
  157. dev_err(ctx->dev, "Invalid SHIM base from IFWI\n");
  158. return -EIO;
  159. }
  160. dev_info(ctx->dev, "LPE base: %#x size:%#x", (unsigned int) rsrc->start,
  161. (unsigned int)resource_size(rsrc));
  162. ctx->iram_base = rsrc->start + ctx->pdata->res_info->iram_offset;
  163. ctx->iram_end = ctx->iram_base + ctx->pdata->res_info->iram_size - 1;
  164. dev_info(ctx->dev, "IRAM base: %#x", ctx->iram_base);
  165. ctx->iram = devm_ioremap_nocache(ctx->dev, ctx->iram_base,
  166. ctx->pdata->res_info->iram_size);
  167. if (!ctx->iram) {
  168. dev_err(ctx->dev, "unable to map IRAM\n");
  169. return -EIO;
  170. }
  171. ctx->dram_base = rsrc->start + ctx->pdata->res_info->dram_offset;
  172. ctx->dram_end = ctx->dram_base + ctx->pdata->res_info->dram_size - 1;
  173. dev_info(ctx->dev, "DRAM base: %#x", ctx->dram_base);
  174. ctx->dram = devm_ioremap_nocache(ctx->dev, ctx->dram_base,
  175. ctx->pdata->res_info->dram_size);
  176. if (!ctx->dram) {
  177. dev_err(ctx->dev, "unable to map DRAM\n");
  178. return -EIO;
  179. }
  180. ctx->shim_phy_add = rsrc->start + ctx->pdata->res_info->shim_offset;
  181. dev_info(ctx->dev, "SHIM base: %#x", ctx->shim_phy_add);
  182. ctx->shim = devm_ioremap_nocache(ctx->dev, ctx->shim_phy_add,
  183. ctx->pdata->res_info->shim_size);
  184. if (!ctx->shim) {
  185. dev_err(ctx->dev, "unable to map SHIM\n");
  186. return -EIO;
  187. }
  188. /* reassign physical address to LPE viewpoint address */
  189. ctx->shim_phy_add = ctx->pdata->res_info->shim_phy_addr;
  190. /* Get mailbox addr */
  191. ctx->mailbox_add = rsrc->start + ctx->pdata->res_info->mbox_offset;
  192. dev_info(ctx->dev, "Mailbox base: %#x", ctx->mailbox_add);
  193. ctx->mailbox = devm_ioremap_nocache(ctx->dev, ctx->mailbox_add,
  194. ctx->pdata->res_info->mbox_size);
  195. if (!ctx->mailbox) {
  196. dev_err(ctx->dev, "unable to map mailbox\n");
  197. return -EIO;
  198. }
  199. /* reassign physical address to LPE viewpoint address */
  200. ctx->mailbox_add = ctx->info.mailbox_start;
  201. rsrc = platform_get_resource(pdev, IORESOURCE_MEM,
  202. ctx->pdata->res_info->acpi_ddr_index);
  203. if (!rsrc) {
  204. dev_err(ctx->dev, "Invalid DDR base from IFWI\n");
  205. return -EIO;
  206. }
  207. ctx->ddr_base = rsrc->start;
  208. ctx->ddr_end = rsrc->end;
  209. dev_info(ctx->dev, "DDR base: %#x", ctx->ddr_base);
  210. ctx->ddr = devm_ioremap_nocache(ctx->dev, ctx->ddr_base,
  211. resource_size(rsrc));
  212. if (!ctx->ddr) {
  213. dev_err(ctx->dev, "unable to map DDR\n");
  214. return -EIO;
  215. }
  216. /* Find the IRQ */
  217. ctx->irq_num = platform_get_irq(pdev,
  218. ctx->pdata->res_info->acpi_ipc_irq_index);
  219. return 0;
  220. }
  221. static int is_byt_cr(struct device *dev, bool *bytcr)
  222. {
  223. int status = 0;
  224. if (IS_ENABLED(CONFIG_IOSF_MBI)) {
  225. static const struct x86_cpu_id cpu_ids[] = {
  226. { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
  227. {}
  228. };
  229. u32 bios_status;
  230. if (!x86_match_cpu(cpu_ids) || !iosf_mbi_available()) {
  231. /* bail silently */
  232. return status;
  233. }
  234. status = iosf_mbi_read(BT_MBI_UNIT_PMC, /* 0x04 PUNIT */
  235. MBI_REG_READ, /* 0x10 */
  236. 0x006, /* BIOS_CONFIG */
  237. &bios_status);
  238. if (status) {
  239. dev_err(dev, "could not read PUNIT BIOS_CONFIG\n");
  240. } else {
  241. /* bits 26:27 mirror PMIC options */
  242. bios_status = (bios_status >> 26) & 3;
  243. if ((bios_status == 1) || (bios_status == 3))
  244. *bytcr = true;
  245. else
  246. dev_info(dev, "BYT-CR not detected\n");
  247. }
  248. } else {
  249. dev_info(dev, "IOSF_MBI not enabled, no BYT-CR detection\n");
  250. }
  251. return status;
  252. }
  253. static int sst_acpi_probe(struct platform_device *pdev)
  254. {
  255. struct device *dev = &pdev->dev;
  256. int ret = 0;
  257. struct intel_sst_drv *ctx;
  258. const struct acpi_device_id *id;
  259. struct sst_acpi_mach *mach;
  260. struct platform_device *mdev;
  261. struct platform_device *plat_dev;
  262. struct sst_platform_info *pdata;
  263. unsigned int dev_id;
  264. bool bytcr = false;
  265. id = acpi_match_device(dev->driver->acpi_match_table, dev);
  266. if (!id)
  267. return -ENODEV;
  268. dev_dbg(dev, "for %s\n", id->id);
  269. mach = (struct sst_acpi_mach *)id->driver_data;
  270. mach = sst_acpi_find_machine(mach);
  271. if (mach == NULL) {
  272. dev_err(dev, "No matching machine driver found\n");
  273. return -ENODEV;
  274. }
  275. if (mach->machine_quirk)
  276. mach = mach->machine_quirk(mach);
  277. pdata = mach->pdata;
  278. ret = kstrtouint(id->id, 16, &dev_id);
  279. if (ret < 0) {
  280. dev_err(dev, "Unique device id conversion error: %d\n", ret);
  281. return ret;
  282. }
  283. dev_dbg(dev, "ACPI device id: %x\n", dev_id);
  284. ret = sst_alloc_drv_context(&ctx, dev, dev_id);
  285. if (ret < 0)
  286. return ret;
  287. ret = is_byt_cr(dev, &bytcr);
  288. if (!((ret < 0) || (bytcr == false))) {
  289. dev_info(dev, "Detected Baytrail-CR platform\n");
  290. /* override resource info */
  291. byt_rvp_platform_data.res_info = &bytcr_res_info;
  292. }
  293. plat_dev = platform_device_register_data(dev, pdata->platform, -1,
  294. NULL, 0);
  295. if (IS_ERR(plat_dev)) {
  296. dev_err(dev, "Failed to create machine device: %s\n",
  297. pdata->platform);
  298. return PTR_ERR(plat_dev);
  299. }
  300. /*
  301. * Create platform device for sst machine driver,
  302. * pass machine info as pdata
  303. */
  304. mdev = platform_device_register_data(dev, mach->drv_name, -1,
  305. (const void *)mach, sizeof(*mach));
  306. if (IS_ERR(mdev)) {
  307. dev_err(dev, "Failed to create machine device: %s\n",
  308. mach->drv_name);
  309. return PTR_ERR(mdev);
  310. }
  311. /* Fill sst platform data */
  312. ctx->pdata = pdata;
  313. strcpy(ctx->firmware_name, mach->fw_filename);
  314. ret = sst_platform_get_resources(ctx);
  315. if (ret)
  316. return ret;
  317. ret = sst_context_init(ctx);
  318. if (ret < 0)
  319. return ret;
  320. /* need to save shim registers in BYT */
  321. ctx->shim_regs64 = devm_kzalloc(ctx->dev, sizeof(*ctx->shim_regs64),
  322. GFP_KERNEL);
  323. if (!ctx->shim_regs64) {
  324. ret = -ENOMEM;
  325. goto do_sst_cleanup;
  326. }
  327. sst_configure_runtime_pm(ctx);
  328. platform_set_drvdata(pdev, ctx);
  329. return ret;
  330. do_sst_cleanup:
  331. sst_context_cleanup(ctx);
  332. platform_set_drvdata(pdev, NULL);
  333. dev_err(ctx->dev, "failed with %d\n", ret);
  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 unsigned long cht_machine_id;
  353. #define CHT_SURFACE_MACH 1
  354. #define BYT_THINKPAD_10 2
  355. static int cht_surface_quirk_cb(const struct dmi_system_id *id)
  356. {
  357. cht_machine_id = CHT_SURFACE_MACH;
  358. return 1;
  359. }
  360. static int byt_thinkpad10_quirk_cb(const struct dmi_system_id *id)
  361. {
  362. cht_machine_id = BYT_THINKPAD_10;
  363. return 1;
  364. }
  365. static const struct dmi_system_id byt_table[] = {
  366. {
  367. .callback = byt_thinkpad10_quirk_cb,
  368. .matches = {
  369. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  370. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 10"),
  371. },
  372. },
  373. {
  374. .callback = byt_thinkpad10_quirk_cb,
  375. .matches = {
  376. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  377. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Tablet B"),
  378. },
  379. },
  380. {
  381. .callback = byt_thinkpad10_quirk_cb,
  382. .matches = {
  383. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  384. DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Miix 2 10"),
  385. },
  386. },
  387. { }
  388. };
  389. static const struct dmi_system_id cht_table[] = {
  390. {
  391. .callback = cht_surface_quirk_cb,
  392. .matches = {
  393. DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
  394. DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
  395. },
  396. },
  397. { }
  398. };
  399. static struct sst_acpi_mach cht_surface_mach = {
  400. "10EC5640", "cht-bsw-rt5645", "/*(DEBLOBBED)*/", "cht-bsw", NULL,
  401. &chv_platform_data };
  402. static struct sst_acpi_mach byt_thinkpad_10 = {
  403. "10EC5640", "cht-bsw-rt5672", "/*(DEBLOBBED)*/", "cht-bsw", NULL,
  404. &byt_rvp_platform_data };
  405. static struct sst_acpi_mach *cht_quirk(void *arg)
  406. {
  407. struct sst_acpi_mach *mach = arg;
  408. dmi_check_system(cht_table);
  409. if (cht_machine_id == CHT_SURFACE_MACH)
  410. return &cht_surface_mach;
  411. else
  412. return mach;
  413. }
  414. static struct sst_acpi_mach *byt_quirk(void *arg)
  415. {
  416. struct sst_acpi_mach *mach = arg;
  417. dmi_check_system(byt_table);
  418. if (cht_machine_id == BYT_THINKPAD_10)
  419. return &byt_thinkpad_10;
  420. else
  421. return mach;
  422. }
  423. static struct sst_acpi_mach sst_acpi_bytcr[] = {
  424. {"10EC5640", "bytcr_rt5640", "/*(DEBLOBBED)*/", "bytcr_rt5640", byt_quirk,
  425. &byt_rvp_platform_data },
  426. {"10EC5642", "bytcr_rt5640", "/*(DEBLOBBED)*/", "bytcr_rt5640", NULL,
  427. &byt_rvp_platform_data },
  428. {"INTCCFFD", "bytcr_rt5640", "/*(DEBLOBBED)*/", "bytcr_rt5640", NULL,
  429. &byt_rvp_platform_data },
  430. {"10EC5651", "bytcr_rt5651", "/*(DEBLOBBED)*/", "bytcr_rt5651", NULL,
  431. &byt_rvp_platform_data },
  432. {},
  433. };
  434. /* Cherryview-based platforms: CherryTrail and Braswell */
  435. static struct sst_acpi_mach sst_acpi_chv[] = {
  436. {"10EC5670", "cht-bsw-rt5672", "/*(DEBLOBBED)*/", "cht-bsw", NULL,
  437. &chv_platform_data },
  438. {"10EC5645", "cht-bsw-rt5645", "/*(DEBLOBBED)*/", "cht-bsw", NULL,
  439. &chv_platform_data },
  440. {"10EC5650", "cht-bsw-rt5645", "/*(DEBLOBBED)*/", "cht-bsw", NULL,
  441. &chv_platform_data },
  442. {"193C9890", "cht-bsw-max98090", "/*(DEBLOBBED)*/", "cht-bsw", NULL,
  443. &chv_platform_data },
  444. /* some CHT-T platforms rely on RT5640, use Baytrail machine driver */
  445. {"10EC5640", "bytcr_rt5640", "/*(DEBLOBBED)*/", "bytcr_rt5640", cht_quirk,
  446. &chv_platform_data },
  447. {},
  448. };
  449. static const struct acpi_device_id sst_acpi_ids[] = {
  450. { "80860F28", (unsigned long)&sst_acpi_bytcr},
  451. { "808622A8", (unsigned long) &sst_acpi_chv},
  452. { },
  453. };
  454. MODULE_DEVICE_TABLE(acpi, sst_acpi_ids);
  455. static struct platform_driver sst_acpi_driver = {
  456. .driver = {
  457. .name = "intel_sst_acpi",
  458. .acpi_match_table = ACPI_PTR(sst_acpi_ids),
  459. .pm = &intel_sst_pm,
  460. },
  461. .probe = sst_acpi_probe,
  462. .remove = sst_acpi_remove,
  463. };
  464. module_platform_driver(sst_acpi_driver);
  465. MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine ACPI Driver");
  466. MODULE_AUTHOR("Ramesh Babu K V");
  467. MODULE_AUTHOR("Omair Mohammed Abdullah");
  468. MODULE_LICENSE("GPL v2");
  469. MODULE_ALIAS("sst");