Linux Audio

Check our new training course

Loading...
v3.15
 
  1/*
  2 *   Sound driver for Silicon Graphics O2 Workstations A/V board audio.
  3 *
  4 *   Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
  5 *   Copyright 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
  6 *   Mxier part taken from mace_audio.c:
  7 *   Copyright 2007 Thorben Jändling <tj.trevelyan@gmail.com>
  8 *
  9 *   This program is free software; you can redistribute it and/or modify
 10 *   it under the terms of the GNU General Public License as published by
 11 *   the Free Software Foundation; either version 2 of the License, or
 12 *   (at your option) any later version.
 13 *
 14 *   This program is distributed in the hope that it will be useful,
 15 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17 *   GNU General Public License for more details.
 18 *
 19 *   You should have received a copy of the GNU General Public License
 20 *   along with this program; if not, write to the Free Software
 21 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 22 *
 23 */
 24
 25#include <linux/init.h>
 26#include <linux/delay.h>
 27#include <linux/spinlock.h>
 28#include <linux/interrupt.h>
 29#include <linux/dma-mapping.h>
 30#include <linux/platform_device.h>
 31#include <linux/io.h>
 32#include <linux/slab.h>
 33#include <linux/module.h>
 34
 35#include <asm/ip32/ip32_ints.h>
 36#include <asm/ip32/mace.h>
 37
 38#include <sound/core.h>
 39#include <sound/control.h>
 40#include <sound/pcm.h>
 41#define SNDRV_GET_ID
 42#include <sound/initval.h>
 43#include <sound/ad1843.h>
 44
 45
 46MODULE_AUTHOR("Vivien Chappelier <vivien.chappelier@linux-mips.org>");
 47MODULE_DESCRIPTION("SGI O2 Audio");
 48MODULE_LICENSE("GPL");
 49MODULE_SUPPORTED_DEVICE("{{Silicon Graphics, O2 Audio}}");
 50
 51static int index = SNDRV_DEFAULT_IDX1;  /* Index 0-MAX */
 52static char *id = SNDRV_DEFAULT_STR1;   /* ID for this card */
 53
 54module_param(index, int, 0444);
 55MODULE_PARM_DESC(index, "Index value for SGI O2 soundcard.");
 56module_param(id, charp, 0444);
 57MODULE_PARM_DESC(id, "ID string for SGI O2 soundcard.");
 58
 59
 60#define AUDIO_CONTROL_RESET              BIT(0) /* 1: reset audio interface */
 61#define AUDIO_CONTROL_CODEC_PRESENT      BIT(1) /* 1: codec detected */
 62
 63#define CODEC_CONTROL_WORD_SHIFT        0
 64#define CODEC_CONTROL_READ              BIT(16)
 65#define CODEC_CONTROL_ADDRESS_SHIFT     17
 66
 67#define CHANNEL_CONTROL_RESET           BIT(10) /* 1: reset channel */
 68#define CHANNEL_DMA_ENABLE              BIT(9)  /* 1: enable DMA transfer */
 69#define CHANNEL_INT_THRESHOLD_DISABLED  (0 << 5) /* interrupt disabled */
 70#define CHANNEL_INT_THRESHOLD_25        (1 << 5) /* int on buffer >25% full */
 71#define CHANNEL_INT_THRESHOLD_50        (2 << 5) /* int on buffer >50% full */
 72#define CHANNEL_INT_THRESHOLD_75        (3 << 5) /* int on buffer >75% full */
 73#define CHANNEL_INT_THRESHOLD_EMPTY     (4 << 5) /* int on buffer empty */
 74#define CHANNEL_INT_THRESHOLD_NOT_EMPTY (5 << 5) /* int on buffer !empty */
 75#define CHANNEL_INT_THRESHOLD_FULL      (6 << 5) /* int on buffer empty */
 76#define CHANNEL_INT_THRESHOLD_NOT_FULL  (7 << 5) /* int on buffer !empty */
 77
 78#define CHANNEL_RING_SHIFT              12
 79#define CHANNEL_RING_SIZE               (1 << CHANNEL_RING_SHIFT)
 80#define CHANNEL_RING_MASK               (CHANNEL_RING_SIZE - 1)
 81
 82#define CHANNEL_LEFT_SHIFT 40
 83#define CHANNEL_RIGHT_SHIFT 8
 84
 85struct snd_sgio2audio_chan {
 86	int idx;
 87	struct snd_pcm_substream *substream;
 88	int pos;
 89	snd_pcm_uframes_t size;
 90	spinlock_t lock;
 91};
 92
 93/* definition of the chip-specific record */
 94struct snd_sgio2audio {
 95	struct snd_card *card;
 96
 97	/* codec */
 98	struct snd_ad1843 ad1843;
 99	spinlock_t ad1843_lock;
100
101	/* channels */
102	struct snd_sgio2audio_chan channel[3];
103
104	/* resources */
105	void *ring_base;
106	dma_addr_t ring_base_dma;
107};
108
109/* AD1843 access */
110
111/*
112 * read_ad1843_reg returns the current contents of a 16 bit AD1843 register.
113 *
114 * Returns unsigned register value on success, -errno on failure.
115 */
116static int read_ad1843_reg(void *priv, int reg)
117{
118	struct snd_sgio2audio *chip = priv;
119	int val;
120	unsigned long flags;
121
122	spin_lock_irqsave(&chip->ad1843_lock, flags);
123
124	writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
125	       CODEC_CONTROL_READ, &mace->perif.audio.codec_control);
126	wmb();
127	val = readq(&mace->perif.audio.codec_control); /* flush bus */
128	udelay(200);
129
130	val = readq(&mace->perif.audio.codec_read);
131
132	spin_unlock_irqrestore(&chip->ad1843_lock, flags);
133	return val;
134}
135
136/*
137 * write_ad1843_reg writes the specified value to a 16 bit AD1843 register.
138 */
139static int write_ad1843_reg(void *priv, int reg, int word)
140{
141	struct snd_sgio2audio *chip = priv;
142	int val;
143	unsigned long flags;
144
145	spin_lock_irqsave(&chip->ad1843_lock, flags);
146
147	writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
148	       (word << CODEC_CONTROL_WORD_SHIFT),
149	       &mace->perif.audio.codec_control);
150	wmb();
151	val = readq(&mace->perif.audio.codec_control); /* flush bus */
152	udelay(200);
153
154	spin_unlock_irqrestore(&chip->ad1843_lock, flags);
155	return 0;
156}
157
158static int sgio2audio_gain_info(struct snd_kcontrol *kcontrol,
159			       struct snd_ctl_elem_info *uinfo)
160{
161	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
162
163	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
164	uinfo->count = 2;
165	uinfo->value.integer.min = 0;
166	uinfo->value.integer.max = ad1843_get_gain_max(&chip->ad1843,
167					     (int)kcontrol->private_value);
168	return 0;
169}
170
171static int sgio2audio_gain_get(struct snd_kcontrol *kcontrol,
172			       struct snd_ctl_elem_value *ucontrol)
173{
174	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
175	int vol;
176
177	vol = ad1843_get_gain(&chip->ad1843, (int)kcontrol->private_value);
178
179	ucontrol->value.integer.value[0] = (vol >> 8) & 0xFF;
180	ucontrol->value.integer.value[1] = vol & 0xFF;
181
182	return 0;
183}
184
185static int sgio2audio_gain_put(struct snd_kcontrol *kcontrol,
186			struct snd_ctl_elem_value *ucontrol)
187{
188	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
189	int newvol, oldvol;
190
191	oldvol = ad1843_get_gain(&chip->ad1843, kcontrol->private_value);
192	newvol = (ucontrol->value.integer.value[0] << 8) |
193		ucontrol->value.integer.value[1];
194
195	newvol = ad1843_set_gain(&chip->ad1843, kcontrol->private_value,
196		newvol);
197
198	return newvol != oldvol;
199}
200
201static int sgio2audio_source_info(struct snd_kcontrol *kcontrol,
202			       struct snd_ctl_elem_info *uinfo)
203{
204	static const char *texts[3] = {
205		"Cam Mic", "Mic", "Line"
206	};
207	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
208	uinfo->count = 1;
209	uinfo->value.enumerated.items = 3;
210	if (uinfo->value.enumerated.item >= 3)
211		uinfo->value.enumerated.item = 1;
212	strcpy(uinfo->value.enumerated.name,
213	       texts[uinfo->value.enumerated.item]);
214	return 0;
215}
216
217static int sgio2audio_source_get(struct snd_kcontrol *kcontrol,
218			       struct snd_ctl_elem_value *ucontrol)
219{
220	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
221
222	ucontrol->value.enumerated.item[0] = ad1843_get_recsrc(&chip->ad1843);
223	return 0;
224}
225
226static int sgio2audio_source_put(struct snd_kcontrol *kcontrol,
227			struct snd_ctl_elem_value *ucontrol)
228{
229	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
230	int newsrc, oldsrc;
231
232	oldsrc = ad1843_get_recsrc(&chip->ad1843);
233	newsrc = ad1843_set_recsrc(&chip->ad1843,
234				   ucontrol->value.enumerated.item[0]);
235
236	return newsrc != oldsrc;
237}
238
239/* dac1/pcm0 mixer control */
240static struct snd_kcontrol_new sgio2audio_ctrl_pcm0 = {
241	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
242	.name           = "PCM Playback Volume",
243	.index          = 0,
244	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
245	.private_value  = AD1843_GAIN_PCM_0,
246	.info           = sgio2audio_gain_info,
247	.get            = sgio2audio_gain_get,
248	.put            = sgio2audio_gain_put,
249};
250
251/* dac2/pcm1 mixer control */
252static struct snd_kcontrol_new sgio2audio_ctrl_pcm1 = {
253	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
254	.name           = "PCM Playback Volume",
255	.index          = 1,
256	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
257	.private_value  = AD1843_GAIN_PCM_1,
258	.info           = sgio2audio_gain_info,
259	.get            = sgio2audio_gain_get,
260	.put            = sgio2audio_gain_put,
261};
262
263/* record level mixer control */
264static struct snd_kcontrol_new sgio2audio_ctrl_reclevel = {
265	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
266	.name           = "Capture Volume",
267	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
268	.private_value  = AD1843_GAIN_RECLEV,
269	.info           = sgio2audio_gain_info,
270	.get            = sgio2audio_gain_get,
271	.put            = sgio2audio_gain_put,
272};
273
274/* record level source control */
275static struct snd_kcontrol_new sgio2audio_ctrl_recsource = {
276	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
277	.name           = "Capture Source",
278	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
279	.info           = sgio2audio_source_info,
280	.get            = sgio2audio_source_get,
281	.put            = sgio2audio_source_put,
282};
283
284/* line mixer control */
285static struct snd_kcontrol_new sgio2audio_ctrl_line = {
286	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
287	.name           = "Line Playback Volume",
288	.index          = 0,
289	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
290	.private_value  = AD1843_GAIN_LINE,
291	.info           = sgio2audio_gain_info,
292	.get            = sgio2audio_gain_get,
293	.put            = sgio2audio_gain_put,
294};
295
296/* cd mixer control */
297static struct snd_kcontrol_new sgio2audio_ctrl_cd = {
298	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
299	.name           = "Line Playback Volume",
300	.index          = 1,
301	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
302	.private_value  = AD1843_GAIN_LINE_2,
303	.info           = sgio2audio_gain_info,
304	.get            = sgio2audio_gain_get,
305	.put            = sgio2audio_gain_put,
306};
307
308/* mic mixer control */
309static struct snd_kcontrol_new sgio2audio_ctrl_mic = {
310	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
311	.name           = "Mic Playback Volume",
312	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
313	.private_value  = AD1843_GAIN_MIC,
314	.info           = sgio2audio_gain_info,
315	.get            = sgio2audio_gain_get,
316	.put            = sgio2audio_gain_put,
317};
318
319
320static int snd_sgio2audio_new_mixer(struct snd_sgio2audio *chip)
321{
322	int err;
323
324	err = snd_ctl_add(chip->card,
325			  snd_ctl_new1(&sgio2audio_ctrl_pcm0, chip));
326	if (err < 0)
327		return err;
328
329	err = snd_ctl_add(chip->card,
330			  snd_ctl_new1(&sgio2audio_ctrl_pcm1, chip));
331	if (err < 0)
332		return err;
333
334	err = snd_ctl_add(chip->card,
335			  snd_ctl_new1(&sgio2audio_ctrl_reclevel, chip));
336	if (err < 0)
337		return err;
338
339	err = snd_ctl_add(chip->card,
340			  snd_ctl_new1(&sgio2audio_ctrl_recsource, chip));
341	if (err < 0)
342		return err;
343	err = snd_ctl_add(chip->card,
344			  snd_ctl_new1(&sgio2audio_ctrl_line, chip));
345	if (err < 0)
346		return err;
347
348	err = snd_ctl_add(chip->card,
349			  snd_ctl_new1(&sgio2audio_ctrl_cd, chip));
350	if (err < 0)
351		return err;
352
353	err = snd_ctl_add(chip->card,
354			  snd_ctl_new1(&sgio2audio_ctrl_mic, chip));
355	if (err < 0)
356		return err;
357
358	return 0;
359}
360
361/* low-level audio interface DMA */
362
363/* get data out of bounce buffer, count must be a multiple of 32 */
364/* returns 1 if a period has elapsed */
365static int snd_sgio2audio_dma_pull_frag(struct snd_sgio2audio *chip,
366					unsigned int ch, unsigned int count)
367{
368	int ret;
369	unsigned long src_base, src_pos, dst_mask;
370	unsigned char *dst_base;
371	int dst_pos;
372	u64 *src;
373	s16 *dst;
374	u64 x;
375	unsigned long flags;
376	struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
377
378	spin_lock_irqsave(&chip->channel[ch].lock, flags);
379
380	src_base = (unsigned long) chip->ring_base | (ch << CHANNEL_RING_SHIFT);
381	src_pos = readq(&mace->perif.audio.chan[ch].read_ptr);
382	dst_base = runtime->dma_area;
383	dst_pos = chip->channel[ch].pos;
384	dst_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
385
386	/* check if a period has elapsed */
387	chip->channel[ch].size += (count >> 3); /* in frames */
388	ret = chip->channel[ch].size >= runtime->period_size;
389	chip->channel[ch].size %= runtime->period_size;
390
391	while (count) {
392		src = (u64 *)(src_base + src_pos);
393		dst = (s16 *)(dst_base + dst_pos);
394
395		x = *src;
396		dst[0] = (x >> CHANNEL_LEFT_SHIFT) & 0xffff;
397		dst[1] = (x >> CHANNEL_RIGHT_SHIFT) & 0xffff;
398
399		src_pos = (src_pos + sizeof(u64)) & CHANNEL_RING_MASK;
400		dst_pos = (dst_pos + 2 * sizeof(s16)) & dst_mask;
401		count -= sizeof(u64);
402	}
403
404	writeq(src_pos, &mace->perif.audio.chan[ch].read_ptr); /* in bytes */
405	chip->channel[ch].pos = dst_pos;
406
407	spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
408	return ret;
409}
410
411/* put some DMA data in bounce buffer, count must be a multiple of 32 */
412/* returns 1 if a period has elapsed */
413static int snd_sgio2audio_dma_push_frag(struct snd_sgio2audio *chip,
414					unsigned int ch, unsigned int count)
415{
416	int ret;
417	s64 l, r;
418	unsigned long dst_base, dst_pos, src_mask;
419	unsigned char *src_base;
420	int src_pos;
421	u64 *dst;
422	s16 *src;
423	unsigned long flags;
424	struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
425
426	spin_lock_irqsave(&chip->channel[ch].lock, flags);
427
428	dst_base = (unsigned long)chip->ring_base | (ch << CHANNEL_RING_SHIFT);
429	dst_pos = readq(&mace->perif.audio.chan[ch].write_ptr);
430	src_base = runtime->dma_area;
431	src_pos = chip->channel[ch].pos;
432	src_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
433
434	/* check if a period has elapsed */
435	chip->channel[ch].size += (count >> 3); /* in frames */
436	ret = chip->channel[ch].size >= runtime->period_size;
437	chip->channel[ch].size %= runtime->period_size;
438
439	while (count) {
440		src = (s16 *)(src_base + src_pos);
441		dst = (u64 *)(dst_base + dst_pos);
442
443		l = src[0]; /* sign extend */
444		r = src[1]; /* sign extend */
445
446		*dst = ((l & 0x00ffffff) << CHANNEL_LEFT_SHIFT) |
447			((r & 0x00ffffff) << CHANNEL_RIGHT_SHIFT);
448
449		dst_pos = (dst_pos + sizeof(u64)) & CHANNEL_RING_MASK;
450		src_pos = (src_pos + 2 * sizeof(s16)) & src_mask;
451		count -= sizeof(u64);
452	}
453
454	writeq(dst_pos, &mace->perif.audio.chan[ch].write_ptr); /* in bytes */
455	chip->channel[ch].pos = src_pos;
456
457	spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
458	return ret;
459}
460
461static int snd_sgio2audio_dma_start(struct snd_pcm_substream *substream)
462{
463	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
464	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
465	int ch = chan->idx;
466
467	/* reset DMA channel */
468	writeq(CHANNEL_CONTROL_RESET, &mace->perif.audio.chan[ch].control);
469	udelay(10);
470	writeq(0, &mace->perif.audio.chan[ch].control);
471
472	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
473		/* push a full buffer */
474		snd_sgio2audio_dma_push_frag(chip, ch, CHANNEL_RING_SIZE - 32);
475	}
476	/* set DMA to wake on 50% empty and enable interrupt */
477	writeq(CHANNEL_DMA_ENABLE | CHANNEL_INT_THRESHOLD_50,
478	       &mace->perif.audio.chan[ch].control);
479	return 0;
480}
481
482static int snd_sgio2audio_dma_stop(struct snd_pcm_substream *substream)
483{
484	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
485
486	writeq(0, &mace->perif.audio.chan[chan->idx].control);
487	return 0;
488}
489
490static irqreturn_t snd_sgio2audio_dma_in_isr(int irq, void *dev_id)
491{
492	struct snd_sgio2audio_chan *chan = dev_id;
493	struct snd_pcm_substream *substream;
494	struct snd_sgio2audio *chip;
495	int count, ch;
496
497	substream = chan->substream;
498	chip = snd_pcm_substream_chip(substream);
499	ch = chan->idx;
500
501	/* empty the ring */
502	count = CHANNEL_RING_SIZE -
503		readq(&mace->perif.audio.chan[ch].depth) - 32;
504	if (snd_sgio2audio_dma_pull_frag(chip, ch, count))
505		snd_pcm_period_elapsed(substream);
506
507	return IRQ_HANDLED;
508}
509
510static irqreturn_t snd_sgio2audio_dma_out_isr(int irq, void *dev_id)
511{
512	struct snd_sgio2audio_chan *chan = dev_id;
513	struct snd_pcm_substream *substream;
514	struct snd_sgio2audio *chip;
515	int count, ch;
516
517	substream = chan->substream;
518	chip = snd_pcm_substream_chip(substream);
519	ch = chan->idx;
520	/* fill the ring */
521	count = CHANNEL_RING_SIZE -
522		readq(&mace->perif.audio.chan[ch].depth) - 32;
523	if (snd_sgio2audio_dma_push_frag(chip, ch, count))
524		snd_pcm_period_elapsed(substream);
525
526	return IRQ_HANDLED;
527}
528
529static irqreturn_t snd_sgio2audio_error_isr(int irq, void *dev_id)
530{
531	struct snd_sgio2audio_chan *chan = dev_id;
532	struct snd_pcm_substream *substream;
533
534	substream = chan->substream;
535	snd_sgio2audio_dma_stop(substream);
536	snd_sgio2audio_dma_start(substream);
537	return IRQ_HANDLED;
538}
539
540/* PCM part */
541/* PCM hardware definition */
542static struct snd_pcm_hardware snd_sgio2audio_pcm_hw = {
543	.info = (SNDRV_PCM_INFO_MMAP |
544		 SNDRV_PCM_INFO_MMAP_VALID |
545		 SNDRV_PCM_INFO_INTERLEAVED |
546		 SNDRV_PCM_INFO_BLOCK_TRANSFER),
547	.formats =          SNDRV_PCM_FMTBIT_S16_BE,
548	.rates =            SNDRV_PCM_RATE_8000_48000,
549	.rate_min =         8000,
550	.rate_max =         48000,
551	.channels_min =     2,
552	.channels_max =     2,
553	.buffer_bytes_max = 65536,
554	.period_bytes_min = 32768,
555	.period_bytes_max = 65536,
556	.periods_min =      1,
557	.periods_max =      1024,
558};
559
560/* PCM playback open callback */
561static int snd_sgio2audio_playback1_open(struct snd_pcm_substream *substream)
562{
563	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
564	struct snd_pcm_runtime *runtime = substream->runtime;
565
566	runtime->hw = snd_sgio2audio_pcm_hw;
567	runtime->private_data = &chip->channel[1];
568	return 0;
569}
570
571static int snd_sgio2audio_playback2_open(struct snd_pcm_substream *substream)
572{
573	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
574	struct snd_pcm_runtime *runtime = substream->runtime;
575
576	runtime->hw = snd_sgio2audio_pcm_hw;
577	runtime->private_data = &chip->channel[2];
578	return 0;
579}
580
581/* PCM capture open callback */
582static int snd_sgio2audio_capture_open(struct snd_pcm_substream *substream)
583{
584	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
585	struct snd_pcm_runtime *runtime = substream->runtime;
586
587	runtime->hw = snd_sgio2audio_pcm_hw;
588	runtime->private_data = &chip->channel[0];
589	return 0;
590}
591
592/* PCM close callback */
593static int snd_sgio2audio_pcm_close(struct snd_pcm_substream *substream)
594{
595	struct snd_pcm_runtime *runtime = substream->runtime;
596
597	runtime->private_data = NULL;
598	return 0;
599}
600
601
602/* hw_params callback */
603static int snd_sgio2audio_pcm_hw_params(struct snd_pcm_substream *substream,
604					struct snd_pcm_hw_params *hw_params)
605{
606	return snd_pcm_lib_alloc_vmalloc_buffer(substream,
607						params_buffer_bytes(hw_params));
608}
609
610/* hw_free callback */
611static int snd_sgio2audio_pcm_hw_free(struct snd_pcm_substream *substream)
612{
613	return snd_pcm_lib_free_vmalloc_buffer(substream);
614}
615
616/* prepare callback */
617static int snd_sgio2audio_pcm_prepare(struct snd_pcm_substream *substream)
618{
619	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
620	struct snd_pcm_runtime *runtime = substream->runtime;
621	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
622	int ch = chan->idx;
623	unsigned long flags;
624
625	spin_lock_irqsave(&chip->channel[ch].lock, flags);
626
627	/* Setup the pseudo-dma transfer pointers.  */
628	chip->channel[ch].pos = 0;
629	chip->channel[ch].size = 0;
630	chip->channel[ch].substream = substream;
631
632	/* set AD1843 format */
633	/* hardware format is always S16_LE */
634	switch (substream->stream) {
635	case SNDRV_PCM_STREAM_PLAYBACK:
636		ad1843_setup_dac(&chip->ad1843,
637				 ch - 1,
638				 runtime->rate,
639				 SNDRV_PCM_FORMAT_S16_LE,
640				 runtime->channels);
641		break;
642	case SNDRV_PCM_STREAM_CAPTURE:
643		ad1843_setup_adc(&chip->ad1843,
644				 runtime->rate,
645				 SNDRV_PCM_FORMAT_S16_LE,
646				 runtime->channels);
647		break;
648	}
649	spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
650	return 0;
651}
652
653/* trigger callback */
654static int snd_sgio2audio_pcm_trigger(struct snd_pcm_substream *substream,
655				      int cmd)
656{
657	switch (cmd) {
658	case SNDRV_PCM_TRIGGER_START:
659		/* start the PCM engine */
660		snd_sgio2audio_dma_start(substream);
661		break;
662	case SNDRV_PCM_TRIGGER_STOP:
663		/* stop the PCM engine */
664		snd_sgio2audio_dma_stop(substream);
665		break;
666	default:
667		return -EINVAL;
668	}
669	return 0;
670}
671
672/* pointer callback */
673static snd_pcm_uframes_t
674snd_sgio2audio_pcm_pointer(struct snd_pcm_substream *substream)
675{
676	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
677	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
678
679	/* get the current hardware pointer */
680	return bytes_to_frames(substream->runtime,
681			       chip->channel[chan->idx].pos);
682}
683
684/* operators */
685static struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
686	.open =        snd_sgio2audio_playback1_open,
687	.close =       snd_sgio2audio_pcm_close,
688	.ioctl =       snd_pcm_lib_ioctl,
689	.hw_params =   snd_sgio2audio_pcm_hw_params,
690	.hw_free =     snd_sgio2audio_pcm_hw_free,
691	.prepare =     snd_sgio2audio_pcm_prepare,
692	.trigger =     snd_sgio2audio_pcm_trigger,
693	.pointer =     snd_sgio2audio_pcm_pointer,
694	.page =        snd_pcm_lib_get_vmalloc_page,
695	.mmap =        snd_pcm_lib_mmap_vmalloc,
696};
697
698static struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
699	.open =        snd_sgio2audio_playback2_open,
700	.close =       snd_sgio2audio_pcm_close,
701	.ioctl =       snd_pcm_lib_ioctl,
702	.hw_params =   snd_sgio2audio_pcm_hw_params,
703	.hw_free =     snd_sgio2audio_pcm_hw_free,
704	.prepare =     snd_sgio2audio_pcm_prepare,
705	.trigger =     snd_sgio2audio_pcm_trigger,
706	.pointer =     snd_sgio2audio_pcm_pointer,
707	.page =        snd_pcm_lib_get_vmalloc_page,
708	.mmap =        snd_pcm_lib_mmap_vmalloc,
709};
710
711static struct snd_pcm_ops snd_sgio2audio_capture_ops = {
712	.open =        snd_sgio2audio_capture_open,
713	.close =       snd_sgio2audio_pcm_close,
714	.ioctl =       snd_pcm_lib_ioctl,
715	.hw_params =   snd_sgio2audio_pcm_hw_params,
716	.hw_free =     snd_sgio2audio_pcm_hw_free,
717	.prepare =     snd_sgio2audio_pcm_prepare,
718	.trigger =     snd_sgio2audio_pcm_trigger,
719	.pointer =     snd_sgio2audio_pcm_pointer,
720	.page =        snd_pcm_lib_get_vmalloc_page,
721	.mmap =        snd_pcm_lib_mmap_vmalloc,
722};
723
724/*
725 *  definitions of capture are omitted here...
726 */
727
728/* create a pcm device */
729static int snd_sgio2audio_new_pcm(struct snd_sgio2audio *chip)
730{
731	struct snd_pcm *pcm;
732	int err;
733
734	/* create first pcm device with one outputs and one input */
735	err = snd_pcm_new(chip->card, "SGI O2 Audio", 0, 1, 1, &pcm);
736	if (err < 0)
737		return err;
738
739	pcm->private_data = chip;
740	strcpy(pcm->name, "SGI O2 DAC1");
741
742	/* set operators */
743	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
744			&snd_sgio2audio_playback1_ops);
745	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
746			&snd_sgio2audio_capture_ops);
 
