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