1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60#include <linux/module.h>
61#include <linux/moduleparam.h>
62#include <linux/init.h>
63#include <linux/err.h>
64#include <linux/platform_device.h>
65#include <linux/errno.h>
66#include <linux/ioctl.h>
67#include <linux/delay.h>
68#include <linux/slab.h>
69
70#ifdef CONFIG_PM
71#include <linux/pm.h>
72#endif
73
74#include <mach/hardware.h>
75#include <mach/h3600.h>
76#include <asm/mach-types.h>
77#include <asm/dma.h>
78
79#include <sound/core.h>
80#include <sound/pcm.h>
81#include <sound/initval.h>
82
83#include <linux/l3/l3.h>
84
85#undef DEBUG_MODE
86#undef DEBUG_FUNCTION_NAMES
87#include <sound/uda1341.h>
88
89
90
91
92
93
94
95
96
97MODULE_AUTHOR("Tomas Kasparek <tomas.kasparek@seznam.cz>");
98MODULE_LICENSE("GPL");
99MODULE_DESCRIPTION("SA1100/SA1111 + UDA1341TS driver for ALSA");
100MODULE_SUPPORTED_DEVICE("{{UDA1341,iPAQ H3600 UDA1341TS}}");
101
102static char *id;
103
104module_param(id, charp, 0444);
105MODULE_PARM_DESC(id, "ID string for SA1100/SA1111 + UDA1341TS soundcard.");
106
107struct audio_stream {
108 char *id;
109 int stream_id;
110 dma_device_t dma_dev;
111#ifdef HH_VERSION
112 dmach_t dmach;
113#else
114 dma_regs_t *dma_regs;
115#endif
116 unsigned int active:1;
117 int period;
118 int periods;
119 int tx_spin;
120 unsigned int old_offset;
121 spinlock_t dma_lock;
122 struct snd_pcm_substream *stream;
123};
124
125struct sa11xx_uda1341 {
126 struct snd_card *card;
127 struct l3_client *uda1341;
128 struct snd_pcm *pcm;
129 long samplerate;
130 struct audio_stream s[2];
131};
132
133static unsigned int rates[] = {
134 8000, 10666, 10985, 14647,
135 16000, 21970, 22050, 24000,
136 29400, 32000, 44100, 48000,
137};
138
139static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
140 .count = ARRAY_SIZE(rates),
141 .list = rates,
142 .mask = 0,
143};
144
145static struct platform_device *device;
146
147
148
149
150
151
152
153
154#define GPIO_H3600_CLK_SET0 GPIO_GPIO (12)
155#define GPIO_H3600_CLK_SET1 GPIO_GPIO (13)
156
157#ifdef CONFIG_SA1100_H3XXX
158#define clr_sa11xx_uda1341_egpio(x) clr_h3600_egpio(x)
159#define set_sa11xx_uda1341_egpio(x) set_h3600_egpio(x)
160#else
161#error This driver could serve H3x00 handhelds only!
162#endif
163
164static void sa11xx_uda1341_set_audio_clock(long val)
165{
166 switch (val) {
167 case 24000: case 32000: case 48000:
168 GPCR = GPIO_H3600_CLK_SET0 | GPIO_H3600_CLK_SET1;
169 break;
170
171 case 22050: case 29400: case 44100:
172 GPSR = GPIO_H3600_CLK_SET0;
173 GPCR = GPIO_H3600_CLK_SET1;
174 break;
175
176 case 8000: case 10666: case 16000:
177 GPCR = GPIO_H3600_CLK_SET0;
178 GPSR = GPIO_H3600_CLK_SET1;
179 break;
180
181 case 10985: case 14647: case 21970:
182 GPSR = GPIO_H3600_CLK_SET0 | GPIO_H3600_CLK_SET1;
183 break;
184 }
185}
186
187static void sa11xx_uda1341_set_samplerate(struct sa11xx_uda1341 *sa11xx_uda1341, long rate)
188{
189 int clk_div = 0;
190 int clk=0;
191
192
193 Ser4SSCR0 &= ~SSCR0_SSE;
194
195 udelay(125);
196
197
198
199
200
201
202
203 if (rate >= 48000)
204 rate = 48000;
205 else if (rate >= 44100)
206 rate = 44100;
207 else if (rate >= 32000)
208 rate = 32000;
209 else if (rate >= 29400)
210 rate = 29400;
211 else if (rate >= 24000)
212 rate = 24000;
213 else if (rate >= 22050)
214 rate = 22050;
215 else if (rate >= 21970)
216 rate = 21970;
217 else if (rate >= 16000)
218 rate = 16000;
219 else if (rate >= 14647)
220 rate = 14647;
221 else if (rate >= 10985)
222 rate = 10985;
223 else if (rate >= 10666)
224 rate = 10666;
225 else
226 rate = 8000;
227
228
229
230 sa11xx_uda1341_set_audio_clock(rate);
231
232
233 switch (rate) {
234 case 8000:
235 case 10985:
236 case 22050:
237 case 24000:
238 clk = F512;
239 clk_div = SSCR0_SerClkDiv(16);
240 break;
241 case 16000:
242 case 21970:
243 case 44100:
244 case 48000:
245 clk = F256;
246 clk_div = SSCR0_SerClkDiv(8);
247 break;
248 case 10666:
249 case 14647:
250 case 29400:
251 case 32000:
252 clk = F384;
253 clk_div = SSCR0_SerClkDiv(12);
254 break;
255 }
256
257
258 l3_command(sa11xx_uda1341->uda1341, CMD_FORMAT, (void *)LSB16);
259
260 l3_command(sa11xx_uda1341->uda1341, CMD_FS, (void *)clk);
261 Ser4SSCR0 = (Ser4SSCR0 & ~0xff00) + clk_div + SSCR0_SSE;
262 sa11xx_uda1341->samplerate = rate;
263}
264
265
266
267
268
269static void sa11xx_uda1341_audio_init(struct sa11xx_uda1341 *sa11xx_uda1341)
270{
271 unsigned long flags;
272
273
274 sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK].id = "UDA1341 out";
275 sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK].stream_id = SNDRV_PCM_STREAM_PLAYBACK;
276 sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK].dma_dev = DMA_Ser4SSPWr;
277
278 sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE].id = "UDA1341 in";
279 sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE].stream_id = SNDRV_PCM_STREAM_CAPTURE;
280 sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE].dma_dev = DMA_Ser4SSPRd;
281
282
283
284
285 local_irq_save(flags);
286 GAFR |= (GPIO_SSP_CLK);
287 GPDR &= ~(GPIO_SSP_CLK);
288 Ser4SSCR0 = 0;
289 Ser4SSCR0 = SSCR0_DataSize(16) + SSCR0_TI + SSCR0_SerClkDiv(8);
290 Ser4SSCR1 = SSCR1_SClkIactL + SSCR1_SClk1P + SSCR1_ExtClk;
291 Ser4SSCR0 |= SSCR0_SSE;
292 local_irq_restore(flags);
293
294
295
296 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_CODEC_NRESET);
297 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_AUDIO_ON);
298 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
299
300
301 mdelay(1);
302
303
304 l3_open(sa11xx_uda1341->uda1341);
305
306
307 sa11xx_uda1341_set_samplerate(sa11xx_uda1341, sa11xx_uda1341->samplerate);
308
309
310 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_CODEC_NRESET);
311 mdelay(1);
312
313
314 Ser4SSDR = 0;
315
316 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
317}
318
319static void sa11xx_uda1341_audio_shutdown(struct sa11xx_uda1341 *sa11xx_uda1341)
320{
321
322 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
323
324
325 l3_close(sa11xx_uda1341->uda1341);
326 Ser4SSCR0 = 0;
327 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_CODEC_NRESET);
328
329
330
331
332 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_AUDIO_ON);
333 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
334}
335
336
337
338
339
340
341
342
343
344#define FORCE_CLOCK_ADDR (dma_addr_t)FLUSH_BASE_PHYS
345#define FORCE_CLOCK_SIZE 4096
346
347
348#define DMA_BUF_SIZE 8176
349
350#ifdef HH_VERSION
351
352static int audio_dma_request(struct audio_stream *s, void (*callback)(void *, int))
353{
354 int ret;
355
356 ret = sa1100_request_dma(&s->dmach, s->id, s->dma_dev);
357 if (ret < 0) {
358 printk(KERN_ERR "unable to grab audio dma 0x%x\n", s->dma_dev);
359 return ret;
360 }
361 sa1100_dma_set_callback(s->dmach, callback);
362 return 0;
363}
364
365static inline void audio_dma_free(struct audio_stream *s)
366{
367 sa1100_free_dma(s->dmach);
368 s->dmach = -1;
369}
370
371#else
372
373static int audio_dma_request(struct audio_stream *s, void (*callback)(void *))
374{
375 int ret;
376
377 ret = sa1100_request_dma(s->dma_dev, s->id, callback, s, &s->dma_regs);
378 if (ret < 0)
379 printk(KERN_ERR "unable to grab audio dma 0x%x\n", s->dma_dev);
380 return ret;
381}
382
383static void audio_dma_free(struct audio_stream *s)
384{
385 sa1100_free_dma(s->dma_regs);
386 s->dma_regs = 0;
387}
388
389#endif
390
391static u_int audio_get_dma_pos(struct audio_stream *s)
392{
393 struct snd_pcm_substream *substream = s->stream;
394 struct snd_pcm_runtime *runtime = substream->runtime;
395 unsigned int offset;
396 unsigned long flags;
397 dma_addr_t addr;
398
399
400 spin_lock_irqsave(&s->dma_lock, flags);
401#ifdef HH_VERSION
402 sa1100_dma_get_current(s->dmach, NULL, &addr);
403#else
404 addr = sa1100_get_dma_pos((s)->dma_regs);
405#endif
406 offset = addr - runtime->dma_addr;
407 spin_unlock_irqrestore(&s->dma_lock, flags);
408
409 offset = bytes_to_frames(runtime,offset);
410 if (offset >= runtime->buffer_size)
411 offset = 0;
412
413 return offset;
414}
415
416
417
418
419static void audio_stop_dma(struct audio_stream *s)
420{
421 unsigned long flags;
422
423 spin_lock_irqsave(&s->dma_lock, flags);
424 s->active = 0;
425 s->period = 0;
426
427#ifdef HH_VERSION
428 sa1100_dma_flush_all(s->dmach);
429#else
430 sa1100_clear_dma(s->dma_regs);
431#endif
432 spin_unlock_irqrestore(&s->dma_lock, flags);
433}
434
435static void audio_process_dma(struct audio_stream *s)
436{
437 struct snd_pcm_substream *substream = s->stream;
438 struct snd_pcm_runtime *runtime;
439 unsigned int dma_size;
440 unsigned int offset;
441 int ret;
442
443
444 if (s->tx_spin) {
445 if (snd_BUG_ON(s->stream_id != SNDRV_PCM_STREAM_PLAYBACK))
446 return;
447
448#ifdef HH_VERSION
449 sa1100_dma_set_spin(s->dmach, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE);
450#else
451 while (1) {
452 ret = sa1100_start_dma(s->dma_regs, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE);
453 if (ret)
454 return;
455 }
456#endif
457 return;
458 }
459
460
461 runtime = substream->runtime;
462 while (s->active && s->periods < runtime->periods) {
463 dma_size = frames_to_bytes(runtime, runtime->period_size);
464 if (s->old_offset) {
465
466 offset = frames_to_bytes(runtime, s->old_offset - 1);
467 s->old_offset = 0;
468 s->periods = 0;
469 s->period = offset / dma_size;
470 offset %= dma_size;
471 dma_size = dma_size - offset;
472 if (!dma_size)
473 continue;
474 } else {
475 offset = dma_size * s->period;
476 snd_BUG_ON(dma_size > DMA_BUF_SIZE);
477 }
478#ifdef HH_VERSION
479 ret = sa1100_dma_queue_buffer(s->dmach, s, runtime->dma_addr + offset, dma_size);
480 if (ret)
481 return;
482#else
483 ret = sa1100_start_dma((s)->dma_regs, runtime->dma_addr + offset, dma_size);
484 if (ret) {
485 printk(KERN_ERR "audio_process_dma: cannot queue DMA buffer (%i)\n", ret);
486 return;
487 }
488#endif
489
490 s->period++;
491 s->period %= runtime->periods;
492 s->periods++;
493 }
494}
495
496#ifdef HH_VERSION
497static void audio_dma_callback(void *data, int size)
498#else
499static void audio_dma_callback(void *data)
500#endif
501{
502 struct audio_stream *s = data;
503
504
505
506
507
508 if (s->active)
509 snd_pcm_period_elapsed(s->stream);
510
511 spin_lock(&s->dma_lock);
512 if (!s->tx_spin && s->periods > 0)
513 s->periods--;
514 audio_process_dma(s);
515 spin_unlock(&s->dma_lock);
516}
517
518
519
520
521
522
523
524static int snd_sa11xx_uda1341_trigger(struct snd_pcm_substream *substream, int cmd)
525{
526 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
527 int stream_id = substream->pstr->stream;
528 struct audio_stream *s = &chip->s[stream_id];
529 struct audio_stream *s1 = &chip->s[stream_id ^ 1];
530 int err = 0;
531
532
533 spin_lock(&s->dma_lock);
534 switch (cmd) {
535 case SNDRV_PCM_TRIGGER_START:
536
537 if (stream_id == SNDRV_PCM_STREAM_CAPTURE && !s1->active) {
538
539 s1->tx_spin = 1;
540 audio_process_dma(s1);
541 }
542
543
544
545
546 else {
547 s->tx_spin = 0;
548 }
549
550
551 s->active = 1;
552 audio_process_dma(s);
553 break;
554 case SNDRV_PCM_TRIGGER_STOP:
555
556 audio_stop_dma(s);
557
558
559
560
561
562
563 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK && s1->active) {
564
565 s->tx_spin = 1;
566 audio_process_dma(s);
567 }
568
569
570
571
572 else {
573 if (s1->tx_spin) {
574 s1->tx_spin = 0;
575 audio_stop_dma(s1);
576 }
577 }
578
579 break;
580 case SNDRV_PCM_TRIGGER_SUSPEND:
581 s->active = 0;
582#ifdef HH_VERSION
583 sa1100_dma_stop(s->dmach);
584#else
585
586#endif
587 s->old_offset = audio_get_dma_pos(s) + 1;
588#ifdef HH_VERSION
589 sa1100_dma_flush_all(s->dmach);
590#else
591
592#endif
593 s->periods = 0;
594 break;
595 case SNDRV_PCM_TRIGGER_RESUME:
596 s->active = 1;
597 s->tx_spin = 0;
598 audio_process_dma(s);
599 if (stream_id == SNDRV_PCM_STREAM_CAPTURE && !s1->active) {
600 s1->tx_spin = 1;
601 audio_process_dma(s1);
602 }
603 break;
604 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
605#ifdef HH_VERSION
606 sa1100_dma_stop(s->dmach);
607#else
608
609#endif
610 s->active = 0;
611 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
612 if (s1->active) {
613 s->tx_spin = 1;
614 s->old_offset = audio_get_dma_pos(s) + 1;
615#ifdef HH_VERSION
616 sa1100_dma_flush_all(s->dmach);
617#else
618
619#endif
620 audio_process_dma(s);
621 }
622 } else {
623 if (s1->tx_spin) {
624 s1->tx_spin = 0;
625#ifdef HH_VERSION
626 sa1100_dma_flush_all(s1->dmach);
627#else
628
629#endif
630 }
631 }
632 break;
633 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
634 s->active = 1;
635 if (s->old_offset) {
636 s->tx_spin = 0;
637 audio_process_dma(s);
638 break;
639 }
640 if (stream_id == SNDRV_PCM_STREAM_CAPTURE && !s1->active) {
641 s1->tx_spin = 1;
642 audio_process_dma(s1);
643 }
644#ifdef HH_VERSION
645 sa1100_dma_resume(s->dmach);
646#else
647
648#endif
649 break;
650 default:
651 err = -EINVAL;
652 break;
653 }
654 spin_unlock(&s->dma_lock);
655 return err;
656}
657
658static int snd_sa11xx_uda1341_prepare(struct snd_pcm_substream *substream)
659{
660 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
661 struct snd_pcm_runtime *runtime = substream->runtime;
662 struct audio_stream *s = &chip->s[substream->pstr->stream];
663
664
665 sa11xx_uda1341_set_samplerate(chip, runtime->rate);
666
667
668
669
670 s->period = 0;
671 s->periods = 0;
672
673 return 0;
674}
675
676static snd_pcm_uframes_t snd_sa11xx_uda1341_pointer(struct snd_pcm_substream *substream)
677{
678 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
679 return audio_get_dma_pos(&chip->s[substream->pstr->stream]);
680}
681
682
683
684static struct snd_pcm_hardware snd_sa11xx_uda1341_capture =
685{
686 .info = (SNDRV_PCM_INFO_INTERLEAVED |
687 SNDRV_PCM_INFO_BLOCK_TRANSFER |
688 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
689 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
690 .formats = SNDRV_PCM_FMTBIT_S16_LE,
691 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
692 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |\
693 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
694 SNDRV_PCM_RATE_KNOT),
695 .rate_min = 8000,
696 .rate_max = 48000,
697 .channels_min = 2,
698 .channels_max = 2,
699 .buffer_bytes_max = 64*1024,
700 .period_bytes_min = 64,
701 .period_bytes_max = DMA_BUF_SIZE,
702 .periods_min = 2,
703 .periods_max = 255,
704 .fifo_size = 0,
705};
706
707static struct snd_pcm_hardware snd_sa11xx_uda1341_playback =
708{
709 .info = (SNDRV_PCM_INFO_INTERLEAVED |
710 SNDRV_PCM_INFO_BLOCK_TRANSFER |
711 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
712 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
713 .formats = SNDRV_PCM_FMTBIT_S16_LE,
714 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
715 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |\
716 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
717 SNDRV_PCM_RATE_KNOT),
718 .rate_min = 8000,
719 .rate_max = 48000,
720 .channels_min = 2,
721 .channels_max = 2,
722 .buffer_bytes_max = 64*1024,
723 .period_bytes_min = 64,
724 .period_bytes_max = DMA_BUF_SIZE,
725 .periods_min = 2,
726 .periods_max = 255,
727 .fifo_size = 0,
728};
729
730static int snd_card_sa11xx_uda1341_open(struct snd_pcm_substream *substream)
731{
732 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
733 struct snd_pcm_runtime *runtime = substream->runtime;
734 int stream_id = substream->pstr->stream;
735 int err;
736
737 chip->s[stream_id].stream = substream;
738
739 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
740 runtime->hw = snd_sa11xx_uda1341_playback;
741 else
742 runtime->hw = snd_sa11xx_uda1341_capture;
743 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
744 return err;
745 if ((err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates)) < 0)
746 return err;
747
748 return 0;
749}
750
751static int snd_card_sa11xx_uda1341_close(struct snd_pcm_substream *substream)
752{
753 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
754
755 chip->s[substream->pstr->stream].stream = NULL;
756 return 0;
757}
758
759
760
761static int snd_sa11xx_uda1341_hw_params(struct snd_pcm_substream *substream,
762 struct snd_pcm_hw_params *hw_params)
763{
764
765 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
766}
767
768static int snd_sa11xx_uda1341_hw_free(struct snd_pcm_substream *substream)
769{
770 return snd_pcm_lib_free_pages(substream);
771}
772
773
774
775static struct snd_pcm_ops snd_card_sa11xx_uda1341_playback_ops = {
776 .open = snd_card_sa11xx_uda1341_open,
777 .close = snd_card_sa11xx_uda1341_close,
778 .ioctl = snd_pcm_lib_ioctl,
779 .hw_params = snd_sa11xx_uda1341_hw_params,
780 .hw_free = snd_sa11xx_uda1341_hw_free,
781 .prepare = snd_sa11xx_uda1341_prepare,
782 .trigger = snd_sa11xx_uda1341_trigger,
783 .pointer = snd_sa11xx_uda1341_pointer,
784};
785
786static struct snd_pcm_ops snd_card_sa11xx_uda1341_capture_ops = {
787 .open = snd_card_sa11xx_uda1341_open,
788 .close = snd_card_sa11xx_uda1341_close,
789 .ioctl = snd_pcm_lib_ioctl,
790 .hw_params = snd_sa11xx_uda1341_hw_params,
791 .hw_free = snd_sa11xx_uda1341_hw_free,
792 .prepare = snd_sa11xx_uda1341_prepare,
793 .trigger = snd_sa11xx_uda1341_trigger,
794 .pointer = snd_sa11xx_uda1341_pointer,
795};
796
797static int __init snd_card_sa11xx_uda1341_pcm(struct sa11xx_uda1341 *sa11xx_uda1341, int device)
798{
799 struct snd_pcm *pcm;
800 int err;
801
802 if ((err = snd_pcm_new(sa11xx_uda1341->card, "UDA1341 PCM", device, 1, 1, &pcm)) < 0)
803 return err;
804
805
806
807
808
809
810 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
811 snd_dma_isa_data(),
812 64*1024, 64*1024);
813
814 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_sa11xx_uda1341_playback_ops);
815 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_sa11xx_uda1341_capture_ops);
816 pcm->private_data = sa11xx_uda1341;
817 pcm->info_flags = 0;
818 strcpy(pcm->name, "UDA1341 PCM");
819
820 sa11xx_uda1341_audio_init(sa11xx_uda1341);
821
822
823 audio_dma_request(&sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK], audio_dma_callback);
824 audio_dma_request(&sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE], audio_dma_callback);
825
826 sa11xx_uda1341->pcm = pcm;
827
828 return 0;
829}
830
831
832
833
834
835#ifdef CONFIG_PM
836
837static int snd_sa11xx_uda1341_suspend(struct platform_device *devptr,
838 pm_message_t state)
839{
840 struct snd_card *card = platform_get_drvdata(devptr);
841 struct sa11xx_uda1341 *chip = card->private_data;
842
843 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
844 snd_pcm_suspend_all(chip->pcm);
845#ifdef HH_VERSION
846 sa1100_dma_sleep(chip->s[SNDRV_PCM_STREAM_PLAYBACK].dmach);
847 sa1100_dma_sleep(chip->s[SNDRV_PCM_STREAM_CAPTURE].dmach);
848#else
849
850#endif
851 l3_command(chip->uda1341, CMD_SUSPEND, NULL);
852 sa11xx_uda1341_audio_shutdown(chip);
853
854 return 0;
855}
856
857static int snd_sa11xx_uda1341_resume(struct platform_device *devptr)
858{
859 struct snd_card *card = platform_get_drvdata(devptr);
860 struct sa11xx_uda1341 *chip = card->private_data;
861
862 sa11xx_uda1341_audio_init(chip);
863 l3_command(chip->uda1341, CMD_RESUME, NULL);
864#ifdef HH_VERSION
865 sa1100_dma_wakeup(chip->s[SNDRV_PCM_STREAM_PLAYBACK].dmach);
866 sa1100_dma_wakeup(chip->s[SNDRV_PCM_STREAM_CAPTURE].dmach);
867#else
868
869#endif
870 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
871 return 0;
872}
873#endif
874
875void snd_sa11xx_uda1341_free(struct snd_card *card)
876{
877 struct sa11xx_uda1341 *chip = card->private_data;
878
879 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_PLAYBACK]);
880 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_CAPTURE]);
881}
882
883static int __devinit sa11xx_uda1341_probe(struct platform_device *devptr)
884{
885 int err;
886 struct snd_card *card;
887 struct sa11xx_uda1341 *chip;
888
889
890 card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct sa11xx_uda1341));
891 if (card == NULL)
892 return -ENOMEM;
893
894 chip = card->private_data;
895 spin_lock_init(&chip->s[0].dma_lock);
896 spin_lock_init(&chip->s[1].dma_lock);
897
898 card->private_free = snd_sa11xx_uda1341_free;
899 chip->card = card;
900 chip->samplerate = AUDIO_RATE_DEFAULT;
901
902
903 if ((err = snd_chip_uda1341_mixer_new(card, &chip->uda1341)))
904 goto nodev;
905
906
907 if ((err = snd_card_sa11xx_uda1341_pcm(chip, 0)) < 0)
908 goto nodev;
909
910 strcpy(card->driver, "UDA1341");
911 strcpy(card->shortname, "H3600 UDA1341TS");
912 sprintf(card->longname, "Compaq iPAQ H3600 with Philips UDA1341TS");
913
914 snd_card_set_dev(card, &devptr->dev);
915
916 if ((err = snd_card_register(card)) == 0) {
917 printk( KERN_INFO "iPAQ audio support initialized\n" );
918 platform_set_drvdata(devptr, card);
919 return 0;
920 }
921
922 nodev:
923 snd_card_free(card);
924 return err;
925}
926
927static int __devexit sa11xx_uda1341_remove(struct platform_device *devptr)
928{
929 snd_card_free(platform_get_drvdata(devptr));
930 platform_set_drvdata(devptr, NULL);
931 return 0;
932}
933
934#define SA11XX_UDA1341_DRIVER "sa11xx_uda1341"
935
936static struct platform_driver sa11xx_uda1341_driver = {
937 .probe = sa11xx_uda1341_probe,
938 .remove = __devexit_p(sa11xx_uda1341_remove),
939#ifdef CONFIG_PM
940 .suspend = snd_sa11xx_uda1341_suspend,
941 .resume = snd_sa11xx_uda1341_resume,
942#endif
943 .driver = {
944 .name = SA11XX_UDA1341_DRIVER,
945 },
946};
947
948static int __init sa11xx_uda1341_init(void)
949{
950 int err;
951
952 if (!machine_is_h3xxx())
953 return -ENODEV;
954 if ((err = platform_driver_register(&sa11xx_uda1341_driver)) < 0)
955 return err;
956 device = platform_device_register_simple(SA11XX_UDA1341_DRIVER, -1, NULL, 0);
957 if (!IS_ERR(device)) {
958 if (platform_get_drvdata(device))
959 return 0;
960 platform_device_unregister(device);
961 err = -ENODEV;
962 } else
963 err = PTR_ERR(device);
964 platform_driver_unregister(&sa11xx_uda1341_driver);
965 return err;
966}
967
968static void __exit sa11xx_uda1341_exit(void)
969{
970 platform_device_unregister(device);
971 platform_driver_unregister(&sa11xx_uda1341_driver);
972}
973
974module_init(sa11xx_uda1341_init);
975module_exit(sa11xx_uda1341_exit);
976
977
978
979
980
981
982
983
984