747
748	/* create second  pcm device with one outputs and no input */
749	err = snd_pcm_new(chip->card, "SGI O2 Audio", 1, 1, 0, &pcm);
750	if (err < 0)
751		return err;
752
753	pcm->private_data = chip;
754	strcpy(pcm->name, "SGI O2 DAC2");
755
756	/* set operators */
757	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
758			&snd_sgio2audio_playback2_ops);
 
759
760	return 0;
761}
762
763static struct {
764	int idx;
765	int irq;
766	irqreturn_t (*isr)(int, void *);
767	const char *desc;
768} snd_sgio2_isr_table[] = {
769	{
770		.idx = 0,
771		.irq = MACEISA_AUDIO1_DMAT_IRQ,
772		.isr = snd_sgio2audio_dma_in_isr,
773		.desc = "Capture DMA Channel 0"
774	}, {
775		.idx = 0,
776		.irq = MACEISA_AUDIO1_OF_IRQ,
777		.isr = snd_sgio2audio_error_isr,
778		.desc = "Capture Overflow"
779	}, {
780		.idx = 1,
781		.irq = MACEISA_AUDIO2_DMAT_IRQ,
782		.isr = snd_sgio2audio_dma_out_isr,
783		.desc = "Playback DMA Channel 1"
784	}, {
785		.idx = 1,
786		.irq = MACEISA_AUDIO2_MERR_IRQ,
787		.isr = snd_sgio2audio_error_isr,
788		.desc = "Memory Error Channel 1"
789	}, {
790		.idx = 2,
791		.irq = MACEISA_AUDIO3_DMAT_IRQ,
792		.isr = snd_sgio2audio_dma_out_isr,
793		.desc = "Playback DMA Channel 2"
794	}, {
795		.idx = 2,
796		.irq = MACEISA_AUDIO3_MERR_IRQ,
797		.isr = snd_sgio2audio_error_isr,
798		.desc = "Memory Error Channel 2"
799	}
800};
801
802/* ALSA driver */
803
804static int snd_sgio2audio_free(struct snd_sgio2audio *chip)
805{
806	int i;
807
808	/* reset interface */
809	writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
810	udelay(1);
811	writeq(0, &mace->perif.audio.control);
812
813	/* release IRQ's */
814	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++)
815		free_irq(snd_sgio2_isr_table[i].irq,
816			 &chip->channel[snd_sgio2_isr_table[i].idx]);
817
818	dma_free_coherent(NULL, MACEISA_RINGBUFFERS_SIZE,
819			  chip->ring_base, chip->ring_base_dma);
820
821	/* release card data */
822	kfree(chip);
823	return 0;
824}
825
826static int snd_sgio2audio_dev_free(struct snd_device *device)
827{
828	struct snd_sgio2audio *chip = device->device_data;
829
830	return snd_sgio2audio_free(chip);
831}
832
833static struct snd_device_ops ops = {
834	.dev_free = snd_sgio2audio_dev_free,
835};
836
837static int snd_sgio2audio_create(struct snd_card *card,
838				 struct snd_sgio2audio **rchip)
839{
840	struct snd_sgio2audio *chip;
841	int i, err;
842
843	*rchip = NULL;
844
845	/* check if a codec is attached to the interface */
846	/* (Audio or Audio/Video board present) */
847	if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
848		return -ENOENT;
849
850	chip = kzalloc(sizeof(struct snd_sgio2audio), GFP_KERNEL);
851	if (chip == NULL)
852		return -ENOMEM;
853
854	chip->card = card;
855
856	chip->ring_base = dma_alloc_coherent(NULL, MACEISA_RINGBUFFERS_SIZE,
857					     &chip->ring_base_dma, GFP_USER);
 
858	if (chip->ring_base == NULL) {
859		printk(KERN_ERR
860		       "sgio2audio: could not allocate ring buffers\n");
861		kfree(chip);
862		return -ENOMEM;
863	}
864
865	spin_lock_init(&chip->ad1843_lock);
866
867	/* initialize channels */
868	for (i = 0; i < 3; i++) {
869		spin_lock_init(&chip->channel[i].lock);
870		chip->channel[i].idx = i;
871	}
872
873	/* allocate IRQs */
874	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
875		if (request_irq(snd_sgio2_isr_table[i].irq,
876				snd_sgio2_isr_table[i].isr,
877				0,
878				snd_sgio2_isr_table[i].desc,
879				&chip->channel[snd_sgio2_isr_table[i].idx])) {
880			snd_sgio2audio_free(chip);
881			printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
882			       snd_sgio2_isr_table[i].irq);
883			return -EBUSY;
884		}
885	}
886
887	/* reset the interface */
888	writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
889	udelay(1);
890	writeq(0, &mace->perif.audio.control);
891	msleep_interruptible(1); /* give time to recover */
892
893	/* set ring base */
894	writeq(chip->ring_base_dma, &mace->perif.ctrl.ringbase);
895
896	/* attach the AD1843 codec */
897	chip->ad1843.read = read_ad1843_reg;
898	chip->ad1843.write = write_ad1843_reg;
899	chip->ad1843.chip = chip;
900
901	/* initialize the AD1843 codec */
902	err = ad1843_init(&chip->ad1843);
903	if (err < 0) {
904		snd_sgio2audio_free(chip);
905		return err;
906	}
907
908	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
909	if (err < 0) {
910		snd_sgio2audio_free(chip);
911		return err;
912	}
913	*rchip = chip;
914	return 0;
915}
916
917static int snd_sgio2audio_probe(struct platform_device *pdev)
918{
919	struct snd_card *card;
920	struct snd_sgio2audio *chip;
921	int err;
922
923	err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
924	if (err < 0)
925		return err;
926
927	err = snd_sgio2audio_create(card, &chip);
928	if (err < 0) {
929		snd_card_free(card);
930		return err;
931	}
932
933	err = snd_sgio2audio_new_pcm(chip);
934	if (err < 0) {
935		snd_card_free(card);
936		return err;
937	}
938	err = snd_sgio2audio_new_mixer(chip);
939	if (err < 0) {
940		snd_card_free(card);
941		return err;
942	}
943
944	strcpy(card->driver, "SGI O2 Audio");
945	strcpy(card->shortname, "SGI O2 Audio");
946	sprintf(card->longname, "%s irq %i-%i",
947		card->shortname,
948		MACEISA_AUDIO1_DMAT_IRQ,
949		MACEISA_AUDIO3_MERR_IRQ);
950
951	err = snd_card_register(card);
952	if (err < 0) {
953		snd_card_free(card);
954		return err;
955	}
956	platform_set_drvdata(pdev, card);
957	return 0;
958}
959
960static int snd_sgio2audio_remove(struct platform_device *pdev)
961{
962	struct snd_card *card = platform_get_drvdata(pdev);
963
964	snd_card_free(card);
965	return 0;
966}
967
968static struct platform_driver sgio2audio_driver = {
969	.probe	= snd_sgio2audio_probe,
970	.remove	= snd_sgio2audio_remove,
971	.driver = {
972		.name	= "sgio2audio",
973		.owner	= THIS_MODULE,
974	}
975};
976
977module_platform_driver(sgio2audio_driver);
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *   Sound driver for Silicon Graphics O2 Workstations A/V board audio.
  4 *
  5 *   Copyright 2003 Vivien Chappelier <vivien.chappelier@linux-mips.org>
  6 *   Copyright 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
  7 *   Mxier part taken from mace_audio.c:
  8 *   Copyright 2007 Thorben Jändling <tj.trevelyan@gmail.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  9 */
 10
 11#include <linux/init.h>
 12#include <linux/delay.h>
 13#include <linux/spinlock.h>
 14#include <linux/interrupt.h>
 15#include <linux/dma-mapping.h>
 16#include <linux/platform_device.h>
 17#include <linux/io.h>
 18#include <linux/slab.h>
 19#include <linux/module.h>
 20
 21#include <asm/ip32/ip32_ints.h>
 22#include <asm/ip32/mace.h>
 23
 24#include <sound/core.h>
 25#include <sound/control.h>
 26#include <sound/pcm.h>
 27#define SNDRV_GET_ID
 28#include <sound/initval.h>
 29#include <sound/ad1843.h>
 30
 31
 32MODULE_AUTHOR("Vivien Chappelier <vivien.chappelier@linux-mips.org>");
 33MODULE_DESCRIPTION("SGI O2 Audio");
 34MODULE_LICENSE("GPL");
 
 35
 36static int index = SNDRV_DEFAULT_IDX1;  /* Index 0-MAX */
 37static char *id = SNDRV_DEFAULT_STR1;   /* ID for this card */
 38
 39module_param(index, int, 0444);
 40MODULE_PARM_DESC(index, "Index value for SGI O2 soundcard.");
 41module_param(id, charp, 0444);
 42MODULE_PARM_DESC(id, "ID string for SGI O2 soundcard.");
 43
 44
 45#define AUDIO_CONTROL_RESET              BIT(0) /* 1: reset audio interface */
 46#define AUDIO_CONTROL_CODEC_PRESENT      BIT(1) /* 1: codec detected */
 47
 48#define CODEC_CONTROL_WORD_SHIFT        0
 49#define CODEC_CONTROL_READ              BIT(16)
 50#define CODEC_CONTROL_ADDRESS_SHIFT     17
 51
 52#define CHANNEL_CONTROL_RESET           BIT(10) /* 1: reset channel */
 53#define CHANNEL_DMA_ENABLE              BIT(9)  /* 1: enable DMA transfer */
 54#define CHANNEL_INT_THRESHOLD_DISABLED  (0 << 5) /* interrupt disabled */
 55#define CHANNEL_INT_THRESHOLD_25        (1 << 5) /* int on buffer >25% full */
 56#define CHANNEL_INT_THRESHOLD_50        (2 << 5) /* int on buffer >50% full */
 57#define CHANNEL_INT_THRESHOLD_75        (3 << 5) /* int on buffer >75% full */
 58#define CHANNEL_INT_THRESHOLD_EMPTY     (4 << 5) /* int on buffer empty */
 59#define CHANNEL_INT_THRESHOLD_NOT_EMPTY (5 << 5) /* int on buffer !empty */
 60#define CHANNEL_INT_THRESHOLD_FULL      (6 << 5) /* int on buffer empty */
 61#define CHANNEL_INT_THRESHOLD_NOT_FULL  (7 << 5) /* int on buffer !empty */
 62
 63#define CHANNEL_RING_SHIFT              12
 64#define CHANNEL_RING_SIZE               (1 << CHANNEL_RING_SHIFT)
 65#define CHANNEL_RING_MASK               (CHANNEL_RING_SIZE - 1)
 66
 67#define CHANNEL_LEFT_SHIFT 40
 68#define CHANNEL_RIGHT_SHIFT 8
 69
 70struct snd_sgio2audio_chan {
 71	int idx;
 72	struct snd_pcm_substream *substream;
 73	int pos;
 74	snd_pcm_uframes_t size;
 75	spinlock_t lock;
 76};
 77
 78/* definition of the chip-specific record */
 79struct snd_sgio2audio {
 80	struct snd_card *card;
 81
 82	/* codec */
 83	struct snd_ad1843 ad1843;
 84	spinlock_t ad1843_lock;
 85
 86	/* channels */
 87	struct snd_sgio2audio_chan channel[3];
 88
 89	/* resources */
 90	void *ring_base;
 91	dma_addr_t ring_base_dma;
 92};
 93
 94/* AD1843 access */
 95
 96/*
 97 * read_ad1843_reg returns the current contents of a 16 bit AD1843 register.
 98 *
 99 * Returns unsigned register value on success, -errno on failure.
100 */
101static int read_ad1843_reg(void *priv, int reg)
102{
103	struct snd_sgio2audio *chip = priv;
104	int val;
105	unsigned long flags;
106
107	spin_lock_irqsave(&chip->ad1843_lock, flags);
108
109	writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
110	       CODEC_CONTROL_READ, &mace->perif.audio.codec_control);
111	wmb();
112	val = readq(&mace->perif.audio.codec_control); /* flush bus */
113	udelay(200);
114
115	val = readq(&mace->perif.audio.codec_read);
116
117	spin_unlock_irqrestore(&chip->ad1843_lock, flags);
118	return val;
119}
120
121/*
122 * write_ad1843_reg writes the specified value to a 16 bit AD1843 register.
123 */
124static int write_ad1843_reg(void *priv, int reg, int word)
125{
126	struct snd_sgio2audio *chip = priv;
127	int val;
128	unsigned long flags;
129
130	spin_lock_irqsave(&chip->ad1843_lock, flags);
131
132	writeq((reg << CODEC_CONTROL_ADDRESS_SHIFT) |
133	       (word << CODEC_CONTROL_WORD_SHIFT),
134	       &mace->perif.audio.codec_control);
135	wmb();
136	val = readq(&mace->perif.audio.codec_control); /* flush bus */
137	udelay(200);
138
139	spin_unlock_irqrestore(&chip->ad1843_lock, flags);
140	return 0;
141}
142
143static int sgio2audio_gain_info(struct snd_kcontrol *kcontrol,
144			       struct snd_ctl_elem_info *uinfo)
145{
146	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
147
148	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
149	uinfo->count = 2;
150	uinfo->value.integer.min = 0;
151	uinfo->value.integer.max = ad1843_get_gain_max(&chip->ad1843,
152					     (int)kcontrol->private_value);
153	return 0;
154}
155
156static int sgio2audio_gain_get(struct snd_kcontrol *kcontrol,
157			       struct snd_ctl_elem_value *ucontrol)
158{
159	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
160	int vol;
161
162	vol = ad1843_get_gain(&chip->ad1843, (int)kcontrol->private_value);
163
164	ucontrol->value.integer.value[0] = (vol >> 8) & 0xFF;
165	ucontrol->value.integer.value[1] = vol & 0xFF;
166
167	return 0;
168}
169
170static int sgio2audio_gain_put(struct snd_kcontrol *kcontrol,
171			struct snd_ctl_elem_value *ucontrol)
172{
173	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
174	int newvol, oldvol;
175
176	oldvol = ad1843_get_gain(&chip->ad1843, kcontrol->private_value);
177	newvol = (ucontrol->value.integer.value[0] << 8) |
178		ucontrol->value.integer.value[1];
179
180	newvol = ad1843_set_gain(&chip->ad1843, kcontrol->private_value,
181		newvol);
182
183	return newvol != oldvol;
184}
185
186static int sgio2audio_source_info(struct snd_kcontrol *kcontrol,
187			       struct snd_ctl_elem_info *uinfo)
188{
189	static const char * const texts[3] = {
190		"Cam Mic", "Mic", "Line"
191	};
192	return snd_ctl_enum_info(uinfo, 1, 3, texts);
 
 
 
 
 
 
 
193}
194
195static int sgio2audio_source_get(struct snd_kcontrol *kcontrol,
196			       struct snd_ctl_elem_value *ucontrol)
197{
198	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
199
200	ucontrol->value.enumerated.item[0] = ad1843_get_recsrc(&chip->ad1843);
201	return 0;
202}
203
204static int sgio2audio_source_put(struct snd_kcontrol *kcontrol,
205			struct snd_ctl_elem_value *ucontrol)
206{
207	struct snd_sgio2audio *chip = snd_kcontrol_chip(kcontrol);
208	int newsrc, oldsrc;
209
210	oldsrc = ad1843_get_recsrc(&chip->ad1843);
211	newsrc = ad1843_set_recsrc(&chip->ad1843,
212				   ucontrol->value.enumerated.item[0]);
213
214	return newsrc != oldsrc;
215}
216
217/* dac1/pcm0 mixer control */
218static const struct snd_kcontrol_new sgio2audio_ctrl_pcm0 = {
219	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
220	.name           = "PCM Playback Volume",
221	.index          = 0,
222	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
223	.private_value  = AD1843_GAIN_PCM_0,
224	.info           = sgio2audio_gain_info,
225	.get            = sgio2audio_gain_get,
226	.put            = sgio2audio_gain_put,
227};
228
229/* dac2/pcm1 mixer control */
230static const struct snd_kcontrol_new sgio2audio_ctrl_pcm1 = {
231	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
232	.name           = "PCM Playback Volume",
233	.index          = 1,
234	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
235	.private_value  = AD1843_GAIN_PCM_1,
236	.info           = sgio2audio_gain_info,
237	.get            = sgio2audio_gain_get,
238	.put            = sgio2audio_gain_put,
239};
240
241/* record level mixer control */
242static const struct snd_kcontrol_new sgio2audio_ctrl_reclevel = {
243	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
244	.name           = "Capture Volume",
245	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
246	.private_value  = AD1843_GAIN_RECLEV,
247	.info           = sgio2audio_gain_info,
248	.get            = sgio2audio_gain_get,
249	.put            = sgio2audio_gain_put,
250};
251
252/* record level source control */
253static const struct snd_kcontrol_new sgio2audio_ctrl_recsource = {
254	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
255	.name           = "Capture Source",
256	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
257	.info           = sgio2audio_source_info,
258	.get            = sgio2audio_source_get,
259	.put            = sgio2audio_source_put,
260};
261
262/* line mixer control */
263static const struct snd_kcontrol_new sgio2audio_ctrl_line = {
264	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
265	.name           = "Line Playback Volume",
266	.index          = 0,
267	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
268	.private_value  = AD1843_GAIN_LINE,
269	.info           = sgio2audio_gain_info,
270	.get            = sgio2audio_gain_get,
271	.put            = sgio2audio_gain_put,
272};
273
274/* cd mixer control */
275static const struct snd_kcontrol_new sgio2audio_ctrl_cd = {
276	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
277	.name           = "Line Playback Volume",
278	.index          = 1,
279	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
280	.private_value  = AD1843_GAIN_LINE_2,
281	.info           = sgio2audio_gain_info,
282	.get            = sgio2audio_gain_get,
283	.put            = sgio2audio_gain_put,
284};
285
286/* mic mixer control */
287static const struct snd_kcontrol_new sgio2audio_ctrl_mic = {
288	.iface          = SNDRV_CTL_ELEM_IFACE_MIXER,
289	.name           = "Mic Playback Volume",
290	.access         = SNDRV_CTL_ELEM_ACCESS_READWRITE,
291	.private_value  = AD1843_GAIN_MIC,
292	.info           = sgio2audio_gain_info,
293	.get            = sgio2audio_gain_get,
294	.put            = sgio2audio_gain_put,
295};
296
297
298static int snd_sgio2audio_new_mixer(struct snd_sgio2audio *chip)
299{
300	int err;
301
302	err = snd_ctl_add(chip->card,
303			  snd_ctl_new1(&sgio2audio_ctrl_pcm0, chip));
304	if (err < 0)
305		return err;
306
307	err = snd_ctl_add(chip->card,
308			  snd_ctl_new1(&sgio2audio_ctrl_pcm1, chip));
309	if (err < 0)
310		return err;
311
312	err = snd_ctl_add(chip->card,
313			  snd_ctl_new1(&sgio2audio_ctrl_reclevel, chip));
314	if (err < 0)
315		return err;
316
317	err = snd_ctl_add(chip->card,
318			  snd_ctl_new1(&sgio2audio_ctrl_recsource, chip));
319	if (err < 0)
320		return err;
321	err = snd_ctl_add(chip->card,
322			  snd_ctl_new1(&sgio2audio_ctrl_line, chip));
323	if (err < 0)
324		return err;
325
326	err = snd_ctl_add(chip->card,
327			  snd_ctl_new1(&sgio2audio_ctrl_cd, chip));
328	if (err < 0)
329		return err;
330
331	err = snd_ctl_add(chip->card,
332			  snd_ctl_new1(&sgio2audio_ctrl_mic, chip));
333	if (err < 0)
334		return err;
335
336	return 0;
337}
338
339/* low-level audio interface DMA */
340
341/* get data out of bounce buffer, count must be a multiple of 32 */
342/* returns 1 if a period has elapsed */
343static int snd_sgio2audio_dma_pull_frag(struct snd_sgio2audio *chip,
344					unsigned int ch, unsigned int count)
345{
346	int ret;
347	unsigned long src_base, src_pos, dst_mask;
348	unsigned char *dst_base;
349	int dst_pos;
350	u64 *src;
351	s16 *dst;
352	u64 x;
353	unsigned long flags;
354	struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
355
356	spin_lock_irqsave(&chip->channel[ch].lock, flags);
357
358	src_base = (unsigned long) chip->ring_base | (ch << CHANNEL_RING_SHIFT);
359	src_pos = readq(&mace->perif.audio.chan[ch].read_ptr);
360	dst_base = runtime->dma_area;
361	dst_pos = chip->channel[ch].pos;
362	dst_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
363
364	/* check if a period has elapsed */
365	chip->channel[ch].size += (count >> 3); /* in frames */
366	ret = chip->channel[ch].size >= runtime->period_size;
367	chip->channel[ch].size %= runtime->period_size;
368
369	while (count) {
370		src = (u64 *)(src_base + src_pos);
371		dst = (s16 *)(dst_base + dst_pos);
372
373		x = *src;
374		dst[0] = (x >> CHANNEL_LEFT_SHIFT) & 0xffff;
375		dst[1] = (x >> CHANNEL_RIGHT_SHIFT) & 0xffff;
376
377		src_pos = (src_pos + sizeof(u64)) & CHANNEL_RING_MASK;
378		dst_pos = (dst_pos + 2 * sizeof(s16)) & dst_mask;
379		count -= sizeof(u64);
380	}
381
382	writeq(src_pos, &mace->perif.audio.chan[ch].read_ptr); /* in bytes */
383	chip->channel[ch].pos = dst_pos;
384
385	spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
386	return ret;
387}
388
389/* put some DMA data in bounce buffer, count must be a multiple of 32 */
390/* returns 1 if a period has elapsed */
391static int snd_sgio2audio_dma_push_frag(struct snd_sgio2audio *chip,
392					unsigned int ch, unsigned int count)
393{
394	int ret;
395	s64 l, r;
396	unsigned long dst_base, dst_pos, src_mask;
397	unsigned char *src_base;
398	int src_pos;
399	u64 *dst;
400	s16 *src;
401	unsigned long flags;
402	struct snd_pcm_runtime *runtime = chip->channel[ch].substream->runtime;
403
404	spin_lock_irqsave(&chip->channel[ch].lock, flags);
405
406	dst_base = (unsigned long)chip->ring_base | (ch << CHANNEL_RING_SHIFT);
407	dst_pos = readq(&mace->perif.audio.chan[ch].write_ptr);
408	src_base = runtime->dma_area;
409	src_pos = chip->channel[ch].pos;
410	src_mask = frames_to_bytes(runtime, runtime->buffer_size) - 1;
411
412	/* check if a period has elapsed */
413	chip->channel[ch].size += (count >> 3); /* in frames */
414	ret = chip->channel[ch].size >= runtime->period_size;
415	chip->channel[ch].size %= runtime->period_size;
416
417	while (count) {
418		src = (s16 *)(src_base + src_pos);
419		dst = (u64 *)(dst_base + dst_pos);
420
421		l = src[0]; /* sign extend */
422		r = src[1]; /* sign extend */
423
424		*dst = ((l & 0x00ffffff) << CHANNEL_LEFT_SHIFT) |
425			((r & 0x00ffffff) << CHANNEL_RIGHT_SHIFT);
426
427		dst_pos = (dst_pos + sizeof(u64)) & CHANNEL_RING_MASK;
428		src_pos = (src_pos + 2 * sizeof(s16)) & src_mask;
429		count -= sizeof(u64);
430	}
431
432	writeq(dst_pos, &mace->perif.audio.chan[ch].write_ptr); /* in bytes */
433	chip->channel[ch].pos = src_pos;
434
435	spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
436	return ret;
437}
438
439static int snd_sgio2audio_dma_start(struct snd_pcm_substream *substream)
440{
441	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
442	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
443	int ch = chan->idx;
444
445	/* reset DMA channel */
446	writeq(CHANNEL_CONTROL_RESET, &mace->perif.audio.chan[ch].control);
447	udelay(10);
448	writeq(0, &mace->perif.audio.chan[ch].control);
449
450	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
451		/* push a full buffer */
452		snd_sgio2audio_dma_push_frag(chip, ch, CHANNEL_RING_SIZE - 32);
453	}
454	/* set DMA to wake on 50% empty and enable interrupt */
455	writeq(CHANNEL_DMA_ENABLE | CHANNEL_INT_THRESHOLD_50,
456	       &mace->perif.audio.chan[ch].control);
457	return 0;
458}
459
460static int snd_sgio2audio_dma_stop(struct snd_pcm_substream *substream)
461{
462	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
463
464	writeq(0, &mace->perif.audio.chan[chan->idx].control);
465	return 0;
466}
467
468static irqreturn_t snd_sgio2audio_dma_in_isr(int irq, void *dev_id)
469{
470	struct snd_sgio2audio_chan *chan = dev_id;
471	struct snd_pcm_substream *substream;
472	struct snd_sgio2audio *chip;
473	int count, ch;
474
475	substream = chan->substream;
476	chip = snd_pcm_substream_chip(substream);
477	ch = chan->idx;
478
479	/* empty the ring */
480	count = CHANNEL_RING_SIZE -
481		readq(&mace->perif.audio.chan[ch].depth) - 32;
482	if (snd_sgio2audio_dma_pull_frag(chip, ch, count))
483		snd_pcm_period_elapsed(substream);
484
485	return IRQ_HANDLED;
486}
487
488static irqreturn_t snd_sgio2audio_dma_out_isr(int irq, void *dev_id)
489{
490	struct snd_sgio2audio_chan *chan = dev_id;
491	struct snd_pcm_substream *substream;
492	struct snd_sgio2audio *chip;
493	int count, ch;
494
495	substream = chan->substream;
496	chip = snd_pcm_substream_chip(substream);
497	ch = chan->idx;
498	/* fill the ring */
499	count = CHANNEL_RING_SIZE -
500		readq(&mace->perif.audio.chan[ch].depth) - 32;
501	if (snd_sgio2audio_dma_push_frag(chip, ch, count))
502		snd_pcm_period_elapsed(substream);
503
504	return IRQ_HANDLED;
505}
506
507static irqreturn_t snd_sgio2audio_error_isr(int irq, void *dev_id)
508{
509	struct snd_sgio2audio_chan *chan = dev_id;
510	struct snd_pcm_substream *substream;
511
512	substream = chan->substream;
513	snd_sgio2audio_dma_stop(substream);
514	snd_sgio2audio_dma_start(substream);
515	return IRQ_HANDLED;
516}
517
518/* PCM part */
519/* PCM hardware definition */
520static const struct snd_pcm_hardware snd_sgio2audio_pcm_hw = {
521	.info = (SNDRV_PCM_INFO_MMAP |
522		 SNDRV_PCM_INFO_MMAP_VALID |
523		 SNDRV_PCM_INFO_INTERLEAVED |
524		 SNDRV_PCM_INFO_BLOCK_TRANSFER),
525	.formats =          SNDRV_PCM_FMTBIT_S16_BE,
526	.rates =            SNDRV_PCM_RATE_8000_48000,
527	.rate_min =         8000,
528	.rate_max =         48000,
529	.channels_min =     2,
530	.channels_max =     2,
531	.buffer_bytes_max = 65536,
532	.period_bytes_min = 32768,
533	.period_bytes_max = 65536,
534	.periods_min =      1,
535	.periods_max =      1024,
536};
537
538/* PCM playback open callback */
539static int snd_sgio2audio_playback1_open(struct snd_pcm_substream *substream)
540{
541	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
542	struct snd_pcm_runtime *runtime = substream->runtime;
543
544	runtime->hw = snd_sgio2audio_pcm_hw;
545	runtime->private_data = &chip->channel[1];
546	return 0;
547}
548
549static int snd_sgio2audio_playback2_open(struct snd_pcm_substream *substream)
550{
551	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
552	struct snd_pcm_runtime *runtime = substream->runtime;
553
554	runtime->hw = snd_sgio2audio_pcm_hw;
555	runtime->private_data = &chip->channel[2];
556	return 0;
557}
558
559/* PCM capture open callback */
560static int snd_sgio2audio_capture_open(struct snd_pcm_substream *substream)
561{
562	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
563	struct snd_pcm_runtime *runtime = substream->runtime;
564
565	runtime->hw = snd_sgio2audio_pcm_hw;
566	runtime->private_data = &chip->channel[0];
567	return 0;
568}
569
570/* PCM close callback */
571static int snd_sgio2audio_pcm_close(struct snd_pcm_substream *substream)
572{
573	struct snd_pcm_runtime *runtime = substream->runtime;
574
575	runtime->private_data = NULL;
576	return 0;
577}
578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579/* prepare callback */
580static int snd_sgio2audio_pcm_prepare(struct snd_pcm_substream *substream)
581{
582	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
583	struct snd_pcm_runtime *runtime = substream->runtime;
584	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
585	int ch = chan->idx;
586	unsigned long flags;
587
588	spin_lock_irqsave(&chip->channel[ch].lock, flags);
589
590	/* Setup the pseudo-dma transfer pointers.  */
591	chip->channel[ch].pos = 0;
592	chip->channel[ch].size = 0;
593	chip->channel[ch].substream = substream;
594
595	/* set AD1843 format */
596	/* hardware format is always S16_LE */
597	switch (substream->stream) {
598	case SNDRV_PCM_STREAM_PLAYBACK:
599		ad1843_setup_dac(&chip->ad1843,
600				 ch - 1,
601				 runtime->rate,
602				 SNDRV_PCM_FORMAT_S16_LE,
603				 runtime->channels);
604		break;
605	case SNDRV_PCM_STREAM_CAPTURE:
606		ad1843_setup_adc(&chip->ad1843,
607				 runtime->rate,
608				 SNDRV_PCM_FORMAT_S16_LE,
609				 runtime->channels);
610		break;
611	}
612	spin_unlock_irqrestore(&chip->channel[ch].lock, flags);
613	return 0;
614}
615
616/* trigger callback */
617static int snd_sgio2audio_pcm_trigger(struct snd_pcm_substream *substream,
618				      int cmd)
619{
620	switch (cmd) {
621	case SNDRV_PCM_TRIGGER_START:
622		/* start the PCM engine */
623		snd_sgio2audio_dma_start(substream);
624		break;
625	case SNDRV_PCM_TRIGGER_STOP:
626		/* stop the PCM engine */
627		snd_sgio2audio_dma_stop(substream);
628		break;
629	default:
630		return -EINVAL;
631	}
632	return 0;
633}
634
635/* pointer callback */
636static snd_pcm_uframes_t
637snd_sgio2audio_pcm_pointer(struct snd_pcm_substream *substream)
638{
639	struct snd_sgio2audio *chip = snd_pcm_substream_chip(substream);
640	struct snd_sgio2audio_chan *chan = substream->runtime->private_data;
641
642	/* get the current hardware pointer */
643	return bytes_to_frames(substream->runtime,
644			       chip->channel[chan->idx].pos);
645}
646
647/* operators */
648static const struct snd_pcm_ops snd_sgio2audio_playback1_ops = {
649	.open =        snd_sgio2audio_playback1_open,
650	.close =       snd_sgio2audio_pcm_close,
 
 
 
651	.prepare =     snd_sgio2audio_pcm_prepare,
652	.trigger =     snd_sgio2audio_pcm_trigger,
653	.pointer =     snd_sgio2audio_pcm_pointer,
 
 
654};
655
656static const struct snd_pcm_ops snd_sgio2audio_playback2_ops = {
657	.open =        snd_sgio2audio_playback2_open,
658	.close =       snd_sgio2audio_pcm_close,
 
 
 
659	.prepare =     snd_sgio2audio_pcm_prepare,
660	.trigger =     snd_sgio2audio_pcm_trigger,
661	.pointer =     snd_sgio2audio_pcm_pointer,
 
 
662};
663
664static const struct snd_pcm_ops snd_sgio2audio_capture_ops = {
665	.open =        snd_sgio2audio_capture_open,
666	.close =       snd_sgio2audio_pcm_close,
 
 
 
667	.prepare =     snd_sgio2audio_pcm_prepare,
668	.trigger =     snd_sgio2audio_pcm_trigger,
669	.pointer =     snd_sgio2audio_pcm_pointer,
 
 
670};
671
672/*
673 *  definitions of capture are omitted here...
674 */
675
676/* create a pcm device */
677static int snd_sgio2audio_new_pcm(struct snd_sgio2audio *chip)
678{
679	struct snd_pcm *pcm;
680	int err;
681
682	/* create first pcm device with one outputs and one input */
683	err = snd_pcm_new(chip->card, "SGI O2 Audio", 0, 1, 1, &pcm);
684	if (err < 0)
685		return err;
686
687	pcm->private_data = chip;
688	strcpy(pcm->name, "SGI O2 DAC1");
689
690	/* set operators */
691	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
692			&snd_sgio2audio_playback1_ops);
693	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
694			&snd_sgio2audio_capture_ops);
695	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
696
697	/* create second  pcm device with one outputs and no input */
698	err = snd_pcm_new(chip->card, "SGI O2 Audio", 1, 1, 0, &pcm);
699	if (err < 0)
700		return err;
701
702	pcm->private_data = chip;
703	strcpy(pcm->name, "SGI O2 DAC2");
704
705	/* set operators */
706	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
707			&snd_sgio2audio_playback2_ops);
708	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0);
709
710	return 0;
711}
712
713static struct {
714	int idx;
715	int irq;
716	irqreturn_t (*isr)(int, void *);
717	const char *desc;
718} snd_sgio2_isr_table[] = {
719	{
720		.idx = 0,
721		.irq = MACEISA_AUDIO1_DMAT_IRQ,
722		.isr = snd_sgio2audio_dma_in_isr,
723		.desc = "Capture DMA Channel 0"
724	}, {
725		.idx = 0,
726		.irq = MACEISA_AUDIO1_OF_IRQ,
727		.isr = snd_sgio2audio_error_isr,
728		.desc = "Capture Overflow"
729	}, {
730		.idx = 1,
731		.irq = MACEISA_AUDIO2_DMAT_IRQ,
732		.isr = snd_sgio2audio_dma_out_isr,
733		.desc = "Playback DMA Channel 1"
734	}, {
735		.idx = 1,
736		.irq = MACEISA_AUDIO2_MERR_IRQ,
737		.isr = snd_sgio2audio_error_isr,
738		.desc = "Memory Error Channel 1"
739	}, {
740		.idx = 2,
741		.irq = MACEISA_AUDIO3_DMAT_IRQ,
742		.isr = snd_sgio2audio_dma_out_isr,
743		.desc = "Playback DMA Channel 2"
744	}, {
745		.idx = 2,
746		.irq = MACEISA_AUDIO3_MERR_IRQ,
747		.isr = snd_sgio2audio_error_isr,
748		.desc = "Memory Error Channel 2"
749	}
750};
751
752/* ALSA driver */
753
754static int snd_sgio2audio_free(struct snd_sgio2audio *chip)
755{
756	int i;
757
758	/* reset interface */
759	writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
760	udelay(1);
761	writeq(0, &mace->perif.audio.control);
762
763	/* release IRQ's */
764	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++)
765		free_irq(snd_sgio2_isr_table[i].irq,
766			 &chip->channel[snd_sgio2_isr_table[i].idx]);
767
768	dma_free_coherent(chip->card->dev, MACEISA_RINGBUFFERS_SIZE,
769			  chip->ring_base, chip->ring_base_dma);
770
771	/* release card data */
772	kfree(chip);
773	return 0;
774}
775
776static int snd_sgio2audio_dev_free(struct snd_device *device)
777{
778	struct snd_sgio2audio *chip = device->device_data;
779
780	return snd_sgio2audio_free(chip);
781}
782
783static const struct snd_device_ops ops = {
784	.dev_free = snd_sgio2audio_dev_free,
785};
786
787static int snd_sgio2audio_create(struct snd_card *card,
788				 struct snd_sgio2audio **rchip)
789{
790	struct snd_sgio2audio *chip;
791	int i, err;
792
793	*rchip = NULL;
794
795	/* check if a codec is attached to the interface */
796	/* (Audio or Audio/Video board present) */
797	if (!(readq(&mace->perif.audio.control) & AUDIO_CONTROL_CODEC_PRESENT))
798		return -ENOENT;
799
800	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
801	if (chip == NULL)
802		return -ENOMEM;
803
804	chip->card = card;
805
806	chip->ring_base = dma_alloc_coherent(card->dev,
807					     MACEISA_RINGBUFFERS_SIZE,
808					     &chip->ring_base_dma, GFP_KERNEL);
809	if (chip->ring_base == NULL) {
810		printk(KERN_ERR
811		       "sgio2audio: could not allocate ring buffers\n");
812		kfree(chip);
813		return -ENOMEM;
814	}
815
816	spin_lock_init(&chip->ad1843_lock);
817
818	/* initialize channels */
819	for (i = 0; i < 3; i++) {
820		spin_lock_init(&chip->channel[i].lock);
821		chip->channel[i].idx = i;
822	}
823
824	/* allocate IRQs */
825	for (i = 0; i < ARRAY_SIZE(snd_sgio2_isr_table); i++) {
826		if (request_irq(snd_sgio2_isr_table[i].irq,
827				snd_sgio2_isr_table[i].isr,
828				0,
829				snd_sgio2_isr_table[i].desc,
830				&chip->channel[snd_sgio2_isr_table[i].idx])) {
831			snd_sgio2audio_free(chip);
832			printk(KERN_ERR "sgio2audio: cannot allocate irq %d\n",
833			       snd_sgio2_isr_table[i].irq);
834			return -EBUSY;
835		}
836	}
837
838	/* reset the interface */
839	writeq(AUDIO_CONTROL_RESET, &mace->perif.audio.control);
840	udelay(1);
841	writeq(0, &mace->perif.audio.control);
842	msleep_interruptible(1); /* give time to recover */
843
844	/* set ring base */
845	writeq(chip->ring_base_dma, &mace->perif.ctrl.ringbase);
846
847	/* attach the AD1843 codec */
848	chip->ad1843.read = read_ad1843_reg;
849	chip->ad1843.write = write_ad1843_reg;
850	chip->ad1843.chip = chip;
851
852	/* initialize the AD1843 codec */
853	err = ad1843_init(&chip->ad1843);
854	if (err < 0) {
855		snd_sgio2audio_free(chip);
856		return err;
857	}
858
859	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
860	if (err < 0) {
861		snd_sgio2audio_free(chip);
862		return err;
863	}
864	*rchip = chip;
865	return 0;
866}
867
868static int snd_sgio2audio_probe(struct platform_device *pdev)
869{
870	struct snd_card *card;
871	struct snd_sgio2audio *chip;
872	int err;
873
874	err = snd_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card);
875	if (err < 0)
876		return err;
877
878	err = snd_sgio2audio_create(card, &chip);
879	if (err < 0) {
880		snd_card_free(card);
881		return err;
882	}
883
884	err = snd_sgio2audio_new_pcm(chip);
885	if (err < 0) {
886		snd_card_free(card);
887		return err;
888	}
889	err = snd_sgio2audio_new_mixer(chip);
890	if (err < 0) {
891		snd_card_free(card);
892		return err;
893	}
894
895	strcpy(card->driver, "SGI O2 Audio");
896	strcpy(card->shortname, "SGI O2 Audio");
897	sprintf(card->longname, "%s irq %i-%i",
898		card->shortname,
899		MACEISA_AUDIO1_DMAT_IRQ,
900		MACEISA_AUDIO3_MERR_IRQ);
901
902	err = snd_card_register(card);
903	if (err < 0) {
904		snd_card_free(card);
905		return err;
906	}
907	platform_set_drvdata(pdev, card);
908	return 0;
909}
910
911static int snd_sgio2audio_remove(struct platform_device *pdev)
912{
913	struct snd_card *card = platform_get_drvdata(pdev);
914
915	snd_card_free(card);
916	return 0;
917}
918
919static struct platform_driver sgio2audio_driver = {
920	.probe	= snd_sgio2audio_probe,
921	.remove	= snd_sgio2audio_remove,
922	.driver = {
923		.name	= "sgio2audio",
 
924	}
925};
926
927module_platform_driver(sgio2audio_driver);