2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-10-02 17:15:49 +08:00
|
|
|
/*
|
|
|
|
* ALSA SoC TLV320AIC23 codec driver
|
|
|
|
*
|
|
|
|
* Author: Arun KS, <arunks@mistralsolutions.com>
|
|
|
|
* Copyright: (C) 2008 Mistral Solutions Pvt Ltd.,
|
|
|
|
*
|
|
|
|
* Based on sound/soc/codecs/wm8731.c by Richard Purdie
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* The AIC23 is a driver for a low power stereo audio
|
|
|
|
* codec tlv320aic23
|
|
|
|
*
|
|
|
|
* The machine layer should disable unsupported inputs/outputs by
|
|
|
|
* snd_soc_dapm_disable_pin(codec, "LHPOUT"), etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/pm.h>
|
2013-09-25 02:26:08 +08:00
|
|
|
#include <linux/regmap.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>
|
2008-10-02 17:15:49 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
|
|
|
|
#include "tlv320aic23.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AIC23 register cache
|
|
|
|
*/
|
2013-09-25 02:26:08 +08:00
|
|
|
static const struct reg_default tlv320aic23_reg[] = {
|
|
|
|
{ 0, 0x0097 },
|
|
|
|
{ 1, 0x0097 },
|
|
|
|
{ 2, 0x00F9 },
|
|
|
|
{ 3, 0x00F9 },
|
|
|
|
{ 4, 0x001A },
|
|
|
|
{ 5, 0x0004 },
|
|
|
|
{ 6, 0x0007 },
|
|
|
|
{ 7, 0x0001 },
|
|
|
|
{ 8, 0x0020 },
|
|
|
|
{ 9, 0x0000 },
|
|
|
|
};
|
|
|
|
|
2014-03-06 18:04:41 +08:00
|
|
|
const struct regmap_config tlv320aic23_regmap = {
|
2013-09-25 02:26:08 +08:00
|
|
|
.reg_bits = 7,
|
|
|
|
.val_bits = 9,
|
|
|
|
|
|
|
|
.max_register = TLV320AIC23_RESET,
|
|
|
|
.reg_defaults = tlv320aic23_reg,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(tlv320aic23_reg),
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
2008-10-02 17:15:49 +08:00
|
|
|
};
|
2014-03-08 17:31:06 +08:00
|
|
|
EXPORT_SYMBOL(tlv320aic23_regmap);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
static const char *rec_src_text[] = { "Line", "Mic" };
|
|
|
|
static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"};
|
|
|
|
|
2014-02-18 17:45:53 +08:00
|
|
|
static SOC_ENUM_SINGLE_DECL(rec_src_enum,
|
|
|
|
TLV320AIC23_ANLG, 2, rec_src_text);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
static const struct snd_kcontrol_new tlv320aic23_rec_src_mux_controls =
|
|
|
|
SOC_DAPM_ENUM("Input Select", rec_src_enum);
|
|
|
|
|
2014-02-18 17:45:53 +08:00
|
|
|
static SOC_ENUM_SINGLE_DECL(tlv320aic23_deemph,
|
|
|
|
TLV320AIC23_DIGT, 1, deemph_text);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -12100, 100, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(input_gain_tlv, -1725, 75, 0);
|
2008-10-03 19:37:30 +08:00
|
|
|
static const DECLARE_TLV_DB_SCALE(sidetone_vol_tlv, -1800, 300, 0);
|
|
|
|
|
|
|
|
static int snd_soc_tlv320aic23_put_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
|
2008-10-03 19:37:30 +08:00
|
|
|
u16 val, reg;
|
|
|
|
|
|
|
|
val = (ucontrol->value.integer.value[0] & 0x07);
|
|
|
|
|
|
|
|
/* linear conversion to userspace
|
|
|
|
* 000 = -6db
|
|
|
|
* 001 = -9db
|
|
|
|
* 010 = -12db
|
|
|
|
* 011 = -18db (Min)
|
|
|
|
* 100 = 0db (Max)
|
|
|
|
*/
|
|
|
|
val = (val >= 4) ? 4 : (3 - val);
|
|
|
|
|
2020-06-16 13:20:46 +08:00
|
|
|
reg = snd_soc_component_read(component, TLV320AIC23_ANLG) & (~0x1C0);
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_ANLG, reg | (val << 6));
|
2008-10-03 19:37:30 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
|
2008-10-03 19:37:30 +08:00
|
|
|
u16 val;
|
|
|
|
|
2020-06-16 13:20:46 +08:00
|
|
|
val = snd_soc_component_read(component, TLV320AIC23_ANLG) & (0x1C0);
|
2008-10-03 19:37:30 +08:00
|
|
|
val = val >> 6;
|
|
|
|
val = (val >= 4) ? 4 : (3 - val);
|
|
|
|
ucontrol->value.integer.value[0] = val;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-10-02 17:15:49 +08:00
|
|
|
static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = {
|
|
|
|
SOC_DOUBLE_R_TLV("Digital Playback Volume", TLV320AIC23_LCHNVOL,
|
|
|
|
TLV320AIC23_RCHNVOL, 0, 127, 0, out_gain_tlv),
|
|
|
|
SOC_SINGLE("Digital Playback Switch", TLV320AIC23_DIGT, 3, 1, 1),
|
|
|
|
SOC_DOUBLE_R("Line Input Switch", TLV320AIC23_LINVOL,
|
|
|
|
TLV320AIC23_RINVOL, 7, 1, 0),
|
|
|
|
SOC_DOUBLE_R_TLV("Line Input Volume", TLV320AIC23_LINVOL,
|
|
|
|
TLV320AIC23_RINVOL, 0, 31, 0, input_gain_tlv),
|
|
|
|
SOC_SINGLE("Mic Input Switch", TLV320AIC23_ANLG, 1, 1, 1),
|
|
|
|
SOC_SINGLE("Mic Booster Switch", TLV320AIC23_ANLG, 0, 1, 0),
|
2011-10-05 15:29:19 +08:00
|
|
|
SOC_SINGLE_EXT_TLV("Sidetone Volume", TLV320AIC23_ANLG, 6, 4, 0,
|
|
|
|
snd_soc_tlv320aic23_get_volsw,
|
|
|
|
snd_soc_tlv320aic23_put_volsw, sidetone_vol_tlv),
|
2008-10-02 17:15:49 +08:00
|
|
|
SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* PGA Mixer controls for Line and Mic switch */
|
|
|
|
static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = {
|
|
|
|
SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Mic Sidetone Switch", TLV320AIC23_ANLG, 5, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Playback Switch", TLV320AIC23_ANLG, 4, 1, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_DAC("DAC", "Playback", TLV320AIC23_PWR, 3, 1),
|
|
|
|
SND_SOC_DAPM_ADC("ADC", "Capture", TLV320AIC23_PWR, 2, 1),
|
|
|
|
SND_SOC_DAPM_MUX("Capture Source", SND_SOC_NOPM, 0, 0,
|
|
|
|
&tlv320aic23_rec_src_mux_controls),
|
|
|
|
SND_SOC_DAPM_MIXER("Output Mixer", TLV320AIC23_PWR, 4, 1,
|
|
|
|
&tlv320aic23_output_mixer_controls[0],
|
|
|
|
ARRAY_SIZE(tlv320aic23_output_mixer_controls)),
|
|
|
|
SND_SOC_DAPM_PGA("Line Input", TLV320AIC23_PWR, 0, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Mic Input", TLV320AIC23_PWR, 1, 1, NULL, 0),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_OUTPUT("LHPOUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("RHPOUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("LOUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("ROUT"),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_INPUT("LLINEIN"),
|
|
|
|
SND_SOC_DAPM_INPUT("RLINEIN"),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_INPUT("MICIN"),
|
|
|
|
};
|
|
|
|
|
2011-03-30 21:53:16 +08:00
|
|
|
static const struct snd_soc_dapm_route tlv320aic23_intercon[] = {
|
2008-10-02 17:15:49 +08:00
|
|
|
/* Output Mixer */
|
|
|
|
{"Output Mixer", "Line Bypass Switch", "Line Input"},
|
|
|
|
{"Output Mixer", "Playback Switch", "DAC"},
|
|
|
|
{"Output Mixer", "Mic Sidetone Switch", "Mic Input"},
|
|
|
|
|
|
|
|
/* Outputs */
|
|
|
|
{"RHPOUT", NULL, "Output Mixer"},
|
|
|
|
{"LHPOUT", NULL, "Output Mixer"},
|
|
|
|
{"LOUT", NULL, "Output Mixer"},
|
|
|
|
{"ROUT", NULL, "Output Mixer"},
|
|
|
|
|
|
|
|
/* Inputs */
|
2017-03-01 20:26:28 +08:00
|
|
|
{"Line Input", NULL, "LLINEIN"},
|
|
|
|
{"Line Input", NULL, "RLINEIN"},
|
|
|
|
{"Mic Input", NULL, "MICIN"},
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
/* input mux */
|
|
|
|
{"Capture Source", "Line", "Line Input"},
|
|
|
|
{"Capture Source", "Mic", "Mic Input"},
|
|
|
|
{"ADC", NULL, "Capture Source"},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-11-06 02:53:28 +08:00
|
|
|
/* AIC23 driver data */
|
|
|
|
struct aic23 {
|
2013-09-25 02:26:08 +08:00
|
|
|
struct regmap *regmap;
|
2008-11-06 02:53:28 +08:00
|
|
|
int mclk;
|
|
|
|
int requested_adc;
|
|
|
|
int requested_dac;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common Crystals used
|
|
|
|
* 11.2896 Mhz /128 = *88.2k /192 = 58.8k
|
|
|
|
* 12.0000 Mhz /125 = *96k /136 = 88.235K
|
|
|
|
* 12.2880 Mhz /128 = *96k /192 = 64k
|
|
|
|
* 16.9344 Mhz /128 = 132.3k /192 = *88.2k
|
|
|
|
* 18.4320 Mhz /128 = 144k /192 = *96k
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normal BOSR 0-256/2 = 128, 1-384/2 = 192
|
|
|
|
* USB BOSR 0-250/2 = 125, 1-272/2 = 136
|
|
|
|
*/
|
|
|
|
static const int bosr_usb_divisor_table[] = {
|
|
|
|
128, 125, 192, 136
|
|
|
|
};
|
|
|
|
#define LOWER_GROUP ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<6) | (1<<7))
|
|
|
|
#define UPPER_GROUP ((1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<15))
|
|
|
|
static const unsigned short sr_valid_mask[] = {
|
|
|
|
LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 0*/
|
|
|
|
LOWER_GROUP, /* Usb, bosr - 0*/
|
2009-11-18 04:51:01 +08:00
|
|
|
LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 1*/
|
2008-11-06 02:53:28 +08:00
|
|
|
UPPER_GROUP, /* Usb, bosr - 1*/
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Every divisor is a factor of 11*12
|
|
|
|
*/
|
|
|
|
#define SR_MULT (11*12)
|
2009-06-06 10:15:58 +08:00
|
|
|
#define A(x) (SR_MULT/x)
|
2008-11-06 02:53:28 +08:00
|
|
|
static const unsigned char sr_adc_mult_table[] = {
|
2009-06-06 10:15:58 +08:00
|
|
|
A(2), A(2), A(12), A(12), 0, 0, A(3), A(1),
|
|
|
|
A(2), A(2), A(11), A(11), 0, 0, 0, A(1)
|
2008-11-06 02:53:28 +08:00
|
|
|
};
|
|
|
|
static const unsigned char sr_dac_mult_table[] = {
|
2009-06-06 10:15:58 +08:00
|
|
|
A(2), A(12), A(2), A(12), 0, 0, A(3), A(1),
|
|
|
|
A(2), A(11), A(2), A(11), 0, 0, 0, A(1)
|
2008-10-02 17:15:49 +08:00
|
|
|
};
|
|
|
|
|
2008-11-06 02:53:28 +08:00
|
|
|
static unsigned get_score(int adc, int adc_l, int adc_h, int need_adc,
|
|
|
|
int dac, int dac_l, int dac_h, int need_dac)
|
|
|
|
{
|
|
|
|
if ((adc >= adc_l) && (adc <= adc_h) &&
|
|
|
|
(dac >= dac_l) && (dac <= dac_h)) {
|
|
|
|
int diff_adc = need_adc - adc;
|
|
|
|
int diff_dac = need_dac - dac;
|
|
|
|
return abs(diff_adc) + abs(diff_dac);
|
|
|
|
}
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_rate(int mclk, u32 need_adc, u32 need_dac)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int best_i = -1;
|
|
|
|
int best_j = -1;
|
|
|
|
int best_div = 0;
|
|
|
|
unsigned best_score = UINT_MAX;
|
|
|
|
int adc_l, adc_h, dac_l, dac_h;
|
|
|
|
|
|
|
|
need_adc *= SR_MULT;
|
|
|
|
need_dac *= SR_MULT;
|
|
|
|
/*
|
|
|
|
* rates given are +/- 1/32
|
|
|
|
*/
|
|
|
|
adc_l = need_adc - (need_adc >> 5);
|
|
|
|
adc_h = need_adc + (need_adc >> 5);
|
|
|
|
dac_l = need_dac - (need_dac >> 5);
|
|
|
|
dac_h = need_dac + (need_dac >> 5);
|
2008-11-18 05:42:01 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(bosr_usb_divisor_table); i++) {
|
2008-11-06 02:53:28 +08:00
|
|
|
int base = mclk / bosr_usb_divisor_table[i];
|
|
|
|
int mask = sr_valid_mask[i];
|
2008-11-18 05:42:01 +08:00
|
|
|
for (j = 0; j < ARRAY_SIZE(sr_adc_mult_table);
|
|
|
|
j++, mask >>= 1) {
|
2008-11-06 02:53:28 +08:00
|
|
|
int adc;
|
|
|
|
int dac;
|
|
|
|
int score;
|
|
|
|
if ((mask & 1) == 0)
|
|
|
|
continue;
|
|
|
|
adc = base * sr_adc_mult_table[j];
|
|
|
|
dac = base * sr_dac_mult_table[j];
|
|
|
|
score = get_score(adc, adc_l, adc_h, need_adc,
|
|
|
|
dac, dac_l, dac_h, need_dac);
|
|
|
|
if (best_score > score) {
|
|
|
|
best_score = score;
|
|
|
|
best_i = i;
|
|
|
|
best_j = j;
|
|
|
|
best_div = 0;
|
|
|
|
}
|
|
|
|
score = get_score((adc >> 1), adc_l, adc_h, need_adc,
|
|
|
|
(dac >> 1), dac_l, dac_h, need_dac);
|
|
|
|
/* prefer to have a /2 */
|
|
|
|
if ((score != UINT_MAX) && (best_score >= score)) {
|
|
|
|
best_score = score;
|
|
|
|
best_i = i;
|
|
|
|
best_j = j;
|
|
|
|
best_div = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (best_j << 2) | best_i | (best_div << TLV320AIC23_CLKIN_SHIFT);
|
|
|
|
}
|
|
|
|
|
2008-11-18 05:42:01 +08:00
|
|
|
#ifdef DEBUG
|
2018-01-29 12:12:48 +08:00
|
|
|
static void get_current_sample_rates(struct snd_soc_component *component, int mclk,
|
2008-11-06 02:53:28 +08:00
|
|
|
u32 *sample_rate_adc, u32 *sample_rate_dac)
|
|
|
|
{
|
2020-06-16 13:20:46 +08:00
|
|
|
int src = snd_soc_component_read(component, TLV320AIC23_SRATE);
|
2008-11-06 02:53:28 +08:00
|
|
|
int sr = (src >> 2) & 0x0f;
|
|
|
|
int val = (mclk / bosr_usb_divisor_table[src & 3]);
|
|
|
|
int adc = (val * sr_adc_mult_table[sr]) / SR_MULT;
|
|
|
|
int dac = (val * sr_dac_mult_table[sr]) / SR_MULT;
|
|
|
|
if (src & TLV320AIC23_CLKIN_HALF) {
|
|
|
|
adc >>= 1;
|
|
|
|
dac >>= 1;
|
|
|
|
}
|
|
|
|
*sample_rate_adc = adc;
|
|
|
|
*sample_rate_dac = dac;
|
|
|
|
}
|
2008-11-18 05:42:01 +08:00
|
|
|
#endif
|
2008-11-06 02:53:28 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
static int set_sample_rate_control(struct snd_soc_component *component, int mclk,
|
2008-11-06 02:53:28 +08:00
|
|
|
u32 sample_rate_adc, u32 sample_rate_dac)
|
|
|
|
{
|
|
|
|
/* Search for the right sample rate */
|
|
|
|
int data = find_rate(mclk, sample_rate_adc, sample_rate_dac);
|
|
|
|
if (data < 0) {
|
|
|
|
printk(KERN_ERR "%s:Invalid rate %u,%u requested\n",
|
|
|
|
__func__, sample_rate_adc, sample_rate_dac);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_SRATE, data);
|
2008-11-18 05:42:01 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
u32 adc, dac;
|
2018-01-29 12:12:48 +08:00
|
|
|
get_current_sample_rates(component, mclk, &adc, &dac);
|
2008-11-06 02:53:28 +08:00
|
|
|
printk(KERN_DEBUG "actual samplerate = %u,%u reg=%x\n",
|
|
|
|
adc, dac, data);
|
|
|
|
}
|
2008-11-18 05:42:01 +08:00
|
|
|
#endif
|
2008-11-06 02:53:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-02 17:15:49 +08:00
|
|
|
static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
|
2008-11-19 06:11:38 +08:00
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = dai->component;
|
2008-11-06 02:53:28 +08:00
|
|
|
u16 iface_reg;
|
|
|
|
int ret;
|
2018-01-29 12:12:48 +08:00
|
|
|
struct aic23 *aic23 = snd_soc_component_get_drvdata(component);
|
2008-11-06 02:53:28 +08:00
|
|
|
u32 sample_rate_adc = aic23->requested_adc;
|
|
|
|
u32 sample_rate_dac = aic23->requested_dac;
|
|
|
|
u32 sample_rate = params_rate(params);
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
aic23->requested_dac = sample_rate_dac = sample_rate;
|
|
|
|
if (!sample_rate_adc)
|
|
|
|
sample_rate_adc = sample_rate;
|
|
|
|
} else {
|
|
|
|
aic23->requested_adc = sample_rate_adc = sample_rate;
|
|
|
|
if (!sample_rate_dac)
|
|
|
|
sample_rate_dac = sample_rate;
|
|
|
|
}
|
2018-01-29 12:12:48 +08:00
|
|
|
ret = set_sample_rate_control(component, aic23->mclk, sample_rate_adc,
|
2008-11-06 02:53:28 +08:00
|
|
|
sample_rate_dac);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2020-06-16 13:20:46 +08:00
|
|
|
iface_reg = snd_soc_component_read(component, TLV320AIC23_DIGT_FMT) & ~(0x03 << 2);
|
2011-10-13 15:06:43 +08:00
|
|
|
|
2014-07-30 03:13:00 +08:00
|
|
|
switch (params_width(params)) {
|
|
|
|
case 16:
|
2008-10-02 17:15:49 +08:00
|
|
|
break;
|
2014-07-30 03:13:00 +08:00
|
|
|
case 20:
|
2008-10-02 17:15:49 +08:00
|
|
|
iface_reg |= (0x01 << 2);
|
|
|
|
break;
|
2014-07-30 03:13:00 +08:00
|
|
|
case 24:
|
2008-10-02 17:15:49 +08:00
|
|
|
iface_reg |= (0x02 << 2);
|
|
|
|
break;
|
2014-07-30 03:13:00 +08:00
|
|
|
case 32:
|
2008-10-02 17:15:49 +08:00
|
|
|
iface_reg |= (0x03 << 2);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_DIGT_FMT, iface_reg);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-19 06:11:38 +08:00
|
|
|
static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = dai->component;
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
/* set active */
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x0001);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-19 06:11:38 +08:00
|
|
|
static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = dai->component;
|
|
|
|
struct aic23 *aic23 = snd_soc_component_get_drvdata(component);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
/* deactivate */
|
2020-05-15 08:47:11 +08:00
|
|
|
if (!snd_soc_component_active(component)) {
|
2008-10-02 17:15:49 +08:00
|
|
|
udelay(50);
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x0);
|
2008-10-02 17:15:49 +08:00
|
|
|
}
|
2008-11-06 02:53:28 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
aic23->requested_dac = 0;
|
|
|
|
else
|
|
|
|
aic23->requested_adc = 0;
|
2008-10-02 17:15:49 +08:00
|
|
|
}
|
|
|
|
|
2020-07-09 09:56:25 +08:00
|
|
|
static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute, int direction)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = dai->component;
|
2008-10-02 17:15:49 +08:00
|
|
|
u16 reg;
|
|
|
|
|
2020-06-16 13:20:46 +08:00
|
|
|
reg = snd_soc_component_read(component, TLV320AIC23_DIGT);
|
2008-10-02 17:15:49 +08:00
|
|
|
if (mute)
|
|
|
|
reg |= TLV320AIC23_DACM_MUTE;
|
|
|
|
|
|
|
|
else
|
|
|
|
reg &= ~TLV320AIC23_DACM_MUTE;
|
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_DIGT, reg);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
|
|
|
|
unsigned int fmt)
|
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
2008-10-02 17:15:49 +08:00
|
|
|
u16 iface_reg;
|
|
|
|
|
2020-06-16 13:20:46 +08:00
|
|
|
iface_reg = snd_soc_component_read(component, TLV320AIC23_DIGT_FMT) & (~0x03);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
/* set master/slave audio interface */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
iface_reg |= TLV320AIC23_MS_MASTER;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
2011-10-27 16:35:49 +08:00
|
|
|
iface_reg &= ~TLV320AIC23_MS_MASTER;
|
2008-10-02 17:15:49 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interface format */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
iface_reg |= TLV320AIC23_FOR_I2S;
|
|
|
|
break;
|
2009-04-09 17:34:40 +08:00
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
iface_reg |= TLV320AIC23_LRP_ON;
|
2020-07-09 09:03:59 +08:00
|
|
|
fallthrough;
|
2008-12-22 16:21:36 +08:00
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
2008-10-02 17:15:49 +08:00
|
|
|
iface_reg |= TLV320AIC23_FOR_DSP;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
iface_reg |= TLV320AIC23_FOR_LJUST;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_DIGT_FMT, iface_reg);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct aic23 *aic23 = snd_soc_dai_get_drvdata(codec_dai);
|
2008-11-06 02:53:28 +08:00
|
|
|
aic23->mclk = freq;
|
|
|
|
return 0;
|
2008-10-02 17:15:49 +08:00
|
|
|
}
|
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
static int tlv320aic23_set_bias_level(struct snd_soc_component *component,
|
2008-10-02 17:15:49 +08:00
|
|
|
enum snd_soc_bias_level level)
|
|
|
|
{
|
2020-06-16 13:20:46 +08:00
|
|
|
u16 reg = snd_soc_component_read(component, TLV320AIC23_PWR) & 0x17f;
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case SND_SOC_BIAS_ON:
|
|
|
|
/* vref/mid, osc on, dac unmute */
|
2010-06-20 01:33:39 +08:00
|
|
|
reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \
|
|
|
|
TLV320AIC23_DAC_OFF);
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_PWR, reg);
|
2008-10-02 17:15:49 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_PREPARE:
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
|
|
/* everything off except vref/vmid, */
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_PWR,
|
2011-10-13 15:06:43 +08:00
|
|
|
reg | TLV320AIC23_CLK_OFF);
|
2008-10-02 17:15:49 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
/* everything off, dac mute, inactive */
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x0);
|
|
|
|
snd_soc_component_write(component, TLV320AIC23_PWR, 0x1ff);
|
2008-10-02 17:15:49 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define AIC23_RATES SNDRV_PCM_RATE_8000_96000
|
|
|
|
#define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
|
|
|
|
|
2011-11-23 18:40:40 +08:00
|
|
|
static const struct snd_soc_dai_ops tlv320aic23_dai_ops = {
|
2009-03-03 09:41:00 +08:00
|
|
|
.prepare = tlv320aic23_pcm_prepare,
|
|
|
|
.hw_params = tlv320aic23_hw_params,
|
|
|
|
.shutdown = tlv320aic23_shutdown,
|
2020-07-09 09:56:25 +08:00
|
|
|
.mute_stream = tlv320aic23_mute,
|
2009-03-03 09:41:00 +08:00
|
|
|
.set_fmt = tlv320aic23_set_dai_fmt,
|
|
|
|
.set_sysclk = tlv320aic23_set_dai_sysclk,
|
2020-07-09 09:56:25 +08:00
|
|
|
.no_capture_mute = 1,
|
2009-03-03 09:41:00 +08:00
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_dai_driver tlv320aic23_dai = {
|
|
|
|
.name = "tlv320aic23-hifi",
|
2008-10-02 17:15:49 +08:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "Playback",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = AIC23_RATES,
|
|
|
|
.formats = AIC23_FORMATS,},
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "Capture",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = AIC23_RATES,
|
|
|
|
.formats = AIC23_FORMATS,},
|
2009-03-03 09:41:00 +08:00
|
|
|
.ops = &tlv320aic23_dai_ops,
|
2008-10-02 17:15:49 +08:00
|
|
|
};
|
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
static int tlv320aic23_resume(struct snd_soc_component *component)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
2018-01-29 12:12:48 +08:00
|
|
|
struct aic23 *aic23 = snd_soc_component_get_drvdata(component);
|
2013-09-25 02:26:08 +08:00
|
|
|
regcache_mark_dirty(aic23->regmap);
|
|
|
|
regcache_sync(aic23->regmap);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
static int tlv320aic23_component_probe(struct snd_soc_component *component)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
|
|
|
/* Reset codec */
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_RESET, 0);
|
2011-10-13 15:06:43 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
/* Unmute input */
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_update_bits(component, TLV320AIC23_LINVOL,
|
2011-10-13 15:06:43 +08:00
|
|
|
TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_update_bits(component, TLV320AIC23_RINVOL,
|
2011-10-13 15:06:43 +08:00
|
|
|
TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_update_bits(component, TLV320AIC23_ANLG,
|
2011-10-13 15:06:43 +08:00
|
|
|
TLV320AIC23_BYPASS_ON | TLV320AIC23_MICM_MUTED,
|
|
|
|
0);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
/* Default output volume */
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_LCHNVOL,
|
2011-10-13 15:06:43 +08:00
|
|
|
TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_RCHNVOL,
|
2011-10-13 15:06:43 +08:00
|
|
|
TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x1);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
static const struct snd_soc_component_driver soc_component_dev_tlv320aic23 = {
|
|
|
|
.probe = tlv320aic23_component_probe,
|
|
|
|
.resume = tlv320aic23_resume,
|
|
|
|
.set_bias_level = tlv320aic23_set_bias_level,
|
|
|
|
.controls = tlv320aic23_snd_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(tlv320aic23_snd_controls),
|
|
|
|
.dapm_widgets = tlv320aic23_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
|
|
|
|
.dapm_routes = tlv320aic23_intercon,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon),
|
|
|
|
.suspend_bias_off = 1,
|
|
|
|
.idle_bias_on = 1,
|
|
|
|
.use_pmdown_time = 1,
|
|
|
|
.endianness = 1,
|
|
|
|
.non_legacy_dai_naming = 1,
|
2010-03-18 04:15:21 +08:00
|
|
|
};
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2014-03-06 18:04:41 +08:00
|
|
|
int tlv320aic23_probe(struct device *dev, struct regmap *regmap)
|
2008-10-02 17:15:49 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct aic23 *aic23;
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2014-03-06 18:04:41 +08:00
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2014-03-06 18:04:41 +08:00
|
|
|
aic23 = devm_kzalloc(dev, sizeof(struct aic23), GFP_KERNEL);
|
2010-03-18 04:15:21 +08:00
|
|
|
if (aic23 == NULL)
|
|
|
|
return -ENOMEM;
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2014-03-06 18:04:41 +08:00
|
|
|
aic23->regmap = regmap;
|
2013-09-25 02:26:08 +08:00
|
|
|
|
2014-03-06 18:04:41 +08:00
|
|
|
dev_set_drvdata(dev, aic23);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
2018-01-29 12:12:48 +08:00
|
|
|
return devm_snd_soc_register_component(dev,
|
|
|
|
&soc_component_dev_tlv320aic23,
|
2014-03-06 18:04:41 +08:00
|
|
|
&tlv320aic23_dai, 1);
|
2008-10-02 17:15:49 +08:00
|
|
|
}
|
2014-03-08 17:31:06 +08:00
|
|
|
EXPORT_SYMBOL(tlv320aic23_probe);
|
2008-10-02 17:15:49 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver");
|
|
|
|
MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|