blob: 8e561cfabe79cae9f51e2968afc4391cea11879a [file] [log] [blame]
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only 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.
*/
#ifndef MSM8X10_WCD_H
#define MSM8X10_WCD_H
#include <sound/soc.h>
#include <sound/jack.h>
#include "wcd9xxx-mbhc.h"
#include "wcd9xxx-resmgr.h"
#define MSM8X10_WCD_NUM_REGISTERS 0x600
#define MSM8X10_WCD_MAX_REGISTER (MSM8X10_WCD_NUM_REGISTERS-1)
#define MSM8X10_WCD_CACHE_SIZE MSM8X10_WCD_NUM_REGISTERS
#define MSM8X10_WCD_NUM_IRQ_REGS 3
#define MAX_REGULATOR 7
#define MSM8X10_WCD_REG_VAL(reg, val) {reg, 0, val}
#define MSM8X10_DINO_LPASS_AUDIO_CORE_DIG_CODEC_CLK_SEL 0xFE03B004
#define MSM8X10_DINO_LPASS_DIGCODEC_CMD_RCGR 0xFE02C000
#define MSM8X10_DINO_LPASS_DIGCODEC_CFG_RCGR 0xFE02C004
#define MSM8X10_DINO_LPASS_DIGCODEC_M 0xFE02C008
#define MSM8X10_DINO_LPASS_DIGCODEC_N 0xFE02C00C
#define MSM8X10_DINO_LPASS_DIGCODEC_D 0xFE02C010
#define MSM8X10_DINO_LPASS_DIGCODEC_CBCR 0xFE02C014
#define MSM8X10_DINO_LPASS_DIGCODEC_AHB_CBCR 0xFE02C018
#define MSM8X10_CODEC_NAME "msm8x10_wcd_codec"
#define MSM8X10_WCD_IS_DINO_REG(reg) \
(((reg >= 0x400) && (reg <= 0x5FF)) ? 1 : 0)
#define MSM8X10_WCD_IS_HELICON_REG(reg) \
(((reg >= 0x000) && (reg <= 0x1FF)) ? 1 : 0)
extern const u8 msm8x10_wcd_reg_readable[MSM8X10_WCD_CACHE_SIZE];
extern const u8 msm8x10_wcd_reset_reg_defaults[MSM8X10_WCD_CACHE_SIZE];
struct msm8x10_wcd_codec_dai_data {
u32 rate;
u32 *ch_num;
u32 ch_act;
u32 ch_tot;
};
enum msm8x10_wcd_pid_current {
MSM8X10_WCD_PID_MIC_2P5_UA,
MSM8X10_WCD_PID_MIC_5_UA,
MSM8X10_WCD_PID_MIC_10_UA,
MSM8X10_WCD_PID_MIC_20_UA,
};
struct msm8x10_wcd_reg_mask_val {
u16 reg;
u8 mask;
u8 val;
};
enum msm8x10_wcd_mbhc_analog_pwr_cfg {
MSM8X10_WCD_ANALOG_PWR_COLLAPSED = 0,
MSM8X10_WCD_ANALOG_PWR_ON,
MSM8X10_WCD_NUM_ANALOG_PWR_CONFIGS,
};
/* Number of input and output Slimbus port */
enum {
MSM8X10_WCD_RX1 = 0,
MSM8X10_WCD_RX2,
MSM8X10_WCD_RX3,
MSM8X10_WCD_RX_MAX,
};
enum {
MSM8X10_WCD_TX1 = 0,
MSM8X10_WCD_TX2,
MSM8X10_WCD_TX3,
MSM8X10_WCD_TX4,
MSM8X10_WCD_TX_MAX,
};
enum {
/* INTR_REG 0 */
MSM8X10_WCD_IRQ_RESERVED_0 = 0,
MSM8X10_WCD_IRQ_MBHC_REMOVAL,
MSM8X10_WCD_IRQ_MBHC_SHORT_TERM,
MSM8X10_WCD_IRQ_MBHC_PRESS,
MSM8X10_WCD_IRQ_MBHC_RELEASE,
MSM8X10_WCD_IRQ_MBHC_POTENTIAL,
MSM8X10_WCD_IRQ_MBHC_INSERTION,
MSM8X10_WCD_IRQ_MBHC_HS_DET,
/* INTR_REG 1 */
MSM8X10_WCD_IRQ_PA_STARTUP,
MSM8X10_WCD_IRQ_BG_PRECHARGE,
MSM8X10_WCD_IRQ_RESERVED_1,
MSM8X10_WCD_IRQ_EAR_PA_OCPL_FAULT,
MSM8X10_WCD_IRQ_EAR_PA_STARTUP,
MSM8X10_WCD_IRQ_SPKR_PA_OCPL_FAULT,
MSM8X10_WCD_IRQ_SPKR_CLIP_FAULT,
MSM8X10_WCD_IRQ_RESERVED_2,
/* INTR_REG 2 */
MSM8X10_WCD_IRQ_HPH_L_PA_STARTUP,
MSM8X10_WCD_IRQ_HPH_R_PA_STARTUP,
MSM8X10_WCD_IRQ_HPH_PA_OCPL_FAULT,
MSM8X10_WCD_IRQ_HPH_PA_OCPR_FAULT,
MSM8X10_WCD_IRQ_RESERVED_3,
MSM8X10_WCD_IRQ_RESERVED_4,
MSM8X10_WCD_IRQ_RESERVED_5,
MSM8X10_WCD_IRQ_RESERVED_6,
MSM8X10_WCD_NUM_IRQS,
};
/*
* Each micbias can be assigned to one of three cfilters
* Vbatt_min >= .15V + ldoh_v
* ldoh_v >= .15v + cfiltx_mv
* If ldoh_v = 1.95 160 mv < cfiltx_mv < 1800 mv
* If ldoh_v = 2.35 200 mv < cfiltx_mv < 2200 mv
* If ldoh_v = 2.75 240 mv < cfiltx_mv < 2600 mv
* If ldoh_v = 2.85 250 mv < cfiltx_mv < 2700 mv
*/
struct msm8x10_wcd_micbias_setting {
u8 ldoh_v;
u32 cfilt1_mv; /* in mv */
/*
* Different WCD9xxx series codecs may not
* have 4 mic biases. If a codec has fewer
* mic biases, some of these properties will
* not be used.
*/
u8 bias1_cfilt_sel;
u8 bias1_cap_mode;
};
struct msm8x10_wcd_ocp_setting {
unsigned int use_pdata:1; /* 0 - use sys default as recommended */
unsigned int num_attempts:4; /* up to 15 attempts */
unsigned int run_time:4; /* in duty cycle */
unsigned int wait_time:4; /* in duty cycle */
unsigned int hph_ocp_limit:3; /* Headphone OCP current limit */
};
struct msm8x10_wcd_regulator {
const char *name;
int min_uV;
int max_uV;
int optimum_uA;
bool ondemand;
struct regulator *regulator;
};
struct msm8x10_wcd_pdata {
int irq;
int irq_base;
int num_irqs;
int reset_gpio;
void *msm8x10_wcd_ahb_base_vaddr;
struct msm8x10_wcd_micbias_setting micbias;
struct msm8x10_wcd_ocp_setting ocp;
struct msm8x10_wcd_regulator regulator[MAX_REGULATOR];
u32 mclk_rate;
};
enum msm8x10_wcd_micbias_num {
MSM8X10_WCD_MICBIAS1 = 0,
};
struct msm8x10_wcd_mbhc_config {
struct snd_soc_jack *headset_jack;
struct snd_soc_jack *button_jack;
bool read_fw_bin;
/*
* void* calibration contains:
* struct msm8x10_wcd_mbhc_general_cfg generic;
* struct msm8x10_wcd_mbhc_plug_detect_cfg plug_det;
* struct msm8x10_wcd_mbhc_plug_type_cfg plug_type;
* struct msm8x10_wcd_mbhc_btn_detect_cfg btn_det;
* struct msm8x10_wcd_mbhc_imped_detect_cfg imped_det;
* Note: various size depends on btn_det->num_btn
*/
void *calibration;
enum msm8x10_wcd_micbias_num micbias;
int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool);
unsigned int mclk_rate;
unsigned int gpio;
unsigned int gpio_irq;
int gpio_level_insert;
bool detect_extn_cable;
/* swap_gnd_mic returns true if extern GND/MIC swap switch toggled */
bool (*swap_gnd_mic) (struct snd_soc_codec *);
};
enum msm8x10_wcd_pm_state {
MSM8X10_WCD_PM_SLEEPABLE,
MSM8X10_WCD_PM_AWAKE,
MSM8X10_WCD_PM_ASLEEP,
};
struct msm8x10_wcd {
struct device *dev;
struct mutex io_lock;
struct mutex xfer_lock;
struct mutex irq_lock;
u8 version;
int reset_gpio;
int (*read_dev)(struct msm8x10_wcd *msm8x10,
unsigned short reg, unsigned int *val);
int (*write_dev)(struct msm8x10_wcd *msm8x10,
unsigned short reg, u8 val);
u32 num_of_supplies;
struct regulator_bulk_data *supplies;
enum msm8x10_wcd_pm_state pm_state;
struct mutex pm_lock;
/* pm_wq notifies change of pm_state */
wait_queue_head_t pm_wq;
struct pm_qos_request pm_qos_req;
int wlock_holders;
u8 idbyte[4];
unsigned int irq_base;
unsigned int irq;
u8 irq_masks_cur[MSM8X10_WCD_NUM_IRQ_REGS];
u8 irq_masks_cache[MSM8X10_WCD_NUM_IRQ_REGS];
bool irq_level_high[MSM8X10_WCD_NUM_IRQS];
int num_irqs;
u32 mclk_rate;
};
extern int msm8x10_wcd_mclk_enable(struct snd_soc_codec *codec, int mclk_enable,
bool dapm);
extern int msm8x10_wcd_hs_detect(struct snd_soc_codec *codec,
struct msm8x10_wcd_mbhc_config *mbhc_cfg);
#endif