21 #include <linux/kernel.h>
24 #include <linux/pci.h>
30 #define LOLA_MAX_BDL_ENTRIES 8
31 #define LOLA_MAX_BUF_SIZE (1024*1024*1024)
32 #define LOLA_BDL_ENTRY_SIZE (16 * 16)
47 static unsigned int lola_get_lrc(
struct lola *
chip)
52 static unsigned int lola_get_tstamp(
struct lola *
chip,
bool quick_no_sync)
54 unsigned int tstamp = lola_get_lrc(chip) >> 8;
56 unsigned int wait_banks = quick_no_sync ? 0 : 8;
64 static void lola_stream_clear_pending_irq(
struct lola *chip,
73 static void lola_stream_start(
struct lola *chip,
struct lola_stream *str,
76 lola_stream_clear_pending_irq(chip, str);
85 static void lola_stream_stop(
struct lola *chip,
struct lola_stream *str,
93 lola_stream_clear_pending_irq(chip, str);
96 static void wait_for_srst_clear(
struct lola *chip,
struct lola_stream *str)
109 static int lola_stream_wait_for_fifo(
struct lola *chip,
128 static int lola_sync_wait_for_fifo(
struct lola *chip,
141 if (s->
pcm->card != substream->
pcm->card)
143 str = lola_get_stream(s);
148 pending = str->
dsd + 1;
164 static void lola_sync_pause(
struct lola *chip,
169 lola_sync_wait_for_fifo(chip, substream,
false);
172 if (s->
pcm->card != substream->
pcm->card)
174 str = lola_get_stream(s);
179 lola_sync_wait_for_fifo(chip, substream,
true);
182 static void lola_stream_reset(
struct lola *chip,
struct lola_stream *str)
190 lola_stream_wait_for_fifo(chip, str,
false);
191 lola_stream_clear_pending_irq(chip, str);
196 wait_for_srst_clear(chip, str);
216 .period_bytes_min = 128,
227 struct lola_stream *str = lola_get_stream(substream);
238 runtime->
hw = lola_pcm_hw;
259 static void lola_cleanup_slave_streams(
struct lola_pcm *pcm,
263 for (i = str->
index + 1; i < pcm->num_streams; i++) {
275 struct lola_stream *str = lola_get_stream(substream);
293 struct lola_stream *str = lola_get_stream(substream);
305 struct lola_pcm *pcm = lola_get_pcm(substream);
306 struct lola_stream *str = lola_get_stream(substream);
309 lola_stream_reset(chip, str);
310 lola_cleanup_slave_streams(pcm, str);
331 addr = snd_pcm_sgbuf_get_addr(substream, ofs);
336 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
354 static int lola_setup_periods(
struct lola *chip,
struct lola_pcm *pcm,
368 for (i = 0; i < periods; i++) {
369 ofs = setup_bdle(substream, str, &bdl, ofs, period_bytes);
385 switch (substream->
runtime->format) {
401 verb |= substream->
runtime->channels;
405 static int lola_set_stream_config(
struct lola *chip,
425 verb = (str->
index << 6) | i;
440 static int lola_setup_controller(
struct lola *chip,
struct lola_pcm *pcm,
454 lola_stream_clear_pending_irq(chip, str);
461 return lola_stream_wait_for_fifo(chip, str,
true);
467 struct lola_pcm *pcm = lola_get_pcm(substream);
468 struct lola_stream *str = lola_get_stream(substream);
470 unsigned int bufsize, period_bytes, format_verb;
474 lola_stream_reset(chip, str);
475 lola_cleanup_slave_streams(pcm, str);
480 for (i = 1; i < runtime->
channels; i++) {
486 bufsize = snd_pcm_lib_buffer_bytes(substream);
487 period_bytes = snd_pcm_lib_period_bytes(substream);
488 format_verb = lola_get_format_verb(substream);
494 err = lola_setup_periods(chip, pcm, substream, str);
503 err = lola_set_stream_config(chip, str, runtime->
channels);
507 err = lola_setup_controller(chip, pcm, str);
509 lola_stream_reset(chip, str);
544 sync_streams = (start && snd_pcm_stream_linked(substream));
545 tstamp = lola_get_tstamp(chip, !sync_streams);
548 if (s->
pcm->card != substream->
pcm->card)
550 str = lola_get_stream(s);
552 lola_stream_start(chip, str, tstamp);
554 lola_stream_stop(chip, str, tstamp);
557 snd_pcm_trigger_done(s, substream);
566 struct lola_stream *str = lola_get_stream(substream);
571 return bytes_to_frames(substream->
runtime, pos);
579 if (bits & (1 << i)) {
589 .open = lola_pcm_open,
590 .close = lola_pcm_close,
592 .hw_params = lola_pcm_hw_params,
593 .hw_free = lola_pcm_hw_free,
594 .prepare = lola_pcm_prepare,
595 .trigger = lola_pcm_trigger,
596 .pointer = lola_pcm_pointer,
605 for (i = 0; i < 2; i++) {
621 for (i = 0; i < 2; i++) {
622 if (chip->
pcm[i].num_streams)
628 1024 * 64, 32 * 1024 * 1024);
641 static int lola_init_stream(
struct lola *chip,
struct lola_stream *str,
642 int idx,
int nid,
int dir)
659 if ((val & 0x00f00dff) != 0x00000010) {
668 if ((val & 0x00f00cff) != 0x00100010) {
674 if ((val & 0x00001200) == 0x00001200)
700 err = lola_init_stream(chip, &pcm->
streams[i], i, nid, dir);