2 * oxfw_pcm.c - a part of driver for OXFW970/971 based devices
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
10 static int firewave_rate_constraint(struct snd_pcm_hw_params *params,
11 struct snd_pcm_hw_rule *rule)
13 static unsigned int stereo_rates[] = { 48000, 96000 };
14 struct snd_interval *channels =
15 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
16 struct snd_interval *rate =
17 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
19 /* two channels work only at 48/96 kHz */
20 if (snd_interval_max(channels) < 6)
21 return snd_interval_list(rate, 2, stereo_rates, 0);
25 static int firewave_channels_constraint(struct snd_pcm_hw_params *params,
26 struct snd_pcm_hw_rule *rule)
28 static const struct snd_interval all_channels = { .min = 6, .max = 6 };
29 struct snd_interval *rate =
30 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
31 struct snd_interval *channels =
32 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
34 /* 32/44.1 kHz work only with all six channels */
35 if (snd_interval_max(rate) < 48000)
36 return snd_interval_refine(channels, &all_channels);
40 int firewave_constraints(struct snd_pcm_runtime *runtime)
42 static unsigned int channels_list[] = { 2, 6 };
43 static struct snd_pcm_hw_constraint_list channels_list_constraint = {
45 .list = channels_list,
49 runtime->hw.rates = SNDRV_PCM_RATE_32000 |
50 SNDRV_PCM_RATE_44100 |
51 SNDRV_PCM_RATE_48000 |
53 runtime->hw.channels_max = 6;
55 err = snd_pcm_hw_constraint_list(runtime, 0,
56 SNDRV_PCM_HW_PARAM_CHANNELS,
57 &channels_list_constraint);
60 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
61 firewave_rate_constraint, NULL,
62 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
65 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
66 firewave_channels_constraint, NULL,
67 SNDRV_PCM_HW_PARAM_RATE, -1);
74 int lacie_speakers_constraints(struct snd_pcm_runtime *runtime)
76 runtime->hw.rates = SNDRV_PCM_RATE_32000 |
77 SNDRV_PCM_RATE_44100 |
78 SNDRV_PCM_RATE_48000 |
79 SNDRV_PCM_RATE_88200 |
85 static int pcm_open(struct snd_pcm_substream *substream)
87 static const struct snd_pcm_hardware hardware = {
88 .info = SNDRV_PCM_INFO_MMAP |
89 SNDRV_PCM_INFO_MMAP_VALID |
90 SNDRV_PCM_INFO_BATCH |
91 SNDRV_PCM_INFO_INTERLEAVED |
92 SNDRV_PCM_INFO_BLOCK_TRANSFER,
93 .formats = AMDTP_OUT_PCM_FORMAT_BITS,
96 .buffer_bytes_max = 4 * 1024 * 1024,
97 .period_bytes_min = 1,
98 .period_bytes_max = UINT_MAX,
100 .periods_max = UINT_MAX,
102 struct snd_oxfw *oxfw = substream->private_data;
103 struct snd_pcm_runtime *runtime = substream->runtime;
107 err = cmp_connection_check_used(&oxfw->in_conn, &used);
108 if ((err < 0) || used)
111 runtime->hw = hardware;
113 err = oxfw->device_info->pcm_constraints(runtime);
116 err = snd_pcm_limit_hw_rates(runtime);
120 err = amdtp_stream_add_pcm_hw_constraints(&oxfw->rx_stream, runtime);
125 static int pcm_close(struct snd_pcm_substream *substream)
130 static int pcm_hw_params(struct snd_pcm_substream *substream,
131 struct snd_pcm_hw_params *hw_params)
133 struct snd_oxfw *oxfw = substream->private_data;
136 mutex_lock(&oxfw->mutex);
138 snd_oxfw_stream_stop_simplex(oxfw);
140 err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
141 params_buffer_bytes(hw_params));
145 amdtp_stream_set_parameters(&oxfw->rx_stream,
146 params_rate(hw_params),
147 params_channels(hw_params),
150 amdtp_stream_set_pcm_format(&oxfw->rx_stream,
151 params_format(hw_params));
153 err = avc_general_set_sig_fmt(oxfw->unit, params_rate(hw_params),
154 AVC_GENERAL_PLUG_DIR_IN, 0);
156 dev_err(&oxfw->unit->device, "failed to set sample rate\n");
163 snd_pcm_lib_free_vmalloc_buffer(substream);
165 mutex_unlock(&oxfw->mutex);
169 static int pcm_hw_free(struct snd_pcm_substream *substream)
171 struct snd_oxfw *oxfw = substream->private_data;
173 mutex_lock(&oxfw->mutex);
174 snd_oxfw_stream_stop_simplex(oxfw);
175 mutex_unlock(&oxfw->mutex);
177 return snd_pcm_lib_free_vmalloc_buffer(substream);
180 static int pcm_prepare(struct snd_pcm_substream *substream)
182 struct snd_oxfw *oxfw = substream->private_data;
185 mutex_lock(&oxfw->mutex);
187 snd_oxfw_stream_stop_simplex(oxfw);
189 err = snd_oxfw_stream_start_simplex(oxfw);
193 amdtp_stream_pcm_prepare(&oxfw->rx_stream);
195 mutex_unlock(&oxfw->mutex);
199 static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
201 struct snd_oxfw *oxfw = substream->private_data;
202 struct snd_pcm_substream *pcm;
205 case SNDRV_PCM_TRIGGER_START:
208 case SNDRV_PCM_TRIGGER_STOP:
214 amdtp_stream_pcm_trigger(&oxfw->rx_stream, pcm);
218 static snd_pcm_uframes_t pcm_pointer(struct snd_pcm_substream *substream)
220 struct snd_oxfw *oxfw = substream->private_data;
222 return amdtp_stream_pcm_pointer(&oxfw->rx_stream);
225 int snd_oxfw_create_pcm(struct snd_oxfw *oxfw)
227 static struct snd_pcm_ops ops = {
230 .ioctl = snd_pcm_lib_ioctl,
231 .hw_params = pcm_hw_params,
232 .hw_free = pcm_hw_free,
233 .prepare = pcm_prepare,
234 .trigger = pcm_trigger,
235 .pointer = pcm_pointer,
236 .page = snd_pcm_lib_get_vmalloc_page,
237 .mmap = snd_pcm_lib_mmap_vmalloc,
242 err = snd_pcm_new(oxfw->card, oxfw->card->driver, 0, 1, 0, &pcm);
245 pcm->private_data = oxfw;
246 strcpy(pcm->name, oxfw->card->shortname);
247 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &ops);