/*
* ALSA SoC TWL6040 codec driver
*
* Author: Misael Lopez Cruz <x0052729@ti.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/i2c/twl.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include "twl6040.h"
#define TWL6040_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
#define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
/* codec private data */
struct twl6040_data {
int audpwron;
int naudint;
int codec_powered;
int pll;
int non_lp;
unsigned int sysclk;
struct snd_pcm_hw_constraint_list *sysclk_constraints;
struct completion ready;
};
/*
* twl6040 register cache & default register settings
*/
static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
0x00, /* not used 0x00 */
0x4B, /* TWL6040_ASICID (ro) 0x01 */
0x00, /* TWL6040_ASICREV (ro) 0x02 */
0x00, /* TWL6040_INTID 0x03 */
0x00, /* TWL6040_INTMR 0x04 */
0x00, /* TWL6040_NCPCTRL 0x05 */
0x00, /* TWL6040_LDOCTL 0x06 */
0x60, /* TWL6040_HPPLLCTL 0x07 */
0x00, /* TWL6040_LPPLLCTL 0x08 */
0x4A, /* TWL6040_LPPLLDIV 0x09 */
0x00, /* TWL6040_AMICBCTL 0x0A */
0x00, /* TWL6040_DMICBCTL 0x0B */
0x18, /* TWL6040_MICLCTL 0x0C - No input selected on Left Mic */
0x18, /* TWL6040_MICRCTL 0x0D - No input selected on Right Mic */
0x00, /* TWL6040_MICGAIN 0x0E */
0x1B, /* TWL6040_LINEGAIN 0x0F */
0x00, /* TWL6040_HSLCTL 0x10 */
0x00, /* TWL6040_HSRCTL 0x11 */
0x00, /* TWL6040_HSGAIN 0x12 */
0x00, /* TWL6040_EARCTL 0x13 */
0x00, /* TWL6040_HFLCTL 0x14 */
0x00, /* TWL6040_HFLGAIN 0x15 */
0x00, /* TWL6040_HFRCTL 0x16 */
0x00, /* TWL6040_HFRGAIN 0x17 */
0x00, /* TWL6040_VIBCTLL 0x18 */
0x00, /* TWL6040_VIBDATL 0x19 */
0x00, /* TWL6040_VIBCTLR 0x1A */
0x00, /* TWL6040_VIBDATR 0x1B */
0x00, /* TWL6040_HKCTL1 0x1C */
0x00, /* TWL6040_HKCTL2 0x1D */
0x00, /* TWL6040_GPOCTL 0x1E */
0x00, /* TWL6040_ALB 0x1F */
0x00, /* TWL6040_DLB 0x20 */
0x00, /* not used 0x21 */
0x00, /* not used 0x22 */
0x00, /* not used 0x23 */
0x00, /* not used 0x24 */
0x00, /* not used 0x25 */
0x00, /* not used 0x26 */
0x00, /* not used 0x27 */
0x00, /* TWL6040_TRIM1 0x28 */
0x00, /* TWL6040_TRIM2 0x29 */
0x00, /* TWL6040_TRIM3 0x2A */
0x00, /* TWL6040_HSOTRIM 0x2B */
0x00, /* TWL6040_HFOTRIM 0x2C */
0x09, /* TWL6040_ACCCTL 0x2D */
0x00, /* TWL6040_STATUS (ro) 0x2E */
};
/*
* twl6040 vio/gnd registers:
* registers under vio/gnd supply can be accessed
* before the power-up sequence, after NRESPWRON goes high
*/
static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = {
TWL6040_REG_ASICID,
TWL6040_REG_ASICREV,
TWL6040_REG_INTID,
TWL6040_REG_INTMR,
TWL6040_REG_NCPCTL,
TWL6040_REG_LDOCTL,
TWL6040_REG_AMICBCTL,
TWL6040_REG_DMICBCTL,
TWL6040_REG_HKCTL1,
TWL6040_REG_HKCTL2,
TWL6040_REG_GPOCTL,
TWL6040_REG_TRIM1,
TWL6040_REG_TRIM2,
TWL6040_REG_TRIM3,
TWL6040_REG_HSOTRIM,
TWL6040_REG_HFOTRIM,
TWL6040_REG_ACCCTL,
TWL6040_REG_STATUS,
};
/*
* twl6040 vdd/vss registers:
* registers under vdd/vss supplies can only be accessed
* after the power-up sequence
*/
static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = {
TWL6040_REG_HPPLLCTL,
TWL6040_REG_LPPLLCTL,
TWL6040_REG_LPPLLDIV,
TWL6040_REG_MICLCTL,
TWL6040_REG_MICRCTL,
TWL6040_REG_MICGAIN,
TWL6040_REG_LINEGAIN,
TWL6040_REG_HSLCTL,
TWL6040_REG_HSRCTL,
TWL6040_REG_HSGAIN,
TWL6040_REG_EARCTL,
TWL6040_REG_HFLCTL,
TWL6040_REG_HFLGAIN,
TWL6040_REG_HFRCTL,
TWL6040_REG_HFRGAIN,
TWL6040_REG_VIBCTLL,
TWL6040_REG_VIBDATL,
TWL6040_REG_VIBCTLR,
TWL6040_REG_VIBDATR