144d0a879SVladimir Barinov /* 244d0a879SVladimir Barinov * ALSA SoC TLV320AIC3X codec driver 344d0a879SVladimir Barinov * 4d6b52039SVladimir Barinov * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> 544d0a879SVladimir Barinov * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> 644d0a879SVladimir Barinov * 744d0a879SVladimir Barinov * This program is free software; you can redistribute it and/or modify 844d0a879SVladimir Barinov * it under the terms of the GNU General Public License version 2 as 944d0a879SVladimir Barinov * published by the Free Software Foundation. 1044d0a879SVladimir Barinov */ 1144d0a879SVladimir Barinov 1244d0a879SVladimir Barinov #ifndef _AIC3X_H 1344d0a879SVladimir Barinov #define _AIC3X_H 1444d0a879SVladimir Barinov 1544d0a879SVladimir Barinov /* AIC3X register space */ 1644d0a879SVladimir Barinov #define AIC3X_CACHEREGNUM 103 1744d0a879SVladimir Barinov 1844d0a879SVladimir Barinov /* Page select register */ 1944d0a879SVladimir Barinov #define AIC3X_PAGE_SELECT 0 2044d0a879SVladimir Barinov /* Software reset register */ 2144d0a879SVladimir Barinov #define AIC3X_RESET 1 2244d0a879SVladimir Barinov /* Codec Sample rate select register */ 2344d0a879SVladimir Barinov #define AIC3X_SAMPLE_RATE_SEL_REG 2 2444d0a879SVladimir Barinov /* PLL progrramming register A */ 2544d0a879SVladimir Barinov #define AIC3X_PLL_PROGA_REG 3 2644d0a879SVladimir Barinov /* PLL progrramming register B */ 2744d0a879SVladimir Barinov #define AIC3X_PLL_PROGB_REG 4 2844d0a879SVladimir Barinov /* PLL progrramming register C */ 2944d0a879SVladimir Barinov #define AIC3X_PLL_PROGC_REG 5 3044d0a879SVladimir Barinov /* PLL progrramming register D */ 3144d0a879SVladimir Barinov #define AIC3X_PLL_PROGD_REG 6 3244d0a879SVladimir Barinov /* Codec datapath setup register */ 3344d0a879SVladimir Barinov #define AIC3X_CODEC_DATAPATH_REG 7 3444d0a879SVladimir Barinov /* Audio serial data interface control register A */ 3544d0a879SVladimir Barinov #define AIC3X_ASD_INTF_CTRLA 8 3644d0a879SVladimir Barinov /* Audio serial data interface control register B */ 3744d0a879SVladimir Barinov #define AIC3X_ASD_INTF_CTRLB 9 38a24f4f68STroy Kisky /* Audio serial data interface control register C */ 39a24f4f68STroy Kisky #define AIC3X_ASD_INTF_CTRLC 10 4044d0a879SVladimir Barinov /* Audio overflow status and PLL R value programming register */ 4144d0a879SVladimir Barinov #define AIC3X_OVRF_STATUS_AND_PLLR_REG 11 424d20f70aSJarkko Nikula /* Audio codec digital filter control register */ 434d20f70aSJarkko Nikula #define AIC3X_CODEC_DFILT_CTRL 12 446f2a974bSDaniel Mack /* Headset/button press detection register */ 456f2a974bSDaniel Mack #define AIC3X_HEADSET_DETECT_CTRL_A 13 466f2a974bSDaniel Mack #define AIC3X_HEADSET_DETECT_CTRL_B 14 4744d0a879SVladimir Barinov /* ADC PGA Gain control registers */ 4844d0a879SVladimir Barinov #define LADC_VOL 15 4944d0a879SVladimir Barinov #define RADC_VOL 16 5044d0a879SVladimir Barinov /* MIC3 control registers */ 5144d0a879SVladimir Barinov #define MIC3LR_2_LADC_CTRL 17 5244d0a879SVladimir Barinov #define MIC3LR_2_RADC_CTRL 18 5344d0a879SVladimir Barinov /* Line1 Input control registers */ 5444d0a879SVladimir Barinov #define LINE1L_2_LADC_CTRL 19 5554f01916SDaniel Mack #define LINE1R_2_LADC_CTRL 21 5644d0a879SVladimir Barinov #define LINE1R_2_RADC_CTRL 22 5754f01916SDaniel Mack #define LINE1L_2_RADC_CTRL 24 5844d0a879SVladimir Barinov /* Line2 Input control registers */ 5944d0a879SVladimir Barinov #define LINE2L_2_LADC_CTRL 20 6044d0a879SVladimir Barinov #define LINE2R_2_RADC_CTRL 23 6144d0a879SVladimir Barinov /* MICBIAS Control Register */ 6244d0a879SVladimir Barinov #define MICBIAS_CTRL 25 6344d0a879SVladimir Barinov 6444d0a879SVladimir Barinov /* AGC Control Registers A, B, C */ 6544d0a879SVladimir Barinov #define LAGC_CTRL_A 26 6644d0a879SVladimir Barinov #define LAGC_CTRL_B 27 6744d0a879SVladimir Barinov #define LAGC_CTRL_C 28 6844d0a879SVladimir Barinov #define RAGC_CTRL_A 29 6944d0a879SVladimir Barinov #define RAGC_CTRL_B 30 7044d0a879SVladimir Barinov #define RAGC_CTRL_C 31 7144d0a879SVladimir Barinov 7244d0a879SVladimir Barinov /* DAC Power and Left High Power Output control registers */ 7344d0a879SVladimir Barinov #define DAC_PWR 37 7444d0a879SVladimir Barinov #define HPLCOM_CFG 37 7544d0a879SVladimir Barinov /* Right High Power Output control registers */ 7644d0a879SVladimir Barinov #define HPRCOM_CFG 38 7744d0a879SVladimir Barinov /* DAC Output Switching control registers */ 7844d0a879SVladimir Barinov #define DAC_LINE_MUX 41 7944d0a879SVladimir Barinov /* High Power Output Driver Pop Reduction registers */ 8044d0a879SVladimir Barinov #define HPOUT_POP_REDUCTION 42 8144d0a879SVladimir Barinov /* DAC Digital control registers */ 8244d0a879SVladimir Barinov #define LDAC_VOL 43 8344d0a879SVladimir Barinov #define RDAC_VOL 44 8444d0a879SVladimir Barinov /* High Power Output control registers */ 8544d0a879SVladimir Barinov #define LINE2L_2_HPLOUT_VOL 45 8644d0a879SVladimir Barinov #define LINE2R_2_HPROUT_VOL 62 8744d0a879SVladimir Barinov #define PGAL_2_HPLOUT_VOL 46 8854f01916SDaniel Mack #define PGAL_2_HPROUT_VOL 60 8954f01916SDaniel Mack #define PGAR_2_HPLOUT_VOL 49 9044d0a879SVladimir Barinov #define PGAR_2_HPROUT_VOL 63 9144d0a879SVladimir Barinov #define DACL1_2_HPLOUT_VOL 47 9244d0a879SVladimir Barinov #define DACR1_2_HPROUT_VOL 64 9344d0a879SVladimir Barinov #define HPLOUT_CTRL 51 9444d0a879SVladimir Barinov #define HPROUT_CTRL 65 9544d0a879SVladimir Barinov /* High Power COM control registers */ 9644d0a879SVladimir Barinov #define LINE2L_2_HPLCOM_VOL 52 9744d0a879SVladimir Barinov #define LINE2R_2_HPRCOM_VOL 69 9844d0a879SVladimir Barinov #define PGAL_2_HPLCOM_VOL 53 9954f01916SDaniel Mack #define PGAR_2_HPLCOM_VOL 56 10054f01916SDaniel Mack #define PGAL_2_HPRCOM_VOL 67 10144d0a879SVladimir Barinov #define PGAR_2_HPRCOM_VOL 70 10244d0a879SVladimir Barinov #define DACL1_2_HPLCOM_VOL 54 10344d0a879SVladimir Barinov #define DACR1_2_HPRCOM_VOL 71 10444d0a879SVladimir Barinov #define HPLCOM_CTRL 58 10544d0a879SVladimir Barinov #define HPRCOM_CTRL 72 10644d0a879SVladimir Barinov /* Mono Line Output Plus/Minus control registers */ 10744d0a879SVladimir Barinov #define LINE2L_2_MONOLOPM_VOL 73 10844d0a879SVladimir Barinov #define LINE2R_2_MONOLOPM_VOL 76 10944d0a879SVladimir Barinov #define PGAL_2_MONOLOPM_VOL 74 11044d0a879SVladimir Barinov #define PGAR_2_MONOLOPM_VOL 77 11144d0a879SVladimir Barinov #define DACL1_2_MONOLOPM_VOL 75 11244d0a879SVladimir Barinov #define DACR1_2_MONOLOPM_VOL 78 11344d0a879SVladimir Barinov #define MONOLOPM_CTRL 79 1146184f105SRandolph Chung /* Class-D speaker driver on tlv320aic3007 */ 1156184f105SRandolph Chung #define CLASSD_CTRL 73 11644d0a879SVladimir Barinov /* Line Output Plus/Minus control registers */ 11744d0a879SVladimir Barinov #define LINE2L_2_LLOPM_VOL 80 11854f01916SDaniel Mack #define LINE2L_2_RLOPM_VOL 87 11954f01916SDaniel Mack #define LINE2R_2_LLOPM_VOL 83 12044d0a879SVladimir Barinov #define LINE2R_2_RLOPM_VOL 90 12144d0a879SVladimir Barinov #define PGAL_2_LLOPM_VOL 81 12254f01916SDaniel Mack #define PGAL_2_RLOPM_VOL 88 12354f01916SDaniel Mack #define PGAR_2_LLOPM_VOL 84 12444d0a879SVladimir Barinov #define PGAR_2_RLOPM_VOL 91 12544d0a879SVladimir Barinov #define DACL1_2_LLOPM_VOL 82 12654f01916SDaniel Mack #define DACL1_2_RLOPM_VOL 89 12744d0a879SVladimir Barinov #define DACR1_2_RLOPM_VOL 92 12854f01916SDaniel Mack #define DACR1_2_LLOPM_VOL 85 12944d0a879SVladimir Barinov #define LLOPM_CTRL 86 13044d0a879SVladimir Barinov #define RLOPM_CTRL 93 13154e7e616SDaniel Mack /* GPIO/IRQ registers */ 13254e7e616SDaniel Mack #define AIC3X_STICKY_IRQ_FLAGS_REG 96 13354e7e616SDaniel Mack #define AIC3X_RT_IRQ_FLAGS_REG 97 13454e7e616SDaniel Mack #define AIC3X_GPIO1_REG 98 13554e7e616SDaniel Mack #define AIC3X_GPIO2_REG 99 13654e7e616SDaniel Mack #define AIC3X_GPIOA_REG 100 1374f9c16ccSDaniel Mack #define AIC3X_GPIOB_REG 101 13854e7e616SDaniel Mack /* Clock generation control register */ 13944d0a879SVladimir Barinov #define AIC3X_CLKGEN_CTRL_REG 102 14044d0a879SVladimir Barinov 14144d0a879SVladimir Barinov /* Page select register bits */ 14244d0a879SVladimir Barinov #define PAGE0_SELECT 0 14344d0a879SVladimir Barinov #define PAGE1_SELECT 1 14444d0a879SVladimir Barinov 14544d0a879SVladimir Barinov /* Audio serial data interface control register A bits */ 14644d0a879SVladimir Barinov #define BIT_CLK_MASTER 0x80 14744d0a879SVladimir Barinov #define WORD_CLK_MASTER 0x40 14844d0a879SVladimir Barinov 14944d0a879SVladimir Barinov /* Codec Datapath setup register 7 */ 15044d0a879SVladimir Barinov #define FSREF_44100 (1 << 7) 15144d0a879SVladimir Barinov #define FSREF_48000 (0 << 7) 15244d0a879SVladimir Barinov #define DUAL_RATE_MODE ((1 << 5) | (1 << 6)) 15344d0a879SVladimir Barinov #define LDAC2LCH (0x1 << 3) 15444d0a879SVladimir Barinov #define RDAC2RCH (0x1 << 1) 15544d0a879SVladimir Barinov 15644d0a879SVladimir Barinov /* PLL registers bitfields */ 15744d0a879SVladimir Barinov #define PLLP_SHIFT 0 1584f9c16ccSDaniel Mack #define PLLQ_SHIFT 3 15944d0a879SVladimir Barinov #define PLLR_SHIFT 0 16044d0a879SVladimir Barinov #define PLLJ_SHIFT 2 16144d0a879SVladimir Barinov #define PLLD_MSB_SHIFT 0 16244d0a879SVladimir Barinov #define PLLD_LSB_SHIFT 2 16344d0a879SVladimir Barinov 16444d0a879SVladimir Barinov /* Clock generation register bits */ 1654f9c16ccSDaniel Mack #define CODEC_CLKIN_PLLDIV 0 1664f9c16ccSDaniel Mack #define CODEC_CLKIN_CLKDIV 1 16744d0a879SVladimir Barinov #define PLL_CLKIN_SHIFT 4 16844d0a879SVladimir Barinov #define MCLK_SOURCE 0x0 16944d0a879SVladimir Barinov #define PLL_CLKDIV_SHIFT 0 17044d0a879SVladimir Barinov 17144d0a879SVladimir Barinov /* Software reset register bits */ 17244d0a879SVladimir Barinov #define SOFT_RESET 0x80 17344d0a879SVladimir Barinov 17444d0a879SVladimir Barinov /* PLL progrramming register A bits */ 17544d0a879SVladimir Barinov #define PLL_ENABLE 0x80 17644d0a879SVladimir Barinov 17744d0a879SVladimir Barinov /* Route bits */ 17844d0a879SVladimir Barinov #define ROUTE_ON 0x80 17944d0a879SVladimir Barinov 18044d0a879SVladimir Barinov /* Mute bits */ 18144d0a879SVladimir Barinov #define UNMUTE 0x08 18244d0a879SVladimir Barinov #define MUTE_ON 0x80 18344d0a879SVladimir Barinov 18444d0a879SVladimir Barinov /* Power bits */ 18544d0a879SVladimir Barinov #define LADC_PWR_ON 0x04 18644d0a879SVladimir Barinov #define RADC_PWR_ON 0x04 18744d0a879SVladimir Barinov #define LDAC_PWR_ON 0x80 18844d0a879SVladimir Barinov #define RDAC_PWR_ON 0x40 18944d0a879SVladimir Barinov #define HPLOUT_PWR_ON 0x01 19044d0a879SVladimir Barinov #define HPROUT_PWR_ON 0x01 19144d0a879SVladimir Barinov #define HPLCOM_PWR_ON 0x01 19244d0a879SVladimir Barinov #define HPRCOM_PWR_ON 0x01 19344d0a879SVladimir Barinov #define MONOLOPM_PWR_ON 0x01 19444d0a879SVladimir Barinov #define LLOPM_PWR_ON 0x01 19544d0a879SVladimir Barinov #define RLOPM_PWR_ON 0x01 19644d0a879SVladimir Barinov 19744d0a879SVladimir Barinov #define INVERT_VOL(val) (0x7f - val) 19844d0a879SVladimir Barinov 19944d0a879SVladimir Barinov /* Default output volume (inverted) */ 20044d0a879SVladimir Barinov #define DEFAULT_VOL INVERT_VOL(0x50) 20144d0a879SVladimir Barinov /* Default input volume */ 20244d0a879SVladimir Barinov #define DEFAULT_GAIN 0x20 20344d0a879SVladimir Barinov 20454e7e616SDaniel Mack void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state); 20554e7e616SDaniel Mack int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio); 2066f2a974bSDaniel Mack 2076f2a974bSDaniel Mack /* headset detection / button API */ 2086f2a974bSDaniel Mack 2096f2a974bSDaniel Mack /* The AIC3x supports detection of stereo headsets (GND + left + right signal) 2106f2a974bSDaniel Mack * and cellular headsets (GND + speaker output + microphone input). 2116f2a974bSDaniel Mack * It is recommended to enable MIC bias for this function to work properly. 2126f2a974bSDaniel Mack * For more information, please refer to the datasheet. */ 2136f2a974bSDaniel Mack enum { 2146f2a974bSDaniel Mack AIC3X_HEADSET_DETECT_OFF = 0, 2156f2a974bSDaniel Mack AIC3X_HEADSET_DETECT_STEREO = 1, 2166f2a974bSDaniel Mack AIC3X_HEADSET_DETECT_CELLULAR = 2, 2176f2a974bSDaniel Mack AIC3X_HEADSET_DETECT_BOTH = 3 2186f2a974bSDaniel Mack }; 2196f2a974bSDaniel Mack 2206f2a974bSDaniel Mack enum { 2216f2a974bSDaniel Mack AIC3X_HEADSET_DEBOUNCE_16MS = 0, 2226f2a974bSDaniel Mack AIC3X_HEADSET_DEBOUNCE_32MS = 1, 2236f2a974bSDaniel Mack AIC3X_HEADSET_DEBOUNCE_64MS = 2, 2246f2a974bSDaniel Mack AIC3X_HEADSET_DEBOUNCE_128MS = 3, 2256f2a974bSDaniel Mack AIC3X_HEADSET_DEBOUNCE_256MS = 4, 2266f2a974bSDaniel Mack AIC3X_HEADSET_DEBOUNCE_512MS = 5 2276f2a974bSDaniel Mack }; 2286f2a974bSDaniel Mack 2296f2a974bSDaniel Mack enum { 2306f2a974bSDaniel Mack AIC3X_BUTTON_DEBOUNCE_0MS = 0, 2316f2a974bSDaniel Mack AIC3X_BUTTON_DEBOUNCE_8MS = 1, 2326f2a974bSDaniel Mack AIC3X_BUTTON_DEBOUNCE_16MS = 2, 2336f2a974bSDaniel Mack AIC3X_BUTTON_DEBOUNCE_32MS = 3 2346f2a974bSDaniel Mack }; 2356f2a974bSDaniel Mack 2366f2a974bSDaniel Mack #define AIC3X_HEADSET_DETECT_ENABLED 0x80 2376f2a974bSDaniel Mack #define AIC3X_HEADSET_DETECT_SHIFT 5 2386f2a974bSDaniel Mack #define AIC3X_HEADSET_DETECT_MASK 3 2396f2a974bSDaniel Mack #define AIC3X_HEADSET_DEBOUNCE_SHIFT 2 2406f2a974bSDaniel Mack #define AIC3X_HEADSET_DEBOUNCE_MASK 7 2416f2a974bSDaniel Mack #define AIC3X_BUTTON_DEBOUNCE_SHIFT 0 2426f2a974bSDaniel Mack #define AIC3X_BUTTON_DEBOUNCE_MASK 3 2436f2a974bSDaniel Mack 2446f2a974bSDaniel Mack /* see the enums above for valid parameters to this function */ 2456f2a974bSDaniel Mack void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect, 2466f2a974bSDaniel Mack int headset_debounce, int button_debounce); 24754e7e616SDaniel Mack int aic3x_headset_detected(struct snd_soc_codec *codec); 2486f2a974bSDaniel Mack int aic3x_button_pressed(struct snd_soc_codec *codec); 24954e7e616SDaniel Mack 25044d0a879SVladimir Barinov #endif /* _AIC3X_H */ 251