]>
Commit | Line | Data |
---|---|---|
d8c2dab8 JK |
1 | /* |
2 | * skl.c - Implementation of ASoC Intel SKL HD Audio driver | |
3 | * | |
4 | * Copyright (C) 2014-2015 Intel Corp | |
5 | * Author: Jeeja KP <jeeja.kp@intel.com> | |
6 | * | |
7 | * Derived mostly from Intel HDA driver with following copyrights: | |
8 | * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de> | |
9 | * PeiSen Hou <pshou@realtek.com.tw> | |
10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; version 2 of the License. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | * | |
21 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
22 | */ | |
23 | ||
24 | #include <linux/module.h> | |
25 | #include <linux/pci.h> | |
26 | #include <linux/pm_runtime.h> | |
27 | #include <linux/platform_device.h> | |
d8018361 | 28 | #include <linux/firmware.h> |
a26a3f53 | 29 | #include <linux/delay.h> |
d8c2dab8 | 30 | #include <sound/pcm.h> |
7feb2f78 | 31 | #include <sound/soc-acpi.h> |
cbaa7f0b | 32 | #include <sound/soc-acpi-intel-match.h> |
6980c057 VK |
33 | #include <sound/hda_register.h> |
34 | #include <sound/hdaudio.h> | |
35 | #include <sound/hda_i915.h> | |
00deadb5 | 36 | #include <sound/hda_codec.h> |
d8c2dab8 | 37 | #include "skl.h" |
0c8ba9d2 J |
38 | #include "skl-sst-dsp.h" |
39 | #include "skl-sst-ipc.h" | |
8c4e7c2e | 40 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) |
6bae5ea9 | 41 | #include "../../../soc/codecs/hdac_hda.h" |
8c4e7c2e | 42 | #endif |
d82b51c8 PLB |
43 | static int skl_pci_binding; |
44 | module_param_named(pci_binding, skl_pci_binding, int, 0444); | |
45 | MODULE_PARM_DESC(pci_binding, "PCI binding (0=auto, 1=only legacy, 2=only asoc"); | |
d8c2dab8 JK |
46 | |
47 | /* | |
48 | * initialize the PCI registers | |
49 | */ | |
50 | static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg, | |
51 | unsigned char mask, unsigned char val) | |
52 | { | |
53 | unsigned char data; | |
54 | ||
55 | pci_read_config_byte(pci, reg, &data); | |
56 | data &= ~mask; | |
57 | data |= (val & mask); | |
58 | pci_write_config_byte(pci, reg, data); | |
59 | } | |
60 | ||
61 | static void skl_init_pci(struct skl *skl) | |
62 | { | |
76f56fae | 63 | struct hdac_bus *bus = skl_to_bus(skl); |
d8c2dab8 JK |
64 | |
65 | /* | |
66 | * Clear bits 0-2 of PCI register TCSEL (at offset 0x44) | |
67 | * TCSEL == Traffic Class Select Register, which sets PCI express QOS | |
68 | * Ensuring these bits are 0 clears playback static on some HD Audio | |
69 | * codecs. | |
70 | * The PCI register TCSEL is defined in the Intel manuals. | |
71 | */ | |
76f56fae | 72 | dev_dbg(bus->dev, "Clearing TCSEL\n"); |
d8c2dab8 JK |
73 | skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0); |
74 | } | |
75 | ||
0c8ba9d2 J |
76 | static void update_pci_dword(struct pci_dev *pci, |
77 | unsigned int reg, u32 mask, u32 val) | |
78 | { | |
79 | u32 data = 0; | |
80 | ||
81 | pci_read_config_dword(pci, reg, &data); | |
82 | data &= ~mask; | |
83 | data |= (val & mask); | |
84 | pci_write_config_dword(pci, reg, data); | |
85 | } | |
86 | ||
87 | /* | |
88 | * skl_enable_miscbdcge - enable/dsiable CGCTL.MISCBDCGE bits | |
89 | * | |
90 | * @dev: device pointer | |
91 | * @enable: enable/disable flag | |
92 | */ | |
93 | static void skl_enable_miscbdcge(struct device *dev, bool enable) | |
94 | { | |
95 | struct pci_dev *pci = to_pci_dev(dev); | |
96 | u32 val; | |
97 | ||
98 | val = enable ? AZX_CGCTL_MISCBDCGE_MASK : 0; | |
99 | ||
100 | update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_MISCBDCGE_MASK, val); | |
101 | } | |
102 | ||
fc9fdd61 SK |
103 | /** |
104 | * skl_clock_power_gating: Enable/Disable clock and power gating | |
105 | * | |
106 | * @dev: Device pointer | |
107 | * @enable: Enable/Disable flag | |
108 | */ | |
109 | static void skl_clock_power_gating(struct device *dev, bool enable) | |
110 | { | |
111 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae | 112 | struct hdac_bus *bus = pci_get_drvdata(pci); |
fc9fdd61 SK |
113 | u32 val; |
114 | ||
115 | /* Update PDCGE bit of CGCTL register */ | |
116 | val = enable ? AZX_CGCTL_ADSPDCGE : 0; | |
117 | update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_ADSPDCGE, val); | |
118 | ||
119 | /* Update L1SEN bit of EM2 register */ | |
120 | val = enable ? AZX_REG_VS_EM2_L1SEN : 0; | |
121 | snd_hdac_chip_updatel(bus, VS_EM2, AZX_REG_VS_EM2_L1SEN, val); | |
122 | ||
123 | /* Update ADSPPGD bit of PGCTL register */ | |
124 | val = enable ? 0 : AZX_PGCTL_ADSPPGD; | |
125 | update_pci_dword(pci, AZX_PCIREG_PGCTL, AZX_PGCTL_ADSPPGD, val); | |
126 | } | |
127 | ||
0c8ba9d2 J |
128 | /* |
129 | * While performing reset, controller may not come back properly causing | |
130 | * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset | |
131 | * (init chip) and then again set CGCTL.MISCBDCGE to 1 | |
132 | */ | |
133 | static int skl_init_chip(struct hdac_bus *bus, bool full_reset) | |
134 | { | |
112c60b3 | 135 | struct hdac_ext_link *hlink; |
0c8ba9d2 J |
136 | int ret; |
137 | ||
138 | skl_enable_miscbdcge(bus->dev, false); | |
139 | ret = snd_hdac_bus_init_chip(bus, full_reset); | |
112c60b3 RU |
140 | |
141 | /* Reset stream-to-link mapping */ | |
76f56fae | 142 | list_for_each_entry(hlink, &bus->hlink_list, list) |
112c60b3 RU |
143 | bus->io_ops->reg_writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV); |
144 | ||
0c8ba9d2 J |
145 | skl_enable_miscbdcge(bus->dev, true); |
146 | ||
147 | return ret; | |
148 | } | |
149 | ||
a26a3f53 PS |
150 | void skl_update_d0i3c(struct device *dev, bool enable) |
151 | { | |
152 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae | 153 | struct hdac_bus *bus = pci_get_drvdata(pci); |
a26a3f53 PS |
154 | u8 reg; |
155 | int timeout = 50; | |
156 | ||
157 | reg = snd_hdac_chip_readb(bus, VS_D0I3C); | |
158 | /* Do not write to D0I3C until command in progress bit is cleared */ | |
159 | while ((reg & AZX_REG_VS_D0I3C_CIP) && --timeout) { | |
160 | udelay(10); | |
161 | reg = snd_hdac_chip_readb(bus, VS_D0I3C); | |
162 | } | |
163 | ||
164 | /* Highly unlikely. But if it happens, flag error explicitly */ | |
165 | if (!timeout) { | |
166 | dev_err(bus->dev, "Before D0I3C update: D0I3C CIP timeout\n"); | |
167 | return; | |
168 | } | |
169 | ||
170 | if (enable) | |
171 | reg = reg | AZX_REG_VS_D0I3C_I3; | |
172 | else | |
173 | reg = reg & (~AZX_REG_VS_D0I3C_I3); | |
174 | ||
175 | snd_hdac_chip_writeb(bus, VS_D0I3C, reg); | |
176 | ||
177 | timeout = 50; | |
178 | /* Wait for cmd in progress to be cleared before exiting the function */ | |
179 | reg = snd_hdac_chip_readb(bus, VS_D0I3C); | |
180 | while ((reg & AZX_REG_VS_D0I3C_CIP) && --timeout) { | |
181 | udelay(10); | |
182 | reg = snd_hdac_chip_readb(bus, VS_D0I3C); | |
183 | } | |
184 | ||
185 | /* Highly unlikely. But if it happens, flag error explicitly */ | |
186 | if (!timeout) { | |
187 | dev_err(bus->dev, "After D0I3C update: D0I3C CIP timeout\n"); | |
188 | return; | |
189 | } | |
190 | ||
191 | dev_dbg(bus->dev, "D0I3C register = 0x%x\n", | |
192 | snd_hdac_chip_readb(bus, VS_D0I3C)); | |
193 | } | |
194 | ||
d8c2dab8 JK |
195 | /* called from IRQ */ |
196 | static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr) | |
197 | { | |
198 | snd_pcm_period_elapsed(hstr->substream); | |
199 | } | |
200 | ||
201 | static irqreturn_t skl_interrupt(int irq, void *dev_id) | |
202 | { | |
76f56fae | 203 | struct hdac_bus *bus = dev_id; |
d8c2dab8 JK |
204 | u32 status; |
205 | ||
206 | if (!pm_runtime_active(bus->dev)) | |
207 | return IRQ_NONE; | |
208 | ||
209 | spin_lock(&bus->reg_lock); | |
210 | ||
211 | status = snd_hdac_chip_readl(bus, INTSTS); | |
212 | if (status == 0 || status == 0xffffffff) { | |
213 | spin_unlock(&bus->reg_lock); | |
214 | return IRQ_NONE; | |
215 | } | |
216 | ||
217 | /* clear rirb int */ | |
218 | status = snd_hdac_chip_readb(bus, RIRBSTS); | |
219 | if (status & RIRB_INT_MASK) { | |
220 | if (status & RIRB_INT_RESPONSE) | |
221 | snd_hdac_bus_update_rirb(bus); | |
222 | snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK); | |
223 | } | |
224 | ||
225 | spin_unlock(&bus->reg_lock); | |
226 | ||
227 | return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED; | |
228 | } | |
229 | ||
230 | static irqreturn_t skl_threaded_handler(int irq, void *dev_id) | |
231 | { | |
76f56fae | 232 | struct hdac_bus *bus = dev_id; |
d8c2dab8 JK |
233 | u32 status; |
234 | ||
235 | status = snd_hdac_chip_readl(bus, INTSTS); | |
236 | ||
237 | snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update); | |
238 | ||
239 | return IRQ_HANDLED; | |
240 | } | |
241 | ||
76f56fae | 242 | static int skl_acquire_irq(struct hdac_bus *bus, int do_disconnect) |
d8c2dab8 | 243 | { |
76f56fae | 244 | struct skl *skl = bus_to_skl(bus); |
d8c2dab8 JK |
245 | int ret; |
246 | ||
247 | ret = request_threaded_irq(skl->pci->irq, skl_interrupt, | |
248 | skl_threaded_handler, | |
249 | IRQF_SHARED, | |
76f56fae | 250 | KBUILD_MODNAME, bus); |
d8c2dab8 JK |
251 | if (ret) { |
252 | dev_err(bus->dev, | |
253 | "unable to grab IRQ %d, disabling device\n", | |
254 | skl->pci->irq); | |
255 | return ret; | |
256 | } | |
257 | ||
258 | bus->irq = skl->pci->irq; | |
259 | pci_intx(skl->pci, 1); | |
260 | ||
261 | return 0; | |
262 | } | |
263 | ||
8b4a133c J |
264 | static int skl_suspend_late(struct device *dev) |
265 | { | |
266 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae RU |
267 | struct hdac_bus *bus = pci_get_drvdata(pci); |
268 | struct skl *skl = bus_to_skl(bus); | |
8b4a133c J |
269 | |
270 | return skl_suspend_late_dsp(skl); | |
271 | } | |
272 | ||
61722f44 | 273 | #ifdef CONFIG_PM |
76f56fae | 274 | static int _skl_suspend(struct hdac_bus *bus) |
61722f44 | 275 | { |
76f56fae | 276 | struct skl *skl = bus_to_skl(bus); |
51a01b8c | 277 | struct pci_dev *pci = to_pci_dev(bus->dev); |
61722f44 JK |
278 | int ret; |
279 | ||
76f56fae | 280 | snd_hdac_ext_bus_link_power_down_all(bus); |
61722f44 JK |
281 | |
282 | ret = skl_suspend_dsp(skl); | |
283 | if (ret < 0) | |
284 | return ret; | |
285 | ||
286 | snd_hdac_bus_stop_chip(bus); | |
51a01b8c D |
287 | update_pci_dword(pci, AZX_PCIREG_PGCTL, |
288 | AZX_PGCTL_LSRMD_MASK, AZX_PGCTL_LSRMD_MASK); | |
0c8ba9d2 | 289 | skl_enable_miscbdcge(bus->dev, false); |
61722f44 | 290 | snd_hdac_bus_enter_link_reset(bus); |
0c8ba9d2 | 291 | skl_enable_miscbdcge(bus->dev, true); |
fe3f4442 | 292 | skl_cleanup_resources(skl); |
61722f44 JK |
293 | |
294 | return 0; | |
295 | } | |
296 | ||
76f56fae | 297 | static int _skl_resume(struct hdac_bus *bus) |
61722f44 | 298 | { |
76f56fae | 299 | struct skl *skl = bus_to_skl(bus); |
61722f44 JK |
300 | |
301 | skl_init_pci(skl); | |
0c8ba9d2 | 302 | skl_init_chip(bus, true); |
61722f44 JK |
303 | |
304 | return skl_resume_dsp(skl); | |
305 | } | |
306 | #endif | |
307 | ||
d8c2dab8 JK |
308 | #ifdef CONFIG_PM_SLEEP |
309 | /* | |
310 | * power management | |
311 | */ | |
312 | static int skl_suspend(struct device *dev) | |
313 | { | |
314 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae RU |
315 | struct hdac_bus *bus = pci_get_drvdata(pci); |
316 | struct skl *skl = bus_to_skl(bus); | |
4f799e73 | 317 | int ret; |
d8c2dab8 | 318 | |
4557c305 JK |
319 | /* |
320 | * Do not suspend if streams which are marked ignore suspend are | |
321 | * running, we need to save the state for these and continue | |
322 | */ | |
323 | if (skl->supend_active) { | |
cce6c149 | 324 | /* turn off the links and stop the CORB/RIRB DMA if it is On */ |
76f56fae | 325 | snd_hdac_ext_bus_link_power_down_all(bus); |
cce6c149 | 326 | |
76f56fae RU |
327 | if (bus->cmd_dma_state) |
328 | snd_hdac_bus_stop_cmd_io(bus); | |
cce6c149 | 329 | |
1f4956fd | 330 | enable_irq_wake(bus->irq); |
4557c305 | 331 | pci_save_state(pci); |
4557c305 | 332 | } else { |
76f56fae | 333 | ret = _skl_suspend(bus); |
af037412 SP |
334 | if (ret < 0) |
335 | return ret; | |
1665c177 | 336 | skl->skl_sst->fw_loaded = false; |
4557c305 | 337 | } |
af037412 | 338 | |
4f799e73 | 339 | return 0; |
d8c2dab8 JK |
340 | } |
341 | ||
342 | static int skl_resume(struct device *dev) | |
343 | { | |
344 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae RU |
345 | struct hdac_bus *bus = pci_get_drvdata(pci); |
346 | struct skl *skl = bus_to_skl(bus); | |
cce6c149 | 347 | struct hdac_ext_link *hlink = NULL; |
4557c305 JK |
348 | int ret; |
349 | ||
350 | /* | |
351 | * resume only when we are not in suspend active, otherwise need to | |
352 | * restore the device | |
353 | */ | |
354 | if (skl->supend_active) { | |
355 | pci_restore_state(pci); | |
76f56fae | 356 | snd_hdac_ext_bus_link_power_up_all(bus); |
1f4956fd | 357 | disable_irq_wake(bus->irq); |
cce6c149 VK |
358 | /* |
359 | * turn On the links which are On before active suspend | |
360 | * and start the CORB/RIRB DMA if On before | |
361 | * active suspend. | |
362 | */ | |
76f56fae | 363 | list_for_each_entry(hlink, &bus->hlink_list, list) { |
cce6c149 VK |
364 | if (hlink->ref_count) |
365 | snd_hdac_ext_bus_link_power_up(hlink); | |
366 | } | |
367 | ||
cc20c4df | 368 | ret = 0; |
76f56fae RU |
369 | if (bus->cmd_dma_state) |
370 | snd_hdac_bus_init_cmd_io(bus); | |
4557c305 | 371 | } else { |
76f56fae | 372 | ret = _skl_resume(bus); |
cce6c149 VK |
373 | |
374 | /* turn off the links which are off before suspend */ | |
76f56fae | 375 | list_for_each_entry(hlink, &bus->hlink_list, list) { |
cce6c149 VK |
376 | if (!hlink->ref_count) |
377 | snd_hdac_ext_bus_link_power_down(hlink); | |
378 | } | |
379 | ||
76f56fae RU |
380 | if (!bus->cmd_dma_state) |
381 | snd_hdac_bus_stop_cmd_io(bus); | |
4557c305 | 382 | } |
d8c2dab8 | 383 | |
4557c305 | 384 | return ret; |
d8c2dab8 JK |
385 | } |
386 | #endif /* CONFIG_PM_SLEEP */ | |
387 | ||
388 | #ifdef CONFIG_PM | |
389 | static int skl_runtime_suspend(struct device *dev) | |
390 | { | |
391 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae | 392 | struct hdac_bus *bus = pci_get_drvdata(pci); |
d8c2dab8 JK |
393 | |
394 | dev_dbg(bus->dev, "in %s\n", __func__); | |
395 | ||
76f56fae | 396 | return _skl_suspend(bus); |
d8c2dab8 JK |
397 | } |
398 | ||
399 | static int skl_runtime_resume(struct device *dev) | |
400 | { | |
401 | struct pci_dev *pci = to_pci_dev(dev); | |
76f56fae | 402 | struct hdac_bus *bus = pci_get_drvdata(pci); |
d8c2dab8 JK |
403 | |
404 | dev_dbg(bus->dev, "in %s\n", __func__); | |
405 | ||
76f56fae | 406 | return _skl_resume(bus); |
d8c2dab8 JK |
407 | } |
408 | #endif /* CONFIG_PM */ | |
409 | ||
410 | static const struct dev_pm_ops skl_pm = { | |
411 | SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume) | |
412 | SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL) | |
8b4a133c | 413 | .suspend_late = skl_suspend_late, |
d8c2dab8 JK |
414 | }; |
415 | ||
416 | /* | |
417 | * destructor | |
418 | */ | |
76f56fae | 419 | static int skl_free(struct hdac_bus *bus) |
d8c2dab8 | 420 | { |
76f56fae | 421 | struct skl *skl = bus_to_skl(bus); |
d8c2dab8 | 422 | |
ab1b732d | 423 | skl->init_done = 0; /* to be sure */ |
d8c2dab8 | 424 | |
76f56fae | 425 | snd_hdac_ext_stop_streams(bus); |
d8c2dab8 JK |
426 | |
427 | if (bus->irq >= 0) | |
76f56fae | 428 | free_irq(bus->irq, (void *)bus); |
d8c2dab8 | 429 | snd_hdac_bus_free_stream_pages(bus); |
76f56fae RU |
430 | snd_hdac_stream_free_all(bus); |
431 | snd_hdac_link_free_all(bus); | |
077411e5 VK |
432 | |
433 | if (bus->remap_addr) | |
434 | iounmap(bus->remap_addr); | |
435 | ||
d8c2dab8 JK |
436 | pci_release_regions(skl->pci); |
437 | pci_disable_device(skl->pci); | |
438 | ||
76f56fae | 439 | snd_hdac_ext_bus_exit(bus); |
d8c2dab8 | 440 | |
ab1b732d | 441 | cancel_work_sync(&skl->probe_work); |
687ae9e2 TI |
442 | if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) { |
443 | snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false); | |
76f56fae | 444 | snd_hdac_i915_exit(bus); |
687ae9e2 | 445 | } |
ab1b732d | 446 | |
d8c2dab8 JK |
447 | return 0; |
448 | } | |
449 | ||
bc2bd45b SP |
450 | /* |
451 | * For each ssp there are 3 clocks (mclk/sclk/sclkfs). | |
452 | * e.g. for ssp0, clocks will be named as | |
453 | * "ssp0_mclk", "ssp0_sclk", "ssp0_sclkfs" | |
454 | * So for skl+, there are 6 ssps, so 18 clocks will be created. | |
455 | */ | |
456 | static struct skl_ssp_clk skl_ssp_clks[] = { | |
457 | {.name = "ssp0_mclk"}, {.name = "ssp1_mclk"}, {.name = "ssp2_mclk"}, | |
458 | {.name = "ssp3_mclk"}, {.name = "ssp4_mclk"}, {.name = "ssp5_mclk"}, | |
459 | {.name = "ssp0_sclk"}, {.name = "ssp1_sclk"}, {.name = "ssp2_sclk"}, | |
460 | {.name = "ssp3_sclk"}, {.name = "ssp4_sclk"}, {.name = "ssp5_sclk"}, | |
461 | {.name = "ssp0_sclkfs"}, {.name = "ssp1_sclkfs"}, | |
462 | {.name = "ssp2_sclkfs"}, | |
463 | {.name = "ssp3_sclkfs"}, {.name = "ssp4_sclkfs"}, | |
464 | {.name = "ssp5_sclkfs"}, | |
465 | }; | |
466 | ||
9cdae435 RU |
467 | static struct snd_soc_acpi_mach *skl_find_hda_machine(struct skl *skl, |
468 | struct snd_soc_acpi_mach *machines) | |
469 | { | |
470 | struct hdac_bus *bus = skl_to_bus(skl); | |
471 | struct snd_soc_acpi_mach *mach; | |
472 | ||
473 | /* check if we have any codecs detected on bus */ | |
474 | if (bus->codec_mask == 0) | |
475 | return NULL; | |
476 | ||
477 | /* point to common table */ | |
478 | mach = snd_soc_acpi_intel_hda_machines; | |
479 | ||
480 | /* all entries in the machine table use the same firmware */ | |
481 | mach->fw_filename = machines->fw_filename; | |
482 | ||
483 | return mach; | |
484 | } | |
485 | ||
752c93aa | 486 | static int skl_find_machine(struct skl *skl, void *driver_data) |
cc18c5fd | 487 | { |
76f56fae | 488 | struct hdac_bus *bus = skl_to_bus(skl); |
7feb2f78 | 489 | struct snd_soc_acpi_mach *mach = driver_data; |
752c93aa | 490 | struct skl_machine_pdata *pdata; |
cc18c5fd | 491 | |
7feb2f78 | 492 | mach = snd_soc_acpi_find_machine(mach); |
9cdae435 RU |
493 | if (!mach) { |
494 | dev_dbg(bus->dev, "No matching I2S machine driver found\n"); | |
495 | mach = skl_find_hda_machine(skl, driver_data); | |
496 | if (!mach) { | |
497 | dev_err(bus->dev, "No matching machine driver found\n"); | |
498 | return -ENODEV; | |
499 | } | |
cc18c5fd | 500 | } |
752c93aa PB |
501 | |
502 | skl->mach = mach; | |
aecf6fd8 | 503 | skl->fw_name = mach->fw_filename; |
5f15f267 | 504 | pdata = mach->pdata; |
752c93aa | 505 | |
5f15f267 | 506 | if (pdata) { |
752c93aa | 507 | skl->use_tplg_pcm = pdata->use_tplg_pcm; |
b92826fa | 508 | mach->mach_params.dmic_num = skl_get_dmic_geo(skl); |
5f15f267 | 509 | } |
752c93aa PB |
510 | |
511 | return 0; | |
512 | } | |
513 | ||
514 | static int skl_machine_device_register(struct skl *skl) | |
515 | { | |
752c93aa | 516 | struct snd_soc_acpi_mach *mach = skl->mach; |
9cdae435 | 517 | struct hdac_bus *bus = skl_to_bus(skl); |
752c93aa PB |
518 | struct platform_device *pdev; |
519 | int ret; | |
cc18c5fd VK |
520 | |
521 | pdev = platform_device_alloc(mach->drv_name, -1); | |
522 | if (pdev == NULL) { | |
523 | dev_err(bus->dev, "platform device alloc failed\n"); | |
524 | return -EIO; | |
525 | } | |
526 | ||
5a619b9e PLB |
527 | mach->mach_params.platform = dev_name(bus->dev); |
528 | mach->mach_params.codec_mask = bus->codec_mask; | |
529 | ||
530 | ret = platform_device_add_data(pdev, (const void *)mach, sizeof(*mach)); | |
531 | if (ret) { | |
532 | dev_err(bus->dev, "failed to add machine device platform data\n"); | |
533 | platform_device_put(pdev); | |
534 | return ret; | |
535 | } | |
536 | ||
cc18c5fd VK |
537 | ret = platform_device_add(pdev); |
538 | if (ret) { | |
539 | dev_err(bus->dev, "failed to add machine device\n"); | |
540 | platform_device_put(pdev); | |
541 | return -EIO; | |
542 | } | |
f65cf7d6 | 543 | |
f65cf7d6 | 544 | |
cc18c5fd VK |
545 | skl->i2s_dev = pdev; |
546 | ||
547 | return 0; | |
548 | } | |
549 | ||
550 | static void skl_machine_device_unregister(struct skl *skl) | |
551 | { | |
552 | if (skl->i2s_dev) | |
553 | platform_device_unregister(skl->i2s_dev); | |
554 | } | |
555 | ||
d8c2dab8 JK |
556 | static int skl_dmic_device_register(struct skl *skl) |
557 | { | |
76f56fae | 558 | struct hdac_bus *bus = skl_to_bus(skl); |
d8c2dab8 JK |
559 | struct platform_device *pdev; |
560 | int ret; | |
561 | ||
562 | /* SKL has one dmic port, so allocate dmic device for this */ | |
563 | pdev = platform_device_alloc("dmic-codec", -1); | |
564 | if (!pdev) { | |
565 | dev_err(bus->dev, "failed to allocate dmic device\n"); | |
566 | return -ENOMEM; | |
567 | } | |
568 | ||
569 | ret = platform_device_add(pdev); | |
570 | if (ret) { | |
571 | dev_err(bus->dev, "failed to add dmic device: %d\n", ret); | |
572 | platform_device_put(pdev); | |
573 | return ret; | |
574 | } | |
575 | skl->dmic_dev = pdev; | |
576 | ||
577 | return 0; | |
578 | } | |
579 | ||
580 | static void skl_dmic_device_unregister(struct skl *skl) | |
581 | { | |
582 | if (skl->dmic_dev) | |
583 | platform_device_unregister(skl->dmic_dev); | |
584 | } | |
585 | ||
bc2bd45b SP |
586 | static struct skl_clk_parent_src skl_clk_src[] = { |
587 | { .clk_id = SKL_XTAL, .name = "xtal" }, | |
588 | { .clk_id = SKL_CARDINAL, .name = "cardinal", .rate = 24576000 }, | |
589 | { .clk_id = SKL_PLL, .name = "pll", .rate = 96000000 }, | |
590 | }; | |
591 | ||
592 | struct skl_clk_parent_src *skl_get_parent_clk(u8 clk_id) | |
593 | { | |
594 | unsigned int i; | |
595 | ||
596 | for (i = 0; i < ARRAY_SIZE(skl_clk_src); i++) { | |
597 | if (skl_clk_src[i].clk_id == clk_id) | |
598 | return &skl_clk_src[i]; | |
599 | } | |
600 | ||
601 | return NULL; | |
602 | } | |
603 | ||
8e79ec98 | 604 | static void init_skl_xtal_rate(int pci_id) |
bc2bd45b SP |
605 | { |
606 | switch (pci_id) { | |
607 | case 0x9d70: | |
608 | case 0x9d71: | |
609 | skl_clk_src[0].rate = 24000000; | |
610 | return; | |
611 | ||
612 | default: | |
613 | skl_clk_src[0].rate = 19200000; | |
614 | return; | |
615 | } | |
616 | } | |
617 | ||
618 | static int skl_clock_device_register(struct skl *skl) | |
619 | { | |
620 | struct platform_device_info pdevinfo = {NULL}; | |
621 | struct skl_clk_pdata *clk_pdata; | |
622 | ||
623 | clk_pdata = devm_kzalloc(&skl->pci->dev, sizeof(*clk_pdata), | |
624 | GFP_KERNEL); | |
625 | if (!clk_pdata) | |
626 | return -ENOMEM; | |
627 | ||
628 | init_skl_xtal_rate(skl->pci->device); | |
629 | ||
630 | clk_pdata->parent_clks = skl_clk_src; | |
631 | clk_pdata->ssp_clks = skl_ssp_clks; | |
632 | clk_pdata->num_clks = ARRAY_SIZE(skl_ssp_clks); | |
633 | ||
634 | /* Query NHLT to fill the rates and parent */ | |
635 | skl_get_clks(skl, clk_pdata->ssp_clks); | |
636 | clk_pdata->pvt_data = skl; | |
637 | ||
638 | /* Register Platform device */ | |
639 | pdevinfo.parent = &skl->pci->dev; | |
640 | pdevinfo.id = -1; | |
641 | pdevinfo.name = "skl-ssp-clk"; | |
642 | pdevinfo.data = clk_pdata; | |
643 | pdevinfo.size_data = sizeof(*clk_pdata); | |
644 | skl->clk_dev = platform_device_register_full(&pdevinfo); | |
645 | return PTR_ERR_OR_ZERO(skl->clk_dev); | |
646 | } | |
647 | ||
648 | static void skl_clock_device_unregister(struct skl *skl) | |
649 | { | |
650 | if (skl->clk_dev) | |
651 | platform_device_unregister(skl->clk_dev); | |
652 | } | |
653 | ||
8c4e7c2e PLB |
654 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) |
655 | ||
6bae5ea9 RU |
656 | #define IDISP_INTEL_VENDOR_ID 0x80860000 |
657 | ||
658 | /* | |
659 | * load the legacy codec driver | |
660 | */ | |
661 | static void load_codec_module(struct hda_codec *codec) | |
662 | { | |
663 | #ifdef MODULE | |
664 | char modalias[MODULE_NAME_LEN]; | |
665 | const char *mod = NULL; | |
666 | ||
667 | snd_hdac_codec_modalias(&codec->core, modalias, sizeof(modalias)); | |
668 | mod = modalias; | |
669 | dev_dbg(&codec->core.dev, "loading %s codec module\n", mod); | |
670 | request_module(mod); | |
671 | #endif | |
672 | } | |
673 | ||
8c4e7c2e PLB |
674 | #endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */ |
675 | ||
d8c2dab8 JK |
676 | /* |
677 | * Probe the given codec address | |
678 | */ | |
76f56fae | 679 | static int probe_codec(struct hdac_bus *bus, int addr) |
d8c2dab8 | 680 | { |
d8c2dab8 JK |
681 | unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) | |
682 | (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID; | |
e6a33532 | 683 | unsigned int res = -1; |
6298542f | 684 | struct skl *skl = bus_to_skl(bus); |
8c4e7c2e | 685 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) |
6bae5ea9 | 686 | struct hdac_hda_priv *hda_codec; |
6bae5ea9 | 687 | int err; |
8c4e7c2e PLB |
688 | #endif |
689 | struct hdac_device *hdev; | |
d8c2dab8 JK |
690 | |
691 | mutex_lock(&bus->cmd_mutex); | |
692 | snd_hdac_bus_send_cmd(bus, cmd); | |
693 | snd_hdac_bus_get_response(bus, addr, &res); | |
694 | mutex_unlock(&bus->cmd_mutex); | |
695 | if (res == -1) | |
696 | return -EIO; | |
00deadb5 | 697 | dev_dbg(bus->dev, "codec #%d probed OK: %x\n", addr, res); |
d8c2dab8 | 698 | |
8c4e7c2e | 699 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) |
6bae5ea9 RU |
700 | hda_codec = devm_kzalloc(&skl->pci->dev, sizeof(*hda_codec), |
701 | GFP_KERNEL); | |
702 | if (!hda_codec) | |
6298542f RU |
703 | return -ENOMEM; |
704 | ||
6bae5ea9 RU |
705 | hda_codec->codec.bus = skl_to_hbus(skl); |
706 | hdev = &hda_codec->codec.core; | |
707 | ||
708 | err = snd_hdac_ext_bus_device_init(bus, addr, hdev); | |
709 | if (err < 0) | |
710 | return err; | |
711 | ||
712 | /* use legacy bus only for HDA codecs, idisp uses ext bus */ | |
713 | if ((res & 0xFFFF0000) != IDISP_INTEL_VENDOR_ID) { | |
714 | hdev->type = HDA_DEV_LEGACY; | |
715 | load_codec_module(&hda_codec->codec); | |
716 | } | |
717 | return 0; | |
8c4e7c2e PLB |
718 | #else |
719 | hdev = devm_kzalloc(&skl->pci->dev, sizeof(*hdev), GFP_KERNEL); | |
720 | if (!hdev) | |
721 | return -ENOMEM; | |
722 | ||
723 | return snd_hdac_ext_bus_device_init(bus, addr, hdev); | |
724 | #endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */ | |
d8c2dab8 JK |
725 | } |
726 | ||
727 | /* Codec initialization */ | |
76f56fae | 728 | static void skl_codec_create(struct hdac_bus *bus) |
d8c2dab8 | 729 | { |
d8c2dab8 JK |
730 | int c, max_slots; |
731 | ||
732 | max_slots = HDA_MAX_CODECS; | |
733 | ||
734 | /* First try to probe all given codec slots */ | |
735 | for (c = 0; c < max_slots; c++) { | |
736 | if ((bus->codec_mask & (1 << c))) { | |
76f56fae | 737 | if (probe_codec(bus, c) < 0) { |
d8c2dab8 JK |
738 | /* |
739 | * Some BIOSen give you wrong codec addresses | |
740 | * that don't exist | |
741 | */ | |
742 | dev_warn(bus->dev, | |
743 | "Codec #%d probe error; disabling it...\n", c); | |
744 | bus->codec_mask &= ~(1 << c); | |
745 | /* | |
746 | * More badly, accessing to a non-existing | |
747 | * codec often screws up the controller bus, | |
748 | * and disturbs the further communications. | |
749 | * Thus if an error occurs during probing, | |
750 | * better to reset the controller bus to get | |
751 | * back to the sanity state. | |
752 | */ | |
753 | snd_hdac_bus_stop_chip(bus); | |
0c8ba9d2 | 754 | skl_init_chip(bus, true); |
d8c2dab8 JK |
755 | } |
756 | } | |
757 | } | |
d8c2dab8 JK |
758 | } |
759 | ||
760 | static const struct hdac_bus_ops bus_core_ops = { | |
761 | .command = snd_hdac_bus_send_cmd, | |
762 | .get_response = snd_hdac_bus_get_response, | |
763 | }; | |
764 | ||
ab1b732d VK |
765 | static int skl_i915_init(struct hdac_bus *bus) |
766 | { | |
767 | int err; | |
768 | ||
769 | /* | |
770 | * The HDMI codec is in GPU so we need to ensure that it is powered | |
771 | * up and ready for probe | |
772 | */ | |
773 | err = snd_hdac_i915_init(bus); | |
774 | if (err < 0) | |
775 | return err; | |
776 | ||
4f799e73 | 777 | snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true); |
ab1b732d | 778 | |
4f799e73 | 779 | return 0; |
ab1b732d VK |
780 | } |
781 | ||
782 | static void skl_probe_work(struct work_struct *work) | |
783 | { | |
784 | struct skl *skl = container_of(work, struct skl, probe_work); | |
76f56fae | 785 | struct hdac_bus *bus = skl_to_bus(skl); |
ab1b732d VK |
786 | struct hdac_ext_link *hlink = NULL; |
787 | int err; | |
788 | ||
789 | if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) { | |
790 | err = skl_i915_init(bus); | |
791 | if (err < 0) | |
792 | return; | |
793 | } | |
794 | ||
795 | err = skl_init_chip(bus, true); | |
796 | if (err < 0) { | |
797 | dev_err(bus->dev, "Init chip failed with err: %d\n", err); | |
798 | goto out_err; | |
799 | } | |
800 | ||
801 | /* codec detection */ | |
802 | if (!bus->codec_mask) | |
803 | dev_info(bus->dev, "no hda codecs found!\n"); | |
804 | ||
805 | /* create codec instances */ | |
76f56fae | 806 | skl_codec_create(bus); |
ab1b732d | 807 | |
752c93aa PB |
808 | /* register platform dai and controls */ |
809 | err = skl_platform_register(bus->dev); | |
810 | if (err < 0) { | |
811 | dev_err(bus->dev, "platform register failed: %d\n", err); | |
687ae9e2 | 812 | goto out_err; |
752c93aa PB |
813 | } |
814 | ||
7f981bdc PLB |
815 | err = skl_machine_device_register(skl); |
816 | if (err < 0) { | |
817 | dev_err(bus->dev, "machine register failed: %d\n", err); | |
818 | goto out_err; | |
752c93aa PB |
819 | } |
820 | ||
4c10473d PLB |
821 | /* |
822 | * we are done probing so decrement link counts | |
823 | */ | |
824 | list_for_each_entry(hlink, &bus->hlink_list, list) | |
825 | snd_hdac_ext_bus_link_put(bus, hlink); | |
826 | ||
4f799e73 TI |
827 | if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) |
828 | snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false); | |
ab1b732d | 829 | |
ab1b732d VK |
830 | /* configure PM */ |
831 | pm_runtime_put_noidle(bus->dev); | |
832 | pm_runtime_allow(bus->dev); | |
833 | skl->init_done = 1; | |
834 | ||
835 | return; | |
836 | ||
837 | out_err: | |
838 | if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) | |
4f799e73 | 839 | snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false); |
ab1b732d VK |
840 | } |
841 | ||
d8c2dab8 JK |
842 | /* |
843 | * constructor | |
844 | */ | |
845 | static int skl_create(struct pci_dev *pci, | |
846 | const struct hdac_io_ops *io_ops, | |
847 | struct skl **rskl) | |
848 | { | |
6bae5ea9 | 849 | struct hdac_ext_bus_ops *ext_ops = NULL; |
d8c2dab8 | 850 | struct skl *skl; |
76f56fae | 851 | struct hdac_bus *bus; |
00deadb5 | 852 | struct hda_bus *hbus; |
d8c2dab8 JK |
853 | int err; |
854 | ||
855 | *rskl = NULL; | |
856 | ||
857 | err = pci_enable_device(pci); | |
858 | if (err < 0) | |
859 | return err; | |
860 | ||
861 | skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL); | |
862 | if (!skl) { | |
863 | pci_disable_device(pci); | |
864 | return -ENOMEM; | |
865 | } | |
76f56fae | 866 | |
00deadb5 | 867 | hbus = skl_to_hbus(skl); |
76f56fae | 868 | bus = skl_to_bus(skl); |
6bae5ea9 | 869 | |
8c4e7c2e | 870 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) |
6bae5ea9 RU |
871 | ext_ops = snd_soc_hdac_hda_get_ops(); |
872 | #endif | |
873 | snd_hdac_ext_bus_init(bus, &pci->dev, &bus_core_ops, io_ops, ext_ops); | |
76f56fae | 874 | bus->use_posbuf = 1; |
d8c2dab8 | 875 | skl->pci = pci; |
ab1b732d | 876 | INIT_WORK(&skl->probe_work, skl_probe_work); |
76f56fae | 877 | bus->bdl_pos_adj = 0; |
d8c2dab8 | 878 | |
00deadb5 RU |
879 | mutex_init(&hbus->prepare_mutex); |
880 | hbus->pci = pci; | |
881 | hbus->mixer_assigned = -1; | |
882 | hbus->modelname = "sklbus"; | |
883 | ||
d8c2dab8 JK |
884 | *rskl = skl; |
885 | ||
886 | return 0; | |
887 | } | |
888 | ||
76f56fae | 889 | static int skl_first_init(struct hdac_bus *bus) |
d8c2dab8 | 890 | { |
76f56fae | 891 | struct skl *skl = bus_to_skl(bus); |
d8c2dab8 JK |
892 | struct pci_dev *pci = skl->pci; |
893 | int err; | |
894 | unsigned short gcap; | |
895 | int cp_streams, pb_streams, start_idx; | |
896 | ||
897 | err = pci_request_regions(pci, "Skylake HD audio"); | |
898 | if (err < 0) | |
899 | return err; | |
900 | ||
901 | bus->addr = pci_resource_start(pci, 0); | |
902 | bus->remap_addr = pci_ioremap_bar(pci, 0); | |
903 | if (bus->remap_addr == NULL) { | |
904 | dev_err(bus->dev, "ioremap error\n"); | |
905 | return -ENXIO; | |
906 | } | |
907 | ||
75383f8d | 908 | snd_hdac_bus_reset_link(bus, true); |
60767abc | 909 | |
ec8ae570 | 910 | snd_hdac_bus_parse_capabilities(bus); |
05057001 | 911 | |
fa11ab56 PLB |
912 | /* check if PPCAP exists */ |
913 | if (!bus->ppcap) { | |
914 | dev_err(bus->dev, "bus ppcap not set, HDaudio or DSP not present?\n"); | |
915 | return -ENODEV; | |
916 | } | |
917 | ||
542cedec YZ |
918 | if (skl_acquire_irq(bus, 0) < 0) |
919 | return -EBUSY; | |
920 | ||
d8c2dab8 | 921 | pci_set_master(pci); |
542cedec | 922 | synchronize_irq(bus->irq); |
d8c2dab8 JK |
923 | |
924 | gcap = snd_hdac_chip_readw(bus, GCAP); | |
925 | dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap); | |
926 | ||
d8c2dab8 JK |
927 | /* read number of streams from GCAP register */ |
928 | cp_streams = (gcap >> 8) & 0x0f; | |
929 | pb_streams = (gcap >> 12) & 0x0f; | |
930 | ||
fa11ab56 PLB |
931 | if (!pb_streams && !cp_streams) { |
932 | dev_err(bus->dev, "no streams found in GCAP definitions?\n"); | |
d8c2dab8 | 933 | return -EIO; |
fa11ab56 | 934 | } |
d8c2dab8 | 935 | |
76f56fae | 936 | bus->num_streams = cp_streams + pb_streams; |
d8c2dab8 | 937 | |
fa11ab56 PLB |
938 | /* allow 64bit DMA address if supported by H/W */ |
939 | if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) { | |
940 | dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64)); | |
941 | } else { | |
942 | dma_set_mask(bus->dev, DMA_BIT_MASK(32)); | |
943 | dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32)); | |
944 | } | |
945 | ||
d8c2dab8 JK |
946 | /* initialize streams */ |
947 | snd_hdac_ext_stream_init_all | |
76f56fae | 948 | (bus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE); |
d8c2dab8 JK |
949 | start_idx = cp_streams; |
950 | snd_hdac_ext_stream_init_all | |
76f56fae | 951 | (bus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK); |
d8c2dab8 JK |
952 | |
953 | err = snd_hdac_bus_alloc_stream_pages(bus); | |
954 | if (err < 0) | |
955 | return err; | |
956 | ||
957 | /* initialize chip */ | |
958 | skl_init_pci(skl); | |
959 | ||
ab1b732d | 960 | return skl_init_chip(bus, true); |
d8c2dab8 JK |
961 | } |
962 | ||
963 | static int skl_probe(struct pci_dev *pci, | |
964 | const struct pci_device_id *pci_id) | |
965 | { | |
966 | struct skl *skl; | |
d8c2dab8 JK |
967 | struct hdac_bus *bus = NULL; |
968 | int err; | |
969 | ||
d82b51c8 PLB |
970 | switch (skl_pci_binding) { |
971 | case SND_SKL_PCI_BIND_AUTO: | |
972 | /* | |
973 | * detect DSP by checking class/subclass/prog-id information | |
974 | * class=04 subclass 03 prog-if 00: no DSP, use legacy driver | |
975 | * class=04 subclass 01 prog-if 00: DSP is present | |
976 | * (and may be required e.g. for DMIC or SSP support) | |
977 | * class=04 subclass 03 prog-if 80: use DSP or legacy mode | |
978 | */ | |
979 | if (pci->class == 0x040300) { | |
980 | dev_info(&pci->dev, "The DSP is not enabled on this platform, aborting probe\n"); | |
981 | return -ENODEV; | |
982 | } | |
983 | if (pci->class != 0x040100 && pci->class != 0x040380) { | |
984 | dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, aborting probe\n", pci->class); | |
985 | return -ENODEV; | |
986 | } | |
987 | dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class); | |
988 | break; | |
989 | case SND_SKL_PCI_BIND_LEGACY: | |
990 | dev_info(&pci->dev, "Module parameter forced binding with HDaudio legacy, aborting probe\n"); | |
991 | return -ENODEV; | |
992 | case SND_SKL_PCI_BIND_ASOC: | |
993 | dev_info(&pci->dev, "Module parameter forced binding with SKL driver, bypassed detection logic\n"); | |
994 | break; | |
995 | default: | |
996 | dev_err(&pci->dev, "invalid value for skl_pci_binding module parameter, ignored\n"); | |
997 | break; | |
998 | } | |
999 | ||
d8c2dab8 JK |
1000 | /* we use ext core ops, so provide NULL for ops here */ |
1001 | err = skl_create(pci, NULL, &skl); | |
1002 | if (err < 0) | |
1003 | return err; | |
1004 | ||
76f56fae | 1005 | bus = skl_to_bus(skl); |
d8c2dab8 | 1006 | |
76f56fae | 1007 | err = skl_first_init(bus); |
f231c34c PLB |
1008 | if (err < 0) { |
1009 | dev_err(bus->dev, "skl_first_init failed with err: %d\n", err); | |
d8c2dab8 | 1010 | goto out_free; |
f231c34c | 1011 | } |
d8c2dab8 | 1012 | |
4b235c43 VK |
1013 | skl->pci_id = pci->device; |
1014 | ||
2e9dc2b6 VK |
1015 | device_disable_async_suspend(bus->dev); |
1016 | ||
87b2bdf0 JK |
1017 | skl->nhlt = skl_nhlt_init(bus->dev); |
1018 | ||
979cf59a | 1019 | if (skl->nhlt == NULL) { |
f231c34c PLB |
1020 | #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC) |
1021 | dev_err(bus->dev, "no nhlt info found\n"); | |
979cf59a | 1022 | err = -ENODEV; |
ab1b732d | 1023 | goto out_free; |
f231c34c PLB |
1024 | #else |
1025 | dev_warn(bus->dev, "no nhlt info found, continuing to try to enable HDaudio codec\n"); | |
1026 | #endif | |
1027 | } else { | |
0cf5a171 | 1028 | |
f231c34c PLB |
1029 | err = skl_nhlt_create_sysfs(skl); |
1030 | if (err < 0) { | |
1031 | dev_err(bus->dev, "skl_nhlt_create_sysfs failed with err: %d\n", err); | |
1032 | goto out_nhlt_free; | |
1033 | } | |
4b235c43 | 1034 | |
f231c34c | 1035 | skl_nhlt_update_topology_bin(skl); |
d8c2dab8 | 1036 | |
bc2bd45b SP |
1037 | /* create device for dsp clk */ |
1038 | err = skl_clock_device_register(skl); | |
f231c34c PLB |
1039 | if (err < 0) { |
1040 | dev_err(bus->dev, "skl_clock_device_register failed with err: %d\n", err); | |
bc2bd45b | 1041 | goto out_clk_free; |
f231c34c PLB |
1042 | } |
1043 | } | |
bc2bd45b | 1044 | |
76f56fae | 1045 | pci_set_drvdata(skl->pci, bus); |
cc18c5fd | 1046 | |
bc2bd45b | 1047 | |
7f981bdc | 1048 | err = skl_find_machine(skl, (void *)pci_id->driver_data); |
f231c34c PLB |
1049 | if (err < 0) { |
1050 | dev_err(bus->dev, "skl_find_machine failed with err: %d\n", err); | |
7f981bdc | 1051 | goto out_nhlt_free; |
f231c34c | 1052 | } |
cc18c5fd | 1053 | |
7f981bdc PLB |
1054 | err = skl_init_dsp(skl); |
1055 | if (err < 0) { | |
1056 | dev_dbg(bus->dev, "error failed to register dsp\n"); | |
1057 | goto out_nhlt_free; | |
05057001 | 1058 | } |
7f981bdc PLB |
1059 | skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge; |
1060 | skl->skl_sst->clock_power_gating = skl_clock_power_gating; | |
1061 | ||
ec8ae570 | 1062 | if (bus->mlcap) |
76f56fae | 1063 | snd_hdac_ext_bus_get_ml_capabilities(bus); |
05057001 | 1064 | |
ab1b732d VK |
1065 | snd_hdac_bus_stop_chip(bus); |
1066 | ||
d8c2dab8 JK |
1067 | /* create device for soc dmic */ |
1068 | err = skl_dmic_device_register(skl); | |
f231c34c PLB |
1069 | if (err < 0) { |
1070 | dev_err(bus->dev, "skl_dmic_device_register failed with err: %d\n", err); | |
2a29b200 | 1071 | goto out_dsp_free; |
f231c34c | 1072 | } |
d8c2dab8 | 1073 | |
ab1b732d | 1074 | schedule_work(&skl->probe_work); |
d8c2dab8 JK |
1075 | |
1076 | return 0; | |
1077 | ||
2a29b200 JK |
1078 | out_dsp_free: |
1079 | skl_free_dsp(skl); | |
bc2bd45b SP |
1080 | out_clk_free: |
1081 | skl_clock_device_unregister(skl); | |
c286b3f9 JK |
1082 | out_nhlt_free: |
1083 | skl_nhlt_free(skl->nhlt); | |
d8c2dab8 | 1084 | out_free: |
76f56fae | 1085 | skl_free(bus); |
d8c2dab8 JK |
1086 | |
1087 | return err; | |
1088 | } | |
1089 | ||
c5a76a24 JK |
1090 | static void skl_shutdown(struct pci_dev *pci) |
1091 | { | |
76f56fae | 1092 | struct hdac_bus *bus = pci_get_drvdata(pci); |
c5a76a24 JK |
1093 | struct hdac_stream *s; |
1094 | struct hdac_ext_stream *stream; | |
1095 | struct skl *skl; | |
1096 | ||
76f56fae | 1097 | if (!bus) |
c5a76a24 JK |
1098 | return; |
1099 | ||
76f56fae | 1100 | skl = bus_to_skl(bus); |
c5a76a24 | 1101 | |
ab1b732d | 1102 | if (!skl->init_done) |
c5a76a24 JK |
1103 | return; |
1104 | ||
76f56fae | 1105 | snd_hdac_ext_stop_streams(bus); |
c5a76a24 JK |
1106 | list_for_each_entry(s, &bus->stream_list, list) { |
1107 | stream = stream_to_hdac_ext_stream(s); | |
76f56fae | 1108 | snd_hdac_ext_stream_decouple(bus, stream, false); |
c5a76a24 JK |
1109 | } |
1110 | ||
1111 | snd_hdac_bus_stop_chip(bus); | |
1112 | } | |
1113 | ||
d8c2dab8 JK |
1114 | static void skl_remove(struct pci_dev *pci) |
1115 | { | |
76f56fae RU |
1116 | struct hdac_bus *bus = pci_get_drvdata(pci); |
1117 | struct skl *skl = bus_to_skl(bus); | |
d8c2dab8 | 1118 | |
1b00126c | 1119 | release_firmware(skl->tplg); |
d8018361 | 1120 | |
6d13f62d | 1121 | pm_runtime_get_noresume(&pci->dev); |
7373f481 VK |
1122 | |
1123 | /* codec removal, invoke bus_device_remove */ | |
76f56fae | 1124 | snd_hdac_ext_bus_device_remove(bus); |
7373f481 | 1125 | |
5cdf6c09 | 1126 | skl->debugfs = NULL; |
d8c2dab8 | 1127 | skl_platform_unregister(&pci->dev); |
2a29b200 | 1128 | skl_free_dsp(skl); |
cc18c5fd | 1129 | skl_machine_device_unregister(skl); |
d8c2dab8 | 1130 | skl_dmic_device_unregister(skl); |
bc2bd45b | 1131 | skl_clock_device_unregister(skl); |
0cf5a171 | 1132 | skl_nhlt_remove_sysfs(skl); |
c286b3f9 | 1133 | skl_nhlt_free(skl->nhlt); |
76f56fae | 1134 | skl_free(bus); |
d8c2dab8 JK |
1135 | dev_set_drvdata(&pci->dev, NULL); |
1136 | } | |
1137 | ||
1138 | /* PCI IDs */ | |
1139 | static const struct pci_device_id skl_ids[] = { | |
35bc99aa | 1140 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL) |
d8c2dab8 | 1141 | /* Sunrise Point-LP */ |
cc18c5fd | 1142 | { PCI_DEVICE(0x8086, 0x9d70), |
cbaa7f0b | 1143 | .driver_data = (unsigned long)&snd_soc_acpi_intel_skl_machines}, |
35bc99aa PLB |
1144 | #endif |
1145 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL) | |
b379b1fa SV |
1146 | /* BXT-P */ |
1147 | { PCI_DEVICE(0x8086, 0x5a98), | |
cbaa7f0b | 1148 | .driver_data = (unsigned long)&snd_soc_acpi_intel_bxt_machines}, |
35bc99aa PLB |
1149 | #endif |
1150 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL) | |
451dfb5f VK |
1151 | /* KBL */ |
1152 | { PCI_DEVICE(0x8086, 0x9D71), | |
cbaa7f0b | 1153 | .driver_data = (unsigned long)&snd_soc_acpi_intel_kbl_machines}, |
35bc99aa PLB |
1154 | #endif |
1155 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_GLK) | |
25504863 VK |
1156 | /* GLK */ |
1157 | { PCI_DEVICE(0x8086, 0x3198), | |
cbaa7f0b | 1158 | .driver_data = (unsigned long)&snd_soc_acpi_intel_glk_machines}, |
35bc99aa PLB |
1159 | #endif |
1160 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CNL) | |
86d7ce3d GS |
1161 | /* CNL */ |
1162 | { PCI_DEVICE(0x8086, 0x9dc8), | |
cbaa7f0b | 1163 | .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines}, |
35bc99aa PLB |
1164 | #endif |
1165 | #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CFL) | |
e6b98db9 TI |
1166 | /* CFL */ |
1167 | { PCI_DEVICE(0x8086, 0xa348), | |
1168 | .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines}, | |
35bc99aa | 1169 | #endif |
d8c2dab8 JK |
1170 | { 0, } |
1171 | }; | |
1172 | MODULE_DEVICE_TABLE(pci, skl_ids); | |
1173 | ||
1174 | /* pci_driver definition */ | |
1175 | static struct pci_driver skl_driver = { | |
1176 | .name = KBUILD_MODNAME, | |
1177 | .id_table = skl_ids, | |
1178 | .probe = skl_probe, | |
1179 | .remove = skl_remove, | |
c5a76a24 | 1180 | .shutdown = skl_shutdown, |
d8c2dab8 JK |
1181 | .driver = { |
1182 | .pm = &skl_pm, | |
1183 | }, | |
1184 | }; | |
1185 | module_pci_driver(skl_driver); | |
1186 | ||
1187 | MODULE_LICENSE("GPL v2"); | |
1188 | MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver"); |