blob: 9cd297a42f24dfc258634583d395a8a7950a7a2b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for Digigram miXart soundcards
3 *
4 * main file with alsa callbacks
5 *
6 * Copyright (c) 2003 by Digigram <alsa@digigram.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
Tobias Klauser9d2f9282006-03-22 10:53:19 +010027#include <linux/dma-mapping.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040028#include <linux/module.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010029#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <sound/core.h>
33#include <sound/initval.h>
34#include <sound/info.h>
35#include <sound/control.h>
36#include <sound/pcm.h>
37#include <sound/pcm_params.h>
38#include "mixart.h"
39#include "mixart_hwdep.h"
40#include "mixart_core.h"
41#include "mixart_mixer.h"
42
43#define CARD_NAME "miXart"
44
45MODULE_AUTHOR("Digigram <alsa@digigram.com>");
46MODULE_DESCRIPTION("Digigram " CARD_NAME);
47MODULE_LICENSE("GPL");
48MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}");
49
50static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
51static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103052static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54module_param_array(index, int, NULL, 0444);
55MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
56module_param_array(id, charp, NULL, 0444);
57MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
58module_param_array(enable, bool, NULL, 0444);
59MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
60
61/*
62 */
63
Benoit Taine9baa3c32014-08-08 15:56:03 +020064static const struct pci_device_id snd_mixart_ids[] = {
Joe Perches28d27aa2009-06-24 22:13:35 -070065 { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 { 0, }
67};
68
69MODULE_DEVICE_TABLE(pci, snd_mixart_ids);
70
71
Takashi Iwai67b48b82005-11-17 15:01:08 +010072static int mixart_set_pipe_state(struct mixart_mgr *mgr,
73 struct mixart_pipe *pipe, int start)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Takashi Iwai67b48b82005-11-17 15:01:08 +010075 struct mixart_group_state_req group_state;
76 struct mixart_group_state_resp group_state_resp;
77 struct mixart_msg request;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 int err;
79 u32 system_msg_uid;
80
81 switch(pipe->status) {
82 case PIPE_RUNNING:
83 case PIPE_CLOCK_SET:
84 if(start) return 0; /* already started */
85 break;
86 case PIPE_STOPPED:
87 if(!start) return 0; /* already stopped */
88 break;
89 default:
Takashi Iwai6414e352014-02-25 17:51:46 +010090 dev_err(&mgr->pci->dev,
91 "error mixart_set_pipe_state called with wrong pipe->status!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 return -EINVAL; /* function called with wrong pipe status */
93 }
94
95 system_msg_uid = 0x12345678; /* the event ! (take care: the MSB and two LSB's have to be 0) */
96
97 /* wait on the last MSG_SYSTEM_SEND_SYNCHRO_CMD command to be really finished */
98
99 request.message_id = MSG_SYSTEM_WAIT_SYNCHRO_CMD;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100100 request.uid = (struct mixart_uid){0,0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 request.data = &system_msg_uid;
102 request.size = sizeof(system_msg_uid);
103
104 err = snd_mixart_send_msg_wait_notif(mgr, &request, system_msg_uid);
105 if(err) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100106 dev_err(&mgr->pci->dev,
107 "error : MSG_SYSTEM_WAIT_SYNCHRO_CMD was not notified !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return err;
109 }
110
111 /* start or stop the pipe (1 pipe) */
112
113 memset(&group_state, 0, sizeof(group_state));
114 group_state.pipe_count = 1;
115 group_state.pipe_uid[0] = pipe->group_uid;
116
117 if(start)
118 request.message_id = MSG_STREAM_START_STREAM_GRP_PACKET;
119 else
120 request.message_id = MSG_STREAM_STOP_STREAM_GRP_PACKET;
121
Takashi Iwai67b48b82005-11-17 15:01:08 +0100122 request.uid = pipe->group_uid; /*(struct mixart_uid){0,0};*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 request.data = &group_state;
124 request.size = sizeof(group_state);
125
126 err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp);
127 if (err < 0 || group_state_resp.txx_status != 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100128 dev_err(&mgr->pci->dev,
129 "error MSG_STREAM_ST***_STREAM_GRP_PACKET err=%x stat=%x !\n",
130 err, group_state_resp.txx_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return -EINVAL;
132 }
133
134 if(start) {
Dan Carpenter8cf39682016-03-16 10:42:13 +0300135 u32 stat = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 group_state.pipe_count = 0; /* in case of start same command once again with pipe_count=0 */
138
139 err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp);
140 if (err < 0 || group_state_resp.txx_status != 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100141 dev_err(&mgr->pci->dev,
142 "error MSG_STREAM_START_STREAM_GRP_PACKET err=%x stat=%x !\n",
143 err, group_state_resp.txx_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return -EINVAL;
145 }
146
147 /* in case of start send a synchro top */
148
149 request.message_id = MSG_SYSTEM_SEND_SYNCHRO_CMD;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100150 request.uid = (struct mixart_uid){0,0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 request.data = NULL;
152 request.size = 0;
153
154 err = snd_mixart_send_msg(mgr, &request, sizeof(stat), &stat);
155 if (err < 0 || stat != 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100156 dev_err(&mgr->pci->dev,
157 "error MSG_SYSTEM_SEND_SYNCHRO_CMD err=%x stat=%x !\n",
158 err, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return -EINVAL;
160 }
161
162 pipe->status = PIPE_RUNNING;
163 }
164 else /* !start */
165 pipe->status = PIPE_STOPPED;
166
167 return 0;
168}
169
170
Takashi Iwai67b48b82005-11-17 15:01:08 +0100171static int mixart_set_clock(struct mixart_mgr *mgr,
172 struct mixart_pipe *pipe, unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100174 struct mixart_msg request;
175 struct mixart_clock_properties clock_properties;
176 struct mixart_clock_properties_resp clock_prop_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 int err;
178
179 switch(pipe->status) {
180 case PIPE_CLOCK_SET:
181 break;
182 case PIPE_RUNNING:
183 if(rate != 0)
184 break;
Gustavo A. R. Silvaac69c2f2018-08-04 15:11:03 -0500185 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 default:
187 if(rate == 0)
188 return 0; /* nothing to do */
189 else {
Takashi Iwai6414e352014-02-25 17:51:46 +0100190 dev_err(&mgr->pci->dev,
191 "error mixart_set_clock(%d) called with wrong pipe->status !\n",
192 rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return -EINVAL;
194 }
195 }
196
197 memset(&clock_properties, 0, sizeof(clock_properties));
198 clock_properties.clock_generic_type = (rate != 0) ? CGT_INTERNAL_CLOCK : CGT_NO_CLOCK;
199 clock_properties.clock_mode = CM_STANDALONE;
200 clock_properties.frequency = rate;
201 clock_properties.nb_callers = 1; /* only one entry in uid_caller ! */
202 clock_properties.uid_caller[0] = pipe->group_uid;
203
Takashi Iwai6414e352014-02-25 17:51:46 +0100204 dev_dbg(&mgr->pci->dev, "mixart_set_clock to %d kHz\n", rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 request.message_id = MSG_CLOCK_SET_PROPERTIES;
207 request.uid = mgr->uid_console_manager;
208 request.data = &clock_properties;
209 request.size = sizeof(clock_properties);
210
211 err = snd_mixart_send_msg(mgr, &request, sizeof(clock_prop_resp), &clock_prop_resp);
212 if (err < 0 || clock_prop_resp.status != 0 || clock_prop_resp.clock_mode != CM_STANDALONE) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100213 dev_err(&mgr->pci->dev,
214 "error MSG_CLOCK_SET_PROPERTIES err=%x stat=%x mod=%x !\n",
215 err, clock_prop_resp.status, clock_prop_resp.clock_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return -EINVAL;
217 }
218
219 if(rate) pipe->status = PIPE_CLOCK_SET;
220 else pipe->status = PIPE_RUNNING;
221
222 return 0;
223}
224
225
226/*
227 * Allocate or reference output pipe for analog IOs (pcmp0/1)
228 */
Takashi Iwai67b48b82005-11-17 15:01:08 +0100229struct mixart_pipe *
230snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture,
231 int monitoring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 int stream_count;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100234 struct mixart_pipe *pipe;
235 struct mixart_msg request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 if(capture) {
238 if (pcm_number == MIXART_PCM_ANALOG) {
239 pipe = &(chip->pipe_in_ana); /* analog inputs */
240 } else {
241 pipe = &(chip->pipe_in_dig); /* digital inputs */
242 }
243 request.message_id = MSG_STREAM_ADD_OUTPUT_GROUP;
244 stream_count = MIXART_CAPTURE_STREAMS;
245 } else {
246 if (pcm_number == MIXART_PCM_ANALOG) {
247 pipe = &(chip->pipe_out_ana); /* analog outputs */
248 } else {
249 pipe = &(chip->pipe_out_dig); /* digital outputs */
250 }
251 request.message_id = MSG_STREAM_ADD_INPUT_GROUP;
252 stream_count = MIXART_PLAYBACK_STREAMS;
253 }
254
255 /* a new stream is opened and there are already all streams in use */
256 if( (monitoring == 0) && (pipe->references >= stream_count) ) {
257 return NULL;
258 }
259
260 /* pipe is not yet defined */
261 if( pipe->status == PIPE_UNDEFINED ) {
262 int err, i;
263 struct {
Takashi Iwai67b48b82005-11-17 15:01:08 +0100264 struct mixart_streaming_group_req sgroup_req;
265 struct mixart_streaming_group sgroup_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 } *buf;
267
Takashi Iwai6414e352014-02-25 17:51:46 +0100268 dev_dbg(chip->card->dev,
269 "add_ref_pipe audio chip(%d) pcm(%d)\n",
270 chip->chip_idx, pcm_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
273 if (!buf)
274 return NULL;
275
Takashi Iwai67b48b82005-11-17 15:01:08 +0100276 request.uid = (struct mixart_uid){0,0}; /* should be StreamManagerUID, but zero is OK if there is only one ! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 request.data = &buf->sgroup_req;
278 request.size = sizeof(buf->sgroup_req);
279
280 memset(&buf->sgroup_req, 0, sizeof(buf->sgroup_req));
281
282 buf->sgroup_req.stream_count = stream_count;
283 buf->sgroup_req.channel_count = 2;
284 buf->sgroup_req.latency = 256;
285 buf->sgroup_req.connector = pipe->uid_left_connector; /* the left connector */
286
287 for (i=0; i<stream_count; i++) {
288 int j;
289 struct mixart_flowinfo *flowinfo;
290 struct mixart_bufferinfo *bufferinfo;
291
292 /* we don't yet know the format, so config 16 bit pcm audio for instance */
293 buf->sgroup_req.stream_info[i].size_max_byte_frame = 1024;
294 buf->sgroup_req.stream_info[i].size_max_sample_frame = 256;
295 buf->sgroup_req.stream_info[i].nb_bytes_max_per_sample = MIXART_FLOAT_P__4_0_TO_HEX; /* is 4.0f */
296
297 /* find the right bufferinfo_array */
298 j = (chip->chip_idx * MIXART_MAX_STREAM_PER_CARD) + (pcm_number * (MIXART_PLAYBACK_STREAMS + MIXART_CAPTURE_STREAMS)) + i;
299 if(capture) j += MIXART_PLAYBACK_STREAMS; /* in the array capture is behind playback */
300
301 buf->sgroup_req.flow_entry[i] = j;
302
303 flowinfo = (struct mixart_flowinfo *)chip->mgr->flowinfo.area;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100304 flowinfo[j].bufferinfo_array_phy_address = (u32)chip->mgr->bufferinfo.addr + (j * sizeof(struct mixart_bufferinfo));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 flowinfo[j].bufferinfo_count = 1; /* 1 will set the miXart to ring-buffer mode ! */
306
307 bufferinfo = (struct mixart_bufferinfo *)chip->mgr->bufferinfo.area;
308 bufferinfo[j].buffer_address = 0; /* buffer is not yet allocated */
309 bufferinfo[j].available_length = 0; /* buffer is not yet allocated */
310
311 /* construct the identifier of the stream buffer received in the interrupts ! */
312 bufferinfo[j].buffer_id = (chip->chip_idx << MIXART_NOTIFY_CARD_OFFSET) + (pcm_number << MIXART_NOTIFY_PCM_OFFSET ) + i;
313 if(capture) {
314 bufferinfo[j].buffer_id |= MIXART_NOTIFY_CAPT_MASK;
315 }
316 }
317
318 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(buf->sgroup_resp), &buf->sgroup_resp);
319 if((err < 0) || (buf->sgroup_resp.status != 0)) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100320 dev_err(chip->card->dev,
321 "error MSG_STREAM_ADD_**PUT_GROUP err=%x stat=%x !\n",
322 err, buf->sgroup_resp.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 kfree(buf);
324 return NULL;
325 }
326
327 pipe->group_uid = buf->sgroup_resp.group; /* id of the pipe, as returned by embedded */
328 pipe->stream_count = buf->sgroup_resp.stream_count;
329 /* pipe->stream_uid[i] = buf->sgroup_resp.stream[i].stream_uid; */
330
331 pipe->status = PIPE_STOPPED;
332 kfree(buf);
333 }
334
335 if(monitoring) pipe->monitoring = 1;
336 else pipe->references++;
337
338 return pipe;
339}
340
341
Takashi Iwai67b48b82005-11-17 15:01:08 +0100342int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr,
343 struct mixart_pipe *pipe, int monitoring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
345 int err = 0;
346
347 if(pipe->status == PIPE_UNDEFINED)
348 return 0;
349
350 if(monitoring)
351 pipe->monitoring = 0;
352 else
353 pipe->references--;
354
355 if((pipe->references <= 0) && (pipe->monitoring == 0)) {
356
Takashi Iwai67b48b82005-11-17 15:01:08 +0100357 struct mixart_msg request;
358 struct mixart_delete_group_resp delete_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 /* release the clock */
361 err = mixart_set_clock( mgr, pipe, 0);
362 if( err < 0 ) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100363 dev_err(&mgr->pci->dev,
364 "mixart_set_clock(0) return error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
367 /* stop the pipe */
368 err = mixart_set_pipe_state(mgr, pipe, 0);
369 if( err < 0 ) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100370 dev_err(&mgr->pci->dev, "error stopping pipe!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372
373 request.message_id = MSG_STREAM_DELETE_GROUP;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100374 request.uid = (struct mixart_uid){0,0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 request.data = &pipe->group_uid; /* the streaming group ! */
376 request.size = sizeof(pipe->group_uid);
377
378 /* delete the pipe */
379 err = snd_mixart_send_msg(mgr, &request, sizeof(delete_resp), &delete_resp);
380 if ((err < 0) || (delete_resp.status != 0)) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100381 dev_err(&mgr->pci->dev,
382 "error MSG_STREAM_DELETE_GROUP err(%x), status(%x)\n",
383 err, delete_resp.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385
Takashi Iwai67b48b82005-11-17 15:01:08 +0100386 pipe->group_uid = (struct mixart_uid){0,0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 pipe->stream_count = 0;
388 pipe->status = PIPE_UNDEFINED;
389 }
390
391 return err;
392}
393
Takashi Iwai67b48b82005-11-17 15:01:08 +0100394static int mixart_set_stream_state(struct mixart_stream *stream, int start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100396 struct snd_mixart *chip;
397 struct mixart_stream_state_req stream_state_req;
398 struct mixart_msg request;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 if(!stream->substream)
401 return -EINVAL;
402
403 memset(&stream_state_req, 0, sizeof(stream_state_req));
404 stream_state_req.stream_count = 1;
405 stream_state_req.stream_info.stream_desc.uid_pipe = stream->pipe->group_uid;
406 stream_state_req.stream_info.stream_desc.stream_idx = stream->substream->number;
407
408 if (stream->substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
409 request.message_id = start ? MSG_STREAM_START_INPUT_STAGE_PACKET : MSG_STREAM_STOP_INPUT_STAGE_PACKET;
410 else
411 request.message_id = start ? MSG_STREAM_START_OUTPUT_STAGE_PACKET : MSG_STREAM_STOP_OUTPUT_STAGE_PACKET;
412
Takashi Iwai67b48b82005-11-17 15:01:08 +0100413 request.uid = (struct mixart_uid){0,0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 request.data = &stream_state_req;
415 request.size = sizeof(stream_state_req);
416
417 stream->abs_period_elapsed = 0; /* reset stream pos */
418 stream->buf_periods = 0;
419 stream->buf_period_frag = 0;
420
421 chip = snd_pcm_substream_chip(stream->substream);
422
423 return snd_mixart_send_msg_nonblock(chip->mgr, &request);
424}
425
426/*
427 * Trigger callback
428 */
429
Takashi Iwai67b48b82005-11-17 15:01:08 +0100430static int snd_mixart_trigger(struct snd_pcm_substream *subs, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100432 struct mixart_stream *stream = subs->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 switch (cmd) {
435 case SNDRV_PCM_TRIGGER_START:
436
Takashi Iwai6414e352014-02-25 17:51:46 +0100437 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_TRIGGER_START\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 /* START_STREAM */
440 if( mixart_set_stream_state(stream, 1) )
441 return -EINVAL;
442
443 stream->status = MIXART_STREAM_STATUS_RUNNING;
444
445 break;
446 case SNDRV_PCM_TRIGGER_STOP:
447
448 /* STOP_STREAM */
449 if( mixart_set_stream_state(stream, 0) )
450 return -EINVAL;
451
452 stream->status = MIXART_STREAM_STATUS_OPEN;
453
Takashi Iwai6414e352014-02-25 17:51:46 +0100454 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_TRIGGER_STOP\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 break;
457
458 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
459 /* TODO */
460 stream->status = MIXART_STREAM_STATUS_PAUSE;
Takashi Iwai6414e352014-02-25 17:51:46 +0100461 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_PAUSE_PUSH\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 break;
463 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
464 /* TODO */
465 stream->status = MIXART_STREAM_STATUS_RUNNING;
Takashi Iwai6414e352014-02-25 17:51:46 +0100466 dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_PAUSE_RELEASE\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 break;
468 default:
469 return -EINVAL;
470 }
471 return 0;
472}
473
Takashi Iwai67b48b82005-11-17 15:01:08 +0100474static int mixart_sync_nonblock_events(struct mixart_mgr *mgr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Nishanth Aravamudanef21ca22005-07-09 10:13:22 +0200476 unsigned long timeout = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 while (atomic_read(&mgr->msg_processed) > 0) {
Nishanth Aravamudanef21ca22005-07-09 10:13:22 +0200478 if (time_after(jiffies, timeout)) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100479 dev_err(&mgr->pci->dev,
480 "mixart: cannot process nonblock events!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return -EBUSY;
482 }
Nishanth Aravamudan8433a502005-10-24 15:02:37 +0200483 schedule_timeout_uninterruptible(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485 return 0;
486}
487
488/*
489 * prepare callback for all pcms
490 */
Takashi Iwai67b48b82005-11-17 15:01:08 +0100491static int snd_mixart_prepare(struct snd_pcm_substream *subs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100493 struct snd_mixart *chip = snd_pcm_substream_chip(subs);
494 struct mixart_stream *stream = subs->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
John Anthony Kazos Jr7bb2acb2007-05-09 08:41:36 +0200496 /* TODO de façon non bloquante, réappliquer les hw_params (rate, bits, codec) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Takashi Iwai6414e352014-02-25 17:51:46 +0100498 dev_dbg(chip->card->dev, "snd_mixart_prepare\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 mixart_sync_nonblock_events(chip->mgr);
501
502 /* only the first stream can choose the sample rate */
503 /* the further opened streams will be limited to its frequency (see open) */
504 if(chip->mgr->ref_count_rate == 1)
505 chip->mgr->sample_rate = subs->runtime->rate;
506
507 /* set the clock only once (first stream) on the same pipe */
508 if(stream->pipe->references == 1) {
509 if( mixart_set_clock(chip->mgr, stream->pipe, subs->runtime->rate) )
510 return -EINVAL;
511 }
512
513 return 0;
514}
515
516
Takashi Iwai67b48b82005-11-17 15:01:08 +0100517static int mixart_set_format(struct mixart_stream *stream, snd_pcm_format_t format)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
519 int err;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100520 struct snd_mixart *chip;
521 struct mixart_msg request;
522 struct mixart_stream_param_desc stream_param;
523 struct mixart_return_uid resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 chip = snd_pcm_substream_chip(stream->substream);
526
527 memset(&stream_param, 0, sizeof(stream_param));
528
529 stream_param.coding_type = CT_LINEAR;
530 stream_param.number_of_channel = stream->channels;
531
532 stream_param.sampling_freq = chip->mgr->sample_rate;
533 if(stream_param.sampling_freq == 0)
534 stream_param.sampling_freq = 44100; /* if frequency not yet defined, use some default */
535
536 switch(format){
537 case SNDRV_PCM_FORMAT_U8:
538 stream_param.sample_type = ST_INTEGER_8;
539 stream_param.sample_size = 8;
540 break;
541 case SNDRV_PCM_FORMAT_S16_LE:
542 stream_param.sample_type = ST_INTEGER_16LE;
543 stream_param.sample_size = 16;
544 break;
545 case SNDRV_PCM_FORMAT_S16_BE:
546 stream_param.sample_type = ST_INTEGER_16BE;
547 stream_param.sample_size = 16;
548 break;
549 case SNDRV_PCM_FORMAT_S24_3LE:
550 stream_param.sample_type = ST_INTEGER_24LE;
551 stream_param.sample_size = 24;
552 break;
553 case SNDRV_PCM_FORMAT_S24_3BE:
554 stream_param.sample_type = ST_INTEGER_24BE;
555 stream_param.sample_size = 24;
556 break;
557 case SNDRV_PCM_FORMAT_FLOAT_LE:
558 stream_param.sample_type = ST_FLOATING_POINT_32LE;
559 stream_param.sample_size = 32;
560 break;
561 case SNDRV_PCM_FORMAT_FLOAT_BE:
562 stream_param.sample_type = ST_FLOATING_POINT_32BE;
563 stream_param.sample_size = 32;
564 break;
565 default:
Takashi Iwai6414e352014-02-25 17:51:46 +0100566 dev_err(chip->card->dev,
567 "error mixart_set_format() : unknown format\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return -EINVAL;
569 }
570
Takashi Iwai6414e352014-02-25 17:51:46 +0100571 dev_dbg(chip->card->dev,
572 "set SNDRV_PCM_FORMAT sample_type(%d) sample_size(%d) freq(%d) channels(%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 stream_param.sample_type, stream_param.sample_size, stream_param.sampling_freq, stream->channels);
574
575 /* TODO: what else to configure ? */
576 /* stream_param.samples_per_frame = 2; */
577 /* stream_param.bytes_per_frame = 4; */
578 /* stream_param.bytes_per_sample = 2; */
579
580 stream_param.pipe_count = 1; /* set to 1 */
581 stream_param.stream_count = 1; /* set to 1 */
582 stream_param.stream_desc[0].uid_pipe = stream->pipe->group_uid;
583 stream_param.stream_desc[0].stream_idx = stream->substream->number;
584
585 request.message_id = MSG_STREAM_SET_INPUT_STAGE_PARAM;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100586 request.uid = (struct mixart_uid){0,0};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 request.data = &stream_param;
588 request.size = sizeof(stream_param);
589
590 err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp);
591 if((err < 0) || resp.error_code) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100592 dev_err(chip->card->dev,
593 "MSG_STREAM_SET_INPUT_STAGE_PARAM err=%x; resp=%x\n",
594 err, resp.error_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 return -EINVAL;
596 }
597 return 0;
598}
599
600
601/*
602 * HW_PARAMS callback for all pcms
603 */
Takashi Iwai67b48b82005-11-17 15:01:08 +0100604static int snd_mixart_hw_params(struct snd_pcm_substream *subs,
605 struct snd_pcm_hw_params *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100607 struct snd_mixart *chip = snd_pcm_substream_chip(subs);
608 struct mixart_mgr *mgr = chip->mgr;
609 struct mixart_stream *stream = subs->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 snd_pcm_format_t format;
611 int err;
612 int channels;
613
614 /* set up channels */
615 channels = params_channels(hw);
616
617 /* set up format for the stream */
618 format = params_format(hw);
619
Ingo Molnar62932df2006-01-16 16:34:20 +0100620 mutex_lock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 /* update the stream levels */
623 if( stream->pcm_number <= MIXART_PCM_DIGITAL ) {
624 int is_aes = stream->pcm_number > MIXART_PCM_ANALOG;
625 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK )
626 mixart_update_playback_stream_level(chip, is_aes, subs->number);
627 else
628 mixart_update_capture_stream_level( chip, is_aes);
629 }
630
631 stream->channels = channels;
632
633 /* set the format to the board */
634 err = mixart_set_format(stream, format);
635 if(err < 0) {
Jiri Slaby82f5d572009-03-11 20:11:41 +0100636 mutex_unlock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 return err;
638 }
639
640 /* allocate buffer */
641 err = snd_pcm_lib_malloc_pages(subs, params_buffer_bytes(hw));
642
643 if (err > 0) {
644 struct mixart_bufferinfo *bufferinfo;
645 int i = (chip->chip_idx * MIXART_MAX_STREAM_PER_CARD) + (stream->pcm_number * (MIXART_PLAYBACK_STREAMS+MIXART_CAPTURE_STREAMS)) + subs->number;
646 if( subs->stream == SNDRV_PCM_STREAM_CAPTURE ) {
647 i += MIXART_PLAYBACK_STREAMS; /* in array capture is behind playback */
648 }
649
650 bufferinfo = (struct mixart_bufferinfo *)chip->mgr->bufferinfo.area;
651 bufferinfo[i].buffer_address = subs->runtime->dma_addr;
652 bufferinfo[i].available_length = subs->runtime->dma_bytes;
653 /* bufferinfo[i].buffer_id is already defined */
654
Takashi Iwai6414e352014-02-25 17:51:46 +0100655 dev_dbg(chip->card->dev,
656 "snd_mixart_hw_params(pcm %d) : dma_addr(%x) dma_bytes(%x) subs-number(%d)\n",
657 i, bufferinfo[i].buffer_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 bufferinfo[i].available_length,
659 subs->number);
660 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100661 mutex_unlock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 return err;
664}
665
Takashi Iwai67b48b82005-11-17 15:01:08 +0100666static int snd_mixart_hw_free(struct snd_pcm_substream *subs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100668 struct snd_mixart *chip = snd_pcm_substream_chip(subs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 snd_pcm_lib_free_pages(subs);
670 mixart_sync_nonblock_events(chip->mgr);
671 return 0;
672}
673
674
675
676/*
677 * TODO CONFIGURATION SPACE for all pcms, mono pcm must update channels_max
678 */
Bhumika Goyal7d4edd42017-08-12 21:01:21 +0530679static const struct snd_pcm_hardware snd_mixart_analog_caps =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
681 .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
Clemens Ladischb83f3462007-08-13 17:37:55 +0200682 SNDRV_PCM_INFO_MMAP_VALID |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 SNDRV_PCM_INFO_PAUSE),
684 .formats = ( SNDRV_PCM_FMTBIT_U8 |
685 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
686 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |
687 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE ),
688 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
689 .rate_min = 8000,
690 .rate_max = 48000,
691 .channels_min = 1,
692 .channels_max = 2,
693 .buffer_bytes_max = (32*1024),
694 .period_bytes_min = 256, /* 256 frames U8 mono*/
695 .period_bytes_max = (16*1024),
696 .periods_min = 2,
697 .periods_max = (32*1024/256),
698};
699
Bhumika Goyal7d4edd42017-08-12 21:01:21 +0530700static const struct snd_pcm_hardware snd_mixart_digital_caps =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
702 .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
Clemens Ladischb83f3462007-08-13 17:37:55 +0200703 SNDRV_PCM_INFO_MMAP_VALID |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 SNDRV_PCM_INFO_PAUSE),
705 .formats = ( SNDRV_PCM_FMTBIT_U8 |
706 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
707 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |
708 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE ),
709 .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
710 .rate_min = 32000,
711 .rate_max = 48000,
712 .channels_min = 1,
713 .channels_max = 2,
714 .buffer_bytes_max = (32*1024),
715 .period_bytes_min = 256, /* 256 frames U8 mono*/
716 .period_bytes_max = (16*1024),
717 .periods_min = 2,
718 .periods_max = (32*1024/256),
719};
720
721
Takashi Iwai67b48b82005-11-17 15:01:08 +0100722static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100724 struct snd_mixart *chip = snd_pcm_substream_chip(subs);
725 struct mixart_mgr *mgr = chip->mgr;
726 struct snd_pcm_runtime *runtime = subs->runtime;
727 struct snd_pcm *pcm = subs->pcm;
728 struct mixart_stream *stream;
729 struct mixart_pipe *pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 int err = 0;
731 int pcm_number;
732
Ingo Molnar62932df2006-01-16 16:34:20 +0100733 mutex_lock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 if ( pcm == chip->pcm ) {
736 pcm_number = MIXART_PCM_ANALOG;
737 runtime->hw = snd_mixart_analog_caps;
738 } else {
Takashi Iwaida3cec32008-08-08 17:12:14 +0200739 snd_BUG_ON(pcm != chip->pcm_dig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 pcm_number = MIXART_PCM_DIGITAL;
741 runtime->hw = snd_mixart_digital_caps;
742 }
Takashi Iwai6414e352014-02-25 17:51:46 +0100743 dev_dbg(chip->card->dev,
744 "snd_mixart_playback_open C%d/P%d/Sub%d\n",
745 chip->chip_idx, pcm_number, subs->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 /* get stream info */
748 stream = &(chip->playback_stream[pcm_number][subs->number]);
749
750 if (stream->status != MIXART_STREAM_STATUS_FREE){
751 /* streams in use */
Takashi Iwai6414e352014-02-25 17:51:46 +0100752 dev_err(chip->card->dev,
753 "snd_mixart_playback_open C%d/P%d/Sub%d in use\n",
754 chip->chip_idx, pcm_number, subs->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 err = -EBUSY;
756 goto _exit_open;
757 }
758
759 /* get pipe pointer (out pipe) */
760 pipe = snd_mixart_add_ref_pipe(chip, pcm_number, 0, 0);
761
762 if (pipe == NULL) {
763 err = -EINVAL;
764 goto _exit_open;
765 }
766
767 /* start the pipe if necessary */
768 err = mixart_set_pipe_state(chip->mgr, pipe, 1);
769 if( err < 0 ) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100770 dev_err(chip->card->dev, "error starting pipe!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0);
772 err = -EINVAL;
773 goto _exit_open;
774 }
775
776 stream->pipe = pipe;
777 stream->pcm_number = pcm_number;
778 stream->status = MIXART_STREAM_STATUS_OPEN;
779 stream->substream = subs;
780 stream->channels = 0; /* not configured yet */
781
782 runtime->private_data = stream;
783
784 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
785 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 64);
786
787 /* if a sample rate is already used, another stream cannot change */
788 if(mgr->ref_count_rate++) {
789 if(mgr->sample_rate) {
790 runtime->hw.rate_min = runtime->hw.rate_max = mgr->sample_rate;
791 }
792 }
793
794 _exit_open:
Ingo Molnar62932df2006-01-16 16:34:20 +0100795 mutex_unlock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 return err;
798}
799
800
Takashi Iwai67b48b82005-11-17 15:01:08 +0100801static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100803 struct snd_mixart *chip = snd_pcm_substream_chip(subs);
804 struct mixart_mgr *mgr = chip->mgr;
805 struct snd_pcm_runtime *runtime = subs->runtime;
806 struct snd_pcm *pcm = subs->pcm;
807 struct mixart_stream *stream;
808 struct mixart_pipe *pipe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 int err = 0;
810 int pcm_number;
811
Ingo Molnar62932df2006-01-16 16:34:20 +0100812 mutex_lock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 if ( pcm == chip->pcm ) {
815 pcm_number = MIXART_PCM_ANALOG;
816 runtime->hw = snd_mixart_analog_caps;
817 } else {
Takashi Iwaida3cec32008-08-08 17:12:14 +0200818 snd_BUG_ON(pcm != chip->pcm_dig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 pcm_number = MIXART_PCM_DIGITAL;
820 runtime->hw = snd_mixart_digital_caps;
821 }
822
823 runtime->hw.channels_min = 2; /* for instance, no mono */
824
Takashi Iwai6414e352014-02-25 17:51:46 +0100825 dev_dbg(chip->card->dev, "snd_mixart_capture_open C%d/P%d/Sub%d\n",
826 chip->chip_idx, pcm_number, subs->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 /* get stream info */
829 stream = &(chip->capture_stream[pcm_number]);
830
831 if (stream->status != MIXART_STREAM_STATUS_FREE){
832 /* streams in use */
Takashi Iwai6414e352014-02-25 17:51:46 +0100833 dev_err(chip->card->dev,
834 "snd_mixart_capture_open C%d/P%d/Sub%d in use\n",
835 chip->chip_idx, pcm_number, subs->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 err = -EBUSY;
837 goto _exit_open;
838 }
839
840 /* get pipe pointer (in pipe) */
841 pipe = snd_mixart_add_ref_pipe(chip, pcm_number, 1, 0);
842
843 if (pipe == NULL) {
844 err = -EINVAL;
845 goto _exit_open;
846 }
847
848 /* start the pipe if necessary */
849 err = mixart_set_pipe_state(chip->mgr, pipe, 1);
850 if( err < 0 ) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100851 dev_err(chip->card->dev, "error starting pipe!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0);
853 err = -EINVAL;
854 goto _exit_open;
855 }
856
857 stream->pipe = pipe;
858 stream->pcm_number = pcm_number;
859 stream->status = MIXART_STREAM_STATUS_OPEN;
860 stream->substream = subs;
861 stream->channels = 0; /* not configured yet */
862
863 runtime->private_data = stream;
864
865 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
866 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 64);
867
868 /* if a sample rate is already used, another stream cannot change */
869 if(mgr->ref_count_rate++) {
870 if(mgr->sample_rate) {
871 runtime->hw.rate_min = runtime->hw.rate_max = mgr->sample_rate;
872 }
873 }
874
875 _exit_open:
Ingo Molnar62932df2006-01-16 16:34:20 +0100876 mutex_unlock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 return err;
879}
880
881
882
Takashi Iwai67b48b82005-11-17 15:01:08 +0100883static int snd_mixart_close(struct snd_pcm_substream *subs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100885 struct snd_mixart *chip = snd_pcm_substream_chip(subs);
886 struct mixart_mgr *mgr = chip->mgr;
887 struct mixart_stream *stream = subs->runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Ingo Molnar62932df2006-01-16 16:34:20 +0100889 mutex_lock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
Takashi Iwai6414e352014-02-25 17:51:46 +0100891 dev_dbg(chip->card->dev, "snd_mixart_close C%d/P%d/Sub%d\n",
892 chip->chip_idx, stream->pcm_number, subs->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 /* sample rate released */
895 if(--mgr->ref_count_rate == 0) {
896 mgr->sample_rate = 0;
897 }
898
899 /* delete pipe */
900 if (snd_mixart_kill_ref_pipe(mgr, stream->pipe, 0 ) < 0) {
901
Takashi Iwai6414e352014-02-25 17:51:46 +0100902 dev_err(chip->card->dev,
903 "error snd_mixart_kill_ref_pipe C%dP%d\n",
904 chip->chip_idx, stream->pcm_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906
907 stream->pipe = NULL;
908 stream->status = MIXART_STREAM_STATUS_FREE;
909 stream->substream = NULL;
910
Ingo Molnar62932df2006-01-16 16:34:20 +0100911 mutex_unlock(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 return 0;
913}
914
915
Takashi Iwai67b48b82005-11-17 15:01:08 +0100916static snd_pcm_uframes_t snd_mixart_stream_pointer(struct snd_pcm_substream *subs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Takashi Iwai67b48b82005-11-17 15:01:08 +0100918 struct snd_pcm_runtime *runtime = subs->runtime;
919 struct mixart_stream *stream = runtime->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 return (snd_pcm_uframes_t)((stream->buf_periods * runtime->period_size) + stream->buf_period_frag);
922}
923
924
925
Julia Lawall6769e9882016-09-02 00:13:10 +0200926static const struct snd_pcm_ops snd_mixart_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 .open = snd_mixart_playback_open,
928 .close = snd_mixart_close,
929 .ioctl = snd_pcm_lib_ioctl,
930 .prepare = snd_mixart_prepare,
931 .hw_params = snd_mixart_hw_params,
932 .hw_free = snd_mixart_hw_free,
933 .trigger = snd_mixart_trigger,
934 .pointer = snd_mixart_stream_pointer,
935};
936
Julia Lawall6769e9882016-09-02 00:13:10 +0200937static const struct snd_pcm_ops snd_mixart_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .open = snd_mixart_capture_open,
939 .close = snd_mixart_close,
940 .ioctl = snd_pcm_lib_ioctl,
941 .prepare = snd_mixart_prepare,
942 .hw_params = snd_mixart_hw_params,
943 .hw_free = snd_mixart_hw_free,
944 .trigger = snd_mixart_trigger,
945 .pointer = snd_mixart_stream_pointer,
946};
947
Takashi Iwai67b48b82005-11-17 15:01:08 +0100948static void preallocate_buffers(struct snd_mixart *chip, struct snd_pcm *pcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
950#if 0
Takashi Iwai67b48b82005-11-17 15:01:08 +0100951 struct snd_pcm_substream *subs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 int stream;
953
954 for (stream = 0; stream < 2; stream++) {
955 int idx = 0;
956 for (subs = pcm->streams[stream].substream; subs; subs = subs->next, idx++)
957 /* set up the unique device id with the chip index */
958 subs->dma_device.id = subs->pcm->device << 16 |
959 subs->stream << 8 | (subs->number + 1) |
960 (chip->chip_idx + 1) << 24;
961 }
962#endif
963 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
964 snd_dma_pci_data(chip->mgr->pci), 32*1024, 32*1024);
965}
966
967/*
968 */
Takashi Iwai67b48b82005-11-17 15:01:08 +0100969static int snd_mixart_pcm_analog(struct snd_mixart *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
971 int err;
Takashi Iwai67b48b82005-11-17 15:01:08 +0100972 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 char name[32];
974
975 sprintf(name, "miXart analog %d", chip->chip_idx);
976 if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_ANALOG,
977 MIXART_PLAYBACK_STREAMS,
978 MIXART_CAPTURE_STREAMS, &pcm)) < 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +0100979 dev_err(chip->card->dev,
980 "cannot create the analog pcm %d\n", chip->chip_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 return err;
982 }
983
984 pcm->private_data = chip;
985
986 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_mixart_playback_ops);
987 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_mixart_capture_ops);
988
989 pcm->info_flags = 0;
Takashi Iwai8d3a8b52014-09-10 11:48:07 +0200990 pcm->nonatomic = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 strcpy(pcm->name, name);
992
993 preallocate_buffers(chip, pcm);
994
995 chip->pcm = pcm;
996 return 0;
997}
998
999
1000/*
1001 */
Takashi Iwai67b48b82005-11-17 15:01:08 +01001002static int snd_mixart_pcm_digital(struct snd_mixart *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
1004 int err;
Takashi Iwai67b48b82005-11-17 15:01:08 +01001005 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 char name[32];
1007
1008 sprintf(name, "miXart AES/EBU %d", chip->chip_idx);
1009 if ((err = snd_pcm_new(chip->card, name, MIXART_PCM_DIGITAL,
1010 MIXART_PLAYBACK_STREAMS,
1011 MIXART_CAPTURE_STREAMS, &pcm)) < 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +01001012 dev_err(chip->card->dev,
1013 "cannot create the digital pcm %d\n", chip->chip_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 return err;
1015 }
1016
1017 pcm->private_data = chip;
1018
1019 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_mixart_playback_ops);
1020 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_mixart_capture_ops);
1021
1022 pcm->info_flags = 0;
Takashi Iwai8d3a8b52014-09-10 11:48:07 +02001023 pcm->nonatomic = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 strcpy(pcm->name, name);
1025
1026 preallocate_buffers(chip, pcm);
1027
1028 chip->pcm_dig = pcm;
1029 return 0;
1030}
1031
Takashi Iwai67b48b82005-11-17 15:01:08 +01001032static int snd_mixart_chip_free(struct snd_mixart *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
1034 kfree(chip);
1035 return 0;
1036}
1037
Takashi Iwai67b48b82005-11-17 15:01:08 +01001038static int snd_mixart_chip_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Takashi Iwai67b48b82005-11-17 15:01:08 +01001040 struct snd_mixart *chip = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 return snd_mixart_chip_free(chip);
1042}
1043
1044
1045/*
1046 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001047static int snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *card, int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
1049 int err;
Takashi Iwai67b48b82005-11-17 15:01:08 +01001050 struct snd_mixart *chip;
1051 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .dev_free = snd_mixart_chip_dev_free,
1053 };
1054
Julia Lawall73f6a122008-11-27 15:40:40 +01001055 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Markus Elfringa357f3d2017-08-12 18:45:42 +02001056 if (!chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 chip->card = card;
1060 chip->chip_idx = idx;
1061 chip->mgr = mgr;
1062
1063 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1064 snd_mixart_chip_free(chip);
1065 return err;
1066 }
1067
Julia Lawall73f6a122008-11-27 15:40:40 +01001068 mgr->chip[idx] = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return 0;
1070}
1071
Takashi Iwai67b48b82005-11-17 15:01:08 +01001072int snd_mixart_create_pcm(struct snd_mixart* chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
1074 int err;
1075
1076 err = snd_mixart_pcm_analog(chip);
1077 if (err < 0)
1078 return err;
1079
1080 if(chip->mgr->board_type == MIXART_DAUGHTER_TYPE_AES) {
1081
1082 err = snd_mixart_pcm_digital(chip);
1083 if (err < 0)
1084 return err;
1085 }
1086 return err;
1087}
1088
1089
1090/*
1091 * release all the cards assigned to a manager instance
1092 */
Takashi Iwai67b48b82005-11-17 15:01:08 +01001093static int snd_mixart_free(struct mixart_mgr *mgr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
1095 unsigned int i;
1096
1097 for (i = 0; i < mgr->num_cards; i++) {
1098 if (mgr->chip[i])
1099 snd_card_free(mgr->chip[i]->card);
1100 }
1101
1102 /* stop mailbox */
1103 snd_mixart_exit_mailbox(mgr);
1104
1105 /* release irq */
1106 if (mgr->irq >= 0)
Takashi Iwai437a5a42006-11-21 12:14:23 +01001107 free_irq(mgr->irq, mgr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 /* reset board if some firmware was loaded */
1110 if(mgr->dsp_loaded) {
1111 snd_mixart_reset_board(mgr);
Takashi Iwai6414e352014-02-25 17:51:46 +01001112 dev_dbg(&mgr->pci->dev, "reset miXart !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 }
1114
1115 /* release the i/o ports */
Markus Elfringff6defa2015-01-03 22:55:54 +01001116 for (i = 0; i < 2; ++i)
1117 iounmap(mgr->mem[i].virt);
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 pci_release_regions(mgr->pci);
1120
1121 /* free flowarray */
1122 if(mgr->flowinfo.area) {
1123 snd_dma_free_pages(&mgr->flowinfo);
1124 mgr->flowinfo.area = NULL;
1125 }
1126 /* free bufferarray */
1127 if(mgr->bufferinfo.area) {
1128 snd_dma_free_pages(&mgr->bufferinfo);
1129 mgr->bufferinfo.area = NULL;
1130 }
1131
1132 pci_disable_device(mgr->pci);
1133 kfree(mgr);
1134 return 0;
1135}
1136
1137/*
1138 * proc interface
1139 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141/*
1142 mixart_BA0 proc interface for BAR 0 - read callback
1143 */
Takashi Iwai24e4a122010-04-13 11:22:01 +02001144static ssize_t snd_mixart_BA0_read(struct snd_info_entry *entry,
1145 void *file_private_data,
1146 struct file *file, char __user *buf,
1147 size_t count, loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Takashi Iwai67b48b82005-11-17 15:01:08 +01001149 struct mixart_mgr *mgr = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Dan Carpenterb0cc58a22010-04-06 19:31:26 +03001151 count = count & ~3; /* make sure the read size is a multiple of 4 bytes */
1152 if (copy_to_user_fromio(buf, MIXART_MEM(mgr, pos), count))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 return -EFAULT;
1154 return count;
1155}
1156
1157/*
1158 mixart_BA1 proc interface for BAR 1 - read callback
1159 */
Takashi Iwai24e4a122010-04-13 11:22:01 +02001160static ssize_t snd_mixart_BA1_read(struct snd_info_entry *entry,
1161 void *file_private_data,
1162 struct file *file, char __user *buf,
1163 size_t count, loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Takashi Iwai67b48b82005-11-17 15:01:08 +01001165 struct mixart_mgr *mgr = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Dan Carpenterb0cc58a22010-04-06 19:31:26 +03001167 count = count & ~3; /* make sure the read size is a multiple of 4 bytes */
1168 if (copy_to_user_fromio(buf, MIXART_REG(mgr, pos), count))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 return -EFAULT;
1170 return count;
1171}
1172
1173static struct snd_info_entry_ops snd_mixart_proc_ops_BA0 = {
1174 .read = snd_mixart_BA0_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175};
1176
1177static struct snd_info_entry_ops snd_mixart_proc_ops_BA1 = {
1178 .read = snd_mixart_BA1_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179};
1180
1181
Takashi Iwai67b48b82005-11-17 15:01:08 +01001182static void snd_mixart_proc_read(struct snd_info_entry *entry,
1183 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
Takashi Iwai67b48b82005-11-17 15:01:08 +01001185 struct snd_mixart *chip = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 u32 ref;
1187
1188 snd_iprintf(buffer, "Digigram miXart (alsa card %d)\n\n", chip->chip_idx);
1189
1190 /* stats available when embedded OS is running */
1191 if (chip->mgr->dsp_loaded & ( 1 << MIXART_MOTHERBOARD_ELF_INDEX)) {
1192 snd_iprintf(buffer, "- hardware -\n");
1193 switch (chip->mgr->board_type ) {
1194 case MIXART_DAUGHTER_TYPE_NONE : snd_iprintf(buffer, "\tmiXart8 (no daughter board)\n\n"); break;
1195 case MIXART_DAUGHTER_TYPE_AES : snd_iprintf(buffer, "\tmiXart8 AES/EBU\n\n"); break;
1196 case MIXART_DAUGHTER_TYPE_COBRANET : snd_iprintf(buffer, "\tmiXart8 Cobranet\n\n"); break;
1197 default: snd_iprintf(buffer, "\tUNKNOWN!\n\n"); break;
1198 }
1199
1200 snd_iprintf(buffer, "- system load -\n");
1201
1202 /* get perf reference */
1203
1204 ref = readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_SYSTEM_LOAD_OFFSET));
1205
1206 if (ref) {
1207 u32 mailbox = 100 * readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_MAILBX_LOAD_OFFSET)) / ref;
1208 u32 streaming = 100 * readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_STREAM_LOAD_OFFSET)) / ref;
1209 u32 interr = 100 * readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_INTERR_LOAD_OFFSET)) / ref;
1210
1211 snd_iprintf(buffer, "\tstreaming : %d\n", streaming);
1212 snd_iprintf(buffer, "\tmailbox : %d\n", mailbox);
Masanari Iidacf2fbdd2013-03-16 20:53:05 +09001213 snd_iprintf(buffer, "\tinterrupts handling : %d\n\n", interr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
1215 } /* endif elf loaded */
1216}
1217
Bill Pembertone23e7a12012-12-06 12:35:10 -05001218static void snd_mixart_proc_init(struct snd_mixart *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Takashi Iwai67b48b82005-11-17 15:01:08 +01001220 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 /* text interface to read perf and temp meters */
1223 if (! snd_card_proc_new(chip->card, "board_info", &entry)) {
1224 entry->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 entry->c.text.read = snd_mixart_proc_read;
1226 }
1227
1228 if (! snd_card_proc_new(chip->card, "mixart_BA0", &entry)) {
1229 entry->content = SNDRV_INFO_CONTENT_DATA;
1230 entry->private_data = chip->mgr;
1231 entry->c.ops = &snd_mixart_proc_ops_BA0;
1232 entry->size = MIXART_BA0_SIZE;
1233 }
1234 if (! snd_card_proc_new(chip->card, "mixart_BA1", &entry)) {
1235 entry->content = SNDRV_INFO_CONTENT_DATA;
1236 entry->private_data = chip->mgr;
1237 entry->c.ops = &snd_mixart_proc_ops_BA1;
1238 entry->size = MIXART_BA1_SIZE;
1239 }
1240}
1241/* end of proc interface */
1242
1243
1244/*
1245 * probe function - creates the card manager
1246 */
Bill Pembertone23e7a12012-12-06 12:35:10 -05001247static int snd_mixart_probe(struct pci_dev *pci,
1248 const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
1250 static int dev;
Takashi Iwai67b48b82005-11-17 15:01:08 +01001251 struct mixart_mgr *mgr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 unsigned int i;
1253 int err;
1254 size_t size;
1255
1256 /*
1257 */
1258 if (dev >= SNDRV_CARDS)
1259 return -ENODEV;
1260 if (! enable[dev]) {
1261 dev++;
1262 return -ENOENT;
1263 }
1264
1265 /* enable PCI device */
1266 if ((err = pci_enable_device(pci)) < 0)
1267 return err;
1268 pci_set_master(pci);
1269
1270 /* check if we can restrict PCI DMA transfers to 32 bits */
Quentin Lambert412b9792015-04-15 16:10:17 +02001271 if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +01001272 dev_err(&pci->dev,
1273 "architecture does not support 32bit PCI busmaster DMA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 pci_disable_device(pci);
1275 return -ENXIO;
1276 }
1277
1278 /*
1279 */
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001280 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 if (! mgr) {
1282 pci_disable_device(pci);
1283 return -ENOMEM;
1284 }
1285
1286 mgr->pci = pci;
1287 mgr->irq = -1;
1288
1289 /* resource assignment */
1290 if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
1291 kfree(mgr);
1292 pci_disable_device(pci);
1293 return err;
1294 }
1295 for (i = 0; i < 2; i++) {
1296 mgr->mem[i].phys = pci_resource_start(pci, i);
Arjan van de Ven2f5ad542008-09-28 16:20:09 -07001297 mgr->mem[i].virt = pci_ioremap_bar(pci, i);
Takashi Iwaif9ff1612007-08-13 16:16:53 +02001298 if (!mgr->mem[i].virt) {
Takashi Iwai6414e352014-02-25 17:51:46 +01001299 dev_err(&pci->dev, "unable to remap resource 0x%lx\n",
Takashi Iwaif9ff1612007-08-13 16:16:53 +02001300 mgr->mem[i].phys);
1301 snd_mixart_free(mgr);
1302 return -EBUSY;
1303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
1305
Takashi Iwai8d3a8b52014-09-10 11:48:07 +02001306 if (request_threaded_irq(pci->irq, snd_mixart_interrupt,
1307 snd_mixart_threaded_irq, IRQF_SHARED,
1308 KBUILD_MODNAME, mgr)) {
Takashi Iwai6414e352014-02-25 17:51:46 +01001309 dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 snd_mixart_free(mgr);
1311 return -EBUSY;
1312 }
1313 mgr->irq = pci->irq;
1314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /* init mailbox */
1316 mgr->msg_fifo_readptr = 0;
1317 mgr->msg_fifo_writeptr = 0;
1318
Takashi Iwai8d3a8b52014-09-10 11:48:07 +02001319 mutex_init(&mgr->lock);
1320 mutex_init(&mgr->msg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 init_waitqueue_head(&mgr->msg_sleep);
1322 atomic_set(&mgr->msg_processed, 0);
1323
1324 /* init setup mutex*/
Ingo Molnar62932df2006-01-16 16:34:20 +01001325 mutex_init(&mgr->setup_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 /* card assignment */
1328 mgr->num_cards = MIXART_MAX_CARDS; /* 4 FIXME: configurable? */
1329 for (i = 0; i < mgr->num_cards; i++) {
Takashi Iwai67b48b82005-11-17 15:01:08 +01001330 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 char tmpid[16];
1332 int idx;
1333
1334 if (index[dev] < 0)
1335 idx = index[dev];
1336 else
1337 idx = index[dev] + i;
1338 snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i);
Takashi Iwai60c57722014-01-29 14:20:19 +01001339 err = snd_card_new(&pci->dev, idx, tmpid, THIS_MODULE,
1340 0, &card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Takashi Iwaie58de7b2008-12-28 16:44:30 +01001342 if (err < 0) {
Takashi Iwai6414e352014-02-25 17:51:46 +01001343 dev_err(&pci->dev, "cannot allocate the card %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 snd_mixart_free(mgr);
Takashi Iwaie58de7b2008-12-28 16:44:30 +01001345 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 }
1347
1348 strcpy(card->driver, CARD_NAME);
Arnd Bergmannc6e486f2017-07-18 13:48:08 +02001349 snprintf(card->shortname, sizeof(card->shortname),
1350 "Digigram miXart [PCM #%d]", i);
1351 snprintf(card->longname, sizeof(card->longname),
1352 "Digigram miXart at 0x%lx & 0x%lx, irq %i [PCM #%d]",
1353 mgr->mem[0].phys, mgr->mem[1].phys, mgr->irq, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 if ((err = snd_mixart_create(mgr, card, i)) < 0) {
Julia Lawall73f6a122008-11-27 15:40:40 +01001356 snd_card_free(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 snd_mixart_free(mgr);
1358 return err;
1359 }
1360
1361 if(i==0) {
1362 /* init proc interface only for chip0 */
1363 snd_mixart_proc_init(mgr->chip[i]);
1364 }
1365
1366 if ((err = snd_card_register(card)) < 0) {
1367 snd_mixart_free(mgr);
1368 return err;
1369 }
1370 }
1371
1372 /* init firmware status (mgr->dsp_loaded reset in hwdep_new) */
1373 mgr->board_type = MIXART_DAUGHTER_TYPE_NONE;
1374
1375 /* create array of streaminfo */
Takashi Iwai67b48b82005-11-17 15:01:08 +01001376 size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS *
1377 sizeof(struct mixart_flowinfo)) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1379 size, &mgr->flowinfo) < 0) {
1380 snd_mixart_free(mgr);
1381 return -ENOMEM;
1382 }
1383 /* init streaminfo_array */
1384 memset(mgr->flowinfo.area, 0, size);
1385
1386 /* create array of bufferinfo */
Takashi Iwai67b48b82005-11-17 15:01:08 +01001387 size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS *
1388 sizeof(struct mixart_bufferinfo)) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1390 size, &mgr->bufferinfo) < 0) {
1391 snd_mixart_free(mgr);
1392 return -ENOMEM;
1393 }
1394 /* init bufferinfo_array */
1395 memset(mgr->bufferinfo.area, 0, size);
1396
1397 /* set up firmware */
1398 err = snd_mixart_setup_firmware(mgr);
1399 if (err < 0) {
1400 snd_mixart_free(mgr);
1401 return err;
1402 }
1403
1404 pci_set_drvdata(pci, mgr);
1405 dev++;
1406 return 0;
1407}
1408
Bill Pembertone23e7a12012-12-06 12:35:10 -05001409static void snd_mixart_remove(struct pci_dev *pci)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
1411 snd_mixart_free(pci_get_drvdata(pci));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412}
1413
Takashi Iwaie9f66d92012-04-24 12:25:00 +02001414static struct pci_driver mixart_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +02001415 .name = KBUILD_MODNAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 .id_table = snd_mixart_ids,
1417 .probe = snd_mixart_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -05001418 .remove = snd_mixart_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419};
1420
Takashi Iwaie9f66d92012-04-24 12:25:00 +02001421module_pci_driver(mixart_driver);