2009-12-13 21:21:56 -07:00
|
|
|
/*
|
|
|
|
* DA7210 ALSA Soc codec driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Dialog Semiconductor
|
|
|
|
* Written by David Chen <Dajun.chen@diasemi.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Renesas Solutions Corp.
|
|
|
|
* Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
|
|
|
|
*
|
|
|
|
* Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/i2c.h>
|
2012-03-29 07:36:29 -06:00
|
|
|
#include <linux/spi/spi.h>
|
2012-03-08 06:34:56 -07: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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2011-07-15 10:38:28 -06:00
|
|
|
#include <linux/module.h>
|
2009-12-13 21:21:56 -07:00
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
2010-11-05 07:53:46 -06:00
|
|
|
#include <sound/soc.h>
|
2009-12-13 21:21:56 -07:00
|
|
|
#include <sound/initval.h>
|
2010-07-20 23:12:16 -06:00
|
|
|
#include <sound/tlv.h>
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* DA7210 register space */
|
2012-03-29 07:36:29 -06:00
|
|
|
#define DA7210_PAGE_CONTROL 0x00
|
2011-10-19 02:54:37 -06:00
|
|
|
#define DA7210_CONTROL 0x01
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_STATUS 0x02
|
|
|
|
#define DA7210_STARTUP1 0x03
|
2011-10-21 06:46:08 -06:00
|
|
|
#define DA7210_STARTUP2 0x04
|
|
|
|
#define DA7210_STARTUP3 0x05
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_MIC_L 0x07
|
|
|
|
#define DA7210_MIC_R 0x08
|
2011-10-19 02:54:37 -06:00
|
|
|
#define DA7210_AUX1_L 0x09
|
|
|
|
#define DA7210_AUX1_R 0x0A
|
2011-10-19 02:49:06 -06:00
|
|
|
#define DA7210_AUX2 0x0B
|
2011-10-19 02:54:37 -06:00
|
|
|
#define DA7210_IN_GAIN 0x0C
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_INMIX_L 0x0D
|
|
|
|
#define DA7210_INMIX_R 0x0E
|
|
|
|
#define DA7210_ADC_HPF 0x0F
|
|
|
|
#define DA7210_ADC 0x10
|
2011-10-15 03:17:56 -06:00
|
|
|
#define DA7210_ADC_EQ1_2 0X11
|
|
|
|
#define DA7210_ADC_EQ3_4 0x12
|
|
|
|
#define DA7210_ADC_EQ5 0x13
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_DAC_HPF 0x14
|
|
|
|
#define DA7210_DAC_L 0x15
|
|
|
|
#define DA7210_DAC_R 0x16
|
|
|
|
#define DA7210_DAC_SEL 0x17
|
2011-10-19 02:49:06 -06:00
|
|
|
#define DA7210_SOFTMUTE 0x18
|
2011-10-15 03:17:56 -06:00
|
|
|
#define DA7210_DAC_EQ1_2 0x19
|
|
|
|
#define DA7210_DAC_EQ3_4 0x1A
|
|
|
|
#define DA7210_DAC_EQ5 0x1B
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_OUTMIX_L 0x1C
|
|
|
|
#define DA7210_OUTMIX_R 0x1D
|
2011-10-21 07:36:23 -06:00
|
|
|
#define DA7210_OUT1_L 0x1E
|
|
|
|
#define DA7210_OUT1_R 0x1F
|
|
|
|
#define DA7210_OUT2 0x20
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_HP_L_VOL 0x21
|
|
|
|
#define DA7210_HP_R_VOL 0x22
|
|
|
|
#define DA7210_HP_CFG 0x23
|
2011-10-19 02:49:06 -06:00
|
|
|
#define DA7210_ZERO_CROSS 0x24
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_DAI_SRC_SEL 0x25
|
|
|
|
#define DA7210_DAI_CFG1 0x26
|
|
|
|
#define DA7210_DAI_CFG3 0x28
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_PLL_DIV1 0x29
|
|
|
|
#define DA7210_PLL_DIV2 0x2A
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_PLL_DIV3 0x2B
|
|
|
|
#define DA7210_PLL 0x2C
|
2011-10-19 02:54:37 -06:00
|
|
|
#define DA7210_ALC_MAX 0x83
|
|
|
|
#define DA7210_ALC_MIN 0x84
|
|
|
|
#define DA7210_ALC_NOIS 0x85
|
|
|
|
#define DA7210_ALC_ATT 0x86
|
|
|
|
#define DA7210_ALC_REL 0x87
|
|
|
|
#define DA7210_ALC_DEL 0x88
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_A_HID_UNLOCK 0x8A
|
|
|
|
#define DA7210_A_TEST_UNLOCK 0x8B
|
|
|
|
#define DA7210_A_PLL1 0x90
|
|
|
|
#define DA7210_A_CP_MODE 0xA7
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* STARTUP1 bit fields */
|
|
|
|
#define DA7210_SC_MST_EN (1 << 0)
|
|
|
|
|
|
|
|
/* MIC_L bit fields */
|
|
|
|
#define DA7210_MICBIAS_EN (1 << 6)
|
|
|
|
#define DA7210_MIC_L_EN (1 << 7)
|
|
|
|
|
|
|
|
/* MIC_R bit fields */
|
|
|
|
#define DA7210_MIC_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* INMIX_L bit fields */
|
|
|
|
#define DA7210_IN_L_EN (1 << 7)
|
|
|
|
|
|
|
|
/* INMIX_R bit fields */
|
|
|
|
#define DA7210_IN_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* ADC bit fields */
|
2011-10-19 02:54:37 -06:00
|
|
|
#define DA7210_ADC_ALC_EN (1 << 0)
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_ADC_L_EN (1 << 3)
|
|
|
|
#define DA7210_ADC_R_EN (1 << 7)
|
|
|
|
|
2010-02-28 18:10:43 -07:00
|
|
|
/* DAC/ADC HPF fields */
|
|
|
|
#define DA7210_VOICE_F0_MASK (0x7 << 4)
|
|
|
|
#define DA7210_VOICE_F0_25 (1 << 4)
|
|
|
|
#define DA7210_VOICE_EN (1 << 7)
|
2009-12-16 13:36:37 -07:00
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
/* DAC_SEL bit fields */
|
|
|
|
#define DA7210_DAC_L_SRC_DAI_L (4 << 0)
|
|
|
|
#define DA7210_DAC_L_EN (1 << 3)
|
|
|
|
#define DA7210_DAC_R_SRC_DAI_R (5 << 4)
|
|
|
|
#define DA7210_DAC_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* OUTMIX_L bit fields */
|
|
|
|
#define DA7210_OUT_L_EN (1 << 7)
|
|
|
|
|
|
|
|
/* OUTMIX_R bit fields */
|
|
|
|
#define DA7210_OUT_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* HP_CFG bit fields */
|
|
|
|
#define DA7210_HP_2CAP_MODE (1 << 1)
|
|
|
|
#define DA7210_HP_SENSE_EN (1 << 2)
|
|
|
|
#define DA7210_HP_L_EN (1 << 3)
|
|
|
|
#define DA7210_HP_MODE (1 << 6)
|
|
|
|
#define DA7210_HP_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* DAI_SRC_SEL bit fields */
|
|
|
|
#define DA7210_DAI_OUT_L_SRC (6 << 0)
|
|
|
|
#define DA7210_DAI_OUT_R_SRC (7 << 4)
|
|
|
|
|
|
|
|
/* DAI_CFG1 bit fields */
|
|
|
|
#define DA7210_DAI_WORD_S16_LE (0 << 0)
|
2011-10-12 09:03:21 -06:00
|
|
|
#define DA7210_DAI_WORD_S20_3LE (1 << 0)
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_DAI_WORD_S24_LE (2 << 0)
|
2011-10-12 09:03:21 -06:00
|
|
|
#define DA7210_DAI_WORD_S32_LE (3 << 0)
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_DAI_FLEN_64BIT (1 << 2)
|
2011-10-12 09:03:21 -06:00
|
|
|
#define DA7210_DAI_MODE_SLAVE (0 << 7)
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_DAI_MODE_MASTER (1 << 7)
|
|
|
|
|
|
|
|
/* DAI_CFG3 bit fields */
|
|
|
|
#define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
|
2011-10-12 09:03:21 -06:00
|
|
|
#define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
|
|
|
|
#define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_DAI_OE (1 << 3)
|
|
|
|
#define DA7210_DAI_EN (1 << 7)
|
|
|
|
|
|
|
|
/*PLL_DIV3 bit fields */
|
2012-04-17 06:34:06 -06:00
|
|
|
#define DA7210_PLL_DIV_L_MASK (0xF << 0)
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
|
|
|
|
#define DA7210_PLL_BYP (1 << 6)
|
|
|
|
|
|
|
|
/* PLL bit fields */
|
2010-02-28 18:10:43 -07:00
|
|
|
#define DA7210_PLL_FS_MASK (0xF << 0)
|
|
|
|
#define DA7210_PLL_FS_8000 (0x1 << 0)
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_PLL_FS_11025 (0x2 << 0)
|
2010-02-28 18:10:43 -07:00
|
|
|
#define DA7210_PLL_FS_12000 (0x3 << 0)
|
|
|
|
#define DA7210_PLL_FS_16000 (0x5 << 0)
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_PLL_FS_22050 (0x6 << 0)
|
2010-02-28 18:10:43 -07:00
|
|
|
#define DA7210_PLL_FS_24000 (0x7 << 0)
|
|
|
|
#define DA7210_PLL_FS_32000 (0x9 << 0)
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_PLL_FS_44100 (0xA << 0)
|
2010-02-28 18:10:43 -07:00
|
|
|
#define DA7210_PLL_FS_48000 (0xB << 0)
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_PLL_FS_88200 (0xE << 0)
|
2010-02-28 18:10:43 -07:00
|
|
|
#define DA7210_PLL_FS_96000 (0xF << 0)
|
2012-04-17 06:34:06 -06:00
|
|
|
#define DA7210_MCLK_DET_EN (0x1 << 5)
|
|
|
|
#define DA7210_MCLK_SRM_EN (0x1 << 6)
|
2010-03-10 19:37:44 -07:00
|
|
|
#define DA7210_PLL_EN (0x1 << 7)
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2011-10-19 02:49:06 -06:00
|
|
|
/* SOFTMUTE bit fields */
|
|
|
|
#define DA7210_RAMP_EN (1 << 6)
|
|
|
|
|
2011-10-19 02:54:37 -06:00
|
|
|
/* CONTROL bit fields */
|
2012-04-17 06:34:06 -06:00
|
|
|
#define DA7210_REG_EN (1 << 0)
|
|
|
|
#define DA7210_BIAS_EN (1 << 2)
|
2011-10-19 02:54:37 -06:00
|
|
|
#define DA7210_NOISE_SUP_EN (1 << 3)
|
|
|
|
|
|
|
|
/* IN_GAIN bit fields */
|
|
|
|
#define DA7210_INPGA_L_VOL (0x0F << 0)
|
|
|
|
#define DA7210_INPGA_R_VOL (0xF0 << 0)
|
|
|
|
|
|
|
|
/* ZERO_CROSS bit fields */
|
|
|
|
#define DA7210_AUX1_L_ZC (1 << 0)
|
|
|
|
#define DA7210_AUX1_R_ZC (1 << 1)
|
|
|
|
#define DA7210_HP_L_ZC (1 << 6)
|
|
|
|
#define DA7210_HP_R_ZC (1 << 7)
|
|
|
|
|
|
|
|
/* AUX1_L bit fields */
|
|
|
|
#define DA7210_AUX1_L_VOL (0x3F << 0)
|
2012-01-02 05:05:52 -07:00
|
|
|
#define DA7210_AUX1_L_EN (1 << 7)
|
2011-10-19 02:54:37 -06:00
|
|
|
|
|
|
|
/* AUX1_R bit fields */
|
|
|
|
#define DA7210_AUX1_R_VOL (0x3F << 0)
|
2012-01-02 05:05:52 -07:00
|
|
|
#define DA7210_AUX1_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* AUX2 bit fields */
|
|
|
|
#define DA7210_AUX2_EN (1 << 3)
|
2011-10-19 02:54:37 -06:00
|
|
|
|
|
|
|
/* Minimum INPGA and AUX1 volume to enable noise suppression */
|
|
|
|
#define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
|
|
|
|
#define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
|
|
|
|
|
2011-10-21 07:36:23 -06:00
|
|
|
/* OUT1_L bit fields */
|
|
|
|
#define DA7210_OUT1_L_EN (1 << 7)
|
|
|
|
|
|
|
|
/* OUT1_R bit fields */
|
|
|
|
#define DA7210_OUT1_R_EN (1 << 7)
|
|
|
|
|
|
|
|
/* OUT2 bit fields */
|
|
|
|
#define DA7210_OUT2_OUTMIX_R (1 << 5)
|
|
|
|
#define DA7210_OUT2_OUTMIX_L (1 << 6)
|
|
|
|
#define DA7210_OUT2_EN (1 << 7)
|
|
|
|
|
2012-04-17 06:34:06 -06:00
|
|
|
struct pll_div {
|
|
|
|
int fref;
|
|
|
|
int fout;
|
|
|
|
u8 div1;
|
|
|
|
u8 div2;
|
|
|
|
u8 div3;
|
|
|
|
u8 mode; /* 0 = slave, 1 = master */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* PLL dividers table */
|
|
|
|
static const struct pll_div da7210_pll_div[] = {
|
|
|
|
/* for MASTER mode, fs = 44.1Khz */
|
|
|
|
{ 12000000, 2822400, 0xE8, 0x6C, 0x2, 1}, /* MCLK=12Mhz */
|
|
|
|
{ 13000000, 2822400, 0xDF, 0x28, 0xC, 1}, /* MCLK=13Mhz */
|
|
|
|
{ 13500000, 2822400, 0xDB, 0x0A, 0xD, 1}, /* MCLK=13.5Mhz */
|
|
|
|
{ 14400000, 2822400, 0xD4, 0x5A, 0x2, 1}, /* MCLK=14.4Mhz */
|
|
|
|
{ 19200000, 2822400, 0xBB, 0x43, 0x9, 1}, /* MCLK=19.2Mhz */
|
|
|
|
{ 19680000, 2822400, 0xB9, 0x6D, 0xA, 1}, /* MCLK=19.68Mhz */
|
|
|
|
{ 19800000, 2822400, 0xB8, 0xFB, 0xB, 1}, /* MCLK=19.8Mhz */
|
|
|
|
/* for MASTER mode, fs = 48Khz */
|
|
|
|
{ 12000000, 3072000, 0xF3, 0x12, 0x7, 1}, /* MCLK=12Mhz */
|
|
|
|
{ 13000000, 3072000, 0xE8, 0xFD, 0x5, 1}, /* MCLK=13Mhz */
|
|
|
|
{ 13500000, 3072000, 0xE4, 0x82, 0x3, 1}, /* MCLK=13.5Mhz */
|
|
|
|
{ 14400000, 3072000, 0xDD, 0x3A, 0x0, 1}, /* MCLK=14.4Mhz */
|
|
|
|
{ 19200000, 3072000, 0xC1, 0xEB, 0x8, 1}, /* MCLK=19.2Mhz */
|
|
|
|
{ 19680000, 3072000, 0xBF, 0xEC, 0x0, 1}, /* MCLK=19.68Mhz */
|
|
|
|
{ 19800000, 3072000, 0xBF, 0x70, 0x0, 1}, /* MCLK=19.8Mhz */
|
|
|
|
/* for SLAVE mode with SRM */
|
|
|
|
{ 12000000, 2822400, 0xED, 0xBF, 0x5, 0}, /* MCLK=12Mhz */
|
|
|
|
{ 13000000, 2822400, 0xE4, 0x13, 0x0, 0}, /* MCLK=13Mhz */
|
|
|
|
{ 13500000, 2822400, 0xDF, 0xC6, 0x8, 0}, /* MCLK=13.5Mhz */
|
|
|
|
{ 14400000, 2822400, 0xD8, 0xCA, 0x1, 0}, /* MCLK=14.4Mhz */
|
|
|
|
{ 19200000, 2822400, 0xBE, 0x97, 0x9, 0}, /* MCLK=19.2Mhz */
|
|
|
|
{ 19680000, 2822400, 0xBC, 0xAC, 0xD, 0}, /* MCLK=19.68Mhz */
|
|
|
|
{ 19800000, 2822400, 0xBC, 0x35, 0xE, 0}, /* MCLK=19.8Mhz */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum clk_src {
|
|
|
|
DA7210_CLKSRC_MCLK
|
|
|
|
};
|
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
#define DA7210_VERSION "0.0.1"
|
|
|
|
|
2010-07-20 23:12:16 -06:00
|
|
|
/*
|
|
|
|
* Playback Volume
|
|
|
|
*
|
|
|
|
* max : 0x3F (+15.0 dB)
|
|
|
|
* (1.5 dB step)
|
|
|
|
* min : 0x11 (-54.0 dB)
|
|
|
|
* mute : 0x10
|
|
|
|
* reserved : 0x00 - 0x0F
|
|
|
|
*
|
|
|
|
* Reserved area are considered as "mute".
|
|
|
|
*/
|
2015-08-02 09:19:37 -06:00
|
|
|
static const DECLARE_TLV_DB_RANGE(hp_out_tlv,
|
2011-10-14 04:55:25 -06:00
|
|
|
0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
|
|
|
|
/* -54 dB to +15 dB */
|
2015-08-02 09:19:37 -06:00
|
|
|
0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
|
|
|
|
);
|
2010-07-20 23:12:16 -06:00
|
|
|
|
2015-08-02 09:19:37 -06:00
|
|
|
static const DECLARE_TLV_DB_RANGE(lineout_vol_tlv,
|
2011-10-21 07:36:23 -06:00
|
|
|
0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
|
|
|
|
/* -54dB to 15dB */
|
|
|
|
0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
|
2015-08-02 09:19:37 -06:00
|
|
|
);
|
2011-10-21 07:36:23 -06:00
|
|
|
|
2015-08-02 09:19:37 -06:00
|
|
|
static const DECLARE_TLV_DB_RANGE(mono_vol_tlv,
|
2011-10-21 07:36:23 -06:00
|
|
|
0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
|
|
|
|
/* -18dB to 6dB */
|
|
|
|
0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
|
2015-08-02 09:19:37 -06:00
|
|
|
);
|
2011-10-21 07:36:23 -06:00
|
|
|
|
2015-08-02 09:19:37 -06:00
|
|
|
static const DECLARE_TLV_DB_RANGE(aux1_vol_tlv,
|
2012-01-02 05:05:52 -07:00
|
|
|
0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
|
|
|
|
/* -48dB to 21dB */
|
|
|
|
0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
|
2015-08-02 09:19:37 -06:00
|
|
|
);
|
2012-01-02 05:05:52 -07:00
|
|
|
|
2011-10-15 03:17:56 -06:00
|
|
|
static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
|
2011-10-21 07:36:23 -06:00
|
|
|
static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
|
2012-01-02 05:05:52 -07:00
|
|
|
static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0);
|
2011-10-15 03:17:56 -06:00
|
|
|
|
2011-10-15 03:20:06 -06:00
|
|
|
/* ADC and DAC high pass filter f0 value */
|
2011-11-09 16:15:26 -07:00
|
|
|
static const char * const da7210_hpf_cutoff_txt[] = {
|
2011-10-15 03:20:06 -06:00
|
|
|
"Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
|
|
|
|
};
|
|
|
|
|
2014-02-18 02:06:00 -07:00
|
|
|
static SOC_ENUM_SINGLE_DECL(da7210_dac_hpf_cutoff,
|
|
|
|
DA7210_DAC_HPF, 0, da7210_hpf_cutoff_txt);
|
2011-10-15 03:20:06 -06:00
|
|
|
|
2014-02-18 02:06:00 -07:00
|
|
|
static SOC_ENUM_SINGLE_DECL(da7210_adc_hpf_cutoff,
|
|
|
|
DA7210_ADC_HPF, 0, da7210_hpf_cutoff_txt);
|
2011-10-15 03:20:06 -06:00
|
|
|
|
|
|
|
/* ADC and DAC voice (8kHz) high pass cutoff value */
|
2011-11-09 16:15:26 -07:00
|
|
|
static const char * const da7210_vf_cutoff_txt[] = {
|
2011-10-15 03:20:06 -06:00
|
|
|
"2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
|
|
|
|
};
|
|
|
|
|
2014-02-18 02:06:00 -07:00
|
|
|
static SOC_ENUM_SINGLE_DECL(da7210_dac_vf_cutoff,
|
|
|
|
DA7210_DAC_HPF, 4, da7210_vf_cutoff_txt);
|
2011-10-15 03:20:06 -06:00
|
|
|
|
2014-02-18 02:06:00 -07:00
|
|
|
static SOC_ENUM_SINGLE_DECL(da7210_adc_vf_cutoff,
|
|
|
|
DA7210_ADC_HPF, 4, da7210_vf_cutoff_txt);
|
2011-10-15 03:20:06 -06:00
|
|
|
|
2011-10-19 02:49:06 -06:00
|
|
|
static const char *da7210_hp_mode_txt[] = {
|
|
|
|
"Class H", "Class G"
|
|
|
|
};
|
|
|
|
|
2014-02-18 02:06:00 -07:00
|
|
|
static SOC_ENUM_SINGLE_DECL(da7210_hp_mode_sel,
|
|
|
|
DA7210_HP_CFG, 0, da7210_hp_mode_txt);
|
2011-10-19 02:49:06 -06:00
|
|
|
|
2011-10-19 02:54:37 -06:00
|
|
|
/* ALC can be enabled only if noise suppression is disabled */
|
|
|
|
static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2014-03-18 02:02:04 -06:00
|
|
|
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
|
2011-10-19 02:54:37 -06:00
|
|
|
|
|
|
|
if (ucontrol->value.integer.value[0]) {
|
|
|
|
/* Check if noise suppression is enabled */
|
|
|
|
if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
|
|
|
|
dev_dbg(codec->dev,
|
|
|
|
"Disable noise suppression to enable ALC\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* If all conditions are met or we are actually disabling ALC */
|
|
|
|
return snd_soc_put_volsw(kcontrol, ucontrol);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Noise suppression can be enabled only if following conditions are met
|
|
|
|
* ALC disabled
|
|
|
|
* ZC enabled for HP and AUX1 PGA
|
|
|
|
* INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
|
|
|
|
* AUX1_L_VOL and AUX1_R_VOL >= 6 dB
|
|
|
|
*/
|
|
|
|
static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
2014-03-18 02:02:04 -06:00
|
|
|
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
|
2011-10-19 02:54:37 -06:00
|
|
|
u8 val;
|
|
|
|
|
|
|
|
if (ucontrol->value.integer.value[0]) {
|
|
|
|
/* Check if ALC is enabled */
|
|
|
|
if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Check ZC for HP and AUX1 PGA */
|
|
|
|
if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
|
|
|
|
(DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
|
|
|
|
DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
|
|
|
|
DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Check INPGA_L_VOL and INPGA_R_VOL */
|
|
|
|
val = snd_soc_read(codec, DA7210_IN_GAIN);
|
|
|
|
if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
|
|
|
|
(((val & DA7210_INPGA_R_VOL) >> 4) <
|
|
|
|
DA7210_INPGA_MIN_VOL_NS))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Check AUX1_L_VOL and AUX1_R_VOL */
|
|
|
|
if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
|
|
|
|
DA7210_AUX1_MIN_VOL_NS) ||
|
|
|
|
((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
|
|
|
|
DA7210_AUX1_MIN_VOL_NS))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
/* If all conditions are met or we are actually disabling Noise sup */
|
|
|
|
return snd_soc_put_volsw(kcontrol, ucontrol);
|
|
|
|
|
|
|
|
err:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-07-20 23:12:16 -06:00
|
|
|
static const struct snd_kcontrol_new da7210_snd_controls[] = {
|
|
|
|
|
|
|
|
SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
|
|
|
|
DA7210_HP_L_VOL, DA7210_HP_R_VOL,
|
|
|
|
0, 0x3F, 0, hp_out_tlv),
|
2011-10-21 07:36:23 -06:00
|
|
|
SOC_DOUBLE_R_TLV("Digital Playback Volume",
|
|
|
|
DA7210_DAC_L, DA7210_DAC_R,
|
|
|
|
0, 0x77, 1, dac_gain_tlv),
|
|
|
|
SOC_DOUBLE_R_TLV("Lineout Playback Volume",
|
|
|
|
DA7210_OUT1_L, DA7210_OUT1_R,
|
|
|
|
0, 0x3f, 0, lineout_vol_tlv),
|
|
|
|
SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0,
|
|
|
|
mono_vol_tlv),
|
2011-10-15 03:17:56 -06:00
|
|
|
|
2012-01-02 05:05:52 -07:00
|
|
|
SOC_DOUBLE_R_TLV("Mic Capture Volume",
|
|
|
|
DA7210_MIC_L, DA7210_MIC_R,
|
|
|
|
0, 0x5, 0, mic_vol_tlv),
|
|
|
|
SOC_DOUBLE_R_TLV("Aux1 Capture Volume",
|
|
|
|
DA7210_AUX1_L, DA7210_AUX1_R,
|
|
|
|
0, 0x3f, 0, aux1_vol_tlv),
|
|
|
|
SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0,
|
|
|
|
aux2_vol_tlv),
|
|
|
|
SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0,
|
|
|
|
inpga_gain_tlv),
|
|
|
|
|
2011-10-15 03:17:56 -06:00
|
|
|
/* DAC Equalizer controls */
|
|
|
|
SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
|
|
|
|
SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
|
|
|
|
/* ADC Equalizer controls */
|
|
|
|
SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
|
|
|
|
SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
|
|
|
|
1, adc_eq_master_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
|
|
|
SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
|
|
|
|
eq_gain_tlv),
|
2011-10-15 03:20:06 -06:00
|
|
|
|
|
|
|
SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
|
|
|
|
SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
|
|
|
|
SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
|
|
|
|
SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
|
|
|
|
|
|
|
|
SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
|
|
|
|
SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
|
|
|
|
SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
|
|
|
|
SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
|
2011-10-19 02:49:06 -06:00
|
|
|
|
|
|
|
/* Mute controls */
|
|
|
|
SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
|
|
|
|
SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
|
|
|
|
SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
|
|
|
|
SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
|
|
|
|
SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
|
|
|
|
|
|
|
|
/* Zero cross controls */
|
|
|
|
SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
|
|
|
|
SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
|
|
|
|
SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
|
|
|
|
SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
|
|
|
|
|
|
|
|
SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
|
2011-10-19 02:54:37 -06:00
|
|
|
|
|
|
|
/* ALC controls */
|
|
|
|
SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
|
|
|
|
snd_soc_get_volsw, da7210_put_alc_sw),
|
|
|
|
SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
|
|
|
|
SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
|
|
|
|
SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
|
|
|
|
SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
|
|
|
|
SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
|
|
|
|
SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
|
|
|
|
|
|
|
|
SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
|
|
|
|
0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
|
2010-07-20 23:12:16 -06:00
|
|
|
};
|
|
|
|
|
2011-10-21 06:46:08 -06:00
|
|
|
/*
|
|
|
|
* DAPM Controls
|
|
|
|
*
|
|
|
|
* Current DAPM implementation covers almost all codec components e.g. IOs,
|
|
|
|
* mixers, PGAs,ADC and DAC.
|
|
|
|
*/
|
|
|
|
/* In Mixer Left */
|
|
|
|
static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
|
|
|
|
SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
|
2012-01-02 05:05:52 -07:00
|
|
|
SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0),
|
2011-10-21 06:46:08 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* In Mixer Right */
|
|
|
|
static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
|
|
|
|
SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
|
2012-01-02 05:05:52 -07:00
|
|
|
SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0),
|
2011-10-21 06:46:08 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Out Mixer Left */
|
|
|
|
static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
|
2012-01-02 05:05:52 -07:00
|
|
|
SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0),
|
2011-10-21 06:46:08 -06:00
|
|
|
SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Out Mixer Right */
|
|
|
|
static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
|
2012-01-02 05:05:52 -07:00
|
|
|
SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0),
|
2011-10-21 06:46:08 -06:00
|
|
|
SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
|
|
|
|
};
|
|
|
|
|
2011-10-21 07:36:23 -06:00
|
|
|
/* Mono Mixer */
|
|
|
|
static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
|
2012-01-02 05:05:52 -07:00
|
|
|
SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0),
|
2011-10-21 07:36:23 -06:00
|
|
|
SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
|
|
|
|
SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
|
|
|
|
};
|
|
|
|
|
2011-10-21 06:46:08 -06:00
|
|
|
/* DAPM widgets */
|
|
|
|
static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
|
|
|
|
/* Input Side */
|
|
|
|
/* Input Lines */
|
|
|
|
SND_SOC_DAPM_INPUT("MICL"),
|
|
|
|
SND_SOC_DAPM_INPUT("MICR"),
|
2012-01-02 05:05:52 -07:00
|
|
|
SND_SOC_DAPM_INPUT("AUX1L"),
|
|
|
|
SND_SOC_DAPM_INPUT("AUX1R"),
|
|
|
|
SND_SOC_DAPM_INPUT("AUX2"),
|
2011-10-21 06:46:08 -06:00
|
|
|
|
|
|
|
/* Input PGAs */
|
|
|
|
SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
|
2012-01-02 05:05:52 -07:00
|
|
|
SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0),
|
2011-10-21 06:46:08 -06:00
|
|
|
|
|
|
|
SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
|
|
|
|
|
2012-01-02 05:05:52 -07:00
|
|
|
/* MICBIAS */
|
|
|
|
SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0),
|
|
|
|
|
2011-10-21 06:46:08 -06:00
|
|
|
/* Input Mixers */
|
|
|
|
SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
|
|
|
|
&da7210_dapm_inmixl_controls[0],
|
|
|
|
ARRAY_SIZE(da7210_dapm_inmixl_controls)),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
|
|
|
|
&da7210_dapm_inmixr_controls[0],
|
|
|
|
ARRAY_SIZE(da7210_dapm_inmixr_controls)),
|
|
|
|
|
|
|
|
/* ADCs */
|
|
|
|
SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
|
|
|
|
SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
|
|
|
|
|
|
|
|
/* Output Side */
|
|
|
|
/* DACs */
|
|
|
|
SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
|
|
|
|
SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
|
|
|
|
|
|
|
|
/* Output Mixers */
|
|
|
|
SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
|
|
|
|
&da7210_dapm_outmixl_controls[0],
|
|
|
|
ARRAY_SIZE(da7210_dapm_outmixl_controls)),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
|
|
|
|
&da7210_dapm_outmixr_controls[0],
|
|
|
|
ARRAY_SIZE(da7210_dapm_outmixr_controls)),
|
|
|
|
|
2011-10-21 07:36:23 -06:00
|
|
|
SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
|
|
|
|
&da7210_dapm_monomix_controls[0],
|
|
|
|
ARRAY_SIZE(da7210_dapm_monomix_controls)),
|
|
|
|
|
2011-10-21 06:46:08 -06:00
|
|
|
/* Output PGAs */
|
|
|
|
SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
|
|
|
|
|
2011-10-21 07:36:23 -06:00
|
|
|
SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0),
|
2011-10-21 06:46:08 -06:00
|
|
|
SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
|
|
|
|
|
|
|
|
/* Output Lines */
|
2011-10-21 07:36:23 -06:00
|
|
|
SND_SOC_DAPM_OUTPUT("OUT1L"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("OUT1R"),
|
2011-10-21 06:46:08 -06:00
|
|
|
SND_SOC_DAPM_OUTPUT("HPL"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("HPR"),
|
2011-10-21 07:36:23 -06:00
|
|
|
SND_SOC_DAPM_OUTPUT("OUT2"),
|
2011-10-21 06:46:08 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* DAPM audio route definition */
|
|
|
|
static const struct snd_soc_dapm_route da7210_audio_map[] = {
|
|
|
|
/* Dest Connecting Widget source */
|
|
|
|
/* Input path */
|
|
|
|
{"Mic Left", NULL, "MICL"},
|
|
|
|
{"Mic Right", NULL, "MICR"},
|
2012-01-02 05:05:52 -07:00
|
|
|
{"Aux1 Left", NULL, "AUX1L"},
|
|
|
|
{"Aux1 Right", NULL, "AUX1R"},
|
|
|
|
{"Aux2 Mono", NULL, "AUX2"},
|
2011-10-21 06:46:08 -06:00
|
|
|
|
|
|
|
{"In Mixer Left", "Mic Left Switch", "Mic Left"},
|
|
|
|
{"In Mixer Left", "Mic Right Switch", "Mic Right"},
|
2012-01-02 05:05:52 -07:00
|
|
|
{"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
|
|
|
|
{"In Mixer Left", "Aux2 Switch", "Aux2 Mono"},
|
|
|
|
{"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"},
|
2011-10-21 06:46:08 -06:00
|
|
|
|
|
|
|
{"In Mixer Right", "Mic Right Switch", "Mic Right"},
|
|
|
|
{"In Mixer Right", "Mic Left Switch", "Mic Left"},
|
2012-01-02 05:05:52 -07:00
|
|
|
{"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
|
|
|
|
{"In Mixer Right", "Aux2 Switch", "Aux2 Mono"},
|
|
|
|
{"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"},
|
2011-10-21 06:46:08 -06:00
|
|
|
|
|
|
|
{"INPGA Left", NULL, "In Mixer Left"},
|
|
|
|
{"ADC Left", NULL, "INPGA Left"},
|
|
|
|
|
|
|
|
{"INPGA Right", NULL, "In Mixer Right"},
|
|
|
|
{"ADC Right", NULL, "INPGA Right"},
|
|
|
|
|
|
|
|
/* Output path */
|
2012-01-02 05:05:52 -07:00
|
|
|
{"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
|
|
|
|
{"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"},
|
|
|
|
{"Out Mixer Left", "INPGA Left Switch", "INPGA Left"},
|
|
|
|
{"Out Mixer Left", "INPGA Right Switch", "INPGA Right"},
|
2011-10-21 06:46:08 -06:00
|
|
|
{"Out Mixer Left", "DAC Left Switch", "DAC Left"},
|
2012-01-02 05:05:52 -07:00
|
|
|
|
|
|
|
{"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
|
|
|
|
{"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"},
|
|
|
|
{"Out Mixer Right", "INPGA Right Switch", "INPGA Right"},
|
|
|
|
{"Out Mixer Right", "INPGA Left Switch", "INPGA Left"},
|
2011-10-21 06:46:08 -06:00
|
|
|
{"Out Mixer Right", "DAC Right Switch", "DAC Right"},
|
|
|
|
|
2012-01-02 05:05:52 -07:00
|
|
|
{"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
|
|
|
|
{"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
|
2011-10-21 07:36:23 -06:00
|
|
|
{"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
|
|
|
|
{"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
|
|
|
|
|
2011-10-21 06:46:08 -06:00
|
|
|
{"OUTPGA Left Enable", NULL, "Out Mixer Left"},
|
|
|
|
{"OUTPGA Right Enable", NULL, "Out Mixer Right"},
|
|
|
|
|
2011-10-21 07:36:23 -06:00
|
|
|
{"Out1 Left", NULL, "OUTPGA Left Enable"},
|
|
|
|
{"OUT1L", NULL, "Out1 Left"},
|
|
|
|
|
|
|
|
{"Out1 Right", NULL, "OUTPGA Right Enable"},
|
|
|
|
{"OUT1R", NULL, "Out1 Right"},
|
|
|
|
|
2011-10-21 06:46:08 -06:00
|
|
|
{"Headphone Left", NULL, "OUTPGA Left Enable"},
|
|
|
|
{"HPL", NULL, "Headphone Left"},
|
|
|
|
|
|
|
|
{"Headphone Right", NULL, "OUTPGA Right Enable"},
|
|
|
|
{"HPR", NULL, "Headphone Right"},
|
2011-10-21 07:36:23 -06:00
|
|
|
|
|
|
|
{"Out2 Mono", NULL, "Mono Mixer"},
|
|
|
|
{"OUT2", NULL, "Out2 Mono"},
|
2011-10-21 06:46:08 -06:00
|
|
|
};
|
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
/* Codec private data */
|
|
|
|
struct da7210_priv {
|
2012-03-08 06:34:56 -07:00
|
|
|
struct regmap *regmap;
|
2012-04-17 06:34:06 -06:00
|
|
|
unsigned int mclk_rate;
|
|
|
|
int master;
|
2009-12-13 21:21:56 -07:00
|
|
|
};
|
|
|
|
|
2015-07-05 03:48:29 -06:00
|
|
|
static const struct reg_default da7210_reg_defaults[] = {
|
2012-03-29 07:36:29 -06:00
|
|
|
{ 0x00, 0x00 },
|
2012-03-08 06:34:56 -07:00
|
|
|
{ 0x01, 0x11 },
|
|
|
|
{ 0x03, 0x00 },
|
|
|
|
{ 0x04, 0x00 },
|
|
|
|
{ 0x05, 0x00 },
|
|
|
|
{ 0x06, 0x00 },
|
|
|
|
{ 0x07, 0x00 },
|
|
|
|
{ 0x08, 0x00 },
|
|
|
|
{ 0x09, 0x00 },
|
|
|
|
{ 0x0a, 0x00 },
|
|
|
|
{ 0x0b, 0x00 },
|
|
|
|
{ 0x0c, 0x00 },
|
|
|
|
{ 0x0d, 0x00 },
|
|
|
|
{ 0x0e, 0x00 },
|
|
|
|
{ 0x0f, 0x08 },
|
|
|
|
{ 0x10, 0x00 },
|
|
|
|
{ 0x11, 0x00 },
|
|
|
|
{ 0x12, 0x00 },
|
|
|
|
{ 0x13, 0x00 },
|
|
|
|
{ 0x14, 0x08 },
|
|
|
|
{ 0x15, 0x10 },
|
|
|
|
{ 0x16, 0x10 },
|
|
|
|
{ 0x17, 0x54 },
|
|
|
|
{ 0x18, 0x40 },
|
|
|
|
{ 0x19, 0x00 },
|
|
|
|
{ 0x1a, 0x00 },
|
|
|
|
{ 0x1b, 0x00 },
|
|
|
|
{ 0x1c, 0x00 },
|
|
|
|
{ 0x1d, 0x00 },
|
|
|
|
{ 0x1e, 0x00 },
|
|
|
|
{ 0x1f, 0x00 },
|
|
|
|
{ 0x20, 0x00 },
|
|
|
|
{ 0x21, 0x00 },
|
|
|
|
{ 0x22, 0x00 },
|
|
|
|
{ 0x23, 0x02 },
|
|
|
|
{ 0x24, 0x00 },
|
|
|
|
{ 0x25, 0x76 },
|
|
|
|
{ 0x26, 0x00 },
|
|
|
|
{ 0x27, 0x00 },
|
|
|
|
{ 0x28, 0x04 },
|
|
|
|
{ 0x29, 0x00 },
|
|
|
|
{ 0x2a, 0x00 },
|
|
|
|
{ 0x2b, 0x30 },
|
|
|
|
{ 0x2c, 0x2A },
|
|
|
|
{ 0x83, 0x00 },
|
|
|
|
{ 0x84, 0x00 },
|
|
|
|
{ 0x85, 0x00 },
|
|
|
|
{ 0x86, 0x00 },
|
|
|
|
{ 0x87, 0x00 },
|
|
|
|
{ 0x88, 0x00 },
|
2009-12-13 21:21:56 -07:00
|
|
|
};
|
|
|
|
|
2012-03-08 06:34:56 -07:00
|
|
|
static bool da7210_readable_register(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case DA7210_A_HID_UNLOCK:
|
|
|
|
case DA7210_A_TEST_UNLOCK:
|
|
|
|
case DA7210_A_PLL1:
|
|
|
|
case DA7210_A_CP_MODE:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool da7210_volatile_register(struct device *dev,
|
2011-10-11 17:16:25 -06:00
|
|
|
unsigned int reg)
|
2009-12-13 21:21:56 -07:00
|
|
|
{
|
2011-10-11 17:16:25 -06:00
|
|
|
switch (reg) {
|
|
|
|
case DA7210_STATUS:
|
2012-03-08 06:34:56 -07:00
|
|
|
return true;
|
2011-10-11 17:16:25 -06:00
|
|
|
default:
|
2012-03-08 06:34:56 -07:00
|
|
|
return false;
|
2011-10-11 17:16:25 -06:00
|
|
|
}
|
2009-12-13 21:21:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set PCM DAI word length.
|
|
|
|
*/
|
|
|
|
static int da7210_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2012-04-04 08:58:16 -06:00
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
2012-04-17 06:34:06 -06:00
|
|
|
struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
|
2009-12-13 21:21:56 -07:00
|
|
|
u32 dai_cfg1;
|
2012-04-17 06:34:06 -06:00
|
|
|
u32 fs, sysclk;
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* set DAI source to Left and Right ADC */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_DAI_SRC_SEL,
|
2009-12-13 21:21:56 -07:00
|
|
|
DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
|
|
|
|
|
|
|
|
/* Enable DAI */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2011-10-11 17:16:25 -06:00
|
|
|
dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2014-01-08 12:49:37 -07:00
|
|
|
switch (params_width(params)) {
|
|
|
|
case 16:
|
2009-12-13 21:21:56 -07:00
|
|
|
dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
|
|
|
|
break;
|
2014-01-08 12:49:37 -07:00
|
|
|
case 20:
|
2011-10-12 09:03:21 -06:00
|
|
|
dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
|
|
|
|
break;
|
2014-01-08 12:49:37 -07:00
|
|
|
case 24:
|
2009-12-13 21:21:56 -07:00
|
|
|
dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
|
|
|
|
break;
|
2014-01-08 12:49:37 -07:00
|
|
|
case 32:
|
2011-10-12 09:03:21 -06:00
|
|
|
dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
|
|
|
|
break;
|
2009-12-13 21:21:56 -07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
switch (params_rate(params)) {
|
2010-02-28 18:10:43 -07:00
|
|
|
case 8000:
|
|
|
|
fs = DA7210_PLL_FS_8000;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 3072000;
|
2010-03-10 19:37:44 -07:00
|
|
|
break;
|
|
|
|
case 11025:
|
|
|
|
fs = DA7210_PLL_FS_11025;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 2822400;
|
2010-02-28 18:10:43 -07:00
|
|
|
break;
|
|
|
|
case 12000:
|
|
|
|
fs = DA7210_PLL_FS_12000;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 3072000;
|
2010-02-28 18:10:43 -07:00
|
|
|
break;
|
|
|
|
case 16000:
|
|
|
|
fs = DA7210_PLL_FS_16000;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 3072000;
|
2010-03-10 19:37:44 -07:00
|
|
|
break;
|
|
|
|
case 22050:
|
|
|
|
fs = DA7210_PLL_FS_22050;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 2822400;
|
2010-02-28 18:10:43 -07:00
|
|
|
break;
|
|
|
|
case 32000:
|
|
|
|
fs = DA7210_PLL_FS_32000;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 3072000;
|
2010-03-10 19:37:44 -07:00
|
|
|
break;
|
|
|
|
case 44100:
|
|
|
|
fs = DA7210_PLL_FS_44100;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 2822400;
|
2010-02-28 18:10:43 -07:00
|
|
|
break;
|
2009-12-13 21:21:56 -07:00
|
|
|
case 48000:
|
2010-02-28 18:10:43 -07:00
|
|
|
fs = DA7210_PLL_FS_48000;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 3072000;
|
2010-03-10 19:37:44 -07:00
|
|
|
break;
|
|
|
|
case 88200:
|
|
|
|
fs = DA7210_PLL_FS_88200;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 2822400;
|
2010-02-28 18:10:43 -07:00
|
|
|
break;
|
|
|
|
case 96000:
|
|
|
|
fs = DA7210_PLL_FS_96000;
|
2012-04-17 06:34:06 -06:00
|
|
|
sysclk = 3072000;
|
2009-12-13 21:21:56 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-03-10 19:37:44 -07:00
|
|
|
/* Disable active mode */
|
|
|
|
snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
|
|
|
|
|
2010-02-28 18:10:43 -07:00
|
|
|
snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
|
2010-03-10 19:37:44 -07:00
|
|
|
|
2012-04-17 06:34:06 -06:00
|
|
|
if (da7210->mclk_rate && (da7210->mclk_rate != sysclk)) {
|
|
|
|
/* PLL mode, disable PLL bypass */
|
|
|
|
snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, 0);
|
2012-05-03 07:57:52 -06:00
|
|
|
|
|
|
|
if (!da7210->master) {
|
|
|
|
/* PLL slave mode, also enable SRM */
|
|
|
|
snd_soc_update_bits(codec, DA7210_PLL,
|
|
|
|
(DA7210_MCLK_SRM_EN |
|
|
|
|
DA7210_MCLK_DET_EN),
|
|
|
|
(DA7210_MCLK_SRM_EN |
|
|
|
|
DA7210_MCLK_DET_EN));
|
|
|
|
}
|
2012-04-17 06:34:06 -06:00
|
|
|
} else {
|
2012-05-03 07:57:52 -06:00
|
|
|
/* PLL bypass mode, enable PLL bypass and Auto Detection */
|
|
|
|
snd_soc_update_bits(codec, DA7210_PLL, DA7210_MCLK_DET_EN,
|
|
|
|
DA7210_MCLK_DET_EN);
|
2012-04-17 06:34:06 -06:00
|
|
|
snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP,
|
|
|
|
DA7210_PLL_BYP);
|
|
|
|
}
|
2010-03-10 19:37:44 -07:00
|
|
|
/* Enable active mode */
|
|
|
|
snd_soc_update_bits(codec, DA7210_STARTUP1,
|
|
|
|
DA7210_SC_MST_EN, DA7210_SC_MST_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set DAI mode and Format
|
|
|
|
*/
|
|
|
|
static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2012-04-17 06:34:06 -06:00
|
|
|
struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
|
2009-12-13 21:21:56 -07:00
|
|
|
u32 dai_cfg1;
|
|
|
|
u32 dai_cfg3;
|
|
|
|
|
2011-10-11 17:16:25 -06:00
|
|
|
dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
|
|
|
|
dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2012-04-17 06:34:06 -06:00
|
|
|
if ((snd_soc_read(codec, DA7210_PLL) & DA7210_PLL_EN) &&
|
|
|
|
(!(snd_soc_read(codec, DA7210_PLL_DIV3) & DA7210_PLL_BYP)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
2012-04-17 06:34:06 -06:00
|
|
|
da7210->master = 1;
|
2009-12-13 21:21:56 -07:00
|
|
|
dai_cfg1 |= DA7210_DAI_MODE_MASTER;
|
|
|
|
break;
|
2011-10-12 09:03:21 -06:00
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
2012-04-17 06:34:06 -06:00
|
|
|
da7210->master = 0;
|
2011-10-12 09:03:21 -06:00
|
|
|
dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
|
|
|
|
break;
|
2009-12-13 21:21:56 -07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME
|
|
|
|
*
|
|
|
|
* It support I2S only now
|
|
|
|
*/
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
|
|
|
|
break;
|
2011-10-12 09:03:21 -06:00
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
|
|
|
dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
|
|
|
|
break;
|
2009-12-13 21:21:56 -07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME
|
|
|
|
*
|
|
|
|
* It support 64bit data transmission only now
|
|
|
|
*/
|
|
|
|
dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
|
|
|
|
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
|
|
|
|
snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-19 02:49:06 -06:00
|
|
|
static int da7210_mute(struct snd_soc_dai *dai, int mute)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
|
|
|
u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
|
|
|
|
|
|
|
|
if (mute)
|
|
|
|
snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
|
|
|
|
else
|
|
|
|
snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-12 09:03:21 -06:00
|
|
|
#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2012-04-17 06:34:06 -06:00
|
|
|
static int da7210_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
|
|
|
struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
switch (clk_id) {
|
|
|
|
case DA7210_CLKSRC_MCLK:
|
|
|
|
switch (freq) {
|
|
|
|
case 12000000:
|
|
|
|
case 13000000:
|
|
|
|
case 13500000:
|
|
|
|
case 14400000:
|
|
|
|
case 19200000:
|
|
|
|
case 19680000:
|
|
|
|
case 19800000:
|
|
|
|
da7210->mclk_rate = freq;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
|
|
|
|
freq);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* da7210_set_dai_pll :Configure the codec PLL
|
|
|
|
* @param codec_dai : pointer to codec DAI
|
|
|
|
* @param pll_id : da7210 has only one pll, so pll_id is always zero
|
|
|
|
* @param fref : MCLK frequency, should be < 20MHz
|
|
|
|
* @param fout : FsDM value, Refer page 44 & 45 of datasheet
|
|
|
|
* @return int : Zero for success, negative error code for error
|
|
|
|
*
|
|
|
|
* Note: Supported PLL input frequencies are 12MHz, 13MHz, 13.5MHz, 14.4MHz,
|
|
|
|
* 19.2MHz, 19.6MHz and 19.8MHz
|
|
|
|
*/
|
|
|
|
static int da7210_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
|
|
|
|
int source, unsigned int fref, unsigned int fout)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
|
|
|
struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
u8 pll_div1, pll_div2, pll_div3, cnt;
|
|
|
|
|
|
|
|
/* In slave mode, there is only one set of divisors */
|
|
|
|
if (!da7210->master)
|
|
|
|
fout = 2822400;
|
|
|
|
|
|
|
|
/* Search pll div array for correct divisors */
|
|
|
|
for (cnt = 0; cnt < ARRAY_SIZE(da7210_pll_div); cnt++) {
|
2012-04-17 09:37:44 -06:00
|
|
|
/* check fref, mode and fout */
|
|
|
|
if ((fref == da7210_pll_div[cnt].fref) &&
|
|
|
|
(da7210->master == da7210_pll_div[cnt].mode) &&
|
|
|
|
(fout == da7210_pll_div[cnt].fout)) {
|
|
|
|
/* all match, pick up divisors */
|
|
|
|
pll_div1 = da7210_pll_div[cnt].div1;
|
|
|
|
pll_div2 = da7210_pll_div[cnt].div2;
|
|
|
|
pll_div3 = da7210_pll_div[cnt].div3;
|
|
|
|
break;
|
2012-04-17 06:34:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cnt >= ARRAY_SIZE(da7210_pll_div))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Disable active mode */
|
|
|
|
snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
|
|
|
|
/* Write PLL dividers */
|
|
|
|
snd_soc_write(codec, DA7210_PLL_DIV1, pll_div1);
|
|
|
|
snd_soc_write(codec, DA7210_PLL_DIV2, pll_div2);
|
|
|
|
snd_soc_update_bits(codec, DA7210_PLL_DIV3,
|
|
|
|
DA7210_PLL_DIV_L_MASK, pll_div3);
|
|
|
|
|
2012-05-03 07:57:52 -06:00
|
|
|
/* Enable PLL */
|
|
|
|
snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
|
|
|
|
|
2012-04-17 06:34:06 -06:00
|
|
|
/* Enable active mode */
|
|
|
|
snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN,
|
|
|
|
DA7210_SC_MST_EN);
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n", fref);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
/* DAI operations */
|
2011-11-23 03:40:40 -07:00
|
|
|
static const struct snd_soc_dai_ops da7210_dai_ops = {
|
2009-12-13 21:21:56 -07:00
|
|
|
.hw_params = da7210_hw_params,
|
|
|
|
.set_fmt = da7210_set_dai_fmt,
|
2012-04-17 06:34:06 -06:00
|
|
|
.set_sysclk = da7210_set_dai_sysclk,
|
|
|
|
.set_pll = da7210_set_dai_pll,
|
2011-10-19 02:49:06 -06:00
|
|
|
.digital_mute = da7210_mute,
|
2009-12-13 21:21:56 -07:00
|
|
|
};
|
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
static struct snd_soc_dai_driver da7210_dai = {
|
|
|
|
.name = "da7210-hifi",
|
2009-12-13 21:21:56 -07:00
|
|
|
/* playback capabilities */
|
|
|
|
.playback = {
|
|
|
|
.stream_name = "Playback",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_96000,
|
|
|
|
.formats = DA7210_FORMATS,
|
|
|
|
},
|
|
|
|
/* capture capabilities */
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "Capture",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_96000,
|
|
|
|
.formats = DA7210_FORMATS,
|
|
|
|
},
|
|
|
|
.ops = &da7210_dai_ops,
|
2010-03-10 19:37:44 -07:00
|
|
|
.symmetric_rates = 1,
|
2009-12-13 21:21:56 -07:00
|
|
|
};
|
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
static int da7210_probe(struct snd_soc_codec *codec)
|
2009-12-13 21:21:56 -07:00
|
|
|
{
|
2010-03-17 14:15:21 -06:00
|
|
|
struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2012-04-17 06:34:06 -06:00
|
|
|
da7210->mclk_rate = 0; /* This will be set from set_sysclk() */
|
|
|
|
da7210->master = 0; /* This will be set from set_fmt() */
|
|
|
|
|
|
|
|
/* Enable internal regulator & bias current */
|
|
|
|
snd_soc_write(codec, DA7210_CONTROL, DA7210_REG_EN | DA7210_BIAS_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ADC settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Enable Left & Right MIC PGA and Mic Bias */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
|
|
|
|
snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* Enable Left and Right input PGA */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
|
|
|
|
snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* Enable Left and Right ADC */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DAC settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Enable Left and Right DAC */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_DAC_SEL,
|
2009-12-13 21:21:56 -07:00
|
|
|
DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
|
|
|
|
DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
|
|
|
|
|
|
|
|
/* Enable Left and Right out PGA */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
|
|
|
|
snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* Enable Left and Right HeadPhone PGA */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_HP_CFG,
|
2009-12-13 21:21:56 -07:00
|
|
|
DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
|
|
|
|
DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
|
|
|
|
|
2011-10-19 02:49:06 -06:00
|
|
|
/* Enable ramp mode for DAC gain update */
|
|
|
|
snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
|
|
|
|
|
2011-10-21 07:36:23 -06:00
|
|
|
/*
|
|
|
|
* For DA7210 codec, there are two ways to enable/disable analog IOs
|
|
|
|
* and ADC/DAC,
|
|
|
|
* (1) Using "Enable Bit" of register associated with that IO
|
|
|
|
* (or ADC/DAC)
|
|
|
|
* e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
|
|
|
|
*
|
|
|
|
* (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
|
|
|
|
* e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
|
|
|
|
*
|
|
|
|
* Out of these two methods, the one using STANDBY bits is preferred
|
|
|
|
* way to enable/disable individual blocks. This is because STANDBY
|
|
|
|
* registers are part of system controller which allows system power
|
|
|
|
* up/down in a controlled, pop-free manner. Also, as per application
|
|
|
|
* note of DA7210, STANDBY register bits are only effective if a
|
|
|
|
* particular IO (or ADC/DAC) is already enabled using enable/disable
|
|
|
|
* register bits. Keeping these things in mind, current DAPM
|
|
|
|
* implementation manipulates only STANDBY bits.
|
|
|
|
*
|
|
|
|
* Overall implementation can be outlined as below,
|
|
|
|
*
|
|
|
|
* - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
|
|
|
|
* - "STANDBY bit" is controlled by DAPM
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Enable Line out amplifiers */
|
|
|
|
snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
|
|
|
|
snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
|
|
|
|
snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
|
|
|
|
DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
|
|
|
|
|
2012-01-02 05:05:52 -07:00
|
|
|
/* Enable Aux1 */
|
|
|
|
snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
|
|
|
|
snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
|
|
|
|
/* Enable Aux2 */
|
|
|
|
snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
|
|
|
|
|
2012-04-27 05:14:04 -06:00
|
|
|
/* Set PLL Master clock range 10-20 MHz, enable PLL bypass */
|
|
|
|
snd_soc_write(codec, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ |
|
|
|
|
DA7210_PLL_BYP);
|
2012-04-17 06:34:06 -06:00
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
/* Diable PLL and bypass it */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
|
|
|
/* Activate all enabled subsystem */
|
2011-10-11 17:16:25 -06:00
|
|
|
snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
return 0;
|
2009-12-13 21:21:56 -07:00
|
|
|
}
|
|
|
|
|
2017-08-03 10:00:19 -06:00
|
|
|
static const struct snd_soc_codec_driver soc_codec_dev_da7210 = {
|
2010-09-15 22:07:06 -06:00
|
|
|
.probe = da7210_probe,
|
2011-10-14 13:18:49 -06:00
|
|
|
|
2016-08-08 03:14:35 -06:00
|
|
|
.component_driver = {
|
|
|
|
.controls = da7210_snd_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(da7210_snd_controls),
|
|
|
|
.dapm_widgets = da7210_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
|
|
|
|
.dapm_routes = da7210_audio_map,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
|
|
|
|
},
|
2010-03-17 14:15:21 -06:00
|
|
|
};
|
|
|
|
|
2013-11-21 07:38:40 -07:00
|
|
|
#if IS_ENABLED(CONFIG_I2C)
|
2012-03-29 07:36:29 -06:00
|
|
|
|
2015-07-17 12:32:04 -06:00
|
|
|
static const struct reg_sequence da7210_regmap_i2c_patch[] = {
|
2012-03-29 07:36:29 -06:00
|
|
|
|
|
|
|
/* System controller master disable */
|
|
|
|
{ DA7210_STARTUP1, 0x00 },
|
2012-04-27 05:14:04 -06:00
|
|
|
/* Set PLL Master clock range 10-20 MHz */
|
|
|
|
{ DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ },
|
2012-03-29 07:36:29 -06:00
|
|
|
|
|
|
|
/* to unlock */
|
|
|
|
{ DA7210_A_HID_UNLOCK, 0x8B},
|
|
|
|
{ DA7210_A_TEST_UNLOCK, 0xB4},
|
|
|
|
{ DA7210_A_PLL1, 0x01},
|
|
|
|
{ DA7210_A_CP_MODE, 0x7C},
|
|
|
|
/* to re-lock */
|
|
|
|
{ DA7210_A_HID_UNLOCK, 0x00},
|
|
|
|
{ DA7210_A_TEST_UNLOCK, 0x00},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_config da7210_regmap_config_i2c = {
|
2012-03-08 06:34:56 -07:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
|
|
|
|
.reg_defaults = da7210_reg_defaults,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
|
|
|
|
.volatile_reg = da7210_volatile_register,
|
|
|
|
.readable_reg = da7210_readable_register,
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
};
|
|
|
|
|
2012-12-07 07:26:37 -07:00
|
|
|
static int da7210_i2c_probe(struct i2c_client *i2c,
|
|
|
|
const struct i2c_device_id *id)
|
2009-12-13 21:21:56 -07:00
|
|
|
{
|
|
|
|
struct da7210_priv *da7210;
|
|
|
|
int ret;
|
|
|
|
|
2011-12-26 05:54:04 -07:00
|
|
|
da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
|
|
|
|
GFP_KERNEL);
|
2009-12-13 21:21:56 -07:00
|
|
|
if (!da7210)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
i2c_set_clientdata(i2c, da7210);
|
2012-03-08 06:34:56 -07:00
|
|
|
|
2012-11-26 04:49:39 -07:00
|
|
|
da7210->regmap = devm_regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
|
2012-03-08 06:34:56 -07:00
|
|
|
if (IS_ERR(da7210->regmap)) {
|
|
|
|
ret = PTR_ERR(da7210->regmap);
|
|
|
|
dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-12-13 21:21:56 -07:00
|
|
|
|
2012-03-29 07:36:29 -06:00
|
|
|
ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
|
|
|
|
ARRAY_SIZE(da7210_regmap_i2c_patch));
|
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
|
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
ret = snd_soc_register_codec(&i2c->dev,
|
|
|
|
&soc_codec_dev_da7210, &da7210_dai, 1);
|
2012-11-26 04:49:39 -07:00
|
|
|
if (ret < 0)
|
2012-03-08 06:34:56 -07:00
|
|
|
dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
|
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-07 07:26:37 -07:00
|
|
|
static int da7210_i2c_remove(struct i2c_client *client)
|
2009-12-13 21:21:56 -07:00
|
|
|
{
|
2010-03-17 14:15:21 -06:00
|
|
|
snd_soc_unregister_codec(&client->dev);
|
2009-12-13 21:21:56 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id da7210_i2c_id[] = {
|
|
|
|
{ "da7210", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
|
|
|
|
|
|
|
|
/* I2C codec control layer */
|
|
|
|
static struct i2c_driver da7210_i2c_driver = {
|
|
|
|
.driver = {
|
2012-03-29 07:36:29 -06:00
|
|
|
.name = "da7210",
|
2009-12-13 21:21:56 -07:00
|
|
|
},
|
2010-09-15 22:07:06 -06:00
|
|
|
.probe = da7210_i2c_probe,
|
2012-12-07 07:26:37 -07:00
|
|
|
.remove = da7210_i2c_remove,
|
2010-09-15 22:07:06 -06:00
|
|
|
.id_table = da7210_i2c_id,
|
2009-12-13 21:21:56 -07:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-03-29 07:36:29 -06:00
|
|
|
#if defined(CONFIG_SPI_MASTER)
|
|
|
|
|
2015-07-17 12:32:04 -06:00
|
|
|
static const struct reg_sequence da7210_regmap_spi_patch[] = {
|
2012-03-29 07:36:29 -06:00
|
|
|
/* Dummy read to give two pulses over nCS for SPI */
|
|
|
|
{ DA7210_AUX2, 0x00 },
|
|
|
|
{ DA7210_AUX2, 0x00 },
|
|
|
|
|
|
|
|
/* System controller master disable */
|
|
|
|
{ DA7210_STARTUP1, 0x00 },
|
2012-04-27 05:14:04 -06:00
|
|
|
/* Set PLL Master clock range 10-20 MHz */
|
|
|
|
{ DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ },
|
2012-03-29 07:36:29 -06:00
|
|
|
|
|
|
|
/* to set PAGE1 of SPI register space */
|
|
|
|
{ DA7210_PAGE_CONTROL, 0x80 },
|
|
|
|
/* to unlock */
|
|
|
|
{ DA7210_A_HID_UNLOCK, 0x8B},
|
|
|
|
{ DA7210_A_TEST_UNLOCK, 0xB4},
|
|
|
|
{ DA7210_A_PLL1, 0x01},
|
|
|
|
{ DA7210_A_CP_MODE, 0x7C},
|
|
|
|
/* to re-lock */
|
|
|
|
{ DA7210_A_HID_UNLOCK, 0x00},
|
|
|
|
{ DA7210_A_TEST_UNLOCK, 0x00},
|
|
|
|
/* to set back PAGE0 of SPI register space */
|
|
|
|
{ DA7210_PAGE_CONTROL, 0x00 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_config da7210_regmap_config_spi = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
.read_flag_mask = 0x01,
|
|
|
|
.write_flag_mask = 0x00,
|
|
|
|
|
|
|
|
.reg_defaults = da7210_reg_defaults,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
|
|
|
|
.volatile_reg = da7210_volatile_register,
|
|
|
|
.readable_reg = da7210_readable_register,
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
};
|
|
|
|
|
2012-12-07 07:26:37 -07:00
|
|
|
static int da7210_spi_probe(struct spi_device *spi)
|
2012-03-29 07:36:29 -06:00
|
|
|
{
|
|
|
|
struct da7210_priv *da7210;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!da7210)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spi_set_drvdata(spi, da7210);
|
|
|
|
da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi);
|
|
|
|
if (IS_ERR(da7210->regmap)) {
|
|
|
|
ret = PTR_ERR(da7210->regmap);
|
|
|
|
dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
|
|
|
|
ARRAY_SIZE(da7210_regmap_spi_patch));
|
|
|
|
if (ret != 0)
|
|
|
|
dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
|
|
|
|
|
2012-12-03 01:13:43 -07:00
|
|
|
ret = snd_soc_register_codec(&spi->dev,
|
2012-03-29 07:36:29 -06:00
|
|
|
&soc_codec_dev_da7210, &da7210_dai, 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-07 07:26:37 -07:00
|
|
|
static int da7210_spi_remove(struct spi_device *spi)
|
2012-03-29 07:36:29 -06:00
|
|
|
{
|
|
|
|
snd_soc_unregister_codec(&spi->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spi_driver da7210_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "da7210",
|
|
|
|
},
|
|
|
|
.probe = da7210_spi_probe,
|
2012-12-07 07:26:37 -07:00
|
|
|
.remove = da7210_spi_remove
|
2012-03-29 07:36:29 -06:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-12-13 21:21:56 -07:00
|
|
|
static int __init da7210_modinit(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2013-11-21 07:38:40 -07:00
|
|
|
#if IS_ENABLED(CONFIG_I2C)
|
2009-12-13 21:21:56 -07:00
|
|
|
ret = i2c_add_driver(&da7210_i2c_driver);
|
2012-03-29 07:36:29 -06:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_SPI_MASTER)
|
|
|
|
ret = spi_register_driver(&da7210_spi_driver);
|
|
|
|
if (ret) {
|
|
|
|
printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
2009-12-13 21:21:56 -07:00
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
module_init(da7210_modinit);
|
|
|
|
|
|
|
|
static void __exit da7210_exit(void)
|
|
|
|
{
|
2013-11-21 07:38:40 -07:00
|
|
|
#if IS_ENABLED(CONFIG_I2C)
|
2009-12-13 21:21:56 -07:00
|
|
|
i2c_del_driver(&da7210_i2c_driver);
|
|
|
|
#endif
|
2012-03-29 07:36:29 -06:00
|
|
|
#if defined(CONFIG_SPI_MASTER)
|
|
|
|
spi_unregister_driver(&da7210_spi_driver);
|
|
|
|
#endif
|
2009-12-13 21:21:56 -07:00
|
|
|
}
|
|
|
|
module_exit(da7210_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ASoC DA7210 driver");
|
|
|
|
MODULE_AUTHOR("David Chen, Kuninori Morimoto");
|
|
|
|
MODULE_LICENSE("GPL");
|