hdac_controller.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * HD-audio controller helpers
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/delay.h>
  6. #include <linux/export.h>
  7. #include <sound/core.h>
  8. #include <sound/hdaudio.h>
  9. #include <sound/hda_register.h>
  10. /* clear CORB read pointer properly */
  11. static void azx_clear_corbrp(struct hdac_bus *bus)
  12. {
  13. int timeout;
  14. for (timeout = 1000; timeout > 0; timeout--) {
  15. if (snd_hdac_chip_readw(bus, CORBRP) & AZX_CORBRP_RST)
  16. break;
  17. udelay(1);
  18. }
  19. if (timeout <= 0)
  20. dev_err(bus->dev, "CORB reset timeout#1, CORBRP = %d\n",
  21. snd_hdac_chip_readw(bus, CORBRP));
  22. snd_hdac_chip_writew(bus, CORBRP, 0);
  23. for (timeout = 1000; timeout > 0; timeout--) {
  24. if (snd_hdac_chip_readw(bus, CORBRP) == 0)
  25. break;
  26. udelay(1);
  27. }
  28. if (timeout <= 0)
  29. dev_err(bus->dev, "CORB reset timeout#2, CORBRP = %d\n",
  30. snd_hdac_chip_readw(bus, CORBRP));
  31. }
  32. /**
  33. * snd_hdac_bus_init_cmd_io - set up CORB/RIRB buffers
  34. * @bus: HD-audio core bus
  35. */
  36. void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus)
  37. {
  38. WARN_ON_ONCE(!bus->rb.area);
  39. spin_lock_irq(&bus->reg_lock);
  40. /* CORB set up */
  41. bus->corb.addr = bus->rb.addr;
  42. bus->corb.buf = (__le32 *)bus->rb.area;
  43. snd_hdac_chip_writel(bus, CORBLBASE, (u32)bus->corb.addr);
  44. snd_hdac_chip_writel(bus, CORBUBASE, upper_32_bits(bus->corb.addr));
  45. /* set the corb size to 256 entries (ULI requires explicitly) */
  46. snd_hdac_chip_writeb(bus, CORBSIZE, 0x02);
  47. /* set the corb write pointer to 0 */
  48. snd_hdac_chip_writew(bus, CORBWP, 0);
  49. /* reset the corb hw read pointer */
  50. snd_hdac_chip_writew(bus, CORBRP, AZX_CORBRP_RST);
  51. if (!bus->corbrp_self_clear)
  52. azx_clear_corbrp(bus);
  53. /* enable corb dma */
  54. snd_hdac_chip_writeb(bus, CORBCTL, AZX_CORBCTL_RUN);
  55. /* RIRB set up */
  56. bus->rirb.addr = bus->rb.addr + 2048;
  57. bus->rirb.buf = (__le32 *)(bus->rb.area + 2048);
  58. bus->rirb.wp = bus->rirb.rp = 0;
  59. memset(bus->rirb.cmds, 0, sizeof(bus->rirb.cmds));
  60. snd_hdac_chip_writel(bus, RIRBLBASE, (u32)bus->rirb.addr);
  61. snd_hdac_chip_writel(bus, RIRBUBASE, upper_32_bits(bus->rirb.addr));
  62. /* set the rirb size to 256 entries (ULI requires explicitly) */
  63. snd_hdac_chip_writeb(bus, RIRBSIZE, 0x02);
  64. /* reset the rirb hw write pointer */
  65. snd_hdac_chip_writew(bus, RIRBWP, AZX_RIRBWP_RST);
  66. /* set N=1, get RIRB response interrupt for new entry */
  67. snd_hdac_chip_writew(bus, RINTCNT, 1);
  68. /* enable rirb dma and response irq */
  69. snd_hdac_chip_writeb(bus, RIRBCTL, AZX_RBCTL_DMA_EN | AZX_RBCTL_IRQ_EN);
  70. spin_unlock_irq(&bus->reg_lock);
  71. }
  72. EXPORT_SYMBOL_GPL(snd_hdac_bus_init_cmd_io);
  73. /* wait for cmd dmas till they are stopped */
  74. static void hdac_wait_for_cmd_dmas(struct hdac_bus *bus)
  75. {
  76. unsigned long timeout;
  77. timeout = jiffies + msecs_to_jiffies(100);
  78. while ((snd_hdac_chip_readb(bus, RIRBCTL) & AZX_RBCTL_DMA_EN)
  79. && time_before(jiffies, timeout))
  80. udelay(10);
  81. timeout = jiffies + msecs_to_jiffies(100);
  82. while ((snd_hdac_chip_readb(bus, CORBCTL) & AZX_CORBCTL_RUN)
  83. && time_before(jiffies, timeout))
  84. udelay(10);
  85. }
  86. /**
  87. * snd_hdac_bus_stop_cmd_io - clean up CORB/RIRB buffers
  88. * @bus: HD-audio core bus
  89. */
  90. void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus)
  91. {
  92. spin_lock_irq(&bus->reg_lock);
  93. /* disable ringbuffer DMAs */
  94. snd_hdac_chip_writeb(bus, RIRBCTL, 0);
  95. snd_hdac_chip_writeb(bus, CORBCTL, 0);
  96. spin_unlock_irq(&bus->reg_lock);
  97. hdac_wait_for_cmd_dmas(bus);
  98. spin_lock_irq(&bus->reg_lock);
  99. /* disable unsolicited responses */
  100. snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0);
  101. spin_unlock_irq(&bus->reg_lock);
  102. }
  103. EXPORT_SYMBOL_GPL(snd_hdac_bus_stop_cmd_io);
  104. static unsigned int azx_command_addr(u32 cmd)
  105. {
  106. unsigned int addr = cmd >> 28;
  107. if (snd_BUG_ON(addr >= HDA_MAX_CODECS))
  108. addr = 0;
  109. return addr;
  110. }
  111. /**
  112. * snd_hdac_bus_send_cmd - send a command verb via CORB
  113. * @bus: HD-audio core bus
  114. * @val: encoded verb value to send
  115. *
  116. * Returns zero for success or a negative error code.
  117. */
  118. int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val)
  119. {
  120. unsigned int addr = azx_command_addr(val);
  121. unsigned int wp, rp;
  122. spin_lock_irq(&bus->reg_lock);
  123. bus->last_cmd[azx_command_addr(val)] = val;
  124. /* add command to corb */
  125. wp = snd_hdac_chip_readw(bus, CORBWP);
  126. if (wp == 0xffff) {
  127. /* something wrong, controller likely turned to D3 */
  128. spin_unlock_irq(&bus->reg_lock);
  129. return -EIO;
  130. }
  131. wp++;
  132. wp %= AZX_MAX_CORB_ENTRIES;
  133. rp = snd_hdac_chip_readw(bus, CORBRP);
  134. if (wp == rp) {
  135. /* oops, it's full */
  136. spin_unlock_irq(&bus->reg_lock);
  137. return -EAGAIN;
  138. }
  139. bus->rirb.cmds[addr]++;
  140. bus->corb.buf[wp] = cpu_to_le32(val);
  141. snd_hdac_chip_writew(bus, CORBWP, wp);
  142. spin_unlock_irq(&bus->reg_lock);
  143. return 0;
  144. }
  145. EXPORT_SYMBOL_GPL(snd_hdac_bus_send_cmd);
  146. #define AZX_RIRB_EX_UNSOL_EV (1<<4)
  147. /**
  148. * snd_hdac_bus_update_rirb - retrieve RIRB entries
  149. * @bus: HD-audio core bus
  150. *
  151. * Usually called from interrupt handler.
  152. */
  153. void snd_hdac_bus_update_rirb(struct hdac_bus *bus)
  154. {
  155. unsigned int rp, wp;
  156. unsigned int addr;
  157. u32 res, res_ex;
  158. wp = snd_hdac_chip_readw(bus, RIRBWP);
  159. if (wp == 0xffff) {
  160. /* something wrong, controller likely turned to D3 */
  161. return;
  162. }
  163. if (wp == bus->rirb.wp)
  164. return;
  165. bus->rirb.wp = wp;
  166. while (bus->rirb.rp != wp) {
  167. bus->rirb.rp++;
  168. bus->rirb.rp %= AZX_MAX_RIRB_ENTRIES;
  169. rp = bus->rirb.rp << 1; /* an RIRB entry is 8-bytes */
  170. res_ex = le32_to_cpu(bus->rirb.buf[rp + 1]);
  171. res = le32_to_cpu(bus->rirb.buf[rp]);
  172. addr = res_ex & 0xf;
  173. if (addr >= HDA_MAX_CODECS) {
  174. dev_err(bus->dev,
  175. "spurious response %#x:%#x, rp = %d, wp = %d",
  176. res, res_ex, bus->rirb.rp, wp);
  177. snd_BUG();
  178. } else if (res_ex & AZX_RIRB_EX_UNSOL_EV)
  179. snd_hdac_bus_queue_event(bus, res, res_ex);
  180. else if (bus->rirb.cmds[addr]) {
  181. bus->rirb.res[addr] = res;
  182. bus->rirb.cmds[addr]--;
  183. } else {
  184. dev_err_ratelimited(bus->dev,
  185. "spurious response %#x:%#x, last cmd=%#08x\n",
  186. res, res_ex, bus->last_cmd[addr]);
  187. }
  188. }
  189. }
  190. EXPORT_SYMBOL_GPL(snd_hdac_bus_update_rirb);
  191. /**
  192. * snd_hdac_bus_get_response - receive a response via RIRB
  193. * @bus: HD-audio core bus
  194. * @addr: codec address
  195. * @res: pointer to store the value, NULL when not needed
  196. *
  197. * Returns zero if a value is read, or a negative error code.
  198. */
  199. int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
  200. unsigned int *res)
  201. {
  202. unsigned long timeout;
  203. unsigned long loopcounter;
  204. timeout = jiffies + msecs_to_jiffies(1000);
  205. for (loopcounter = 0;; loopcounter++) {
  206. spin_lock_irq(&bus->reg_lock);
  207. if (!bus->rirb.cmds[addr]) {
  208. if (res)
  209. *res = bus->rirb.res[addr]; /* the last value */
  210. spin_unlock_irq(&bus->reg_lock);
  211. return 0;
  212. }
  213. spin_unlock_irq(&bus->reg_lock);
  214. if (time_after(jiffies, timeout))
  215. break;
  216. if (loopcounter > 3000)
  217. msleep(2); /* temporary workaround */
  218. else {
  219. udelay(10);
  220. cond_resched();
  221. }
  222. }
  223. return -EIO;
  224. }
  225. EXPORT_SYMBOL_GPL(snd_hdac_bus_get_response);
  226. #define HDAC_MAX_CAPS 10
  227. /**
  228. * snd_hdac_bus_parse_capabilities - parse capability structure
  229. * @bus: the pointer to bus object
  230. *
  231. * Returns 0 if successful, or a negative error code.
  232. */
  233. int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus)
  234. {
  235. unsigned int cur_cap;
  236. unsigned int offset;
  237. unsigned int counter = 0;
  238. offset = snd_hdac_chip_readw(bus, LLCH);
  239. /* Lets walk the linked capabilities list */
  240. do {
  241. cur_cap = _snd_hdac_chip_readl(bus, offset);
  242. dev_dbg(bus->dev, "Capability version: 0x%x\n",
  243. (cur_cap & AZX_CAP_HDR_VER_MASK) >> AZX_CAP_HDR_VER_OFF);
  244. dev_dbg(bus->dev, "HDA capability ID: 0x%x\n",
  245. (cur_cap & AZX_CAP_HDR_ID_MASK) >> AZX_CAP_HDR_ID_OFF);
  246. if (cur_cap == -1) {
  247. dev_dbg(bus->dev, "Invalid capability reg read\n");
  248. break;
  249. }
  250. switch ((cur_cap & AZX_CAP_HDR_ID_MASK) >> AZX_CAP_HDR_ID_OFF) {
  251. case AZX_ML_CAP_ID:
  252. dev_dbg(bus->dev, "Found ML capability\n");
  253. bus->mlcap = bus->remap_addr + offset;
  254. break;
  255. case AZX_GTS_CAP_ID:
  256. dev_dbg(bus->dev, "Found GTS capability offset=%x\n", offset);
  257. bus->gtscap = bus->remap_addr + offset;
  258. break;
  259. case AZX_PP_CAP_ID:
  260. /* PP capability found, the Audio DSP is present */
  261. dev_dbg(bus->dev, "Found PP capability offset=%x\n", offset);
  262. bus->ppcap = bus->remap_addr + offset;
  263. break;
  264. case AZX_SPB_CAP_ID:
  265. /* SPIB capability found, handler function */
  266. dev_dbg(bus->dev, "Found SPB capability\n");
  267. bus->spbcap = bus->remap_addr + offset;
  268. break;
  269. case AZX_DRSM_CAP_ID:
  270. /* DMA resume capability found, handler function */
  271. dev_dbg(bus->dev, "Found DRSM capability\n");
  272. bus->drsmcap = bus->remap_addr + offset;
  273. break;
  274. default:
  275. dev_err(bus->dev, "Unknown capability %d\n", cur_cap);
  276. cur_cap = 0;
  277. break;
  278. }
  279. counter++;
  280. if (counter > HDAC_MAX_CAPS) {
  281. dev_err(bus->dev, "We exceeded HDAC capabilities!!!\n");
  282. break;
  283. }
  284. /* read the offset of next capability */
  285. offset = cur_cap & AZX_CAP_HDR_NXT_PTR_MASK;
  286. } while (offset);
  287. return 0;
  288. }
  289. EXPORT_SYMBOL_GPL(snd_hdac_bus_parse_capabilities);
  290. /*
  291. * Lowlevel interface
  292. */
  293. /**
  294. * snd_hdac_bus_enter_link_reset - enter link reset
  295. * @bus: HD-audio core bus
  296. *
  297. * Enter to the link reset state.
  298. */
  299. void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus)
  300. {
  301. unsigned long timeout;
  302. /* reset controller */
  303. snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_RESET, 0);
  304. timeout = jiffies + msecs_to_jiffies(100);
  305. while ((snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET) &&
  306. time_before(jiffies, timeout))
  307. usleep_range(500, 1000);
  308. }
  309. EXPORT_SYMBOL_GPL(snd_hdac_bus_enter_link_reset);
  310. /**
  311. * snd_hdac_bus_exit_link_reset - exit link reset
  312. * @bus: HD-audio core bus
  313. *
  314. * Exit from the link reset state.
  315. */
  316. void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus)
  317. {
  318. unsigned long timeout;
  319. snd_hdac_chip_updateb(bus, GCTL, 0, AZX_GCTL_RESET);
  320. timeout = jiffies + msecs_to_jiffies(100);
  321. while (!snd_hdac_chip_readb(bus, GCTL) && time_before(jiffies, timeout))
  322. usleep_range(500, 1000);
  323. }
  324. EXPORT_SYMBOL_GPL(snd_hdac_bus_exit_link_reset);
  325. /* reset codec link */
  326. int snd_hdac_bus_reset_link(struct hdac_bus *bus, bool full_reset)
  327. {
  328. if (!full_reset)
  329. goto skip_reset;
  330. /* clear STATESTS */
  331. snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK);
  332. /* reset controller */
  333. snd_hdac_bus_enter_link_reset(bus);
  334. /* delay for >= 100us for codec PLL to settle per spec
  335. * Rev 0.9 section 5.5.1
  336. */
  337. usleep_range(500, 1000);
  338. /* Bring controller out of reset */
  339. snd_hdac_bus_exit_link_reset(bus);
  340. /* Brent Chartrand said to wait >= 540us for codecs to initialize */
  341. usleep_range(1000, 1200);
  342. skip_reset:
  343. /* check to see if controller is ready */
  344. if (!snd_hdac_chip_readb(bus, GCTL)) {
  345. dev_dbg(bus->dev, "controller not ready!\n");
  346. return -EBUSY;
  347. }
  348. /* Accept unsolicited responses */
  349. snd_hdac_chip_updatel(bus, GCTL, 0, AZX_GCTL_UNSOL);
  350. /* detect codecs */
  351. if (!bus->codec_mask) {
  352. bus->codec_mask = snd_hdac_chip_readw(bus, STATESTS);
  353. dev_dbg(bus->dev, "codec_mask = 0x%lx\n", bus->codec_mask);
  354. }
  355. return 0;
  356. }
  357. EXPORT_SYMBOL_GPL(snd_hdac_bus_reset_link);
  358. /* enable interrupts */
  359. static void azx_int_enable(struct hdac_bus *bus)
  360. {
  361. /* enable controller CIE and GIE */
  362. snd_hdac_chip_updatel(bus, INTCTL, 0, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN);
  363. }
  364. /* disable interrupts */
  365. static void azx_int_disable(struct hdac_bus *bus)
  366. {
  367. struct hdac_stream *azx_dev;
  368. /* disable interrupts in stream descriptor */
  369. list_for_each_entry(azx_dev, &bus->stream_list, list)
  370. snd_hdac_stream_updateb(azx_dev, SD_CTL, SD_INT_MASK, 0);
  371. /* disable SIE for all streams */
  372. snd_hdac_chip_writeb(bus, INTCTL, 0);
  373. /* disable controller CIE and GIE */
  374. snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN, 0);
  375. }
  376. /* clear interrupts */
  377. static void azx_int_clear(struct hdac_bus *bus)
  378. {
  379. struct hdac_stream *azx_dev;
  380. /* clear stream status */
  381. list_for_each_entry(azx_dev, &bus->stream_list, list)
  382. snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK);
  383. /* clear STATESTS */
  384. snd_hdac_chip_writew(bus, STATESTS, STATESTS_INT_MASK);
  385. /* clear rirb status */
  386. snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
  387. /* clear int status */
  388. snd_hdac_chip_writel(bus, INTSTS, AZX_INT_CTRL_EN | AZX_INT_ALL_STREAM);
  389. }
  390. /**
  391. * snd_hdac_bus_init_chip - reset and start the controller registers
  392. * @bus: HD-audio core bus
  393. * @full_reset: Do full reset
  394. */
  395. bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset)
  396. {
  397. if (bus->chip_init)
  398. return false;
  399. /* reset controller */
  400. snd_hdac_bus_reset_link(bus, full_reset);
  401. /* clear interrupts */
  402. azx_int_clear(bus);
  403. /* initialize the codec command I/O */
  404. snd_hdac_bus_init_cmd_io(bus);
  405. /* enable interrupts after CORB/RIRB buffers are initialized above */
  406. azx_int_enable(bus);
  407. /* program the position buffer */
  408. if (bus->use_posbuf && bus->posbuf.addr) {
  409. snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr);
  410. snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr));
  411. }
  412. bus->chip_init = true;
  413. return true;
  414. }
  415. EXPORT_SYMBOL_GPL(snd_hdac_bus_init_chip);
  416. /**
  417. * snd_hdac_bus_stop_chip - disable the whole IRQ and I/Os
  418. * @bus: HD-audio core bus
  419. */
  420. void snd_hdac_bus_stop_chip(struct hdac_bus *bus)
  421. {
  422. if (!bus->chip_init)
  423. return;
  424. /* disable interrupts */
  425. azx_int_disable(bus);
  426. azx_int_clear(bus);
  427. /* disable CORB/RIRB */
  428. snd_hdac_bus_stop_cmd_io(bus);
  429. /* disable position buffer */
  430. if (bus->posbuf.addr) {
  431. snd_hdac_chip_writel(bus, DPLBASE, 0);
  432. snd_hdac_chip_writel(bus, DPUBASE, 0);
  433. }
  434. bus->chip_init = false;
  435. }
  436. EXPORT_SYMBOL_GPL(snd_hdac_bus_stop_chip);
  437. /**
  438. * snd_hdac_bus_handle_stream_irq - interrupt handler for streams
  439. * @bus: HD-audio core bus
  440. * @status: INTSTS register value
  441. * @ask: callback to be called for woken streams
  442. *
  443. * Returns the bits of handled streams, or zero if no stream is handled.
  444. */
  445. int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status,
  446. void (*ack)(struct hdac_bus *,
  447. struct hdac_stream *))
  448. {
  449. struct hdac_stream *azx_dev;
  450. u8 sd_status;
  451. int handled = 0;
  452. list_for_each_entry(azx_dev, &bus->stream_list, list) {
  453. if (status & azx_dev->sd_int_sta_mask) {
  454. sd_status = snd_hdac_stream_readb(azx_dev, SD_STS);
  455. snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK);
  456. handled |= 1 << azx_dev->index;
  457. if (!azx_dev->substream || !azx_dev->running ||
  458. !(sd_status & SD_INT_COMPLETE))
  459. continue;
  460. if (ack)
  461. ack(bus, azx_dev);
  462. }
  463. }
  464. return handled;
  465. }
  466. EXPORT_SYMBOL_GPL(snd_hdac_bus_handle_stream_irq);
  467. /**
  468. * snd_hdac_bus_alloc_stream_pages - allocate BDL and other buffers
  469. * @bus: HD-audio core bus
  470. *
  471. * Call this after assigning the all streams.
  472. * Returns zero for success, or a negative error code.
  473. */
  474. int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus)
  475. {
  476. struct hdac_stream *s;
  477. int num_streams = 0;
  478. int err;
  479. list_for_each_entry(s, &bus->stream_list, list) {
  480. /* allocate memory for the BDL for each stream */
  481. err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV,
  482. BDL_SIZE, &s->bdl);
  483. num_streams++;
  484. if (err < 0)
  485. return -ENOMEM;
  486. }
  487. if (WARN_ON(!num_streams))
  488. return -EINVAL;
  489. /* allocate memory for the position buffer */
  490. err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV,
  491. num_streams * 8, &bus->posbuf);
  492. if (err < 0)
  493. return -ENOMEM;
  494. list_for_each_entry(s, &bus->stream_list, list)
  495. s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8);
  496. /* single page (at least 4096 bytes) must suffice for both ringbuffes */
  497. return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV,
  498. PAGE_SIZE, &bus->rb);
  499. }
  500. EXPORT_SYMBOL_GPL(snd_hdac_bus_alloc_stream_pages);
  501. /**
  502. * snd_hdac_bus_free_stream_pages - release BDL and other buffers
  503. * @bus: HD-audio core bus
  504. */
  505. void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus)
  506. {
  507. struct hdac_stream *s;
  508. list_for_each_entry(s, &bus->stream_list, list) {
  509. if (s->bdl.area)
  510. bus->io_ops->dma_free_pages(bus, &s->bdl);
  511. }
  512. if (bus->rb.area)
  513. bus->io_ops->dma_free_pages(bus, &bus->rb);
  514. if (bus->posbuf.area)
  515. bus->io_ops->dma_free_pages(bus, &bus->posbuf);
  516. }
  517. EXPORT_SYMBOL_GPL(snd_hdac_bus_free_stream_pages);