9 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
17 #define TICKS_PER_CYCLE 3072
18 #define CYCLES_PER_SECOND 8000
19 #define TICKS_PER_SECOND (TICKS_PER_CYCLE * CYCLES_PER_SECOND)
21 #define TRANSFER_DELAY_TICKS 0x2e00
25 #define CIP_EOH (1u << 31)
26 #define CIP_FMT_AM (0x10 << 24)
27 #define AMDTP_FDF_AM824 (0 << 19)
28 #define AMDTP_FDF_SFC_SHIFT 16
31 #define INTERRUPT_INTERVAL 16
32 #define QUEUE_LENGTH 48
34 static void pcm_period_tasklet(
unsigned long data);
48 s->
unit = fw_unit_get(unit);
83 unsigned int syt_interval;
118 static const unsigned int max_data_blocks[] = {
160 case SNDRV_PCM_FORMAT_S16:
163 case SNDRV_PCM_FORMAT_S32:
187 unsigned int phase, data_blocks;
189 if (!cip_sfc_is_base_44100(s->
sfc)) {
205 data_blocks = 5 + ((phase & 1) ^
206 (phase == 0 || phase >= 40));
209 data_blocks = 11 * (s->
sfc >> 1) + (phase == 0);
210 if (++phase >= (80 >> (s->
sfc >> 1)))
224 if (!cip_sfc_is_base_44100(s->
sfc))
240 syt_offset += 1386 + ((index && !(index & 3)) ||
266 unsigned int channels, remaining_frames, frame_step,
i,
c;
275 for (i = 0; i < frames; ++
i) {
281 buffer += frame_step;
282 if (--remaining_frames == 0)
289 __be32 *buffer,
unsigned int frames)
292 unsigned int channels, remaining_frames, frame_step,
i,
c;
301 for (i = 0; i < frames; ++
i) {
307 buffer += frame_step;
308 if (--remaining_frames == 0)
314 __be32 *buffer,
unsigned int frames)
318 for (i = 0; i < frames; ++
i) {
326 __be32 *buffer,
unsigned int frames)
330 for (i = 0; i < frames; ++
i)
335 static void queue_out_packet(
struct amdtp_out_stream *s,
unsigned int cycle)
338 unsigned int index, data_blocks, syt,
ptr;
347 data_blocks = calculate_data_blocks(s);
348 syt = calculate_syt(s, cycle);
362 amdtp_fill_pcm_silence(s, buffer, data_blocks);
364 amdtp_fill_midi(s, buffer, data_blocks);
376 s->
buffer.packets[index].offset);
378 dev_err(&s->
unit->device,
"queueing error: %d\n", err);
390 if (ptr >= pcm->
runtime->buffer_size)
391 ptr -= pcm->
runtime->buffer_size;
403 static void pcm_period_tasklet(
unsigned long data)
416 unsigned int i,
packets = header_length / 4;
426 queue_out_packet(s, ++cycle);
464 static const struct {
465 unsigned int data_block;
466 unsigned int syt_offset;
467 } initial_state[] = {
499 out_packet_callback, s);
504 "no free output stream on this controller\n");
512 err = queue_initial_skip_packets(s);
561 (fw_parent_device(s->
unit)->card->node_id & 0x3f) << 24;
604 snd_pcm_stream_lock_irq(pcm);
605 if (snd_pcm_running(pcm))
607 snd_pcm_stream_unlock_irq(pcm);