2 * sst_acpi.c - SST (LPE) driver init file for ACPI enumeration.
4 * Copyright (c) 2013, Intel Corporation.
6 * Authors: Ramesh Babu K V <Ramesh.Babu@intel.com>
7 * Authors: Omair Mohammed Abdullah <omair.m.abdullah@intel.com>
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.
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
21 #include <linux/module.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.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 <sound/soc-acpi.h>
44 #include "../sst-mfld-platform.h"
45 #include "../../common/sst-dsp.h"
48 /* LPE viewpoint addresses */
49 #define SST_BYT_IRAM_PHY_START 0xff2c0000
50 #define SST_BYT_IRAM_PHY_END 0xff2d4000
51 #define SST_BYT_DRAM_PHY_START 0xff300000
52 #define SST_BYT_DRAM_PHY_END 0xff320000
53 #define SST_BYT_IMR_VIRT_START 0xc0000000 /* virtual addr in LPE */
54 #define SST_BYT_IMR_VIRT_END 0xc01fffff
55 #define SST_BYT_SHIM_PHY_ADDR 0xff340000
56 #define SST_BYT_MBOX_PHY_ADDR 0xff344000
57 #define SST_BYT_DMA0_PHY_ADDR 0xff298000
58 #define SST_BYT_DMA1_PHY_ADDR 0xff29c000
59 #define SST_BYT_SSP0_PHY_ADDR 0xff2a0000
60 #define SST_BYT_SSP2_PHY_ADDR 0xff2a2000
62 #define BYT_FW_MOD_TABLE_OFFSET 0x80000
63 #define BYT_FW_MOD_TABLE_SIZE 0x100
64 #define BYT_FW_MOD_OFFSET (BYT_FW_MOD_TABLE_OFFSET + BYT_FW_MOD_TABLE_SIZE)
66 static const struct sst_info byt_fwparse_info
= {
69 .iram_start
= SST_BYT_IRAM_PHY_START
,
70 .iram_end
= SST_BYT_IRAM_PHY_END
,
72 .dram_start
= SST_BYT_DRAM_PHY_START
,
73 .dram_end
= SST_BYT_DRAM_PHY_END
,
75 .imr_start
= SST_BYT_IMR_VIRT_START
,
76 .imr_end
= SST_BYT_IMR_VIRT_END
,
78 .mailbox_start
= SST_BYT_MBOX_PHY_ADDR
,
80 .lpe_viewpt_rqd
= true,
83 static const struct sst_ipc_info byt_ipc_info
= {
85 .mbox_recv_off
= 0x400,
88 static const struct sst_lib_dnld_info byt_lib_dnld_info
= {
89 .mod_base
= SST_BYT_IMR_VIRT_START
,
90 .mod_end
= SST_BYT_IMR_VIRT_END
,
91 .mod_table_offset
= BYT_FW_MOD_TABLE_OFFSET
,
92 .mod_table_size
= BYT_FW_MOD_TABLE_SIZE
,
93 .mod_ddr_dnld
= false,
96 static const struct sst_res_info byt_rvp_res_info
= {
97 .shim_offset
= 0x140000,
98 .shim_size
= 0x000100,
99 .shim_phy_addr
= SST_BYT_SHIM_PHY_ADDR
,
100 .ssp0_offset
= 0xa0000,
102 .dma0_offset
= 0x98000,
104 .dma1_offset
= 0x9c000,
106 .iram_offset
= 0x0c0000,
107 .iram_size
= 0x14000,
108 .dram_offset
= 0x100000,
109 .dram_size
= 0x28000,
110 .mbox_offset
= 0x144000,
112 .acpi_lpe_res_index
= 0,
114 .acpi_ipc_irq_index
= 5,
117 /* BYTCR has different BIOS from BYT */
118 static const struct sst_res_info bytcr_res_info
= {
119 .shim_offset
= 0x140000,
120 .shim_size
= 0x000100,
121 .shim_phy_addr
= SST_BYT_SHIM_PHY_ADDR
,
122 .ssp0_offset
= 0xa0000,
124 .dma0_offset
= 0x98000,
126 .dma1_offset
= 0x9c000,
128 .iram_offset
= 0x0c0000,
129 .iram_size
= 0x14000,
130 .dram_offset
= 0x100000,
131 .dram_size
= 0x28000,
132 .mbox_offset
= 0x144000,
134 .acpi_lpe_res_index
= 0,
136 .acpi_ipc_irq_index
= 0
139 static struct sst_platform_info byt_rvp_platform_data
= {
140 .probe_data
= &byt_fwparse_info
,
141 .ipc_info
= &byt_ipc_info
,
142 .lib_info
= &byt_lib_dnld_info
,
143 .res_info
= &byt_rvp_res_info
,
144 .platform
= "sst-mfld-platform",
147 /* Cherryview (Cherrytrail and Braswell) uses same mrfld dpcm fw as Baytrail,
148 * so pdata is same as Baytrail.
150 static struct sst_platform_info chv_platform_data
= {
151 .probe_data
= &byt_fwparse_info
,
152 .ipc_info
= &byt_ipc_info
,
153 .lib_info
= &byt_lib_dnld_info
,
154 .res_info
= &byt_rvp_res_info
,
155 .platform
= "sst-mfld-platform",
158 static int sst_platform_get_resources(struct intel_sst_drv
*ctx
)
160 struct resource
*rsrc
;
161 struct platform_device
*pdev
= to_platform_device(ctx
->dev
);
163 /* All ACPI resource request here */
165 rsrc
= platform_get_resource(pdev
, IORESOURCE_MEM
,
166 ctx
->pdata
->res_info
->acpi_lpe_res_index
);
168 dev_err(ctx
->dev
, "Invalid SHIM base from IFWI\n");
171 dev_info(ctx
->dev
, "LPE base: %#x size:%#x", (unsigned int) rsrc
->start
,
172 (unsigned int)resource_size(rsrc
));
174 ctx
->iram_base
= rsrc
->start
+ ctx
->pdata
->res_info
->iram_offset
;
175 ctx
->iram_end
= ctx
->iram_base
+ ctx
->pdata
->res_info
->iram_size
- 1;
176 dev_info(ctx
->dev
, "IRAM base: %#x", ctx
->iram_base
);
177 ctx
->iram
= devm_ioremap_nocache(ctx
->dev
, ctx
->iram_base
,
178 ctx
->pdata
->res_info
->iram_size
);
180 dev_err(ctx
->dev
, "unable to map IRAM\n");
184 ctx
->dram_base
= rsrc
->start
+ ctx
->pdata
->res_info
->dram_offset
;
185 ctx
->dram_end
= ctx
->dram_base
+ ctx
->pdata
->res_info
->dram_size
- 1;
186 dev_info(ctx
->dev
, "DRAM base: %#x", ctx
->dram_base
);
187 ctx
->dram
= devm_ioremap_nocache(ctx
->dev
, ctx
->dram_base
,
188 ctx
->pdata
->res_info
->dram_size
);
190 dev_err(ctx
->dev
, "unable to map DRAM\n");
194 ctx
->shim_phy_add
= rsrc
->start
+ ctx
->pdata
->res_info
->shim_offset
;
195 dev_info(ctx
->dev
, "SHIM base: %#x", ctx
->shim_phy_add
);
196 ctx
->shim
= devm_ioremap_nocache(ctx
->dev
, ctx
->shim_phy_add
,
197 ctx
->pdata
->res_info
->shim_size
);
199 dev_err(ctx
->dev
, "unable to map SHIM\n");
203 /* reassign physical address to LPE viewpoint address */
204 ctx
->shim_phy_add
= ctx
->pdata
->res_info
->shim_phy_addr
;
206 /* Get mailbox addr */
207 ctx
->mailbox_add
= rsrc
->start
+ ctx
->pdata
->res_info
->mbox_offset
;
208 dev_info(ctx
->dev
, "Mailbox base: %#x", ctx
->mailbox_add
);
209 ctx
->mailbox
= devm_ioremap_nocache(ctx
->dev
, ctx
->mailbox_add
,
210 ctx
->pdata
->res_info
->mbox_size
);
212 dev_err(ctx
->dev
, "unable to map mailbox\n");
216 /* reassign physical address to LPE viewpoint address */
217 ctx
->mailbox_add
= ctx
->info
.mailbox_start
;
219 rsrc
= platform_get_resource(pdev
, IORESOURCE_MEM
,
220 ctx
->pdata
->res_info
->acpi_ddr_index
);
222 dev_err(ctx
->dev
, "Invalid DDR base from IFWI\n");
225 ctx
->ddr_base
= rsrc
->start
;
226 ctx
->ddr_end
= rsrc
->end
;
227 dev_info(ctx
->dev
, "DDR base: %#x", ctx
->ddr_base
);
228 ctx
->ddr
= devm_ioremap_nocache(ctx
->dev
, ctx
->ddr_base
,
229 resource_size(rsrc
));
231 dev_err(ctx
->dev
, "unable to map DDR\n");
236 ctx
->irq_num
= platform_get_irq(pdev
,
237 ctx
->pdata
->res_info
->acpi_ipc_irq_index
);
242 static int is_byt_cr(struct device
*dev
, bool *bytcr
)
246 if (IS_ENABLED(CONFIG_IOSF_MBI
)) {
247 static const struct x86_cpu_id cpu_ids
[] = {
248 { X86_VENDOR_INTEL
, 6, 55 }, /* Valleyview, Bay Trail */
253 if (!x86_match_cpu(cpu_ids
) || !iosf_mbi_available()) {
258 status
= iosf_mbi_read(BT_MBI_UNIT_PMC
, /* 0x04 PUNIT */
259 MBI_REG_READ
, /* 0x10 */
260 0x006, /* BIOS_CONFIG */
264 dev_err(dev
, "could not read PUNIT BIOS_CONFIG\n");
266 /* bits 26:27 mirror PMIC options */
267 bios_status
= (bios_status
>> 26) & 3;
269 if ((bios_status
== 1) || (bios_status
== 3))
272 dev_info(dev
, "BYT-CR not detected\n");
275 dev_info(dev
, "IOSF_MBI not enabled, no BYT-CR detection\n");
281 static int sst_acpi_probe(struct platform_device
*pdev
)
283 struct device
*dev
= &pdev
->dev
;
285 struct intel_sst_drv
*ctx
;
286 const struct acpi_device_id
*id
;
287 struct snd_soc_acpi_mach
*mach
;
288 struct platform_device
*mdev
;
289 struct platform_device
*plat_dev
;
290 struct sst_platform_info
*pdata
;
294 id
= acpi_match_device(dev
->driver
->acpi_match_table
, dev
);
297 dev_dbg(dev
, "for %s\n", id
->id
);
299 mach
= (struct snd_soc_acpi_mach
*)id
->driver_data
;
300 mach
= snd_soc_acpi_find_machine(mach
);
302 dev_err(dev
, "No matching machine driver found\n");
308 ret
= kstrtouint(id
->id
, 16, &dev_id
);
310 dev_err(dev
, "Unique device id conversion error: %d\n", ret
);
314 dev_dbg(dev
, "ACPI device id: %x\n", dev_id
);
316 ret
= sst_alloc_drv_context(&ctx
, dev
, dev_id
);
320 ret
= is_byt_cr(dev
, &bytcr
);
321 if (!((ret
< 0) || (bytcr
== false))) {
322 dev_info(dev
, "Detected Baytrail-CR platform\n");
324 /* override resource info */
325 byt_rvp_platform_data
.res_info
= &bytcr_res_info
;
328 plat_dev
= platform_device_register_data(dev
, pdata
->platform
, -1,
330 if (IS_ERR(plat_dev
)) {
331 dev_err(dev
, "Failed to create machine device: %s\n",
333 return PTR_ERR(plat_dev
);
337 * Create platform device for sst machine driver,
338 * pass machine info as pdata
340 mdev
= platform_device_register_data(dev
, mach
->drv_name
, -1,
341 (const void *)mach
, sizeof(*mach
));
343 dev_err(dev
, "Failed to create machine device: %s\n",
345 return PTR_ERR(mdev
);
348 /* Fill sst platform data */
350 strcpy(ctx
->firmware_name
, mach
->fw_filename
);
352 ret
= sst_platform_get_resources(ctx
);
356 ret
= sst_context_init(ctx
);
360 sst_configure_runtime_pm(ctx
);
361 platform_set_drvdata(pdev
, ctx
);
366 * intel_sst_remove - remove function
368 * @pdev: platform device structure
370 * This function is called by OS when a device is unloaded
371 * This frees the interrupt etc
373 static int sst_acpi_remove(struct platform_device
*pdev
)
375 struct intel_sst_drv
*ctx
;
377 ctx
= platform_get_drvdata(pdev
);
378 sst_context_cleanup(ctx
);
379 platform_set_drvdata(pdev
, NULL
);
383 static unsigned long cht_machine_id
;
385 #define CHT_SURFACE_MACH 1
386 #define BYT_THINKPAD_10 2
388 static int cht_surface_quirk_cb(const struct dmi_system_id
*id
)
390 cht_machine_id
= CHT_SURFACE_MACH
;
394 static int byt_thinkpad10_quirk_cb(const struct dmi_system_id
*id
)
396 cht_machine_id
= BYT_THINKPAD_10
;
401 static const struct dmi_system_id byt_table
[] = {
403 .callback
= byt_thinkpad10_quirk_cb
,
405 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
406 DMI_MATCH(DMI_PRODUCT_VERSION
, "ThinkPad 10"),
410 .callback
= byt_thinkpad10_quirk_cb
,
412 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
413 DMI_MATCH(DMI_PRODUCT_VERSION
, "ThinkPad Tablet B"),
417 .callback
= byt_thinkpad10_quirk_cb
,
419 DMI_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
420 DMI_MATCH(DMI_PRODUCT_VERSION
, "Lenovo Miix 2 10"),
426 static const struct dmi_system_id cht_table
[] = {
428 .callback
= cht_surface_quirk_cb
,
430 DMI_MATCH(DMI_SYS_VENDOR
, "Microsoft Corporation"),
431 DMI_MATCH(DMI_PRODUCT_NAME
, "Surface 3"),
438 static struct snd_soc_acpi_mach cht_surface_mach
= {
440 .drv_name
= "cht-bsw-rt5645",
441 .fw_filename
= "intel/fw_sst_22a8.bin",
443 .pdata
= &chv_platform_data
,
446 static struct snd_soc_acpi_mach byt_thinkpad_10
= {
448 .drv_name
= "cht-bsw-rt5672",
449 .fw_filename
= "intel/fw_sst_0f28.bin",
451 .pdata
= &byt_rvp_platform_data
,
454 static struct snd_soc_acpi_mach
*cht_quirk(void *arg
)
456 struct snd_soc_acpi_mach
*mach
= arg
;
458 dmi_check_system(cht_table
);
460 if (cht_machine_id
== CHT_SURFACE_MACH
)
461 return &cht_surface_mach
;
466 static struct snd_soc_acpi_mach
*byt_quirk(void *arg
)
468 struct snd_soc_acpi_mach
*mach
= arg
;
470 dmi_check_system(byt_table
);
472 if (cht_machine_id
== BYT_THINKPAD_10
)
473 return &byt_thinkpad_10
;
479 static struct snd_soc_acpi_mach sst_acpi_bytcr
[] = {
482 .drv_name
= "bytcr_rt5640",
483 .fw_filename
= "intel/fw_sst_0f28.bin",
484 .board
= "bytcr_rt5640",
485 .machine_quirk
= byt_quirk
,
486 .pdata
= &byt_rvp_platform_data
,
490 .drv_name
= "bytcr_rt5640",
491 .fw_filename
= "intel/fw_sst_0f28.bin",
492 .board
= "bytcr_rt5640",
493 .pdata
= &byt_rvp_platform_data
497 .drv_name
= "bytcr_rt5640",
498 .fw_filename
= "intel/fw_sst_0f28.bin",
499 .board
= "bytcr_rt5640",
500 .pdata
= &byt_rvp_platform_data
504 .drv_name
= "bytcr_rt5651",
505 .fw_filename
= "intel/fw_sst_0f28.bin",
506 .board
= "bytcr_rt5651",
507 .pdata
= &byt_rvp_platform_data
511 .drv_name
= "bytcht_da7213",
512 .fw_filename
= "intel/fw_sst_0f28.bin",
513 .board
= "bytcht_da7213",
514 .pdata
= &byt_rvp_platform_data
518 .drv_name
= "bytcht_da7213",
519 .fw_filename
= "intel/fw_sst_0f28.bin",
520 .board
= "bytcht_da7213",
521 .pdata
= &byt_rvp_platform_data
523 /* some Baytrail platforms rely on RT5645, use CHT machine driver */
526 .drv_name
= "cht-bsw-rt5645",
527 .fw_filename
= "intel/fw_sst_0f28.bin",
529 .pdata
= &byt_rvp_platform_data
533 .drv_name
= "cht-bsw-rt5645",
534 .fw_filename
= "intel/fw_sst_0f28.bin",
536 .pdata
= &byt_rvp_platform_data
538 /* use CHT driver to Baytrail Chromebooks */
541 .drv_name
= "cht-bsw-max98090",
542 .fw_filename
= "intel/fw_sst_0f28.bin",
544 .pdata
= &byt_rvp_platform_data
546 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
548 * This is always last in the table so that it is selected only when
549 * enabled explicitly and there is no codec-related information in SSDT
553 .drv_name
= "bytcht_nocodec",
554 .fw_filename
= "intel/fw_sst_0f28.bin",
555 .board
= "bytcht_nocodec",
556 .pdata
= &byt_rvp_platform_data
562 /* Cherryview-based platforms: CherryTrail and Braswell */
563 static struct snd_soc_acpi_mach sst_acpi_chv
[] = {
566 .drv_name
= "cht-bsw-rt5672",
567 .fw_filename
= "intel/fw_sst_22a8.bin",
569 .pdata
= &chv_platform_data
573 .drv_name
= "cht-bsw-rt5672",
574 .fw_filename
= "intel/fw_sst_22a8.bin",
576 .pdata
= &chv_platform_data
580 .drv_name
= "cht-bsw-rt5645",
581 .fw_filename
= "intel/fw_sst_22a8.bin",
583 .pdata
= &chv_platform_data
587 .drv_name
= "cht-bsw-rt5645",
588 .fw_filename
= "intel/fw_sst_22a8.bin",
590 .pdata
= &chv_platform_data
594 .drv_name
= "cht-bsw-rt5645",
595 .fw_filename
= "intel/fw_sst_22a8.bin",
597 .pdata
= &chv_platform_data
602 .drv_name
= "cht-bsw-max98090",
603 .fw_filename
= "intel/fw_sst_22a8.bin",
605 .pdata
= &chv_platform_data
609 .drv_name
= "bytcht_da7213",
610 .fw_filename
= "intel/fw_sst_22a8.bin",
611 .board
= "bytcht_da7213",
612 .pdata
= &chv_platform_data
616 .drv_name
= "bytcht_da7213",
617 .fw_filename
= "intel/fw_sst_22a8.bin",
618 .board
= "bytcht_da7213",
619 .pdata
= &chv_platform_data
623 .drv_name
= "bytcht_es8316",
624 .fw_filename
= "intel/fw_sst_22a8.bin",
625 .board
= "bytcht_es8316",
626 .pdata
= &chv_platform_data
628 /* some CHT-T platforms rely on RT5640, use Baytrail machine driver */
631 .drv_name
= "bytcr_rt5640",
632 .fw_filename
= "intel/fw_sst_22a8.bin",
633 .board
= "bytcr_rt5640",
634 .machine_quirk
= cht_quirk
,
635 .pdata
= &chv_platform_data
639 .drv_name
= "bytcr_rt5640",
640 .fw_filename
= "intel/fw_sst_22a8.bin",
641 .board
= "bytcr_rt5640",
642 .pdata
= &chv_platform_data
644 /* some CHT-T platforms rely on RT5651, use Baytrail machine driver */
647 .drv_name
= "bytcr_rt5651",
648 .fw_filename
= "intel/fw_sst_22a8.bin",
649 .board
= "bytcr_rt5651",
650 .pdata
= &chv_platform_data
652 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
654 * This is always last in the table so that it is selected only when
655 * enabled explicitly and there is no codec-related information in SSDT
659 .drv_name
= "bytcht_nocodec",
660 .fw_filename
= "intel/fw_sst_22a8.bin",
661 .board
= "bytcht_nocodec",
662 .pdata
= &chv_platform_data
668 static const struct acpi_device_id sst_acpi_ids
[] = {
669 { "80860F28", (unsigned long)&sst_acpi_bytcr
},
670 { "808622A8", (unsigned long) &sst_acpi_chv
},
674 MODULE_DEVICE_TABLE(acpi
, sst_acpi_ids
);
676 static struct platform_driver sst_acpi_driver
= {
678 .name
= "intel_sst_acpi",
679 .acpi_match_table
= ACPI_PTR(sst_acpi_ids
),
682 .probe
= sst_acpi_probe
,
683 .remove
= sst_acpi_remove
,
686 module_platform_driver(sst_acpi_driver
);
688 MODULE_DESCRIPTION("Intel (R) SST(R) Audio Engine ACPI Driver");
689 MODULE_AUTHOR("Ramesh Babu K V");
690 MODULE_AUTHOR("Omair Mohammed Abdullah");
691 MODULE_LICENSE("GPL v2");