2 * amdtp-ff.c - a part of driver for RME Fireface series
4 * Copyright (c) 2015-2017 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
13 unsigned int pcm_channels
;
16 int amdtp_ff_set_parameters(struct amdtp_stream
*s
, unsigned int rate
,
17 unsigned int pcm_channels
)
19 struct amdtp_ff
*p
= s
->protocol
;
20 unsigned int data_channels
;
22 if (amdtp_stream_running(s
))
25 p
->pcm_channels
= pcm_channels
;
26 data_channels
= pcm_channels
;
28 return amdtp_stream_set_parameters(s
, rate
, data_channels
);
31 static void write_pcm_s32(struct amdtp_stream
*s
,
32 struct snd_pcm_substream
*pcm
,
33 __le32
*buffer
, unsigned int frames
)
35 struct amdtp_ff
*p
= s
->protocol
;
36 struct snd_pcm_runtime
*runtime
= pcm
->runtime
;
37 unsigned int channels
, remaining_frames
, i
, c
;
40 channels
= p
->pcm_channels
;
41 src
= (void *)runtime
->dma_area
+
42 frames_to_bytes(runtime
, s
->pcm_buffer_pointer
);
43 remaining_frames
= runtime
->buffer_size
- s
->pcm_buffer_pointer
;
45 for (i
= 0; i
< frames
; ++i
) {
46 for (c
= 0; c
< channels
; ++c
) {
47 buffer
[c
] = cpu_to_le32(*src
);
50 buffer
+= s
->data_block_quadlets
;
51 if (--remaining_frames
== 0)
52 src
= (void *)runtime
->dma_area
;
56 static void read_pcm_s32(struct amdtp_stream
*s
,
57 struct snd_pcm_substream
*pcm
,
58 __le32
*buffer
, unsigned int frames
)
60 struct amdtp_ff
*p
= s
->protocol
;
61 struct snd_pcm_runtime
*runtime
= pcm
->runtime
;
62 unsigned int channels
, remaining_frames
, i
, c
;
65 channels
= p
->pcm_channels
;
66 dst
= (void *)runtime
->dma_area
+
67 frames_to_bytes(runtime
, s
->pcm_buffer_pointer
);
68 remaining_frames
= runtime
->buffer_size
- s
->pcm_buffer_pointer
;
70 for (i
= 0; i
< frames
; ++i
) {
71 for (c
= 0; c
< channels
; ++c
) {
72 *dst
= le32_to_cpu(buffer
[c
]) & 0xffffff00;
75 buffer
+= s
->data_block_quadlets
;
76 if (--remaining_frames
== 0)
77 dst
= (void *)runtime
->dma_area
;
81 static void write_pcm_silence(struct amdtp_stream
*s
,
82 __le32
*buffer
, unsigned int frames
)
84 struct amdtp_ff
*p
= s
->protocol
;
85 unsigned int i
, c
, channels
= p
->pcm_channels
;
87 for (i
= 0; i
< frames
; ++i
) {
88 for (c
= 0; c
< channels
; ++c
)
89 buffer
[c
] = cpu_to_le32(0x00000000);
90 buffer
+= s
->data_block_quadlets
;
94 int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream
*s
,
95 struct snd_pcm_runtime
*runtime
)
99 err
= snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
103 return amdtp_stream_add_pcm_hw_constraints(s
, runtime
);
106 static unsigned int process_rx_data_blocks(struct amdtp_stream
*s
,
108 unsigned int data_blocks
,
111 struct snd_pcm_substream
*pcm
= READ_ONCE(s
->pcm
);
112 unsigned int pcm_frames
;
115 write_pcm_s32(s
, pcm
, (__le32
*)buffer
, data_blocks
);
116 pcm_frames
= data_blocks
;
118 write_pcm_silence(s
, (__le32
*)buffer
, data_blocks
);
125 static unsigned int process_tx_data_blocks(struct amdtp_stream
*s
,
127 unsigned int data_blocks
,
130 struct snd_pcm_substream
*pcm
= READ_ONCE(s
->pcm
);
131 unsigned int pcm_frames
;
134 read_pcm_s32(s
, pcm
, (__le32
*)buffer
, data_blocks
);
135 pcm_frames
= data_blocks
;
143 int amdtp_ff_init(struct amdtp_stream
*s
, struct fw_unit
*unit
,
144 enum amdtp_stream_direction dir
)
146 amdtp_stream_process_data_blocks_t process_data_blocks
;
148 if (dir
== AMDTP_IN_STREAM
)
149 process_data_blocks
= process_tx_data_blocks
;
151 process_data_blocks
= process_rx_data_blocks
;
153 return amdtp_stream_init(s
, unit
, dir
, CIP_NO_HEADER
, 0,
154 process_data_blocks
, sizeof(struct amdtp_ff
));