1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * ALSA driver for the digigram lx6464es interface
6 * Copyright (c) 2008, 2009 Tim Blechmann <tim@klingt.org>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/pci.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
15 #include <sound/initval.h>
16 #include <sound/control.h>
17 #include <sound/info.h>
21 MODULE_AUTHOR("Tim Blechmann");
22 MODULE_LICENSE("GPL");
23 MODULE_DESCRIPTION("digigram lx6464es");
25 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
26 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
27 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
29 module_param_array(index, int, NULL, 0444);
30 MODULE_PARM_DESC(index, "Index value for Digigram LX6464ES interface.");
31 module_param_array(id, charp, NULL, 0444);
32 MODULE_PARM_DESC(id, "ID string for Digigram LX6464ES interface.");
33 module_param_array(enable, bool, NULL, 0444);
34 MODULE_PARM_DESC(enable, "Enable/disable specific Digigram LX6464ES soundcards.");
36 static const char card_name[] = "LX6464ES";
39 #define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
41 static const struct pci_device_id snd_lx6464es_ids[] = {
42 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES,
43 PCI_VENDOR_ID_DIGIGRAM,
44 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM),
46 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES,
47 PCI_VENDOR_ID_DIGIGRAM,
48 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM),
50 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES,
51 PCI_VENDOR_ID_DIGIGRAM,
52 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ESE_SERIAL_SUBSYSTEM),
54 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES,
55 PCI_VENDOR_ID_DIGIGRAM,
56 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ESE_CAE_SERIAL_SUBSYSTEM),
57 }, /* LX6464ESe-CAE */
61 MODULE_DEVICE_TABLE(pci, snd_lx6464es_ids);
65 /* PGO pour USERo dans le registre pci_0x06/loc_0xEC */
66 #define CHIPSC_RESET_XILINX (1L<<16)
70 static const struct snd_pcm_hardware lx_caps = {
71 .info = (SNDRV_PCM_INFO_MMAP |
72 SNDRV_PCM_INFO_INTERLEAVED |
73 SNDRV_PCM_INFO_MMAP_VALID |
74 SNDRV_PCM_INFO_SYNC_START),
75 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
76 SNDRV_PCM_FMTBIT_S16_BE |
77 SNDRV_PCM_FMTBIT_S24_3LE |
78 SNDRV_PCM_FMTBIT_S24_3BE),
79 .rates = (SNDRV_PCM_RATE_CONTINUOUS |
80 SNDRV_PCM_RATE_8000_192000),
85 .buffer_bytes_max = 64*2*3*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER,
86 .period_bytes_min = (2*2*MICROBLAZE_IBL_MIN*2),
87 .period_bytes_max = (4*64*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER),
89 .periods_max = MAX_STREAM_BUFFER,
92 static int lx_set_granularity(struct lx6464es *chip, u32 gran);
95 static int lx_hardware_open(struct lx6464es *chip,
96 struct snd_pcm_substream *substream)
99 struct snd_pcm_runtime *runtime = substream->runtime;
100 int channels = runtime->channels;
101 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
103 snd_pcm_uframes_t period_size = runtime->period_size;
105 dev_dbg(chip->card->dev, "allocating pipe for %d channels\n", channels);
106 err = lx_pipe_allocate(chip, 0, is_capture, channels);
108 dev_err(chip->card->dev, LXP "allocating pipe failed\n");
112 err = lx_set_granularity(chip, period_size);
114 dev_err(chip->card->dev, "setting granularity to %ld failed\n",
122 static int lx_hardware_start(struct lx6464es *chip,
123 struct snd_pcm_substream *substream)
126 struct snd_pcm_runtime *runtime = substream->runtime;
127 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
129 dev_dbg(chip->card->dev, "setting stream format\n");
130 err = lx_stream_set_format(chip, runtime, 0, is_capture);
132 dev_err(chip->card->dev, "setting stream format failed\n");
136 dev_dbg(chip->card->dev, "starting pipe\n");
137 err = lx_pipe_start(chip, 0, is_capture);
139 dev_err(chip->card->dev, "starting pipe failed\n");
143 dev_dbg(chip->card->dev, "waiting for pipe to start\n");
144 err = lx_pipe_wait_for_start(chip, 0, is_capture);
146 dev_err(chip->card->dev, "waiting for pipe failed\n");
154 static int lx_hardware_stop(struct lx6464es *chip,
155 struct snd_pcm_substream *substream)
158 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
160 dev_dbg(chip->card->dev, "pausing pipe\n");
161 err = lx_pipe_pause(chip, 0, is_capture);
163 dev_err(chip->card->dev, "pausing pipe failed\n");
167 dev_dbg(chip->card->dev, "waiting for pipe to become idle\n");
168 err = lx_pipe_wait_for_idle(chip, 0, is_capture);
170 dev_err(chip->card->dev, "waiting for pipe failed\n");
174 dev_dbg(chip->card->dev, "stopping pipe\n");
175 err = lx_pipe_stop(chip, 0, is_capture);
177 dev_err(chip->card->dev, "stopping pipe failed\n");
185 static int lx_hardware_close(struct lx6464es *chip,
186 struct snd_pcm_substream *substream)
189 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
191 dev_dbg(chip->card->dev, "releasing pipe\n");
192 err = lx_pipe_release(chip, 0, is_capture);
194 dev_err(chip->card->dev, "releasing pipe failed\n");
202 static int lx_pcm_open(struct snd_pcm_substream *substream)
204 struct lx6464es *chip = snd_pcm_substream_chip(substream);
205 struct snd_pcm_runtime *runtime = substream->runtime;
209 dev_dbg(chip->card->dev, "->lx_pcm_open\n");
210 mutex_lock(&chip->setup_mutex);
212 /* copy the struct snd_pcm_hardware struct */
213 runtime->hw = lx_caps;
216 /* buffer-size should better be multiple of period-size */
217 err = snd_pcm_hw_constraint_integer(runtime,
218 SNDRV_PCM_HW_PARAM_PERIODS);
220 dev_warn(chip->card->dev, "could not constrain periods\n");
225 /* the clock rate cannot be changed */
226 board_rate = chip->board_sample_rate;
227 err = snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_RATE,
231 dev_warn(chip->card->dev, "could not constrain periods\n");
235 /* constrain period size */
236 err = snd_pcm_hw_constraint_minmax(runtime,
237 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
241 dev_warn(chip->card->dev,
242 "could not constrain period size\n");
246 snd_pcm_hw_constraint_step(runtime, 0,
247 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
249 snd_pcm_set_sync(substream);
253 runtime->private_data = chip;
255 mutex_unlock(&chip->setup_mutex);
256 dev_dbg(chip->card->dev, "<-lx_pcm_open, %d\n", err);
260 static int lx_pcm_close(struct snd_pcm_substream *substream)
262 dev_dbg(substream->pcm->card->dev, "->lx_pcm_close\n");
266 static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream
269 struct lx6464es *chip = snd_pcm_substream_chip(substream);
270 snd_pcm_uframes_t pos;
271 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
273 struct lx_stream *lx_stream = is_capture ? &chip->capture_stream :
274 &chip->playback_stream;
276 dev_dbg(chip->card->dev, "->lx_pcm_stream_pointer\n");
278 mutex_lock(&chip->lock);
279 pos = lx_stream->frame_pos * substream->runtime->period_size;
280 mutex_unlock(&chip->lock);
282 dev_dbg(chip->card->dev, "stream_pointer at %ld\n", pos);
286 static int lx_pcm_prepare(struct snd_pcm_substream *substream)
288 struct lx6464es *chip = snd_pcm_substream_chip(substream);
290 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
292 dev_dbg(chip->card->dev, "->lx_pcm_prepare\n");
294 mutex_lock(&chip->setup_mutex);
296 if (chip->hardware_running[is_capture]) {
297 err = lx_hardware_stop(chip, substream);
299 dev_err(chip->card->dev, "failed to stop hardware. "
300 "Error code %d\n", err);
304 err = lx_hardware_close(chip, substream);
306 dev_err(chip->card->dev, "failed to close hardware. "
307 "Error code %d\n", err);
312 dev_dbg(chip->card->dev, "opening hardware\n");
313 err = lx_hardware_open(chip, substream);
315 dev_err(chip->card->dev, "failed to open hardware. "
316 "Error code %d\n", err);
320 err = lx_hardware_start(chip, substream);
322 dev_err(chip->card->dev, "failed to start hardware. "
323 "Error code %d\n", err);
327 chip->hardware_running[is_capture] = 1;
329 if (chip->board_sample_rate != substream->runtime->rate) {
331 chip->board_sample_rate = substream->runtime->rate;
335 mutex_unlock(&chip->setup_mutex);
339 static int lx_pcm_hw_params(struct snd_pcm_substream *substream,
340 struct snd_pcm_hw_params *hw_params, int is_capture)
342 struct lx6464es *chip = snd_pcm_substream_chip(substream);
344 dev_dbg(chip->card->dev, "->lx_pcm_hw_params\n");
346 mutex_lock(&chip->setup_mutex);
349 chip->capture_stream.stream = substream;
351 chip->playback_stream.stream = substream;
353 mutex_unlock(&chip->setup_mutex);
357 static int lx_pcm_hw_params_playback(struct snd_pcm_substream *substream,
358 struct snd_pcm_hw_params *hw_params)
360 return lx_pcm_hw_params(substream, hw_params, 0);
363 static int lx_pcm_hw_params_capture(struct snd_pcm_substream *substream,
364 struct snd_pcm_hw_params *hw_params)
366 return lx_pcm_hw_params(substream, hw_params, 1);
369 static int lx_pcm_hw_free(struct snd_pcm_substream *substream)
371 struct lx6464es *chip = snd_pcm_substream_chip(substream);
373 int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
375 dev_dbg(chip->card->dev, "->lx_pcm_hw_free\n");
376 mutex_lock(&chip->setup_mutex);
378 if (chip->hardware_running[is_capture]) {
379 err = lx_hardware_stop(chip, substream);
381 dev_err(chip->card->dev, "failed to stop hardware. "
382 "Error code %d\n", err);
386 err = lx_hardware_close(chip, substream);
388 dev_err(chip->card->dev, "failed to close hardware. "
389 "Error code %d\n", err);
393 chip->hardware_running[is_capture] = 0;
397 chip->capture_stream.stream = NULL;
399 chip->playback_stream.stream = NULL;
402 mutex_unlock(&chip->setup_mutex);
406 static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
408 struct snd_pcm_substream *substream = lx_stream->stream;
409 const unsigned int is_capture = lx_stream->is_capture;
413 const u32 channels = substream->runtime->channels;
414 const u32 bytes_per_frame = channels * 3;
415 const u32 period_size = substream->runtime->period_size;
416 const u32 periods = substream->runtime->periods;
417 const u32 period_bytes = period_size * bytes_per_frame;
419 dma_addr_t buf = substream->dma_buffer.addr;
425 for (i = 0; i != periods; ++i) {
426 u32 buffer_index = 0;
428 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed,
430 dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n",
433 err = lx_buffer_give(chip, 0, is_capture, period_bytes,
434 lower_32_bits(buf), upper_32_bits(buf),
437 dev_dbg(chip->card->dev, "starting: buffer index %x on 0x%lx (%d bytes)\n",
438 buffer_index, (unsigned long)buf, period_bytes);
442 err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
443 dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n", needed, freed);
445 dev_dbg(chip->card->dev, "starting: starting stream\n");
446 err = lx_stream_start(chip, 0, is_capture);
448 dev_err(chip->card->dev, "couldn't start stream\n");
450 lx_stream->status = LX_STREAM_STATUS_RUNNING;
452 lx_stream->frame_pos = 0;
455 static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
457 const unsigned int is_capture = lx_stream->is_capture;
460 dev_dbg(chip->card->dev, "stopping: stopping stream\n");
461 err = lx_stream_stop(chip, 0, is_capture);
463 dev_err(chip->card->dev, "couldn't stop stream\n");
465 lx_stream->status = LX_STREAM_STATUS_FREE;
469 static void lx_trigger_dispatch_stream(struct lx6464es *chip,
470 struct lx_stream *lx_stream)
472 switch (lx_stream->status) {
473 case LX_STREAM_STATUS_SCHEDULE_RUN:
474 lx_trigger_start(chip, lx_stream);
477 case LX_STREAM_STATUS_SCHEDULE_STOP:
478 lx_trigger_stop(chip, lx_stream);
486 static int lx_pcm_trigger_dispatch(struct lx6464es *chip,
487 struct lx_stream *lx_stream, int cmd)
491 mutex_lock(&chip->lock);
493 case SNDRV_PCM_TRIGGER_START:
494 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_RUN;
497 case SNDRV_PCM_TRIGGER_STOP:
498 lx_stream->status = LX_STREAM_STATUS_SCHEDULE_STOP;
506 lx_trigger_dispatch_stream(chip, &chip->capture_stream);
507 lx_trigger_dispatch_stream(chip, &chip->playback_stream);
510 mutex_unlock(&chip->lock);
515 static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
517 struct lx6464es *chip = snd_pcm_substream_chip(substream);
518 const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
519 struct lx_stream *stream = is_capture ? &chip->capture_stream :
520 &chip->playback_stream;
522 dev_dbg(chip->card->dev, "->lx_pcm_trigger\n");
524 return lx_pcm_trigger_dispatch(chip, stream, cmd);
527 static void snd_lx6464es_free(struct snd_card *card)
529 struct lx6464es *chip = card->private_data;
531 lx_irq_disable(chip);
534 /* reset the dsp during initialization */
535 static int lx_init_xilinx_reset(struct lx6464es *chip)
538 u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC);
540 dev_dbg(chip->card->dev, "->lx_init_xilinx_reset\n");
542 /* activate reset of xilinx */
543 plx_reg &= ~CHIPSC_RESET_XILINX;
545 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
548 lx_plx_reg_write(chip, ePLX_MBOX3, 0);
551 plx_reg |= CHIPSC_RESET_XILINX;
552 lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
554 /* deactivate reset of xilinx */
555 for (i = 0; i != 100; ++i) {
558 reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3);
560 dev_dbg(chip->card->dev, "xilinx reset done\n");
561 dev_dbg(chip->card->dev, "xilinx took %d loops\n", i);
566 /* todo: add some error handling? */
569 lx_dsp_reg_write(chip, eReg_CSM, 0);
571 /* le xilinx ES peut ne pas etre encore pret, on attend. */
577 static int lx_init_xilinx_test(struct lx6464es *chip)
581 dev_dbg(chip->card->dev, "->lx_init_xilinx_test\n");
583 /* TEST if we have access to Xilinx/MicroBlaze */
584 lx_dsp_reg_write(chip, eReg_CSM, 0);
586 reg = lx_dsp_reg_read(chip, eReg_CSM);
589 dev_err(chip->card->dev, "Problem: Reg_CSM %x.\n", reg);
591 /* PCI9056_SPACE0_REMAP */
592 lx_plx_reg_write(chip, ePLX_PCICR, 1);
594 reg = lx_dsp_reg_read(chip, eReg_CSM);
596 dev_err(chip->card->dev, "Error: Reg_CSM %x.\n", reg);
597 return -EAGAIN; /* seems to be appropriate */
601 dev_dbg(chip->card->dev, "Xilinx/MicroBlaze access test successful\n");
606 /* initialize ethersound */
607 static int lx_init_ethersound_config(struct lx6464es *chip)
610 u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
612 /* configure 64 io channels */
613 u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) |
614 (64 << IOCR_INPUTS_OFFSET) |
615 (64 << IOCR_OUTPUTS_OFFSET) |
616 (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
618 dev_dbg(chip->card->dev, "->lx_init_ethersound\n");
620 chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
623 * write it to the card !
624 * this actually kicks the ES xilinx, the first time since poweron.
625 * the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers
626 * is not ready before this is done, and the bit 2 in Reg_CSES is set.
628 lx_dsp_reg_write(chip, eReg_CONFES, conf_es);
630 for (i = 0; i != 1000; ++i) {
631 if (lx_dsp_reg_read(chip, eReg_CSES) & 4) {
632 dev_dbg(chip->card->dev, "ethersound initialized after %dms\n",
634 goto ethersound_initialized;
638 dev_warn(chip->card->dev,
639 "ethersound could not be initialized after %dms\n", i);
642 ethersound_initialized:
643 dev_dbg(chip->card->dev, "ethersound initialized\n");
647 static int lx_init_get_version_features(struct lx6464es *chip)
653 dev_dbg(chip->card->dev, "->lx_init_get_version_features\n");
655 err = lx_dsp_get_version(chip, &dsp_version);
660 dev_info(chip->card->dev, "DSP version: V%02d.%02d #%d\n",
661 (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff,
664 /* later: what firmware version do we expect? */
666 /* retrieve Play/Rec features */
667 /* done here because we may have to handle alternate
671 /* init the EtherSound sample rate */
672 err = lx_dsp_get_clock_frequency(chip, &freq);
674 chip->board_sample_rate = freq;
675 dev_dbg(chip->card->dev, "actual clock frequency %d\n", freq);
677 dev_err(chip->card->dev, "DSP corrupted \n");
684 static int lx_set_granularity(struct lx6464es *chip, u32 gran)
687 u32 snapped_gran = MICROBLAZE_IBL_MIN;
689 dev_dbg(chip->card->dev, "->lx_set_granularity\n");
691 /* blocksize is a power of 2 */
692 while ((snapped_gran < gran) &&
693 (snapped_gran < MICROBLAZE_IBL_MAX)) {
697 if (snapped_gran == chip->pcm_granularity)
700 err = lx_dsp_set_granularity(chip, snapped_gran);
702 dev_warn(chip->card->dev, "could not set granularity\n");
706 if (snapped_gran != gran)
707 dev_err(chip->card->dev, "snapped blocksize to %d\n", snapped_gran);
709 dev_dbg(chip->card->dev, "set blocksize on board %d\n", snapped_gran);
710 chip->pcm_granularity = snapped_gran;
715 /* initialize and test the xilinx dsp chip */
716 static int lx_init_dsp(struct lx6464es *chip)
721 dev_dbg(chip->card->dev, "->lx_init_dsp\n");
723 dev_dbg(chip->card->dev, "initialize board\n");
724 err = lx_init_xilinx_reset(chip);
728 dev_dbg(chip->card->dev, "testing board\n");
729 err = lx_init_xilinx_test(chip);
733 dev_dbg(chip->card->dev, "initialize ethersound configuration\n");
734 err = lx_init_ethersound_config(chip);
740 /** \todo the mac address should be ready by not, but it isn't,
741 * so we wait for it */
742 for (i = 0; i != 1000; ++i) {
743 err = lx_dsp_get_mac(chip);
746 if (chip->mac_address[0] || chip->mac_address[1] || chip->mac_address[2] ||
747 chip->mac_address[3] || chip->mac_address[4] || chip->mac_address[5])
754 dev_dbg(chip->card->dev, "mac address ready read after: %dms\n", i);
755 dev_info(chip->card->dev,
756 "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
757 chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
758 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
760 err = lx_init_get_version_features(chip);
764 lx_set_granularity(chip, MICROBLAZE_IBL_DEFAULT);
766 chip->playback_mute = 0;
771 static const struct snd_pcm_ops lx_ops_playback = {
773 .close = lx_pcm_close,
774 .prepare = lx_pcm_prepare,
775 .hw_params = lx_pcm_hw_params_playback,
776 .hw_free = lx_pcm_hw_free,
777 .trigger = lx_pcm_trigger,
778 .pointer = lx_pcm_stream_pointer,
781 static const struct snd_pcm_ops lx_ops_capture = {
783 .close = lx_pcm_close,
784 .prepare = lx_pcm_prepare,
785 .hw_params = lx_pcm_hw_params_capture,
786 .hw_free = lx_pcm_hw_free,
787 .trigger = lx_pcm_trigger,
788 .pointer = lx_pcm_stream_pointer,
791 static int lx_pcm_create(struct lx6464es *chip)
796 u32 size = 64 * /* channels */
797 3 * /* 24 bit samples */
798 MAX_STREAM_BUFFER * /* periods */
799 MICROBLAZE_IBL_MAX * /* frames per period */
802 size = PAGE_ALIGN(size);
804 /* hardcoded device name & channel count */
805 err = snd_pcm_new(chip->card, (char *)card_name, 0,
810 pcm->private_data = chip;
812 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &lx_ops_playback);
813 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &lx_ops_capture);
816 pcm->nonatomic = true;
817 strcpy(pcm->name, card_name);
819 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
820 &chip->pci->dev, size, size);
823 chip->capture_stream.is_capture = 1;
828 static int lx_control_playback_info(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_info *uinfo)
831 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
833 uinfo->value.integer.min = 0;
834 uinfo->value.integer.max = 1;
838 static int lx_control_playback_get(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
841 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
842 ucontrol->value.integer.value[0] = chip->playback_mute;
846 static int lx_control_playback_put(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
849 struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
851 int current_value = chip->playback_mute;
853 if (current_value != ucontrol->value.integer.value[0]) {
854 lx_level_unmute(chip, 0, !current_value);
855 chip->playback_mute = !current_value;
861 static const struct snd_kcontrol_new lx_control_playback_switch = {
862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
863 .name = "PCM Playback Switch",
865 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
867 .info = lx_control_playback_info,
868 .get = lx_control_playback_get,
869 .put = lx_control_playback_put
874 static void lx_proc_levels_read(struct snd_info_entry *entry,
875 struct snd_info_buffer *buffer)
880 struct lx6464es *chip = entry->private_data;
882 snd_iprintf(buffer, "capture levels:\n");
883 err = lx_level_peaks(chip, 1, 64, levels);
887 for (i = 0; i != 8; ++i) {
888 for (j = 0; j != 8; ++j)
889 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
890 snd_iprintf(buffer, "\n");
893 snd_iprintf(buffer, "\nplayback levels:\n");
895 err = lx_level_peaks(chip, 0, 64, levels);
899 for (i = 0; i != 8; ++i) {
900 for (j = 0; j != 8; ++j)
901 snd_iprintf(buffer, "%08x ", levels[i*8+j]);
902 snd_iprintf(buffer, "\n");
905 snd_iprintf(buffer, "\n");
908 static int lx_proc_create(struct snd_card *card, struct lx6464es *chip)
910 return snd_card_ro_proc_new(card, "levels", chip, lx_proc_levels_read);
914 static int snd_lx6464es_create(struct snd_card *card,
917 struct lx6464es *chip = card->private_data;
920 dev_dbg(card->dev, "->snd_lx6464es_create\n");
922 /* enable PCI device */
923 err = pcim_enable_device(pci);
929 /* check if we can restrict PCI DMA transfers to 32 bits */
930 err = dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
933 "architecture does not support 32bit PCI busmaster DMA\n");
941 /* initialize synchronization structs */
942 mutex_init(&chip->lock);
943 mutex_init(&chip->msg_lock);
944 mutex_init(&chip->setup_mutex);
946 /* request resources */
947 err = pci_request_regions(pci, card_name);
952 chip->port_plx = pci_resource_start(pci, 1);
953 chip->port_plx_remapped = devm_ioport_map(&pci->dev, chip->port_plx,
954 pci_resource_len(pci, 1));
955 if (!chip->port_plx_remapped)
959 chip->port_dsp_bar = pcim_iomap(pci, 2, 0);
960 if (!chip->port_dsp_bar)
963 err = devm_request_threaded_irq(&pci->dev, pci->irq, lx_interrupt,
964 lx_threaded_irq, IRQF_SHARED,
965 KBUILD_MODNAME, chip);
967 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
970 chip->irq = pci->irq;
971 card->sync_irq = chip->irq;
972 card->private_free = snd_lx6464es_free;
974 err = lx_init_dsp(chip);
976 dev_err(card->dev, "error during DSP initialization\n");
980 err = lx_pcm_create(chip);
984 err = lx_proc_create(card, chip);
988 err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
996 static int snd_lx6464es_probe(struct pci_dev *pci,
997 const struct pci_device_id *pci_id)
1000 struct snd_card *card;
1001 struct lx6464es *chip;
1004 dev_dbg(&pci->dev, "->snd_lx6464es_probe\n");
1006 if (dev >= SNDRV_CARDS)
1013 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1014 sizeof(*chip), &card);
1017 chip = card->private_data;
1019 err = snd_lx6464es_create(card, pci);
1021 dev_err(card->dev, "error during snd_lx6464es_create\n");
1025 strcpy(card->driver, "LX6464ES");
1026 sprintf(card->id, "LX6464ES_%02X%02X%02X",
1027 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
1029 sprintf(card->shortname, "LX6464ES %02X.%02X.%02X.%02X.%02X.%02X",
1030 chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
1031 chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
1033 sprintf(card->longname, "%s at 0x%lx, 0x%p, irq %i",
1034 card->shortname, chip->port_plx,
1035 chip->port_dsp_bar, chip->irq);
1037 err = snd_card_register(card);
1041 dev_dbg(chip->card->dev, "initialization successful\n");
1042 pci_set_drvdata(pci, card);
1047 snd_card_free(card);
1051 static struct pci_driver lx6464es_driver = {
1052 .name = KBUILD_MODNAME,
1053 .id_table = snd_lx6464es_ids,
1054 .probe = snd_lx6464es_probe,
1057 module_pci_driver(lx6464es_driver);