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");
24 MODULE_SUPPORTED_DEVICE("{digigram lx6464es{}}");
27 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
28 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
29 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
31 module_param_array(index
, int, NULL
, 0444);
32 MODULE_PARM_DESC(index
, "Index value for Digigram LX6464ES interface.");
33 module_param_array(id
, charp
, NULL
, 0444);
34 MODULE_PARM_DESC(id
, "ID string for Digigram LX6464ES interface.");
35 module_param_array(enable
, bool, NULL
, 0444);
36 MODULE_PARM_DESC(enable
, "Enable/disable specific Digigram LX6464ES soundcards.");
38 static const char card_name
[] = "LX6464ES";
41 #define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
43 static const struct pci_device_id snd_lx6464es_ids
[] = {
44 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_LX6464ES
,
45 PCI_VENDOR_ID_DIGIGRAM
,
46 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM
),
48 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_LX6464ES
,
49 PCI_VENDOR_ID_DIGIGRAM
,
50 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM
),
52 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_LX6464ES
,
53 PCI_VENDOR_ID_DIGIGRAM
,
54 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ESE_SERIAL_SUBSYSTEM
),
56 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_LX6464ES
,
57 PCI_VENDOR_ID_DIGIGRAM
,
58 PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ESE_CAE_SERIAL_SUBSYSTEM
),
59 }, /* LX6464ESe-CAE */
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 const 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 dev_dbg(chip
->card
->dev
, "allocating pipe for %d channels\n", channels
);
108 err
= lx_pipe_allocate(chip
, 0, is_capture
, channels
);
110 dev_err(chip
->card
->dev
, LXP
"allocating pipe failed\n");
114 err
= lx_set_granularity(chip
, period_size
);
116 dev_err(chip
->card
->dev
, "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 dev_dbg(chip
->card
->dev
, "setting stream format\n");
132 err
= lx_stream_set_format(chip
, runtime
, 0, is_capture
);
134 dev_err(chip
->card
->dev
, "setting stream format failed\n");
138 dev_dbg(chip
->card
->dev
, "starting pipe\n");
139 err
= lx_pipe_start(chip
, 0, is_capture
);
141 dev_err(chip
->card
->dev
, "starting pipe failed\n");
145 dev_dbg(chip
->card
->dev
, "waiting for pipe to start\n");
146 err
= lx_pipe_wait_for_start(chip
, 0, is_capture
);
148 dev_err(chip
->card
->dev
, "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 dev_dbg(chip
->card
->dev
, "pausing pipe\n");
163 err
= lx_pipe_pause(chip
, 0, is_capture
);
165 dev_err(chip
->card
->dev
, "pausing pipe failed\n");
169 dev_dbg(chip
->card
->dev
, "waiting for pipe to become idle\n");
170 err
= lx_pipe_wait_for_idle(chip
, 0, is_capture
);
172 dev_err(chip
->card
->dev
, "waiting for pipe failed\n");
176 dev_dbg(chip
->card
->dev
, "stopping pipe\n");
177 err
= lx_pipe_stop(chip
, 0, is_capture
);
179 dev_err(chip
->card
->dev
, "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 dev_dbg(chip
->card
->dev
, "releasing pipe\n");
194 err
= lx_pipe_release(chip
, 0, is_capture
);
196 dev_err(chip
->card
->dev
, "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 dev_dbg(chip
->card
->dev
, "->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 dev_warn(chip
->card
->dev
, "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_single(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
233 dev_warn(chip
->card
->dev
, "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 dev_warn(chip
->card
->dev
,
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 dev_dbg(chip
->card
->dev
, "<-lx_pcm_open, %d\n", err
);
262 static int lx_pcm_close(struct snd_pcm_substream
*substream
)
264 dev_dbg(substream
->pcm
->card
->dev
, "->lx_pcm_close\n");
268 static snd_pcm_uframes_t
lx_pcm_stream_pointer(struct snd_pcm_substream
271 struct lx6464es
*chip
= snd_pcm_substream_chip(substream
);
272 snd_pcm_uframes_t pos
;
273 int is_capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
275 struct lx_stream
*lx_stream
= is_capture
? &chip
->capture_stream
:
276 &chip
->playback_stream
;
278 dev_dbg(chip
->card
->dev
, "->lx_pcm_stream_pointer\n");
280 mutex_lock(&chip
->lock
);
281 pos
= lx_stream
->frame_pos
* substream
->runtime
->period_size
;
282 mutex_unlock(&chip
->lock
);
284 dev_dbg(chip
->card
->dev
, "stream_pointer at %ld\n", pos
);
288 static int lx_pcm_prepare(struct snd_pcm_substream
*substream
)
290 struct lx6464es
*chip
= snd_pcm_substream_chip(substream
);
292 const int is_capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
294 dev_dbg(chip
->card
->dev
, "->lx_pcm_prepare\n");
296 mutex_lock(&chip
->setup_mutex
);
298 if (chip
->hardware_running
[is_capture
]) {
299 err
= lx_hardware_stop(chip
, substream
);
301 dev_err(chip
->card
->dev
, "failed to stop hardware. "
302 "Error code %d\n", err
);
306 err
= lx_hardware_close(chip
, substream
);
308 dev_err(chip
->card
->dev
, "failed to close hardware. "
309 "Error code %d\n", err
);
314 dev_dbg(chip
->card
->dev
, "opening hardware\n");
315 err
= lx_hardware_open(chip
, substream
);
317 dev_err(chip
->card
->dev
, "failed to open hardware. "
318 "Error code %d\n", err
);
322 err
= lx_hardware_start(chip
, substream
);
324 dev_err(chip
->card
->dev
, "failed to start hardware. "
325 "Error code %d\n", err
);
329 chip
->hardware_running
[is_capture
] = 1;
331 if (chip
->board_sample_rate
!= substream
->runtime
->rate
) {
333 chip
->board_sample_rate
= substream
->runtime
->rate
;
337 mutex_unlock(&chip
->setup_mutex
);
341 static int lx_pcm_hw_params(struct snd_pcm_substream
*substream
,
342 struct snd_pcm_hw_params
*hw_params
, int is_capture
)
344 struct lx6464es
*chip
= snd_pcm_substream_chip(substream
);
346 dev_dbg(chip
->card
->dev
, "->lx_pcm_hw_params\n");
348 mutex_lock(&chip
->setup_mutex
);
351 chip
->capture_stream
.stream
= substream
;
353 chip
->playback_stream
.stream
= substream
;
355 mutex_unlock(&chip
->setup_mutex
);
359 static int lx_pcm_hw_params_playback(struct snd_pcm_substream
*substream
,
360 struct snd_pcm_hw_params
*hw_params
)
362 return lx_pcm_hw_params(substream
, hw_params
, 0);
365 static int lx_pcm_hw_params_capture(struct snd_pcm_substream
*substream
,
366 struct snd_pcm_hw_params
*hw_params
)
368 return lx_pcm_hw_params(substream
, hw_params
, 1);
371 static int lx_pcm_hw_free(struct snd_pcm_substream
*substream
)
373 struct lx6464es
*chip
= snd_pcm_substream_chip(substream
);
375 int is_capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
377 dev_dbg(chip
->card
->dev
, "->lx_pcm_hw_free\n");
378 mutex_lock(&chip
->setup_mutex
);
380 if (chip
->hardware_running
[is_capture
]) {
381 err
= lx_hardware_stop(chip
, substream
);
383 dev_err(chip
->card
->dev
, "failed to stop hardware. "
384 "Error code %d\n", err
);
388 err
= lx_hardware_close(chip
, substream
);
390 dev_err(chip
->card
->dev
, "failed to close hardware. "
391 "Error code %d\n", err
);
395 chip
->hardware_running
[is_capture
] = 0;
399 chip
->capture_stream
.stream
= NULL
;
401 chip
->playback_stream
.stream
= NULL
;
404 mutex_unlock(&chip
->setup_mutex
);
408 static void lx_trigger_start(struct lx6464es
*chip
, struct lx_stream
*lx_stream
)
410 struct snd_pcm_substream
*substream
= lx_stream
->stream
;
411 const unsigned int is_capture
= lx_stream
->is_capture
;
415 const u32 channels
= substream
->runtime
->channels
;
416 const u32 bytes_per_frame
= channels
* 3;
417 const u32 period_size
= substream
->runtime
->period_size
;
418 const u32 periods
= substream
->runtime
->periods
;
419 const u32 period_bytes
= period_size
* bytes_per_frame
;
421 dma_addr_t buf
= substream
->dma_buffer
.addr
;
427 for (i
= 0; i
!= periods
; ++i
) {
428 u32 buffer_index
= 0;
430 err
= lx_buffer_ask(chip
, 0, is_capture
, &needed
, &freed
,
432 dev_dbg(chip
->card
->dev
, "starting: needed %d, freed %d\n",
435 err
= lx_buffer_give(chip
, 0, is_capture
, period_bytes
,
436 lower_32_bits(buf
), upper_32_bits(buf
),
439 dev_dbg(chip
->card
->dev
, "starting: buffer index %x on 0x%lx (%d bytes)\n",
440 buffer_index
, (unsigned long)buf
, period_bytes
);
444 err
= lx_buffer_ask(chip
, 0, is_capture
, &needed
, &freed
, size_array
);
445 dev_dbg(chip
->card
->dev
, "starting: needed %d, freed %d\n", needed
, freed
);
447 dev_dbg(chip
->card
->dev
, "starting: starting stream\n");
448 err
= lx_stream_start(chip
, 0, is_capture
);
450 dev_err(chip
->card
->dev
, "couldn't start stream\n");
452 lx_stream
->status
= LX_STREAM_STATUS_RUNNING
;
454 lx_stream
->frame_pos
= 0;
457 static void lx_trigger_stop(struct lx6464es
*chip
, struct lx_stream
*lx_stream
)
459 const unsigned int is_capture
= lx_stream
->is_capture
;
462 dev_dbg(chip
->card
->dev
, "stopping: stopping stream\n");
463 err
= lx_stream_stop(chip
, 0, is_capture
);
465 dev_err(chip
->card
->dev
, "couldn't stop stream\n");
467 lx_stream
->status
= LX_STREAM_STATUS_FREE
;
471 static void lx_trigger_dispatch_stream(struct lx6464es
*chip
,
472 struct lx_stream
*lx_stream
)
474 switch (lx_stream
->status
) {
475 case LX_STREAM_STATUS_SCHEDULE_RUN
:
476 lx_trigger_start(chip
, lx_stream
);
479 case LX_STREAM_STATUS_SCHEDULE_STOP
:
480 lx_trigger_stop(chip
, lx_stream
);
488 static int lx_pcm_trigger_dispatch(struct lx6464es
*chip
,
489 struct lx_stream
*lx_stream
, int cmd
)
493 mutex_lock(&chip
->lock
);
495 case SNDRV_PCM_TRIGGER_START
:
496 lx_stream
->status
= LX_STREAM_STATUS_SCHEDULE_RUN
;
499 case SNDRV_PCM_TRIGGER_STOP
:
500 lx_stream
->status
= LX_STREAM_STATUS_SCHEDULE_STOP
;
508 lx_trigger_dispatch_stream(chip
, &chip
->capture_stream
);
509 lx_trigger_dispatch_stream(chip
, &chip
->playback_stream
);
512 mutex_unlock(&chip
->lock
);
517 static int lx_pcm_trigger(struct snd_pcm_substream
*substream
, int cmd
)
519 struct lx6464es
*chip
= snd_pcm_substream_chip(substream
);
520 const int is_capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
521 struct lx_stream
*stream
= is_capture
? &chip
->capture_stream
:
522 &chip
->playback_stream
;
524 dev_dbg(chip
->card
->dev
, "->lx_pcm_trigger\n");
526 return lx_pcm_trigger_dispatch(chip
, stream
, cmd
);
529 static int snd_lx6464es_free(struct lx6464es
*chip
)
531 dev_dbg(chip
->card
->dev
, "->snd_lx6464es_free\n");
533 lx_irq_disable(chip
);
536 free_irq(chip
->irq
, chip
);
538 iounmap(chip
->port_dsp_bar
);
539 ioport_unmap(chip
->port_plx_remapped
);
541 pci_release_regions(chip
->pci
);
542 pci_disable_device(chip
->pci
);
549 static int snd_lx6464es_dev_free(struct snd_device
*device
)
551 return snd_lx6464es_free(device
->device_data
);
554 /* reset the dsp during initialization */
555 static int lx_init_xilinx_reset(struct lx6464es
*chip
)
558 u32 plx_reg
= lx_plx_reg_read(chip
, ePLX_CHIPSC
);
560 dev_dbg(chip
->card
->dev
, "->lx_init_xilinx_reset\n");
562 /* activate reset of xilinx */
563 plx_reg
&= ~CHIPSC_RESET_XILINX
;
565 lx_plx_reg_write(chip
, ePLX_CHIPSC
, plx_reg
);
568 lx_plx_reg_write(chip
, ePLX_MBOX3
, 0);
571 plx_reg
|= CHIPSC_RESET_XILINX
;
572 lx_plx_reg_write(chip
, ePLX_CHIPSC
, plx_reg
);
574 /* deactivate reset of xilinx */
575 for (i
= 0; i
!= 100; ++i
) {
578 reg_mbox3
= lx_plx_reg_read(chip
, ePLX_MBOX3
);
580 dev_dbg(chip
->card
->dev
, "xilinx reset done\n");
581 dev_dbg(chip
->card
->dev
, "xilinx took %d loops\n", i
);
586 /* todo: add some error handling? */
589 lx_dsp_reg_write(chip
, eReg_CSM
, 0);
591 /* le xilinx ES peut ne pas etre encore pret, on attend. */
597 static int lx_init_xilinx_test(struct lx6464es
*chip
)
601 dev_dbg(chip
->card
->dev
, "->lx_init_xilinx_test\n");
603 /* TEST if we have access to Xilinx/MicroBlaze */
604 lx_dsp_reg_write(chip
, eReg_CSM
, 0);
606 reg
= lx_dsp_reg_read(chip
, eReg_CSM
);
609 dev_err(chip
->card
->dev
, "Problem: Reg_CSM %x.\n", reg
);
611 /* PCI9056_SPACE0_REMAP */
612 lx_plx_reg_write(chip
, ePLX_PCICR
, 1);
614 reg
= lx_dsp_reg_read(chip
, eReg_CSM
);
616 dev_err(chip
->card
->dev
, "Error: Reg_CSM %x.\n", reg
);
617 return -EAGAIN
; /* seems to be appropriate */
621 dev_dbg(chip
->card
->dev
, "Xilinx/MicroBlaze access test successful\n");
626 /* initialize ethersound */
627 static int lx_init_ethersound_config(struct lx6464es
*chip
)
630 u32 orig_conf_es
= lx_dsp_reg_read(chip
, eReg_CONFES
);
632 /* configure 64 io channels */
633 u32 conf_es
= (orig_conf_es
& CONFES_READ_PART_MASK
) |
634 (64 << IOCR_INPUTS_OFFSET
) |
635 (64 << IOCR_OUTPUTS_OFFSET
) |
636 (FREQ_RATIO_SINGLE_MODE
<< FREQ_RATIO_OFFSET
);
638 dev_dbg(chip
->card
->dev
, "->lx_init_ethersound\n");
640 chip
->freq_ratio
= FREQ_RATIO_SINGLE_MODE
;
643 * write it to the card !
644 * this actually kicks the ES xilinx, the first time since poweron.
645 * the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers
646 * is not ready before this is done, and the bit 2 in Reg_CSES is set.
648 lx_dsp_reg_write(chip
, eReg_CONFES
, conf_es
);
650 for (i
= 0; i
!= 1000; ++i
) {
651 if (lx_dsp_reg_read(chip
, eReg_CSES
) & 4) {
652 dev_dbg(chip
->card
->dev
, "ethersound initialized after %dms\n",
654 goto ethersound_initialized
;
658 dev_warn(chip
->card
->dev
,
659 "ethersound could not be initialized after %dms\n", i
);
662 ethersound_initialized
:
663 dev_dbg(chip
->card
->dev
, "ethersound initialized\n");
667 static int lx_init_get_version_features(struct lx6464es
*chip
)
673 dev_dbg(chip
->card
->dev
, "->lx_init_get_version_features\n");
675 err
= lx_dsp_get_version(chip
, &dsp_version
);
680 dev_info(chip
->card
->dev
, "DSP version: V%02d.%02d #%d\n",
681 (dsp_version
>>16) & 0xff, (dsp_version
>>8) & 0xff,
684 /* later: what firmware version do we expect? */
686 /* retrieve Play/Rec features */
687 /* done here because we may have to handle alternate
691 /* init the EtherSound sample rate */
692 err
= lx_dsp_get_clock_frequency(chip
, &freq
);
694 chip
->board_sample_rate
= freq
;
695 dev_dbg(chip
->card
->dev
, "actual clock frequency %d\n", freq
);
697 dev_err(chip
->card
->dev
, "DSP corrupted \n");
704 static int lx_set_granularity(struct lx6464es
*chip
, u32 gran
)
707 u32 snapped_gran
= MICROBLAZE_IBL_MIN
;
709 dev_dbg(chip
->card
->dev
, "->lx_set_granularity\n");
711 /* blocksize is a power of 2 */
712 while ((snapped_gran
< gran
) &&
713 (snapped_gran
< MICROBLAZE_IBL_MAX
)) {
717 if (snapped_gran
== chip
->pcm_granularity
)
720 err
= lx_dsp_set_granularity(chip
, snapped_gran
);
722 dev_warn(chip
->card
->dev
, "could not set granularity\n");
726 if (snapped_gran
!= gran
)
727 dev_err(chip
->card
->dev
, "snapped blocksize to %d\n", snapped_gran
);
729 dev_dbg(chip
->card
->dev
, "set blocksize on board %d\n", snapped_gran
);
730 chip
->pcm_granularity
= snapped_gran
;
735 /* initialize and test the xilinx dsp chip */
736 static int lx_init_dsp(struct lx6464es
*chip
)
741 dev_dbg(chip
->card
->dev
, "->lx_init_dsp\n");
743 dev_dbg(chip
->card
->dev
, "initialize board\n");
744 err
= lx_init_xilinx_reset(chip
);
748 dev_dbg(chip
->card
->dev
, "testing board\n");
749 err
= lx_init_xilinx_test(chip
);
753 dev_dbg(chip
->card
->dev
, "initialize ethersound configuration\n");
754 err
= lx_init_ethersound_config(chip
);
760 /** \todo the mac address should be ready by not, but it isn't,
761 * so we wait for it */
762 for (i
= 0; i
!= 1000; ++i
) {
763 err
= lx_dsp_get_mac(chip
);
766 if (chip
->mac_address
[0] || chip
->mac_address
[1] || chip
->mac_address
[2] ||
767 chip
->mac_address
[3] || chip
->mac_address
[4] || chip
->mac_address
[5])
774 dev_dbg(chip
->card
->dev
, "mac address ready read after: %dms\n", i
);
775 dev_info(chip
->card
->dev
,
776 "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
777 chip
->mac_address
[0], chip
->mac_address
[1], chip
->mac_address
[2],
778 chip
->mac_address
[3], chip
->mac_address
[4], chip
->mac_address
[5]);
780 err
= lx_init_get_version_features(chip
);
784 lx_set_granularity(chip
, MICROBLAZE_IBL_DEFAULT
);
786 chip
->playback_mute
= 0;
791 static const struct snd_pcm_ops lx_ops_playback
= {
793 .close
= lx_pcm_close
,
794 .prepare
= lx_pcm_prepare
,
795 .hw_params
= lx_pcm_hw_params_playback
,
796 .hw_free
= lx_pcm_hw_free
,
797 .trigger
= lx_pcm_trigger
,
798 .pointer
= lx_pcm_stream_pointer
,
801 static const struct snd_pcm_ops lx_ops_capture
= {
803 .close
= lx_pcm_close
,
804 .prepare
= lx_pcm_prepare
,
805 .hw_params
= lx_pcm_hw_params_capture
,
806 .hw_free
= lx_pcm_hw_free
,
807 .trigger
= lx_pcm_trigger
,
808 .pointer
= lx_pcm_stream_pointer
,
811 static int lx_pcm_create(struct lx6464es
*chip
)
816 u32 size
= 64 * /* channels */
817 3 * /* 24 bit samples */
818 MAX_STREAM_BUFFER
* /* periods */
819 MICROBLAZE_IBL_MAX
* /* frames per period */
822 size
= PAGE_ALIGN(size
);
824 /* hardcoded device name & channel count */
825 err
= snd_pcm_new(chip
->card
, (char *)card_name
, 0,
830 pcm
->private_data
= chip
;
832 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &lx_ops_playback
);
833 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &lx_ops_capture
);
836 pcm
->nonatomic
= true;
837 strcpy(pcm
->name
, card_name
);
839 snd_pcm_set_managed_buffer_all(pcm
, SNDRV_DMA_TYPE_DEV
,
840 &chip
->pci
->dev
, size
, size
);
843 chip
->capture_stream
.is_capture
= 1;
848 static int lx_control_playback_info(struct snd_kcontrol
*kcontrol
,
849 struct snd_ctl_elem_info
*uinfo
)
851 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
853 uinfo
->value
.integer
.min
= 0;
854 uinfo
->value
.integer
.max
= 1;
858 static int lx_control_playback_get(struct snd_kcontrol
*kcontrol
,
859 struct snd_ctl_elem_value
*ucontrol
)
861 struct lx6464es
*chip
= snd_kcontrol_chip(kcontrol
);
862 ucontrol
->value
.integer
.value
[0] = chip
->playback_mute
;
866 static int lx_control_playback_put(struct snd_kcontrol
*kcontrol
,
867 struct snd_ctl_elem_value
*ucontrol
)
869 struct lx6464es
*chip
= snd_kcontrol_chip(kcontrol
);
871 int current_value
= chip
->playback_mute
;
873 if (current_value
!= ucontrol
->value
.integer
.value
[0]) {
874 lx_level_unmute(chip
, 0, !current_value
);
875 chip
->playback_mute
= !current_value
;
881 static const struct snd_kcontrol_new lx_control_playback_switch
= {
882 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
883 .name
= "PCM Playback Switch",
885 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
887 .info
= lx_control_playback_info
,
888 .get
= lx_control_playback_get
,
889 .put
= lx_control_playback_put
894 static void lx_proc_levels_read(struct snd_info_entry
*entry
,
895 struct snd_info_buffer
*buffer
)
900 struct lx6464es
*chip
= entry
->private_data
;
902 snd_iprintf(buffer
, "capture levels:\n");
903 err
= lx_level_peaks(chip
, 1, 64, levels
);
907 for (i
= 0; i
!= 8; ++i
) {
908 for (j
= 0; j
!= 8; ++j
)
909 snd_iprintf(buffer
, "%08x ", levels
[i
*8+j
]);
910 snd_iprintf(buffer
, "\n");
913 snd_iprintf(buffer
, "\nplayback levels:\n");
915 err
= lx_level_peaks(chip
, 0, 64, levels
);
919 for (i
= 0; i
!= 8; ++i
) {
920 for (j
= 0; j
!= 8; ++j
)
921 snd_iprintf(buffer
, "%08x ", levels
[i
*8+j
]);
922 snd_iprintf(buffer
, "\n");
925 snd_iprintf(buffer
, "\n");
928 static int lx_proc_create(struct snd_card
*card
, struct lx6464es
*chip
)
930 return snd_card_ro_proc_new(card
, "levels", chip
, lx_proc_levels_read
);
934 static int snd_lx6464es_create(struct snd_card
*card
,
936 struct lx6464es
**rchip
)
938 struct lx6464es
*chip
;
941 static const struct snd_device_ops ops
= {
942 .dev_free
= snd_lx6464es_dev_free
,
945 dev_dbg(card
->dev
, "->snd_lx6464es_create\n");
949 /* enable PCI device */
950 err
= pci_enable_device(pci
);
956 /* check if we can restrict PCI DMA transfers to 32 bits */
957 err
= dma_set_mask(&pci
->dev
, DMA_BIT_MASK(32));
960 "architecture does not support 32bit PCI busmaster DMA\n");
961 pci_disable_device(pci
);
965 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
975 /* initialize synchronization structs */
976 mutex_init(&chip
->lock
);
977 mutex_init(&chip
->msg_lock
);
978 mutex_init(&chip
->setup_mutex
);
980 /* request resources */
981 err
= pci_request_regions(pci
, card_name
);
983 goto request_regions_failed
;
986 chip
->port_plx
= pci_resource_start(pci
, 1);
987 chip
->port_plx_remapped
= ioport_map(chip
->port_plx
,
988 pci_resource_len(pci
, 1));
991 chip
->port_dsp_bar
= pci_ioremap_bar(pci
, 2);
992 if (!chip
->port_dsp_bar
) {
993 dev_err(card
->dev
, "cannot remap PCI memory region\n");
995 goto remap_pci_failed
;
998 err
= request_threaded_irq(pci
->irq
, lx_interrupt
, lx_threaded_irq
,
999 IRQF_SHARED
, KBUILD_MODNAME
, chip
);
1001 dev_err(card
->dev
, "unable to grab IRQ %d\n", pci
->irq
);
1002 goto request_irq_failed
;
1004 chip
->irq
= pci
->irq
;
1005 card
->sync_irq
= chip
->irq
;
1007 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
);
1009 goto device_new_failed
;
1011 err
= lx_init_dsp(chip
);
1013 dev_err(card
->dev
, "error during DSP initialization\n");
1017 err
= lx_pcm_create(chip
);
1021 err
= lx_proc_create(card
, chip
);
1025 err
= snd_ctl_add(card
, snd_ctl_new1(&lx_control_playback_switch
,
1034 free_irq(pci
->irq
, chip
);
1037 iounmap(chip
->port_dsp_bar
);
1040 pci_release_regions(pci
);
1042 request_regions_failed
:
1046 pci_disable_device(pci
);
1051 static int snd_lx6464es_probe(struct pci_dev
*pci
,
1052 const struct pci_device_id
*pci_id
)
1055 struct snd_card
*card
;
1056 struct lx6464es
*chip
;
1059 dev_dbg(&pci
->dev
, "->snd_lx6464es_probe\n");
1061 if (dev
>= SNDRV_CARDS
)
1068 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
1073 err
= snd_lx6464es_create(card
, pci
, &chip
);
1075 dev_err(card
->dev
, "error during snd_lx6464es_create\n");
1079 strcpy(card
->driver
, "LX6464ES");
1080 sprintf(card
->id
, "LX6464ES_%02X%02X%02X",
1081 chip
->mac_address
[3], chip
->mac_address
[4], chip
->mac_address
[5]);
1083 sprintf(card
->shortname
, "LX6464ES %02X.%02X.%02X.%02X.%02X.%02X",
1084 chip
->mac_address
[0], chip
->mac_address
[1], chip
->mac_address
[2],
1085 chip
->mac_address
[3], chip
->mac_address
[4], chip
->mac_address
[5]);
1087 sprintf(card
->longname
, "%s at 0x%lx, 0x%p, irq %i",
1088 card
->shortname
, chip
->port_plx
,
1089 chip
->port_dsp_bar
, chip
->irq
);
1091 err
= snd_card_register(card
);
1095 dev_dbg(chip
->card
->dev
, "initialization successful\n");
1096 pci_set_drvdata(pci
, card
);
1101 snd_card_free(card
);
1106 static void snd_lx6464es_remove(struct pci_dev
*pci
)
1108 snd_card_free(pci_get_drvdata(pci
));
1112 static struct pci_driver lx6464es_driver
= {
1113 .name
= KBUILD_MODNAME
,
1114 .id_table
= snd_lx6464es_ids
,
1115 .probe
= snd_lx6464es_probe
,
1116 .remove
= snd_lx6464es_remove
,
1119 module_pci_driver(lx6464es_driver
);