skl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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. #include <linux/module.h>
  24. #include <linux/pci.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/firmware.h>
  28. #include <sound/pcm.h>
  29. #include "../common/sst-acpi.h"
  30. #include <sound/hda_register.h>
  31. #include <sound/hdaudio.h>
  32. #include <sound/hda_i915.h>
  33. #include "skl.h"
  34. #include "skl-sst-dsp.h"
  35. #include "skl-sst-ipc.h"
  36. static struct skl_machine_pdata skl_dmic_data;
  37. /*
  38. * initialize the PCI registers
  39. */
  40. static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg,
  41. unsigned char mask, unsigned char val)
  42. {
  43. unsigned char data;
  44. pci_read_config_byte(pci, reg, &data);
  45. data &= ~mask;
  46. data |= (val & mask);
  47. pci_write_config_byte(pci, reg, data);
  48. }
  49. static void skl_init_pci(struct skl *skl)
  50. {
  51. struct hdac_ext_bus *ebus = &skl->ebus;
  52. /*
  53. * Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
  54. * TCSEL == Traffic Class Select Register, which sets PCI express QOS
  55. * Ensuring these bits are 0 clears playback static on some HD Audio
  56. * codecs.
  57. * The PCI register TCSEL is defined in the Intel manuals.
  58. */
  59. dev_dbg(ebus_to_hbus(ebus)->dev, "Clearing TCSEL\n");
  60. skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0);
  61. }
  62. static void update_pci_dword(struct pci_dev *pci,
  63. unsigned int reg, u32 mask, u32 val)
  64. {
  65. u32 data = 0;
  66. pci_read_config_dword(pci, reg, &data);
  67. data &= ~mask;
  68. data |= (val & mask);
  69. pci_write_config_dword(pci, reg, data);
  70. }
  71. /*
  72. * skl_enable_miscbdcge - enable/dsiable CGCTL.MISCBDCGE bits
  73. *
  74. * @dev: device pointer
  75. * @enable: enable/disable flag
  76. */
  77. static void skl_enable_miscbdcge(struct device *dev, bool enable)
  78. {
  79. struct pci_dev *pci = to_pci_dev(dev);
  80. u32 val;
  81. val = enable ? AZX_CGCTL_MISCBDCGE_MASK : 0;
  82. update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_MISCBDCGE_MASK, val);
  83. }
  84. /*
  85. * While performing reset, controller may not come back properly causing
  86. * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
  87. * (init chip) and then again set CGCTL.MISCBDCGE to 1
  88. */
  89. static int skl_init_chip(struct hdac_bus *bus, bool full_reset)
  90. {
  91. int ret;
  92. skl_enable_miscbdcge(bus->dev, false);
  93. ret = snd_hdac_bus_init_chip(bus, full_reset);
  94. skl_enable_miscbdcge(bus->dev, true);
  95. return ret;
  96. }
  97. /* called from IRQ */
  98. static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr)
  99. {
  100. snd_pcm_period_elapsed(hstr->substream);
  101. }
  102. static irqreturn_t skl_interrupt(int irq, void *dev_id)
  103. {
  104. struct hdac_ext_bus *ebus = dev_id;
  105. struct hdac_bus *bus = ebus_to_hbus(ebus);
  106. u32 status;
  107. if (!pm_runtime_active(bus->dev))
  108. return IRQ_NONE;
  109. spin_lock(&bus->reg_lock);
  110. status = snd_hdac_chip_readl(bus, INTSTS);
  111. if (status == 0 || status == 0xffffffff) {
  112. spin_unlock(&bus->reg_lock);
  113. return IRQ_NONE;
  114. }
  115. /* clear rirb int */
  116. status = snd_hdac_chip_readb(bus, RIRBSTS);
  117. if (status & RIRB_INT_MASK) {
  118. if (status & RIRB_INT_RESPONSE)
  119. snd_hdac_bus_update_rirb(bus);
  120. snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
  121. }
  122. spin_unlock(&bus->reg_lock);
  123. return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
  124. }
  125. static irqreturn_t skl_threaded_handler(int irq, void *dev_id)
  126. {
  127. struct hdac_ext_bus *ebus = dev_id;
  128. struct hdac_bus *bus = ebus_to_hbus(ebus);
  129. u32 status;
  130. status = snd_hdac_chip_readl(bus, INTSTS);
  131. snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update);
  132. return IRQ_HANDLED;
  133. }
  134. static int skl_acquire_irq(struct hdac_ext_bus *ebus, int do_disconnect)
  135. {
  136. struct skl *skl = ebus_to_skl(ebus);
  137. struct hdac_bus *bus = ebus_to_hbus(ebus);
  138. int ret;
  139. ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
  140. skl_threaded_handler,
  141. IRQF_SHARED,
  142. KBUILD_MODNAME, ebus);
  143. if (ret) {
  144. dev_err(bus->dev,
  145. "unable to grab IRQ %d, disabling device\n",
  146. skl->pci->irq);
  147. return ret;
  148. }
  149. bus->irq = skl->pci->irq;
  150. pci_intx(skl->pci, 1);
  151. return 0;
  152. }
  153. #ifdef CONFIG_PM
  154. static int _skl_suspend(struct hdac_ext_bus *ebus)
  155. {
  156. struct skl *skl = ebus_to_skl(ebus);
  157. struct hdac_bus *bus = ebus_to_hbus(ebus);
  158. struct pci_dev *pci = to_pci_dev(bus->dev);
  159. int ret;
  160. snd_hdac_ext_bus_link_power_down_all(ebus);
  161. ret = skl_suspend_dsp(skl);
  162. if (ret < 0)
  163. return ret;
  164. snd_hdac_bus_stop_chip(bus);
  165. update_pci_dword(pci, AZX_PCIREG_PGCTL,
  166. AZX_PGCTL_LSRMD_MASK, AZX_PGCTL_LSRMD_MASK);
  167. skl_enable_miscbdcge(bus->dev, false);
  168. snd_hdac_bus_enter_link_reset(bus);
  169. skl_enable_miscbdcge(bus->dev, true);
  170. skl_cleanup_resources(skl);
  171. return 0;
  172. }
  173. static int _skl_resume(struct hdac_ext_bus *ebus)
  174. {
  175. struct skl *skl = ebus_to_skl(ebus);
  176. struct hdac_bus *bus = ebus_to_hbus(ebus);
  177. skl_init_pci(skl);
  178. skl_init_chip(bus, true);
  179. return skl_resume_dsp(skl);
  180. }
  181. #endif
  182. #ifdef CONFIG_PM_SLEEP
  183. /*
  184. * power management
  185. */
  186. static int skl_suspend(struct device *dev)
  187. {
  188. struct pci_dev *pci = to_pci_dev(dev);
  189. struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
  190. struct skl *skl = ebus_to_skl(ebus);
  191. struct hdac_bus *bus = ebus_to_hbus(ebus);
  192. int ret = 0;
  193. /*
  194. * Do not suspend if streams which are marked ignore suspend are
  195. * running, we need to save the state for these and continue
  196. */
  197. if (skl->supend_active) {
  198. /* turn off the links and stop the CORB/RIRB DMA if it is On */
  199. snd_hdac_ext_bus_link_power_down_all(ebus);
  200. if (ebus->cmd_dma_state)
  201. snd_hdac_bus_stop_cmd_io(&ebus->bus);
  202. enable_irq_wake(bus->irq);
  203. pci_save_state(pci);
  204. pci_disable_device(pci);
  205. } else {
  206. ret = _skl_suspend(ebus);
  207. if (ret < 0)
  208. return ret;
  209. skl->skl_sst->fw_loaded = false;
  210. }
  211. if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
  212. ret = snd_hdac_display_power(bus, false);
  213. if (ret < 0)
  214. dev_err(bus->dev,
  215. "Cannot turn OFF display power on i915\n");
  216. }
  217. return ret;
  218. }
  219. static int skl_resume(struct device *dev)
  220. {
  221. struct pci_dev *pci = to_pci_dev(dev);
  222. struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
  223. struct skl *skl = ebus_to_skl(ebus);
  224. struct hdac_bus *bus = ebus_to_hbus(ebus);
  225. struct hdac_ext_link *hlink = NULL;
  226. int ret;
  227. /* Turned OFF in HDMI codec driver after codec reconfiguration */
  228. if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
  229. ret = snd_hdac_display_power(bus, true);
  230. if (ret < 0) {
  231. dev_err(bus->dev,
  232. "Cannot turn on display power on i915\n");
  233. return ret;
  234. }
  235. }
  236. /*
  237. * resume only when we are not in suspend active, otherwise need to
  238. * restore the device
  239. */
  240. if (skl->supend_active) {
  241. pci_restore_state(pci);
  242. ret = pci_enable_device(pci);
  243. snd_hdac_ext_bus_link_power_up_all(ebus);
  244. disable_irq_wake(bus->irq);
  245. /*
  246. * turn On the links which are On before active suspend
  247. * and start the CORB/RIRB DMA if On before
  248. * active suspend.
  249. */
  250. list_for_each_entry(hlink, &ebus->hlink_list, list) {
  251. if (hlink->ref_count)
  252. snd_hdac_ext_bus_link_power_up(hlink);
  253. }
  254. if (ebus->cmd_dma_state)
  255. snd_hdac_bus_init_cmd_io(&ebus->bus);
  256. } else {
  257. ret = _skl_resume(ebus);
  258. /* turn off the links which are off before suspend */
  259. list_for_each_entry(hlink, &ebus->hlink_list, list) {
  260. if (!hlink->ref_count)
  261. snd_hdac_ext_bus_link_power_down(hlink);
  262. }
  263. if (!ebus->cmd_dma_state)
  264. snd_hdac_bus_stop_cmd_io(&ebus->bus);
  265. }
  266. return ret;
  267. }
  268. #endif /* CONFIG_PM_SLEEP */
  269. #ifdef CONFIG_PM
  270. static int skl_runtime_suspend(struct device *dev)
  271. {
  272. struct pci_dev *pci = to_pci_dev(dev);
  273. struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
  274. struct hdac_bus *bus = ebus_to_hbus(ebus);
  275. dev_dbg(bus->dev, "in %s\n", __func__);
  276. return _skl_suspend(ebus);
  277. }
  278. static int skl_runtime_resume(struct device *dev)
  279. {
  280. struct pci_dev *pci = to_pci_dev(dev);
  281. struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
  282. struct hdac_bus *bus = ebus_to_hbus(ebus);
  283. dev_dbg(bus->dev, "in %s\n", __func__);
  284. return _skl_resume(ebus);
  285. }
  286. #endif /* CONFIG_PM */
  287. static const struct dev_pm_ops skl_pm = {
  288. SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume)
  289. SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL)
  290. };
  291. /*
  292. * destructor
  293. */
  294. static int skl_free(struct hdac_ext_bus *ebus)
  295. {
  296. struct skl *skl = ebus_to_skl(ebus);
  297. struct hdac_bus *bus = ebus_to_hbus(ebus);
  298. skl->init_failed = 1; /* to be sure */
  299. snd_hdac_ext_stop_streams(ebus);
  300. if (bus->irq >= 0)
  301. free_irq(bus->irq, (void *)bus);
  302. snd_hdac_bus_free_stream_pages(bus);
  303. snd_hdac_stream_free_all(ebus);
  304. snd_hdac_link_free_all(ebus);
  305. if (bus->remap_addr)
  306. iounmap(bus->remap_addr);
  307. pci_release_regions(skl->pci);
  308. pci_disable_device(skl->pci);
  309. snd_hdac_ext_bus_exit(ebus);
  310. if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
  311. snd_hdac_i915_exit(&ebus->bus);
  312. return 0;
  313. }
  314. static int skl_machine_device_register(struct skl *skl, void *driver_data)
  315. {
  316. struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
  317. struct platform_device *pdev;
  318. struct sst_acpi_mach *mach = driver_data;
  319. int ret;
  320. mach = sst_acpi_find_machine(mach);
  321. if (mach == NULL) {
  322. dev_err(bus->dev, "No matching machine driver found\n");
  323. return -ENODEV;
  324. }
  325. skl->fw_name = mach->fw_filename;
  326. pdev = platform_device_alloc(mach->drv_name, -1);
  327. if (pdev == NULL) {
  328. dev_err(bus->dev, "platform device alloc failed\n");
  329. return -EIO;
  330. }
  331. ret = platform_device_add(pdev);
  332. if (ret) {
  333. dev_err(bus->dev, "failed to add machine device\n");
  334. platform_device_put(pdev);
  335. return -EIO;
  336. }
  337. if (mach->pdata)
  338. dev_set_drvdata(&pdev->dev, mach->pdata);
  339. skl->i2s_dev = pdev;
  340. return 0;
  341. }
  342. static void skl_machine_device_unregister(struct skl *skl)
  343. {
  344. if (skl->i2s_dev)
  345. platform_device_unregister(skl->i2s_dev);
  346. }
  347. static int skl_dmic_device_register(struct skl *skl)
  348. {
  349. struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
  350. struct platform_device *pdev;
  351. int ret;
  352. /* SKL has one dmic port, so allocate dmic device for this */
  353. pdev = platform_device_alloc("dmic-codec", -1);
  354. if (!pdev) {
  355. dev_err(bus->dev, "failed to allocate dmic device\n");
  356. return -ENOMEM;
  357. }
  358. ret = platform_device_add(pdev);
  359. if (ret) {
  360. dev_err(bus->dev, "failed to add dmic device: %d\n", ret);
  361. platform_device_put(pdev);
  362. return ret;
  363. }
  364. skl->dmic_dev = pdev;
  365. return 0;
  366. }
  367. static void skl_dmic_device_unregister(struct skl *skl)
  368. {
  369. if (skl->dmic_dev)
  370. platform_device_unregister(skl->dmic_dev);
  371. }
  372. /*
  373. * Probe the given codec address
  374. */
  375. static int probe_codec(struct hdac_ext_bus *ebus, int addr)
  376. {
  377. struct hdac_bus *bus = ebus_to_hbus(ebus);
  378. unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
  379. (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
  380. unsigned int res = -1;
  381. mutex_lock(&bus->cmd_mutex);
  382. snd_hdac_bus_send_cmd(bus, cmd);
  383. snd_hdac_bus_get_response(bus, addr, &res);
  384. mutex_unlock(&bus->cmd_mutex);
  385. if (res == -1)
  386. return -EIO;
  387. dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
  388. return snd_hdac_ext_bus_device_init(ebus, addr);
  389. }
  390. /* Codec initialization */
  391. static int skl_codec_create(struct hdac_ext_bus *ebus)
  392. {
  393. struct hdac_bus *bus = ebus_to_hbus(ebus);
  394. int c, max_slots;
  395. max_slots = HDA_MAX_CODECS;
  396. /* First try to probe all given codec slots */
  397. for (c = 0; c < max_slots; c++) {
  398. if ((bus->codec_mask & (1 << c))) {
  399. if (probe_codec(ebus, c) < 0) {
  400. /*
  401. * Some BIOSen give you wrong codec addresses
  402. * that don't exist
  403. */
  404. dev_warn(bus->dev,
  405. "Codec #%d probe error; disabling it...\n", c);
  406. bus->codec_mask &= ~(1 << c);
  407. /*
  408. * More badly, accessing to a non-existing
  409. * codec often screws up the controller bus,
  410. * and disturbs the further communications.
  411. * Thus if an error occurs during probing,
  412. * better to reset the controller bus to get
  413. * back to the sanity state.
  414. */
  415. snd_hdac_bus_stop_chip(bus);
  416. skl_init_chip(bus, true);
  417. }
  418. }
  419. }
  420. return 0;
  421. }
  422. static const struct hdac_bus_ops bus_core_ops = {
  423. .command = snd_hdac_bus_send_cmd,
  424. .get_response = snd_hdac_bus_get_response,
  425. };
  426. /*
  427. * constructor
  428. */
  429. static int skl_create(struct pci_dev *pci,
  430. const struct hdac_io_ops *io_ops,
  431. struct skl **rskl)
  432. {
  433. struct skl *skl;
  434. struct hdac_ext_bus *ebus;
  435. int err;
  436. *rskl = NULL;
  437. err = pci_enable_device(pci);
  438. if (err < 0)
  439. return err;
  440. skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);
  441. if (!skl) {
  442. pci_disable_device(pci);
  443. return -ENOMEM;
  444. }
  445. ebus = &skl->ebus;
  446. snd_hdac_ext_bus_init(ebus, &pci->dev, &bus_core_ops, io_ops);
  447. ebus->bus.use_posbuf = 1;
  448. skl->pci = pci;
  449. ebus->bus.bdl_pos_adj = 0;
  450. *rskl = skl;
  451. return 0;
  452. }
  453. static int skl_i915_init(struct hdac_bus *bus)
  454. {
  455. int err;
  456. /*
  457. * The HDMI codec is in GPU so we need to ensure that it is powered
  458. * up and ready for probe
  459. */
  460. err = snd_hdac_i915_init(bus);
  461. if (err < 0)
  462. return err;
  463. err = snd_hdac_display_power(bus, true);
  464. if (err < 0) {
  465. dev_err(bus->dev, "Cannot turn on display power on i915\n");
  466. return err;
  467. }
  468. return err;
  469. }
  470. static int skl_first_init(struct hdac_ext_bus *ebus)
  471. {
  472. struct skl *skl = ebus_to_skl(ebus);
  473. struct hdac_bus *bus = ebus_to_hbus(ebus);
  474. struct pci_dev *pci = skl->pci;
  475. int err;
  476. unsigned short gcap;
  477. int cp_streams, pb_streams, start_idx;
  478. err = pci_request_regions(pci, "Skylake HD audio");
  479. if (err < 0)
  480. return err;
  481. bus->addr = pci_resource_start(pci, 0);
  482. bus->remap_addr = pci_ioremap_bar(pci, 0);
  483. if (bus->remap_addr == NULL) {
  484. dev_err(bus->dev, "ioremap error\n");
  485. return -ENXIO;
  486. }
  487. snd_hdac_bus_parse_capabilities(bus);
  488. if (skl_acquire_irq(ebus, 0) < 0)
  489. return -EBUSY;
  490. pci_set_master(pci);
  491. synchronize_irq(bus->irq);
  492. gcap = snd_hdac_chip_readw(bus, GCAP);
  493. dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
  494. /* allow 64bit DMA address if supported by H/W */
  495. if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
  496. dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
  497. } else {
  498. dma_set_mask(bus->dev, DMA_BIT_MASK(32));
  499. dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
  500. }
  501. /* read number of streams from GCAP register */
  502. cp_streams = (gcap >> 8) & 0x0f;
  503. pb_streams = (gcap >> 12) & 0x0f;
  504. if (!pb_streams && !cp_streams)
  505. return -EIO;
  506. ebus->num_streams = cp_streams + pb_streams;
  507. /* initialize streams */
  508. snd_hdac_ext_stream_init_all
  509. (ebus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
  510. start_idx = cp_streams;
  511. snd_hdac_ext_stream_init_all
  512. (ebus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
  513. err = snd_hdac_bus_alloc_stream_pages(bus);
  514. if (err < 0)
  515. return err;
  516. /* initialize chip */
  517. skl_init_pci(skl);
  518. if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
  519. err = skl_i915_init(bus);
  520. if (err < 0)
  521. return err;
  522. }
  523. skl_init_chip(bus, true);
  524. /* codec detection */
  525. if (!bus->codec_mask) {
  526. dev_info(bus->dev, "no hda codecs found!\n");
  527. }
  528. return 0;
  529. }
  530. static int skl_probe(struct pci_dev *pci,
  531. const struct pci_device_id *pci_id)
  532. {
  533. struct skl *skl;
  534. struct hdac_ext_bus *ebus = NULL;
  535. struct hdac_bus *bus = NULL;
  536. struct hdac_ext_link *hlink = NULL;
  537. int err;
  538. /* we use ext core ops, so provide NULL for ops here */
  539. err = skl_create(pci, NULL, &skl);
  540. if (err < 0)
  541. return err;
  542. ebus = &skl->ebus;
  543. bus = ebus_to_hbus(ebus);
  544. err = skl_first_init(ebus);
  545. if (err < 0)
  546. goto out_free;
  547. skl->pci_id = pci->device;
  548. device_disable_async_suspend(bus->dev);
  549. skl->nhlt = skl_nhlt_init(bus->dev);
  550. if (skl->nhlt == NULL) {
  551. err = -ENODEV;
  552. goto out_display_power_off;
  553. }
  554. skl_nhlt_update_topology_bin(skl);
  555. pci_set_drvdata(skl->pci, ebus);
  556. skl_dmic_data.dmic_num = skl_get_dmic_geo(skl);
  557. /* check if dsp is there */
  558. if (bus->ppcap) {
  559. err = skl_machine_device_register(skl,
  560. (void *)pci_id->driver_data);
  561. if (err < 0)
  562. goto out_nhlt_free;
  563. err = skl_init_dsp(skl);
  564. if (err < 0) {
  565. dev_dbg(bus->dev, "error failed to register dsp\n");
  566. goto out_mach_free;
  567. }
  568. skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge;
  569. }
  570. if (bus->mlcap)
  571. snd_hdac_ext_bus_get_ml_capabilities(ebus);
  572. /* create device for soc dmic */
  573. err = skl_dmic_device_register(skl);
  574. if (err < 0)
  575. goto out_dsp_free;
  576. /* register platform dai and controls */
  577. err = skl_platform_register(bus->dev);
  578. if (err < 0)
  579. goto out_dmic_free;
  580. /* create codec instances */
  581. err = skl_codec_create(ebus);
  582. if (err < 0)
  583. goto out_unregister;
  584. if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
  585. err = snd_hdac_display_power(bus, false);
  586. if (err < 0) {
  587. dev_err(bus->dev, "Cannot turn off display power on i915\n");
  588. return err;
  589. }
  590. }
  591. /*
  592. * we are done probling so decrement link counts
  593. */
  594. list_for_each_entry(hlink, &ebus->hlink_list, list)
  595. snd_hdac_ext_bus_link_put(ebus, hlink);
  596. /* configure PM */
  597. pm_runtime_put_noidle(bus->dev);
  598. pm_runtime_allow(bus->dev);
  599. return 0;
  600. out_unregister:
  601. skl_platform_unregister(bus->dev);
  602. out_dmic_free:
  603. skl_dmic_device_unregister(skl);
  604. out_dsp_free:
  605. skl_free_dsp(skl);
  606. out_mach_free:
  607. skl_machine_device_unregister(skl);
  608. out_nhlt_free:
  609. skl_nhlt_free(skl->nhlt);
  610. out_display_power_off:
  611. if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
  612. snd_hdac_display_power(bus, false);
  613. out_free:
  614. skl->init_failed = 1;
  615. skl_free(ebus);
  616. return err;
  617. }
  618. static void skl_shutdown(struct pci_dev *pci)
  619. {
  620. struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
  621. struct hdac_bus *bus = ebus_to_hbus(ebus);
  622. struct hdac_stream *s;
  623. struct hdac_ext_stream *stream;
  624. struct skl *skl;
  625. if (ebus == NULL)
  626. return;
  627. skl = ebus_to_skl(ebus);
  628. if (skl->init_failed)
  629. return;
  630. snd_hdac_ext_stop_streams(ebus);
  631. list_for_each_entry(s, &bus->stream_list, list) {
  632. stream = stream_to_hdac_ext_stream(s);
  633. snd_hdac_ext_stream_decouple(ebus, stream, false);
  634. }
  635. snd_hdac_bus_stop_chip(bus);
  636. }
  637. static void skl_remove(struct pci_dev *pci)
  638. {
  639. struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
  640. struct skl *skl = ebus_to_skl(ebus);
  641. release_firmware(skl->tplg);
  642. pm_runtime_get_noresume(&pci->dev);
  643. /* codec removal, invoke bus_device_remove */
  644. snd_hdac_ext_bus_device_remove(ebus);
  645. skl_platform_unregister(&pci->dev);
  646. skl_free_dsp(skl);
  647. skl_machine_device_unregister(skl);
  648. skl_dmic_device_unregister(skl);
  649. skl_nhlt_free(skl->nhlt);
  650. skl_free(ebus);
  651. dev_set_drvdata(&pci->dev, NULL);
  652. }
  653. static struct sst_acpi_mach sst_skl_devdata[] = {
  654. { "INT343A", "skl_alc286s_i2s", "/*(DEBLOBBED)*/", NULL, NULL, NULL },
  655. { "INT343B", "skl_n88l25_s4567", "/*(DEBLOBBED)*/",
  656. NULL, NULL, &skl_dmic_data },
  657. { "MX98357A", "skl_n88l25_m98357a", "/*(DEBLOBBED)*/",
  658. NULL, NULL, &skl_dmic_data },
  659. {}
  660. };
  661. static struct sst_acpi_mach sst_bxtp_devdata[] = {
  662. { "INT343A", "bxt_alc298s_i2s", "/*(DEBLOBBED)*/", NULL, NULL, NULL },
  663. { "DLGS7219", "bxt_da7219_max98357a_i2s", "/*(DEBLOBBED)*/", NULL, NULL, NULL },
  664. };
  665. static struct sst_acpi_mach sst_kbl_devdata[] = {
  666. { "INT343A", "kbl_alc286s_i2s", "/*(DEBLOBBED)*/", NULL, NULL, NULL },
  667. { "INT343B", "kbl_n88l25_s4567", "/*(DEBLOBBED)*/", NULL, NULL, &skl_dmic_data },
  668. { "MX98357A", "kbl_n88l25_m98357a", "/*(DEBLOBBED)*/", NULL, NULL, &skl_dmic_data },
  669. {}
  670. };
  671. /* PCI IDs */
  672. static const struct pci_device_id skl_ids[] = {
  673. /* Sunrise Point-LP */
  674. { PCI_DEVICE(0x8086, 0x9d70),
  675. .driver_data = (unsigned long)&sst_skl_devdata},
  676. /* BXT-P */
  677. { PCI_DEVICE(0x8086, 0x5a98),
  678. .driver_data = (unsigned long)&sst_bxtp_devdata},
  679. /* KBL */
  680. { PCI_DEVICE(0x8086, 0x9D71),
  681. .driver_data = (unsigned long)&sst_kbl_devdata},
  682. { 0, }
  683. };
  684. MODULE_DEVICE_TABLE(pci, skl_ids);
  685. /* pci_driver definition */
  686. static struct pci_driver skl_driver = {
  687. .name = KBUILD_MODNAME,
  688. .id_table = skl_ids,
  689. .probe = skl_probe,
  690. .remove = skl_remove,
  691. .shutdown = skl_shutdown,
  692. .driver = {
  693. .pm = &skl_pm,
  694. },
  695. };
  696. module_pci_driver(skl_driver);
  697. MODULE_LICENSE("GPL v2");
  698. MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver");