mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 21:51:40 +00:00
6aa7de0591
Please do not apply this to mainline directly, instead please re-run the coccinelle script shown below and apply its output. For several reasons, it is desirable to use {READ,WRITE}_ONCE() in preference to ACCESS_ONCE(), and new code is expected to use one of the former. So far, there's been no reason to change most existing uses of ACCESS_ONCE(), as these aren't harmful, and changing them results in churn. However, for some features, the read/write distinction is critical to correct operation. To distinguish these cases, separate read/write accessors must be used. This patch migrates (most) remaining ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following coccinelle script: ---- // Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and // WRITE_ONCE() // $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch virtual patch @ depends on patch @ expression E1, E2; @@ - ACCESS_ONCE(E1) = E2 + WRITE_ONCE(E1, E2) @ depends on patch @ expression E; @@ - ACCESS_ONCE(E) + READ_ONCE(E) ---- Signed-off-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: davem@davemloft.net Cc: linux-arch@vger.kernel.org Cc: mpe@ellerman.id.au Cc: shuah@kernel.org Cc: snitzer@redhat.com Cc: thor.thayer@linux.intel.com Cc: tj@kernel.org Cc: viro@zeniv.linux.org.uk Cc: will.deacon@arm.com Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
156 lines
3.7 KiB
C
156 lines
3.7 KiB
C
/*
|
|
* amdtp-ff.c - a part of driver for RME Fireface series
|
|
*
|
|
* Copyright (c) 2015-2017 Takashi Sakamoto
|
|
*
|
|
* Licensed under the terms of the GNU General Public License, version 2.
|
|
*/
|
|
|
|
#include <sound/pcm.h>
|
|
#include "ff.h"
|
|
|
|
struct amdtp_ff {
|
|
unsigned int pcm_channels;
|
|
};
|
|
|
|
int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
|
|
unsigned int pcm_channels)
|
|
{
|
|
struct amdtp_ff *p = s->protocol;
|
|
unsigned int data_channels;
|
|
|
|
if (amdtp_stream_running(s))
|
|
return -EBUSY;
|
|
|
|
p->pcm_channels = pcm_channels;
|
|
data_channels = pcm_channels;
|
|
|
|
return amdtp_stream_set_parameters(s, rate, data_channels);
|
|
}
|
|
|
|
static void write_pcm_s32(struct amdtp_stream *s,
|
|
struct snd_pcm_substream *pcm,
|
|
__le32 *buffer, unsigned int frames)
|
|
{
|
|
struct amdtp_ff *p = s->protocol;
|
|
struct snd_pcm_runtime *runtime = pcm->runtime;
|
|
unsigned int channels, remaining_frames, i, c;
|
|
const u32 *src;
|
|
|
|
channels = p->pcm_channels;
|
|
src = (void *)runtime->dma_area +
|
|
frames_to_bytes(runtime, s->pcm_buffer_pointer);
|
|
remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
|
|
|
|
for (i = 0; i < frames; ++i) {
|
|
for (c = 0; c < channels; ++c) {
|
|
buffer[c] = cpu_to_le32(*src);
|
|
src++;
|
|
}
|
|
buffer += s->data_block_quadlets;
|
|
if (--remaining_frames == 0)
|
|
src = (void *)runtime->dma_area;
|
|
}
|
|
}
|
|
|
|
static void read_pcm_s32(struct amdtp_stream *s,
|
|
struct snd_pcm_substream *pcm,
|
|
__le32 *buffer, unsigned int frames)
|
|
{
|
|
struct amdtp_ff *p = s->protocol;
|
|
struct snd_pcm_runtime *runtime = pcm->runtime;
|
|
unsigned int channels, remaining_frames, i, c;
|
|
u32 *dst;
|
|
|
|
channels = p->pcm_channels;
|
|
dst = (void *)runtime->dma_area +
|
|
frames_to_bytes(runtime, s->pcm_buffer_pointer);
|
|
remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
|
|
|
|
for (i = 0; i < frames; ++i) {
|
|
for (c = 0; c < channels; ++c) {
|
|
*dst = le32_to_cpu(buffer[c]) & 0xffffff00;
|
|
dst++;
|
|
}
|
|
buffer += s->data_block_quadlets;
|
|
if (--remaining_frames == 0)
|
|
dst = (void *)runtime->dma_area;
|
|
}
|
|
}
|
|
|
|
static void write_pcm_silence(struct amdtp_stream *s,
|
|
__le32 *buffer, unsigned int frames)
|
|
{
|
|
struct amdtp_ff *p = s->protocol;
|
|
unsigned int i, c, channels = p->pcm_channels;
|
|
|
|
for (i = 0; i < frames; ++i) {
|
|
for (c = 0; c < channels; ++c)
|
|
buffer[c] = cpu_to_le32(0x00000000);
|
|
buffer += s->data_block_quadlets;
|
|
}
|
|
}
|
|
|
|
int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
|
|
struct snd_pcm_runtime *runtime)
|
|
{
|
|
int err;
|
|
|
|
err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
return amdtp_stream_add_pcm_hw_constraints(s, runtime);
|
|
}
|
|
|
|
static unsigned int process_rx_data_blocks(struct amdtp_stream *s,
|
|
__be32 *buffer,
|
|
unsigned int data_blocks,
|
|
unsigned int *syt)
|
|
{
|
|
struct snd_pcm_substream *pcm = READ_ONCE(s->pcm);
|
|
unsigned int pcm_frames;
|
|
|
|
if (pcm) {
|
|
write_pcm_s32(s, pcm, (__le32 *)buffer, data_blocks);
|
|
pcm_frames = data_blocks;
|
|
} else {
|
|
write_pcm_silence(s, (__le32 *)buffer, data_blocks);
|
|
pcm_frames = 0;
|
|
}
|
|
|
|
return pcm_frames;
|
|
}
|
|
|
|
static unsigned int process_tx_data_blocks(struct amdtp_stream *s,
|
|
__be32 *buffer,
|
|
unsigned int data_blocks,
|
|
unsigned int *syt)
|
|
{
|
|
struct snd_pcm_substream *pcm = READ_ONCE(s->pcm);
|
|
unsigned int pcm_frames;
|
|
|
|
if (pcm) {
|
|
read_pcm_s32(s, pcm, (__le32 *)buffer, data_blocks);
|
|
pcm_frames = data_blocks;
|
|
} else {
|
|
pcm_frames = 0;
|
|
}
|
|
|
|
return pcm_frames;
|
|
}
|
|
|
|
int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
|
|
enum amdtp_stream_direction dir)
|
|
{
|
|
amdtp_stream_process_data_blocks_t process_data_blocks;
|
|
|
|
if (dir == AMDTP_IN_STREAM)
|
|
process_data_blocks = process_tx_data_blocks;
|
|
else
|
|
process_data_blocks = process_rx_data_blocks;
|
|
|
|
return amdtp_stream_init(s, unit, dir, CIP_NO_HEADER, 0,
|
|
process_data_blocks, sizeof(struct amdtp_ff));
|
|
}
|