Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ALSA SoC TLV320AIC3X codec driver
0004  *
0005  * Author:      Vladimir Barinov, <vbarinov@embeddedalley.com>
0006  * Copyright:   (C) 2007 MontaVista Software, Inc., <source@mvista.com>
0007  */
0008 
0009 #ifndef _AIC3X_H
0010 #define _AIC3X_H
0011 
0012 struct device;
0013 struct regmap_config;
0014 
0015 extern const struct regmap_config aic3x_regmap;
0016 int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver_data);
0017 void aic3x_remove(struct device *dev);
0018 
0019 #define AIC3X_MODEL_3X 0
0020 #define AIC3X_MODEL_33 1
0021 #define AIC3X_MODEL_3007 2
0022 #define AIC3X_MODEL_3104 3
0023 #define AIC3X_MODEL_3106 4
0024 
0025 /* AIC3X register space */
0026 #define AIC3X_CACHEREGNUM       110
0027 
0028 /* Page select register */
0029 #define AIC3X_PAGE_SELECT       0
0030 /* Software reset register */
0031 #define AIC3X_RESET         1
0032 /* Codec Sample rate select register */
0033 #define AIC3X_SAMPLE_RATE_SEL_REG   2
0034 /* PLL progrramming register A */
0035 #define AIC3X_PLL_PROGA_REG     3
0036 /* PLL progrramming register B */
0037 #define AIC3X_PLL_PROGB_REG     4
0038 /* PLL progrramming register C */
0039 #define AIC3X_PLL_PROGC_REG     5
0040 /* PLL progrramming register D */
0041 #define AIC3X_PLL_PROGD_REG     6
0042 /* Codec datapath setup register */
0043 #define AIC3X_CODEC_DATAPATH_REG    7
0044 /* Audio serial data interface control register A */
0045 #define AIC3X_ASD_INTF_CTRLA        8
0046 /* Audio serial data interface control register B */
0047 #define AIC3X_ASD_INTF_CTRLB        9
0048 /* Audio serial data interface control register C */
0049 #define AIC3X_ASD_INTF_CTRLC        10
0050 /* Audio overflow status and PLL R value programming register */
0051 #define AIC3X_OVRF_STATUS_AND_PLLR_REG  11
0052 /* Audio codec digital filter control register */
0053 #define AIC3X_CODEC_DFILT_CTRL      12
0054 /* Headset/button press detection register */
0055 #define AIC3X_HEADSET_DETECT_CTRL_A 13
0056 #define AIC3X_HEADSET_DETECT_CTRL_B 14
0057 /* ADC PGA Gain control registers */
0058 #define LADC_VOL            15
0059 #define RADC_VOL            16
0060 /* MIC3 control registers */
0061 #define MIC3LR_2_LADC_CTRL      17
0062 #define MIC3LR_2_RADC_CTRL      18
0063 /* Line1 Input control registers */
0064 #define LINE1L_2_LADC_CTRL      19
0065 #define LINE1R_2_LADC_CTRL      21
0066 #define LINE1R_2_RADC_CTRL      22
0067 #define LINE1L_2_RADC_CTRL      24
0068 /* Line2 Input control registers */
0069 #define LINE2L_2_LADC_CTRL      20
0070 #define LINE2R_2_RADC_CTRL      23
0071 /* MICBIAS Control Register */
0072 #define MICBIAS_CTRL            25
0073 
0074 /* AGC Control Registers A, B, C */
0075 #define LAGC_CTRL_A         26
0076 #define LAGC_CTRL_B         27
0077 #define LAGC_CTRL_C         28
0078 #define RAGC_CTRL_A         29
0079 #define RAGC_CTRL_B         30
0080 #define RAGC_CTRL_C         31
0081 
0082 /* DAC Power and Left High Power Output control registers */
0083 #define DAC_PWR             37
0084 #define HPLCOM_CFG          37
0085 /* Right High Power Output control registers */
0086 #define HPRCOM_CFG          38
0087 /* High Power Output Stage Control Register */
0088 #define HPOUT_SC            40
0089 /* DAC Output Switching control registers */
0090 #define DAC_LINE_MUX            41
0091 /* High Power Output Driver Pop Reduction registers */
0092 #define HPOUT_POP_REDUCTION     42
0093 /* DAC Digital control registers */
0094 #define LDAC_VOL            43
0095 #define RDAC_VOL            44
0096 /* Left High Power Output control registers */
0097 #define LINE2L_2_HPLOUT_VOL     45
0098 #define PGAL_2_HPLOUT_VOL       46
0099 #define DACL1_2_HPLOUT_VOL      47
0100 #define LINE2R_2_HPLOUT_VOL     48
0101 #define PGAR_2_HPLOUT_VOL       49
0102 #define DACR1_2_HPLOUT_VOL      50
0103 #define HPLOUT_CTRL         51
0104 /* Left High Power COM control registers */
0105 #define LINE2L_2_HPLCOM_VOL     52
0106 #define PGAL_2_HPLCOM_VOL       53
0107 #define DACL1_2_HPLCOM_VOL      54
0108 #define LINE2R_2_HPLCOM_VOL     55
0109 #define PGAR_2_HPLCOM_VOL       56
0110 #define DACR1_2_HPLCOM_VOL      57
0111 #define HPLCOM_CTRL         58
0112 /* Right High Power Output control registers */
0113 #define LINE2L_2_HPROUT_VOL     59
0114 #define PGAL_2_HPROUT_VOL       60
0115 #define DACL1_2_HPROUT_VOL      61
0116 #define LINE2R_2_HPROUT_VOL     62
0117 #define PGAR_2_HPROUT_VOL       63
0118 #define DACR1_2_HPROUT_VOL      64
0119 #define HPROUT_CTRL         65
0120 /* Right High Power COM control registers */
0121 #define LINE2L_2_HPRCOM_VOL     66
0122 #define PGAL_2_HPRCOM_VOL       67
0123 #define DACL1_2_HPRCOM_VOL      68
0124 #define LINE2R_2_HPRCOM_VOL     69
0125 #define PGAR_2_HPRCOM_VOL       70
0126 #define DACR1_2_HPRCOM_VOL      71
0127 #define HPRCOM_CTRL         72
0128 /* Mono Line Output Plus/Minus control registers */
0129 #define LINE2L_2_MONOLOPM_VOL       73
0130 #define PGAL_2_MONOLOPM_VOL     74
0131 #define DACL1_2_MONOLOPM_VOL        75
0132 #define LINE2R_2_MONOLOPM_VOL       76
0133 #define PGAR_2_MONOLOPM_VOL     77
0134 #define DACR1_2_MONOLOPM_VOL        78
0135 #define MONOLOPM_CTRL           79
0136 /* Class-D speaker driver on tlv320aic3007 */
0137 #define CLASSD_CTRL         73
0138 /* Left Line Output Plus/Minus control registers */
0139 #define LINE2L_2_LLOPM_VOL      80
0140 #define PGAL_2_LLOPM_VOL        81
0141 #define DACL1_2_LLOPM_VOL       82
0142 #define LINE2R_2_LLOPM_VOL      83
0143 #define PGAR_2_LLOPM_VOL        84
0144 #define DACR1_2_LLOPM_VOL       85
0145 #define LLOPM_CTRL          86
0146 /* Right Line Output Plus/Minus control registers */
0147 #define LINE2L_2_RLOPM_VOL      87
0148 #define PGAL_2_RLOPM_VOL        88
0149 #define DACL1_2_RLOPM_VOL       89
0150 #define LINE2R_2_RLOPM_VOL      90
0151 #define PGAR_2_RLOPM_VOL        91
0152 #define DACR1_2_RLOPM_VOL       92
0153 #define RLOPM_CTRL          93
0154 /* GPIO/IRQ registers */
0155 #define AIC3X_STICKY_IRQ_FLAGS_REG  96
0156 #define AIC3X_RT_IRQ_FLAGS_REG      97
0157 #define AIC3X_GPIO1_REG         98
0158 #define AIC3X_GPIO2_REG         99
0159 #define AIC3X_GPIOA_REG         100
0160 #define AIC3X_GPIOB_REG         101
0161 /* Clock generation control register */
0162 #define AIC3X_CLKGEN_CTRL_REG       102
0163 /* New AGC registers */
0164 #define LAGCN_ATTACK            103
0165 #define LAGCN_DECAY         104
0166 #define RAGCN_ATTACK            105
0167 #define RAGCN_DECAY         106
0168 /* New Programmable ADC Digital Path and I2C Bus Condition Register */
0169 #define NEW_ADC_DIGITALPATH     107
0170 /* Passive Analog Signal Bypass Selection During Powerdown Register */
0171 #define PASSIVE_BYPASS          108
0172 /* DAC Quiescent Current Adjustment Register */
0173 #define DAC_ICC_ADJ         109
0174 
0175 /* Page select register bits */
0176 #define PAGE0_SELECT        0
0177 #define PAGE1_SELECT        1
0178 
0179 /* Audio serial data interface control register A bits */
0180 #define BIT_CLK_MASTER          0x80
0181 #define WORD_CLK_MASTER         0x40
0182 #define DOUT_TRISTATE       0x20
0183 
0184 /* Codec Datapath setup register 7 */
0185 #define FSREF_44100     (1 << 7)
0186 #define FSREF_48000     (0 << 7)
0187 #define DUAL_RATE_MODE      ((1 << 5) | (1 << 6))
0188 #define LDAC2LCH        (0x1 << 3)
0189 #define RDAC2RCH        (0x1 << 1)
0190 #define LDAC2RCH        (0x2 << 3)
0191 #define RDAC2LCH        (0x2 << 1)
0192 #define LDAC2MONOMIX        (0x3 << 3)
0193 #define RDAC2MONOMIX        (0x3 << 1)
0194 
0195 /* PLL registers bitfields */
0196 #define PLLP_SHIFT      0
0197 #define PLLP_MASK       7
0198 #define PLLQ_SHIFT      3
0199 #define PLLR_SHIFT      0
0200 #define PLLJ_SHIFT      2
0201 #define PLLD_MSB_SHIFT      0
0202 #define PLLD_LSB_SHIFT      2
0203 
0204 /* Clock generation register bits */
0205 #define CODEC_CLKIN_PLLDIV  0
0206 #define CODEC_CLKIN_CLKDIV  1
0207 #define PLL_CLKIN_SHIFT     4
0208 #define MCLK_SOURCE     0x0
0209 #define PLL_CLKDIV_SHIFT    0
0210 #define PLLCLK_IN_MASK      0x30
0211 #define PLLCLK_IN_SHIFT     4
0212 #define CLKDIV_IN_MASK      0xc0
0213 #define CLKDIV_IN_SHIFT     6
0214 /* clock in source */
0215 #define CLKIN_MCLK      0
0216 #define CLKIN_GPIO2     1
0217 #define CLKIN_BCLK      2
0218 
0219 /* Software reset register bits */
0220 #define SOFT_RESET      0x80
0221 
0222 /* PLL progrramming register A bits */
0223 #define PLL_ENABLE      0x80
0224 
0225 /* Route bits */
0226 #define ROUTE_ON        0x80
0227 
0228 /* Mute bits */
0229 #define UNMUTE          0x08
0230 #define MUTE_ON         0x80
0231 
0232 /* Power bits */
0233 #define LADC_PWR_ON     0x04
0234 #define RADC_PWR_ON     0x04
0235 #define LDAC_PWR_ON     0x80
0236 #define RDAC_PWR_ON     0x40
0237 #define HPLOUT_PWR_ON       0x01
0238 #define HPROUT_PWR_ON       0x01
0239 #define HPLCOM_PWR_ON       0x01
0240 #define HPRCOM_PWR_ON       0x01
0241 #define MONOLOPM_PWR_ON     0x01
0242 #define LLOPM_PWR_ON        0x01
0243 #define RLOPM_PWR_ON    0x01
0244 
0245 #define INVERT_VOL(val)   (0x7f - val)
0246 
0247 /* Default output volume (inverted) */
0248 #define DEFAULT_VOL     INVERT_VOL(0x50)
0249 /* Default input volume */
0250 #define DEFAULT_GAIN    0x20
0251 
0252 /* MICBIAS Control Register */
0253 #define MICBIAS_LEVEL_SHIFT (6)
0254 #define MICBIAS_LEVEL_MASK  (3 << 6)
0255 
0256 /* HPOUT_SC */
0257 #define HPOUT_SC_OCMV_MASK  (3 << 6)
0258 #define HPOUT_SC_OCMV_SHIFT (6)
0259 #define HPOUT_SC_OCMV_1_35V 0
0260 #define HPOUT_SC_OCMV_1_5V  1
0261 #define HPOUT_SC_OCMV_1_65V 2
0262 #define HPOUT_SC_OCMV_1_8V  3
0263 
0264 /* headset detection / button API */
0265 
0266 /* The AIC3x supports detection of stereo headsets (GND + left + right signal)
0267  * and cellular headsets (GND + speaker output + microphone input).
0268  * It is recommended to enable MIC bias for this function to work properly.
0269  * For more information, please refer to the datasheet. */
0270 enum {
0271     AIC3X_HEADSET_DETECT_OFF    = 0,
0272     AIC3X_HEADSET_DETECT_STEREO = 1,
0273     AIC3X_HEADSET_DETECT_CELLULAR   = 2,
0274     AIC3X_HEADSET_DETECT_BOTH   = 3
0275 };
0276 
0277 enum {
0278     AIC3X_HEADSET_DEBOUNCE_16MS = 0,
0279     AIC3X_HEADSET_DEBOUNCE_32MS = 1,
0280     AIC3X_HEADSET_DEBOUNCE_64MS = 2,
0281     AIC3X_HEADSET_DEBOUNCE_128MS    = 3,
0282     AIC3X_HEADSET_DEBOUNCE_256MS    = 4,
0283     AIC3X_HEADSET_DEBOUNCE_512MS    = 5
0284 };
0285 
0286 enum {
0287     AIC3X_BUTTON_DEBOUNCE_0MS   = 0,
0288     AIC3X_BUTTON_DEBOUNCE_8MS   = 1,
0289     AIC3X_BUTTON_DEBOUNCE_16MS  = 2,
0290     AIC3X_BUTTON_DEBOUNCE_32MS  = 3
0291 };
0292 
0293 #define AIC3X_HEADSET_DETECT_ENABLED    0x80
0294 #define AIC3X_HEADSET_DETECT_SHIFT  5
0295 #define AIC3X_HEADSET_DETECT_MASK   3
0296 #define AIC3X_HEADSET_DEBOUNCE_SHIFT    2
0297 #define AIC3X_HEADSET_DEBOUNCE_MASK 7
0298 #define AIC3X_BUTTON_DEBOUNCE_SHIFT     0
0299 #define AIC3X_BUTTON_DEBOUNCE_MASK  3
0300 
0301 #endif /* _AIC3X_H */