2009-03-24 19:24:35 +08:00
|
|
|
/* -*- linux-c -*- *
|
|
|
|
*
|
|
|
|
* ALSA driver for the digigram lx6464es interface
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008, 2009 Tim Blechmann <tim@klingt.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/control.h>
|
|
|
|
#include <sound/info.h>
|
|
|
|
|
|
|
|
#include "lx6464es.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Tim Blechmann");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("digigram lx6464es");
|
|
|
|
MODULE_SUPPORTED_DEVICE("{digigram lx6464es{}}");
|
|
|
|
|
|
|
|
|
|
|
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
|
|
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
2011-12-15 11:19:36 +08:00
|
|
|
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2009-06-11 22:03:34 +08:00
|
|
|
module_param_array(index, int, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(index, "Index value for Digigram LX6464ES interface.");
|
|
|
|
module_param_array(id, charp, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(id, "ID string for Digigram LX6464ES interface.");
|
|
|
|
module_param_array(enable, bool, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(enable, "Enable/disable specific Digigram LX6464ES soundcards.");
|
|
|
|
|
2009-03-24 19:24:35 +08:00
|
|
|
static const char card_name[] = "LX6464ES";
|
|
|
|
|
|
|
|
|
|
|
|
#define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056
|
|
|
|
|
2014-08-08 21:56:03 +08:00
|
|
|
static const struct pci_device_id snd_lx6464es_ids[] = {
|
2015-05-26 18:52:54 +08:00
|
|
|
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES,
|
|
|
|
PCI_VENDOR_ID_DIGIGRAM,
|
|
|
|
PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM),
|
2009-03-24 19:24:35 +08:00
|
|
|
}, /* LX6464ES */
|
2015-05-26 18:52:54 +08:00
|
|
|
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES,
|
|
|
|
PCI_VENDOR_ID_DIGIGRAM,
|
|
|
|
PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM),
|
2009-03-24 19:24:35 +08:00
|
|
|
}, /* LX6464ES-CAE */
|
|
|
|
{ 0, },
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, snd_lx6464es_ids);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* PGO pour USERo dans le registre pci_0x06/loc_0xEC */
|
|
|
|
#define CHIPSC_RESET_XILINX (1L<<16)
|
|
|
|
|
|
|
|
|
|
|
|
/* alsa callbacks */
|
2017-08-12 23:31:20 +08:00
|
|
|
static const struct snd_pcm_hardware lx_caps = {
|
2009-03-24 19:24:35 +08:00
|
|
|
.info = (SNDRV_PCM_INFO_MMAP |
|
|
|
|
SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_MMAP_VALID |
|
|
|
|
SNDRV_PCM_INFO_SYNC_START),
|
|
|
|
.formats = (SNDRV_PCM_FMTBIT_S16_LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S16_BE |
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3BE),
|
|
|
|
.rates = (SNDRV_PCM_RATE_CONTINUOUS |
|
|
|
|
SNDRV_PCM_RATE_8000_192000),
|
|
|
|
.rate_min = 8000,
|
|
|
|
.rate_max = 192000,
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 64,
|
|
|
|
.buffer_bytes_max = 64*2*3*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER,
|
|
|
|
.period_bytes_min = (2*2*MICROBLAZE_IBL_MIN*2),
|
|
|
|
.period_bytes_max = (4*64*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER),
|
|
|
|
.periods_min = 2,
|
|
|
|
.periods_max = MAX_STREAM_BUFFER,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int lx_set_granularity(struct lx6464es *chip, u32 gran);
|
|
|
|
|
|
|
|
|
|
|
|
static int lx_hardware_open(struct lx6464es *chip,
|
|
|
|
struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
int channels = runtime->channels;
|
|
|
|
int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
|
|
|
snd_pcm_uframes_t period_size = runtime->period_size;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "allocating pipe for %d channels\n", channels);
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_allocate(chip, 0, is_capture, channels);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, LXP "allocating pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lx_set_granularity(chip, period_size);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "setting granularity to %ld failed\n",
|
2009-03-24 19:24:35 +08:00
|
|
|
period_size);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_hardware_start(struct lx6464es *chip,
|
|
|
|
struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "setting stream format\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_stream_set_format(chip, runtime, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "setting stream format failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "starting pipe\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_start(chip, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "starting pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "waiting for pipe to start\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_wait_for_start(chip, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "waiting for pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lx_hardware_stop(struct lx6464es *chip,
|
|
|
|
struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "pausing pipe\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_pause(chip, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "pausing pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "waiting for pipe to become idle\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_wait_for_idle(chip, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "waiting for pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "stopping pipe\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_stop(chip, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "stopping pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lx_hardware_close(struct lx6464es *chip,
|
|
|
|
struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "releasing pipe\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_pipe_release(chip, 0, is_capture);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "releasing pipe failed\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lx_pcm_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
int err = 0;
|
|
|
|
int board_rate;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_pcm_open\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
mutex_lock(&chip->setup_mutex);
|
|
|
|
|
|
|
|
/* copy the struct snd_pcm_hardware struct */
|
|
|
|
runtime->hw = lx_caps;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* buffer-size should better be multiple of period-size */
|
|
|
|
err = snd_pcm_hw_constraint_integer(runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_warn(chip->card->dev, "could not constrain periods\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* the clock rate cannot be changed */
|
|
|
|
board_rate = chip->board_sample_rate;
|
2015-10-18 21:39:18 +08:00
|
|
|
err = snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
board_rate);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_warn(chip->card->dev, "could not constrain periods\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* constrain period size */
|
|
|
|
err = snd_pcm_hw_constraint_minmax(runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
|
|
|
|
MICROBLAZE_IBL_MIN,
|
|
|
|
MICROBLAZE_IBL_MAX);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_warn(chip->card->dev,
|
2009-03-24 19:24:35 +08:00
|
|
|
"could not constrain period size\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_pcm_hw_constraint_step(runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);
|
|
|
|
|
|
|
|
snd_pcm_set_sync(substream);
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
runtime->private_data = chip;
|
|
|
|
|
|
|
|
mutex_unlock(&chip->setup_mutex);
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "<-lx_pcm_open, %d\n", err);
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
int err = 0;
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(substream->pcm->card->dev, "->lx_pcm_close\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream
|
|
|
|
*substream)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_pcm_substream_chip(substream);
|
|
|
|
snd_pcm_uframes_t pos;
|
|
|
|
int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
|
|
|
struct lx_stream *lx_stream = is_capture ? &chip->capture_stream :
|
|
|
|
&chip->playback_stream;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_pcm_stream_pointer\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2014-09-10 20:01:05 +08:00
|
|
|
mutex_lock(&chip->lock);
|
2009-03-24 19:24:35 +08:00
|
|
|
pos = lx_stream->frame_pos * substream->runtime->period_size;
|
2014-09-10 20:01:05 +08:00
|
|
|
mutex_unlock(&chip->lock);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "stream_pointer at %ld\n", pos);
|
2009-03-24 19:24:35 +08:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_prepare(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_pcm_substream_chip(substream);
|
|
|
|
int err = 0;
|
|
|
|
const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_pcm_prepare\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
mutex_lock(&chip->setup_mutex);
|
|
|
|
|
|
|
|
if (chip->hardware_running[is_capture]) {
|
|
|
|
err = lx_hardware_stop(chip, substream);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "failed to stop hardware. "
|
2009-03-24 19:24:35 +08:00
|
|
|
"Error code %d\n", err);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lx_hardware_close(chip, substream);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "failed to close hardware. "
|
2009-03-24 19:24:35 +08:00
|
|
|
"Error code %d\n", err);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "opening hardware\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_hardware_open(chip, substream);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "failed to open hardware. "
|
2009-03-24 19:24:35 +08:00
|
|
|
"Error code %d\n", err);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lx_hardware_start(chip, substream);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "failed to start hardware. "
|
2009-03-24 19:24:35 +08:00
|
|
|
"Error code %d\n", err);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->hardware_running[is_capture] = 1;
|
|
|
|
|
|
|
|
if (chip->board_sample_rate != substream->runtime->rate) {
|
|
|
|
if (!err)
|
|
|
|
chip->board_sample_rate = substream->runtime->rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mutex_unlock(&chip->setup_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params, int is_capture)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_pcm_substream_chip(substream);
|
|
|
|
int err = 0;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_pcm_hw_params\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
mutex_lock(&chip->setup_mutex);
|
|
|
|
|
|
|
|
/* set dma buffer */
|
|
|
|
err = snd_pcm_lib_malloc_pages(substream,
|
|
|
|
params_buffer_bytes(hw_params));
|
|
|
|
|
|
|
|
if (is_capture)
|
|
|
|
chip->capture_stream.stream = substream;
|
|
|
|
else
|
|
|
|
chip->playback_stream.stream = substream;
|
|
|
|
|
|
|
|
mutex_unlock(&chip->setup_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_hw_params_playback(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
|
|
|
{
|
|
|
|
return lx_pcm_hw_params(substream, hw_params, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_hw_params_capture(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
|
|
|
{
|
|
|
|
return lx_pcm_hw_params(substream, hw_params, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_hw_free(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_pcm_substream_chip(substream);
|
|
|
|
int err = 0;
|
|
|
|
int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_pcm_hw_free\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
mutex_lock(&chip->setup_mutex);
|
|
|
|
|
|
|
|
if (chip->hardware_running[is_capture]) {
|
|
|
|
err = lx_hardware_stop(chip, substream);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "failed to stop hardware. "
|
2009-03-24 19:24:35 +08:00
|
|
|
"Error code %d\n", err);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lx_hardware_close(chip, substream);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "failed to close hardware. "
|
2009-03-24 19:24:35 +08:00
|
|
|
"Error code %d\n", err);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->hardware_running[is_capture] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_lib_free_pages(substream);
|
|
|
|
|
|
|
|
if (is_capture)
|
2015-05-26 18:56:21 +08:00
|
|
|
chip->capture_stream.stream = NULL;
|
2009-03-24 19:24:35 +08:00
|
|
|
else
|
2015-05-26 18:56:21 +08:00
|
|
|
chip->playback_stream.stream = NULL;
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mutex_unlock(&chip->setup_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream)
|
|
|
|
{
|
|
|
|
struct snd_pcm_substream *substream = lx_stream->stream;
|
2010-11-01 02:46:19 +08:00
|
|
|
const unsigned int is_capture = lx_stream->is_capture;
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
const u32 channels = substream->runtime->channels;
|
|
|
|
const u32 bytes_per_frame = channels * 3;
|
|
|
|
const u32 period_size = substream->runtime->period_size;
|
|
|
|
const u32 periods = substream->runtime->periods;
|
|
|
|
const u32 period_bytes = period_size * bytes_per_frame;
|
|
|
|
|
|
|
|
dma_addr_t buf = substream->dma_buffer.addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
u32 needed, freed;
|
|
|
|
u32 size_array[5];
|
|
|
|
|
|
|
|
for (i = 0; i != periods; ++i) {
|
|
|
|
u32 buffer_index = 0;
|
|
|
|
|
|
|
|
err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed,
|
|
|
|
size_array);
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n",
|
2009-03-24 19:24:35 +08:00
|
|
|
needed, freed);
|
|
|
|
|
|
|
|
err = lx_buffer_give(chip, 0, is_capture, period_bytes,
|
|
|
|
lower_32_bits(buf), upper_32_bits(buf),
|
|
|
|
&buffer_index);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "starting: buffer index %x on 0x%lx (%d bytes)\n",
|
2013-11-07 00:54:55 +08:00
|
|
|
buffer_index, (unsigned long)buf, period_bytes);
|
2009-03-24 19:24:35 +08:00
|
|
|
buf += period_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n", needed, freed);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "starting: starting stream\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_stream_start(chip, 0, is_capture);
|
|
|
|
if (err < 0)
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "couldn't start stream\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
else
|
|
|
|
lx_stream->status = LX_STREAM_STATUS_RUNNING;
|
|
|
|
|
|
|
|
lx_stream->frame_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream)
|
|
|
|
{
|
2010-11-01 02:46:19 +08:00
|
|
|
const unsigned int is_capture = lx_stream->is_capture;
|
2009-03-24 19:24:35 +08:00
|
|
|
int err;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "stopping: stopping stream\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_stream_stop(chip, 0, is_capture);
|
|
|
|
if (err < 0)
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "couldn't stop stream\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
else
|
|
|
|
lx_stream->status = LX_STREAM_STATUS_FREE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-10 20:01:05 +08:00
|
|
|
static void lx_trigger_dispatch_stream(struct lx6464es *chip,
|
|
|
|
struct lx_stream *lx_stream)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
switch (lx_stream->status) {
|
|
|
|
case LX_STREAM_STATUS_SCHEDULE_RUN:
|
|
|
|
lx_trigger_start(chip, lx_stream);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LX_STREAM_STATUS_SCHEDULE_STOP:
|
|
|
|
lx_trigger_stop(chip, lx_stream);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_pcm_trigger_dispatch(struct lx6464es *chip,
|
|
|
|
struct lx_stream *lx_stream, int cmd)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2014-09-10 20:01:05 +08:00
|
|
|
mutex_lock(&chip->lock);
|
2009-03-24 19:24:35 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
lx_stream->status = LX_STREAM_STATUS_SCHEDULE_RUN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
lx_stream->status = LX_STREAM_STATUS_SCHEDULE_STOP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
goto exit;
|
|
|
|
}
|
2014-09-10 20:01:05 +08:00
|
|
|
|
|
|
|
lx_trigger_dispatch_stream(chip, &chip->capture_stream);
|
|
|
|
lx_trigger_dispatch_stream(chip, &chip->playback_stream);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
exit:
|
2014-09-10 20:01:05 +08:00
|
|
|
mutex_unlock(&chip->lock);
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_pcm_substream_chip(substream);
|
|
|
|
const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
struct lx_stream *stream = is_capture ? &chip->capture_stream :
|
|
|
|
&chip->playback_stream;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_pcm_trigger\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
return lx_pcm_trigger_dispatch(chip, stream, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int snd_lx6464es_free(struct lx6464es *chip)
|
|
|
|
{
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->snd_lx6464es_free\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
lx_irq_disable(chip);
|
|
|
|
|
|
|
|
if (chip->irq >= 0)
|
|
|
|
free_irq(chip->irq, chip);
|
|
|
|
|
|
|
|
iounmap(chip->port_dsp_bar);
|
|
|
|
ioport_unmap(chip->port_plx_remapped);
|
|
|
|
|
|
|
|
pci_release_regions(chip->pci);
|
|
|
|
pci_disable_device(chip->pci);
|
|
|
|
|
|
|
|
kfree(chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int snd_lx6464es_dev_free(struct snd_device *device)
|
|
|
|
{
|
|
|
|
return snd_lx6464es_free(device->device_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the dsp during initialization */
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_init_xilinx_reset(struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_init_xilinx_reset\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
/* activate reset of xilinx */
|
|
|
|
plx_reg &= ~CHIPSC_RESET_XILINX;
|
|
|
|
|
|
|
|
lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
|
|
|
|
msleep(1);
|
|
|
|
|
|
|
|
lx_plx_reg_write(chip, ePLX_MBOX3, 0);
|
|
|
|
msleep(1);
|
|
|
|
|
|
|
|
plx_reg |= CHIPSC_RESET_XILINX;
|
|
|
|
lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg);
|
|
|
|
|
|
|
|
/* deactivate reset of xilinx */
|
|
|
|
for (i = 0; i != 100; ++i) {
|
|
|
|
u32 reg_mbox3;
|
|
|
|
msleep(10);
|
|
|
|
reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3);
|
|
|
|
if (reg_mbox3) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "xilinx reset done\n");
|
|
|
|
dev_dbg(chip->card->dev, "xilinx took %d loops\n", i);
|
2009-03-24 19:24:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* todo: add some error handling? */
|
|
|
|
|
|
|
|
/* clear mr */
|
|
|
|
lx_dsp_reg_write(chip, eReg_CSM, 0);
|
|
|
|
|
|
|
|
/* le xilinx ES peut ne pas etre encore pret, on attend. */
|
|
|
|
msleep(600);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_init_xilinx_test(struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
u32 reg;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_init_xilinx_test\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
/* TEST if we have access to Xilinx/MicroBlaze */
|
|
|
|
lx_dsp_reg_write(chip, eReg_CSM, 0);
|
|
|
|
|
|
|
|
reg = lx_dsp_reg_read(chip, eReg_CSM);
|
|
|
|
|
|
|
|
if (reg) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "Problem: Reg_CSM %x.\n", reg);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
/* PCI9056_SPACE0_REMAP */
|
|
|
|
lx_plx_reg_write(chip, ePLX_PCICR, 1);
|
|
|
|
|
|
|
|
reg = lx_dsp_reg_read(chip, eReg_CSM);
|
|
|
|
if (reg) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "Error: Reg_CSM %x.\n", reg);
|
2009-03-24 19:24:35 +08:00
|
|
|
return -EAGAIN; /* seems to be appropriate */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "Xilinx/MicroBlaze access test successful\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize ethersound */
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_init_ethersound_config(struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES);
|
|
|
|
|
2009-06-25 15:41:46 +08:00
|
|
|
/* configure 64 io channels */
|
|
|
|
u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) |
|
2009-03-24 19:24:35 +08:00
|
|
|
(64 << IOCR_INPUTS_OFFSET) |
|
2009-06-25 15:41:46 +08:00
|
|
|
(64 << IOCR_OUTPUTS_OFFSET) |
|
2009-03-24 19:24:35 +08:00
|
|
|
(FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET);
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_init_ethersound\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
chip->freq_ratio = FREQ_RATIO_SINGLE_MODE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write it to the card !
|
|
|
|
* this actually kicks the ES xilinx, the first time since poweron.
|
|
|
|
* the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers
|
|
|
|
* is not ready before this is done, and the bit 2 in Reg_CSES is set.
|
|
|
|
* */
|
|
|
|
lx_dsp_reg_write(chip, eReg_CONFES, conf_es);
|
|
|
|
|
|
|
|
for (i = 0; i != 1000; ++i) {
|
|
|
|
if (lx_dsp_reg_read(chip, eReg_CSES) & 4) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "ethersound initialized after %dms\n",
|
2009-03-24 19:24:35 +08:00
|
|
|
i);
|
|
|
|
goto ethersound_initialized;
|
|
|
|
}
|
|
|
|
msleep(1);
|
|
|
|
}
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_warn(chip->card->dev,
|
2009-03-24 19:24:35 +08:00
|
|
|
"ethersound could not be initialized after %dms\n", i);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
ethersound_initialized:
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "ethersound initialized\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_init_get_version_features(struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
u32 dsp_version;
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_init_get_version_features\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
err = lx_dsp_get_version(chip, &dsp_version);
|
|
|
|
|
|
|
|
if (err == 0) {
|
|
|
|
u32 freq;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_info(chip->card->dev, "DSP version: V%02d.%02d #%d\n",
|
2009-03-24 19:24:35 +08:00
|
|
|
(dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff,
|
|
|
|
dsp_version & 0xff);
|
|
|
|
|
|
|
|
/* later: what firmware version do we expect? */
|
|
|
|
|
|
|
|
/* retrieve Play/Rec features */
|
|
|
|
/* done here because we may have to handle alternate
|
|
|
|
* DSP files. */
|
|
|
|
/* later */
|
|
|
|
|
|
|
|
/* init the EtherSound sample rate */
|
|
|
|
err = lx_dsp_get_clock_frequency(chip, &freq);
|
|
|
|
if (err == 0)
|
|
|
|
chip->board_sample_rate = freq;
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "actual clock frequency %d\n", freq);
|
2009-03-24 19:24:35 +08:00
|
|
|
} else {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "DSP corrupted \n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_set_granularity(struct lx6464es *chip, u32 gran)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u32 snapped_gran = MICROBLAZE_IBL_MIN;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_set_granularity\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
/* blocksize is a power of 2 */
|
|
|
|
while ((snapped_gran < gran) &&
|
|
|
|
(snapped_gran < MICROBLAZE_IBL_MAX)) {
|
|
|
|
snapped_gran *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (snapped_gran == chip->pcm_granularity)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err = lx_dsp_set_granularity(chip, snapped_gran);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_warn(chip->card->dev, "could not set granularity\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (snapped_gran != gran)
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(chip->card->dev, "snapped blocksize to %d\n", snapped_gran);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "set blocksize on board %d\n", snapped_gran);
|
2009-03-24 19:24:35 +08:00
|
|
|
chip->pcm_granularity = snapped_gran;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize and test the xilinx dsp chip */
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_init_dsp(struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int i;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "->lx_init_dsp\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "initialize board\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_init_xilinx_reset(chip);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "testing board\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_init_xilinx_test(chip);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "initialize ethersound configuration\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
err = lx_init_ethersound_config(chip);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
lx_irq_enable(chip);
|
|
|
|
|
|
|
|
/** \todo the mac address should be ready by not, but it isn't,
|
|
|
|
* so we wait for it */
|
|
|
|
for (i = 0; i != 1000; ++i) {
|
2011-06-24 23:36:20 +08:00
|
|
|
err = lx_dsp_get_mac(chip);
|
2009-03-24 19:24:35 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2011-06-24 23:36:20 +08:00
|
|
|
if (chip->mac_address[0] || chip->mac_address[1] || chip->mac_address[2] ||
|
|
|
|
chip->mac_address[3] || chip->mac_address[4] || chip->mac_address[5])
|
2009-03-24 19:24:35 +08:00
|
|
|
goto mac_ready;
|
|
|
|
msleep(1);
|
|
|
|
}
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
mac_ready:
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "mac address ready read after: %dms\n", i);
|
|
|
|
dev_info(chip->card->dev,
|
|
|
|
"mac address: %02X.%02X.%02X.%02X.%02X.%02X\n",
|
2011-06-24 23:36:20 +08:00
|
|
|
chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
|
|
|
|
chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
err = lx_init_get_version_features(chip);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
lx_set_granularity(chip, MICROBLAZE_IBL_DEFAULT);
|
|
|
|
|
|
|
|
chip->playback_mute = 0;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-09-02 06:13:10 +08:00
|
|
|
static const struct snd_pcm_ops lx_ops_playback = {
|
2009-03-24 19:24:35 +08:00
|
|
|
.open = lx_pcm_open,
|
|
|
|
.close = lx_pcm_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.prepare = lx_pcm_prepare,
|
|
|
|
.hw_params = lx_pcm_hw_params_playback,
|
|
|
|
.hw_free = lx_pcm_hw_free,
|
|
|
|
.trigger = lx_pcm_trigger,
|
|
|
|
.pointer = lx_pcm_stream_pointer,
|
|
|
|
};
|
|
|
|
|
2016-09-02 06:13:10 +08:00
|
|
|
static const struct snd_pcm_ops lx_ops_capture = {
|
2009-03-24 19:24:35 +08:00
|
|
|
.open = lx_pcm_open,
|
|
|
|
.close = lx_pcm_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.prepare = lx_pcm_prepare,
|
|
|
|
.hw_params = lx_pcm_hw_params_capture,
|
|
|
|
.hw_free = lx_pcm_hw_free,
|
|
|
|
.trigger = lx_pcm_trigger,
|
|
|
|
.pointer = lx_pcm_stream_pointer,
|
|
|
|
};
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_pcm_create(struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct snd_pcm *pcm;
|
|
|
|
|
|
|
|
u32 size = 64 * /* channels */
|
|
|
|
3 * /* 24 bit samples */
|
|
|
|
MAX_STREAM_BUFFER * /* periods */
|
|
|
|
MICROBLAZE_IBL_MAX * /* frames per period */
|
|
|
|
2; /* duplex */
|
|
|
|
|
|
|
|
size = PAGE_ALIGN(size);
|
|
|
|
|
|
|
|
/* hardcoded device name & channel count */
|
|
|
|
err = snd_pcm_new(chip->card, (char *)card_name, 0,
|
|
|
|
1, 1, &pcm);
|
2012-08-14 23:42:11 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
pcm->private_data = chip;
|
|
|
|
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &lx_ops_playback);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &lx_ops_capture);
|
|
|
|
|
|
|
|
pcm->info_flags = 0;
|
2014-09-10 20:01:05 +08:00
|
|
|
pcm->nonatomic = true;
|
2009-03-24 19:24:35 +08:00
|
|
|
strcpy(pcm->name, card_name);
|
|
|
|
|
|
|
|
err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
|
|
|
|
snd_dma_pci_data(chip->pci),
|
|
|
|
size, size);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
chip->pcm = pcm;
|
|
|
|
chip->capture_stream.is_capture = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_control_playback_info(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_control_playback_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
|
|
|
|
ucontrol->value.integer.value[0] = chip->playback_mute;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lx_control_playback_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct lx6464es *chip = snd_kcontrol_chip(kcontrol);
|
|
|
|
int changed = 0;
|
|
|
|
int current_value = chip->playback_mute;
|
|
|
|
|
|
|
|
if (current_value != ucontrol->value.integer.value[0]) {
|
|
|
|
lx_level_unmute(chip, 0, !current_value);
|
|
|
|
chip->playback_mute = !current_value;
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2017-02-20 02:48:09 +08:00
|
|
|
static const struct snd_kcontrol_new lx_control_playback_switch = {
|
2009-03-24 19:24:35 +08:00
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "PCM Playback Switch",
|
|
|
|
.index = 0,
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
|
|
|
|
.private_value = 0,
|
|
|
|
.info = lx_control_playback_info,
|
|
|
|
.get = lx_control_playback_get,
|
|
|
|
.put = lx_control_playback_put
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void lx_proc_levels_read(struct snd_info_entry *entry,
|
|
|
|
struct snd_info_buffer *buffer)
|
|
|
|
{
|
|
|
|
u32 levels[64];
|
|
|
|
int err;
|
|
|
|
int i, j;
|
|
|
|
struct lx6464es *chip = entry->private_data;
|
|
|
|
|
|
|
|
snd_iprintf(buffer, "capture levels:\n");
|
|
|
|
err = lx_level_peaks(chip, 1, 64, levels);
|
|
|
|
if (err < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i != 8; ++i) {
|
|
|
|
for (j = 0; j != 8; ++j)
|
|
|
|
snd_iprintf(buffer, "%08x ", levels[i*8+j]);
|
|
|
|
snd_iprintf(buffer, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_iprintf(buffer, "\nplayback levels:\n");
|
|
|
|
|
|
|
|
err = lx_level_peaks(chip, 0, 64, levels);
|
|
|
|
if (err < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i != 8; ++i) {
|
|
|
|
for (j = 0; j != 8; ++j)
|
|
|
|
snd_iprintf(buffer, "%08x ", levels[i*8+j]);
|
|
|
|
snd_iprintf(buffer, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_iprintf(buffer, "\n");
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static int lx_proc_create(struct snd_card *card, struct lx6464es *chip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
struct snd_info_entry *entry;
|
|
|
|
int err = snd_card_proc_new(card, "levels", &entry);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
snd_info_set_text_ops(entry, chip, lx_proc_levels_read);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static int snd_lx6464es_create(struct snd_card *card,
|
|
|
|
struct pci_dev *pci,
|
|
|
|
struct lx6464es **rchip)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
struct lx6464es *chip;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
static struct snd_device_ops ops = {
|
|
|
|
.dev_free = snd_lx6464es_dev_free,
|
|
|
|
};
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(card->dev, "->snd_lx6464es_create\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
*rchip = NULL;
|
|
|
|
|
|
|
|
/* enable PCI device */
|
|
|
|
err = pci_enable_device(pci);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
pci_set_master(pci);
|
|
|
|
|
|
|
|
/* check if we can restrict PCI DMA transfers to 32 bits */
|
ALSA: remove deprecated use of pci api
Replace occurences of the pci api by appropriate call to the dma api.
A simplified version of the semantic patch that finds this problem is as
follows: (http://coccinelle.lip6.fr)
@deprecated@
idexpression id;
position p;
@@
(
pci_dma_supported@p ( id, ...)
|
pci_alloc_consistent@p ( id, ...)
)
@bad1@
idexpression id;
position deprecated.p;
@@
...when != &id->dev
when != pci_get_drvdata ( id )
when != pci_enable_device ( id )
(
pci_dma_supported@p ( id, ...)
|
pci_alloc_consistent@p ( id, ...)
)
@depends on !bad1@
idexpression id;
expression direction;
position deprecated.p;
@@
(
- pci_dma_supported@p ( id,
+ dma_supported ( &id->dev,
...
+ , GFP_ATOMIC
)
|
- pci_alloc_consistent@p ( id,
+ dma_alloc_coherent ( &id->dev,
...
+ , GFP_ATOMIC
)
)
Signed-off-by: Quentin Lambert <lambert.quentin@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-04-15 22:10:17 +08:00
|
|
|
err = dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
|
2009-03-24 19:24:35 +08:00
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(card->dev,
|
|
|
|
"architecture does not support 32bit PCI busmaster DMA\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
pci_disable_device(pci);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
|
|
|
if (chip == NULL) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto alloc_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->card = card;
|
|
|
|
chip->pci = pci;
|
|
|
|
chip->irq = -1;
|
|
|
|
|
|
|
|
/* initialize synchronization structs */
|
2014-09-10 20:01:05 +08:00
|
|
|
mutex_init(&chip->lock);
|
|
|
|
mutex_init(&chip->msg_lock);
|
2009-03-24 19:24:35 +08:00
|
|
|
mutex_init(&chip->setup_mutex);
|
|
|
|
|
|
|
|
/* request resources */
|
|
|
|
err = pci_request_regions(pci, card_name);
|
|
|
|
if (err < 0)
|
|
|
|
goto request_regions_failed;
|
|
|
|
|
|
|
|
/* plx port */
|
|
|
|
chip->port_plx = pci_resource_start(pci, 1);
|
|
|
|
chip->port_plx_remapped = ioport_map(chip->port_plx,
|
|
|
|
pci_resource_len(pci, 1));
|
|
|
|
|
|
|
|
/* dsp port */
|
|
|
|
chip->port_dsp_bar = pci_ioremap_bar(pci, 2);
|
2018-06-14 21:51:46 +08:00
|
|
|
if (!chip->port_dsp_bar) {
|
|
|
|
dev_err(card->dev, "cannot remap PCI memory region\n");
|
2018-06-21 16:07:21 +08:00
|
|
|
err = -ENOMEM;
|
2018-06-14 21:51:46 +08:00
|
|
|
goto remap_pci_failed;
|
|
|
|
}
|
2009-03-24 19:24:35 +08:00
|
|
|
|
2014-09-10 20:01:05 +08:00
|
|
|
err = request_threaded_irq(pci->irq, lx_interrupt, lx_threaded_irq,
|
|
|
|
IRQF_SHARED, KBUILD_MODNAME, chip);
|
2009-03-24 19:24:35 +08:00
|
|
|
if (err) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
|
2009-03-24 19:24:35 +08:00
|
|
|
goto request_irq_failed;
|
|
|
|
}
|
|
|
|
chip->irq = pci->irq;
|
|
|
|
|
|
|
|
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
|
|
|
|
if (err < 0)
|
|
|
|
goto device_new_failed;
|
|
|
|
|
|
|
|
err = lx_init_dsp(chip);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(card->dev, "error during DSP initialization\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = lx_pcm_create(chip);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = lx_proc_create(card, chip);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch,
|
|
|
|
chip));
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
*rchip = chip;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
device_new_failed:
|
|
|
|
free_irq(pci->irq, chip);
|
|
|
|
|
|
|
|
request_irq_failed:
|
2018-06-14 21:51:46 +08:00
|
|
|
iounmap(chip->port_dsp_bar);
|
|
|
|
|
|
|
|
remap_pci_failed:
|
2009-03-24 19:24:35 +08:00
|
|
|
pci_release_regions(pci);
|
|
|
|
|
|
|
|
request_regions_failed:
|
|
|
|
kfree(chip);
|
|
|
|
|
|
|
|
alloc_failed:
|
|
|
|
pci_disable_device(pci);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static int snd_lx6464es_probe(struct pci_dev *pci,
|
|
|
|
const struct pci_device_id *pci_id)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
static int dev;
|
|
|
|
struct snd_card *card;
|
|
|
|
struct lx6464es *chip;
|
|
|
|
int err;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(&pci->dev, "->snd_lx6464es_probe\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
if (dev >= SNDRV_CARDS)
|
|
|
|
return -ENODEV;
|
|
|
|
if (!enable[dev]) {
|
|
|
|
dev++;
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2014-01-29 21:20:19 +08:00
|
|
|
err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
|
|
|
|
0, &card);
|
2009-04-14 18:25:52 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2009-03-24 19:24:35 +08:00
|
|
|
|
|
|
|
err = snd_lx6464es_create(card, pci, &chip);
|
|
|
|
if (err < 0) {
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_err(card->dev, "error during snd_lx6464es_create\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2011-06-24 23:36:20 +08:00
|
|
|
strcpy(card->driver, "LX6464ES");
|
|
|
|
sprintf(card->id, "LX6464ES_%02X%02X%02X",
|
|
|
|
chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
|
|
|
|
|
|
|
|
sprintf(card->shortname, "LX6464ES %02X.%02X.%02X.%02X.%02X.%02X",
|
|
|
|
chip->mac_address[0], chip->mac_address[1], chip->mac_address[2],
|
|
|
|
chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]);
|
|
|
|
|
2009-03-24 19:24:35 +08:00
|
|
|
sprintf(card->longname, "%s at 0x%lx, 0x%p, irq %i",
|
|
|
|
card->shortname, chip->port_plx,
|
|
|
|
chip->port_dsp_bar, chip->irq);
|
|
|
|
|
|
|
|
err = snd_card_register(card);
|
|
|
|
if (err < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
2014-02-26 00:32:49 +08:00
|
|
|
dev_dbg(chip->card->dev, "initialization successful\n");
|
2009-03-24 19:24:35 +08:00
|
|
|
pci_set_drvdata(pci, card);
|
|
|
|
dev++;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
snd_card_free(card);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-07 01:35:10 +08:00
|
|
|
static void snd_lx6464es_remove(struct pci_dev *pci)
|
2009-03-24 19:24:35 +08:00
|
|
|
{
|
|
|
|
snd_card_free(pci_get_drvdata(pci));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-24 18:25:00 +08:00
|
|
|
static struct pci_driver lx6464es_driver = {
|
2011-06-10 22:20:20 +08:00
|
|
|
.name = KBUILD_MODNAME,
|
2009-03-24 19:24:35 +08:00
|
|
|
.id_table = snd_lx6464es_ids,
|
|
|
|
.probe = snd_lx6464es_probe,
|
2012-12-07 01:35:10 +08:00
|
|
|
.remove = snd_lx6464es_remove,
|
2009-03-24 19:24:35 +08:00
|
|
|
};
|
|
|
|
|
2012-04-24 18:25:00 +08:00
|
|
|
module_pci_driver(lx6464es_driver);
|