xref: /linux/sound/soc/sof/intel/pci-tng.c (revision d27656d02d85078c63f060fca9c5d99794791a75)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // This file is provided under a dual BSD/GPLv2 license.  When using or
4 // redistributing this file, you may do so under either license.
5 //
6 // Copyright(c) 2018-2021 Intel Corporation. All rights reserved.
7 //
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9 //
10 
11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <sound/soc-acpi.h>
14 #include <sound/soc-acpi-intel-match.h>
15 #include <sound/sof.h>
16 #include "../ops.h"
17 #include "atom.h"
18 #include "../sof-pci-dev.h"
19 #include "../sof-audio.h"
20 
21 /* platform specific devices */
22 #include "shim.h"
23 
24 static struct snd_soc_acpi_mach sof_tng_machines[] = {
25 	{
26 		.id = "INT343A",
27 		.drv_name = "edison",
28 		.sof_fw_filename = "sof-byt.ri",
29 		.sof_tplg_filename = "sof-byt.tplg",
30 	},
31 	{}
32 };
33 
34 static const struct snd_sof_debugfs_map tng_debugfs[] = {
35 	{"dmac0", DSP_BAR, DMAC0_OFFSET, DMAC_SIZE,
36 	 SOF_DEBUGFS_ACCESS_ALWAYS},
37 	{"dmac1", DSP_BAR, DMAC1_OFFSET, DMAC_SIZE,
38 	 SOF_DEBUGFS_ACCESS_ALWAYS},
39 	{"ssp0", DSP_BAR, SSP0_OFFSET, SSP_SIZE,
40 	 SOF_DEBUGFS_ACCESS_ALWAYS},
41 	{"ssp1", DSP_BAR, SSP1_OFFSET, SSP_SIZE,
42 	 SOF_DEBUGFS_ACCESS_ALWAYS},
43 	{"ssp2", DSP_BAR, SSP2_OFFSET, SSP_SIZE,
44 	 SOF_DEBUGFS_ACCESS_ALWAYS},
45 	{"iram", DSP_BAR, IRAM_OFFSET, IRAM_SIZE,
46 	 SOF_DEBUGFS_ACCESS_D0_ONLY},
47 	{"dram", DSP_BAR, DRAM_OFFSET, DRAM_SIZE,
48 	 SOF_DEBUGFS_ACCESS_D0_ONLY},
49 	{"shim", DSP_BAR, SHIM_OFFSET, SHIM_SIZE_BYT,
50 	 SOF_DEBUGFS_ACCESS_ALWAYS},
51 };
52 
53 static int tangier_pci_probe(struct snd_sof_dev *sdev)
54 {
55 	struct snd_sof_pdata *pdata = sdev->pdata;
56 	const struct sof_dev_desc *desc = pdata->desc;
57 	struct pci_dev *pci = to_pci_dev(sdev->dev);
58 	const struct sof_intel_dsp_desc *chip;
59 	u32 base, size;
60 	int ret;
61 
62 	chip = get_chip_info(sdev->pdata);
63 	if (!chip) {
64 		dev_err(sdev->dev, "error: no such device supported\n");
65 		return -EIO;
66 	}
67 
68 	sdev->num_cores = chip->cores_num;
69 
70 	/* DSP DMA can only access low 31 bits of host memory */
71 	ret = dma_coerce_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31));
72 	if (ret < 0) {
73 		dev_err(sdev->dev, "error: failed to set DMA mask %d\n", ret);
74 		return ret;
75 	}
76 
77 	/* LPE base */
78 	base = pci_resource_start(pci, desc->resindex_lpe_base) - IRAM_OFFSET;
79 	size = PCI_BAR_SIZE;
80 
81 	dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size);
82 	sdev->bar[DSP_BAR] = devm_ioremap(sdev->dev, base, size);
83 	if (!sdev->bar[DSP_BAR]) {
84 		dev_err(sdev->dev, "error: failed to ioremap LPE base 0x%x size 0x%x\n",
85 			base, size);
86 		return -ENODEV;
87 	}
88 	dev_dbg(sdev->dev, "LPE VADDR %p\n", sdev->bar[DSP_BAR]);
89 
90 	/* IMR base - optional */
91 	if (desc->resindex_imr_base == -1)
92 		goto irq;
93 
94 	base = pci_resource_start(pci, desc->resindex_imr_base);
95 	size = pci_resource_len(pci, desc->resindex_imr_base);
96 
97 	/* some BIOSes don't map IMR */
98 	if (base == 0x55aa55aa || base == 0x0) {
99 		dev_info(sdev->dev, "IMR not set by BIOS. Ignoring\n");
100 		goto irq;
101 	}
102 
103 	dev_dbg(sdev->dev, "IMR base at 0x%x size 0x%x", base, size);
104 	sdev->bar[IMR_BAR] = devm_ioremap(sdev->dev, base, size);
105 	if (!sdev->bar[IMR_BAR]) {
106 		dev_err(sdev->dev, "error: failed to ioremap IMR base 0x%x size 0x%x\n",
107 			base, size);
108 		return -ENODEV;
109 	}
110 	dev_dbg(sdev->dev, "IMR VADDR %p\n", sdev->bar[IMR_BAR]);
111 
112 irq:
113 	/* register our IRQ */
114 	sdev->ipc_irq = pci->irq;
115 	dev_dbg(sdev->dev, "using IRQ %d\n", sdev->ipc_irq);
116 	ret = devm_request_threaded_irq(sdev->dev, sdev->ipc_irq,
117 					atom_irq_handler, atom_irq_thread,
118 					0, "AudioDSP", sdev);
119 	if (ret < 0) {
120 		dev_err(sdev->dev, "error: failed to register IRQ %d\n",
121 			sdev->ipc_irq);
122 		return ret;
123 	}
124 
125 	/* enable BUSY and disable DONE Interrupt by default */
126 	snd_sof_dsp_update_bits64(sdev, DSP_BAR, SHIM_IMRX,
127 				  SHIM_IMRX_BUSY | SHIM_IMRX_DONE,
128 				  SHIM_IMRX_DONE);
129 
130 	/* set default mailbox offset for FW ready message */
131 	sdev->dsp_box.offset = MBOX_OFFSET;
132 
133 	return ret;
134 }
135 
136 const struct snd_sof_dsp_ops sof_tng_ops = {
137 	/* device init */
138 	.probe		= tangier_pci_probe,
139 
140 	/* DSP core boot / reset */
141 	.run		= atom_run,
142 	.reset		= atom_reset,
143 
144 	/* Register IO */
145 	.write		= sof_io_write,
146 	.read		= sof_io_read,
147 	.write64	= sof_io_write64,
148 	.read64		= sof_io_read64,
149 
150 	/* Block IO */
151 	.block_read	= sof_block_read,
152 	.block_write	= sof_block_write,
153 
154 	/* Mailbox IO */
155 	.mailbox_read	= sof_mailbox_read,
156 	.mailbox_write	= sof_mailbox_write,
157 
158 	/* doorbell */
159 	.irq_handler	= atom_irq_handler,
160 	.irq_thread	= atom_irq_thread,
161 
162 	/* ipc */
163 	.send_msg	= atom_send_msg,
164 	.fw_ready	= sof_fw_ready,
165 	.get_mailbox_offset = atom_get_mailbox_offset,
166 	.get_window_offset = atom_get_window_offset,
167 
168 	.ipc_msg_data	= sof_ipc_msg_data,
169 	.ipc_pcm_params	= sof_ipc_pcm_params,
170 
171 	/* machine driver */
172 	.machine_select = atom_machine_select,
173 	.machine_register = sof_machine_register,
174 	.machine_unregister = sof_machine_unregister,
175 	.set_mach_params = atom_set_mach_params,
176 
177 	/* debug */
178 	.debug_map	= tng_debugfs,
179 	.debug_map_count	= ARRAY_SIZE(tng_debugfs),
180 	.dbg_dump	= atom_dump,
181 	.debugfs_add_region_item = snd_sof_debugfs_add_region_item_iomem,
182 
183 	/* stream callbacks */
184 	.pcm_open	= sof_stream_pcm_open,
185 	.pcm_close	= sof_stream_pcm_close,
186 
187 	/* module loading */
188 	.load_module	= snd_sof_parse_module_memcpy,
189 
190 	/*Firmware loading */
191 	.load_firmware	= snd_sof_load_firmware_memcpy,
192 
193 	/* DAI drivers */
194 	.drv = atom_dai,
195 	.num_drv = 3, /* we have only 3 SSPs on byt*/
196 
197 	/* ALSA HW info flags */
198 	.hw_info =	SNDRV_PCM_INFO_MMAP |
199 			SNDRV_PCM_INFO_MMAP_VALID |
200 			SNDRV_PCM_INFO_INTERLEAVED |
201 			SNDRV_PCM_INFO_PAUSE |
202 			SNDRV_PCM_INFO_BATCH,
203 
204 	.dsp_arch_ops = &sof_xtensa_arch_ops,
205 };
206 
207 const struct sof_intel_dsp_desc tng_chip_info = {
208 	.cores_num = 1,
209 	.host_managed_cores_mask = 1,
210 };
211 
212 static const struct sof_dev_desc tng_desc = {
213 	.machines		= sof_tng_machines,
214 	.resindex_lpe_base	= 3,	/* IRAM, but subtract IRAM offset */
215 	.resindex_pcicfg_base	= -1,
216 	.resindex_imr_base	= 0,
217 	.irqindex_host_ipc	= -1,
218 	.chip_info = &tng_chip_info,
219 	.default_fw_path = "intel/sof",
220 	.default_tplg_path = "intel/sof-tplg",
221 	.default_fw_filename = "sof-byt.ri",
222 	.nocodec_tplg_filename = "sof-byt.tplg",
223 	.ops = &sof_tng_ops,
224 };
225 
226 /* PCI IDs */
227 static const struct pci_device_id sof_pci_ids[] = {
228 	{ PCI_DEVICE(0x8086, 0x119a),
229 		.driver_data = (unsigned long)&tng_desc},
230 	{ 0, }
231 };
232 MODULE_DEVICE_TABLE(pci, sof_pci_ids);
233 
234 /* pci_driver definition */
235 static struct pci_driver snd_sof_pci_intel_tng_driver = {
236 	.name = "sof-audio-pci-intel-tng",
237 	.id_table = sof_pci_ids,
238 	.probe = sof_pci_probe,
239 	.remove = sof_pci_remove,
240 	.shutdown = sof_pci_shutdown,
241 	.driver = {
242 		.pm = &sof_pci_pm,
243 	},
244 };
245 module_pci_driver(snd_sof_pci_intel_tng_driver);
246 
247 MODULE_LICENSE("Dual BSD/GPL");
248 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HIFI_EP_IPC);
249 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
250 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);
251 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_ATOM_HIFI_EP);
252