2006-10-07 00:31:09 +08:00
|
|
|
/*
|
|
|
|
* soc-core.c -- ALSA SoC Audio Layer
|
|
|
|
*
|
|
|
|
* Copyright 2005 Wolfson Microelectronics PLC.
|
2006-12-18 21:39:02 +08:00
|
|
|
* Copyright 2005 Openedhand Ltd.
|
2010-03-18 04:15:21 +08:00
|
|
|
* Copyright (C) 2010 Slimlogic Ltd.
|
|
|
|
* Copyright (C) 2010 Texas Instruments Inc.
|
2006-12-18 21:39:02 +08:00
|
|
|
*
|
2008-10-12 20:17:36 +08:00
|
|
|
* Author: Liam Girdwood <lrg@slimlogic.co.uk>
|
2006-12-18 21:39:02 +08:00
|
|
|
* with code, comments and ideas from :-
|
|
|
|
* Richard Purdie <richard@openedhand.com>
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o Add hw rules to enforce rates, etc.
|
|
|
|
* o More testing with other codecs/machines.
|
|
|
|
* o Add more codecs and platforms to ensure good API coverage.
|
|
|
|
* o Support TDM on PCM and I2S
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/bitops.h>
|
2008-10-14 08:42:14 +08:00
|
|
|
#include <linux/debugfs.h>
|
2006-10-07 00:31:09 +08:00
|
|
|
#include <linux/platform_device.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-07-22 19:01:03 +08:00
|
|
|
#include <sound/ac97_codec.h>
|
2006-10-07 00:31:09 +08:00
|
|
|
#include <sound/core.h>
|
2010-12-05 20:22:46 +08:00
|
|
|
#include <sound/jack.h>
|
2006-10-07 00:31:09 +08:00
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
|
2010-11-04 06:05:58 +08:00
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include <trace/events/asoc.h>
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
#define NAME_SIZE 32
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
static DEFINE_MUTEX(pcm_mutex);
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
|
|
|
|
|
2008-12-04 01:34:03 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
static struct dentry *debugfs_root;
|
|
|
|
#endif
|
|
|
|
|
2008-11-28 21:29:45 +08:00
|
|
|
static DEFINE_MUTEX(client_mutex);
|
|
|
|
static LIST_HEAD(card_list);
|
2008-12-01 07:31:24 +08:00
|
|
|
static LIST_HEAD(dai_list);
|
2008-12-04 03:40:30 +08:00
|
|
|
static LIST_HEAD(platform_list);
|
2008-12-10 22:32:45 +08:00
|
|
|
static LIST_HEAD(codec_list);
|
2008-11-28 21:29:45 +08:00
|
|
|
|
|
|
|
static int snd_soc_register_card(struct snd_soc_card *card);
|
|
|
|
static int snd_soc_unregister_card(struct snd_soc_card *card);
|
2010-03-18 04:15:21 +08:00
|
|
|
static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
|
2008-11-28 21:29:45 +08:00
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/*
|
|
|
|
* This is a timeout to do a DAPM powerdown after a stream is closed().
|
|
|
|
* It can be used to eliminate pops between different playback streams, e.g.
|
|
|
|
* between two audio tracks.
|
|
|
|
*/
|
|
|
|
static int pmdown_time = 5000;
|
|
|
|
module_param(pmdown_time, int, 0);
|
|
|
|
MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
|
|
|
|
|
2009-11-04 05:56:13 +08:00
|
|
|
/* codec register dump */
|
|
|
|
static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
|
|
|
|
{
|
2010-07-14 23:14:33 +08:00
|
|
|
int ret, i, step = 1, count = 0;
|
2009-11-04 05:56:13 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (!codec->driver->reg_cache_size)
|
2009-11-04 05:56:13 +08:00
|
|
|
return 0;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec->driver->reg_cache_step)
|
|
|
|
step = codec->driver->reg_cache_step;
|
2009-11-04 05:56:13 +08:00
|
|
|
|
|
|
|
count += sprintf(buf, "%s registers\n", codec->name);
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < codec->driver->reg_cache_size; i += step) {
|
|
|
|
if (codec->driver->readable_register && !codec->driver->readable_register(i))
|
2009-11-04 05:56:13 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
count += sprintf(buf + count, "%2x: ", i);
|
|
|
|
if (count >= PAGE_SIZE - 1)
|
|
|
|
break;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec->driver->display_register) {
|
|
|
|
count += codec->driver->display_register(codec, buf + count,
|
2009-11-04 05:56:13 +08:00
|
|
|
PAGE_SIZE - count, i);
|
2010-07-14 23:14:33 +08:00
|
|
|
} else {
|
|
|
|
/* If the read fails it's almost certainly due to
|
|
|
|
* the register being volatile and the device being
|
|
|
|
* powered off.
|
|
|
|
*/
|
2010-12-08 00:30:38 +08:00
|
|
|
ret = snd_soc_read(codec, i);
|
2010-07-14 23:14:33 +08:00
|
|
|
if (ret >= 0)
|
|
|
|
count += snprintf(buf + count,
|
|
|
|
PAGE_SIZE - count,
|
|
|
|
"%4x", ret);
|
|
|
|
else
|
|
|
|
count += snprintf(buf + count,
|
|
|
|
PAGE_SIZE - count,
|
|
|
|
"<no data: %d>", ret);
|
|
|
|
}
|
2009-11-04 05:56:13 +08:00
|
|
|
|
|
|
|
if (count >= PAGE_SIZE - 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
count += snprintf(buf + count, PAGE_SIZE - count, "\n");
|
|
|
|
if (count >= PAGE_SIZE - 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Truncate count; min() would cause a warning */
|
|
|
|
if (count >= PAGE_SIZE)
|
|
|
|
count = PAGE_SIZE - 1;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
static ssize_t codec_reg_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd =
|
|
|
|
container_of(dev, struct snd_soc_pcm_runtime, dev);
|
|
|
|
|
|
|
|
return soc_codec_reg_show(rtd->codec, buf);
|
2009-11-04 05:56:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
|
|
|
|
|
2010-02-12 19:37:24 +08:00
|
|
|
static ssize_t pmdown_time_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd =
|
|
|
|
container_of(dev, struct snd_soc_pcm_runtime, dev);
|
2010-02-12 19:37:24 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
return sprintf(buf, "%ld\n", rtd->pmdown_time);
|
2010-02-12 19:37:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t pmdown_time_set(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd =
|
|
|
|
container_of(dev, struct snd_soc_pcm_runtime, dev);
|
2010-10-28 11:11:17 +08:00
|
|
|
int ret;
|
2010-02-12 19:37:24 +08:00
|
|
|
|
2010-10-28 11:11:17 +08:00
|
|
|
ret = strict_strtol(buf, 10, &rtd->pmdown_time);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-02-12 19:37:24 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
|
|
|
|
|
2009-11-04 05:56:13 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
static int codec_reg_open_file(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
file->private_data = inode->i_private;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
struct snd_soc_codec *codec = file->private_data;
|
|
|
|
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
ret = soc_codec_reg_show(codec, buf);
|
|
|
|
if (ret >= 0)
|
|
|
|
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
|
|
|
|
kfree(buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t codec_reg_write_file(struct file *file,
|
|
|
|
const char __user *user_buf, size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
int buf_size;
|
|
|
|
char *start = buf;
|
|
|
|
unsigned long reg, value;
|
|
|
|
int step = 1;
|
|
|
|
struct snd_soc_codec *codec = file->private_data;
|
|
|
|
|
|
|
|
buf_size = min(count, (sizeof(buf)-1));
|
|
|
|
if (copy_from_user(buf, user_buf, buf_size))
|
|
|
|
return -EFAULT;
|
|
|
|
buf[buf_size] = 0;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec->driver->reg_cache_step)
|
|
|
|
step = codec->driver->reg_cache_step;
|
2009-11-04 05:56:13 +08:00
|
|
|
|
|
|
|
while (*start == ' ')
|
|
|
|
start++;
|
|
|
|
reg = simple_strtoul(start, &start, 16);
|
2010-03-18 04:15:21 +08:00
|
|
|
if ((reg >= codec->driver->reg_cache_size) || (reg % step))
|
2009-11-04 05:56:13 +08:00
|
|
|
return -EINVAL;
|
|
|
|
while (*start == ' ')
|
|
|
|
start++;
|
|
|
|
if (strict_strtoul(start, 16, &value))
|
|
|
|
return -EINVAL;
|
2010-12-08 00:30:38 +08:00
|
|
|
snd_soc_write(codec, reg, value);
|
2009-11-04 05:56:13 +08:00
|
|
|
return buf_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations codec_reg_fops = {
|
|
|
|
.open = codec_reg_open_file,
|
|
|
|
.read = codec_reg_read_file,
|
|
|
|
.write = codec_reg_write_file,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = default_llseek,
|
2009-11-04 05:56:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
|
|
|
|
{
|
2010-11-06 02:35:20 +08:00
|
|
|
struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
|
|
|
|
|
|
|
|
codec->debugfs_codec_root = debugfs_create_dir(codec->name,
|
|
|
|
debugfs_card_root);
|
2009-11-04 05:56:13 +08:00
|
|
|
if (!codec->debugfs_codec_root) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"ASoC: Failed to create codec debugfs directory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
|
|
|
|
codec->debugfs_codec_root,
|
|
|
|
codec, &codec_reg_fops);
|
|
|
|
if (!codec->debugfs_reg)
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"ASoC: Failed to create codec register debugfs file\n");
|
|
|
|
|
2010-11-05 21:53:46 +08:00
|
|
|
codec->dapm.debugfs_dapm = debugfs_create_dir("dapm",
|
2009-11-04 05:56:13 +08:00
|
|
|
codec->debugfs_codec_root);
|
2010-11-05 21:53:46 +08:00
|
|
|
if (!codec->dapm.debugfs_dapm)
|
2009-11-04 05:56:13 +08:00
|
|
|
printk(KERN_WARNING
|
|
|
|
"Failed to create DAPM debugfs directory\n");
|
|
|
|
|
2010-11-05 21:53:46 +08:00
|
|
|
snd_soc_dapm_debugfs_init(&codec->dapm);
|
2009-11-04 05:56:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
debugfs_remove_recursive(codec->debugfs_codec_root);
|
|
|
|
}
|
|
|
|
|
2010-09-16 01:15:14 +08:00
|
|
|
static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
2010-10-13 17:52:16 +08:00
|
|
|
ssize_t len, ret = 0;
|
2010-09-16 01:15:14 +08:00
|
|
|
struct snd_soc_codec *codec;
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-10-13 17:52:16 +08:00
|
|
|
list_for_each_entry(codec, &codec_list, list) {
|
|
|
|
len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
|
|
|
|
codec->name);
|
|
|
|
if (len >= 0)
|
|
|
|
ret += len;
|
|
|
|
if (ret > PAGE_SIZE) {
|
|
|
|
ret = PAGE_SIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 01:15:14 +08:00
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations codec_list_fops = {
|
|
|
|
.read = codec_list_read_file,
|
|
|
|
.llseek = default_llseek,/* read accesses f_pos */
|
|
|
|
};
|
|
|
|
|
2010-09-16 01:19:07 +08:00
|
|
|
static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
2010-10-13 17:52:16 +08:00
|
|
|
ssize_t len, ret = 0;
|
2010-09-16 01:19:07 +08:00
|
|
|
struct snd_soc_dai *dai;
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-10-13 17:52:16 +08:00
|
|
|
list_for_each_entry(dai, &dai_list, list) {
|
|
|
|
len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
|
|
|
|
if (len >= 0)
|
|
|
|
ret += len;
|
|
|
|
if (ret > PAGE_SIZE) {
|
|
|
|
ret = PAGE_SIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 01:19:07 +08:00
|
|
|
|
2010-10-13 17:52:16 +08:00
|
|
|
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
|
2010-09-16 01:19:07 +08:00
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations dai_list_fops = {
|
|
|
|
.read = dai_list_read_file,
|
|
|
|
.llseek = default_llseek,/* read accesses f_pos */
|
|
|
|
};
|
|
|
|
|
2010-09-16 01:22:40 +08:00
|
|
|
static ssize_t platform_list_read_file(struct file *file,
|
|
|
|
char __user *user_buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
2010-10-13 17:52:16 +08:00
|
|
|
ssize_t len, ret = 0;
|
2010-09-16 01:22:40 +08:00
|
|
|
struct snd_soc_platform *platform;
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-10-13 17:52:16 +08:00
|
|
|
list_for_each_entry(platform, &platform_list, list) {
|
|
|
|
len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
|
|
|
|
platform->name);
|
|
|
|
if (len >= 0)
|
|
|
|
ret += len;
|
|
|
|
if (ret > PAGE_SIZE) {
|
|
|
|
ret = PAGE_SIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 01:22:40 +08:00
|
|
|
|
2010-10-13 17:52:16 +08:00
|
|
|
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
|
2010-09-16 01:22:40 +08:00
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations platform_list_fops = {
|
|
|
|
.read = platform_list_read_file,
|
|
|
|
.llseek = default_llseek,/* read accesses f_pos */
|
|
|
|
};
|
|
|
|
|
2010-11-06 02:35:19 +08:00
|
|
|
static void soc_init_card_debugfs(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
card->debugfs_card_root = debugfs_create_dir(card->name,
|
|
|
|
debugfs_root);
|
2010-11-06 02:35:21 +08:00
|
|
|
if (!card->debugfs_card_root) {
|
2010-11-06 02:35:19 +08:00
|
|
|
dev_warn(card->dev,
|
|
|
|
"ASoC: Failed to create codec debugfs directory\n");
|
2010-11-06 02:35:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
|
|
|
|
card->debugfs_card_root,
|
|
|
|
&card->pop_time);
|
|
|
|
if (!card->debugfs_pop_time)
|
|
|
|
dev_warn(card->dev,
|
|
|
|
"Failed to create pop time debugfs file\n");
|
2010-11-06 02:35:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
debugfs_remove_recursive(card->debugfs_card_root);
|
|
|
|
}
|
|
|
|
|
2009-11-04 05:56:13 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
}
|
2010-11-09 17:06:44 +08:00
|
|
|
|
|
|
|
static inline void soc_init_card_debugfs(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
}
|
2009-11-04 05:56:13 +08:00
|
|
|
#endif
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
#ifdef CONFIG_SND_SOC_AC97_BUS
|
|
|
|
/* unregister ac97 codec */
|
|
|
|
static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
if (codec->ac97->dev.bus)
|
|
|
|
device_unregister(&codec->ac97->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop no dev release warning */
|
|
|
|
static void soc_ac97_device_release(struct device *dev){}
|
|
|
|
|
|
|
|
/* register ac97 codec to bus */
|
|
|
|
static int soc_ac97_dev_register(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
codec->ac97->dev.bus = &ac97_bus_type;
|
2009-04-02 02:35:01 +08:00
|
|
|
codec->ac97->dev.parent = codec->card->dev;
|
2006-10-07 00:31:09 +08:00
|
|
|
codec->ac97->dev.release = soc_ac97_device_release;
|
|
|
|
|
2008-11-02 10:50:35 +08:00
|
|
|
dev_set_name(&codec->ac97->dev, "%d-%d:%s",
|
2010-03-18 04:15:21 +08:00
|
|
|
codec->card->snd_card->number, 0, codec->name);
|
2006-10-07 00:31:09 +08:00
|
|
|
err = device_register(&codec->ac97->dev);
|
|
|
|
if (err < 0) {
|
|
|
|
snd_printk(KERN_ERR "Can't register ac97 bus\n");
|
|
|
|
codec->ac97->dev.bus = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-08 01:10:13 +08:00
|
|
|
static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2009-04-08 01:10:13 +08:00
|
|
|
int ret;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->symmetric_rates || cpu_dai->driver->symmetric_rates ||
|
|
|
|
rtd->dai_link->symmetric_rates) {
|
|
|
|
dev_dbg(&rtd->dev, "Symmetry forces %dHz rate\n",
|
|
|
|
rtd->rate);
|
2009-04-08 01:10:13 +08:00
|
|
|
|
|
|
|
ret = snd_pcm_hw_constraint_minmax(substream->runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_RATE,
|
2010-03-18 04:15:21 +08:00
|
|
|
rtd->rate,
|
|
|
|
rtd->rate);
|
2009-04-08 01:10:13 +08:00
|
|
|
if (ret < 0) {
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_err(&rtd->dev,
|
2009-04-08 01:10:13 +08:00
|
|
|
"Unable to apply rate symmetry constraint: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/*
|
|
|
|
* Called by ALSA when a PCM substream is opened, the runtime->hw record is
|
|
|
|
* then initialized and any private data can be allocated. This also calls
|
|
|
|
* startup for the cpu DAI, platform, machine and codec DAI.
|
|
|
|
*/
|
|
|
|
static int soc_pcm_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
|
|
|
struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
|
|
|
|
struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
|
2006-10-07 00:31:09 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&pcm_mutex);
|
|
|
|
|
|
|
|
/* startup the audio subsystem */
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->startup) {
|
|
|
|
ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: can't open interface %s\n",
|
2007-02-03 00:13:49 +08:00
|
|
|
cpu_dai->name);
|
2006-10-07 00:31:09 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->open) {
|
|
|
|
ret = platform->driver->ops->open(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
|
|
|
|
goto platform_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->startup) {
|
|
|
|
ret = codec_dai->driver->ops->startup(substream, codec_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
2007-02-03 00:13:49 +08:00
|
|
|
printk(KERN_ERR "asoc: can't open codec %s\n",
|
|
|
|
codec_dai->name);
|
|
|
|
goto codec_dai_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
|
|
|
|
ret = rtd->dai_link->ops->startup(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
2010-03-18 04:15:21 +08:00
|
|
|
printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
|
2007-02-03 00:13:49 +08:00
|
|
|
goto machine_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 00:24:24 +08:00
|
|
|
/* Check that the codec and cpu DAIs are compatible */
|
2006-10-07 00:31:09 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
runtime->hw.rate_min =
|
2010-03-18 04:15:21 +08:00
|
|
|
max(codec_dai_drv->playback.rate_min,
|
|
|
|
cpu_dai_drv->playback.rate_min);
|
2006-10-07 00:31:09 +08:00
|
|
|
runtime->hw.rate_max =
|
2010-03-18 04:15:21 +08:00
|
|
|
min(codec_dai_drv->playback.rate_max,
|
|
|
|
cpu_dai_drv->playback.rate_max);
|
2006-10-07 00:31:09 +08:00
|
|
|
runtime->hw.channels_min =
|
2010-03-18 04:15:21 +08:00
|
|
|
max(codec_dai_drv->playback.channels_min,
|
|
|
|
cpu_dai_drv->playback.channels_min);
|
2006-10-07 00:31:09 +08:00
|
|
|
runtime->hw.channels_max =
|
2010-03-18 04:15:21 +08:00
|
|
|
min(codec_dai_drv->playback.channels_max,
|
|
|
|
cpu_dai_drv->playback.channels_max);
|
2007-02-03 00:13:49 +08:00
|
|
|
runtime->hw.formats =
|
2010-03-18 04:15:21 +08:00
|
|
|
codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
|
2007-02-03 00:13:49 +08:00
|
|
|
runtime->hw.rates =
|
2010-03-18 04:15:21 +08:00
|
|
|
codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
|
|
|
|
if (codec_dai_drv->playback.rates
|
2010-03-12 12:38:52 +08:00
|
|
|
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
|
2010-03-18 04:15:21 +08:00
|
|
|
runtime->hw.rates |= cpu_dai_drv->playback.rates;
|
|
|
|
if (cpu_dai_drv->playback.rates
|
2010-03-12 12:38:52 +08:00
|
|
|
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
|
2010-03-18 04:15:21 +08:00
|
|
|
runtime->hw.rates |= codec_dai_drv->playback.rates;
|
2006-10-07 00:31:09 +08:00
|
|
|
} else {
|
|
|
|
runtime->hw.rate_min =
|
2010-03-18 04:15:21 +08:00
|
|
|
max(codec_dai_drv->capture.rate_min,
|
|
|
|
cpu_dai_drv->capture.rate_min);
|
2006-10-07 00:31:09 +08:00
|
|
|
runtime->hw.rate_max =
|
2010-03-18 04:15:21 +08:00
|
|
|
min(codec_dai_drv->capture.rate_max,
|
|
|
|
cpu_dai_drv->capture.rate_max);
|
2006-10-07 00:31:09 +08:00
|
|
|
runtime->hw.channels_min =
|
2010-03-18 04:15:21 +08:00
|
|
|
max(codec_dai_drv->capture.channels_min,
|
|
|
|
cpu_dai_drv->capture.channels_min);
|
2006-10-07 00:31:09 +08:00
|
|
|
runtime->hw.channels_max =
|
2010-03-18 04:15:21 +08:00
|
|
|
min(codec_dai_drv->capture.channels_max,
|
|
|
|
cpu_dai_drv->capture.channels_max);
|
2007-02-03 00:13:49 +08:00
|
|
|
runtime->hw.formats =
|
2010-03-18 04:15:21 +08:00
|
|
|
codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
|
2007-02-03 00:13:49 +08:00
|
|
|
runtime->hw.rates =
|
2010-03-18 04:15:21 +08:00
|
|
|
codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
|
|
|
|
if (codec_dai_drv->capture.rates
|
2010-03-12 12:38:52 +08:00
|
|
|
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
|
2010-03-18 04:15:21 +08:00
|
|
|
runtime->hw.rates |= cpu_dai_drv->capture.rates;
|
|
|
|
if (cpu_dai_drv->capture.rates
|
2010-03-12 12:38:52 +08:00
|
|
|
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
|
2010-03-18 04:15:21 +08:00
|
|
|
runtime->hw.rates |= codec_dai_drv->capture.rates;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
snd_pcm_limit_hw_rates(runtime);
|
|
|
|
if (!runtime->hw.rates) {
|
|
|
|
printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
|
2007-02-03 00:13:49 +08:00
|
|
|
codec_dai->name, cpu_dai->name);
|
2010-02-25 10:24:53 +08:00
|
|
|
goto config_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
if (!runtime->hw.formats) {
|
|
|
|
printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
|
2007-02-03 00:13:49 +08:00
|
|
|
codec_dai->name, cpu_dai->name);
|
2010-02-25 10:24:53 +08:00
|
|
|
goto config_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
|
|
|
|
printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
|
2010-03-18 04:15:21 +08:00
|
|
|
codec_dai->name, cpu_dai->name);
|
2010-02-25 10:24:53 +08:00
|
|
|
goto config_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2009-04-08 01:10:13 +08:00
|
|
|
/* Symmetry only applies if we've already got an active stream. */
|
|
|
|
if (cpu_dai->active || codec_dai->active) {
|
|
|
|
ret = soc_pcm_apply_symmetry(substream);
|
|
|
|
if (ret != 0)
|
2010-02-25 10:24:53 +08:00
|
|
|
goto config_err;
|
2009-04-08 01:10:13 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
pr_debug("asoc: %s <-> %s info:\n",
|
|
|
|
codec_dai->name, cpu_dai->name);
|
2008-10-22 04:45:08 +08:00
|
|
|
pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
|
|
|
|
pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
|
|
|
|
runtime->hw.channels_max);
|
|
|
|
pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
|
|
|
|
runtime->hw.rate_max);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-02-26 08:12:32 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
2010-03-18 04:15:21 +08:00
|
|
|
cpu_dai->playback_active++;
|
|
|
|
codec_dai->playback_active++;
|
2010-02-26 08:12:32 +08:00
|
|
|
} else {
|
2010-03-18 04:15:21 +08:00
|
|
|
cpu_dai->capture_active++;
|
|
|
|
codec_dai->capture_active++;
|
2010-02-26 08:12:32 +08:00
|
|
|
}
|
|
|
|
cpu_dai->active++;
|
|
|
|
codec_dai->active++;
|
2010-03-18 04:15:21 +08:00
|
|
|
rtd->codec->active++;
|
2006-10-07 00:31:09 +08:00
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return 0;
|
|
|
|
|
2010-02-25 10:24:53 +08:00
|
|
|
config_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
|
|
|
|
rtd->dai_link->ops->shutdown(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-02-25 10:24:53 +08:00
|
|
|
machine_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->shutdown)
|
|
|
|
codec_dai->driver->ops->shutdown(substream, codec_dai);
|
2010-02-25 10:24:53 +08:00
|
|
|
|
2007-02-03 00:13:49 +08:00
|
|
|
codec_dai_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->close)
|
|
|
|
platform->driver->ops->close(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
platform_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->shutdown)
|
|
|
|
cpu_dai->driver->ops->shutdown(substream, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
out:
|
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-20 05:10:43 +08:00
|
|
|
* Power down the audio subsystem pmdown_time msecs after close is called.
|
2006-10-07 00:31:09 +08:00
|
|
|
* This is to ensure there are no pops or clicks in between any music tracks
|
|
|
|
* due to DAPM power cycling.
|
|
|
|
*/
|
2006-12-15 16:30:07 +08:00
|
|
|
static void close_delayed_work(struct work_struct *work)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd =
|
|
|
|
container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
mutex_lock(&pcm_mutex);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
pr_debug("pop wq checking: %s status: %s waiting: %s\n",
|
|
|
|
codec_dai->driver->playback.stream_name,
|
|
|
|
codec_dai->playback_active ? "active" : "inactive",
|
|
|
|
codec_dai->pop_wait ? "yes" : "no");
|
|
|
|
|
|
|
|
/* are we waiting on this codec DAI stream */
|
|
|
|
if (codec_dai->pop_wait == 1) {
|
|
|
|
codec_dai->pop_wait = 0;
|
|
|
|
snd_soc_dapm_stream_event(rtd,
|
|
|
|
codec_dai->driver->playback.stream_name,
|
|
|
|
SND_SOC_DAPM_STREAM_STOP);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by ALSA when a PCM substream is closed. Private data can be
|
|
|
|
* freed here. The cpu DAI, codec DAI, machine and platform are also
|
|
|
|
* shutdown.
|
|
|
|
*/
|
|
|
|
static int soc_codec_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
mutex_lock(&pcm_mutex);
|
|
|
|
|
2010-02-26 08:12:32 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
2010-03-18 04:15:21 +08:00
|
|
|
cpu_dai->playback_active--;
|
|
|
|
codec_dai->playback_active--;
|
2010-02-26 08:12:32 +08:00
|
|
|
} else {
|
2010-03-18 04:15:21 +08:00
|
|
|
cpu_dai->capture_active--;
|
|
|
|
codec_dai->capture_active--;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
2010-02-26 08:12:32 +08:00
|
|
|
|
|
|
|
cpu_dai->active--;
|
|
|
|
codec_dai->active--;
|
2006-10-07 00:31:09 +08:00
|
|
|
codec->active--;
|
|
|
|
|
2008-09-07 01:33:24 +08:00
|
|
|
/* Muting the DAC suppresses artifacts caused during digital
|
|
|
|
* shutdown, for example from stopping clocks.
|
|
|
|
*/
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
snd_soc_dai_digital_mute(codec_dai, 1);
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->shutdown)
|
|
|
|
cpu_dai->driver->ops->shutdown(substream, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->shutdown)
|
|
|
|
codec_dai->driver->ops->shutdown(substream, codec_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
|
|
|
|
rtd->dai_link->ops->shutdown(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->close)
|
|
|
|
platform->driver->ops->close(substream);
|
|
|
|
cpu_dai->runtime = NULL;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
/* start delayed pop wq here for playback streams */
|
2007-02-03 00:13:49 +08:00
|
|
|
codec_dai->pop_wait = 1;
|
2010-03-18 04:15:21 +08:00
|
|
|
schedule_delayed_work(&rtd->delayed_work,
|
|
|
|
msecs_to_jiffies(rtd->pmdown_time));
|
2006-10-07 00:31:09 +08:00
|
|
|
} else {
|
|
|
|
/* capture streams can be powered down now */
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_dapm_stream_event(rtd,
|
|
|
|
codec_dai->driver->capture.stream_name,
|
2008-01-10 21:36:20 +08:00
|
|
|
SND_SOC_DAPM_STREAM_STOP);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by ALSA when the PCM substream is prepared, can set format, sample
|
|
|
|
* rate, etc. This function is non atomic and can be called multiple times,
|
|
|
|
* it can refer to the runtime info.
|
|
|
|
*/
|
|
|
|
static int soc_pcm_prepare(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2006-10-07 00:31:09 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&pcm_mutex);
|
2007-02-03 00:13:49 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
|
|
|
|
ret = rtd->dai_link->ops->prepare(substream);
|
2007-02-03 00:13:49 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: machine prepare error\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->prepare) {
|
|
|
|
ret = platform->driver->ops->prepare(substream);
|
2006-10-20 02:35:56 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: platform prepare error\n");
|
2006-10-07 00:31:09 +08:00
|
|
|
goto out;
|
2006-10-20 02:35:56 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->prepare) {
|
|
|
|
ret = codec_dai->driver->ops->prepare(substream, codec_dai);
|
2006-10-20 02:35:56 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: codec DAI prepare error\n");
|
2006-10-07 00:31:09 +08:00
|
|
|
goto out;
|
2006-10-20 02:35:56 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->prepare) {
|
|
|
|
ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
|
2007-02-03 00:13:49 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: cpu DAI prepare error\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-10-14 20:58:36 +08:00
|
|
|
/* cancel any delayed stream shutdown that is pending */
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
|
|
|
|
codec_dai->pop_wait) {
|
|
|
|
codec_dai->pop_wait = 0;
|
2010-03-18 04:15:21 +08:00
|
|
|
cancel_delayed_work(&rtd->delayed_work);
|
2008-10-14 20:58:36 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2009-05-18 04:41:23 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_dapm_stream_event(rtd,
|
|
|
|
codec_dai->driver->playback.stream_name,
|
2009-05-18 04:41:23 +08:00
|
|
|
SND_SOC_DAPM_STREAM_START);
|
|
|
|
else
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_dapm_stream_event(rtd,
|
|
|
|
codec_dai->driver->capture.stream_name,
|
2009-05-18 04:41:23 +08:00
|
|
|
SND_SOC_DAPM_STREAM_START);
|
2008-07-08 20:19:13 +08:00
|
|
|
|
2009-05-18 04:41:23 +08:00
|
|
|
snd_soc_dai_digital_mute(codec_dai, 0);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by ALSA when the hardware params are set by application. This
|
|
|
|
* function can also be called multiple times and can allocate buffers
|
|
|
|
* (using snd_pcm_lib_* ). It's non-atomic.
|
|
|
|
*/
|
|
|
|
static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2006-10-07 00:31:09 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&pcm_mutex);
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
|
|
|
|
ret = rtd->dai_link->ops->hw_params(substream, params);
|
2007-02-03 00:13:49 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: machine hw_params failed\n");
|
2006-10-07 00:31:09 +08:00
|
|
|
goto out;
|
2007-02-03 00:13:49 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->hw_params) {
|
|
|
|
ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: can't set codec %s hw params\n",
|
2007-02-03 00:13:49 +08:00
|
|
|
codec_dai->name);
|
|
|
|
goto codec_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->hw_params) {
|
|
|
|
ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
2008-05-19 18:32:25 +08:00
|
|
|
printk(KERN_ERR "asoc: interface %s hw params failed\n",
|
2007-02-03 00:13:49 +08:00
|
|
|
cpu_dai->name);
|
2006-10-07 00:31:09 +08:00
|
|
|
goto interface_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->hw_params) {
|
|
|
|
ret = platform->driver->ops->hw_params(substream, params);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
2008-05-19 18:32:25 +08:00
|
|
|
printk(KERN_ERR "asoc: platform %s hw params failed\n",
|
2006-10-07 00:31:09 +08:00
|
|
|
platform->name);
|
|
|
|
goto platform_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
rtd->rate = params_rate(params);
|
2009-04-08 01:10:13 +08:00
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
out:
|
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
platform_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->hw_free)
|
|
|
|
cpu_dai->driver->ops->hw_free(substream, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
interface_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->hw_free)
|
|
|
|
codec_dai->driver->ops->hw_free(substream, codec_dai);
|
2007-02-03 00:13:49 +08:00
|
|
|
|
|
|
|
codec_err:
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
|
|
|
|
rtd->dai_link->ops->hw_free(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-12-03 00:24:24 +08:00
|
|
|
* Frees resources allocated by hw_params, can be called multiple times
|
2006-10-07 00:31:09 +08:00
|
|
|
*/
|
|
|
|
static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
mutex_lock(&pcm_mutex);
|
|
|
|
|
|
|
|
/* apply codec digital mute */
|
2008-07-08 20:19:13 +08:00
|
|
|
if (!codec->active)
|
|
|
|
snd_soc_dai_digital_mute(codec_dai, 1);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
/* free any machine hw params */
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
|
|
|
|
rtd->dai_link->ops->hw_free(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
/* free any DMA resources */
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->hw_free)
|
|
|
|
platform->driver->ops->hw_free(substream);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-12-03 00:24:24 +08:00
|
|
|
/* now free hw params for the DAIs */
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->hw_free)
|
|
|
|
codec_dai->driver->ops->hw_free(substream, codec_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->hw_free)
|
|
|
|
cpu_dai->driver->ops->hw_free(substream, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
mutex_unlock(&pcm_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2006-10-07 00:31:09 +08:00
|
|
|
int ret;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->trigger) {
|
|
|
|
ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->trigger) {
|
|
|
|
ret = platform->driver->ops->trigger(substream, cmd);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->trigger) {
|
|
|
|
ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-03 21:08:06 +08:00
|
|
|
/*
|
|
|
|
* soc level wrapper for pointer callback
|
2010-03-03 21:08:07 +08:00
|
|
|
* If cpu_dai, codec_dai, platform driver has the delay callback, than
|
|
|
|
* the runtime->delay will be updated accordingly.
|
2010-03-03 21:08:06 +08:00
|
|
|
*/
|
|
|
|
static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
2010-03-03 21:08:07 +08:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2010-03-03 21:08:06 +08:00
|
|
|
snd_pcm_uframes_t offset = 0;
|
2010-03-03 21:08:07 +08:00
|
|
|
snd_pcm_sframes_t delay = 0;
|
2010-03-03 21:08:06 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->ops->pointer)
|
|
|
|
offset = platform->driver->ops->pointer(substream);
|
2010-03-03 21:08:06 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->ops->delay)
|
|
|
|
delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
|
2010-03-03 21:08:07 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->ops->delay)
|
|
|
|
delay += codec_dai->driver->ops->delay(substream, codec_dai);
|
2010-03-03 21:08:07 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (platform->driver->delay)
|
|
|
|
delay += platform->driver->delay(substream, codec_dai);
|
2010-03-03 21:08:07 +08:00
|
|
|
|
|
|
|
runtime->delay = delay;
|
|
|
|
|
2010-03-03 21:08:06 +08:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/* ASoC PCM operations */
|
|
|
|
static struct snd_pcm_ops soc_pcm_ops = {
|
|
|
|
.open = soc_pcm_open,
|
|
|
|
.close = soc_codec_close,
|
|
|
|
.hw_params = soc_pcm_hw_params,
|
|
|
|
.hw_free = soc_pcm_hw_free,
|
|
|
|
.prepare = soc_pcm_prepare,
|
|
|
|
.trigger = soc_pcm_trigger,
|
2010-03-03 21:08:06 +08:00
|
|
|
.pointer = soc_pcm_pointer,
|
2006-10-07 00:31:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
/* powers down audio subsystem for suspend */
|
2009-07-01 02:05:15 +08:00
|
|
|
static int soc_suspend(struct device *dev)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
2009-07-01 02:05:15 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
2010-11-25 23:47:38 +08:00
|
|
|
struct snd_soc_codec *codec;
|
2006-10-07 00:31:09 +08:00
|
|
|
int i;
|
|
|
|
|
2009-06-03 23:44:49 +08:00
|
|
|
/* If the initialization of this soc device failed, there is no codec
|
|
|
|
* associated with it. Just bail out in this case.
|
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
if (list_empty(&card->codec_dev_list))
|
2009-06-03 23:44:49 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-06-13 23:24:05 +08:00
|
|
|
/* Due to the resume being scheduled into a workqueue we could
|
|
|
|
* suspend before that's finished - wait for it to complete.
|
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_power_lock(card->snd_card);
|
|
|
|
snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
|
|
|
|
snd_power_unlock(card->snd_card);
|
2008-06-13 23:24:05 +08:00
|
|
|
|
|
|
|
/* we're going to block userspace touching us until resume completes */
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
|
2008-06-13 23:24:05 +08:00
|
|
|
|
2010-12-03 00:24:24 +08:00
|
|
|
/* mute any active DACs */
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *dai = card->rtd[i].codec_dai;
|
|
|
|
struct snd_soc_dai_driver *drv = dai->driver;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (drv->ops->digital_mute && dai->playback_active)
|
|
|
|
drv->ops->digital_mute(dai, 1);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2008-01-10 21:39:01 +08:00
|
|
|
/* suspend all pcms */
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_pcm_suspend_all(card->rtd[i].pcm);
|
2010-05-09 20:25:43 +08:00
|
|
|
}
|
2008-01-10 21:39:01 +08:00
|
|
|
|
2008-11-19 04:50:34 +08:00
|
|
|
if (card->suspend_pre)
|
2009-07-01 02:05:15 +08:00
|
|
|
card->suspend_pre(pdev, PMSG_SUSPEND);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
|
|
|
|
struct snd_soc_platform *platform = card->rtd[i].platform;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
|
|
|
|
cpu_dai->driver->suspend(cpu_dai);
|
|
|
|
if (platform->driver->suspend && !platform->suspended) {
|
|
|
|
platform->driver->suspend(cpu_dai);
|
|
|
|
platform->suspended = 1;
|
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* close any waiting streams and save state */
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
2010-12-12 00:51:26 +08:00
|
|
|
flush_delayed_work_sync(&card->rtd[i].delayed_work);
|
2010-11-05 21:53:46 +08:00
|
|
|
card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (driver->playback.stream_name != NULL)
|
|
|
|
snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
|
2006-10-07 00:31:09 +08:00
|
|
|
SND_SOC_DAPM_STREAM_SUSPEND);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
if (driver->capture.stream_name != NULL)
|
|
|
|
snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
|
2006-10-07 00:31:09 +08:00
|
|
|
SND_SOC_DAPM_STREAM_SUSPEND);
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* suspend all CODECs */
|
2010-11-25 23:47:38 +08:00
|
|
|
list_for_each_entry(codec, &card->codec_dev_list, card_list) {
|
2010-03-18 04:15:21 +08:00
|
|
|
/* If there are paths active then the CODEC will be held with
|
|
|
|
* bias _ON and should not be suspended. */
|
|
|
|
if (!codec->suspended && codec->driver->suspend) {
|
2010-11-05 21:53:46 +08:00
|
|
|
switch (codec->dapm.bias_level) {
|
2010-03-18 04:15:21 +08:00
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
codec->driver->suspend(codec, PMSG_SUSPEND);
|
|
|
|
codec->suspended = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_dbg(codec->dev, "CODEC is on over suspend\n");
|
|
|
|
break;
|
|
|
|
}
|
2010-05-08 04:11:40 +08:00
|
|
|
}
|
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
|
|
|
|
cpu_dai->driver->suspend(cpu_dai);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2008-11-19 04:50:34 +08:00
|
|
|
if (card->suspend_post)
|
2009-07-01 02:05:15 +08:00
|
|
|
card->suspend_post(pdev, PMSG_SUSPEND);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-13 23:24:05 +08:00
|
|
|
/* deferred resume work, so resume can complete before we finished
|
|
|
|
* setting our codec back up, which can be very slow on I2C
|
|
|
|
*/
|
|
|
|
static void soc_resume_deferred(struct work_struct *work)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_card *card =
|
|
|
|
container_of(work, struct snd_soc_card, deferred_resume_work);
|
|
|
|
struct platform_device *pdev = to_platform_device(card->dev);
|
2010-11-25 23:47:38 +08:00
|
|
|
struct snd_soc_codec *codec;
|
2006-10-07 00:31:09 +08:00
|
|
|
int i;
|
|
|
|
|
2008-06-13 23:24:05 +08:00
|
|
|
/* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
|
|
|
|
* so userspace apps are blocked from touching us
|
|
|
|
*/
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(card->dev, "starting resume work\n");
|
2008-06-13 23:24:05 +08:00
|
|
|
|
2010-05-08 03:24:05 +08:00
|
|
|
/* Bring us up into D2 so that DAPM starts enabling things */
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
|
2010-05-08 03:24:05 +08:00
|
|
|
|
2008-11-19 04:50:34 +08:00
|
|
|
if (card->resume_pre)
|
|
|
|
card->resume_pre(pdev);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* resume AC97 DAIs */
|
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
|
|
|
|
cpu_dai->driver->resume(cpu_dai);
|
|
|
|
}
|
|
|
|
|
2010-11-25 23:47:38 +08:00
|
|
|
list_for_each_entry(codec, &card->codec_dev_list, card_list) {
|
2010-03-18 04:15:21 +08:00
|
|
|
/* If the CODEC was idle over suspend then it will have been
|
|
|
|
* left with bias OFF or STANDBY and suspended so we must now
|
|
|
|
* resume. Otherwise the suspend was suppressed.
|
|
|
|
*/
|
|
|
|
if (codec->driver->resume && codec->suspended) {
|
2010-11-05 21:53:46 +08:00
|
|
|
switch (codec->dapm.bias_level) {
|
2010-03-18 04:15:21 +08:00
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
codec->driver->resume(codec);
|
|
|
|
codec->suspended = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_dbg(codec->dev, "CODEC was on over suspend\n");
|
|
|
|
break;
|
|
|
|
}
|
2010-05-08 04:11:40 +08:00
|
|
|
}
|
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (driver->playback.stream_name != NULL)
|
|
|
|
snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
|
2006-10-07 00:31:09 +08:00
|
|
|
SND_SOC_DAPM_STREAM_RESUME);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
if (driver->capture.stream_name != NULL)
|
|
|
|
snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
|
2006-10-07 00:31:09 +08:00
|
|
|
SND_SOC_DAPM_STREAM_RESUME);
|
|
|
|
}
|
|
|
|
|
2008-05-19 18:32:25 +08:00
|
|
|
/* unmute any active DACs */
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *dai = card->rtd[i].codec_dai;
|
|
|
|
struct snd_soc_dai_driver *drv = dai->driver;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (drv->ops->digital_mute && dai->playback_active)
|
|
|
|
drv->ops->digital_mute(dai, 0);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
|
|
|
|
struct snd_soc_platform *platform = card->rtd[i].platform;
|
2010-05-09 20:25:43 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd[i].dai_link->ignore_suspend)
|
2010-05-09 20:25:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
|
|
|
|
cpu_dai->driver->resume(cpu_dai);
|
|
|
|
if (platform->driver->resume && platform->suspended) {
|
|
|
|
platform->driver->resume(cpu_dai);
|
|
|
|
platform->suspended = 0;
|
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2008-11-19 04:50:34 +08:00
|
|
|
if (card->resume_post)
|
|
|
|
card->resume_post(pdev);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(card->dev, "resume work completed\n");
|
2008-06-13 23:24:05 +08:00
|
|
|
|
|
|
|
/* userspace can access us now we are back as we were before */
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
|
2008-06-13 23:24:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* powers up audio subsystem after a suspend */
|
2009-07-01 02:05:15 +08:00
|
|
|
static int soc_resume(struct device *dev)
|
2008-06-13 23:24:05 +08:00
|
|
|
{
|
2009-07-01 02:05:15 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
|
|
|
int i;
|
2010-02-22 19:27:13 +08:00
|
|
|
|
2009-03-31 18:27:03 +08:00
|
|
|
/* AC97 devices might have other drivers hanging off them so
|
|
|
|
* need to resume immediately. Other drivers don't have that
|
|
|
|
* problem and may take a substantial amount of time to resume
|
|
|
|
* due to I/O costs and anti-pop so handle them out of line.
|
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
|
|
|
|
if (cpu_dai->driver->ac97_control) {
|
|
|
|
dev_dbg(dev, "Resuming AC97 immediately\n");
|
|
|
|
soc_resume_deferred(&card->deferred_resume_work);
|
|
|
|
} else {
|
|
|
|
dev_dbg(dev, "Scheduling resume work\n");
|
|
|
|
if (!schedule_work(&card->deferred_resume_work))
|
|
|
|
dev_err(dev, "resume work item may be lost\n");
|
|
|
|
}
|
2009-03-31 18:27:03 +08:00
|
|
|
}
|
2008-06-13 23:24:05 +08:00
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define soc_suspend NULL
|
|
|
|
#define soc_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2009-10-16 18:13:38 +08:00
|
|
|
static struct snd_soc_dai_ops null_dai_ops = {
|
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int soc_bind_dai_link(struct snd_soc_card *card, int num)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai_link *dai_link = &card->dai_link[num];
|
|
|
|
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
|
2009-11-04 06:13:13 +08:00
|
|
|
struct snd_soc_codec *codec;
|
2008-12-04 23:32:53 +08:00
|
|
|
struct snd_soc_platform *platform;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai *codec_dai, *cpu_dai;
|
2008-12-04 23:32:53 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->complete)
|
|
|
|
return 1;
|
|
|
|
dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
|
2008-12-04 23:32:53 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* do we already have the CPU DAI for this link ? */
|
|
|
|
if (rtd->cpu_dai) {
|
|
|
|
goto find_codec;
|
|
|
|
}
|
|
|
|
/* no, then find CPU DAI from registered DAIs*/
|
|
|
|
list_for_each_entry(cpu_dai, &dai_list, list) {
|
|
|
|
if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) {
|
|
|
|
|
|
|
|
if (!try_module_get(cpu_dai->dev->driver->owner))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
rtd->cpu_dai = cpu_dai;
|
|
|
|
goto find_codec;
|
2008-12-04 23:32:53 +08:00
|
|
|
}
|
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(card->dev, "CPU DAI %s not registered\n",
|
|
|
|
dai_link->cpu_dai_name);
|
2008-12-02 23:08:03 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
find_codec:
|
|
|
|
/* do we already have the CODEC for this link ? */
|
|
|
|
if (rtd->codec) {
|
|
|
|
goto find_platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no, then find CODEC from registered CODECs*/
|
|
|
|
list_for_each_entry(codec, &codec_list, list) {
|
|
|
|
if (!strcmp(codec->name, dai_link->codec_name)) {
|
|
|
|
rtd->codec = codec;
|
|
|
|
|
|
|
|
/* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
|
|
|
|
list_for_each_entry(codec_dai, &dai_list, list) {
|
|
|
|
if (codec->dev == codec_dai->dev &&
|
|
|
|
!strcmp(codec_dai->name, dai_link->codec_dai_name)) {
|
|
|
|
rtd->codec_dai = codec_dai;
|
|
|
|
goto find_platform;
|
|
|
|
}
|
2008-12-04 23:32:53 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(card->dev, "CODEC DAI %s not registered\n",
|
|
|
|
dai_link->codec_dai_name);
|
|
|
|
|
|
|
|
goto find_platform;
|
2008-12-04 23:32:53 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
|
|
|
dev_dbg(card->dev, "CODEC %s not registered\n",
|
|
|
|
dai_link->codec_name);
|
2008-12-09 03:26:48 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
find_platform:
|
|
|
|
/* do we already have the CODEC DAI for this link ? */
|
|
|
|
if (rtd->platform) {
|
|
|
|
goto out;
|
2008-11-28 21:29:45 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
/* no, then find CPU DAI from registered DAIs*/
|
|
|
|
list_for_each_entry(platform, &platform_list, list) {
|
|
|
|
if (!strcmp(platform->name, dai_link->platform_name)) {
|
|
|
|
rtd->platform = platform;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-16 18:13:38 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(card->dev, "platform %s not registered\n",
|
|
|
|
dai_link->platform_name);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* mark rtd as complete if we found all 4 of our client devices */
|
|
|
|
if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
|
|
|
|
rtd->complete = 1;
|
|
|
|
card->num_rtd++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
static void soc_remove_codec(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (codec->driver->remove) {
|
|
|
|
err = codec->driver->remove(codec);
|
|
|
|
if (err < 0)
|
|
|
|
dev_err(codec->dev,
|
|
|
|
"asoc: failed to remove %s: %d\n",
|
|
|
|
codec->name, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure all DAPM widgets are freed */
|
|
|
|
snd_soc_dapm_free(&codec->dapm);
|
|
|
|
|
|
|
|
soc_cleanup_codec_debugfs(codec);
|
|
|
|
codec->probed = 0;
|
|
|
|
list_del(&codec->card_list);
|
|
|
|
module_put(codec->dev->driver->owner);
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static void soc_remove_dai_link(struct snd_soc_card *card, int num)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
|
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* unregister the rtd device */
|
|
|
|
if (rtd->dev_registered) {
|
|
|
|
device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
|
2010-12-06 22:27:07 +08:00
|
|
|
device_remove_file(&rtd->dev, &dev_attr_codec_reg);
|
2010-03-18 04:15:21 +08:00
|
|
|
device_unregister(&rtd->dev);
|
|
|
|
rtd->dev_registered = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the CODEC DAI */
|
|
|
|
if (codec_dai && codec_dai->probed) {
|
|
|
|
if (codec_dai->driver->remove) {
|
|
|
|
err = codec_dai->driver->remove(codec_dai);
|
|
|
|
if (err < 0)
|
|
|
|
printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
|
2008-12-09 03:26:48 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
codec_dai->probed = 0;
|
|
|
|
list_del(&codec_dai->card_list);
|
|
|
|
}
|
2008-12-09 03:26:48 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* remove the platform */
|
|
|
|
if (platform && platform->probed) {
|
|
|
|
if (platform->driver->remove) {
|
|
|
|
err = platform->driver->remove(platform);
|
|
|
|
if (err < 0)
|
|
|
|
printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
|
|
|
|
}
|
|
|
|
platform->probed = 0;
|
|
|
|
list_del(&platform->card_list);
|
|
|
|
module_put(platform->dev->driver->owner);
|
|
|
|
}
|
2008-12-04 23:32:53 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* remove the CODEC */
|
2010-12-06 22:27:07 +08:00
|
|
|
if (codec && codec->probed)
|
|
|
|
soc_remove_codec(codec);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* remove the cpu_dai */
|
|
|
|
if (cpu_dai && cpu_dai->probed) {
|
|
|
|
if (cpu_dai->driver->remove) {
|
|
|
|
err = cpu_dai->driver->remove(cpu_dai);
|
|
|
|
if (err < 0)
|
|
|
|
printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
cpu_dai->probed = 0;
|
|
|
|
list_del(&cpu_dai->card_list);
|
|
|
|
module_put(cpu_dai->dev->driver->owner);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in
an ASoC machine that has multiple codecs with conflicting names. The name
collision would occur when codec drivers try to registering kcontrols with
the same name or when building audio paths.
This patch introduces optional prefix_map into struct snd_soc_card. With it
machine drivers can specify a unique name prefix to each codec that have
conflicting names with anothers. Prefix to codec is matched with codec
name.
Following example illustrates a machine that has two same codec instances.
Name collision from kcontrol registration is avoided by specifying a name
prefix "foo" for the second codec. As the codec widget names are prefixed
then second audio map for that codec shows a prefixed widget name.
static const struct snd_soc_dapm_route map0[] = {
{"Spk", NULL, "MONO"},
};
static const struct snd_soc_dapm_route map1[] = {
{"Vibra", NULL, "foo MONO"},
};
static struct snd_soc_prefix_map codec_prefix[] = {
{
.dev_name = "codec.2",
.name_prefix = "foo",
},
};
static struct snd_soc_card card = {
...
.prefix_map = codec_prefix,
.num_prefixes = ARRAY_SIZE(codec_prefix),
};
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2010-11-14 02:40:44 +08:00
|
|
|
static void soc_set_name_prefix(struct snd_soc_card *card,
|
|
|
|
struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-12-02 22:53:03 +08:00
|
|
|
if (card->codec_conf == NULL)
|
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in
an ASoC machine that has multiple codecs with conflicting names. The name
collision would occur when codec drivers try to registering kcontrols with
the same name or when building audio paths.
This patch introduces optional prefix_map into struct snd_soc_card. With it
machine drivers can specify a unique name prefix to each codec that have
conflicting names with anothers. Prefix to codec is matched with codec
name.
Following example illustrates a machine that has two same codec instances.
Name collision from kcontrol registration is avoided by specifying a name
prefix "foo" for the second codec. As the codec widget names are prefixed
then second audio map for that codec shows a prefixed widget name.
static const struct snd_soc_dapm_route map0[] = {
{"Spk", NULL, "MONO"},
};
static const struct snd_soc_dapm_route map1[] = {
{"Vibra", NULL, "foo MONO"},
};
static struct snd_soc_prefix_map codec_prefix[] = {
{
.dev_name = "codec.2",
.name_prefix = "foo",
},
};
static struct snd_soc_card card = {
...
.prefix_map = codec_prefix,
.num_prefixes = ARRAY_SIZE(codec_prefix),
};
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2010-11-14 02:40:44 +08:00
|
|
|
return;
|
|
|
|
|
2010-12-02 22:53:03 +08:00
|
|
|
for (i = 0; i < card->num_configs; i++) {
|
|
|
|
struct snd_soc_codec_conf *map = &card->codec_conf[i];
|
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in
an ASoC machine that has multiple codecs with conflicting names. The name
collision would occur when codec drivers try to registering kcontrols with
the same name or when building audio paths.
This patch introduces optional prefix_map into struct snd_soc_card. With it
machine drivers can specify a unique name prefix to each codec that have
conflicting names with anothers. Prefix to codec is matched with codec
name.
Following example illustrates a machine that has two same codec instances.
Name collision from kcontrol registration is avoided by specifying a name
prefix "foo" for the second codec. As the codec widget names are prefixed
then second audio map for that codec shows a prefixed widget name.
static const struct snd_soc_dapm_route map0[] = {
{"Spk", NULL, "MONO"},
};
static const struct snd_soc_dapm_route map1[] = {
{"Vibra", NULL, "foo MONO"},
};
static struct snd_soc_prefix_map codec_prefix[] = {
{
.dev_name = "codec.2",
.name_prefix = "foo",
},
};
static struct snd_soc_card card = {
...
.prefix_map = codec_prefix,
.num_prefixes = ARRAY_SIZE(codec_prefix),
};
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2010-11-14 02:40:44 +08:00
|
|
|
if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
|
|
|
|
codec->name_prefix = map->name_prefix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
static int soc_probe_codec(struct snd_soc_card *card,
|
|
|
|
struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
codec->card = card;
|
|
|
|
codec->dapm.card = card;
|
|
|
|
soc_set_name_prefix(card, codec);
|
|
|
|
|
|
|
|
if (codec->driver->probe) {
|
|
|
|
ret = codec->driver->probe(codec);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(codec->dev,
|
|
|
|
"asoc: failed to probe CODEC %s: %d\n",
|
|
|
|
codec->name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
soc_init_codec_debugfs(codec);
|
|
|
|
|
|
|
|
/* mark codec as probed and add to card codec list */
|
2011-01-05 14:04:51 +08:00
|
|
|
if (!try_module_get(codec->dev->driver->owner))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
codec->probed = 1;
|
|
|
|
list_add(&codec->card_list, &card->codec_dev_list);
|
2010-12-14 18:18:32 +08:00
|
|
|
list_add(&codec->dapm.list, &card->dapm_list);
|
2010-12-06 22:27:07 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static void rtd_release(struct device *dev) {}
|
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
static int soc_post_component_init(struct snd_soc_card *card,
|
|
|
|
struct snd_soc_codec *codec,
|
|
|
|
int num, int dailess)
|
|
|
|
{
|
|
|
|
struct snd_soc_dai_link *dai_link = NULL;
|
|
|
|
struct snd_soc_aux_dev *aux_dev = NULL;
|
|
|
|
struct snd_soc_pcm_runtime *rtd;
|
|
|
|
const char *temp, *name;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!dailess) {
|
|
|
|
dai_link = &card->dai_link[num];
|
|
|
|
rtd = &card->rtd[num];
|
|
|
|
name = dai_link->name;
|
|
|
|
} else {
|
|
|
|
aux_dev = &card->aux_dev[num];
|
|
|
|
rtd = &card->rtd_aux[num];
|
|
|
|
name = aux_dev->name;
|
|
|
|
}
|
2011-02-03 04:11:41 +08:00
|
|
|
rtd->card = card;
|
2010-12-06 22:27:07 +08:00
|
|
|
|
|
|
|
/* machine controls, routes and widgets are not prefixed */
|
|
|
|
temp = codec->name_prefix;
|
|
|
|
codec->name_prefix = NULL;
|
|
|
|
|
|
|
|
/* do machine specific initialization */
|
|
|
|
if (!dailess && dai_link->init)
|
|
|
|
ret = dai_link->init(rtd);
|
|
|
|
else if (dailess && aux_dev->init)
|
|
|
|
ret = aux_dev->init(&codec->dapm);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
codec->name_prefix = temp;
|
|
|
|
|
|
|
|
/* Make sure all DAPM widgets are instantiated */
|
|
|
|
snd_soc_dapm_new_widgets(&codec->dapm);
|
|
|
|
snd_soc_dapm_sync(&codec->dapm);
|
|
|
|
|
|
|
|
/* register the rtd device */
|
|
|
|
rtd->codec = codec;
|
|
|
|
rtd->dev.parent = card->dev;
|
|
|
|
rtd->dev.release = rtd_release;
|
|
|
|
rtd->dev.init_name = name;
|
|
|
|
ret = device_register(&rtd->dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(card->dev,
|
|
|
|
"asoc: failed to register runtime device: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
rtd->dev_registered = 1;
|
|
|
|
|
|
|
|
/* add DAPM sysfs entries for this codec */
|
|
|
|
ret = snd_soc_dapm_sys_add(&rtd->dev);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(codec->dev,
|
|
|
|
"asoc: failed to add codec dapm sysfs entries: %d\n",
|
|
|
|
ret);
|
|
|
|
|
|
|
|
/* add codec sysfs entries */
|
|
|
|
ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(codec->dev,
|
|
|
|
"asoc: failed to add codec sysfs files: %d\n", ret);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int soc_probe_dai_link(struct snd_soc_card *card, int num)
|
|
|
|
{
|
|
|
|
struct snd_soc_dai_link *dai_link = &card->dai_link[num];
|
|
|
|
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
|
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num);
|
|
|
|
|
|
|
|
/* config components */
|
|
|
|
codec_dai->codec = codec;
|
|
|
|
cpu_dai->platform = platform;
|
|
|
|
codec_dai->card = card;
|
|
|
|
cpu_dai->card = card;
|
|
|
|
|
|
|
|
/* set default power off timeout */
|
|
|
|
rtd->pmdown_time = pmdown_time;
|
|
|
|
|
|
|
|
/* probe the cpu_dai */
|
|
|
|
if (!cpu_dai->probed) {
|
|
|
|
if (cpu_dai->driver->probe) {
|
|
|
|
ret = cpu_dai->driver->probe(cpu_dai);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
|
|
|
|
cpu_dai->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cpu_dai->probed = 1;
|
|
|
|
/* mark cpu_dai as probed and add to card cpu_dai list */
|
|
|
|
list_add(&cpu_dai->card_list, &card->dai_dev_list);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* probe the CODEC */
|
|
|
|
if (!codec->probed) {
|
2010-12-06 22:27:07 +08:00
|
|
|
ret = soc_probe_codec(card, codec);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* probe the platform */
|
|
|
|
if (!platform->probed) {
|
|
|
|
if (platform->driver->probe) {
|
|
|
|
ret = platform->driver->probe(platform);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: failed to probe platform %s\n",
|
|
|
|
platform->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* mark platform as probed and add to card platform list */
|
2011-01-05 14:04:51 +08:00
|
|
|
|
|
|
|
if (!try_module_get(platform->dev->driver->owner))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
platform->probed = 1;
|
|
|
|
list_add(&platform->card_list, &card->platform_dev_list);
|
|
|
|
}
|
2008-06-13 23:24:05 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* probe the CODEC DAI */
|
|
|
|
if (!codec_dai->probed) {
|
|
|
|
if (codec_dai->driver->probe) {
|
|
|
|
ret = codec_dai->driver->probe(codec_dai);
|
2009-11-04 06:13:13 +08:00
|
|
|
if (ret < 0) {
|
2010-03-18 04:15:21 +08:00
|
|
|
printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
|
|
|
|
codec_dai->name);
|
|
|
|
return ret;
|
2009-11-04 06:13:13 +08:00
|
|
|
}
|
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
/* mark cpu_dai as probed and add to card cpu_dai list */
|
|
|
|
codec_dai->probed = 1;
|
|
|
|
list_add(&codec_dai->card_list, &card->dai_dev_list);
|
2009-11-04 06:13:13 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* DAPM dai link stream work */
|
|
|
|
INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
|
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
ret = soc_post_component_init(card, codec, num, 0);
|
|
|
|
if (ret)
|
2010-03-18 04:15:21 +08:00
|
|
|
return ret;
|
2009-11-04 06:13:13 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
|
|
|
|
if (ret < 0)
|
|
|
|
printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
|
|
|
|
|
|
|
|
/* create the pcm */
|
|
|
|
ret = soc_new_pcm(rtd, num);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add platform data for AC97 devices */
|
|
|
|
if (rtd->codec_dai->driver->ac97_control)
|
|
|
|
snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-04 06:13:13 +08:00
|
|
|
#ifdef CONFIG_SND_SOC_AC97_BUS
|
2010-03-18 04:15:21 +08:00
|
|
|
static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2009-11-04 06:13:13 +08:00
|
|
|
/* Only instantiate AC97 if not already done by the adaptor
|
|
|
|
* for the generic AC97 subsystem.
|
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
|
2010-10-13 16:30:32 +08:00
|
|
|
/*
|
|
|
|
* It is possible that the AC97 device is already registered to
|
|
|
|
* the device subsystem. This happens when the device is created
|
|
|
|
* via snd_ac97_mixer(). Currently only SoC codec that does so
|
|
|
|
* is the generic AC97 glue but others migh emerge.
|
|
|
|
*
|
|
|
|
* In those cases we don't try to register the device again.
|
|
|
|
*/
|
|
|
|
if (!rtd->codec->ac97_created)
|
|
|
|
return 0;
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
ret = soc_ac97_dev_register(rtd->codec);
|
2009-11-04 06:13:13 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: AC97 device register failed\n");
|
2010-03-18 04:15:21 +08:00
|
|
|
return ret;
|
2009-11-04 06:13:13 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
rtd->codec->ac97_registered = 1;
|
2009-11-04 06:13:13 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
if (codec->ac97_registered) {
|
|
|
|
soc_ac97_dev_unregister(codec);
|
|
|
|
codec->ac97_registered = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-11-04 06:13:13 +08:00
|
|
|
#endif
|
|
|
|
|
2010-11-25 23:47:38 +08:00
|
|
|
static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
|
|
|
|
{
|
|
|
|
struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
|
|
|
|
struct snd_soc_codec *codec;
|
2010-12-03 15:18:22 +08:00
|
|
|
int ret = -ENODEV;
|
2010-11-25 23:47:38 +08:00
|
|
|
|
|
|
|
/* find CODEC from registered CODECs*/
|
|
|
|
list_for_each_entry(codec, &codec_list, list) {
|
|
|
|
if (!strcmp(codec->name, aux_dev->codec_name)) {
|
|
|
|
if (codec->probed) {
|
|
|
|
dev_err(codec->dev,
|
|
|
|
"asoc: codec already probed");
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-12-03 15:18:22 +08:00
|
|
|
goto found;
|
2010-11-25 23:47:38 +08:00
|
|
|
}
|
|
|
|
}
|
2010-12-03 15:18:22 +08:00
|
|
|
/* codec not found */
|
|
|
|
dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
|
|
|
|
goto out;
|
2010-11-25 23:47:38 +08:00
|
|
|
|
2010-12-03 15:18:22 +08:00
|
|
|
found:
|
2010-12-06 22:27:07 +08:00
|
|
|
ret = soc_probe_codec(card, codec);
|
2010-11-25 23:47:38 +08:00
|
|
|
if (ret < 0)
|
2010-12-06 22:27:07 +08:00
|
|
|
return ret;
|
2010-11-25 23:47:38 +08:00
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
ret = soc_post_component_init(card, codec, num, 1);
|
2010-11-25 23:47:38 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
|
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
|
|
|
|
|
|
|
/* unregister the rtd device */
|
|
|
|
if (rtd->dev_registered) {
|
2010-12-06 22:27:07 +08:00
|
|
|
device_remove_file(&rtd->dev, &dev_attr_codec_reg);
|
2010-11-25 23:47:38 +08:00
|
|
|
device_unregister(&rtd->dev);
|
|
|
|
rtd->dev_registered = 0;
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:27:07 +08:00
|
|
|
if (codec && codec->probed)
|
|
|
|
soc_remove_codec(codec);
|
2010-11-25 23:47:38 +08:00
|
|
|
}
|
|
|
|
|
2010-12-03 00:11:06 +08:00
|
|
|
static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
|
|
|
|
enum snd_soc_compress_type compress_type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (codec->cache_init)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* override the compress_type if necessary */
|
|
|
|
if (compress_type && codec->compress_type != compress_type)
|
|
|
|
codec->compress_type = compress_type;
|
|
|
|
ret = snd_soc_cache_init(codec);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(codec->dev, "Failed to set cache compression type: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
codec->cache_init = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static void snd_soc_instantiate_card(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(card->dev);
|
2010-12-03 00:11:06 +08:00
|
|
|
struct snd_soc_codec *codec;
|
|
|
|
struct snd_soc_codec_conf *codec_conf;
|
|
|
|
enum snd_soc_compress_type compress_type;
|
2010-03-18 04:15:21 +08:00
|
|
|
int ret, i;
|
2009-11-04 06:13:13 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
mutex_lock(&card->mutex);
|
2010-02-12 19:37:24 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->instantiated) {
|
|
|
|
mutex_unlock(&card->mutex);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-04 06:13:13 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* bind DAIs */
|
|
|
|
for (i = 0; i < card->num_links; i++)
|
|
|
|
soc_bind_dai_link(card, i);
|
2009-11-04 06:13:13 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* bind completed ? */
|
|
|
|
if (card->num_rtd != card->num_links) {
|
|
|
|
mutex_unlock(&card->mutex);
|
|
|
|
return;
|
|
|
|
}
|
2008-12-04 23:32:53 +08:00
|
|
|
|
2010-12-03 00:11:06 +08:00
|
|
|
/* initialize the register cache for each available codec */
|
|
|
|
list_for_each_entry(codec, &codec_list, list) {
|
|
|
|
if (codec->cache_init)
|
|
|
|
continue;
|
|
|
|
/* check to see if we need to override the compress_type */
|
|
|
|
for (i = 0; i < card->num_configs; ++i) {
|
|
|
|
codec_conf = &card->codec_conf[i];
|
|
|
|
if (!strcmp(codec->name, codec_conf->dev_name)) {
|
|
|
|
compress_type = codec_conf->compress_type;
|
|
|
|
if (compress_type && compress_type
|
|
|
|
!= codec->compress_type)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == card->num_configs) {
|
|
|
|
/* no need to override the compress_type so
|
|
|
|
* go ahead and do the standard thing */
|
|
|
|
ret = snd_soc_init_codec_cache(codec, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
mutex_unlock(&card->mutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* override the compress_type with the one supplied in
|
|
|
|
* the machine driver */
|
|
|
|
ret = snd_soc_init_codec_cache(codec, compress_type);
|
|
|
|
if (ret < 0) {
|
|
|
|
mutex_unlock(&card->mutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* card bind complete so register a sound card */
|
|
|
|
ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
|
|
|
|
card->owner, 0, &card->snd_card);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: can't create sound card for card %s\n",
|
|
|
|
card->name);
|
|
|
|
mutex_unlock(&card->mutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
card->snd_card->dev = card->dev;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
/* deferred resume work */
|
|
|
|
INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
|
|
|
|
#endif
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* initialise the sound card only once */
|
|
|
|
if (card->probe) {
|
|
|
|
ret = card->probe(pdev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto card_probe_error;
|
|
|
|
}
|
2009-11-04 06:13:13 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_links; i++) {
|
|
|
|
ret = soc_probe_dai_link(card, i);
|
|
|
|
if (ret < 0) {
|
2010-09-21 22:09:37 +08:00
|
|
|
pr_err("asoc: failed to instantiate card %s: %d\n",
|
|
|
|
card->name, ret);
|
2010-03-18 04:15:21 +08:00
|
|
|
goto probe_dai_err;
|
|
|
|
}
|
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-11-25 23:47:38 +08:00
|
|
|
for (i = 0; i < card->num_aux_devs; i++) {
|
|
|
|
ret = soc_probe_aux_dev(card, i);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("asoc: failed to add auxiliary devices %s: %d\n",
|
|
|
|
card->name, ret);
|
|
|
|
goto probe_aux_dev_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
|
|
|
|
"%s", card->name);
|
|
|
|
snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
|
|
|
|
"%s", card->name);
|
|
|
|
|
|
|
|
ret = snd_card_register(card->snd_card);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
|
2010-12-07 16:12:29 +08:00
|
|
|
goto probe_aux_dev_err;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
#ifdef CONFIG_SND_SOC_AC97_BUS
|
|
|
|
/* register any AC97 codecs */
|
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
2010-12-07 16:12:29 +08:00
|
|
|
ret = soc_register_ac97_dai_link(&card->rtd[i]);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
|
|
|
|
while (--i >= 0)
|
2010-12-14 01:03:27 +08:00
|
|
|
soc_unregister_ac97_dai_link(card->rtd[i].codec);
|
2010-12-07 16:12:29 +08:00
|
|
|
goto probe_aux_dev_err;
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
2010-12-07 16:12:29 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
card->instantiated = 1;
|
|
|
|
mutex_unlock(&card->mutex);
|
|
|
|
return;
|
|
|
|
|
2010-11-25 23:47:38 +08:00
|
|
|
probe_aux_dev_err:
|
|
|
|
for (i = 0; i < card->num_aux_devs; i++)
|
|
|
|
soc_remove_aux_dev(card, i);
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
probe_dai_err:
|
|
|
|
for (i = 0; i < card->num_links; i++)
|
|
|
|
soc_remove_dai_link(card, i);
|
|
|
|
|
|
|
|
card_probe_error:
|
2008-11-19 04:50:34 +08:00
|
|
|
if (card->remove)
|
|
|
|
card->remove(pdev);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
snd_card_free(card->snd_card);
|
|
|
|
|
|
|
|
mutex_unlock(&card->mutex);
|
2008-12-04 23:32:53 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-12-04 23:32:53 +08:00
|
|
|
/*
|
2010-06-11 18:17:00 +08:00
|
|
|
* Attempt to initialise any uninitialised cards. Must be called with
|
2008-12-04 23:32:53 +08:00
|
|
|
* client_mutex.
|
|
|
|
*/
|
|
|
|
static void snd_soc_instantiate_cards(void)
|
|
|
|
{
|
|
|
|
struct snd_soc_card *card;
|
|
|
|
list_for_each_entry(card, &card_list, list)
|
|
|
|
snd_soc_instantiate_card(card);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* probes a new socdev */
|
|
|
|
static int soc_probe(struct platform_device *pdev)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
2008-12-04 23:32:53 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Bodge while we unpick instantiation */
|
|
|
|
card->dev = &pdev->dev;
|
2010-03-18 04:15:21 +08:00
|
|
|
INIT_LIST_HEAD(&card->dai_dev_list);
|
|
|
|
INIT_LIST_HEAD(&card->codec_dev_list);
|
|
|
|
INIT_LIST_HEAD(&card->platform_dev_list);
|
2010-12-14 18:18:31 +08:00
|
|
|
INIT_LIST_HEAD(&card->widgets);
|
2010-12-14 18:18:30 +08:00
|
|
|
INIT_LIST_HEAD(&card->paths);
|
2010-12-14 18:18:32 +08:00
|
|
|
INIT_LIST_HEAD(&card->dapm_list);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2010-11-06 02:35:19 +08:00
|
|
|
soc_init_card_debugfs(card);
|
|
|
|
|
2008-12-04 23:32:53 +08:00
|
|
|
ret = snd_soc_register_card(card);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to register card\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* removes a socdev */
|
|
|
|
static int soc_remove(struct platform_device *pdev)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
2006-10-07 00:31:09 +08:00
|
|
|
int i;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->instantiated) {
|
2009-05-11 18:04:55 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* make sure any delayed work runs */
|
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
|
2010-12-12 00:51:26 +08:00
|
|
|
flush_delayed_work_sync(&rtd->delayed_work);
|
2010-03-18 15:23:33 +08:00
|
|
|
}
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-11-25 23:47:38 +08:00
|
|
|
/* remove auxiliary devices */
|
|
|
|
for (i = 0; i < card->num_aux_devs; i++)
|
|
|
|
soc_remove_aux_dev(card, i);
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* remove and free each DAI */
|
|
|
|
for (i = 0; i < card->num_rtd; i++)
|
|
|
|
soc_remove_dai_link(card, i);
|
|
|
|
|
2010-11-06 02:35:19 +08:00
|
|
|
soc_cleanup_card_debugfs(card);
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* remove the card */
|
2010-03-18 15:23:33 +08:00
|
|
|
if (card->remove)
|
|
|
|
card->remove(pdev);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
kfree(card->rtd);
|
|
|
|
snd_card_free(card->snd_card);
|
|
|
|
}
|
2008-11-28 21:29:45 +08:00
|
|
|
snd_soc_unregister_card(card);
|
2006-10-07 00:31:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-01 02:05:15 +08:00
|
|
|
static int soc_poweroff(struct device *dev)
|
2009-06-22 20:16:51 +08:00
|
|
|
{
|
2009-07-01 02:05:15 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
|
|
|
int i;
|
2009-06-22 20:16:51 +08:00
|
|
|
|
|
|
|
if (!card->instantiated)
|
2009-07-01 02:05:15 +08:00
|
|
|
return 0;
|
2009-06-22 20:16:51 +08:00
|
|
|
|
|
|
|
/* Flush out pmdown_time work - we actually do want to run it
|
|
|
|
* now, we're shutting down so no imminent restart. */
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < card->num_rtd; i++) {
|
|
|
|
struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
|
2010-12-12 00:51:26 +08:00
|
|
|
flush_delayed_work_sync(&rtd->delayed_work);
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
2009-06-22 20:16:51 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_dapm_shutdown(card);
|
2009-07-01 02:05:15 +08:00
|
|
|
|
|
|
|
return 0;
|
2009-06-22 20:16:51 +08:00
|
|
|
}
|
|
|
|
|
2009-12-15 10:00:08 +08:00
|
|
|
static const struct dev_pm_ops soc_pm_ops = {
|
2009-07-01 02:05:15 +08:00
|
|
|
.suspend = soc_suspend,
|
|
|
|
.resume = soc_resume,
|
|
|
|
.poweroff = soc_poweroff,
|
|
|
|
};
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/* ASoC platform driver */
|
|
|
|
static struct platform_driver soc_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "soc-audio",
|
2008-04-14 19:33:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
2009-07-01 02:05:15 +08:00
|
|
|
.pm = &soc_pm_ops,
|
2006-10-07 00:31:09 +08:00
|
|
|
},
|
|
|
|
.probe = soc_probe,
|
|
|
|
.remove = soc_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* create a new pcm */
|
2010-03-18 04:15:21 +08:00
|
|
|
static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = rtd->codec;
|
|
|
|
struct snd_soc_platform *platform = rtd->platform;
|
|
|
|
struct snd_soc_dai *codec_dai = rtd->codec_dai;
|
|
|
|
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
|
2006-10-07 00:31:09 +08:00
|
|
|
struct snd_pcm *pcm;
|
|
|
|
char new_name[64];
|
|
|
|
int ret = 0, playback = 0, capture = 0;
|
|
|
|
|
|
|
|
/* check client and interface hw capabilities */
|
2009-12-24 21:44:28 +08:00
|
|
|
snprintf(new_name, sizeof(new_name), "%s %s-%d",
|
2010-03-18 04:15:21 +08:00
|
|
|
rtd->dai_link->stream_name, codec_dai->name, num);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->playback.channels_min)
|
2006-10-07 00:31:09 +08:00
|
|
|
playback = 1;
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec_dai->driver->capture.channels_min)
|
2006-10-07 00:31:09 +08:00
|
|
|
capture = 1;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name);
|
|
|
|
ret = snd_pcm_new(rtd->card->snd_card, new_name,
|
|
|
|
num, playback, capture, &pcm);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
2010-03-18 04:15:21 +08:00
|
|
|
printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
|
2006-10-07 00:31:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
rtd->pcm = pcm;
|
2006-10-07 00:31:09 +08:00
|
|
|
pcm->private_data = rtd;
|
2010-03-18 04:15:21 +08:00
|
|
|
soc_pcm_ops.mmap = platform->driver->ops->mmap;
|
|
|
|
soc_pcm_ops.pointer = platform->driver->ops->pointer;
|
|
|
|
soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
|
|
|
|
soc_pcm_ops.copy = platform->driver->ops->copy;
|
|
|
|
soc_pcm_ops.silence = platform->driver->ops->silence;
|
|
|
|
soc_pcm_ops.ack = platform->driver->ops->ack;
|
|
|
|
soc_pcm_ops.page = platform->driver->ops->page;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
if (playback)
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
|
|
|
|
|
|
|
|
if (capture)
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
ret = platform->driver->pcm_new(rtd->card->snd_card, codec_dai, pcm);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "asoc: platform pcm constructor failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
pcm->private_free = platform->driver->pcm_free;
|
2006-10-07 00:31:09 +08:00
|
|
|
printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
|
|
|
|
cpu_dai->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-05 22:12:22 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_codec_volatile_register: Report if a register is volatile.
|
|
|
|
*
|
|
|
|
* @codec: CODEC to query.
|
|
|
|
* @reg: Register to query.
|
|
|
|
*
|
|
|
|
* Boolean function indiciating if a CODEC register is volatile.
|
|
|
|
*/
|
|
|
|
int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (codec->driver->volatile_register)
|
|
|
|
return codec->driver->volatile_register(reg);
|
2009-07-05 22:12:22 +08:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_new_ac97_codec - initailise AC97 device
|
|
|
|
* @codec: audio codec
|
|
|
|
* @ops: AC97 bus operations
|
|
|
|
* @num: AC97 codec number
|
|
|
|
*
|
|
|
|
* Initialises AC97 codec resources for use by ad-hoc devices only.
|
|
|
|
*/
|
|
|
|
int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
|
|
|
|
struct snd_ac97_bus_ops *ops, int num)
|
|
|
|
{
|
|
|
|
mutex_lock(&codec->mutex);
|
|
|
|
|
|
|
|
codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
|
|
|
|
if (codec->ac97 == NULL) {
|
|
|
|
mutex_unlock(&codec->mutex);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
|
|
|
|
if (codec->ac97->bus == NULL) {
|
|
|
|
kfree(codec->ac97);
|
|
|
|
codec->ac97 = NULL;
|
|
|
|
mutex_unlock(&codec->mutex);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
codec->ac97->bus->ops = ops;
|
|
|
|
codec->ac97->num = num;
|
2010-10-13 16:30:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the AC97 device to be created by us. This way we ensure that the
|
|
|
|
* device will be registered with the device subsystem later on.
|
|
|
|
*/
|
|
|
|
codec->ac97_created = 1;
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
mutex_unlock(&codec->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_free_ac97_codec - free AC97 codec device
|
|
|
|
* @codec: audio codec
|
|
|
|
*
|
|
|
|
* Frees AC97 codec device resources.
|
|
|
|
*/
|
|
|
|
void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
mutex_lock(&codec->mutex);
|
2010-03-18 04:15:21 +08:00
|
|
|
#ifdef CONFIG_SND_SOC_AC97_BUS
|
|
|
|
soc_unregister_ac97_dai_link(codec);
|
|
|
|
#endif
|
2006-10-07 00:31:09 +08:00
|
|
|
kfree(codec->ac97->bus);
|
|
|
|
kfree(codec->ac97);
|
|
|
|
codec->ac97 = NULL;
|
2010-10-13 16:30:32 +08:00
|
|
|
codec->ac97_created = 0;
|
2006-10-07 00:31:09 +08:00
|
|
|
mutex_unlock(&codec->mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
|
|
|
|
|
2010-11-02 03:41:57 +08:00
|
|
|
unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
|
|
|
|
{
|
|
|
|
unsigned int ret;
|
|
|
|
|
2010-12-03 00:15:29 +08:00
|
|
|
ret = codec->read(codec, reg);
|
2010-11-02 03:41:57 +08:00
|
|
|
dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
|
2010-11-04 06:05:58 +08:00
|
|
|
trace_snd_soc_reg_read(codec, reg, ret);
|
2010-11-02 03:41:57 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_read);
|
|
|
|
|
|
|
|
unsigned int snd_soc_write(struct snd_soc_codec *codec,
|
|
|
|
unsigned int reg, unsigned int val)
|
|
|
|
{
|
|
|
|
dev_dbg(codec->dev, "write %x = %x\n", reg, val);
|
2010-11-04 06:05:58 +08:00
|
|
|
trace_snd_soc_reg_write(codec, reg, val);
|
2010-12-03 00:15:29 +08:00
|
|
|
return codec->write(codec, reg, val);
|
2010-11-02 03:41:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_write);
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_update_bits - update codec register bits
|
|
|
|
* @codec: audio codec
|
|
|
|
* @reg: codec register
|
|
|
|
* @mask: register mask
|
|
|
|
* @value: new value
|
|
|
|
*
|
|
|
|
* Writes new register value.
|
|
|
|
*
|
|
|
|
* Returns 1 for change else 0.
|
|
|
|
*/
|
|
|
|
int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int mask, unsigned int value)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
|
|
|
int change;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int old, new;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
old = snd_soc_read(codec, reg);
|
|
|
|
new = (old & ~mask) | value;
|
|
|
|
change = old != new;
|
|
|
|
if (change)
|
|
|
|
snd_soc_write(codec, reg, new);
|
|
|
|
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_update_bits);
|
|
|
|
|
2009-10-30 19:34:03 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_update_bits_locked - update codec register bits
|
|
|
|
* @codec: audio codec
|
|
|
|
* @reg: codec register
|
|
|
|
* @mask: register mask
|
|
|
|
* @value: new value
|
|
|
|
*
|
|
|
|
* Writes new register value, and takes the codec mutex.
|
|
|
|
*
|
|
|
|
* Returns 1 for change else 0.
|
|
|
|
*/
|
2009-12-04 22:22:03 +08:00
|
|
|
int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
|
|
|
|
unsigned short reg, unsigned int mask,
|
|
|
|
unsigned int value)
|
2009-10-30 19:34:03 +08:00
|
|
|
{
|
|
|
|
int change;
|
|
|
|
|
|
|
|
mutex_lock(&codec->mutex);
|
|
|
|
change = snd_soc_update_bits(codec, reg, mask, value);
|
|
|
|
mutex_unlock(&codec->mutex);
|
|
|
|
|
|
|
|
return change;
|
|
|
|
}
|
2009-12-04 22:22:03 +08:00
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
|
2009-10-30 19:34:03 +08:00
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_test_bits - test register for change
|
|
|
|
* @codec: audio codec
|
|
|
|
* @reg: codec register
|
|
|
|
* @mask: register mask
|
|
|
|
* @value: new value
|
|
|
|
*
|
|
|
|
* Tests a register with a new value and checks if the new value is
|
|
|
|
* different from the old value.
|
|
|
|
*
|
|
|
|
* Returns 1 for change else 0.
|
|
|
|
*/
|
|
|
|
int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int mask, unsigned int value)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
|
|
|
int change;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int old, new;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
old = snd_soc_read(codec, reg);
|
|
|
|
new = (old & ~mask) | value;
|
|
|
|
change = old != new;
|
|
|
|
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_test_bits);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_set_runtime_hwparams - set the runtime hardware parameters
|
|
|
|
* @substream: the pcm substream
|
|
|
|
* @hw: the hardware parameters
|
|
|
|
*
|
|
|
|
* Sets the substream runtime hardware parameters.
|
|
|
|
*/
|
|
|
|
int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
|
|
|
|
const struct snd_pcm_hardware *hw)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
runtime->hw.info = hw->info;
|
|
|
|
runtime->hw.formats = hw->formats;
|
|
|
|
runtime->hw.period_bytes_min = hw->period_bytes_min;
|
|
|
|
runtime->hw.period_bytes_max = hw->period_bytes_max;
|
|
|
|
runtime->hw.periods_min = hw->periods_min;
|
|
|
|
runtime->hw.periods_max = hw->periods_max;
|
|
|
|
runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
|
|
|
|
runtime->hw.fifo_size = hw->fifo_size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_cnew - create new control
|
|
|
|
* @_template: control template
|
|
|
|
* @data: control private data
|
2009-01-01 20:18:17 +08:00
|
|
|
* @long_name: control long name
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Create a new mixer control from a template control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success, else error.
|
|
|
|
*/
|
|
|
|
struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
|
|
|
|
void *data, char *long_name)
|
|
|
|
{
|
|
|
|
struct snd_kcontrol_new template;
|
|
|
|
|
|
|
|
memcpy(&template, _template, sizeof(template));
|
|
|
|
if (long_name)
|
|
|
|
template.name = long_name;
|
|
|
|
template.index = 0;
|
|
|
|
|
|
|
|
return snd_ctl_new1(&template, data);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_cnew);
|
|
|
|
|
2009-01-09 08:23:21 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_add_controls - add an array of controls to a codec.
|
|
|
|
* Convienience function to add a list of controls. Many codecs were
|
|
|
|
* duplicating this code.
|
|
|
|
*
|
|
|
|
* @codec: codec to add controls to
|
|
|
|
* @controls: array of controls to add
|
|
|
|
* @num_controls: number of elements in the array
|
|
|
|
*
|
|
|
|
* Return 0 for success, else error.
|
|
|
|
*/
|
|
|
|
int snd_soc_add_controls(struct snd_soc_codec *codec,
|
|
|
|
const struct snd_kcontrol_new *controls, int num_controls)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_card *card = codec->card->snd_card;
|
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in
an ASoC machine that has multiple codecs with conflicting names. The name
collision would occur when codec drivers try to registering kcontrols with
the same name or when building audio paths.
This patch introduces optional prefix_map into struct snd_soc_card. With it
machine drivers can specify a unique name prefix to each codec that have
conflicting names with anothers. Prefix to codec is matched with codec
name.
Following example illustrates a machine that has two same codec instances.
Name collision from kcontrol registration is avoided by specifying a name
prefix "foo" for the second codec. As the codec widget names are prefixed
then second audio map for that codec shows a prefixed widget name.
static const struct snd_soc_dapm_route map0[] = {
{"Spk", NULL, "MONO"},
};
static const struct snd_soc_dapm_route map1[] = {
{"Vibra", NULL, "foo MONO"},
};
static struct snd_soc_prefix_map codec_prefix[] = {
{
.dev_name = "codec.2",
.name_prefix = "foo",
},
};
static struct snd_soc_card card = {
...
.prefix_map = codec_prefix,
.num_prefixes = ARRAY_SIZE(codec_prefix),
};
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2010-11-14 02:40:44 +08:00
|
|
|
char prefixed_name[44], *name;
|
2009-01-09 08:23:21 +08:00
|
|
|
int err, i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_controls; i++) {
|
|
|
|
const struct snd_kcontrol_new *control = &controls[i];
|
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in
an ASoC machine that has multiple codecs with conflicting names. The name
collision would occur when codec drivers try to registering kcontrols with
the same name or when building audio paths.
This patch introduces optional prefix_map into struct snd_soc_card. With it
machine drivers can specify a unique name prefix to each codec that have
conflicting names with anothers. Prefix to codec is matched with codec
name.
Following example illustrates a machine that has two same codec instances.
Name collision from kcontrol registration is avoided by specifying a name
prefix "foo" for the second codec. As the codec widget names are prefixed
then second audio map for that codec shows a prefixed widget name.
static const struct snd_soc_dapm_route map0[] = {
{"Spk", NULL, "MONO"},
};
static const struct snd_soc_dapm_route map1[] = {
{"Vibra", NULL, "foo MONO"},
};
static struct snd_soc_prefix_map codec_prefix[] = {
{
.dev_name = "codec.2",
.name_prefix = "foo",
},
};
static struct snd_soc_card card = {
...
.prefix_map = codec_prefix,
.num_prefixes = ARRAY_SIZE(codec_prefix),
};
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2010-11-14 02:40:44 +08:00
|
|
|
if (codec->name_prefix) {
|
|
|
|
snprintf(prefixed_name, sizeof(prefixed_name), "%s %s",
|
|
|
|
codec->name_prefix, control->name);
|
|
|
|
name = prefixed_name;
|
|
|
|
} else {
|
|
|
|
name = control->name;
|
|
|
|
}
|
|
|
|
err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
|
2009-01-09 08:23:21 +08:00
|
|
|
if (err < 0) {
|
2010-09-21 02:03:28 +08:00
|
|
|
dev_err(codec->dev, "%s: Failed to add %s: %d\n",
|
ASoC: Add optional name_prefix for codec kcontrol, widget and route names
There is a need to prefix codec kcontrol, widget and internal route names in
an ASoC machine that has multiple codecs with conflicting names. The name
collision would occur when codec drivers try to registering kcontrols with
the same name or when building audio paths.
This patch introduces optional prefix_map into struct snd_soc_card. With it
machine drivers can specify a unique name prefix to each codec that have
conflicting names with anothers. Prefix to codec is matched with codec
name.
Following example illustrates a machine that has two same codec instances.
Name collision from kcontrol registration is avoided by specifying a name
prefix "foo" for the second codec. As the codec widget names are prefixed
then second audio map for that codec shows a prefixed widget name.
static const struct snd_soc_dapm_route map0[] = {
{"Spk", NULL, "MONO"},
};
static const struct snd_soc_dapm_route map1[] = {
{"Vibra", NULL, "foo MONO"},
};
static struct snd_soc_prefix_map codec_prefix[] = {
{
.dev_name = "codec.2",
.name_prefix = "foo",
},
};
static struct snd_soc_card card = {
...
.prefix_map = codec_prefix,
.num_prefixes = ARRAY_SIZE(codec_prefix),
};
Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2010-11-14 02:40:44 +08:00
|
|
|
codec->name, name, err);
|
2009-01-09 08:23:21 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_add_controls);
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_info_enum_double - enumerated double mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Callback to provide information about a double enumerated
|
|
|
|
* mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
|
|
|
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
|
|
|
uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
|
2008-07-29 18:42:27 +08:00
|
|
|
uinfo->value.enumerated.items = e->max;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-07-29 18:42:27 +08:00
|
|
|
if (uinfo->value.enumerated.item > e->max - 1)
|
|
|
|
uinfo->value.enumerated.item = e->max - 1;
|
2006-10-07 00:31:09 +08:00
|
|
|
strcpy(uinfo->value.enumerated.name,
|
|
|
|
e->texts[uinfo->value.enumerated.item]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_get_enum_double - enumerated double mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Callback to get the value of a double enumerated mixer.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int val, bitmask;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-07-29 18:42:27 +08:00
|
|
|
for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
|
2006-10-07 00:31:09 +08:00
|
|
|
;
|
|
|
|
val = snd_soc_read(codec, e->reg);
|
2008-05-19 18:32:25 +08:00
|
|
|
ucontrol->value.enumerated.item[0]
|
|
|
|
= (val >> e->shift_l) & (bitmask - 1);
|
2006-10-07 00:31:09 +08:00
|
|
|
if (e->shift_l != e->shift_r)
|
|
|
|
ucontrol->value.enumerated.item[1] =
|
|
|
|
(val >> e->shift_r) & (bitmask - 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_put_enum_double - enumerated double mixer put callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Callback to set the value of a double enumerated mixer.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int val;
|
|
|
|
unsigned int mask, bitmask;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-07-29 18:42:27 +08:00
|
|
|
for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
|
2006-10-07 00:31:09 +08:00
|
|
|
;
|
2008-07-29 18:42:27 +08:00
|
|
|
if (ucontrol->value.enumerated.item[0] > e->max - 1)
|
2006-10-07 00:31:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
val = ucontrol->value.enumerated.item[0] << e->shift_l;
|
|
|
|
mask = (bitmask - 1) << e->shift_l;
|
|
|
|
if (e->shift_l != e->shift_r) {
|
2008-07-29 18:42:27 +08:00
|
|
|
if (ucontrol->value.enumerated.item[1] > e->max - 1)
|
2006-10-07 00:31:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
val |= ucontrol->value.enumerated.item[1] << e->shift_r;
|
|
|
|
mask |= (bitmask - 1) << e->shift_r;
|
|
|
|
}
|
|
|
|
|
2009-10-30 19:34:03 +08:00
|
|
|
return snd_soc_update_bits_locked(codec, e->reg, mask, val);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
|
|
|
|
|
2009-01-05 15:54:57 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_get_value_enum_double - semi enumerated double mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @ucontrol: control element information
|
|
|
|
*
|
|
|
|
* Callback to get the value of a double semi enumerated mixer.
|
|
|
|
*
|
|
|
|
* Semi enumerated mixer: the enumerated items are referred as values. Can be
|
|
|
|
* used for handling bitfield coded enumeration for example.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2009-01-08 19:34:29 +08:00
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int reg_val, val, mux;
|
2009-01-05 15:54:57 +08:00
|
|
|
|
|
|
|
reg_val = snd_soc_read(codec, e->reg);
|
|
|
|
val = (reg_val >> e->shift_l) & e->mask;
|
|
|
|
for (mux = 0; mux < e->max; mux++) {
|
|
|
|
if (val == e->values[mux])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ucontrol->value.enumerated.item[0] = mux;
|
|
|
|
if (e->shift_l != e->shift_r) {
|
|
|
|
val = (reg_val >> e->shift_r) & e->mask;
|
|
|
|
for (mux = 0; mux < e->max; mux++) {
|
|
|
|
if (val == e->values[mux])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ucontrol->value.enumerated.item[1] = mux;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_put_value_enum_double - semi enumerated double mixer put callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @ucontrol: control element information
|
|
|
|
*
|
|
|
|
* Callback to set the value of a double semi enumerated mixer.
|
|
|
|
*
|
|
|
|
* Semi enumerated mixer: the enumerated items are referred as values. Can be
|
|
|
|
* used for handling bitfield coded enumeration for example.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2009-01-08 19:34:29 +08:00
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int val;
|
|
|
|
unsigned int mask;
|
2009-01-05 15:54:57 +08:00
|
|
|
|
|
|
|
if (ucontrol->value.enumerated.item[0] > e->max - 1)
|
|
|
|
return -EINVAL;
|
|
|
|
val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
|
|
|
|
mask = e->mask << e->shift_l;
|
|
|
|
if (e->shift_l != e->shift_r) {
|
|
|
|
if (ucontrol->value.enumerated.item[1] > e->max - 1)
|
|
|
|
return -EINVAL;
|
|
|
|
val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
|
|
|
|
mask |= e->mask << e->shift_r;
|
|
|
|
}
|
|
|
|
|
2009-10-30 19:34:03 +08:00
|
|
|
return snd_soc_update_bits_locked(codec, e->reg, mask, val);
|
2009-01-05 15:54:57 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_info_enum_ext - external enumerated single mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Callback to provide information about an external enumerated
|
|
|
|
* single mixer.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
|
|
|
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
|
|
|
uinfo->count = 1;
|
2008-07-29 18:42:27 +08:00
|
|
|
uinfo->value.enumerated.items = e->max;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-07-29 18:42:27 +08:00
|
|
|
if (uinfo->value.enumerated.item > e->max - 1)
|
|
|
|
uinfo->value.enumerated.item = e->max - 1;
|
2006-10-07 00:31:09 +08:00
|
|
|
strcpy(uinfo->value.enumerated.name,
|
|
|
|
e->texts[uinfo->value.enumerated.item]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_info_volsw_ext - external single mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Callback to provide information about a single external mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
2008-01-10 21:37:42 +08:00
|
|
|
int max = kcontrol->private_value;
|
|
|
|
|
2009-04-16 04:37:46 +08:00
|
|
|
if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
|
2008-01-10 21:37:42 +08:00
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
|
|
|
else
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.integer.min = 0;
|
2008-01-10 21:37:42 +08:00
|
|
|
uinfo->value.integer.max = max;
|
2006-10-07 00:31:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_info_volsw - single mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Callback to provide information about a single mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2010-05-10 19:39:24 +08:00
|
|
|
int platform_max;
|
2008-10-30 20:37:08 +08:00
|
|
|
unsigned int shift = mc->shift;
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int rshift = mc->rshift;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2010-05-10 19:39:24 +08:00
|
|
|
if (!mc->platform_max)
|
|
|
|
mc->platform_max = mc->max;
|
|
|
|
platform_max = mc->platform_max;
|
|
|
|
|
|
|
|
if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
|
2008-01-10 21:37:42 +08:00
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
|
|
|
else
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
uinfo->count = shift == rshift ? 1 : 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
2010-05-10 19:39:24 +08:00
|
|
|
uinfo->value.integer.max = platform_max;
|
2006-10-07 00:31:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_get_volsw - single mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Callback to get the value of a single mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2006-10-07 00:31:09 +08:00
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int reg = mc->reg;
|
|
|
|
unsigned int shift = mc->shift;
|
|
|
|
unsigned int rshift = mc->rshift;
|
2008-07-29 18:42:26 +08:00
|
|
|
int max = mc->max;
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int mask = (1 << fls(max)) - 1;
|
|
|
|
unsigned int invert = mc->invert;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
|
|
(snd_soc_read(codec, reg) >> shift) & mask;
|
|
|
|
if (shift != rshift)
|
|
|
|
ucontrol->value.integer.value[1] =
|
|
|
|
(snd_soc_read(codec, reg) >> rshift) & mask;
|
|
|
|
if (invert) {
|
|
|
|
ucontrol->value.integer.value[0] =
|
2008-01-10 21:37:42 +08:00
|
|
|
max - ucontrol->value.integer.value[0];
|
2006-10-07 00:31:09 +08:00
|
|
|
if (shift != rshift)
|
|
|
|
ucontrol->value.integer.value[1] =
|
2008-01-10 21:37:42 +08:00
|
|
|
max - ucontrol->value.integer.value[1];
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_put_volsw - single mixer put callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Callback to set the value of a single mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2006-10-07 00:31:09 +08:00
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int reg = mc->reg;
|
|
|
|
unsigned int shift = mc->shift;
|
|
|
|
unsigned int rshift = mc->rshift;
|
2008-07-29 18:42:26 +08:00
|
|
|
int max = mc->max;
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int mask = (1 << fls(max)) - 1;
|
|
|
|
unsigned int invert = mc->invert;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int val, val2, val_mask;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
val = (ucontrol->value.integer.value[0] & mask);
|
|
|
|
if (invert)
|
2008-01-10 21:37:42 +08:00
|
|
|
val = max - val;
|
2006-10-07 00:31:09 +08:00
|
|
|
val_mask = mask << shift;
|
|
|
|
val = val << shift;
|
|
|
|
if (shift != rshift) {
|
|
|
|
val2 = (ucontrol->value.integer.value[1] & mask);
|
|
|
|
if (invert)
|
2008-01-10 21:37:42 +08:00
|
|
|
val2 = max - val2;
|
2006-10-07 00:31:09 +08:00
|
|
|
val_mask |= mask << rshift;
|
|
|
|
val |= val2 << rshift;
|
|
|
|
}
|
2009-10-30 19:34:03 +08:00
|
|
|
return snd_soc_update_bits_locked(codec, reg, val_mask, val);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_info_volsw_2r - double mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Callback to provide information about a double mixer control that
|
|
|
|
* spans 2 codec registers.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2010-05-10 19:39:24 +08:00
|
|
|
int platform_max;
|
2008-01-10 21:37:42 +08:00
|
|
|
|
2010-05-10 19:39:24 +08:00
|
|
|
if (!mc->platform_max)
|
|
|
|
mc->platform_max = mc->max;
|
|
|
|
platform_max = mc->platform_max;
|
|
|
|
|
|
|
|
if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
|
2008-01-10 21:37:42 +08:00
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
|
|
|
else
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
2010-05-10 19:39:24 +08:00
|
|
|
uinfo->value.integer.max = platform_max;
|
2006-10-07 00:31:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_get_volsw_2r - double mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Callback to get the value of a double mixer control that spans 2 registers.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2006-10-07 00:31:09 +08:00
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int reg = mc->reg;
|
|
|
|
unsigned int reg2 = mc->rreg;
|
|
|
|
unsigned int shift = mc->shift;
|
2008-07-29 18:42:26 +08:00
|
|
|
int max = mc->max;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int mask = (1 << fls(max)) - 1;
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int invert = mc->invert;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
|
|
(snd_soc_read(codec, reg) >> shift) & mask;
|
|
|
|
ucontrol->value.integer.value[1] =
|
|
|
|
(snd_soc_read(codec, reg2) >> shift) & mask;
|
|
|
|
if (invert) {
|
|
|
|
ucontrol->value.integer.value[0] =
|
2008-01-10 21:37:42 +08:00
|
|
|
max - ucontrol->value.integer.value[0];
|
2006-10-07 00:31:09 +08:00
|
|
|
ucontrol->value.integer.value[1] =
|
2008-01-10 21:37:42 +08:00
|
|
|
max - ucontrol->value.integer.value[1];
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_put_volsw_2r - double mixer set callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2006-10-07 00:31:09 +08:00
|
|
|
*
|
|
|
|
* Callback to set the value of a double mixer control that spans 2 registers.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2006-10-07 00:31:09 +08:00
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int reg = mc->reg;
|
|
|
|
unsigned int reg2 = mc->rreg;
|
|
|
|
unsigned int shift = mc->shift;
|
2008-07-29 18:42:26 +08:00
|
|
|
int max = mc->max;
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int mask = (1 << fls(max)) - 1;
|
|
|
|
unsigned int invert = mc->invert;
|
2006-10-07 00:31:09 +08:00
|
|
|
int err;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int val, val2, val_mask;
|
2006-10-07 00:31:09 +08:00
|
|
|
|
|
|
|
val_mask = mask << shift;
|
|
|
|
val = (ucontrol->value.integer.value[0] & mask);
|
|
|
|
val2 = (ucontrol->value.integer.value[1] & mask);
|
|
|
|
|
|
|
|
if (invert) {
|
2008-01-10 21:37:42 +08:00
|
|
|
val = max - val;
|
|
|
|
val2 = max - val2;
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
val = val << shift;
|
|
|
|
val2 = val2 << shift;
|
|
|
|
|
2009-10-30 19:34:03 +08:00
|
|
|
err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
|
2008-05-19 18:32:25 +08:00
|
|
|
if (err < 0)
|
2006-10-07 00:31:09 +08:00
|
|
|
return err;
|
|
|
|
|
2009-10-30 19:34:03 +08:00
|
|
|
err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
|
2006-10-07 00:31:09 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
|
|
|
|
|
2008-05-29 00:58:05 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_info_volsw_s8 - signed mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Callback to provide information about a signed mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2010-05-10 19:39:24 +08:00
|
|
|
int platform_max;
|
2008-07-29 18:42:26 +08:00
|
|
|
int min = mc->min;
|
2008-05-29 00:58:05 +08:00
|
|
|
|
2010-05-10 19:39:24 +08:00
|
|
|
if (!mc->platform_max)
|
|
|
|
mc->platform_max = mc->max;
|
|
|
|
platform_max = mc->platform_max;
|
|
|
|
|
2008-05-29 00:58:05 +08:00
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
2010-05-10 19:39:24 +08:00
|
|
|
uinfo->value.integer.max = platform_max - min;
|
2008-05-29 00:58:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_get_volsw_s8 - signed mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2008-05-29 00:58:05 +08:00
|
|
|
*
|
|
|
|
* Callback to get the value of a signed mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2008-05-29 00:58:05 +08:00
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int reg = mc->reg;
|
2008-07-29 18:42:26 +08:00
|
|
|
int min = mc->min;
|
2008-05-29 00:58:05 +08:00
|
|
|
int val = snd_soc_read(codec, reg);
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
|
|
((signed char)(val & 0xff))-min;
|
|
|
|
ucontrol->value.integer.value[1] =
|
|
|
|
((signed char)((val >> 8) & 0xff))-min;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_put_volsw_sgn - signed mixer put callback
|
|
|
|
* @kcontrol: mixer control
|
2009-01-01 20:18:17 +08:00
|
|
|
* @ucontrol: control element information
|
2008-05-29 00:58:05 +08:00
|
|
|
*
|
|
|
|
* Callback to set the value of a signed mixer control.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2008-07-29 18:42:26 +08:00
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
2008-05-29 00:58:05 +08:00
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2008-07-29 22:22:24 +08:00
|
|
|
unsigned int reg = mc->reg;
|
2008-07-29 18:42:26 +08:00
|
|
|
int min = mc->min;
|
2009-06-07 13:49:11 +08:00
|
|
|
unsigned int val;
|
2008-05-29 00:58:05 +08:00
|
|
|
|
|
|
|
val = (ucontrol->value.integer.value[0]+min) & 0xff;
|
|
|
|
val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
|
|
|
|
|
2009-10-30 19:34:03 +08:00
|
|
|
return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
|
2008-05-29 00:58:05 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
|
|
|
|
|
2010-05-07 19:05:49 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_limit_volume - Set new limit to an existing volume control.
|
|
|
|
*
|
|
|
|
* @codec: where to look for the control
|
|
|
|
* @name: Name of the control
|
|
|
|
* @max: new maximum limit
|
|
|
|
*
|
|
|
|
* Return 0 for success, else error.
|
|
|
|
*/
|
|
|
|
int snd_soc_limit_volume(struct snd_soc_codec *codec,
|
|
|
|
const char *name, int max)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_card *card = codec->card->snd_card;
|
2010-05-07 19:05:49 +08:00
|
|
|
struct snd_kcontrol *kctl;
|
|
|
|
struct soc_mixer_control *mc;
|
|
|
|
int found = 0;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
/* Sanity check for name and max */
|
|
|
|
if (unlikely(!name || max <= 0))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
list_for_each_entry(kctl, &card->controls, list) {
|
|
|
|
if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
mc = (struct soc_mixer_control *)kctl->private_value;
|
|
|
|
if (max <= mc->max) {
|
2010-05-10 19:39:24 +08:00
|
|
|
mc->platform_max = max;
|
2010-05-07 19:05:49 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
|
|
|
|
|
2010-05-15 23:30:01 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_info_volsw_2r_sx - double with tlv and variable data size
|
|
|
|
* mixer info callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
{
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
int max = mc->max;
|
|
|
|
int min = mc->min;
|
|
|
|
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = max-min;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_get_volsw_2r_sx - double with tlv and variable data size
|
|
|
|
* mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
|
|
|
unsigned int mask = (1<<mc->shift)-1;
|
|
|
|
int min = mc->min;
|
|
|
|
int val = snd_soc_read(codec, mc->reg) & mask;
|
|
|
|
int valr = snd_soc_read(codec, mc->rreg) & mask;
|
|
|
|
|
2010-06-18 10:56:10 +08:00
|
|
|
ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
|
|
|
|
ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
|
2010-05-15 23:30:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_put_volsw_2r_sx - double with tlv and variable data size
|
|
|
|
* mixer put callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @uinfo: control element information
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
|
|
|
unsigned int mask = (1<<mc->shift)-1;
|
|
|
|
int min = mc->min;
|
|
|
|
int ret;
|
|
|
|
unsigned int val, valr, oval, ovalr;
|
|
|
|
|
|
|
|
val = ((ucontrol->value.integer.value[0]+min) & 0xff);
|
|
|
|
val &= mask;
|
|
|
|
valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
|
|
|
|
valr &= mask;
|
|
|
|
|
|
|
|
oval = snd_soc_read(codec, mc->reg) & mask;
|
|
|
|
ovalr = snd_soc_read(codec, mc->rreg) & mask;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
if (oval != val) {
|
|
|
|
ret = snd_soc_write(codec, mc->reg, val);
|
|
|
|
if (ret < 0)
|
2010-06-15 22:14:31 +08:00
|
|
|
return ret;
|
2010-05-15 23:30:01 +08:00
|
|
|
}
|
|
|
|
if (ovalr != valr) {
|
|
|
|
ret = snd_soc_write(codec, mc->rreg, valr);
|
|
|
|
if (ret < 0)
|
2010-06-15 22:14:31 +08:00
|
|
|
return ret;
|
2010-05-15 23:30:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
|
|
|
|
|
2008-07-08 20:19:13 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_sysclk - configure DAI system or master clock.
|
|
|
|
* @dai: DAI
|
|
|
|
* @clk_id: DAI specific clock ID
|
|
|
|
* @freq: new clock frequency in Hz
|
|
|
|
* @dir: new clock direction - input/output.
|
|
|
|
*
|
|
|
|
* Configures the DAI master (MCLK) or system (SYSCLK) clocking.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
|
|
|
|
unsigned int freq, int dir)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_sysclk)
|
|
|
|
return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_clkdiv - configure DAI clock dividers.
|
|
|
|
* @dai: DAI
|
2009-01-01 20:18:17 +08:00
|
|
|
* @div_id: DAI specific clock divider ID
|
2008-07-08 20:19:13 +08:00
|
|
|
* @div: new clock divisor.
|
|
|
|
*
|
|
|
|
* Configures the clock dividers. This is used to derive the best DAI bit and
|
|
|
|
* frame clocks from the system or master clock. It's best to set the DAI bit
|
|
|
|
* and frame clocks as low as possible to save system power.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
|
|
|
|
int div_id, int div)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_clkdiv)
|
|
|
|
return dai->driver->ops->set_clkdiv(dai, div_id, div);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_pll - configure DAI PLL.
|
|
|
|
* @dai: DAI
|
|
|
|
* @pll_id: DAI specific PLL ID
|
2009-09-06 01:52:16 +08:00
|
|
|
* @source: DAI specific source for the PLL
|
2008-07-08 20:19:13 +08:00
|
|
|
* @freq_in: PLL input clock frequency in Hz
|
|
|
|
* @freq_out: requested PLL output clock frequency in Hz
|
|
|
|
*
|
|
|
|
* Configures and enables PLL to generate output clock based on input clock.
|
|
|
|
*/
|
2009-09-06 01:52:16 +08:00
|
|
|
int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
|
|
|
|
unsigned int freq_in, unsigned int freq_out)
|
2008-07-08 20:19:13 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_pll)
|
|
|
|
return dai->driver->ops->set_pll(dai, pll_id, source,
|
2009-09-06 01:52:16 +08:00
|
|
|
freq_in, freq_out);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_fmt - configure DAI hardware audio format.
|
|
|
|
* @dai: DAI
|
|
|
|
* @fmt: SND_SOC_DAIFMT_ format value.
|
|
|
|
*
|
|
|
|
* Configures the DAI hardware format and clocking.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_fmt)
|
|
|
|
return dai->driver->ops->set_fmt(dai, fmt);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_tdm_slot - configure DAI TDM.
|
|
|
|
* @dai: DAI
|
2009-06-16 08:44:31 +08:00
|
|
|
* @tx_mask: bitmask representing active TX slots.
|
|
|
|
* @rx_mask: bitmask representing active RX slots.
|
2008-07-08 20:19:13 +08:00
|
|
|
* @slots: Number of slots in use.
|
2009-06-16 08:44:31 +08:00
|
|
|
* @slot_width: Width in bits for each slot.
|
2008-07-08 20:19:13 +08:00
|
|
|
*
|
|
|
|
* Configures a DAI for TDM operation. Both mask and slots are codec and DAI
|
|
|
|
* specific.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
|
2009-06-16 08:44:31 +08:00
|
|
|
unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
|
2008-07-08 20:19:13 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_tdm_slot)
|
|
|
|
return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
|
2009-06-16 08:44:31 +08:00
|
|
|
slots, slot_width);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
|
|
|
|
|
2009-09-12 01:16:29 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_channel_map - configure DAI audio channel map
|
|
|
|
* @dai: DAI
|
|
|
|
* @tx_num: how many TX channels
|
|
|
|
* @tx_slot: pointer to an array which imply the TX slot number channel
|
|
|
|
* 0~num-1 uses
|
|
|
|
* @rx_num: how many RX channels
|
|
|
|
* @rx_slot: pointer to an array which imply the RX slot number channel
|
|
|
|
* 0~num-1 uses
|
|
|
|
*
|
|
|
|
* configure the relationship between channel number and TDM slot number.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
|
|
|
|
unsigned int tx_num, unsigned int *tx_slot,
|
|
|
|
unsigned int rx_num, unsigned int *rx_slot)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_channel_map)
|
|
|
|
return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
|
2009-09-12 01:16:29 +08:00
|
|
|
rx_num, rx_slot);
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
|
|
|
|
|
2008-07-08 20:19:13 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_dai_set_tristate - configure DAI system or master clock.
|
|
|
|
* @dai: DAI
|
|
|
|
* @tristate: tristate enable
|
|
|
|
*
|
|
|
|
* Tristates the DAI so that others can use it.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->set_tristate)
|
|
|
|
return dai->driver->ops->set_tristate(dai, tristate);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_dai_digital_mute - configure DAI system or master clock.
|
|
|
|
* @dai: DAI
|
|
|
|
* @mute: mute enable
|
|
|
|
*
|
|
|
|
* Mutes the DAI DAC.
|
|
|
|
*/
|
|
|
|
int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
if (dai->driver && dai->driver->ops->digital_mute)
|
|
|
|
return dai->driver->ops->digital_mute(dai, mute);
|
2008-07-08 20:19:13 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
|
|
|
|
|
2008-11-28 21:29:45 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_register_card - Register a card with the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @card: Card to register
|
2008-11-28 21:29:45 +08:00
|
|
|
*
|
|
|
|
* Note that currently this is an internal only function: it will be
|
|
|
|
* exposed to machine drivers after further backporting of ASoC v2
|
|
|
|
* registration APIs.
|
|
|
|
*/
|
|
|
|
static int snd_soc_register_card(struct snd_soc_card *card)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
int i;
|
|
|
|
|
2008-11-28 21:29:45 +08:00
|
|
|
if (!card->name || !card->dev)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-11-25 23:47:38 +08:00
|
|
|
card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
|
|
|
|
(card->num_links + card->num_aux_devs),
|
|
|
|
GFP_KERNEL);
|
2010-03-18 04:15:21 +08:00
|
|
|
if (card->rtd == NULL)
|
|
|
|
return -ENOMEM;
|
2010-11-25 23:47:38 +08:00
|
|
|
card->rtd_aux = &card->rtd[card->num_links];
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
for (i = 0; i < card->num_links; i++)
|
|
|
|
card->rtd[i].dai_link = &card->dai_link[i];
|
|
|
|
|
2008-11-28 21:29:45 +08:00
|
|
|
INIT_LIST_HEAD(&card->list);
|
|
|
|
card->instantiated = 0;
|
2010-03-18 04:15:21 +08:00
|
|
|
mutex_init(&card->mutex);
|
2008-11-28 21:29:45 +08:00
|
|
|
|
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_add(&card->list, &card_list);
|
2008-12-04 23:32:53 +08:00
|
|
|
snd_soc_instantiate_cards();
|
2008-11-28 21:29:45 +08:00
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
dev_dbg(card->dev, "Registered card '%s'\n", card->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_unregister_card - Unregister a card with the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @card: Card to unregister
|
2008-11-28 21:29:45 +08:00
|
|
|
*
|
|
|
|
* Note that currently this is an internal only function: it will be
|
|
|
|
* exposed to machine drivers after further backporting of ASoC v2
|
|
|
|
* registration APIs.
|
|
|
|
*/
|
|
|
|
static int snd_soc_unregister_card(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_del(&card->list);
|
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/*
|
|
|
|
* Simplify DAI link configuration by removing ".-1" from device names
|
|
|
|
* and sanitizing names.
|
|
|
|
*/
|
2010-12-06 23:49:20 +08:00
|
|
|
static char *fmt_single_name(struct device *dev, int *id)
|
2010-03-18 04:15:21 +08:00
|
|
|
{
|
|
|
|
char *found, name[NAME_SIZE];
|
|
|
|
int id1, id2;
|
|
|
|
|
|
|
|
if (dev_name(dev) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-06 23:42:17 +08:00
|
|
|
strlcpy(name, dev_name(dev), NAME_SIZE);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
/* are we a "%s.%d" name (platform and SPI components) */
|
|
|
|
found = strstr(name, dev->driver->name);
|
|
|
|
if (found) {
|
|
|
|
/* get ID */
|
|
|
|
if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
|
|
|
|
|
|
|
|
/* discard ID from name if ID == -1 */
|
|
|
|
if (*id == -1)
|
|
|
|
found[strlen(dev->driver->name)] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* I2C component devices are named "bus-addr" */
|
|
|
|
if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
|
|
|
|
char tmp[NAME_SIZE];
|
|
|
|
|
|
|
|
/* create unique ID number from I2C addr and bus */
|
2010-10-19 16:10:45 +08:00
|
|
|
*id = ((id1 & 0xffff) << 16) + id2;
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
/* sanitize component name for DAI link creation */
|
|
|
|
snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
|
2010-12-06 23:42:17 +08:00
|
|
|
strlcpy(name, tmp, NAME_SIZE);
|
2010-03-18 04:15:21 +08:00
|
|
|
} else
|
|
|
|
*id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kstrdup(name, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simplify DAI link naming for single devices with multiple DAIs by removing
|
|
|
|
* any ".-1" and using the DAI name (instead of device name).
|
|
|
|
*/
|
|
|
|
static inline char *fmt_multiple_name(struct device *dev,
|
|
|
|
struct snd_soc_dai_driver *dai_drv)
|
|
|
|
{
|
|
|
|
if (dai_drv->name == NULL) {
|
|
|
|
printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
|
|
|
|
dev_name(dev));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kstrdup(dai_drv->name, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
|
2008-12-01 07:31:24 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_register_dai - Register a DAI with the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @dai: DAI to register
|
2008-12-01 07:31:24 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
int snd_soc_register_dai(struct device *dev,
|
|
|
|
struct snd_soc_dai_driver *dai_drv)
|
2008-12-01 07:31:24 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai *dai;
|
|
|
|
|
|
|
|
dev_dbg(dev, "dai register %s\n", dev_name(dev));
|
2008-12-01 07:31:24 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
|
|
|
|
if (dai == NULL)
|
|
|
|
return -ENOMEM;
|
2008-12-01 07:31:24 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* create DAI component name */
|
|
|
|
dai->name = fmt_single_name(dev, &dai->id);
|
|
|
|
if (dai->name == NULL) {
|
|
|
|
kfree(dai);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2009-03-03 09:41:00 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dai->dev = dev;
|
|
|
|
dai->driver = dai_drv;
|
|
|
|
if (!dai->driver->ops)
|
|
|
|
dai->driver->ops = &null_dai_ops;
|
2008-12-01 07:31:24 +08:00
|
|
|
|
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_add(&dai->list, &dai_list);
|
2008-12-04 23:32:53 +08:00
|
|
|
snd_soc_instantiate_cards();
|
2008-12-01 07:31:24 +08:00
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Registered DAI '%s'\n", dai->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_register_dai);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_unregister_dai - Unregister a DAI from the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @dai: DAI to unregister
|
2008-12-01 07:31:24 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
void snd_soc_unregister_dai(struct device *dev)
|
2008-12-01 07:31:24 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai *dai;
|
|
|
|
|
|
|
|
list_for_each_entry(dai, &dai_list, list) {
|
|
|
|
if (dev == dai->dev)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
found:
|
2008-12-01 07:31:24 +08:00
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_del(&dai->list);
|
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Unregistered DAI '%s'\n", dai->name);
|
2010-03-18 04:15:21 +08:00
|
|
|
kfree(dai->name);
|
|
|
|
kfree(dai);
|
2008-12-01 07:31:24 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_register_dais - Register multiple DAIs with the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @dai: Array of DAIs to register
|
|
|
|
* @count: Number of DAIs
|
2008-12-01 07:31:24 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
int snd_soc_register_dais(struct device *dev,
|
|
|
|
struct snd_soc_dai_driver *dai_drv, size_t count)
|
2008-12-01 07:31:24 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai *dai;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
2010-08-18 07:30:30 +08:00
|
|
|
dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
|
2008-12-01 07:31:24 +08:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
|
2010-11-03 15:04:45 +08:00
|
|
|
if (dai == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
/* create DAI component name */
|
|
|
|
dai->name = fmt_multiple_name(dev, &dai_drv[i]);
|
|
|
|
if (dai->name == NULL) {
|
|
|
|
kfree(dai);
|
|
|
|
ret = -EINVAL;
|
2008-12-01 07:31:24 +08:00
|
|
|
goto err;
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dai->dev = dev;
|
|
|
|
dai->driver = &dai_drv[i];
|
2010-10-12 22:43:21 +08:00
|
|
|
if (dai->driver->id)
|
|
|
|
dai->id = dai->driver->id;
|
|
|
|
else
|
|
|
|
dai->id = i;
|
2010-03-18 04:15:21 +08:00
|
|
|
if (!dai->driver->ops)
|
|
|
|
dai->driver->ops = &null_dai_ops;
|
|
|
|
|
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_add(&dai->list, &dai_list);
|
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Registered DAI '%s'\n", dai->name);
|
2008-12-01 07:31:24 +08:00
|
|
|
}
|
|
|
|
|
2010-12-06 16:48:03 +08:00
|
|
|
mutex_lock(&client_mutex);
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_instantiate_cards();
|
2010-12-06 16:48:03 +08:00
|
|
|
mutex_unlock(&client_mutex);
|
2008-12-01 07:31:24 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
for (i--; i >= 0; i--)
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_unregister_dai(dev);
|
2008-12-01 07:31:24 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_register_dais);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @dai: Array of DAIs to unregister
|
|
|
|
* @count: Number of DAIs
|
2008-12-01 07:31:24 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
void snd_soc_unregister_dais(struct device *dev, size_t count)
|
2008-12-01 07:31:24 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_unregister_dai(dev);
|
2008-12-01 07:31:24 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
|
|
|
|
|
2008-12-04 03:40:30 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_register_platform - Register a platform with the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @platform: platform to register
|
2008-12-04 03:40:30 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
int snd_soc_register_platform(struct device *dev,
|
|
|
|
struct snd_soc_platform_driver *platform_drv)
|
2008-12-04 03:40:30 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform;
|
|
|
|
|
|
|
|
dev_dbg(dev, "platform register %s\n", dev_name(dev));
|
|
|
|
|
|
|
|
platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
|
|
|
|
if (platform == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* create platform component name */
|
|
|
|
platform->name = fmt_single_name(dev, &platform->id);
|
|
|
|
if (platform->name == NULL) {
|
|
|
|
kfree(platform);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-12-04 03:40:30 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
platform->dev = dev;
|
|
|
|
platform->driver = platform_drv;
|
2008-12-04 03:40:30 +08:00
|
|
|
|
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_add(&platform->list, &platform_list);
|
2008-12-04 23:32:53 +08:00
|
|
|
snd_soc_instantiate_cards();
|
2008-12-04 03:40:30 +08:00
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Registered platform '%s'\n", platform->name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_register_platform);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_unregister_platform - Unregister a platform from the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @platform: platform to unregister
|
2008-12-04 03:40:30 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
void snd_soc_unregister_platform(struct device *dev)
|
2008-12-04 03:40:30 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_platform *platform;
|
|
|
|
|
|
|
|
list_for_each_entry(platform, &platform_list, list) {
|
|
|
|
if (dev == platform->dev)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
found:
|
2008-12-04 03:40:30 +08:00
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_del(&platform->list);
|
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Unregistered platform '%s'\n", platform->name);
|
2010-03-18 04:15:21 +08:00
|
|
|
kfree(platform->name);
|
|
|
|
kfree(platform);
|
2008-12-04 03:40:30 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
|
|
|
|
|
2009-05-09 23:22:58 +08:00
|
|
|
static u64 codec_format_map[] = {
|
|
|
|
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
|
|
|
|
SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
|
|
|
|
SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
|
|
|
|
SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
|
|
|
|
SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
|
|
|
|
SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
|
|
|
|
SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
|
|
|
|
| SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Fix up the DAI formats for endianness: codecs don't actually see
|
|
|
|
* the endianness of the data but we're using the CPU format
|
|
|
|
* definitions which do need to include endianness so we ensure that
|
|
|
|
* codec DAIs always have both big and little endian variants set.
|
|
|
|
*/
|
|
|
|
static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
|
|
|
|
if (stream->formats & codec_format_map[i])
|
|
|
|
stream->formats |= codec_format_map[i];
|
|
|
|
}
|
|
|
|
|
2008-12-10 22:32:45 +08:00
|
|
|
/**
|
|
|
|
* snd_soc_register_codec - Register a codec with the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @codec: codec to register
|
2008-12-10 22:32:45 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
int snd_soc_register_codec(struct device *dev,
|
2010-12-03 00:21:08 +08:00
|
|
|
const struct snd_soc_codec_driver *codec_drv,
|
|
|
|
struct snd_soc_dai_driver *dai_drv,
|
|
|
|
int num_dai)
|
2008-12-10 22:32:45 +08:00
|
|
|
{
|
2010-12-03 00:11:05 +08:00
|
|
|
size_t reg_size;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_codec *codec;
|
|
|
|
int ret, i;
|
2009-05-09 23:22:58 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_dbg(dev, "codec register %s\n", dev_name(dev));
|
|
|
|
|
|
|
|
codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
|
|
|
|
if (codec == NULL)
|
|
|
|
return -ENOMEM;
|
2008-12-10 22:32:45 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* create CODEC component name */
|
|
|
|
codec->name = fmt_single_name(dev, &codec->id);
|
|
|
|
if (codec->name == NULL) {
|
|
|
|
kfree(codec);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2010-12-02 22:53:01 +08:00
|
|
|
if (codec_drv->compress_type)
|
|
|
|
codec->compress_type = codec_drv->compress_type;
|
|
|
|
else
|
|
|
|
codec->compress_type = SND_SOC_FLAT_COMPRESSION;
|
|
|
|
|
2010-12-03 00:15:29 +08:00
|
|
|
codec->write = codec_drv->write;
|
|
|
|
codec->read = codec_drv->read;
|
2010-11-05 21:53:46 +08:00
|
|
|
codec->dapm.bias_level = SND_SOC_BIAS_OFF;
|
|
|
|
codec->dapm.dev = dev;
|
|
|
|
codec->dapm.codec = codec;
|
2010-11-11 18:04:57 +08:00
|
|
|
codec->dev = dev;
|
|
|
|
codec->driver = codec_drv;
|
|
|
|
codec->num_dai = num_dai;
|
|
|
|
mutex_init(&codec->mutex);
|
2010-11-05 21:53:46 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
/* allocate CODEC register cache */
|
|
|
|
if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
|
2010-12-03 00:11:05 +08:00
|
|
|
reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size;
|
|
|
|
/* it is necessary to make a copy of the default register cache
|
|
|
|
* because in the case of using a compression type that requires
|
|
|
|
* the default register cache to be marked as __devinitconst the
|
|
|
|
* kernel might have freed the array by the time we initialize
|
|
|
|
* the cache.
|
|
|
|
*/
|
|
|
|
codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default,
|
|
|
|
reg_size, GFP_KERNEL);
|
|
|
|
if (!codec->reg_def_copy) {
|
|
|
|
ret = -ENOMEM;
|
2010-12-03 00:11:06 +08:00
|
|
|
goto fail;
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
2009-05-09 23:22:58 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
for (i = 0; i < num_dai; i++) {
|
|
|
|
fixup_codec_formats(&dai_drv[i].playback);
|
|
|
|
fixup_codec_formats(&dai_drv[i].capture);
|
|
|
|
}
|
|
|
|
|
2010-08-19 03:20:55 +08:00
|
|
|
/* register any DAIs */
|
|
|
|
if (num_dai) {
|
|
|
|
ret = snd_soc_register_dais(dev, dai_drv, num_dai);
|
|
|
|
if (ret < 0)
|
2010-12-03 00:11:06 +08:00
|
|
|
goto fail;
|
2010-08-19 03:20:55 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2008-12-10 22:32:45 +08:00
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_add(&codec->list, &codec_list);
|
|
|
|
snd_soc_instantiate_cards();
|
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Registered codec '%s'\n", codec->name);
|
|
|
|
return 0;
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2010-12-03 00:11:06 +08:00
|
|
|
fail:
|
2010-12-03 00:11:05 +08:00
|
|
|
kfree(codec->reg_def_copy);
|
|
|
|
codec->reg_def_copy = NULL;
|
2010-03-18 04:15:21 +08:00
|
|
|
kfree(codec->name);
|
|
|
|
kfree(codec);
|
|
|
|
return ret;
|
2008-12-10 22:32:45 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_register_codec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_soc_unregister_codec - Unregister a codec from the ASoC core
|
|
|
|
*
|
2009-01-01 20:18:17 +08:00
|
|
|
* @codec: codec to unregister
|
2008-12-10 22:32:45 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
void snd_soc_unregister_codec(struct device *dev)
|
2008-12-10 22:32:45 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_codec *codec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
list_for_each_entry(codec, &codec_list, list) {
|
|
|
|
if (dev == codec->dev)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
found:
|
2010-08-19 03:20:55 +08:00
|
|
|
if (codec->num_dai)
|
|
|
|
for (i = 0; i < codec->num_dai; i++)
|
|
|
|
snd_soc_unregister_dai(dev);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2008-12-10 22:32:45 +08:00
|
|
|
mutex_lock(&client_mutex);
|
|
|
|
list_del(&codec->list);
|
|
|
|
mutex_unlock(&client_mutex);
|
|
|
|
|
|
|
|
pr_debug("Unregistered codec '%s'\n", codec->name);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2010-11-11 18:04:57 +08:00
|
|
|
snd_soc_cache_exit(codec);
|
2010-12-03 00:11:05 +08:00
|
|
|
kfree(codec->reg_def_copy);
|
2010-10-21 20:19:45 +08:00
|
|
|
kfree(codec->name);
|
2010-03-18 04:15:21 +08:00
|
|
|
kfree(codec);
|
2008-12-10 22:32:45 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
|
|
|
|
|
2008-12-10 14:47:22 +08:00
|
|
|
static int __init snd_soc_init(void)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
2008-12-04 01:34:03 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
debugfs_root = debugfs_create_dir("asoc", NULL);
|
|
|
|
if (IS_ERR(debugfs_root) || !debugfs_root) {
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"ASoC: Failed to create debugfs directory\n");
|
|
|
|
debugfs_root = NULL;
|
|
|
|
}
|
2010-09-16 01:15:14 +08:00
|
|
|
|
|
|
|
if (!debugfs_create_file("codecs", 0444, debugfs_root, NULL,
|
|
|
|
&codec_list_fops))
|
|
|
|
pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
|
|
|
|
|
2010-09-16 01:19:07 +08:00
|
|
|
if (!debugfs_create_file("dais", 0444, debugfs_root, NULL,
|
|
|
|
&dai_list_fops))
|
|
|
|
pr_warn("ASoC: Failed to create DAI list debugfs file\n");
|
2010-09-16 01:22:40 +08:00
|
|
|
|
|
|
|
if (!debugfs_create_file("platforms", 0444, debugfs_root, NULL,
|
|
|
|
&platform_list_fops))
|
|
|
|
pr_warn("ASoC: Failed to create platform list debugfs file\n");
|
2008-12-04 01:34:03 +08:00
|
|
|
#endif
|
|
|
|
|
2006-10-07 00:31:09 +08:00
|
|
|
return platform_driver_register(&soc_driver);
|
|
|
|
}
|
2010-10-13 00:41:03 +08:00
|
|
|
module_init(snd_soc_init);
|
2006-10-07 00:31:09 +08:00
|
|
|
|
2008-12-01 06:11:24 +08:00
|
|
|
static void __exit snd_soc_exit(void)
|
2006-10-07 00:31:09 +08:00
|
|
|
{
|
2008-12-04 01:34:03 +08:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
debugfs_remove_recursive(debugfs_root);
|
|
|
|
#endif
|
2008-05-19 18:32:25 +08:00
|
|
|
platform_driver_unregister(&soc_driver);
|
2006-10-07 00:31:09 +08:00
|
|
|
}
|
|
|
|
module_exit(snd_soc_exit);
|
|
|
|
|
|
|
|
/* Module information */
|
2008-10-12 20:17:36 +08:00
|
|
|
MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
|
2006-10-07 00:31:09 +08:00
|
|
|
MODULE_DESCRIPTION("ALSA SoC Core");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-14 19:33:36 +08:00
|
|
|
MODULE_ALIAS("platform:soc-audio");
|