Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Audio and Music Data Transmission Protocol (IEC 61883-6) streams |
| 3 | * with Common Isochronous Packet (IEC 61883-1) headers |
| 4 | * |
| 5 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
| 6 | * Licensed under the terms of the GNU General Public License, version 2. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/device.h> |
| 10 | #include <linux/err.h> |
| 11 | #include <linux/firewire.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/slab.h> |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 14 | #include <linux/sched.h> |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 15 | #include <sound/pcm.h> |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 16 | #include <sound/rawmidi.h> |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 17 | #include "amdtp.h" |
| 18 | |
| 19 | #define TICKS_PER_CYCLE 3072 |
| 20 | #define CYCLES_PER_SECOND 8000 |
| 21 | #define TICKS_PER_SECOND (TICKS_PER_CYCLE * CYCLES_PER_SECOND) |
| 22 | |
| 23 | #define TRANSFER_DELAY_TICKS 0x2e00 /* 479.17 µs */ |
| 24 | |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 25 | /* isochronous header parameters */ |
| 26 | #define ISO_DATA_LENGTH_SHIFT 16 |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 27 | #define TAG_CIP 1 |
| 28 | |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 29 | /* common isochronous packet header parameters */ |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 30 | #define CIP_EOH (1u << 31) |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 31 | #define CIP_EOH_MASK 0x80000000 |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 32 | #define CIP_FMT_AM (0x10 << 24) |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 33 | #define CIP_FMT_MASK 0x3f000000 |
| 34 | #define CIP_SYT_MASK 0x0000ffff |
| 35 | #define CIP_SYT_NO_INFO 0xffff |
| 36 | #define CIP_FDF_MASK 0x00ff0000 |
| 37 | #define CIP_FDF_SFC_SHIFT 16 |
| 38 | |
| 39 | /* |
| 40 | * Audio and Music transfer protocol specific parameters |
| 41 | * only "Clock-based rate control mode" is supported |
| 42 | */ |
| 43 | #define AMDTP_FDF_AM824 (0 << (CIP_FDF_SFC_SHIFT + 3)) |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 44 | #define AMDTP_FDF_NO_DATA 0xff |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 45 | #define AMDTP_DBS_MASK 0x00ff0000 |
| 46 | #define AMDTP_DBS_SHIFT 16 |
| 47 | #define AMDTP_DBC_MASK 0x000000ff |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 48 | |
| 49 | /* TODO: make these configurable */ |
| 50 | #define INTERRUPT_INTERVAL 16 |
| 51 | #define QUEUE_LENGTH 48 |
| 52 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 53 | #define IN_PACKET_HEADER_SIZE 4 |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 54 | #define OUT_PACKET_HEADER_SIZE 0 |
| 55 | |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 56 | static void pcm_period_tasklet(unsigned long data); |
| 57 | |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 58 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 59 | * amdtp_stream_init - initialize an AMDTP stream structure |
| 60 | * @s: the AMDTP stream to initialize |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 61 | * @unit: the target of the stream |
Takashi Sakamoto | 3ff7e8f | 2014-04-25 22:44:44 +0900 | [diff] [blame] | 62 | * @dir: the direction of stream |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 63 | * @flags: the packet transmission method to use |
| 64 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 65 | int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit, |
Takashi Sakamoto | 3ff7e8f | 2014-04-25 22:44:44 +0900 | [diff] [blame] | 66 | enum amdtp_stream_direction dir, enum cip_flags flags) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 67 | { |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 68 | s->unit = fw_unit_get(unit); |
Takashi Sakamoto | 3ff7e8f | 2014-04-25 22:44:44 +0900 | [diff] [blame] | 69 | s->direction = dir; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 70 | s->flags = flags; |
| 71 | s->context = ERR_PTR(-1); |
| 72 | mutex_init(&s->mutex); |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 73 | tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s); |
Clemens Ladisch | ec00f5e | 2011-03-15 07:57:24 +0100 | [diff] [blame] | 74 | s->packet_index = 0; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 75 | |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 76 | init_waitqueue_head(&s->callback_wait); |
| 77 | s->callbacked = false; |
| 78 | s->sync_slave = NULL; |
| 79 | |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 80 | return 0; |
| 81 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 82 | EXPORT_SYMBOL(amdtp_stream_init); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 83 | |
| 84 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 85 | * amdtp_stream_destroy - free stream resources |
| 86 | * @s: the AMDTP stream to destroy |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 87 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 88 | void amdtp_stream_destroy(struct amdtp_stream *s) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 89 | { |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 90 | WARN_ON(amdtp_stream_running(s)); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 91 | mutex_destroy(&s->mutex); |
| 92 | fw_unit_put(s->unit); |
| 93 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 94 | EXPORT_SYMBOL(amdtp_stream_destroy); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 95 | |
Clemens Ladisch | c5280e9 | 2011-10-16 21:39:00 +0200 | [diff] [blame] | 96 | const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = { |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 97 | [CIP_SFC_32000] = 8, |
| 98 | [CIP_SFC_44100] = 8, |
| 99 | [CIP_SFC_48000] = 8, |
| 100 | [CIP_SFC_88200] = 16, |
| 101 | [CIP_SFC_96000] = 16, |
| 102 | [CIP_SFC_176400] = 32, |
| 103 | [CIP_SFC_192000] = 32, |
| 104 | }; |
| 105 | EXPORT_SYMBOL(amdtp_syt_intervals); |
| 106 | |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 107 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 108 | * amdtp_stream_set_parameters - set stream parameters |
| 109 | * @s: the AMDTP stream to configure |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 110 | * @rate: the sample rate |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 111 | * @pcm_channels: the number of PCM samples in each data block, to be encoded |
| 112 | * as AM824 multi-bit linear audio |
| 113 | * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 114 | * |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 115 | * The parameters must be set before the stream is started, and must not be |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 116 | * changed while the stream is running. |
| 117 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 118 | void amdtp_stream_set_parameters(struct amdtp_stream *s, |
| 119 | unsigned int rate, |
| 120 | unsigned int pcm_channels, |
| 121 | unsigned int midi_ports) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 122 | { |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 123 | static const unsigned int rates[] = { |
| 124 | [CIP_SFC_32000] = 32000, |
| 125 | [CIP_SFC_44100] = 44100, |
| 126 | [CIP_SFC_48000] = 48000, |
| 127 | [CIP_SFC_88200] = 88200, |
| 128 | [CIP_SFC_96000] = 96000, |
| 129 | [CIP_SFC_176400] = 176400, |
| 130 | [CIP_SFC_192000] = 192000, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 131 | }; |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 132 | unsigned int i, sfc, midi_channels; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 133 | |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 134 | midi_channels = DIV_ROUND_UP(midi_ports, 8); |
| 135 | |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 136 | if (WARN_ON(amdtp_stream_running(s)) | |
| 137 | WARN_ON(pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM) | |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 138 | WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI)) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 139 | return; |
| 140 | |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 141 | for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc) |
| 142 | if (rates[sfc] == rate) |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 143 | goto sfc_found; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 144 | WARN_ON(1); |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 145 | return; |
| 146 | |
| 147 | sfc_found: |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame^] | 148 | s->pcm_channels = pcm_channels; |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 149 | s->sfc = sfc; |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 150 | s->data_block_quadlets = s->pcm_channels + midi_channels; |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 151 | s->midi_ports = midi_ports; |
| 152 | |
| 153 | s->syt_interval = amdtp_syt_intervals[sfc]; |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 154 | |
| 155 | /* default buffering in the device */ |
| 156 | s->transfer_delay = TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE; |
| 157 | if (s->flags & CIP_BLOCKING) |
| 158 | /* additional buffering needed to adjust for no-data packets */ |
| 159 | s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate; |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 160 | |
| 161 | /* init the position map for PCM and MIDI channels */ |
| 162 | for (i = 0; i < pcm_channels; i++) |
| 163 | s->pcm_positions[i] = i; |
| 164 | s->midi_position = s->pcm_channels; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 165 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 166 | EXPORT_SYMBOL(amdtp_stream_set_parameters); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 167 | |
| 168 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 169 | * amdtp_stream_get_max_payload - get the stream's packet size |
| 170 | * @s: the AMDTP stream |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 171 | * |
| 172 | * This function must not be called before the stream has been configured |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 173 | * with amdtp_stream_set_parameters(). |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 174 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 175 | unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 176 | { |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 177 | return 8 + s->syt_interval * s->data_block_quadlets * 4; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 178 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 179 | EXPORT_SYMBOL(amdtp_stream_get_max_payload); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 180 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 181 | static void amdtp_write_s16(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 182 | struct snd_pcm_substream *pcm, |
| 183 | __be32 *buffer, unsigned int frames); |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 184 | static void amdtp_write_s32(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 185 | struct snd_pcm_substream *pcm, |
| 186 | __be32 *buffer, unsigned int frames); |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 187 | static void amdtp_read_s32(struct amdtp_stream *s, |
| 188 | struct snd_pcm_substream *pcm, |
| 189 | __be32 *buffer, unsigned int frames); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 190 | |
| 191 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 192 | * amdtp_stream_set_pcm_format - set the PCM format |
| 193 | * @s: the AMDTP stream to configure |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 194 | * @format: the format of the ALSA PCM device |
| 195 | * |
Clemens Ladisch | a7304e3 | 2011-09-04 22:16:10 +0200 | [diff] [blame] | 196 | * The sample format must be set after the other paramters (rate/PCM channels/ |
| 197 | * MIDI) and before the stream is started, and must not be changed while the |
| 198 | * stream is running. |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 199 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 200 | void amdtp_stream_set_pcm_format(struct amdtp_stream *s, |
| 201 | snd_pcm_format_t format) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 202 | { |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 203 | if (WARN_ON(amdtp_stream_pcm_running(s))) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 204 | return; |
| 205 | |
| 206 | switch (format) { |
| 207 | default: |
| 208 | WARN_ON(1); |
| 209 | /* fall through */ |
| 210 | case SNDRV_PCM_FORMAT_S16: |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 211 | if (s->direction == AMDTP_OUT_STREAM) { |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame^] | 212 | s->transfer_samples = amdtp_write_s16; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | WARN_ON(1); |
| 216 | /* fall through */ |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 217 | case SNDRV_PCM_FORMAT_S32: |
Takashi Sakamoto | 10550be | 2014-04-25 22:44:51 +0900 | [diff] [blame^] | 218 | if (s->direction == AMDTP_OUT_STREAM) |
| 219 | s->transfer_samples = amdtp_write_s32; |
| 220 | else |
| 221 | s->transfer_samples = amdtp_read_s32; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 225 | EXPORT_SYMBOL(amdtp_stream_set_pcm_format); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 226 | |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 227 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 228 | * amdtp_stream_pcm_prepare - prepare PCM device for running |
| 229 | * @s: the AMDTP stream |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 230 | * |
| 231 | * This function should be called from the PCM device's .prepare callback. |
| 232 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 233 | void amdtp_stream_pcm_prepare(struct amdtp_stream *s) |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 234 | { |
| 235 | tasklet_kill(&s->period_tasklet); |
| 236 | s->pcm_buffer_pointer = 0; |
| 237 | s->pcm_period_pointer = 0; |
Clemens Ladisch | 92b862c | 2012-05-13 19:07:22 +0200 | [diff] [blame] | 238 | s->pointer_flush = true; |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 239 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 240 | EXPORT_SYMBOL(amdtp_stream_pcm_prepare); |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 241 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 242 | static unsigned int calculate_data_blocks(struct amdtp_stream *s) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 243 | { |
| 244 | unsigned int phase, data_blocks; |
| 245 | |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 246 | if (s->flags & CIP_BLOCKING) |
| 247 | data_blocks = s->syt_interval; |
| 248 | else if (!cip_sfc_is_base_44100(s->sfc)) { |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 249 | /* Sample_rate / 8000 is an integer, and precomputed. */ |
| 250 | data_blocks = s->data_block_state; |
| 251 | } else { |
| 252 | phase = s->data_block_state; |
| 253 | |
| 254 | /* |
| 255 | * This calculates the number of data blocks per packet so that |
| 256 | * 1) the overall rate is correct and exactly synchronized to |
| 257 | * the bus clock, and |
| 258 | * 2) packets with a rounded-up number of blocks occur as early |
| 259 | * as possible in the sequence (to prevent underruns of the |
| 260 | * device's buffer). |
| 261 | */ |
| 262 | if (s->sfc == CIP_SFC_44100) |
| 263 | /* 6 6 5 6 5 6 5 ... */ |
| 264 | data_blocks = 5 + ((phase & 1) ^ |
| 265 | (phase == 0 || phase >= 40)); |
| 266 | else |
| 267 | /* 12 11 11 11 11 ... or 23 22 22 22 22 ... */ |
| 268 | data_blocks = 11 * (s->sfc >> 1) + (phase == 0); |
| 269 | if (++phase >= (80 >> (s->sfc >> 1))) |
| 270 | phase = 0; |
| 271 | s->data_block_state = phase; |
| 272 | } |
| 273 | |
| 274 | return data_blocks; |
| 275 | } |
| 276 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 277 | static unsigned int calculate_syt(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 278 | unsigned int cycle) |
| 279 | { |
| 280 | unsigned int syt_offset, phase, index, syt; |
| 281 | |
| 282 | if (s->last_syt_offset < TICKS_PER_CYCLE) { |
| 283 | if (!cip_sfc_is_base_44100(s->sfc)) |
| 284 | syt_offset = s->last_syt_offset + s->syt_offset_state; |
| 285 | else { |
| 286 | /* |
| 287 | * The time, in ticks, of the n'th SYT_INTERVAL sample is: |
| 288 | * n * SYT_INTERVAL * 24576000 / sample_rate |
| 289 | * Modulo TICKS_PER_CYCLE, the difference between successive |
| 290 | * elements is about 1386.23. Rounding the results of this |
| 291 | * formula to the SYT precision results in a sequence of |
| 292 | * differences that begins with: |
| 293 | * 1386 1386 1387 1386 1386 1386 1387 1386 1386 1386 1387 ... |
| 294 | * This code generates _exactly_ the same sequence. |
| 295 | */ |
| 296 | phase = s->syt_offset_state; |
| 297 | index = phase % 13; |
| 298 | syt_offset = s->last_syt_offset; |
| 299 | syt_offset += 1386 + ((index && !(index & 3)) || |
| 300 | phase == 146); |
| 301 | if (++phase >= 147) |
| 302 | phase = 0; |
| 303 | s->syt_offset_state = phase; |
| 304 | } |
| 305 | } else |
| 306 | syt_offset = s->last_syt_offset - TICKS_PER_CYCLE; |
| 307 | s->last_syt_offset = syt_offset; |
| 308 | |
Clemens Ladisch | be45436 | 2011-03-15 07:55:02 +0100 | [diff] [blame] | 309 | if (syt_offset < TICKS_PER_CYCLE) { |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 310 | syt_offset += s->transfer_delay; |
Clemens Ladisch | be45436 | 2011-03-15 07:55:02 +0100 | [diff] [blame] | 311 | syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12; |
| 312 | syt += syt_offset % TICKS_PER_CYCLE; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 313 | |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 314 | return syt & CIP_SYT_MASK; |
Clemens Ladisch | be45436 | 2011-03-15 07:55:02 +0100 | [diff] [blame] | 315 | } else { |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 316 | return CIP_SYT_NO_INFO; |
Clemens Ladisch | be45436 | 2011-03-15 07:55:02 +0100 | [diff] [blame] | 317 | } |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 318 | } |
| 319 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 320 | static void amdtp_write_s32(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 321 | struct snd_pcm_substream *pcm, |
| 322 | __be32 *buffer, unsigned int frames) |
| 323 | { |
| 324 | struct snd_pcm_runtime *runtime = pcm->runtime; |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 325 | unsigned int channels, remaining_frames, i, c; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 326 | const u32 *src; |
| 327 | |
| 328 | channels = s->pcm_channels; |
| 329 | src = (void *)runtime->dma_area + |
Takashi Sakamoto | e84841f | 2013-09-14 00:35:47 +0900 | [diff] [blame] | 330 | frames_to_bytes(runtime, s->pcm_buffer_pointer); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 331 | remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 332 | |
| 333 | for (i = 0; i < frames; ++i) { |
| 334 | for (c = 0; c < channels; ++c) { |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 335 | buffer[s->pcm_positions[c]] = |
| 336 | cpu_to_be32((*src >> 8) | 0x40000000); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 337 | src++; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 338 | } |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 339 | buffer += s->data_block_quadlets; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 340 | if (--remaining_frames == 0) |
| 341 | src = (void *)runtime->dma_area; |
| 342 | } |
| 343 | } |
| 344 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 345 | static void amdtp_write_s16(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 346 | struct snd_pcm_substream *pcm, |
| 347 | __be32 *buffer, unsigned int frames) |
| 348 | { |
| 349 | struct snd_pcm_runtime *runtime = pcm->runtime; |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 350 | unsigned int channels, remaining_frames, i, c; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 351 | const u16 *src; |
| 352 | |
| 353 | channels = s->pcm_channels; |
| 354 | src = (void *)runtime->dma_area + |
Takashi Sakamoto | e84841f | 2013-09-14 00:35:47 +0900 | [diff] [blame] | 355 | frames_to_bytes(runtime, s->pcm_buffer_pointer); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 356 | remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 357 | |
| 358 | for (i = 0; i < frames; ++i) { |
| 359 | for (c = 0; c < channels; ++c) { |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 360 | buffer[s->pcm_positions[c]] = |
| 361 | cpu_to_be32((*src << 8) | 0x40000000); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 362 | src++; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 363 | } |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 364 | buffer += s->data_block_quadlets; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 365 | if (--remaining_frames == 0) |
| 366 | src = (void *)runtime->dma_area; |
| 367 | } |
| 368 | } |
| 369 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 370 | static void amdtp_read_s32(struct amdtp_stream *s, |
| 371 | struct snd_pcm_substream *pcm, |
| 372 | __be32 *buffer, unsigned int frames) |
| 373 | { |
| 374 | struct snd_pcm_runtime *runtime = pcm->runtime; |
| 375 | unsigned int channels, remaining_frames, i, c; |
| 376 | u32 *dst; |
| 377 | |
| 378 | channels = s->pcm_channels; |
| 379 | dst = (void *)runtime->dma_area + |
| 380 | frames_to_bytes(runtime, s->pcm_buffer_pointer); |
| 381 | remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; |
| 382 | |
| 383 | for (i = 0; i < frames; ++i) { |
| 384 | for (c = 0; c < channels; ++c) { |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 385 | *dst = be32_to_cpu(buffer[s->pcm_positions[c]]) << 8; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 386 | dst++; |
| 387 | } |
| 388 | buffer += s->data_block_quadlets; |
| 389 | if (--remaining_frames == 0) |
| 390 | dst = (void *)runtime->dma_area; |
| 391 | } |
| 392 | } |
| 393 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 394 | static void amdtp_fill_pcm_silence(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 395 | __be32 *buffer, unsigned int frames) |
| 396 | { |
| 397 | unsigned int i, c; |
| 398 | |
| 399 | for (i = 0; i < frames; ++i) { |
| 400 | for (c = 0; c < s->pcm_channels; ++c) |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 401 | buffer[s->pcm_positions[c]] = cpu_to_be32(0x40000000); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 402 | buffer += s->data_block_quadlets; |
| 403 | } |
| 404 | } |
| 405 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 406 | static void amdtp_fill_midi(struct amdtp_stream *s, |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 407 | __be32 *buffer, unsigned int frames) |
| 408 | { |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 409 | unsigned int f, port; |
| 410 | u8 *b; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 411 | |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 412 | for (f = 0; f < frames; f++) { |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 413 | buffer[s->midi_position] = 0; |
| 414 | b = (u8 *)&buffer[s->midi_position]; |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 415 | |
| 416 | port = (s->data_block_counter + f) % 8; |
| 417 | if ((s->midi[port] == NULL) || |
| 418 | (snd_rawmidi_transmit(s->midi[port], b + 1, 1) <= 0)) |
| 419 | b[0] = 0x80; |
| 420 | else |
| 421 | b[0] = 0x81; |
| 422 | |
| 423 | buffer += s->data_block_quadlets; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | static void amdtp_pull_midi(struct amdtp_stream *s, |
| 428 | __be32 *buffer, unsigned int frames) |
| 429 | { |
| 430 | unsigned int f, port; |
| 431 | int len; |
| 432 | u8 *b; |
| 433 | |
| 434 | for (f = 0; f < frames; f++) { |
| 435 | port = (s->data_block_counter + f) % 8; |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 436 | b = (u8 *)&buffer[s->midi_position]; |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 437 | |
| 438 | len = b[0] - 0x80; |
| 439 | if ((1 <= len) && (len <= 3) && (s->midi[port])) |
| 440 | snd_rawmidi_receive(s->midi[port], b + 1, len); |
| 441 | |
| 442 | buffer += s->data_block_quadlets; |
| 443 | } |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 446 | static void update_pcm_pointers(struct amdtp_stream *s, |
| 447 | struct snd_pcm_substream *pcm, |
| 448 | unsigned int frames) |
| 449 | { unsigned int ptr; |
| 450 | |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 451 | ptr = s->pcm_buffer_pointer + frames; |
| 452 | if (ptr >= pcm->runtime->buffer_size) |
| 453 | ptr -= pcm->runtime->buffer_size; |
| 454 | ACCESS_ONCE(s->pcm_buffer_pointer) = ptr; |
| 455 | |
| 456 | s->pcm_period_pointer += frames; |
| 457 | if (s->pcm_period_pointer >= pcm->runtime->period_size) { |
| 458 | s->pcm_period_pointer -= pcm->runtime->period_size; |
| 459 | s->pointer_flush = false; |
| 460 | tasklet_hi_schedule(&s->period_tasklet); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | static void pcm_period_tasklet(unsigned long data) |
| 465 | { |
| 466 | struct amdtp_stream *s = (void *)data; |
| 467 | struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm); |
| 468 | |
| 469 | if (pcm) |
| 470 | snd_pcm_period_elapsed(pcm); |
| 471 | } |
| 472 | |
| 473 | static int queue_packet(struct amdtp_stream *s, |
| 474 | unsigned int header_length, |
| 475 | unsigned int payload_length, bool skip) |
| 476 | { |
| 477 | struct fw_iso_packet p = {0}; |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 478 | int err = 0; |
| 479 | |
| 480 | if (IS_ERR(s->context)) |
| 481 | goto end; |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 482 | |
| 483 | p.interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL); |
| 484 | p.tag = TAG_CIP; |
| 485 | p.header_length = header_length; |
| 486 | p.payload_length = (!skip) ? payload_length : 0; |
| 487 | p.skip = skip; |
| 488 | err = fw_iso_context_queue(s->context, &p, &s->buffer.iso_buffer, |
| 489 | s->buffer.packets[s->packet_index].offset); |
| 490 | if (err < 0) { |
| 491 | dev_err(&s->unit->device, "queueing error: %d\n", err); |
| 492 | goto end; |
| 493 | } |
| 494 | |
| 495 | if (++s->packet_index >= QUEUE_LENGTH) |
| 496 | s->packet_index = 0; |
| 497 | end: |
| 498 | return err; |
| 499 | } |
| 500 | |
| 501 | static inline int queue_out_packet(struct amdtp_stream *s, |
| 502 | unsigned int payload_length, bool skip) |
| 503 | { |
| 504 | return queue_packet(s, OUT_PACKET_HEADER_SIZE, |
| 505 | payload_length, skip); |
| 506 | } |
| 507 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 508 | static inline int queue_in_packet(struct amdtp_stream *s) |
| 509 | { |
| 510 | return queue_packet(s, IN_PACKET_HEADER_SIZE, |
| 511 | amdtp_stream_get_max_payload(s), false); |
| 512 | } |
| 513 | |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 514 | static void handle_out_packet(struct amdtp_stream *s, unsigned int syt) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 515 | { |
| 516 | __be32 *buffer; |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 517 | unsigned int data_blocks, payload_length; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 518 | struct snd_pcm_substream *pcm; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 519 | |
Clemens Ladisch | ec00f5e | 2011-03-15 07:57:24 +0100 | [diff] [blame] | 520 | if (s->packet_index < 0) |
| 521 | return; |
Clemens Ladisch | ec00f5e | 2011-03-15 07:57:24 +0100 | [diff] [blame] | 522 | |
Takashi Sakamoto | 82755ab | 2013-11-21 14:21:06 +0900 | [diff] [blame] | 523 | /* this module generate empty packet for 'no data' */ |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 524 | if (!(s->flags & CIP_BLOCKING) || (syt != CIP_SYT_NO_INFO)) |
Clemens Ladisch | e84d15f | 2011-09-04 22:12:48 +0200 | [diff] [blame] | 525 | data_blocks = calculate_data_blocks(s); |
Takashi Sakamoto | 82755ab | 2013-11-21 14:21:06 +0900 | [diff] [blame] | 526 | else |
| 527 | data_blocks = 0; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 528 | |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 529 | buffer = s->buffer.packets[s->packet_index].buffer; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 530 | buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) | |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 531 | (s->data_block_quadlets << AMDTP_DBS_SHIFT) | |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 532 | s->data_block_counter); |
| 533 | buffer[1] = cpu_to_be32(CIP_EOH | CIP_FMT_AM | AMDTP_FDF_AM824 | |
Takashi Sakamoto | b445db4 | 2014-04-25 22:44:43 +0900 | [diff] [blame] | 534 | (s->sfc << CIP_FDF_SFC_SHIFT) | syt); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 535 | buffer += 2; |
| 536 | |
| 537 | pcm = ACCESS_ONCE(s->pcm); |
| 538 | if (pcm) |
| 539 | s->transfer_samples(s, pcm, buffer, data_blocks); |
| 540 | else |
| 541 | amdtp_fill_pcm_silence(s, buffer, data_blocks); |
| 542 | if (s->midi_ports) |
| 543 | amdtp_fill_midi(s, buffer, data_blocks); |
| 544 | |
| 545 | s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff; |
| 546 | |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 547 | payload_length = 8 + data_blocks * 4 * s->data_block_quadlets; |
| 548 | if (queue_out_packet(s, payload_length, false) < 0) { |
Clemens Ladisch | ec00f5e | 2011-03-15 07:57:24 +0100 | [diff] [blame] | 549 | s->packet_index = -1; |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 550 | amdtp_stream_pcm_abort(s); |
Clemens Ladisch | ec00f5e | 2011-03-15 07:57:24 +0100 | [diff] [blame] | 551 | return; |
| 552 | } |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 553 | |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 554 | if (pcm) |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 555 | update_pcm_pointers(s, pcm, data_blocks); |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 556 | } |
| 557 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 558 | static void handle_in_packet(struct amdtp_stream *s, |
| 559 | unsigned int payload_quadlets, |
| 560 | __be32 *buffer) |
| 561 | { |
| 562 | u32 cip_header[2]; |
| 563 | unsigned int data_blocks, data_block_quadlets, data_block_counter; |
| 564 | struct snd_pcm_substream *pcm = NULL; |
| 565 | |
| 566 | cip_header[0] = be32_to_cpu(buffer[0]); |
| 567 | cip_header[1] = be32_to_cpu(buffer[1]); |
| 568 | |
| 569 | /* |
| 570 | * This module supports 'Two-quadlet CIP header with SYT field'. |
Takashi Sakamoto | 77d2a8a | 2014-04-25 22:44:50 +0900 | [diff] [blame] | 571 | * For convenience, also check FMT field is AM824 or not. |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 572 | */ |
| 573 | if (((cip_header[0] & CIP_EOH_MASK) == CIP_EOH) || |
| 574 | ((cip_header[1] & CIP_EOH_MASK) != CIP_EOH) || |
| 575 | ((cip_header[1] & CIP_FMT_MASK) != CIP_FMT_AM)) { |
| 576 | dev_info_ratelimited(&s->unit->device, |
| 577 | "Invalid CIP header for AMDTP: %08X:%08X\n", |
| 578 | cip_header[0], cip_header[1]); |
| 579 | goto end; |
| 580 | } |
| 581 | |
| 582 | /* Calculate data blocks */ |
| 583 | if (payload_quadlets < 3 || |
| 584 | ((cip_header[1] & CIP_FDF_MASK) == |
| 585 | (AMDTP_FDF_NO_DATA << CIP_FDF_SFC_SHIFT))) { |
| 586 | data_blocks = 0; |
| 587 | } else { |
| 588 | data_block_quadlets = |
| 589 | (cip_header[0] & AMDTP_DBS_MASK) >> AMDTP_DBS_SHIFT; |
| 590 | /* avoid division by zero */ |
| 591 | if (data_block_quadlets == 0) { |
| 592 | dev_info_ratelimited(&s->unit->device, |
| 593 | "Detect invalid value in dbs field: %08X\n", |
| 594 | cip_header[0]); |
| 595 | goto err; |
| 596 | } |
| 597 | |
| 598 | data_blocks = (payload_quadlets - 2) / data_block_quadlets; |
| 599 | } |
| 600 | |
| 601 | /* Check data block counter continuity */ |
| 602 | data_block_counter = cip_header[0] & AMDTP_DBC_MASK; |
| 603 | if (data_block_counter != s->data_block_counter) { |
| 604 | dev_info(&s->unit->device, |
| 605 | "Detect discontinuity of CIP: %02X %02X\n", |
| 606 | s->data_block_counter, data_block_counter); |
| 607 | goto err; |
| 608 | } |
| 609 | |
| 610 | if (data_blocks > 0) { |
| 611 | buffer += 2; |
| 612 | |
| 613 | pcm = ACCESS_ONCE(s->pcm); |
| 614 | if (pcm) |
| 615 | s->transfer_samples(s, pcm, buffer, data_blocks); |
Takashi Sakamoto | 83d8d72 | 2014-04-25 22:44:47 +0900 | [diff] [blame] | 616 | |
| 617 | if (s->midi_ports) |
| 618 | amdtp_pull_midi(s, buffer, data_blocks); |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | s->data_block_counter = (data_block_counter + data_blocks) & 0xff; |
| 622 | end: |
| 623 | if (queue_in_packet(s) < 0) |
| 624 | goto err; |
| 625 | |
| 626 | if (pcm) |
| 627 | update_pcm_pointers(s, pcm, data_blocks); |
| 628 | |
| 629 | return; |
| 630 | err: |
| 631 | s->packet_index = -1; |
| 632 | amdtp_stream_pcm_abort(s); |
| 633 | } |
| 634 | |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 635 | static void out_stream_callback(struct fw_iso_context *context, u32 cycle, |
| 636 | size_t header_length, void *header, |
| 637 | void *private_data) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 638 | { |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 639 | struct amdtp_stream *s = private_data; |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 640 | unsigned int i, syt, packets = header_length / 4; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 641 | |
| 642 | /* |
| 643 | * Compute the cycle of the last queued packet. |
| 644 | * (We need only the four lowest bits for the SYT, so we can ignore |
| 645 | * that bits 0-11 must wrap around at 3072.) |
| 646 | */ |
| 647 | cycle += QUEUE_LENGTH - packets; |
| 648 | |
Takashi Sakamoto | ccccad8 | 2014-04-25 22:44:48 +0900 | [diff] [blame] | 649 | for (i = 0; i < packets; ++i) { |
| 650 | syt = calculate_syt(s, ++cycle); |
| 651 | handle_out_packet(s, syt); |
| 652 | } |
Clemens Ladisch | 13882a8 | 2011-05-02 09:33:56 +0200 | [diff] [blame] | 653 | fw_iso_context_queue_flush(s->context); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 656 | static void in_stream_callback(struct fw_iso_context *context, u32 cycle, |
| 657 | size_t header_length, void *header, |
| 658 | void *private_data) |
| 659 | { |
| 660 | struct amdtp_stream *s = private_data; |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 661 | unsigned int p, syt, packets, payload_quadlets; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 662 | __be32 *buffer, *headers = header; |
| 663 | |
| 664 | /* The number of packets in buffer */ |
| 665 | packets = header_length / IN_PACKET_HEADER_SIZE; |
| 666 | |
| 667 | for (p = 0; p < packets; p++) { |
| 668 | if (s->packet_index < 0) |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 669 | break; |
| 670 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 671 | buffer = s->buffer.packets[s->packet_index].buffer; |
| 672 | |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 673 | /* Process sync slave stream */ |
| 674 | if (s->sync_slave && s->sync_slave->callbacked) { |
| 675 | syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK; |
| 676 | handle_out_packet(s->sync_slave, syt); |
| 677 | } |
| 678 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 679 | /* The number of quadlets in this packet */ |
| 680 | payload_quadlets = |
| 681 | (be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4; |
| 682 | handle_in_packet(s, payload_quadlets, buffer); |
| 683 | } |
| 684 | |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 685 | /* Queueing error or detecting discontinuity */ |
| 686 | if (s->packet_index < 0) { |
| 687 | /* Abort sync slave. */ |
| 688 | if (s->sync_slave) { |
| 689 | s->sync_slave->packet_index = -1; |
| 690 | amdtp_stream_pcm_abort(s->sync_slave); |
| 691 | } |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | /* when sync to device, flush the packets for slave stream */ |
| 696 | if (s->sync_slave && s->sync_slave->callbacked) |
| 697 | fw_iso_context_queue_flush(s->sync_slave->context); |
| 698 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 699 | fw_iso_context_queue_flush(s->context); |
| 700 | } |
| 701 | |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 702 | /* processing is done by master callback */ |
| 703 | static void slave_stream_callback(struct fw_iso_context *context, u32 cycle, |
| 704 | size_t header_length, void *header, |
| 705 | void *private_data) |
| 706 | { |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | /* this is executed one time */ |
| 711 | static void amdtp_stream_first_callback(struct fw_iso_context *context, |
| 712 | u32 cycle, size_t header_length, |
| 713 | void *header, void *private_data) |
| 714 | { |
| 715 | struct amdtp_stream *s = private_data; |
| 716 | |
| 717 | /* |
| 718 | * For in-stream, first packet has come. |
| 719 | * For out-stream, prepared to transmit first packet |
| 720 | */ |
| 721 | s->callbacked = true; |
| 722 | wake_up(&s->callback_wait); |
| 723 | |
| 724 | if (s->direction == AMDTP_IN_STREAM) |
| 725 | context->callback.sc = in_stream_callback; |
| 726 | else if ((s->flags & CIP_BLOCKING) && (s->flags & CIP_SYNC_TO_DEVICE)) |
| 727 | context->callback.sc = slave_stream_callback; |
| 728 | else |
| 729 | context->callback.sc = out_stream_callback; |
| 730 | |
| 731 | context->callback.sc(context, cycle, header_length, header, s); |
| 732 | } |
| 733 | |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 734 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 735 | * amdtp_stream_start - start transferring packets |
| 736 | * @s: the AMDTP stream to start |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 737 | * @channel: the isochronous channel on the bus |
| 738 | * @speed: firewire speed code |
| 739 | * |
| 740 | * The stream cannot be started until it has been configured with |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 741 | * amdtp_stream_set_parameters() and it must be started before any PCM or MIDI |
| 742 | * device can be started. |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 743 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 744 | int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 745 | { |
| 746 | static const struct { |
| 747 | unsigned int data_block; |
| 748 | unsigned int syt_offset; |
| 749 | } initial_state[] = { |
| 750 | [CIP_SFC_32000] = { 4, 3072 }, |
| 751 | [CIP_SFC_48000] = { 6, 1024 }, |
| 752 | [CIP_SFC_96000] = { 12, 1024 }, |
| 753 | [CIP_SFC_192000] = { 24, 1024 }, |
| 754 | [CIP_SFC_44100] = { 0, 67 }, |
| 755 | [CIP_SFC_88200] = { 0, 67 }, |
| 756 | [CIP_SFC_176400] = { 0, 67 }, |
| 757 | }; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 758 | unsigned int header_size; |
| 759 | enum dma_data_direction dir; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 760 | int type, err; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 761 | |
| 762 | mutex_lock(&s->mutex); |
| 763 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 764 | if (WARN_ON(amdtp_stream_running(s) || |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 765 | (s->data_block_quadlets < 1))) { |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 766 | err = -EBADFD; |
| 767 | goto err_unlock; |
| 768 | } |
| 769 | |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 770 | s->data_block_counter = 0; |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 771 | s->data_block_state = initial_state[s->sfc].data_block; |
| 772 | s->syt_offset_state = initial_state[s->sfc].syt_offset; |
| 773 | s->last_syt_offset = TICKS_PER_CYCLE; |
| 774 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 775 | /* initialize packet buffer */ |
| 776 | if (s->direction == AMDTP_IN_STREAM) { |
| 777 | dir = DMA_FROM_DEVICE; |
| 778 | type = FW_ISO_CONTEXT_RECEIVE; |
| 779 | header_size = IN_PACKET_HEADER_SIZE; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 780 | } else { |
| 781 | dir = DMA_TO_DEVICE; |
| 782 | type = FW_ISO_CONTEXT_TRANSMIT; |
| 783 | header_size = OUT_PACKET_HEADER_SIZE; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 784 | } |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 785 | err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH, |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 786 | amdtp_stream_get_max_payload(s), dir); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 787 | if (err < 0) |
| 788 | goto err_unlock; |
| 789 | |
| 790 | s->context = fw_iso_context_create(fw_parent_device(s->unit)->card, |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 791 | type, channel, speed, header_size, |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 792 | amdtp_stream_first_callback, s); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 793 | if (IS_ERR(s->context)) { |
| 794 | err = PTR_ERR(s->context); |
| 795 | if (err == -EBUSY) |
| 796 | dev_err(&s->unit->device, |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 797 | "no free stream on this controller\n"); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 798 | goto err_buffer; |
| 799 | } |
| 800 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 801 | amdtp_stream_update(s); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 802 | |
Clemens Ladisch | ec00f5e | 2011-03-15 07:57:24 +0100 | [diff] [blame] | 803 | s->packet_index = 0; |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 804 | do { |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 805 | if (s->direction == AMDTP_IN_STREAM) |
| 806 | err = queue_in_packet(s); |
| 807 | else |
| 808 | err = queue_out_packet(s, 0, true); |
Takashi Sakamoto | 4b7da11 | 2014-04-25 22:44:45 +0900 | [diff] [blame] | 809 | if (err < 0) |
| 810 | goto err_context; |
| 811 | } while (s->packet_index > 0); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 812 | |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 813 | /* NOTE: TAG1 matches CIP. This just affects in stream. */ |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 814 | s->callbacked = false; |
Takashi Sakamoto | 2b3fc45 | 2014-04-25 22:44:46 +0900 | [diff] [blame] | 815 | err = fw_iso_context_start(s->context, -1, 0, |
| 816 | FW_ISO_CONTEXT_MATCH_TAG1); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 817 | if (err < 0) |
| 818 | goto err_context; |
| 819 | |
| 820 | mutex_unlock(&s->mutex); |
| 821 | |
| 822 | return 0; |
| 823 | |
| 824 | err_context: |
| 825 | fw_iso_context_destroy(s->context); |
| 826 | s->context = ERR_PTR(-1); |
| 827 | err_buffer: |
| 828 | iso_packets_buffer_destroy(&s->buffer, s->unit); |
| 829 | err_unlock: |
| 830 | mutex_unlock(&s->mutex); |
| 831 | |
| 832 | return err; |
| 833 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 834 | EXPORT_SYMBOL(amdtp_stream_start); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 835 | |
| 836 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 837 | * amdtp_stream_pcm_pointer - get the PCM buffer position |
| 838 | * @s: the AMDTP stream that transports the PCM data |
Clemens Ladisch | e9148dd | 2012-05-13 18:49:14 +0200 | [diff] [blame] | 839 | * |
| 840 | * Returns the current buffer position, in frames. |
| 841 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 842 | unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s) |
Clemens Ladisch | e9148dd | 2012-05-13 18:49:14 +0200 | [diff] [blame] | 843 | { |
Clemens Ladisch | 92b862c | 2012-05-13 19:07:22 +0200 | [diff] [blame] | 844 | /* this optimization is allowed to be racy */ |
| 845 | if (s->pointer_flush) |
| 846 | fw_iso_context_flush_completions(s->context); |
| 847 | else |
| 848 | s->pointer_flush = true; |
Clemens Ladisch | e9148dd | 2012-05-13 18:49:14 +0200 | [diff] [blame] | 849 | |
| 850 | return ACCESS_ONCE(s->pcm_buffer_pointer); |
| 851 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 852 | EXPORT_SYMBOL(amdtp_stream_pcm_pointer); |
Clemens Ladisch | e9148dd | 2012-05-13 18:49:14 +0200 | [diff] [blame] | 853 | |
| 854 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 855 | * amdtp_stream_update - update the stream after a bus reset |
| 856 | * @s: the AMDTP stream |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 857 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 858 | void amdtp_stream_update(struct amdtp_stream *s) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 859 | { |
| 860 | ACCESS_ONCE(s->source_node_id_field) = |
| 861 | (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24; |
| 862 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 863 | EXPORT_SYMBOL(amdtp_stream_update); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 864 | |
| 865 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 866 | * amdtp_stream_stop - stop sending packets |
| 867 | * @s: the AMDTP stream to stop |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 868 | * |
| 869 | * All PCM and MIDI devices of the stream must be stopped before the stream |
| 870 | * itself can be stopped. |
| 871 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 872 | void amdtp_stream_stop(struct amdtp_stream *s) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 873 | { |
| 874 | mutex_lock(&s->mutex); |
| 875 | |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 876 | if (!amdtp_stream_running(s)) { |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 877 | mutex_unlock(&s->mutex); |
| 878 | return; |
| 879 | } |
| 880 | |
Clemens Ladisch | 76fb878 | 2012-05-13 22:03:09 +0200 | [diff] [blame] | 881 | tasklet_kill(&s->period_tasklet); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 882 | fw_iso_context_stop(s->context); |
| 883 | fw_iso_context_destroy(s->context); |
| 884 | s->context = ERR_PTR(-1); |
| 885 | iso_packets_buffer_destroy(&s->buffer, s->unit); |
| 886 | |
Takashi Sakamoto | 7b3b0d8 | 2014-04-25 22:44:49 +0900 | [diff] [blame] | 887 | s->callbacked = false; |
| 888 | |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 889 | mutex_unlock(&s->mutex); |
| 890 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 891 | EXPORT_SYMBOL(amdtp_stream_stop); |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 892 | |
| 893 | /** |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 894 | * amdtp_stream_pcm_abort - abort the running PCM device |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 895 | * @s: the AMDTP stream about to be stopped |
| 896 | * |
| 897 | * If the isochronous stream needs to be stopped asynchronously, call this |
| 898 | * function first to stop the PCM device. |
| 899 | */ |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 900 | void amdtp_stream_pcm_abort(struct amdtp_stream *s) |
Clemens Ladisch | 31ef913 | 2011-03-15 07:53:21 +0100 | [diff] [blame] | 901 | { |
| 902 | struct snd_pcm_substream *pcm; |
| 903 | |
| 904 | pcm = ACCESS_ONCE(s->pcm); |
| 905 | if (pcm) { |
| 906 | snd_pcm_stream_lock_irq(pcm); |
| 907 | if (snd_pcm_running(pcm)) |
| 908 | snd_pcm_stop(pcm, SNDRV_PCM_STATE_XRUN); |
| 909 | snd_pcm_stream_unlock_irq(pcm); |
| 910 | } |
| 911 | } |
Takashi Sakamoto | be4a289 | 2014-04-25 22:44:42 +0900 | [diff] [blame] | 912 | EXPORT_SYMBOL(amdtp_stream_pcm_abort); |