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>
29 #include <linux/slab.h>
31 #include <sound/initval.h>
32 #include <sound/control.h>
33 #include <sound/info.h>
37 MODULE_AUTHOR("Tim Blechmann");
38 MODULE_LICENSE("GPL");
39 MODULE_DESCRIPTION("digigram lx6464es");
40 MODULE_SUPPORTED_DEVICE("{digigram lx6464es{}}");
43 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
44 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
45 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
47 module_param_array(index, int, NULL, 0444);
48 MODULE_PARM_DESC(index, "Index value for Digigram LX6464ES interface.");
49 module_param_array(id, charp, NULL, 0444);
50 MODULE_PARM_DESC(id, "ID string for Digigram LX6464ES interface.");
51 module_param_array(enable, bool, NULL, 0444);
52 MODULE_PARM_DESC(enable, "Enable/disable specific Digigram LX6464ES soundcards.");
54 static const char card_name[] = "LX6464ES";
57 #define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
59 static DEFINE_PCI_DEVICE_TABLE(snd_lx6464es_ids) = {
60 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
61 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
62 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM
64 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES),
65 .subvendor = PCI_VENDOR_ID_DIGIGRAM,
66 .subdevice = PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM
71 MODULE_DEVICE_TABLE(pci, snd_lx6464es_ids);
75 /* PGO pour USERo dans le registre pci_0x06/loc_0xEC */
76 #define CHIPSC_RESET_XILINX (1L<<16)
80 static struct snd_pcm_hardware lx_caps = {
81 .info = (SNDRV_PCM_INFO_MMAP |
82 SNDRV_PCM_INFO_INTERLEAVED |
83 SNDRV_PCM_INFO_MMAP_VALID |
84 SNDRV_PCM_INFO_SYNC_START),
85 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
86 SNDRV_PCM_FMTBIT_S16_BE |
87 SNDRV_PCM_FMTBIT_S24_3LE |
88 SNDRV_PCM_FMTBIT_S24_3BE),
89 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
90 SNDRV_PCM_RATE_8000_192000),
95 .buffer_bytes_max = 64*2*3*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER,
96 .period_bytes_min = (2*2*MICROBLAZE_IBL_MIN*2),
97 .period_bytes_max = (4*64*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER),
99 .periods_max = MAX_STREAM_BUFFER,
102 static int lx_set_granularity(struct lx6464es *chip, u32 gran);
105 static int lx_hardware_open(struct lx6464es *chip,
106 struct snd_pcm_substream *substream)
109 struct snd_pcm_runtime *runtime = substream->runtime;
110 int channels = runtime->channels;
111 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
113 snd_pcm_uframes_t period_size = runtime->period_size;
115 dev_dbg(chip->card->dev, "allocating pipe for %d channels\n", channels);
116 err = lx_pipe_allocate(chip, 0, is_capture, channels);
118 dev_err(chip->card->dev, LXP "allocating pipe failed\n");
122 err = lx_set_granularity(chip, period_size);
124 dev_err(chip->card->dev, "setting granularity to %ld failed\n",
132 static int lx_hardware_start(struct lx6464es *chip,
133 struct snd_pcm_substream *substream)
136 struct snd_pcm_runtime *runtime = substream->runtime;
137 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
139 dev_dbg(chip->card->dev, "setting stream format\n");
140 err = lx_stream_set_format(chip, runtime, 0, is_capture);
142 dev_err(chip->card->dev, "setting stream format failed\n");
146 dev_dbg(chip->card->dev, "starting pipe\n");
147 err = lx_pipe_start(chip, 0, is_capture);
149 dev_err(chip->card->dev, "starting pipe failed\n");
153 dev_dbg(chip->card->dev, "waiting for pipe to start\n");
154 err = lx_pipe_wait_for_start(chip, 0, is_capture);
156 dev_err(chip->card->dev, "waiting for pipe failed\n");
164 static int lx_hardware_stop(struct lx6464es *chip,
165 struct snd_pcm_substream *substream)
168 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
170 dev_dbg(chip->card->dev, "pausing pipe\n");
171 err = lx_pipe_pause(chip, 0, is_capture);
173 dev_err(chip->card->dev, "pausing pipe failed\n");
177 dev_dbg(chip->card->dev, "waiting for pipe to become idle\n");
178 err = lx_pipe_wait_for_idle(chip, 0, is_capture);
180 dev_err(chip->card->dev, "waiting for pipe failed\n");
184 dev_dbg(chip->card->dev, "stopping pipe\n");
185 err = lx_pipe_stop(chip, 0, is_capture);
187 dev_err(chip->card->dev, "stopping pipe failed\n");
195 static int lx_hardware_close(struct lx6464es *chip,
196 struct snd_pcm_substream *substream)
199 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
201 dev_dbg(chip->card->dev, "releasing pipe\n");
202 err = lx_pipe_release(chip, 0, is_capture);
204 dev_err(chip->card->dev, "releasing pipe failed\n");
212 static int lx_pcm_open(struct snd_pcm_substream *substream)
214 struct lx6464es *chip = snd_pcm_substream_chip(substream);
215 struct snd_pcm_runtime *runtime = substream->runtime;
219 dev_dbg(chip->card->dev, "->lx_pcm_open\n");
220 mutex_lock(&chip->setup_mutex);
222 /* copy the struct snd_pcm_hardware struct */
223 runtime->hw = lx_caps;
226 /* buffer-size should better be multiple of period-size */
227 err = snd_pcm_hw_constraint_integer(runtime,
228 SNDRV_PCM_HW_PARAM_PERIODS);
230 dev_warn(chip->card->dev, "could not constrain periods\n");
235 /* the clock rate cannot be changed */
236 board_rate = chip->board_sample_rate;
237 err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
238 board_rate, board_rate);
241 dev_warn(chip->card->dev, "could not constrain periods\n");
245 /* constrain period size */
246 err = snd_pcm_hw_constraint_minmax(runtime,
247 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
251 dev_warn(chip->card->dev,
252 "could not constrain period size\n");
256 snd_pcm_hw_constraint_step(runtime, 0,
257 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
259 snd_pcm_set_sync(substream);
263 runtime->private_data = chip;
265 mutex_unlock(&chip->setup_mutex);
266 dev_dbg(chip->card->dev, "<-lx_pcm_open, %d\n", err);
270 static int lx_pcm_close(struct snd_pcm_substream *substream)
273 dev_dbg(substream->pcm->card->dev, "->lx_pcm_close\n");
277 static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream
280 struct lx6464es *chip = snd_pcm_substream_chip(substream);
281 snd_pcm_uframes_t pos;
283 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
285 struct lx_stream *lx_stream = is_capture ? &chip->capture_stream :
286 &chip->playback_stream;
288 dev_dbg(chip->card->dev, "->lx_pcm_stream_pointer\n");
290 spin_lock_irqsave(&chip->lock, flags);
291 pos = lx_stream->frame_pos * substream->runtime->period_size;
292 spin_unlock_irqrestore(&chip->lock, flags);
294 dev_dbg(chip->card->dev, "stream_pointer at %ld\n", pos);
298 static int lx_pcm_prepare(struct snd_pcm_substream *substream)
300 struct lx6464es *chip = snd_pcm_substream_chip(substream);
302 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
304 dev_dbg(chip->card->dev, "->lx_pcm_prepare\n");
306 mutex_lock(&chip->setup_mutex);
308 if (chip->hardware_running[is_capture]) {
309 err = lx_hardware_stop(chip, substream);
311 dev_err(chip->card->dev, "failed to stop hardware. "
312 "Error code %d\n", err);
316 err = lx_hardware_close(chip, substream);
318 dev_err(chip->card->dev, "failed to close hardware. "
319 "Error code %d\n", err);
324 dev_dbg(chip->card->dev, "opening hardware\n");
325 err = lx_hardware_open(chip, substream);
327 dev_err(chip->card->dev, "failed to open hardware. "
328 "Error code %d\n", err);
332 err = lx_hardware_start(chip, substream);
334 dev_err(chip->card->dev, "failed to start hardware. "
335 "Error code %d\n", err);
339 chip->hardware_running[is_capture] = 1;
341 if (chip->board_sample_rate != substream->runtime->rate) {
343 chip->board_sample_rate = substream->runtime->rate;
347 mutex_unlock(&chip->setup_mutex);
351 static int lx_pcm_hw_params(struct snd_pcm_substream *substream,
352 struct snd_pcm_hw_params *hw_params, int is_capture)
354 struct lx6464es *chip = snd_pcm_substream_chip(substream);
357 dev_dbg(chip->card->dev, "->lx_pcm_hw_params\n");
359 mutex_lock(&chip->setup_mutex);
362 err = snd_pcm_lib_malloc_pages(substream,
363 params_buffer_bytes(hw_params));
366 chip->capture_stream.stream = substream;
368 chip->playback_stream.stream = substream;
370 mutex_unlock(&chip->setup_mutex);
374 static int lx_pcm_hw_params_playback(struct snd_pcm_substream *substream,
375 struct snd_pcm_hw_params *hw_params)
377 return lx_pcm_hw_params(substream, hw_params, 0);
380 static int lx_pcm_hw_params_capture(struct snd_pcm_substream *substream,
381 struct snd_pcm_hw_params *hw_params)
383 return lx_pcm_hw_params(substream, hw_params, 1);
386 static int lx_pcm_hw_free(struct snd_pcm_substream *substream)
388 struct lx6464es *chip = snd_pcm_substream_chip(substream);
390 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
392 dev_dbg(chip->card->dev, "->lx_pcm_hw_free\n");
393 mutex_lock(&chip->setup_mutex);
395 if (chip->hardware_running[is_capture]) {
396 err = lx_hardware_stop(chip, substream);
398 dev_err(chip->card->dev, "failed to stop hardware. "
399 "Error code %d\n", err);
403 err = lx_hardware_close(chip, substream);
405 dev_err(chip->card->dev, "failed to close hardware. "
406 "Error code %d\n", err);
410 chip->hardware_running[is_capture] = 0;
413 err = snd_pcm_lib_free_pages(substream);
416 chip->capture_stream.stream = 0;
418 chip->playback_stream.stream = 0;
421 mutex_unlock(&chip->setup_mutex);
425 static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
427 struct snd_pcm_substream *substream = lx_stream->stream;
428 const unsigned int is_capture = lx_stream->is_capture;
432 const u32 channels = substream->runtime->channels;
433 const u32 bytes_per_frame = channels * 3;
434 const u32 period_size = substream->runtime->period_size;
435 const u32 periods = substream->runtime->periods;
436 const u32 period_bytes = period_size * bytes_per_frame;
438 dma_addr_t buf = substream->dma_buffer.addr;
444 for (i = 0; i != periods; ++i) {
445 u32 buffer_index = 0;
447 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed,
449 dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n",
452 err = lx_buffer_give(chip, 0, is_capture, period_bytes,
453 lower_32_bits(buf), upper_32_bits(buf),
456 dev_dbg(chip->card->dev, "starting: buffer index %x on 0x%lx (%d bytes)\n",
457 buffer_index, (unsigned long)buf, period_bytes);
461 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
462 dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n", needed, freed);
464 dev_dbg(chip->card->dev, "starting: starting stream\n");
465 err = lx_stream_start(chip, 0, is_capture);
467 dev_err(chip->card->dev, "couldn't start stream\n");
469 lx_stream->status = LX_STREAM_STATUS_RUNNING;
471 lx_stream->frame_pos = 0;
474 static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
476 const unsigned int is_capture = lx_stream->is_capture;
479 dev_dbg(chip->card->dev, "stopping: stopping stream\n");
480 err = lx_stream_stop(chip, 0, is_capture);
482 dev_err(chip->card->dev, "couldn't stop stream\n");
484 lx_stream->status = LX_STREAM_STATUS_FREE;
488 static void lx_trigger_tasklet_dispatch_stream(struct lx6464es *chip,
489 struct lx_stream *lx_stream)
491 switch (lx_stream->status) {
492 case LX_STREAM_STATUS_SCHEDULE_RUN:
493 lx_trigger_start(chip, lx_stream);
496 case LX_STREAM_STATUS_SCHEDULE_STOP:
497 lx_trigger_stop(chip, lx_stream);
505 static void lx_trigger_tasklet(unsigned long data)
507 struct lx6464es *chip = (struct lx6464es *)data;
510 dev_dbg(chip->card->dev, "->lx_trigger_tasklet\n");
512 spin_lock_irqsave(&chip->lock, flags);
513 lx_trigger_tasklet_dispatch_stream(chip, &chip->capture_stream);
514 lx_trigger_tasklet_dispatch_stream(chip, &chip->playback_stream);
515 spin_unlock_irqrestore(&chip->lock, flags);
518 static int lx_pcm_trigger_dispatch(struct lx6464es *chip,
519 struct lx_stream *lx_stream, int cmd)
524 case SNDRV_PCM_TRIGGER_START:
525 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_RUN;
528 case SNDRV_PCM_TRIGGER_STOP:
529 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_STOP;
536 tasklet_schedule(&chip->trigger_tasklet);
543 static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
545 struct lx6464es *chip = snd_pcm_substream_chip(substream);
546 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
547 struct lx_stream *stream = is_capture ? &chip->capture_stream :
548 &chip->playback_stream;
550 dev_dbg(chip->card->dev, "->lx_pcm_trigger\n");
552 return lx_pcm_trigger_dispatch(chip, stream, cmd);
555 static int snd_lx6464es_free(struct lx6464es *chip)
557 dev_dbg(chip->card->dev, "->snd_lx6464es_free\n");
559 lx_irq_disable(chip);
562 free_irq(chip->irq, chip);
564 iounmap(chip->port_dsp_bar);
565 ioport_unmap(chip->port_plx_remapped);
567 pci_release_regions(chip->pci);
568 pci_disable_device(chip->pci);
575 static int snd_lx6464es_dev_free(struct snd_device *device)
577 return snd_lx6464es_free(device->device_data);
580 /* reset the dsp during initialization */
581 static int lx_init_xilinx_reset(struct lx6464es *chip)
584 u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC);
586 dev_dbg(chip->card->dev, "->lx_init_xilinx_reset\n");
588 /* activate reset of xilinx */
589 plx_reg &= ~CHIPSC_RESET_XILINX;
591 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
594 lx_plx_reg_write(chip, ePLX_MBOX3, 0);
597 plx_reg |= CHIPSC_RESET_XILINX;
598 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
600 /* deactivate reset of xilinx */
601 for (i = 0; i != 100; ++i) {
604 reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3);
606 dev_dbg(chip->card->dev, "xilinx reset done\n");
607 dev_dbg(chip->card->dev, "xilinx took %d loops\n", i);
612 /* todo: add some error handling? */
615 lx_dsp_reg_write(chip, eReg_CSM, 0);
617 /* le xilinx ES peut ne pas etre encore pret, on attend. */
623 static int lx_init_xilinx_test(struct lx6464es *chip)
627 dev_dbg(chip->card->dev, "->lx_init_xilinx_test\n");
629 /* TEST if we have access to Xilinx/MicroBlaze */
630 lx_dsp_reg_write(chip, eReg_CSM, 0);
632 reg = lx_dsp_reg_read(chip, eReg_CSM);
635 dev_err(chip->card->dev, "Problem: Reg_CSM %x.\n", reg);
637 /* PCI9056_SPACE0_REMAP */
638 lx_plx_reg_write(chip, ePLX_PCICR, 1);
640 reg = lx_dsp_reg_read(chip, eReg_CSM);
642 dev_err(chip->card->dev, "Error: Reg_CSM %x.\n", reg);
643 return -EAGAIN; /* seems to be appropriate */
647 dev_dbg(chip->card->dev, "Xilinx/MicroBlaze access test successful\n");
652 /* initialize ethersound */
653 static int lx_init_ethersound_config(struct lx6464es *chip)
656 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
658 /* configure 64 io channels */
659 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) |
660 (64 << IOCR_INPUTS_OFFSET) |
661 (64 << IOCR_OUTPUTS_OFFSET) |
662 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
664 dev_dbg(chip->card->dev, "->lx_init_ethersound\n");
666 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
669 * write it to the card !
670 * this actually kicks the ES xilinx, the first time since poweron.
671 * the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers
672 * is not ready before this is done, and the bit 2 in Reg_CSES is set.
674 lx_dsp_reg_write(chip, eReg_CONFES, conf_es);
676 for (i = 0; i != 1000; ++i) {
677 if (lx_dsp_reg_read(chip, eReg_CSES) & 4) {
678 dev_dbg(chip->card->dev, "ethersound initialized after %dms\n",
680 goto ethersound_initialized;
684 dev_warn(chip->card->dev,
685 "ethersound could not be initialized after %dms\n", i);
688 ethersound_initialized:
689 dev_dbg(chip->card->dev, "ethersound initialized\n");
693 static int lx_init_get_version_features(struct lx6464es *chip)
699 dev_dbg(chip->card->dev, "->lx_init_get_version_features\n");
701 err = lx_dsp_get_version(chip, &dsp_version);
706 dev_info(chip->card->dev, "DSP version: V%02d.%02d #%d\n",
707 (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff,
710 /* later: what firmware version do we expect? */
712 /* retrieve Play/Rec features */
713 /* done here because we may have to handle alternate
717 /* init the EtherSound sample rate */
718 err = lx_dsp_get_clock_frequency(chip, &freq);
720 chip->board_sample_rate = freq;
721 dev_dbg(chip->card->dev, "actual clock frequency %d\n", freq);
723 dev_err(chip->card->dev, "DSP corrupted \n");
730 static int lx_set_granularity(struct lx6464es *chip, u32 gran)
733 u32 snapped_gran = MICROBLAZE_IBL_MIN;
735 dev_dbg(chip->card->dev, "->lx_set_granularity\n");
737 /* blocksize is a power of 2 */
738 while ((snapped_gran < gran) &&
739 (snapped_gran < MICROBLAZE_IBL_MAX)) {
743 if (snapped_gran == chip->pcm_granularity)
746 err = lx_dsp_set_granularity(chip, snapped_gran);
748 dev_warn(chip->card->dev, "could not set granularity\n");
752 if (snapped_gran != gran)
753 dev_err(chip->card->dev, "snapped blocksize to %d\n", snapped_gran);
755 dev_dbg(chip->card->dev, "set blocksize on board %d\n", snapped_gran);
756 chip->pcm_granularity = snapped_gran;
761 /* initialize and test the xilinx dsp chip */
762 static int lx_init_dsp(struct lx6464es *chip)
767 dev_dbg(chip->card->dev, "->lx_init_dsp\n");
769 dev_dbg(chip->card->dev, "initialize board\n");
770 err = lx_init_xilinx_reset(chip);
774 dev_dbg(chip->card->dev, "testing board\n");
775 err = lx_init_xilinx_test(chip);
779 dev_dbg(chip->card->dev, "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);
792 if (chip->mac_address[0] || chip->mac_address[1] || chip->mac_address[2] ||
793 chip->mac_address[3] || chip->mac_address[4] || chip->mac_address[5])
800 dev_dbg(chip->card->dev, "mac address ready read after: %dms\n", i);
801 dev_info(chip->card->dev,
802 "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
803 chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
804 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
806 err = lx_init_get_version_features(chip);
810 lx_set_granularity(chip, MICROBLAZE_IBL_DEFAULT);
812 chip->playback_mute = 0;
817 static struct snd_pcm_ops lx_ops_playback = {
819 .close = lx_pcm_close,
820 .ioctl = snd_pcm_lib_ioctl,
821 .prepare = lx_pcm_prepare,
822 .hw_params = lx_pcm_hw_params_playback,
823 .hw_free = lx_pcm_hw_free,
824 .trigger = lx_pcm_trigger,
825 .pointer = lx_pcm_stream_pointer,
828 static struct snd_pcm_ops lx_ops_capture = {
830 .close = lx_pcm_close,
831 .ioctl = snd_pcm_lib_ioctl,
832 .prepare = lx_pcm_prepare,
833 .hw_params = lx_pcm_hw_params_capture,
834 .hw_free = lx_pcm_hw_free,
835 .trigger = lx_pcm_trigger,
836 .pointer = lx_pcm_stream_pointer,
839 static int lx_pcm_create(struct lx6464es *chip)
844 u32 size = 64 * /* channels */
845 3 * /* 24 bit samples */
846 MAX_STREAM_BUFFER * /* periods */
847 MICROBLAZE_IBL_MAX * /* frames per period */
850 size = PAGE_ALIGN(size);
852 /* hardcoded device name & channel count */
853 err = snd_pcm_new(chip->card, (char *)card_name, 0,
858 pcm->private_data = chip;
860 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &lx_ops_playback);
861 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &lx_ops_capture);
864 strcpy(pcm->name, card_name);
866 err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
867 snd_dma_pci_data(chip->pci),
873 chip->capture_stream.is_capture = 1;
878 static int lx_control_playback_info(struct snd_kcontrol *kcontrol,
879 struct snd_ctl_elem_info *uinfo)
881 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
883 uinfo->value.integer.min = 0;
884 uinfo->value.integer.max = 1;
888 static int lx_control_playback_get(struct snd_kcontrol *kcontrol,
889 struct snd_ctl_elem_value *ucontrol)
891 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
892 ucontrol->value.integer.value[0] = chip->playback_mute;
896 static int lx_control_playback_put(struct snd_kcontrol *kcontrol,
897 struct snd_ctl_elem_value *ucontrol)
899 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
901 int current_value = chip->playback_mute;
903 if (current_value != ucontrol->value.integer.value[0]) {
904 lx_level_unmute(chip, 0, !current_value);
905 chip->playback_mute = !current_value;
911 static struct snd_kcontrol_new lx_control_playback_switch = {
912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
913 .name = "PCM Playback Switch",
915 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
917 .info = lx_control_playback_info,
918 .get = lx_control_playback_get,
919 .put = lx_control_playback_put
924 static void lx_proc_levels_read(struct snd_info_entry *entry,
925 struct snd_info_buffer *buffer)
930 struct lx6464es *chip = entry->private_data;
932 snd_iprintf(buffer, "capture levels:\n");
933 err = lx_level_peaks(chip, 1, 64, levels);
937 for (i = 0; i != 8; ++i) {
938 for (j = 0; j != 8; ++j)
939 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
940 snd_iprintf(buffer, "\n");
943 snd_iprintf(buffer, "\nplayback levels:\n");
945 err = lx_level_peaks(chip, 0, 64, levels);
949 for (i = 0; i != 8; ++i) {
950 for (j = 0; j != 8; ++j)
951 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
952 snd_iprintf(buffer, "\n");
955 snd_iprintf(buffer, "\n");
958 static int lx_proc_create(struct snd_card *card, struct lx6464es *chip)
960 struct snd_info_entry *entry;
961 int err = snd_card_proc_new(card, "levels", &entry);
965 snd_info_set_text_ops(entry, chip, lx_proc_levels_read);
970 static int snd_lx6464es_create(struct snd_card *card,
972 struct lx6464es **rchip)
974 struct lx6464es *chip;
977 static struct snd_device_ops ops = {
978 .dev_free = snd_lx6464es_dev_free,
981 dev_dbg(card->dev, "->snd_lx6464es_create\n");
985 /* enable PCI device */
986 err = pci_enable_device(pci);
992 /* check if we can restrict PCI DMA transfers to 32 bits */
993 err = pci_set_dma_mask(pci, DMA_BIT_MASK(32));
996 "architecture does not support 32bit PCI busmaster DMA\n");
997 pci_disable_device(pci);
1001 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1011 /* initialize synchronization structs */
1012 spin_lock_init(&chip->lock);
1013 spin_lock_init(&chip->msg_lock);
1014 mutex_init(&chip->setup_mutex);
1015 tasklet_init(&chip->trigger_tasklet, lx_trigger_tasklet,
1016 (unsigned long)chip);
1017 tasklet_init(&chip->tasklet_capture, lx_tasklet_capture,
1018 (unsigned long)chip);
1019 tasklet_init(&chip->tasklet_playback, lx_tasklet_playback,
1020 (unsigned long)chip);
1022 /* request resources */
1023 err = pci_request_regions(pci, card_name);
1025 goto request_regions_failed;
1028 chip->port_plx = pci_resource_start(pci, 1);
1029 chip->port_plx_remapped = ioport_map(chip->port_plx,
1030 pci_resource_len(pci, 1));
1033 chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
1035 err = request_irq(pci->irq, lx_interrupt, IRQF_SHARED,
1036 KBUILD_MODNAME, chip);
1038 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1039 goto request_irq_failed;
1041 chip->irq = pci->irq;
1043 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1045 goto device_new_failed;
1047 err = lx_init_dsp(chip);
1049 dev_err(card->dev, "error during DSP initialization\n");
1053 err = lx_pcm_create(chip);
1057 err = lx_proc_create(card, chip);
1061 err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
1070 free_irq(pci->irq, chip);
1073 pci_release_regions(pci);
1075 request_regions_failed:
1079 pci_disable_device(pci);
1084 static int snd_lx6464es_probe(struct pci_dev *pci,
1085 const struct pci_device_id *pci_id)
1088 struct snd_card *card;
1089 struct lx6464es *chip;
1092 dev_dbg(&pci->dev, "->snd_lx6464es_probe\n");
1094 if (dev >= SNDRV_CARDS)
1101 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1106 err = snd_lx6464es_create(card, pci, &chip);
1108 dev_err(card->dev, "error during snd_lx6464es_create\n");
1112 strcpy(card->driver, "LX6464ES");
1113 sprintf(card->id, "LX6464ES_%02X%02X%02X",
1114 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
1116 sprintf(card->shortname, "LX6464ES %02X.%02X.%02X.%02X.%02X.%02X",
1117 chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
1118 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
1120 sprintf(card->longname, "%s at 0x%lx, 0x%p, irq %i",
1121 card->shortname, chip->port_plx,
1122 chip->port_dsp_bar, chip->irq);
1124 err = snd_card_register(card);
1128 dev_dbg(chip->card->dev, "initialization successful\n");
1129 pci_set_drvdata(pci, card);
1134 snd_card_free(card);
1139 static void snd_lx6464es_remove(struct pci_dev *pci)
1141 snd_card_free(pci_get_drvdata(pci));
1145 static struct pci_driver lx6464es_driver = {
1146 .name = KBUILD_MODNAME,
1147 .id_table = snd_lx6464es_ids,
1148 .probe = snd_lx6464es_probe,
1149 .remove = snd_lx6464es_remove,
1152 module_pci_driver(lx6464es_driver);