blob: ff705c63a03a2f0292438a380e11b2f76212de22 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Hewlett-Packard Harmony audio driver
2 *
3 * This is a driver for the Harmony audio chipset found
4 * on the LASI ASIC of various early HP PA-RISC workstations.
5 *
6 * Copyright (C) 2004, Kyle McMartin <kyle@{debian.org,parisc-linux.org}>
7 *
8 * Based on the previous Harmony incarnations by,
9 * Copyright 2000 (c) Linuxcare Canada, Alex deVries
10 * Copyright 2000-2003 (c) Helge Deller
11 * Copyright 2001 (c) Matthieu Delahaye
12 * Copyright 2001 (c) Jean-Christophe Vaugeois
13 * Copyright 2003 (c) Laurent Canet
14 * Copyright 2004 (c) Stuart Brady
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License, version 2, as
18 * published by the Free Software Foundation.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 * Notes:
30 * - graveyard and silence buffers last for lifetime of
31 * the driver. playback and capture buffers are allocated
32 * per _open()/_close().
33 *
34 * TODO:
35 *
36 */
37
38#include <linux/init.h>
39#include <linux/slab.h>
40#include <linux/time.h>
41#include <linux/wait.h>
42#include <linux/delay.h>
43#include <linux/module.h>
44#include <linux/interrupt.h>
45#include <linux/spinlock.h>
46#include <linux/dma-mapping.h>
47
48#include <sound/driver.h>
49#include <sound/core.h>
50#include <sound/pcm.h>
51#include <sound/control.h>
52#include <sound/rawmidi.h>
53#include <sound/initval.h>
54#include <sound/info.h>
55
56#include <asm/io.h>
57#include <asm/hardware.h>
58#include <asm/parisc-device.h>
59
60#include "harmony.h"
61
Takashi Iwai03f9ae22005-11-17 10:34:40 +010062static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
63static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
64module_param(index, int, 0444);
65MODULE_PARM_DESC(index, "Index value for Harmony driver.");
66module_param(id, charp, 0444);
67MODULE_PARM_DESC(id, "ID string for Harmony driver.");
68
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static struct parisc_device_id snd_harmony_devtable[] = {
71 /* bushmaster / flounder */
72 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A },
73 /* 712 / 715 */
74 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B },
75 /* pace */
76 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E },
77 /* outfield / coral II */
78 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F },
79 { 0, }
80};
81
82MODULE_DEVICE_TABLE(parisc, snd_harmony_devtable);
83
84#define NAME "harmony"
85#define PFX NAME ": "
86
87static unsigned int snd_harmony_rates[] = {
88 5512, 6615, 8000, 9600,
89 11025, 16000, 18900, 22050,
90 27428, 32000, 33075, 37800,
91 44100, 48000
92};
93
94static unsigned int rate_bits[14] = {
95 HARMONY_SR_5KHZ, HARMONY_SR_6KHZ, HARMONY_SR_8KHZ,
96 HARMONY_SR_9KHZ, HARMONY_SR_11KHZ, HARMONY_SR_16KHZ,
97 HARMONY_SR_18KHZ, HARMONY_SR_22KHZ, HARMONY_SR_27KHZ,
98 HARMONY_SR_32KHZ, HARMONY_SR_33KHZ, HARMONY_SR_37KHZ,
99 HARMONY_SR_44KHZ, HARMONY_SR_48KHZ
100};
101
Takashi Iwai67b10202005-11-17 15:12:11 +0100102static struct snd_pcm_hw_constraint_list hw_constraint_rates = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 .count = ARRAY_SIZE(snd_harmony_rates),
104 .list = snd_harmony_rates,
105 .mask = 0,
106};
107
Takashi Iwai67b10202005-11-17 15:12:11 +0100108static inline unsigned long
109harmony_read(struct snd_harmony *h, unsigned r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 return __raw_readl(h->iobase + r);
112}
113
Takashi Iwai67b10202005-11-17 15:12:11 +0100114static inline void
115harmony_write(struct snd_harmony *h, unsigned r, unsigned long v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
117 __raw_writel(v, h->iobase + r);
118}
119
Takashi Iwai67b10202005-11-17 15:12:11 +0100120static inline void
121harmony_wait_for_control(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 while (harmony_read(h, HARMONY_CNTL) & HARMONY_CNTL_C) ;
124}
125
Takashi Iwai67b10202005-11-17 15:12:11 +0100126static inline void
127harmony_reset(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 harmony_write(h, HARMONY_RESET, 1);
130 mdelay(50);
131 harmony_write(h, HARMONY_RESET, 0);
132}
133
134static void
Takashi Iwai67b10202005-11-17 15:12:11 +0100135harmony_disable_interrupts(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
137 u32 dstatus;
138 harmony_wait_for_control(h);
139 dstatus = harmony_read(h, HARMONY_DSTATUS);
140 dstatus &= ~HARMONY_DSTATUS_IE;
141 harmony_write(h, HARMONY_DSTATUS, dstatus);
142}
143
144static void
Takashi Iwai67b10202005-11-17 15:12:11 +0100145harmony_enable_interrupts(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 u32 dstatus;
148 harmony_wait_for_control(h);
149 dstatus = harmony_read(h, HARMONY_DSTATUS);
150 dstatus |= HARMONY_DSTATUS_IE;
151 harmony_write(h, HARMONY_DSTATUS, dstatus);
152}
153
154static void
Takashi Iwai67b10202005-11-17 15:12:11 +0100155harmony_mute(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 unsigned long flags;
158
159 spin_lock_irqsave(&h->mixer_lock, flags);
160 harmony_wait_for_control(h);
161 harmony_write(h, HARMONY_GAINCTL, HARMONY_GAIN_SILENCE);
162 spin_unlock_irqrestore(&h->mixer_lock, flags);
163}
164
165static void
Takashi Iwai67b10202005-11-17 15:12:11 +0100166harmony_unmute(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
168 unsigned long flags;
169
170 spin_lock_irqsave(&h->mixer_lock, flags);
171 harmony_wait_for_control(h);
172 harmony_write(h, HARMONY_GAINCTL, h->st.gain);
173 spin_unlock_irqrestore(&h->mixer_lock, flags);
174}
175
176static void
Takashi Iwai67b10202005-11-17 15:12:11 +0100177harmony_set_control(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
179 u32 ctrl;
180 unsigned long flags;
181
182 spin_lock_irqsave(&h->lock, flags);
183
184 ctrl = (HARMONY_CNTL_C |
185 (h->st.format << 6) |
186 (h->st.stereo << 5) |
187 (h->st.rate));
188
189 harmony_wait_for_control(h);
190 harmony_write(h, HARMONY_CNTL, ctrl);
191
192 spin_unlock_irqrestore(&h->lock, flags);
193}
194
195static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100196snd_harmony_interrupt(int irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 u32 dstatus;
Takashi Iwai67b10202005-11-17 15:12:11 +0100199 struct snd_harmony *h = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 spin_lock(&h->lock);
202 harmony_disable_interrupts(h);
203 harmony_wait_for_control(h);
204 dstatus = harmony_read(h, HARMONY_DSTATUS);
205 spin_unlock(&h->lock);
206
207 if (dstatus & HARMONY_DSTATUS_PN) {
Stuart Brady3a165682005-10-21 22:42:38 -0400208 if (h->psubs && h->st.playing) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 spin_lock(&h->lock);
210 h->pbuf.buf += h->pbuf.count; /* PAGE_SIZE */
211 h->pbuf.buf %= h->pbuf.size; /* MAX_BUFS*PAGE_SIZE */
212
213 harmony_write(h, HARMONY_PNXTADD,
214 h->pbuf.addr + h->pbuf.buf);
215 h->stats.play_intr++;
216 spin_unlock(&h->lock);
217 snd_pcm_period_elapsed(h->psubs);
218 } else {
219 spin_lock(&h->lock);
220 harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
221 h->stats.silence_intr++;
222 spin_unlock(&h->lock);
223 }
224 }
225
226 if (dstatus & HARMONY_DSTATUS_RN) {
Stuart Brady3a165682005-10-21 22:42:38 -0400227 if (h->csubs && h->st.capturing) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 spin_lock(&h->lock);
229 h->cbuf.buf += h->cbuf.count;
230 h->cbuf.buf %= h->cbuf.size;
231
232 harmony_write(h, HARMONY_RNXTADD,
233 h->cbuf.addr + h->cbuf.buf);
234 h->stats.rec_intr++;
235 spin_unlock(&h->lock);
236 snd_pcm_period_elapsed(h->csubs);
237 } else {
238 spin_lock(&h->lock);
239 harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
240 h->stats.graveyard_intr++;
241 spin_unlock(&h->lock);
242 }
243 }
244
245 spin_lock(&h->lock);
246 harmony_enable_interrupts(h);
247 spin_unlock(&h->lock);
248
249 return IRQ_HANDLED;
250}
251
252static unsigned int
253snd_harmony_rate_bits(int rate)
254{
255 unsigned int i;
256
257 for (i = 0; i < ARRAY_SIZE(snd_harmony_rates); i++)
258 if (snd_harmony_rates[i] == rate)
259 return rate_bits[i];
260
261 return HARMONY_SR_44KHZ;
262}
263
Takashi Iwai67b10202005-11-17 15:12:11 +0100264static struct snd_pcm_hardware snd_harmony_playback =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
267 SNDRV_PCM_INFO_JOINT_DUPLEX | SNDRV_PCM_INFO_MMAP_VALID |
268 SNDRV_PCM_INFO_BLOCK_TRANSFER),
269 .formats = (SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_MU_LAW |
270 SNDRV_PCM_FMTBIT_A_LAW),
271 .rates = (SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000 |
272 SNDRV_PCM_RATE_KNOT),
273 .rate_min = 5512,
274 .rate_max = 48000,
275 .channels_min = 1,
276 .channels_max = 2,
277 .buffer_bytes_max = MAX_BUF_SIZE,
278 .period_bytes_min = BUF_SIZE,
279 .period_bytes_max = BUF_SIZE,
280 .periods_min = 1,
281 .periods_max = MAX_BUFS,
282 .fifo_size = 0,
283};
284
Takashi Iwai67b10202005-11-17 15:12:11 +0100285static struct snd_pcm_hardware snd_harmony_capture =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
288 SNDRV_PCM_INFO_JOINT_DUPLEX | SNDRV_PCM_INFO_MMAP_VALID |
289 SNDRV_PCM_INFO_BLOCK_TRANSFER),
290 .formats = (SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_MU_LAW |
291 SNDRV_PCM_FMTBIT_A_LAW),
292 .rates = (SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000 |
293 SNDRV_PCM_RATE_KNOT),
294 .rate_min = 5512,
295 .rate_max = 48000,
296 .channels_min = 1,
297 .channels_max = 2,
298 .buffer_bytes_max = MAX_BUF_SIZE,
299 .period_bytes_min = BUF_SIZE,
300 .period_bytes_max = BUF_SIZE,
301 .periods_min = 1,
302 .periods_max = MAX_BUFS,
303 .fifo_size = 0,
304};
305
306static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100307snd_harmony_playback_trigger(struct snd_pcm_substream *ss, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Takashi Iwai67b10202005-11-17 15:12:11 +0100309 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 if (h->st.capturing)
312 return -EBUSY;
313
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100314 spin_lock(&h->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 switch (cmd) {
316 case SNDRV_PCM_TRIGGER_START:
317 h->st.playing = 1;
318 harmony_write(h, HARMONY_PNXTADD, h->pbuf.addr);
319 harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
320 harmony_unmute(h);
321 harmony_enable_interrupts(h);
322 break;
323 case SNDRV_PCM_TRIGGER_STOP:
324 h->st.playing = 0;
325 harmony_mute(h);
Stuart Brady3a165682005-10-21 22:42:38 -0400326 harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 harmony_disable_interrupts(h);
328 break;
329 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
330 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
331 case SNDRV_PCM_TRIGGER_SUSPEND:
332 default:
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100333 spin_unlock(&h->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 snd_BUG();
335 return -EINVAL;
336 }
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100337 spin_unlock(&h->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 return 0;
340}
341
342static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100343snd_harmony_capture_trigger(struct snd_pcm_substream *ss, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Takashi Iwai67b10202005-11-17 15:12:11 +0100345 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if (h->st.playing)
348 return -EBUSY;
349
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100350 spin_lock(&h->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 switch (cmd) {
352 case SNDRV_PCM_TRIGGER_START:
353 h->st.capturing = 1;
354 harmony_write(h, HARMONY_PNXTADD, h->sdma.addr);
355 harmony_write(h, HARMONY_RNXTADD, h->cbuf.addr);
356 harmony_unmute(h);
357 harmony_enable_interrupts(h);
358 break;
359 case SNDRV_PCM_TRIGGER_STOP:
360 h->st.capturing = 0;
Stuart Brady3a165682005-10-21 22:42:38 -0400361 harmony_mute(h);
362 harmony_write(h, HARMONY_RNXTADD, h->gdma.addr);
363 harmony_disable_interrupts(h);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 break;
365 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
366 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
367 case SNDRV_PCM_TRIGGER_SUSPEND:
368 default:
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100369 spin_unlock(&h->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 snd_BUG();
371 return -EINVAL;
372 }
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100373 spin_unlock(&h->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 return 0;
376}
377
378static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100379snd_harmony_set_data_format(struct snd_harmony *h, int fmt, int force)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 int o = h->st.format;
382 int n;
383
384 switch(fmt) {
385 case SNDRV_PCM_FORMAT_S16_BE:
386 n = HARMONY_DF_16BIT_LINEAR;
387 break;
388 case SNDRV_PCM_FORMAT_A_LAW:
389 n = HARMONY_DF_8BIT_ALAW;
390 break;
391 case SNDRV_PCM_FORMAT_MU_LAW:
392 n = HARMONY_DF_8BIT_ULAW;
393 break;
394 default:
395 n = HARMONY_DF_16BIT_LINEAR;
396 break;
397 }
398
399 if (force || o != n) {
400 snd_pcm_format_set_silence(fmt, h->sdma.area, SILENCE_BUFSZ /
401 (snd_pcm_format_physical_width(fmt)
402 / 8));
403 }
404
405 return n;
406}
407
408static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100409snd_harmony_playback_prepare(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Takashi Iwai67b10202005-11-17 15:12:11 +0100411 struct snd_harmony *h = snd_pcm_substream_chip(ss);
412 struct snd_pcm_runtime *rt = ss->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 if (h->st.capturing)
415 return -EBUSY;
416
417 h->pbuf.size = snd_pcm_lib_buffer_bytes(ss);
418 h->pbuf.count = snd_pcm_lib_period_bytes(ss);
Stuart Brady3a165682005-10-21 22:42:38 -0400419 if (h->pbuf.buf >= h->pbuf.size)
420 h->pbuf.buf = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 h->st.playing = 0;
422
423 h->st.rate = snd_harmony_rate_bits(rt->rate);
424 h->st.format = snd_harmony_set_data_format(h, rt->format, 0);
425
426 if (rt->channels == 2)
427 h->st.stereo = HARMONY_SS_STEREO;
428 else
429 h->st.stereo = HARMONY_SS_MONO;
430
431 harmony_set_control(h);
432
433 h->pbuf.addr = rt->dma_addr;
434
435 return 0;
436}
437
438static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100439snd_harmony_capture_prepare(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Takashi Iwai67b10202005-11-17 15:12:11 +0100441 struct snd_harmony *h = snd_pcm_substream_chip(ss);
442 struct snd_pcm_runtime *rt = ss->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 if (h->st.playing)
445 return -EBUSY;
446
447 h->cbuf.size = snd_pcm_lib_buffer_bytes(ss);
448 h->cbuf.count = snd_pcm_lib_period_bytes(ss);
Stuart Brady3a165682005-10-21 22:42:38 -0400449 if (h->cbuf.buf >= h->cbuf.size)
450 h->cbuf.buf = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 h->st.capturing = 0;
452
453 h->st.rate = snd_harmony_rate_bits(rt->rate);
454 h->st.format = snd_harmony_set_data_format(h, rt->format, 0);
455
456 if (rt->channels == 2)
457 h->st.stereo = HARMONY_SS_STEREO;
458 else
459 h->st.stereo = HARMONY_SS_MONO;
460
461 harmony_set_control(h);
462
463 h->cbuf.addr = rt->dma_addr;
464
465 return 0;
466}
467
468static snd_pcm_uframes_t
Takashi Iwai67b10202005-11-17 15:12:11 +0100469snd_harmony_playback_pointer(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Takashi Iwai67b10202005-11-17 15:12:11 +0100471 struct snd_pcm_runtime *rt = ss->runtime;
472 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 unsigned long pcuradd;
474 unsigned long played;
475
476 if (!(h->st.playing) || (h->psubs == NULL))
477 return 0;
478
479 if ((h->pbuf.addr == 0) || (h->pbuf.size == 0))
480 return 0;
481
482 pcuradd = harmony_read(h, HARMONY_PCURADD);
483 played = pcuradd - h->pbuf.addr;
484
485#ifdef HARMONY_DEBUG
486 printk(KERN_DEBUG PFX "playback_pointer is 0x%lx-0x%lx = %d bytes\n",
487 pcuradd, h->pbuf.addr, played);
488#endif
489
490 if (pcuradd > h->pbuf.addr + h->pbuf.size) {
491 return 0;
492 }
493
494 return bytes_to_frames(rt, played);
495}
496
497static snd_pcm_uframes_t
Takashi Iwai67b10202005-11-17 15:12:11 +0100498snd_harmony_capture_pointer(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Takashi Iwai67b10202005-11-17 15:12:11 +0100500 struct snd_pcm_runtime *rt = ss->runtime;
501 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 unsigned long rcuradd;
503 unsigned long caught;
504
505 if (!(h->st.capturing) || (h->csubs == NULL))
506 return 0;
507
508 if ((h->cbuf.addr == 0) || (h->cbuf.size == 0))
509 return 0;
510
511 rcuradd = harmony_read(h, HARMONY_RCURADD);
512 caught = rcuradd - h->cbuf.addr;
513
514#ifdef HARMONY_DEBUG
515 printk(KERN_DEBUG PFX "capture_pointer is 0x%lx-0x%lx = %d bytes\n",
516 rcuradd, h->cbuf.addr, caught);
517#endif
518
519 if (rcuradd > h->cbuf.addr + h->cbuf.size) {
520 return 0;
521 }
522
523 return bytes_to_frames(rt, caught);
524}
525
526static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100527snd_harmony_playback_open(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Takashi Iwai67b10202005-11-17 15:12:11 +0100529 struct snd_harmony *h = snd_pcm_substream_chip(ss);
530 struct snd_pcm_runtime *rt = ss->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 int err;
532
533 h->psubs = ss;
534 rt->hw = snd_harmony_playback;
535 snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
536 &hw_constraint_rates);
537
538 err = snd_pcm_hw_constraint_integer(rt, SNDRV_PCM_HW_PARAM_PERIODS);
539 if (err < 0)
540 return err;
541
542 return 0;
543}
544
545static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100546snd_harmony_capture_open(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Takashi Iwai67b10202005-11-17 15:12:11 +0100548 struct snd_harmony *h = snd_pcm_substream_chip(ss);
549 struct snd_pcm_runtime *rt = ss->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 int err;
551
552 h->csubs = ss;
553 rt->hw = snd_harmony_capture;
554 snd_pcm_hw_constraint_list(rt, 0, SNDRV_PCM_HW_PARAM_RATE,
555 &hw_constraint_rates);
556
557 err = snd_pcm_hw_constraint_integer(rt, SNDRV_PCM_HW_PARAM_PERIODS);
558 if (err < 0)
559 return err;
560
561 return 0;
562}
563
564static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100565snd_harmony_playback_close(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
Takashi Iwai67b10202005-11-17 15:12:11 +0100567 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 h->psubs = NULL;
569 return 0;
570}
571
572static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100573snd_harmony_capture_close(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Takashi Iwai67b10202005-11-17 15:12:11 +0100575 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 h->csubs = NULL;
577 return 0;
578}
579
580static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100581snd_harmony_hw_params(struct snd_pcm_substream *ss,
582 struct snd_pcm_hw_params *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
584 int err;
Takashi Iwai67b10202005-11-17 15:12:11 +0100585 struct snd_harmony *h = snd_pcm_substream_chip(ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 err = snd_pcm_lib_malloc_pages(ss, params_buffer_bytes(hw));
588 if (err > 0 && h->dma.type == SNDRV_DMA_TYPE_CONTINUOUS)
589 ss->runtime->dma_addr = __pa(ss->runtime->dma_area);
590
591 return err;
592}
593
594static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100595snd_harmony_hw_free(struct snd_pcm_substream *ss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
597 return snd_pcm_lib_free_pages(ss);
598}
599
Takashi Iwai67b10202005-11-17 15:12:11 +0100600static struct snd_pcm_ops snd_harmony_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .open = snd_harmony_playback_open,
602 .close = snd_harmony_playback_close,
603 .ioctl = snd_pcm_lib_ioctl,
604 .hw_params = snd_harmony_hw_params,
605 .hw_free = snd_harmony_hw_free,
606 .prepare = snd_harmony_playback_prepare,
607 .trigger = snd_harmony_playback_trigger,
608 .pointer = snd_harmony_playback_pointer,
609};
610
Takashi Iwai67b10202005-11-17 15:12:11 +0100611static struct snd_pcm_ops snd_harmony_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .open = snd_harmony_capture_open,
613 .close = snd_harmony_capture_close,
614 .ioctl = snd_pcm_lib_ioctl,
615 .hw_params = snd_harmony_hw_params,
616 .hw_free = snd_harmony_hw_free,
617 .prepare = snd_harmony_capture_prepare,
618 .trigger = snd_harmony_capture_trigger,
619 .pointer = snd_harmony_capture_pointer,
620};
621
622static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100623snd_harmony_pcm_init(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Takashi Iwai67b10202005-11-17 15:12:11 +0100625 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 int err;
627
628 harmony_disable_interrupts(h);
629
630 err = snd_pcm_new(h->card, "harmony", 0, 1, 1, &pcm);
631 if (err < 0)
632 return err;
633
634 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
635 &snd_harmony_playback_ops);
636 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
637 &snd_harmony_capture_ops);
638
639 pcm->private_data = h;
640 pcm->info_flags = 0;
641 strcpy(pcm->name, "harmony");
642 h->pcm = pcm;
643
644 h->psubs = NULL;
645 h->csubs = NULL;
646
647 /* initialize graveyard buffer */
648 h->dma.type = SNDRV_DMA_TYPE_DEV;
649 h->dma.dev = &h->dev->dev;
650 err = snd_dma_alloc_pages(h->dma.type,
651 h->dma.dev,
652 BUF_SIZE*GRAVEYARD_BUFS,
653 &h->gdma);
654 if (err < 0) {
655 printk(KERN_ERR PFX "cannot allocate graveyard buffer!\n");
656 return err;
657 }
658
659 /* initialize silence buffers */
660 err = snd_dma_alloc_pages(h->dma.type,
661 h->dma.dev,
662 BUF_SIZE*SILENCE_BUFS,
663 &h->sdma);
664 if (err < 0) {
665 printk(KERN_ERR PFX "cannot allocate silence buffer!\n");
666 return err;
667 }
668
669 /* pre-allocate space for DMA */
670 err = snd_pcm_lib_preallocate_pages_for_all(pcm, h->dma.type,
671 h->dma.dev,
672 MAX_BUF_SIZE,
673 MAX_BUF_SIZE);
674 if (err < 0) {
675 printk(KERN_ERR PFX "buffer allocation error: %d\n", err);
676 return err;
677 }
678
679 h->st.format = snd_harmony_set_data_format(h,
680 SNDRV_PCM_FORMAT_S16_BE, 1);
681
682 return 0;
683}
684
685static void
Takashi Iwai67b10202005-11-17 15:12:11 +0100686snd_harmony_set_new_gain(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 harmony_wait_for_control(h);
689 harmony_write(h, HARMONY_GAINCTL, h->st.gain);
690}
691
692static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100693snd_harmony_mixercontrol_info(struct snd_kcontrol *kc,
694 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
696 int mask = (kc->private_value >> 16) & 0xff;
697 int left_shift = (kc->private_value) & 0xff;
698 int right_shift = (kc->private_value >> 8) & 0xff;
699
700 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN :
701 SNDRV_CTL_ELEM_TYPE_INTEGER;
702 uinfo->count = left_shift == right_shift ? 1 : 2;
703 uinfo->value.integer.min = 0;
704 uinfo->value.integer.max = mask;
705
706 return 0;
707}
708
709static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100710snd_harmony_volume_get(struct snd_kcontrol *kc,
711 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Takashi Iwai67b10202005-11-17 15:12:11 +0100713 struct snd_harmony *h = snd_kcontrol_chip(kc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 int shift_left = (kc->private_value) & 0xff;
715 int shift_right = (kc->private_value >> 8) & 0xff;
716 int mask = (kc->private_value >> 16) & 0xff;
717 int invert = (kc->private_value >> 24) & 0xff;
718 int left, right;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100720 spin_lock_irq(&h->mixer_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 left = (h->st.gain >> shift_left) & mask;
723 right = (h->st.gain >> shift_right) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (invert) {
725 left = mask - left;
726 right = mask - right;
727 }
Stuart Brady3a165682005-10-21 22:42:38 -0400728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 ucontrol->value.integer.value[0] = left;
Stuart Brady3a165682005-10-21 22:42:38 -0400730 if (shift_left != shift_right)
731 ucontrol->value.integer.value[1] = right;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100733 spin_unlock_irq(&h->mixer_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 return 0;
736}
737
738static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100739snd_harmony_volume_put(struct snd_kcontrol *kc,
740 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
Takashi Iwai67b10202005-11-17 15:12:11 +0100742 struct snd_harmony *h = snd_kcontrol_chip(kc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 int shift_left = (kc->private_value) & 0xff;
744 int shift_right = (kc->private_value >> 8) & 0xff;
745 int mask = (kc->private_value >> 16) & 0xff;
746 int invert = (kc->private_value >> 24) & 0xff;
747 int left, right;
748 int old_gain = h->st.gain;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100750 spin_lock_irq(&h->mixer_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Stuart Brady3a165682005-10-21 22:42:38 -0400752 left = ucontrol->value.integer.value[0] & mask;
753 if (invert)
754 left = mask - left;
755 h->st.gain &= ~( (mask << shift_left ) );
756 h->st.gain |= (left << shift_left);
757
758 if (shift_left != shift_right) {
759 right = ucontrol->value.integer.value[1] & mask;
760 if (invert)
761 right = mask - right;
762 h->st.gain &= ~( (mask << shift_right) );
763 h->st.gain |= (right << shift_right);
764 }
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 snd_harmony_set_new_gain(h);
767
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100768 spin_unlock_irq(&h->mixer_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Stuart Brady3a165682005-10-21 22:42:38 -0400770 return h->st.gain != old_gain;
771}
772
773static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100774snd_harmony_captureroute_info(struct snd_kcontrol *kc,
775 struct snd_ctl_elem_info *uinfo)
Stuart Brady3a165682005-10-21 22:42:38 -0400776{
777 static char *texts[2] = { "Line", "Mic" };
778 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
779 uinfo->count = 1;
780 uinfo->value.enumerated.items = 2;
781 if (uinfo->value.enumerated.item > 1)
782 uinfo->value.enumerated.item = 1;
783 strcpy(uinfo->value.enumerated.name,
784 texts[uinfo->value.enumerated.item]);
785 return 0;
786}
787
788static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100789snd_harmony_captureroute_get(struct snd_kcontrol *kc,
790 struct snd_ctl_elem_value *ucontrol)
Stuart Brady3a165682005-10-21 22:42:38 -0400791{
Takashi Iwai67b10202005-11-17 15:12:11 +0100792 struct snd_harmony *h = snd_kcontrol_chip(kc);
Stuart Brady3a165682005-10-21 22:42:38 -0400793 int value;
Stuart Brady3a165682005-10-21 22:42:38 -0400794
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100795 spin_lock_irq(&h->mixer_lock);
Stuart Brady3a165682005-10-21 22:42:38 -0400796
797 value = (h->st.gain >> HARMONY_GAIN_IS_SHIFT) & 1;
798 ucontrol->value.enumerated.item[0] = value;
799
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100800 spin_unlock_irq(&h->mixer_lock);
Stuart Brady3a165682005-10-21 22:42:38 -0400801
802 return 0;
803}
804
805static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100806snd_harmony_captureroute_put(struct snd_kcontrol *kc,
807 struct snd_ctl_elem_value *ucontrol)
Stuart Brady3a165682005-10-21 22:42:38 -0400808{
Takashi Iwai67b10202005-11-17 15:12:11 +0100809 struct snd_harmony *h = snd_kcontrol_chip(kc);
Stuart Brady3a165682005-10-21 22:42:38 -0400810 int value;
811 int old_gain = h->st.gain;
Stuart Brady3a165682005-10-21 22:42:38 -0400812
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100813 spin_lock_irq(&h->mixer_lock);
Stuart Brady3a165682005-10-21 22:42:38 -0400814
815 value = ucontrol->value.enumerated.item[0] & 1;
816 h->st.gain &= ~HARMONY_GAIN_IS_MASK;
817 h->st.gain |= value << HARMONY_GAIN_IS_SHIFT;
818
819 snd_harmony_set_new_gain(h);
820
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100821 spin_unlock_irq(&h->mixer_lock);
Stuart Brady3a165682005-10-21 22:42:38 -0400822
823 return h->st.gain != old_gain;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
Takashi Iwai67b10202005-11-17 15:12:11 +0100826#define HARMONY_CONTROLS ARRAY_SIZE(snd_harmony_controls)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828#define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \
829{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
830 .info = snd_harmony_mixercontrol_info, \
831 .get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
832 .private_value = ((left_shift) | ((right_shift) << 8) | \
833 ((mask) << 16) | ((invert) << 24)) }
834
Takashi Iwai67b10202005-11-17 15:12:11 +0100835static struct snd_kcontrol_new snd_harmony_controls[] = {
Stuart Brady3a165682005-10-21 22:42:38 -0400836 HARMONY_VOLUME("Master Playback Volume", HARMONY_GAIN_LO_SHIFT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 HARMONY_GAIN_RO_SHIFT, HARMONY_GAIN_OUT, 1),
838 HARMONY_VOLUME("Capture Volume", HARMONY_GAIN_LI_SHIFT,
839 HARMONY_GAIN_RI_SHIFT, HARMONY_GAIN_IN, 0),
Stuart Brady3a165682005-10-21 22:42:38 -0400840 HARMONY_VOLUME("Monitor Volume", HARMONY_GAIN_MA_SHIFT,
841 HARMONY_GAIN_MA_SHIFT, HARMONY_GAIN_MA, 1),
842 {
843 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
844 .name = "Input Route",
845 .info = snd_harmony_captureroute_info,
846 .get = snd_harmony_captureroute_get,
847 .put = snd_harmony_captureroute_put
848 },
849 HARMONY_VOLUME("Internal Speaker Switch", HARMONY_GAIN_SE_SHIFT,
850 HARMONY_GAIN_SE_SHIFT, 1, 0),
851 HARMONY_VOLUME("Line-Out Switch", HARMONY_GAIN_LE_SHIFT,
852 HARMONY_GAIN_LE_SHIFT, 1, 0),
853 HARMONY_VOLUME("Headphones Switch", HARMONY_GAIN_HE_SHIFT,
854 HARMONY_GAIN_HE_SHIFT, 1, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855};
856
Helge Deller992378a2007-01-28 17:06:12 +0100857static void __devinit
Takashi Iwai67b10202005-11-17 15:12:11 +0100858snd_harmony_mixer_reset(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860 harmony_mute(h);
861 harmony_reset(h);
862 h->st.gain = HARMONY_GAIN_DEFAULT;
863 harmony_unmute(h);
864}
865
Helge Deller992378a2007-01-28 17:06:12 +0100866static int __devinit
Takashi Iwai67b10202005-11-17 15:12:11 +0100867snd_harmony_mixer_init(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Takashi Iwai67b10202005-11-17 15:12:11 +0100869 struct snd_card *card = h->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 int idx, err;
871
872 snd_assert(h != NULL, return -EINVAL);
873 strcpy(card->mixername, "Harmony Gain control interface");
874
875 for (idx = 0; idx < HARMONY_CONTROLS; idx++) {
876 err = snd_ctl_add(card,
877 snd_ctl_new1(&snd_harmony_controls[idx], h));
878 if (err < 0)
879 return err;
880 }
881
882 snd_harmony_mixer_reset(h);
883
884 return 0;
885}
886
887static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100888snd_harmony_free(struct snd_harmony *h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
890 if (h->gdma.addr)
891 snd_dma_free_pages(&h->gdma);
892 if (h->sdma.addr)
893 snd_dma_free_pages(&h->sdma);
894
895 if (h->irq >= 0)
896 free_irq(h->irq, h);
897
898 if (h->iobase)
899 iounmap(h->iobase);
900
901 parisc_set_drvdata(h->dev, NULL);
902
903 kfree(h);
904 return 0;
905}
906
907static int
Takashi Iwai67b10202005-11-17 15:12:11 +0100908snd_harmony_dev_free(struct snd_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Takashi Iwai67b10202005-11-17 15:12:11 +0100910 struct snd_harmony *h = dev->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 return snd_harmony_free(h);
912}
913
914static int __devinit
Takashi Iwai67b10202005-11-17 15:12:11 +0100915snd_harmony_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 struct parisc_device *padev,
Takashi Iwai67b10202005-11-17 15:12:11 +0100917 struct snd_harmony **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
919 int err;
Takashi Iwai67b10202005-11-17 15:12:11 +0100920 struct snd_harmony *h;
921 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 .dev_free = snd_harmony_dev_free,
923 };
924
925 *rchip = NULL;
926
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100927 h = kzalloc(sizeof(*h), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if (h == NULL)
929 return -ENOMEM;
930
Matthew Wilcox53f01bb2005-10-21 22:36:40 -0400931 h->hpa = padev->hpa.start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 h->card = card;
933 h->dev = padev;
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100934 h->irq = -1;
Matthew Wilcox53f01bb2005-10-21 22:36:40 -0400935 h->iobase = ioremap_nocache(padev->hpa.start, HARMONY_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (h->iobase == NULL) {
937 printk(KERN_ERR PFX "unable to remap hpa 0x%lx\n",
Matthew Wilcox53f01bb2005-10-21 22:36:40 -0400938 padev->hpa.start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 err = -EBUSY;
940 goto free_and_ret;
941 }
942
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100943 err = request_irq(padev->irq, snd_harmony_interrupt, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 "harmony", h);
945 if (err) {
946 printk(KERN_ERR PFX "could not obtain interrupt %d",
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100947 padev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 goto free_and_ret;
949 }
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100950 h->irq = padev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 spin_lock_init(&h->mixer_lock);
953 spin_lock_init(&h->lock);
954
955 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
956 h, &ops)) < 0) {
957 goto free_and_ret;
958 }
959
Takashi Iwaia76af192005-09-05 16:56:40 +0200960 snd_card_set_dev(card, &padev->dev);
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 *rchip = h;
963
964 return 0;
965
966free_and_ret:
967 snd_harmony_free(h);
968 return err;
969}
970
971static int __devinit
972snd_harmony_probe(struct parisc_device *padev)
973{
974 int err;
Takashi Iwai67b10202005-11-17 15:12:11 +0100975 struct snd_card *card;
976 struct snd_harmony *h;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 card = snd_card_new(index, id, THIS_MODULE, 0);
979 if (card == NULL)
980 return -ENOMEM;
981
982 err = snd_harmony_create(card, padev, &h);
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100983 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 goto free_and_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 err = snd_harmony_pcm_init(h);
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100987 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 goto free_and_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 err = snd_harmony_mixer_init(h);
Takashi Iwai03f9ae22005-11-17 10:34:40 +0100991 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 goto free_and_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 strcpy(card->driver, "harmony");
995 strcpy(card->shortname, "Harmony");
996 sprintf(card->longname, "%s at 0x%lx, irq %i",
997 card->shortname, h->hpa, h->irq);
998
999 err = snd_card_register(card);
Takashi Iwai03f9ae22005-11-17 10:34:40 +01001000 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 goto free_and_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Takashi Iwai03f9ae22005-11-17 10:34:40 +01001003 parisc_set_drvdata(padev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 return 0;
1005
1006free_and_ret:
1007 snd_card_free(card);
1008 return err;
1009}
1010
1011static int __devexit
1012snd_harmony_remove(struct parisc_device *padev)
1013{
Takashi Iwai03f9ae22005-11-17 10:34:40 +01001014 snd_card_free(parisc_get_drvdata(padev));
1015 parisc_set_drvdata(padev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 return 0;
1017}
1018
1019static struct parisc_driver snd_harmony_driver = {
1020 .name = "harmony",
1021 .id_table = snd_harmony_devtable,
1022 .probe = snd_harmony_probe,
1023 .remove = snd_harmony_remove,
1024};
1025
1026static int __init
1027alsa_harmony_init(void)
1028{
Takashi Iwai03f9ae22005-11-17 10:34:40 +01001029 return register_parisc_driver(&snd_harmony_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
1032static void __exit
1033alsa_harmony_fini(void)
1034{
Takashi Iwai67b10202005-11-17 15:12:11 +01001035 unregister_parisc_driver(&snd_harmony_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
1038MODULE_LICENSE("GPL");
1039MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>");
1040MODULE_DESCRIPTION("Harmony sound driver");
1041
1042module_init(alsa_harmony_init);
1043module_exit(alsa_harmony_fini);