3 * ALSA driver for the digigram lx6464es interface
5 * Copyright (c) 2008, 2009 Tim Blechmann <tim@klingt.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/pci.h>
28 #include <linux/delay.h>
30 #include <sound/initval.h>
31 #include <sound/control.h>
32 #include <sound/info.h>
36 MODULE_AUTHOR("Tim Blechmann");
37 MODULE_LICENSE("GPL");
38 MODULE_DESCRIPTION("digigram lx6464es");
39 MODULE_SUPPORTED_DEVICE("{digigram lx6464es{}}");
42 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
43 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
44 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
46 module_param_array(index, int, NULL, 0444);
47 MODULE_PARM_DESC(index, "Index value for Digigram LX6464ES interface.");
48 module_param_array(id, charp, NULL, 0444);
49 MODULE_PARM_DESC(id, "ID string for Digigram LX6464ES interface.");
50 module_param_array(enable, bool, NULL, 0444);
51 MODULE_PARM_DESC(enable, "Enable/disable specific Digigram LX6464ES soundcards.");
53 static const char card_name[] = "LX6464ES";
56 #define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
58 static struct pci_device_id snd_lx6464es_ids[] = {
59 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
60 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
61 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM
63 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
64 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
65 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM
70 MODULE_DEVICE_TABLE(pci, snd_lx6464es_ids);
74 /* PGO pour USERo dans le registre pci_0x06/loc_0xEC */
75 #define CHIPSC_RESET_XILINX (1L<<16)
79 static struct snd_pcm_hardware lx_caps = {
80 .info = (SNDRV_PCM_INFO_MMAP |
81 SNDRV_PCM_INFO_INTERLEAVED |
82 SNDRV_PCM_INFO_MMAP_VALID |
83 SNDRV_PCM_INFO_SYNC_START),
84 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
85 SNDRV_PCM_FMTBIT_S16_BE |
86 SNDRV_PCM_FMTBIT_S24_3LE |
87 SNDRV_PCM_FMTBIT_S24_3BE),
88 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
89 SNDRV_PCM_RATE_8000_192000),
94 .buffer_bytes_max = 64*2*3*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER,
95 .period_bytes_min = (2*2*MICROBLAZE_IBL_MIN*2),
96 .period_bytes_max = (4*64*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER),
98 .periods_max = MAX_STREAM_BUFFER,
101 static int lx_set_granularity(struct lx6464es *chip, u32 gran);
104 static int lx_hardware_open(struct lx6464es *chip,
105 struct snd_pcm_substream *substream)
108 struct snd_pcm_runtime *runtime = substream->runtime;
109 int channels = runtime->channels;
110 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
112 snd_pcm_uframes_t period_size = runtime->period_size;
114 snd_printd(LXP "allocating pipe for %d channels\n", channels);
115 err = lx_pipe_allocate(chip, 0, is_capture, channels);
117 snd_printk(KERN_ERR LXP "allocating pipe failed\n");
121 err = lx_set_granularity(chip, period_size);
123 snd_printk(KERN_ERR LXP "setting granularity to %ld failed\n",
131 static int lx_hardware_start(struct lx6464es *chip,
132 struct snd_pcm_substream *substream)
135 struct snd_pcm_runtime *runtime = substream->runtime;
136 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
138 snd_printd(LXP "setting stream format\n");
139 err = lx_stream_set_format(chip, runtime, 0, is_capture);
141 snd_printk(KERN_ERR LXP "setting stream format failed\n");
145 snd_printd(LXP "starting pipe\n");
146 err = lx_pipe_start(chip, 0, is_capture);
148 snd_printk(KERN_ERR LXP "starting pipe failed\n");
152 snd_printd(LXP "waiting for pipe to start\n");
153 err = lx_pipe_wait_for_start(chip, 0, is_capture);
155 snd_printk(KERN_ERR LXP "waiting for pipe failed\n");
163 static int lx_hardware_stop(struct lx6464es *chip,
164 struct snd_pcm_substream *substream)
167 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
169 snd_printd(LXP "pausing pipe\n");
170 err = lx_pipe_pause(chip, 0, is_capture);
172 snd_printk(KERN_ERR LXP "pausing pipe failed\n");
176 snd_printd(LXP "waiting for pipe to become idle\n");
177 err = lx_pipe_wait_for_idle(chip, 0, is_capture);
179 snd_printk(KERN_ERR LXP "waiting for pipe failed\n");
183 snd_printd(LXP "stopping pipe\n");
184 err = lx_pipe_stop(chip, 0, is_capture);
186 snd_printk(LXP "stopping pipe failed\n");
194 static int lx_hardware_close(struct lx6464es *chip,
195 struct snd_pcm_substream *substream)
198 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
200 snd_printd(LXP "releasing pipe\n");
201 err = lx_pipe_release(chip, 0, is_capture);
203 snd_printk(LXP "releasing pipe failed\n");
211 static int lx_pcm_open(struct snd_pcm_substream *substream)
213 struct lx6464es *chip = snd_pcm_substream_chip(substream);
214 struct snd_pcm_runtime *runtime = substream->runtime;
218 snd_printdd("->lx_pcm_open\n");
219 mutex_lock(&chip->setup_mutex);
221 /* copy the struct snd_pcm_hardware struct */
222 runtime->hw = lx_caps;
225 /* buffer-size should better be multiple of period-size */
226 err = snd_pcm_hw_constraint_integer(runtime,
227 SNDRV_PCM_HW_PARAM_PERIODS);
229 snd_printk(KERN_WARNING LXP "could not constrain periods\n");
234 /* the clock rate cannot be changed */
235 board_rate = chip->board_sample_rate;
236 err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
237 board_rate, board_rate);
240 snd_printk(KERN_WARNING LXP "could not constrain periods\n");
244 /* constrain period size */
245 err = snd_pcm_hw_constraint_minmax(runtime,
246 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
250 snd_printk(KERN_WARNING LXP
251 "could not constrain period size\n");
255 snd_pcm_hw_constraint_step(runtime, 0,
256 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
258 snd_pcm_set_sync(substream);
262 runtime->private_data = chip;
264 mutex_unlock(&chip->setup_mutex);
265 snd_printdd("<-lx_pcm_open, %d\n", err);
269 static int lx_pcm_close(struct snd_pcm_substream *substream)
272 snd_printdd("->lx_pcm_close\n");
276 static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream
279 struct lx6464es *chip = snd_pcm_substream_chip(substream);
280 snd_pcm_uframes_t pos;
282 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
284 struct lx_stream *lx_stream = is_capture ? &chip->capture_stream :
285 &chip->playback_stream;
287 snd_printdd("->lx_pcm_stream_pointer\n");
289 spin_lock_irqsave(&chip->lock, flags);
290 pos = lx_stream->frame_pos * substream->runtime->period_size;
291 spin_unlock_irqrestore(&chip->lock, flags);
293 snd_printdd(LXP "stream_pointer at %ld\n", pos);
297 static int lx_pcm_prepare(struct snd_pcm_substream *substream)
299 struct lx6464es *chip = snd_pcm_substream_chip(substream);
301 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
303 snd_printdd("->lx_pcm_prepare\n");
305 mutex_lock(&chip->setup_mutex);
307 if (chip->hardware_running[is_capture]) {
308 err = lx_hardware_stop(chip, substream);
310 snd_printk(KERN_ERR LXP "failed to stop hardware. "
311 "Error code %d\n", err);
315 err = lx_hardware_close(chip, substream);
317 snd_printk(KERN_ERR LXP "failed to close hardware. "
318 "Error code %d\n", err);
323 snd_printd(LXP "opening hardware\n");
324 err = lx_hardware_open(chip, substream);
326 snd_printk(KERN_ERR LXP "failed to open hardware. "
327 "Error code %d\n", err);
331 err = lx_hardware_start(chip, substream);
333 snd_printk(KERN_ERR LXP "failed to start hardware. "
334 "Error code %d\n", err);
338 chip->hardware_running[is_capture] = 1;
340 if (chip->board_sample_rate != substream->runtime->rate) {
342 chip->board_sample_rate = substream->runtime->rate;
346 mutex_unlock(&chip->setup_mutex);
350 static int lx_pcm_hw_params(struct snd_pcm_substream *substream,
351 struct snd_pcm_hw_params *hw_params, int is_capture)
353 struct lx6464es *chip = snd_pcm_substream_chip(substream);
356 snd_printdd("->lx_pcm_hw_params\n");
358 mutex_lock(&chip->setup_mutex);
361 err = snd_pcm_lib_malloc_pages(substream,
362 params_buffer_bytes(hw_params));
365 chip->capture_stream.stream = substream;
367 chip->playback_stream.stream = substream;
369 mutex_unlock(&chip->setup_mutex);
373 static int lx_pcm_hw_params_playback(struct snd_pcm_substream *substream,
374 struct snd_pcm_hw_params *hw_params)
376 return lx_pcm_hw_params(substream, hw_params, 0);
379 static int lx_pcm_hw_params_capture(struct snd_pcm_substream *substream,
380 struct snd_pcm_hw_params *hw_params)
382 return lx_pcm_hw_params(substream, hw_params, 1);
385 static int lx_pcm_hw_free(struct snd_pcm_substream *substream)
387 struct lx6464es *chip = snd_pcm_substream_chip(substream);
389 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
391 snd_printdd("->lx_pcm_hw_free\n");
392 mutex_lock(&chip->setup_mutex);
394 if (chip->hardware_running[is_capture]) {
395 err = lx_hardware_stop(chip, substream);
397 snd_printk(KERN_ERR LXP "failed to stop hardware. "
398 "Error code %d\n", err);
402 err = lx_hardware_close(chip, substream);
404 snd_printk(KERN_ERR LXP "failed to close hardware. "
405 "Error code %d\n", err);
409 chip->hardware_running[is_capture] = 0;
412 err = snd_pcm_lib_free_pages(substream);
415 chip->capture_stream.stream = 0;
417 chip->playback_stream.stream = 0;
420 mutex_unlock(&chip->setup_mutex);
424 static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
426 struct snd_pcm_substream *substream = lx_stream->stream;
427 const int is_capture = lx_stream->is_capture;
431 const u32 channels = substream->runtime->channels;
432 const u32 bytes_per_frame = channels * 3;
433 const u32 period_size = substream->runtime->period_size;
434 const u32 periods = substream->runtime->periods;
435 const u32 period_bytes = period_size * bytes_per_frame;
437 dma_addr_t buf = substream->dma_buffer.addr;
443 for (i = 0; i != periods; ++i) {
444 u32 buffer_index = 0;
446 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed,
448 snd_printdd(LXP "starting: needed %d, freed %d\n",
451 err = lx_buffer_give(chip, 0, is_capture, period_bytes,
452 lower_32_bits(buf), upper_32_bits(buf),
455 snd_printdd(LXP "starting: buffer index %x on %p (%d bytes)\n",
456 buffer_index, (void *)buf, period_bytes);
460 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
461 snd_printdd(LXP "starting: needed %d, freed %d\n", needed, freed);
463 snd_printd(LXP "starting: starting stream\n");
464 err = lx_stream_start(chip, 0, is_capture);
466 snd_printk(KERN_ERR LXP "couldn't start stream\n");
468 lx_stream->status = LX_STREAM_STATUS_RUNNING;
470 lx_stream->frame_pos = 0;
473 static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
475 const int is_capture = lx_stream->is_capture;
478 snd_printd(LXP "stopping: stopping stream\n");
479 err = lx_stream_stop(chip, 0, is_capture);
481 snd_printk(KERN_ERR LXP "couldn't stop stream\n");
483 lx_stream->status = LX_STREAM_STATUS_FREE;
487 static void lx_trigger_tasklet_dispatch_stream(struct lx6464es *chip,
488 struct lx_stream *lx_stream)
490 switch (lx_stream->status) {
491 case LX_STREAM_STATUS_SCHEDULE_RUN:
492 lx_trigger_start(chip, lx_stream);
495 case LX_STREAM_STATUS_SCHEDULE_STOP:
496 lx_trigger_stop(chip, lx_stream);
504 static void lx_trigger_tasklet(unsigned long data)
506 struct lx6464es *chip = (struct lx6464es *)data;
509 snd_printdd("->lx_trigger_tasklet\n");
511 spin_lock_irqsave(&chip->lock, flags);
512 lx_trigger_tasklet_dispatch_stream(chip, &chip->capture_stream);
513 lx_trigger_tasklet_dispatch_stream(chip, &chip->playback_stream);
514 spin_unlock_irqrestore(&chip->lock, flags);
517 static int lx_pcm_trigger_dispatch(struct lx6464es *chip,
518 struct lx_stream *lx_stream, int cmd)
523 case SNDRV_PCM_TRIGGER_START:
524 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_RUN;
527 case SNDRV_PCM_TRIGGER_STOP:
528 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_STOP;
535 tasklet_schedule(&chip->trigger_tasklet);
542 static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
544 struct lx6464es *chip = snd_pcm_substream_chip(substream);
545 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
546 struct lx_stream *stream = is_capture ? &chip->capture_stream :
547 &chip->playback_stream;
549 snd_printdd("->lx_pcm_trigger\n");
551 return lx_pcm_trigger_dispatch(chip, stream, cmd);
554 static int snd_lx6464es_free(struct lx6464es *chip)
556 snd_printdd("->snd_lx6464es_free\n");
558 lx_irq_disable(chip);
561 free_irq(chip->irq, chip);
563 iounmap(chip->port_dsp_bar);
564 ioport_unmap(chip->port_plx_remapped);
566 pci_release_regions(chip->pci);
567 pci_disable_device(chip->pci);
574 static int snd_lx6464es_dev_free(struct snd_device *device)
576 return snd_lx6464es_free(device->device_data);
579 /* reset the dsp during initialization */
580 static int __devinit lx_init_xilinx_reset(struct lx6464es *chip)
583 u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC);
585 snd_printdd("->lx_init_xilinx_reset\n");
587 /* activate reset of xilinx */
588 plx_reg &= ~CHIPSC_RESET_XILINX;
590 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
593 lx_plx_reg_write(chip, ePLX_MBOX3, 0);
596 plx_reg |= CHIPSC_RESET_XILINX;
597 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
599 /* deactivate reset of xilinx */
600 for (i = 0; i != 100; ++i) {
603 reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3);
605 snd_printd(LXP "xilinx reset done\n");
606 snd_printdd(LXP "xilinx took %d loops\n", i);
611 /* todo: add some error handling? */
614 lx_dsp_reg_write(chip, eReg_CSM, 0);
616 /* le xilinx ES peut ne pas etre encore pret, on attend. */
622 static int __devinit lx_init_xilinx_test(struct lx6464es *chip)
626 snd_printdd("->lx_init_xilinx_test\n");
628 /* TEST if we have access to Xilinx/MicroBlaze */
629 lx_dsp_reg_write(chip, eReg_CSM, 0);
631 reg = lx_dsp_reg_read(chip, eReg_CSM);
634 snd_printk(KERN_ERR LXP "Problem: Reg_CSM %x.\n", reg);
636 /* PCI9056_SPACE0_REMAP */
637 lx_plx_reg_write(chip, ePLX_PCICR, 1);
639 reg = lx_dsp_reg_read(chip, eReg_CSM);
641 snd_printk(KERN_ERR LXP "Error: Reg_CSM %x.\n", reg);
642 return -EAGAIN; /* seems to be appropriate */
646 snd_printd(LXP "Xilinx/MicroBlaze access test successful\n");
651 /* initialize ethersound */
652 static int __devinit lx_init_ethersound_config(struct lx6464es *chip)
655 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
657 /* configure 64 io channels */
658 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) |
659 (64 << IOCR_INPUTS_OFFSET) |
660 (64 << IOCR_OUTPUTS_OFFSET) |
661 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
663 snd_printdd("->lx_init_ethersound\n");
665 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
668 * write it to the card !
669 * this actually kicks the ES xilinx, the first time since poweron.
670 * the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers
671 * is not ready before this is done, and the bit 2 in Reg_CSES is set.
673 lx_dsp_reg_write(chip, eReg_CONFES, conf_es);
675 for (i = 0; i != 1000; ++i) {
676 if (lx_dsp_reg_read(chip, eReg_CSES) & 4) {
677 snd_printd(LXP "ethersound initialized after %dms\n",
679 goto ethersound_initialized;
683 snd_printk(KERN_WARNING LXP
684 "ethersound could not be initialized after %dms\n", i);
687 ethersound_initialized:
688 snd_printd(LXP "ethersound initialized\n");
692 static int __devinit lx_init_get_version_features(struct lx6464es *chip)
698 snd_printdd("->lx_init_get_version_features\n");
700 err = lx_dsp_get_version(chip, &dsp_version);
705 snd_printk(LXP "DSP version: V%02d.%02d #%d\n",
706 (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff,
709 /* later: what firmware version do we expect? */
711 /* retrieve Play/Rec features */
712 /* done here because we may have to handle alternate
716 /* init the EtherSound sample rate */
717 err = lx_dsp_get_clock_frequency(chip, &freq);
719 chip->board_sample_rate = freq;
720 snd_printd(LXP "actual clock frequency %d\n", freq);
722 snd_printk(KERN_ERR LXP "DSP corrupted \n");
729 static int lx_set_granularity(struct lx6464es *chip, u32 gran)
732 u32 snapped_gran = MICROBLAZE_IBL_MIN;
734 snd_printdd("->lx_set_granularity\n");
736 /* blocksize is a power of 2 */
737 while ((snapped_gran < gran) &&
738 (snapped_gran < MICROBLAZE_IBL_MAX)) {
742 if (snapped_gran == chip->pcm_granularity)
745 err = lx_dsp_set_granularity(chip, snapped_gran);
747 snd_printk(KERN_WARNING LXP "could not set granularity\n");
751 if (snapped_gran != gran)
752 snd_printk(LXP "snapped blocksize to %d\n", snapped_gran);
754 snd_printd(LXP "set blocksize on board %d\n", snapped_gran);
755 chip->pcm_granularity = snapped_gran;
760 /* initialize and test the xilinx dsp chip */
761 static int __devinit lx_init_dsp(struct lx6464es *chip)
767 snd_printdd("->lx_init_dsp\n");
769 snd_printd(LXP "initialize board\n");
770 err = lx_init_xilinx_reset(chip);
774 snd_printd(LXP "testing board\n");
775 err = lx_init_xilinx_test(chip);
779 snd_printd(LXP "initialize ethersound configuration\n");
780 err = lx_init_ethersound_config(chip);
786 /** \todo the mac address should be ready by not, but it isn't,
787 * so we wait for it */
788 for (i = 0; i != 1000; ++i) {
789 err = lx_dsp_get_mac(chip, mac_address);
792 if (mac_address[0] || mac_address[1] || mac_address[2] ||
793 mac_address[3] || mac_address[4] || mac_address[5])
800 snd_printd(LXP "mac address ready read after: %dms\n", i);
801 snd_printk(LXP "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
802 mac_address[0], mac_address[1], mac_address[2],
803 mac_address[3], mac_address[4], mac_address[5]);
805 err = lx_init_get_version_features(chip);
809 lx_set_granularity(chip, MICROBLAZE_IBL_DEFAULT);
811 chip->playback_mute = 0;
816 static struct snd_pcm_ops lx_ops_playback = {
818 .close = lx_pcm_close,
819 .ioctl = snd_pcm_lib_ioctl,
820 .prepare = lx_pcm_prepare,
821 .hw_params = lx_pcm_hw_params_playback,
822 .hw_free = lx_pcm_hw_free,
823 .trigger = lx_pcm_trigger,
824 .pointer = lx_pcm_stream_pointer,
827 static struct snd_pcm_ops lx_ops_capture = {
829 .close = lx_pcm_close,
830 .ioctl = snd_pcm_lib_ioctl,
831 .prepare = lx_pcm_prepare,
832 .hw_params = lx_pcm_hw_params_capture,
833 .hw_free = lx_pcm_hw_free,
834 .trigger = lx_pcm_trigger,
835 .pointer = lx_pcm_stream_pointer,
838 static int __devinit lx_pcm_create(struct lx6464es *chip)
843 u32 size = 64 * /* channels */
844 3 * /* 24 bit samples */
845 MAX_STREAM_BUFFER * /* periods */
846 MICROBLAZE_IBL_MAX * /* frames per period */
849 size = PAGE_ALIGN(size);
851 /* hardcoded device name & channel count */
852 err = snd_pcm_new(chip->card, (char *)card_name, 0,
855 pcm->private_data = chip;
857 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &lx_ops_playback);
858 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &lx_ops_capture);
861 strcpy(pcm->name, card_name);
863 err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
864 snd_dma_pci_data(chip->pci),
870 chip->capture_stream.is_capture = 1;
875 static int lx_control_playback_info(struct snd_kcontrol *kcontrol,
876 struct snd_ctl_elem_info *uinfo)
878 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
880 uinfo->value.integer.min = 0;
881 uinfo->value.integer.max = 1;
885 static int lx_control_playback_get(struct snd_kcontrol *kcontrol,
886 struct snd_ctl_elem_value *ucontrol)
888 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
889 ucontrol->value.integer.value[0] = chip->playback_mute;
893 static int lx_control_playback_put(struct snd_kcontrol *kcontrol,
894 struct snd_ctl_elem_value *ucontrol)
896 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
898 int current_value = chip->playback_mute;
900 if (current_value != ucontrol->value.integer.value[0]) {
901 lx_level_unmute(chip, 0, !current_value);
902 chip->playback_mute = !current_value;
908 static struct snd_kcontrol_new lx_control_playback_switch __devinitdata = {
909 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
910 .name = "PCM Playback Switch",
912 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
914 .info = lx_control_playback_info,
915 .get = lx_control_playback_get,
916 .put = lx_control_playback_put
921 static void lx_proc_levels_read(struct snd_info_entry *entry,
922 struct snd_info_buffer *buffer)
927 struct lx6464es *chip = entry->private_data;
929 snd_iprintf(buffer, "capture levels:\n");
930 err = lx_level_peaks(chip, 1, 64, levels);
934 for (i = 0; i != 8; ++i) {
935 for (j = 0; j != 8; ++j)
936 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
937 snd_iprintf(buffer, "\n");
940 snd_iprintf(buffer, "\nplayback levels:\n");
942 err = lx_level_peaks(chip, 0, 64, levels);
946 for (i = 0; i != 8; ++i) {
947 for (j = 0; j != 8; ++j)
948 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
949 snd_iprintf(buffer, "\n");
952 snd_iprintf(buffer, "\n");
955 static int __devinit lx_proc_create(struct snd_card *card, struct lx6464es *chip)
957 struct snd_info_entry *entry;
958 int err = snd_card_proc_new(card, "levels", &entry);
962 snd_info_set_text_ops(entry, chip, lx_proc_levels_read);
967 static int __devinit snd_lx6464es_create(struct snd_card *card,
969 struct lx6464es **rchip)
971 struct lx6464es *chip;
974 static struct snd_device_ops ops = {
975 .dev_free = snd_lx6464es_dev_free,
978 snd_printdd("->snd_lx6464es_create\n");
982 /* enable PCI device */
983 err = pci_enable_device(pci);
989 /* check if we can restrict PCI DMA transfers to 32 bits */
990 err = pci_set_dma_mask(pci, DMA_BIT_MASK(32));
992 snd_printk(KERN_ERR "architecture does not support "
993 "32bit PCI busmaster DMA\n");
994 pci_disable_device(pci);
998 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1008 /* initialize synchronization structs */
1009 spin_lock_init(&chip->lock);
1010 spin_lock_init(&chip->msg_lock);
1011 mutex_init(&chip->setup_mutex);
1012 tasklet_init(&chip->trigger_tasklet, lx_trigger_tasklet,
1013 (unsigned long)chip);
1014 tasklet_init(&chip->tasklet_capture, lx_tasklet_capture,
1015 (unsigned long)chip);
1016 tasklet_init(&chip->tasklet_playback, lx_tasklet_playback,
1017 (unsigned long)chip);
1019 /* request resources */
1020 err = pci_request_regions(pci, card_name);
1022 goto request_regions_failed;
1025 chip->port_plx = pci_resource_start(pci, 1);
1026 chip->port_plx_remapped = ioport_map(chip->port_plx,
1027 pci_resource_len(pci, 1));
1030 chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
1032 err = request_irq(pci->irq, lx_interrupt, IRQF_SHARED,
1035 snd_printk(KERN_ERR LXP "unable to grab IRQ %d\n", pci->irq);
1036 goto request_irq_failed;
1038 chip->irq = pci->irq;
1040 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1042 goto device_new_failed;
1044 err = lx_init_dsp(chip);
1046 snd_printk(KERN_ERR LXP "error during DSP initialization\n");
1050 err = lx_pcm_create(chip);
1054 err = lx_proc_create(card, chip);
1058 err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
1063 snd_card_set_dev(card, &pci->dev);
1069 free_irq(pci->irq, chip);
1072 pci_release_regions(pci);
1074 request_regions_failed:
1078 pci_disable_device(pci);
1083 static int __devinit snd_lx6464es_probe(struct pci_dev *pci,
1084 const struct pci_device_id *pci_id)
1087 struct snd_card *card;
1088 struct lx6464es *chip;
1091 snd_printdd("->snd_lx6464es_probe\n");
1093 if (dev >= SNDRV_CARDS)
1100 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1104 err = snd_lx6464es_create(card, pci, &chip);
1106 snd_printk(KERN_ERR LXP "error during snd_lx6464es_create\n");
1110 strcpy(card->driver, "lx6464es");
1111 strcpy(card->shortname, "Digigram LX6464ES");
1112 sprintf(card->longname, "%s at 0x%lx, 0x%p, irq %i",
1113 card->shortname, chip->port_plx,
1114 chip->port_dsp_bar, chip->irq);
1116 err = snd_card_register(card);
1120 snd_printdd(LXP "initialization successful\n");
1121 pci_set_drvdata(pci, card);
1126 snd_card_free(card);
1131 static void __devexit snd_lx6464es_remove(struct pci_dev *pci)
1133 snd_card_free(pci_get_drvdata(pci));
1134 pci_set_drvdata(pci, NULL);
1138 static struct pci_driver driver = {
1139 .name = "Digigram LX6464ES",
1140 .id_table = snd_lx6464es_ids,
1141 .probe = snd_lx6464es_probe,
1142 .remove = __devexit_p(snd_lx6464es_remove),
1146 /* module initialization */
1147 static int __init mod_init(void)
1149 return pci_register_driver(&driver);
1152 static void __exit mod_exit(void)
1154 pci_unregister_driver(&driver);
1157 module_init(mod_init);
1158 module_exit(mod_exit);