blob: c06903304e120d25d74a8b8bac8175d2058d2de1 [file] [log] [blame]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001/*
2 * Asihpi soundcard
3 * Copyright (c) by AudioScience Inc <alsa@audioscience.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 *
19 * The following is not a condition of use, merely a request:
20 * If you modify this program, particularly if you fix errors, AudioScience Inc
21 * would appreciate it if you grant us the right to use those modifications
22 * for any purpose including commercial applications.
23 */
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +130024
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020025#include "hpi_internal.h"
Eliot Blennerhassettf50efa22011-12-22 13:38:48 +130026#include "hpi_version.h"
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020027#include "hpimsginit.h"
28#include "hpioctl.h"
Eliot Blennerhassett7036b922011-12-22 13:38:43 +130029#include "hpicmn.h"
30
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020031#include <linux/pci.h>
32#include <linux/init.h>
33#include <linux/jiffies.h>
34#include <linux/slab.h>
35#include <linux/time.h>
36#include <linux/wait.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040037#include <linux/module.h>
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020038#include <sound/core.h>
39#include <sound/control.h>
40#include <sound/pcm.h>
41#include <sound/pcm_params.h>
42#include <sound/info.h>
43#include <sound/initval.h>
44#include <sound/tlv.h>
45#include <sound/hwdep.h>
46
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020047MODULE_LICENSE("GPL");
48MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
Eliot Blennerhassette9886ab2014-11-20 16:22:48 +130049MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx "
Eliot Blennerhassettf50efa22011-12-22 13:38:48 +130050 HPI_VER_STRING);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020051
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +130052#if defined CONFIG_SND_DEBUG_VERBOSE
53/**
54 * snd_printddd - very verbose debug printk
55 * @format: format string
56 *
57 * Works like snd_printk() for debugging purposes.
58 * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
59 * Must set snd module debug parameter to 3 to enable at runtime.
60 */
61#define snd_printddd(format, args...) \
62 __snd_printk(3, __FILE__, __LINE__, format, ##args)
63#else
Eliot Blennerhassettb0096a62011-04-05 20:55:46 +120064#define snd_printddd(format, args...) do { } while (0)
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +130065#endif
66
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020067static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */
68static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103069static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
70static bool enable_hpi_hwdep = 1;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020071
72module_param_array(index, int, NULL, S_IRUGO);
73MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard.");
74
75module_param_array(id, charp, NULL, S_IRUGO);
76MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard.");
77
78module_param_array(enable, bool, NULL, S_IRUGO);
79MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard.");
80
81module_param(enable_hpi_hwdep, bool, S_IRUGO|S_IWUSR);
82MODULE_PARM_DESC(enable_hpi_hwdep,
83 "ALSA enable HPI hwdep for AudioScience soundcard ");
84
85/* identify driver */
86#ifdef KERNEL_ALSA_BUILD
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +130087static char *build_info = "Built using headers from kernel source";
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020088module_param(build_info, charp, S_IRUGO);
Eliot Blennerhassette9886ab2014-11-20 16:22:48 +130089MODULE_PARM_DESC(build_info, "Built using headers from kernel source");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020090#else
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +130091static char *build_info = "Built within ALSA source";
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020092module_param(build_info, charp, S_IRUGO);
Eliot Blennerhassette9886ab2014-11-20 16:22:48 +130093MODULE_PARM_DESC(build_info, "Built within ALSA source");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020094#endif
95
96/* set to 1 to dump every control from adapter to log */
97static const int mixer_dump;
98
99#define DEFAULT_SAMPLERATE 44100
100static int adapter_fs = DEFAULT_SAMPLERATE;
101
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200102/* defaults */
103#define PERIODS_MIN 2
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300104#define PERIOD_BYTES_MIN 2048
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200105#define BUFFER_BYTES_MAX (512 * 1024)
106
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200107#define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
108
109struct clk_source {
110 int source;
111 int index;
Eliot Blennerhassett3872f192014-11-20 16:22:49 +1300112 const char *name;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200113};
114
115struct clk_cache {
116 int count;
117 int has_local;
118 struct clk_source s[MAX_CLOCKSOURCES];
119};
120
121/* Per card data */
122struct snd_card_asihpi {
123 struct snd_card *card;
124 struct pci_dev *pci;
Eliot Blennerhassett7036b922011-12-22 13:38:43 +1300125 struct hpi_adapter *hpi;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200126
127 u32 h_mixer;
128 struct clk_cache cc;
129
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200130 u16 can_dma;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200131 u16 support_grouping;
132 u16 support_mrx;
133 u16 update_interval_frames;
134 u16 in_max_chans;
135 u16 out_max_chans;
Eliot Blennerhassettc382a5d2011-12-22 13:38:33 +1300136 u16 in_min_chans;
137 u16 out_min_chans;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200138};
139
140/* Per stream data */
141struct snd_card_asihpi_pcm {
142 struct timer_list timer;
143 unsigned int respawn_timer;
144 unsigned int hpi_buffer_attached;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300145 unsigned int buffer_bytes;
146 unsigned int period_bytes;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200147 unsigned int bytes_per_sec;
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300148 unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */
149 unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */
150 unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */
Eliot Blennerhassett0b7ce9e2011-04-05 20:55:43 +1200151 unsigned int drained_count;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200152 struct snd_pcm_substream *substream;
153 u32 h_stream;
154 struct hpi_format format;
155};
156
157/* universal stream verbs work with out or in stream handles */
158
159/* Functions to allow driver to give a buffer to HPI for busmastering */
160
161static u16 hpi_stream_host_buffer_attach(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200162 u32 h_stream, /* handle to outstream. */
163 u32 size_in_bytes, /* size in bytes of bus mastering buffer */
164 u32 pci_address
165)
166{
167 struct hpi_message hm;
168 struct hpi_response hr;
169 unsigned int obj = hpi_handle_object(h_stream);
170
171 if (!h_stream)
172 return HPI_ERROR_INVALID_OBJ;
173 hpi_init_message_response(&hm, &hr, obj,
174 obj == HPI_OBJ_OSTREAM ?
175 HPI_OSTREAM_HOSTBUFFER_ALLOC :
176 HPI_ISTREAM_HOSTBUFFER_ALLOC);
177
178 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
179 &hm.obj_index);
180
181 hm.u.d.u.buffer.buffer_size = size_in_bytes;
182 hm.u.d.u.buffer.pci_address = pci_address;
183 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
184 hpi_send_recv(&hm, &hr);
185 return hr.error;
186}
187
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300188static u16 hpi_stream_host_buffer_detach(u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200189{
190 struct hpi_message hm;
191 struct hpi_response hr;
192 unsigned int obj = hpi_handle_object(h_stream);
193
194 if (!h_stream)
195 return HPI_ERROR_INVALID_OBJ;
196
197 hpi_init_message_response(&hm, &hr, obj,
198 obj == HPI_OBJ_OSTREAM ?
199 HPI_OSTREAM_HOSTBUFFER_FREE :
200 HPI_ISTREAM_HOSTBUFFER_FREE);
201
202 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
203 &hm.obj_index);
204 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
205 hpi_send_recv(&hm, &hr);
206 return hr.error;
207}
208
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300209static inline u16 hpi_stream_start(u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200210{
211 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300212 return hpi_outstream_start(h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200213 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300214 return hpi_instream_start(h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200215}
216
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300217static inline u16 hpi_stream_stop(u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200218{
219 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300220 return hpi_outstream_stop(h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200221 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300222 return hpi_instream_stop(h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200223}
224
225static inline u16 hpi_stream_get_info_ex(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200226 u32 h_stream,
227 u16 *pw_state,
228 u32 *pbuffer_size,
229 u32 *pdata_in_buffer,
230 u32 *psample_count,
231 u32 *pauxiliary_data
232)
233{
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300234 u16 e;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200235 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300236 e = hpi_outstream_get_info_ex(h_stream, pw_state,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200237 pbuffer_size, pdata_in_buffer,
238 psample_count, pauxiliary_data);
239 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300240 e = hpi_instream_get_info_ex(h_stream, pw_state,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200241 pbuffer_size, pdata_in_buffer,
242 psample_count, pauxiliary_data);
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300243 return e;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200244}
245
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300246static inline u16 hpi_stream_group_add(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200247 u32 h_master,
248 u32 h_stream)
249{
250 if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300251 return hpi_outstream_group_add(h_master, h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200252 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300253 return hpi_instream_group_add(h_master, h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200254}
255
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300256static inline u16 hpi_stream_group_reset(u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200257{
258 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300259 return hpi_outstream_group_reset(h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200260 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300261 return hpi_instream_group_reset(h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200262}
263
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300264static inline u16 hpi_stream_group_get_map(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200265 u32 h_stream, u32 *mo, u32 *mi)
266{
267 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300268 return hpi_outstream_group_get_map(h_stream, mo, mi);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200269 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300270 return hpi_instream_group_get_map(h_stream, mo, mi);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200271}
272
273static u16 handle_error(u16 err, int line, char *filename)
274{
275 if (err)
276 printk(KERN_WARNING
277 "in file %s, line %d: HPI error %d\n",
278 filename, line, err);
279 return err;
280}
281
282#define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
283
284/***************************** GENERAL PCM ****************/
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200285
286static void print_hwparams(struct snd_pcm_substream *substream,
287 struct snd_pcm_hw_params *p)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200288{
Eliot Blennerhassett0a17e992011-07-22 15:52:44 +1200289 char name[16];
290 snd_pcm_debug_name(substream, name, sizeof(name));
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300291 snd_printdd("%s HWPARAMS\n", name);
292 snd_printdd(" samplerate=%dHz channels=%d format=%d subformat=%d\n",
293 params_rate(p), params_channels(p),
294 params_format(p), params_subformat(p));
295 snd_printdd(" buffer=%dB period=%dB period_size=%dB periods=%d\n",
296 params_buffer_bytes(p), params_period_bytes(p),
297 params_period_size(p), params_periods(p));
298 snd_printdd(" buffer_size=%d access=%d data_rate=%dB/s\n",
299 params_buffer_size(p), params_access(p),
300 params_rate(p) * params_channels(p) *
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200301 snd_pcm_format_width(params_format(p)) / 8);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200302}
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200303
304static snd_pcm_format_t hpi_to_alsa_formats[] = {
305 -1, /* INVALID */
306 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
307 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
308 -1, /* HPI_FORMAT_MPEG_L1 3 */
309 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */
310 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */
311 -1, /* HPI_FORMAT_DOLBY_AC2 6 */
312 -1, /* HPI_FORMAT_DOLBY_AC3 7 */
313 SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
314 -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
315 -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
316 SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */
317 -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */
318 -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
319 SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */
320#if 1
321 /* ALSA can't handle 3 byte sample size together with power-of-2
322 * constraint on buffer_bytes, so disable this format
323 */
324 -1
325#else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300326 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200327#endif
328};
329
330
331static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
332 u16 *hpi_format)
333{
334 u16 format;
335
336 for (format = HPI_FORMAT_PCM8_UNSIGNED;
337 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
338 if (hpi_to_alsa_formats[format] == alsa_format) {
339 *hpi_format = format;
340 return 0;
341 }
342 }
343
344 snd_printd(KERN_WARNING "failed match for alsa format %d\n",
345 alsa_format);
346 *hpi_format = 0;
347 return -EINVAL;
348}
349
350static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
351 struct snd_pcm_hardware *pcmhw)
352{
353 u16 err;
354 u32 h_control;
355 u32 sample_rate;
356 int idx;
357 unsigned int rate_min = 200000;
358 unsigned int rate_max = 0;
359 unsigned int rates = 0;
360
361 if (asihpi->support_mrx) {
362 rates |= SNDRV_PCM_RATE_CONTINUOUS;
363 rates |= SNDRV_PCM_RATE_8000_96000;
364 rate_min = 8000;
365 rate_max = 100000;
366 } else {
367 /* on cards without SRC,
368 valid rates are determined by sampleclock */
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300369 err = hpi_mixer_get_control(asihpi->h_mixer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200370 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
371 HPI_CONTROL_SAMPLECLOCK, &h_control);
372 if (err) {
373 snd_printk(KERN_ERR
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300374 "No local sampleclock, err %d\n", err);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200375 }
376
Eliot Blennerhassett7bf76c32011-03-25 15:25:46 +1300377 for (idx = -1; idx < 100; idx++) {
378 if (idx == -1) {
379 if (hpi_sample_clock_get_sample_rate(h_control,
380 &sample_rate))
381 continue;
382 } else if (hpi_sample_clock_query_local_rate(h_control,
383 idx, &sample_rate)) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200384 break;
385 }
386
387 rate_min = min(rate_min, sample_rate);
388 rate_max = max(rate_max, sample_rate);
389
390 switch (sample_rate) {
391 case 5512:
392 rates |= SNDRV_PCM_RATE_5512;
393 break;
394 case 8000:
395 rates |= SNDRV_PCM_RATE_8000;
396 break;
397 case 11025:
398 rates |= SNDRV_PCM_RATE_11025;
399 break;
400 case 16000:
401 rates |= SNDRV_PCM_RATE_16000;
402 break;
403 case 22050:
404 rates |= SNDRV_PCM_RATE_22050;
405 break;
406 case 32000:
407 rates |= SNDRV_PCM_RATE_32000;
408 break;
409 case 44100:
410 rates |= SNDRV_PCM_RATE_44100;
411 break;
412 case 48000:
413 rates |= SNDRV_PCM_RATE_48000;
414 break;
415 case 64000:
416 rates |= SNDRV_PCM_RATE_64000;
417 break;
418 case 88200:
419 rates |= SNDRV_PCM_RATE_88200;
420 break;
421 case 96000:
422 rates |= SNDRV_PCM_RATE_96000;
423 break;
424 case 176400:
425 rates |= SNDRV_PCM_RATE_176400;
426 break;
427 case 192000:
428 rates |= SNDRV_PCM_RATE_192000;
429 break;
430 default: /* some other rate */
431 rates |= SNDRV_PCM_RATE_KNOT;
432 }
433 }
434 }
435
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200436 pcmhw->rates = rates;
437 pcmhw->rate_min = rate_min;
438 pcmhw->rate_max = rate_max;
439}
440
441static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
442 struct snd_pcm_hw_params *params)
443{
444 struct snd_pcm_runtime *runtime = substream->runtime;
445 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
446 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
447 int err;
448 u16 format;
Kulikov Vasiliy315e8f72010-07-15 22:48:19 +0400449 int width;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200450 unsigned int bytes_per_sec;
451
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200452 print_hwparams(substream, params);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200453 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
454 if (err < 0)
455 return err;
456 err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
457 if (err)
458 return err;
459
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200460 hpi_handle_error(hpi_format_create(&dpcm->format,
461 params_channels(params),
462 format, params_rate(params), 0, 0));
463
464 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300465 if (hpi_instream_reset(dpcm->h_stream) != 0)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200466 return -EINVAL;
467
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300468 if (hpi_instream_set_format(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200469 dpcm->h_stream, &dpcm->format) != 0)
470 return -EINVAL;
471 }
472
473 dpcm->hpi_buffer_attached = 0;
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200474 if (card->can_dma) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300475 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200476 params_buffer_bytes(params), runtime->dma_addr);
477 if (err == 0) {
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +1300478 snd_printdd(
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300479 "stream_host_buffer_attach success %u %lu\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200480 params_buffer_bytes(params),
481 (unsigned long)runtime->dma_addr);
482 } else {
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +1300483 snd_printd("stream_host_buffer_attach error %d\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200484 err);
485 return -ENOMEM;
486 }
487
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300488 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300489 &dpcm->hpi_buffer_attached, NULL, NULL, NULL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200490 }
491 bytes_per_sec = params_rate(params) * params_channels(params);
Kulikov Vasiliy315e8f72010-07-15 22:48:19 +0400492 width = snd_pcm_format_width(params_format(params));
493 bytes_per_sec *= width;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200494 bytes_per_sec /= 8;
Kulikov Vasiliy315e8f72010-07-15 22:48:19 +0400495 if (width < 0 || bytes_per_sec == 0)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200496 return -EINVAL;
497
498 dpcm->bytes_per_sec = bytes_per_sec;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300499 dpcm->buffer_bytes = params_buffer_bytes(params);
500 dpcm->period_bytes = params_period_bytes(params);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200501
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200502 return 0;
503}
504
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300505static int
506snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
507{
508 struct snd_pcm_runtime *runtime = substream->runtime;
509 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
510 if (dpcm->hpi_buffer_attached)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300511 hpi_stream_host_buffer_detach(dpcm->h_stream);
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300512
513 snd_pcm_lib_free_pages(substream);
514 return 0;
515}
516
517static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
518{
519 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
520 kfree(dpcm);
521}
522
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200523static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
524 substream)
525{
526 struct snd_pcm_runtime *runtime = substream->runtime;
527 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
528 int expiry;
529
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300530 expiry = HZ / 200;
Eliot Blennerhassette9886ab2014-11-20 16:22:48 +1300531
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300532 expiry = max(expiry, 1); /* don't let it be zero! */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200533 dpcm->timer.expires = jiffies + expiry;
534 dpcm->respawn_timer = 1;
535 add_timer(&dpcm->timer);
536}
537
538static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
539{
540 struct snd_pcm_runtime *runtime = substream->runtime;
541 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
542
543 dpcm->respawn_timer = 0;
544 del_timer(&dpcm->timer);
545}
546
547static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
548 int cmd)
549{
550 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
551 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
552 struct snd_pcm_substream *s;
553 u16 e;
Eliot Blennerhassett0a17e992011-07-22 15:52:44 +1200554 char name[16];
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200555
Eliot Blennerhassett0a17e992011-07-22 15:52:44 +1200556 snd_pcm_debug_name(substream, name, sizeof(name));
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200557
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200558 switch (cmd) {
559 case SNDRV_PCM_TRIGGER_START:
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300560 snd_printdd("%s trigger start\n", name);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200561 snd_pcm_group_for_each_entry(s, substream) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300562 struct snd_pcm_runtime *runtime = s->runtime;
563 struct snd_card_asihpi_pcm *ds = runtime->private_data;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200564
565 if (snd_pcm_substream_chip(s) != card)
566 continue;
567
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300568 /* don't link Cap and Play */
569 if (substream->stream != s->stream)
570 continue;
571
Eliot Blennerhassett0b7ce9e2011-04-05 20:55:43 +1200572 ds->drained_count = 0;
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200573 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200574 /* How do I know how much valid data is present
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300575 * in buffer? Must be at least one period!
576 * Guessing 2 periods, but if
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200577 * buffer is bigger it may contain even more
578 * data??
579 */
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300580 unsigned int preload = ds->period_bytes * 1;
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300581 snd_printddd("%d preload %d\n", s->number, preload);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200582 hpi_handle_error(hpi_outstream_write_buf(
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300583 ds->h_stream,
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300584 &runtime->dma_area[0],
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200585 preload,
586 &ds->format));
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300587 ds->pcm_buf_host_rw_ofs = preload;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200588 }
589
590 if (card->support_grouping) {
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200591 snd_printdd("%d group\n", s->number);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300592 e = hpi_stream_group_add(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200593 dpcm->h_stream,
594 ds->h_stream);
595 if (!e) {
596 snd_pcm_trigger_done(s, substream);
597 } else {
598 hpi_handle_error(e);
599 break;
600 }
601 } else
602 break;
603 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200604 /* start the master stream */
605 snd_card_asihpi_pcm_timer_start(substream);
Eliot Blennerhassettc4ed97d2011-02-10 17:26:20 +1300606 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200607 !card->can_dma)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300608 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200609 break;
610
611 case SNDRV_PCM_TRIGGER_STOP:
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300612 snd_printdd("%s trigger stop\n", name);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200613 snd_card_asihpi_pcm_timer_stop(substream);
614 snd_pcm_group_for_each_entry(s, substream) {
615 if (snd_pcm_substream_chip(s) != card)
616 continue;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300617 /* don't link Cap and Play */
618 if (substream->stream != s->stream)
619 continue;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200620
621 /*? workaround linked streams don't
622 transition to SETUP 20070706*/
623 s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
624
625 if (card->support_grouping) {
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200626 snd_printdd("%d group\n", s->number);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200627 snd_pcm_trigger_done(s, substream);
628 } else
629 break;
630 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200631
632 /* _prepare and _hwparams reset the stream */
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300633 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200634 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
635 hpi_handle_error(
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300636 hpi_outstream_reset(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200637
638 if (card->support_grouping)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300639 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200640 break;
641
642 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300643 snd_printdd("%s trigger pause release\n", name);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300644 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200645 snd_card_asihpi_pcm_timer_start(substream);
646 break;
647 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300648 snd_printdd("%s trigger pause push\n", name);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200649 snd_card_asihpi_pcm_timer_stop(substream);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300650 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200651 break;
652 default:
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300653 snd_printd(KERN_ERR "\tINVALID\n");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200654 return -EINVAL;
655 }
656
657 return 0;
658}
659
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200660/*algorithm outline
661 Without linking degenerates to getting single stream pos etc
662 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
663*/
664/*
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300665pcm_buf_dma_ofs=get_buf_pos(s);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200666for_each_linked_stream(s) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300667 pcm_buf_dma_ofs=get_buf_pos(s);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300668 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300669 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200670}
671timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
672for_each_linked_stream(s) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300673 s->pcm_buf_dma_ofs = min_buf_pos;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300674 if (new_data > period_bytes) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200675 if (mmap) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300676 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200677 if (playback) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300678 write(period_bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200679 } else {
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300680 read(period_bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200681 }
682 }
683 snd_pcm_period_elapsed(s);
684 }
685}
686*/
687
688/** Minimum of 2 modulo values. Works correctly when the difference between
689* the values is less than half the modulus
690*/
691static inline unsigned int modulo_min(unsigned int a, unsigned int b,
692 unsigned long int modulus)
693{
694 unsigned int result;
695 if (((a-b) % modulus) < (modulus/2))
696 result = b;
697 else
698 result = a;
699
700 return result;
701}
702
703/** Timer function, equivalent to interrupt service routine for cards
704*/
705static void snd_card_asihpi_timer_function(unsigned long data)
706{
707 struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300708 struct snd_pcm_substream *substream = dpcm->substream;
709 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200710 struct snd_pcm_runtime *runtime;
711 struct snd_pcm_substream *s;
712 unsigned int newdata = 0;
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300713 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200714 unsigned int remdata, xfercount, next_jiffies;
715 int first = 1;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300716 int loops = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200717 u16 state;
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300718 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
Eliot Blennerhassett0a17e992011-07-22 15:52:44 +1200719 char name[16];
720
721 snd_pcm_debug_name(substream, name, sizeof(name));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200722
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300723
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200724 /* find minimum newdata and buffer pos in group */
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300725 snd_pcm_group_for_each_entry(s, substream) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200726 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
727 runtime = s->runtime;
728
729 if (snd_pcm_substream_chip(s) != card)
730 continue;
731
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300732 /* don't link Cap and Play */
733 if (substream->stream != s->stream)
734 continue;
735
736 hpi_handle_error(hpi_stream_get_info_ex(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200737 ds->h_stream, &state,
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300738 &buffer_size, &bytes_avail,
739 &samples_played, &on_card_bytes));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200740
741 /* number of bytes in on-card buffer */
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300742 runtime->delay = on_card_bytes;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200743
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200744 if (!card->can_dma)
745 on_card_bytes = bytes_avail;
746
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300747 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300748 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300749 if (state == HPI_STATE_STOPPED) {
Eliot Blennerhassett0be55c42011-12-22 13:38:37 +1300750 if (bytes_avail == 0) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300751 hpi_handle_error(hpi_stream_start(ds->h_stream));
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +1300752 snd_printdd("P%d start\n", s->number);
Eliot Blennerhassett0b7ce9e2011-04-05 20:55:43 +1200753 ds->drained_count = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300754 }
755 } else if (state == HPI_STATE_DRAINED) {
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +1300756 snd_printd(KERN_WARNING "P%d drained\n",
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300757 s->number);
Eliot Blennerhassett0b7ce9e2011-04-05 20:55:43 +1200758 ds->drained_count++;
Eliot Blennerhassett0be55c42011-12-22 13:38:37 +1300759 if (ds->drained_count > 20) {
Takashi Iwai1fb85102014-11-07 17:08:28 +0100760 snd_pcm_stop_xrun(s);
Eliot Blennerhassett0b7ce9e2011-04-05 20:55:43 +1200761 continue;
762 }
763 } else {
764 ds->drained_count = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300765 }
766 } else
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300767 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200768
769 if (first) {
770 /* can't statically init min when wrap is involved */
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300771 min_buf_pos = pcm_buf_dma_ofs;
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300772 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200773 first = 0;
774 } else {
775 min_buf_pos =
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300776 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200777 newdata = min(
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300778 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200779 newdata);
780 }
781
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300782 snd_printddd("timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
783 name, s->number, state,
784 ds->pcm_buf_elapsed_dma_ofs,
785 ds->pcm_buf_host_rw_ofs,
786 pcm_buf_dma_ofs,
787 (int)bytes_avail,
788
789 (int)on_card_bytes,
790 buffer_size-bytes_avail,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200791 (unsigned long)frames_to_bytes(runtime,
792 runtime->status->hw_ptr),
793 (unsigned long)frames_to_bytes(runtime,
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300794 runtime->control->appl_ptr)
795 );
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300796 loops++;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200797 }
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300798 pcm_buf_dma_ofs = min_buf_pos;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200799
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300800 remdata = newdata % dpcm->period_bytes;
801 xfercount = newdata - remdata; /* a multiple of period_bytes */
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300802 /* come back when on_card_bytes has decreased enough to allow
803 write to happen, or when data has been consumed to make another
804 period
805 */
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300806 if (xfercount && (on_card_bytes > dpcm->period_bytes))
807 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300808 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300809 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300810
811 next_jiffies = max(next_jiffies, 1U);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200812 dpcm->timer.expires = jiffies + next_jiffies;
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300813 snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300814 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
815
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300816 snd_pcm_group_for_each_entry(s, substream) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200817 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200818
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300819 /* don't link Cap and Play */
820 if (substream->stream != s->stream)
821 continue;
822
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300823 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
824
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200825 if (xfercount &&
826 /* Limit use of on card fifo for playback */
827 ((on_card_bytes <= ds->period_bytes) ||
828 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
829
830 {
831
832 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
833 unsigned int xfer1, xfer2;
834 char *pd = &s->runtime->dma_area[buf_ofs];
835
Eliot Blennerhassettb0096a62011-04-05 20:55:46 +1200836 if (card->can_dma) { /* buffer wrap is handled at lower level */
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200837 xfer1 = xfercount;
838 xfer2 = 0;
839 } else {
840 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
841 xfer2 = xfercount - xfer1;
842 }
843
844 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300845 snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n",
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200846 s->number, xfer1, buf_ofs);
847 hpi_handle_error(
848 hpi_outstream_write_buf(
849 ds->h_stream, pd, xfer1,
850 &ds->format));
851
852 if (xfer2) {
853 pd = s->runtime->dma_area;
854
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300855 snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200856 s->number,
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200857 xfercount - xfer1, buf_ofs);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200858 hpi_handle_error(
859 hpi_outstream_write_buf(
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200860 ds->h_stream, pd,
861 xfercount - xfer1,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200862 &ds->format));
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200863 }
864 } else {
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300865 snd_printddd("read1, C=%d, xfer=%d\n",
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200866 s->number, xfer1);
867 hpi_handle_error(
868 hpi_instream_read_buf(
869 ds->h_stream,
870 pd, xfer1));
871 if (xfer2) {
872 pd = s->runtime->dma_area;
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300873 snd_printddd("read2, C=%d, xfer=%d\n",
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200874 s->number, xfer2);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200875 hpi_handle_error(
876 hpi_instream_read_buf(
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300877 ds->h_stream,
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200878 pd, xfer2));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200879 }
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +1200880 }
Eliot Blennerhassett47a74a52011-12-22 11:54:02 +1300881 ds->pcm_buf_host_rw_ofs += xfercount;
882 ds->pcm_buf_elapsed_dma_ofs += xfercount;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200883 snd_pcm_period_elapsed(s);
884 }
885 }
886
887 if (dpcm->respawn_timer)
888 add_timer(&dpcm->timer);
889}
890
891/***************************** PLAYBACK OPS ****************/
892static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
893 unsigned int cmd, void *arg)
894{
Eliot Blennerhassettcbd757d2011-12-22 13:38:35 +1300895 char name[16];
896 snd_pcm_debug_name(substream, name, sizeof(name));
897 snd_printddd(KERN_INFO "%s ioctl %d\n", name, cmd);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200898 return snd_pcm_lib_ioctl(substream, cmd, arg);
899}
900
901static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
902 substream)
903{
904 struct snd_pcm_runtime *runtime = substream->runtime;
905 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
906
Eliot Blennerhassetta6477132011-04-05 20:55:42 +1200907 snd_printdd("P%d prepare\n", substream->number);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200908
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300909 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +1300910 dpcm->pcm_buf_host_rw_ofs = 0;
911 dpcm->pcm_buf_dma_ofs = 0;
912 dpcm->pcm_buf_elapsed_dma_ofs = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200913 return 0;
914}
915
916static snd_pcm_uframes_t
917snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
918{
919 struct snd_pcm_runtime *runtime = substream->runtime;
920 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
921 snd_pcm_uframes_t ptr;
Eliot Blennerhassettcbd757d2011-12-22 13:38:35 +1300922 char name[16];
923 snd_pcm_debug_name(substream, name, sizeof(name));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200924
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300925 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +1300926 snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200927 return ptr;
928}
929
Eliot Blennerhassett68d53392011-12-22 13:38:51 +1300930static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi,
931 u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200932{
933 struct hpi_format hpi_format;
934 u16 format;
935 u16 err;
936 u32 h_control;
937 u32 sample_rate = 48000;
Eliot Blennerhassett68d53392011-12-22 13:38:51 +1300938 u64 formats = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200939
940 /* on cards without SRC, must query at valid rate,
941 * maybe set by external sync
942 */
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300943 err = hpi_mixer_get_control(asihpi->h_mixer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200944 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
945 HPI_CONTROL_SAMPLECLOCK, &h_control);
946
947 if (!err)
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300948 err = hpi_sample_clock_get_sample_rate(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200949 &sample_rate);
950
951 for (format = HPI_FORMAT_PCM8_UNSIGNED;
952 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
Eliot Blennerhassettc1d70dd2011-12-22 13:38:50 +1300953 err = hpi_format_create(&hpi_format, asihpi->out_max_chans,
954 format, sample_rate, 128000, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200955 if (!err)
Eliot Blennerhassettc1d70dd2011-12-22 13:38:50 +1300956 err = hpi_outstream_query_format(h_stream, &hpi_format);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200957 if (!err && (hpi_to_alsa_formats[format] != -1))
Eldad Zack74c34ca2013-04-23 01:00:41 +0200958 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200959 }
Eliot Blennerhassett68d53392011-12-22 13:38:51 +1300960 return formats;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200961}
962
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200963static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
964{
965 struct snd_pcm_runtime *runtime = substream->runtime;
966 struct snd_card_asihpi_pcm *dpcm;
967 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
Eliot Blennerhassett68d53392011-12-22 13:38:51 +1300968 struct snd_pcm_hardware snd_card_asihpi_playback;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200969 int err;
970
971 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
972 if (dpcm == NULL)
973 return -ENOMEM;
974
Eliot Blennerhassett68d53392011-12-22 13:38:51 +1300975 err = hpi_outstream_open(card->hpi->adapter->index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200976 substream->number, &dpcm->h_stream);
977 hpi_handle_error(err);
978 if (err)
979 kfree(dpcm);
980 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
981 return -EBUSY;
982 if (err)
983 return -EIO;
984
985 /*? also check ASI5000 samplerate source
986 If external, only support external rate.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300987 If internal and other stream playing, can't switch
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200988 */
989
990 init_timer(&dpcm->timer);
991 dpcm->timer.data = (unsigned long) dpcm;
992 dpcm->timer.function = snd_card_asihpi_timer_function;
993 dpcm->substream = substream;
994 runtime->private_data = dpcm;
995 runtime->private_free = snd_card_asihpi_runtime_free;
996
Eliot Blennerhassett68d53392011-12-22 13:38:51 +1300997 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
998 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
999 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001000 /*?snd_card_asihpi_playback.period_bytes_min =
1001 card->out_max_chans * 4096; */
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001002 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1003 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1004 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1005 /* snd_card_asihpi_playback.fifo_size = 0; */
1006 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1007 snd_card_asihpi_playback.channels_min = card->out_min_chans;
1008 snd_card_asihpi_playback.formats =
1009 snd_card_asihpi_playback_formats(card, dpcm->h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001010
1011 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1012
1013 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1014 SNDRV_PCM_INFO_DOUBLE |
1015 SNDRV_PCM_INFO_BATCH |
1016 SNDRV_PCM_INFO_BLOCK_TRANSFER |
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12001017 SNDRV_PCM_INFO_PAUSE |
1018 SNDRV_PCM_INFO_MMAP |
1019 SNDRV_PCM_INFO_MMAP_VALID;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001020
Eliot Blennerhassett09c728a2011-12-22 13:38:38 +13001021 if (card->support_grouping) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001022 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
Eliot Blennerhassett09c728a2011-12-22 13:38:38 +13001023 snd_pcm_set_sync(substream);
1024 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001025
1026 /* struct is copied, so can create initializer dynamically */
1027 runtime->hw = snd_card_asihpi_playback;
1028
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12001029 if (card->can_dma)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001030 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1031 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1032 if (err < 0)
1033 return err;
1034
1035 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1036 card->update_interval_frames);
Eliot Blennerhassett26aebef2011-03-25 15:25:47 +13001037
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001038 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001039 card->update_interval_frames * 2, UINT_MAX);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001040
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +13001041 snd_printdd("playback open\n");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001042
1043 return 0;
1044}
1045
1046static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1047{
1048 struct snd_pcm_runtime *runtime = substream->runtime;
1049 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1050
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001051 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +13001052 snd_printdd("playback close\n");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001053
1054 return 0;
1055}
1056
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001057static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1058 .open = snd_card_asihpi_playback_open,
1059 .close = snd_card_asihpi_playback_close,
1060 .ioctl = snd_card_asihpi_playback_ioctl,
1061 .hw_params = snd_card_asihpi_pcm_hw_params,
1062 .hw_free = snd_card_asihpi_hw_free,
1063 .prepare = snd_card_asihpi_playback_prepare,
1064 .trigger = snd_card_asihpi_trigger,
1065 .pointer = snd_card_asihpi_playback_pointer,
1066};
1067
1068/***************************** CAPTURE OPS ****************/
1069static snd_pcm_uframes_t
1070snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1071{
1072 struct snd_pcm_runtime *runtime = substream->runtime;
1073 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +13001074 char name[16];
1075 snd_pcm_debug_name(substream, name, sizeof(name));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001076
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +13001077 snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001078 /* NOTE Unlike playback can't use actual samples_played
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001079 for the capture position, because those samples aren't yet in
1080 the local buffer available for reading.
1081 */
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001082 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001083}
1084
1085static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream,
1086 unsigned int cmd, void *arg)
1087{
1088 return snd_pcm_lib_ioctl(substream, cmd, arg);
1089}
1090
1091static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1092{
1093 struct snd_pcm_runtime *runtime = substream->runtime;
1094 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1095
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001096 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001097 dpcm->pcm_buf_host_rw_ofs = 0;
1098 dpcm->pcm_buf_dma_ofs = 0;
1099 dpcm->pcm_buf_elapsed_dma_ofs = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001100
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +13001101 snd_printdd("Capture Prepare %d\n", substream->number);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001102 return 0;
1103}
1104
1105
1106
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001107static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
1108 u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001109{
1110 struct hpi_format hpi_format;
1111 u16 format;
1112 u16 err;
1113 u32 h_control;
1114 u32 sample_rate = 48000;
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001115 u64 formats = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001116
1117 /* on cards without SRC, must query at valid rate,
1118 maybe set by external sync */
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001119 err = hpi_mixer_get_control(asihpi->h_mixer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001120 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1121 HPI_CONTROL_SAMPLECLOCK, &h_control);
1122
1123 if (!err)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001124 err = hpi_sample_clock_get_sample_rate(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001125 &sample_rate);
1126
1127 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1128 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1129
Eliot Blennerhassettc1d70dd2011-12-22 13:38:50 +13001130 err = hpi_format_create(&hpi_format, asihpi->in_max_chans,
1131 format, sample_rate, 128000, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001132 if (!err)
Eliot Blennerhassettc1d70dd2011-12-22 13:38:50 +13001133 err = hpi_instream_query_format(h_stream, &hpi_format);
Eldad Zack167d0a12013-04-23 01:00:42 +02001134 if (!err && (hpi_to_alsa_formats[format] != -1))
Eldad Zack74c34ca2013-04-23 01:00:41 +02001135 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001136 }
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001137 return formats;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001138}
1139
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001140static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1141{
1142 struct snd_pcm_runtime *runtime = substream->runtime;
1143 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1144 struct snd_card_asihpi_pcm *dpcm;
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001145 struct snd_pcm_hardware snd_card_asihpi_capture;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001146 int err;
1147
1148 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1149 if (dpcm == NULL)
1150 return -ENOMEM;
1151
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +13001152 snd_printdd("capture open adapter %d stream %d\n",
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13001153 card->hpi->adapter->index, substream->number);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001154
1155 err = hpi_handle_error(
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13001156 hpi_instream_open(card->hpi->adapter->index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001157 substream->number, &dpcm->h_stream));
1158 if (err)
1159 kfree(dpcm);
1160 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1161 return -EBUSY;
1162 if (err)
1163 return -EIO;
1164
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001165 init_timer(&dpcm->timer);
1166 dpcm->timer.data = (unsigned long) dpcm;
1167 dpcm->timer.function = snd_card_asihpi_timer_function;
1168 dpcm->substream = substream;
1169 runtime->private_data = dpcm;
1170 runtime->private_free = snd_card_asihpi_runtime_free;
1171
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001172 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1173 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1174 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1175 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1176 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1177 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1178 /* snd_card_asihpi_capture.fifo_size = 0; */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001179 snd_card_asihpi_capture.channels_max = card->in_max_chans;
Eliot Blennerhassettc382a5d2011-12-22 13:38:33 +13001180 snd_card_asihpi_capture.channels_min = card->in_min_chans;
Eliot Blennerhassett68d53392011-12-22 13:38:51 +13001181 snd_card_asihpi_capture.formats =
1182 snd_card_asihpi_capture_formats(card, dpcm->h_stream);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001183 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12001184 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1185 SNDRV_PCM_INFO_MMAP |
1186 SNDRV_PCM_INFO_MMAP_VALID;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001187
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001188 if (card->support_grouping)
1189 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1190
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001191 runtime->hw = snd_card_asihpi_capture;
1192
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12001193 if (card->can_dma)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001194 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1195 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1196 if (err < 0)
1197 return err;
1198
1199 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1200 card->update_interval_frames);
1201 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1202 card->update_interval_frames * 2, UINT_MAX);
1203
1204 snd_pcm_set_sync(substream);
1205
1206 return 0;
1207}
1208
1209static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1210{
1211 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1212
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001213 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001214 return 0;
1215}
1216
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001217static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1218 .open = snd_card_asihpi_capture_open,
1219 .close = snd_card_asihpi_capture_close,
1220 .ioctl = snd_card_asihpi_capture_ioctl,
1221 .hw_params = snd_card_asihpi_pcm_hw_params,
1222 .hw_free = snd_card_asihpi_hw_free,
1223 .prepare = snd_card_asihpi_capture_prepare,
1224 .trigger = snd_card_asihpi_trigger,
1225 .pointer = snd_card_asihpi_capture_pointer,
1226};
1227
Bill Pembertone23e7a12012-12-06 12:35:10 -05001228static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001229{
1230 struct snd_pcm *pcm;
1231 int err;
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13001232 u16 num_instreams, num_outstreams, x16;
1233 u32 x32;
1234
1235 err = hpi_adapter_get_info(asihpi->hpi->adapter->index,
1236 &num_outstreams, &num_instreams,
1237 &x16, &x32, &x16);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001238
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001239 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13001240 num_outstreams, num_instreams, &pcm);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001241 if (err < 0)
1242 return err;
Dan Carpenterc687c9b2014-03-31 10:49:15 +03001243
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001244 /* pointer to ops struct is stored, dont change ops afterwards! */
Dan Carpenterc687c9b2014-03-31 10:49:15 +03001245 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1246 &snd_card_asihpi_playback_mmap_ops);
1247 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1248 &snd_card_asihpi_capture_mmap_ops);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001249
1250 pcm->private_data = asihpi;
1251 pcm->info_flags = 0;
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001252 strcpy(pcm->name, "Asihpi PCM");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001253
1254 /*? do we want to emulate MMAP for non-BBM cards?
1255 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1256 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1257 snd_dma_pci_data(asihpi->pci),
1258 64*1024, BUFFER_BYTES_MAX);
1259
1260 return 0;
1261}
1262
1263/***************************** MIXER CONTROLS ****************/
1264struct hpi_control {
1265 u32 h_control;
1266 u16 control_type;
1267 u16 src_node_type;
1268 u16 src_node_index;
1269 u16 dst_node_type;
1270 u16 dst_node_index;
1271 u16 band;
Takashi Iwai975cc022013-06-28 11:56:49 +02001272 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001273};
1274
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001275static const char * const asihpi_tuner_band_names[] = {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001276 "invalid",
1277 "AM",
1278 "FM mono",
1279 "TV NTSC-M",
1280 "FM stereo",
1281 "AUX",
1282 "TV PAL BG",
1283 "TV PAL I",
1284 "TV PAL DK",
1285 "TV SECAM",
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13001286 "TV DAB",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001287};
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13001288/* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001289compile_time_assert(
1290 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1291 (HPI_TUNER_BAND_LAST+1)),
1292 assert_tuner_band_names_size);
1293
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001294static const char * const asihpi_src_names[] = {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001295 "no source",
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001296 "PCM",
1297 "Line",
1298 "Digital",
1299 "Tuner",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001300 "RF",
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001301 "Clock",
1302 "Bitstream",
Eliot Blennerhassettc8306132011-07-22 15:53:00 +12001303 "Mic",
1304 "Net",
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001305 "Analog",
1306 "Adapter",
Eliot Blennerhassettc8306132011-07-22 15:53:00 +12001307 "RTP",
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13001308 "Internal",
1309 "AVB",
1310 "BLU-Link"
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001311};
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13001312/* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001313compile_time_assert(
1314 (ARRAY_SIZE(asihpi_src_names) ==
Eliot Blennerhassett168f1b02010-07-06 08:37:06 +12001315 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001316 assert_src_names_size);
1317
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001318static const char * const asihpi_dst_names[] = {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001319 "no destination",
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001320 "PCM",
1321 "Line",
1322 "Digital",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001323 "RF",
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001324 "Speaker",
Eliot Blennerhassettc8306132011-07-22 15:53:00 +12001325 "Net",
1326 "Analog",
1327 "RTP",
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13001328 "AVB",
1329 "Internal",
1330 "BLU-Link"
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001331};
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13001332/* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001333compile_time_assert(
1334 (ARRAY_SIZE(asihpi_dst_names) ==
Eliot Blennerhassett168f1b02010-07-06 08:37:06 +12001335 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001336 assert_dst_names_size);
1337
1338static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1339 struct snd_card_asihpi *asihpi)
1340{
1341 int err;
1342
1343 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1344 if (err < 0)
1345 return err;
1346 else if (mixer_dump)
1347 snd_printk(KERN_INFO "added %s(%d)\n", ctl->name, ctl->index);
1348
1349 return 0;
1350}
1351
1352/* Convert HPI control name and location into ALSA control name */
1353static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1354 struct hpi_control *hpi_ctl,
1355 char *name)
1356{
Eliot Blennerhassett550ac6b2011-04-05 20:55:41 +12001357 char *dir;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001358 memset(snd_control, 0, sizeof(*snd_control));
1359 snd_control->name = hpi_ctl->name;
1360 snd_control->private_value = hpi_ctl->h_control;
1361 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1362 snd_control->index = 0;
1363
Eliot Blennerhassett550ac6b2011-04-05 20:55:41 +12001364 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1365 dir = ""; /* clock is neither capture nor playback */
1366 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001367 dir = "Capture "; /* On or towards a PCM capture destination*/
1368 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1369 (!hpi_ctl->dst_node_type))
1370 dir = "Capture "; /* On a source node that is not PCM playback */
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001371 else if (hpi_ctl->src_node_type &&
1372 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001373 (hpi_ctl->dst_node_type))
1374 dir = "Monitor Playback "; /* Between an input and an output */
1375 else
1376 dir = "Playback "; /* PCM Playback source, or output node */
1377
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001378 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
Eliot Blennerhassett550ac6b2011-04-05 20:55:41 +12001379 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001380 asihpi_src_names[hpi_ctl->src_node_type],
1381 hpi_ctl->src_node_index,
1382 asihpi_dst_names[hpi_ctl->dst_node_type],
1383 hpi_ctl->dst_node_index,
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001384 dir, name);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001385 else if (hpi_ctl->dst_node_type) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001386 sprintf(hpi_ctl->name, "%s %d %s%s",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001387 asihpi_dst_names[hpi_ctl->dst_node_type],
1388 hpi_ctl->dst_node_index,
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001389 dir, name);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001390 } else {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001391 sprintf(hpi_ctl->name, "%s %d %s%s",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001392 asihpi_src_names[hpi_ctl->src_node_type],
1393 hpi_ctl->src_node_index,
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001394 dir, name);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001395 }
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001396 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1397 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001398}
1399
1400/*------------------------------------------------------------
1401 Volume controls
1402 ------------------------------------------------------------*/
1403#define VOL_STEP_mB 1
1404static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1405 struct snd_ctl_elem_info *uinfo)
1406{
1407 u32 h_control = kcontrol->private_value;
Eliot Blennerhassettd4b06d22011-12-22 13:38:34 +13001408 u32 count;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001409 u16 err;
1410 /* native gains are in millibels */
1411 short min_gain_mB;
1412 short max_gain_mB;
1413 short step_gain_mB;
1414
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001415 err = hpi_volume_query_range(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001416 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1417 if (err) {
1418 max_gain_mB = 0;
1419 min_gain_mB = -10000;
1420 step_gain_mB = VOL_STEP_mB;
1421 }
1422
Eliot Blennerhassettd4b06d22011-12-22 13:38:34 +13001423 err = hpi_meter_query_channels(h_control, &count);
1424 if (err)
1425 count = HPI_MAX_CHANNELS;
1426
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001427 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
Eliot Blennerhassettd4b06d22011-12-22 13:38:34 +13001428 uinfo->count = count;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001429 uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
1430 uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
1431 uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
1432 return 0;
1433}
1434
1435static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
1436 struct snd_ctl_elem_value *ucontrol)
1437{
1438 u32 h_control = kcontrol->private_value;
1439 short an_gain_mB[HPI_MAX_CHANNELS];
1440
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001441 hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001442 ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
1443 ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
1444
1445 return 0;
1446}
1447
1448static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
1449 struct snd_ctl_elem_value *ucontrol)
1450{
1451 int change;
1452 u32 h_control = kcontrol->private_value;
1453 short an_gain_mB[HPI_MAX_CHANNELS];
1454
1455 an_gain_mB[0] =
1456 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1457 an_gain_mB[1] =
1458 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1459 /* change = asihpi->mixer_volume[addr][0] != left ||
1460 asihpi->mixer_volume[addr][1] != right;
1461 */
1462 change = 1;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001463 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001464 return change;
1465}
1466
1467static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1468
Takashi Iwai000477a2011-07-22 07:57:44 +02001469#define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
Eliot Blennerhassettfe0aa88e2011-07-22 15:53:03 +12001470
1471static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1472 struct snd_ctl_elem_value *ucontrol)
1473{
1474 u32 h_control = kcontrol->private_value;
1475 u32 mute;
1476
1477 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1478 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1479
1480 return 0;
1481}
1482
1483static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1484 struct snd_ctl_elem_value *ucontrol)
1485{
1486 u32 h_control = kcontrol->private_value;
1487 int change = 1;
1488 /* HPI currently only supports all or none muting of multichannel volume
1489 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1490 */
1491 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1492 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1493 return change;
1494}
1495
Bill Pembertone23e7a12012-12-06 12:35:10 -05001496static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1497 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001498{
1499 struct snd_card *card = asihpi->card;
1500 struct snd_kcontrol_new snd_control;
Eliot Blennerhassettfe0aa88e2011-07-22 15:53:03 +12001501 int err;
1502 u32 mute;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001503
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001504 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001505 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1506 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1507 snd_control.info = snd_asihpi_volume_info;
1508 snd_control.get = snd_asihpi_volume_get;
1509 snd_control.put = snd_asihpi_volume_put;
1510 snd_control.tlv.p = db_scale_100;
1511
Eliot Blennerhassettfe0aa88e2011-07-22 15:53:03 +12001512 err = ctl_add(card, &snd_control, asihpi);
1513 if (err)
1514 return err;
1515
1516 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1517 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1518 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1519 snd_control.info = snd_asihpi_volume_mute_info;
1520 snd_control.get = snd_asihpi_volume_mute_get;
1521 snd_control.put = snd_asihpi_volume_mute_put;
1522 err = ctl_add(card, &snd_control, asihpi);
1523 }
1524 return err;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001525}
1526
1527/*------------------------------------------------------------
1528 Level controls
1529 ------------------------------------------------------------*/
1530static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1531 struct snd_ctl_elem_info *uinfo)
1532{
1533 u32 h_control = kcontrol->private_value;
1534 u16 err;
1535 short min_gain_mB;
1536 short max_gain_mB;
1537 short step_gain_mB;
1538
1539 err =
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001540 hpi_level_query_range(h_control, &min_gain_mB,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001541 &max_gain_mB, &step_gain_mB);
1542 if (err) {
1543 max_gain_mB = 2400;
1544 min_gain_mB = -1000;
1545 step_gain_mB = 100;
1546 }
1547
1548 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1549 uinfo->count = 2;
1550 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1551 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1552 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1553 return 0;
1554}
1555
1556static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1557 struct snd_ctl_elem_value *ucontrol)
1558{
1559 u32 h_control = kcontrol->private_value;
1560 short an_gain_mB[HPI_MAX_CHANNELS];
1561
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001562 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001563 ucontrol->value.integer.value[0] =
1564 an_gain_mB[0] / HPI_UNITS_PER_dB;
1565 ucontrol->value.integer.value[1] =
1566 an_gain_mB[1] / HPI_UNITS_PER_dB;
1567
1568 return 0;
1569}
1570
1571static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1572 struct snd_ctl_elem_value *ucontrol)
1573{
1574 int change;
1575 u32 h_control = kcontrol->private_value;
1576 short an_gain_mB[HPI_MAX_CHANNELS];
1577
1578 an_gain_mB[0] =
1579 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1580 an_gain_mB[1] =
1581 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1582 /* change = asihpi->mixer_level[addr][0] != left ||
1583 asihpi->mixer_level[addr][1] != right;
1584 */
1585 change = 1;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001586 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001587 return change;
1588}
1589
1590static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1591
Bill Pembertone23e7a12012-12-06 12:35:10 -05001592static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1593 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001594{
1595 struct snd_card *card = asihpi->card;
1596 struct snd_kcontrol_new snd_control;
1597
1598 /* can't use 'volume' cos some nodes have volume as well */
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001599 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001600 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1601 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1602 snd_control.info = snd_asihpi_level_info;
1603 snd_control.get = snd_asihpi_level_get;
1604 snd_control.put = snd_asihpi_level_put;
1605 snd_control.tlv.p = db_scale_level;
1606
1607 return ctl_add(card, &snd_control, asihpi);
1608}
1609
1610/*------------------------------------------------------------
1611 AESEBU controls
1612 ------------------------------------------------------------*/
1613
1614/* AESEBU format */
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001615static const char * const asihpi_aesebu_format_names[] = {
1616 "N/A", "S/PDIF", "AES/EBU" };
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001617
1618static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_info *uinfo)
1620{
Takashi Iwai30d0ae42014-10-20 18:15:50 +02001621 return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001622}
1623
1624static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_value *ucontrol,
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001626 u16 (*func)(u32, u16 *))
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001627{
1628 u32 h_control = kcontrol->private_value;
1629 u16 source, err;
1630
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001631 err = func(h_control, &source);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001632
1633 /* default to N/A */
1634 ucontrol->value.enumerated.item[0] = 0;
1635 /* return success but set the control to N/A */
1636 if (err)
1637 return 0;
1638 if (source == HPI_AESEBU_FORMAT_SPDIF)
1639 ucontrol->value.enumerated.item[0] = 1;
1640 if (source == HPI_AESEBU_FORMAT_AESEBU)
1641 ucontrol->value.enumerated.item[0] = 2;
1642
1643 return 0;
1644}
1645
1646static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol,
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001648 u16 (*func)(u32, u16))
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001649{
1650 u32 h_control = kcontrol->private_value;
1651
1652 /* default to S/PDIF */
1653 u16 source = HPI_AESEBU_FORMAT_SPDIF;
1654
1655 if (ucontrol->value.enumerated.item[0] == 1)
1656 source = HPI_AESEBU_FORMAT_SPDIF;
1657 if (ucontrol->value.enumerated.item[0] == 2)
1658 source = HPI_AESEBU_FORMAT_AESEBU;
1659
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001660 if (func(h_control, source) != 0)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001661 return -EINVAL;
1662
1663 return 1;
1664}
1665
1666static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
1667 struct snd_ctl_elem_value *ucontrol) {
1668 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001669 hpi_aesebu_receiver_get_format);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001670}
1671
1672static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
1673 struct snd_ctl_elem_value *ucontrol) {
1674 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001675 hpi_aesebu_receiver_set_format);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001676}
1677
1678static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
1679 struct snd_ctl_elem_info *uinfo)
1680{
1681 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1682 uinfo->count = 1;
1683
1684 uinfo->value.integer.min = 0;
1685 uinfo->value.integer.max = 0X1F;
1686 uinfo->value.integer.step = 1;
1687
1688 return 0;
1689}
1690
1691static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
1692 struct snd_ctl_elem_value *ucontrol) {
1693
1694 u32 h_control = kcontrol->private_value;
1695 u16 status;
1696
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001697 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1698 h_control, &status));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001699 ucontrol->value.integer.value[0] = status;
1700 return 0;
1701}
1702
Bill Pembertone23e7a12012-12-06 12:35:10 -05001703static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
1704 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001705{
1706 struct snd_card *card = asihpi->card;
1707 struct snd_kcontrol_new snd_control;
1708
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001709 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001710 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1711 snd_control.info = snd_asihpi_aesebu_format_info;
1712 snd_control.get = snd_asihpi_aesebu_rx_format_get;
1713 snd_control.put = snd_asihpi_aesebu_rx_format_put;
1714
1715
1716 if (ctl_add(card, &snd_control, asihpi) < 0)
1717 return -EINVAL;
1718
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001719 asihpi_ctl_init(&snd_control, hpi_ctl, "Status");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001720 snd_control.access =
1721 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
1722 snd_control.info = snd_asihpi_aesebu_rxstatus_info;
1723 snd_control.get = snd_asihpi_aesebu_rxstatus_get;
1724
1725 return ctl_add(card, &snd_control, asihpi);
1726}
1727
1728static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol) {
1730 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001731 hpi_aesebu_transmitter_get_format);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001732}
1733
1734static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_value *ucontrol) {
1736 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001737 hpi_aesebu_transmitter_set_format);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001738}
1739
1740
Bill Pembertone23e7a12012-12-06 12:35:10 -05001741static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
1742 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001743{
1744 struct snd_card *card = asihpi->card;
1745 struct snd_kcontrol_new snd_control;
1746
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001747 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001748 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1749 snd_control.info = snd_asihpi_aesebu_format_info;
1750 snd_control.get = snd_asihpi_aesebu_tx_format_get;
1751 snd_control.put = snd_asihpi_aesebu_tx_format_put;
1752
1753 return ctl_add(card, &snd_control, asihpi);
1754}
1755
1756/*------------------------------------------------------------
1757 Tuner controls
1758 ------------------------------------------------------------*/
1759
1760/* Gain */
1761
1762static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_info *uinfo)
1764{
1765 u32 h_control = kcontrol->private_value;
1766 u16 err;
1767 short idx;
1768 u16 gain_range[3];
1769
1770 for (idx = 0; idx < 3; idx++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001771 err = hpi_tuner_query_gain(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001772 idx, &gain_range[idx]);
1773 if (err != 0)
1774 return err;
1775 }
1776
1777 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1778 uinfo->count = 1;
1779 uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
1780 uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
1781 uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
1782 return 0;
1783}
1784
1785static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
1786 struct snd_ctl_elem_value *ucontrol)
1787{
1788 /*
1789 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1790 */
1791 u32 h_control = kcontrol->private_value;
1792 short gain;
1793
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001794 hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001795 ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
1796
1797 return 0;
1798}
1799
1800static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
1801 struct snd_ctl_elem_value *ucontrol)
1802{
1803 /*
1804 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1805 */
1806 u32 h_control = kcontrol->private_value;
1807 short gain;
1808
1809 gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001810 hpi_handle_error(hpi_tuner_set_gain(h_control, gain));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001811
1812 return 1;
1813}
1814
1815/* Band */
1816
1817static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
1818 u16 *band_list, u32 len) {
1819 u32 h_control = kcontrol->private_value;
1820 u16 err = 0;
1821 u32 i;
1822
1823 for (i = 0; i < len; i++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001824 err = hpi_tuner_query_band(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001825 h_control, i, &band_list[i]);
1826 if (err != 0)
1827 break;
1828 }
1829
1830 if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
1831 return -EIO;
1832
1833 return i;
1834}
1835
1836static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1837 struct snd_ctl_elem_info *uinfo)
1838{
1839 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1840 int num_bands = 0;
1841
1842 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1843 HPI_TUNER_BAND_LAST);
1844
1845 if (num_bands < 0)
1846 return num_bands;
1847
Takashi Iwai30d0ae42014-10-20 18:15:50 +02001848 return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001849}
1850
1851static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1852 struct snd_ctl_elem_value *ucontrol)
1853{
1854 u32 h_control = kcontrol->private_value;
1855 /*
1856 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1857 */
1858 u16 band, idx;
1859 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1860 u32 num_bands = 0;
1861
1862 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1863 HPI_TUNER_BAND_LAST);
1864
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001865 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001866
1867 ucontrol->value.enumerated.item[0] = -1;
1868 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1869 if (tuner_bands[idx] == band) {
1870 ucontrol->value.enumerated.item[0] = idx;
1871 break;
1872 }
1873
1874 return 0;
1875}
1876
1877static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1878 struct snd_ctl_elem_value *ucontrol)
1879{
1880 /*
1881 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1882 */
1883 u32 h_control = kcontrol->private_value;
Dan Carpenter0c21fcc2013-09-13 10:44:44 +03001884 unsigned int idx;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001885 u16 band;
1886 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1887 u32 num_bands = 0;
1888
1889 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1890 HPI_TUNER_BAND_LAST);
1891
Dan Carpenter0c21fcc2013-09-13 10:44:44 +03001892 idx = ucontrol->value.enumerated.item[0];
1893 if (idx >= ARRAY_SIZE(tuner_bands))
1894 idx = ARRAY_SIZE(tuner_bands) - 1;
1895 band = tuner_bands[idx];
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001896 hpi_handle_error(hpi_tuner_set_band(h_control, band));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001897
1898 return 1;
1899}
1900
1901/* Freq */
1902
1903static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1904 struct snd_ctl_elem_info *uinfo)
1905{
1906 u32 h_control = kcontrol->private_value;
1907 u16 err;
1908 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1909 u16 num_bands = 0, band_iter, idx;
1910 u32 freq_range[3], temp_freq_range[3];
1911
1912 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1913 HPI_TUNER_BAND_LAST);
1914
1915 freq_range[0] = INT_MAX;
1916 freq_range[1] = 0;
1917 freq_range[2] = INT_MAX;
1918
1919 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1920 for (idx = 0; idx < 3; idx++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001921 err = hpi_tuner_query_frequency(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001922 idx, tuner_bands[band_iter],
1923 &temp_freq_range[idx]);
1924 if (err != 0)
1925 return err;
1926 }
1927
1928 /* skip band with bogus stepping */
1929 if (temp_freq_range[2] <= 0)
1930 continue;
1931
1932 if (temp_freq_range[0] < freq_range[0])
1933 freq_range[0] = temp_freq_range[0];
1934 if (temp_freq_range[1] > freq_range[1])
1935 freq_range[1] = temp_freq_range[1];
1936 if (temp_freq_range[2] < freq_range[2])
1937 freq_range[2] = temp_freq_range[2];
1938 }
1939
1940 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1941 uinfo->count = 1;
1942 uinfo->value.integer.min = ((int)freq_range[0]);
1943 uinfo->value.integer.max = ((int)freq_range[1]);
1944 uinfo->value.integer.step = ((int)freq_range[2]);
1945 return 0;
1946}
1947
1948static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
1949 struct snd_ctl_elem_value *ucontrol)
1950{
1951 u32 h_control = kcontrol->private_value;
1952 u32 freq;
1953
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001954 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001955 ucontrol->value.integer.value[0] = freq;
1956
1957 return 0;
1958}
1959
1960static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
1961 struct snd_ctl_elem_value *ucontrol)
1962{
1963 u32 h_control = kcontrol->private_value;
1964 u32 freq;
1965
1966 freq = ucontrol->value.integer.value[0];
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001967 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001968
1969 return 1;
1970}
1971
1972/* Tuner control group initializer */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001973static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
1974 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001975{
1976 struct snd_card *card = asihpi->card;
1977 struct snd_kcontrol_new snd_control;
1978
1979 snd_control.private_value = hpi_ctl->h_control;
1980 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1981
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001982 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001983 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001984 snd_control.info = snd_asihpi_tuner_gain_info;
1985 snd_control.get = snd_asihpi_tuner_gain_get;
1986 snd_control.put = snd_asihpi_tuner_gain_put;
1987
1988 if (ctl_add(card, &snd_control, asihpi) < 0)
1989 return -EINVAL;
1990 }
1991
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13001992 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001993 snd_control.info = snd_asihpi_tuner_band_info;
1994 snd_control.get = snd_asihpi_tuner_band_get;
1995 snd_control.put = snd_asihpi_tuner_band_put;
1996
1997 if (ctl_add(card, &snd_control, asihpi) < 0)
1998 return -EINVAL;
1999
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002000 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002001 snd_control.info = snd_asihpi_tuner_freq_info;
2002 snd_control.get = snd_asihpi_tuner_freq_get;
2003 snd_control.put = snd_asihpi_tuner_freq_put;
2004
2005 return ctl_add(card, &snd_control, asihpi);
2006}
2007
2008/*------------------------------------------------------------
2009 Meter controls
2010 ------------------------------------------------------------*/
2011static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2012 struct snd_ctl_elem_info *uinfo)
2013{
Eliot Blennerhassettd4b06d22011-12-22 13:38:34 +13002014 u32 h_control = kcontrol->private_value;
2015 u32 count;
2016 u16 err;
2017 err = hpi_meter_query_channels(h_control, &count);
2018 if (err)
2019 count = HPI_MAX_CHANNELS;
2020
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002021 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
Eliot Blennerhassettd4b06d22011-12-22 13:38:34 +13002022 uinfo->count = count;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002023 uinfo->value.integer.min = 0;
2024 uinfo->value.integer.max = 0x7FFFFFFF;
2025 return 0;
2026}
2027
2028/* linear values for 10dB steps */
2029static int log2lin[] = {
2030 0x7FFFFFFF, /* 0dB */
2031 679093956,
2032 214748365,
2033 67909396,
2034 21474837,
2035 6790940,
2036 2147484, /* -60dB */
2037 679094,
2038 214748, /* -80 */
2039 67909,
2040 21475, /* -100 */
2041 6791,
2042 2147,
2043 679,
2044 214,
2045 68,
2046 21,
2047 7,
2048 2
2049};
2050
2051static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2052 struct snd_ctl_elem_value *ucontrol)
2053{
2054 u32 h_control = kcontrol->private_value;
2055 short an_gain_mB[HPI_MAX_CHANNELS], i;
2056 u16 err;
2057
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002058 err = hpi_meter_get_peak(h_control, an_gain_mB);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002059
2060 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2061 if (err) {
2062 ucontrol->value.integer.value[i] = 0;
2063 } else if (an_gain_mB[i] >= 0) {
2064 ucontrol->value.integer.value[i] =
2065 an_gain_mB[i] << 16;
2066 } else {
2067 /* -ve is log value in millibels < -60dB,
2068 * convert to (roughly!) linear,
2069 */
2070 ucontrol->value.integer.value[i] =
2071 log2lin[an_gain_mB[i] / -1000];
2072 }
2073 }
2074 return 0;
2075}
2076
Bill Pembertone23e7a12012-12-06 12:35:10 -05002077static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2078 struct hpi_control *hpi_ctl, int subidx)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002079{
2080 struct snd_card *card = asihpi->card;
2081 struct snd_kcontrol_new snd_control;
2082
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002083 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002084 snd_control.access =
2085 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2086 snd_control.info = snd_asihpi_meter_info;
2087 snd_control.get = snd_asihpi_meter_get;
2088
2089 snd_control.index = subidx;
2090
2091 return ctl_add(card, &snd_control, asihpi);
2092}
2093
2094/*------------------------------------------------------------
2095 Multiplexer controls
2096 ------------------------------------------------------------*/
2097static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2098{
2099 u32 h_control = snd_control->private_value;
2100 struct hpi_control hpi_ctl;
2101 int s, err;
2102 for (s = 0; s < 32; s++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002103 err = hpi_multiplexer_query_source(h_control, s,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002104 &hpi_ctl.
2105 src_node_type,
2106 &hpi_ctl.
2107 src_node_index);
2108 if (err)
2109 break;
2110 }
2111 return s;
2112}
2113
2114static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2115 struct snd_ctl_elem_info *uinfo)
2116{
2117 int err;
2118 u16 src_node_type, src_node_index;
2119 u32 h_control = kcontrol->private_value;
2120
2121 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2122 uinfo->count = 1;
2123 uinfo->value.enumerated.items =
2124 snd_card_asihpi_mux_count_sources(kcontrol);
2125
2126 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2127 uinfo->value.enumerated.item =
2128 uinfo->value.enumerated.items - 1;
2129
2130 err =
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002131 hpi_multiplexer_query_source(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002132 uinfo->value.enumerated.item,
2133 &src_node_type, &src_node_index);
2134
2135 sprintf(uinfo->value.enumerated.name, "%s %d",
Eliot Blennerhassett168f1b02010-07-06 08:37:06 +12002136 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002137 src_node_index);
2138 return 0;
2139}
2140
2141static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2142 struct snd_ctl_elem_value *ucontrol)
2143{
2144 u32 h_control = kcontrol->private_value;
2145 u16 source_type, source_index;
2146 u16 src_node_type, src_node_index;
2147 int s;
2148
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002149 hpi_handle_error(hpi_multiplexer_get_source(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002150 &source_type, &source_index));
2151 /* Should cache this search result! */
2152 for (s = 0; s < 256; s++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002153 if (hpi_multiplexer_query_source(h_control, s,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002154 &src_node_type, &src_node_index))
2155 break;
2156
2157 if ((source_type == src_node_type)
2158 && (source_index == src_node_index)) {
2159 ucontrol->value.enumerated.item[0] = s;
2160 return 0;
2161 }
2162 }
2163 snd_printd(KERN_WARNING
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002164 "Control %x failed to match mux source %hu %hu\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002165 h_control, source_type, source_index);
2166 ucontrol->value.enumerated.item[0] = 0;
2167 return 0;
2168}
2169
2170static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2171 struct snd_ctl_elem_value *ucontrol)
2172{
2173 int change;
2174 u32 h_control = kcontrol->private_value;
2175 u16 source_type, source_index;
2176 u16 e;
2177
2178 change = 1;
2179
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002180 e = hpi_multiplexer_query_source(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002181 ucontrol->value.enumerated.item[0],
2182 &source_type, &source_index);
2183 if (!e)
2184 hpi_handle_error(
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002185 hpi_multiplexer_set_source(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002186 source_type, source_index));
2187 return change;
2188}
2189
2190
Bill Pembertone23e7a12012-12-06 12:35:10 -05002191static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2192 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002193{
2194 struct snd_card *card = asihpi->card;
2195 struct snd_kcontrol_new snd_control;
2196
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002197 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002198 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2199 snd_control.info = snd_asihpi_mux_info;
2200 snd_control.get = snd_asihpi_mux_get;
2201 snd_control.put = snd_asihpi_mux_put;
2202
2203 return ctl_add(card, &snd_control, asihpi);
2204
2205}
2206
2207/*------------------------------------------------------------
2208 Channel mode controls
2209 ------------------------------------------------------------*/
2210static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2211 struct snd_ctl_elem_info *uinfo)
2212{
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002213 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2214 "invalid",
2215 "Normal", "Swap",
2216 "From Left", "From Right",
2217 "To Left", "To Right"
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002218 };
2219
2220 u32 h_control = kcontrol->private_value;
2221 u16 mode;
2222 int i;
Takashi Iwai30d0ae42014-10-20 18:15:50 +02002223 const char *mapped_names[6];
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002224 int valid_modes = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002225
2226 /* HPI channel mode values can be from 1 to 6
2227 Some adapters only support a contiguous subset
2228 */
2229 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002230 if (!hpi_channel_mode_query_mode(
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002231 h_control, i, &mode)) {
Takashi Iwai30d0ae42014-10-20 18:15:50 +02002232 mapped_names[valid_modes] = mode_names[mode];
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002233 valid_modes++;
2234 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002235
Takashi Iwai74eeb142012-01-09 18:26:05 +01002236 if (!valid_modes)
2237 return -EINVAL;
2238
Takashi Iwai30d0ae42014-10-20 18:15:50 +02002239 return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002240}
2241
2242static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
2243 struct snd_ctl_elem_value *ucontrol)
2244{
2245 u32 h_control = kcontrol->private_value;
2246 u16 mode;
2247
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002248 if (hpi_channel_mode_get(h_control, &mode))
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002249 mode = 1;
2250
2251 ucontrol->value.enumerated.item[0] = mode - 1;
2252
2253 return 0;
2254}
2255
2256static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
2257 struct snd_ctl_elem_value *ucontrol)
2258{
2259 int change;
2260 u32 h_control = kcontrol->private_value;
2261
2262 change = 1;
2263
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002264 hpi_handle_error(hpi_channel_mode_set(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002265 ucontrol->value.enumerated.item[0] + 1));
2266 return change;
2267}
2268
2269
Bill Pembertone23e7a12012-12-06 12:35:10 -05002270static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2271 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002272{
2273 struct snd_card *card = asihpi->card;
2274 struct snd_kcontrol_new snd_control;
2275
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002276 asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002277 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2278 snd_control.info = snd_asihpi_cmode_info;
2279 snd_control.get = snd_asihpi_cmode_get;
2280 snd_control.put = snd_asihpi_cmode_put;
2281
2282 return ctl_add(card, &snd_control, asihpi);
2283}
2284
2285/*------------------------------------------------------------
2286 Sampleclock source controls
2287 ------------------------------------------------------------*/
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13002288static const char const *sampleclock_sources[] = {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002289 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2290 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13002291 "Prev Module", "BLU-Link",
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002292 "Digital2", "Digital3", "Digital4", "Digital5",
2293 "Digital6", "Digital7", "Digital8"};
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002294
Eliot Blennerhassett3872f192014-11-20 16:22:49 +13002295 /* Number of strings must match expected enumerated values */
2296 compile_time_assert(
2297 (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES),
2298 assert_sampleclock_sources_size);
2299
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002300static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_info *uinfo)
2302{
2303 struct snd_card_asihpi *asihpi =
2304 (struct snd_card_asihpi *)(kcontrol->private_data);
2305 struct clk_cache *clkcache = &asihpi->cc;
2306 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2307 uinfo->count = 1;
2308 uinfo->value.enumerated.items = clkcache->count;
2309
2310 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2311 uinfo->value.enumerated.item =
2312 uinfo->value.enumerated.items - 1;
2313
2314 strcpy(uinfo->value.enumerated.name,
2315 clkcache->s[uinfo->value.enumerated.item].name);
2316 return 0;
2317}
2318
2319static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
2320 struct snd_ctl_elem_value *ucontrol)
2321{
2322 struct snd_card_asihpi *asihpi =
2323 (struct snd_card_asihpi *)(kcontrol->private_data);
2324 struct clk_cache *clkcache = &asihpi->cc;
2325 u32 h_control = kcontrol->private_value;
2326 u16 source, srcindex = 0;
2327 int i;
2328
2329 ucontrol->value.enumerated.item[0] = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002330 if (hpi_sample_clock_get_source(h_control, &source))
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002331 source = 0;
2332
2333 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002334 if (hpi_sample_clock_get_source_index(h_control, &srcindex))
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002335 srcindex = 0;
2336
2337 for (i = 0; i < clkcache->count; i++)
2338 if ((clkcache->s[i].source == source) &&
2339 (clkcache->s[i].index == srcindex))
2340 break;
2341
2342 ucontrol->value.enumerated.item[0] = i;
2343
2344 return 0;
2345}
2346
2347static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2348 struct snd_ctl_elem_value *ucontrol)
2349{
2350 struct snd_card_asihpi *asihpi =
2351 (struct snd_card_asihpi *)(kcontrol->private_data);
2352 struct clk_cache *clkcache = &asihpi->cc;
Dan Carpenter0c21fcc2013-09-13 10:44:44 +03002353 unsigned int item;
2354 int change;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002355 u32 h_control = kcontrol->private_value;
2356
2357 change = 1;
2358 item = ucontrol->value.enumerated.item[0];
2359 if (item >= clkcache->count)
2360 item = clkcache->count-1;
2361
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002362 hpi_handle_error(hpi_sample_clock_set_source(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002363 h_control, clkcache->s[item].source));
2364
2365 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002366 hpi_handle_error(hpi_sample_clock_set_source_index(
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002367 h_control, clkcache->s[item].index));
2368 return change;
2369}
2370
2371/*------------------------------------------------------------
2372 Clkrate controls
2373 ------------------------------------------------------------*/
2374/* Need to change this to enumerated control with list of rates */
2375static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2376 struct snd_ctl_elem_info *uinfo)
2377{
2378 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2379 uinfo->count = 1;
2380 uinfo->value.integer.min = 8000;
2381 uinfo->value.integer.max = 192000;
2382 uinfo->value.integer.step = 100;
2383
2384 return 0;
2385}
2386
2387static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2388 struct snd_ctl_elem_value *ucontrol)
2389{
2390 u32 h_control = kcontrol->private_value;
2391 u32 rate;
2392 u16 e;
2393
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002394 e = hpi_sample_clock_get_local_rate(h_control, &rate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002395 if (!e)
2396 ucontrol->value.integer.value[0] = rate;
2397 else
2398 ucontrol->value.integer.value[0] = 0;
2399 return 0;
2400}
2401
2402static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2404{
2405 int change;
2406 u32 h_control = kcontrol->private_value;
2407
2408 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2409 asihpi->mixer_clkrate[addr][1] != right;
2410 */
2411 change = 1;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002412 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002413 ucontrol->value.integer.value[0]));
2414 return change;
2415}
2416
2417static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2418 struct snd_ctl_elem_info *uinfo)
2419{
2420 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2421 uinfo->count = 1;
2422 uinfo->value.integer.min = 8000;
2423 uinfo->value.integer.max = 192000;
2424 uinfo->value.integer.step = 100;
2425
2426 return 0;
2427}
2428
2429static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_value *ucontrol)
2431{
2432 u32 h_control = kcontrol->private_value;
2433 u32 rate;
2434 u16 e;
2435
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002436 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002437 if (!e)
2438 ucontrol->value.integer.value[0] = rate;
2439 else
2440 ucontrol->value.integer.value[0] = 0;
2441 return 0;
2442}
2443
Bill Pembertone23e7a12012-12-06 12:35:10 -05002444static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2445 struct hpi_control *hpi_ctl)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002446{
2447 struct snd_card *card = asihpi->card;
2448 struct snd_kcontrol_new snd_control;
2449
2450 struct clk_cache *clkcache = &asihpi->cc;
2451 u32 hSC = hpi_ctl->h_control;
2452 int has_aes_in = 0;
2453 int i, j;
2454 u16 source;
2455
2456 snd_control.private_value = hpi_ctl->h_control;
2457
2458 clkcache->has_local = 0;
2459
2460 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002461 if (hpi_sample_clock_query_source(hSC,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002462 i, &source))
2463 break;
2464 clkcache->s[i].source = source;
2465 clkcache->s[i].index = 0;
2466 clkcache->s[i].name = sampleclock_sources[source];
2467 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2468 has_aes_in = 1;
2469 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2470 clkcache->has_local = 1;
2471 }
2472 if (has_aes_in)
2473 /* already will have picked up index 0 above */
2474 for (j = 1; j < 8; j++) {
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002475 if (hpi_sample_clock_query_source_index(hSC,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002476 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2477 &source))
2478 break;
2479 clkcache->s[i].source =
2480 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2481 clkcache->s[i].index = j;
2482 clkcache->s[i].name = sampleclock_sources[
2483 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2484 i++;
2485 }
2486 clkcache->count = i;
2487
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002488 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002489 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2490 snd_control.info = snd_asihpi_clksrc_info;
2491 snd_control.get = snd_asihpi_clksrc_get;
2492 snd_control.put = snd_asihpi_clksrc_put;
2493 if (ctl_add(card, &snd_control, asihpi) < 0)
2494 return -EINVAL;
2495
2496
2497 if (clkcache->has_local) {
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002498 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002499 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2500 snd_control.info = snd_asihpi_clklocal_info;
2501 snd_control.get = snd_asihpi_clklocal_get;
2502 snd_control.put = snd_asihpi_clklocal_put;
2503
2504
2505 if (ctl_add(card, &snd_control, asihpi) < 0)
2506 return -EINVAL;
2507 }
2508
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002509 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002510 snd_control.access =
2511 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2512 snd_control.info = snd_asihpi_clkrate_info;
2513 snd_control.get = snd_asihpi_clkrate_get;
2514
2515 return ctl_add(card, &snd_control, asihpi);
2516}
2517/*------------------------------------------------------------
2518 Mixer
2519 ------------------------------------------------------------*/
2520
Bill Pembertone23e7a12012-12-06 12:35:10 -05002521static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002522{
Wei Yongjun2e9b9a32013-03-12 00:16:40 +08002523 struct snd_card *card;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002524 unsigned int idx = 0;
2525 unsigned int subindex = 0;
2526 int err;
2527 struct hpi_control hpi_ctl, prev_ctl;
2528
2529 if (snd_BUG_ON(!asihpi))
2530 return -EINVAL;
Wei Yongjun2e9b9a32013-03-12 00:16:40 +08002531 card = asihpi->card;
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002532 strcpy(card->mixername, "Asihpi Mixer");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002533
2534 err =
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002535 hpi_mixer_open(asihpi->hpi->adapter->index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002536 &asihpi->h_mixer);
2537 hpi_handle_error(err);
2538 if (err)
2539 return -err;
2540
Takashi Iwai21896bc2010-06-02 12:08:37 +02002541 memset(&prev_ctl, 0, sizeof(prev_ctl));
2542 prev_ctl.control_type = -1;
2543
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002544 for (idx = 0; idx < 2000; idx++) {
2545 err = hpi_mixer_get_control_by_index(
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002546 asihpi->h_mixer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002547 idx,
2548 &hpi_ctl.src_node_type,
2549 &hpi_ctl.src_node_index,
2550 &hpi_ctl.dst_node_type,
2551 &hpi_ctl.dst_node_index,
2552 &hpi_ctl.control_type,
2553 &hpi_ctl.h_control);
2554 if (err) {
2555 if (err == HPI_ERROR_CONTROL_DISABLED) {
2556 if (mixer_dump)
2557 snd_printk(KERN_INFO
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002558 "Disabled HPI Control(%d)\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002559 idx);
2560 continue;
2561 } else
2562 break;
2563
2564 }
2565
Eliot Blennerhassett168f1b02010-07-06 08:37:06 +12002566 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2567 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002568
2569 /* ASI50xx in SSX mode has multiple meters on the same node.
2570 Use subindex to create distinct ALSA controls
2571 for any duplicated controls.
2572 */
2573 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2574 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2575 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2576 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2577 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2578 subindex++;
2579 else
2580 subindex = 0;
2581
2582 prev_ctl = hpi_ctl;
2583
2584 switch (hpi_ctl.control_type) {
2585 case HPI_CONTROL_VOLUME:
2586 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2587 break;
2588 case HPI_CONTROL_LEVEL:
2589 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2590 break;
2591 case HPI_CONTROL_MULTIPLEXER:
2592 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2593 break;
2594 case HPI_CONTROL_CHANNEL_MODE:
2595 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2596 break;
2597 case HPI_CONTROL_METER:
2598 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2599 break;
2600 case HPI_CONTROL_SAMPLECLOCK:
2601 err = snd_asihpi_sampleclock_add(
2602 asihpi, &hpi_ctl);
2603 break;
2604 case HPI_CONTROL_CONNECTION: /* ignore these */
2605 continue;
2606 case HPI_CONTROL_TUNER:
2607 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2608 break;
2609 case HPI_CONTROL_AESEBU_TRANSMITTER:
2610 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2611 break;
2612 case HPI_CONTROL_AESEBU_RECEIVER:
2613 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2614 break;
2615 case HPI_CONTROL_VOX:
2616 case HPI_CONTROL_BITSTREAM:
2617 case HPI_CONTROL_MICROPHONE:
2618 case HPI_CONTROL_PARAMETRIC_EQ:
2619 case HPI_CONTROL_COMPANDER:
2620 default:
2621 if (mixer_dump)
2622 snd_printk(KERN_INFO
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002623 "Untranslated HPI Control"
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002624 "(%d) %d %d %d %d %d\n",
2625 idx,
2626 hpi_ctl.control_type,
2627 hpi_ctl.src_node_type,
2628 hpi_ctl.src_node_index,
2629 hpi_ctl.dst_node_type,
2630 hpi_ctl.dst_node_index);
2631 continue;
Peter Senna Tschudin395d9dd2012-09-28 11:24:57 +02002632 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002633 if (err < 0)
2634 return err;
2635 }
2636 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2637 hpi_handle_error(err);
2638
2639 snd_printk(KERN_INFO "%d mixer controls found\n", idx);
2640
2641 return 0;
2642}
2643
2644/*------------------------------------------------------------
2645 /proc interface
2646 ------------------------------------------------------------*/
2647
2648static void
2649snd_asihpi_proc_read(struct snd_info_entry *entry,
2650 struct snd_info_buffer *buffer)
2651{
2652 struct snd_card_asihpi *asihpi = entry->private_data;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002653 u32 h_control;
2654 u32 rate = 0;
2655 u16 source = 0;
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002656
2657 u16 num_outstreams;
2658 u16 num_instreams;
2659 u16 version;
2660 u32 serial_number;
2661 u16 type;
2662
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002663 int err;
2664
2665 snd_iprintf(buffer, "ASIHPI driver proc file\n");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002666
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002667 hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index,
2668 &num_outstreams, &num_instreams,
2669 &version, &serial_number, &type));
2670
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002671 snd_iprintf(buffer,
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002672 "Adapter type ASI%4X\nHardware Index %d\n"
2673 "%d outstreams\n%d instreams\n",
2674 type, asihpi->hpi->adapter->index,
2675 num_outstreams, num_instreams);
2676
2677 snd_iprintf(buffer,
2678 "Serial#%d\nHardware version %c%d\nDSP code version %03d\n",
2679 serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002680 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2681
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002682 err = hpi_mixer_get_control(asihpi->h_mixer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002683 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2684 HPI_CONTROL_SAMPLECLOCK, &h_control);
2685
2686 if (!err) {
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002687 err = hpi_sample_clock_get_sample_rate(h_control, &rate);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002688 err += hpi_sample_clock_get_source(h_control, &source);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002689
2690 if (!err)
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002691 snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002692 rate, sampleclock_sources[source]);
2693 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002694}
2695
Bill Pembertone23e7a12012-12-06 12:35:10 -05002696static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002697{
2698 struct snd_info_entry *entry;
2699
2700 if (!snd_card_proc_new(asihpi->card, "info", &entry))
2701 snd_info_set_text_ops(entry, asihpi, snd_asihpi_proc_read);
2702}
2703
2704/*------------------------------------------------------------
2705 HWDEP
2706 ------------------------------------------------------------*/
2707
2708static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2709{
2710 if (enable_hpi_hwdep)
2711 return 0;
2712 else
2713 return -ENODEV;
2714
2715}
2716
2717static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2718{
2719 if (enable_hpi_hwdep)
2720 return asihpi_hpi_release(file);
2721 else
2722 return -ENODEV;
2723}
2724
2725static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2726 unsigned int cmd, unsigned long arg)
2727{
2728 if (enable_hpi_hwdep)
2729 return asihpi_hpi_ioctl(file, cmd, arg);
2730 else
2731 return -ENODEV;
2732}
2733
2734
2735/* results in /dev/snd/hwC#D0 file for each card with index #
2736 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2737*/
Bill Pembertone23e7a12012-12-06 12:35:10 -05002738static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi,
2739 int device, struct snd_hwdep **rhwdep)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002740{
2741 struct snd_hwdep *hw;
2742 int err;
2743
2744 if (rhwdep)
2745 *rhwdep = NULL;
2746 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2747 if (err < 0)
2748 return err;
2749 strcpy(hw->name, "asihpi (HPI)");
2750 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2751 hw->ops.open = snd_asihpi_hpi_open;
2752 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2753 hw->ops.release = snd_asihpi_hpi_release;
2754 hw->private_data = asihpi;
2755 if (rhwdep)
2756 *rhwdep = hw;
2757 return 0;
2758}
2759
2760/*------------------------------------------------------------
2761 CARD
2762 ------------------------------------------------------------*/
Bill Pembertone23e7a12012-12-06 12:35:10 -05002763static int snd_asihpi_probe(struct pci_dev *pci_dev,
2764 const struct pci_device_id *pci_id)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002765{
2766 int err;
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002767 struct hpi_adapter *hpi;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002768 struct snd_card *card;
2769 struct snd_card_asihpi *asihpi;
2770
2771 u32 h_control;
2772 u32 h_stream;
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002773 u32 adapter_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002774
2775 static int dev;
2776 if (dev >= SNDRV_CARDS)
2777 return -ENODEV;
2778
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002779 /* Should this be enable[hpi->index] ? */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002780 if (!enable[dev]) {
2781 dev++;
2782 return -ENOENT;
2783 }
2784
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002785 /* Initialise low-level HPI driver */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002786 err = asihpi_adapter_probe(pci_dev, pci_id);
2787 if (err < 0)
2788 return err;
2789
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002790 hpi = pci_get_drvdata(pci_dev);
2791 adapter_index = hpi->adapter->index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002792 /* first try to give the card the same index as its hardware index */
Takashi Iwai60c57722014-01-29 14:20:19 +01002793 err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index],
2794 THIS_MODULE, sizeof(struct snd_card_asihpi), &card);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002795 if (err < 0) {
2796 /* if that fails, try the default index==next available */
Takashi Iwai60c57722014-01-29 14:20:19 +01002797 err = snd_card_new(&pci_dev->dev, index[dev], id[dev],
2798 THIS_MODULE, sizeof(struct snd_card_asihpi),
2799 &card);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002800 if (err < 0)
2801 return err;
2802 snd_printk(KERN_WARNING
Eliot Blennerhassette64b1a22011-02-10 17:25:59 +13002803 "**** WARNING **** Adapter index %d->ALSA index %d\n",
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002804 adapter_index, card->number);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002805 }
2806
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002807 asihpi = card->private_data;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002808 asihpi->card = card;
Eliot Blennerhassett12253672011-02-10 17:26:10 +13002809 asihpi->pci = pci_dev;
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002810 asihpi->hpi = hpi;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002811
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002812 snd_printk(KERN_INFO "adapter ID=%4X index=%d\n",
2813 asihpi->hpi->adapter->type, adapter_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002814
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002815 err = hpi_adapter_get_property(adapter_index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002816 HPI_ADAPTER_PROPERTY_CAPS1,
2817 NULL, &asihpi->support_grouping);
2818 if (err)
2819 asihpi->support_grouping = 0;
2820
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002821 err = hpi_adapter_get_property(adapter_index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002822 HPI_ADAPTER_PROPERTY_CAPS2,
2823 &asihpi->support_mrx, NULL);
2824 if (err)
2825 asihpi->support_mrx = 0;
2826
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002827 err = hpi_adapter_get_property(adapter_index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002828 HPI_ADAPTER_PROPERTY_INTERVAL,
2829 NULL, &asihpi->update_interval_frames);
2830 if (err)
2831 asihpi->update_interval_frames = 512;
2832
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12002833 if (!asihpi->can_dma)
Eliot Blennerhassett26aebef2011-03-25 15:25:47 +13002834 asihpi->update_interval_frames *= 2;
2835
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002836 hpi_handle_error(hpi_instream_open(adapter_index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002837 0, &h_stream));
2838
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002839 err = hpi_instream_host_buffer_free(h_stream);
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12002840 asihpi->can_dma = (!err);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002841
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002842 hpi_handle_error(hpi_instream_close(h_stream));
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002843
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002844 err = hpi_adapter_get_property(adapter_index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002845 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2846 &asihpi->in_max_chans, &asihpi->out_max_chans);
2847 if (err) {
2848 asihpi->in_max_chans = 2;
2849 asihpi->out_max_chans = 2;
2850 }
2851
Eliot Blennerhassettc382a5d2011-12-22 13:38:33 +13002852 if (asihpi->out_max_chans > 2) { /* assume LL mode */
2853 asihpi->out_min_chans = asihpi->out_max_chans;
2854 asihpi->in_min_chans = asihpi->in_max_chans;
2855 asihpi->support_grouping = 0;
2856 } else {
2857 asihpi->out_min_chans = 1;
2858 asihpi->in_min_chans = 1;
2859 }
2860
Eliot Blennerhassett35a8dc12014-11-20 16:22:50 +13002861 snd_printk(KERN_INFO "update_interval_frames: %d",
2862 asihpi->update_interval_frames);
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002863 snd_printk(KERN_INFO "Has dma:%d, grouping:%d, mrx:%d\n",
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12002864 asihpi->can_dma,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002865 asihpi->support_grouping,
2866 asihpi->support_mrx
2867 );
2868
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002869 err = snd_card_asihpi_pcm_new(asihpi, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002870 if (err < 0) {
2871 snd_printk(KERN_ERR "pcm_new failed\n");
2872 goto __nodev;
2873 }
2874 err = snd_card_asihpi_mixer_new(asihpi);
2875 if (err < 0) {
2876 snd_printk(KERN_ERR "mixer_new failed\n");
2877 goto __nodev;
2878 }
2879
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002880 err = hpi_mixer_get_control(asihpi->h_mixer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002881 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2882 HPI_CONTROL_SAMPLECLOCK, &h_control);
2883
2884 if (!err)
2885 err = hpi_sample_clock_set_local_rate(
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002886 h_control, adapter_fs);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002887
2888 snd_asihpi_proc_init(asihpi);
2889
2890 /* always create, can be enabled or disabled dynamically
2891 by enable_hwdep module param*/
2892 snd_asihpi_hpi_new(asihpi, 0, NULL);
2893
Eliot Blennerhassettf3d145a2011-04-05 20:55:44 +12002894 strcpy(card->driver, "ASIHPI");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002895
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002896 sprintf(card->shortname, "AudioScience ASI%4X",
2897 asihpi->hpi->adapter->type);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002898 sprintf(card->longname, "%s %i",
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002899 card->shortname, adapter_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002900 err = snd_card_register(card);
Eliot Blennerhassettb2e65c82011-03-25 15:25:48 +13002901
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002902 if (!err) {
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002903 hpi->snd_card = card;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002904 dev++;
2905 return 0;
2906 }
2907__nodev:
2908 snd_card_free(card);
2909 snd_printk(KERN_ERR "snd_asihpi_probe error %d\n", err);
2910 return err;
2911
2912}
2913
Bill Pembertone23e7a12012-12-06 12:35:10 -05002914static void snd_asihpi_remove(struct pci_dev *pci_dev)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002915{
Eliot Blennerhassett7036b922011-12-22 13:38:43 +13002916 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
2917 snd_card_free(hpi->snd_card);
2918 hpi->snd_card = NULL;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002919 asihpi_adapter_remove(pci_dev);
2920}
2921
Benoit Taine9baa3c32014-08-08 15:56:03 +02002922static const struct pci_device_id asihpi_pci_tbl[] = {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002923 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
2924 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2925 (kernel_ulong_t)HPI_6205},
2926 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
2927 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2928 (kernel_ulong_t)HPI_6000},
2929 {0,}
2930};
2931MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
2932
2933static struct pci_driver driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +02002934 .name = KBUILD_MODNAME,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002935 .id_table = asihpi_pci_tbl,
2936 .probe = snd_asihpi_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -05002937 .remove = snd_asihpi_remove,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002938};
2939
2940static int __init snd_asihpi_init(void)
2941{
2942 asihpi_init();
2943 return pci_register_driver(&driver);
2944}
2945
2946static void __exit snd_asihpi_exit(void)
2947{
2948
2949 pci_unregister_driver(&driver);
2950 asihpi_exit();
2951}
2952
2953module_init(snd_asihpi_init)
2954module_exit(snd_asihpi_exit)
2955