2019-05-29 22:18:00 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-09-13 22:30:11 +08:00
|
|
|
/*
|
|
|
|
* Driver for the Conexant CX25821 PCIe bridge
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Conexant Systems Inc.
|
|
|
|
* Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
|
|
|
|
* Based on SAA713x ALSA driver and CX88 driver
|
|
|
|
*/
|
|
|
|
|
2010-11-08 04:48:21 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/pci.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-09-15 22:33:54 +08:00
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
#include <linux/delay.h>
|
2009-09-15 22:33:54 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/control.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
|
|
|
|
#include "cx25821.h"
|
|
|
|
#include "cx25821-reg.h"
|
|
|
|
|
|
|
|
#define AUDIO_SRAM_CHANNEL SRAM_CH08
|
|
|
|
|
2010-11-08 04:48:21 +08:00
|
|
|
#define dprintk(level, fmt, arg...) \
|
|
|
|
do { \
|
|
|
|
if (debug >= level) \
|
|
|
|
pr_info("%s/1: " fmt, chip->dev->name, ##arg); \
|
|
|
|
} while (0)
|
|
|
|
#define dprintk_core(level, fmt, arg...) \
|
|
|
|
do { \
|
|
|
|
if (debug >= level) \
|
|
|
|
printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name, ##arg); \
|
|
|
|
} while (0)
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Data type declarations - Can be moded to a header file later
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int devno;
|
|
|
|
|
2010-05-11 21:36:31 +08:00
|
|
|
struct cx25821_audio_buffer {
|
|
|
|
unsigned int bpl;
|
2014-12-12 21:27:54 +08:00
|
|
|
struct cx25821_riscmem risc;
|
2014-12-12 21:27:57 +08:00
|
|
|
void *vaddr;
|
|
|
|
struct scatterlist *sglist;
|
|
|
|
int sglen;
|
|
|
|
int nr_pages;
|
2010-05-11 21:36:31 +08:00
|
|
|
};
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
struct cx25821_audio_dev {
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_dev *dev;
|
|
|
|
struct cx25821_dmaqueue q;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* pci i/o */
|
2009-09-13 22:30:11 +08:00
|
|
|
struct pci_dev *pci;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* audio controls */
|
2009-09-13 22:30:11 +08:00
|
|
|
int irq;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
struct snd_card *card;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
unsigned long iobase;
|
2009-09-13 22:30:11 +08:00
|
|
|
spinlock_t reg_lock;
|
|
|
|
atomic_t count;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
unsigned int dma_size;
|
|
|
|
unsigned int period_size;
|
|
|
|
unsigned int num_periods;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2010-05-11 21:36:31 +08:00
|
|
|
struct cx25821_audio_buffer *buf;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
struct snd_pcm_substream *substream;
|
2009-09-15 22:33:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Module global static vars
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
|
|
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
2015-09-22 00:00:41 +08:00
|
|
|
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
module_param_array(enable, bool, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
|
|
|
|
|
|
|
|
module_param_array(index, int, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Module macros
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ALSA driver module for cx25821 based capture cards");
|
|
|
|
MODULE_AUTHOR("Hiep Huynh");
|
|
|
|
MODULE_LICENSE("GPL");
|
2010-03-14 23:44:37 +08:00
|
|
|
MODULE_SUPPORTED_DEVICE("{{Conexant,25821}"); /* "{{Conexant,23881}," */
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
static unsigned int debug;
|
2009-09-13 22:30:11 +08:00
|
|
|
module_param(debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(debug, "enable debug messages");
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2019-02-19 03:28:59 +08:00
|
|
|
Module specific functions
|
2009-09-15 22:33:54 +08:00
|
|
|
****************************************************************************/
|
|
|
|
/* Constants taken from cx88-reg.h */
|
|
|
|
#define AUD_INT_DN_RISCI1 (1 << 0)
|
|
|
|
#define AUD_INT_UP_RISCI1 (1 << 1)
|
|
|
|
#define AUD_INT_RDS_DN_RISCI1 (1 << 2)
|
2009-09-13 22:30:11 +08:00
|
|
|
#define AUD_INT_DN_RISCI2 (1 << 4) /* yes, 3 is skipped */
|
2009-09-15 22:33:54 +08:00
|
|
|
#define AUD_INT_UP_RISCI2 (1 << 5)
|
|
|
|
#define AUD_INT_RDS_DN_RISCI2 (1 << 6)
|
|
|
|
#define AUD_INT_DN_SYNC (1 << 12)
|
|
|
|
#define AUD_INT_UP_SYNC (1 << 13)
|
|
|
|
#define AUD_INT_RDS_DN_SYNC (1 << 14)
|
|
|
|
#define AUD_INT_OPC_ERR (1 << 16)
|
|
|
|
#define AUD_INT_BER_IRQ (1 << 20)
|
|
|
|
#define AUD_INT_MCHG_IRQ (1 << 21)
|
|
|
|
#define GP_COUNT_CONTROL_RESET 0x3
|
|
|
|
|
|
|
|
#define PCI_MSK_AUD_EXT (1 << 4)
|
|
|
|
#define PCI_MSK_AUD_INT (1 << 3)
|
2014-12-12 21:27:57 +08:00
|
|
|
|
|
|
|
static int cx25821_alsa_dma_init(struct cx25821_audio_dev *chip, int nr_pages)
|
|
|
|
{
|
|
|
|
struct cx25821_audio_buffer *buf = chip->buf;
|
|
|
|
struct page *pg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
|
|
|
|
if (NULL == buf->vaddr) {
|
|
|
|
dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-11-02 05:05:46 +08:00
|
|
|
dprintk(1, "vmalloc is at addr 0x%p, size=%d\n",
|
|
|
|
buf->vaddr,
|
2014-12-12 21:27:57 +08:00
|
|
|
nr_pages << PAGE_SHIFT);
|
|
|
|
|
|
|
|
memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT);
|
|
|
|
buf->nr_pages = nr_pages;
|
|
|
|
|
treewide: Use array_size() in vzalloc()
The vzalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:
vzalloc(a * b)
with:
vzalloc(array_size(a, b))
as well as handling cases of:
vzalloc(a * b * c)
with:
vzalloc(array3_size(a, b, c))
This does, however, attempt to ignore constant size factors like:
vzalloc(4 * 1024)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
vzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
vzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
vzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
vzalloc(
- sizeof(TYPE) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT_ID
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT_ID
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
vzalloc(
- SIZE * COUNT
+ array_size(COUNT, SIZE)
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
vzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
vzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
vzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
vzalloc(C1 * C2 * C3, ...)
|
vzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@
(
vzalloc(C1 * C2, ...)
|
vzalloc(
- E1 * E2
+ array_size(E1, E2)
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:27:37 +08:00
|
|
|
buf->sglist = vzalloc(array_size(sizeof(*buf->sglist), buf->nr_pages));
|
2014-12-12 21:27:57 +08:00
|
|
|
if (NULL == buf->sglist)
|
|
|
|
goto vzalloc_err;
|
|
|
|
|
|
|
|
sg_init_table(buf->sglist, buf->nr_pages);
|
|
|
|
for (i = 0; i < buf->nr_pages; i++) {
|
|
|
|
pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE);
|
|
|
|
if (NULL == pg)
|
|
|
|
goto vmalloc_to_page_err;
|
|
|
|
sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
vmalloc_to_page_err:
|
|
|
|
vfree(buf->sglist);
|
|
|
|
buf->sglist = NULL;
|
|
|
|
vzalloc_err:
|
|
|
|
vfree(buf->vaddr);
|
|
|
|
buf->vaddr = NULL;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cx25821_alsa_dma_map(struct cx25821_audio_dev *dev)
|
|
|
|
{
|
|
|
|
struct cx25821_audio_buffer *buf = dev->buf;
|
|
|
|
|
|
|
|
buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist,
|
|
|
|
buf->nr_pages, PCI_DMA_FROMDEVICE);
|
|
|
|
|
|
|
|
if (0 == buf->sglen) {
|
|
|
|
pr_warn("%s: cx25821_alsa_map_sg failed\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cx25821_alsa_dma_unmap(struct cx25821_audio_dev *dev)
|
|
|
|
{
|
|
|
|
struct cx25821_audio_buffer *buf = dev->buf;
|
|
|
|
|
|
|
|
if (!buf->sglen)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE);
|
|
|
|
buf->sglen = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cx25821_alsa_dma_free(struct cx25821_audio_buffer *buf)
|
|
|
|
{
|
|
|
|
vfree(buf->sglist);
|
|
|
|
buf->sglist = NULL;
|
|
|
|
vfree(buf->vaddr);
|
|
|
|
buf->vaddr = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
/*
|
|
|
|
* BOARD Specific: Sets audio DMA
|
|
|
|
*/
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2010-05-11 21:36:31 +08:00
|
|
|
struct cx25821_audio_buffer *buf = chip->buf;
|
2009-09-13 22:30:11 +08:00
|
|
|
struct cx25821_dev *dev = chip->dev;
|
2013-04-13 17:28:54 +08:00
|
|
|
const struct sram_channel *audio_ch =
|
2009-09-13 22:30:11 +08:00
|
|
|
&cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
|
2009-09-15 22:33:54 +08:00
|
|
|
u32 tmp = 0;
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
/* enable output on the GPIO 0 for the MCLK ADC (Audio) */
|
2009-09-13 22:30:11 +08:00
|
|
|
cx25821_set_gpiopin_direction(chip->dev, 0, 0);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
|
2009-09-13 22:30:11 +08:00
|
|
|
cx_clear(AUD_INT_DMA_CTL,
|
|
|
|
FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* setup fifo + format - out channel */
|
2009-09-13 22:30:11 +08:00
|
|
|
cx25821_sram_channel_setup_audio(chip->dev, audio_ch, buf->bpl,
|
|
|
|
buf->risc.dma);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* sets bpl size */
|
|
|
|
cx_write(AUD_A_LNGTH, buf->bpl);
|
|
|
|
|
|
|
|
/* reset counter */
|
2010-03-14 23:44:37 +08:00
|
|
|
/* GP_COUNT_CONTROL_RESET = 0x3 */
|
|
|
|
cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
|
2009-09-15 22:33:54 +08:00
|
|
|
atomic_set(&chip->count, 0);
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
/* Set the input mode to 16-bit */
|
2009-09-13 22:30:11 +08:00
|
|
|
tmp = cx_read(AUD_A_CFG);
|
2011-10-22 12:43:24 +08:00
|
|
|
cx_write(AUD_A_CFG, tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE |
|
2009-09-13 22:30:11 +08:00
|
|
|
FLD_AUD_CLK_ENABLE);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2010-11-08 04:48:21 +08:00
|
|
|
/*
|
|
|
|
pr_info("DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d byte buffer\n",
|
|
|
|
buf->bpl, audio_ch->cmds_start,
|
|
|
|
cx_read(audio_ch->cmds_start + 12)>>1,
|
|
|
|
chip->num_periods, buf->bpl * chip->num_periods);
|
2010-03-14 23:44:37 +08:00
|
|
|
*/
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* Enables corresponding bits at AUD_INT_STAT */
|
2011-10-22 12:43:24 +08:00
|
|
|
cx_write(AUD_A_INT_MSK, FLD_AUD_DST_RISCI1 | FLD_AUD_DST_OF |
|
|
|
|
FLD_AUD_DST_SYNC | FLD_AUD_DST_OPC_ERR);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* Clean any pending interrupt bits already set */
|
|
|
|
cx_write(AUD_A_INT_STAT, ~0);
|
|
|
|
|
|
|
|
/* enable audio irqs */
|
|
|
|
cx_set(PCI_INT_MSK, chip->dev->pci_irqmask | PCI_MSK_AUD_INT);
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
/* Turn on audio downstream fifo and risc enable 0x101 */
|
2009-09-13 22:30:11 +08:00
|
|
|
tmp = cx_read(AUD_INT_DMA_CTL);
|
2011-10-22 12:43:24 +08:00
|
|
|
cx_set(AUD_INT_DMA_CTL, tmp |
|
|
|
|
(FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN));
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
mdelay(100);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BOARD Specific: Resets audio DMA
|
|
|
|
*/
|
2010-03-14 23:44:37 +08:00
|
|
|
static int _cx25821_stop_audio_dma(struct cx25821_audio_dev *chip)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
|
|
|
struct cx25821_dev *dev = chip->dev;
|
|
|
|
|
|
|
|
/* stop dma */
|
2009-09-13 22:30:11 +08:00
|
|
|
cx_clear(AUD_INT_DMA_CTL,
|
|
|
|
FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* disable irqs */
|
|
|
|
cx_clear(PCI_INT_MSK, PCI_MSK_AUD_INT);
|
2011-10-22 12:43:24 +08:00
|
|
|
cx_clear(AUD_A_INT_MSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
|
|
|
|
AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_IRQ_LOOP 50
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BOARD Specific: IRQ dma bits
|
|
|
|
*/
|
|
|
|
static char *cx25821_aud_irqs[32] = {
|
2009-09-13 22:30:11 +08:00
|
|
|
"dn_risci1", "up_risci1", "rds_dn_risc1", /* 0-2 */
|
2011-10-22 12:43:21 +08:00
|
|
|
NULL, /* reserved */
|
2009-09-13 22:30:11 +08:00
|
|
|
"dn_risci2", "up_risci2", "rds_dn_risc2", /* 4-6 */
|
2011-10-22 12:43:21 +08:00
|
|
|
NULL, /* reserved */
|
|
|
|
"dnf_of", "upf_uf", "rds_dnf_uf", /* 8-10 */
|
|
|
|
NULL, /* reserved */
|
|
|
|
"dn_sync", "up_sync", "rds_dn_sync", /* 12-14 */
|
|
|
|
NULL, /* reserved */
|
|
|
|
"opc_err", "par_err", "rip_err", /* 16-18 */
|
|
|
|
"pci_abort", "ber_irq", "mchg_irq" /* 19-21 */
|
2009-09-15 22:33:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BOARD Specific: Threats IRQ audio specific calls
|
|
|
|
*/
|
2010-03-14 23:44:37 +08:00
|
|
|
static void cx25821_aud_irq(struct cx25821_audio_dev *chip, u32 status,
|
|
|
|
u32 mask)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
|
|
|
struct cx25821_dev *dev = chip->dev;
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
if (0 == (status & mask))
|
2009-09-15 22:33:54 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
cx_write(AUD_A_INT_STAT, status);
|
2009-09-13 22:30:11 +08:00
|
|
|
if (debug > 1 || (status & mask & ~0xff))
|
2011-10-22 12:43:24 +08:00
|
|
|
cx25821_print_irqbits(dev->name, "irq aud", cx25821_aud_irqs,
|
|
|
|
ARRAY_SIZE(cx25821_aud_irqs), status, mask);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* risc op code error */
|
|
|
|
if (status & AUD_INT_OPC_ERR) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_warn("WARNING %s/1: Audio risc op code error\n", dev->name);
|
2009-09-13 22:30:11 +08:00
|
|
|
|
|
|
|
cx_clear(AUD_INT_DMA_CTL,
|
|
|
|
FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
|
|
|
|
cx25821_sram_channel_dump_audio(dev,
|
2011-10-22 12:43:24 +08:00
|
|
|
&cx25821_sram_channels[AUDIO_SRAM_CHANNEL]);
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
if (status & AUD_INT_DN_SYNC) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_warn("WARNING %s: Downstream sync error!\n", dev->name);
|
2009-09-15 22:33:54 +08:00
|
|
|
cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* risc1 downstream */
|
|
|
|
if (status & AUD_INT_DN_RISCI1) {
|
|
|
|
atomic_set(&chip->count, cx_read(AUD_A_GPCNT));
|
|
|
|
snd_pcm_period_elapsed(chip->substream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* BOARD Specific: Handles IRQ calls
|
|
|
|
*/
|
|
|
|
static irqreturn_t cx25821_irq(int irq, void *dev_id)
|
|
|
|
{
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip = dev_id;
|
2009-09-15 22:33:54 +08:00
|
|
|
struct cx25821_dev *dev = chip->dev;
|
|
|
|
u32 status, pci_status;
|
|
|
|
u32 audint_status, audint_mask;
|
|
|
|
int loop, handled = 0;
|
|
|
|
|
|
|
|
audint_status = cx_read(AUD_A_INT_STAT);
|
2009-09-13 22:30:11 +08:00
|
|
|
audint_mask = cx_read(AUD_A_INT_MSK);
|
2009-09-15 22:33:54 +08:00
|
|
|
status = cx_read(PCI_INT_STAT);
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
for (loop = 0; loop < 1; loop++) {
|
2009-09-15 22:33:54 +08:00
|
|
|
status = cx_read(PCI_INT_STAT);
|
2009-09-13 22:30:11 +08:00
|
|
|
if (0 == status) {
|
2009-09-15 22:33:54 +08:00
|
|
|
status = cx_read(PCI_INT_STAT);
|
|
|
|
audint_status = cx_read(AUD_A_INT_STAT);
|
|
|
|
audint_mask = cx_read(AUD_A_INT_MSK);
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (status) {
|
2009-09-15 22:33:54 +08:00
|
|
|
handled = 1;
|
|
|
|
cx_write(PCI_INT_STAT, status);
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
cx25821_aud_irq(chip, audint_status,
|
|
|
|
audint_mask);
|
2009-09-15 22:33:54 +08:00
|
|
|
break;
|
2011-10-22 12:43:22 +08:00
|
|
|
} else {
|
2009-09-15 22:33:54 +08:00
|
|
|
goto out;
|
2011-10-22 12:43:22 +08:00
|
|
|
}
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handled = 1;
|
|
|
|
cx_write(PCI_INT_STAT, status);
|
|
|
|
|
|
|
|
cx25821_aud_irq(chip, audint_status, audint_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_status = cx_read(PCI_INT_STAT);
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
cx_write(PCI_INT_STAT, pci_status);
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
out:
|
2009-09-15 22:33:54 +08:00
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
static int dsp_buffer_free(struct cx25821_audio_dev *chip)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2014-12-12 21:27:54 +08:00
|
|
|
struct cx25821_riscmem *risc = &chip->buf->risc;
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
BUG_ON(!chip->dma_size);
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
dprintk(2, "Freeing buffer\n");
|
2014-12-12 21:27:57 +08:00
|
|
|
cx25821_alsa_dma_unmap(chip);
|
|
|
|
cx25821_alsa_dma_free(chip->buf);
|
2014-12-12 21:27:54 +08:00
|
|
|
pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma);
|
2009-09-15 22:33:54 +08:00
|
|
|
kfree(chip->buf);
|
|
|
|
|
2014-12-12 21:27:57 +08:00
|
|
|
chip->buf = NULL;
|
2009-09-15 22:33:54 +08:00
|
|
|
chip->dma_size = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
ALSA PCM Interface
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Digital hardware definition
|
|
|
|
*/
|
|
|
|
#define DEFAULT_FIFO_SIZE 384
|
2017-08-13 20:43:09 +08:00
|
|
|
static const struct snd_pcm_hardware snd_cx25821_digital_hw = {
|
2011-10-22 12:43:24 +08:00
|
|
|
.info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID,
|
2009-09-15 22:33:54 +08:00
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
.rates = SNDRV_PCM_RATE_48000,
|
|
|
|
.rate_min = 48000,
|
|
|
|
.rate_max = 48000,
|
2009-09-15 22:33:54 +08:00
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
/* Analog audio output will be full of clicks and pops if there
|
|
|
|
are not exactly four lines in the SRAM FIFO buffer. */
|
2009-09-13 22:30:11 +08:00
|
|
|
.period_bytes_min = DEFAULT_FIFO_SIZE / 3,
|
|
|
|
.period_bytes_max = DEFAULT_FIFO_SIZE / 3,
|
2009-09-15 22:33:54 +08:00
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = AUDIO_LINE_SIZE,
|
2010-03-14 23:44:37 +08:00
|
|
|
/* 128 * 128 = 16384 = 1024 * 16 */
|
|
|
|
.buffer_bytes_max = (AUDIO_LINE_SIZE * AUDIO_LINE_SIZE),
|
2009-09-15 22:33:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* audio pcm capture open callback
|
|
|
|
*/
|
|
|
|
static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
|
2009-09-15 22:33:54 +08:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
int err;
|
|
|
|
unsigned int bpl = 0;
|
|
|
|
|
|
|
|
if (!chip) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_err("DEBUG: cx25821 can't find device struct. Can't proceed with open\n");
|
2009-09-15 22:33:54 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2011-10-22 12:43:24 +08:00
|
|
|
err = snd_pcm_hw_constraint_pow2(runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS);
|
2009-09-15 22:33:54 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto _error;
|
|
|
|
|
|
|
|
chip->substream = substream;
|
|
|
|
|
|
|
|
runtime->hw = snd_cx25821_digital_hw;
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size !=
|
|
|
|
DEFAULT_FIFO_SIZE) {
|
2010-03-14 23:44:37 +08:00
|
|
|
/* since there are 3 audio Clusters */
|
|
|
|
bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3;
|
2009-09-13 22:30:11 +08:00
|
|
|
bpl &= ~7; /* must be multiple of 8 */
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
if (bpl > AUDIO_LINE_SIZE)
|
2009-09-15 22:33:54 +08:00
|
|
|
bpl = AUDIO_LINE_SIZE;
|
2010-03-14 23:44:37 +08:00
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
runtime->hw.period_bytes_min = bpl;
|
|
|
|
runtime->hw.period_bytes_max = bpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-03-14 23:44:37 +08:00
|
|
|
_error:
|
2009-09-13 22:30:11 +08:00
|
|
|
dprintk(1, "Error opening PCM!\n");
|
2009-09-15 22:33:54 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* audio close callback
|
|
|
|
*/
|
|
|
|
static int snd_cx25821_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hw_params callback
|
|
|
|
*/
|
2009-09-13 22:30:11 +08:00
|
|
|
static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hw_params)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
|
2010-05-11 21:36:31 +08:00
|
|
|
struct cx25821_audio_buffer *buf;
|
2009-09-15 22:33:54 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (substream->runtime->dma_area) {
|
|
|
|
dsp_buffer_free(chip);
|
|
|
|
substream->runtime->dma_area = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->period_size = params_period_bytes(hw_params);
|
|
|
|
chip->num_periods = params_periods(hw_params);
|
|
|
|
chip->dma_size = chip->period_size * params_periods(hw_params);
|
|
|
|
|
|
|
|
BUG_ON(!chip->dma_size);
|
2009-09-13 22:30:11 +08:00
|
|
|
BUG_ON(chip->num_periods & (chip->num_periods - 1));
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2010-05-11 21:36:31 +08:00
|
|
|
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
|
2009-09-15 22:33:54 +08:00
|
|
|
if (NULL == buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
if (chip->period_size > AUDIO_LINE_SIZE)
|
2009-09-15 22:33:54 +08:00
|
|
|
chip->period_size = AUDIO_LINE_SIZE;
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->bpl = chip->period_size;
|
2014-12-12 21:27:57 +08:00
|
|
|
chip->buf = buf;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2014-12-12 21:27:57 +08:00
|
|
|
ret = cx25821_alsa_dma_init(chip,
|
2011-10-22 12:43:24 +08:00
|
|
|
(PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT));
|
2009-09-15 22:33:54 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
2014-12-12 21:27:57 +08:00
|
|
|
ret = cx25821_alsa_dma_map(chip);
|
2009-09-15 22:33:54 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
2014-12-12 21:27:57 +08:00
|
|
|
ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, buf->sglist,
|
2011-10-22 12:43:24 +08:00
|
|
|
chip->period_size, chip->num_periods, 1);
|
2009-09-13 22:30:11 +08:00
|
|
|
if (ret < 0) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
|
2009-09-15 22:33:54 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop back to start of program */
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
|
2009-09-15 22:33:54 +08:00
|
|
|
buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
|
2009-09-13 22:30:11 +08:00
|
|
|
buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2014-12-12 21:27:57 +08:00
|
|
|
substream->runtime->dma_area = chip->buf->vaddr;
|
2009-09-15 22:33:54 +08:00
|
|
|
substream->runtime->dma_bytes = chip->dma_size;
|
|
|
|
substream->runtime->dma_addr = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
error:
|
2014-12-12 21:27:57 +08:00
|
|
|
chip->buf = NULL;
|
2009-09-15 22:33:54 +08:00
|
|
|
kfree(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hw free callback
|
|
|
|
*/
|
2009-09-13 22:30:11 +08:00
|
|
|
static int snd_cx25821_hw_free(struct snd_pcm_substream *substream)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
if (substream->runtime->dma_area) {
|
|
|
|
dsp_buffer_free(chip);
|
|
|
|
substream->runtime->dma_area = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prepare callback
|
|
|
|
*/
|
|
|
|
static int snd_cx25821_prepare(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* trigger callback
|
|
|
|
*/
|
2009-09-13 22:30:11 +08:00
|
|
|
static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream,
|
|
|
|
int cmd)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
|
2009-09-15 22:33:54 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/* Local interrupts are already disabled by ALSA */
|
|
|
|
spin_lock(&chip->reg_lock);
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
err = _cx25821_start_audio_dma(chip);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
err = _cx25821_stop_audio_dma(chip);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&chip->reg_lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pointer callback
|
|
|
|
*/
|
2009-09-13 22:30:11 +08:00
|
|
|
static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream
|
|
|
|
*substream)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
|
2009-09-15 22:33:54 +08:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
u16 count;
|
|
|
|
|
|
|
|
count = atomic_read(&chip->count);
|
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
return runtime->period_size * (count & (runtime->periods - 1));
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* page callback (needed for mmap)
|
|
|
|
*/
|
|
|
|
static struct page *snd_cx25821_page(struct snd_pcm_substream *substream,
|
2009-09-13 22:30:11 +08:00
|
|
|
unsigned long offset)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
|
|
|
void *pageptr = substream->runtime->dma_area + offset;
|
|
|
|
|
|
|
|
return vmalloc_to_page(pageptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* operators
|
|
|
|
*/
|
2016-09-08 08:44:39 +08:00
|
|
|
static const struct snd_pcm_ops snd_cx25821_pcm_ops = {
|
2009-09-15 22:33:54 +08:00
|
|
|
.open = snd_cx25821_pcm_open,
|
|
|
|
.close = snd_cx25821_close,
|
|
|
|
.hw_params = snd_cx25821_hw_params,
|
|
|
|
.hw_free = snd_cx25821_hw_free,
|
|
|
|
.prepare = snd_cx25821_prepare,
|
|
|
|
.trigger = snd_cx25821_card_trigger,
|
|
|
|
.pointer = snd_cx25821_pointer,
|
|
|
|
.page = snd_cx25821_page,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2010-03-14 23:44:37 +08:00
|
|
|
* ALSA create a PCM device: Called when initializing the board.
|
|
|
|
* Sets up the name and hooks up the callbacks
|
2009-09-15 22:33:54 +08:00
|
|
|
*/
|
2010-03-14 23:44:37 +08:00
|
|
|
static int snd_cx25821_pcm(struct cx25821_audio_dev *chip, int device,
|
|
|
|
char *name)
|
2009-09-15 22:33:54 +08:00
|
|
|
{
|
|
|
|
struct snd_pcm *pcm;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
|
2009-09-13 22:30:11 +08:00
|
|
|
if (err < 0) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("ERROR: FAILED snd_pcm_new() in %s\n", __func__);
|
2009-09-15 22:33:54 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
pcm->private_data = chip;
|
|
|
|
pcm->info_flags = 0;
|
2018-09-11 04:20:42 +08:00
|
|
|
strscpy(pcm->name, name, sizeof(pcm->name));
|
2009-09-15 22:33:54 +08:00
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cx25821_pcm_ops);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
Basic Flow for Sound Devices
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
|
|
|
|
* Only boards with eeprom and byte 1 at eeprom=1 have it
|
|
|
|
*/
|
|
|
|
|
2016-06-24 20:46:54 +08:00
|
|
|
static const struct pci_device_id __maybe_unused cx25821_audio_pci_tbl[] = {
|
2009-09-13 22:30:11 +08:00
|
|
|
{0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
|
|
|
|
{0,}
|
2009-09-15 22:33:54 +08:00
|
|
|
};
|
2009-09-13 22:30:11 +08:00
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Alsa Constructor - Component probe
|
|
|
|
*/
|
|
|
|
static int cx25821_audio_initdev(struct cx25821_dev *dev)
|
|
|
|
{
|
2009-09-13 22:30:11 +08:00
|
|
|
struct snd_card *card;
|
2010-03-14 23:44:37 +08:00
|
|
|
struct cx25821_audio_dev *chip;
|
2009-09-13 22:30:11 +08:00
|
|
|
int err;
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2009-09-13 22:30:11 +08:00
|
|
|
if (devno >= SNDRV_CARDS) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("DEBUG ERROR: devno >= SNDRV_CARDS %s\n", __func__);
|
2010-03-14 23:44:37 +08:00
|
|
|
return -ENODEV;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!enable[devno]) {
|
|
|
|
++devno;
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("DEBUG ERROR: !enable[devno] %s\n", __func__);
|
2010-03-14 23:44:37 +08:00
|
|
|
return -ENOENT;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2014-01-29 21:48:43 +08:00
|
|
|
err = snd_card_new(&dev->pci->dev, index[devno], id[devno],
|
|
|
|
THIS_MODULE,
|
|
|
|
sizeof(struct cx25821_audio_dev), &card);
|
2009-09-13 22:39:12 +08:00
|
|
|
if (err < 0) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("DEBUG ERROR: cannot create snd_card_new in %s\n",
|
|
|
|
__func__);
|
2009-09-13 22:39:12 +08:00
|
|
|
return err;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
2018-09-11 04:20:42 +08:00
|
|
|
strscpy(card->driver, "cx25821", sizeof(card->driver));
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
/* Card "creation" */
|
2010-07-13 04:50:10 +08:00
|
|
|
chip = card->private_data;
|
2009-09-15 22:33:54 +08:00
|
|
|
spin_lock_init(&chip->reg_lock);
|
|
|
|
|
|
|
|
chip->dev = dev;
|
|
|
|
chip->card = card;
|
|
|
|
chip->pci = dev->pci;
|
|
|
|
chip->iobase = pci_resource_start(dev->pci, 0);
|
|
|
|
|
|
|
|
chip->irq = dev->pci->irq;
|
|
|
|
|
|
|
|
err = request_irq(dev->pci->irq, cx25821_irq,
|
2011-09-07 16:10:22 +08:00
|
|
|
IRQF_SHARED, chip->dev->name, chip);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
if (err < 0) {
|
2011-10-22 12:43:24 +08:00
|
|
|
pr_err("ERROR %s: can't get IRQ %d for ALSA\n", chip->dev->name,
|
|
|
|
dev->pci->irq);
|
2009-09-15 22:33:54 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-04-29 01:17:00 +08:00
|
|
|
err = snd_cx25821_pcm(chip, 0, "cx25821 Digital");
|
|
|
|
if (err < 0) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("DEBUG ERROR: cannot create snd_cx25821_pcm %s\n",
|
|
|
|
__func__);
|
2009-09-15 22:33:54 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-09-11 04:20:42 +08:00
|
|
|
strscpy(card->shortname, "cx25821", sizeof(card->shortname));
|
2009-09-13 22:30:11 +08:00
|
|
|
sprintf(card->longname, "%s at 0x%lx irq %d", chip->dev->name,
|
|
|
|
chip->iobase, chip->irq);
|
2018-09-11 04:20:42 +08:00
|
|
|
strscpy(card->mixername, "CX25821", sizeof(card->mixername));
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2011-10-22 12:43:24 +08:00
|
|
|
pr_info("%s/%i: ALSA support for cx25821 boards\n", card->driver,
|
|
|
|
devno);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
err = snd_card_register(card);
|
2009-09-13 22:30:11 +08:00
|
|
|
if (err < 0) {
|
2010-11-08 04:48:21 +08:00
|
|
|
pr_info("DEBUG ERROR: cannot register sound card %s\n",
|
|
|
|
__func__);
|
2009-09-15 22:33:54 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-04-13 18:07:40 +08:00
|
|
|
dev->card = card;
|
2009-09-15 22:33:54 +08:00
|
|
|
devno++;
|
|
|
|
return 0;
|
|
|
|
|
2010-03-14 23:44:37 +08:00
|
|
|
error:
|
2009-09-15 22:33:54 +08:00
|
|
|
snd_card_free(card);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
LINUX MODULE INIT
|
|
|
|
****************************************************************************/
|
2013-04-13 18:07:40 +08:00
|
|
|
|
|
|
|
static int cx25821_alsa_exit_callback(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
|
|
|
|
struct cx25821_dev *cxdev = get_cx25821(v4l2_dev);
|
|
|
|
|
|
|
|
snd_card_free(cxdev->card);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-15 22:33:54 +08:00
|
|
|
static void cx25821_audio_fini(void)
|
|
|
|
{
|
2013-04-13 18:07:40 +08:00
|
|
|
struct device_driver *drv = driver_find("cx25821", &pci_bus_type);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = driver_for_each_device(drv, NULL, NULL, cx25821_alsa_exit_callback);
|
2013-04-26 02:58:44 +08:00
|
|
|
if (ret)
|
|
|
|
pr_err("%s failed to find a cx25821 driver.\n", __func__);
|
2013-04-13 18:07:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cx25821_alsa_init_callback(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
|
|
|
|
struct cx25821_dev *cxdev = get_cx25821(v4l2_dev);
|
|
|
|
|
|
|
|
cx25821_audio_initdev(cxdev);
|
|
|
|
return 0;
|
2009-09-15 22:33:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module initializer
|
|
|
|
*
|
|
|
|
* Loops through present saa7134 cards, and assigns an ALSA device
|
|
|
|
* to each one
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int cx25821_alsa_init(void)
|
|
|
|
{
|
2013-04-13 18:07:40 +08:00
|
|
|
struct device_driver *drv = driver_find("cx25821", &pci_bus_type);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
2013-04-13 18:07:40 +08:00
|
|
|
return driver_for_each_device(drv, NULL, NULL, cx25821_alsa_init_callback);
|
2009-09-15 22:33:54 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
late_initcall(cx25821_alsa_init);
|
|
|
|
module_exit(cx25821_audio_fini);
|