140bc18a2SBard Liao /* 240bc18a2SBard Liao * rt5651.c -- RT5651 ALSA SoC audio codec driver 340bc18a2SBard Liao * 440bc18a2SBard Liao * Copyright 2014 Realtek Semiconductor Corp. 540bc18a2SBard Liao * Author: Bard Liao <bardliao@realtek.com> 640bc18a2SBard Liao * 740bc18a2SBard Liao * This program is free software; you can redistribute it and/or modify 840bc18a2SBard Liao * it under the terms of the GNU General Public License version 2 as 940bc18a2SBard Liao * published by the Free Software Foundation. 1040bc18a2SBard Liao */ 1140bc18a2SBard Liao 1240bc18a2SBard Liao #include <linux/module.h> 1340bc18a2SBard Liao #include <linux/moduleparam.h> 1440bc18a2SBard Liao #include <linux/init.h> 1540bc18a2SBard Liao #include <linux/delay.h> 1640bc18a2SBard Liao #include <linux/pm.h> 1740bc18a2SBard Liao #include <linux/i2c.h> 1840bc18a2SBard Liao #include <linux/regmap.h> 1940bc18a2SBard Liao #include <linux/platform_device.h> 2040bc18a2SBard Liao #include <linux/spi/spi.h> 213ae08dc0SBard Liao #include <linux/acpi.h> 22b4435130SCarlo Caione #include <linux/dmi.h> 2340bc18a2SBard Liao #include <sound/core.h> 2440bc18a2SBard Liao #include <sound/pcm.h> 2540bc18a2SBard Liao #include <sound/pcm_params.h> 2640bc18a2SBard Liao #include <sound/soc.h> 2740bc18a2SBard Liao #include <sound/soc-dapm.h> 2840bc18a2SBard Liao #include <sound/initval.h> 2940bc18a2SBard Liao #include <sound/tlv.h> 3080bbe4a3SCarlo Caione #include <sound/jack.h> 3140bc18a2SBard Liao 3249ef7925SOder Chiou #include "rl6231.h" 3340bc18a2SBard Liao #include "rt5651.h" 3440bc18a2SBard Liao 35b4435130SCarlo Caione #define RT5651_JD_MAP(quirk) ((quirk) & GENMASK(7, 0)) 36b4435130SCarlo Caione 3740bc18a2SBard Liao #define RT5651_DEVICE_ID_VALUE 0x6281 3840bc18a2SBard Liao 3940bc18a2SBard Liao #define RT5651_PR_RANGE_BASE (0xff + 1) 4040bc18a2SBard Liao #define RT5651_PR_SPACING 0x100 4140bc18a2SBard Liao 4240bc18a2SBard Liao #define RT5651_PR_BASE (RT5651_PR_RANGE_BASE + (0 * RT5651_PR_SPACING)) 4340bc18a2SBard Liao 44b4435130SCarlo Caione static unsigned long rt5651_quirk; 45b4435130SCarlo Caione 4640bc18a2SBard Liao static const struct regmap_range_cfg rt5651_ranges[] = { 4740bc18a2SBard Liao { .name = "PR", .range_min = RT5651_PR_BASE, 4840bc18a2SBard Liao .range_max = RT5651_PR_BASE + 0xb4, 4940bc18a2SBard Liao .selector_reg = RT5651_PRIV_INDEX, 5040bc18a2SBard Liao .selector_mask = 0xff, 5140bc18a2SBard Liao .selector_shift = 0x0, 5240bc18a2SBard Liao .window_start = RT5651_PRIV_DATA, 5340bc18a2SBard Liao .window_len = 0x1, }, 5440bc18a2SBard Liao }; 5540bc18a2SBard Liao 5641a5fefeSMark Brown static const struct reg_sequence init_list[] = { 5740bc18a2SBard Liao {RT5651_PR_BASE + 0x3d, 0x3e00}, 5840bc18a2SBard Liao }; 5940bc18a2SBard Liao 6040bc18a2SBard Liao static const struct reg_default rt5651_reg[] = { 6140bc18a2SBard Liao { 0x00, 0x0000 }, 6240bc18a2SBard Liao { 0x02, 0xc8c8 }, 6340bc18a2SBard Liao { 0x03, 0xc8c8 }, 6440bc18a2SBard Liao { 0x05, 0x0000 }, 6540bc18a2SBard Liao { 0x0d, 0x0000 }, 6640bc18a2SBard Liao { 0x0e, 0x0000 }, 6740bc18a2SBard Liao { 0x0f, 0x0808 }, 6840bc18a2SBard Liao { 0x10, 0x0808 }, 6940bc18a2SBard Liao { 0x19, 0xafaf }, 7040bc18a2SBard Liao { 0x1a, 0xafaf }, 7140bc18a2SBard Liao { 0x1b, 0x0c00 }, 7240bc18a2SBard Liao { 0x1c, 0x2f2f }, 7340bc18a2SBard Liao { 0x1d, 0x2f2f }, 7440bc18a2SBard Liao { 0x1e, 0x0000 }, 7540bc18a2SBard Liao { 0x27, 0x7860 }, 7640bc18a2SBard Liao { 0x28, 0x7070 }, 7740bc18a2SBard Liao { 0x29, 0x8080 }, 7840bc18a2SBard Liao { 0x2a, 0x5252 }, 7940bc18a2SBard Liao { 0x2b, 0x5454 }, 8040bc18a2SBard Liao { 0x2f, 0x0000 }, 8140bc18a2SBard Liao { 0x30, 0x5000 }, 8240bc18a2SBard Liao { 0x3b, 0x0000 }, 8340bc18a2SBard Liao { 0x3c, 0x006f }, 8440bc18a2SBard Liao { 0x3d, 0x0000 }, 8540bc18a2SBard Liao { 0x3e, 0x006f }, 8640bc18a2SBard Liao { 0x45, 0x6000 }, 8740bc18a2SBard Liao { 0x4d, 0x0000 }, 8840bc18a2SBard Liao { 0x4e, 0x0000 }, 8940bc18a2SBard Liao { 0x4f, 0x0279 }, 9040bc18a2SBard Liao { 0x50, 0x0000 }, 9140bc18a2SBard Liao { 0x51, 0x0000 }, 9240bc18a2SBard Liao { 0x52, 0x0279 }, 9340bc18a2SBard Liao { 0x53, 0xf000 }, 9440bc18a2SBard Liao { 0x61, 0x0000 }, 9540bc18a2SBard Liao { 0x62, 0x0000 }, 9640bc18a2SBard Liao { 0x63, 0x00c0 }, 9740bc18a2SBard Liao { 0x64, 0x0000 }, 9840bc18a2SBard Liao { 0x65, 0x0000 }, 9940bc18a2SBard Liao { 0x66, 0x0000 }, 10040bc18a2SBard Liao { 0x70, 0x8000 }, 10140bc18a2SBard Liao { 0x71, 0x8000 }, 10240bc18a2SBard Liao { 0x73, 0x1104 }, 10340bc18a2SBard Liao { 0x74, 0x0c00 }, 10440bc18a2SBard Liao { 0x75, 0x1400 }, 10540bc18a2SBard Liao { 0x77, 0x0c00 }, 10640bc18a2SBard Liao { 0x78, 0x4000 }, 10740bc18a2SBard Liao { 0x79, 0x0123 }, 10840bc18a2SBard Liao { 0x80, 0x0000 }, 10940bc18a2SBard Liao { 0x81, 0x0000 }, 11040bc18a2SBard Liao { 0x82, 0x0000 }, 11140bc18a2SBard Liao { 0x83, 0x0800 }, 11240bc18a2SBard Liao { 0x84, 0x0000 }, 11340bc18a2SBard Liao { 0x85, 0x0008 }, 11440bc18a2SBard Liao { 0x89, 0x0000 }, 11540bc18a2SBard Liao { 0x8e, 0x0004 }, 11640bc18a2SBard Liao { 0x8f, 0x1100 }, 11740bc18a2SBard Liao { 0x90, 0x0000 }, 11840bc18a2SBard Liao { 0x93, 0x2000 }, 11940bc18a2SBard Liao { 0x94, 0x0200 }, 12040bc18a2SBard Liao { 0xb0, 0x2080 }, 12140bc18a2SBard Liao { 0xb1, 0x0000 }, 12240bc18a2SBard Liao { 0xb4, 0x2206 }, 12340bc18a2SBard Liao { 0xb5, 0x1f00 }, 12440bc18a2SBard Liao { 0xb6, 0x0000 }, 12540bc18a2SBard Liao { 0xbb, 0x0000 }, 12640bc18a2SBard Liao { 0xbc, 0x0000 }, 12740bc18a2SBard Liao { 0xbd, 0x0000 }, 12840bc18a2SBard Liao { 0xbe, 0x0000 }, 12940bc18a2SBard Liao { 0xbf, 0x0000 }, 13040bc18a2SBard Liao { 0xc0, 0x0400 }, 13140bc18a2SBard Liao { 0xc1, 0x0000 }, 13240bc18a2SBard Liao { 0xc2, 0x0000 }, 13340bc18a2SBard Liao { 0xcf, 0x0013 }, 13440bc18a2SBard Liao { 0xd0, 0x0680 }, 13540bc18a2SBard Liao { 0xd1, 0x1c17 }, 13640bc18a2SBard Liao { 0xd3, 0xb320 }, 13740bc18a2SBard Liao { 0xd9, 0x0809 }, 13840bc18a2SBard Liao { 0xfa, 0x0010 }, 13940bc18a2SBard Liao { 0xfe, 0x10ec }, 14040bc18a2SBard Liao { 0xff, 0x6281 }, 14140bc18a2SBard Liao }; 14240bc18a2SBard Liao 14340bc18a2SBard Liao static bool rt5651_volatile_register(struct device *dev, unsigned int reg) 14440bc18a2SBard Liao { 14540bc18a2SBard Liao int i; 14640bc18a2SBard Liao 14740bc18a2SBard Liao for (i = 0; i < ARRAY_SIZE(rt5651_ranges); i++) { 14840bc18a2SBard Liao if ((reg >= rt5651_ranges[i].window_start && 14940bc18a2SBard Liao reg <= rt5651_ranges[i].window_start + 15040bc18a2SBard Liao rt5651_ranges[i].window_len) || 15140bc18a2SBard Liao (reg >= rt5651_ranges[i].range_min && 15240bc18a2SBard Liao reg <= rt5651_ranges[i].range_max)) { 15340bc18a2SBard Liao return true; 15440bc18a2SBard Liao } 15540bc18a2SBard Liao } 15640bc18a2SBard Liao 15740bc18a2SBard Liao switch (reg) { 15840bc18a2SBard Liao case RT5651_RESET: 15940bc18a2SBard Liao case RT5651_PRIV_DATA: 16040bc18a2SBard Liao case RT5651_EQ_CTRL1: 16140bc18a2SBard Liao case RT5651_ALC_1: 16240bc18a2SBard Liao case RT5651_IRQ_CTRL2: 16340bc18a2SBard Liao case RT5651_INT_IRQ_ST: 16440bc18a2SBard Liao case RT5651_PGM_REG_ARR1: 16540bc18a2SBard Liao case RT5651_PGM_REG_ARR3: 16640bc18a2SBard Liao case RT5651_VENDOR_ID: 16740bc18a2SBard Liao case RT5651_DEVICE_ID: 16840bc18a2SBard Liao return true; 16940bc18a2SBard Liao default: 17040bc18a2SBard Liao return false; 17140bc18a2SBard Liao } 17240bc18a2SBard Liao } 17340bc18a2SBard Liao 17440bc18a2SBard Liao static bool rt5651_readable_register(struct device *dev, unsigned int reg) 17540bc18a2SBard Liao { 17640bc18a2SBard Liao int i; 17740bc18a2SBard Liao 17840bc18a2SBard Liao for (i = 0; i < ARRAY_SIZE(rt5651_ranges); i++) { 17940bc18a2SBard Liao if ((reg >= rt5651_ranges[i].window_start && 18040bc18a2SBard Liao reg <= rt5651_ranges[i].window_start + 18140bc18a2SBard Liao rt5651_ranges[i].window_len) || 18240bc18a2SBard Liao (reg >= rt5651_ranges[i].range_min && 18340bc18a2SBard Liao reg <= rt5651_ranges[i].range_max)) { 18440bc18a2SBard Liao return true; 18540bc18a2SBard Liao } 18640bc18a2SBard Liao } 18740bc18a2SBard Liao 18840bc18a2SBard Liao switch (reg) { 18940bc18a2SBard Liao case RT5651_RESET: 19040bc18a2SBard Liao case RT5651_VERSION_ID: 19140bc18a2SBard Liao case RT5651_VENDOR_ID: 19240bc18a2SBard Liao case RT5651_DEVICE_ID: 19340bc18a2SBard Liao case RT5651_HP_VOL: 19440bc18a2SBard Liao case RT5651_LOUT_CTRL1: 19540bc18a2SBard Liao case RT5651_LOUT_CTRL2: 19640bc18a2SBard Liao case RT5651_IN1_IN2: 19740bc18a2SBard Liao case RT5651_IN3: 19840bc18a2SBard Liao case RT5651_INL1_INR1_VOL: 19940bc18a2SBard Liao case RT5651_INL2_INR2_VOL: 20040bc18a2SBard Liao case RT5651_DAC1_DIG_VOL: 20140bc18a2SBard Liao case RT5651_DAC2_DIG_VOL: 20240bc18a2SBard Liao case RT5651_DAC2_CTRL: 20340bc18a2SBard Liao case RT5651_ADC_DIG_VOL: 20440bc18a2SBard Liao case RT5651_ADC_DATA: 20540bc18a2SBard Liao case RT5651_ADC_BST_VOL: 20640bc18a2SBard Liao case RT5651_STO1_ADC_MIXER: 20740bc18a2SBard Liao case RT5651_STO2_ADC_MIXER: 20840bc18a2SBard Liao case RT5651_AD_DA_MIXER: 20940bc18a2SBard Liao case RT5651_STO_DAC_MIXER: 21040bc18a2SBard Liao case RT5651_DD_MIXER: 21140bc18a2SBard Liao case RT5651_DIG_INF_DATA: 21240bc18a2SBard Liao case RT5651_PDM_CTL: 21340bc18a2SBard Liao case RT5651_REC_L1_MIXER: 21440bc18a2SBard Liao case RT5651_REC_L2_MIXER: 21540bc18a2SBard Liao case RT5651_REC_R1_MIXER: 21640bc18a2SBard Liao case RT5651_REC_R2_MIXER: 21740bc18a2SBard Liao case RT5651_HPO_MIXER: 21840bc18a2SBard Liao case RT5651_OUT_L1_MIXER: 21940bc18a2SBard Liao case RT5651_OUT_L2_MIXER: 22040bc18a2SBard Liao case RT5651_OUT_L3_MIXER: 22140bc18a2SBard Liao case RT5651_OUT_R1_MIXER: 22240bc18a2SBard Liao case RT5651_OUT_R2_MIXER: 22340bc18a2SBard Liao case RT5651_OUT_R3_MIXER: 22440bc18a2SBard Liao case RT5651_LOUT_MIXER: 22540bc18a2SBard Liao case RT5651_PWR_DIG1: 22640bc18a2SBard Liao case RT5651_PWR_DIG2: 22740bc18a2SBard Liao case RT5651_PWR_ANLG1: 22840bc18a2SBard Liao case RT5651_PWR_ANLG2: 22940bc18a2SBard Liao case RT5651_PWR_MIXER: 23040bc18a2SBard Liao case RT5651_PWR_VOL: 23140bc18a2SBard Liao case RT5651_PRIV_INDEX: 23240bc18a2SBard Liao case RT5651_PRIV_DATA: 23340bc18a2SBard Liao case RT5651_I2S1_SDP: 23440bc18a2SBard Liao case RT5651_I2S2_SDP: 23540bc18a2SBard Liao case RT5651_ADDA_CLK1: 23640bc18a2SBard Liao case RT5651_ADDA_CLK2: 23740bc18a2SBard Liao case RT5651_DMIC: 23840bc18a2SBard Liao case RT5651_TDM_CTL_1: 23940bc18a2SBard Liao case RT5651_TDM_CTL_2: 24040bc18a2SBard Liao case RT5651_TDM_CTL_3: 24140bc18a2SBard Liao case RT5651_GLB_CLK: 24240bc18a2SBard Liao case RT5651_PLL_CTRL1: 24340bc18a2SBard Liao case RT5651_PLL_CTRL2: 24440bc18a2SBard Liao case RT5651_PLL_MODE_1: 24540bc18a2SBard Liao case RT5651_PLL_MODE_2: 24640bc18a2SBard Liao case RT5651_PLL_MODE_3: 24740bc18a2SBard Liao case RT5651_PLL_MODE_4: 24840bc18a2SBard Liao case RT5651_PLL_MODE_5: 24940bc18a2SBard Liao case RT5651_PLL_MODE_6: 25040bc18a2SBard Liao case RT5651_PLL_MODE_7: 25140bc18a2SBard Liao case RT5651_DEPOP_M1: 25240bc18a2SBard Liao case RT5651_DEPOP_M2: 25340bc18a2SBard Liao case RT5651_DEPOP_M3: 25440bc18a2SBard Liao case RT5651_CHARGE_PUMP: 25540bc18a2SBard Liao case RT5651_MICBIAS: 25640bc18a2SBard Liao case RT5651_A_JD_CTL1: 25740bc18a2SBard Liao case RT5651_EQ_CTRL1: 25840bc18a2SBard Liao case RT5651_EQ_CTRL2: 25940bc18a2SBard Liao case RT5651_ALC_1: 26040bc18a2SBard Liao case RT5651_ALC_2: 26140bc18a2SBard Liao case RT5651_ALC_3: 26240bc18a2SBard Liao case RT5651_JD_CTRL1: 26340bc18a2SBard Liao case RT5651_JD_CTRL2: 26440bc18a2SBard Liao case RT5651_IRQ_CTRL1: 26540bc18a2SBard Liao case RT5651_IRQ_CTRL2: 26640bc18a2SBard Liao case RT5651_INT_IRQ_ST: 26740bc18a2SBard Liao case RT5651_GPIO_CTRL1: 26840bc18a2SBard Liao case RT5651_GPIO_CTRL2: 26940bc18a2SBard Liao case RT5651_GPIO_CTRL3: 27040bc18a2SBard Liao case RT5651_PGM_REG_ARR1: 27140bc18a2SBard Liao case RT5651_PGM_REG_ARR2: 27240bc18a2SBard Liao case RT5651_PGM_REG_ARR3: 27340bc18a2SBard Liao case RT5651_PGM_REG_ARR4: 27440bc18a2SBard Liao case RT5651_PGM_REG_ARR5: 27540bc18a2SBard Liao case RT5651_SCB_FUNC: 27640bc18a2SBard Liao case RT5651_SCB_CTRL: 27740bc18a2SBard Liao case RT5651_BASE_BACK: 27840bc18a2SBard Liao case RT5651_MP3_PLUS1: 27940bc18a2SBard Liao case RT5651_MP3_PLUS2: 28040bc18a2SBard Liao case RT5651_ADJ_HPF_CTRL1: 28140bc18a2SBard Liao case RT5651_ADJ_HPF_CTRL2: 28240bc18a2SBard Liao case RT5651_HP_CALIB_AMP_DET: 28340bc18a2SBard Liao case RT5651_HP_CALIB2: 28440bc18a2SBard Liao case RT5651_SV_ZCD1: 28540bc18a2SBard Liao case RT5651_SV_ZCD2: 28640bc18a2SBard Liao case RT5651_D_MISC: 28740bc18a2SBard Liao case RT5651_DUMMY2: 28840bc18a2SBard Liao case RT5651_DUMMY3: 28940bc18a2SBard Liao return true; 29040bc18a2SBard Liao default: 29140bc18a2SBard Liao return false; 29240bc18a2SBard Liao } 29340bc18a2SBard Liao } 29440bc18a2SBard Liao 29540bc18a2SBard Liao static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -4650, 150, 0); 29640bc18a2SBard Liao static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -65625, 375, 0); 29740bc18a2SBard Liao static const DECLARE_TLV_DB_SCALE(in_vol_tlv, -3450, 150, 0); 29840bc18a2SBard Liao static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -17625, 375, 0); 29940bc18a2SBard Liao static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0); 30040bc18a2SBard Liao 30140bc18a2SBard Liao /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */ 3028e3648e1SLars-Peter Clausen static const DECLARE_TLV_DB_RANGE(bst_tlv, 30340bc18a2SBard Liao 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0), 30440bc18a2SBard Liao 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0), 30540bc18a2SBard Liao 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0), 30640bc18a2SBard Liao 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0), 30740bc18a2SBard Liao 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0), 30840bc18a2SBard Liao 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0), 3098e3648e1SLars-Peter Clausen 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0) 3108e3648e1SLars-Peter Clausen ); 31140bc18a2SBard Liao 31240bc18a2SBard Liao /* Interface data select */ 31340bc18a2SBard Liao static const char * const rt5651_data_select[] = { 31440bc18a2SBard Liao "Normal", "Swap", "left copy to right", "right copy to left"}; 31540bc18a2SBard Liao 31640bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL(rt5651_if2_dac_enum, RT5651_DIG_INF_DATA, 31740bc18a2SBard Liao RT5651_IF2_DAC_SEL_SFT, rt5651_data_select); 31840bc18a2SBard Liao 31940bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL(rt5651_if2_adc_enum, RT5651_DIG_INF_DATA, 32040bc18a2SBard Liao RT5651_IF2_ADC_SEL_SFT, rt5651_data_select); 32140bc18a2SBard Liao 32240bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_snd_controls[] = { 32340bc18a2SBard Liao /* Headphone Output Volume */ 32440bc18a2SBard Liao SOC_DOUBLE_TLV("HP Playback Volume", RT5651_HP_VOL, 32540bc18a2SBard Liao RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 39, 1, out_vol_tlv), 32640bc18a2SBard Liao /* OUTPUT Control */ 32740bc18a2SBard Liao SOC_DOUBLE_TLV("OUT Playback Volume", RT5651_LOUT_CTRL1, 32840bc18a2SBard Liao RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 39, 1, out_vol_tlv), 32940bc18a2SBard Liao 33040bc18a2SBard Liao /* DAC Digital Volume */ 33140bc18a2SBard Liao SOC_DOUBLE("DAC2 Playback Switch", RT5651_DAC2_CTRL, 33240bc18a2SBard Liao RT5651_M_DAC_L2_VOL_SFT, RT5651_M_DAC_R2_VOL_SFT, 1, 1), 33340bc18a2SBard Liao SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5651_DAC1_DIG_VOL, 33440bc18a2SBard Liao RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 33540bc18a2SBard Liao 175, 0, dac_vol_tlv), 33640bc18a2SBard Liao SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5651_DAC2_DIG_VOL, 33740bc18a2SBard Liao RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 33840bc18a2SBard Liao 175, 0, dac_vol_tlv), 33940bc18a2SBard Liao /* IN1/IN2 Control */ 34040bc18a2SBard Liao SOC_SINGLE_TLV("IN1 Boost", RT5651_IN1_IN2, 34140bc18a2SBard Liao RT5651_BST_SFT1, 8, 0, bst_tlv), 34240bc18a2SBard Liao SOC_SINGLE_TLV("IN2 Boost", RT5651_IN1_IN2, 34340bc18a2SBard Liao RT5651_BST_SFT2, 8, 0, bst_tlv), 34440bc18a2SBard Liao /* INL/INR Volume Control */ 34540bc18a2SBard Liao SOC_DOUBLE_TLV("IN Capture Volume", RT5651_INL1_INR1_VOL, 34640bc18a2SBard Liao RT5651_INL_VOL_SFT, RT5651_INR_VOL_SFT, 34740bc18a2SBard Liao 31, 1, in_vol_tlv), 34840bc18a2SBard Liao /* ADC Digital Volume Control */ 34940bc18a2SBard Liao SOC_DOUBLE("ADC Capture Switch", RT5651_ADC_DIG_VOL, 35040bc18a2SBard Liao RT5651_L_MUTE_SFT, RT5651_R_MUTE_SFT, 1, 1), 35140bc18a2SBard Liao SOC_DOUBLE_TLV("ADC Capture Volume", RT5651_ADC_DIG_VOL, 35240bc18a2SBard Liao RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 35340bc18a2SBard Liao 127, 0, adc_vol_tlv), 35440bc18a2SBard Liao SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5651_ADC_DATA, 35540bc18a2SBard Liao RT5651_L_VOL_SFT, RT5651_R_VOL_SFT, 35640bc18a2SBard Liao 127, 0, adc_vol_tlv), 35740bc18a2SBard Liao /* ADC Boost Volume Control */ 35840bc18a2SBard Liao SOC_DOUBLE_TLV("ADC Boost Gain", RT5651_ADC_BST_VOL, 35940bc18a2SBard Liao RT5651_ADC_L_BST_SFT, RT5651_ADC_R_BST_SFT, 36040bc18a2SBard Liao 3, 0, adc_bst_tlv), 36140bc18a2SBard Liao 36240bc18a2SBard Liao /* ASRC */ 36340bc18a2SBard Liao SOC_SINGLE("IF1 ASRC Switch", RT5651_PLL_MODE_1, 36440bc18a2SBard Liao RT5651_STO1_T_SFT, 1, 0), 36540bc18a2SBard Liao SOC_SINGLE("IF2 ASRC Switch", RT5651_PLL_MODE_1, 36640bc18a2SBard Liao RT5651_STO2_T_SFT, 1, 0), 36740bc18a2SBard Liao SOC_SINGLE("DMIC ASRC Switch", RT5651_PLL_MODE_1, 36840bc18a2SBard Liao RT5651_DMIC_1_M_SFT, 1, 0), 36940bc18a2SBard Liao 37040bc18a2SBard Liao SOC_ENUM("ADC IF2 Data Switch", rt5651_if2_adc_enum), 37140bc18a2SBard Liao SOC_ENUM("DAC IF2 Data Switch", rt5651_if2_dac_enum), 37240bc18a2SBard Liao }; 37340bc18a2SBard Liao 37440bc18a2SBard Liao /** 37540bc18a2SBard Liao * set_dmic_clk - Set parameter of dmic. 37640bc18a2SBard Liao * 37740bc18a2SBard Liao * @w: DAPM widget. 37840bc18a2SBard Liao * @kcontrol: The kcontrol of this widget. 37940bc18a2SBard Liao * @event: Event id. 38040bc18a2SBard Liao * 38140bc18a2SBard Liao */ 38240bc18a2SBard Liao static int set_dmic_clk(struct snd_soc_dapm_widget *w, 38340bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 38440bc18a2SBard Liao { 38517b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 38617b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 38700a6d6e5SOder Chiou int idx, rate; 38840bc18a2SBard Liao 38900a6d6e5SOder Chiou rate = rt5651->sysclk / rl6231_get_pre_div(rt5651->regmap, 39000a6d6e5SOder Chiou RT5651_ADDA_CLK1, RT5651_I2S_PD1_SFT); 39100a6d6e5SOder Chiou idx = rl6231_calc_dmic_clk(rate); 39240bc18a2SBard Liao if (idx < 0) 39317b52010SKuninori Morimoto dev_err(component->dev, "Failed to set DMIC clock\n"); 39440bc18a2SBard Liao else 39517b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_DMIC, RT5651_DMIC_CLK_MASK, 39640bc18a2SBard Liao idx << RT5651_DMIC_CLK_SFT); 39740bc18a2SBard Liao 39840bc18a2SBard Liao return idx; 39940bc18a2SBard Liao } 40040bc18a2SBard Liao 40140bc18a2SBard Liao /* Digital Mixer */ 40240bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto1_adc_l_mix[] = { 40340bc18a2SBard Liao SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO1_ADC_MIXER, 40440bc18a2SBard Liao RT5651_M_STO1_ADC_L1_SFT, 1, 1), 40540bc18a2SBard Liao SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO1_ADC_MIXER, 40640bc18a2SBard Liao RT5651_M_STO1_ADC_L2_SFT, 1, 1), 40740bc18a2SBard Liao }; 40840bc18a2SBard Liao 40940bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto1_adc_r_mix[] = { 41040bc18a2SBard Liao SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO1_ADC_MIXER, 41140bc18a2SBard Liao RT5651_M_STO1_ADC_R1_SFT, 1, 1), 41240bc18a2SBard Liao SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO1_ADC_MIXER, 41340bc18a2SBard Liao RT5651_M_STO1_ADC_R2_SFT, 1, 1), 41440bc18a2SBard Liao }; 41540bc18a2SBard Liao 41640bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto2_adc_l_mix[] = { 41740bc18a2SBard Liao SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO2_ADC_MIXER, 41840bc18a2SBard Liao RT5651_M_STO2_ADC_L1_SFT, 1, 1), 41940bc18a2SBard Liao SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO2_ADC_MIXER, 42040bc18a2SBard Liao RT5651_M_STO2_ADC_L2_SFT, 1, 1), 42140bc18a2SBard Liao }; 42240bc18a2SBard Liao 42340bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto2_adc_r_mix[] = { 42440bc18a2SBard Liao SOC_DAPM_SINGLE("ADC1 Switch", RT5651_STO2_ADC_MIXER, 42540bc18a2SBard Liao RT5651_M_STO2_ADC_R1_SFT, 1, 1), 42640bc18a2SBard Liao SOC_DAPM_SINGLE("ADC2 Switch", RT5651_STO2_ADC_MIXER, 42740bc18a2SBard Liao RT5651_M_STO2_ADC_R2_SFT, 1, 1), 42840bc18a2SBard Liao }; 42940bc18a2SBard Liao 43040bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_dac_l_mix[] = { 43140bc18a2SBard Liao SOC_DAPM_SINGLE("Stereo ADC Switch", RT5651_AD_DA_MIXER, 43240bc18a2SBard Liao RT5651_M_ADCMIX_L_SFT, 1, 1), 43340bc18a2SBard Liao SOC_DAPM_SINGLE("INF1 Switch", RT5651_AD_DA_MIXER, 43440bc18a2SBard Liao RT5651_M_IF1_DAC_L_SFT, 1, 1), 43540bc18a2SBard Liao }; 43640bc18a2SBard Liao 43740bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_dac_r_mix[] = { 43840bc18a2SBard Liao SOC_DAPM_SINGLE("Stereo ADC Switch", RT5651_AD_DA_MIXER, 43940bc18a2SBard Liao RT5651_M_ADCMIX_R_SFT, 1, 1), 44040bc18a2SBard Liao SOC_DAPM_SINGLE("INF1 Switch", RT5651_AD_DA_MIXER, 44140bc18a2SBard Liao RT5651_M_IF1_DAC_R_SFT, 1, 1), 44240bc18a2SBard Liao }; 44340bc18a2SBard Liao 44440bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto_dac_l_mix[] = { 44540bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_STO_DAC_MIXER, 44640bc18a2SBard Liao RT5651_M_DAC_L1_MIXL_SFT, 1, 1), 44740bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L2 Switch", RT5651_STO_DAC_MIXER, 44840bc18a2SBard Liao RT5651_M_DAC_L2_MIXL_SFT, 1, 1), 44940bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_STO_DAC_MIXER, 45040bc18a2SBard Liao RT5651_M_DAC_R1_MIXL_SFT, 1, 1), 45140bc18a2SBard Liao }; 45240bc18a2SBard Liao 45340bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto_dac_r_mix[] = { 45440bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_STO_DAC_MIXER, 45540bc18a2SBard Liao RT5651_M_DAC_R1_MIXR_SFT, 1, 1), 45640bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R2 Switch", RT5651_STO_DAC_MIXER, 45740bc18a2SBard Liao RT5651_M_DAC_R2_MIXR_SFT, 1, 1), 45840bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_STO_DAC_MIXER, 45940bc18a2SBard Liao RT5651_M_DAC_L1_MIXR_SFT, 1, 1), 46040bc18a2SBard Liao }; 46140bc18a2SBard Liao 46240bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_dd_dac_l_mix[] = { 46340bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_DD_MIXER, 46440bc18a2SBard Liao RT5651_M_STO_DD_L1_SFT, 1, 1), 46540bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L2 Switch", RT5651_DD_MIXER, 46640bc18a2SBard Liao RT5651_M_STO_DD_L2_SFT, 1, 1), 46740bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R2 Switch", RT5651_DD_MIXER, 46840bc18a2SBard Liao RT5651_M_STO_DD_R2_L_SFT, 1, 1), 46940bc18a2SBard Liao }; 47040bc18a2SBard Liao 47140bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_dd_dac_r_mix[] = { 47240bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_DD_MIXER, 47340bc18a2SBard Liao RT5651_M_STO_DD_R1_SFT, 1, 1), 47440bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R2 Switch", RT5651_DD_MIXER, 47540bc18a2SBard Liao RT5651_M_STO_DD_R2_SFT, 1, 1), 47640bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L2 Switch", RT5651_DD_MIXER, 47740bc18a2SBard Liao RT5651_M_STO_DD_L2_R_SFT, 1, 1), 47840bc18a2SBard Liao }; 47940bc18a2SBard Liao 48040bc18a2SBard Liao /* Analog Input Mixer */ 48140bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_rec_l_mix[] = { 48240bc18a2SBard Liao SOC_DAPM_SINGLE("INL1 Switch", RT5651_REC_L2_MIXER, 48340bc18a2SBard Liao RT5651_M_IN1_L_RM_L_SFT, 1, 1), 48440bc18a2SBard Liao SOC_DAPM_SINGLE("BST3 Switch", RT5651_REC_L2_MIXER, 48540bc18a2SBard Liao RT5651_M_BST3_RM_L_SFT, 1, 1), 48640bc18a2SBard Liao SOC_DAPM_SINGLE("BST2 Switch", RT5651_REC_L2_MIXER, 48740bc18a2SBard Liao RT5651_M_BST2_RM_L_SFT, 1, 1), 48840bc18a2SBard Liao SOC_DAPM_SINGLE("BST1 Switch", RT5651_REC_L2_MIXER, 48940bc18a2SBard Liao RT5651_M_BST1_RM_L_SFT, 1, 1), 49040bc18a2SBard Liao }; 49140bc18a2SBard Liao 49240bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_rec_r_mix[] = { 49340bc18a2SBard Liao SOC_DAPM_SINGLE("INR1 Switch", RT5651_REC_R2_MIXER, 49440bc18a2SBard Liao RT5651_M_IN1_R_RM_R_SFT, 1, 1), 49540bc18a2SBard Liao SOC_DAPM_SINGLE("BST3 Switch", RT5651_REC_R2_MIXER, 49640bc18a2SBard Liao RT5651_M_BST3_RM_R_SFT, 1, 1), 49740bc18a2SBard Liao SOC_DAPM_SINGLE("BST2 Switch", RT5651_REC_R2_MIXER, 49840bc18a2SBard Liao RT5651_M_BST2_RM_R_SFT, 1, 1), 49940bc18a2SBard Liao SOC_DAPM_SINGLE("BST1 Switch", RT5651_REC_R2_MIXER, 50040bc18a2SBard Liao RT5651_M_BST1_RM_R_SFT, 1, 1), 50140bc18a2SBard Liao }; 50240bc18a2SBard Liao 50340bc18a2SBard Liao /* Analog Output Mixer */ 50440bc18a2SBard Liao 50540bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_out_l_mix[] = { 50640bc18a2SBard Liao SOC_DAPM_SINGLE("BST1 Switch", RT5651_OUT_L3_MIXER, 50740bc18a2SBard Liao RT5651_M_BST1_OM_L_SFT, 1, 1), 50840bc18a2SBard Liao SOC_DAPM_SINGLE("BST2 Switch", RT5651_OUT_L3_MIXER, 50940bc18a2SBard Liao RT5651_M_BST2_OM_L_SFT, 1, 1), 51040bc18a2SBard Liao SOC_DAPM_SINGLE("INL1 Switch", RT5651_OUT_L3_MIXER, 51140bc18a2SBard Liao RT5651_M_IN1_L_OM_L_SFT, 1, 1), 51240bc18a2SBard Liao SOC_DAPM_SINGLE("REC MIXL Switch", RT5651_OUT_L3_MIXER, 51340bc18a2SBard Liao RT5651_M_RM_L_OM_L_SFT, 1, 1), 51440bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_OUT_L3_MIXER, 51540bc18a2SBard Liao RT5651_M_DAC_L1_OM_L_SFT, 1, 1), 51640bc18a2SBard Liao }; 51740bc18a2SBard Liao 51840bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_out_r_mix[] = { 51940bc18a2SBard Liao SOC_DAPM_SINGLE("BST2 Switch", RT5651_OUT_R3_MIXER, 52040bc18a2SBard Liao RT5651_M_BST2_OM_R_SFT, 1, 1), 52140bc18a2SBard Liao SOC_DAPM_SINGLE("BST1 Switch", RT5651_OUT_R3_MIXER, 52240bc18a2SBard Liao RT5651_M_BST1_OM_R_SFT, 1, 1), 52340bc18a2SBard Liao SOC_DAPM_SINGLE("INR1 Switch", RT5651_OUT_R3_MIXER, 52440bc18a2SBard Liao RT5651_M_IN1_R_OM_R_SFT, 1, 1), 52540bc18a2SBard Liao SOC_DAPM_SINGLE("REC MIXR Switch", RT5651_OUT_R3_MIXER, 52640bc18a2SBard Liao RT5651_M_RM_R_OM_R_SFT, 1, 1), 52740bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_OUT_R3_MIXER, 52840bc18a2SBard Liao RT5651_M_DAC_R1_OM_R_SFT, 1, 1), 52940bc18a2SBard Liao }; 53040bc18a2SBard Liao 53140bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_hpo_mix[] = { 53240bc18a2SBard Liao SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5651_HPO_MIXER, 53340bc18a2SBard Liao RT5651_M_DAC1_HM_SFT, 1, 1), 53440bc18a2SBard Liao SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5651_HPO_MIXER, 53540bc18a2SBard Liao RT5651_M_HPVOL_HM_SFT, 1, 1), 53640bc18a2SBard Liao }; 53740bc18a2SBard Liao 53840bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_lout_mix[] = { 53940bc18a2SBard Liao SOC_DAPM_SINGLE("DAC L1 Switch", RT5651_LOUT_MIXER, 54040bc18a2SBard Liao RT5651_M_DAC_L1_LM_SFT, 1, 1), 54140bc18a2SBard Liao SOC_DAPM_SINGLE("DAC R1 Switch", RT5651_LOUT_MIXER, 54240bc18a2SBard Liao RT5651_M_DAC_R1_LM_SFT, 1, 1), 54340bc18a2SBard Liao SOC_DAPM_SINGLE("OUTVOL L Switch", RT5651_LOUT_MIXER, 54440bc18a2SBard Liao RT5651_M_OV_L_LM_SFT, 1, 1), 54540bc18a2SBard Liao SOC_DAPM_SINGLE("OUTVOL R Switch", RT5651_LOUT_MIXER, 54640bc18a2SBard Liao RT5651_M_OV_R_LM_SFT, 1, 1), 54740bc18a2SBard Liao }; 54840bc18a2SBard Liao 54940bc18a2SBard Liao static const struct snd_kcontrol_new outvol_l_control = 55040bc18a2SBard Liao SOC_DAPM_SINGLE("Switch", RT5651_LOUT_CTRL1, 55140bc18a2SBard Liao RT5651_VOL_L_SFT, 1, 1); 55240bc18a2SBard Liao 55340bc18a2SBard Liao static const struct snd_kcontrol_new outvol_r_control = 55440bc18a2SBard Liao SOC_DAPM_SINGLE("Switch", RT5651_LOUT_CTRL1, 55540bc18a2SBard Liao RT5651_VOL_R_SFT, 1, 1); 55640bc18a2SBard Liao 55740bc18a2SBard Liao static const struct snd_kcontrol_new lout_l_mute_control = 55840bc18a2SBard Liao SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_LOUT_CTRL1, 55940bc18a2SBard Liao RT5651_L_MUTE_SFT, 1, 1); 56040bc18a2SBard Liao 56140bc18a2SBard Liao static const struct snd_kcontrol_new lout_r_mute_control = 56240bc18a2SBard Liao SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_LOUT_CTRL1, 56340bc18a2SBard Liao RT5651_R_MUTE_SFT, 1, 1); 56440bc18a2SBard Liao 56540bc18a2SBard Liao static const struct snd_kcontrol_new hpovol_l_control = 56640bc18a2SBard Liao SOC_DAPM_SINGLE("Switch", RT5651_HP_VOL, 56740bc18a2SBard Liao RT5651_VOL_L_SFT, 1, 1); 56840bc18a2SBard Liao 56940bc18a2SBard Liao static const struct snd_kcontrol_new hpovol_r_control = 57040bc18a2SBard Liao SOC_DAPM_SINGLE("Switch", RT5651_HP_VOL, 57140bc18a2SBard Liao RT5651_VOL_R_SFT, 1, 1); 57240bc18a2SBard Liao 57340bc18a2SBard Liao static const struct snd_kcontrol_new hpo_l_mute_control = 57440bc18a2SBard Liao SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_HP_VOL, 57540bc18a2SBard Liao RT5651_L_MUTE_SFT, 1, 1); 57640bc18a2SBard Liao 57740bc18a2SBard Liao static const struct snd_kcontrol_new hpo_r_mute_control = 57840bc18a2SBard Liao SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5651_HP_VOL, 57940bc18a2SBard Liao RT5651_R_MUTE_SFT, 1, 1); 58040bc18a2SBard Liao 58140bc18a2SBard Liao /* Stereo ADC source */ 58240bc18a2SBard Liao static const char * const rt5651_stereo1_adc1_src[] = {"DD MIX", "ADC"}; 58340bc18a2SBard Liao 58440bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 58540bc18a2SBard Liao rt5651_stereo1_adc1_enum, RT5651_STO1_ADC_MIXER, 58640bc18a2SBard Liao RT5651_STO1_ADC_1_SRC_SFT, rt5651_stereo1_adc1_src); 58740bc18a2SBard Liao 58840bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto1_adc_l1_mux = 58940bc18a2SBard Liao SOC_DAPM_ENUM("Stereo1 ADC L1 source", rt5651_stereo1_adc1_enum); 59040bc18a2SBard Liao 59140bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto1_adc_r1_mux = 59240bc18a2SBard Liao SOC_DAPM_ENUM("Stereo1 ADC R1 source", rt5651_stereo1_adc1_enum); 59340bc18a2SBard Liao 59440bc18a2SBard Liao static const char * const rt5651_stereo1_adc2_src[] = {"DMIC", "DD MIX"}; 59540bc18a2SBard Liao 59640bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 59740bc18a2SBard Liao rt5651_stereo1_adc2_enum, RT5651_STO1_ADC_MIXER, 59840bc18a2SBard Liao RT5651_STO1_ADC_2_SRC_SFT, rt5651_stereo1_adc2_src); 59940bc18a2SBard Liao 60040bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto1_adc_l2_mux = 60140bc18a2SBard Liao SOC_DAPM_ENUM("Stereo1 ADC L2 source", rt5651_stereo1_adc2_enum); 60240bc18a2SBard Liao 60340bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto1_adc_r2_mux = 60440bc18a2SBard Liao SOC_DAPM_ENUM("Stereo1 ADC R2 source", rt5651_stereo1_adc2_enum); 60540bc18a2SBard Liao 60640bc18a2SBard Liao /* Mono ADC source */ 60740bc18a2SBard Liao static const char * const rt5651_sto2_adc_l1_src[] = {"DD MIXL", "ADCL"}; 60840bc18a2SBard Liao 60940bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 61040bc18a2SBard Liao rt5651_sto2_adc_l1_enum, RT5651_STO1_ADC_MIXER, 61140bc18a2SBard Liao RT5651_STO2_ADC_L1_SRC_SFT, rt5651_sto2_adc_l1_src); 61240bc18a2SBard Liao 61340bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto2_adc_l1_mux = 61440bc18a2SBard Liao SOC_DAPM_ENUM("Stereo2 ADC1 left source", rt5651_sto2_adc_l1_enum); 61540bc18a2SBard Liao 61640bc18a2SBard Liao static const char * const rt5651_sto2_adc_l2_src[] = {"DMIC L", "DD MIXL"}; 61740bc18a2SBard Liao 61840bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 61940bc18a2SBard Liao rt5651_sto2_adc_l2_enum, RT5651_STO1_ADC_MIXER, 62040bc18a2SBard Liao RT5651_STO2_ADC_L2_SRC_SFT, rt5651_sto2_adc_l2_src); 62140bc18a2SBard Liao 62240bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto2_adc_l2_mux = 62340bc18a2SBard Liao SOC_DAPM_ENUM("Stereo2 ADC2 left source", rt5651_sto2_adc_l2_enum); 62440bc18a2SBard Liao 62540bc18a2SBard Liao static const char * const rt5651_sto2_adc_r1_src[] = {"DD MIXR", "ADCR"}; 62640bc18a2SBard Liao 62740bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 62840bc18a2SBard Liao rt5651_sto2_adc_r1_enum, RT5651_STO1_ADC_MIXER, 62940bc18a2SBard Liao RT5651_STO2_ADC_R1_SRC_SFT, rt5651_sto2_adc_r1_src); 63040bc18a2SBard Liao 63140bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto2_adc_r1_mux = 63240bc18a2SBard Liao SOC_DAPM_ENUM("Stereo2 ADC1 right source", rt5651_sto2_adc_r1_enum); 63340bc18a2SBard Liao 63440bc18a2SBard Liao static const char * const rt5651_sto2_adc_r2_src[] = {"DMIC R", "DD MIXR"}; 63540bc18a2SBard Liao 63640bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 63740bc18a2SBard Liao rt5651_sto2_adc_r2_enum, RT5651_STO1_ADC_MIXER, 63840bc18a2SBard Liao RT5651_STO2_ADC_R2_SRC_SFT, rt5651_sto2_adc_r2_src); 63940bc18a2SBard Liao 64040bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_sto2_adc_r2_mux = 64140bc18a2SBard Liao SOC_DAPM_ENUM("Stereo2 ADC2 right source", rt5651_sto2_adc_r2_enum); 64240bc18a2SBard Liao 64340bc18a2SBard Liao /* DAC2 channel source */ 64440bc18a2SBard Liao 64540bc18a2SBard Liao static const char * const rt5651_dac_src[] = {"IF1", "IF2"}; 64640bc18a2SBard Liao 64740bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL(rt5651_dac_l2_enum, RT5651_DAC2_CTRL, 64840bc18a2SBard Liao RT5651_SEL_DAC_L2_SFT, rt5651_dac_src); 64940bc18a2SBard Liao 65040bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_dac_l2_mux = 65140bc18a2SBard Liao SOC_DAPM_ENUM("DAC2 left channel source", rt5651_dac_l2_enum); 65240bc18a2SBard Liao 65340bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 65440bc18a2SBard Liao rt5651_dac_r2_enum, RT5651_DAC2_CTRL, 65540bc18a2SBard Liao RT5651_SEL_DAC_R2_SFT, rt5651_dac_src); 65640bc18a2SBard Liao 65740bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_dac_r2_mux = 65840bc18a2SBard Liao SOC_DAPM_ENUM("DAC2 right channel source", rt5651_dac_r2_enum); 65940bc18a2SBard Liao 66040bc18a2SBard Liao /* IF2_ADC channel source */ 66140bc18a2SBard Liao 66240bc18a2SBard Liao static const char * const rt5651_adc_src[] = {"IF1 ADC1", "IF1 ADC2"}; 66340bc18a2SBard Liao 66440bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL(rt5651_if2_adc_src_enum, RT5651_DIG_INF_DATA, 66540bc18a2SBard Liao RT5651_IF2_ADC_SRC_SFT, rt5651_adc_src); 66640bc18a2SBard Liao 66740bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_if2_adc_src_mux = 66840bc18a2SBard Liao SOC_DAPM_ENUM("IF2 ADC channel source", rt5651_if2_adc_src_enum); 66940bc18a2SBard Liao 67040bc18a2SBard Liao /* PDM select */ 67140bc18a2SBard Liao static const char * const rt5651_pdm_sel[] = {"DD MIX", "Stereo DAC MIX"}; 67240bc18a2SBard Liao 67340bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 67440bc18a2SBard Liao rt5651_pdm_l_sel_enum, RT5651_PDM_CTL, 67540bc18a2SBard Liao RT5651_PDM_L_SEL_SFT, rt5651_pdm_sel); 67640bc18a2SBard Liao 67740bc18a2SBard Liao static SOC_ENUM_SINGLE_DECL( 67840bc18a2SBard Liao rt5651_pdm_r_sel_enum, RT5651_PDM_CTL, 67940bc18a2SBard Liao RT5651_PDM_R_SEL_SFT, rt5651_pdm_sel); 68040bc18a2SBard Liao 68140bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_pdm_l_mux = 68240bc18a2SBard Liao SOC_DAPM_ENUM("PDM L select", rt5651_pdm_l_sel_enum); 68340bc18a2SBard Liao 68440bc18a2SBard Liao static const struct snd_kcontrol_new rt5651_pdm_r_mux = 68540bc18a2SBard Liao SOC_DAPM_ENUM("PDM R select", rt5651_pdm_r_sel_enum); 68640bc18a2SBard Liao 68740bc18a2SBard Liao static int rt5651_amp_power_event(struct snd_soc_dapm_widget *w, 68840bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 68940bc18a2SBard Liao { 69017b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 69117b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 69240bc18a2SBard Liao 69340bc18a2SBard Liao switch (event) { 69440bc18a2SBard Liao case SND_SOC_DAPM_POST_PMU: 69540bc18a2SBard Liao /* depop parameters */ 69640bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_PR_BASE + 69740bc18a2SBard Liao RT5651_CHPUMP_INT_REG1, 0x0700, 0x0200); 69840bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M2, 69940bc18a2SBard Liao RT5651_DEPOP_MASK, RT5651_DEPOP_MAN); 70040bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M1, 70140bc18a2SBard Liao RT5651_HP_CP_MASK | RT5651_HP_SG_MASK | 70240bc18a2SBard Liao RT5651_HP_CB_MASK, RT5651_HP_CP_PU | 70340bc18a2SBard Liao RT5651_HP_SG_DIS | RT5651_HP_CB_PU); 70440bc18a2SBard Liao regmap_write(rt5651->regmap, RT5651_PR_BASE + 70540bc18a2SBard Liao RT5651_HP_DCC_INT1, 0x9f00); 70640bc18a2SBard Liao /* headphone amp power on */ 70740bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG1, 70840bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2, 0); 70940bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG1, 71040bc18a2SBard Liao RT5651_PWR_HA, 71140bc18a2SBard Liao RT5651_PWR_HA); 71240bc18a2SBard Liao usleep_range(10000, 15000); 71340bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_PWR_ANLG1, 71440bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2 , 71540bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2); 71640bc18a2SBard Liao break; 71740bc18a2SBard Liao 71840bc18a2SBard Liao default: 71940bc18a2SBard Liao return 0; 72040bc18a2SBard Liao } 72140bc18a2SBard Liao 72240bc18a2SBard Liao return 0; 72340bc18a2SBard Liao } 72440bc18a2SBard Liao 72540bc18a2SBard Liao static int rt5651_hp_event(struct snd_soc_dapm_widget *w, 72640bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 72740bc18a2SBard Liao { 72817b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 72917b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 73040bc18a2SBard Liao 73140bc18a2SBard Liao switch (event) { 73240bc18a2SBard Liao case SND_SOC_DAPM_POST_PMU: 73340bc18a2SBard Liao /* headphone unmute sequence */ 73440bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M2, 73540bc18a2SBard Liao RT5651_DEPOP_MASK | RT5651_DIG_DP_MASK, 73640bc18a2SBard Liao RT5651_DEPOP_AUTO | RT5651_DIG_DP_EN); 73740bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_CHARGE_PUMP, 73840bc18a2SBard Liao RT5651_PM_HP_MASK, RT5651_PM_HP_HV); 73940bc18a2SBard Liao 74040bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M3, 74140bc18a2SBard Liao RT5651_CP_FQ1_MASK | RT5651_CP_FQ2_MASK | 74240bc18a2SBard Liao RT5651_CP_FQ3_MASK, 74340bc18a2SBard Liao (RT5651_CP_FQ_192_KHZ << RT5651_CP_FQ1_SFT) | 74440bc18a2SBard Liao (RT5651_CP_FQ_12_KHZ << RT5651_CP_FQ2_SFT) | 74540bc18a2SBard Liao (RT5651_CP_FQ_192_KHZ << RT5651_CP_FQ3_SFT)); 74640bc18a2SBard Liao 74740bc18a2SBard Liao regmap_write(rt5651->regmap, RT5651_PR_BASE + 74840bc18a2SBard Liao RT5651_MAMP_INT_REG2, 0x1c00); 74940bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_DEPOP_M1, 75040bc18a2SBard Liao RT5651_HP_CP_MASK | RT5651_HP_SG_MASK, 75140bc18a2SBard Liao RT5651_HP_CP_PD | RT5651_HP_SG_EN); 75240bc18a2SBard Liao regmap_update_bits(rt5651->regmap, RT5651_PR_BASE + 75340bc18a2SBard Liao RT5651_CHPUMP_INT_REG1, 0x0700, 0x0400); 75440bc18a2SBard Liao rt5651->hp_mute = 0; 75540bc18a2SBard Liao break; 75640bc18a2SBard Liao 75740bc18a2SBard Liao case SND_SOC_DAPM_PRE_PMD: 75840bc18a2SBard Liao rt5651->hp_mute = 1; 75940bc18a2SBard Liao usleep_range(70000, 75000); 76040bc18a2SBard Liao break; 76140bc18a2SBard Liao 76240bc18a2SBard Liao default: 76340bc18a2SBard Liao return 0; 76440bc18a2SBard Liao } 76540bc18a2SBard Liao 76640bc18a2SBard Liao return 0; 76740bc18a2SBard Liao } 76840bc18a2SBard Liao 76940bc18a2SBard Liao static int rt5651_hp_post_event(struct snd_soc_dapm_widget *w, 77040bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 77140bc18a2SBard Liao { 77230c173edSLars-Peter Clausen 77317b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 77417b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 77540bc18a2SBard Liao 77640bc18a2SBard Liao switch (event) { 77740bc18a2SBard Liao case SND_SOC_DAPM_POST_PMU: 77840bc18a2SBard Liao if (!rt5651->hp_mute) 77940bc18a2SBard Liao usleep_range(80000, 85000); 78040bc18a2SBard Liao 78140bc18a2SBard Liao break; 78240bc18a2SBard Liao 78340bc18a2SBard Liao default: 78440bc18a2SBard Liao return 0; 78540bc18a2SBard Liao } 78640bc18a2SBard Liao 78740bc18a2SBard Liao return 0; 78840bc18a2SBard Liao } 78940bc18a2SBard Liao 79040bc18a2SBard Liao static int rt5651_bst1_event(struct snd_soc_dapm_widget *w, 79140bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 79240bc18a2SBard Liao { 79317b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 79440bc18a2SBard Liao 79540bc18a2SBard Liao switch (event) { 79640bc18a2SBard Liao case SND_SOC_DAPM_POST_PMU: 79717b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 79840bc18a2SBard Liao RT5651_PWR_BST1_OP2, RT5651_PWR_BST1_OP2); 79940bc18a2SBard Liao break; 80040bc18a2SBard Liao 80140bc18a2SBard Liao case SND_SOC_DAPM_PRE_PMD: 80217b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 80340bc18a2SBard Liao RT5651_PWR_BST1_OP2, 0); 80440bc18a2SBard Liao break; 80540bc18a2SBard Liao 80640bc18a2SBard Liao default: 80740bc18a2SBard Liao return 0; 80840bc18a2SBard Liao } 80940bc18a2SBard Liao 81040bc18a2SBard Liao return 0; 81140bc18a2SBard Liao } 81240bc18a2SBard Liao 81340bc18a2SBard Liao static int rt5651_bst2_event(struct snd_soc_dapm_widget *w, 81440bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 81540bc18a2SBard Liao { 81617b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 81740bc18a2SBard Liao 81840bc18a2SBard Liao switch (event) { 81940bc18a2SBard Liao case SND_SOC_DAPM_POST_PMU: 82017b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 82140bc18a2SBard Liao RT5651_PWR_BST2_OP2, RT5651_PWR_BST2_OP2); 82240bc18a2SBard Liao break; 82340bc18a2SBard Liao 82440bc18a2SBard Liao case SND_SOC_DAPM_PRE_PMD: 82517b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 82640bc18a2SBard Liao RT5651_PWR_BST2_OP2, 0); 82740bc18a2SBard Liao break; 82840bc18a2SBard Liao 82940bc18a2SBard Liao default: 83040bc18a2SBard Liao return 0; 83140bc18a2SBard Liao } 83240bc18a2SBard Liao 83340bc18a2SBard Liao return 0; 83440bc18a2SBard Liao } 83540bc18a2SBard Liao 83640bc18a2SBard Liao static int rt5651_bst3_event(struct snd_soc_dapm_widget *w, 83740bc18a2SBard Liao struct snd_kcontrol *kcontrol, int event) 83840bc18a2SBard Liao { 83917b52010SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 84040bc18a2SBard Liao 84140bc18a2SBard Liao switch (event) { 84240bc18a2SBard Liao case SND_SOC_DAPM_POST_PMU: 84317b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 84440bc18a2SBard Liao RT5651_PWR_BST3_OP2, RT5651_PWR_BST3_OP2); 84540bc18a2SBard Liao break; 84640bc18a2SBard Liao 84740bc18a2SBard Liao case SND_SOC_DAPM_PRE_PMD: 84817b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 84940bc18a2SBard Liao RT5651_PWR_BST3_OP2, 0); 85040bc18a2SBard Liao break; 85140bc18a2SBard Liao 85240bc18a2SBard Liao default: 85340bc18a2SBard Liao return 0; 85440bc18a2SBard Liao } 85540bc18a2SBard Liao 85640bc18a2SBard Liao return 0; 85740bc18a2SBard Liao } 85840bc18a2SBard Liao 85940bc18a2SBard Liao static const struct snd_soc_dapm_widget rt5651_dapm_widgets[] = { 86040bc18a2SBard Liao /* ASRC */ 86140bc18a2SBard Liao SND_SOC_DAPM_SUPPLY_S("I2S1 ASRC", 1, RT5651_PLL_MODE_2, 86240bc18a2SBard Liao 15, 0, NULL, 0), 86340bc18a2SBard Liao SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5651_PLL_MODE_2, 86440bc18a2SBard Liao 14, 0, NULL, 0), 86540bc18a2SBard Liao SND_SOC_DAPM_SUPPLY_S("STO1 DAC ASRC", 1, RT5651_PLL_MODE_2, 86640bc18a2SBard Liao 13, 0, NULL, 0), 86740bc18a2SBard Liao SND_SOC_DAPM_SUPPLY_S("STO2 DAC ASRC", 1, RT5651_PLL_MODE_2, 86840bc18a2SBard Liao 12, 0, NULL, 0), 86940bc18a2SBard Liao SND_SOC_DAPM_SUPPLY_S("ADC ASRC", 1, RT5651_PLL_MODE_2, 87040bc18a2SBard Liao 11, 0, NULL, 0), 87140bc18a2SBard Liao 87240bc18a2SBard Liao /* Input Side */ 87380bbe4a3SCarlo Caione SND_SOC_DAPM_SUPPLY("JD Power", RT5651_PWR_ANLG2, 87480bbe4a3SCarlo Caione RT5651_PWM_JD_M_BIT, 0, NULL, 0), 87580bbe4a3SCarlo Caione 87640bc18a2SBard Liao /* micbias */ 87740bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("LDO", RT5651_PWR_ANLG1, 87840bc18a2SBard Liao RT5651_PWR_LDO_BIT, 0, NULL, 0), 879be96fc54SCarlo Caione SND_SOC_DAPM_SUPPLY("micbias1", RT5651_PWR_ANLG2, 880be96fc54SCarlo Caione RT5651_PWR_MB1_BIT, 0, NULL, 0), 88140bc18a2SBard Liao /* Input Lines */ 88240bc18a2SBard Liao SND_SOC_DAPM_INPUT("MIC1"), 88340bc18a2SBard Liao SND_SOC_DAPM_INPUT("MIC2"), 88440bc18a2SBard Liao SND_SOC_DAPM_INPUT("MIC3"), 88540bc18a2SBard Liao 88640bc18a2SBard Liao SND_SOC_DAPM_INPUT("IN1P"), 88740bc18a2SBard Liao SND_SOC_DAPM_INPUT("IN2P"), 88840bc18a2SBard Liao SND_SOC_DAPM_INPUT("IN2N"), 88940bc18a2SBard Liao SND_SOC_DAPM_INPUT("IN3P"), 89040bc18a2SBard Liao SND_SOC_DAPM_INPUT("DMIC L1"), 89140bc18a2SBard Liao SND_SOC_DAPM_INPUT("DMIC R1"), 89240bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("DMIC CLK", RT5651_DMIC, RT5651_DMIC_1_EN_SFT, 89340bc18a2SBard Liao 0, set_dmic_clk, SND_SOC_DAPM_PRE_PMU), 89440bc18a2SBard Liao /* Boost */ 89540bc18a2SBard Liao SND_SOC_DAPM_PGA_E("BST1", RT5651_PWR_ANLG2, 89640bc18a2SBard Liao RT5651_PWR_BST1_BIT, 0, NULL, 0, rt5651_bst1_event, 89740bc18a2SBard Liao SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 89840bc18a2SBard Liao SND_SOC_DAPM_PGA_E("BST2", RT5651_PWR_ANLG2, 89940bc18a2SBard Liao RT5651_PWR_BST2_BIT, 0, NULL, 0, rt5651_bst2_event, 90040bc18a2SBard Liao SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 90140bc18a2SBard Liao SND_SOC_DAPM_PGA_E("BST3", RT5651_PWR_ANLG2, 90240bc18a2SBard Liao RT5651_PWR_BST3_BIT, 0, NULL, 0, rt5651_bst3_event, 90340bc18a2SBard Liao SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 90440bc18a2SBard Liao /* Input Volume */ 90540bc18a2SBard Liao SND_SOC_DAPM_PGA("INL1 VOL", RT5651_PWR_VOL, 90640bc18a2SBard Liao RT5651_PWR_IN1_L_BIT, 0, NULL, 0), 90740bc18a2SBard Liao SND_SOC_DAPM_PGA("INR1 VOL", RT5651_PWR_VOL, 90840bc18a2SBard Liao RT5651_PWR_IN1_R_BIT, 0, NULL, 0), 90940bc18a2SBard Liao SND_SOC_DAPM_PGA("INL2 VOL", RT5651_PWR_VOL, 91040bc18a2SBard Liao RT5651_PWR_IN2_L_BIT, 0, NULL, 0), 91140bc18a2SBard Liao SND_SOC_DAPM_PGA("INR2 VOL", RT5651_PWR_VOL, 91240bc18a2SBard Liao RT5651_PWR_IN2_R_BIT, 0, NULL, 0), 9135800b697SBard Liao 91440bc18a2SBard Liao /* REC Mixer */ 91540bc18a2SBard Liao SND_SOC_DAPM_MIXER("RECMIXL", RT5651_PWR_MIXER, RT5651_PWR_RM_L_BIT, 0, 91640bc18a2SBard Liao rt5651_rec_l_mix, ARRAY_SIZE(rt5651_rec_l_mix)), 91740bc18a2SBard Liao SND_SOC_DAPM_MIXER("RECMIXR", RT5651_PWR_MIXER, RT5651_PWR_RM_R_BIT, 0, 91840bc18a2SBard Liao rt5651_rec_r_mix, ARRAY_SIZE(rt5651_rec_r_mix)), 91940bc18a2SBard Liao /* ADCs */ 92040bc18a2SBard Liao SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0), 92140bc18a2SBard Liao SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0), 92240bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("ADC L Power", RT5651_PWR_DIG1, 92340bc18a2SBard Liao RT5651_PWR_ADC_L_BIT, 0, NULL, 0), 92440bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("ADC R Power", RT5651_PWR_DIG1, 92540bc18a2SBard Liao RT5651_PWR_ADC_R_BIT, 0, NULL, 0), 92640bc18a2SBard Liao /* ADC Mux */ 92740bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 92840bc18a2SBard Liao &rt5651_sto1_adc_l2_mux), 92940bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 93040bc18a2SBard Liao &rt5651_sto1_adc_r2_mux), 93140bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 93240bc18a2SBard Liao &rt5651_sto1_adc_l1_mux), 93340bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 93440bc18a2SBard Liao &rt5651_sto1_adc_r1_mux), 93540bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo2 ADC L2 Mux", SND_SOC_NOPM, 0, 0, 93640bc18a2SBard Liao &rt5651_sto2_adc_l2_mux), 93740bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo2 ADC L1 Mux", SND_SOC_NOPM, 0, 0, 93840bc18a2SBard Liao &rt5651_sto2_adc_l1_mux), 93940bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo2 ADC R1 Mux", SND_SOC_NOPM, 0, 0, 94040bc18a2SBard Liao &rt5651_sto2_adc_r1_mux), 94140bc18a2SBard Liao SND_SOC_DAPM_MUX("Stereo2 ADC R2 Mux", SND_SOC_NOPM, 0, 0, 94240bc18a2SBard Liao &rt5651_sto2_adc_r2_mux), 94340bc18a2SBard Liao /* ADC Mixer */ 94440bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("Stereo1 Filter", RT5651_PWR_DIG2, 94540bc18a2SBard Liao RT5651_PWR_ADC_STO1_F_BIT, 0, NULL, 0), 94640bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("Stereo2 Filter", RT5651_PWR_DIG2, 94740bc18a2SBard Liao RT5651_PWR_ADC_STO2_F_BIT, 0, NULL, 0), 94840bc18a2SBard Liao SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", SND_SOC_NOPM, 0, 0, 94940bc18a2SBard Liao rt5651_sto1_adc_l_mix, 95040bc18a2SBard Liao ARRAY_SIZE(rt5651_sto1_adc_l_mix)), 95140bc18a2SBard Liao SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", SND_SOC_NOPM, 0, 0, 95240bc18a2SBard Liao rt5651_sto1_adc_r_mix, 95340bc18a2SBard Liao ARRAY_SIZE(rt5651_sto1_adc_r_mix)), 95440bc18a2SBard Liao SND_SOC_DAPM_MIXER("Stereo2 ADC MIXL", SND_SOC_NOPM, 0, 0, 95540bc18a2SBard Liao rt5651_sto2_adc_l_mix, 95640bc18a2SBard Liao ARRAY_SIZE(rt5651_sto2_adc_l_mix)), 95740bc18a2SBard Liao SND_SOC_DAPM_MIXER("Stereo2 ADC MIXR", SND_SOC_NOPM, 0, 0, 95840bc18a2SBard Liao rt5651_sto2_adc_r_mix, 95940bc18a2SBard Liao ARRAY_SIZE(rt5651_sto2_adc_r_mix)), 96040bc18a2SBard Liao 96140bc18a2SBard Liao /* Digital Interface */ 96240bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("I2S1", RT5651_PWR_DIG1, 96340bc18a2SBard Liao RT5651_PWR_I2S1_BIT, 0, NULL, 0), 96440bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 96540bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0), 96640bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0), 96740bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 ADC1", SND_SOC_NOPM, 0, 0, NULL, 0), 96840bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 DAC2 L", SND_SOC_NOPM, 0, 0, NULL, 0), 96940bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 DAC2 R", SND_SOC_NOPM, 0, 0, NULL, 0), 97040bc18a2SBard Liao SND_SOC_DAPM_PGA("IF1 ADC2", SND_SOC_NOPM, 0, 0, NULL, 0), 97140bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("I2S2", RT5651_PWR_DIG1, 97240bc18a2SBard Liao RT5651_PWR_I2S2_BIT, 0, NULL, 0), 97340bc18a2SBard Liao SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM, 0, 0, NULL, 0), 97440bc18a2SBard Liao SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM, 0, 0, NULL, 0), 97540bc18a2SBard Liao SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM, 0, 0, NULL, 0), 97640bc18a2SBard Liao SND_SOC_DAPM_MUX("IF2 ADC", SND_SOC_NOPM, 0, 0, 97740bc18a2SBard Liao &rt5651_if2_adc_src_mux), 97840bc18a2SBard Liao 97940bc18a2SBard Liao /* Digital Interface Select */ 98040bc18a2SBard Liao 98140bc18a2SBard Liao SND_SOC_DAPM_MUX("PDM L Mux", RT5651_PDM_CTL, 98240bc18a2SBard Liao RT5651_M_PDM_L_SFT, 1, &rt5651_pdm_l_mux), 98340bc18a2SBard Liao SND_SOC_DAPM_MUX("PDM R Mux", RT5651_PDM_CTL, 98440bc18a2SBard Liao RT5651_M_PDM_R_SFT, 1, &rt5651_pdm_r_mux), 98540bc18a2SBard Liao /* Audio Interface */ 98640bc18a2SBard Liao SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 98740bc18a2SBard Liao SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0), 98840bc18a2SBard Liao SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0), 98940bc18a2SBard Liao SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0), 99040bc18a2SBard Liao 99140bc18a2SBard Liao /* Audio DSP */ 99240bc18a2SBard Liao SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM, 0, 0, NULL, 0), 99340bc18a2SBard Liao 99440bc18a2SBard Liao /* Output Side */ 99540bc18a2SBard Liao /* DAC mixer before sound effect */ 99640bc18a2SBard Liao SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM, 0, 0, 99740bc18a2SBard Liao rt5651_dac_l_mix, ARRAY_SIZE(rt5651_dac_l_mix)), 99840bc18a2SBard Liao SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM, 0, 0, 99940bc18a2SBard Liao rt5651_dac_r_mix, ARRAY_SIZE(rt5651_dac_r_mix)), 100040bc18a2SBard Liao 100140bc18a2SBard Liao /* DAC2 channel Mux */ 100240bc18a2SBard Liao SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM, 0, 0, &rt5651_dac_l2_mux), 100340bc18a2SBard Liao SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM, 0, 0, &rt5651_dac_r2_mux), 100440bc18a2SBard Liao SND_SOC_DAPM_PGA("DAC L2 Volume", SND_SOC_NOPM, 0, 0, NULL, 0), 100540bc18a2SBard Liao SND_SOC_DAPM_PGA("DAC R2 Volume", SND_SOC_NOPM, 0, 0, NULL, 0), 100640bc18a2SBard Liao 100740bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("Stero1 DAC Power", RT5651_PWR_DIG2, 100840bc18a2SBard Liao RT5651_PWR_DAC_STO1_F_BIT, 0, NULL, 0), 100940bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("Stero2 DAC Power", RT5651_PWR_DIG2, 101040bc18a2SBard Liao RT5651_PWR_DAC_STO2_F_BIT, 0, NULL, 0), 101140bc18a2SBard Liao /* DAC Mixer */ 101240bc18a2SBard Liao SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM, 0, 0, 101340bc18a2SBard Liao rt5651_sto_dac_l_mix, 101440bc18a2SBard Liao ARRAY_SIZE(rt5651_sto_dac_l_mix)), 101540bc18a2SBard Liao SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM, 0, 0, 101640bc18a2SBard Liao rt5651_sto_dac_r_mix, 101740bc18a2SBard Liao ARRAY_SIZE(rt5651_sto_dac_r_mix)), 101840bc18a2SBard Liao SND_SOC_DAPM_MIXER("DD MIXL", SND_SOC_NOPM, 0, 0, 101940bc18a2SBard Liao rt5651_dd_dac_l_mix, 102040bc18a2SBard Liao ARRAY_SIZE(rt5651_dd_dac_l_mix)), 102140bc18a2SBard Liao SND_SOC_DAPM_MIXER("DD MIXR", SND_SOC_NOPM, 0, 0, 102240bc18a2SBard Liao rt5651_dd_dac_r_mix, 102340bc18a2SBard Liao ARRAY_SIZE(rt5651_dd_dac_r_mix)), 102440bc18a2SBard Liao 102540bc18a2SBard Liao /* DACs */ 102640bc18a2SBard Liao SND_SOC_DAPM_DAC("DAC L1", NULL, SND_SOC_NOPM, 0, 0), 102740bc18a2SBard Liao SND_SOC_DAPM_DAC("DAC R1", NULL, SND_SOC_NOPM, 0, 0), 102840bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("DAC L1 Power", RT5651_PWR_DIG1, 102940bc18a2SBard Liao RT5651_PWR_DAC_L1_BIT, 0, NULL, 0), 103040bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("DAC R1 Power", RT5651_PWR_DIG1, 103140bc18a2SBard Liao RT5651_PWR_DAC_R1_BIT, 0, NULL, 0), 103240bc18a2SBard Liao /* OUT Mixer */ 103340bc18a2SBard Liao SND_SOC_DAPM_MIXER("OUT MIXL", RT5651_PWR_MIXER, RT5651_PWR_OM_L_BIT, 103440bc18a2SBard Liao 0, rt5651_out_l_mix, ARRAY_SIZE(rt5651_out_l_mix)), 103540bc18a2SBard Liao SND_SOC_DAPM_MIXER("OUT MIXR", RT5651_PWR_MIXER, RT5651_PWR_OM_R_BIT, 103640bc18a2SBard Liao 0, rt5651_out_r_mix, ARRAY_SIZE(rt5651_out_r_mix)), 103740bc18a2SBard Liao /* Ouput Volume */ 103840bc18a2SBard Liao SND_SOC_DAPM_SWITCH("OUTVOL L", RT5651_PWR_VOL, 103940bc18a2SBard Liao RT5651_PWR_OV_L_BIT, 0, &outvol_l_control), 104040bc18a2SBard Liao SND_SOC_DAPM_SWITCH("OUTVOL R", RT5651_PWR_VOL, 104140bc18a2SBard Liao RT5651_PWR_OV_R_BIT, 0, &outvol_r_control), 104240bc18a2SBard Liao SND_SOC_DAPM_SWITCH("HPOVOL L", RT5651_PWR_VOL, 104340bc18a2SBard Liao RT5651_PWR_HV_L_BIT, 0, &hpovol_l_control), 104440bc18a2SBard Liao SND_SOC_DAPM_SWITCH("HPOVOL R", RT5651_PWR_VOL, 104540bc18a2SBard Liao RT5651_PWR_HV_R_BIT, 0, &hpovol_r_control), 104640bc18a2SBard Liao SND_SOC_DAPM_PGA("INL1", RT5651_PWR_VOL, 104740bc18a2SBard Liao RT5651_PWR_IN1_L_BIT, 0, NULL, 0), 104840bc18a2SBard Liao SND_SOC_DAPM_PGA("INR1", RT5651_PWR_VOL, 104940bc18a2SBard Liao RT5651_PWR_IN1_R_BIT, 0, NULL, 0), 105040bc18a2SBard Liao SND_SOC_DAPM_PGA("INL2", RT5651_PWR_VOL, 105140bc18a2SBard Liao RT5651_PWR_IN2_L_BIT, 0, NULL, 0), 105240bc18a2SBard Liao SND_SOC_DAPM_PGA("INR2", RT5651_PWR_VOL, 105340bc18a2SBard Liao RT5651_PWR_IN2_R_BIT, 0, NULL, 0), 105440bc18a2SBard Liao /* HPO/LOUT/Mono Mixer */ 105540bc18a2SBard Liao SND_SOC_DAPM_MIXER("HPOL MIX", SND_SOC_NOPM, 0, 0, 105640bc18a2SBard Liao rt5651_hpo_mix, ARRAY_SIZE(rt5651_hpo_mix)), 105740bc18a2SBard Liao SND_SOC_DAPM_MIXER("HPOR MIX", SND_SOC_NOPM, 0, 0, 105840bc18a2SBard Liao rt5651_hpo_mix, ARRAY_SIZE(rt5651_hpo_mix)), 105940bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("HP L Amp", RT5651_PWR_ANLG1, 106040bc18a2SBard Liao RT5651_PWR_HP_L_BIT, 0, NULL, 0), 106140bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("HP R Amp", RT5651_PWR_ANLG1, 106240bc18a2SBard Liao RT5651_PWR_HP_R_BIT, 0, NULL, 0), 106340bc18a2SBard Liao SND_SOC_DAPM_MIXER("LOUT MIX", RT5651_PWR_ANLG1, RT5651_PWR_LM_BIT, 0, 106440bc18a2SBard Liao rt5651_lout_mix, ARRAY_SIZE(rt5651_lout_mix)), 106540bc18a2SBard Liao 106640bc18a2SBard Liao SND_SOC_DAPM_SUPPLY("Amp Power", RT5651_PWR_ANLG1, 106740bc18a2SBard Liao RT5651_PWR_HA_BIT, 0, rt5651_amp_power_event, 106840bc18a2SBard Liao SND_SOC_DAPM_POST_PMU), 106940bc18a2SBard Liao SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5651_hp_event, 107040bc18a2SBard Liao SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 107140bc18a2SBard Liao SND_SOC_DAPM_SWITCH("HPO L Playback", SND_SOC_NOPM, 0, 0, 107240bc18a2SBard Liao &hpo_l_mute_control), 107340bc18a2SBard Liao SND_SOC_DAPM_SWITCH("HPO R Playback", SND_SOC_NOPM, 0, 0, 107440bc18a2SBard Liao &hpo_r_mute_control), 107540bc18a2SBard Liao SND_SOC_DAPM_SWITCH("LOUT L Playback", SND_SOC_NOPM, 0, 0, 107640bc18a2SBard Liao &lout_l_mute_control), 107740bc18a2SBard Liao SND_SOC_DAPM_SWITCH("LOUT R Playback", SND_SOC_NOPM, 0, 0, 107840bc18a2SBard Liao &lout_r_mute_control), 107940bc18a2SBard Liao SND_SOC_DAPM_POST("HP Post", rt5651_hp_post_event), 108040bc18a2SBard Liao 108140bc18a2SBard Liao /* Output Lines */ 108240bc18a2SBard Liao SND_SOC_DAPM_OUTPUT("HPOL"), 108340bc18a2SBard Liao SND_SOC_DAPM_OUTPUT("HPOR"), 108440bc18a2SBard Liao SND_SOC_DAPM_OUTPUT("LOUTL"), 108540bc18a2SBard Liao SND_SOC_DAPM_OUTPUT("LOUTR"), 108640bc18a2SBard Liao SND_SOC_DAPM_OUTPUT("PDML"), 108740bc18a2SBard Liao SND_SOC_DAPM_OUTPUT("PDMR"), 108840bc18a2SBard Liao }; 108940bc18a2SBard Liao 109040bc18a2SBard Liao static const struct snd_soc_dapm_route rt5651_dapm_routes[] = { 109140bc18a2SBard Liao {"Stero1 DAC Power", NULL, "STO1 DAC ASRC"}, 109240bc18a2SBard Liao {"Stero2 DAC Power", NULL, "STO2 DAC ASRC"}, 109340bc18a2SBard Liao {"I2S1", NULL, "I2S1 ASRC"}, 109440bc18a2SBard Liao {"I2S2", NULL, "I2S2 ASRC"}, 109540bc18a2SBard Liao 109640bc18a2SBard Liao {"IN1P", NULL, "LDO"}, 109740bc18a2SBard Liao {"IN2P", NULL, "LDO"}, 109840bc18a2SBard Liao {"IN3P", NULL, "LDO"}, 109940bc18a2SBard Liao 110040bc18a2SBard Liao {"IN1P", NULL, "MIC1"}, 110140bc18a2SBard Liao {"IN2P", NULL, "MIC2"}, 110240bc18a2SBard Liao {"IN2N", NULL, "MIC2"}, 110340bc18a2SBard Liao {"IN3P", NULL, "MIC3"}, 110440bc18a2SBard Liao 110540bc18a2SBard Liao {"BST1", NULL, "IN1P"}, 110640bc18a2SBard Liao {"BST2", NULL, "IN2P"}, 110740bc18a2SBard Liao {"BST2", NULL, "IN2N"}, 110840bc18a2SBard Liao {"BST3", NULL, "IN3P"}, 110940bc18a2SBard Liao 111040bc18a2SBard Liao {"INL1 VOL", NULL, "IN2P"}, 111140bc18a2SBard Liao {"INR1 VOL", NULL, "IN2N"}, 111240bc18a2SBard Liao 111340bc18a2SBard Liao {"RECMIXL", "INL1 Switch", "INL1 VOL"}, 111440bc18a2SBard Liao {"RECMIXL", "BST3 Switch", "BST3"}, 111540bc18a2SBard Liao {"RECMIXL", "BST2 Switch", "BST2"}, 111640bc18a2SBard Liao {"RECMIXL", "BST1 Switch", "BST1"}, 111740bc18a2SBard Liao 111840bc18a2SBard Liao {"RECMIXR", "INR1 Switch", "INR1 VOL"}, 111940bc18a2SBard Liao {"RECMIXR", "BST3 Switch", "BST3"}, 112040bc18a2SBard Liao {"RECMIXR", "BST2 Switch", "BST2"}, 112140bc18a2SBard Liao {"RECMIXR", "BST1 Switch", "BST1"}, 112240bc18a2SBard Liao 112340bc18a2SBard Liao {"ADC L", NULL, "RECMIXL"}, 112440bc18a2SBard Liao {"ADC L", NULL, "ADC L Power"}, 112540bc18a2SBard Liao {"ADC R", NULL, "RECMIXR"}, 112640bc18a2SBard Liao {"ADC R", NULL, "ADC R Power"}, 112740bc18a2SBard Liao 112840bc18a2SBard Liao {"DMIC L1", NULL, "DMIC CLK"}, 112940bc18a2SBard Liao {"DMIC R1", NULL, "DMIC CLK"}, 113040bc18a2SBard Liao 113140bc18a2SBard Liao {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"}, 113240bc18a2SBard Liao {"Stereo1 ADC L2 Mux", "DD MIX", "DD MIXL"}, 113340bc18a2SBard Liao {"Stereo1 ADC L1 Mux", "ADC", "ADC L"}, 113440bc18a2SBard Liao {"Stereo1 ADC L1 Mux", "DD MIX", "DD MIXL"}, 113540bc18a2SBard Liao 113640bc18a2SBard Liao {"Stereo1 ADC R1 Mux", "ADC", "ADC R"}, 113740bc18a2SBard Liao {"Stereo1 ADC R1 Mux", "DD MIX", "DD MIXR"}, 113840bc18a2SBard Liao {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"}, 113940bc18a2SBard Liao {"Stereo1 ADC R2 Mux", "DD MIX", "DD MIXR"}, 114040bc18a2SBard Liao 114140bc18a2SBard Liao {"Stereo2 ADC L2 Mux", "DMIC L", "DMIC L1"}, 114240bc18a2SBard Liao {"Stereo2 ADC L2 Mux", "DD MIXL", "DD MIXL"}, 114340bc18a2SBard Liao {"Stereo2 ADC L1 Mux", "DD MIXL", "DD MIXL"}, 114440bc18a2SBard Liao {"Stereo2 ADC L1 Mux", "ADCL", "ADC L"}, 114540bc18a2SBard Liao 114640bc18a2SBard Liao {"Stereo2 ADC R1 Mux", "DD MIXR", "DD MIXR"}, 114740bc18a2SBard Liao {"Stereo2 ADC R1 Mux", "ADCR", "ADC R"}, 114840bc18a2SBard Liao {"Stereo2 ADC R2 Mux", "DMIC R", "DMIC R1"}, 114940bc18a2SBard Liao {"Stereo2 ADC R2 Mux", "DD MIXR", "DD MIXR"}, 115040bc18a2SBard Liao 115140bc18a2SBard Liao {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"}, 115240bc18a2SBard Liao {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"}, 115340bc18a2SBard Liao {"Stereo1 ADC MIXL", NULL, "Stereo1 Filter"}, 115440bc18a2SBard Liao {"Stereo1 Filter", NULL, "ADC ASRC"}, 115540bc18a2SBard Liao 115640bc18a2SBard Liao {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"}, 115740bc18a2SBard Liao {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"}, 115840bc18a2SBard Liao {"Stereo1 ADC MIXR", NULL, "Stereo1 Filter"}, 115940bc18a2SBard Liao 116040bc18a2SBard Liao {"Stereo2 ADC MIXL", "ADC1 Switch", "Stereo2 ADC L1 Mux"}, 116140bc18a2SBard Liao {"Stereo2 ADC MIXL", "ADC2 Switch", "Stereo2 ADC L2 Mux"}, 116240bc18a2SBard Liao {"Stereo2 ADC MIXL", NULL, "Stereo2 Filter"}, 116340bc18a2SBard Liao {"Stereo2 Filter", NULL, "ADC ASRC"}, 116440bc18a2SBard Liao 116540bc18a2SBard Liao {"Stereo2 ADC MIXR", "ADC1 Switch", "Stereo2 ADC R1 Mux"}, 116640bc18a2SBard Liao {"Stereo2 ADC MIXR", "ADC2 Switch", "Stereo2 ADC R2 Mux"}, 116740bc18a2SBard Liao {"Stereo2 ADC MIXR", NULL, "Stereo2 Filter"}, 116840bc18a2SBard Liao 116940bc18a2SBard Liao {"IF1 ADC2", NULL, "Stereo2 ADC MIXL"}, 117040bc18a2SBard Liao {"IF1 ADC2", NULL, "Stereo2 ADC MIXR"}, 117140bc18a2SBard Liao {"IF1 ADC1", NULL, "Stereo1 ADC MIXL"}, 117240bc18a2SBard Liao {"IF1 ADC1", NULL, "Stereo1 ADC MIXR"}, 117340bc18a2SBard Liao 117440bc18a2SBard Liao {"IF1 ADC1", NULL, "I2S1"}, 117540bc18a2SBard Liao 117640bc18a2SBard Liao {"IF2 ADC", "IF1 ADC1", "IF1 ADC1"}, 117740bc18a2SBard Liao {"IF2 ADC", "IF1 ADC2", "IF1 ADC2"}, 117840bc18a2SBard Liao {"IF2 ADC", NULL, "I2S2"}, 117940bc18a2SBard Liao 118040bc18a2SBard Liao {"AIF1TX", NULL, "IF1 ADC1"}, 118140bc18a2SBard Liao {"AIF1TX", NULL, "IF1 ADC2"}, 118240bc18a2SBard Liao {"AIF2TX", NULL, "IF2 ADC"}, 118340bc18a2SBard Liao 118440bc18a2SBard Liao {"IF1 DAC", NULL, "AIF1RX"}, 118540bc18a2SBard Liao {"IF1 DAC", NULL, "I2S1"}, 118640bc18a2SBard Liao {"IF2 DAC", NULL, "AIF2RX"}, 118740bc18a2SBard Liao {"IF2 DAC", NULL, "I2S2"}, 118840bc18a2SBard Liao 118940bc18a2SBard Liao {"IF1 DAC1 L", NULL, "IF1 DAC"}, 119040bc18a2SBard Liao {"IF1 DAC1 R", NULL, "IF1 DAC"}, 119140bc18a2SBard Liao {"IF1 DAC2 L", NULL, "IF1 DAC"}, 119240bc18a2SBard Liao {"IF1 DAC2 R", NULL, "IF1 DAC"}, 119340bc18a2SBard Liao {"IF2 DAC L", NULL, "IF2 DAC"}, 119440bc18a2SBard Liao {"IF2 DAC R", NULL, "IF2 DAC"}, 119540bc18a2SBard Liao 119640bc18a2SBard Liao {"DAC MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"}, 119740bc18a2SBard Liao {"DAC MIXL", "INF1 Switch", "IF1 DAC1 L"}, 119840bc18a2SBard Liao {"DAC MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"}, 119940bc18a2SBard Liao {"DAC MIXR", "INF1 Switch", "IF1 DAC1 R"}, 120040bc18a2SBard Liao 120140bc18a2SBard Liao {"Audio DSP", NULL, "DAC MIXL"}, 120240bc18a2SBard Liao {"Audio DSP", NULL, "DAC MIXR"}, 120340bc18a2SBard Liao 120440bc18a2SBard Liao {"DAC L2 Mux", "IF1", "IF1 DAC2 L"}, 120540bc18a2SBard Liao {"DAC L2 Mux", "IF2", "IF2 DAC L"}, 120640bc18a2SBard Liao {"DAC L2 Volume", NULL, "DAC L2 Mux"}, 120740bc18a2SBard Liao 120840bc18a2SBard Liao {"DAC R2 Mux", "IF1", "IF1 DAC2 R"}, 120940bc18a2SBard Liao {"DAC R2 Mux", "IF2", "IF2 DAC R"}, 121040bc18a2SBard Liao {"DAC R2 Volume", NULL, "DAC R2 Mux"}, 121140bc18a2SBard Liao 121240bc18a2SBard Liao {"Stereo DAC MIXL", "DAC L1 Switch", "Audio DSP"}, 121340bc18a2SBard Liao {"Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Volume"}, 121440bc18a2SBard Liao {"Stereo DAC MIXL", "DAC R1 Switch", "DAC MIXR"}, 121540bc18a2SBard Liao {"Stereo DAC MIXL", NULL, "Stero1 DAC Power"}, 121640bc18a2SBard Liao {"Stereo DAC MIXL", NULL, "Stero2 DAC Power"}, 121740bc18a2SBard Liao {"Stereo DAC MIXR", "DAC R1 Switch", "Audio DSP"}, 121840bc18a2SBard Liao {"Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Volume"}, 121940bc18a2SBard Liao {"Stereo DAC MIXR", "DAC L1 Switch", "DAC MIXL"}, 122040bc18a2SBard Liao {"Stereo DAC MIXR", NULL, "Stero1 DAC Power"}, 122140bc18a2SBard Liao {"Stereo DAC MIXR", NULL, "Stero2 DAC Power"}, 122240bc18a2SBard Liao 122340bc18a2SBard Liao {"PDM L Mux", "Stereo DAC MIX", "Stereo DAC MIXL"}, 122440bc18a2SBard Liao {"PDM L Mux", "DD MIX", "DAC MIXL"}, 122540bc18a2SBard Liao {"PDM R Mux", "Stereo DAC MIX", "Stereo DAC MIXR"}, 122640bc18a2SBard Liao {"PDM R Mux", "DD MIX", "DAC MIXR"}, 122740bc18a2SBard Liao 122840bc18a2SBard Liao {"DAC L1", NULL, "Stereo DAC MIXL"}, 122940bc18a2SBard Liao {"DAC L1", NULL, "DAC L1 Power"}, 123040bc18a2SBard Liao {"DAC R1", NULL, "Stereo DAC MIXR"}, 123140bc18a2SBard Liao {"DAC R1", NULL, "DAC R1 Power"}, 123240bc18a2SBard Liao 123340bc18a2SBard Liao {"DD MIXL", "DAC L1 Switch", "DAC MIXL"}, 123440bc18a2SBard Liao {"DD MIXL", "DAC L2 Switch", "DAC L2 Volume"}, 123540bc18a2SBard Liao {"DD MIXL", "DAC R2 Switch", "DAC R2 Volume"}, 123640bc18a2SBard Liao {"DD MIXL", NULL, "Stero2 DAC Power"}, 123740bc18a2SBard Liao 123840bc18a2SBard Liao {"DD MIXR", "DAC R1 Switch", "DAC MIXR"}, 123940bc18a2SBard Liao {"DD MIXR", "DAC R2 Switch", "DAC R2 Volume"}, 124040bc18a2SBard Liao {"DD MIXR", "DAC L2 Switch", "DAC L2 Volume"}, 124140bc18a2SBard Liao {"DD MIXR", NULL, "Stero2 DAC Power"}, 124240bc18a2SBard Liao 124340bc18a2SBard Liao {"OUT MIXL", "BST1 Switch", "BST1"}, 124440bc18a2SBard Liao {"OUT MIXL", "BST2 Switch", "BST2"}, 124540bc18a2SBard Liao {"OUT MIXL", "INL1 Switch", "INL1 VOL"}, 124640bc18a2SBard Liao {"OUT MIXL", "REC MIXL Switch", "RECMIXL"}, 124740bc18a2SBard Liao {"OUT MIXL", "DAC L1 Switch", "DAC L1"}, 124840bc18a2SBard Liao 124940bc18a2SBard Liao {"OUT MIXR", "BST2 Switch", "BST2"}, 125040bc18a2SBard Liao {"OUT MIXR", "BST1 Switch", "BST1"}, 125140bc18a2SBard Liao {"OUT MIXR", "INR1 Switch", "INR1 VOL"}, 125240bc18a2SBard Liao {"OUT MIXR", "REC MIXR Switch", "RECMIXR"}, 125340bc18a2SBard Liao {"OUT MIXR", "DAC R1 Switch", "DAC R1"}, 125440bc18a2SBard Liao 125540bc18a2SBard Liao {"HPOVOL L", "Switch", "OUT MIXL"}, 125640bc18a2SBard Liao {"HPOVOL R", "Switch", "OUT MIXR"}, 125740bc18a2SBard Liao {"OUTVOL L", "Switch", "OUT MIXL"}, 125840bc18a2SBard Liao {"OUTVOL R", "Switch", "OUT MIXR"}, 125940bc18a2SBard Liao 126040bc18a2SBard Liao {"HPOL MIX", "HPO MIX DAC1 Switch", "DAC L1"}, 126140bc18a2SBard Liao {"HPOL MIX", "HPO MIX HPVOL Switch", "HPOVOL L"}, 126240bc18a2SBard Liao {"HPOL MIX", NULL, "HP L Amp"}, 126340bc18a2SBard Liao {"HPOR MIX", "HPO MIX DAC1 Switch", "DAC R1"}, 126440bc18a2SBard Liao {"HPOR MIX", "HPO MIX HPVOL Switch", "HPOVOL R"}, 126540bc18a2SBard Liao {"HPOR MIX", NULL, "HP R Amp"}, 126640bc18a2SBard Liao 126740bc18a2SBard Liao {"LOUT MIX", "DAC L1 Switch", "DAC L1"}, 126840bc18a2SBard Liao {"LOUT MIX", "DAC R1 Switch", "DAC R1"}, 126940bc18a2SBard Liao {"LOUT MIX", "OUTVOL L Switch", "OUTVOL L"}, 127040bc18a2SBard Liao {"LOUT MIX", "OUTVOL R Switch", "OUTVOL R"}, 127140bc18a2SBard Liao 127240bc18a2SBard Liao {"HP Amp", NULL, "HPOL MIX"}, 127340bc18a2SBard Liao {"HP Amp", NULL, "HPOR MIX"}, 127440bc18a2SBard Liao {"HP Amp", NULL, "Amp Power"}, 127540bc18a2SBard Liao {"HPO L Playback", "Switch", "HP Amp"}, 127640bc18a2SBard Liao {"HPO R Playback", "Switch", "HP Amp"}, 127740bc18a2SBard Liao {"HPOL", NULL, "HPO L Playback"}, 127840bc18a2SBard Liao {"HPOR", NULL, "HPO R Playback"}, 127940bc18a2SBard Liao 128040bc18a2SBard Liao {"LOUT L Playback", "Switch", "LOUT MIX"}, 128140bc18a2SBard Liao {"LOUT R Playback", "Switch", "LOUT MIX"}, 128240bc18a2SBard Liao {"LOUTL", NULL, "LOUT L Playback"}, 128340bc18a2SBard Liao {"LOUTL", NULL, "Amp Power"}, 128440bc18a2SBard Liao {"LOUTR", NULL, "LOUT R Playback"}, 128540bc18a2SBard Liao {"LOUTR", NULL, "Amp Power"}, 128640bc18a2SBard Liao 128740bc18a2SBard Liao {"PDML", NULL, "PDM L Mux"}, 128840bc18a2SBard Liao {"PDMR", NULL, "PDM R Mux"}, 128940bc18a2SBard Liao }; 129040bc18a2SBard Liao 129140bc18a2SBard Liao static int rt5651_hw_params(struct snd_pcm_substream *substream, 129240bc18a2SBard Liao struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 129340bc18a2SBard Liao { 129417b52010SKuninori Morimoto struct snd_soc_component *component = dai->component; 129517b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 129640bc18a2SBard Liao unsigned int val_len = 0, val_clk, mask_clk; 129740bc18a2SBard Liao int pre_div, bclk_ms, frame_size; 129840bc18a2SBard Liao 129940bc18a2SBard Liao rt5651->lrck[dai->id] = params_rate(params); 1300d92950e7SOder Chiou pre_div = rl6231_get_clk_info(rt5651->sysclk, rt5651->lrck[dai->id]); 130140bc18a2SBard Liao 130240bc18a2SBard Liao if (pre_div < 0) { 130317b52010SKuninori Morimoto dev_err(component->dev, "Unsupported clock setting\n"); 130440bc18a2SBard Liao return -EINVAL; 130540bc18a2SBard Liao } 130640bc18a2SBard Liao frame_size = snd_soc_params_to_frame_size(params); 130740bc18a2SBard Liao if (frame_size < 0) { 130817b52010SKuninori Morimoto dev_err(component->dev, "Unsupported frame size: %d\n", frame_size); 130940bc18a2SBard Liao return -EINVAL; 131040bc18a2SBard Liao } 131140bc18a2SBard Liao bclk_ms = frame_size > 32 ? 1 : 0; 131240bc18a2SBard Liao rt5651->bclk[dai->id] = rt5651->lrck[dai->id] * (32 << bclk_ms); 131340bc18a2SBard Liao 131440bc18a2SBard Liao dev_dbg(dai->dev, "bclk is %dHz and lrck is %dHz\n", 131540bc18a2SBard Liao rt5651->bclk[dai->id], rt5651->lrck[dai->id]); 131640bc18a2SBard Liao dev_dbg(dai->dev, "bclk_ms is %d and pre_div is %d for iis %d\n", 131740bc18a2SBard Liao bclk_ms, pre_div, dai->id); 131840bc18a2SBard Liao 1319794f33d2SMark Brown switch (params_width(params)) { 1320794f33d2SMark Brown case 16: 132140bc18a2SBard Liao break; 1322794f33d2SMark Brown case 20: 132340bc18a2SBard Liao val_len |= RT5651_I2S_DL_20; 132440bc18a2SBard Liao break; 1325794f33d2SMark Brown case 24: 132640bc18a2SBard Liao val_len |= RT5651_I2S_DL_24; 132740bc18a2SBard Liao break; 1328794f33d2SMark Brown case 8: 132940bc18a2SBard Liao val_len |= RT5651_I2S_DL_8; 133040bc18a2SBard Liao break; 133140bc18a2SBard Liao default: 133240bc18a2SBard Liao return -EINVAL; 133340bc18a2SBard Liao } 133440bc18a2SBard Liao 133540bc18a2SBard Liao switch (dai->id) { 133640bc18a2SBard Liao case RT5651_AIF1: 133740bc18a2SBard Liao mask_clk = RT5651_I2S_PD1_MASK; 133840bc18a2SBard Liao val_clk = pre_div << RT5651_I2S_PD1_SFT; 133917b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_I2S1_SDP, 134040bc18a2SBard Liao RT5651_I2S_DL_MASK, val_len); 134117b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_ADDA_CLK1, mask_clk, val_clk); 134240bc18a2SBard Liao break; 134340bc18a2SBard Liao case RT5651_AIF2: 134440bc18a2SBard Liao mask_clk = RT5651_I2S_BCLK_MS2_MASK | RT5651_I2S_PD2_MASK; 134540bc18a2SBard Liao val_clk = pre_div << RT5651_I2S_PD2_SFT; 134617b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_I2S2_SDP, 134740bc18a2SBard Liao RT5651_I2S_DL_MASK, val_len); 134817b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_ADDA_CLK1, mask_clk, val_clk); 134940bc18a2SBard Liao break; 135040bc18a2SBard Liao default: 135117b52010SKuninori Morimoto dev_err(component->dev, "Wrong dai->id: %d\n", dai->id); 135240bc18a2SBard Liao return -EINVAL; 135340bc18a2SBard Liao } 135440bc18a2SBard Liao 135540bc18a2SBard Liao return 0; 135640bc18a2SBard Liao } 135740bc18a2SBard Liao 135840bc18a2SBard Liao static int rt5651_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) 135940bc18a2SBard Liao { 136017b52010SKuninori Morimoto struct snd_soc_component *component = dai->component; 136117b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 136240bc18a2SBard Liao unsigned int reg_val = 0; 136340bc18a2SBard Liao 136440bc18a2SBard Liao switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 136540bc18a2SBard Liao case SND_SOC_DAIFMT_CBM_CFM: 136640bc18a2SBard Liao rt5651->master[dai->id] = 1; 136740bc18a2SBard Liao break; 136840bc18a2SBard Liao case SND_SOC_DAIFMT_CBS_CFS: 136940bc18a2SBard Liao reg_val |= RT5651_I2S_MS_S; 137040bc18a2SBard Liao rt5651->master[dai->id] = 0; 137140bc18a2SBard Liao break; 137240bc18a2SBard Liao default: 137340bc18a2SBard Liao return -EINVAL; 137440bc18a2SBard Liao } 137540bc18a2SBard Liao 137640bc18a2SBard Liao switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 137740bc18a2SBard Liao case SND_SOC_DAIFMT_NB_NF: 137840bc18a2SBard Liao break; 137940bc18a2SBard Liao case SND_SOC_DAIFMT_IB_NF: 138040bc18a2SBard Liao reg_val |= RT5651_I2S_BP_INV; 138140bc18a2SBard Liao break; 138240bc18a2SBard Liao default: 138340bc18a2SBard Liao return -EINVAL; 138440bc18a2SBard Liao } 138540bc18a2SBard Liao 138640bc18a2SBard Liao switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 138740bc18a2SBard Liao case SND_SOC_DAIFMT_I2S: 138840bc18a2SBard Liao break; 138940bc18a2SBard Liao case SND_SOC_DAIFMT_LEFT_J: 139040bc18a2SBard Liao reg_val |= RT5651_I2S_DF_LEFT; 139140bc18a2SBard Liao break; 139240bc18a2SBard Liao case SND_SOC_DAIFMT_DSP_A: 139340bc18a2SBard Liao reg_val |= RT5651_I2S_DF_PCM_A; 139440bc18a2SBard Liao break; 139540bc18a2SBard Liao case SND_SOC_DAIFMT_DSP_B: 139640bc18a2SBard Liao reg_val |= RT5651_I2S_DF_PCM_B; 139740bc18a2SBard Liao break; 139840bc18a2SBard Liao default: 139940bc18a2SBard Liao return -EINVAL; 140040bc18a2SBard Liao } 140140bc18a2SBard Liao 140240bc18a2SBard Liao switch (dai->id) { 140340bc18a2SBard Liao case RT5651_AIF1: 140417b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_I2S1_SDP, 140540bc18a2SBard Liao RT5651_I2S_MS_MASK | RT5651_I2S_BP_MASK | 140640bc18a2SBard Liao RT5651_I2S_DF_MASK, reg_val); 140740bc18a2SBard Liao break; 140840bc18a2SBard Liao case RT5651_AIF2: 140917b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_I2S2_SDP, 141040bc18a2SBard Liao RT5651_I2S_MS_MASK | RT5651_I2S_BP_MASK | 141140bc18a2SBard Liao RT5651_I2S_DF_MASK, reg_val); 141240bc18a2SBard Liao break; 141340bc18a2SBard Liao default: 141417b52010SKuninori Morimoto dev_err(component->dev, "Wrong dai->id: %d\n", dai->id); 141540bc18a2SBard Liao return -EINVAL; 141640bc18a2SBard Liao } 141740bc18a2SBard Liao return 0; 141840bc18a2SBard Liao } 141940bc18a2SBard Liao 142040bc18a2SBard Liao static int rt5651_set_dai_sysclk(struct snd_soc_dai *dai, 142140bc18a2SBard Liao int clk_id, unsigned int freq, int dir) 142240bc18a2SBard Liao { 142317b52010SKuninori Morimoto struct snd_soc_component *component = dai->component; 142417b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 142540bc18a2SBard Liao unsigned int reg_val = 0; 1426d082174cSHans de Goede unsigned int pll_bit = 0; 142740bc18a2SBard Liao 142840bc18a2SBard Liao if (freq == rt5651->sysclk && clk_id == rt5651->sysclk_src) 142940bc18a2SBard Liao return 0; 143040bc18a2SBard Liao 143140bc18a2SBard Liao switch (clk_id) { 143240bc18a2SBard Liao case RT5651_SCLK_S_MCLK: 143340bc18a2SBard Liao reg_val |= RT5651_SCLK_SRC_MCLK; 143440bc18a2SBard Liao break; 143540bc18a2SBard Liao case RT5651_SCLK_S_PLL1: 143640bc18a2SBard Liao reg_val |= RT5651_SCLK_SRC_PLL1; 1437d082174cSHans de Goede pll_bit |= RT5651_PWR_PLL; 143840bc18a2SBard Liao break; 143940bc18a2SBard Liao case RT5651_SCLK_S_RCCLK: 144040bc18a2SBard Liao reg_val |= RT5651_SCLK_SRC_RCCLK; 144140bc18a2SBard Liao break; 144240bc18a2SBard Liao default: 144317b52010SKuninori Morimoto dev_err(component->dev, "Invalid clock id (%d)\n", clk_id); 144440bc18a2SBard Liao return -EINVAL; 144540bc18a2SBard Liao } 1446d082174cSHans de Goede snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 1447d082174cSHans de Goede RT5651_PWR_PLL, pll_bit); 144817b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_GLB_CLK, 144940bc18a2SBard Liao RT5651_SCLK_SRC_MASK, reg_val); 145040bc18a2SBard Liao rt5651->sysclk = freq; 145140bc18a2SBard Liao rt5651->sysclk_src = clk_id; 145240bc18a2SBard Liao 145340bc18a2SBard Liao dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); 145440bc18a2SBard Liao 145540bc18a2SBard Liao return 0; 145640bc18a2SBard Liao } 145740bc18a2SBard Liao 145840bc18a2SBard Liao static int rt5651_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, 145940bc18a2SBard Liao unsigned int freq_in, unsigned int freq_out) 146040bc18a2SBard Liao { 146117b52010SKuninori Morimoto struct snd_soc_component *component = dai->component; 146217b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 146371c7a2d6SOder Chiou struct rl6231_pll_code pll_code; 146440bc18a2SBard Liao int ret; 146540bc18a2SBard Liao 146640bc18a2SBard Liao if (source == rt5651->pll_src && freq_in == rt5651->pll_in && 146740bc18a2SBard Liao freq_out == rt5651->pll_out) 146840bc18a2SBard Liao return 0; 146940bc18a2SBard Liao 147040bc18a2SBard Liao if (!freq_in || !freq_out) { 147117b52010SKuninori Morimoto dev_dbg(component->dev, "PLL disabled\n"); 147240bc18a2SBard Liao 147340bc18a2SBard Liao rt5651->pll_in = 0; 147440bc18a2SBard Liao rt5651->pll_out = 0; 147517b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_GLB_CLK, 147640bc18a2SBard Liao RT5651_SCLK_SRC_MASK, RT5651_SCLK_SRC_MCLK); 147740bc18a2SBard Liao return 0; 147840bc18a2SBard Liao } 147940bc18a2SBard Liao 148040bc18a2SBard Liao switch (source) { 148140bc18a2SBard Liao case RT5651_PLL1_S_MCLK: 148217b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_GLB_CLK, 148340bc18a2SBard Liao RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_MCLK); 148440bc18a2SBard Liao break; 148540bc18a2SBard Liao case RT5651_PLL1_S_BCLK1: 148617b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_GLB_CLK, 148740bc18a2SBard Liao RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_BCLK1); 148840bc18a2SBard Liao break; 148940bc18a2SBard Liao case RT5651_PLL1_S_BCLK2: 149017b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_GLB_CLK, 149140bc18a2SBard Liao RT5651_PLL1_SRC_MASK, RT5651_PLL1_SRC_BCLK2); 149240bc18a2SBard Liao break; 149340bc18a2SBard Liao default: 149417b52010SKuninori Morimoto dev_err(component->dev, "Unknown PLL source %d\n", source); 149540bc18a2SBard Liao return -EINVAL; 149640bc18a2SBard Liao } 149740bc18a2SBard Liao 149871c7a2d6SOder Chiou ret = rl6231_pll_calc(freq_in, freq_out, &pll_code); 149940bc18a2SBard Liao if (ret < 0) { 150017b52010SKuninori Morimoto dev_err(component->dev, "Unsupport input clock %d\n", freq_in); 150140bc18a2SBard Liao return ret; 150240bc18a2SBard Liao } 150340bc18a2SBard Liao 150417b52010SKuninori Morimoto dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", 150571c7a2d6SOder Chiou pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), 150671c7a2d6SOder Chiou pll_code.n_code, pll_code.k_code); 150740bc18a2SBard Liao 150817b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_PLL_CTRL1, 150971c7a2d6SOder Chiou pll_code.n_code << RT5651_PLL_N_SFT | pll_code.k_code); 151017b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_PLL_CTRL2, 151171c7a2d6SOder Chiou (pll_code.m_bp ? 0 : pll_code.m_code) << RT5651_PLL_M_SFT | 151271c7a2d6SOder Chiou pll_code.m_bp << RT5651_PLL_M_BP_SFT); 151340bc18a2SBard Liao 151440bc18a2SBard Liao rt5651->pll_in = freq_in; 151540bc18a2SBard Liao rt5651->pll_out = freq_out; 151640bc18a2SBard Liao rt5651->pll_src = source; 151740bc18a2SBard Liao 151840bc18a2SBard Liao return 0; 151940bc18a2SBard Liao } 152040bc18a2SBard Liao 152117b52010SKuninori Morimoto static int rt5651_set_bias_level(struct snd_soc_component *component, 152240bc18a2SBard Liao enum snd_soc_bias_level level) 152340bc18a2SBard Liao { 152440bc18a2SBard Liao switch (level) { 152540bc18a2SBard Liao case SND_SOC_BIAS_PREPARE: 152617b52010SKuninori Morimoto if (SND_SOC_BIAS_STANDBY == snd_soc_component_get_bias_level(component)) { 1527984c803fSHans de Goede if (snd_soc_component_read32(component, RT5651_PLL_MODE_1) & 0x9200) 1528984c803fSHans de Goede snd_soc_component_update_bits(component, RT5651_D_MISC, 1529984c803fSHans de Goede 0xc00, 0xc00); 1530984c803fSHans de Goede } 1531984c803fSHans de Goede break; 1532984c803fSHans de Goede case SND_SOC_BIAS_STANDBY: 1533984c803fSHans de Goede if (SND_SOC_BIAS_OFF == snd_soc_component_get_bias_level(component)) { 153417b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 153540bc18a2SBard Liao RT5651_PWR_VREF1 | RT5651_PWR_MB | 153640bc18a2SBard Liao RT5651_PWR_BG | RT5651_PWR_VREF2, 153740bc18a2SBard Liao RT5651_PWR_VREF1 | RT5651_PWR_MB | 153840bc18a2SBard Liao RT5651_PWR_BG | RT5651_PWR_VREF2); 153940bc18a2SBard Liao usleep_range(10000, 15000); 154017b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 154140bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2, 154240bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2); 154317b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 154440bc18a2SBard Liao RT5651_PWR_LDO_DVO_MASK, 154540bc18a2SBard Liao RT5651_PWR_LDO_DVO_1_2V); 154617b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_D_MISC, 0x1, 0x1); 154740bc18a2SBard Liao } 154840bc18a2SBard Liao break; 154940bc18a2SBard Liao 1550984c803fSHans de Goede case SND_SOC_BIAS_OFF: 155117b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_D_MISC, 0x0010); 155217b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_PWR_DIG1, 0x0000); 155317b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_PWR_DIG2, 0x0000); 155417b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_PWR_VOL, 0x0000); 155517b52010SKuninori Morimoto snd_soc_component_write(component, RT5651_PWR_MIXER, 0x0000); 1556bba4e685SHans de Goede /* Do not touch the LDO voltage select bits on bias-off */ 1557bba4e685SHans de Goede snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 1558bba4e685SHans de Goede ~RT5651_PWR_LDO_DVO_MASK, 0); 1559*887fcc6fSHans de Goede /* Leave PLL1 and jack-detect power as is, all others off */ 1560*887fcc6fSHans de Goede snd_soc_component_update_bits(component, RT5651_PWR_ANLG2, 1561*887fcc6fSHans de Goede ~(RT5651_PWR_PLL | RT5651_PWR_JD_M), 0); 156240bc18a2SBard Liao break; 156340bc18a2SBard Liao 156440bc18a2SBard Liao default: 156540bc18a2SBard Liao break; 156640bc18a2SBard Liao } 156740bc18a2SBard Liao 156840bc18a2SBard Liao return 0; 156940bc18a2SBard Liao } 157040bc18a2SBard Liao 1571d8b8c878SHans de Goede static irqreturn_t rt5651_irq(int irq, void *data) 1572d8b8c878SHans de Goede { 1573d8b8c878SHans de Goede struct rt5651_priv *rt5651 = data; 1574d8b8c878SHans de Goede 1575d8b8c878SHans de Goede queue_delayed_work(system_power_efficient_wq, 1576d8b8c878SHans de Goede &rt5651->jack_detect_work, msecs_to_jiffies(250)); 1577d8b8c878SHans de Goede 1578d8b8c878SHans de Goede return IRQ_HANDLED; 1579d8b8c878SHans de Goede } 1580d8b8c878SHans de Goede 15816f0b819aSHans de Goede static int rt5651_set_jack(struct snd_soc_component *component, 15826f0b819aSHans de Goede struct snd_soc_jack *hp_jack, void *data) 1583d8b8c878SHans de Goede { 1584d8b8c878SHans de Goede struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 1585d8b8c878SHans de Goede struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 1586d8b8c878SHans de Goede int ret; 1587d8b8c878SHans de Goede 1588d8b8c878SHans de Goede if (!rt5651->irq) 1589d8b8c878SHans de Goede return -EINVAL; 1590d8b8c878SHans de Goede 1591d8b8c878SHans de Goede /* IRQ output on GPIO1 */ 1592d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1, 1593d8b8c878SHans de Goede RT5651_GP1_PIN_MASK, RT5651_GP1_PIN_IRQ); 1594d8b8c878SHans de Goede 1595d8b8c878SHans de Goede /* Select jack detect source */ 1596d8b8c878SHans de Goede switch (rt5651->jd_src) { 1597d8b8c878SHans de Goede case RT5651_JD1_1: 1598d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_JD_CTRL2, 1599d8b8c878SHans de Goede RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD1_1); 1600d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_IRQ_CTRL1, 1601d8b8c878SHans de Goede RT5651_JD1_1_IRQ_EN, RT5651_JD1_1_IRQ_EN); 1602d8b8c878SHans de Goede break; 1603d8b8c878SHans de Goede case RT5651_JD1_2: 1604d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_JD_CTRL2, 1605d8b8c878SHans de Goede RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD1_2); 1606d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_IRQ_CTRL1, 1607d8b8c878SHans de Goede RT5651_JD1_2_IRQ_EN, RT5651_JD1_2_IRQ_EN); 1608d8b8c878SHans de Goede break; 1609d8b8c878SHans de Goede case RT5651_JD2: 1610d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_JD_CTRL2, 1611d8b8c878SHans de Goede RT5651_JD_TRG_SEL_MASK, RT5651_JD_TRG_SEL_JD2); 1612d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_IRQ_CTRL1, 1613d8b8c878SHans de Goede RT5651_JD2_IRQ_EN, RT5651_JD2_IRQ_EN); 1614d8b8c878SHans de Goede break; 1615d8b8c878SHans de Goede case RT5651_JD_NULL: 1616d8b8c878SHans de Goede return 0; 1617d8b8c878SHans de Goede default: 1618d8b8c878SHans de Goede dev_err(component->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n"); 1619d8b8c878SHans de Goede return -EINVAL; 1620d8b8c878SHans de Goede } 1621d8b8c878SHans de Goede 1622d8b8c878SHans de Goede snd_soc_dapm_force_enable_pin(dapm, "JD Power"); 1623d8b8c878SHans de Goede snd_soc_dapm_force_enable_pin(dapm, "LDO"); 1624d8b8c878SHans de Goede snd_soc_dapm_sync(dapm); 1625d8b8c878SHans de Goede 1626d8b8c878SHans de Goede snd_soc_component_update_bits(component, RT5651_MICBIAS, 0x38, 0x38); 1627d8b8c878SHans de Goede 1628d8b8c878SHans de Goede rt5651->hp_jack = hp_jack; 1629d8b8c878SHans de Goede 1630d8b8c878SHans de Goede ret = devm_request_threaded_irq(component->dev, rt5651->irq, NULL, 1631d8b8c878SHans de Goede rt5651_irq, 1632d8b8c878SHans de Goede IRQF_TRIGGER_RISING | 1633d8b8c878SHans de Goede IRQF_TRIGGER_FALLING | 1634d8b8c878SHans de Goede IRQF_ONESHOT, "rt5651", rt5651); 1635d8b8c878SHans de Goede if (ret) { 1636d8b8c878SHans de Goede dev_err(component->dev, "Failed to reguest IRQ: %d\n", ret); 1637d8b8c878SHans de Goede return ret; 1638d8b8c878SHans de Goede } 1639d8b8c878SHans de Goede 1640d8b8c878SHans de Goede /* sync initial jack state */ 1641d8b8c878SHans de Goede queue_delayed_work(system_power_efficient_wq, 1642d8b8c878SHans de Goede &rt5651->jack_detect_work, 0); 1643d8b8c878SHans de Goede 1644d8b8c878SHans de Goede return 0; 1645d8b8c878SHans de Goede } 1646d8b8c878SHans de Goede 16475f293d43SHans de Goede void rt5651_apply_properties(struct snd_soc_component *component) 16485f293d43SHans de Goede { 16495f293d43SHans de Goede if (device_property_read_bool(component->dev, "realtek,in2-differential")) 16505f293d43SHans de Goede snd_soc_component_update_bits(component, RT5651_IN1_IN2, 16515f293d43SHans de Goede RT5651_IN_DF2, RT5651_IN_DF2); 16525f293d43SHans de Goede 16535f293d43SHans de Goede if (device_property_read_bool(component->dev, "realtek,dmic-en")) 16545f293d43SHans de Goede snd_soc_component_update_bits(component, RT5651_GPIO_CTRL1, 16555f293d43SHans de Goede RT5651_GP2_PIN_MASK, RT5651_GP2_PIN_DMIC1_SCL); 16565f293d43SHans de Goede } 16575f293d43SHans de Goede EXPORT_SYMBOL_GPL(rt5651_apply_properties); 16585f293d43SHans de Goede 165917b52010SKuninori Morimoto static int rt5651_probe(struct snd_soc_component *component) 166040bc18a2SBard Liao { 166117b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 166240bc18a2SBard Liao 166317b52010SKuninori Morimoto rt5651->component = component; 166440bc18a2SBard Liao 166517b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 166640bc18a2SBard Liao RT5651_PWR_VREF1 | RT5651_PWR_MB | 166740bc18a2SBard Liao RT5651_PWR_BG | RT5651_PWR_VREF2, 166840bc18a2SBard Liao RT5651_PWR_VREF1 | RT5651_PWR_MB | 166940bc18a2SBard Liao RT5651_PWR_BG | RT5651_PWR_VREF2); 167040bc18a2SBard Liao usleep_range(10000, 15000); 167117b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_PWR_ANLG1, 167240bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2, 167340bc18a2SBard Liao RT5651_PWR_FV1 | RT5651_PWR_FV2); 167440bc18a2SBard Liao 167517b52010SKuninori Morimoto snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF); 167640bc18a2SBard Liao 16775f293d43SHans de Goede rt5651_apply_properties(component); 16785f293d43SHans de Goede 167940bc18a2SBard Liao return 0; 168040bc18a2SBard Liao } 168140bc18a2SBard Liao 168240bc18a2SBard Liao #ifdef CONFIG_PM 168317b52010SKuninori Morimoto static int rt5651_suspend(struct snd_soc_component *component) 168440bc18a2SBard Liao { 168517b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 168640bc18a2SBard Liao 168740bc18a2SBard Liao regcache_cache_only(rt5651->regmap, true); 168840bc18a2SBard Liao regcache_mark_dirty(rt5651->regmap); 168940bc18a2SBard Liao return 0; 169040bc18a2SBard Liao } 169140bc18a2SBard Liao 169217b52010SKuninori Morimoto static int rt5651_resume(struct snd_soc_component *component) 169340bc18a2SBard Liao { 169417b52010SKuninori Morimoto struct rt5651_priv *rt5651 = snd_soc_component_get_drvdata(component); 169540bc18a2SBard Liao 169640bc18a2SBard Liao regcache_cache_only(rt5651->regmap, false); 169717b52010SKuninori Morimoto snd_soc_component_cache_sync(component); 169840bc18a2SBard Liao 169940bc18a2SBard Liao return 0; 170040bc18a2SBard Liao } 170140bc18a2SBard Liao #else 170240bc18a2SBard Liao #define rt5651_suspend NULL 170340bc18a2SBard Liao #define rt5651_resume NULL 170440bc18a2SBard Liao #endif 170540bc18a2SBard Liao 170640bc18a2SBard Liao #define RT5651_STEREO_RATES SNDRV_PCM_RATE_8000_96000 170740bc18a2SBard Liao #define RT5651_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 170840bc18a2SBard Liao SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 170940bc18a2SBard Liao 1710871c131dSMark Brown static const struct snd_soc_dai_ops rt5651_aif_dai_ops = { 171140bc18a2SBard Liao .hw_params = rt5651_hw_params, 171240bc18a2SBard Liao .set_fmt = rt5651_set_dai_fmt, 171340bc18a2SBard Liao .set_sysclk = rt5651_set_dai_sysclk, 171440bc18a2SBard Liao .set_pll = rt5651_set_dai_pll, 171540bc18a2SBard Liao }; 171640bc18a2SBard Liao 1717871c131dSMark Brown static struct snd_soc_dai_driver rt5651_dai[] = { 171840bc18a2SBard Liao { 171940bc18a2SBard Liao .name = "rt5651-aif1", 172040bc18a2SBard Liao .id = RT5651_AIF1, 172140bc18a2SBard Liao .playback = { 172240bc18a2SBard Liao .stream_name = "AIF1 Playback", 172340bc18a2SBard Liao .channels_min = 1, 172440bc18a2SBard Liao .channels_max = 2, 172540bc18a2SBard Liao .rates = RT5651_STEREO_RATES, 172640bc18a2SBard Liao .formats = RT5651_FORMATS, 172740bc18a2SBard Liao }, 172840bc18a2SBard Liao .capture = { 172940bc18a2SBard Liao .stream_name = "AIF1 Capture", 173040bc18a2SBard Liao .channels_min = 1, 173140bc18a2SBard Liao .channels_max = 2, 173240bc18a2SBard Liao .rates = RT5651_STEREO_RATES, 173340bc18a2SBard Liao .formats = RT5651_FORMATS, 173440bc18a2SBard Liao }, 173540bc18a2SBard Liao .ops = &rt5651_aif_dai_ops, 173640bc18a2SBard Liao }, 173740bc18a2SBard Liao { 173840bc18a2SBard Liao .name = "rt5651-aif2", 173940bc18a2SBard Liao .id = RT5651_AIF2, 174040bc18a2SBard Liao .playback = { 174140bc18a2SBard Liao .stream_name = "AIF2 Playback", 174240bc18a2SBard Liao .channels_min = 1, 174340bc18a2SBard Liao .channels_max = 2, 174440bc18a2SBard Liao .rates = RT5651_STEREO_RATES, 174540bc18a2SBard Liao .formats = RT5651_FORMATS, 174640bc18a2SBard Liao }, 174740bc18a2SBard Liao .capture = { 174840bc18a2SBard Liao .stream_name = "AIF2 Capture", 174940bc18a2SBard Liao .channels_min = 1, 175040bc18a2SBard Liao .channels_max = 2, 175140bc18a2SBard Liao .rates = RT5651_STEREO_RATES, 175240bc18a2SBard Liao .formats = RT5651_FORMATS, 175340bc18a2SBard Liao }, 175440bc18a2SBard Liao .ops = &rt5651_aif_dai_ops, 175540bc18a2SBard Liao }, 175640bc18a2SBard Liao }; 175740bc18a2SBard Liao 175817b52010SKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_rt5651 = { 175940bc18a2SBard Liao .probe = rt5651_probe, 176040bc18a2SBard Liao .suspend = rt5651_suspend, 176140bc18a2SBard Liao .resume = rt5651_resume, 176240bc18a2SBard Liao .set_bias_level = rt5651_set_bias_level, 17636f0b819aSHans de Goede .set_jack = rt5651_set_jack, 176440bc18a2SBard Liao .controls = rt5651_snd_controls, 176540bc18a2SBard Liao .num_controls = ARRAY_SIZE(rt5651_snd_controls), 176640bc18a2SBard Liao .dapm_widgets = rt5651_dapm_widgets, 176740bc18a2SBard Liao .num_dapm_widgets = ARRAY_SIZE(rt5651_dapm_widgets), 176840bc18a2SBard Liao .dapm_routes = rt5651_dapm_routes, 176940bc18a2SBard Liao .num_dapm_routes = ARRAY_SIZE(rt5651_dapm_routes), 177017b52010SKuninori Morimoto .use_pmdown_time = 1, 177117b52010SKuninori Morimoto .endianness = 1, 177217b52010SKuninori Morimoto .non_legacy_dai_naming = 1, 177340bc18a2SBard Liao }; 177440bc18a2SBard Liao 177540bc18a2SBard Liao static const struct regmap_config rt5651_regmap = { 177640bc18a2SBard Liao .reg_bits = 8, 177740bc18a2SBard Liao .val_bits = 16, 177840bc18a2SBard Liao 177940bc18a2SBard Liao .max_register = RT5651_DEVICE_ID + 1 + (ARRAY_SIZE(rt5651_ranges) * 178040bc18a2SBard Liao RT5651_PR_SPACING), 178140bc18a2SBard Liao .volatile_reg = rt5651_volatile_register, 178240bc18a2SBard Liao .readable_reg = rt5651_readable_register, 178340bc18a2SBard Liao 178440bc18a2SBard Liao .cache_type = REGCACHE_RBTREE, 178540bc18a2SBard Liao .reg_defaults = rt5651_reg, 178640bc18a2SBard Liao .num_reg_defaults = ARRAY_SIZE(rt5651_reg), 178740bc18a2SBard Liao .ranges = rt5651_ranges, 178840bc18a2SBard Liao .num_ranges = ARRAY_SIZE(rt5651_ranges), 178940bc18a2SBard Liao }; 179040bc18a2SBard Liao 17913ae08dc0SBard Liao #if defined(CONFIG_OF) 17923ae08dc0SBard Liao static const struct of_device_id rt5651_of_match[] = { 17933ae08dc0SBard Liao { .compatible = "realtek,rt5651", }, 17943ae08dc0SBard Liao {}, 17953ae08dc0SBard Liao }; 17963ae08dc0SBard Liao MODULE_DEVICE_TABLE(of, rt5651_of_match); 17973ae08dc0SBard Liao #endif 17983ae08dc0SBard Liao 17993ae08dc0SBard Liao #ifdef CONFIG_ACPI 18003ae08dc0SBard Liao static const struct acpi_device_id rt5651_acpi_match[] = { 18013ae08dc0SBard Liao { "10EC5651", 0 }, 18023ae08dc0SBard Liao { }, 18033ae08dc0SBard Liao }; 18043ae08dc0SBard Liao MODULE_DEVICE_TABLE(acpi, rt5651_acpi_match); 18053ae08dc0SBard Liao #endif 18063ae08dc0SBard Liao 180740bc18a2SBard Liao static const struct i2c_device_id rt5651_i2c_id[] = { 180840bc18a2SBard Liao { "rt5651", 0 }, 180940bc18a2SBard Liao { } 181040bc18a2SBard Liao }; 181140bc18a2SBard Liao MODULE_DEVICE_TABLE(i2c, rt5651_i2c_id); 181240bc18a2SBard Liao 1813b4435130SCarlo Caione static int rt5651_quirk_cb(const struct dmi_system_id *id) 1814b4435130SCarlo Caione { 1815b4435130SCarlo Caione rt5651_quirk = (unsigned long) id->driver_data; 1816b4435130SCarlo Caione return 1; 1817b4435130SCarlo Caione } 1818b4435130SCarlo Caione 1819b4435130SCarlo Caione static const struct dmi_system_id rt5651_quirk_table[] = { 1820f85353fdSCarlo Caione { 1821f85353fdSCarlo Caione .callback = rt5651_quirk_cb, 1822f85353fdSCarlo Caione .matches = { 1823f85353fdSCarlo Caione DMI_MATCH(DMI_SYS_VENDOR, "KIANO"), 1824f85353fdSCarlo Caione DMI_MATCH(DMI_PRODUCT_NAME, "KIANO SlimNote 14.2"), 1825f85353fdSCarlo Caione }, 1826f85353fdSCarlo Caione .driver_data = (unsigned long *) RT5651_JD1_1, 1827f85353fdSCarlo Caione }, 1828b4435130SCarlo Caione {} 1829b4435130SCarlo Caione }; 1830b4435130SCarlo Caione 183117b52010SKuninori Morimoto static int rt5651_jack_detect(struct snd_soc_component *component, int jack_insert) 183280bbe4a3SCarlo Caione { 183317b52010SKuninori Morimoto struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 183480bbe4a3SCarlo Caione int jack_type; 183580bbe4a3SCarlo Caione 183680bbe4a3SCarlo Caione if (jack_insert) { 183780bbe4a3SCarlo Caione snd_soc_dapm_force_enable_pin(dapm, "LDO"); 183880bbe4a3SCarlo Caione snd_soc_dapm_sync(dapm); 183980bbe4a3SCarlo Caione 184017b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_MICBIAS, 184180bbe4a3SCarlo Caione RT5651_MIC1_OVCD_MASK | 184280bbe4a3SCarlo Caione RT5651_MIC1_OVTH_MASK | 184380bbe4a3SCarlo Caione RT5651_PWR_CLK12M_MASK | 184480bbe4a3SCarlo Caione RT5651_PWR_MB_MASK, 184580bbe4a3SCarlo Caione RT5651_MIC1_OVCD_EN | 184680bbe4a3SCarlo Caione RT5651_MIC1_OVTH_600UA | 184780bbe4a3SCarlo Caione RT5651_PWR_MB_PU | 184880bbe4a3SCarlo Caione RT5651_PWR_CLK12M_PU); 184980bbe4a3SCarlo Caione msleep(100); 185017b52010SKuninori Morimoto if (snd_soc_component_read32(component, RT5651_IRQ_CTRL2) & RT5651_MB1_OC_CLR) 185180bbe4a3SCarlo Caione jack_type = SND_JACK_HEADPHONE; 185280bbe4a3SCarlo Caione else 185380bbe4a3SCarlo Caione jack_type = SND_JACK_HEADSET; 185417b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_IRQ_CTRL2, 185580bbe4a3SCarlo Caione RT5651_MB1_OC_CLR, 0); 185680bbe4a3SCarlo Caione } else { /* jack out */ 185780bbe4a3SCarlo Caione jack_type = 0; 185880bbe4a3SCarlo Caione 185917b52010SKuninori Morimoto snd_soc_component_update_bits(component, RT5651_MICBIAS, 186080bbe4a3SCarlo Caione RT5651_MIC1_OVCD_MASK, 186180bbe4a3SCarlo Caione RT5651_MIC1_OVCD_DIS); 186280bbe4a3SCarlo Caione } 186380bbe4a3SCarlo Caione 186480bbe4a3SCarlo Caione return jack_type; 186580bbe4a3SCarlo Caione } 186680bbe4a3SCarlo Caione 186780bbe4a3SCarlo Caione static void rt5651_jack_detect_work(struct work_struct *work) 186880bbe4a3SCarlo Caione { 186980bbe4a3SCarlo Caione struct rt5651_priv *rt5651 = 187080bbe4a3SCarlo Caione container_of(work, struct rt5651_priv, jack_detect_work.work); 187180bbe4a3SCarlo Caione 187280bbe4a3SCarlo Caione int report, val = 0; 187380bbe4a3SCarlo Caione 187417b52010SKuninori Morimoto if (!rt5651->component) 187580bbe4a3SCarlo Caione return; 187680bbe4a3SCarlo Caione 187754e3a3a1SHans de Goede switch (rt5651->jd_src) { 187880bbe4a3SCarlo Caione case RT5651_JD1_1: 187917b52010SKuninori Morimoto val = snd_soc_component_read32(rt5651->component, RT5651_INT_IRQ_ST) & 0x1000; 188080bbe4a3SCarlo Caione break; 188180bbe4a3SCarlo Caione case RT5651_JD1_2: 188217b52010SKuninori Morimoto val = snd_soc_component_read32(rt5651->component, RT5651_INT_IRQ_ST) & 0x2000; 188380bbe4a3SCarlo Caione break; 188480bbe4a3SCarlo Caione case RT5651_JD2: 188517b52010SKuninori Morimoto val = snd_soc_component_read32(rt5651->component, RT5651_INT_IRQ_ST) & 0x4000; 188680bbe4a3SCarlo Caione break; 188780bbe4a3SCarlo Caione default: 188880bbe4a3SCarlo Caione break; 188980bbe4a3SCarlo Caione } 189080bbe4a3SCarlo Caione 189117b52010SKuninori Morimoto report = rt5651_jack_detect(rt5651->component, !val); 189280bbe4a3SCarlo Caione 189380bbe4a3SCarlo Caione snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET); 189480bbe4a3SCarlo Caione } 189580bbe4a3SCarlo Caione 189640bc18a2SBard Liao static int rt5651_i2c_probe(struct i2c_client *i2c, 189740bc18a2SBard Liao const struct i2c_device_id *id) 189840bc18a2SBard Liao { 189940bc18a2SBard Liao struct rt5651_priv *rt5651; 190040bc18a2SBard Liao int ret; 190140bc18a2SBard Liao 190240bc18a2SBard Liao rt5651 = devm_kzalloc(&i2c->dev, sizeof(*rt5651), 190340bc18a2SBard Liao GFP_KERNEL); 190440bc18a2SBard Liao if (NULL == rt5651) 190540bc18a2SBard Liao return -ENOMEM; 190640bc18a2SBard Liao 190740bc18a2SBard Liao i2c_set_clientdata(i2c, rt5651); 190840bc18a2SBard Liao 1909b4435130SCarlo Caione dmi_check_system(rt5651_quirk_table); 191054e3a3a1SHans de Goede rt5651->jd_src = RT5651_JD_MAP(rt5651_quirk); 191140bc18a2SBard Liao 191240bc18a2SBard Liao rt5651->regmap = devm_regmap_init_i2c(i2c, &rt5651_regmap); 191340bc18a2SBard Liao if (IS_ERR(rt5651->regmap)) { 191440bc18a2SBard Liao ret = PTR_ERR(rt5651->regmap); 191540bc18a2SBard Liao dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 191640bc18a2SBard Liao ret); 191740bc18a2SBard Liao return ret; 191840bc18a2SBard Liao } 191940bc18a2SBard Liao 192040bc18a2SBard Liao regmap_read(rt5651->regmap, RT5651_DEVICE_ID, &ret); 192140bc18a2SBard Liao if (ret != RT5651_DEVICE_ID_VALUE) { 192240bc18a2SBard Liao dev_err(&i2c->dev, 1923469444fbSJarkko Nikula "Device with ID register %#x is not rt5651\n", ret); 192440bc18a2SBard Liao return -ENODEV; 192540bc18a2SBard Liao } 192640bc18a2SBard Liao 192740bc18a2SBard Liao regmap_write(rt5651->regmap, RT5651_RESET, 0); 192840bc18a2SBard Liao 192940bc18a2SBard Liao ret = regmap_register_patch(rt5651->regmap, init_list, 193040bc18a2SBard Liao ARRAY_SIZE(init_list)); 193140bc18a2SBard Liao if (ret != 0) 193240bc18a2SBard Liao dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); 193340bc18a2SBard Liao 1934f06da4fdSHans de Goede rt5651->irq = i2c->irq; 193540bc18a2SBard Liao rt5651->hp_mute = 1; 193640bc18a2SBard Liao 193780bbe4a3SCarlo Caione INIT_DELAYED_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work); 193880bbe4a3SCarlo Caione 193917b52010SKuninori Morimoto ret = devm_snd_soc_register_component(&i2c->dev, 194017b52010SKuninori Morimoto &soc_component_dev_rt5651, 194140bc18a2SBard Liao rt5651_dai, ARRAY_SIZE(rt5651_dai)); 194240bc18a2SBard Liao 194340bc18a2SBard Liao return ret; 194440bc18a2SBard Liao } 194540bc18a2SBard Liao 194640bc18a2SBard Liao static int rt5651_i2c_remove(struct i2c_client *i2c) 194740bc18a2SBard Liao { 194880bbe4a3SCarlo Caione struct rt5651_priv *rt5651 = i2c_get_clientdata(i2c); 194980bbe4a3SCarlo Caione 195080bbe4a3SCarlo Caione cancel_delayed_work_sync(&rt5651->jack_detect_work); 195140bc18a2SBard Liao 195240bc18a2SBard Liao return 0; 195340bc18a2SBard Liao } 195440bc18a2SBard Liao 1955871c131dSMark Brown static struct i2c_driver rt5651_i2c_driver = { 195640bc18a2SBard Liao .driver = { 195740bc18a2SBard Liao .name = "rt5651", 19583ae08dc0SBard Liao .acpi_match_table = ACPI_PTR(rt5651_acpi_match), 19593ae08dc0SBard Liao .of_match_table = of_match_ptr(rt5651_of_match), 196040bc18a2SBard Liao }, 196140bc18a2SBard Liao .probe = rt5651_i2c_probe, 196240bc18a2SBard Liao .remove = rt5651_i2c_remove, 196340bc18a2SBard Liao .id_table = rt5651_i2c_id, 196440bc18a2SBard Liao }; 196540bc18a2SBard Liao module_i2c_driver(rt5651_i2c_driver); 196640bc18a2SBard Liao 196740bc18a2SBard Liao MODULE_DESCRIPTION("ASoC RT5651 driver"); 196840bc18a2SBard Liao MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>"); 196940bc18a2SBard Liao MODULE_LICENSE("GPL v2"); 1970