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 static const char card_name[] = "LX6464ES";
49 #define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
51 static struct pci_device_id snd_lx6464es_ids[] = {
52 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
53 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
54 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM
56 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
57 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
58 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM
63 MODULE_DEVICE_TABLE(pci, snd_lx6464es_ids);
67 /* PGO pour USERo dans le registre pci_0x06/loc_0xEC */
68 #define CHIPSC_RESET_XILINX (1L<<16)
72 static struct snd_pcm_hardware lx_caps = {
73 .info = (SNDRV_PCM_INFO_MMAP |
74 SNDRV_PCM_INFO_INTERLEAVED |
75 SNDRV_PCM_INFO_MMAP_VALID |
76 SNDRV_PCM_INFO_SYNC_START),
77 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
78 SNDRV_PCM_FMTBIT_S16_BE |
79 SNDRV_PCM_FMTBIT_S24_3LE |
80 SNDRV_PCM_FMTBIT_S24_3BE),
81 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
82 SNDRV_PCM_RATE_8000_192000),
87 .buffer_bytes_max = 64*2*3*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER,
88 .period_bytes_min = (2*2*MICROBLAZE_IBL_MIN*2),
89 .period_bytes_max = (4*64*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER),
91 .periods_max = MAX_STREAM_BUFFER,
94 static int lx_set_granularity(struct lx6464es *chip, u32 gran);
97 static int lx_hardware_open(struct lx6464es *chip,
98 struct snd_pcm_substream *substream)
101 struct snd_pcm_runtime *runtime = substream->runtime;
102 int channels = runtime->channels;
103 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
105 snd_pcm_uframes_t period_size = runtime->period_size;
107 snd_printd(LXP "allocating pipe for %d channels\n", channels);
108 err = lx_pipe_allocate(chip, 0, is_capture, channels);
110 snd_printk(KERN_ERR LXP "allocating pipe failed\n");
114 err = lx_set_granularity(chip, period_size);
116 snd_printk(KERN_ERR LXP "setting granularity to %ld failed\n",
124 static int lx_hardware_start(struct lx6464es *chip,
125 struct snd_pcm_substream *substream)
128 struct snd_pcm_runtime *runtime = substream->runtime;
129 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
131 snd_printd(LXP "setting stream format\n");
132 err = lx_stream_set_format(chip, runtime, 0, is_capture);
134 snd_printk(KERN_ERR LXP "setting stream format failed\n");
138 snd_printd(LXP "starting pipe\n");
139 err = lx_pipe_start(chip, 0, is_capture);
141 snd_printk(KERN_ERR LXP "starting pipe failed\n");
145 snd_printd(LXP "waiting for pipe to start\n");
146 err = lx_pipe_wait_for_start(chip, 0, is_capture);
148 snd_printk(KERN_ERR LXP "waiting for pipe failed\n");
156 static int lx_hardware_stop(struct lx6464es *chip,
157 struct snd_pcm_substream *substream)
160 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
162 snd_printd(LXP "pausing pipe\n");
163 err = lx_pipe_pause(chip, 0, is_capture);
165 snd_printk(KERN_ERR LXP "pausing pipe failed\n");
169 snd_printd(LXP "waiting for pipe to become idle\n");
170 err = lx_pipe_wait_for_idle(chip, 0, is_capture);
172 snd_printk(KERN_ERR LXP "waiting for pipe failed\n");
176 snd_printd(LXP "stopping pipe\n");
177 err = lx_pipe_stop(chip, 0, is_capture);
179 snd_printk(LXP "stopping pipe failed\n");
187 static int lx_hardware_close(struct lx6464es *chip,
188 struct snd_pcm_substream *substream)
191 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
193 snd_printd(LXP "releasing pipe\n");
194 err = lx_pipe_release(chip, 0, is_capture);
196 snd_printk(LXP "releasing pipe failed\n");
204 static int lx_pcm_open(struct snd_pcm_substream *substream)
206 struct lx6464es *chip = snd_pcm_substream_chip(substream);
207 struct snd_pcm_runtime *runtime = substream->runtime;
211 snd_printdd("->lx_pcm_open\n");
212 mutex_lock(&chip->setup_mutex);
214 /* copy the struct snd_pcm_hardware struct */
215 runtime->hw = lx_caps;
218 /* buffer-size should better be multiple of period-size */
219 err = snd_pcm_hw_constraint_integer(runtime,
220 SNDRV_PCM_HW_PARAM_PERIODS);
222 snd_printk(KERN_WARNING LXP "could not constrain periods\n");
227 /* the clock rate cannot be changed */
228 board_rate = chip->board_sample_rate;
229 err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
230 board_rate, board_rate);
233 snd_printk(KERN_WARNING LXP "could not constrain periods\n");
237 /* constrain period size */
238 err = snd_pcm_hw_constraint_minmax(runtime,
239 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
243 snd_printk(KERN_WARNING LXP
244 "could not constrain period size\n");
248 snd_pcm_hw_constraint_step(runtime, 0,
249 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
251 snd_pcm_set_sync(substream);
255 runtime->private_data = chip;
257 mutex_unlock(&chip->setup_mutex);
258 snd_printdd("<-lx_pcm_open, %d\n", err);
262 static int lx_pcm_close(struct snd_pcm_substream *substream)
265 snd_printdd("->lx_pcm_close\n");
269 static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream
272 struct lx6464es *chip = snd_pcm_substream_chip(substream);
273 snd_pcm_uframes_t pos;
275 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
277 struct lx_stream *lx_stream = is_capture ? &chip->capture_stream :
278 &chip->playback_stream;
280 snd_printdd("->lx_pcm_stream_pointer\n");
282 spin_lock_irqsave(&chip->lock, flags);
283 pos = lx_stream->frame_pos * substream->runtime->period_size;
284 spin_unlock_irqrestore(&chip->lock, flags);
286 snd_printdd(LXP "stream_pointer at %ld\n", pos);
290 static int lx_pcm_prepare(struct snd_pcm_substream *substream)
292 struct lx6464es *chip = snd_pcm_substream_chip(substream);
294 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
296 snd_printdd("->lx_pcm_prepare\n");
298 mutex_lock(&chip->setup_mutex);
300 if (chip->hardware_running[is_capture]) {
301 err = lx_hardware_stop(chip, substream);
303 snd_printk(KERN_ERR LXP "failed to stop hardware. "
304 "Error code %d\n", err);
308 err = lx_hardware_close(chip, substream);
310 snd_printk(KERN_ERR LXP "failed to close hardware. "
311 "Error code %d\n", err);
316 snd_printd(LXP "opening hardware\n");
317 err = lx_hardware_open(chip, substream);
319 snd_printk(KERN_ERR LXP "failed to open hardware. "
320 "Error code %d\n", err);
324 err = lx_hardware_start(chip, substream);
326 snd_printk(KERN_ERR LXP "failed to start hardware. "
327 "Error code %d\n", err);
331 chip->hardware_running[is_capture] = 1;
333 if (chip->board_sample_rate != substream->runtime->rate) {
335 chip->board_sample_rate = substream->runtime->rate;
339 mutex_unlock(&chip->setup_mutex);
343 static int lx_pcm_hw_params(struct snd_pcm_substream *substream,
344 struct snd_pcm_hw_params *hw_params, int is_capture)
346 struct lx6464es *chip = snd_pcm_substream_chip(substream);
349 snd_printdd("->lx_pcm_hw_params\n");
351 mutex_lock(&chip->setup_mutex);
354 err = snd_pcm_lib_malloc_pages(substream,
355 params_buffer_bytes(hw_params));
358 chip->capture_stream.stream = substream;
360 chip->playback_stream.stream = substream;
362 mutex_unlock(&chip->setup_mutex);
366 static int lx_pcm_hw_params_playback(struct snd_pcm_substream *substream,
367 struct snd_pcm_hw_params *hw_params)
369 return lx_pcm_hw_params(substream, hw_params, 0);
372 static int lx_pcm_hw_params_capture(struct snd_pcm_substream *substream,
373 struct snd_pcm_hw_params *hw_params)
375 return lx_pcm_hw_params(substream, hw_params, 1);
378 static int lx_pcm_hw_free(struct snd_pcm_substream *substream)
380 struct lx6464es *chip = snd_pcm_substream_chip(substream);
382 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
384 snd_printdd("->lx_pcm_hw_free\n");
385 mutex_lock(&chip->setup_mutex);
387 if (chip->hardware_running[is_capture]) {
388 err = lx_hardware_stop(chip, substream);
390 snd_printk(KERN_ERR LXP "failed to stop hardware. "
391 "Error code %d\n", err);
395 err = lx_hardware_close(chip, substream);
397 snd_printk(KERN_ERR LXP "failed to close hardware. "
398 "Error code %d\n", err);
402 chip->hardware_running[is_capture] = 0;
405 err = snd_pcm_lib_free_pages(substream);
408 chip->capture_stream.stream = 0;
410 chip->playback_stream.stream = 0;
413 mutex_unlock(&chip->setup_mutex);
417 static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
419 struct snd_pcm_substream *substream = lx_stream->stream;
420 const int is_capture = lx_stream->is_capture;
424 const u32 channels = substream->runtime->channels;
425 const u32 bytes_per_frame = channels * 3;
426 const u32 period_size = substream->runtime->period_size;
427 const u32 periods = substream->runtime->periods;
428 const u32 period_bytes = period_size * bytes_per_frame;
430 dma_addr_t buf = substream->dma_buffer.addr;
436 for (i = 0; i != periods; ++i) {
437 u32 buffer_index = 0;
439 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed,
441 snd_printdd(LXP "starting: needed %d, freed %d\n",
444 err = lx_buffer_give(chip, 0, is_capture, period_bytes,
445 lower_32_bits(buf), upper_32_bits(buf),
448 snd_printdd(LXP "starting: buffer index %x on %p (%d bytes)\n",
449 buffer_index, (void *)buf, period_bytes);
453 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
454 snd_printdd(LXP "starting: needed %d, freed %d\n", needed, freed);
456 snd_printd(LXP "starting: starting stream\n");
457 err = lx_stream_start(chip, 0, is_capture);
459 snd_printk(KERN_ERR LXP "couldn't start stream\n");
461 lx_stream->status = LX_STREAM_STATUS_RUNNING;
463 lx_stream->frame_pos = 0;
466 static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
468 const int is_capture = lx_stream->is_capture;
471 snd_printd(LXP "stopping: stopping stream\n");
472 err = lx_stream_stop(chip, 0, is_capture);
474 snd_printk(KERN_ERR LXP "couldn't stop stream\n");
476 lx_stream->status = LX_STREAM_STATUS_FREE;
480 static void lx_trigger_tasklet_dispatch_stream(struct lx6464es *chip,
481 struct lx_stream *lx_stream)
483 switch (lx_stream->status) {
484 case LX_STREAM_STATUS_SCHEDULE_RUN:
485 lx_trigger_start(chip, lx_stream);
488 case LX_STREAM_STATUS_SCHEDULE_STOP:
489 lx_trigger_stop(chip, lx_stream);
497 static void lx_trigger_tasklet(unsigned long data)
499 struct lx6464es *chip = (struct lx6464es *)data;
502 snd_printdd("->lx_trigger_tasklet\n");
504 spin_lock_irqsave(&chip->lock, flags);
505 lx_trigger_tasklet_dispatch_stream(chip, &chip->capture_stream);
506 lx_trigger_tasklet_dispatch_stream(chip, &chip->playback_stream);
507 spin_unlock_irqrestore(&chip->lock, flags);
510 static int lx_pcm_trigger_dispatch(struct lx6464es *chip,
511 struct lx_stream *lx_stream, int cmd)
516 case SNDRV_PCM_TRIGGER_START:
517 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_RUN;
520 case SNDRV_PCM_TRIGGER_STOP:
521 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_STOP;
528 tasklet_schedule(&chip->trigger_tasklet);
535 static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
537 struct lx6464es *chip = snd_pcm_substream_chip(substream);
538 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
539 struct lx_stream *stream = is_capture ? &chip->capture_stream :
540 &chip->playback_stream;
542 snd_printdd("->lx_pcm_trigger\n");
544 return lx_pcm_trigger_dispatch(chip, stream, cmd);
547 static int snd_lx6464es_free(struct lx6464es *chip)
549 snd_printdd("->snd_lx6464es_free\n");
551 lx_irq_disable(chip);
554 free_irq(chip->irq, chip);
556 iounmap(chip->port_dsp_bar);
557 ioport_unmap(chip->port_plx_remapped);
559 pci_release_regions(chip->pci);
560 pci_disable_device(chip->pci);
567 static int snd_lx6464es_dev_free(struct snd_device *device)
569 return snd_lx6464es_free(device->device_data);
572 /* reset the dsp during initialization */
573 static int __devinit lx_init_xilinx_reset(struct lx6464es *chip)
576 u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC);
578 snd_printdd("->lx_init_xilinx_reset\n");
580 /* activate reset of xilinx */
581 plx_reg &= ~CHIPSC_RESET_XILINX;
583 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
586 lx_plx_reg_write(chip, ePLX_MBOX3, 0);
589 plx_reg |= CHIPSC_RESET_XILINX;
590 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
592 /* deactivate reset of xilinx */
593 for (i = 0; i != 100; ++i) {
596 reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3);
598 snd_printd(LXP "xilinx reset done\n");
599 snd_printdd(LXP "xilinx took %d loops\n", i);
604 /* todo: add some error handling? */
607 lx_dsp_reg_write(chip, eReg_CSM, 0);
609 /* le xilinx ES peut ne pas etre encore pret, on attend. */
615 static int __devinit lx_init_xilinx_test(struct lx6464es *chip)
619 snd_printdd("->lx_init_xilinx_test\n");
621 /* TEST if we have access to Xilinx/MicroBlaze */
622 lx_dsp_reg_write(chip, eReg_CSM, 0);
624 reg = lx_dsp_reg_read(chip, eReg_CSM);
627 snd_printk(KERN_ERR LXP "Problem: Reg_CSM %x.\n", reg);
629 /* PCI9056_SPACE0_REMAP */
630 lx_plx_reg_write(chip, ePLX_PCICR, 1);
632 reg = lx_dsp_reg_read(chip, eReg_CSM);
634 snd_printk(KERN_ERR LXP "Error: Reg_CSM %x.\n", reg);
635 return -EAGAIN; /* seems to be appropriate */
639 snd_printd(LXP "Xilinx/MicroBlaze access test successful\n");
644 /* initialize ethersound */
645 static int __devinit lx_init_ethersound_config(struct lx6464es *chip)
648 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
650 u32 default_conf_es = (64 << IOCR_OUTPUTS_OFFSET) |
651 (64 << IOCR_INPUTS_OFFSET) |
652 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
654 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK)
655 | (default_conf_es & CONFES_WRITE_PART_MASK);
657 snd_printdd("->lx_init_ethersound\n");
659 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
662 * write it to the card !
663 * this actually kicks the ES xilinx, the first time since poweron.
664 * the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers
665 * is not ready before this is done, and the bit 2 in Reg_CSES is set.
667 lx_dsp_reg_write(chip, eReg_CONFES, conf_es);
669 for (i = 0; i != 1000; ++i) {
670 if (lx_dsp_reg_read(chip, eReg_CSES) & 4) {
671 snd_printd(LXP "ethersound initialized after %dms\n",
673 goto ethersound_initialized;
677 snd_printk(KERN_WARNING LXP
678 "ethersound could not be initialized after %dms\n", i);
681 ethersound_initialized:
682 snd_printd(LXP "ethersound initialized\n");
686 static int __devinit lx_init_get_version_features(struct lx6464es *chip)
692 snd_printdd("->lx_init_get_version_features\n");
694 err = lx_dsp_get_version(chip, &dsp_version);
699 snd_printk(LXP "DSP version: V%02d.%02d #%d\n",
700 (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff,
703 /* later: what firmware version do we expect? */
705 /* retrieve Play/Rec features */
706 /* done here because we may have to handle alternate
710 /* init the EtherSound sample rate */
711 err = lx_dsp_get_clock_frequency(chip, &freq);
713 chip->board_sample_rate = freq;
714 snd_printd(LXP "actual clock frequency %d\n", freq);
716 snd_printk(KERN_ERR LXP "DSP corrupted \n");
723 static int lx_set_granularity(struct lx6464es *chip, u32 gran)
726 u32 snapped_gran = MICROBLAZE_IBL_MIN;
728 snd_printdd("->lx_set_granularity\n");
730 /* blocksize is a power of 2 */
731 while ((snapped_gran < gran) &&
732 (snapped_gran < MICROBLAZE_IBL_MAX)) {
736 if (snapped_gran == chip->pcm_granularity)
739 err = lx_dsp_set_granularity(chip, snapped_gran);
741 snd_printk(KERN_WARNING LXP "could not set granularity\n");
745 if (snapped_gran != gran)
746 snd_printk(LXP "snapped blocksize to %d\n", snapped_gran);
748 snd_printd(LXP "set blocksize on board %d\n", snapped_gran);
749 chip->pcm_granularity = snapped_gran;
754 /* initialize and test the xilinx dsp chip */
755 static int __devinit lx_init_dsp(struct lx6464es *chip)
761 snd_printdd("->lx_init_dsp\n");
763 snd_printd(LXP "initialize board\n");
764 err = lx_init_xilinx_reset(chip);
768 snd_printd(LXP "testing board\n");
769 err = lx_init_xilinx_test(chip);
773 snd_printd(LXP "initialize ethersound configuration\n");
774 err = lx_init_ethersound_config(chip);
780 /** \todo the mac address should be ready by not, but it isn't,
781 * so we wait for it */
782 for (i = 0; i != 1000; ++i) {
783 err = lx_dsp_get_mac(chip, mac_address);
786 if (mac_address[0] || mac_address[1] || mac_address[2] ||
787 mac_address[3] || mac_address[4] || mac_address[5])
794 snd_printd(LXP "mac address ready read after: %dms\n", i);
795 snd_printk(LXP "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
796 mac_address[0], mac_address[1], mac_address[2],
797 mac_address[3], mac_address[4], mac_address[5]);
799 err = lx_init_get_version_features(chip);
803 lx_set_granularity(chip, MICROBLAZE_IBL_DEFAULT);
805 chip->playback_mute = 0;
810 static struct snd_pcm_ops lx_ops_playback = {
812 .close = lx_pcm_close,
813 .ioctl = snd_pcm_lib_ioctl,
814 .prepare = lx_pcm_prepare,
815 .hw_params = lx_pcm_hw_params_playback,
816 .hw_free = lx_pcm_hw_free,
817 .trigger = lx_pcm_trigger,
818 .pointer = lx_pcm_stream_pointer,
821 static struct snd_pcm_ops lx_ops_capture = {
823 .close = lx_pcm_close,
824 .ioctl = snd_pcm_lib_ioctl,
825 .prepare = lx_pcm_prepare,
826 .hw_params = lx_pcm_hw_params_capture,
827 .hw_free = lx_pcm_hw_free,
828 .trigger = lx_pcm_trigger,
829 .pointer = lx_pcm_stream_pointer,
832 static int __devinit lx_pcm_create(struct lx6464es *chip)
837 u32 size = 64 * /* channels */
838 3 * /* 24 bit samples */
839 MAX_STREAM_BUFFER * /* periods */
840 MICROBLAZE_IBL_MAX * /* frames per period */
843 size = PAGE_ALIGN(size);
845 /* hardcoded device name & channel count */
846 err = snd_pcm_new(chip->card, (char *)card_name, 0,
849 pcm->private_data = chip;
851 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &lx_ops_playback);
852 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &lx_ops_capture);
855 strcpy(pcm->name, card_name);
857 err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
858 snd_dma_pci_data(chip->pci),
864 chip->capture_stream.is_capture = 1;
869 static int lx_control_playback_info(struct snd_kcontrol *kcontrol,
870 struct snd_ctl_elem_info *uinfo)
872 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
874 uinfo->value.integer.min = 0;
875 uinfo->value.integer.max = 1;
879 static int lx_control_playback_get(struct snd_kcontrol *kcontrol,
880 struct snd_ctl_elem_value *ucontrol)
882 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
883 ucontrol->value.integer.value[0] = chip->playback_mute;
887 static int lx_control_playback_put(struct snd_kcontrol *kcontrol,
888 struct snd_ctl_elem_value *ucontrol)
890 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
892 int current_value = chip->playback_mute;
894 if (current_value != ucontrol->value.integer.value[0]) {
895 lx_level_unmute(chip, 0, !current_value);
896 chip->playback_mute = !current_value;
902 static struct snd_kcontrol_new lx_control_playback_switch __devinitdata = {
903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
904 .name = "PCM Playback Switch",
906 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
908 .info = lx_control_playback_info,
909 .get = lx_control_playback_get,
910 .put = lx_control_playback_put
915 static void lx_proc_levels_read(struct snd_info_entry *entry,
916 struct snd_info_buffer *buffer)
921 struct lx6464es *chip = entry->private_data;
923 snd_iprintf(buffer, "capture levels:\n");
924 err = lx_level_peaks(chip, 1, 64, levels);
928 for (i = 0; i != 8; ++i) {
929 for (j = 0; j != 8; ++j)
930 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
931 snd_iprintf(buffer, "\n");
934 snd_iprintf(buffer, "\nplayback levels:\n");
936 err = lx_level_peaks(chip, 0, 64, levels);
940 for (i = 0; i != 8; ++i) {
941 for (j = 0; j != 8; ++j)
942 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
943 snd_iprintf(buffer, "\n");
946 snd_iprintf(buffer, "\n");
949 static int __devinit lx_proc_create(struct snd_card *card, struct lx6464es *chip)
951 struct snd_info_entry *entry;
952 int err = snd_card_proc_new(card, "levels", &entry);
956 snd_info_set_text_ops(entry, chip, lx_proc_levels_read);
961 static int __devinit snd_lx6464es_create(struct snd_card *card,
963 struct lx6464es **rchip)
965 struct lx6464es *chip;
968 static struct snd_device_ops ops = {
969 .dev_free = snd_lx6464es_dev_free,
972 snd_printdd("->snd_lx6464es_create\n");
976 /* enable PCI device */
977 err = pci_enable_device(pci);
983 /* check if we can restrict PCI DMA transfers to 32 bits */
984 err = pci_set_dma_mask(pci, DMA_32BIT_MASK);
986 snd_printk(KERN_ERR "architecture does not support "
987 "32bit PCI busmaster DMA\n");
988 pci_disable_device(pci);
992 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1002 /* initialize synchronization structs */
1003 spin_lock_init(&chip->lock);
1004 spin_lock_init(&chip->msg_lock);
1005 mutex_init(&chip->setup_mutex);
1006 tasklet_init(&chip->trigger_tasklet, lx_trigger_tasklet,
1007 (unsigned long)chip);
1008 tasklet_init(&chip->tasklet_capture, lx_tasklet_capture,
1009 (unsigned long)chip);
1010 tasklet_init(&chip->tasklet_playback, lx_tasklet_playback,
1011 (unsigned long)chip);
1013 /* request resources */
1014 err = pci_request_regions(pci, card_name);
1016 goto request_regions_failed;
1019 chip->port_plx = pci_resource_start(pci, 1);
1020 chip->port_plx_remapped = ioport_map(chip->port_plx,
1021 pci_resource_len(pci, 1));
1024 chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
1026 err = request_irq(pci->irq, lx_interrupt, IRQF_SHARED,
1029 snd_printk(KERN_ERR LXP "unable to grab IRQ %d\n", pci->irq);
1030 goto request_irq_failed;
1032 chip->irq = pci->irq;
1034 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1036 goto device_new_failed;
1038 err = lx_init_dsp(chip);
1040 snd_printk(KERN_ERR LXP "error during DSP initialization\n");
1044 err = lx_pcm_create(chip);
1048 err = lx_proc_create(card, chip);
1052 err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
1057 snd_card_set_dev(card, &pci->dev);
1063 free_irq(pci->irq, chip);
1066 pci_release_regions(pci);
1068 request_regions_failed:
1072 pci_disable_device(pci);
1077 static int __devinit snd_lx6464es_probe(struct pci_dev *pci,
1078 const struct pci_device_id *pci_id)
1081 struct snd_card *card;
1082 struct lx6464es *chip;
1085 snd_printdd("->snd_lx6464es_probe\n");
1087 if (dev >= SNDRV_CARDS)
1094 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1098 err = snd_lx6464es_create(card, pci, &chip);
1100 snd_printk(KERN_ERR LXP "error during snd_lx6464es_create\n");
1104 strcpy(card->driver, "lx6464es");
1105 strcpy(card->shortname, "Digigram LX6464ES");
1106 sprintf(card->longname, "%s at 0x%lx, 0x%p, irq %i",
1107 card->shortname, chip->port_plx,
1108 chip->port_dsp_bar, chip->irq);
1110 err = snd_card_register(card);
1114 snd_printdd(LXP "initialization successful\n");
1115 pci_set_drvdata(pci, card);
1120 snd_card_free(card);
1125 static void __devexit snd_lx6464es_remove(struct pci_dev *pci)
1127 snd_card_free(pci_get_drvdata(pci));
1128 pci_set_drvdata(pci, NULL);
1132 static struct pci_driver driver = {
1133 .name = "Digigram LX6464ES",
1134 .id_table = snd_lx6464es_ids,
1135 .probe = snd_lx6464es_probe,
1136 .remove = __devexit_p(snd_lx6464es_remove),
1140 /* module initialization */
1141 static int __init mod_init(void)
1143 return pci_register_driver(&driver);
1146 static void __exit mod_exit(void)
1148 pci_unregister_driver(&driver);
1151 module_init(mod_init);
1152 module_exit(mod_exit);